@portabletext/editor 1.15.3 → 1.16.0
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-cjs/behavior.core.cjs +25 -25
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +14 -14
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selectors.cjs → selector.is-selection-collapsed.cjs} +8 -8
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +7 -7
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +14 -14
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selectors.js → selector.is-selection-collapsed.js} +8 -8
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -0
- package/lib/behaviors/index.cjs +23 -23
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/behaviors/index.js +8 -8
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +855 -515
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +4126 -4834
- package/lib/index.d.ts +4126 -4834
- package/lib/index.js +852 -514
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +166 -16
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +54 -5
- package/lib/selectors/index.d.ts +54 -5
- package/lib/selectors/index.js +154 -3
- package/lib/selectors/index.js.map +1 -1
- package/package.json +11 -11
- package/src/behaviors/behavior.code-editor.ts +5 -9
- package/src/behaviors/behavior.core.block-objects.ts +13 -19
- package/src/behaviors/behavior.core.lists.ts +11 -17
- package/src/behaviors/behavior.links.ts +4 -4
- package/src/behaviors/behavior.markdown.ts +16 -21
- package/src/editor/Editable.tsx +11 -4
- package/src/editor/PortableTextEditor.tsx +2 -3
- package/src/editor/{hooks/useSyncValue.test.tsx → __tests__/sync-value.test.tsx} +42 -23
- package/src/editor/components/Synchronizer.tsx +53 -80
- package/src/editor/editor-machine.ts +129 -80
- package/src/editor/editor-provider.tsx +0 -3
- package/src/editor/editor-selector.ts +5 -0
- package/src/editor/editor-snapshot.ts +1 -0
- package/src/editor/get-active-decorators.ts +20 -0
- package/src/editor/mutation-machine.ts +100 -0
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +21 -15
- package/src/editor/plugins/createWithMaxBlocks.ts +1 -1
- package/src/editor/plugins/createWithPatches.ts +0 -4
- package/src/editor/plugins/createWithPlaceholderBlock.ts +1 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -1
- package/src/editor/plugins/createWithUndoRedo.ts +3 -3
- package/src/editor/sync-machine.ts +657 -0
- package/src/editor/withSyncRangeDecorations.ts +17 -5
- package/src/selectors/_exports/index.ts +1 -0
- package/src/selectors/index.ts +9 -1
- package/src/selectors/selector.get-active-style.ts +37 -0
- package/src/selectors/selector.get-selected-spans.ts +136 -0
- package/src/selectors/selector.is-active-annotation.ts +49 -0
- package/src/selectors/selector.is-active-decorator.ts +21 -0
- package/src/selectors/selector.is-active-list-item.ts +13 -0
- package/src/selectors/selector.is-active-style.ts +13 -0
- package/src/selectors/selector.is-selection-collapsed.ts +12 -0
- package/src/selectors/selector.is-selection-expanded.ts +9 -0
- package/src/selectors/selectors.ts +0 -11
- package/src/utils/weakMaps.ts +0 -3
- package/src/utils/withChanges.ts +1 -8
- package/lib/_chunks-cjs/selectors.cjs.map +0 -1
- package/lib/_chunks-es/selectors.js.map +0 -1
- package/src/editor/hooks/useSyncValue.ts +0 -426
|
@@ -49,26 +49,22 @@ describe('plugin:withPortableTextMarksModel', () => {
|
|
|
49
49
|
anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
|
|
50
50
|
})
|
|
51
51
|
PortableTextEditor.toggleMark(editor, 'strong')
|
|
52
|
-
expect(PortableTextEditor.getValue(editor)).
|
|
53
|
-
[
|
|
52
|
+
expect(PortableTextEditor.getValue(editor)).toEqual([
|
|
54
53
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
_key: 'a',
|
|
55
|
+
_type: 'myTestBlockType',
|
|
56
|
+
children: [
|
|
58
57
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
],
|
|
64
|
-
"text": "1234",
|
|
58
|
+
_key: 'a1',
|
|
59
|
+
_type: 'span',
|
|
60
|
+
marks: ['strong'],
|
|
61
|
+
text: '1234',
|
|
65
62
|
},
|
|
66
63
|
],
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
markDefs: [],
|
|
65
|
+
style: 'normal',
|
|
69
66
|
},
|
|
70
|
-
]
|
|
71
|
-
`)
|
|
67
|
+
])
|
|
72
68
|
})
|
|
73
69
|
await waitFor(() => {
|
|
74
70
|
if (editorRef.current) {
|
|
@@ -871,6 +867,16 @@ describe('plugin:withPortableTextMarksModel', () => {
|
|
|
871
867
|
)
|
|
872
868
|
})
|
|
873
869
|
|
|
870
|
+
await waitFor(() => {
|
|
871
|
+
if (editorRef.current) {
|
|
872
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
873
|
+
type: 'value',
|
|
874
|
+
value: initialValue,
|
|
875
|
+
})
|
|
876
|
+
expect(onChange).toHaveBeenCalledWith({type: 'ready'})
|
|
877
|
+
}
|
|
878
|
+
})
|
|
879
|
+
|
|
874
880
|
await waitFor(() => {
|
|
875
881
|
if (editorRef.current) {
|
|
876
882
|
PortableTextEditor.focus(editorRef.current)
|
|
@@ -13,7 +13,7 @@ export function createWithMaxBlocks(editorActor: EditorActor) {
|
|
|
13
13
|
): PortableTextSlateEditor {
|
|
14
14
|
const {apply} = editor
|
|
15
15
|
editor.apply = (operation) => {
|
|
16
|
-
if (editorActor.getSnapshot().
|
|
16
|
+
if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
|
|
17
17
|
apply(operation)
|
|
18
18
|
return
|
|
19
19
|
}
|
|
@@ -150,10 +150,6 @@ export function createWithPatches({
|
|
|
150
150
|
})
|
|
151
151
|
|
|
152
152
|
editor.apply = (operation: Operation): void | Editor => {
|
|
153
|
-
if (editorActor.getSnapshot().context.readOnly) {
|
|
154
|
-
apply(operation)
|
|
155
|
-
return editor
|
|
156
|
-
}
|
|
157
153
|
let patches: Patch[] = []
|
|
158
154
|
|
|
159
155
|
// Update previous children here before we apply
|
|
@@ -57,7 +57,10 @@ export function createWithPortableTextSelections(
|
|
|
57
57
|
editor.onChange = () => {
|
|
58
58
|
const hasChanges = editor.operations.length > 0
|
|
59
59
|
onChange()
|
|
60
|
-
if (
|
|
60
|
+
if (
|
|
61
|
+
hasChanges &&
|
|
62
|
+
!editorActor.getSnapshot().matches({setup: 'setting up'})
|
|
63
|
+
) {
|
|
61
64
|
emitPortableTextSelection()
|
|
62
65
|
}
|
|
63
66
|
}
|
|
@@ -114,7 +114,7 @@ export function createWithUndoRedo(
|
|
|
114
114
|
editor.history = {undos: [], redos: []}
|
|
115
115
|
const {apply} = editor
|
|
116
116
|
editor.apply = (op: Operation) => {
|
|
117
|
-
if (editorActor.getSnapshot().
|
|
117
|
+
if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
|
|
118
118
|
apply(op)
|
|
119
119
|
return
|
|
120
120
|
}
|
|
@@ -181,7 +181,7 @@ export function createWithUndoRedo(
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
editor.undo = () => {
|
|
184
|
-
if (editorActor.getSnapshot().
|
|
184
|
+
if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
|
|
185
185
|
return
|
|
186
186
|
}
|
|
187
187
|
const {undos} = editor.history
|
|
@@ -239,7 +239,7 @@ export function createWithUndoRedo(
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
editor.redo = () => {
|
|
242
|
-
if (editorActor.getSnapshot().
|
|
242
|
+
if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
|
|
243
243
|
return
|
|
244
244
|
}
|
|
245
245
|
const {redos} = editor.history
|