Skip to content

Commit 7f787bc

Browse files
matdruprevwong
andauthored
chore: Add prettier config (prevwong#87)
* chore: update stable docs * Adds prettier config * Fix wrong tab width * Brings back semis Co-authored-by: Prev Wong <[email protected]>
1 parent f1a7b05 commit 7f787bc

File tree

161 files changed

+1742
-1622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1742
-1622
lines changed

.github/workflows/pull-request.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
run: yarn build
2525

2626
- name: Run tests
27-
run: yarn test
27+
run: yarn test

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
node-version: 10.x
2121

2222
- run: yarn install --frozen-lockfile
23-
- run: yarn release
23+
- run: yarn release

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"singleQuote": true
5+
}

config.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
module.exports = {
22
url: {
33
production: {
4-
LANDING: "https://craft.js.org/",
5-
DOCUMENTATION: "https://craft.js.org/r/docs/overview/",
6-
BASIC_EXAMPLE: "https://craft.js.org/examples/basic/",
4+
LANDING: 'https://craft.js.org/',
5+
DOCUMENTATION: 'https://craft.js.org/r/docs/overview/',
6+
BASIC_EXAMPLE: 'https://craft.js.org/examples/basic/',
77
},
88
staging: {
9-
LANDING: "https://craftjs.netlify.com/",
10-
DOCUMENTATION: "https://craftjs.netlify.com/r/docs/overview/",
11-
BASIC_EXAMPLE: "https://craftjs.netlify.com/examples/basic/",
9+
LANDING: 'https://craftjs.netlify.com/',
10+
DOCUMENTATION: 'https://craftjs.netlify.com/r/docs/overview/',
11+
BASIC_EXAMPLE: 'https://craftjs.netlify.com/examples/basic/',
1212
},
1313
development: {
14-
LANDING: "http://localhost:3001/",
15-
DOCUMENTATION: "http://localhost:3000/r/docs/overview/",
16-
BASIC_EXAMPLE: "http://localhost:3002/",
14+
LANDING: 'http://localhost:3001/',
15+
DOCUMENTATION: 'http://localhost:3000/r/docs/overview/',
16+
BASIC_EXAMPLE: 'http://localhost:3002/',
1717
},
18-
}[process.env.ENV || "development"],
18+
}[process.env.ENV || 'development'],
1919
};

jest/setup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Enzyme = require("enzyme");
2-
const Adapter = require("enzyme-adapter-react-16");
1+
const Enzyme = require('enzyme');
2+
const Adapter = require('enzyme-adapter-react-16');
33

44
Enzyme.configure({ adapter: new Adapter() });

lerna.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"npmClient": "yarn",
33
"useWorkspaces": true,
4-
"packages": [
5-
"packages/*",
6-
"packages/examples/*"
7-
],
4+
"packages": ["packages/*", "packages/examples/*"],
85
"version": "0.1.0-beta.7"
96
}

packages/core/rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import config from "../../rollup.config";
1+
import config from '../../rollup.config';
22

33
export default {
44
...config,
5-
input: "./src/index.tsx",
5+
input: './src/index.tsx',
66
};

packages/core/src/editor/Editor.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { useEffect } from "react";
1+
import React, { useEffect } from 'react';
22

3-
import { Options } from "../interfaces";
4-
import { Events } from "../events";
3+
import { Options } from '../interfaces';
4+
import { Events } from '../events';
55

6-
import { useEditorStore } from "./store";
7-
import { EditorContext } from "./EditorContext";
6+
import { useEditorStore } from './store';
7+
import { EditorContext } from './EditorContext';
88

