From a601263ef356e31e224c9a646e86f1da0b8f9211 Mon Sep 17 00:00:00 2001 From: Cary Dunn Date: Tue, 13 Nov 2018 08:09:18 -0800 Subject: [PATCH 1/5] wip --- lib/changes/decreaseItemDepth.js | 25 +++--- lib/changes/increaseItemDepth.js | 33 +++---- lib/changes/splitListItem.js | 10 +-- lib/changes/unwrapList.js | 20 ++--- lib/changes/wrapInList.js | 19 ++-- lib/handlers/onBackspace.js | 16 ++-- lib/handlers/onEnter.js | 20 ++--- lib/handlers/onTab.js | 12 ++- lib/index.js | 6 +- lib/validation/index.js | 1 + lib/validation/normalizeNode.js | 20 +++-- lib/validation/schema.js | 37 ++++---- package.json | 8 +- tests/backspace-end-of-inline/change.js | 2 +- yarn.lock | 115 +++++++++++++----------- 15 files changed, 181 insertions(+), 163 deletions(-) diff --git a/lib/changes/decreaseItemDepth.js b/lib/changes/decreaseItemDepth.js index 7a6a4d0e..73045362 100644 --- a/lib/changes/decreaseItemDepth.js +++ b/lib/changes/decreaseItemDepth.js @@ -1,5 +1,6 @@ // @flow -import { Block, type Change } from 'slate'; +import { Block } from 'slate'; +import { Editor } from 'slate-react' import type Options from '../options'; import { getItemDepth, getCurrentItem } from '../utils'; @@ -10,19 +11,19 @@ import { getItemDepth, getCurrentItem } from '../utils'; * * No-op for root items. */ -function decreaseItemDepth(opts: Options, change: Change): Change { - const { value } = change; +function decreaseItemDepth(opts: Options, editor: Editor): Editor { + const { value } = editor; const { document } = value; // Cannot decrease item depth of root items const depth = getItemDepth(opts, value); if (depth == 1) { - return change; + return editor; } const currentItem = getCurrentItem(opts, value); if (!currentItem) { - return change; + return editor; } const currentList = document.getParent(currentItem.key); @@ -46,14 +47,14 @@ function decreaseItemDepth(opts: Options, change: Change): Change { data: currentList.data }); // Add the sublist - change.withoutNormalizing(() => { - change.insertNodeByKey( + editor.withoutNormalizing(() => { + editor.insertNodeByKey( currentItem.key, currentItem.nodes.size, sublist ); - change.moveNodeByKey( + editor.moveNodeByKey( currentItem.key, parentList.key, parentList.nodes.indexOf(parentItem) + 1 @@ -61,7 +62,7 @@ function decreaseItemDepth(opts: Options, change: Change): Change { // Move the followingItems to the sublist followingItems.forEach((item, index) => - change.moveNodeByKey( + editor.moveNodeByKey( item.key, sublist.key, sublist.nodes.size + index @@ -69,7 +70,7 @@ function decreaseItemDepth(opts: Options, change: Change): Change { ); }); } else { - change.moveNodeByKey( + editor.moveNodeByKey( currentItem.key, parentList.key, parentList.nodes.indexOf(parentItem) + 1 @@ -78,10 +79,10 @@ function decreaseItemDepth(opts: Options, change: Change): Change { // Remove the currentList completely if needed if (willEmptyCurrentList) { - change.removeNodeByKey(currentList.key); + editor.removeNodeByKey(currentList.key); } - return change; + return editor; } export default decreaseItemDepth; diff --git a/lib/changes/increaseItemDepth.js b/lib/changes/increaseItemDepth.js index f6e0dcfc..a6ac422e 100644 --- a/lib/changes/increaseItemDepth.js +++ b/lib/changes/increaseItemDepth.js @@ -1,5 +1,6 @@ // @flow -import { Block, type Change } from 'slate'; +import { Block } from 'slate'; +import { Editor } from "slate-react"; import type Options from '../options'; import { @@ -14,20 +15,20 @@ import { * of previous item. * For first items in a list, does nothing. */ -function increaseItemDepth(opts: Options, change: Change): Change { - const previousItem = getPreviousItem(opts, change.value); - const currentItem = getCurrentItem(opts, change.value); +function increaseItemDepth(opts: Options, editor: Editor): Editor { + const previousItem = getPreviousItem(opts, editor.value); + const currentItem = getCurrentItem(opts, editor.value); if (!previousItem) { - return change; + return editor; } if (!currentItem) { - return change; + return editor; } // Move the item in the sublist of previous item - return moveAsSubItem(opts, change, currentItem, previousItem.key); + return moveAsSubItem(opts, editor, currentItem, previousItem.key); } /** @@ -36,13 +37,13 @@ function increaseItemDepth(opts: Options, change: Change): Change { */ function moveAsSubItem( opts: Options, - change: Change, + editor: Editor, // The list item to add item: Block, // The key of the destination node destKey: string -): Change { - const destination = change.value.document.getDescendant(destKey); +): Editor { + const destination = editor.value.document.getDescendant(destKey); const lastIndex = destination.nodes.size; const lastChild = destination.nodes.last(); @@ -50,13 +51,13 @@ function moveAsSubItem( const existingList = isList(opts, lastChild) ? lastChild : null; if (existingList) { - return change.moveNodeByKey( + return editor.moveNodeByKey( item.key, existingList.key, existingList.nodes.size // as last item ); } - const currentList = getListForItem(opts, change.value, destination); + const currentList = getListForItem(opts, editor.value, destination); if (!currentList) { throw new Error('Destination is not in a list'); } @@ -67,10 +68,10 @@ function moveAsSubItem( data: currentList.data }); - return change.withoutNormalizing(() => { - change.insertNodeByKey(destKey, lastIndex, newSublist); - change.moveNodeByKey(item.key, newSublist.key, 0); - }); + // return editor.withoutNormalizing(() => { + editor.insertNodeByKey(destKey, lastIndex, newSublist); + editor.moveNodeByKey(item.key, newSublist.key, 0); + // }); } export default increaseItemDepth; diff --git a/lib/changes/splitListItem.js b/lib/changes/splitListItem.js index 14b7f241..a6f7312e 100644 --- a/lib/changes/splitListItem.js +++ b/lib/changes/splitListItem.js @@ -1,5 +1,5 @@ // @flow -import { type Change } from 'slate'; +import { Editor } from 'slate-react'; import type Options from '../options'; import { getCurrentItem } from '../utils'; @@ -7,17 +7,17 @@ import { getCurrentItem } from '../utils'; /** * Split a list item at the start of the current range. */ -function splitListItem(opts: Options, change: Change): Change { - const { value } = change; +function splitListItem(opts: Options, editor: Editor): Editor { + const { value } = editor; const currentItem = getCurrentItem(opts, value); if (!currentItem) { - return change; + return editor; } const { start } = value.selection; const splitOffset = start.offset; - return change.splitDescendantsByKey( + return editor.splitDescendantsByKey( currentItem.key, start.key, splitOffset diff --git a/lib/changes/unwrapList.js b/lib/changes/unwrapList.js index 02942470..957b7b8f 100644 --- a/lib/changes/unwrapList.js +++ b/lib/changes/unwrapList.js @@ -1,5 +1,5 @@ // @flow -import { type Change } from 'slate'; +import { Editor } from 'slate-react'; import type Options from '../options'; import { getItemsAtRange } from '../utils'; @@ -7,35 +7,35 @@ import { getItemsAtRange } from '../utils'; /** * Unwrap items at range from their list. */ -function unwrapList(opts: Options, change: Change): Change { - const items = getItemsAtRange(opts, change.value); +function unwrapList(opts: Options, editor: Editor): Editor { + const items = getItemsAtRange(opts, editor.value); if (items.isEmpty()) { - return change; + return editor; } - return change.withoutNormalizing(() => { + return editor.withoutNormalizing(() => { // Unwrap the items from their list - items.forEach(item => change.unwrapNodeByKey(item.key)); + items.forEach(item => editor.unwrapNodeByKey(item.key)); // Parent of the list of the items const firstItem = items.first(); - const parent = change.value.document.getParent(firstItem.key); + const parent = editor.value.document.getParent(firstItem.key); let index = parent.nodes.findIndex(node => node.key === firstItem.key); // Unwrap the items' children items.forEach(item => item.nodes.forEach(node => { - change.moveNodeByKey(node.key, parent.key, index); + editor.moveNodeByKey(node.key, parent.key, index); index += 1; }) ); // Finally, remove the now empty items - items.forEach(item => change.removeNodeByKey(item.key)); + items.forEach(item => editor.removeNodeByKey(item.key)); - return change; + return editor; }); } diff --git a/lib/changes/wrapInList.js b/lib/changes/wrapInList.js index ebc1dbac..053336b2 100644 --- a/lib/changes/wrapInList.js +++ b/lib/changes/wrapInList.js @@ -1,5 +1,6 @@ // @flow -import { Data, type Value, type Change, type Block } from 'slate'; +import { Data, type Value, type Block } from 'slate'; +import { Editor } from 'slate-react'; import { List } from 'immutable'; import type Options from '../options'; @@ -11,16 +12,16 @@ import { isList } from '../utils'; */ function wrapInList( opts: Options, - change: Change, + editor: Editor, type?: string, data?: Object | Data -): Change { - const selectedBlocks = getHighestSelectedBlocks(change.value); +): Editor { + const selectedBlocks = getHighestSelectedBlocks(editor.value); type = type || opts.types[0]; - change.withoutNormalizing(() => { + editor.withoutNormalizing(() => { // Wrap in container - change.wrapBlock({ + editor.wrapBlock({ type, data: Data.create(data) }); @@ -29,14 +30,14 @@ function wrapInList( selectedBlocks.forEach(node => { if (isList(opts, node)) { // Merge its items with the created list - node.nodes.forEach(({ key }) => change.unwrapNodeByKey(key)); + node.nodes.forEach(({ key }) => editor.unwrapNodeByKey(key)); } else { - change.wrapBlockByKey(node.key, opts.typeItem); + editor.wrapBlockByKey(node.key, opts.typeItem); } }); }); - return change.normalize(); + return editor.normalize(); } /** diff --git a/lib/handlers/onBackspace.js b/lib/handlers/onBackspace.js index 26c4f8a7..55c9a270 100644 --- a/lib/handlers/onBackspace.js +++ b/lib/handlers/onBackspace.js @@ -1,6 +1,4 @@ // @flow -import { type Change } from 'slate'; - import type Options from '../options'; import { unwrapList } from '../changes'; import { getCurrentItem } from '../utils'; @@ -10,36 +8,36 @@ import { getCurrentItem } from '../utils'; */ function onBackspace( event: *, - change: Change, editor: *, + next: *, opts: Options ): void | any { - const { value } = change; + const { value } = editor; const { selection } = value; const { start, isCollapsed, isExpanded } = selection; // Only unwrap... // ... with a collapsed selection if (isExpanded) { - return undefined; + return next(); } // ... when at the beginning of nodes if (start.offset > 0) { - return undefined; + return next(); } // ... in a list const currentItem = getCurrentItem(opts, value); if (!currentItem) { - return undefined; + return next(); } // ... more precisely at the beginning of the current item if (!isCollapsed || !start.isAtStartOfNode(currentItem)) { - return undefined; + return next(); } event.preventDefault(); - return unwrapList(opts, change); + return unwrapList(opts, editor); } export default onBackspace; diff --git a/lib/handlers/onEnter.js b/lib/handlers/onEnter.js index 8ed5e28f..d9341bbf 100644 --- a/lib/handlers/onEnter.js +++ b/lib/handlers/onEnter.js @@ -1,6 +1,4 @@ // @flow -import { type Change } from 'slate'; - import type Options from '../options'; import { unwrapList, splitListItem, decreaseItemDepth } from '../changes'; import { getCurrentItem, getItemDepth } from '../utils'; @@ -14,41 +12,41 @@ import { getCurrentItem, getItemDepth } from '../utils'; */ function onEnter( event: *, - change: Change, editor: *, + next: *, opts: Options ): void | any { // Pressing Shift+Enter // should split block normally if (event.shiftKey) { - return undefined; + return next(); } - const { value } = change; + const { value } = editor; const currentItem = getCurrentItem(opts, value); // Not in a list if (!currentItem) { - return undefined; + return next(); } event.preventDefault(); // If expanded, delete first. if (value.selection.isExpanded) { - change.delete(); + editor.delete(); } - if (!value.schema.isVoid(currentItem) && currentItem.text === '') { + if (!editor.isVoid(currentItem) && currentItem.text === '') { // Block is empty, we exit the list if (getItemDepth(opts, value) > 1) { - return decreaseItemDepth(opts, change); + return decreaseItemDepth(opts, editor); } // Exit list - return unwrapList(opts, change); + return unwrapList(opts, editor); } // Split list item - return splitListItem(opts, change); + return splitListItem(opts, editor); } export default onEnter; diff --git a/lib/handlers/onTab.js b/lib/handlers/onTab.js index 4e2c3246..b4399d8a 100644 --- a/lib/handlers/onTab.js +++ b/lib/handlers/onTab.js @@ -1,6 +1,4 @@ // @flow -import { type Change } from 'slate'; - import type Options from '../options'; import { decreaseItemDepth, increaseItemDepth } from '../changes'; import { getCurrentItem } from '../utils'; @@ -10,23 +8,23 @@ import { getCurrentItem } from '../utils'; * Tab -> Increase item depth if inside a list item * Shift+Tab -> Decrease item depth if inside a list item */ -function onTab(event: *, change: Change, editor: *, opts: Options): void | any { - const { value } = change; +function onTab(event: *, editor: *, next: *, opts: Options): void | any { + const { value } = editor; const { isCollapsed } = value.selection; if (!isCollapsed || !getCurrentItem(opts, value)) { - return undefined; + return next(); } event.preventDefault(); // Shift+tab reduce depth if (event.shiftKey) { - return decreaseItemDepth(opts, change); + return decreaseItemDepth(opts, editor); } // Tab increases depth - return increaseItemDepth(opts, change); + return increaseItemDepth(opts, editor); } export default onTab; diff --git a/lib/index.js b/lib/index.js index 74573815..0afa43e6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,8 +26,8 @@ function EditList( /** * User is pressing a key in the editor */ -function onKeyDown(opts: Options, event, change, editor: *): void | any { - const args = [event, change, editor, opts]; +function onKeyDown(opts: Options, event, editor: *, next): void | any { + const args = [event, editor, next, opts]; switch (event.key) { case KEY_ENTER: @@ -37,7 +37,7 @@ function onKeyDown(opts: Options, event, change, editor: *): void | any { case KEY_BACKSPACE: return onBackspace(...args); default: - return undefined; + return next(); } } diff --git a/lib/validation/index.js b/lib/validation/index.js index 2ef8f612..b1aca029 100644 --- a/lib/validation/index.js +++ b/lib/validation/index.js @@ -1,4 +1,5 @@ import schema from './schema'; import normalizeNode from './normalizeNode'; +console.log({ schema, normalizeNode }); export { schema, normalizeNode }; diff --git a/lib/validation/normalizeNode.js b/lib/validation/normalizeNode.js index 8e35ade1..3fda3583 100644 --- a/lib/validation/normalizeNode.js +++ b/lib/validation/normalizeNode.js @@ -1,31 +1,35 @@ // @flow -import { type Change, type Node } from 'slate'; +import { type Node } from 'slate'; +import { Editor } from 'slate-react'; import { isList } from '../utils'; import type Options from '../options'; -type Normalizer = Change => any; +type Normalizer = Editor => any; /** * Create a schema definition with rules to normalize lists */ function normalizeNode(opts: Options): Node => void | Normalizer { - return node => joinAdjacentLists(opts, node); + return (node, next) => { + console.log('normalizeNode', node, next); + next(); + } } /** * A rule that joins adjacent lists of the same type */ -function joinAdjacentLists(opts: Options, node: Node): void | Normalizer { +function joinAdjacentLists(opts: Options, node: Node, next): void | Normalizer { if (node.object !== 'document' && node.object !== 'block') { - return undefined; + return next(); } const invalids = node.nodes .map((child, i) => { if (!isList(opts, child)) return null; - const next = node.nodes.get(i + 1); - if (!next || !isList(opts, next) || !opts.canMerge(child, next)) { + const nextNode = node.nodes.get(i + 1); + if (!nextNode || !isList(opts, nextNode) || !opts.canMerge(child, nextNode)) { return null; } @@ -34,7 +38,7 @@ function joinAdjacentLists(opts: Options, node: Node): void | Normalizer { .filter(Boolean); if (invalids.isEmpty()) { - return undefined; + return next(); } /** diff --git a/lib/validation/schema.js b/lib/validation/schema.js index 68cd2b78..9f102e54 100644 --- a/lib/validation/schema.js +++ b/lib/validation/schema.js @@ -1,12 +1,14 @@ // @flow -import { type Change, type Node } from 'slate'; +import { type Node } from 'slate'; +import { Editor } from 'slate-react' import type Options from '../options'; /** * Create a schema definition with rules to normalize lists */ function schema(opts: Options): Object { + console.log('schema, ', opts); const constructedSchema = { blocks: { [opts.typeItem]: { @@ -14,12 +16,12 @@ function schema(opts: Options): Object { nodes: [{ match: { object: 'block' } }], normalize: normalize({ - parent_type_invalid: (change, context) => - change.unwrapBlockByKey(context.node.key, { + parent_type_invalid: (editor, context) => + editor.unwrapBlockByKey(context.node.key, { normalize: false }), - child_object_invalid: (change, context) => - wrapChildrenInDefaultBlock(opts, change, context.node) + child_object_invalid: (editor, context) => + wrapChildrenInDefaultBlock(opts, editor, context.node) }) } } @@ -30,52 +32,53 @@ function schema(opts: Options): Object { constructedSchema.blocks[type] = { nodes: [{ match: { type: opts.typeItem } }], normalize: normalize({ - child_type_invalid: (change, context) => - change.wrapBlockByKey(context.child.key, opts.typeItem, { + child_type_invalid: (editor, context) => + editor.wrapBlockByKey(context.child.key, opts.typeItem, { normalize: false }) }) }; }); + console.log(constructedSchema); return constructedSchema; } /* * Allows to define a normalize function through a keyed collection of functions */ -function normalize(reasons: { [string]: (Change, context: any) => any }): * { - return (change, error) => { +function normalize(reasons: { [string]: (Editor, context: any) => any }): * { + return (editor, error) => { const reasonFn = reasons[error.code]; if (reasonFn) { - reasonFn(change, error); + reasonFn(editor, error); } }; } /** * Wraps all child of a node in the default block type. - * Returns a change, for chaining purposes + * Returns a editor, for chaining purposes */ function wrapChildrenInDefaultBlock( opts: Options, - change: Change, + editor: Editor, node: Node -): Change { - change.wrapBlockByKey(node.nodes.first().key, opts.typeDefault, { +): Editor { + editor.wrapBlockByKey(node.nodes.first().key, opts.typeDefault, { normalize: false }); - const wrapper = change.value.document.getDescendant(node.key).nodes.first(); + const wrapper = editor.value.document.getDescendant(node.key).nodes.first(); // Add in the remaining items node.nodes.rest().forEach((child, index) => - change.moveNodeByKey(child.key, wrapper.key, index + 1, { + editor.moveNodeByKey(child.key, wrapper.key, index + 1, { normalize: false }) ); - return change; + return editor; } export default schema; diff --git a/package.json b/package.json index de72872e..73d44c75 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "main": "./dist/index.js", "peerDependencies": { "immutable": "^3.8.2", - "slate": "^0.32.0" + "slate": "^0.44.0" }, "files": [ "dist", @@ -44,10 +44,10 @@ "prettier": "^1.13.3", "react": "^16.0.0", "react-dom": "^16.0.0", - "slate": "^0.41.1", + "slate": "^0.44.2", "slate-hyperprint": "^2.2.5", - "slate-hyperscript": "^0.10.6", - "slate-react": "^0.18.9", + "slate-hyperscript": "^0.11.21", + "slate-react": "^0.21.12", "stringify": "^5.1.0" }, "scripts": { diff --git a/tests/backspace-end-of-inline/change.js b/tests/backspace-end-of-inline/change.js index 9eb67bd8..26c2554c 100644 --- a/tests/backspace-end-of-inline/change.js +++ b/tests/backspace-end-of-inline/change.js @@ -6,7 +6,7 @@ export default function(plugin, change) { key: 'Backspace' }, change, - {} + () => {} ); return change; diff --git a/yarn.lock b/yarn.lock index 860dabb8..697ac926 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1935,9 +1935,9 @@ debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9: ms "2.0.0" debug@^3.1.0: - version "3.2.5" - resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.5.tgz#c2418fbfd7a29f4d4f70ff4cea604d4b64c46407" - integrity sha512-D61LaDQPQkxJ5AUM2mbSJRbPkNs/TmdmOeLAi1hgDkpDfIfetSrjmWhccwtuResSwMbACjx/xXQofvM9CE/aeg== + version "3.2.6" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" + integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== dependencies: ms "^2.1.1" @@ -3352,10 +3352,10 @@ is-glob@^4.0.0: dependencies: is-extglob "^2.1.1" -is-hotkey@^0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/is-hotkey/-/is-hotkey-0.1.3.tgz#8a129eec16f3941bd4f37191e02b9c3e91950549" - integrity sha512-wB5PP/lwpaN5zNT1vjHxYFBxiq5zvUZiv8696eB5OmeCRCgNIzb3cMJjRhogSQXe8LLDKOzzlFfGlMaWnc4emQ== +is-hotkey@0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/is-hotkey/-/is-hotkey-0.1.4.tgz#c34d2c85d6ec8d09a871dcf71931c8067a824c7d" + integrity sha512-Py+aW4r5mBBY18TGzGz286/gKS+fCQ0Hee3qkaiSmEPiD0PqFpe0wuA3l7rTOUKyeXl8Mxf3XzJxIoTlSv+kxA== is-in-browser@^1.1.3: version "1.1.3" @@ -3815,9 +3815,9 @@ mem@^4.0.0: p-is-promise "^1.1.0" memoize-one@^4.0.0: - version "4.0.2" - resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.0.2.tgz#3fb8db695aa14ab9c0f1644e1585a8806adc1aee" - integrity sha512-ucx2DmXTeZTsS4GPPUZCbULAN7kdPT1G+H49Y34JjbQ5ESc6OGhVxKvb1iKhr9v19ZB9OtnHwNnhUnNR/7Wteg== + version "4.0.3" + resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.0.3.tgz#cdfdd942853f1a1b4c71c5336b8c49da0bf0273c" + integrity sha512-QmpUu4KqDmX0plH4u+tf0riMc1KHE1+lw95cMrLlXQAFOx/xnBtwhZ52XJxd9X2O6kwKBqX32kmhbhlobD0cuw== meow@^5.0.0: version "5.0.0" @@ -5081,10 +5081,10 @@ slash@^1.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU= -slate-base64-serializer@^0.2.67: - version "0.2.67" - resolved "https://registry.yarnpkg.com/slate-base64-serializer/-/slate-base64-serializer-0.2.67.tgz#7f79a2209e1fdc62f8a9099767ace2a19ad2af7c" - integrity sha512-sZAzS07Cn1VRo4448SJpSU9WhRqOJnAV1JbJdghBhnjLU+IXQAgZTgXPwlp/jIa6jcW9wr4bLZ/uqTPiuOzzDA== +slate-base64-serializer@^0.2.91: + version "0.2.91" + resolved "https://registry.yarnpkg.com/slate-base64-serializer/-/slate-base64-serializer-0.2.91.tgz#d66fe202288dedc6cf0189f20c36fce695d54580" + integrity sha512-kZIklWhDurFmFEWJjIao0rg3d+oDLhMqENne57lpYcKCM/DWAVK8Ohx9KlaamX87hEr6moUtkqbJ9PyTFXoZlg== dependencies: isomorphic-base64 "^1.0.2" @@ -5095,17 +5095,12 @@ slate-dev-environment@^0.2.0: dependencies: is-in-browser "^1.1.3" -slate-dev-warning@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/slate-dev-warning/-/slate-dev-warning-0.0.1.tgz#f6c36731babea5e301b5bd504fe64911dd24200a" - integrity sha512-QdXa+qmOG46VrTfnzn2gUVzs1WiO3Q+zCv3XomzMNGdgAJjCgHBs3jaeQD845h15loS3OJ181gCNAkB3dby6Hw== - -slate-hotkeys@^0.2.5: - version "0.2.5" - resolved "https://registry.yarnpkg.com/slate-hotkeys/-/slate-hotkeys-0.2.5.tgz#5e78e535f1305cea2664c0e56a082e9f4919bbc4" - integrity sha512-b1KnfQTcw6HwgKNUQCdxl1SUu6Sm26DaAqYjxM+ftd/6sUSmDN0YTdMfK+UbNND7WRCkN2Acqq36zQJfEczekg== +slate-hotkeys@^0.2.7: + version "0.2.7" + resolved "https://registry.yarnpkg.com/slate-hotkeys/-/slate-hotkeys-0.2.7.tgz#a5b613ced4af931b2d74a206f985ee2c63f3b0f9" + integrity sha512-k6iaR24w15CSM24jbi6My4WD2ePw4Byn8x3ARz3UtKrfSEO4F8Er/aPxegLhBujNE9u041uBMGeua44rlhemkw== dependencies: - is-hotkey "^0.1.3" + is-hotkey "0.1.4" slate-dev-environment "^0.2.0" slate-hyperprint@^2.2.5: @@ -5120,27 +5115,32 @@ slate-hyperprint@^2.2.5: prettier "1.13.6" stringify-object "^3.2.2" -slate-hyperscript@^0.10.6: - version "0.10.6" - resolved "https://registry.yarnpkg.com/slate-hyperscript/-/slate-hyperscript-0.10.6.tgz#79f50c1694593c03246755e961097f2fdb217b9b" - integrity sha512-PAxjPAd54A9U6bi1f53HGfRshESROVtATwubOOy12JEHoD4HrqHAoH5W0jOWOk82sruu/q10boSPuqv3hoYwbw== +slate-hyperscript@^0.11.21: + version "0.11.21" + resolved "https://registry.yarnpkg.com/slate-hyperscript/-/slate-hyperscript-0.11.21.tgz#ce960ab17daef81cb6d243426dc06566ac6907e9" + integrity sha512-dgh1lXygL7CJKW+JeQEMPhwfsItLRW7rV4IKWfyP9nh/bE8U3yp7EssZKaOpKuZ6Q0+L2Z68SQcNWwUYxmLYwg== dependencies: is-plain-object "^2.0.4" -slate-plain-serializer@^0.6.6: - version "0.6.6" - resolved "https://registry.yarnpkg.com/slate-plain-serializer/-/slate-plain-serializer-0.6.6.tgz#c869135c47811d8d8daae1b0badbda99504d579e" - integrity sha512-DyTVsoRxMh4fql2AOkU20WpQDdR1Tv7jlkU5ko/i8jUzapkWcav1fqusA89wlSa2arywoNIV1CwXArrgcmHB6g== +slate-plain-serializer@^0.6.30: + version "0.6.30" + resolved "https://registry.yarnpkg.com/slate-plain-serializer/-/slate-plain-serializer-0.6.30.tgz#2a18aac879988eacf7ef370d735c1aff2d70131b" + integrity sha512-+Zz2VaYhshXztavHXYKfA7MT/w4sQHxe9X3a9uTqP/N5nIHswln82UdGZSDXPtI7XnBbU/depxhQPTPhUxOE8Q== + +slate-prop-types@^0.5.21: + version "0.5.21" + resolved "https://registry.yarnpkg.com/slate-prop-types/-/slate-prop-types-0.5.21.tgz#996e0b2a219d7c7da0e127f6d31b2fb19b688ae7" + integrity sha512-fYp+12rofb4sp3/V0l5w9ji9M4f+UbtbyIIDWcfKjFMjmBh6ViksbG3gB334bErS79rwtq0LzNF5sVSUuP5kgg== -slate-prop-types@^0.4.65: - version "0.4.65" - resolved "https://registry.yarnpkg.com/slate-prop-types/-/slate-prop-types-0.4.65.tgz#0b728417246b049ab8a381ccdd5ff8379b0f7d77" - integrity sha512-QpoQkSKdh6yWvL2KqN+ky6KT+ng0jLR7PWi5O/x7A3LpomVnHlZeYPEpLhNOOjoAjBA1Dcnbaz/lw2Avi6MUhA== +slate-react-placeholder@^0.1.9: + version "0.1.9" + resolved "https://registry.yarnpkg.com/slate-react-placeholder/-/slate-react-placeholder-0.1.9.tgz#683aaa4542c91b55552c51e4649d76ca778e14fb" + integrity sha512-Y4AB8QG0PK7jsCAkFfh4jX7+qLR2VIs5JbVuqorRPUcbA6iQk/gm0CylaUEEFCVEf6JiCd6yAwjRm38xSQQsmw== -slate-react@^0.18.9: - version "0.18.9" - resolved "https://registry.yarnpkg.com/slate-react/-/slate-react-0.18.9.tgz#ab6de2b2e2db0ab38452e9ec5dc2f269f1d113df" - integrity sha512-zRstNh475LVtLBDoKndlcQ2F8szNLwhsCDBQGhawYgHSaiASNFK0nlDjpa8E0l5w9c8w2NzIohhV8fWFTlbqaA== +slate-react@^0.21.12: + version "0.21.12" + resolved "https://registry.yarnpkg.com/slate-react/-/slate-react-0.21.12.tgz#e3bee253324167ebb5185a6587c5450558575c23" + integrity sha512-eTdHQrAUKt2ep/HjuWn1cCEzs16xJw0owHdku76PVoezaxHpOGxRTBVppjQzy57eAOIngdo0LkdiT4c9BpO19A== dependencies: debug "^3.1.0" get-window "^1.1.1" @@ -5150,24 +5150,27 @@ slate-react@^0.18.9: prop-types "^15.5.8" react-immutable-proptypes "^2.1.0" selection-is-backward "^1.0.0" - slate-base64-serializer "^0.2.67" + slate-base64-serializer "^0.2.91" slate-dev-environment "^0.2.0" - slate-dev-warning "^0.0.1" - slate-hotkeys "^0.2.5" - slate-plain-serializer "^0.6.6" - slate-prop-types "^0.4.65" - -slate@^0.41.1: - version "0.41.1" - resolved "https://registry.yarnpkg.com/slate/-/slate-0.41.1.tgz#2b10ccb71a23432161bc326fc8e37d14c36b5605" - integrity sha512-JIkf8RIXe08PsPzZhujcZIfKSrmbgheOjImAZ40uN+uBWZm6lYpOl/HgKm/dja01knx+PCnPkLSSFmJ4Ogrz0Q== + slate-hotkeys "^0.2.7" + slate-plain-serializer "^0.6.30" + slate-prop-types "^0.5.21" + slate-react-placeholder "^0.1.9" + tiny-invariant "^1.0.1" + tiny-warning "^0.0.3" + +slate@^0.44.2: + version "0.44.6" + resolved "https://registry.yarnpkg.com/slate/-/slate-0.44.6.tgz#47ab3127641bc1faa3e5a5b01bfab8861843c82e" + integrity sha512-Q5DASlX7tUXrAaQFb5AliZjAeuXkI1oVq3HM8A/mb4qClwpSpuKq/uOcA3855bFzAOXSjUM/kESK3M3oiIHnNA== dependencies: debug "^3.1.0" direction "^0.1.5" esrever "^0.2.0" is-plain-object "^2.0.4" lodash "^4.17.4" - slate-dev-warning "^0.0.1" + tiny-invariant "^1.0.1" + tiny-warning "^0.0.3" type-of "^2.0.1" slice-ansi@1.0.0: @@ -5508,6 +5511,16 @@ timers-browserify@^1.0.1: dependencies: process "~0.11.0" +tiny-invariant@^1.0.1: + version "1.0.3" + resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.0.3.tgz#91efaaa0269ccb6271f0296aeedb05fc3e067b7a" + integrity sha512-ytQx8T4DL8PjlX53yYzcIC0WhIZbpR0p1qcYjw2pHu3w6UtgWwFJQ/02cnhOnBBhlFx/edUIfcagCaQSe3KMWg== + +tiny-warning@^0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-0.0.3.tgz#1807eb4c5f81784a6354d58ea1d5024f18c6c81f" + integrity sha512-r0SSA5Y5IWERF9Xh++tFPx0jITBgGggOsRLDWWew6YRw/C2dr4uNO1fw1vanrBmHsICmPyMLNBZboTlxUmUuaA== + tmp@^0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" From 1411bb0001f70f9498770ef62adf9767d9284d93 Mon Sep 17 00:00:00 2001 From: Cary Dunn Date: Tue, 13 Nov 2018 10:18:23 -0800 Subject: [PATCH 2/5] wip --- lib/changes/increaseItemDepth.js | 8 ++--- lib/validation/index.js | 1 - lib/validation/normalizeNode.js | 7 ++--- lib/validation/schema.js | 2 -- tests/all.js | 31 +++++++++---------- .../backspace-empty-between-inline/change.js | 2 +- .../change.js | 2 +- tests/increase-item-depth-fifth/change.js | 2 +- tests/shift-enter-middle-item/change.js | 2 +- tests/split-item-start/change.js | 2 +- .../change.js | 2 +- .../change.js | 2 +- tests/undo-split-item-sublist-deep/change.js | 2 +- tests/undo-unwrap-long-list/change.js | 2 +- tests/undo-wrap-in-list/change.js | 2 +- tests/unwrap-list-multiple-nested/change.js | 2 +- tests/unwrap-list-multiple/change.js | 2 +- tests/unwrap-list/change.js | 2 +- tests/unwrap-long-list/change.js | 2 +- tests/unwrap-nested-list/change.js | 2 +- tests/wrap-in-list-list-with-data/change.js | 2 +- tests/wrap-in-list-list/change.js | 2 +- .../wrap-in-list-multiple-with-data/change.js | 2 +- tests/wrap-in-list-multiple/change.js | 2 +- tests/wrap-in-list-with-data/change.js | 2 +- tests/wrap-in-list/change.js | 2 +- tests/wrap-in-ol/change.js | 2 +- 27 files changed, 44 insertions(+), 49 deletions(-) diff --git a/lib/changes/increaseItemDepth.js b/lib/changes/increaseItemDepth.js index a6ac422e..12bb7715 100644 --- a/lib/changes/increaseItemDepth.js +++ b/lib/changes/increaseItemDepth.js @@ -68,10 +68,10 @@ function moveAsSubItem( data: currentList.data }); - // return editor.withoutNormalizing(() => { - editor.insertNodeByKey(destKey, lastIndex, newSublist); - editor.moveNodeByKey(item.key, newSublist.key, 0); - // }); + return editor.withoutNormalizing(() => { + editor.insertNodeByKey(destKey, lastIndex, newSublist); + editor.moveNodeByKey(item.key, newSublist.key, 0); + }); } export default increaseItemDepth; diff --git a/lib/validation/index.js b/lib/validation/index.js index b1aca029..2ef8f612 100644 --- a/lib/validation/index.js +++ b/lib/validation/index.js @@ -1,5 +1,4 @@ import schema from './schema'; import normalizeNode from './normalizeNode'; -console.log({ schema, normalizeNode }); export { schema, normalizeNode }; diff --git a/lib/validation/normalizeNode.js b/lib/validation/normalizeNode.js index 3fda3583..b5b18ec3 100644 --- a/lib/validation/normalizeNode.js +++ b/lib/validation/normalizeNode.js @@ -11,9 +11,8 @@ type Normalizer = Editor => any; * Create a schema definition with rules to normalize lists */ function normalizeNode(opts: Options): Node => void | Normalizer { - return (node, next) => { - console.log('normalizeNode', node, next); - next(); + return (node, editor, next) => { + return joinAdjacentLists(opts, node, next); } } @@ -33,7 +32,7 @@ function joinAdjacentLists(opts: Options, node: Node, next): void | Normalizer { return null; } - return [child, next]; + return [child, nextNode]; }) .filter(Boolean); diff --git a/lib/validation/schema.js b/lib/validation/schema.js index 9f102e54..402d176e 100644 --- a/lib/validation/schema.js +++ b/lib/validation/schema.js @@ -8,7 +8,6 @@ import type Options from '../options'; * Create a schema definition with rules to normalize lists */ function schema(opts: Options): Object { - console.log('schema, ', opts); const constructedSchema = { blocks: { [opts.typeItem]: { @@ -40,7 +39,6 @@ function schema(opts: Options): Object { }; }); - console.log(constructedSchema); return constructedSchema; } diff --git a/tests/all.js b/tests/all.js index 3d4e0f3b..c7721d61 100644 --- a/tests/all.js +++ b/tests/all.js @@ -10,18 +10,15 @@ import EditList from '../lib'; // Provide the value with function deserializeValue(plugin, value) { - const SCHEMA = Slate.Schema.create({ - plugins: [plugin] - }); - - return Slate.Value.fromJSON( + return new Slate.Editor({ + plugins: [plugin], + value: Slate.Value.fromJSON( { - selection: value.selection, - document: value.document, - schema: SCHEMA - }, - { normalize: false } - ); + selection: value.selection, + document: value.document, + } + ) + }); } describe('slate-edit-list', () => { @@ -38,20 +35,22 @@ describe('slate-edit-list', () => { require(path.resolve(dir, 'input.js')).default ); + // console.log('input', input); + const expectedPath = path.resolve(dir, 'expected.js'); const expected = fs.existsSync(expectedPath) && deserializeValue(plugin, require(expectedPath).default); const runChange = require(path.resolve(dir, 'change.js')).default; + // console.log('runChange', runChange); - const newChange = runChange(plugin, input.change()); - + const newChange = runChange(plugin, input); if (expected) { - const actual = newChange.value; + const actual = newChange.value.document; - expect(hyperprint(actual, { strict: true })).toEqual( - hyperprint(expected, { strict: true }) + expect(hyperprint(actual, { strict: false })).toEqual( + hyperprint(expected.value.document, { strict: false }) ); } }); diff --git a/tests/backspace-empty-between-inline/change.js b/tests/backspace-empty-between-inline/change.js index c1000988..cdad46ea 100644 --- a/tests/backspace-empty-between-inline/change.js +++ b/tests/backspace-empty-between-inline/change.js @@ -8,7 +8,7 @@ export default function(plugin, change) { key: 'Backspace' }, change, - {} + () => {} ); // Selection check diff --git a/tests/decrease-item-depth-long-sublist/change.js b/tests/decrease-item-depth-long-sublist/change.js index 084435d6..34556304 100644 --- a/tests/decrease-item-depth-long-sublist/change.js +++ b/tests/decrease-item-depth-long-sublist/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.decreaseItemDepth); + return change.command(plugin.changes.decreaseItemDepth); } diff --git a/tests/increase-item-depth-fifth/change.js b/tests/increase-item-depth-fifth/change.js index 76e7ee29..d9cebc8c 100644 --- a/tests/increase-item-depth-fifth/change.js +++ b/tests/increase-item-depth-fifth/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.increaseItemDepth); + return change.command(plugin.changes.increaseItemDepth); } diff --git a/tests/shift-enter-middle-item/change.js b/tests/shift-enter-middle-item/change.js index 9522c30b..a4f038c1 100644 --- a/tests/shift-enter-middle-item/change.js +++ b/tests/shift-enter-middle-item/change.js @@ -9,7 +9,7 @@ export default function(plugin, change) { shiftKey: true }, change, - {} + () => {} ); expect(ret == null).toBe(true); diff --git a/tests/split-item-start/change.js b/tests/split-item-start/change.js index 42b5e327..17712665 100644 --- a/tests/split-item-start/change.js +++ b/tests/split-item-start/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.splitListItem); + return change.command(plugin.changes.splitListItem); } diff --git a/tests/undo-decrease-item-depth-long-sublist/change.js b/tests/undo-decrease-item-depth-long-sublist/change.js index 3ab91226..0114373c 100644 --- a/tests/undo-decrease-item-depth-long-sublist/change.js +++ b/tests/undo-decrease-item-depth-long-sublist/change.js @@ -1,7 +1,7 @@ import expect from 'expect'; export default function(plugin, change) { - change.call(plugin.changes.decreaseItemDepth).undo(); + change.command(plugin.changes.decreaseItemDepth).undo(); // Back to previous cursor position expect(change.value.startBlock.text).toEqual('Item 1.1'); diff --git a/tests/undo-increase-item-depth-complex/change.js b/tests/undo-increase-item-depth-complex/change.js index 122d8e35..02e371d0 100644 --- a/tests/undo-increase-item-depth-complex/change.js +++ b/tests/undo-increase-item-depth-complex/change.js @@ -4,7 +4,7 @@ export default function(plugin, change) { const initialText = change.value.startBlock.text; const initialSelection = change.value.selection; - change.call(plugin.changes.increaseItemDepth).undo(); + change.command(plugin.changes.increaseItemDepth).undo(); // Back to previous cursor position expect(change.value.startBlock.text).toEqual(initialText); diff --git a/tests/undo-split-item-sublist-deep/change.js b/tests/undo-split-item-sublist-deep/change.js index 245a0a04..b36c3312 100644 --- a/tests/undo-split-item-sublist-deep/change.js +++ b/tests/undo-split-item-sublist-deep/change.js @@ -4,7 +4,7 @@ export default function(plugin, change) { const initialText = change.value.startBlock.text; const initialSelection = change.value.selection; - change.call(plugin.changes.splitListItem).undo(); + change.command(plugin.changes.splitListItem).undo(); // Back to previous cursor position expect(change.value.startBlock.text).toEqual(initialText); diff --git a/tests/undo-unwrap-long-list/change.js b/tests/undo-unwrap-long-list/change.js index 75d37824..bb3224a0 100644 --- a/tests/undo-unwrap-long-list/change.js +++ b/tests/undo-unwrap-long-list/change.js @@ -4,7 +4,7 @@ export default function(plugin, change) { const initialText = change.value.startBlock.text; const initialSelection = change.value.selection; - change.call(plugin.changes.unwrapList).undo(); + change.command(plugin.changes.unwrapList).undo(); // Back to previous cursor position expect(change.value.startBlock.text).toEqual(initialText); diff --git a/tests/undo-wrap-in-list/change.js b/tests/undo-wrap-in-list/change.js index 96f02380..93412a1b 100644 --- a/tests/undo-wrap-in-list/change.js +++ b/tests/undo-wrap-in-list/change.js @@ -5,7 +5,7 @@ export default function(plugin, change) { const initialText = value.startBlock.text; const initialSelection = value.selection; - change.call(plugin.changes.wrapInList).undo(); + change.command(plugin.changes.wrapInList).undo(); // Back to previous cursor position expect(change.value.startBlock.text).toEqual(initialText); diff --git a/tests/unwrap-list-multiple-nested/change.js b/tests/unwrap-list-multiple-nested/change.js index d40ac01c..232ac1dc 100644 --- a/tests/unwrap-list-multiple-nested/change.js +++ b/tests/unwrap-list-multiple-nested/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.unwrapList); + return change.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-list-multiple/change.js b/tests/unwrap-list-multiple/change.js index d40ac01c..232ac1dc 100644 --- a/tests/unwrap-list-multiple/change.js +++ b/tests/unwrap-list-multiple/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.unwrapList); + return change.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-list/change.js b/tests/unwrap-list/change.js index d40ac01c..232ac1dc 100644 --- a/tests/unwrap-list/change.js +++ b/tests/unwrap-list/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.unwrapList); + return change.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-long-list/change.js b/tests/unwrap-long-list/change.js index d40ac01c..232ac1dc 100644 --- a/tests/unwrap-long-list/change.js +++ b/tests/unwrap-long-list/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.unwrapList); + return change.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-nested-list/change.js b/tests/unwrap-nested-list/change.js index d40ac01c..232ac1dc 100644 --- a/tests/unwrap-nested-list/change.js +++ b/tests/unwrap-nested-list/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.unwrapList); + return change.command(plugin.changes.unwrapList); } diff --git a/tests/wrap-in-list-list-with-data/change.js b/tests/wrap-in-list-list-with-data/change.js index e12f5a4d..3df265d4 100644 --- a/tests/wrap-in-list-list-with-data/change.js +++ b/tests/wrap-in-list-list-with-data/change.js @@ -1,4 +1,4 @@ export default function(plugin, change) { const data = { style: { listStyleType: 'disc' } }; - return change.call(plugin.changes.wrapInList, false, data); + return change.command(plugin.changes.wrapInList, false, data); } diff --git a/tests/wrap-in-list-list/change.js b/tests/wrap-in-list-list/change.js index 3251ba16..dd904845 100644 --- a/tests/wrap-in-list-list/change.js +++ b/tests/wrap-in-list-list/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.wrapInList); + return change.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-list-multiple-with-data/change.js b/tests/wrap-in-list-multiple-with-data/change.js index e12f5a4d..3df265d4 100644 --- a/tests/wrap-in-list-multiple-with-data/change.js +++ b/tests/wrap-in-list-multiple-with-data/change.js @@ -1,4 +1,4 @@ export default function(plugin, change) { const data = { style: { listStyleType: 'disc' } }; - return change.call(plugin.changes.wrapInList, false, data); + return change.command(plugin.changes.wrapInList, false, data); } diff --git a/tests/wrap-in-list-multiple/change.js b/tests/wrap-in-list-multiple/change.js index 3251ba16..dd904845 100644 --- a/tests/wrap-in-list-multiple/change.js +++ b/tests/wrap-in-list-multiple/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.wrapInList); + return change.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-list-with-data/change.js b/tests/wrap-in-list-with-data/change.js index 096c0a56..2ac175de 100644 --- a/tests/wrap-in-list-with-data/change.js +++ b/tests/wrap-in-list-with-data/change.js @@ -1,4 +1,4 @@ export default function(plugin, change) { const data = { style: { listStyleType: 'decimal' } }; - return change.call(plugin.changes.wrapInList, 'ol_list', data); + return change.command(plugin.changes.wrapInList, 'ol_list', data); } diff --git a/tests/wrap-in-list/change.js b/tests/wrap-in-list/change.js index 3251ba16..dd904845 100644 --- a/tests/wrap-in-list/change.js +++ b/tests/wrap-in-list/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.wrapInList); + return change.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-ol/change.js b/tests/wrap-in-ol/change.js index df914727..6e8f8a04 100644 --- a/tests/wrap-in-ol/change.js +++ b/tests/wrap-in-ol/change.js @@ -1,3 +1,3 @@ export default function(plugin, change) { - return change.call(plugin.changes.wrapInList, 'ol_list'); + return change.command(plugin.changes.wrapInList, 'ol_list'); } From 617c396c9c622095c2da1b98f79f8504384252b4 Mon Sep 17 00:00:00 2001 From: Cary Dunn Date: Tue, 13 Nov 2018 14:51:39 -0800 Subject: [PATCH 3/5] wip --- tests/all.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/all.js b/tests/all.js index c7721d61..db9fd97c 100644 --- a/tests/all.js +++ b/tests/all.js @@ -35,15 +35,12 @@ describe('slate-edit-list', () => { require(path.resolve(dir, 'input.js')).default ); - // console.log('input', input); - const expectedPath = path.resolve(dir, 'expected.js'); const expected = fs.existsSync(expectedPath) && deserializeValue(plugin, require(expectedPath).default); const runChange = require(path.resolve(dir, 'change.js')).default; - // console.log('runChange', runChange); const newChange = runChange(plugin, input); if (expected) { From 035487c7899adfb3092dd4e8f9c047435572555d Mon Sep 17 00:00:00 2001 From: Cary Dunn Date: Fri, 16 Nov 2018 14:41:50 -0800 Subject: [PATCH 4/5] minor type changes --- lib/changes/decreaseItemDepth.js | 2 +- lib/changes/increaseItemDepth.js | 2 +- lib/changes/splitListItem.js | 2 +- lib/changes/unwrapList.js | 2 +- lib/changes/wrapInList.js | 2 +- lib/validation/schema.js | 2 +- tests/backspace-empty-between-inline/change.js | 12 ++++++------ tests/backspace-end-of-inline/change.js | 6 +++--- tests/backspace-start-of-inline/change.js | 14 +++++++------- tests/backspace-start-of-item/change.js | 6 +++--- tests/decrease-item-depth-basic/change.js | 4 ++-- .../change.js | 4 ++-- tests/decrease-item-depth-long-sublist/change.js | 4 ++-- tests/enter-empty-block-in-item/change.js | 6 +++--- tests/enter-empty-item/change.js | 6 +++--- tests/enter-middle-item/change.js | 6 +++--- tests/enter-nested-item/change.js | 6 +++--- tests/get-current-item/change.js | 4 ++-- tests/get-previous-item/change.js | 4 ++-- .../increase-item-depth-basic-with-data/change.js | 4 ++-- tests/increase-item-depth-basic/change.js | 4 ++-- tests/increase-item-depth-complex/change.js | 4 ++-- .../increase-item-depth-existing-sublist/change.js | 4 ++-- tests/increase-item-depth-fifth/change.js | 4 ++-- tests/schema-items-are-list-children/change.js | 4 ++-- tests/schema-items-contain-blocks-2/change.js | 4 ++-- tests/schema-items-contain-blocks/change.js | 4 ++-- .../change.js | 4 ++-- tests/schema-join-adjacent-lists/change.js | 4 ++-- tests/schema-lists-contain-items/change.js | 4 ++-- tests/schema-nested-lists/change.js | 4 ++-- tests/schema-ul-ul-li-li/change.js | 4 ++-- tests/shift-enter-middle-item/change.js | 4 ++-- tests/split-item-end/change.js | 4 ++-- tests/split-item-offset-multiple-blocks/change.js | 4 ++-- tests/split-item-offset/change.js | 4 ++-- tests/split-item-start/change.js | 4 ++-- tests/split-item-sublist-deep/change.js | 12 ++++++------ tests/split-item-sublist/change.js | 4 ++-- .../change.js | 8 ++++---- tests/undo-increase-item-depth-complex/change.js | 14 +++++++------- tests/undo-split-item-sublist-deep/change.js | 14 +++++++------- tests/undo-unwrap-long-list/change.js | 14 +++++++------- tests/undo-wrap-in-list/change.js | 12 ++++++------ tests/unwrap-list-multiple-nested/change.js | 4 ++-- tests/unwrap-list-multiple/change.js | 4 ++-- tests/unwrap-list/change.js | 4 ++-- tests/unwrap-long-list/change.js | 4 ++-- tests/unwrap-nested-list/change.js | 4 ++-- tests/wrap-in-list-list-with-data/change.js | 4 ++-- tests/wrap-in-list-list/change.js | 4 ++-- tests/wrap-in-list-multiple-with-data/change.js | 4 ++-- tests/wrap-in-list-multiple/change.js | 4 ++-- tests/wrap-in-list-with-data/change.js | 4 ++-- tests/wrap-in-list/change.js | 4 ++-- tests/wrap-in-ol/change.js | 4 ++-- 56 files changed, 146 insertions(+), 146 deletions(-) diff --git a/lib/changes/decreaseItemDepth.js b/lib/changes/decreaseItemDepth.js index 73045362..e979162a 100644 --- a/lib/changes/decreaseItemDepth.js +++ b/lib/changes/decreaseItemDepth.js @@ -1,6 +1,6 @@ // @flow import { Block } from 'slate'; -import { Editor } from 'slate-react' +import { type Editor } from 'slate-react' import type Options from '../options'; import { getItemDepth, getCurrentItem } from '../utils'; diff --git a/lib/changes/increaseItemDepth.js b/lib/changes/increaseItemDepth.js index 12bb7715..c1221d2b 100644 --- a/lib/changes/increaseItemDepth.js +++ b/lib/changes/increaseItemDepth.js @@ -1,6 +1,6 @@ // @flow import { Block } from 'slate'; -import { Editor } from "slate-react"; +import { type Editor } from "slate-react"; import type Options from '../options'; import { diff --git a/lib/changes/splitListItem.js b/lib/changes/splitListItem.js index a6f7312e..30eebc2f 100644 --- a/lib/changes/splitListItem.js +++ b/lib/changes/splitListItem.js @@ -1,5 +1,5 @@ // @flow -import { Editor } from 'slate-react'; +import { type Editor } from 'slate-react'; import type Options from '../options'; import { getCurrentItem } from '../utils'; diff --git a/lib/changes/unwrapList.js b/lib/changes/unwrapList.js index 957b7b8f..bd86e27c 100644 --- a/lib/changes/unwrapList.js +++ b/lib/changes/unwrapList.js @@ -1,5 +1,5 @@ // @flow -import { Editor } from 'slate-react'; +import { type Editor } from 'slate-react'; import type Options from '../options'; import { getItemsAtRange } from '../utils'; diff --git a/lib/changes/wrapInList.js b/lib/changes/wrapInList.js index 053336b2..4df170d6 100644 --- a/lib/changes/wrapInList.js +++ b/lib/changes/wrapInList.js @@ -1,6 +1,6 @@ // @flow import { Data, type Value, type Block } from 'slate'; -import { Editor } from 'slate-react'; +import { type Editor } from 'slate-react'; import { List } from 'immutable'; import type Options from '../options'; diff --git a/lib/validation/schema.js b/lib/validation/schema.js index 402d176e..f691eaf8 100644 --- a/lib/validation/schema.js +++ b/lib/validation/schema.js @@ -1,7 +1,7 @@ // @flow import { type Node } from 'slate'; -import { Editor } from 'slate-react' +import { type Editor } from 'slate-react' import type Options from '../options'; /** diff --git a/tests/backspace-empty-between-inline/change.js b/tests/backspace-empty-between-inline/change.js index cdad46ea..e5ae3548 100644 --- a/tests/backspace-empty-between-inline/change.js +++ b/tests/backspace-empty-between-inline/change.js @@ -1,20 +1,20 @@ import expect from 'expect'; -export default function(plugin, change) { +export default function(plugin, editor) { plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Backspace' }, - change, + editor, () => {} ); // Selection check - expect(change.value.startBlock.text).toEqual(''); - expect(change.value.selection.anchor.offset).toEqual(0); - expect(change.value.selection.isCollapsed).toBe(true); + expect(editor.value.startBlock.text).toEqual(''); + expect(editor.value.selection.anchor.offset).toEqual(0); + expect(editor.value.selection.isCollapsed).toBe(true); - return change; + return editor; } diff --git a/tests/backspace-end-of-inline/change.js b/tests/backspace-end-of-inline/change.js index 26c2554c..a6716e69 100644 --- a/tests/backspace-end-of-inline/change.js +++ b/tests/backspace-end-of-inline/change.js @@ -1,13 +1,13 @@ -export default function(plugin, change) { +export default function(plugin, editor) { plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Backspace' }, - change, + editor, () => {} ); - return change; + return editor; } diff --git a/tests/backspace-start-of-inline/change.js b/tests/backspace-start-of-inline/change.js index d07632bd..787d1e1d 100644 --- a/tests/backspace-start-of-inline/change.js +++ b/tests/backspace-start-of-inline/change.js @@ -1,19 +1,19 @@ import expect from 'expect'; -export default function(plugin, change) { +export default function(plugin, editor) { plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Backspace' }, - change, - {} + editor, + () => {} ); // Selection check - expect(change.value.startBlock.text).toEqual('Second item'); - expect(change.value.selection.anchor.offset).toEqual(0); - expect(change.value.selection.isCollapsed).toBe(true); - return change; + expect(editor.value.startBlock.text).toEqual('Second item'); + expect(editor.value.selection.anchor.offset).toEqual(0); + expect(editor.value.selection.isCollapsed).toBe(true); + return editor; } diff --git a/tests/backspace-start-of-item/change.js b/tests/backspace-start-of-item/change.js index d7b2fecc..afb6a7d2 100644 --- a/tests/backspace-start-of-item/change.js +++ b/tests/backspace-start-of-item/change.js @@ -1,11 +1,11 @@ -export default function(plugin, change) { +export default function(plugin, editor) { return plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Backspace' }, - change, - {} + editor, + () => {} ); } diff --git a/tests/decrease-item-depth-basic/change.js b/tests/decrease-item-depth-basic/change.js index 3fc7f807..b89c8481 100644 --- a/tests/decrease-item-depth-basic/change.js +++ b/tests/decrease-item-depth-basic/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.decreaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.decreaseItemDepth(editor); } diff --git a/tests/decrease-item-depth-long-sublist-with-data/change.js b/tests/decrease-item-depth-long-sublist-with-data/change.js index 3fc7f807..b89c8481 100644 --- a/tests/decrease-item-depth-long-sublist-with-data/change.js +++ b/tests/decrease-item-depth-long-sublist-with-data/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.decreaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.decreaseItemDepth(editor); } diff --git a/tests/decrease-item-depth-long-sublist/change.js b/tests/decrease-item-depth-long-sublist/change.js index 34556304..dd3e516e 100644 --- a/tests/decrease-item-depth-long-sublist/change.js +++ b/tests/decrease-item-depth-long-sublist/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.decreaseItemDepth); +export default function(plugin, editor) { + return editor.command(plugin.changes.decreaseItemDepth); } diff --git a/tests/enter-empty-block-in-item/change.js b/tests/enter-empty-block-in-item/change.js index 727866a8..6f7b0d78 100644 --- a/tests/enter-empty-block-in-item/change.js +++ b/tests/enter-empty-block-in-item/change.js @@ -1,11 +1,11 @@ -export default function(plugin, change) { +export default function(plugin, editor) { return plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Enter' }, - change, - {} + editor, + () => {} ); } diff --git a/tests/enter-empty-item/change.js b/tests/enter-empty-item/change.js index 727866a8..6f7b0d78 100644 --- a/tests/enter-empty-item/change.js +++ b/tests/enter-empty-item/change.js @@ -1,11 +1,11 @@ -export default function(plugin, change) { +export default function(plugin, editor) { return plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Enter' }, - change, - {} + editor, + () => {} ); } diff --git a/tests/enter-middle-item/change.js b/tests/enter-middle-item/change.js index 727866a8..6f7b0d78 100644 --- a/tests/enter-middle-item/change.js +++ b/tests/enter-middle-item/change.js @@ -1,11 +1,11 @@ -export default function(plugin, change) { +export default function(plugin, editor) { return plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Enter' }, - change, - {} + editor, + () => {} ); } diff --git a/tests/enter-nested-item/change.js b/tests/enter-nested-item/change.js index 727866a8..6f7b0d78 100644 --- a/tests/enter-nested-item/change.js +++ b/tests/enter-nested-item/change.js @@ -1,11 +1,11 @@ -export default function(plugin, change) { +export default function(plugin, editor) { return plugin.onKeyDown( { preventDefault: () => {}, stopPropagation: () => {}, key: 'Enter' }, - change, - {} + editor, + () => {} ); } diff --git a/tests/get-current-item/change.js b/tests/get-current-item/change.js index fd1674b4..454140d8 100644 --- a/tests/get-current-item/change.js +++ b/tests/get-current-item/change.js @@ -1,6 +1,6 @@ import expect from 'expect'; -export default function(plugin, change) { - const currentItem = plugin.utils.getCurrentItem(change.value); +export default function(plugin, editor) { + const currentItem = plugin.utils.getCurrentItem(editor.value); expect(currentItem.key).toBe('current_item'); } diff --git a/tests/get-previous-item/change.js b/tests/get-previous-item/change.js index 2ec5e99f..423878f1 100644 --- a/tests/get-previous-item/change.js +++ b/tests/get-previous-item/change.js @@ -1,6 +1,6 @@ import expect from 'expect'; -export default function(plugin, change) { - const previousItem = plugin.utils.getPreviousItem(change.value); +export default function(plugin, editor) { + const previousItem = plugin.utils.getPreviousItem(editor.value); expect(previousItem.key).toBe('previous_item'); } diff --git a/tests/increase-item-depth-basic-with-data/change.js b/tests/increase-item-depth-basic-with-data/change.js index 39ae0673..2cd74827 100644 --- a/tests/increase-item-depth-basic-with-data/change.js +++ b/tests/increase-item-depth-basic-with-data/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.increaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.increaseItemDepth(editor); } diff --git a/tests/increase-item-depth-basic/change.js b/tests/increase-item-depth-basic/change.js index 39ae0673..2cd74827 100644 --- a/tests/increase-item-depth-basic/change.js +++ b/tests/increase-item-depth-basic/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.increaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.increaseItemDepth(editor); } diff --git a/tests/increase-item-depth-complex/change.js b/tests/increase-item-depth-complex/change.js index 39ae0673..2cd74827 100644 --- a/tests/increase-item-depth-complex/change.js +++ b/tests/increase-item-depth-complex/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.increaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.increaseItemDepth(editor); } diff --git a/tests/increase-item-depth-existing-sublist/change.js b/tests/increase-item-depth-existing-sublist/change.js index 39ae0673..2cd74827 100644 --- a/tests/increase-item-depth-existing-sublist/change.js +++ b/tests/increase-item-depth-existing-sublist/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.increaseItemDepth(change); +export default function(plugin, editor) { + return plugin.changes.increaseItemDepth(editor); } diff --git a/tests/increase-item-depth-fifth/change.js b/tests/increase-item-depth-fifth/change.js index d9cebc8c..35dd8888 100644 --- a/tests/increase-item-depth-fifth/change.js +++ b/tests/increase-item-depth-fifth/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.increaseItemDepth); +export default function(plugin, editor) { + return editor.command(plugin.changes.increaseItemDepth); } diff --git a/tests/schema-items-are-list-children/change.js b/tests/schema-items-are-list-children/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-items-are-list-children/change.js +++ b/tests/schema-items-are-list-children/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-items-contain-blocks-2/change.js b/tests/schema-items-contain-blocks-2/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-items-contain-blocks-2/change.js +++ b/tests/schema-items-contain-blocks-2/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-items-contain-blocks/change.js b/tests/schema-items-contain-blocks/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-items-contain-blocks/change.js +++ b/tests/schema-items-contain-blocks/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-join-adjacent-lists-unless-different/change.js b/tests/schema-join-adjacent-lists-unless-different/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-join-adjacent-lists-unless-different/change.js +++ b/tests/schema-join-adjacent-lists-unless-different/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-join-adjacent-lists/change.js b/tests/schema-join-adjacent-lists/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-join-adjacent-lists/change.js +++ b/tests/schema-join-adjacent-lists/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-lists-contain-items/change.js b/tests/schema-lists-contain-items/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-lists-contain-items/change.js +++ b/tests/schema-lists-contain-items/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-nested-lists/change.js b/tests/schema-nested-lists/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-nested-lists/change.js +++ b/tests/schema-nested-lists/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/schema-ul-ul-li-li/change.js b/tests/schema-ul-ul-li-li/change.js index dafcd4d3..e4b359ae 100644 --- a/tests/schema-ul-ul-li-li/change.js +++ b/tests/schema-ul-ul-li-li/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.normalize(); +export default function(plugin, editor) { + return editor.normalize(); } diff --git a/tests/shift-enter-middle-item/change.js b/tests/shift-enter-middle-item/change.js index a4f038c1..ada87d73 100644 --- a/tests/shift-enter-middle-item/change.js +++ b/tests/shift-enter-middle-item/change.js @@ -1,6 +1,6 @@ import expect from 'expect'; -export default function(plugin, change) { +export default function(plugin, editor) { const ret = plugin.onKeyDown( { preventDefault: () => {}, @@ -8,7 +8,7 @@ export default function(plugin, change) { key: 'Enter', shiftKey: true }, - change, + editor, () => {} ); diff --git a/tests/split-item-end/change.js b/tests/split-item-end/change.js index 9b816f63..af35fd27 100644 --- a/tests/split-item-end/change.js +++ b/tests/split-item-end/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.splitListItem(change); +export default function(plugin, editor) { + return plugin.changes.splitListItem(editor); } diff --git a/tests/split-item-offset-multiple-blocks/change.js b/tests/split-item-offset-multiple-blocks/change.js index 9b816f63..af35fd27 100644 --- a/tests/split-item-offset-multiple-blocks/change.js +++ b/tests/split-item-offset-multiple-blocks/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.splitListItem(change); +export default function(plugin, editor) { + return plugin.changes.splitListItem(editor); } diff --git a/tests/split-item-offset/change.js b/tests/split-item-offset/change.js index 9b816f63..af35fd27 100644 --- a/tests/split-item-offset/change.js +++ b/tests/split-item-offset/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.splitListItem(change); +export default function(plugin, editor) { + return plugin.changes.splitListItem(editor); } diff --git a/tests/split-item-start/change.js b/tests/split-item-start/change.js index 17712665..aecb64af 100644 --- a/tests/split-item-start/change.js +++ b/tests/split-item-start/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.splitListItem); +export default function(plugin, editor) { + return editor.command(plugin.changes.splitListItem); } diff --git a/tests/split-item-sublist-deep/change.js b/tests/split-item-sublist-deep/change.js index 4afe4bb9..b22a2013 100644 --- a/tests/split-item-sublist-deep/change.js +++ b/tests/split-item-sublist-deep/change.js @@ -1,15 +1,15 @@ import expect from 'expect'; -export default function(plugin, change) { - plugin.changes.splitListItem(change); +export default function(plugin, editor) { + plugin.changes.splitListItem(editor); // check new selection - const selectedNode = change.value.document.getTexts().get(2); - const selectedNodePath = change.value.document + const selectedNode = editor.value.document.getTexts().get(2); + const selectedNodePath = editor.value.document .getPath(selectedNode.key) .toJS(); - expect(change.value.selection.toJS()).toMatchObject({ + expect(editor.value.selection.toJS()).toMatchObject({ object: 'selection', anchor: { object: 'point', @@ -25,5 +25,5 @@ export default function(plugin, change) { marks: null }); - return change; + return editor; } diff --git a/tests/split-item-sublist/change.js b/tests/split-item-sublist/change.js index 9b816f63..af35fd27 100644 --- a/tests/split-item-sublist/change.js +++ b/tests/split-item-sublist/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return plugin.changes.splitListItem(change); +export default function(plugin, editor) { + return plugin.changes.splitListItem(editor); } diff --git a/tests/undo-decrease-item-depth-long-sublist/change.js b/tests/undo-decrease-item-depth-long-sublist/change.js index 0114373c..0a9d9691 100644 --- a/tests/undo-decrease-item-depth-long-sublist/change.js +++ b/tests/undo-decrease-item-depth-long-sublist/change.js @@ -1,10 +1,10 @@ import expect from 'expect'; -export default function(plugin, change) { - change.command(plugin.changes.decreaseItemDepth).undo(); +export default function(plugin, editor) { + editor.command(plugin.changes.decreaseItemDepth).undo(); // Back to previous cursor position - expect(change.value.startBlock.text).toEqual('Item 1.1'); + expect(editor.value.startBlock.text).toEqual('Item 1.1'); - return change; + return editor; } diff --git a/tests/undo-increase-item-depth-complex/change.js b/tests/undo-increase-item-depth-complex/change.js index 02e371d0..104dac2f 100644 --- a/tests/undo-increase-item-depth-complex/change.js +++ b/tests/undo-increase-item-depth-complex/change.js @@ -1,14 +1,14 @@ import expect from 'expect'; -export default function(plugin, change) { - const initialText = change.value.startBlock.text; - const initialSelection = change.value.selection; +export default function(plugin, editor) { + const initialText = editor.value.startBlock.text; + const initialSelection = editor.value.selection; - change.command(plugin.changes.increaseItemDepth).undo(); + editor.command(plugin.changes.increaseItemDepth).undo(); // Back to previous cursor position - expect(change.value.startBlock.text).toEqual(initialText); - expect(change.value.selection.toJS()).toEqual(initialSelection.toJS()); + expect(editor.value.startBlock.text).toEqual(initialText); + expect(editor.value.selection.toJS()).toEqual(initialSelection.toJS()); - return change; + return editor; } diff --git a/tests/undo-split-item-sublist-deep/change.js b/tests/undo-split-item-sublist-deep/change.js index b36c3312..d3dd7b7a 100644 --- a/tests/undo-split-item-sublist-deep/change.js +++ b/tests/undo-split-item-sublist-deep/change.js @@ -1,14 +1,14 @@ import expect from 'expect'; -export default function(plugin, change) { - const initialText = change.value.startBlock.text; - const initialSelection = change.value.selection; +export default function(plugin, editor) { + const initialText = editor.value.startBlock.text; + const initialSelection = editor.value.selection; - change.command(plugin.changes.splitListItem).undo(); + editor.command(plugin.changes.splitListItem).undo(); // Back to previous cursor position - expect(change.value.startBlock.text).toEqual(initialText); - expect(change.value.selection.toJS()).toEqual(initialSelection.toJS()); + expect(editor.value.startBlock.text).toEqual(initialText); + expect(editor.value.selection.toJS()).toEqual(initialSelection.toJS()); - return change; + return editor; } diff --git a/tests/undo-unwrap-long-list/change.js b/tests/undo-unwrap-long-list/change.js index bb3224a0..c163ee8b 100644 --- a/tests/undo-unwrap-long-list/change.js +++ b/tests/undo-unwrap-long-list/change.js @@ -1,14 +1,14 @@ import expect from 'expect'; -export default function(plugin, change) { - const initialText = change.value.startBlock.text; - const initialSelection = change.value.selection; +export default function(plugin, editor) { + const initialText = editor.value.startBlock.text; + const initialSelection = editor.value.selection; - change.command(plugin.changes.unwrapList).undo(); + editor.command(plugin.changes.unwrapList).undo(); // Back to previous cursor position - expect(change.value.startBlock.text).toEqual(initialText); - expect(change.value.selection.toJS()).toEqual(initialSelection.toJS()); + expect(editor.value.startBlock.text).toEqual(initialText); + expect(editor.value.selection.toJS()).toEqual(initialSelection.toJS()); - return change; + return editor; } diff --git a/tests/undo-wrap-in-list/change.js b/tests/undo-wrap-in-list/change.js index 93412a1b..970773b6 100644 --- a/tests/undo-wrap-in-list/change.js +++ b/tests/undo-wrap-in-list/change.js @@ -1,15 +1,15 @@ import expect from 'expect'; -export default function(plugin, change) { - const { value } = change; +export default function(plugin, editor) { + const { value } = editor; const initialText = value.startBlock.text; const initialSelection = value.selection; - change.command(plugin.changes.wrapInList).undo(); + editor.command(plugin.changes.wrapInList).undo(); // Back to previous cursor position - expect(change.value.startBlock.text).toEqual(initialText); - expect(change.value.selection.toJS()).toEqual(initialSelection.toJS()); + expect(editor.value.startBlock.text).toEqual(initialText); + expect(editor.value.selection.toJS()).toEqual(initialSelection.toJS()); - return change; + return editor; } diff --git a/tests/unwrap-list-multiple-nested/change.js b/tests/unwrap-list-multiple-nested/change.js index 232ac1dc..c2929adf 100644 --- a/tests/unwrap-list-multiple-nested/change.js +++ b/tests/unwrap-list-multiple-nested/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.unwrapList); +export default function(plugin, editor) { + return editor.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-list-multiple/change.js b/tests/unwrap-list-multiple/change.js index 232ac1dc..c2929adf 100644 --- a/tests/unwrap-list-multiple/change.js +++ b/tests/unwrap-list-multiple/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.unwrapList); +export default function(plugin, editor) { + return editor.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-list/change.js b/tests/unwrap-list/change.js index 232ac1dc..c2929adf 100644 --- a/tests/unwrap-list/change.js +++ b/tests/unwrap-list/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.unwrapList); +export default function(plugin, editor) { + return editor.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-long-list/change.js b/tests/unwrap-long-list/change.js index 232ac1dc..c2929adf 100644 --- a/tests/unwrap-long-list/change.js +++ b/tests/unwrap-long-list/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.unwrapList); +export default function(plugin, editor) { + return editor.command(plugin.changes.unwrapList); } diff --git a/tests/unwrap-nested-list/change.js b/tests/unwrap-nested-list/change.js index 232ac1dc..c2929adf 100644 --- a/tests/unwrap-nested-list/change.js +++ b/tests/unwrap-nested-list/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.unwrapList); +export default function(plugin, editor) { + return editor.command(plugin.changes.unwrapList); } diff --git a/tests/wrap-in-list-list-with-data/change.js b/tests/wrap-in-list-list-with-data/change.js index 3df265d4..57a2b577 100644 --- a/tests/wrap-in-list-list-with-data/change.js +++ b/tests/wrap-in-list-list-with-data/change.js @@ -1,4 +1,4 @@ -export default function(plugin, change) { +export default function(plugin, editor) { const data = { style: { listStyleType: 'disc' } }; - return change.command(plugin.changes.wrapInList, false, data); + return editor.command(plugin.changes.wrapInList, false, data); } diff --git a/tests/wrap-in-list-list/change.js b/tests/wrap-in-list-list/change.js index dd904845..2257f6ed 100644 --- a/tests/wrap-in-list-list/change.js +++ b/tests/wrap-in-list-list/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.wrapInList); +export default function(plugin, editor) { + return editor.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-list-multiple-with-data/change.js b/tests/wrap-in-list-multiple-with-data/change.js index 3df265d4..57a2b577 100644 --- a/tests/wrap-in-list-multiple-with-data/change.js +++ b/tests/wrap-in-list-multiple-with-data/change.js @@ -1,4 +1,4 @@ -export default function(plugin, change) { +export default function(plugin, editor) { const data = { style: { listStyleType: 'disc' } }; - return change.command(plugin.changes.wrapInList, false, data); + return editor.command(plugin.changes.wrapInList, false, data); } diff --git a/tests/wrap-in-list-multiple/change.js b/tests/wrap-in-list-multiple/change.js index dd904845..2257f6ed 100644 --- a/tests/wrap-in-list-multiple/change.js +++ b/tests/wrap-in-list-multiple/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.wrapInList); +export default function(plugin, editor) { + return editor.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-list-with-data/change.js b/tests/wrap-in-list-with-data/change.js index 2ac175de..d8d03470 100644 --- a/tests/wrap-in-list-with-data/change.js +++ b/tests/wrap-in-list-with-data/change.js @@ -1,4 +1,4 @@ -export default function(plugin, change) { +export default function(plugin, editor) { const data = { style: { listStyleType: 'decimal' } }; - return change.command(plugin.changes.wrapInList, 'ol_list', data); + return editor.command(plugin.changes.wrapInList, 'ol_list', data); } diff --git a/tests/wrap-in-list/change.js b/tests/wrap-in-list/change.js index dd904845..2257f6ed 100644 --- a/tests/wrap-in-list/change.js +++ b/tests/wrap-in-list/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.wrapInList); +export default function(plugin, editor) { + return editor.command(plugin.changes.wrapInList); } diff --git a/tests/wrap-in-ol/change.js b/tests/wrap-in-ol/change.js index 6e8f8a04..fc208dfe 100644 --- a/tests/wrap-in-ol/change.js +++ b/tests/wrap-in-ol/change.js @@ -1,3 +1,3 @@ -export default function(plugin, change) { - return change.command(plugin.changes.wrapInList, 'ol_list'); +export default function(plugin, editor) { + return editor.command(plugin.changes.wrapInList, 'ol_list'); } From dc0fdcb073e9507d522e1ada976a17901e4f252d Mon Sep 17 00:00:00 2001 From: Cary Dunn Date: Fri, 29 Mar 2019 14:36:39 -0700 Subject: [PATCH 5/5] update package for fork --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 73d44c75..d93c2d16 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { - "name": "front-slate-edit-list", + "name": "@tildepage/slate-edit-list", "description": "A Slate plugin to handle keyboard events in lists.", - "version": "0.12.2-1", + "version": "0.1.0", "license": "Apache-2.0", - "repository": "git://github.com/GitbookIO/slate-edit-list.git", + "repository": "git://github.com/cdunn/slate-edit-list.git", "main": "./dist/index.js", "peerDependencies": { "immutable": "^3.8.2",