Skip to content

Commit

Permalink
Merge changes from candulabs/craft.js (prevwong#69)
Browse files Browse the repository at this point in the history
* Add prepush hook, some small nits to the craft project setup (#1)

* add test staged

* add prepush hook

* Add onStateChanged hook (#2)

* improve unit tests setup, refactor and move some unit tests. Also add a callback for nodes

* add pull request template

* add unit tests for frame, improve handling of frame

* Editor state get & set (#3)

* Adds nodes state get and set methods

* Fixes over-shadowing bug

* Add private @candulabs scope for release

* Switches whole repo to point to @candulabs fork

* Updates tests

* Bumps up core version

* Update README.md

Adds warning about using this fork instead of official release

* Sync changes from main repo (#4)

* add test staged

* add prepush hook

* run prettier

* change unit test matcher

* ignore Canvas root id test

Caused by Subscriber, to be fixed

* v0.1.0-beta.4

* Update contributing

* update naming

* update version number

* package naming

Co-authored-by: Prev Wong <prevwong@gmail.com>

* Adds github workflow (#5)

* Adds test workflow

* Fixes shell linter

* Refactors flow to use node step

* Adds build step

* Corrects dep version

* Removes bad dependency

* Fixes potential case sensitive typo

* Configures lerna version

* Reset fork versions for lerna

* v0.1.5

* Adds optional publish step

* Adds better name to workflow

* Removes redundant job name

* Improves naming further

* Actions - second attempt (#6)

* Adds test workflow

* Fixes shell linter

* Refactors flow to use node step

* Adds build step

* Corrects dep version

* Removes bad dependency

* Fixes potential case sensitive typo

* Configures lerna version

* Reset fork versions for lerna

* v0.1.5

* Adds optional publish step

* Adds better name to workflow

* Removes redundant job name

* Improves naming further

* Introduces split workflow

* v0.1.6

* Adds npmrc

* Moves env to job level

* v0.1.7

* Sync changes from main repo (#8)

* add test staged

* add prepush hook

* run prettier

* change unit test matcher

* ignore Canvas root id test

Caused by Subscriber, to be fixed

* v0.1.0-beta.4

* Update contributing

* fix: allow Subscriber to collect state when created (prevwong#52)

* fix: add types for subscriber

* docs: update styling

* docs: fix typos

* docs: add example for drop indicator colours

* chore: add open collective

* docs: add layers gif

* chore: update README

* docs: fix Frame props description

Co-authored-by: Michele Riccardo Esposito <mresposito5@gmail.com>
Co-authored-by: Prev Wong <prevwong@gmail.com>

* v0.1.8

* expose use node context (#9)

* v0.1.9

* Rewrite actions.delete and actions.add plus unit tests (#10)

* tidy up the style inside actions

* add unit tests for action

* improve actions.add and actions.delete functions

* fix drag selection

* v0.1.10

* Refactor event handler to add more unit tests and make it more readable (#11)

* couple small style improvements

* refactor event handlers

* sort the query methods by name

* v0.1.11

* Local development with yalc (#12)

* Adds setup for local development with yalc

* Adds nodemon config file to npmignore

* v0.1.12

* Parse entire tree when dropping a node (#13)

* change query to create and parse a tree, small code style nits

* parse an entire tree from jsx instead of just a single node

* implement adding the tree recursively

* fix dropping shadow

* improve the renderNode function to render nodes among children if there are any

* prevent nodes from being stripped from state if they are not in a canvas node

* v0.1.13

* Adds check if resolver has isCanvas set (#14)

* v0.1.14

* fix: use Subscriber to handle onStateChange (#15)

* v0.1.15

* add enzyme deps

* pr review

* feat: Improvements to PR-69 (prevwong#72)

* Add parseNodeFromNodeData method in query, deprecate query.createNode (#18)

* rename query.createNode to query.parseNodeFromReactNode

* refactor transformJSXToNode and create node

* some light refactoring for readibiliyt

* try up the code

* add a couple unit tests, fix some small bugs

* fix fromEntries on node
# Conflicts:
#	packages/core/src/render/Frame.tsx
#	packages/core/src/render/tests/Frame.test.tsx
#	packages/utils/src/tests/History.test.ts

* fix: remove support for adding child nodes in non-Canvas

This will be added when the Element component is introduced

* fix: resetting parent nodes, re-added support for childCanvas

* chore: move event() to utils

* feat: PR improvements

* chore: rename SerialisedNodeData

* chore

* nit

Co-authored-by: Michele Riccardo Esposito <mresposito5@gmail.com>

Co-authored-by: Mateusz Drulis <mateusz.drulis@gmail.com>
Co-authored-by: Prev Wong <prevwong@gmail.com>
Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Prev Wong <prevwong@icloud.com>
  • Loading branch information
5 people authored May 16, 2020
1 parent 6147a24 commit 8fa6f00
Show file tree
Hide file tree
Showing 49 changed files with 2,234 additions and 660 deletions.
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|)"
],
"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

0 comments on commit 8fa6f00

Please sign in to comment.