Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes from candulabs/craft.js #69

Merged
merged 31 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f61c311
Add prepush hook, some small nits to the craft project setup (#1)
mresposito Mar 25, 2020
663958e
Add onStateChanged hook (#2)
mresposito Mar 28, 2020
28a20de
Editor state get & set (#3)
matdru Mar 28, 2020
06fa0a8
Sync changes from main repo (#4)
mresposito Mar 31, 2020
64159fd
Adds github workflow (#5)
matdru Apr 1, 2020
da5787c
Actions - second attempt (#6)
matdru Apr 1, 2020
8b95a6e
v0.1.6
actions-user Apr 1, 2020
3ef647f
Adds npmrc
matdru Apr 1, 2020
f55a6bf
Moves env to job level
matdru Apr 1, 2020
6450d98
v0.1.7
actions-user Apr 1, 2020
39b1458
Sync changes from main repo (#8)
matdru Apr 2, 2020
1687460
v0.1.8
actions-user Apr 2, 2020
894b4b0
expose use node context (#9)
mresposito Apr 3, 2020
99557af
v0.1.9
actions-user Apr 3, 2020
ab593ff
Rewrite actions.delete and actions.add plus unit tests (#10)
mresposito Apr 8, 2020
559ee2c
v0.1.10
actions-user Apr 8, 2020
03188b2
Refactor event handler to add more unit tests and make it more readab…
mresposito Apr 9, 2020
3f2f209
v0.1.11
actions-user Apr 9, 2020
8d800de
Local development with yalc (#12)
matdru Apr 9, 2020
514be31
v0.1.12
actions-user Apr 9, 2020
9fc2b6a
Parse entire tree when dropping a node (#13)
mresposito Apr 12, 2020
3c7d13f
v0.1.13
actions-user Apr 12, 2020
844c6bf
Adds check if resolver has isCanvas set (#14)
matdru Apr 14, 2020
56a1c25
v0.1.14
actions-user Apr 14, 2020
b836815
fix: use Subscriber to handle onStateChange (#15)
Apr 21, 2020
9d85e4e
v0.1.15
actions-user Apr 21, 2020
36bfbf0
merge all the changes from candulabs craft
mresposito Apr 26, 2020
c744ec8
add enzyme deps
mresposito Apr 27, 2020
b19607d
pr review
mresposito Apr 29, 2020
f51eeaa
feat: Improvements to PR-69 (#72)
prevwong May 14, 2020
2fcd8df
Merge branch 'master' into michele-actions
mresposito May 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
beforeEach(() => {
console.error = jest.fn();
});
const Enzyme = require("enzyme");
const Adapter = require("enzyme-adapter-react-16");

Enzyme.configure({ adapter: new Adapter() });
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"@typescript-eslint/parser": "^2.14.0",
"babel-eslint": "^10.0.3",
"cross-env": "^6.0.3",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-config-react-app": "^5.1.0",
Expand Down Expand Up @@ -83,7 +85,7 @@
"<rootDir>/packages/core/"
],
"testMatch": [
"<rootDir>/packages/core/src/**/__tests__/?(*.)spec.ts(x|)"
"<rootDir>/packages/core/src/**/?(*.)test.ts(x|)"
prevwong marked this conversation as resolved.
Show resolved Hide resolved
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
Expand Down
61 changes: 0 additions & 61 deletions packages/core/src/__tests__/Canvas.spec.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions packages/core/src/__tests__/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions packages/core/src/__tests__/useEditor.spec.tsx

This file was deleted.

54 changes: 54 additions & 0 deletions packages/core/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useEffect } from "react";

import { Options } from "../interfaces";
import { Events } from "../events";

import { useEditorStore } from "./store";
import { EditorContext } from "./EditorContext";

export const withDefaults = (options: Partial<Options> = {}) => ({
onStateChange: () => null,
onRender: ({ render }) => render,
resolver: {},
nodes: null,
enabled: true,
indicator: {
error: "red",
success: "rgb(98, 196, 98)",
},
...options,
});

/**
* A React Component that provides the Editor context
*/
export const Editor: React.FC<Partial<Options>> = ({
children,
...options
}) => {
const context = useEditorStore(withDefaults(options));

useEffect(() => {
if (context && options)
context.actions.setOptions((editorOptions) => {
editorOptions = options;
});
}, [context, options]);

useEffect(() => {
context.subscribe(
(_) => ({
json: context.query.serialize(),
}),
({ json }) => {
context.query.getOptions().onStateChange(JSON.parse(json));
}
);
}, [context]);

return context ? (
<EditorContext.Provider value={context}>
<Events>{children}</Events>
</EditorContext.Provider>
) : null;
};
Loading