@portabletext/editor 1.16.2 → 1.16.3
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 +106 -100
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +36 -113
- package/lib/index.d.ts +36 -113
- package/lib/index.js +107 -101
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.actions.ts +0 -3
- package/src/editor/editor-machine.ts +8 -7
- package/src/editor/sync-machine.ts +117 -107
package/lib/index.cjs
CHANGED
|
@@ -11,11 +11,11 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
11
11
|
return a;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
14
|
-
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$
|
|
14
|
+
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$l = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), xstate = require("xstate"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selector_isSelectionCollapsed = require("./_chunks-cjs/selector.is-selection-collapsed.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
|
|
15
15
|
function _interopDefaultCompat(e) {
|
|
16
16
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
17
17
|
}
|
|
18
|
-
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$
|
|
18
|
+
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$l), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
|
|
19
19
|
function createEditorSchema(portableTextType) {
|
|
20
20
|
var _a, _b, _c;
|
|
21
21
|
if (!portableTextType)
|
|
@@ -155,7 +155,7 @@ function compileSchemaDefinition(definition) {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
const rootName = "sanity-pte:";
|
|
158
|
-
|
|
158
|
+
debug__default.default(rootName);
|
|
159
159
|
function debugWithName(name) {
|
|
160
160
|
const namespace = `${rootName}${name}`;
|
|
161
161
|
return debug__default.default && debug__default.default.enabled(namespace) ? debug__default.default(namespace) : debug__default.default(rootName);
|
|
@@ -2315,24 +2315,20 @@ const syncValueCallback = ({
|
|
|
2315
2315
|
event
|
|
2316
2316
|
}) => (xstate.assertEvent(event, "done syncing"), event.value)
|
|
2317
2317
|
}),
|
|
2318
|
-
"emit done syncing": xstate.emit(
|
|
2319
|
-
|
|
2320
|
-
})
|
|
2318
|
+
"emit done syncing initial value": xstate.emit({
|
|
2319
|
+
type: "done syncing initial value"
|
|
2320
|
+
})
|
|
2321
2321
|
},
|
|
2322
2322
|
guards: {
|
|
2323
|
-
"
|
|
2323
|
+
"initial value synced": ({
|
|
2324
2324
|
context
|
|
2325
|
-
}) => context.
|
|
2326
|
-
"is
|
|
2327
|
-
context
|
|
2328
|
-
}) => context.isProcessingLocalChanges,
|
|
2329
|
-
"is processing remote changes": ({
|
|
2325
|
+
}) => context.initialValueSynced,
|
|
2326
|
+
"is busy": ({
|
|
2330
2327
|
context
|
|
2331
2328
|
}) => {
|
|
2332
2329
|
var _a;
|
|
2333
|
-
return (_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1;
|
|
2330
|
+
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2334
2331
|
},
|
|
2335
|
-
"is busy": xstate.and([xstate.not("is readOnly"), xstate.or(["is processing local changes", "is processing remote changes"])]),
|
|
2336
2332
|
"value changed while syncing": ({
|
|
2337
2333
|
context,
|
|
2338
2334
|
event
|
|
@@ -2358,7 +2354,6 @@ const syncValueCallback = ({
|
|
|
2358
2354
|
pendingValue: void 0,
|
|
2359
2355
|
previousValue: void 0
|
|
2360
2356
|
}),
|
|
2361
|
-
initial: "idle",
|
|
2362
2357
|
on: {
|
|
2363
2358
|
"has pending patches": {
|
|
2364
2359
|
actions: xstate.assign({
|
|
@@ -2374,94 +2369,105 @@ const syncValueCallback = ({
|
|
|
2374
2369
|
actions: ["assign readOnly"]
|
|
2375
2370
|
}
|
|
2376
2371
|
},
|
|
2372
|
+
type: "parallel",
|
|
2377
2373
|
states: {
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
busy: {
|
|
2391
|
-
after: {
|
|
2392
|
-
1e3: {
|
|
2393
|
-
target: "syncing"
|
|
2374
|
+
"setting up": {
|
|
2375
|
+
initial: "syncing initial value",
|
|
2376
|
+
states: {
|
|
2377
|
+
"syncing initial value": {
|
|
2378
|
+
always: {
|
|
2379
|
+
guard: "initial value synced",
|
|
2380
|
+
target: "done syncing initial value"
|
|
2381
|
+
}
|
|
2382
|
+
},
|
|
2383
|
+
"done syncing initial value": {
|
|
2384
|
+
entry: ["emit done syncing initial value"],
|
|
2385
|
+
type: "final"
|
|
2394
2386
|
}
|
|
2395
|
-
},
|
|
2396
|
-
on: {
|
|
2397
|
-
"update value": [{
|
|
2398
|
-
guard: "is busy",
|
|
2399
|
-
actions: ["assign pending value"],
|
|
2400
|
-
reenter: !0
|
|
2401
|
-
}, {
|
|
2402
|
-
target: "syncing",
|
|
2403
|
-
actions: ["assign pending value"]
|
|
2404
|
-
}]
|
|
2405
2387
|
}
|
|
2406
2388
|
},
|
|
2407
2389
|
syncing: {
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
},
|
|
2422
|
-
slateEditor: context.slateEditor,
|
|
2423
|
-
streamBlocks: !context.initialValueSynced,
|
|
2424
|
-
value: (_a = context.pendingValue) != null ? _a : void 0
|
|
2425
|
-
};
|
|
2426
|
-
}
|
|
2427
|
-
},
|
|
2428
|
-
always: {
|
|
2429
|
-
guard: "pending value equals previous value",
|
|
2430
|
-
actions: [xstate.emit(({
|
|
2431
|
-
context
|
|
2432
|
-
}) => ({
|
|
2433
|
-
type: "done syncing",
|
|
2434
|
-
value: context.previousValue
|
|
2435
|
-
}))],
|
|
2436
|
-
target: "idle"
|
|
2437
|
-
},
|
|
2438
|
-
on: {
|
|
2439
|
-
"update value": {
|
|
2440
|
-
actions: ["assign pending value"]
|
|
2441
|
-
},
|
|
2442
|
-
patch: {
|
|
2443
|
-
actions: [xstate.emit(({
|
|
2444
|
-
event
|
|
2445
|
-
}) => event)]
|
|
2446
|
-
},
|
|
2447
|
-
"invalid value": {
|
|
2448
|
-
actions: [xstate.emit(({
|
|
2449
|
-
event
|
|
2450
|
-
}) => event)]
|
|
2390
|
+
initial: "idle",
|
|
2391
|
+
states: {
|
|
2392
|
+
idle: {
|
|
2393
|
+
on: {
|
|
2394
|
+
"update value": [{
|
|
2395
|
+
guard: "is busy",
|
|
2396
|
+
target: "busy",
|
|
2397
|
+
actions: ["assign pending value"]
|
|
2398
|
+
}, {
|
|
2399
|
+
target: "syncing",
|
|
2400
|
+
actions: ["assign pending value"]
|
|
2401
|
+
}]
|
|
2402
|
+
}
|
|
2451
2403
|
},
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2404
|
+
busy: {
|
|
2405
|
+
after: {
|
|
2406
|
+
1e3: [{
|
|
2407
|
+
guard: "is busy",
|
|
2408
|
+
reenter: !0
|
|
2409
|
+
}, {
|
|
2410
|
+
target: "syncing"
|
|
2411
|
+
}]
|
|
2412
|
+
},
|
|
2413
|
+
on: {
|
|
2414
|
+
"update value": [{
|
|
2415
|
+
actions: ["assign pending value"]
|
|
2416
|
+
}]
|
|
2417
|
+
}
|
|
2456
2418
|
},
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2419
|
+
syncing: {
|
|
2420
|
+
always: {
|
|
2421
|
+
guard: "pending value equals previous value",
|
|
2422
|
+
target: "idle",
|
|
2423
|
+
actions: ["clear pending value", "assign initial value synced"]
|
|
2424
|
+
},
|
|
2425
|
+
invoke: {
|
|
2426
|
+
src: "sync value",
|
|
2427
|
+
id: "sync value",
|
|
2428
|
+
input: ({
|
|
2429
|
+
context
|
|
2430
|
+
}) => ({
|
|
2431
|
+
context: {
|
|
2432
|
+
keyGenerator: context.keyGenerator,
|
|
2433
|
+
previousValue: context.previousValue,
|
|
2434
|
+
readOnly: context.readOnly,
|
|
2435
|
+
schema: context.schema
|
|
2436
|
+
},
|
|
2437
|
+
slateEditor: context.slateEditor,
|
|
2438
|
+
streamBlocks: !context.initialValueSynced,
|
|
2439
|
+
value: context.pendingValue
|
|
2440
|
+
})
|
|
2441
|
+
},
|
|
2442
|
+
on: {
|
|
2443
|
+
"update value": {
|
|
2444
|
+
actions: ["assign pending value"]
|
|
2445
|
+
},
|
|
2446
|
+
patch: {
|
|
2447
|
+
actions: [xstate.emit(({
|
|
2448
|
+
event
|
|
2449
|
+
}) => event)]
|
|
2450
|
+
},
|
|
2451
|
+
"invalid value": {
|
|
2452
|
+
actions: [xstate.emit(({
|
|
2453
|
+
event
|
|
2454
|
+
}) => event)]
|
|
2455
|
+
},
|
|
2456
|
+
"value changed": {
|
|
2457
|
+
actions: [xstate.emit(({
|
|
2458
|
+
event
|
|
2459
|
+
}) => event)]
|
|
2460
|
+
},
|
|
2461
|
+
"done syncing": [{
|
|
2462
|
+
guard: "value changed while syncing",
|
|
2463
|
+
actions: ["assign previous value", "assign initial value synced"],
|
|
2464
|
+
reenter: !0
|
|
2465
|
+
}, {
|
|
2466
|
+
target: "idle",
|
|
2467
|
+
actions: ["clear pending value", "assign previous value", "assign initial value synced"]
|
|
2468
|
+
}]
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2465
2471
|
}
|
|
2466
2472
|
}
|
|
2467
2473
|
}
|
|
@@ -5704,7 +5710,7 @@ function performAction({
|
|
|
5704
5710
|
context,
|
|
5705
5711
|
action
|
|
5706
5712
|
}) {
|
|
5707
|
-
switch (
|
|
5713
|
+
switch (action.type) {
|
|
5708
5714
|
case "delete.block": {
|
|
5709
5715
|
behaviorActionImplementations["delete.block"]({
|
|
5710
5716
|
context,
|
|
@@ -6043,7 +6049,7 @@ const editorMachine = xstate.setup({
|
|
|
6043
6049
|
enqueue
|
|
6044
6050
|
}) => {
|
|
6045
6051
|
var _a;
|
|
6046
|
-
xstate.assertEvent(event, ["behavior event"])
|
|
6052
|
+
xstate.assertEvent(event, ["behavior event"]);
|
|
6047
6053
|
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : __spreadProps$4(__spreadValues$4({}, event.behaviorEvent), {
|
|
6048
6054
|
editor: event.editor
|
|
6049
6055
|
}), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
@@ -6231,7 +6237,7 @@ const editorMachine = xstate.setup({
|
|
|
6231
6237
|
states: {
|
|
6232
6238
|
"determine initial edit mode": {
|
|
6233
6239
|
on: {
|
|
6234
|
-
"done syncing": [{
|
|
6240
|
+
"done syncing initial value": [{
|
|
6235
6241
|
target: "#editor.edit mode.read only.read only",
|
|
6236
6242
|
guard: ({
|
|
6237
6243
|
context
|
|
@@ -6327,7 +6333,7 @@ const editorMachine = xstate.setup({
|
|
|
6327
6333
|
mutation: {
|
|
6328
6334
|
actions: "defer event"
|
|
6329
6335
|
},
|
|
6330
|
-
"done syncing": {
|
|
6336
|
+
"done syncing initial value": {
|
|
6331
6337
|
target: "pristine"
|
|
6332
6338
|
}
|
|
6333
6339
|
}
|