diff --git a/test/transforms/fixtures/wrap-block/across-blocks/index.js b/test/transforms/fixtures/wrap-block/across-blocks/index.js new file mode 100644 index 000000000..1a6b91255 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-blocks/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const second = texts.last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .wrapBlock('quote') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-block/across-blocks/input.yaml b/test/transforms/fixtures/wrap-block/across-blocks/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-blocks/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/wrap-block/across-blocks/output.yaml b/test/transforms/fixtures/wrap-block/across-blocks/output.yaml new file mode 100644 index 000000000..87b381f13 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-blocks/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/wrap-block/across-inlines/index.js b/test/transforms/fixtures/wrap-block/across-inlines/index.js new file mode 100644 index 000000000..1a6b91255 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-inlines/index.js @@ -0,0 +1,28 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const second = texts.last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .wrapBlock('quote') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-block/across-inlines/input.yaml b/test/transforms/fixtures/wrap-block/across-inlines/input.yaml new file mode 100644 index 000000000..c31f583e3 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-inlines/input.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/wrap-block/across-inlines/output.yaml b/test/transforms/fixtures/wrap-block/across-inlines/output.yaml new file mode 100644 index 000000000..f4bfc7303 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/across-inlines/output.yaml @@ -0,0 +1,23 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/wrap-block/nested-block/index.js b/test/transforms/fixtures/wrap-block/nested-block/index.js new file mode 100644 index 000000000..826996c9a --- /dev/null +++ b/test/transforms/fixtures/wrap-block/nested-block/index.js @@ -0,0 +1,27 @@ + +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') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-block/nested-block/input.yaml b/test/transforms/fixtures/wrap-block/nested-block/input.yaml new file mode 100644 index 000000000..c4ac2e6c5 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/nested-block/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/nested-block/output.yaml b/test/transforms/fixtures/wrap-block/nested-block/output.yaml new file mode 100644 index 000000000..5dd1c2b59 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/nested-block/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/single-block/index.js b/test/transforms/fixtures/wrap-block/single-block/index.js new file mode 100644 index 000000000..826996c9a --- /dev/null +++ b/test/transforms/fixtures/wrap-block/single-block/index.js @@ -0,0 +1,27 @@ + +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') + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-block/single-block/input.yaml b/test/transforms/fixtures/wrap-block/single-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/single-block/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/single-block/output.yaml b/test/transforms/fixtures/wrap-block/single-block/output.yaml new file mode 100644 index 000000000..c4ac2e6c5 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/single-block/output.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: quote + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data-object/index.js b/test/transforms/fixtures/wrap-block/with-data-object/index.js new file mode 100644 index 000000000..4db6731d1 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data-object/index.js @@ -0,0 +1,27 @@ + +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', { key: 'value' }) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/wrap-block/with-data-object/input.yaml b/test/transforms/fixtures/wrap-block/with-data-object/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data-object/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data-object/output.yaml b/test/transforms/fixtures/wrap-block/with-data-object/output.yaml new file mode 100644 index 000000000..ad222fcde --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data-object/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: quote + data: + key: value + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data/index.js b/test/transforms/fixtures/wrap-block/with-data/index.js new file mode 100644 index 000000000..ee1e137b0 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data/index.js @@ -0,0 +1,28 @@ + +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/input.yaml b/test/transforms/fixtures/wrap-block/with-data/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/wrap-block/with-data/output.yaml b/test/transforms/fixtures/wrap-block/with-data/output.yaml new file mode 100644 index 000000000..ad222fcde --- /dev/null +++ b/test/transforms/fixtures/wrap-block/with-data/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: quote + data: + key: value + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word