@portabletext/editor 2.21.3 → 3.0.1
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 +49 -209
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +103 -20
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/{util.get-text-block-text.js → util.slice-blocks.js} +73 -24
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -0
- package/lib/_chunks-es/util.slice-text-block.js +13 -2
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/behaviors/index.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +339 -341
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +2 -133
- package/lib/plugins/index.js +2 -796
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.ts +2 -24
- package/lib/selectors/index.js +28 -130
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.ts +6 -4
- package/lib/utils/index.js +98 -9
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -3
- package/src/behaviors/behavior.abstract.split.ts +1 -0
- package/src/behaviors/behavior.perform-event.ts +7 -7
- package/src/converters/converter.portable-text.ts +1 -0
- package/src/converters/converter.text-html.ts +1 -0
- package/src/converters/converter.text-plain.ts +1 -0
- package/src/editor/Editable.tsx +1 -0
- package/src/editor/PortableTextEditor.tsx +0 -19
- package/src/editor/create-editor.ts +0 -3
- package/src/editor/editor-machine.ts +0 -10
- package/src/editor/event-to-change.tsx +5 -1
- package/src/editor/plugins/create-with-event-listeners.ts +30 -6
- package/src/editor/plugins/createWithObjectKeys.ts +2 -1
- package/src/editor/plugins/createWithPatches.ts +3 -3
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -1
- package/src/editor/plugins/with-plugins.ts +10 -14
- package/src/editor/relay-machine.ts +0 -4
- package/src/editor/sync-machine.ts +2 -2
- package/src/editor.ts +0 -4
- package/src/history/behavior.operation.history.redo.ts +67 -0
- package/src/history/behavior.operation.history.undo.ts +71 -0
- package/src/history/event.history.undo.test.tsx +672 -0
- package/src/history/history.preserving-keys.test.tsx +112 -0
- package/src/history/remote-patches.ts +20 -0
- package/src/history/slate-plugin.history.ts +146 -0
- package/src/history/slate-plugin.redoing.ts +21 -0
- package/src/history/slate-plugin.undoing.ts +21 -0
- package/src/history/slate-plugin.without-history.ts +23 -0
- package/src/history/transform-operation.ts +245 -0
- package/src/history/undo-redo-collaboration.test.tsx +541 -0
- package/src/history/undo-redo.feature +125 -0
- package/src/history/undo-redo.test.tsx +195 -0
- package/src/history/undo-step.ts +148 -0
- package/src/index.ts +0 -1
- package/src/internal-utils/operation-to-patches.test.ts +23 -25
- package/src/internal-utils/operation-to-patches.ts +31 -22
- package/src/internal-utils/selection-text.test.ts +3 -0
- package/src/internal-utils/selection-text.ts +5 -2
- package/src/internal-utils/values.ts +23 -11
- package/src/operations/behavior.operation.block.set.ts +1 -0
- package/src/operations/behavior.operation.block.unset.ts +2 -0
- package/src/operations/behavior.operation.insert.block.ts +1 -0
- package/src/operations/behavior.operations.ts +2 -4
- package/src/plugins/index.ts +0 -3
- package/src/selectors/index.ts +0 -3
- package/src/test/vitest/step-definitions.tsx +57 -0
- package/src/test/vitest/test-editor.tsx +1 -1
- package/src/utils/parse-blocks.test.ts +296 -16
- package/src/utils/parse-blocks.ts +81 -22
- package/src/utils/util.merge-text-blocks.ts +5 -1
- package/src/utils/util.slice-blocks.ts +24 -10
- package/lib/_chunks-es/selector.get-selection-text.js +0 -92
- package/lib/_chunks-es/selector.get-selection-text.js.map +0 -1
- package/lib/_chunks-es/selector.get-text-before.js +0 -36
- package/lib/_chunks-es/selector.get-text-before.js.map +0 -1
- package/lib/_chunks-es/util.get-text-block-text.js.map +0 -1
- package/lib/_chunks-es/util.is-empty-text-block.js +0 -40
- package/lib/_chunks-es/util.is-empty-text-block.js.map +0 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +0 -101
- package/lib/_chunks-es/util.merge-text-blocks.js.map +0 -1
- package/src/editor/plugins/createWithMaxBlocks.ts +0 -53
- package/src/editor/plugins/createWithUndoRedo.ts +0 -628
- package/src/editor/with-undo-step.ts +0 -37
- package/src/editor/withUndoRedo.ts +0 -34
- package/src/editor-event-listener.tsx +0 -28
- package/src/plugins/plugin.decorator-shortcut.ts +0 -238
- package/src/plugins/plugin.markdown.test.tsx +0 -42
- package/src/plugins/plugin.markdown.tsx +0 -131
- package/src/plugins/plugin.one-line.tsx +0 -123
- package/src/selectors/selector.get-list-state.test.ts +0 -189
- package/src/selectors/selector.get-list-state.ts +0 -96
- package/src/selectors/selector.get-selected-slice.ts +0 -13
- package/src/selectors/selector.get-trimmed-selection.test.ts +0 -657
- package/src/selectors/selector.get-trimmed-selection.ts +0 -189
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {flatten} from 'lodash'
|
|
2
|
+
import {Editor, Transforms} from 'slate'
|
|
3
|
+
import {debugWithName} from '../internal-utils/debug'
|
|
4
|
+
import type {BehaviorOperationImplementation} from '../operations/behavior.operations'
|
|
5
|
+
import {getRemotePatches} from './remote-patches'
|
|
6
|
+
import {pluginRedoing, setIsRedoing} from './slate-plugin.redoing'
|
|
7
|
+
import {
|
|
8
|
+
pluginWithoutHistory,
|
|
9
|
+
setWithHistory,
|
|
10
|
+
} from './slate-plugin.without-history'
|
|
11
|
+
import {transformOperation} from './transform-operation'
|
|
12
|
+
|
|
13
|
+
const debug = debugWithName('behavior.operation.history.redo')
|
|
14
|
+
|
|
15
|
+
export const historyRedoOperationImplementation: BehaviorOperationImplementation<
|
|
16
|
+
'history.redo'
|
|
17
|
+
> = ({operation}) => {
|
|
18
|
+
const editor = operation.editor
|
|
19
|
+
const {redos} = editor.history
|
|
20
|
+
const remotePatches = getRemotePatches(editor)
|
|
21
|
+
|
|
22
|
+
if (redos.length > 0) {
|
|
23
|
+
const step = redos[redos.length - 1]
|
|
24
|
+
debug('Redoing', step)
|
|
25
|
+
if (step.operations.length > 0) {
|
|
26
|
+
const otherPatches = remotePatches.filter(
|
|
27
|
+
(item) => item.time >= step.timestamp,
|
|
28
|
+
)
|
|
29
|
+
let transformedOperations = step.operations
|
|
30
|
+
otherPatches.forEach((item) => {
|
|
31
|
+
transformedOperations = flatten(
|
|
32
|
+
transformedOperations.map((op) =>
|
|
33
|
+
transformOperation(
|
|
34
|
+
editor,
|
|
35
|
+
item.patch,
|
|
36
|
+
op,
|
|
37
|
+
item.snapshot,
|
|
38
|
+
item.previousSnapshot,
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
try {
|
|
44
|
+
Editor.withoutNormalizing(editor, () => {
|
|
45
|
+
pluginRedoing(editor, () => {
|
|
46
|
+
pluginWithoutHistory(editor, () => {
|
|
47
|
+
transformedOperations.forEach((op) => {
|
|
48
|
+
editor.apply(op)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
} catch (err) {
|
|
54
|
+
debug('Could not perform redo step', err)
|
|
55
|
+
remotePatches.splice(0, remotePatches.length)
|
|
56
|
+
Transforms.deselect(editor)
|
|
57
|
+
editor.history = {undos: [], redos: []}
|
|
58
|
+
setWithHistory(editor, true)
|
|
59
|
+
setIsRedoing(editor, false)
|
|
60
|
+
editor.onChange()
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
editor.history.undos.push(step)
|
|
64
|
+
editor.history.redos.pop()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {flatten} from 'lodash'
|
|
2
|
+
import {Editor, Operation, Transforms} from 'slate'
|
|
3
|
+
import {debugWithName} from '../internal-utils/debug'
|
|
4
|
+
import type {BehaviorOperationImplementation} from '../operations/behavior.operations'
|
|
5
|
+
import {getRemotePatches} from './remote-patches'
|
|
6
|
+
import {pluginUndoing, setIsUndoing} from './slate-plugin.undoing'
|
|
7
|
+
import {
|
|
8
|
+
pluginWithoutHistory,
|
|
9
|
+
setWithHistory,
|
|
10
|
+
} from './slate-plugin.without-history'
|
|
11
|
+
import {transformOperation} from './transform-operation'
|
|
12
|
+
|
|
13
|
+
const debug = debugWithName('behavior.operation.history.undo')
|
|
14
|
+
|
|
15
|
+
export const historyUndoOperationImplementation: BehaviorOperationImplementation<
|
|
16
|
+
'history.undo'
|
|
17
|
+
> = ({operation}) => {
|
|
18
|
+
const editor = operation.editor
|
|
19
|
+
const {undos} = editor.history
|
|
20
|
+
const remotePatches = getRemotePatches(editor)
|
|
21
|
+
|
|
22
|
+
if (undos.length > 0) {
|
|
23
|
+
const step = undos[undos.length - 1]
|
|
24
|
+
debug('Undoing', step)
|
|
25
|
+
if (step.operations.length > 0) {
|
|
26
|
+
const otherPatches = remotePatches.filter(
|
|
27
|
+
(item) => item.time >= step.timestamp,
|
|
28
|
+
)
|
|
29
|
+
let transformedOperations = step.operations
|
|
30
|
+
otherPatches.forEach((item) => {
|
|
31
|
+
transformedOperations = flatten(
|
|
32
|
+
transformedOperations.map((op) =>
|
|
33
|
+
transformOperation(
|
|
34
|
+
editor,
|
|
35
|
+
item.patch,
|
|
36
|
+
op,
|
|
37
|
+
item.snapshot,
|
|
38
|
+
item.previousSnapshot,
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
const reversedOperations = transformedOperations
|
|
44
|
+
.map(Operation.inverse)
|
|
45
|
+
.reverse()
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
Editor.withoutNormalizing(editor, () => {
|
|
49
|
+
pluginUndoing(editor, () => {
|
|
50
|
+
pluginWithoutHistory(editor, () => {
|
|
51
|
+
reversedOperations.forEach((op) => {
|
|
52
|
+
editor.apply(op)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
} catch (err) {
|
|
58
|
+
debug('Could not perform undo step', err)
|
|
59
|
+
remotePatches.splice(0, remotePatches.length)
|
|
60
|
+
Transforms.deselect(editor)
|
|
61
|
+
editor.history = {undos: [], redos: []}
|
|
62
|
+
setWithHistory(editor, true)
|
|
63
|
+
setIsUndoing(editor, false)
|
|
64
|
+
editor.onChange()
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
editor.history.redos.push(step)
|
|
68
|
+
editor.history.undos.pop()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|