@portabletext/editor 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-dts/index.d.ts +7 -1
- package/package.json +16 -19
- package/src/behaviors/_exports/index.ts +0 -1
- package/src/behaviors/behavior.abstract.annotation.ts +0 -77
- package/src/behaviors/behavior.abstract.decorator.ts +0 -39
- package/src/behaviors/behavior.abstract.delete.ts +0 -273
- package/src/behaviors/behavior.abstract.deserialize.ts +0 -232
- package/src/behaviors/behavior.abstract.insert.ts +0 -525
- package/src/behaviors/behavior.abstract.keyboard.ts +0 -189
- package/src/behaviors/behavior.abstract.list-item.ts +0 -70
- package/src/behaviors/behavior.abstract.move.ts +0 -79
- package/src/behaviors/behavior.abstract.select.ts +0 -118
- package/src/behaviors/behavior.abstract.serialize.ts +0 -96
- package/src/behaviors/behavior.abstract.split.ts +0 -170
- package/src/behaviors/behavior.abstract.style.ts +0 -55
- package/src/behaviors/behavior.abstract.ts +0 -139
- package/src/behaviors/behavior.config.ts +0 -7
- package/src/behaviors/behavior.core.annotations.ts +0 -62
- package/src/behaviors/behavior.core.block-element.ts +0 -116
- package/src/behaviors/behavior.core.block-objects.ts +0 -285
- package/src/behaviors/behavior.core.decorators.ts +0 -44
- package/src/behaviors/behavior.core.dnd.ts +0 -356
- package/src/behaviors/behavior.core.insert-break.ts +0 -266
- package/src/behaviors/behavior.core.insert.ts +0 -52
- package/src/behaviors/behavior.core.lists.ts +0 -691
- package/src/behaviors/behavior.core.ts +0 -44
- package/src/behaviors/behavior.perform-event.ts +0 -354
- package/src/behaviors/behavior.types.action.ts +0 -102
- package/src/behaviors/behavior.types.behavior.ts +0 -83
- package/src/behaviors/behavior.types.event.ts +0 -667
- package/src/behaviors/behavior.types.guard.ts +0 -11
- package/src/behaviors/index.ts +0 -17
- package/src/converters/converter.json.ts +0 -53
- package/src/converters/converter.portable-text.deserialize.test.ts +0 -680
- package/src/converters/converter.portable-text.ts +0 -75
- package/src/converters/converter.text-html.deserialize.test.ts +0 -406
- package/src/converters/converter.text-html.serialize.test.ts +0 -246
- package/src/converters/converter.text-html.ts +0 -87
- package/src/converters/converter.text-markdown.ts +0 -67
- package/src/converters/converter.text-plain.test.ts +0 -245
- package/src/converters/converter.text-plain.ts +0 -126
- package/src/converters/converter.types.ts +0 -72
- package/src/converters/converters.core.ts +0 -18
- package/src/editor/Editable.tsx +0 -1012
- package/src/editor/PortableTextEditor.tsx +0 -791
- package/src/editor/components/drop-indicator.tsx +0 -17
- package/src/editor/components/render-block-object.tsx +0 -121
- package/src/editor/components/render-default-object.tsx +0 -21
- package/src/editor/components/render-element.tsx +0 -88
- package/src/editor/components/render-inline-object.tsx +0 -129
- package/src/editor/components/render-leaf.tsx +0 -64
- package/src/editor/components/render-span.tsx +0 -303
- package/src/editor/components/render-text-block.tsx +0 -265
- package/src/editor/components/render-text.tsx +0 -18
- package/src/editor/components/use-core-block-element-behaviors.ts +0 -39
- package/src/editor/create-editor.ts +0 -323
- package/src/editor/create-slate-editor.tsx +0 -64
- package/src/editor/editor-actor-context.ts +0 -4
- package/src/editor/editor-context.tsx +0 -7
- package/src/editor/editor-dom.ts +0 -220
- package/src/editor/editor-machine.ts +0 -751
- package/src/editor/editor-provider.tsx +0 -111
- package/src/editor/editor-schema.ts +0 -6
- package/src/editor/editor-selector.ts +0 -89
- package/src/editor/editor-snapshot.ts +0 -68
- package/src/editor/event-to-change.tsx +0 -49
- package/src/editor/hooks/usePortableTextEditor.ts +0 -25
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +0 -28
- package/src/editor/mutation-machine.ts +0 -322
- package/src/editor/plugins/create-with-event-listeners.ts +0 -271
- package/src/editor/plugins/createWithEditableAPI.ts +0 -529
- package/src/editor/plugins/createWithHotKeys.ts +0 -68
- package/src/editor/plugins/createWithObjectKeys.ts +0 -289
- package/src/editor/plugins/createWithPatches.ts +0 -272
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +0 -559
- package/src/editor/plugins/createWithSchemaTypes.ts +0 -121
- package/src/editor/plugins/slate-plugin.update-selection.ts +0 -51
- package/src/editor/plugins/slate-plugin.update-value.ts +0 -46
- package/src/editor/plugins/with-plugins.ts +0 -69
- package/src/editor/range-decorations-machine.ts +0 -421
- package/src/editor/relay-actor-context.ts +0 -4
- package/src/editor/relay-machine.ts +0 -152
- package/src/editor/sync-machine.ts +0 -961
- package/src/editor/use-editor.ts +0 -27
- package/src/editor/validate-selection-machine.test.ts +0 -47
- package/src/editor/validate-selection-machine.ts +0 -149
- package/src/editor/weakMaps.ts +0 -15
- package/src/editor/with-normalizing-node.ts +0 -14
- package/src/editor/with-performing-behavior-operation.ts +0 -21
- package/src/editor/withChanges.ts +0 -13
- package/src/editor/without-normalizing-conditional.ts +0 -13
- package/src/editor/withoutPatching.ts +0 -14
- package/src/editor.ts +0 -59
- package/src/history/behavior.operation.history.redo.ts +0 -67
- package/src/history/behavior.operation.history.undo.ts +0 -71
- package/src/history/event.history.undo.test.tsx +0 -672
- package/src/history/history.preserving-keys.test.tsx +0 -112
- package/src/history/remote-patches.ts +0 -20
- package/src/history/slate-plugin.history.ts +0 -142
- package/src/history/slate-plugin.redoing.ts +0 -21
- package/src/history/slate-plugin.undoing.ts +0 -21
- package/src/history/slate-plugin.without-history.ts +0 -23
- package/src/history/transform-operation.ts +0 -245
- package/src/history/undo-redo-collaboration.test.tsx +0 -541
- package/src/history/undo-redo.feature +0 -125
- package/src/history/undo-redo.test.tsx +0 -195
- package/src/history/undo-step.ts +0 -148
- package/src/index.ts +0 -98
- package/src/internal-utils/__tests__/ranges.test.ts +0 -23
- package/src/internal-utils/__tests__/values.test.ts +0 -110
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +0 -1861
- package/src/internal-utils/apply-operation-to-portable-text.ts +0 -615
- package/src/internal-utils/applyPatch.ts +0 -644
- package/src/internal-utils/block-keys.ts +0 -9
- package/src/internal-utils/build-index-maps.test.ts +0 -464
- package/src/internal-utils/build-index-maps.ts +0 -131
- package/src/internal-utils/collapse-selection.ts +0 -36
- package/src/internal-utils/compound-client-rect.ts +0 -28
- package/src/internal-utils/create-placeholder-block.ts +0 -21
- package/src/internal-utils/create-test-snapshot.ts +0 -28
- package/src/internal-utils/debug.ts +0 -12
- package/src/internal-utils/editor-selection.test.ts +0 -44
- package/src/internal-utils/editor-selection.ts +0 -56
- package/src/internal-utils/event-position.ts +0 -318
- package/src/internal-utils/global-scope.ts +0 -27
- package/src/internal-utils/globally-scoped-context.ts +0 -39
- package/src/internal-utils/is-hotkey.test.ts +0 -114
- package/src/internal-utils/is-hotkey.ts +0 -209
- package/src/internal-utils/mime-type.ts +0 -1
- package/src/internal-utils/move-range-by-operation.ts +0 -19
- package/src/internal-utils/operation-to-patches.test.ts +0 -522
- package/src/internal-utils/operation-to-patches.ts +0 -571
- package/src/internal-utils/portable-text-node.ts +0 -209
- package/src/internal-utils/schema.ts +0 -8
- package/src/internal-utils/selection-block-keys.ts +0 -20
- package/src/internal-utils/selection-focus-text.ts +0 -40
- package/src/internal-utils/selection-text.test.ts +0 -32
- package/src/internal-utils/selection-text.ts +0 -21
- package/src/internal-utils/selection.ts +0 -77
- package/src/internal-utils/sibling-utils.ts +0 -55
- package/src/internal-utils/slate-utils.test.tsx +0 -121
- package/src/internal-utils/slate-utils.ts +0 -417
- package/src/internal-utils/split-string.ts +0 -12
- package/src/internal-utils/stop-actor.ts +0 -43
- package/src/internal-utils/string-overlap.test.ts +0 -14
- package/src/internal-utils/string-overlap.ts +0 -28
- package/src/internal-utils/string-utils.ts +0 -7
- package/src/internal-utils/text-block-key.test.ts +0 -41
- package/src/internal-utils/text-block-key.ts +0 -26
- package/src/internal-utils/text-marks.test.ts +0 -41
- package/src/internal-utils/text-marks.ts +0 -22
- package/src/internal-utils/text-selection.test.ts +0 -211
- package/src/internal-utils/text-selection.ts +0 -121
- package/src/internal-utils/to-slate-range.test.ts +0 -278
- package/src/internal-utils/to-slate-range.ts +0 -171
- package/src/internal-utils/validateValue.ts +0 -443
- package/src/internal-utils/value-annotations.ts +0 -33
- package/src/internal-utils/values.test.ts +0 -282
- package/src/internal-utils/values.ts +0 -266
- package/src/keyboard-shortcuts/default-keyboard-shortcuts.ts +0 -146
- package/src/operations/behavior.operation.annotation.add.ts +0 -99
- package/src/operations/behavior.operation.annotation.remove.ts +0 -150
- package/src/operations/behavior.operation.block.set.ts +0 -104
- package/src/operations/behavior.operation.block.unset.ts +0 -54
- package/src/operations/behavior.operation.child.set.ts +0 -107
- package/src/operations/behavior.operation.child.unset.ts +0 -116
- package/src/operations/behavior.operation.decorator.add.ts +0 -131
- package/src/operations/behavior.operation.delete.ts +0 -294
- package/src/operations/behavior.operation.insert.block.ts +0 -495
- package/src/operations/behavior.operation.insert.child.ts +0 -129
- package/src/operations/behavior.operation.insert.text.ts +0 -8
- package/src/operations/behavior.operation.move.backward.ts +0 -12
- package/src/operations/behavior.operation.move.block.ts +0 -44
- package/src/operations/behavior.operation.move.forward.ts +0 -11
- package/src/operations/behavior.operation.select.ts +0 -27
- package/src/operations/behavior.operations.ts +0 -221
- package/src/plugins/_exports/index.ts +0 -1
- package/src/plugins/index.ts +0 -3
- package/src/plugins/plugin.behavior.tsx +0 -24
- package/src/plugins/plugin.editor-ref.tsx +0 -17
- package/src/plugins/plugin.event-listener.tsx +0 -68
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +0 -71
- package/src/plugins/plugin.internal.auto-close-brackets.ts +0 -62
- package/src/plugins/plugin.internal.change-ref.tsx +0 -19
- package/src/plugins/plugin.internal.portable-text-editor-ref.tsx +0 -16
- package/src/plugins/plugin.internal.slate-editor-ref.tsx +0 -15
- package/src/priority/priority.core.ts +0 -3
- package/src/priority/priority.sort.test.ts +0 -319
- package/src/priority/priority.sort.ts +0 -123
- package/src/priority/priority.types.ts +0 -24
- package/src/selectors/_exports/index.ts +0 -1
- package/src/selectors/drag-selection.test.ts +0 -578
- package/src/selectors/drag-selection.ts +0 -118
- package/src/selectors/index.ts +0 -54
- package/src/selectors/selector.get-active-annotation-marks.ts +0 -12
- package/src/selectors/selector.get-active-annotations.ts +0 -36
- package/src/selectors/selector.get-active-decorators.ts +0 -29
- package/src/selectors/selector.get-active-list-item.ts +0 -38
- package/src/selectors/selector.get-active-style.ts +0 -38
- package/src/selectors/selector.get-anchor-block.ts +0 -22
- package/src/selectors/selector.get-anchor-child.ts +0 -36
- package/src/selectors/selector.get-anchor-span.ts +0 -17
- package/src/selectors/selector.get-anchor-text-block.ts +0 -18
- package/src/selectors/selector.get-block-offsets.ts +0 -34
- package/src/selectors/selector.get-caret-word-selection.test.ts +0 -284
- package/src/selectors/selector.get-caret-word-selection.ts +0 -134
- package/src/selectors/selector.get-first-block.ts +0 -14
- package/src/selectors/selector.get-focus-block-object.ts +0 -18
- package/src/selectors/selector.get-focus-block.ts +0 -23
- package/src/selectors/selector.get-focus-child.ts +0 -36
- package/src/selectors/selector.get-focus-inline-object.ts +0 -17
- package/src/selectors/selector.get-focus-list-block.ts +0 -18
- package/src/selectors/selector.get-focus-span.ts +0 -18
- package/src/selectors/selector.get-focus-text-block.ts +0 -18
- package/src/selectors/selector.get-last-block.ts +0 -16
- package/src/selectors/selector.get-mark-state.test.ts +0 -325
- package/src/selectors/selector.get-mark-state.ts +0 -263
- package/src/selectors/selector.get-next-block.ts +0 -29
- package/src/selectors/selector.get-next-inline-object.ts +0 -53
- package/src/selectors/selector.get-next-inline-objects.ts +0 -50
- package/src/selectors/selector.get-next-span.ts +0 -56
- package/src/selectors/selector.get-previous-block.ts +0 -29
- package/src/selectors/selector.get-previous-inline-object.ts +0 -50
- package/src/selectors/selector.get-previous-inline-objects.ts +0 -47
- package/src/selectors/selector.get-previous-span.ts +0 -53
- package/src/selectors/selector.get-selected-blocks.ts +0 -61
- package/src/selectors/selector.get-selected-spans.test.ts +0 -347
- package/src/selectors/selector.get-selected-spans.ts +0 -155
- package/src/selectors/selector.get-selected-text-blocks.ts +0 -73
- package/src/selectors/selector.get-selected-value.test.ts +0 -834
- package/src/selectors/selector.get-selected-value.ts +0 -66
- package/src/selectors/selector.get-selection-end-block.ts +0 -33
- package/src/selectors/selector.get-selection-end-child.ts +0 -33
- package/src/selectors/selector.get-selection-end-point.ts +0 -17
- package/src/selectors/selector.get-selection-start-block.ts +0 -33
- package/src/selectors/selector.get-selection-start-child.ts +0 -33
- package/src/selectors/selector.get-selection-start-point.ts +0 -17
- package/src/selectors/selector.get-selection-text.test.ts +0 -421
- package/src/selectors/selector.get-selection-text.ts +0 -27
- package/src/selectors/selector.get-selection.ts +0 -9
- package/src/selectors/selector.get-text-after.ts +0 -46
- package/src/selectors/selector.get-text-before.ts +0 -46
- package/src/selectors/selector.get-value.ts +0 -11
- package/src/selectors/selector.is-active-annotation.test.ts +0 -320
- package/src/selectors/selector.is-active-annotation.ts +0 -52
- package/src/selectors/selector.is-active-decorator.test.ts +0 -136
- package/src/selectors/selector.is-active-decorator.ts +0 -24
- package/src/selectors/selector.is-active-list-item.ts +0 -13
- package/src/selectors/selector.is-active-style.ts +0 -13
- package/src/selectors/selector.is-at-the-end-of-block.ts +0 -30
- package/src/selectors/selector.is-at-the-start-of-block.ts +0 -30
- package/src/selectors/selector.is-overlapping-selection.test.ts +0 -304
- package/src/selectors/selector.is-overlapping-selection.ts +0 -181
- package/src/selectors/selector.is-point-after-selection.ts +0 -97
- package/src/selectors/selector.is-point-before-selection.ts +0 -97
- package/src/selectors/selector.is-selecting-entire-blocks.ts +0 -43
- package/src/selectors/selector.is-selection-collapsed.ts +0 -17
- package/src/selectors/selector.is-selection-expanded.test.ts +0 -63
- package/src/selectors/selector.is-selection-expanded.ts +0 -9
- package/src/test/_exports/index.ts +0 -1
- package/src/test/gherkin-parameter-types.ts +0 -112
- package/src/test/index.ts +0 -1
- package/src/test/vitest/_exports/index.ts +0 -1
- package/src/test/vitest/index.ts +0 -3
- package/src/test/vitest/step-context.ts +0 -13
- package/src/test/vitest/step-definitions.tsx +0 -960
- package/src/test/vitest/test-editor.tsx +0 -198
- package/src/type-utils.ts +0 -29
- package/src/types/block-offset.ts +0 -9
- package/src/types/block-with-optional-key.ts +0 -25
- package/src/types/editor.ts +0 -509
- package/src/types/options.ts +0 -13
- package/src/types/paths.ts +0 -35
- package/src/types/slate-editor.ts +0 -50
- package/src/types/slate.ts +0 -27
- package/src/utils/_exports/index.ts +0 -1
- package/src/utils/asserters.ts +0 -9
- package/src/utils/index.ts +0 -24
- package/src/utils/key-generator.ts +0 -33
- package/src/utils/parse-blocks.test.ts +0 -836
- package/src/utils/parse-blocks.ts +0 -504
- package/src/utils/util.at-the-beginning-of-block.ts +0 -32
- package/src/utils/util.block-offset-to-block-selection-point.ts +0 -28
- package/src/utils/util.block-offset-to-selection-point.ts +0 -33
- package/src/utils/util.block-offset.test.ts +0 -375
- package/src/utils/util.block-offset.ts +0 -136
- package/src/utils/util.block-offsets-to-selection.ts +0 -38
- package/src/utils/util.child-selection-point-to-block-offset.ts +0 -51
- package/src/utils/util.get-block-end-point.ts +0 -35
- package/src/utils/util.get-block-start-point.ts +0 -31
- package/src/utils/util.get-selection-end-point.ts +0 -20
- package/src/utils/util.get-selection-start-point.ts +0 -20
- package/src/utils/util.get-text-block-text.ts +0 -8
- package/src/utils/util.is-empty-text-block.ts +0 -21
- package/src/utils/util.is-equal-selection-points.ts +0 -13
- package/src/utils/util.is-equal-selections.ts +0 -20
- package/src/utils/util.is-keyed-segment.ts +0 -8
- package/src/utils/util.is-selection-collapsed.ts +0 -16
- package/src/utils/util.is-selection-expanded.ts +0 -13
- package/src/utils/util.merge-text-blocks.ts +0 -40
- package/src/utils/util.reverse-selection.ts +0 -26
- package/src/utils/util.selection-point-to-block-offset.ts +0 -30
- package/src/utils/util.selection-point.ts +0 -22
- package/src/utils/util.slice-blocks.ts +0 -221
- package/src/utils/util.slice-text-block.test.ts +0 -190
- package/src/utils/util.slice-text-block.ts +0 -89
- package/src/utils/util.split-text-block.ts +0 -54
|
@@ -1,960 +0,0 @@
|
|
|
1
|
-
import {defineSchema} from '@portabletext/schema'
|
|
2
|
-
import {getTersePt, parseTersePt} from '@portabletext/test'
|
|
3
|
-
import {Given, Then, When} from 'racejar'
|
|
4
|
-
import {assert, expect, vi} from 'vitest'
|
|
5
|
-
import {userEvent} from 'vitest/browser'
|
|
6
|
-
import {getEditorSelection} from '../../internal-utils/editor-selection'
|
|
7
|
-
import {IS_MAC} from '../../internal-utils/is-hotkey'
|
|
8
|
-
import {getSelectionText} from '../../internal-utils/selection-text'
|
|
9
|
-
import {getTextBlockKey} from '../../internal-utils/text-block-key'
|
|
10
|
-
import {getTextMarks} from '../../internal-utils/text-marks'
|
|
11
|
-
import {
|
|
12
|
-
getSelectionAfterText,
|
|
13
|
-
getSelectionBeforeText,
|
|
14
|
-
getTextSelection,
|
|
15
|
-
} from '../../internal-utils/text-selection'
|
|
16
|
-
import {getValueAnnotations} from '../../internal-utils/value-annotations'
|
|
17
|
-
import {createTestEditor, createTestEditors} from '../../test/vitest'
|
|
18
|
-
import {
|
|
19
|
-
parseBlocks,
|
|
20
|
-
parseInlineObject,
|
|
21
|
-
parseSpan,
|
|
22
|
-
} from '../../utils/parse-blocks'
|
|
23
|
-
import {spanSelectionPointToBlockOffset} from '../../utils/util.block-offset'
|
|
24
|
-
import {reverseSelection} from '../../utils/util.reverse-selection'
|
|
25
|
-
import {selectionPointToBlockOffset} from '../../utils/util.selection-point-to-block-offset'
|
|
26
|
-
import type {Parameter} from '../gherkin-parameter-types'
|
|
27
|
-
import type {Context} from './step-context'
|
|
28
|
-
|
|
29
|
-
const schemaDefinition = defineSchema({
|
|
30
|
-
annotations: [{name: 'comment'}, {name: 'link'}],
|
|
31
|
-
decorators: [{name: 'em'}, {name: 'strong'}],
|
|
32
|
-
blockObjects: [{name: 'image'}, {name: 'break'}],
|
|
33
|
-
inlineObjects: [{name: 'stock-ticker'}],
|
|
34
|
-
lists: [{name: 'bullet'}, {name: 'number'}],
|
|
35
|
-
styles: [
|
|
36
|
-
{name: 'normal'},
|
|
37
|
-
{name: 'h1'},
|
|
38
|
-
{name: 'h2'},
|
|
39
|
-
{name: 'h3'},
|
|
40
|
-
{name: 'h4'},
|
|
41
|
-
{name: 'h5'},
|
|
42
|
-
{name: 'h6'},
|
|
43
|
-
{name: 'blockquote'},
|
|
44
|
-
],
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
export const stepDefinitions = [
|
|
51
|
-
Given('one editor', async (context: Context) => {
|
|
52
|
-
const {editor, locator} = await createTestEditor({
|
|
53
|
-
schemaDefinition,
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
context.locator = locator
|
|
57
|
-
context.editor = editor
|
|
58
|
-
}),
|
|
59
|
-
Given('two editors', async (context: Context) => {
|
|
60
|
-
const {editor, locator, editorB, locatorB} = await createTestEditors({
|
|
61
|
-
schemaDefinition,
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
context.locator = locator
|
|
65
|
-
context.editor = editor
|
|
66
|
-
context.locatorB = locatorB
|
|
67
|
-
context.editorB = editorB
|
|
68
|
-
}),
|
|
69
|
-
|
|
70
|
-
Given('a global keymap', (context: Context) => {
|
|
71
|
-
context.keyMap = new Map()
|
|
72
|
-
}),
|
|
73
|
-
|
|
74
|
-
When('the editor is focused', async (context: Context) => {
|
|
75
|
-
await userEvent.click(context.locator)
|
|
76
|
-
}),
|
|
77
|
-
|
|
78
|
-
When('Editor B is focused', async (context: Context) => {
|
|
79
|
-
await userEvent.click(context.locatorB)
|
|
80
|
-
}),
|
|
81
|
-
|
|
82
|
-
Given(
|
|
83
|
-
'the text {terse-pt}',
|
|
84
|
-
(context: Context, tersePt: Parameter['tersePt']) => {
|
|
85
|
-
const blocks = parseTersePt(
|
|
86
|
-
{
|
|
87
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
88
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
89
|
-
},
|
|
90
|
-
tersePt,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
context.editor.send({
|
|
94
|
-
type: 'insert.blocks',
|
|
95
|
-
blocks,
|
|
96
|
-
placement: 'auto',
|
|
97
|
-
select: 'end',
|
|
98
|
-
})
|
|
99
|
-
},
|
|
100
|
-
),
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Block steps
|
|
104
|
-
*/
|
|
105
|
-
Given(
|
|
106
|
-
'blocks {placement}',
|
|
107
|
-
(context: Context, placement: Parameter['placement'], blocks: string) => {
|
|
108
|
-
context.editor.send({
|
|
109
|
-
type: 'insert.blocks',
|
|
110
|
-
blocks: parseBlocks({
|
|
111
|
-
context: {
|
|
112
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
113
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
114
|
-
},
|
|
115
|
-
blocks: JSON.parse(blocks),
|
|
116
|
-
options: {
|
|
117
|
-
normalize: false,
|
|
118
|
-
removeUnusedMarkDefs: false,
|
|
119
|
-
validateFields: true,
|
|
120
|
-
},
|
|
121
|
-
}),
|
|
122
|
-
placement,
|
|
123
|
-
})
|
|
124
|
-
},
|
|
125
|
-
),
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Child steps
|
|
129
|
-
*/
|
|
130
|
-
When('a child is inserted', (context: Context, child: string) => {
|
|
131
|
-
const parsedChild =
|
|
132
|
-
parseSpan({
|
|
133
|
-
context: {
|
|
134
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
135
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
136
|
-
},
|
|
137
|
-
span: JSON.parse(child),
|
|
138
|
-
markDefKeyMap: new Map(),
|
|
139
|
-
options: {validateFields: true},
|
|
140
|
-
}) ??
|
|
141
|
-
parseInlineObject({
|
|
142
|
-
context: {
|
|
143
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
144
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
145
|
-
},
|
|
146
|
-
inlineObject: JSON.parse(child),
|
|
147
|
-
options: {validateFields: true},
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
if (!parsedChild) {
|
|
151
|
-
throw new Error(`Unable to parse child ${child}`)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
context.editor.send({
|
|
155
|
-
type: 'insert.child',
|
|
156
|
-
child: parsedChild,
|
|
157
|
-
})
|
|
158
|
-
}),
|
|
159
|
-
When(
|
|
160
|
-
'a(n) {inline-object} is inserted',
|
|
161
|
-
(context: Context, inlineObject: Parameter['inlineObject']) => {
|
|
162
|
-
context.editor.send({
|
|
163
|
-
type: 'insert.inline object',
|
|
164
|
-
inlineObject: {
|
|
165
|
-
name: inlineObject,
|
|
166
|
-
value: {},
|
|
167
|
-
},
|
|
168
|
-
})
|
|
169
|
-
},
|
|
170
|
-
),
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Text steps
|
|
174
|
-
*/
|
|
175
|
-
Given(
|
|
176
|
-
'a block {key} with text {text}',
|
|
177
|
-
(context: Context, key: string, text: Parameter['text']) => {
|
|
178
|
-
context.editor.send({
|
|
179
|
-
type: 'insert.block',
|
|
180
|
-
block: {
|
|
181
|
-
_key: key,
|
|
182
|
-
_type: 'block',
|
|
183
|
-
children: [{_type: 'span', text, marks: []}],
|
|
184
|
-
},
|
|
185
|
-
placement: 'auto',
|
|
186
|
-
select: 'end',
|
|
187
|
-
})
|
|
188
|
-
},
|
|
189
|
-
),
|
|
190
|
-
When('{string} is typed', async (context: Context, text: string) => {
|
|
191
|
-
await userEvent.type(context.locator, text)
|
|
192
|
-
}),
|
|
193
|
-
When(
|
|
194
|
-
'{string} is typed in Editor B',
|
|
195
|
-
async (context: Context, text: string) => {
|
|
196
|
-
await userEvent.type(context.locatorB, text)
|
|
197
|
-
},
|
|
198
|
-
),
|
|
199
|
-
When('{string} is inserted', (context: Context, text: string) => {
|
|
200
|
-
context.editor.send({type: 'insert.text', text})
|
|
201
|
-
}),
|
|
202
|
-
Then(
|
|
203
|
-
'{terse-pt} is in block {key}',
|
|
204
|
-
(context: Context, text: Array<string>, key: string) => {
|
|
205
|
-
const string = text.at(0)
|
|
206
|
-
|
|
207
|
-
if (string === undefined) {
|
|
208
|
-
assert.fail('Expected at least one text string')
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (text.length > 1) {
|
|
212
|
-
assert.fail('Expected at most one text string')
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
expect(
|
|
216
|
-
getTextBlockKey(context.editor.getSnapshot().context, string),
|
|
217
|
-
).toBe(key)
|
|
218
|
-
},
|
|
219
|
-
),
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Button steps
|
|
223
|
-
*/
|
|
224
|
-
When(
|
|
225
|
-
'{button} is pressed',
|
|
226
|
-
async (context: Context, button: Parameter['button']) => {
|
|
227
|
-
const previousSelection = context.editor.getSnapshot().context.selection
|
|
228
|
-
await userEvent.keyboard(button)
|
|
229
|
-
|
|
230
|
-
// Small delay to allow the browser to process the event
|
|
231
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
232
|
-
|
|
233
|
-
await vi.waitFor(() => {
|
|
234
|
-
const currentSelection = context.editor.getSnapshot().context.selection
|
|
235
|
-
|
|
236
|
-
if (currentSelection) {
|
|
237
|
-
expect(currentSelection).not.toBe(previousSelection)
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
},
|
|
241
|
-
),
|
|
242
|
-
When(
|
|
243
|
-
'{button} is pressed in Editor B',
|
|
244
|
-
async (context: Context, button: Parameter['button']) => {
|
|
245
|
-
const previousSelection = context.editorB.getSnapshot().context.selection
|
|
246
|
-
await userEvent.keyboard(button)
|
|
247
|
-
|
|
248
|
-
// Small delay to allow the browser to process the event
|
|
249
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
250
|
-
|
|
251
|
-
await vi.waitFor(() => {
|
|
252
|
-
const currentSelection = context.editorB.getSnapshot().context.selection
|
|
253
|
-
|
|
254
|
-
if (currentSelection) {
|
|
255
|
-
expect(currentSelection).not.toBe(previousSelection)
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
},
|
|
259
|
-
),
|
|
260
|
-
When(
|
|
261
|
-
'{button} is pressed {int} times',
|
|
262
|
-
async (context: Context, button: Parameter['button'], times: number) => {
|
|
263
|
-
for (let i = 0; i < times; i++) {
|
|
264
|
-
const previousSelection = context.editor.getSnapshot().context.selection
|
|
265
|
-
await userEvent.keyboard(button)
|
|
266
|
-
|
|
267
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
268
|
-
|
|
269
|
-
await vi.waitFor(() => {
|
|
270
|
-
const currentSelection =
|
|
271
|
-
context.editor.getSnapshot().context.selection
|
|
272
|
-
|
|
273
|
-
if (currentSelection) {
|
|
274
|
-
expect(currentSelection).not.toBe(previousSelection)
|
|
275
|
-
}
|
|
276
|
-
})
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
),
|
|
280
|
-
When(
|
|
281
|
-
'{button} is pressed {int} times in Editor B',
|
|
282
|
-
async (context: Context, button: Parameter['button'], times: number) => {
|
|
283
|
-
for (let i = 0; i < times; i++) {
|
|
284
|
-
const previousSelection =
|
|
285
|
-
context.editorB.getSnapshot().context.selection
|
|
286
|
-
await userEvent.keyboard(button)
|
|
287
|
-
|
|
288
|
-
// Small delay to allow the browser to process the event
|
|
289
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
290
|
-
|
|
291
|
-
await vi.waitFor(() => {
|
|
292
|
-
const currentSelection =
|
|
293
|
-
context.editorB.getSnapshot().context.selection
|
|
294
|
-
|
|
295
|
-
if (currentSelection) {
|
|
296
|
-
expect(currentSelection).not.toBe(previousSelection)
|
|
297
|
-
}
|
|
298
|
-
})
|
|
299
|
-
}
|
|
300
|
-
},
|
|
301
|
-
),
|
|
302
|
-
When(
|
|
303
|
-
'{shortcut} is pressed',
|
|
304
|
-
async (context: Context, shortcut: Parameter['shortcut']) => {
|
|
305
|
-
const shortcuts: Record<Parameter['shortcut'], string> = {
|
|
306
|
-
'deleteWord.backward': IS_MAC
|
|
307
|
-
? '{Alt>}{Backspace}{/Alt}'
|
|
308
|
-
: '{Control>}{Backspace}{/Control}',
|
|
309
|
-
'deleteWord.forward': IS_MAC
|
|
310
|
-
? '{Alt>}{Delete}{/Alt}'
|
|
311
|
-
: '{Control>}{Delete}{/Control}',
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const previousSelection = context.editor.getSnapshot().context.selection
|
|
315
|
-
await userEvent.keyboard(shortcuts[shortcut])
|
|
316
|
-
|
|
317
|
-
// Small delay to allow the browser to process the event
|
|
318
|
-
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
319
|
-
|
|
320
|
-
await vi.waitFor(() => {
|
|
321
|
-
const currentSelection = context.editor.getSnapshot().context.selection
|
|
322
|
-
|
|
323
|
-
if (currentSelection) {
|
|
324
|
-
expect(currentSelection).not.toBe(previousSelection)
|
|
325
|
-
}
|
|
326
|
-
})
|
|
327
|
-
},
|
|
328
|
-
),
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Selection steps
|
|
332
|
-
*/
|
|
333
|
-
When(
|
|
334
|
-
'the caret is put before {string}',
|
|
335
|
-
async (context: Context, text: string) => {
|
|
336
|
-
await vi.waitFor(() => {
|
|
337
|
-
const selection = getSelectionBeforeText(
|
|
338
|
-
context.editor.getSnapshot().context,
|
|
339
|
-
text,
|
|
340
|
-
)
|
|
341
|
-
expect(selection).not.toBeNull()
|
|
342
|
-
|
|
343
|
-
context.editor.send({
|
|
344
|
-
type: 'select',
|
|
345
|
-
at: selection,
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
349
|
-
selection,
|
|
350
|
-
)
|
|
351
|
-
})
|
|
352
|
-
},
|
|
353
|
-
),
|
|
354
|
-
When(
|
|
355
|
-
'the caret is put before {string} in Editor B',
|
|
356
|
-
async (context: Context, text: string) => {
|
|
357
|
-
await vi.waitFor(() => {
|
|
358
|
-
const selection = getSelectionBeforeText(
|
|
359
|
-
context.editorB.getSnapshot().context,
|
|
360
|
-
text,
|
|
361
|
-
)
|
|
362
|
-
expect(selection).not.toBeNull()
|
|
363
|
-
|
|
364
|
-
context.editorB.send({
|
|
365
|
-
type: 'select',
|
|
366
|
-
at: selection,
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
expect(context.editorB.getSnapshot().context.selection).toEqual(
|
|
370
|
-
selection,
|
|
371
|
-
)
|
|
372
|
-
})
|
|
373
|
-
},
|
|
374
|
-
),
|
|
375
|
-
Then(
|
|
376
|
-
'the caret is before {string}',
|
|
377
|
-
async (context: Context, text: string) => {
|
|
378
|
-
await vi.waitFor(() => {
|
|
379
|
-
const selection = getSelectionBeforeText(
|
|
380
|
-
context.editor.getSnapshot().context,
|
|
381
|
-
text,
|
|
382
|
-
)
|
|
383
|
-
expect(selection).not.toBeNull()
|
|
384
|
-
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
385
|
-
selection,
|
|
386
|
-
)
|
|
387
|
-
})
|
|
388
|
-
},
|
|
389
|
-
),
|
|
390
|
-
When(
|
|
391
|
-
'the caret is put after {string}',
|
|
392
|
-
async (context: Context, text: string) => {
|
|
393
|
-
await vi.waitFor(() => {
|
|
394
|
-
const selection = getSelectionAfterText(
|
|
395
|
-
context.editor.getSnapshot().context,
|
|
396
|
-
text,
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
expect(selection).not.toBeNull()
|
|
400
|
-
|
|
401
|
-
context.editor.send({
|
|
402
|
-
type: 'select',
|
|
403
|
-
at: selection,
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
407
|
-
selection,
|
|
408
|
-
)
|
|
409
|
-
})
|
|
410
|
-
},
|
|
411
|
-
),
|
|
412
|
-
When(
|
|
413
|
-
'the caret is put after {string} in Editor B',
|
|
414
|
-
async (context: Context, text: string) => {
|
|
415
|
-
await vi.waitFor(() => {
|
|
416
|
-
const selection = getSelectionAfterText(
|
|
417
|
-
context.editorB.getSnapshot().context,
|
|
418
|
-
text,
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
expect(selection).not.toBeNull()
|
|
422
|
-
|
|
423
|
-
context.editorB.send({
|
|
424
|
-
type: 'select',
|
|
425
|
-
at: selection,
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
expect(context.editorB.getSnapshot().context.selection).toEqual(
|
|
429
|
-
selection,
|
|
430
|
-
)
|
|
431
|
-
})
|
|
432
|
-
},
|
|
433
|
-
),
|
|
434
|
-
Then(
|
|
435
|
-
'the caret is after {string}',
|
|
436
|
-
async (context: Context, text: string) => {
|
|
437
|
-
await vi.waitFor(() => {
|
|
438
|
-
const selection = getSelectionAfterText(
|
|
439
|
-
context.editor.getSnapshot().context,
|
|
440
|
-
text,
|
|
441
|
-
)
|
|
442
|
-
expect(selection).not.toBeNull()
|
|
443
|
-
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
444
|
-
selection,
|
|
445
|
-
)
|
|
446
|
-
})
|
|
447
|
-
},
|
|
448
|
-
),
|
|
449
|
-
Then('nothing is selected', async (context: Context) => {
|
|
450
|
-
await vi.waitFor(() => {
|
|
451
|
-
expect(context.editor.getSnapshot().context.selection).toBeNull()
|
|
452
|
-
})
|
|
453
|
-
}),
|
|
454
|
-
When('everything is selected', (context: Context) => {
|
|
455
|
-
const editorSelection = getEditorSelection(
|
|
456
|
-
context.editor.getSnapshot().context,
|
|
457
|
-
)
|
|
458
|
-
|
|
459
|
-
context.editor.send({
|
|
460
|
-
type: 'select',
|
|
461
|
-
at: editorSelection,
|
|
462
|
-
})
|
|
463
|
-
}),
|
|
464
|
-
When('everything is selected backwards', (context: Context) => {
|
|
465
|
-
const editorSelection = reverseSelection(
|
|
466
|
-
getEditorSelection(context.editor.getSnapshot().context),
|
|
467
|
-
)
|
|
468
|
-
|
|
469
|
-
context.editor.send({
|
|
470
|
-
type: 'select',
|
|
471
|
-
at: editorSelection,
|
|
472
|
-
})
|
|
473
|
-
}),
|
|
474
|
-
When('{string} is selected', async (context: Context, text: string) => {
|
|
475
|
-
await vi.waitFor(() => {
|
|
476
|
-
const selection = getTextSelection(
|
|
477
|
-
context.editor.getSnapshot().context,
|
|
478
|
-
text,
|
|
479
|
-
)
|
|
480
|
-
expect(selection).not.toBeNull()
|
|
481
|
-
|
|
482
|
-
context.editor.send({
|
|
483
|
-
type: 'select',
|
|
484
|
-
at: selection,
|
|
485
|
-
})
|
|
486
|
-
})
|
|
487
|
-
}),
|
|
488
|
-
When(
|
|
489
|
-
'{string} is selected {direction}',
|
|
490
|
-
async (
|
|
491
|
-
context: Context,
|
|
492
|
-
text: string,
|
|
493
|
-
direction: Parameter['direction'],
|
|
494
|
-
) => {
|
|
495
|
-
await vi.waitFor(() => {
|
|
496
|
-
const selection = getTextSelection(
|
|
497
|
-
context.editor.getSnapshot().context,
|
|
498
|
-
text,
|
|
499
|
-
)
|
|
500
|
-
expect(selection).not.toBeNull()
|
|
501
|
-
|
|
502
|
-
context.editor.send({
|
|
503
|
-
type: 'select',
|
|
504
|
-
at:
|
|
505
|
-
direction === 'forwards' ? selection : reverseSelection(selection),
|
|
506
|
-
})
|
|
507
|
-
})
|
|
508
|
-
},
|
|
509
|
-
),
|
|
510
|
-
When(
|
|
511
|
-
'{string} is selected backwards',
|
|
512
|
-
async (context: Context, text: string) => {
|
|
513
|
-
await vi.waitFor(() => {
|
|
514
|
-
const selection = reverseSelection(
|
|
515
|
-
getTextSelection(context.editor.getSnapshot().context, text),
|
|
516
|
-
)
|
|
517
|
-
expect(selection).not.toBeNull()
|
|
518
|
-
|
|
519
|
-
context.editor.send({
|
|
520
|
-
type: 'select',
|
|
521
|
-
at: selection,
|
|
522
|
-
})
|
|
523
|
-
})
|
|
524
|
-
},
|
|
525
|
-
),
|
|
526
|
-
Then(
|
|
527
|
-
'{terse-pt} is selected',
|
|
528
|
-
async (context: Context, text: Array<string>) => {
|
|
529
|
-
await vi.waitFor(() => {
|
|
530
|
-
expect(
|
|
531
|
-
getSelectionText(context.editor.getSnapshot().context),
|
|
532
|
-
'Unexpected selection',
|
|
533
|
-
).toEqual(text)
|
|
534
|
-
})
|
|
535
|
-
},
|
|
536
|
-
),
|
|
537
|
-
|
|
538
|
-
When(
|
|
539
|
-
'{terse-pt} is inserted at {placement}',
|
|
540
|
-
(
|
|
541
|
-
context: Context,
|
|
542
|
-
tersePt: Parameter['tersePt'],
|
|
543
|
-
placement: Parameter['placement'],
|
|
544
|
-
) => {
|
|
545
|
-
const blocks = parseTersePt(
|
|
546
|
-
{
|
|
547
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
548
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
549
|
-
},
|
|
550
|
-
tersePt,
|
|
551
|
-
)
|
|
552
|
-
|
|
553
|
-
context.editor.send({
|
|
554
|
-
type: 'insert.blocks',
|
|
555
|
-
blocks,
|
|
556
|
-
placement,
|
|
557
|
-
})
|
|
558
|
-
},
|
|
559
|
-
),
|
|
560
|
-
When(
|
|
561
|
-
'{terse-pt} is inserted at {placement} and selected at the {select-position}',
|
|
562
|
-
(
|
|
563
|
-
context: Context,
|
|
564
|
-
tersePt: Parameter['tersePt'],
|
|
565
|
-
placement: Parameter['placement'],
|
|
566
|
-
selectPosition: Parameter['selectPosition'],
|
|
567
|
-
) => {
|
|
568
|
-
const blocks = parseTersePt(
|
|
569
|
-
{
|
|
570
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
571
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
572
|
-
},
|
|
573
|
-
tersePt,
|
|
574
|
-
)
|
|
575
|
-
|
|
576
|
-
context.editor.send({
|
|
577
|
-
type: 'insert.blocks',
|
|
578
|
-
blocks,
|
|
579
|
-
placement,
|
|
580
|
-
select: selectPosition,
|
|
581
|
-
})
|
|
582
|
-
},
|
|
583
|
-
),
|
|
584
|
-
When(
|
|
585
|
-
'blocks are inserted at {placement} and selected at the {select-position}',
|
|
586
|
-
(
|
|
587
|
-
context: Context,
|
|
588
|
-
placement: Parameter['placement'],
|
|
589
|
-
selectPosition: Parameter['selectPosition'],
|
|
590
|
-
blocks: string,
|
|
591
|
-
) => {
|
|
592
|
-
context.editor.send({
|
|
593
|
-
type: 'insert.blocks',
|
|
594
|
-
blocks: parseBlocks({
|
|
595
|
-
context: {
|
|
596
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
597
|
-
keyGenerator: context.editor.getSnapshot().context.keyGenerator,
|
|
598
|
-
},
|
|
599
|
-
blocks: JSON.parse(blocks),
|
|
600
|
-
options: {
|
|
601
|
-
normalize: false,
|
|
602
|
-
removeUnusedMarkDefs: false,
|
|
603
|
-
validateFields: true,
|
|
604
|
-
},
|
|
605
|
-
}),
|
|
606
|
-
placement,
|
|
607
|
-
select: selectPosition,
|
|
608
|
-
})
|
|
609
|
-
},
|
|
610
|
-
),
|
|
611
|
-
|
|
612
|
-
Then(
|
|
613
|
-
'the text is {terse-pt}',
|
|
614
|
-
async (context: Context, tersePt: Parameter['tersePt']) => {
|
|
615
|
-
await vi.waitFor(() => {
|
|
616
|
-
expect(
|
|
617
|
-
getTersePt(context.editor.getSnapshot().context),
|
|
618
|
-
'Unexpected editor text',
|
|
619
|
-
).toEqual(tersePt)
|
|
620
|
-
})
|
|
621
|
-
},
|
|
622
|
-
),
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Annotation steps
|
|
626
|
-
*/
|
|
627
|
-
Given(
|
|
628
|
-
'a(n) {annotation} {keyKeys} around {string}',
|
|
629
|
-
async (
|
|
630
|
-
context: Context,
|
|
631
|
-
annotation: Parameter['annotation'],
|
|
632
|
-
keyKeys: Array<string>,
|
|
633
|
-
text: string,
|
|
634
|
-
) => {
|
|
635
|
-
await vi.waitFor(() => {
|
|
636
|
-
const selection = getTextSelection(
|
|
637
|
-
context.editor.getSnapshot().context,
|
|
638
|
-
text,
|
|
639
|
-
)
|
|
640
|
-
expect(selection).not.toBeNull()
|
|
641
|
-
|
|
642
|
-
context.editor.send({
|
|
643
|
-
type: 'select',
|
|
644
|
-
at: selection,
|
|
645
|
-
})
|
|
646
|
-
})
|
|
647
|
-
|
|
648
|
-
const value = context.editor.getSnapshot().context.value
|
|
649
|
-
const priorAnnotationKeys = getValueAnnotations(
|
|
650
|
-
context.editor.getSnapshot().context.schema,
|
|
651
|
-
value,
|
|
652
|
-
)
|
|
653
|
-
|
|
654
|
-
context.editor.send({
|
|
655
|
-
type: 'annotation.toggle',
|
|
656
|
-
annotation: {
|
|
657
|
-
name: annotation,
|
|
658
|
-
value: {},
|
|
659
|
-
},
|
|
660
|
-
})
|
|
661
|
-
|
|
662
|
-
let newAnnotationKeys: Array<string> = []
|
|
663
|
-
|
|
664
|
-
await vi.waitFor(() => {
|
|
665
|
-
const newValue = context.editor.getSnapshot().context.value
|
|
666
|
-
|
|
667
|
-
expect(priorAnnotationKeys).not.toEqual(
|
|
668
|
-
getValueAnnotations(
|
|
669
|
-
context.editor.getSnapshot().context.schema,
|
|
670
|
-
newValue,
|
|
671
|
-
),
|
|
672
|
-
)
|
|
673
|
-
|
|
674
|
-
newAnnotationKeys = getValueAnnotations(
|
|
675
|
-
context.editor.getSnapshot().context.schema,
|
|
676
|
-
newValue,
|
|
677
|
-
).filter(
|
|
678
|
-
(newAnnotationKey) => !priorAnnotationKeys.includes(newAnnotationKey),
|
|
679
|
-
)
|
|
680
|
-
})
|
|
681
|
-
|
|
682
|
-
if (newAnnotationKeys.length !== keyKeys.length) {
|
|
683
|
-
assert.fail(
|
|
684
|
-
`Expected ${keyKeys.length} new annotation keys, but got ${newAnnotationKeys.length}`,
|
|
685
|
-
)
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
keyKeys.forEach((keyKey, index) => {
|
|
689
|
-
context.keyMap?.set(keyKey, newAnnotationKeys[index])
|
|
690
|
-
})
|
|
691
|
-
},
|
|
692
|
-
),
|
|
693
|
-
When(
|
|
694
|
-
'{annotation} is toggled',
|
|
695
|
-
(context: Context, annotation: Parameter['annotation']) => {
|
|
696
|
-
context.editor.send({
|
|
697
|
-
type: 'annotation.toggle',
|
|
698
|
-
annotation: {
|
|
699
|
-
name: annotation,
|
|
700
|
-
value: {},
|
|
701
|
-
},
|
|
702
|
-
})
|
|
703
|
-
},
|
|
704
|
-
),
|
|
705
|
-
When(
|
|
706
|
-
'{annotation} {keyKeys} is toggled',
|
|
707
|
-
async (
|
|
708
|
-
context: Context,
|
|
709
|
-
annotation: Parameter['annotation'],
|
|
710
|
-
keyKeys: Array<string>,
|
|
711
|
-
) => {
|
|
712
|
-
const value = context.editor.getSnapshot().context.value
|
|
713
|
-
const priorAnnotationKeys = getValueAnnotations(
|
|
714
|
-
context.editor.getSnapshot().context.schema,
|
|
715
|
-
value,
|
|
716
|
-
)
|
|
717
|
-
|
|
718
|
-
context.editor.send({
|
|
719
|
-
type: 'annotation.toggle',
|
|
720
|
-
annotation: {
|
|
721
|
-
name: annotation,
|
|
722
|
-
value: {},
|
|
723
|
-
},
|
|
724
|
-
})
|
|
725
|
-
|
|
726
|
-
let newAnnotationKeys: Array<string> = []
|
|
727
|
-
|
|
728
|
-
await vi.waitFor(() => {
|
|
729
|
-
const newValue = context.editor.getSnapshot().context.value
|
|
730
|
-
|
|
731
|
-
expect(priorAnnotationKeys).not.toEqual(
|
|
732
|
-
getValueAnnotations(
|
|
733
|
-
context.editor.getSnapshot().context.schema,
|
|
734
|
-
newValue,
|
|
735
|
-
),
|
|
736
|
-
)
|
|
737
|
-
|
|
738
|
-
newAnnotationKeys = getValueAnnotations(
|
|
739
|
-
context.editor.getSnapshot().context.schema,
|
|
740
|
-
newValue,
|
|
741
|
-
).filter(
|
|
742
|
-
(newAnnotationKey) => !priorAnnotationKeys.includes(newAnnotationKey),
|
|
743
|
-
)
|
|
744
|
-
})
|
|
745
|
-
|
|
746
|
-
if (newAnnotationKeys.length !== keyKeys.length) {
|
|
747
|
-
assert.fail(
|
|
748
|
-
`Expected ${keyKeys.length} new annotation keys, but got ${newAnnotationKeys.length}`,
|
|
749
|
-
)
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
keyKeys.forEach((keyKey, index) => {
|
|
753
|
-
context.keyMap?.set(keyKey, newAnnotationKeys[index])
|
|
754
|
-
})
|
|
755
|
-
},
|
|
756
|
-
),
|
|
757
|
-
Then(
|
|
758
|
-
'{string} has an annotation different than {key}',
|
|
759
|
-
(context: Context, text: string, key: string) => {
|
|
760
|
-
const marks = getTextMarks(context.editor.getSnapshot().context, text)
|
|
761
|
-
const expectedMarks = [context.keyMap?.get(key) ?? key]
|
|
762
|
-
|
|
763
|
-
expect(marks).not.toEqual(expectedMarks)
|
|
764
|
-
},
|
|
765
|
-
),
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* Decorator steps
|
|
769
|
-
*/
|
|
770
|
-
Given(
|
|
771
|
-
'{decorator} around {string}',
|
|
772
|
-
async (
|
|
773
|
-
context: Context,
|
|
774
|
-
decorator: Parameter['decorator'],
|
|
775
|
-
text: string,
|
|
776
|
-
) => {
|
|
777
|
-
await vi.waitFor(() => {
|
|
778
|
-
const selection = getTextSelection(
|
|
779
|
-
context.editor.getSnapshot().context,
|
|
780
|
-
text,
|
|
781
|
-
)
|
|
782
|
-
const anchorOffset = selection
|
|
783
|
-
? selectionPointToBlockOffset({
|
|
784
|
-
context: {
|
|
785
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
786
|
-
value: context.editor.getSnapshot().context.value,
|
|
787
|
-
},
|
|
788
|
-
selectionPoint: selection.anchor,
|
|
789
|
-
})
|
|
790
|
-
: undefined
|
|
791
|
-
const focusOffset = selection
|
|
792
|
-
? selectionPointToBlockOffset({
|
|
793
|
-
context: {
|
|
794
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
795
|
-
value: context.editor.getSnapshot().context.value,
|
|
796
|
-
},
|
|
797
|
-
selectionPoint: selection.focus,
|
|
798
|
-
})
|
|
799
|
-
: undefined
|
|
800
|
-
expect(anchorOffset).toBeDefined()
|
|
801
|
-
expect(focusOffset).toBeDefined()
|
|
802
|
-
|
|
803
|
-
context.editor.send({
|
|
804
|
-
type: 'decorator.toggle',
|
|
805
|
-
decorator,
|
|
806
|
-
at: {
|
|
807
|
-
anchor: anchorOffset!,
|
|
808
|
-
focus: focusOffset!,
|
|
809
|
-
},
|
|
810
|
-
})
|
|
811
|
-
})
|
|
812
|
-
},
|
|
813
|
-
),
|
|
814
|
-
When(
|
|
815
|
-
'{decorator} is toggled',
|
|
816
|
-
async (context: Context, decorator: Parameter['decorator']) => {
|
|
817
|
-
await vi.waitFor(() => {
|
|
818
|
-
context.editor.send({
|
|
819
|
-
type: 'decorator.toggle',
|
|
820
|
-
decorator,
|
|
821
|
-
})
|
|
822
|
-
})
|
|
823
|
-
},
|
|
824
|
-
),
|
|
825
|
-
When(
|
|
826
|
-
'{string} is marked with {decorator}',
|
|
827
|
-
async (
|
|
828
|
-
context: Context,
|
|
829
|
-
text: string,
|
|
830
|
-
decorator: Parameter['decorator'],
|
|
831
|
-
) => {
|
|
832
|
-
await vi.waitFor(() => {
|
|
833
|
-
const selection = getTextSelection(
|
|
834
|
-
context.editor.getSnapshot().context,
|
|
835
|
-
text,
|
|
836
|
-
)
|
|
837
|
-
const anchorOffset = selection
|
|
838
|
-
? spanSelectionPointToBlockOffset({
|
|
839
|
-
context: {
|
|
840
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
841
|
-
value: context.editor.getSnapshot().context.value,
|
|
842
|
-
},
|
|
843
|
-
selectionPoint: selection.anchor,
|
|
844
|
-
})
|
|
845
|
-
: undefined
|
|
846
|
-
const focusOffset = selection
|
|
847
|
-
? spanSelectionPointToBlockOffset({
|
|
848
|
-
context: {
|
|
849
|
-
schema: context.editor.getSnapshot().context.schema,
|
|
850
|
-
value: context.editor.getSnapshot().context.value,
|
|
851
|
-
},
|
|
852
|
-
selectionPoint: selection.focus,
|
|
853
|
-
})
|
|
854
|
-
: undefined
|
|
855
|
-
|
|
856
|
-
expect(anchorOffset).toBeDefined()
|
|
857
|
-
expect(focusOffset).toBeDefined()
|
|
858
|
-
|
|
859
|
-
context.editor.send({
|
|
860
|
-
type: 'decorator.toggle',
|
|
861
|
-
decorator,
|
|
862
|
-
at: {
|
|
863
|
-
anchor: anchorOffset!,
|
|
864
|
-
focus: focusOffset!,
|
|
865
|
-
},
|
|
866
|
-
})
|
|
867
|
-
})
|
|
868
|
-
},
|
|
869
|
-
),
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* Mark steps
|
|
873
|
-
*/
|
|
874
|
-
Then(
|
|
875
|
-
'{string} has marks {marks}',
|
|
876
|
-
async (context: Context, text: string, marks: Parameter['marks']) => {
|
|
877
|
-
await vi.waitFor(() => {
|
|
878
|
-
const actualMarks =
|
|
879
|
-
getTextMarks(context.editor.getSnapshot().context, text) ?? []
|
|
880
|
-
const expectedMarks = marks.map(
|
|
881
|
-
(mark) => context.keyMap?.get(mark) ?? mark,
|
|
882
|
-
)
|
|
883
|
-
|
|
884
|
-
expect(actualMarks).toEqual(expectedMarks)
|
|
885
|
-
})
|
|
886
|
-
},
|
|
887
|
-
),
|
|
888
|
-
Then('{string} has no marks', async (context: Context, text: string) => {
|
|
889
|
-
await vi.waitFor(() => {
|
|
890
|
-
const textMarks = getTextMarks(context.editor.getSnapshot().context, text)
|
|
891
|
-
expect(textMarks).toEqual([])
|
|
892
|
-
})
|
|
893
|
-
}),
|
|
894
|
-
Then(
|
|
895
|
-
'{string} and {string} have the same marks',
|
|
896
|
-
(context: Context, textA: string, textB: string) => {
|
|
897
|
-
const marksA = getTextMarks(context.editor.getSnapshot().context, textA)
|
|
898
|
-
const marksB = getTextMarks(context.editor.getSnapshot().context, textB)
|
|
899
|
-
|
|
900
|
-
expect(
|
|
901
|
-
marksA,
|
|
902
|
-
`Expected "${textA}" and "${textB}" to have the same marks`,
|
|
903
|
-
).toEqual(marksB)
|
|
904
|
-
},
|
|
905
|
-
),
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* Style steps
|
|
909
|
-
*/
|
|
910
|
-
When('{style} is toggled', (context: Context, style: Parameter['style']) => {
|
|
911
|
-
context.editor.send({type: 'style.toggle', style})
|
|
912
|
-
}),
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Clipboard steps
|
|
916
|
-
*/
|
|
917
|
-
When('x-portable-text is pasted', (context: Context, blocks: string) => {
|
|
918
|
-
const dataTransfer = new DataTransfer()
|
|
919
|
-
dataTransfer.setData('application/x-portable-text', blocks)
|
|
920
|
-
dataTransfer.setData('application/json', blocks)
|
|
921
|
-
|
|
922
|
-
context.editor.send({
|
|
923
|
-
type: 'clipboard.paste',
|
|
924
|
-
originEvent: {
|
|
925
|
-
dataTransfer,
|
|
926
|
-
},
|
|
927
|
-
position: {
|
|
928
|
-
selection: context.editor.getSnapshot().context.selection!,
|
|
929
|
-
},
|
|
930
|
-
})
|
|
931
|
-
}),
|
|
932
|
-
When(
|
|
933
|
-
'data is pasted',
|
|
934
|
-
(context: Context, dataTable: Array<[mime: string, data: string]>) => {
|
|
935
|
-
const dataTransfer = new DataTransfer()
|
|
936
|
-
|
|
937
|
-
for (const data of dataTable) {
|
|
938
|
-
dataTransfer.setData(data[0], data[1])
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
context.editor.send({
|
|
942
|
-
type: 'clipboard.paste',
|
|
943
|
-
originEvent: {dataTransfer},
|
|
944
|
-
position: {
|
|
945
|
-
selection: context.editor.getSnapshot().context.selection!,
|
|
946
|
-
},
|
|
947
|
-
})
|
|
948
|
-
},
|
|
949
|
-
),
|
|
950
|
-
|
|
951
|
-
/**
|
|
952
|
-
* Undo/Redo steps
|
|
953
|
-
*/
|
|
954
|
-
When('undo is performed', (context: Context) => {
|
|
955
|
-
context.editor.send({type: 'history.undo'})
|
|
956
|
-
}),
|
|
957
|
-
When('redo is performed', (context: Context) => {
|
|
958
|
-
context.editor.send({type: 'history.redo'})
|
|
959
|
-
}),
|
|
960
|
-
]
|