Update Slate to 0.27.0

This commit is contained in:
Shawn Erquhart 2017-11-16 10:15:45 -05:00
parent b02d3dc47a
commit ff0b8d4ca8
5 changed files with 71 additions and 81 deletions

View File

@ -176,11 +176,11 @@
"remark-stringify": "^3.0.1", "remark-stringify": "^3.0.1",
"sanitize-filename": "^1.6.1", "sanitize-filename": "^1.6.1",
"semaphore": "^1.0.5", "semaphore": "^1.0.5",
"slate": "^0.26.0", "slate": "^0.27.0",
"slate-edit-list": "^0.8.0", "slate-edit-list": "^0.9.0",
"slate-edit-table": "^0.11.0", "slate-edit-table": "^0.12.0",
"slate-plain-serializer": "^0.1.10", "slate-plain-serializer": "^0.2.0",
"slate-react": "^0.3.0", "slate-react": "^0.4.0",
"slate-soft-break": "^0.4.0", "slate-soft-break": "^0.4.0",
"slug": "^0.9.1", "slug": "^0.9.1",
"toml-j0.4": "^1.1.1", "toml-j0.4": "^1.1.1",

View File

@ -44,12 +44,12 @@ function onKeyDown(e, data, change) {
/** /**
* If "Enter" is pressed while a single void block is selected, a new * If "Enter" is pressed while a single void block is selected, a new
* paragraph should be added above or below it, and the current selection * paragraph should be added above or below it, and the current selection
* should be collapsed to the start of the new paragraph. * (range) should be collapsed to the start of the new paragraph.
* *
* If the selected block is the first block in the document, create the * If the selected block is the first block in the document, create the
* new block above it. If not, create the new block below it. * new block above it. If not, create the new block below it.
*/ */
const { document: doc, selection, anchorBlock, focusBlock } = change.state; const { document: doc, range, anchorBlock, focusBlock } = change.state;
const singleBlockSelected = anchorBlock === focusBlock; const singleBlockSelected = anchorBlock === focusBlock;
if (!singleBlockSelected || !focusBlock.isVoid) return; if (!singleBlockSelected || !focusBlock.isVoid) return;

View File

@ -94,8 +94,8 @@ function createInline(type, props = {}, nodes) {
*/ */
function createText(value, data) { function createText(value, data) {
const node = { kind: 'text', data }; const node = { kind: 'text', data };
const ranges = isArray(value) ? value : [{ text: value }]; const leaves = isArray(value) ? value : [{ text: value }];
return { ...node, ranges }; return { ...node, leaves };
} }
function processMarkNode(node, parentMarks = []) { function processMarkNode(node, parentMarks = []) {
@ -110,8 +110,8 @@ function processMarkNode(node, parentMarks = []) {
switch (childNode.type) { switch (childNode.type) {
/** /**
* If a text node is a direct child of the current node, it should be * If a text node is a direct child of the current node, it should be
* set aside as a range, and all marks that have been collected in the * set aside as a leaf, and all marks that have been collected in the
* `marks` array should apply to that specific range. * `marks` array should apply to that specific leaf.
*/ */
case 'html': case 'html':
case 'text': case 'text':
@ -129,8 +129,8 @@ function processMarkNode(node, parentMarks = []) {
/** /**
* Process nested style nodes. The recursive results should be pushed into * Process nested style nodes. The recursive results should be pushed into
* the ranges array. This way, every MDAST nested text structure becomes a * the leaves array. This way, every MDAST nested text structure becomes a
* flat array of ranges that can serve as the value of a single Slate Raw * flat array of leaves that can serve as the value of a single Slate Raw
* text node. * text node.
*/ */
case 'strong': case 'strong':
@ -155,8 +155,8 @@ function convertMarkNode(node) {
const convertedSlateNodes = slateNodes.reduce((acc, node) => { const convertedSlateNodes = slateNodes.reduce((acc, node) => {
const lastConvertedNode = last(acc); const lastConvertedNode = last(acc);
if (node.text && lastConvertedNode && lastConvertedNode.ranges) { if (node.text && lastConvertedNode && lastConvertedNode.leaves) {
lastConvertedNode.ranges.push(node); lastConvertedNode.leaves.push(node);
} }
else if (node.text) { else if (node.text) {
acc.push(createText([node])); acc.push(createText([node]));
@ -232,16 +232,16 @@ function convertNode(node, nodes) {
* Inline Code * Inline Code
* *
* Inline code nodes from an MDAST are represented in our Slate schema as * Inline code nodes from an MDAST are represented in our Slate schema as
* text nodes with a "code" mark. We manually create the "range" containing * text nodes with a "code" mark. We manually create the "leaf" containing
* the inline code value and a "code" mark, and place it in an array for use * the inline code value and a "code" mark, and place it in an array for use
* as a Slate text node's children array. * as a Slate text node's children array.
*/ */
case 'inlineCode': { case 'inlineCode': {
const range = { const leaf = {
text: node.value, text: node.value,
marks: [{ type: 'code' }], marks: [{ type: 'code' }],
}; };
return createText([ range ]); return createText([ leaf ]);
} }
/** /**

View File

@ -85,7 +85,7 @@ function transform(node) {
/** /**
* Includes inline nodes as ranges in adjacent text nodes where appropriate, so * Includes inline nodes as leaves in adjacent text nodes where appropriate, so
* that mark node combining logic can apply to both text and inline nodes. This * that mark node combining logic can apply to both text and inline nodes. This
* is necessary because Slate doesn't allow inline nodes to have marks while * is necessary because Slate doesn't allow inline nodes to have marks while
* inline nodes in MDAST may be nested within mark nodes. Treating them as if * inline nodes in MDAST may be nested within mark nodes. Treating them as if
@ -94,23 +94,23 @@ function transform(node) {
function combineTextAndInline(nodes) { function combineTextAndInline(nodes) {
return nodes.reduce((acc, node, idx, nodes) => { return nodes.reduce((acc, node, idx, nodes) => {
const prevNode = last(acc); const prevNode = last(acc);
const prevNodeRanges = get(prevNode, 'ranges'); const prevNodeLeaves = get(prevNode, 'leaves');
const data = node.data || {}; const data = node.data || {};
/** /**
* If the previous node has ranges and the current node has marks in data * If the previous node has leaves and the current node has marks in data
* (only happens when we place them on inline nodes here in the parser), or * (only happens when we place them on inline nodes here in the parser), or
* the current node also has ranges (because the previous node was * the current node also has leaves (because the previous node was
* originally an inline node that we've already squashed into a range) * originally an inline node that we've already squashed into a leaf)
* combine the current node into the previous. * combine the current node into the previous.
*/ */
if (!isEmpty(prevNodeRanges) && !isEmpty(data.marks)) { if (!isEmpty(prevNodeLeaves) && !isEmpty(data.marks)) {
prevNodeRanges.push({ node, marks: data.marks }); prevNodeLeaves.push({ node, marks: data.marks });
return acc; return acc;
} }
if (!isEmpty(prevNodeRanges) && !isEmpty(node.ranges)) { if (!isEmpty(prevNodeLeaves) && !isEmpty(node.leaves)) {
prevNode.ranges = prevNodeRanges.concat(node.ranges); prevNode.leaves = prevNodeLeaves.concat(node.leaves);
return acc; return acc;
} }
@ -125,10 +125,10 @@ function combineTextAndInline(nodes) {
} }
/** /**
* Convert remaining inline nodes to standalone text nodes with ranges. * Convert remaining inline nodes to standalone text nodes with leaves.
*/ */
if (node.kind === 'inline') { if (node.kind === 'inline') {
acc.push({ kind: 'text', ranges: [{ node, marks: data.marks }] }); acc.push({ kind: 'text', leaves: [{ node, marks: data.marks }] });
return acc; return acc;
} }
@ -177,23 +177,23 @@ function wrapTextWithMarks(textNode, markTypes) {
* Slate text nodes without marks often simply have a "text" property with * Slate text nodes without marks often simply have a "text" property with
* the value. In this case the conversion to MDAST is simple. If a Slate * the value. In this case the conversion to MDAST is simple. If a Slate
* text node does not have a "text" property, it will instead have a * text node does not have a "text" property, it will instead have a
* "ranges" property containing an array of objects, each with an array of * "leaves" property containing an array of objects, each with an array of
* marks, such as "bold" or "italic", along with a "text" property. * marks, such as "bold" or "italic", along with a "text" property.
* *
* MDAST instead expresses such marks in a nested structure, with individual * MDAST instead expresses such marks in a nested structure, with individual
* nodes for each mark type nested until the deepest mark node, which will * nodes for each mark type nested until the deepest mark node, which will
* contain the text node. * contain the text node.
* *
* To convert a Slate text node's marks to MDAST, we treat each "range" as a * To convert a Slate text node's marks to MDAST, we treat each "leaf" as a
* separate text node, convert the text node itself to an MDAST text node, * separate text node, convert the text node itself to an MDAST text node,
* and then recursively wrap the text node for each mark, collecting the results * and then recursively wrap the text node for each mark, collecting the results
* of each range in a single array of child nodes. * of each leaf in a single array of child nodes.
* *
* For example, this Slate text node: * For example, this Slate text node:
* *
* { * {
* kind: 'text', * kind: 'text',
* ranges: [ * leaves: [
* { * {
* text: 'test', * text: 'test',
* marks: ['bold', 'italic'] * marks: ['bold', 'italic']
@ -228,13 +228,13 @@ function wrapTextWithMarks(textNode, markTypes) {
*/ */
function convertTextNode(node) { function convertTextNode(node) {
/** /**
* If the Slate text node has a "ranges" property, translate the Slate AST to * If the Slate text node has a "leaves" property, translate the Slate AST to
* a nested MDAST structure. Otherwise, just return an equivalent MDAST text * a nested MDAST structure. Otherwise, just return an equivalent MDAST text
* node. * node.
*/ */
if (node.ranges) { if (node.leaves) {
const processedRanges = node.ranges.map(processRanges); const processedLeaves = node.leaves.map(processLeaves);
const condensedNodes = processedRanges.reduce(condenseNodesReducer, { nodes: [] }); const condensedNodes = processedLeaves.reduce(condenseNodesReducer, { nodes: [] });
return condensedNodes.nodes; return condensedNodes.nodes;
} }
@ -247,17 +247,17 @@ function convertTextNode(node) {
/** /**
* Process Slate node ranges in preparation for MDAST transformation. * Process Slate node leaves in preparation for MDAST transformation.
*/ */
function processRanges(range) { function processLeaves(leaves) {
/** /**
* Get an array of the mark types, converted to their MDAST equivalent * Get an array of the mark types, converted to their MDAST equivalent
* types. * types.
*/ */
const { marks = [], text } = range; const { marks = [], text } = leaf;
const markTypes = marks.map(mark => markMap[mark.type]); const markTypes = marks.map(mark => markMap[mark.type]);
if (typeof range.text === 'string') { if (typeof leaf.text === 'string') {
/** /**
* Code marks must be removed from the marks array, and the presence of a * Code marks must be removed from the marks array, and the presence of a
* code mark changes the text node type that should be used. * code mark changes the text node type that should be used.
@ -266,14 +266,14 @@ function processRanges(range) {
return { text, marks: filteredMarkTypes, textNodeType }; return { text, marks: filteredMarkTypes, textNodeType };
} }
return { node: range.node, marks: markTypes }; return { node: leaf.node, marks: markTypes };
} }
/** /**
* Slate's AST doesn't group adjacent text nodes with the same marks - a * Slate's AST doesn't group adjacent text nodes with the same marks - a
* change in marks from letter to letter, even if some are in common, results * change in marks from letter to letter, even if some are in common, results
* in a separate range. For example, given "**a_b_**", transformation to and * in a separate leaf. For example, given "**a_b_**", transformation to and
* from Slate's AST will result in "**a****_b_**". * from Slate's AST will result in "**a****_b_**".
* *
* MDAST treats styling entities as distinct nodes that contain children, so a * MDAST treats styling entities as distinct nodes that contain children, so a
@ -436,7 +436,7 @@ function convertNode(node, children, shortcodePlugins) {
*/ */
case 'code': { case 'code': {
const value = flatMap(node.nodes, child => { const value = flatMap(node.nodes, child => {
return flatMap(child.ranges, 'text'); return flatMap(child.leaves, 'text');
}).join(''); }).join('');
const { lang, ...data } = get(node, 'data', {}); const { lang, ...data } = get(node, 'data', {});
return u(typeMap[node.type], { lang, data }, value); return u(typeMap[node.type], { lang, data }, value);

View File

@ -8521,49 +8521,39 @@ slash@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
slate-base64-serializer@^0.1.13: slate-base64-serializer@^0.1.14:
version "0.1.22" version "0.1.22"
resolved "https://registry.yarnpkg.com/slate-base64-serializer/-/slate-base64-serializer-0.1.22.tgz#548e589178c75653004168004aad152f1976dd35" resolved "https://registry.yarnpkg.com/slate-base64-serializer/-/slate-base64-serializer-0.1.22.tgz#548e589178c75653004168004aad152f1976dd35"
dependencies: dependencies:
isomorphic-base64 "^1.0.2" isomorphic-base64 "^1.0.2"
slate-dev-logger@^0.1.11: slate-dev-logger@^0.1.15, slate-dev-logger@^0.1.20, slate-dev-logger@^0.1.23:
version "0.1.11"
resolved "https://registry.yarnpkg.com/slate-dev-logger/-/slate-dev-logger-0.1.11.tgz#740fd2e23b1dda1f4629419fc914eea91272b6f0"
slate-dev-logger@^0.1.14:
version "0.1.33" version "0.1.33"
resolved "https://registry.yarnpkg.com/slate-dev-logger/-/slate-dev-logger-0.1.33.tgz#b4a4272255c2d598e5f26db5d85c58435357755f" resolved "https://registry.yarnpkg.com/slate-dev-logger/-/slate-dev-logger-0.1.33.tgz#b4a4272255c2d598e5f26db5d85c58435357755f"
slate-edit-list@^0.8.0: slate-edit-list@^0.9.0:
version "0.8.0" version "0.9.0"
resolved "https://registry.yarnpkg.com/slate-edit-list/-/slate-edit-list-0.8.0.tgz#3f8904fc9cb308d3c614efa5586953a6de6a4608" resolved "https://registry.yarnpkg.com/slate-edit-list/-/slate-edit-list-0.9.0.tgz#18fdeb8e6f4068da88a05aa0cb499a191d8343e6"
slate-edit-table@^0.11.0: slate-edit-table@^0.12.0:
version "0.11.0" version "0.12.0"
resolved "https://registry.yarnpkg.com/slate-edit-table/-/slate-edit-table-0.11.0.tgz#4ab175a02146ec1c45a4a2826eaa66b5db0d2266" resolved "https://registry.yarnpkg.com/slate-edit-table/-/slate-edit-table-0.12.0.tgz#9163e67b8025c3c09d6037eb76cb5e652b65dd47"
slate-plain-serializer@^0.1.10: slate-plain-serializer@^0.2.0:
version "0.1.11" version "0.2.8"
resolved "https://registry.yarnpkg.com/slate-plain-serializer/-/slate-plain-serializer-0.1.11.tgz#0b70cd870a935b294d6418785084be33ae23b96e" resolved "https://registry.yarnpkg.com/slate-plain-serializer/-/slate-plain-serializer-0.2.8.tgz#9bff5fafa09ab2ad47d961820f09d7d2abcb20a9"
dependencies: dependencies:
slate-dev-logger "^0.1.11" slate-dev-logger "^0.1.23"
slate-plain-serializer@^0.1.14: slate-prop-types@^0.2.0:
version "0.1.14" version "0.2.8"
resolved "https://registry.yarnpkg.com/slate-plain-serializer/-/slate-plain-serializer-0.1.14.tgz#19f6cd9a47d2e7db93d928a8adae10ceb779e743" resolved "https://registry.yarnpkg.com/slate-prop-types/-/slate-prop-types-0.2.8.tgz#2d0e1df0a372c635068c6f74a52b567b996f51c2"
dependencies: dependencies:
slate-dev-logger "^0.1.14" slate-dev-logger "^0.1.23"
slate-prop-types@^0.1.13: slate-react@^0.4.0:
version "0.1.13" version "0.4.0"
resolved "https://registry.yarnpkg.com/slate-prop-types/-/slate-prop-types-0.1.13.tgz#2045d73b12a2fe7205bd6e8792ff1c5b06420fef" resolved "https://registry.yarnpkg.com/slate-react/-/slate-react-0.4.0.tgz#e15c9034df5ea58fcb8a0c49c1cd159702296e0c"
dependencies:
slate-dev-logger "^0.1.14"
slate-react@^0.3.0:
version "0.3.4"
resolved "https://registry.yarnpkg.com/slate-react/-/slate-react-0.3.4.tgz#45b34e1909cd86651b718d0d3bb1e35654259e89"
dependencies: dependencies:
debug "^2.3.2" debug "^2.3.2"
get-window "^1.1.1" get-window "^1.1.1"
@ -8574,18 +8564,18 @@ slate-react@^0.3.0:
react-immutable-proptypes "^2.1.0" react-immutable-proptypes "^2.1.0"
react-portal "^3.1.0" react-portal "^3.1.0"
selection-is-backward "^1.0.0" selection-is-backward "^1.0.0"
slate-base64-serializer "^0.1.13" slate-base64-serializer "^0.1.14"
slate-dev-logger "^0.1.14" slate-dev-logger "^0.1.15"
slate-plain-serializer "^0.1.14" slate-plain-serializer "^0.2.0"
slate-prop-types "^0.1.13" slate-prop-types "^0.2.0"
slate-soft-break@^0.4.0: slate-soft-break@^0.4.0:
version "0.4.3" version "0.4.3"
resolved "https://registry.yarnpkg.com/slate-soft-break/-/slate-soft-break-0.4.3.tgz#e3a9279a9b92ca173915467f5fbd359f739a7e96" resolved "https://registry.yarnpkg.com/slate-soft-break/-/slate-soft-break-0.4.3.tgz#e3a9279a9b92ca173915467f5fbd359f739a7e96"
slate@^0.26.0: slate@^0.27.0:
version "0.26.1" version "0.27.5"
resolved "https://registry.yarnpkg.com/slate/-/slate-0.26.1.tgz#3f71712b2f5eb30934caebd199d93acc0b11a458" resolved "https://registry.yarnpkg.com/slate/-/slate-0.27.5.tgz#ab9d9f35e03f1910c59016ad66ee685255b5a645"
dependencies: dependencies:
debug "^2.3.2" debug "^2.3.2"
direction "^0.1.5" direction "^0.1.5"
@ -8594,7 +8584,7 @@ slate@^0.26.0:
is-empty "^1.0.0" is-empty "^1.0.0"
is-plain-object "^2.0.4" is-plain-object "^2.0.4"
lodash "^4.17.4" lodash "^4.17.4"
slate-dev-logger "^0.1.14" slate-dev-logger "^0.1.20"
type-of "^2.0.1" type-of "^2.0.1"
slice-ansi@0.0.4: slice-ansi@0.0.4: