@portabletext/editor 1.16.1 → 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 +222 -151
- 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 +223 -152
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.actions.ts +0 -3
- package/src/editor/__tests__/RangeDecorations.test.tsx +23 -8
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +3 -3
- package/src/editor/editor-machine.ts +8 -7
- package/src/editor/sync-machine.ts +262 -202
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);
|
|
@@ -2262,6 +2262,19 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
2262
2262
|
let block;
|
|
2263
2263
|
return operation.type === "set_selection" && editor.selection ? block = editor.children[editor.selection.focus.path[0]] : "path" in operation && (block = editor.children[operation.path[0]]), block;
|
|
2264
2264
|
}
|
|
2265
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name), __await = function(promise, isYieldStar) {
|
|
2266
|
+
this[0] = promise, this[1] = isYieldStar;
|
|
2267
|
+
}, __asyncGenerator = (__this, __arguments, generator) => {
|
|
2268
|
+
var resume = (k, v, yes, no) => {
|
|
2269
|
+
try {
|
|
2270
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
2271
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
2272
|
+
} catch (e) {
|
|
2273
|
+
no(e);
|
|
2274
|
+
}
|
|
2275
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
2276
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
2277
|
+
}, __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
2265
2278
|
const syncValueCallback = ({
|
|
2266
2279
|
sendBack,
|
|
2267
2280
|
input
|
|
@@ -2270,7 +2283,8 @@ const syncValueCallback = ({
|
|
|
2270
2283
|
context: input.context,
|
|
2271
2284
|
sendBack,
|
|
2272
2285
|
slateEditor: input.slateEditor,
|
|
2273
|
-
value: input.value
|
|
2286
|
+
value: input.value,
|
|
2287
|
+
streamBlocks: input.streamBlocks
|
|
2274
2288
|
});
|
|
2275
2289
|
}, syncValueLogic = xstate.fromCallback(syncValueCallback), syncMachine = xstate.setup({
|
|
2276
2290
|
types: {
|
|
@@ -2280,6 +2294,9 @@ const syncValueCallback = ({
|
|
|
2280
2294
|
emitted: {}
|
|
2281
2295
|
},
|
|
2282
2296
|
actions: {
|
|
2297
|
+
"assign initial value synced": xstate.assign({
|
|
2298
|
+
initialValueSynced: !0
|
|
2299
|
+
}),
|
|
2283
2300
|
"assign readOnly": xstate.assign({
|
|
2284
2301
|
readOnly: ({
|
|
2285
2302
|
event
|
|
@@ -2298,24 +2315,20 @@ const syncValueCallback = ({
|
|
|
2298
2315
|
event
|
|
2299
2316
|
}) => (xstate.assertEvent(event, "done syncing"), event.value)
|
|
2300
2317
|
}),
|
|
2301
|
-
"emit done syncing": xstate.emit(
|
|
2302
|
-
|
|
2303
|
-
})
|
|
2318
|
+
"emit done syncing initial value": xstate.emit({
|
|
2319
|
+
type: "done syncing initial value"
|
|
2320
|
+
})
|
|
2304
2321
|
},
|
|
2305
2322
|
guards: {
|
|
2306
|
-
"
|
|
2323
|
+
"initial value synced": ({
|
|
2307
2324
|
context
|
|
2308
|
-
}) => context.
|
|
2309
|
-
"is
|
|
2310
|
-
context
|
|
2311
|
-
}) => context.isProcessingLocalChanges,
|
|
2312
|
-
"is processing remote changes": ({
|
|
2325
|
+
}) => context.initialValueSynced,
|
|
2326
|
+
"is busy": ({
|
|
2313
2327
|
context
|
|
2314
2328
|
}) => {
|
|
2315
2329
|
var _a;
|
|
2316
|
-
return (_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1;
|
|
2330
|
+
return !context.readOnly && (context.isProcessingLocalChanges || ((_a = isChangingRemotely(context.slateEditor)) != null ? _a : !1));
|
|
2317
2331
|
},
|
|
2318
|
-
"is busy": xstate.and([xstate.not("is readOnly"), xstate.or(["is processing local changes", "is processing remote changes"])]),
|
|
2319
2332
|
"value changed while syncing": ({
|
|
2320
2333
|
context,
|
|
2321
2334
|
event
|
|
@@ -2332,6 +2345,7 @@ const syncValueCallback = ({
|
|
|
2332
2345
|
context: ({
|
|
2333
2346
|
input
|
|
2334
2347
|
}) => ({
|
|
2348
|
+
initialValueSynced: !1,
|
|
2335
2349
|
isProcessingLocalChanges: !1,
|
|
2336
2350
|
keyGenerator: input.keyGenerator,
|
|
2337
2351
|
schema: input.schema,
|
|
@@ -2340,7 +2354,6 @@ const syncValueCallback = ({
|
|
|
2340
2354
|
pendingValue: void 0,
|
|
2341
2355
|
previousValue: void 0
|
|
2342
2356
|
}),
|
|
2343
|
-
initial: "idle",
|
|
2344
2357
|
on: {
|
|
2345
2358
|
"has pending patches": {
|
|
2346
2359
|
actions: xstate.assign({
|
|
@@ -2356,101 +2369,114 @@ const syncValueCallback = ({
|
|
|
2356
2369
|
actions: ["assign readOnly"]
|
|
2357
2370
|
}
|
|
2358
2371
|
},
|
|
2372
|
+
type: "parallel",
|
|
2359
2373
|
states: {
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
busy: {
|
|
2373
|
-
after: {
|
|
2374
|
-
1e3: {
|
|
2375
|
-
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"
|
|
2376
2386
|
}
|
|
2377
|
-
},
|
|
2378
|
-
on: {
|
|
2379
|
-
"update value": [{
|
|
2380
|
-
guard: "is busy",
|
|
2381
|
-
actions: ["assign pending value"],
|
|
2382
|
-
reenter: !0
|
|
2383
|
-
}, {
|
|
2384
|
-
target: "syncing",
|
|
2385
|
-
actions: ["assign pending value"]
|
|
2386
|
-
}]
|
|
2387
2387
|
}
|
|
2388
2388
|
},
|
|
2389
2389
|
syncing: {
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
},
|
|
2404
|
-
slateEditor: context.slateEditor,
|
|
2405
|
-
value: (_a = context.pendingValue) != null ? _a : void 0
|
|
2406
|
-
};
|
|
2407
|
-
}
|
|
2408
|
-
},
|
|
2409
|
-
always: {
|
|
2410
|
-
guard: "pending value equals previous value",
|
|
2411
|
-
actions: [xstate.emit(({
|
|
2412
|
-
context
|
|
2413
|
-
}) => ({
|
|
2414
|
-
type: "done syncing",
|
|
2415
|
-
value: context.previousValue
|
|
2416
|
-
}))],
|
|
2417
|
-
target: "idle"
|
|
2418
|
-
},
|
|
2419
|
-
on: {
|
|
2420
|
-
"update value": {
|
|
2421
|
-
actions: ["assign pending value"]
|
|
2422
|
-
},
|
|
2423
|
-
patch: {
|
|
2424
|
-
actions: [xstate.emit(({
|
|
2425
|
-
event
|
|
2426
|
-
}) => event)]
|
|
2427
|
-
},
|
|
2428
|
-
"invalid value": {
|
|
2429
|
-
actions: [xstate.emit(({
|
|
2430
|
-
event
|
|
2431
|
-
}) => 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
|
+
}
|
|
2432
2403
|
},
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
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
|
+
}
|
|
2437
2418
|
},
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
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
|
+
}
|
|
2446
2471
|
}
|
|
2447
2472
|
}
|
|
2448
2473
|
}
|
|
2449
2474
|
}), debug$i = debugWithName("hook:useSyncValue");
|
|
2450
|
-
function updateValue({
|
|
2475
|
+
async function updateValue({
|
|
2451
2476
|
context,
|
|
2452
2477
|
sendBack,
|
|
2453
2478
|
slateEditor,
|
|
2479
|
+
streamBlocks,
|
|
2454
2480
|
value
|
|
2455
2481
|
}) {
|
|
2456
2482
|
let isChanged = !1, isValid = !0;
|
|
@@ -2475,31 +2501,48 @@ function updateValue({
|
|
|
2475
2501
|
const slateValueFromProps = toSlateValue(value, {
|
|
2476
2502
|
schemaTypes: context.schema
|
|
2477
2503
|
});
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2504
|
+
await new Promise((resolve) => {
|
|
2505
|
+
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2506
|
+
withRemoteChanges(slateEditor, () => {
|
|
2507
|
+
withoutPatching(slateEditor, async () => {
|
|
2508
|
+
const childrenLength = slateEditor.children.length;
|
|
2509
|
+
if (slateValueFromProps.length < childrenLength) {
|
|
2510
|
+
for (let i = childrenLength - 1; i > slateValueFromProps.length - 1; i--)
|
|
2511
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
2512
|
+
at: [i]
|
|
2513
|
+
});
|
|
2514
|
+
isChanged = !0;
|
|
2515
|
+
}
|
|
2516
|
+
try {
|
|
2517
|
+
for (var iter = __forAwait(getBlocks({
|
|
2518
|
+
slateValue: slateValueFromProps,
|
|
2519
|
+
streamBlocks
|
|
2520
|
+
})), more, temp, error; more = !(temp = await iter.next()).done; more = !1) {
|
|
2521
|
+
const [currentBlock, currentBlockIndex] = temp.value, {
|
|
2522
|
+
blockChanged,
|
|
2523
|
+
blockValid
|
|
2524
|
+
} = syncBlock({
|
|
2525
|
+
context,
|
|
2526
|
+
sendBack,
|
|
2527
|
+
block: currentBlock,
|
|
2528
|
+
index: currentBlockIndex,
|
|
2529
|
+
slateEditor,
|
|
2530
|
+
value
|
|
2531
|
+
});
|
|
2532
|
+
isChanged = blockChanged || isChanged, isValid = isValid && blockValid;
|
|
2533
|
+
}
|
|
2534
|
+
} catch (temp2) {
|
|
2535
|
+
error = [temp2];
|
|
2536
|
+
} finally {
|
|
2537
|
+
try {
|
|
2538
|
+
more && (temp = iter.return) && await temp.call(iter);
|
|
2539
|
+
} finally {
|
|
2540
|
+
if (error)
|
|
2541
|
+
throw error[0];
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
resolve();
|
|
2545
|
+
});
|
|
2503
2546
|
});
|
|
2504
2547
|
});
|
|
2505
2548
|
});
|
|
@@ -2546,6 +2589,29 @@ function updateValue({
|
|
|
2546
2589
|
value
|
|
2547
2590
|
});
|
|
2548
2591
|
}
|
|
2592
|
+
function getBlocks(_0) {
|
|
2593
|
+
return __asyncGenerator(this, arguments, function* ({
|
|
2594
|
+
slateValue,
|
|
2595
|
+
streamBlocks
|
|
2596
|
+
}) {
|
|
2597
|
+
let index = 0;
|
|
2598
|
+
try {
|
|
2599
|
+
for (var iter = __forAwait(slateValue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = !1) {
|
|
2600
|
+
const block = temp.value;
|
|
2601
|
+
streamBlocks && (yield new __await(new Promise((resolve) => setTimeout(resolve, 0)))), yield [block, index], index++;
|
|
2602
|
+
}
|
|
2603
|
+
} catch (temp2) {
|
|
2604
|
+
error = [temp2];
|
|
2605
|
+
} finally {
|
|
2606
|
+
try {
|
|
2607
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2608
|
+
} finally {
|
|
2609
|
+
if (error)
|
|
2610
|
+
throw error[0];
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
});
|
|
2614
|
+
}
|
|
2549
2615
|
function syncBlock({
|
|
2550
2616
|
context,
|
|
2551
2617
|
sendBack,
|
|
@@ -2554,33 +2620,38 @@ function syncBlock({
|
|
|
2554
2620
|
slateEditor,
|
|
2555
2621
|
value
|
|
2556
2622
|
}) {
|
|
2557
|
-
var _a, _b, _c, _d, _e;
|
|
2558
2623
|
let blockChanged = !1, blockValid = !0;
|
|
2559
|
-
const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex];
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2624
|
+
const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex], hasChanges = oldBlock && !isEqual__default.default(currentBlock, oldBlock);
|
|
2625
|
+
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
2626
|
+
withRemoteChanges(slateEditor, () => {
|
|
2627
|
+
withoutPatching(slateEditor, () => {
|
|
2628
|
+
var _a, _b, _c, _d, _e;
|
|
2629
|
+
if (hasChanges && blockValid) {
|
|
2630
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2631
|
+
!validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
|
|
2632
|
+
sendBack({
|
|
2633
|
+
type: "patch",
|
|
2634
|
+
patch
|
|
2635
|
+
});
|
|
2636
|
+
})), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2637
|
+
type: "invalid value",
|
|
2638
|
+
resolution: validation.resolution,
|
|
2639
|
+
value
|
|
2640
|
+
}), blockValid = !1);
|
|
2641
|
+
}
|
|
2642
|
+
if (!oldBlock && blockValid) {
|
|
2643
|
+
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2644
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || (_e = validation.resolution) != null && _e.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2645
|
+
at: [currentBlockIndex]
|
|
2646
|
+
}) : (debug$i("Invalid", validation), sendBack({
|
|
2647
|
+
type: "invalid value",
|
|
2648
|
+
resolution: validation.resolution,
|
|
2649
|
+
value
|
|
2650
|
+
}), blockValid = !1);
|
|
2651
|
+
}
|
|
2566
2652
|
});
|
|
2567
|
-
})
|
|
2568
|
-
|
|
2569
|
-
resolution: validation.resolution,
|
|
2570
|
-
value
|
|
2571
|
-
}), blockValid = !1);
|
|
2572
|
-
}
|
|
2573
|
-
if (!oldBlock && blockValid) {
|
|
2574
|
-
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2575
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation.valid || (_e = validation.resolution) != null && _e.autoResolve ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2576
|
-
at: [currentBlockIndex]
|
|
2577
|
-
}) : (debug$i("Invalid", validation), sendBack({
|
|
2578
|
-
type: "invalid value",
|
|
2579
|
-
resolution: validation.resolution,
|
|
2580
|
-
value
|
|
2581
|
-
}), blockValid = !1);
|
|
2582
|
-
}
|
|
2583
|
-
return {
|
|
2653
|
+
});
|
|
2654
|
+
}), {
|
|
2584
2655
|
blockChanged,
|
|
2585
2656
|
blockValid
|
|
2586
2657
|
};
|
|
@@ -5639,7 +5710,7 @@ function performAction({
|
|
|
5639
5710
|
context,
|
|
5640
5711
|
action
|
|
5641
5712
|
}) {
|
|
5642
|
-
switch (
|
|
5713
|
+
switch (action.type) {
|
|
5643
5714
|
case "delete.block": {
|
|
5644
5715
|
behaviorActionImplementations["delete.block"]({
|
|
5645
5716
|
context,
|
|
@@ -5978,7 +6049,7 @@ const editorMachine = xstate.setup({
|
|
|
5978
6049
|
enqueue
|
|
5979
6050
|
}) => {
|
|
5980
6051
|
var _a;
|
|
5981
|
-
xstate.assertEvent(event, ["behavior event"])
|
|
6052
|
+
xstate.assertEvent(event, ["behavior event"]);
|
|
5982
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), {
|
|
5983
6054
|
editor: event.editor
|
|
5984
6055
|
}), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
@@ -6166,7 +6237,7 @@ const editorMachine = xstate.setup({
|
|
|
6166
6237
|
states: {
|
|
6167
6238
|
"determine initial edit mode": {
|
|
6168
6239
|
on: {
|
|
6169
|
-
"done syncing": [{
|
|
6240
|
+
"done syncing initial value": [{
|
|
6170
6241
|
target: "#editor.edit mode.read only.read only",
|
|
6171
6242
|
guard: ({
|
|
6172
6243
|
context
|
|
@@ -6262,7 +6333,7 @@ const editorMachine = xstate.setup({
|
|
|
6262
6333
|
mutation: {
|
|
6263
6334
|
actions: "defer event"
|
|
6264
6335
|
},
|
|
6265
|
-
"done syncing": {
|
|
6336
|
+
"done syncing initial value": {
|
|
6266
6337
|
target: "pristine"
|
|
6267
6338
|
}
|
|
6268
6339
|
}
|