@portabletext/editor 1.36.6 → 1.37.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.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +63 -4
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +67 -8
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +1 -0
- package/lib/behaviors/index.d.ts +1 -0
- package/lib/index.d.cts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +1 -0
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +69 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +17 -0
- package/lib/selectors/index.d.ts +17 -0
- package/lib/selectors/index.js +63 -8
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/package.json +7 -7
- package/src/behavior-actions/behavior.action.decorator.add.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.ts +1 -3
- package/src/behavior-actions/behavior.action.insert-blocks.ts +66 -1
- package/src/editor/editor-machine.ts +16 -3
- package/src/editor/editor-selector.ts +1 -0
- package/src/editor/editor-snapshot.ts +4 -0
- package/src/internal-utils/create-test-snapshot.ts +1 -0
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-focus-inline-object.ts +21 -0
- package/src/selectors/selector.is-overlapping-selection.test.ts +171 -0
- package/src/selectors/selector.is-overlapping-selection.ts +108 -4
- package/src/selectors/selector.is-point-after-selection.ts +3 -1
- package/src/selectors/selector.is-point-before-selection.ts +3 -1
- package/src/selectors/selector.is-selecting-entire-blocks.ts +34 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var types = require("@sanity/types"),
|
|
2
|
+
var types = require("@sanity/types"), util_sliceBlocks = require("./util.slice-blocks.cjs"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_getTextBefore = require("./selector.get-text-before.cjs"), behavior_core = require("./behavior.core.cjs");
|
|
3
3
|
function createMarkdownBehaviors(config) {
|
|
4
4
|
const automaticBlockquoteOnSpace = behavior_core.defineBehavior({
|
|
5
5
|
on: "insert.text",
|
|
@@ -3041,6 +3041,7 @@ const decoratorAddActionImplementation = ({
|
|
|
3041
3041
|
activeDecorators: [],
|
|
3042
3042
|
converters: [],
|
|
3043
3043
|
keyGenerator: context.keyGenerator,
|
|
3044
|
+
readOnly: !1,
|
|
3044
3045
|
schema: context.schema,
|
|
3045
3046
|
selection: newSelection,
|
|
3046
3047
|
value: newValue
|
|
@@ -4235,7 +4236,9 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4235
4236
|
const range = toSlateRange(action.selection, action.editor);
|
|
4236
4237
|
if (!range)
|
|
4237
4238
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(action.selection)}`);
|
|
4238
|
-
|
|
4239
|
+
action.editor.delete({
|
|
4240
|
+
at: range
|
|
4241
|
+
});
|
|
4239
4242
|
}, deleteTextActionImplementation = ({
|
|
4240
4243
|
context,
|
|
4241
4244
|
action
|
|
@@ -4258,6 +4261,7 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4258
4261
|
schema: context.schema,
|
|
4259
4262
|
keyGenerator: context.keyGenerator,
|
|
4260
4263
|
activeDecorators: [],
|
|
4264
|
+
readOnly: !1,
|
|
4261
4265
|
value,
|
|
4262
4266
|
selection
|
|
4263
4267
|
}
|
|
@@ -4323,6 +4327,44 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4323
4327
|
const nextPath = [focusPath[0] + 1];
|
|
4324
4328
|
slate.Transforms.insertNodes(action.editor, fragment, {
|
|
4325
4329
|
at: nextPath
|
|
4330
|
+
});
|
|
4331
|
+
const [nextBlock, nextBlockPath] = slate.Editor.node(action.editor, slate.Path.next(focusPath), {
|
|
4332
|
+
depth: 1
|
|
4333
|
+
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
4334
|
+
!action.editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(action.editor, {
|
|
4335
|
+
_key: context.keyGenerator(),
|
|
4336
|
+
_type: "span",
|
|
4337
|
+
text: "",
|
|
4338
|
+
marks: []
|
|
4339
|
+
}, {
|
|
4340
|
+
at: [nextBlockPath[0], 0]
|
|
4341
|
+
}), slate.Transforms.select(action.editor, {
|
|
4342
|
+
anchor: {
|
|
4343
|
+
path: [nextPath[0], 0],
|
|
4344
|
+
offset: 0
|
|
4345
|
+
},
|
|
4346
|
+
focus: {
|
|
4347
|
+
path: [nextPath[0], 0],
|
|
4348
|
+
offset: 0
|
|
4349
|
+
}
|
|
4350
|
+
});
|
|
4351
|
+
return;
|
|
4352
|
+
}
|
|
4353
|
+
if (!action.editor.isTextBlock(focusBlock)) {
|
|
4354
|
+
const nextPath = [focusPath[0] + 1];
|
|
4355
|
+
slate.Transforms.insertNodes(action.editor, fragment, {
|
|
4356
|
+
at: nextPath
|
|
4357
|
+
});
|
|
4358
|
+
const [nextBlock, nextBlockPath] = slate.Editor.node(action.editor, slate.Path.next(focusPath), {
|
|
4359
|
+
depth: 1
|
|
4360
|
+
}), nextChild = slate.Node.child(nextBlock, 0);
|
|
4361
|
+
!action.editor.isTextSpan(nextChild) && slate.Transforms.insertNodes(action.editor, {
|
|
4362
|
+
_key: context.keyGenerator(),
|
|
4363
|
+
_type: "span",
|
|
4364
|
+
text: "",
|
|
4365
|
+
marks: []
|
|
4366
|
+
}, {
|
|
4367
|
+
at: [nextBlockPath[0], 0]
|
|
4326
4368
|
}), slate.Transforms.select(action.editor, {
|
|
4327
4369
|
anchor: {
|
|
4328
4370
|
path: [nextPath[0], 0],
|
|
@@ -6058,6 +6100,7 @@ function createEditorSnapshot({
|
|
|
6058
6100
|
converters,
|
|
6059
6101
|
editor,
|
|
6060
6102
|
keyGenerator,
|
|
6103
|
+
readOnly,
|
|
6061
6104
|
schema: schema2,
|
|
6062
6105
|
hasTag
|
|
6063
6106
|
}) {
|
|
@@ -6070,6 +6113,7 @@ function createEditorSnapshot({
|
|
|
6070
6113
|
}),
|
|
6071
6114
|
converters,
|
|
6072
6115
|
keyGenerator,
|
|
6116
|
+
readOnly,
|
|
6073
6117
|
schema: schema2,
|
|
6074
6118
|
selection,
|
|
6075
6119
|
value
|
|
@@ -6177,7 +6221,10 @@ const editorMachine = xstate.setup({
|
|
|
6177
6221
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6178
6222
|
try {
|
|
6179
6223
|
performAction({
|
|
6180
|
-
context
|
|
6224
|
+
context: {
|
|
6225
|
+
keyGenerator: context.keyGenerator,
|
|
6226
|
+
schema: context.schema
|
|
6227
|
+
},
|
|
6181
6228
|
action: defaultAction
|
|
6182
6229
|
});
|
|
6183
6230
|
} catch (error) {
|
|
@@ -6190,6 +6237,9 @@ const editorMachine = xstate.setup({
|
|
|
6190
6237
|
converters: [...context.converters],
|
|
6191
6238
|
editor: event.editor,
|
|
6192
6239
|
keyGenerator: context.keyGenerator,
|
|
6240
|
+
readOnly: self.getSnapshot().matches({
|
|
6241
|
+
"edit mode": "read only"
|
|
6242
|
+
}),
|
|
6193
6243
|
schema: context.schema,
|
|
6194
6244
|
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6195
6245
|
});
|
|
@@ -6228,7 +6278,10 @@ const editorMachine = xstate.setup({
|
|
|
6228
6278
|
};
|
|
6229
6279
|
try {
|
|
6230
6280
|
performAction({
|
|
6231
|
-
context
|
|
6281
|
+
context: {
|
|
6282
|
+
keyGenerator: context.keyGenerator,
|
|
6283
|
+
schema: context.schema
|
|
6284
|
+
},
|
|
6232
6285
|
action: internalAction
|
|
6233
6286
|
});
|
|
6234
6287
|
} catch (error) {
|
|
@@ -6258,7 +6311,10 @@ const editorMachine = xstate.setup({
|
|
|
6258
6311
|
withApplyingBehaviorActions(event.editor, () => {
|
|
6259
6312
|
try {
|
|
6260
6313
|
performAction({
|
|
6261
|
-
context
|
|
6314
|
+
context: {
|
|
6315
|
+
keyGenerator: context.keyGenerator,
|
|
6316
|
+
schema: context.schema
|
|
6317
|
+
},
|
|
6262
6318
|
action: defaultAction
|
|
6263
6319
|
});
|
|
6264
6320
|
} catch (error) {
|
|
@@ -6649,6 +6705,9 @@ function getEditorSnapshot({
|
|
|
6649
6705
|
slateEditorInstance
|
|
6650
6706
|
}),
|
|
6651
6707
|
keyGenerator: editorActorSnapshot.context.keyGenerator,
|
|
6708
|
+
readOnly: editorActorSnapshot.matches({
|
|
6709
|
+
"edit mode": "read only"
|
|
6710
|
+
}),
|
|
6652
6711
|
schema: editorActorSnapshot.context.schema,
|
|
6653
6712
|
selection: editorActorSnapshot.context.selection,
|
|
6654
6713
|
value: getValue({
|