diff --git a/docs/reference/models/transform.md b/docs/reference/models/transform.md index 4f3f80f2f..34db115ae 100644 --- a/docs/reference/models/transform.md +++ b/docs/reference/models/transform.md @@ -317,24 +317,24 @@ Remove a [`mark`](./mark.md) from the characters in a `range`. For convenience, Add or remove a [`mark`](./mark.md) from the characters in a `range`, depending on whether any of them already have the mark. For convenience, you can pass a `type` string or `properties` object to implicitly create a [`Mark`](./mark.md) of that type. ### `unwrapBlockAtRange` -`unwrapBlockAtRange(range: Selection, [type: String], [data: Data]) => Transform` +`unwrapBlockAtRange(range: Selection, properties: Object || String) => Transform` -Unwrap all [`Block`](./block.md) nodes in a `range` that match a `type` and/or `data`. +Unwrap all [`Block`](./block.md) nodes in a `range` that match `properties`. For convenience, you can pass a `type` string or `properties` object. ### `unwrapInlineAtRange` -`unwrapInlineAtRange(range: Selection, [type: String], [data: Data]) => Transform` +`unwrapInlineAtRange(range: Selection, properties: Object || String) => Transform` -Unwrap all [`Inline`](./inline.md) nodes in a `range` that match a `type` and/or `data`. +Unwrap all [`Inline`](./inline.md) nodes in a `range` that match `properties`. For convenience, you can pass a `type` string or `properties` object. ### `wrapBlockAtRange` -`wrapBlockAtRange(range: Selection, type: String, [data: Data]) => Transform` +`wrapBlockAtRange(range: Selection, properties: Object || String) => Transform` -Wrap the [`Block`](./block.md) nodes in a `range` with a new [`Block`](./block.md) node of `type`, with optional `data`. +Wrap the [`Block`](./block.md) nodes in a `range` with a new [`Block`](./block.md) node with `properties`. For convenience, you can pass a `type` string or `properties` object. ### `wrapInlineAtRange` -`wrapInlineAtRange(range: Selection, type: String, [data: Data]) => Transform` +`wrapInlineAtRange(range: Selection, properties: Object || String) => Transform` -Wrap the [`Inline`](./inline.md) nodes in a `range` with a new [`Inline`](./inline.md) node of `type`, with optional `data`. +Wrap the [`Inline`](./inline.md) nodes in a `range` with a new [`Inline`](./inline.md) node with `properties`. For convenience, you can pass a `type` string or `properties` object. ## History Transforms diff --git a/lib/models/transforms.js b/lib/models/transforms.js index ec68c2031..4488b9858 100644 --- a/lib/models/transforms.js +++ b/lib/models/transforms.js @@ -745,26 +745,17 @@ const Transforms = { }, /** - * Unwrap all of the block nodes in a `range` from a block node of `type.` + * Unwrap all of the block nodes in a `range` from a block with `properties`. * * @param {Selection} range - * @param {String} type (optional) - * @param {Data or Object} data (optional) + * @param {String or Object} properties * @return {Node} node */ - unwrapBlockAtRange(range, type, data) { + unwrapBlockAtRange(range, properties) { + properties = normalizeProperties(properties) let node = this - // Allow for only data. - if (typeof type == 'object') { - data = type - type = null - } - - // Ensure that data is immutable. - if (data) data = Data.create(data) - // Get the deepest blocks in the range. const blocks = node.getBlocksAtRange(range) @@ -772,8 +763,8 @@ const Transforms = { const wrappers = blocks.reduce((memo, text) => { const match = node.getClosest(text, (parent) => { if (parent.kind != 'block') return false - if (type && parent.type != type) return false - if (data && !parent.data.isSuperset(data)) return false + if (properties.type && parent.type != properties.type) return false + if (properties.data && !parent.data.isSuperset(properties.data)) return false return true }) @@ -846,34 +837,25 @@ const Transforms = { }, /** - * Unwrap the inline nodes in a `range` from an parent inline with `type`. + * Unwrap the inline nodes in a `range` from an inline with `properties`. * * @param {Selection} range - * @param {String} type (optional) - * @param {Data} data (optional) + * @param {String or Object} properties * @return {Node} node */ - unwrapInlineAtRange(range, type, data) { + unwrapInlineAtRange(range, properties) { + properties = normalizeProperties(properties) let node = this let blocks = node.getInlinesAtRange(range) - // Allow for no type. - if (typeof type == 'object') { - data = type - type = null - } - - // Ensure that data is immutable. - if (data) data = Data.create(data) - // Find the closest matching inline wrappers of each text node. const texts = this.getTexts() const wrappers = texts.reduce((memo, text) => { const match = node.getClosest(text, (parent) => { if (parent.kind != 'inline') return false - if (type && parent.type != type) return false - if (data && !parent.data.isSuperset(data)) return false + if (properties.type && parent.type != properties.type) return false + if (properties.data && !parent.data.isSuperset(properties.data)) return false return true }) @@ -900,16 +882,15 @@ const Transforms = { }, /** - * Wrap all of the blocks in a `range` in a new block node of `type`. + * Wrap all of the blocks in a `range` in a new block with `properties`. * * @param {Selection} range - * @param {String} type - * @param {Data} data (optional) + * @param {String or Object} properties * @return {Node} node */ - wrapBlockAtRange(range, type, data) { - data = Data.create(data) + wrapBlockAtRange(range, properties) { + properties = normalizeProperties(properties) let node = this // Get the block nodes, sorted by depth. @@ -936,8 +917,8 @@ const Transforms = { // Wrap the siblings in a new block. const wrapper = Block.create({ nodes: siblings, - type, - data + type: properties.type, + data: properties.data }) // Replace the siblings with the wrapper. @@ -958,16 +939,15 @@ const Transforms = { }, /** - * Wrap the text and inline nodes in a `range` with a new inline node. + * Wrap the text and inlines in a `range` in a new inline with `properties`. * * @param {Selection} range - * @param {String} type - * @param {Data} data (optional) + * @param {String or Object} properties * @return {Node} node */ - wrapInlineAtRange(range, type, data) { - data = Data.create(data) + wrapInlineAtRange(range, properties) { + properties = normalizeProperties(properties) let node = this // If collapsed, there's nothing to wrap. @@ -1007,11 +987,11 @@ const Transforms = { // Iterate each of the child nodes, wrapping them. children.forEach((child) => { - const obj = {} - obj.nodes = [child] - obj.type = type - if (data) obj.data = data - const wrapper = Inline.create(obj) + const wrapper = Inline.create({ + nodes: [child], + type: properties.type, + data: properties.data + }) // Replace the child in it's parent with the wrapper. const parent = node.getParent(child) diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data/index.js b/test/transforms/fixtures/unwrap-block-at-range/with-data/index.js deleted file mode 100644 index 4aedeed52..000000000 --- a/test/transforms/fixtures/unwrap-block-at-range/with-data/index.js +++ /dev/null @@ -1,19 +0,0 @@ - -import { Data } from '../../../../..' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 0, - focusKey: first.key, - focusOffset: 0 - }) - - return state - .transform() - .unwrapBlockAtRange(range, 'quote', Data.create({ key: 'value' })) - .apply() -} diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data-object/index.js b/test/transforms/fixtures/unwrap-block-at-range/with-object/index.js similarity index 77% rename from test/transforms/fixtures/wrap-block-at-range/with-data-object/index.js rename to test/transforms/fixtures/unwrap-block-at-range/with-object/index.js index 42a4d33a6..0b9948eff 100644 --- a/test/transforms/fixtures/wrap-block-at-range/with-data-object/index.js +++ b/test/transforms/fixtures/unwrap-block-at-range/with-object/index.js @@ -12,6 +12,9 @@ export default function (state) { return state .transform() - .wrapBlockAtRange(range, 'quote', { key: 'value' }) + .unwrapBlockAtRange(range, { + type: 'quote', + data: { key: 'value' } + }) .apply() } diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data-object/input.yaml b/test/transforms/fixtures/unwrap-block-at-range/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-block-at-range/with-data-object/input.yaml rename to test/transforms/fixtures/unwrap-block-at-range/with-object/input.yaml diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data-object/output.yaml b/test/transforms/fixtures/unwrap-block-at-range/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-block-at-range/with-data-object/output.yaml rename to test/transforms/fixtures/unwrap-block-at-range/with-object/output.yaml diff --git a/test/transforms/fixtures/unwrap-block/with-data-object/input.yaml b/test/transforms/fixtures/unwrap-block/with-data-object/input.yaml deleted file mode 100644 index 9f139e014..000000000 --- a/test/transforms/fixtures/unwrap-block/with-data-object/input.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -nodes: - - kind: block - type: quote - data: - key: value - nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/unwrap-block/with-data-object/output.yaml b/test/transforms/fixtures/unwrap-block/with-data-object/output.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/unwrap-block/with-data-object/output.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/unwrap-block/with-data/index.js b/test/transforms/fixtures/unwrap-block/with-data/index.js deleted file mode 100644 index be0299735..000000000 --- a/test/transforms/fixtures/unwrap-block/with-data/index.js +++ /dev/null @@ -1,28 +0,0 @@ - -import { Data } from '../../../../..' -import assert from 'assert' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 0, - focusKey: first.key, - focusOffset: 0 - }) - - const next = state - .transform() - .moveTo(range) - .unwrapBlock('quote', Data.create({ key: 'value' })) - .apply() - - assert.deepEqual( - next.selection.toJS(), - range.toJS() - ) - - return next -} diff --git a/test/transforms/fixtures/unwrap-block/with-data/input.yaml b/test/transforms/fixtures/unwrap-block/with-data/input.yaml deleted file mode 100644 index 9f139e014..000000000 --- a/test/transforms/fixtures/unwrap-block/with-data/input.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -nodes: - - kind: block - type: quote - data: - key: value - nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/unwrap-block/with-data/output.yaml b/test/transforms/fixtures/unwrap-block/with-data/output.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/unwrap-block/with-data/output.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/unwrap-block/with-data-object/index.js b/test/transforms/fixtures/unwrap-block/with-object/index.js similarity index 85% rename from test/transforms/fixtures/unwrap-block/with-data-object/index.js rename to test/transforms/fixtures/unwrap-block/with-object/index.js index 5911ed141..a1a1f5558 100644 --- a/test/transforms/fixtures/unwrap-block/with-data-object/index.js +++ b/test/transforms/fixtures/unwrap-block/with-object/index.js @@ -15,7 +15,10 @@ export default function (state) { const next = state .transform() .moveTo(range) - .unwrapBlock('quote', { key: 'value' }) + .unwrapBlock({ + type: 'quote', + data: { key: 'value' } + }) .apply() assert.deepEqual( diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data/input.yaml b/test/transforms/fixtures/unwrap-block/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-block-at-range/with-data/input.yaml rename to test/transforms/fixtures/unwrap-block/with-object/input.yaml diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data/output.yaml b/test/transforms/fixtures/unwrap-block/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-block-at-range/with-data/output.yaml rename to test/transforms/fixtures/unwrap-block/with-object/output.yaml diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data/index.js b/test/transforms/fixtures/unwrap-inline-at-range/with-data/index.js deleted file mode 100644 index 007f3d907..000000000 --- a/test/transforms/fixtures/unwrap-inline-at-range/with-data/index.js +++ /dev/null @@ -1,19 +0,0 @@ - -import { Data } from '../../../../..' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 1, - focusKey: first.key, - focusOffset: 3 - }) - - return state - .transform() - .unwrapInlineAtRange(range, 'hashtag', Data.create({ key: 'one' })) - .apply() -} diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data-object/index.js b/test/transforms/fixtures/unwrap-inline-at-range/with-object/index.js similarity index 77% rename from test/transforms/fixtures/wrap-inline-at-range/with-data-object/index.js rename to test/transforms/fixtures/unwrap-inline-at-range/with-object/index.js index 4e8d9e378..e18ed3821 100644 --- a/test/transforms/fixtures/wrap-inline-at-range/with-data-object/index.js +++ b/test/transforms/fixtures/unwrap-inline-at-range/with-object/index.js @@ -12,6 +12,9 @@ export default function (state) { return state .transform() - .wrapInlineAtRange(range, 'hashtag', { key: 'value' }) + .unwrapInlineAtRange(range, { + type: 'hashtag', + data: { key: 'one' } + }) .apply() } diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data-object/input.yaml b/test/transforms/fixtures/unwrap-inline-at-range/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-inline-at-range/with-data-object/input.yaml rename to test/transforms/fixtures/unwrap-inline-at-range/with-object/input.yaml diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data-object/output.yaml b/test/transforms/fixtures/unwrap-inline-at-range/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-inline-at-range/with-data-object/output.yaml rename to test/transforms/fixtures/unwrap-inline-at-range/with-object/output.yaml diff --git a/test/transforms/fixtures/unwrap-inline/with-data-object/input.yaml b/test/transforms/fixtures/unwrap-inline/with-data-object/input.yaml deleted file mode 100644 index bea41d2de..000000000 --- a/test/transforms/fixtures/unwrap-inline/with-data-object/input.yaml +++ /dev/null @@ -1,21 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: one - nodes: - - kind: inline - type: hashtag - data: - key: two - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/unwrap-inline/with-data-object/output.yaml b/test/transforms/fixtures/unwrap-inline/with-data-object/output.yaml deleted file mode 100644 index 466693bbb..000000000 --- a/test/transforms/fixtures/unwrap-inline/with-data-object/output.yaml +++ /dev/null @@ -1,16 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: two - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/unwrap-inline/with-data/index.js b/test/transforms/fixtures/unwrap-inline/with-data/index.js deleted file mode 100644 index 1e94d6d1d..000000000 --- a/test/transforms/fixtures/unwrap-inline/with-data/index.js +++ /dev/null @@ -1,28 +0,0 @@ - -import { Data } from '../../../../..' -import assert from 'assert' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 1, - focusKey: first.key, - focusOffset: 3 - }) - - const next = state - .transform() - .moveTo(range) - .unwrapInline('hashtag', Data.create({ key: 'one' })) - .apply() - - assert.deepEqual( - next.selection.toJS(), - range.toJS() - ) - - return next -} diff --git a/test/transforms/fixtures/unwrap-inline/with-data/input.yaml b/test/transforms/fixtures/unwrap-inline/with-data/input.yaml deleted file mode 100644 index bea41d2de..000000000 --- a/test/transforms/fixtures/unwrap-inline/with-data/input.yaml +++ /dev/null @@ -1,21 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: one - nodes: - - kind: inline - type: hashtag - data: - key: two - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/unwrap-inline/with-data/output.yaml b/test/transforms/fixtures/unwrap-inline/with-data/output.yaml deleted file mode 100644 index 466693bbb..000000000 --- a/test/transforms/fixtures/unwrap-inline/with-data/output.yaml +++ /dev/null @@ -1,16 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: two - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/unwrap-inline/with-data-object/index.js b/test/transforms/fixtures/unwrap-inline/with-object/index.js similarity index 85% rename from test/transforms/fixtures/unwrap-inline/with-data-object/index.js rename to test/transforms/fixtures/unwrap-inline/with-object/index.js index 1230a08c6..ac861d6cb 100644 --- a/test/transforms/fixtures/unwrap-inline/with-data-object/index.js +++ b/test/transforms/fixtures/unwrap-inline/with-object/index.js @@ -15,7 +15,10 @@ export default function (state) { const next = state .transform() .moveTo(range) - .unwrapInline('hashtag', { key: 'one' }) + .unwrapInline({ + type: 'hashtag', + data: { key: 'one' } + }) .apply() assert.deepEqual( diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data/input.yaml b/test/transforms/fixtures/unwrap-inline/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-inline-at-range/with-data/input.yaml rename to test/transforms/fixtures/unwrap-inline/with-object/input.yaml diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data/output.yaml b/test/transforms/fixtures/unwrap-inline/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/unwrap-inline-at-range/with-data/output.yaml rename to test/transforms/fixtures/unwrap-inline/with-object/output.yaml diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data/index.js b/test/transforms/fixtures/wrap-block-at-range/with-data/index.js deleted file mode 100644 index 803c87f7b..000000000 --- a/test/transforms/fixtures/wrap-block-at-range/with-data/index.js +++ /dev/null @@ -1,19 +0,0 @@ - -import { Data } from '../../../../..' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 0, - focusKey: first.key, - focusOffset: 0 - }) - - return state - .transform() - .wrapBlockAtRange(range, 'quote', Data.create({ key: 'value' })) - .apply() -} diff --git a/test/transforms/fixtures/unwrap-block-at-range/with-data-object/index.js b/test/transforms/fixtures/wrap-block-at-range/with-object/index.js similarity index 78% rename from test/transforms/fixtures/unwrap-block-at-range/with-data-object/index.js rename to test/transforms/fixtures/wrap-block-at-range/with-object/index.js index 31a9faac3..642879fea 100644 --- a/test/transforms/fixtures/unwrap-block-at-range/with-data-object/index.js +++ b/test/transforms/fixtures/wrap-block-at-range/with-object/index.js @@ -12,6 +12,9 @@ export default function (state) { return state .transform() - .unwrapBlockAtRange(range, 'quote', { key: 'value' }) + .wrapBlockAtRange(range, { + type: 'quote', + data: { key: 'value' } + }) .apply() } diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data-object/input.yaml b/test/transforms/fixtures/wrap-block-at-range/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block-at-range/with-data-object/input.yaml rename to test/transforms/fixtures/wrap-block-at-range/with-object/input.yaml diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data-object/output.yaml b/test/transforms/fixtures/wrap-block-at-range/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block-at-range/with-data-object/output.yaml rename to test/transforms/fixtures/wrap-block-at-range/with-object/output.yaml diff --git a/test/transforms/fixtures/wrap-block/with-data-object/output.yaml b/test/transforms/fixtures/wrap-block/with-data-object/output.yaml deleted file mode 100644 index 9f139e014..000000000 --- a/test/transforms/fixtures/wrap-block/with-data-object/output.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -nodes: - - kind: block - type: quote - data: - key: value - nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data/index.js b/test/transforms/fixtures/wrap-block/with-data/index.js deleted file mode 100644 index ee1e137b0..000000000 --- a/test/transforms/fixtures/wrap-block/with-data/index.js +++ /dev/null @@ -1,28 +0,0 @@ - -import { Data } from '../../../../..' -import assert from 'assert' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 0, - focusKey: first.key, - focusOffset: 0 - }) - - const next = state - .transform() - .moveTo(range) - .wrapBlock('quote', Data.create({ key: 'value' })) - .apply() - - assert.deepEqual( - next.selection.toJS(), - range.toJS() - ) - - return next -} diff --git a/test/transforms/fixtures/wrap-block/with-data/output.yaml b/test/transforms/fixtures/wrap-block/with-data/output.yaml deleted file mode 100644 index 9f139e014..000000000 --- a/test/transforms/fixtures/wrap-block/with-data/output.yaml +++ /dev/null @@ -1,12 +0,0 @@ - -nodes: - - kind: block - type: quote - data: - key: value - nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data-object/index.js b/test/transforms/fixtures/wrap-block/with-object/index.js similarity index 86% rename from test/transforms/fixtures/wrap-block/with-data-object/index.js rename to test/transforms/fixtures/wrap-block/with-object/index.js index 4db6731d1..98545cdd2 100644 --- a/test/transforms/fixtures/wrap-block/with-data-object/index.js +++ b/test/transforms/fixtures/wrap-block/with-object/index.js @@ -15,7 +15,10 @@ export default function (state) { const next = state .transform() .moveTo(range) - .wrapBlock('quote', { key: 'value' }) + .wrapBlock({ + type: 'quote', + data: { key: 'value' } + }) .apply() assert.deepEqual( diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data/input.yaml b/test/transforms/fixtures/wrap-block/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block-at-range/with-data/input.yaml rename to test/transforms/fixtures/wrap-block/with-object/input.yaml diff --git a/test/transforms/fixtures/wrap-block-at-range/with-data/output.yaml b/test/transforms/fixtures/wrap-block/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block-at-range/with-data/output.yaml rename to test/transforms/fixtures/wrap-block/with-object/output.yaml diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data-object/input.yaml b/test/transforms/fixtures/wrap-inline-at-range/with-data-object/input.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/wrap-inline-at-range/with-data-object/input.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data/index.js b/test/transforms/fixtures/wrap-inline-at-range/with-data/index.js deleted file mode 100644 index 3eaa23653..000000000 --- a/test/transforms/fixtures/wrap-inline-at-range/with-data/index.js +++ /dev/null @@ -1,19 +0,0 @@ - -import { Data } from '../../../../..' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 1, - focusKey: first.key, - focusOffset: 3 - }) - - return state - .transform() - .wrapInlineAtRange(range, 'hashtag', Data.create({ key: 'value' })) - .apply() -} diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data/input.yaml b/test/transforms/fixtures/wrap-inline-at-range/with-data/input.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/wrap-inline-at-range/with-data/input.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/unwrap-inline-at-range/with-data-object/index.js b/test/transforms/fixtures/wrap-inline-at-range/with-object/index.js similarity index 77% rename from test/transforms/fixtures/unwrap-inline-at-range/with-data-object/index.js rename to test/transforms/fixtures/wrap-inline-at-range/with-object/index.js index db155f38a..5e39ac689 100644 --- a/test/transforms/fixtures/unwrap-inline-at-range/with-data-object/index.js +++ b/test/transforms/fixtures/wrap-inline-at-range/with-object/index.js @@ -12,6 +12,9 @@ export default function (state) { return state .transform() - .unwrapInlineAtRange(range, 'hashtag', { key: 'one' }) + .wrapInlineAtRange(range, { + type: 'hashtag', + data: { key: 'value' } + }) .apply() } diff --git a/test/transforms/fixtures/wrap-block/with-data-object/input.yaml b/test/transforms/fixtures/wrap-inline-at-range/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block/with-data-object/input.yaml rename to test/transforms/fixtures/wrap-inline-at-range/with-object/input.yaml diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data-object/output.yaml b/test/transforms/fixtures/wrap-inline-at-range/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/wrap-inline-at-range/with-data-object/output.yaml rename to test/transforms/fixtures/wrap-inline-at-range/with-object/output.yaml diff --git a/test/transforms/fixtures/wrap-inline/with-data-object/input.yaml b/test/transforms/fixtures/wrap-inline/with-data-object/input.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/wrap-inline/with-data-object/input.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/wrap-inline/with-data-object/output.yaml b/test/transforms/fixtures/wrap-inline/with-data-object/output.yaml deleted file mode 100644 index ebb90a36a..000000000 --- a/test/transforms/fixtures/wrap-inline/with-data-object/output.yaml +++ /dev/null @@ -1,16 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: value - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/wrap-inline/with-data/index.js b/test/transforms/fixtures/wrap-inline/with-data/index.js deleted file mode 100644 index 68a698c0e..000000000 --- a/test/transforms/fixtures/wrap-inline/with-data/index.js +++ /dev/null @@ -1,35 +0,0 @@ - -import { Data } from '../../../../..' -import assert from 'assert' - -export default function (state) { - const { document, selection } = state - const texts = document.getTexts() - const first = texts.first() - const range = selection.merge({ - anchorKey: first.key, - anchorOffset: 1, - focusKey: first.key, - focusOffset: 3 - }) - - const next = state - .transform() - .moveTo(range) - .wrapInline('hashtag', Data.create({ key: 'value' })) - .apply() - - const updated = next.document.getTexts().get(1) - - assert.deepEqual( - next.selection.toJS(), - range.merge({ - anchorKey: updated.key, - anchorOffset: 0, - focusKey: updated.key, - focusOffset: updated.length - }).toJS() - ) - - return next -} diff --git a/test/transforms/fixtures/wrap-inline/with-data/input.yaml b/test/transforms/fixtures/wrap-inline/with-data/input.yaml deleted file mode 100644 index 27f668fe2..000000000 --- a/test/transforms/fixtures/wrap-inline/with-data/input.yaml +++ /dev/null @@ -1,7 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: word diff --git a/test/transforms/fixtures/wrap-inline/with-data/output.yaml b/test/transforms/fixtures/wrap-inline/with-data/output.yaml deleted file mode 100644 index ebb90a36a..000000000 --- a/test/transforms/fixtures/wrap-inline/with-data/output.yaml +++ /dev/null @@ -1,16 +0,0 @@ - -nodes: - - kind: block - type: paragraph - nodes: - - kind: text - text: w - - kind: inline - type: hashtag - data: - key: value - nodes: - - kind: text - text: or - - kind: text - text: d diff --git a/test/transforms/fixtures/wrap-inline/with-data-object/index.js b/test/transforms/fixtures/wrap-inline/with-object/index.js similarity index 89% rename from test/transforms/fixtures/wrap-inline/with-data-object/index.js rename to test/transforms/fixtures/wrap-inline/with-object/index.js index 5e3ac2f60..74d67394f 100644 --- a/test/transforms/fixtures/wrap-inline/with-data-object/index.js +++ b/test/transforms/fixtures/wrap-inline/with-object/index.js @@ -15,7 +15,10 @@ export default function (state) { const next = state .transform() .moveTo(range) - .wrapInline('hashtag', { key: 'value' }) + .wrapInline({ + type: 'hashtag', + data: { key: 'value' } + }) .apply() const updated = next.document.getTexts().get(1) diff --git a/test/transforms/fixtures/wrap-block/with-data/input.yaml b/test/transforms/fixtures/wrap-inline/with-object/input.yaml similarity index 100% rename from test/transforms/fixtures/wrap-block/with-data/input.yaml rename to test/transforms/fixtures/wrap-inline/with-object/input.yaml diff --git a/test/transforms/fixtures/wrap-inline-at-range/with-data/output.yaml b/test/transforms/fixtures/wrap-inline/with-object/output.yaml similarity index 100% rename from test/transforms/fixtures/wrap-inline-at-range/with-data/output.yaml rename to test/transforms/fixtures/wrap-inline/with-object/output.yaml