@portabletext/editor 1.44.3 → 1.44.5
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/editor-provider.cjs +29 -7
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +29 -7
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/index.cjs +255 -95
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +257 -96
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/Editable.tsx +43 -169
- package/src/editor/__tests__/RangeDecorations.test.tsx +26 -0
- package/src/editor/range-decorations-machine.ts +346 -0
- package/src/internal-utils/slate-utils.ts +42 -21
- package/src/editor/withSyncRangeDecorations.ts +0 -32
|
@@ -234,14 +234,24 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
234
234
|
function getFocusBlock({
|
|
235
235
|
editor
|
|
236
236
|
}) {
|
|
237
|
-
|
|
237
|
+
if (!editor.selection)
|
|
238
|
+
return [void 0, void 0];
|
|
239
|
+
try {
|
|
240
|
+
return slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0];
|
|
241
|
+
} catch {
|
|
242
|
+
return [void 0, void 0];
|
|
243
|
+
}
|
|
238
244
|
}
|
|
239
245
|
function getPointBlock({
|
|
240
246
|
editor,
|
|
241
247
|
point
|
|
242
248
|
}) {
|
|
243
|
-
|
|
244
|
-
|
|
249
|
+
try {
|
|
250
|
+
const [block] = slate.Editor.node(editor, point.path.slice(0, 1)) ?? [void 0, void 0];
|
|
251
|
+
return block ? [block, point.path] : [void 0, void 0];
|
|
252
|
+
} catch {
|
|
253
|
+
return [void 0, void 0];
|
|
254
|
+
}
|
|
245
255
|
}
|
|
246
256
|
function getFocusChild({
|
|
247
257
|
editor
|
|
@@ -251,8 +261,12 @@ function getFocusChild({
|
|
|
251
261
|
}), childIndex = editor.selection?.focus.path.at(1);
|
|
252
262
|
if (!focusBlock || !focusBlockPath || childIndex === void 0)
|
|
253
263
|
return [void 0, void 0];
|
|
254
|
-
|
|
255
|
-
|
|
264
|
+
try {
|
|
265
|
+
const focusChild = slate.Node.child(focusBlock, childIndex);
|
|
266
|
+
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
267
|
+
} catch {
|
|
268
|
+
return [void 0, void 0];
|
|
269
|
+
}
|
|
256
270
|
}
|
|
257
271
|
function getPointChild({
|
|
258
272
|
editor,
|
|
@@ -275,13 +289,21 @@ function getFirstBlock({
|
|
|
275
289
|
editor
|
|
276
290
|
}) {
|
|
277
291
|
const firstBlockPath = slate.Editor.start(editor, []).path.at(0);
|
|
278
|
-
|
|
292
|
+
try {
|
|
293
|
+
return firstBlockPath !== void 0 ? slate.Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
294
|
+
} catch {
|
|
295
|
+
return [void 0, void 0];
|
|
296
|
+
}
|
|
279
297
|
}
|
|
280
298
|
function getLastBlock({
|
|
281
299
|
editor
|
|
282
300
|
}) {
|
|
283
301
|
const lastBlockPath = slate.Editor.end(editor, []).path.at(0);
|
|
284
|
-
|
|
302
|
+
try {
|
|
303
|
+
return lastBlockPath !== void 0 ? slate.Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
304
|
+
} catch {
|
|
305
|
+
return [void 0, void 0];
|
|
306
|
+
}
|
|
285
307
|
}
|
|
286
308
|
function getNodeBlock({
|
|
287
309
|
editor,
|