@portabletext/editor 1.34.1 → 1.35.1
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 +57 -118
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +27 -67
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/{plugin.event-listener.cjs → editor-provider.cjs} +101 -87
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +5 -7
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +22 -36
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +68 -153
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.block-offsets-to-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +57 -118
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +27 -67
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/{plugin.event-listener.js → editor-provider.js} +102 -88
- package/lib/_chunks-es/editor-provider.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +5 -7
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +22 -36
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +68 -153
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -1
- package/lib/_chunks-es/util.block-offsets-to-selection.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/behaviors/index.cjs +18 -48
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +19392 -214
- package/lib/behaviors/index.d.ts +19392 -214
- package/lib/behaviors/index.js +18 -48
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +81 -51
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +334 -59
- package/lib/index.d.ts +334 -59
- package/lib/index.js +35 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +200 -189
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +344 -25
- package/lib/plugins/index.d.ts +344 -25
- package/lib/plugins/index.js +198 -187
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +22 -50
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +19485 -174
- package/lib/selectors/index.d.ts +19485 -174
- package/lib/selectors/index.js +22 -50
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +19518 -7
- package/lib/utils/index.d.ts +19518 -7
- package/lib/utils/index.js.map +1 -1
- 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/behaviors/behavior.code-editor.ts +6 -6
- package/src/behaviors/behavior.core.annotations.ts +5 -4
- package/src/behaviors/behavior.core.block-objects.ts +17 -17
- package/src/behaviors/behavior.core.decorators.ts +12 -8
- package/src/behaviors/behavior.core.insert-break.ts +27 -29
- package/src/behaviors/behavior.core.lists.ts +19 -19
- package/src/behaviors/behavior.decorator-pair.ts +201 -0
- package/src/behaviors/behavior.default.ts +35 -30
- package/src/behaviors/behavior.emoji-picker.ts +12 -12
- package/src/behaviors/behavior.links.ts +7 -7
- package/src/behaviors/behavior.markdown.ts +41 -42
- package/src/behaviors/behavior.types.ts +14 -17
- package/src/behaviors/index.ts +0 -1
- package/src/converters/converter.json.ts +6 -6
- package/src/converters/converter.portable-text.deserialize.test.ts +27 -29
- package/src/converters/converter.portable-text.ts +13 -7
- package/src/converters/converter.text-html.deserialize.test.ts +16 -18
- package/src/converters/converter.text-html.serialize.test.ts +56 -57
- package/src/converters/converter.text-html.ts +14 -10
- package/src/converters/converter.text-plain.test.ts +17 -17
- package/src/converters/converter.text-plain.ts +15 -11
- package/src/converters/converter.types.ts +5 -5
- package/src/editor/Editable.tsx +26 -0
- package/src/editor/editor-machine.ts +170 -142
- package/src/editor/editor-selector.ts +3 -0
- package/src/editor/editor-snapshot.ts +13 -0
- package/src/editor-event-listener.tsx +30 -0
- package/src/index.ts +3 -3
- package/src/internal-utils/create-test-snapshot.ts +23 -0
- package/src/internal-utils/get-text-to-emphasize.ts +29 -7
- package/src/plugins/plugin.decorator-shortcut.ts +235 -0
- package/src/plugins/plugin.markdown.tsx +56 -8
- package/src/plugins/plugin.one-line.tsx +17 -17
- package/src/selectors/selector.get-active-annotations.test.ts +4 -13
- package/src/selectors/selector.get-active-list-item.ts +4 -4
- package/src/selectors/selector.get-active-style.ts +6 -6
- package/src/selectors/selector.get-anchor-block.ts +5 -5
- package/src/selectors/selector.get-anchor-child.ts +5 -5
- package/src/selectors/selector.get-anchor-span.ts +2 -2
- package/src/selectors/selector.get-anchor-text-block.ts +2 -2
- package/src/selectors/selector.get-block-offsets.ts +8 -7
- package/src/selectors/selector.get-caret-word-selection.test.ts +3 -7
- package/src/selectors/selector.get-caret-word-selection.ts +19 -16
- package/src/selectors/selector.get-next-inline-object.ts +4 -4
- package/src/selectors/selector.get-previous-inline-object.ts +4 -4
- package/src/selectors/selector.get-selected-slice.ts +7 -4
- package/src/selectors/selector.get-selected-spans.test.ts +5 -9
- package/src/selectors/selector.get-selected-spans.ts +9 -9
- package/src/selectors/selector.get-selection-end-point.ts +5 -5
- package/src/selectors/selector.get-selection-start-point.ts +5 -5
- package/src/selectors/selector.get-selection-text.test.ts +5 -7
- package/src/selectors/selector.get-selection-text.ts +2 -2
- package/src/selectors/selector.get-selection.ts +2 -2
- package/src/selectors/selector.get-text-before.ts +8 -8
- package/src/selectors/selector.get-trimmed-selection.test.ts +3 -5
- package/src/selectors/selector.get-trimmed-selection.ts +15 -13
- package/src/selectors/selector.get-value.ts +4 -4
- package/src/selectors/selector.is-active-decorator.test.ts +5 -9
- package/src/selectors/selector.is-at-the-end-of-block.ts +6 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +3 -3
- package/src/selectors/selector.is-overlapping-selection.ts +8 -6
- package/src/selectors/selector.is-selection-collapsed.ts +6 -5
- package/src/selectors/selector.is-selection-expanded.ts +2 -2
- package/src/selectors/selectors.ts +59 -59
- package/src/types/block-offset.ts +9 -0
- package/src/utils/index.ts +0 -1
- package/src/utils/util.block-offset.ts +1 -1
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +1 -1
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +0 -1
- package/lib/_chunks-es/plugin.event-listener.js.map +0 -1
- package/src/behaviors/behavior.markdown-emphasis.ts +0 -437
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var jsxRuntime = require("react/jsx-runtime"), reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), slateReact = require("slate-react"), react = require("@xstate/react"), debug$e = require("debug"), slate = require("slate"), xstate = require("xstate"), isEqual = require("lodash/isEqual.js"), patches = require("@portabletext/patches"), types = require("@sanity/types"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), uniq = require("lodash/uniq.js"), getRandomValues = require("get-random-values-esm"), util_blockOffsetsToSelection = require("./util.block-offsets-to-selection.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema = require("@sanity/schema"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), selector_isActiveStyle = require("./selector.is-active-style.cjs"), omit = require("lodash/omit.js"), startCase = require("lodash.startcase"), behavior_core = require("./behavior.core.cjs"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event");
|
|
3
3
|
function _interopDefaultCompat(e) {
|
|
4
4
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
5
5
|
}
|
|
@@ -2255,13 +2255,13 @@ Synchronizer.displayName = "Synchronizer";
|
|
|
2255
2255
|
const converterJson = {
|
|
2256
2256
|
mimeType: "application/json",
|
|
2257
2257
|
serialize: ({
|
|
2258
|
-
|
|
2258
|
+
snapshot,
|
|
2259
2259
|
event
|
|
2260
2260
|
}) => {
|
|
2261
|
-
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2261
|
+
const portableTextConverter = snapshot.context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2262
2262
|
return portableTextConverter ? {
|
|
2263
2263
|
...portableTextConverter.serialize({
|
|
2264
|
-
|
|
2264
|
+
snapshot,
|
|
2265
2265
|
event
|
|
2266
2266
|
}),
|
|
2267
2267
|
mimeType: "application/json",
|
|
@@ -2274,13 +2274,13 @@ const converterJson = {
|
|
|
2274
2274
|
};
|
|
2275
2275
|
},
|
|
2276
2276
|
deserialize: ({
|
|
2277
|
-
|
|
2277
|
+
snapshot,
|
|
2278
2278
|
event
|
|
2279
2279
|
}) => {
|
|
2280
|
-
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2280
|
+
const portableTextConverter = snapshot.context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2281
2281
|
return portableTextConverter ? {
|
|
2282
2282
|
...portableTextConverter.deserialize({
|
|
2283
|
-
|
|
2283
|
+
snapshot,
|
|
2284
2284
|
event
|
|
2285
2285
|
}),
|
|
2286
2286
|
mimeType: "application/json"
|
|
@@ -2293,10 +2293,10 @@ const converterJson = {
|
|
|
2293
2293
|
}, converterPortableText = {
|
|
2294
2294
|
mimeType: "application/x-portable-text",
|
|
2295
2295
|
serialize: ({
|
|
2296
|
-
|
|
2296
|
+
snapshot,
|
|
2297
2297
|
event
|
|
2298
2298
|
}) => {
|
|
2299
|
-
if (!context.selection)
|
|
2299
|
+
if (!snapshot.context.selection)
|
|
2300
2300
|
return {
|
|
2301
2301
|
type: "serialization.failure",
|
|
2302
2302
|
mimeType: "application/x-portable-text",
|
|
@@ -2304,8 +2304,8 @@ const converterJson = {
|
|
|
2304
2304
|
reason: "No selection"
|
|
2305
2305
|
};
|
|
2306
2306
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2307
|
-
blocks: context.value,
|
|
2308
|
-
selection: context.selection
|
|
2307
|
+
blocks: snapshot.context.value,
|
|
2308
|
+
selection: snapshot.context.selection
|
|
2309
2309
|
});
|
|
2310
2310
|
return {
|
|
2311
2311
|
type: "serialization.success",
|
|
@@ -2315,7 +2315,7 @@ const converterJson = {
|
|
|
2315
2315
|
};
|
|
2316
2316
|
},
|
|
2317
2317
|
deserialize: ({
|
|
2318
|
-
|
|
2318
|
+
snapshot,
|
|
2319
2319
|
event
|
|
2320
2320
|
}) => {
|
|
2321
2321
|
const blocks = JSON.parse(event.data);
|
|
@@ -2327,10 +2327,14 @@ const converterJson = {
|
|
|
2327
2327
|
};
|
|
2328
2328
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2329
2329
|
const parsedBlock = util_blockOffsetsToSelection.parseBlock({
|
|
2330
|
-
context,
|
|
2330
|
+
context: snapshot.context,
|
|
2331
2331
|
block,
|
|
2332
2332
|
options: {
|
|
2333
|
-
|
|
2333
|
+
/**
|
|
2334
|
+
* If we are dragging internally then we would like to keep the
|
|
2335
|
+
* dropped portable text as is.
|
|
2336
|
+
*/
|
|
2337
|
+
refreshKeys: !snapshot.beta.hasTag?.("dragging internally")
|
|
2334
2338
|
}
|
|
2335
2339
|
});
|
|
2336
2340
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -2348,10 +2352,10 @@ const converterJson = {
|
|
|
2348
2352
|
}, converterTextHtml = {
|
|
2349
2353
|
mimeType: "text/html",
|
|
2350
2354
|
serialize: ({
|
|
2351
|
-
|
|
2355
|
+
snapshot,
|
|
2352
2356
|
event
|
|
2353
2357
|
}) => {
|
|
2354
|
-
if (!context.selection)
|
|
2358
|
+
if (!snapshot.context.selection)
|
|
2355
2359
|
return {
|
|
2356
2360
|
type: "serialization.failure",
|
|
2357
2361
|
mimeType: "text/html",
|
|
@@ -2359,8 +2363,8 @@ const converterJson = {
|
|
|
2359
2363
|
reason: "No selection"
|
|
2360
2364
|
};
|
|
2361
2365
|
const blocks = util_sliceBlocks.sliceBlocks({
|
|
2362
|
-
blocks: context.value,
|
|
2363
|
-
selection: context.selection
|
|
2366
|
+
blocks: snapshot.context.value,
|
|
2367
|
+
selection: snapshot.context.selection
|
|
2364
2368
|
}), html = toHtml.toHTML(blocks, {
|
|
2365
2369
|
onMissingComponent: !1,
|
|
2366
2370
|
components: {
|
|
@@ -2382,27 +2386,27 @@ const converterJson = {
|
|
|
2382
2386
|
};
|
|
2383
2387
|
},
|
|
2384
2388
|
deserialize: ({
|
|
2385
|
-
|
|
2389
|
+
snapshot,
|
|
2386
2390
|
event
|
|
2387
2391
|
}) => ({
|
|
2388
2392
|
type: "deserialization.success",
|
|
2389
|
-
data: blockTools.htmlToBlocks(event.data, context.schema.portableText, {
|
|
2390
|
-
keyGenerator: context.keyGenerator,
|
|
2391
|
-
unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2393
|
+
data: blockTools.htmlToBlocks(event.data, snapshot.context.schema.portableText, {
|
|
2394
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
2395
|
+
unstable_whitespaceOnPasteMode: snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2392
2396
|
}),
|
|
2393
2397
|
mimeType: "text/html"
|
|
2394
2398
|
})
|
|
2395
2399
|
}, converterTextPlain = {
|
|
2396
2400
|
mimeType: "text/plain",
|
|
2397
2401
|
serialize: ({
|
|
2398
|
-
|
|
2402
|
+
snapshot,
|
|
2399
2403
|
event
|
|
2400
|
-
}) => context.selection ? {
|
|
2404
|
+
}) => snapshot.context.selection ? {
|
|
2401
2405
|
type: "serialization.success",
|
|
2402
2406
|
data: util_sliceBlocks.sliceBlocks({
|
|
2403
|
-
blocks: context.value,
|
|
2404
|
-
selection: context.selection
|
|
2405
|
-
}).map((block) => types.isPortableTextTextBlock(block) ? block.children.map((child) => child._type === context.schema.span.name ? child.text : `[${context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
|
|
2407
|
+
blocks: snapshot.context.value,
|
|
2408
|
+
selection: snapshot.context.selection
|
|
2409
|
+
}).map((block) => types.isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]`).join("") : `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]`).join(`
|
|
2406
2410
|
|
|
2407
2411
|
`),
|
|
2408
2412
|
mimeType: "text/plain",
|
|
@@ -2414,14 +2418,14 @@ const converterJson = {
|
|
|
2414
2418
|
reason: "No selection"
|
|
2415
2419
|
},
|
|
2416
2420
|
deserialize: ({
|
|
2417
|
-
|
|
2421
|
+
snapshot,
|
|
2418
2422
|
event
|
|
2419
2423
|
}) => {
|
|
2420
2424
|
const textToHtml = `<html><body>${escapeHtml(event.data).split(/\n{2,}/).map((line) => line ? `<p>${line.replace(/(?:\r\n|\r|\n)/g, "<br/>")}</p>` : "<p></p>").join("")}</body></html>`;
|
|
2421
2425
|
return {
|
|
2422
2426
|
type: "deserialization.success",
|
|
2423
|
-
data: blockTools.htmlToBlocks(textToHtml, context.schema.portableText, {
|
|
2424
|
-
keyGenerator: context.keyGenerator
|
|
2427
|
+
data: blockTools.htmlToBlocks(textToHtml, snapshot.context.schema.portableText, {
|
|
2428
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
2425
2429
|
}),
|
|
2426
2430
|
mimeType: "text/plain"
|
|
2427
2431
|
};
|
|
@@ -2914,6 +2918,9 @@ const decoratorAddActionImplementation = ({
|
|
|
2914
2918
|
},
|
|
2915
2919
|
backward: editorSelection?.backward
|
|
2916
2920
|
}), trimmedSelection = selector_isActiveStyle.getTrimmedSelection({
|
|
2921
|
+
beta: {
|
|
2922
|
+
hasTag: () => !1
|
|
2923
|
+
},
|
|
2917
2924
|
context: {
|
|
2918
2925
|
activeDecorators: [],
|
|
2919
2926
|
converters: [],
|
|
@@ -4127,6 +4134,9 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4127
4134
|
if (!selection)
|
|
4128
4135
|
throw new Error("Unable to find selection from block offsets");
|
|
4129
4136
|
const trimmedSelection = selector_isActiveStyle.getTrimmedSelection({
|
|
4137
|
+
beta: {
|
|
4138
|
+
hasTag: () => !1
|
|
4139
|
+
},
|
|
4130
4140
|
context: {
|
|
4131
4141
|
converters: [],
|
|
4132
4142
|
schema: context.schema,
|
|
@@ -5707,11 +5717,9 @@ function createSlateEditor(config) {
|
|
|
5707
5717
|
const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
5708
5718
|
on: "annotation.toggle",
|
|
5709
5719
|
guard: ({
|
|
5710
|
-
|
|
5720
|
+
snapshot,
|
|
5711
5721
|
event
|
|
5712
|
-
}) => selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(
|
|
5713
|
-
context
|
|
5714
|
-
}),
|
|
5722
|
+
}) => selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5715
5723
|
actions: [({
|
|
5716
5724
|
event
|
|
5717
5725
|
}) => [behavior_core.raise({
|
|
@@ -5721,11 +5729,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5721
5729
|
}), toggleAnnotationOn = behavior_core.defineBehavior({
|
|
5722
5730
|
on: "annotation.toggle",
|
|
5723
5731
|
guard: ({
|
|
5724
|
-
|
|
5732
|
+
snapshot,
|
|
5725
5733
|
event
|
|
5726
|
-
}) => !selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(
|
|
5727
|
-
context
|
|
5728
|
-
}),
|
|
5734
|
+
}) => !selector_isActiveStyle.isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5729
5735
|
actions: [({
|
|
5730
5736
|
event
|
|
5731
5737
|
}) => [behavior_core.raise({
|
|
@@ -5735,11 +5741,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5735
5741
|
}), toggleDecoratorOff = behavior_core.defineBehavior({
|
|
5736
5742
|
on: "decorator.toggle",
|
|
5737
5743
|
guard: ({
|
|
5738
|
-
|
|
5744
|
+
snapshot,
|
|
5739
5745
|
event
|
|
5740
|
-
}) => selector_isActiveStyle.isActiveDecorator(event.decorator)(
|
|
5741
|
-
context
|
|
5742
|
-
}),
|
|
5746
|
+
}) => selector_isActiveStyle.isActiveDecorator(event.decorator)(snapshot),
|
|
5743
5747
|
actions: [({
|
|
5744
5748
|
event
|
|
5745
5749
|
}) => [behavior_core.raise({
|
|
@@ -5749,11 +5753,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5749
5753
|
}), toggleDecoratorOn = behavior_core.defineBehavior({
|
|
5750
5754
|
on: "decorator.toggle",
|
|
5751
5755
|
guard: ({
|
|
5752
|
-
|
|
5756
|
+
snapshot,
|
|
5753
5757
|
event
|
|
5754
|
-
}) => !selector_isActiveStyle.isActiveDecorator(event.decorator)(
|
|
5755
|
-
context
|
|
5756
|
-
}),
|
|
5758
|
+
}) => !selector_isActiveStyle.isActiveDecorator(event.decorator)(snapshot),
|
|
5757
5759
|
actions: [({
|
|
5758
5760
|
event
|
|
5759
5761
|
}) => [behavior_core.raise({
|
|
@@ -5763,11 +5765,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5763
5765
|
}), toggleListItemOff = behavior_core.defineBehavior({
|
|
5764
5766
|
on: "list item.toggle",
|
|
5765
5767
|
guard: ({
|
|
5766
|
-
|
|
5768
|
+
snapshot,
|
|
5767
5769
|
event
|
|
5768
|
-
}) => selector_isActiveStyle.isActiveListItem(event.listItem)(
|
|
5769
|
-
context
|
|
5770
|
-
}),
|
|
5770
|
+
}) => selector_isActiveStyle.isActiveListItem(event.listItem)(snapshot),
|
|
5771
5771
|
actions: [({
|
|
5772
5772
|
event
|
|
5773
5773
|
}) => [behavior_core.raise({
|
|
@@ -5777,11 +5777,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5777
5777
|
}), toggleListItemOn = behavior_core.defineBehavior({
|
|
5778
5778
|
on: "list item.toggle",
|
|
5779
5779
|
guard: ({
|
|
5780
|
-
|
|
5780
|
+
snapshot,
|
|
5781
5781
|
event
|
|
5782
|
-
}) => !selector_isActiveStyle.isActiveListItem(event.listItem)(
|
|
5783
|
-
context
|
|
5784
|
-
}),
|
|
5782
|
+
}) => !selector_isActiveStyle.isActiveListItem(event.listItem)(snapshot),
|
|
5785
5783
|
actions: [({
|
|
5786
5784
|
event
|
|
5787
5785
|
}) => [behavior_core.raise({
|
|
@@ -5791,11 +5789,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5791
5789
|
}), toggleStyleOff = behavior_core.defineBehavior({
|
|
5792
5790
|
on: "style.toggle",
|
|
5793
5791
|
guard: ({
|
|
5794
|
-
|
|
5792
|
+
snapshot,
|
|
5795
5793
|
event
|
|
5796
|
-
}) => selector_isActiveStyle.isActiveStyle(event.style)(
|
|
5797
|
-
context
|
|
5798
|
-
}),
|
|
5794
|
+
}) => selector_isActiveStyle.isActiveStyle(event.style)(snapshot),
|
|
5799
5795
|
actions: [({
|
|
5800
5796
|
event
|
|
5801
5797
|
}) => [behavior_core.raise({
|
|
@@ -5805,11 +5801,9 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5805
5801
|
}), toggleStyleOn = behavior_core.defineBehavior({
|
|
5806
5802
|
on: "style.toggle",
|
|
5807
5803
|
guard: ({
|
|
5808
|
-
|
|
5804
|
+
snapshot,
|
|
5809
5805
|
event
|
|
5810
|
-
}) => !selector_isActiveStyle.isActiveStyle(event.style)(
|
|
5811
|
-
context
|
|
5812
|
-
}),
|
|
5806
|
+
}) => !selector_isActiveStyle.isActiveStyle(event.style)(snapshot),
|
|
5813
5807
|
actions: [({
|
|
5814
5808
|
event
|
|
5815
5809
|
}) => [behavior_core.raise({
|
|
@@ -5819,13 +5813,13 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5819
5813
|
}), raiseDeserializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
5820
5814
|
on: "deserialize",
|
|
5821
5815
|
guard: ({
|
|
5822
|
-
|
|
5816
|
+
snapshot,
|
|
5823
5817
|
event
|
|
5824
5818
|
}) => {
|
|
5825
|
-
const deserializeEvents = context.converters.flatMap((converter) => {
|
|
5819
|
+
const deserializeEvents = snapshot.context.converters.flatMap((converter) => {
|
|
5826
5820
|
const data = event.dataTransfer.getData(converter.mimeType);
|
|
5827
5821
|
return data ? [converter.deserialize({
|
|
5828
|
-
|
|
5822
|
+
snapshot,
|
|
5829
5823
|
event: {
|
|
5830
5824
|
type: "deserialize",
|
|
5831
5825
|
data
|
|
@@ -5855,13 +5849,13 @@ const toggleAnnotationOff = behavior_core.defineBehavior({
|
|
|
5855
5849
|
}), raiseSerializationSuccessOrFailure = behavior_core.defineBehavior({
|
|
5856
5850
|
on: "serialize",
|
|
5857
5851
|
guard: ({
|
|
5858
|
-
|
|
5852
|
+
snapshot,
|
|
5859
5853
|
event
|
|
5860
5854
|
}) => {
|
|
5861
|
-
if (context.converters.length === 0)
|
|
5855
|
+
if (snapshot.context.converters.length === 0)
|
|
5862
5856
|
return !1;
|
|
5863
|
-
const serializeEvents = context.converters.map((converter) => converter.serialize({
|
|
5864
|
-
|
|
5857
|
+
const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
|
|
5858
|
+
snapshot,
|
|
5865
5859
|
event
|
|
5866
5860
|
}));
|
|
5867
5861
|
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
@@ -5906,7 +5900,8 @@ function createEditorSnapshot({
|
|
|
5906
5900
|
converters,
|
|
5907
5901
|
editor,
|
|
5908
5902
|
keyGenerator,
|
|
5909
|
-
schema: schema2
|
|
5903
|
+
schema: schema2,
|
|
5904
|
+
hasTag
|
|
5910
5905
|
}) {
|
|
5911
5906
|
const value = fromSlateValue(editor.children, schema2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema2);
|
|
5912
5907
|
return {
|
|
@@ -5920,6 +5915,9 @@ function createEditorSnapshot({
|
|
|
5920
5915
|
schema: schema2,
|
|
5921
5916
|
selection,
|
|
5922
5917
|
value
|
|
5918
|
+
},
|
|
5919
|
+
beta: {
|
|
5920
|
+
hasTag
|
|
5923
5921
|
}
|
|
5924
5922
|
};
|
|
5925
5923
|
}
|
|
@@ -5928,7 +5926,8 @@ const editorMachine = xstate.setup({
|
|
|
5928
5926
|
context: {},
|
|
5929
5927
|
events: {},
|
|
5930
5928
|
emitted: {},
|
|
5931
|
-
input: {}
|
|
5929
|
+
input: {},
|
|
5930
|
+
tags: {}
|
|
5932
5931
|
},
|
|
5933
5932
|
actions: {
|
|
5934
5933
|
"add behavior to context": xstate.assign({
|
|
@@ -5987,7 +5986,8 @@ const editorMachine = xstate.setup({
|
|
|
5987
5986
|
"handle behavior event": xstate.enqueueActions(({
|
|
5988
5987
|
context,
|
|
5989
5988
|
event,
|
|
5990
|
-
enqueue
|
|
5989
|
+
enqueue,
|
|
5990
|
+
self
|
|
5991
5991
|
}) => {
|
|
5992
5992
|
xstate.assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
5993
5993
|
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
@@ -6023,18 +6023,21 @@ const editorMachine = xstate.setup({
|
|
|
6023
6023
|
converters: [...context.converters],
|
|
6024
6024
|
editor: event.editor,
|
|
6025
6025
|
keyGenerator: context.keyGenerator,
|
|
6026
|
-
schema: context.schema
|
|
6026
|
+
schema: context.schema,
|
|
6027
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6027
6028
|
});
|
|
6028
6029
|
let behaviorOverwritten = !1;
|
|
6029
6030
|
for (const eventBehavior of eventBehaviors) {
|
|
6030
6031
|
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6031
6032
|
context: editorSnapshot.context,
|
|
6033
|
+
snapshot: editorSnapshot,
|
|
6032
6034
|
event: event.behaviorEvent
|
|
6033
6035
|
});
|
|
6034
6036
|
if (!shouldRun)
|
|
6035
6037
|
continue;
|
|
6036
6038
|
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
6037
6039
|
context: editorSnapshot.context,
|
|
6040
|
+
snapshot: editorSnapshot,
|
|
6038
6041
|
event: event.behaviorEvent
|
|
6039
6042
|
}, shouldRun));
|
|
6040
6043
|
for (const actionIntends of actionIntendSets)
|
|
@@ -6357,6 +6360,27 @@ const editorMachine = xstate.setup({
|
|
|
6357
6360
|
event
|
|
6358
6361
|
}) => event)
|
|
6359
6362
|
}
|
|
6363
|
+
},
|
|
6364
|
+
initial: "idle",
|
|
6365
|
+
states: {
|
|
6366
|
+
idle: {
|
|
6367
|
+
on: {
|
|
6368
|
+
dragstart: {
|
|
6369
|
+
target: "dragging internally"
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
},
|
|
6373
|
+
"dragging internally": {
|
|
6374
|
+
tags: ["dragging internally"],
|
|
6375
|
+
on: {
|
|
6376
|
+
dragend: {
|
|
6377
|
+
target: "idle"
|
|
6378
|
+
},
|
|
6379
|
+
drop: {
|
|
6380
|
+
target: "idle"
|
|
6381
|
+
}
|
|
6382
|
+
}
|
|
6383
|
+
}
|
|
6360
6384
|
}
|
|
6361
6385
|
}
|
|
6362
6386
|
}
|
|
@@ -6464,6 +6488,9 @@ function getEditorSnapshot({
|
|
|
6464
6488
|
editorActorSnapshot,
|
|
6465
6489
|
slateEditorInstance
|
|
6466
6490
|
})
|
|
6491
|
+
},
|
|
6492
|
+
beta: {
|
|
6493
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6467
6494
|
}
|
|
6468
6495
|
};
|
|
6469
6496
|
}
|
|
@@ -7088,21 +7115,8 @@ function useEditor() {
|
|
|
7088
7115
|
throw new Error("No Editor set. Use EditorProvider to set one.");
|
|
7089
7116
|
return editor;
|
|
7090
7117
|
}
|
|
7091
|
-
function EventListenerPlugin(props) {
|
|
7092
|
-
const $ = reactCompilerRuntime.c(5), editor = useEditor(), on = useEffectEvent.useEffectEvent(props.on);
|
|
7093
|
-
let t0;
|
|
7094
|
-
$[0] !== editor || $[1] !== on ? (t0 = () => {
|
|
7095
|
-
const subscription = editor.on("*", on);
|
|
7096
|
-
return () => {
|
|
7097
|
-
subscription.unsubscribe();
|
|
7098
|
-
};
|
|
7099
|
-
}, $[0] = editor, $[1] = on, $[2] = t0) : t0 = $[2];
|
|
7100
|
-
let t1;
|
|
7101
|
-
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], React.useEffect(t0, t1), null;
|
|
7102
|
-
}
|
|
7103
7118
|
exports.EditorActorContext = EditorActorContext;
|
|
7104
7119
|
exports.EditorProvider = EditorProvider;
|
|
7105
|
-
exports.EventListenerPlugin = EventListenerPlugin;
|
|
7106
7120
|
exports.IS_DRAGGING = IS_DRAGGING;
|
|
7107
7121
|
exports.IS_DRAGGING_BLOCK_ELEMENT = IS_DRAGGING_BLOCK_ELEMENT;
|
|
7108
7122
|
exports.IS_DRAGGING_BLOCK_TARGET_POSITION = IS_DRAGGING_BLOCK_TARGET_POSITION;
|
|
@@ -7122,4 +7136,4 @@ exports.useEditor = useEditor;
|
|
|
7122
7136
|
exports.useEditorSelector = useEditorSelector;
|
|
7123
7137
|
exports.usePortableTextEditor = usePortableTextEditor;
|
|
7124
7138
|
exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
|
|
7125
|
-
//# sourceMappingURL=
|
|
7139
|
+
//# sourceMappingURL=editor-provider.cjs.map
|