@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,7 +1,6 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { c } from "react-compiler-runtime";
|
|
2
3
|
import React, { createContext, useContext, useEffect, useState, startTransition, Component } from "react";
|
|
3
|
-
import { useEffectEvent } from "use-effect-event";
|
|
4
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
4
|
import { ReactEditor, withReact, Slate } from "slate-react";
|
|
6
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
7
6
|
import debug$e from "debug";
|
|
@@ -28,6 +27,7 @@ import omit from "lodash/omit.js";
|
|
|
28
27
|
import startCase from "lodash.startcase";
|
|
29
28
|
import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
30
29
|
import { Subject } from "rxjs";
|
|
30
|
+
import { useEffectEvent } from "use-effect-event";
|
|
31
31
|
function createEditorSchema(portableTextType) {
|
|
32
32
|
if (!portableTextType)
|
|
33
33
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -2279,13 +2279,13 @@ Synchronizer.displayName = "Synchronizer";
|
|
|
2279
2279
|
const converterJson = {
|
|
2280
2280
|
mimeType: "application/json",
|
|
2281
2281
|
serialize: ({
|
|
2282
|
-
|
|
2282
|
+
snapshot,
|
|
2283
2283
|
event
|
|
2284
2284
|
}) => {
|
|
2285
|
-
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2285
|
+
const portableTextConverter = snapshot.context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2286
2286
|
return portableTextConverter ? {
|
|
2287
2287
|
...portableTextConverter.serialize({
|
|
2288
|
-
|
|
2288
|
+
snapshot,
|
|
2289
2289
|
event
|
|
2290
2290
|
}),
|
|
2291
2291
|
mimeType: "application/json",
|
|
@@ -2298,13 +2298,13 @@ const converterJson = {
|
|
|
2298
2298
|
};
|
|
2299
2299
|
},
|
|
2300
2300
|
deserialize: ({
|
|
2301
|
-
|
|
2301
|
+
snapshot,
|
|
2302
2302
|
event
|
|
2303
2303
|
}) => {
|
|
2304
|
-
const portableTextConverter = context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2304
|
+
const portableTextConverter = snapshot.context.converters.find((converter) => converter.mimeType === "application/x-portable-text");
|
|
2305
2305
|
return portableTextConverter ? {
|
|
2306
2306
|
...portableTextConverter.deserialize({
|
|
2307
|
-
|
|
2307
|
+
snapshot,
|
|
2308
2308
|
event
|
|
2309
2309
|
}),
|
|
2310
2310
|
mimeType: "application/json"
|
|
@@ -2317,10 +2317,10 @@ const converterJson = {
|
|
|
2317
2317
|
}, converterPortableText = {
|
|
2318
2318
|
mimeType: "application/x-portable-text",
|
|
2319
2319
|
serialize: ({
|
|
2320
|
-
|
|
2320
|
+
snapshot,
|
|
2321
2321
|
event
|
|
2322
2322
|
}) => {
|
|
2323
|
-
if (!context.selection)
|
|
2323
|
+
if (!snapshot.context.selection)
|
|
2324
2324
|
return {
|
|
2325
2325
|
type: "serialization.failure",
|
|
2326
2326
|
mimeType: "application/x-portable-text",
|
|
@@ -2328,8 +2328,8 @@ const converterJson = {
|
|
|
2328
2328
|
reason: "No selection"
|
|
2329
2329
|
};
|
|
2330
2330
|
const blocks = sliceBlocks({
|
|
2331
|
-
blocks: context.value,
|
|
2332
|
-
selection: context.selection
|
|
2331
|
+
blocks: snapshot.context.value,
|
|
2332
|
+
selection: snapshot.context.selection
|
|
2333
2333
|
});
|
|
2334
2334
|
return {
|
|
2335
2335
|
type: "serialization.success",
|
|
@@ -2339,7 +2339,7 @@ const converterJson = {
|
|
|
2339
2339
|
};
|
|
2340
2340
|
},
|
|
2341
2341
|
deserialize: ({
|
|
2342
|
-
|
|
2342
|
+
snapshot,
|
|
2343
2343
|
event
|
|
2344
2344
|
}) => {
|
|
2345
2345
|
const blocks = JSON.parse(event.data);
|
|
@@ -2351,10 +2351,14 @@ const converterJson = {
|
|
|
2351
2351
|
};
|
|
2352
2352
|
const parsedBlocks = blocks.flatMap((block) => {
|
|
2353
2353
|
const parsedBlock = parseBlock({
|
|
2354
|
-
context,
|
|
2354
|
+
context: snapshot.context,
|
|
2355
2355
|
block,
|
|
2356
2356
|
options: {
|
|
2357
|
-
|
|
2357
|
+
/**
|
|
2358
|
+
* If we are dragging internally then we would like to keep the
|
|
2359
|
+
* dropped portable text as is.
|
|
2360
|
+
*/
|
|
2361
|
+
refreshKeys: !snapshot.beta.hasTag?.("dragging internally")
|
|
2358
2362
|
}
|
|
2359
2363
|
});
|
|
2360
2364
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -2372,10 +2376,10 @@ const converterJson = {
|
|
|
2372
2376
|
}, converterTextHtml = {
|
|
2373
2377
|
mimeType: "text/html",
|
|
2374
2378
|
serialize: ({
|
|
2375
|
-
|
|
2379
|
+
snapshot,
|
|
2376
2380
|
event
|
|
2377
2381
|
}) => {
|
|
2378
|
-
if (!context.selection)
|
|
2382
|
+
if (!snapshot.context.selection)
|
|
2379
2383
|
return {
|
|
2380
2384
|
type: "serialization.failure",
|
|
2381
2385
|
mimeType: "text/html",
|
|
@@ -2383,8 +2387,8 @@ const converterJson = {
|
|
|
2383
2387
|
reason: "No selection"
|
|
2384
2388
|
};
|
|
2385
2389
|
const blocks = sliceBlocks({
|
|
2386
|
-
blocks: context.value,
|
|
2387
|
-
selection: context.selection
|
|
2390
|
+
blocks: snapshot.context.value,
|
|
2391
|
+
selection: snapshot.context.selection
|
|
2388
2392
|
}), html = toHTML(blocks, {
|
|
2389
2393
|
onMissingComponent: !1,
|
|
2390
2394
|
components: {
|
|
@@ -2406,27 +2410,27 @@ const converterJson = {
|
|
|
2406
2410
|
};
|
|
2407
2411
|
},
|
|
2408
2412
|
deserialize: ({
|
|
2409
|
-
|
|
2413
|
+
snapshot,
|
|
2410
2414
|
event
|
|
2411
2415
|
}) => ({
|
|
2412
2416
|
type: "deserialization.success",
|
|
2413
|
-
data: htmlToBlocks(event.data, context.schema.portableText, {
|
|
2414
|
-
keyGenerator: context.keyGenerator,
|
|
2415
|
-
unstable_whitespaceOnPasteMode: context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2417
|
+
data: htmlToBlocks(event.data, snapshot.context.schema.portableText, {
|
|
2418
|
+
keyGenerator: snapshot.context.keyGenerator,
|
|
2419
|
+
unstable_whitespaceOnPasteMode: snapshot.context.schema.block.options.unstable_whitespaceOnPasteMode
|
|
2416
2420
|
}),
|
|
2417
2421
|
mimeType: "text/html"
|
|
2418
2422
|
})
|
|
2419
2423
|
}, converterTextPlain = {
|
|
2420
2424
|
mimeType: "text/plain",
|
|
2421
2425
|
serialize: ({
|
|
2422
|
-
|
|
2426
|
+
snapshot,
|
|
2423
2427
|
event
|
|
2424
|
-
}) => context.selection ? {
|
|
2428
|
+
}) => snapshot.context.selection ? {
|
|
2425
2429
|
type: "serialization.success",
|
|
2426
2430
|
data: sliceBlocks({
|
|
2427
|
-
blocks: context.value,
|
|
2428
|
-
selection: context.selection
|
|
2429
|
-
}).map((block) => 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(`
|
|
2431
|
+
blocks: snapshot.context.value,
|
|
2432
|
+
selection: snapshot.context.selection
|
|
2433
|
+
}).map((block) => 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(`
|
|
2430
2434
|
|
|
2431
2435
|
`),
|
|
2432
2436
|
mimeType: "text/plain",
|
|
@@ -2438,14 +2442,14 @@ const converterJson = {
|
|
|
2438
2442
|
reason: "No selection"
|
|
2439
2443
|
},
|
|
2440
2444
|
deserialize: ({
|
|
2441
|
-
|
|
2445
|
+
snapshot,
|
|
2442
2446
|
event
|
|
2443
2447
|
}) => {
|
|
2444
2448
|
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>`;
|
|
2445
2449
|
return {
|
|
2446
2450
|
type: "deserialization.success",
|
|
2447
|
-
data: htmlToBlocks(textToHtml, context.schema.portableText, {
|
|
2448
|
-
keyGenerator: context.keyGenerator
|
|
2451
|
+
data: htmlToBlocks(textToHtml, snapshot.context.schema.portableText, {
|
|
2452
|
+
keyGenerator: snapshot.context.keyGenerator
|
|
2449
2453
|
}),
|
|
2450
2454
|
mimeType: "text/plain"
|
|
2451
2455
|
};
|
|
@@ -2938,6 +2942,9 @@ const decoratorAddActionImplementation = ({
|
|
|
2938
2942
|
},
|
|
2939
2943
|
backward: editorSelection?.backward
|
|
2940
2944
|
}), trimmedSelection = getTrimmedSelection({
|
|
2945
|
+
beta: {
|
|
2946
|
+
hasTag: () => !1
|
|
2947
|
+
},
|
|
2941
2948
|
context: {
|
|
2942
2949
|
activeDecorators: [],
|
|
2943
2950
|
converters: [],
|
|
@@ -4151,6 +4158,9 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4151
4158
|
if (!selection)
|
|
4152
4159
|
throw new Error("Unable to find selection from block offsets");
|
|
4153
4160
|
const trimmedSelection = getTrimmedSelection({
|
|
4161
|
+
beta: {
|
|
4162
|
+
hasTag: () => !1
|
|
4163
|
+
},
|
|
4154
4164
|
context: {
|
|
4155
4165
|
converters: [],
|
|
4156
4166
|
schema: context.schema,
|
|
@@ -5731,11 +5741,9 @@ function createSlateEditor(config) {
|
|
|
5731
5741
|
const toggleAnnotationOff = defineBehavior({
|
|
5732
5742
|
on: "annotation.toggle",
|
|
5733
5743
|
guard: ({
|
|
5734
|
-
|
|
5744
|
+
snapshot,
|
|
5735
5745
|
event
|
|
5736
|
-
}) => isActiveAnnotation(event.annotation.name)(
|
|
5737
|
-
context
|
|
5738
|
-
}),
|
|
5746
|
+
}) => isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5739
5747
|
actions: [({
|
|
5740
5748
|
event
|
|
5741
5749
|
}) => [raise({
|
|
@@ -5745,11 +5753,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5745
5753
|
}), toggleAnnotationOn = defineBehavior({
|
|
5746
5754
|
on: "annotation.toggle",
|
|
5747
5755
|
guard: ({
|
|
5748
|
-
|
|
5756
|
+
snapshot,
|
|
5749
5757
|
event
|
|
5750
|
-
}) => !isActiveAnnotation(event.annotation.name)(
|
|
5751
|
-
context
|
|
5752
|
-
}),
|
|
5758
|
+
}) => !isActiveAnnotation(event.annotation.name)(snapshot),
|
|
5753
5759
|
actions: [({
|
|
5754
5760
|
event
|
|
5755
5761
|
}) => [raise({
|
|
@@ -5759,11 +5765,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5759
5765
|
}), toggleDecoratorOff = defineBehavior({
|
|
5760
5766
|
on: "decorator.toggle",
|
|
5761
5767
|
guard: ({
|
|
5762
|
-
|
|
5768
|
+
snapshot,
|
|
5763
5769
|
event
|
|
5764
|
-
}) => isActiveDecorator(event.decorator)(
|
|
5765
|
-
context
|
|
5766
|
-
}),
|
|
5770
|
+
}) => isActiveDecorator(event.decorator)(snapshot),
|
|
5767
5771
|
actions: [({
|
|
5768
5772
|
event
|
|
5769
5773
|
}) => [raise({
|
|
@@ -5773,11 +5777,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5773
5777
|
}), toggleDecoratorOn = defineBehavior({
|
|
5774
5778
|
on: "decorator.toggle",
|
|
5775
5779
|
guard: ({
|
|
5776
|
-
|
|
5780
|
+
snapshot,
|
|
5777
5781
|
event
|
|
5778
|
-
}) => !isActiveDecorator(event.decorator)(
|
|
5779
|
-
context
|
|
5780
|
-
}),
|
|
5782
|
+
}) => !isActiveDecorator(event.decorator)(snapshot),
|
|
5781
5783
|
actions: [({
|
|
5782
5784
|
event
|
|
5783
5785
|
}) => [raise({
|
|
@@ -5787,11 +5789,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5787
5789
|
}), toggleListItemOff = defineBehavior({
|
|
5788
5790
|
on: "list item.toggle",
|
|
5789
5791
|
guard: ({
|
|
5790
|
-
|
|
5792
|
+
snapshot,
|
|
5791
5793
|
event
|
|
5792
|
-
}) => isActiveListItem(event.listItem)(
|
|
5793
|
-
context
|
|
5794
|
-
}),
|
|
5794
|
+
}) => isActiveListItem(event.listItem)(snapshot),
|
|
5795
5795
|
actions: [({
|
|
5796
5796
|
event
|
|
5797
5797
|
}) => [raise({
|
|
@@ -5801,11 +5801,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5801
5801
|
}), toggleListItemOn = defineBehavior({
|
|
5802
5802
|
on: "list item.toggle",
|
|
5803
5803
|
guard: ({
|
|
5804
|
-
|
|
5804
|
+
snapshot,
|
|
5805
5805
|
event
|
|
5806
|
-
}) => !isActiveListItem(event.listItem)(
|
|
5807
|
-
context
|
|
5808
|
-
}),
|
|
5806
|
+
}) => !isActiveListItem(event.listItem)(snapshot),
|
|
5809
5807
|
actions: [({
|
|
5810
5808
|
event
|
|
5811
5809
|
}) => [raise({
|
|
@@ -5815,11 +5813,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5815
5813
|
}), toggleStyleOff = defineBehavior({
|
|
5816
5814
|
on: "style.toggle",
|
|
5817
5815
|
guard: ({
|
|
5818
|
-
|
|
5816
|
+
snapshot,
|
|
5819
5817
|
event
|
|
5820
|
-
}) => isActiveStyle(event.style)(
|
|
5821
|
-
context
|
|
5822
|
-
}),
|
|
5818
|
+
}) => isActiveStyle(event.style)(snapshot),
|
|
5823
5819
|
actions: [({
|
|
5824
5820
|
event
|
|
5825
5821
|
}) => [raise({
|
|
@@ -5829,11 +5825,9 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5829
5825
|
}), toggleStyleOn = defineBehavior({
|
|
5830
5826
|
on: "style.toggle",
|
|
5831
5827
|
guard: ({
|
|
5832
|
-
|
|
5828
|
+
snapshot,
|
|
5833
5829
|
event
|
|
5834
|
-
}) => !isActiveStyle(event.style)(
|
|
5835
|
-
context
|
|
5836
|
-
}),
|
|
5830
|
+
}) => !isActiveStyle(event.style)(snapshot),
|
|
5837
5831
|
actions: [({
|
|
5838
5832
|
event
|
|
5839
5833
|
}) => [raise({
|
|
@@ -5843,13 +5837,13 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5843
5837
|
}), raiseDeserializationSuccessOrFailure = defineBehavior({
|
|
5844
5838
|
on: "deserialize",
|
|
5845
5839
|
guard: ({
|
|
5846
|
-
|
|
5840
|
+
snapshot,
|
|
5847
5841
|
event
|
|
5848
5842
|
}) => {
|
|
5849
|
-
const deserializeEvents = context.converters.flatMap((converter) => {
|
|
5843
|
+
const deserializeEvents = snapshot.context.converters.flatMap((converter) => {
|
|
5850
5844
|
const data = event.dataTransfer.getData(converter.mimeType);
|
|
5851
5845
|
return data ? [converter.deserialize({
|
|
5852
|
-
|
|
5846
|
+
snapshot,
|
|
5853
5847
|
event: {
|
|
5854
5848
|
type: "deserialize",
|
|
5855
5849
|
data
|
|
@@ -5879,13 +5873,13 @@ const toggleAnnotationOff = defineBehavior({
|
|
|
5879
5873
|
}), raiseSerializationSuccessOrFailure = defineBehavior({
|
|
5880
5874
|
on: "serialize",
|
|
5881
5875
|
guard: ({
|
|
5882
|
-
|
|
5876
|
+
snapshot,
|
|
5883
5877
|
event
|
|
5884
5878
|
}) => {
|
|
5885
|
-
if (context.converters.length === 0)
|
|
5879
|
+
if (snapshot.context.converters.length === 0)
|
|
5886
5880
|
return !1;
|
|
5887
|
-
const serializeEvents = context.converters.map((converter) => converter.serialize({
|
|
5888
|
-
|
|
5881
|
+
const serializeEvents = snapshot.context.converters.map((converter) => converter.serialize({
|
|
5882
|
+
snapshot,
|
|
5889
5883
|
event
|
|
5890
5884
|
}));
|
|
5891
5885
|
return serializeEvents.length === 0 ? !1 : serializeEvents;
|
|
@@ -5930,7 +5924,8 @@ function createEditorSnapshot({
|
|
|
5930
5924
|
converters,
|
|
5931
5925
|
editor,
|
|
5932
5926
|
keyGenerator,
|
|
5933
|
-
schema
|
|
5927
|
+
schema,
|
|
5928
|
+
hasTag
|
|
5934
5929
|
}) {
|
|
5935
5930
|
const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
|
|
5936
5931
|
return {
|
|
@@ -5944,6 +5939,9 @@ function createEditorSnapshot({
|
|
|
5944
5939
|
schema,
|
|
5945
5940
|
selection,
|
|
5946
5941
|
value
|
|
5942
|
+
},
|
|
5943
|
+
beta: {
|
|
5944
|
+
hasTag
|
|
5947
5945
|
}
|
|
5948
5946
|
};
|
|
5949
5947
|
}
|
|
@@ -5952,7 +5950,8 @@ const editorMachine = setup({
|
|
|
5952
5950
|
context: {},
|
|
5953
5951
|
events: {},
|
|
5954
5952
|
emitted: {},
|
|
5955
|
-
input: {}
|
|
5953
|
+
input: {},
|
|
5954
|
+
tags: {}
|
|
5956
5955
|
},
|
|
5957
5956
|
actions: {
|
|
5958
5957
|
"add behavior to context": assign({
|
|
@@ -6011,7 +6010,8 @@ const editorMachine = setup({
|
|
|
6011
6010
|
"handle behavior event": enqueueActions(({
|
|
6012
6011
|
context,
|
|
6013
6012
|
event,
|
|
6014
|
-
enqueue
|
|
6013
|
+
enqueue,
|
|
6014
|
+
self
|
|
6015
6015
|
}) => {
|
|
6016
6016
|
assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6017
6017
|
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 : {
|
|
@@ -6047,18 +6047,21 @@ const editorMachine = setup({
|
|
|
6047
6047
|
converters: [...context.converters],
|
|
6048
6048
|
editor: event.editor,
|
|
6049
6049
|
keyGenerator: context.keyGenerator,
|
|
6050
|
-
schema: context.schema
|
|
6050
|
+
schema: context.schema,
|
|
6051
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6051
6052
|
});
|
|
6052
6053
|
let behaviorOverwritten = !1;
|
|
6053
6054
|
for (const eventBehavior of eventBehaviors) {
|
|
6054
6055
|
const shouldRun = eventBehavior.guard === void 0 || eventBehavior.guard({
|
|
6055
6056
|
context: editorSnapshot.context,
|
|
6057
|
+
snapshot: editorSnapshot,
|
|
6056
6058
|
event: event.behaviorEvent
|
|
6057
6059
|
});
|
|
6058
6060
|
if (!shouldRun)
|
|
6059
6061
|
continue;
|
|
6060
6062
|
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
6061
6063
|
context: editorSnapshot.context,
|
|
6064
|
+
snapshot: editorSnapshot,
|
|
6062
6065
|
event: event.behaviorEvent
|
|
6063
6066
|
}, shouldRun));
|
|
6064
6067
|
for (const actionIntends of actionIntendSets)
|
|
@@ -6381,6 +6384,27 @@ const editorMachine = setup({
|
|
|
6381
6384
|
event
|
|
6382
6385
|
}) => event)
|
|
6383
6386
|
}
|
|
6387
|
+
},
|
|
6388
|
+
initial: "idle",
|
|
6389
|
+
states: {
|
|
6390
|
+
idle: {
|
|
6391
|
+
on: {
|
|
6392
|
+
dragstart: {
|
|
6393
|
+
target: "dragging internally"
|
|
6394
|
+
}
|
|
6395
|
+
}
|
|
6396
|
+
},
|
|
6397
|
+
"dragging internally": {
|
|
6398
|
+
tags: ["dragging internally"],
|
|
6399
|
+
on: {
|
|
6400
|
+
dragend: {
|
|
6401
|
+
target: "idle"
|
|
6402
|
+
},
|
|
6403
|
+
drop: {
|
|
6404
|
+
target: "idle"
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6384
6408
|
}
|
|
6385
6409
|
}
|
|
6386
6410
|
}
|
|
@@ -6488,6 +6512,9 @@ function getEditorSnapshot({
|
|
|
6488
6512
|
editorActorSnapshot,
|
|
6489
6513
|
slateEditorInstance
|
|
6490
6514
|
})
|
|
6515
|
+
},
|
|
6516
|
+
beta: {
|
|
6517
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6491
6518
|
}
|
|
6492
6519
|
};
|
|
6493
6520
|
}
|
|
@@ -7112,22 +7139,9 @@ function useEditor() {
|
|
|
7112
7139
|
throw new Error("No Editor set. Use EditorProvider to set one.");
|
|
7113
7140
|
return editor;
|
|
7114
7141
|
}
|
|
7115
|
-
function EventListenerPlugin(props) {
|
|
7116
|
-
const $ = c(5), editor = useEditor(), on = useEffectEvent(props.on);
|
|
7117
|
-
let t0;
|
|
7118
|
-
$[0] !== editor || $[1] !== on ? (t0 = () => {
|
|
7119
|
-
const subscription = editor.on("*", on);
|
|
7120
|
-
return () => {
|
|
7121
|
-
subscription.unsubscribe();
|
|
7122
|
-
};
|
|
7123
|
-
}, $[0] = editor, $[1] = on, $[2] = t0) : t0 = $[2];
|
|
7124
|
-
let t1;
|
|
7125
|
-
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
|
|
7126
|
-
}
|
|
7127
7142
|
export {
|
|
7128
7143
|
EditorActorContext,
|
|
7129
7144
|
EditorProvider,
|
|
7130
|
-
EventListenerPlugin,
|
|
7131
7145
|
IS_DRAGGING,
|
|
7132
7146
|
IS_DRAGGING_BLOCK_ELEMENT,
|
|
7133
7147
|
IS_DRAGGING_BLOCK_TARGET_POSITION,
|
|
@@ -7148,4 +7162,4 @@ export {
|
|
|
7148
7162
|
usePortableTextEditor,
|
|
7149
7163
|
usePortableTextEditorSelection
|
|
7150
7164
|
};
|
|
7151
|
-
//# sourceMappingURL=
|
|
7165
|
+
//# sourceMappingURL=editor-provider.js.map
|