@portabletext/editor 1.4.0 → 1.4.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/index.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +21 -324
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +88 -392
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +21 -324
- package/lib/index.mjs.map +1 -1
- package/package.json +9 -8
- package/src/editor/plugins/createWithEditableAPI.ts +1 -1
- package/src/types/editor.ts +1 -1
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, is
|
|
|
2
2
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import isEqual from "lodash/isEqual.js";
|
|
4
4
|
import noop from "lodash/noop.js";
|
|
5
|
-
import
|
|
5
|
+
import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle } from "react";
|
|
6
6
|
import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Node, Operation, createEditor, deleteBackward, deleteForward, insertText } from "slate";
|
|
7
7
|
import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
|
|
8
8
|
import debug$m from "debug";
|
|
@@ -10,7 +10,7 @@ import { c } from "react-compiler-runtime";
|
|
|
10
10
|
import { styled } from "styled-components";
|
|
11
11
|
import uniq from "lodash/uniq.js";
|
|
12
12
|
import { Subject } from "rxjs";
|
|
13
|
-
import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor
|
|
13
|
+
import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor } from "xstate";
|
|
14
14
|
import { Schema } from "@sanity/schema";
|
|
15
15
|
import { diffMatchPatch as diffMatchPatch$1, set, insert, setIfMissing, unset, applyAll } from "@portabletext/patches";
|
|
16
16
|
import get from "lodash/get.js";
|
|
@@ -24,6 +24,7 @@ import throttle from "lodash/throttle.js";
|
|
|
24
24
|
import { useEffectEvent } from "use-effect-event";
|
|
25
25
|
import debounce from "lodash/debounce.js";
|
|
26
26
|
import { randomKey } from "@sanity/util/content";
|
|
27
|
+
import { useActorRef } from "@xstate/react";
|
|
27
28
|
function defineBehavior(behavior) {
|
|
28
29
|
return behavior;
|
|
29
30
|
}
|
|
@@ -2699,9 +2700,9 @@ function debugState(editor, stateName) {
|
|
|
2699
2700
|
}
|
|
2700
2701
|
function findBlockFromPath(editor, path) {
|
|
2701
2702
|
let blockIndex = -1;
|
|
2702
|
-
const block = editor.children.find((node,
|
|
2703
|
-
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key :
|
|
2704
|
-
return isMatch && (blockIndex =
|
|
2703
|
+
const block = editor.children.find((node, index) => {
|
|
2704
|
+
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
2705
|
+
return isMatch && (blockIndex = index), isMatch;
|
|
2705
2706
|
});
|
|
2706
2707
|
return block ? {
|
|
2707
2708
|
block,
|
|
@@ -2721,9 +2722,9 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2721
2722
|
childPath: void 0
|
|
2722
2723
|
};
|
|
2723
2724
|
let childIndex = -1;
|
|
2724
|
-
const child = block.children.find((node,
|
|
2725
|
-
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key :
|
|
2726
|
-
return isMatch && (childIndex =
|
|
2725
|
+
const child = block.children.find((node, index) => {
|
|
2726
|
+
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
2727
|
+
return isMatch && (childIndex = index), isMatch;
|
|
2727
2728
|
});
|
|
2728
2729
|
return child ? {
|
|
2729
2730
|
block,
|
|
@@ -2920,9 +2921,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2920
2921
|
const {
|
|
2921
2922
|
diffs
|
|
2922
2923
|
} = diffPatch;
|
|
2923
|
-
if (diffs.forEach((diff2,
|
|
2924
|
+
if (diffs.forEach((diff2, index) => {
|
|
2924
2925
|
const [diffType, text] = diff2;
|
|
2925
|
-
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(
|
|
2926
|
+
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2926
2927
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2927
2928
|
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2928
2929
|
...transformedOperation.properties.focus
|
|
@@ -4016,10 +4017,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4016
4017
|
}
|
|
4017
4018
|
},
|
|
4018
4019
|
value
|
|
4019
|
-
} : (value.some((blk,
|
|
4020
|
+
} : (value.some((blk, index) => {
|
|
4020
4021
|
if (!isPlainObject(blk))
|
|
4021
4022
|
return resolution = {
|
|
4022
|
-
patches: [unset([
|
|
4023
|
+
patches: [unset([index])],
|
|
4023
4024
|
description: `Block must be an object, got ${String(blk)}`,
|
|
4024
4025
|
action: "Unset invalid item",
|
|
4025
4026
|
item: blk,
|
|
@@ -4027,7 +4028,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4027
4028
|
description: "inputs.portable-text.invalid-value.not-an-object.description",
|
|
4028
4029
|
action: "inputs.portable-text.invalid-value.not-an-object.action",
|
|
4029
4030
|
values: {
|
|
4030
|
-
index
|
|
4031
|
+
index
|
|
4031
4032
|
}
|
|
4032
4033
|
}
|
|
4033
4034
|
}, !0;
|
|
@@ -4036,15 +4037,15 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4036
4037
|
patches: [set({
|
|
4037
4038
|
...blk,
|
|
4038
4039
|
_key: keyGenerator()
|
|
4039
|
-
}, [
|
|
4040
|
-
description: `Block at index ${
|
|
4040
|
+
}, [index])],
|
|
4041
|
+
description: `Block at index ${index} is missing required _key.`,
|
|
4041
4042
|
action: "Set the block with a random _key value",
|
|
4042
4043
|
item: blk,
|
|
4043
4044
|
i18n: {
|
|
4044
4045
|
description: "inputs.portable-text.invalid-value.missing-key.description",
|
|
4045
4046
|
action: "inputs.portable-text.invalid-value.missing-key.action",
|
|
4046
4047
|
values: {
|
|
4047
|
-
index
|
|
4048
|
+
index
|
|
4048
4049
|
}
|
|
4049
4050
|
}
|
|
4050
4051
|
}, !0;
|
|
@@ -4676,9 +4677,9 @@ function useSyncValue(props) {
|
|
|
4676
4677
|
withoutPatching(slateEditor, () => {
|
|
4677
4678
|
hadSelection && Transforms.deselect(slateEditor);
|
|
4678
4679
|
const childrenLength = slateEditor.children.length;
|
|
4679
|
-
slateEditor.children.forEach((_,
|
|
4680
|
+
slateEditor.children.forEach((_, index) => {
|
|
4680
4681
|
Transforms.removeNodes(slateEditor, {
|
|
4681
|
-
at: [childrenLength - 1 -
|
|
4682
|
+
at: [childrenLength - 1 - index]
|
|
4682
4683
|
});
|
|
4683
4684
|
}), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
4684
4685
|
decorators: []
|
|
@@ -4783,8 +4784,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
4783
4784
|
at: [currentBlockIndex]
|
|
4784
4785
|
}), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
4785
4786
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
4786
|
-
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_,
|
|
4787
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
4787
|
+
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
4788
|
+
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
4788
4789
|
childIndex > 0 && (debug$5("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
4789
4790
|
at: [currentBlockIndex, childIndex]
|
|
4790
4791
|
}));
|
|
@@ -6214,310 +6215,6 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6214
6215
|
) : null;
|
|
6215
6216
|
});
|
|
6216
6217
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6217
|
-
var index = typeof document < "u" ? useLayoutEffect : useEffect, withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
|
|
6218
|
-
/**
|
|
6219
|
-
* @license React
|
|
6220
|
-
* use-sync-external-store-shim.production.min.js
|
|
6221
|
-
*
|
|
6222
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6223
|
-
*
|
|
6224
|
-
* This source code is licensed under the MIT license found in the
|
|
6225
|
-
* LICENSE file in the root directory of this source tree.
|
|
6226
|
-
*/
|
|
6227
|
-
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
6228
|
-
function requireUseSyncExternalStoreShim_production_min() {
|
|
6229
|
-
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
6230
|
-
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
6231
|
-
var e = require$$0;
|
|
6232
|
-
function h(a, b) {
|
|
6233
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6234
|
-
}
|
|
6235
|
-
var k = typeof Object.is == "function" ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
|
|
6236
|
-
function q(a, b) {
|
|
6237
|
-
var d = b(), f = l({
|
|
6238
|
-
inst: {
|
|
6239
|
-
value: d,
|
|
6240
|
-
getSnapshot: b
|
|
6241
|
-
}
|
|
6242
|
-
}), c2 = f[0].inst, g = f[1];
|
|
6243
|
-
return n(function() {
|
|
6244
|
-
c2.value = d, c2.getSnapshot = b, r(c2) && g({
|
|
6245
|
-
inst: c2
|
|
6246
|
-
});
|
|
6247
|
-
}, [a, d, b]), m(function() {
|
|
6248
|
-
return r(c2) && g({
|
|
6249
|
-
inst: c2
|
|
6250
|
-
}), a(function() {
|
|
6251
|
-
r(c2) && g({
|
|
6252
|
-
inst: c2
|
|
6253
|
-
});
|
|
6254
|
-
});
|
|
6255
|
-
}, [a]), p(d), d;
|
|
6256
|
-
}
|
|
6257
|
-
function r(a) {
|
|
6258
|
-
var b = a.getSnapshot;
|
|
6259
|
-
a = a.value;
|
|
6260
|
-
try {
|
|
6261
|
-
var d = b();
|
|
6262
|
-
return !k(a, d);
|
|
6263
|
-
} catch {
|
|
6264
|
-
return !0;
|
|
6265
|
-
}
|
|
6266
|
-
}
|
|
6267
|
-
function t(a, b) {
|
|
6268
|
-
return b();
|
|
6269
|
-
}
|
|
6270
|
-
var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : q;
|
|
6271
|
-
return useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u, useSyncExternalStoreShim_production_min;
|
|
6272
|
-
}
|
|
6273
|
-
var useSyncExternalStoreShim_development = {};
|
|
6274
|
-
/**
|
|
6275
|
-
* @license React
|
|
6276
|
-
* use-sync-external-store-shim.development.js
|
|
6277
|
-
*
|
|
6278
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6279
|
-
*
|
|
6280
|
-
* This source code is licensed under the MIT license found in the
|
|
6281
|
-
* LICENSE file in the root directory of this source tree.
|
|
6282
|
-
*/
|
|
6283
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
6284
|
-
function requireUseSyncExternalStoreShim_development() {
|
|
6285
|
-
return hasRequiredUseSyncExternalStoreShim_development || (hasRequiredUseSyncExternalStoreShim_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6286
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6287
|
-
var React = require$$0, ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
6288
|
-
function error(format) {
|
|
6289
|
-
{
|
|
6290
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++)
|
|
6291
|
-
args[_key2 - 1] = arguments[_key2];
|
|
6292
|
-
printWarning("error", format, args);
|
|
6293
|
-
}
|
|
6294
|
-
}
|
|
6295
|
-
function printWarning(level, format, args) {
|
|
6296
|
-
{
|
|
6297
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame, stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
6298
|
-
stack !== "" && (format += "%s", args = args.concat([stack]));
|
|
6299
|
-
var argsWithFormat = args.map(function(item) {
|
|
6300
|
-
return String(item);
|
|
6301
|
-
});
|
|
6302
|
-
argsWithFormat.unshift("Warning: " + format), Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
6303
|
-
}
|
|
6304
|
-
}
|
|
6305
|
-
function is(x, y) {
|
|
6306
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6307
|
-
}
|
|
6308
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect2 = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = !1, didWarnUncachedGetSnapshot = !1;
|
|
6309
|
-
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
6310
|
-
didWarnOld18Alpha || React.startTransition !== void 0 && (didWarnOld18Alpha = !0, error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
|
|
6311
|
-
var value = getSnapshot();
|
|
6312
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
6313
|
-
var cachedValue = getSnapshot();
|
|
6314
|
-
objectIs(value, cachedValue) || (error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = !0);
|
|
6315
|
-
}
|
|
6316
|
-
var _useState = useState2({
|
|
6317
|
-
inst: {
|
|
6318
|
-
value,
|
|
6319
|
-
getSnapshot
|
|
6320
|
-
}
|
|
6321
|
-
}), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
6322
|
-
return useLayoutEffect2(function() {
|
|
6323
|
-
inst.value = value, inst.getSnapshot = getSnapshot, checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6324
|
-
inst
|
|
6325
|
-
});
|
|
6326
|
-
}, [subscribe, value, getSnapshot]), useEffect2(function() {
|
|
6327
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6328
|
-
inst
|
|
6329
|
-
});
|
|
6330
|
-
var handleStoreChange = function() {
|
|
6331
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6332
|
-
inst
|
|
6333
|
-
});
|
|
6334
|
-
};
|
|
6335
|
-
return subscribe(handleStoreChange);
|
|
6336
|
-
}, [subscribe]), useDebugValue(value), value;
|
|
6337
|
-
}
|
|
6338
|
-
function checkIfSnapshotChanged(inst) {
|
|
6339
|
-
var latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
|
|
6340
|
-
try {
|
|
6341
|
-
var nextValue = latestGetSnapshot();
|
|
6342
|
-
return !objectIs(prevValue, nextValue);
|
|
6343
|
-
} catch {
|
|
6344
|
-
return !0;
|
|
6345
|
-
}
|
|
6346
|
-
}
|
|
6347
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
6348
|
-
return getSnapshot();
|
|
6349
|
-
}
|
|
6350
|
-
var canUseDOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", isServerEnvironment = !canUseDOM, shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore, useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
|
|
6351
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
6352
|
-
}()), useSyncExternalStoreShim_development;
|
|
6353
|
-
}
|
|
6354
|
-
var hasRequiredShim;
|
|
6355
|
-
function requireShim() {
|
|
6356
|
-
return hasRequiredShim || (hasRequiredShim = 1, process.env.NODE_ENV === "production" ? shim.exports = requireUseSyncExternalStoreShim_production_min() : shim.exports = requireUseSyncExternalStoreShim_development()), shim.exports;
|
|
6357
|
-
}
|
|
6358
|
-
/**
|
|
6359
|
-
* @license React
|
|
6360
|
-
* use-sync-external-store-shim/with-selector.production.min.js
|
|
6361
|
-
*
|
|
6362
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6363
|
-
*
|
|
6364
|
-
* This source code is licensed under the MIT license found in the
|
|
6365
|
-
* LICENSE file in the root directory of this source tree.
|
|
6366
|
-
*/
|
|
6367
|
-
var hasRequiredWithSelector_production_min;
|
|
6368
|
-
function requireWithSelector_production_min() {
|
|
6369
|
-
if (hasRequiredWithSelector_production_min) return withSelector_production_min;
|
|
6370
|
-
hasRequiredWithSelector_production_min = 1;
|
|
6371
|
-
var h = require$$0, n = requireShim();
|
|
6372
|
-
function p(a, b) {
|
|
6373
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6374
|
-
}
|
|
6375
|
-
var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
|
|
6376
|
-
return withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
|
|
6377
|
-
var c2 = t(null);
|
|
6378
|
-
if (c2.current === null) {
|
|
6379
|
-
var f = {
|
|
6380
|
-
hasValue: !1,
|
|
6381
|
-
value: null
|
|
6382
|
-
};
|
|
6383
|
-
c2.current = f;
|
|
6384
|
-
} else f = c2.current;
|
|
6385
|
-
c2 = v(function() {
|
|
6386
|
-
function a2(a3) {
|
|
6387
|
-
if (!c3) {
|
|
6388
|
-
if (c3 = !0, d2 = a3, a3 = l(a3), g !== void 0 && f.hasValue) {
|
|
6389
|
-
var b2 = f.value;
|
|
6390
|
-
if (g(b2, a3)) return k = b2;
|
|
6391
|
-
}
|
|
6392
|
-
return k = a3;
|
|
6393
|
-
}
|
|
6394
|
-
if (b2 = k, q(d2, a3)) return b2;
|
|
6395
|
-
var e2 = l(a3);
|
|
6396
|
-
return g !== void 0 && g(b2, e2) ? b2 : (d2 = a3, k = e2);
|
|
6397
|
-
}
|
|
6398
|
-
var c3 = !1, d2, k, m = e === void 0 ? null : e;
|
|
6399
|
-
return [function() {
|
|
6400
|
-
return a2(b());
|
|
6401
|
-
}, m === null ? void 0 : function() {
|
|
6402
|
-
return a2(m());
|
|
6403
|
-
}];
|
|
6404
|
-
}, [b, e, l, g]);
|
|
6405
|
-
var d = r(a, c2[0], c2[1]);
|
|
6406
|
-
return u(function() {
|
|
6407
|
-
f.hasValue = !0, f.value = d;
|
|
6408
|
-
}, [d]), w(d), d;
|
|
6409
|
-
}, withSelector_production_min;
|
|
6410
|
-
}
|
|
6411
|
-
var withSelector_development = {};
|
|
6412
|
-
/**
|
|
6413
|
-
* @license React
|
|
6414
|
-
* use-sync-external-store-shim/with-selector.development.js
|
|
6415
|
-
*
|
|
6416
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6417
|
-
*
|
|
6418
|
-
* This source code is licensed under the MIT license found in the
|
|
6419
|
-
* LICENSE file in the root directory of this source tree.
|
|
6420
|
-
*/
|
|
6421
|
-
var hasRequiredWithSelector_development;
|
|
6422
|
-
function requireWithSelector_development() {
|
|
6423
|
-
return hasRequiredWithSelector_development || (hasRequiredWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6424
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6425
|
-
var React = require$$0, shim2 = requireShim();
|
|
6426
|
-
function is(x, y) {
|
|
6427
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6428
|
-
}
|
|
6429
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
|
|
6430
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
|
|
6431
|
-
var instRef = useRef2(null), inst;
|
|
6432
|
-
instRef.current === null ? (inst = {
|
|
6433
|
-
hasValue: !1,
|
|
6434
|
-
value: null
|
|
6435
|
-
}, instRef.current = inst) : inst = instRef.current;
|
|
6436
|
-
var _useMemo = useMemo2(function() {
|
|
6437
|
-
var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) {
|
|
6438
|
-
if (!hasMemo) {
|
|
6439
|
-
hasMemo = !0, memoizedSnapshot = nextSnapshot;
|
|
6440
|
-
var _nextSelection = selector(nextSnapshot);
|
|
6441
|
-
if (isEqual2 !== void 0 && inst.hasValue) {
|
|
6442
|
-
var currentSelection = inst.value;
|
|
6443
|
-
if (isEqual2(currentSelection, _nextSelection))
|
|
6444
|
-
return memoizedSelection = currentSelection, currentSelection;
|
|
6445
|
-
}
|
|
6446
|
-
return memoizedSelection = _nextSelection, _nextSelection;
|
|
6447
|
-
}
|
|
6448
|
-
var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection;
|
|
6449
|
-
if (objectIs(prevSnapshot, nextSnapshot))
|
|
6450
|
-
return prevSelection;
|
|
6451
|
-
var nextSelection = selector(nextSnapshot);
|
|
6452
|
-
return isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection);
|
|
6453
|
-
}, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() {
|
|
6454
|
-
return memoizedSelector(getSnapshot());
|
|
6455
|
-
}, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
6456
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
6457
|
-
};
|
|
6458
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
6459
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
6460
|
-
return useEffect2(function() {
|
|
6461
|
-
inst.hasValue = !0, inst.value = value;
|
|
6462
|
-
}, [value]), useDebugValue(value), value;
|
|
6463
|
-
}
|
|
6464
|
-
withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
6465
|
-
}()), withSelector_development;
|
|
6466
|
-
}
|
|
6467
|
-
var hasRequiredWithSelector;
|
|
6468
|
-
function requireWithSelector() {
|
|
6469
|
-
return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireWithSelector_production_min() : withSelector.exports = requireWithSelector_development()), withSelector.exports;
|
|
6470
|
-
}
|
|
6471
|
-
requireWithSelector();
|
|
6472
|
-
requireShim();
|
|
6473
|
-
const forEachActor = (actorRef, callback) => {
|
|
6474
|
-
callback(actorRef);
|
|
6475
|
-
const children = actorRef.getSnapshot().children;
|
|
6476
|
-
children && Object.values(children).forEach((child) => {
|
|
6477
|
-
forEachActor(child, callback);
|
|
6478
|
-
});
|
|
6479
|
-
};
|
|
6480
|
-
function stopRootWithRehydration(actorRef) {
|
|
6481
|
-
const persistedSnapshots = [];
|
|
6482
|
-
forEachActor(actorRef, (ref) => {
|
|
6483
|
-
persistedSnapshots.push([ref, ref.getSnapshot()]), ref.observers = /* @__PURE__ */ new Set();
|
|
6484
|
-
});
|
|
6485
|
-
const systemSnapshot = actorRef.system.getSnapshot?.();
|
|
6486
|
-
actorRef.stop(), actorRef.system._snapshot = systemSnapshot, persistedSnapshots.forEach(([ref, snapshot]) => {
|
|
6487
|
-
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6488
|
-
});
|
|
6489
|
-
}
|
|
6490
|
-
function useIdleActorRef(logic, ...[options]) {
|
|
6491
|
-
let [[currentConfig, actorRef], setCurrent] = useState(() => {
|
|
6492
|
-
const actorRef2 = createActor(logic, options);
|
|
6493
|
-
return [logic.config, actorRef2];
|
|
6494
|
-
});
|
|
6495
|
-
if (logic.config !== currentConfig) {
|
|
6496
|
-
const newActorRef = createActor(logic, {
|
|
6497
|
-
...options,
|
|
6498
|
-
snapshot: actorRef.getPersistedSnapshot({
|
|
6499
|
-
__unsafeAllowInlineActors: !0
|
|
6500
|
-
})
|
|
6501
|
-
});
|
|
6502
|
-
setCurrent([logic.config, newActorRef]), actorRef = newActorRef;
|
|
6503
|
-
}
|
|
6504
|
-
return index(() => {
|
|
6505
|
-
actorRef.logic.implementations = logic.implementations;
|
|
6506
|
-
}), actorRef;
|
|
6507
|
-
}
|
|
6508
|
-
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
6509
|
-
const actorRef = useIdleActorRef(machine, options);
|
|
6510
|
-
return useEffect(() => {
|
|
6511
|
-
if (!observerOrListener)
|
|
6512
|
-
return;
|
|
6513
|
-
let sub = actorRef.subscribe(toObserver(observerOrListener));
|
|
6514
|
-
return () => {
|
|
6515
|
-
sub.unsubscribe();
|
|
6516
|
-
};
|
|
6517
|
-
}, [observerOrListener]), useEffect(() => (actorRef.start(), () => {
|
|
6518
|
-
stopRootWithRehydration(actorRef);
|
|
6519
|
-
}), [actorRef]), actorRef;
|
|
6520
|
-
}
|
|
6521
6218
|
function useEditor(config) {
|
|
6522
6219
|
const $ = c(8);
|
|
6523
6220
|
let t0;
|