@portabletext/editor 4.0.0 → 4.0.2
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _portabletext_schema6 from "@portabletext/schema";
|
|
2
2
|
import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, TypedObject, defineSchema } from "@portabletext/schema";
|
|
3
3
|
import { BaseRange, Descendant, Operation, Range } from "slate";
|
|
4
|
-
import * as
|
|
4
|
+
import * as xstate71 from "xstate";
|
|
5
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
6
6
|
import * as react10 from "react";
|
|
7
7
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
@@ -148,6 +148,7 @@ interface PortableTextSlateEditor extends ReactEditor {
|
|
|
148
148
|
remotePatches: Array<RemotePatch>;
|
|
149
149
|
undoStepId: string | undefined;
|
|
150
150
|
value: Array<PortableTextBlock>;
|
|
151
|
+
isDeferringMutations: boolean;
|
|
151
152
|
isNormalizingNode: boolean;
|
|
152
153
|
isPatching: boolean;
|
|
153
154
|
isPerformingBehaviorOperation: boolean;
|
|
@@ -1365,7 +1366,7 @@ type EditorActor = ActorRefFrom<typeof editorMachine>;
|
|
|
1365
1366
|
/**
|
|
1366
1367
|
* @internal
|
|
1367
1368
|
*/
|
|
1368
|
-
declare const editorMachine:
|
|
1369
|
+
declare const editorMachine: xstate71.StateMachine<{
|
|
1369
1370
|
behaviors: Set<BehaviorConfig>;
|
|
1370
1371
|
behaviorsSorted: boolean;
|
|
1371
1372
|
converters: Set<Converter>;
|
|
@@ -1427,46 +1428,46 @@ declare const editorMachine: xstate72.StateMachine<{
|
|
|
1427
1428
|
editor: PortableTextSlateEditor;
|
|
1428
1429
|
}, {}, never, {
|
|
1429
1430
|
type: "add behavior to context";
|
|
1430
|
-
params:
|
|
1431
|
+
params: xstate71.NonReducibleUnknown;
|
|
1431
1432
|
} | {
|
|
1432
1433
|
type: "remove behavior from context";
|
|
1433
|
-
params:
|
|
1434
|
+
params: xstate71.NonReducibleUnknown;
|
|
1434
1435
|
} | {
|
|
1435
1436
|
type: "add slate editor to context";
|
|
1436
|
-
params:
|
|
1437
|
+
params: xstate71.NonReducibleUnknown;
|
|
1437
1438
|
} | {
|
|
1438
1439
|
type: "emit patch event";
|
|
1439
|
-
params:
|
|
1440
|
+
params: xstate71.NonReducibleUnknown;
|
|
1440
1441
|
} | {
|
|
1441
1442
|
type: "emit mutation event";
|
|
1442
|
-
params:
|
|
1443
|
+
params: xstate71.NonReducibleUnknown;
|
|
1443
1444
|
} | {
|
|
1444
1445
|
type: "emit read only";
|
|
1445
|
-
params:
|
|
1446
|
+
params: xstate71.NonReducibleUnknown;
|
|
1446
1447
|
} | {
|
|
1447
1448
|
type: "emit editable";
|
|
1448
|
-
params:
|
|
1449
|
+
params: xstate71.NonReducibleUnknown;
|
|
1449
1450
|
} | {
|
|
1450
1451
|
type: "defer event";
|
|
1451
|
-
params:
|
|
1452
|
+
params: xstate71.NonReducibleUnknown;
|
|
1452
1453
|
} | {
|
|
1453
1454
|
type: "emit pending events";
|
|
1454
|
-
params:
|
|
1455
|
+
params: xstate71.NonReducibleUnknown;
|
|
1455
1456
|
} | {
|
|
1456
1457
|
type: "emit ready";
|
|
1457
|
-
params:
|
|
1458
|
+
params: xstate71.NonReducibleUnknown;
|
|
1458
1459
|
} | {
|
|
1459
1460
|
type: "clear pending events";
|
|
1460
|
-
params:
|
|
1461
|
+
params: xstate71.NonReducibleUnknown;
|
|
1461
1462
|
} | {
|
|
1462
1463
|
type: "defer incoming patches";
|
|
1463
|
-
params:
|
|
1464
|
+
params: xstate71.NonReducibleUnknown;
|
|
1464
1465
|
} | {
|
|
1465
1466
|
type: "emit pending incoming patches";
|
|
1466
|
-
params:
|
|
1467
|
+
params: xstate71.NonReducibleUnknown;
|
|
1467
1468
|
} | {
|
|
1468
1469
|
type: "clear pending incoming patches";
|
|
1469
|
-
params:
|
|
1470
|
+
params: xstate71.NonReducibleUnknown;
|
|
1470
1471
|
} | {
|
|
1471
1472
|
type: "handle blur";
|
|
1472
1473
|
params: unknown;
|
|
@@ -1478,7 +1479,7 @@ declare const editorMachine: xstate72.StateMachine<{
|
|
|
1478
1479
|
params: unknown;
|
|
1479
1480
|
} | {
|
|
1480
1481
|
type: "sort behaviors";
|
|
1481
|
-
params:
|
|
1482
|
+
params: xstate71.NonReducibleUnknown;
|
|
1482
1483
|
}, {
|
|
1483
1484
|
type: "slate is busy";
|
|
1484
1485
|
params: unknown;
|
|
@@ -1508,7 +1509,7 @@ declare const editorMachine: xstate72.StateMachine<{
|
|
|
1508
1509
|
readOnly?: boolean;
|
|
1509
1510
|
schema: EditorSchema;
|
|
1510
1511
|
initialValue?: Array<PortableTextBlock>;
|
|
1511
|
-
},
|
|
1512
|
+
}, xstate71.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1512
1513
|
type: "blurred";
|
|
1513
1514
|
event: react10.FocusEvent<HTMLDivElement, Element>;
|
|
1514
1515
|
} | {
|
|
@@ -1539,7 +1540,7 @@ declare const editorMachine: xstate72.StateMachine<{
|
|
|
1539
1540
|
} | {
|
|
1540
1541
|
type: "value changed";
|
|
1541
1542
|
value: Array<PortableTextBlock> | undefined;
|
|
1542
|
-
},
|
|
1543
|
+
}, xstate71.MetaObject, {
|
|
1543
1544
|
id: "editor";
|
|
1544
1545
|
states: {
|
|
1545
1546
|
readonly 'edit mode': {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionEndPoint as getSelectionEndPoint$1, getSelectionStartPoint as getSelectionStartPoint$1, isEqualSelectionPoints, getBlockStartPoint, getBlockEndPoint, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
|
|
1
2
|
import { isTextBlock, isSpan } from "@portabletext/schema";
|
|
2
|
-
import { getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, isEqualSelectionPoints, getBlockStartPoint, getBlockEndPoint, sliceBlocks, isSelectionCollapsed as isSelectionCollapsed$1, blockOffsetToSpanSelectionPoint, isKeyedSegment, spanSelectionPointToBlockOffset, isListBlock } from "./util.slice-blocks.js";
|
|
3
3
|
const getFocusBlock = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
5
5
|
return;
|
|
@@ -29,82 +29,12 @@ const getFocusBlock = (snapshot) => {
|
|
|
29
29
|
_key: key
|
|
30
30
|
}]
|
|
31
31
|
} : void 0;
|
|
32
|
-
}, getFocusInlineObject = (snapshot) => {
|
|
33
|
-
const focusChild = getFocusChild(snapshot);
|
|
34
|
-
return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
|
|
35
|
-
node: focusChild.node,
|
|
36
|
-
path: focusChild.path
|
|
37
|
-
} : void 0;
|
|
38
32
|
}, getFocusSpan = (snapshot) => {
|
|
39
33
|
const focusChild = getFocusChild(snapshot);
|
|
40
34
|
return focusChild && isSpan(snapshot.context, focusChild.node) ? {
|
|
41
35
|
node: focusChild.node,
|
|
42
36
|
path: focusChild.path
|
|
43
37
|
} : void 0;
|
|
44
|
-
}, getSelectedBlocks = (snapshot) => {
|
|
45
|
-
if (!snapshot.context.selection)
|
|
46
|
-
return [];
|
|
47
|
-
const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
48
|
-
if (!startKey || !endKey)
|
|
49
|
-
return selectedBlocks;
|
|
50
|
-
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
51
|
-
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
52
|
-
return selectedBlocks;
|
|
53
|
-
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
54
|
-
for (const block of slicedValue) {
|
|
55
|
-
if (block._key === startKey) {
|
|
56
|
-
if (selectedBlocks.push({
|
|
57
|
-
node: block,
|
|
58
|
-
path: [{
|
|
59
|
-
_key: block._key
|
|
60
|
-
}]
|
|
61
|
-
}), startKey === endKey)
|
|
62
|
-
break;
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (block._key === endKey) {
|
|
66
|
-
selectedBlocks.push({
|
|
67
|
-
node: block,
|
|
68
|
-
path: [{
|
|
69
|
-
_key: block._key
|
|
70
|
-
}]
|
|
71
|
-
});
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
75
|
-
node: block,
|
|
76
|
-
path: [{
|
|
77
|
-
_key: block._key
|
|
78
|
-
}]
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return selectedBlocks;
|
|
82
|
-
}, getSelectionEndBlock = (snapshot) => {
|
|
83
|
-
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
84
|
-
if (endPoint)
|
|
85
|
-
return getFocusBlock({
|
|
86
|
-
...snapshot,
|
|
87
|
-
context: {
|
|
88
|
-
...snapshot.context,
|
|
89
|
-
selection: {
|
|
90
|
-
anchor: endPoint,
|
|
91
|
-
focus: endPoint
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}, getSelectionStartBlock = (snapshot) => {
|
|
96
|
-
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
97
|
-
if (startPoint)
|
|
98
|
-
return getFocusBlock({
|
|
99
|
-
...snapshot,
|
|
100
|
-
context: {
|
|
101
|
-
...snapshot.context,
|
|
102
|
-
selection: {
|
|
103
|
-
anchor: startPoint,
|
|
104
|
-
focus: startPoint
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
38
|
}, getSelectionEndPoint = (snapshot) => {
|
|
109
39
|
if (snapshot.context.selection)
|
|
110
40
|
return snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus;
|
|
@@ -226,7 +156,77 @@ function isOverlappingSelection(selection) {
|
|
|
226
156
|
return !endPointEqualToOriginalStartPoint && !startPointEqualToOriginalEndPoint && !originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint || endPointBeforeSelection && !endPointEqualToOriginalStartPoint || startPointAfterSelection && !startPointEqualToOriginalEndPoint ? !1 : !originalStartPointBeforeStartPoint && originalStartPointAfterStartPoint && !originalEndPointBeforeEndPoint && originalEndPointAfterEndPoint ? !endPointEqualToOriginalStartPoint : originalStartPointBeforeStartPoint && !originalStartPointAfterStartPoint && originalEndPointBeforeEndPoint && !originalEndPointAfterEndPoint ? !startPointEqualToOriginalEndPoint : !startPointAfterSelection || !startPointBeforeSelection || !endPointAfterSelection || !endPointBeforeSelection;
|
|
227
157
|
};
|
|
228
158
|
}
|
|
229
|
-
const isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1,
|
|
159
|
+
const isSelectionCollapsed = (snapshot) => snapshot.context.selection ? JSON.stringify(snapshot.context.selection.anchor.path) === JSON.stringify(snapshot.context.selection.focus.path) && snapshot.context.selection?.anchor.offset === snapshot.context.selection?.focus.offset : !1, getFocusInlineObject = (snapshot) => {
|
|
160
|
+
const focusChild = getFocusChild(snapshot);
|
|
161
|
+
return focusChild && !isSpan(snapshot.context, focusChild.node) ? {
|
|
162
|
+
node: focusChild.node,
|
|
163
|
+
path: focusChild.path
|
|
164
|
+
} : void 0;
|
|
165
|
+
}, getSelectedBlocks = (snapshot) => {
|
|
166
|
+
if (!snapshot.context.selection)
|
|
167
|
+
return [];
|
|
168
|
+
const selectedBlocks = [], startPoint = getSelectionStartPoint$1(snapshot.context.selection), endPoint = getSelectionEndPoint$1(snapshot.context.selection), startKey = getBlockKeyFromSelectionPoint(startPoint), endKey = getBlockKeyFromSelectionPoint(endPoint);
|
|
169
|
+
if (!startKey || !endKey)
|
|
170
|
+
return selectedBlocks;
|
|
171
|
+
const startBlockIndex = snapshot.blockIndexMap.get(startKey), endBlockIndex = snapshot.blockIndexMap.get(endKey);
|
|
172
|
+
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
173
|
+
return selectedBlocks;
|
|
174
|
+
const slicedValue = snapshot.context.value.slice(startBlockIndex, endBlockIndex + 1);
|
|
175
|
+
for (const block of slicedValue) {
|
|
176
|
+
if (block._key === startKey) {
|
|
177
|
+
if (selectedBlocks.push({
|
|
178
|
+
node: block,
|
|
179
|
+
path: [{
|
|
180
|
+
_key: block._key
|
|
181
|
+
}]
|
|
182
|
+
}), startKey === endKey)
|
|
183
|
+
break;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (block._key === endKey) {
|
|
187
|
+
selectedBlocks.push({
|
|
188
|
+
node: block,
|
|
189
|
+
path: [{
|
|
190
|
+
_key: block._key
|
|
191
|
+
}]
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
selectedBlocks.length > 0 && selectedBlocks.push({
|
|
196
|
+
node: block,
|
|
197
|
+
path: [{
|
|
198
|
+
_key: block._key
|
|
199
|
+
}]
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return selectedBlocks;
|
|
203
|
+
}, getSelectionEndBlock = (snapshot) => {
|
|
204
|
+
const endPoint = getSelectionEndPoint$1(snapshot.context.selection);
|
|
205
|
+
if (endPoint)
|
|
206
|
+
return getFocusBlock({
|
|
207
|
+
...snapshot,
|
|
208
|
+
context: {
|
|
209
|
+
...snapshot.context,
|
|
210
|
+
selection: {
|
|
211
|
+
anchor: endPoint,
|
|
212
|
+
focus: endPoint
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}, getSelectionStartBlock = (snapshot) => {
|
|
217
|
+
const startPoint = getSelectionStartPoint$1(snapshot.context.selection);
|
|
218
|
+
if (startPoint)
|
|
219
|
+
return getFocusBlock({
|
|
220
|
+
...snapshot,
|
|
221
|
+
context: {
|
|
222
|
+
...snapshot.context,
|
|
223
|
+
selection: {
|
|
224
|
+
anchor: startPoint,
|
|
225
|
+
focus: startPoint
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}, isSelectionExpanded$1 = (snapshot) => snapshot.context.selection !== null && !isSelectionCollapsed(snapshot), isSelectingEntireBlocks = (snapshot) => {
|
|
230
230
|
if (!snapshot.context.selection)
|
|
231
231
|
return !1;
|
|
232
232
|
const startPoint = snapshot.context.selection.backward ? snapshot.context.selection.focus : snapshot.context.selection.anchor, endPoint = snapshot.context.selection.backward ? snapshot.context.selection.anchor : snapshot.context.selection.focus, startBlock = getSelectionStartBlock(snapshot), endBlock = getSelectionEndBlock(snapshot);
|