@portabletext/editor 1.44.1 → 1.44.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.
- package/lib/_chunks-cjs/behavior.core.cjs +3 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +166 -272
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +3 -3
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +167 -273
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.cjs +2 -2
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +7951 -15846
- package/lib/behaviors/index.d.ts +7951 -15846
- package/lib/behaviors/index.js +4 -4
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +2 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1742 -15478
- package/lib/index.d.ts +1742 -15478
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +1742 -15479
- package/lib/plugins/index.d.ts +1742 -15479
- package/lib/selectors/index.d.cts +1739 -15475
- package/lib/selectors/index.d.ts +1739 -15475
- package/lib/utils/index.d.cts +1739 -15475
- package/lib/utils/index.d.ts +1739 -15475
- package/package.json +1 -1
- package/src/behavior-actions/behavior.actions.ts +0 -18
- package/src/behaviors/{behavior.internal.annotation.ts → behavior.abstract.annotation.ts} +1 -1
- package/src/behaviors/{behavior.internal.decorator.ts → behavior.abstract.decorator.ts} +1 -1
- package/src/behaviors/{behavior.internal.insert.ts → behavior.abstract.insert.ts} +1 -1
- package/src/behaviors/{behavior.internal.list-item.ts → behavior.abstract.list-item.ts} +1 -1
- package/src/behaviors/behavior.abstract.move.ts +78 -0
- package/src/behaviors/{behavior.internal.select.ts → behavior.abstract.select.ts} +1 -1
- package/src/behaviors/{behavior.internal.style.ts → behavior.abstract.style.ts} +1 -1
- package/src/behaviors/behavior.code-editor.ts +13 -8
- package/src/behaviors/behavior.default.ts +14 -12
- package/src/behaviors/behavior.perform-event.ts +4 -4
- package/src/behaviors/behavior.types.action.ts +3 -3
- package/src/behaviors/behavior.types.behavior.ts +4 -3
- package/src/behaviors/behavior.types.event.ts +153 -153
- package/src/editor/components/Leaf.tsx +2 -2
- package/src/editor/create-editor.ts +37 -11
- package/src/editor/editor-machine.ts +4 -76
- package/src/editor/editor-selector.ts +5 -2
- package/src/editor/editor-snapshot.ts +2 -7
- package/src/editor/plugins/create-with-event-listeners.ts +1 -64
- package/src/editor/plugins/with-plugins.ts +1 -4
- package/src/internal-utils/slate-children-to-blocks.ts +49 -0
- package/src/internal-utils/slate-utils.ts +6 -8
- package/src/type-utils.ts +2 -0
- package/src/behavior-actions/behavior.action.move.block-down.ts +0 -48
- package/src/behavior-actions/behavior.action.move.block-up.ts +0 -53
|
@@ -315,10 +315,7 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
315
315
|
function getFocusBlock({
|
|
316
316
|
editor
|
|
317
317
|
}) {
|
|
318
|
-
return editor.selection ?
|
|
319
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
320
|
-
match: (n) => !slate.Editor.isEditor(n)
|
|
321
|
-
})).at(0) ?? [void 0, void 0] : [void 0, void 0];
|
|
318
|
+
return editor.selection ? slate.Editor.node(editor, editor.selection.focus.path.slice(0, 1)) ?? [void 0, void 0] : [void 0, void 0];
|
|
322
319
|
}
|
|
323
320
|
function getFocusChild({
|
|
324
321
|
editor
|
|
@@ -4426,63 +4423,6 @@ const insertTextActionImplementation = ({
|
|
|
4426
4423
|
to,
|
|
4427
4424
|
mode: "highest"
|
|
4428
4425
|
});
|
|
4429
|
-
}, moveBlockDownActionImplementation = ({
|
|
4430
|
-
context,
|
|
4431
|
-
action
|
|
4432
|
-
}) => {
|
|
4433
|
-
const at = [toSlatePath(action.at, action.editor)[0]], to = [slate.Path.next(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4434
|
-
anchor: {
|
|
4435
|
-
path: to,
|
|
4436
|
-
offset: 0
|
|
4437
|
-
},
|
|
4438
|
-
focus: {
|
|
4439
|
-
path: to,
|
|
4440
|
-
offset: 0
|
|
4441
|
-
}
|
|
4442
|
-
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4443
|
-
if (destinationBlockKey === void 0) {
|
|
4444
|
-
console.error("Could not find destination block key");
|
|
4445
|
-
return;
|
|
4446
|
-
}
|
|
4447
|
-
moveBlockActionImplementation({
|
|
4448
|
-
action: {
|
|
4449
|
-
at: action.at,
|
|
4450
|
-
to: [{
|
|
4451
|
-
_key: destinationBlockKey
|
|
4452
|
-
}],
|
|
4453
|
-
editor: action.editor
|
|
4454
|
-
}
|
|
4455
|
-
});
|
|
4456
|
-
}, moveBlockUpActionImplementation = ({
|
|
4457
|
-
context,
|
|
4458
|
-
action
|
|
4459
|
-
}) => {
|
|
4460
|
-
const at = [toSlatePath(action.at, action.editor)[0]];
|
|
4461
|
-
if (!slate.Path.hasPrevious(at))
|
|
4462
|
-
return;
|
|
4463
|
-
const to = [slate.Path.previous(at)[0]], selection = toPortableTextRange(action.editor.children, {
|
|
4464
|
-
anchor: {
|
|
4465
|
-
path: to,
|
|
4466
|
-
offset: 0
|
|
4467
|
-
},
|
|
4468
|
-
focus: {
|
|
4469
|
-
path: to,
|
|
4470
|
-
offset: 0
|
|
4471
|
-
}
|
|
4472
|
-
}, context.schema), destinationBlockKey = selection && util_sliceBlocks.isKeyedSegment(selection.focus.path[0]) ? selection.focus.path[0]._key : void 0;
|
|
4473
|
-
if (destinationBlockKey === void 0) {
|
|
4474
|
-
console.error("Could not find destination block key");
|
|
4475
|
-
return;
|
|
4476
|
-
}
|
|
4477
|
-
moveBlockActionImplementation({
|
|
4478
|
-
action: {
|
|
4479
|
-
at: action.at,
|
|
4480
|
-
to: [{
|
|
4481
|
-
_key: destinationBlockKey
|
|
4482
|
-
}],
|
|
4483
|
-
editor: action.editor
|
|
4484
|
-
}
|
|
4485
|
-
});
|
|
4486
4426
|
}, noopActionImplementation = () => {
|
|
4487
4427
|
}, selectActionImplementation = ({
|
|
4488
4428
|
action
|
|
@@ -4513,8 +4453,6 @@ const insertTextActionImplementation = ({
|
|
|
4513
4453
|
"insert.text": insertTextActionImplementation,
|
|
4514
4454
|
effect: effectActionImplementation,
|
|
4515
4455
|
"move.block": moveBlockActionImplementation,
|
|
4516
|
-
"move.block down": moveBlockDownActionImplementation,
|
|
4517
|
-
"move.block up": moveBlockUpActionImplementation,
|
|
4518
4456
|
noop: noopActionImplementation,
|
|
4519
4457
|
select: selectActionImplementation
|
|
4520
4458
|
};
|
|
@@ -4684,20 +4622,6 @@ function performAction({
|
|
|
4684
4622
|
});
|
|
4685
4623
|
break;
|
|
4686
4624
|
}
|
|
4687
|
-
case "move.block down": {
|
|
4688
|
-
behaviorActionImplementations["move.block down"]({
|
|
4689
|
-
context,
|
|
4690
|
-
action
|
|
4691
|
-
});
|
|
4692
|
-
break;
|
|
4693
|
-
}
|
|
4694
|
-
case "move.block up": {
|
|
4695
|
-
behaviorActionImplementations["move.block up"]({
|
|
4696
|
-
context,
|
|
4697
|
-
action
|
|
4698
|
-
});
|
|
4699
|
-
break;
|
|
4700
|
-
}
|
|
4701
4625
|
case "noop":
|
|
4702
4626
|
break;
|
|
4703
4627
|
default: {
|
|
@@ -4709,65 +4633,10 @@ function performAction({
|
|
|
4709
4633
|
}
|
|
4710
4634
|
}
|
|
4711
4635
|
}
|
|
4712
|
-
function createWithEventListeners(editorActor
|
|
4636
|
+
function createWithEventListeners(editorActor) {
|
|
4713
4637
|
return function(editor) {
|
|
4714
4638
|
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
4715
4639
|
return editor;
|
|
4716
|
-
subscriptions.push(() => {
|
|
4717
|
-
const subscription = editorActor.on("*", (event) => {
|
|
4718
|
-
switch (event.type) {
|
|
4719
|
-
// These events are not relevant for Behaviors
|
|
4720
|
-
case "blurred":
|
|
4721
|
-
case "done loading":
|
|
4722
|
-
case "editable":
|
|
4723
|
-
case "error":
|
|
4724
|
-
case "focused":
|
|
4725
|
-
case "invalid value":
|
|
4726
|
-
case "loading":
|
|
4727
|
-
case "mutation":
|
|
4728
|
-
case "patch":
|
|
4729
|
-
case "internal.patch":
|
|
4730
|
-
case "patches":
|
|
4731
|
-
case "read only":
|
|
4732
|
-
case "ready":
|
|
4733
|
-
case "selection":
|
|
4734
|
-
case "value changed":
|
|
4735
|
-
case "unset":
|
|
4736
|
-
break;
|
|
4737
|
-
case "custom.*":
|
|
4738
|
-
editorActor.send({
|
|
4739
|
-
type: "custom behavior event",
|
|
4740
|
-
behaviorEvent: event.event,
|
|
4741
|
-
editor
|
|
4742
|
-
});
|
|
4743
|
-
break;
|
|
4744
|
-
case "insert.block object":
|
|
4745
|
-
editorActor.send({
|
|
4746
|
-
type: "behavior event",
|
|
4747
|
-
behaviorEvent: {
|
|
4748
|
-
type: "insert.block",
|
|
4749
|
-
block: {
|
|
4750
|
-
_type: event.blockObject.name,
|
|
4751
|
-
...event.blockObject.value ?? {}
|
|
4752
|
-
},
|
|
4753
|
-
placement: event.placement
|
|
4754
|
-
},
|
|
4755
|
-
editor
|
|
4756
|
-
});
|
|
4757
|
-
break;
|
|
4758
|
-
default:
|
|
4759
|
-
editorActor.send({
|
|
4760
|
-
type: "behavior event",
|
|
4761
|
-
behaviorEvent: event,
|
|
4762
|
-
editor
|
|
4763
|
-
});
|
|
4764
|
-
break;
|
|
4765
|
-
}
|
|
4766
|
-
});
|
|
4767
|
-
return () => {
|
|
4768
|
-
subscription.unsubscribe();
|
|
4769
|
-
};
|
|
4770
|
-
});
|
|
4771
4640
|
const {
|
|
4772
4641
|
deleteBackward,
|
|
4773
4642
|
deleteForward,
|
|
@@ -5578,7 +5447,7 @@ const withPlugins = (editor, options) => {
|
|
|
5578
5447
|
editorActor,
|
|
5579
5448
|
schemaTypes
|
|
5580
5449
|
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
5581
|
-
return createWithEventListeners(editorActor
|
|
5450
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e)))))))))));
|
|
5582
5451
|
}, debug$3 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
5583
5452
|
function createSlateEditor(config) {
|
|
5584
5453
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
@@ -5600,17 +5469,7 @@ function createSlateEditor(config) {
|
|
|
5600
5469
|
};
|
|
5601
5470
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5602
5471
|
}
|
|
5603
|
-
const
|
|
5604
|
-
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
5605
|
-
}, raiseInsertSoftBreak = behavior_core.defineBehavior({
|
|
5606
|
-
on: "keyboard.keydown",
|
|
5607
|
-
guard: ({
|
|
5608
|
-
event
|
|
5609
|
-
}) => keyIs.lineBreak(event.originEvent),
|
|
5610
|
-
actions: [() => [behavior_core.raise({
|
|
5611
|
-
type: "insert.soft break"
|
|
5612
|
-
})]]
|
|
5613
|
-
}), internalAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
5472
|
+
const abstractAnnotationBehaviors = [behavior_core.defineBehavior({
|
|
5614
5473
|
on: "annotation.toggle",
|
|
5615
5474
|
guard: ({
|
|
5616
5475
|
snapshot,
|
|
@@ -5634,7 +5493,7 @@ const keyIs = {
|
|
|
5634
5493
|
type: "annotation.add",
|
|
5635
5494
|
annotation: event.annotation
|
|
5636
5495
|
})]]
|
|
5637
|
-
})],
|
|
5496
|
+
})], abstractDecoratorBehaviors = [behavior_core.defineBehavior({
|
|
5638
5497
|
on: "decorator.toggle",
|
|
5639
5498
|
guard: ({
|
|
5640
5499
|
snapshot,
|
|
@@ -5670,7 +5529,7 @@ const keyIs = {
|
|
|
5670
5529
|
...event,
|
|
5671
5530
|
type: "decorator.add"
|
|
5672
5531
|
})]]
|
|
5673
|
-
})],
|
|
5532
|
+
})], abstractInsertBehaviors = [behavior_core.defineBehavior({
|
|
5674
5533
|
on: "insert.blocks",
|
|
5675
5534
|
guard: ({
|
|
5676
5535
|
event
|
|
@@ -5746,7 +5605,7 @@ const keyIs = {
|
|
|
5746
5605
|
placement: index === 0 ? "auto" : "after",
|
|
5747
5606
|
select: "end"
|
|
5748
5607
|
}))]
|
|
5749
|
-
})],
|
|
5608
|
+
})], abstractListItemBehaviors = [behavior_core.defineBehavior({
|
|
5750
5609
|
on: "list item.add",
|
|
5751
5610
|
guard: ({
|
|
5752
5611
|
snapshot
|
|
@@ -5803,7 +5662,75 @@ const keyIs = {
|
|
|
5803
5662
|
type: "list item.add",
|
|
5804
5663
|
listItem: event.listItem
|
|
5805
5664
|
})]]
|
|
5806
|
-
})],
|
|
5665
|
+
})], abstractMoveBehaviors = [behavior_core.defineBehavior({
|
|
5666
|
+
on: "move.block up",
|
|
5667
|
+
guard: ({
|
|
5668
|
+
snapshot,
|
|
5669
|
+
event
|
|
5670
|
+
}) => {
|
|
5671
|
+
const previousBlock = selector_isOverlappingSelection.getPreviousBlock({
|
|
5672
|
+
context: {
|
|
5673
|
+
...snapshot.context,
|
|
5674
|
+
selection: {
|
|
5675
|
+
anchor: {
|
|
5676
|
+
path: event.at,
|
|
5677
|
+
offset: 0
|
|
5678
|
+
},
|
|
5679
|
+
focus: {
|
|
5680
|
+
path: event.at,
|
|
5681
|
+
offset: 0
|
|
5682
|
+
}
|
|
5683
|
+
}
|
|
5684
|
+
}
|
|
5685
|
+
});
|
|
5686
|
+
return previousBlock ? {
|
|
5687
|
+
previousBlock
|
|
5688
|
+
} : !1;
|
|
5689
|
+
},
|
|
5690
|
+
actions: [({
|
|
5691
|
+
event
|
|
5692
|
+
}, {
|
|
5693
|
+
previousBlock
|
|
5694
|
+
}) => [behavior_core.raise({
|
|
5695
|
+
type: "move.block",
|
|
5696
|
+
at: event.at,
|
|
5697
|
+
to: previousBlock.path
|
|
5698
|
+
})]]
|
|
5699
|
+
}), behavior_core.defineBehavior({
|
|
5700
|
+
on: "move.block down",
|
|
5701
|
+
guard: ({
|
|
5702
|
+
snapshot,
|
|
5703
|
+
event
|
|
5704
|
+
}) => {
|
|
5705
|
+
const nextBlock = selector_isOverlappingSelection.getNextBlock({
|
|
5706
|
+
context: {
|
|
5707
|
+
...snapshot.context,
|
|
5708
|
+
selection: {
|
|
5709
|
+
anchor: {
|
|
5710
|
+
path: event.at,
|
|
5711
|
+
offset: 0
|
|
5712
|
+
},
|
|
5713
|
+
focus: {
|
|
5714
|
+
path: event.at,
|
|
5715
|
+
offset: 0
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
}
|
|
5719
|
+
});
|
|
5720
|
+
return nextBlock ? {
|
|
5721
|
+
nextBlock
|
|
5722
|
+
} : !1;
|
|
5723
|
+
},
|
|
5724
|
+
actions: [({
|
|
5725
|
+
event
|
|
5726
|
+
}, {
|
|
5727
|
+
nextBlock
|
|
5728
|
+
}) => [behavior_core.raise({
|
|
5729
|
+
type: "move.block",
|
|
5730
|
+
at: event.at,
|
|
5731
|
+
to: nextBlock.path
|
|
5732
|
+
})]]
|
|
5733
|
+
})], abstractSelectBehaviors = [behavior_core.defineBehavior({
|
|
5807
5734
|
on: "select.previous block",
|
|
5808
5735
|
guard: ({
|
|
5809
5736
|
snapshot,
|
|
@@ -5849,7 +5776,7 @@ const keyIs = {
|
|
|
5849
5776
|
type: "select",
|
|
5850
5777
|
selection
|
|
5851
5778
|
})]]
|
|
5852
|
-
})],
|
|
5779
|
+
})], abstractStyleBehaviors = [behavior_core.defineBehavior({
|
|
5853
5780
|
on: "style.add",
|
|
5854
5781
|
guard: ({
|
|
5855
5782
|
snapshot
|
|
@@ -5905,7 +5832,17 @@ const keyIs = {
|
|
|
5905
5832
|
type: "style.add",
|
|
5906
5833
|
style: event.style
|
|
5907
5834
|
})]]
|
|
5908
|
-
})],
|
|
5835
|
+
})], keyIs = {
|
|
5836
|
+
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
5837
|
+
}, raiseInsertSoftBreak = behavior_core.defineBehavior({
|
|
5838
|
+
on: "keyboard.keydown",
|
|
5839
|
+
guard: ({
|
|
5840
|
+
event
|
|
5841
|
+
}) => keyIs.lineBreak(event.originEvent),
|
|
5842
|
+
actions: [() => [behavior_core.raise({
|
|
5843
|
+
type: "insert.soft break"
|
|
5844
|
+
})]]
|
|
5845
|
+
}), raiseDeserializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
5909
5846
|
on: "deserialize",
|
|
5910
5847
|
guard: ({
|
|
5911
5848
|
snapshot,
|
|
@@ -6233,43 +6170,30 @@ const keyIs = {
|
|
|
6233
6170
|
originEvent: event
|
|
6234
6171
|
})]]
|
|
6235
6172
|
}),
|
|
6236
|
-
...
|
|
6237
|
-
...
|
|
6238
|
-
...
|
|
6239
|
-
...
|
|
6240
|
-
...
|
|
6241
|
-
...
|
|
6173
|
+
...abstractAnnotationBehaviors,
|
|
6174
|
+
...abstractDecoratorBehaviors,
|
|
6175
|
+
...abstractInsertBehaviors,
|
|
6176
|
+
...abstractListItemBehaviors,
|
|
6177
|
+
...abstractMoveBehaviors,
|
|
6178
|
+
...abstractStyleBehaviors,
|
|
6179
|
+
...abstractSelectBehaviors,
|
|
6242
6180
|
raiseDeserializationSuccessOrFailure,
|
|
6243
6181
|
raiseSerializationSuccessOrFailure,
|
|
6244
6182
|
raiseInsertSoftBreak
|
|
6245
|
-
];
|
|
6246
|
-
function
|
|
6247
|
-
return event.type
|
|
6248
|
-
}
|
|
6249
|
-
function isInternalBehaviorEvent(event) {
|
|
6250
|
-
return event.type === "deserialize" || event.type.startsWith("deserialization.") || event.type === "insert.blocks" || event.type.startsWith("list item.") || event.type === "serialize" || event.type.startsWith("serialization.") || event.type === "select.next block" || event.type === "select.previous block" || event.type.startsWith("style.");
|
|
6183
|
+
], abstractBehaviorEventTypes = ["annotation.toggle", "decorator.toggle", "deserialize", "deserialization.success", "deserialization.failure", "insert.blocks", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialization.success", "serialization.failure", "style.add", "style.remove", "style.toggle"];
|
|
6184
|
+
function isAbstractBehaviorEvent(event) {
|
|
6185
|
+
return abstractBehaviorEventTypes.includes(event.type);
|
|
6251
6186
|
}
|
|
6187
|
+
const nativeBehaviorEventTypes = ["clipboard.copy", "clipboard.cut", "clipboard.paste", "drag.dragstart", "drag.drag", "drag.dragend", "drag.dragenter", "drag.dragover", "drag.dragleave", "drag.drop", "input.*", "keyboard.keydown", "keyboard.keyup", "mouse.click"];
|
|
6252
6188
|
function isNativeBehaviorEvent(event) {
|
|
6253
|
-
return
|
|
6254
|
-
}
|
|
6255
|
-
function isClipboardBehaviorEvent(event) {
|
|
6256
|
-
return event.type.startsWith("clipboard.");
|
|
6257
|
-
}
|
|
6258
|
-
function isDragBehaviorEvent(event) {
|
|
6259
|
-
return event.type.startsWith("drag.");
|
|
6260
|
-
}
|
|
6261
|
-
function isInputBehaviorEvent(event) {
|
|
6262
|
-
return event.type.startsWith("input.");
|
|
6263
|
-
}
|
|
6264
|
-
function isMouseBehaviorEvent(event) {
|
|
6265
|
-
return event.type.startsWith("mouse.");
|
|
6189
|
+
return nativeBehaviorEventTypes.includes(event.type);
|
|
6266
6190
|
}
|
|
6267
6191
|
function isCustomBehaviorEvent(event) {
|
|
6268
6192
|
return event.type.startsWith("custom.");
|
|
6269
6193
|
}
|
|
6270
6194
|
const debug$2 = debugWithName("behaviors:event");
|
|
6271
6195
|
function eventCategory(event) {
|
|
6272
|
-
return isNativeBehaviorEvent(event) ? "native" :
|
|
6196
|
+
return isNativeBehaviorEvent(event) ? "native" : isAbstractBehaviorEvent(event) ? "abstract" : isCustomBehaviorEvent(event) ? "custom" : "synthetic";
|
|
6273
6197
|
}
|
|
6274
6198
|
function performEvent({
|
|
6275
6199
|
behaviors,
|
|
@@ -6282,7 +6206,7 @@ function performEvent({
|
|
|
6282
6206
|
defaultActionCallback
|
|
6283
6207
|
}) {
|
|
6284
6208
|
debug$2(`(${eventCategory(event)})`, JSON.stringify(event, null, 2));
|
|
6285
|
-
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) ||
|
|
6209
|
+
const defaultAction = isCustomBehaviorEvent(event) || isNativeBehaviorEvent(event) || isAbstractBehaviorEvent(event) ? void 0 : {
|
|
6286
6210
|
...event,
|
|
6287
6211
|
editor
|
|
6288
6212
|
}, eventBehaviors = behaviors.filter((behavior) => {
|
|
@@ -6401,6 +6325,34 @@ function performEvent({
|
|
|
6401
6325
|
}), editor.onChange();
|
|
6402
6326
|
}
|
|
6403
6327
|
}
|
|
6328
|
+
function slateChildrenToBlocks(schema2, value) {
|
|
6329
|
+
const blocks = new Array(value.length);
|
|
6330
|
+
for (let blockIndex = 0; blockIndex < value.length; blockIndex++) {
|
|
6331
|
+
const descendant = value[blockIndex];
|
|
6332
|
+
if (descendant._type !== schema2.block.name) {
|
|
6333
|
+
blocks[blockIndex] = {
|
|
6334
|
+
_key: descendant._key,
|
|
6335
|
+
_type: descendant._type,
|
|
6336
|
+
..."value" in descendant && typeof descendant.value == "object" ? descendant.value : {}
|
|
6337
|
+
};
|
|
6338
|
+
continue;
|
|
6339
|
+
}
|
|
6340
|
+
const children = "children" in descendant ? descendant.children : [], processedChildren = new Array(children.length);
|
|
6341
|
+
for (let childIndex = 0; childIndex < children.length; childIndex++) {
|
|
6342
|
+
const child = children[childIndex];
|
|
6343
|
+
processedChildren[childIndex] = child._type === schema2.span.name ? child : {
|
|
6344
|
+
_key: child._key,
|
|
6345
|
+
_type: child._type,
|
|
6346
|
+
..."value" in child && typeof child.value == "object" ? child.value : {}
|
|
6347
|
+
};
|
|
6348
|
+
}
|
|
6349
|
+
blocks[blockIndex] = {
|
|
6350
|
+
...descendant,
|
|
6351
|
+
children: processedChildren
|
|
6352
|
+
};
|
|
6353
|
+
}
|
|
6354
|
+
return blocks;
|
|
6355
|
+
}
|
|
6404
6356
|
function getActiveDecorators({
|
|
6405
6357
|
schema: schema2,
|
|
6406
6358
|
slateEditorInstance
|
|
@@ -6419,7 +6371,7 @@ function createEditorSnapshot({
|
|
|
6419
6371
|
hasTag,
|
|
6420
6372
|
internalDrag
|
|
6421
6373
|
}) {
|
|
6422
|
-
const value =
|
|
6374
|
+
const value = slateChildrenToBlocks(schema2, editor.children), selection = toPortableTextRange(value, editor.selection, schema2);
|
|
6423
6375
|
return {
|
|
6424
6376
|
context: {
|
|
6425
6377
|
activeDecorators: getActiveDecorators({
|
|
@@ -6515,7 +6467,7 @@ const editorMachine = xstate.setup({
|
|
|
6515
6467
|
event,
|
|
6516
6468
|
self
|
|
6517
6469
|
}) => {
|
|
6518
|
-
xstate.assertEvent(event, ["behavior event"
|
|
6470
|
+
xstate.assertEvent(event, ["behavior event"]), performEvent({
|
|
6519
6471
|
behaviors: [...context.behaviors.values(), ...defaultBehaviors],
|
|
6520
6472
|
event: event.behaviorEvent,
|
|
6521
6473
|
editor: event.editor,
|
|
@@ -6714,87 +6666,6 @@ const editorMachine = xstate.setup({
|
|
|
6714
6666
|
},
|
|
6715
6667
|
"behavior event": {
|
|
6716
6668
|
actions: "handle behavior event"
|
|
6717
|
-
},
|
|
6718
|
-
"custom behavior event": {
|
|
6719
|
-
actions: "handle behavior event"
|
|
6720
|
-
},
|
|
6721
|
-
"annotation.*": {
|
|
6722
|
-
actions: xstate.emit(({
|
|
6723
|
-
event
|
|
6724
|
-
}) => event)
|
|
6725
|
-
},
|
|
6726
|
-
"block.*": {
|
|
6727
|
-
actions: xstate.emit(({
|
|
6728
|
-
event
|
|
6729
|
-
}) => event)
|
|
6730
|
-
},
|
|
6731
|
-
blur: {
|
|
6732
|
-
actions: xstate.emit(({
|
|
6733
|
-
event
|
|
6734
|
-
}) => event)
|
|
6735
|
-
},
|
|
6736
|
-
"custom.*": {
|
|
6737
|
-
actions: xstate.emit(({
|
|
6738
|
-
event
|
|
6739
|
-
}) => ({
|
|
6740
|
-
type: "custom.*",
|
|
6741
|
-
event
|
|
6742
|
-
}))
|
|
6743
|
-
},
|
|
6744
|
-
"decorator.*": {
|
|
6745
|
-
actions: xstate.emit(({
|
|
6746
|
-
event
|
|
6747
|
-
}) => event)
|
|
6748
|
-
},
|
|
6749
|
-
"delete.*": {
|
|
6750
|
-
actions: xstate.emit(({
|
|
6751
|
-
event
|
|
6752
|
-
}) => event)
|
|
6753
|
-
},
|
|
6754
|
-
focus: {
|
|
6755
|
-
actions: xstate.emit(({
|
|
6756
|
-
event
|
|
6757
|
-
}) => event)
|
|
6758
|
-
},
|
|
6759
|
-
"history.*": {
|
|
6760
|
-
actions: xstate.emit(({
|
|
6761
|
-
event
|
|
6762
|
-
}) => event)
|
|
6763
|
-
},
|
|
6764
|
-
"insert.*": {
|
|
6765
|
-
actions: xstate.emit(({
|
|
6766
|
-
event
|
|
6767
|
-
}) => event)
|
|
6768
|
-
},
|
|
6769
|
-
"list item.*": {
|
|
6770
|
-
actions: xstate.emit(({
|
|
6771
|
-
event
|
|
6772
|
-
}) => event)
|
|
6773
|
-
},
|
|
6774
|
-
"move.*": {
|
|
6775
|
-
actions: xstate.emit(({
|
|
6776
|
-
event
|
|
6777
|
-
}) => event)
|
|
6778
|
-
},
|
|
6779
|
-
select: {
|
|
6780
|
-
actions: xstate.emit(({
|
|
6781
|
-
event
|
|
6782
|
-
}) => event)
|
|
6783
|
-
},
|
|
6784
|
-
"select.*": {
|
|
6785
|
-
actions: xstate.emit(({
|
|
6786
|
-
event
|
|
6787
|
-
}) => event)
|
|
6788
|
-
},
|
|
6789
|
-
"style.*": {
|
|
6790
|
-
actions: xstate.emit(({
|
|
6791
|
-
event
|
|
6792
|
-
}) => event)
|
|
6793
|
-
},
|
|
6794
|
-
"text block.*": {
|
|
6795
|
-
actions: xstate.emit(({
|
|
6796
|
-
event
|
|
6797
|
-
}) => event)
|
|
6798
6669
|
}
|
|
6799
6670
|
},
|
|
6800
6671
|
initial: "idle",
|
|
@@ -6906,12 +6777,6 @@ const editorMachine = xstate.setup({
|
|
|
6906
6777
|
}
|
|
6907
6778
|
}
|
|
6908
6779
|
});
|
|
6909
|
-
function getValue({
|
|
6910
|
-
editorActorSnapshot,
|
|
6911
|
-
slateEditorInstance
|
|
6912
|
-
}) {
|
|
6913
|
-
return fromSlateValue(slateEditorInstance.children, editorActorSnapshot.context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditorInstance));
|
|
6914
|
-
}
|
|
6915
6780
|
function defaultCompare(a, b) {
|
|
6916
6781
|
return a === b;
|
|
6917
6782
|
}
|
|
@@ -6943,10 +6808,7 @@ function getEditorSnapshot({
|
|
|
6943
6808
|
}),
|
|
6944
6809
|
schema: editorActorSnapshot.context.schema,
|
|
6945
6810
|
selection: editorActorSnapshot.context.selection,
|
|
6946
|
-
value:
|
|
6947
|
-
editorActorSnapshot,
|
|
6948
|
-
slateEditorInstance
|
|
6949
|
-
})
|
|
6811
|
+
value: slateChildrenToBlocks(editorActorSnapshot.context.schema, slateEditorInstance.children)
|
|
6950
6812
|
},
|
|
6951
6813
|
beta: {
|
|
6952
6814
|
hasTag: (tag) => editorActorSnapshot.hasTag(tag),
|
|
@@ -7002,7 +6864,39 @@ function createInternalEditorFromActor(editorActor) {
|
|
|
7002
6864
|
});
|
|
7003
6865
|
}),
|
|
7004
6866
|
send: (event) => {
|
|
7005
|
-
|
|
6867
|
+
switch (event.type) {
|
|
6868
|
+
case "add behavior":
|
|
6869
|
+
case "remove behavior":
|
|
6870
|
+
case "update behaviors":
|
|
6871
|
+
case "update key generator":
|
|
6872
|
+
case "update readOnly":
|
|
6873
|
+
case "patches":
|
|
6874
|
+
case "update value":
|
|
6875
|
+
case "update schema":
|
|
6876
|
+
case "update maxBlocks":
|
|
6877
|
+
editorActor.send(event);
|
|
6878
|
+
break;
|
|
6879
|
+
case "insert.block object":
|
|
6880
|
+
editorActor.send({
|
|
6881
|
+
type: "behavior event",
|
|
6882
|
+
behaviorEvent: {
|
|
6883
|
+
type: "insert.block",
|
|
6884
|
+
block: {
|
|
6885
|
+
_type: event.blockObject.name,
|
|
6886
|
+
...event.blockObject.value ?? {}
|
|
6887
|
+
},
|
|
6888
|
+
placement: event.placement
|
|
6889
|
+
},
|
|
6890
|
+
editor: slateEditor.instance
|
|
6891
|
+
});
|
|
6892
|
+
break;
|
|
6893
|
+
default:
|
|
6894
|
+
editorActor.send({
|
|
6895
|
+
type: "behavior event",
|
|
6896
|
+
behaviorEvent: event,
|
|
6897
|
+
editor: slateEditor.instance
|
|
6898
|
+
});
|
|
6899
|
+
}
|
|
7006
6900
|
},
|
|
7007
6901
|
on: (event, listener) => editorActor.on(event, (event2) => {
|
|
7008
6902
|
switch (event2.type) {
|