99
export const withDefaults = (options: Partial<Options> = {}) => ({
1010
onNodesChange: () => null,
@@ -13,8 +13,8 @@ export const withDefaults = (options: Partial<Options> = {}) => ({
1313
nodes: null,
1414
enabled: true,
1515
indicator: {
16-
error: "red",
17-
success: "rgb(98, 196, 98)",
16+
error: 'red',
17+
success: 'rgb(98, 196, 98)',
1818
},
1919
...options,
2020
});
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createContext } from "react";
2-
import { EditorStore } from "./store";
1+
import { createContext } from 'react';
2+
import { EditorStore } from './store';
33

44
export type EditorContext = EditorStore;
55
export const EditorContext = createContext<EditorContext>({} as EditorContext);

packages/core/src/editor/NodeHelpers.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { EditorState, Node, NodeId } from "@craftjs/core";
2-
import invariant from "tiny-invariant";
1+
import { EditorState, Node, NodeId } from '@craftjs/core';
2+
import invariant from 'tiny-invariant';
33
import {
44
deprecationWarning,
55
ERROR_CANNOT_DRAG,
@@ -12,19 +12,19 @@ import {
1212
ERROR_MOVE_TO_NONCANVAS_PARENT,
1313
ERROR_MOVE_TOP_LEVEL_NODE,
1414
ROOT_NODE,
15-
} from "@craftjs/utils";
16-
import { serializeNode } from "../utils/serializeNode";
17-
import { mergeTrees } from "../utils/mergeTrees";
15+
} from '@craftjs/utils';
16+
import { serializeNode } from '../utils/serializeNode';
17+
import { mergeTrees } from '../utils/mergeTrees';
1818

1919
export function NodeHelpers(state: EditorState, id: NodeId) {
20-
invariant(typeof id == "string", ERROR_INVALID_NODE_ID);
20+
invariant(typeof id == 'string', ERROR_INVALID_NODE_ID);
2121

2222
const node = state.nodes[id];
2323

2424
const nodeHelpers = (id) => NodeHelpers(state, id);
2525

2626
const getNodeFromIdOrNode = (node: NodeId | Node) =>
27-
typeof node === "string" ? state.nodes[node] : node;
27+
typeof node === 'string' ? state.nodes[node] : node;
2828

2929
return {
3030
isCanvas() {
@@ -47,8 +47,8 @@ export function NodeHelpers(state: EditorState, id: NodeId) {
4747
},
4848
isParentOfTopLevelNodes: () => !!node.data.linkedNodes,
4949
isParentOfTopLevelCanvas() {
50-
deprecationWarning("query.node(id).isParentOfTopLevelCanvas", {
51-
suggest: "query.node(id).isParentOfTopLevelNodes",
50+
deprecationWarning('query.node(id).isParentOfTopLevelCanvas', {
51+
suggest: 'query.node(id).isParentOfTopLevelNodes',
5252
});
5353
return this.isParentOfTopLevelNodes();
5454
},
@@ -142,12 +142,12 @@ export function NodeHelpers(state: EditorState, id: NodeId) {
142142
}
143143
},
144144
isDroppable(target: NodeId | Node, onError?: (err: string) => void) {
145-
const isNewNode = typeof target == "object" && !state.nodes[target.id];
145+
const isNewNode = typeof target == 'object' && !state.nodes[target.id];
146146
const targetNode = getNodeFromIdOrNode(target),
147147
newParentNode = node;
148148
try {
149149
// If target is a NodeId (thus it's already in the state), check if it's a top-level node
150-
if (typeof target === "string") {
150+
if (typeof target === 'string') {
151151
invariant(
152152
!nodeHelpers(target).isTopLevelNode(),
153153
ERROR_MOVE_TOP_LEVEL_NODE
@@ -215,8 +215,8 @@ export function NodeHelpers(state: EditorState, id: NodeId) {
215215
**/
216216

217217
decendants(deep = false) {
218-
deprecationWarning("query.node(id).decendants", {
219-
suggest: "query.node(id).descendants",
218+
deprecationWarning('query.node(id).decendants', {
219+
suggest: 'query.node(id).descendants',
220220
});
221221
return this.descendants(deep);
222222
},

packages/core/src/editor/actions.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
NodeEvents,
99
NodeTree,
1010
SerializedNodes,
11-
} from "../interfaces";
11+
} from '../interfaces';
1212
import {
1313
deprecationWarning,
1414
ERROR_INVALID_NODEID,
@@ -17,12 +17,12 @@ import {
1717
QueryCallbacksFor,
1818
ERROR_NOPARENT,
1919
ERROR_DELETE_TOP_LEVEL_NODE,
20-
} from "@craftjs/utils";
21-
import { QueryMethods } from "./query";
22-
import { fromEntries } from "../utils/fromEntries";
23-
import { updateEventsNode } from "../utils/updateEventsNode";
24-
import invariant from "tiny-invariant";
25-
import { editorInitialState } from "./store";
20+
} from '@craftjs/utils';
21+
import { QueryMethods } from './query';
22+
import { fromEntries } from '../utils/fromEntries';
23+
import { updateEventsNode } from '../utils/updateEventsNode';
24+
import invariant from 'tiny-invariant';
25+
import { editorInitialState } from './store';
2626

2727
export const Actions = (
2828
state: EditorState,
@@ -41,7 +41,7 @@ export const Actions = (
4141
}
4242

4343
if (parent.data.props.children) {
44-
delete parent.data.props["children"];
44+
delete parent.data.props['children'];
4545
}
4646

4747
if (index != null) {
@@ -122,8 +122,8 @@ export const Actions = (
122122
// TODO: Deprecate adding array of Nodes to keep implementation simpler
123123
let nodes = [nodeToAdd];
124124
if (Array.isArray(nodeToAdd)) {
125-
deprecationWarning("actions.add(node: Node[])", {
126-
suggest: "actions.add(node: Node)",
125+
deprecationWarning('actions.add(node: Node[])', {
126+
suggest: 'actions.add(node: Node)',
127127
});
128128
nodes = nodeToAdd;
129129
}
@@ -145,7 +145,7 @@ export const Actions = (
145145
if (!parentId) {
146146
invariant(
147147
tree.rootNodeId === ROOT_NODE,
148-
"Cannot add non-root Node without a parent"
148+
'Cannot add non-root Node without a parent'
149149
);
150150
state.nodes[tree.rootNodeId] = node;
151151
}
@@ -176,7 +176,7 @@ export const Actions = (
176176

177177
deserialize(input: SerializedNodes | string) {
178178
const dehydratedNodes =
179-
typeof input == "string" ? JSON.parse(input) : input;
179+
typeof input == 'string' ? JSON.parse(input) : input;
180180

181181
const nodePairs = Object.keys(dehydratedNodes).map((id) => {
182182
let nodeId = id;
@@ -212,7 +212,7 @@ export const Actions = (
212212
const currentParent = state.nodes[currentParentId],
213213
currentParentNodes = currentParent.data.nodes!;
214214

215-
currentParentNodes[currentParentNodes.indexOf(targetId)] = "marked";
215+
currentParentNodes[currentParentNodes.indexOf(targetId)] = 'marked';
216216

217217
if (newParentNodes) {
218218
newParentNodes.splice(index, 0, targetId);
@@ -222,7 +222,7 @@ export const Actions = (
222222

223223
state.nodes[targetId].data.parent = newParentId;
224224
state.nodes[targetId].data.index = index;
225-
currentParentNodes.splice(currentParentNodes.indexOf("marked"), 1);
225+
currentParentNodes.splice(currentParentNodes.indexOf('marked'), 1);
226226
},
227227

228228
replaceNodes(nodes: Nodes) {
@@ -272,7 +272,7 @@ export const Actions = (
272272
*/
273273
setCustom<T extends NodeId>(
274274
id: T,
275-
cb: (data: EditorState["nodes"][T]["data"]["custom"]) => void
275+
cb: (data: EditorState['nodes'][T]['data']['custom']) => void
276276
) {
277277
cb(state.nodes[id].data.custom);
278278
},

packages/core/src/editor/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "./Editor";
1+
export * from './Editor';

packages/core/src/editor/query.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React from 'react';
22
import {
33
NodeId,
44
EditorState,
@@ -9,23 +9,23 @@ import {
99
NodeTree,
1010
SerializedNodes,
1111
SerializedNode,
12-
} from "../interfaces";
13-
import invariant from "tiny-invariant";
12+
} from '../interfaces';
13+
import invariant from 'tiny-invariant';
1414
import {
1515
QueryCallbacksFor,
1616
ERROR_NOT_IN_RESOLVER,
1717
getDOMInfo,
1818
deprecationWarning,
1919
DEPRECATED_ROOT_NODE,
2020
ROOT_NODE,
21-
} from "@craftjs/utils";
22-
import findPosition from "../events/findPosition";
23-
import { parseNodeFromJSX } from "../utils/parseNodeFromJSX";
24-
import { fromEntries } from "../utils/fromEntries";
25-
import { mergeTrees } from "../utils/mergeTrees";
26-
import { resolveComponent } from "../utils/resolveComponent";
27-
import { deserializeNode } from "../utils/deserializeNode";
28-
import { NodeHelpers } from "./NodeHelpers";
21+
} from '@craftjs/utils';
22+
import findPosition from '../events/findPosition';
23+
import { parseNodeFromJSX } from '../utils/parseNodeFromJSX';
24+
import { fromEntries } from '../utils/fromEntries';
25+
import { mergeTrees } from '../utils/mergeTrees';
26+
import { resolveComponent } from '../utils/resolveComponent';
27+
import { deserializeNode } from '../utils/deserializeNode';
28+
import { NodeHelpers } from './NodeHelpers';
2929

3030
export function QueryMethods(state: EditorState) {
3131
const options = state && state.options;
@@ -45,7 +45,7 @@ export function QueryMethods(state: EditorState) {
4545
state.nodes[node.id].dom
4646
) => {
4747
if (source === target) return;
48-
const sourceNodeFromId = typeof source == "string" && state.nodes[source],
48+
const sourceNodeFromId = typeof source == 'string' && state.nodes[source],
4949
targetNode = state.nodes[target],
5050
isTargetCanvas = _().node(targetNode.id).isCanvas();
5151

packages/core/src/editor/store.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useMethods, SubscriberAndCallbacksFor } from "@craftjs/utils";
2-
import { Actions } from "./actions";
3-
import { QueryMethods } from "./query";
1+
import { useMethods, SubscriberAndCallbacksFor } from '@craftjs/utils';
2+
import { Actions } from './actions';
3+
import { QueryMethods } from './query';
44

55
export type EditorStore = SubscriberAndCallbacksFor<typeof Actions>;
66

packages/core/src/editor/tests/Editor.test.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import React from "react";
2-
import { shallow } from "enzyme";
3-
import { act } from "react-dom/test-utils";
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import { act } from 'react-dom/test-utils';
44

5-
import { EditorContext } from "../EditorContext";
6-
import { Editor } from "../Editor";
7-
import { Events } from "../../events";
8-
import { useEditorStore } from "../store";
5+
import { EditorContext } from '../EditorContext';
6+
import { Editor } from '../Editor';
7+
import { Events } from '../../events';
8+
import { useEditorStore } from '../store';
99

10-
jest.mock("../store");
10+
jest.mock('../store');
1111
const mockStore = useEditorStore as jest.Mock<any>;
1212

13-
describe("<Editor />", () => {
13+
describe('<Editor />', () => {
1414
const children = <h1>a children</h1>;
1515
let actions;
1616
let component;
@@ -20,7 +20,7 @@ describe("<Editor />", () => {
2020
beforeEach(() => {
2121
React.useEffect = (f) => f();
2222

23-
query = { serialize: jest.fn().mockImplementation(() => "{}") };
23+
query = { serialize: jest.fn().mockImplementation(() => '{}') };
2424
onStateChange = jest.fn();
2525
mockStore.mockImplementation((value) => ({ ...value, query, actions }));
2626
act(() => {
@@ -29,10 +29,10 @@ describe("<Editor />", () => {
2929
);
3030
});
3131
});
32-
it("should render the children with events", () => {
32+
it('should render the children with events', () => {
3333
expect(component.contains(<Events>{children}</Events>)).toBe(true);
3434
});
35-
it("should render the EditorContext.Provider", () => {
35+
it('should render the EditorContext.Provider', () => {
3636
expect(component.find(EditorContext.Provider)).toHaveLength(1);
3737
});
3838

0 commit comments

Comments
 (0)