@portabletext/editor 1.44.7 → 1.44.8
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/index.cjs +15 -7
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +15 -7
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/range-decorations-machine.ts +39 -24
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {isEqual} from 'lodash'
|
|
2
2
|
import {
|
|
3
|
+
Element,
|
|
3
4
|
Path,
|
|
4
5
|
Range,
|
|
5
6
|
type BaseRange,
|
|
@@ -224,6 +225,8 @@ export const rangeDecorationsMachine = setup({
|
|
|
224
225
|
'slate operation listener': fromCallback(slateOperationCallback),
|
|
225
226
|
},
|
|
226
227
|
guards: {
|
|
228
|
+
'has pending range decorations': ({context}) =>
|
|
229
|
+
context.pendingRangeDecorations.length > 0,
|
|
227
230
|
'has range decorations': ({context}) => context.decoratedRanges.length > 0,
|
|
228
231
|
'has different decorations': ({context, event}) => {
|
|
229
232
|
assertEvent(event, 'range decorations updated')
|
|
@@ -274,10 +277,19 @@ export const rangeDecorationsMachine = setup({
|
|
|
274
277
|
'range decorations updated': {
|
|
275
278
|
actions: ['update pending range decorations'],
|
|
276
279
|
},
|
|
277
|
-
'ready':
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
'ready': [
|
|
281
|
+
{
|
|
282
|
+
target: 'ready',
|
|
283
|
+
guard: 'has pending range decorations',
|
|
284
|
+
actions: [
|
|
285
|
+
'set up initial range decorations',
|
|
286
|
+
'increment update count',
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
target: 'ready',
|
|
291
|
+
},
|
|
292
|
+
],
|
|
281
293
|
},
|
|
282
294
|
},
|
|
283
295
|
ready: {
|
|
@@ -312,7 +324,7 @@ export const rangeDecorationsMachine = setup({
|
|
|
312
324
|
export function createDecorate(
|
|
313
325
|
rangeDecorationActor: ActorRefFrom<typeof rangeDecorationsMachine>,
|
|
314
326
|
) {
|
|
315
|
-
return function decorate([, path]: NodeEntry): Array<BaseRange> {
|
|
327
|
+
return function decorate([node, path]: NodeEntry): Array<BaseRange> {
|
|
316
328
|
if (
|
|
317
329
|
isEqualToEmptyEditor(
|
|
318
330
|
rangeDecorationActor.getSnapshot().context.slateEditor.children,
|
|
@@ -339,35 +351,38 @@ export function createDecorate(
|
|
|
339
351
|
return []
|
|
340
352
|
}
|
|
341
353
|
|
|
342
|
-
|
|
354
|
+
if (!Element.isElement(node) || node.children.length === 0) {
|
|
355
|
+
return []
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const blockIndex = path.at(0)
|
|
359
|
+
|
|
360
|
+
if (blockIndex === undefined) {
|
|
361
|
+
return []
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return rangeDecorationActor
|
|
343
365
|
.getSnapshot()
|
|
344
|
-
.context.decoratedRanges.filter((
|
|
366
|
+
.context.decoratedRanges.filter((decoratedRange) => {
|
|
345
367
|
// Special case in order to only return one decoration for collapsed ranges
|
|
346
|
-
if (Range.isCollapsed(
|
|
368
|
+
if (Range.isCollapsed(decoratedRange)) {
|
|
347
369
|
// Collapsed ranges should only be decorated if they are on a block child level (length 2)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
370
|
+
return node.children.some(
|
|
371
|
+
(_, childIndex) =>
|
|
372
|
+
Path.equals(decoratedRange.anchor.path, [
|
|
373
|
+
blockIndex,
|
|
374
|
+
childIndex,
|
|
375
|
+
]) &&
|
|
376
|
+
Path.equals(decoratedRange.focus.path, [blockIndex, childIndex]),
|
|
355
377
|
)
|
|
356
378
|
}
|
|
357
379
|
|
|
358
|
-
// Include decorations that either include or intersects with this path
|
|
359
380
|
return (
|
|
360
|
-
Range.intersection(
|
|
381
|
+
Range.intersection(decoratedRange, {
|
|
361
382
|
anchor: {path, offset: 0},
|
|
362
383
|
focus: {path, offset: 0},
|
|
363
|
-
}) || Range.includes(
|
|
384
|
+
}) || Range.includes(decoratedRange, path)
|
|
364
385
|
)
|
|
365
386
|
})
|
|
366
|
-
|
|
367
|
-
if (result.length > 0) {
|
|
368
|
-
return result
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return []
|
|
372
387
|
}
|
|
373
388
|
}
|