@sanity/document-internationalization 3.2.0 → 3.2.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/README.md +4 -4
- package/dist/index.esm.js +2996 -169
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2989 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2996 -169
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -11
package/dist/index.esm.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
5
|
+
for (var prop in b || (b = {}))
|
|
6
|
+
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
7
|
+
if (__getOwnPropSymbols)
|
|
8
|
+
for (var prop of __getOwnPropSymbols(b))
|
|
9
|
+
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
10
|
+
return a;
|
|
11
|
+
};
|
|
1
12
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
13
|
import { TrashIcon, CopyIcon, CogIcon, SplitVerticalIcon, CheckmarkIcon, AddIcon, EditIcon, TranslateIcon, InfoOutlineIcon } from "@sanity/icons";
|
|
3
|
-
import { Flex, Spinner, Stack, Text, Card, Grid, Button, useToast, Tooltip, Box, Badge, useClickOutside, TextInput, Popover, Inline, Dialog } from "@sanity/ui";
|
|
14
|
+
import { Flex, Spinner, Stack as Stack$1, Text, Card, Grid, Button, useToast, Tooltip, Box, Badge, useClickOutside, TextInput, Popover, Inline, Dialog } from "@sanity/ui";
|
|
4
15
|
import { useMemo, useEffect, createContext, useContext, useState, useCallback } from "react";
|
|
5
16
|
import { useSchema, Preview, useClient, useWorkspace, defineLocaleResourceBundle, useDocumentStore, useDocumentOperation, useDocumentPairPermissions, DEFAULT_STUDIO_CLIENT_OPTIONS, useTranslation, useCurrentUser, InsufficientPermissionsMessage, isDocumentSchemaType, pathToString, useEditState, useValidationStatus, TextWithTone, PatchEvent, unset, defineType, defineField, definePlugin, isSanityDocument } from "sanity";
|
|
6
17
|
import { Feedback, useListeningQuery } from "sanity-plugin-utils";
|
|
7
18
|
import { uuid } from "@sanity/uuid";
|
|
8
19
|
import { useRouter, RouterContext } from "sanity/router";
|
|
9
20
|
import { structureLocaleNamespace, usePaneRouter, useDocumentPane } from "sanity/structure";
|
|
10
|
-
import
|
|
21
|
+
import require$$0 from "tty";
|
|
22
|
+
import require$$1 from "util";
|
|
11
23
|
import { styled } from "styled-components";
|
|
12
24
|
import { internationalizedArray } from "sanity-plugin-internationalized-array";
|
|
13
25
|
function DocumentPreview(props) {
|
|
@@ -40,9 +52,9 @@ function DeleteTranslationDialog(props) {
|
|
|
40
52
|
);
|
|
41
53
|
return useEffect(() => {
|
|
42
54
|
setTranslations(translations);
|
|
43
|
-
}, [setTranslations, translations]), loading ? /* @__PURE__ */ jsx(Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
55
|
+
}, [setTranslations, translations]), loading ? /* @__PURE__ */ jsx(Flex, { padding: 4, align: "center", justify: "center", children: /* @__PURE__ */ jsx(Spinner, {}) }) : /* @__PURE__ */ jsxs(Stack$1, { space: 4, children: [
|
|
44
56
|
translations && translations.length > 0 ? /* @__PURE__ */ jsx(Text, { children: "This document is a language-specific version which other translations depend on." }) : /* @__PURE__ */ jsx(Text, { children: "This document does not have connected translations." }),
|
|
45
|
-
/* @__PURE__ */ jsx(Card, { border: !0, padding: 3, children: /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
57
|
+
/* @__PURE__ */ jsx(Card, { border: !0, padding: 3, children: /* @__PURE__ */ jsxs(Stack$1, { space: 4, children: [
|
|
46
58
|
/* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: translations && translations.length > 0 ? /* @__PURE__ */ jsx(Fragment, { children: "Before this document can be deleted" }) : /* @__PURE__ */ jsx(Fragment, { children: "This document can now be deleted" }) }),
|
|
47
59
|
/* @__PURE__ */ jsx(DocumentPreview, { value: doc, type: doc._type }),
|
|
48
60
|
translations && translations.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -141,7 +153,16 @@ function query$1(fn, keys = null, preload = !1, config2 = {}) {
|
|
|
141
153
|
if (globalCache.push(entry), !preload)
|
|
142
154
|
throw entry.promise;
|
|
143
155
|
}
|
|
144
|
-
const suspend = (fn, keys, config2) => query$1(fn, keys, !1, config2)
|
|
156
|
+
const suspend = (fn, keys, config2) => query$1(fn, keys, !1, config2);
|
|
157
|
+
var __defProp$i = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
158
|
+
for (var prop in b || (b = {}))
|
|
159
|
+
__hasOwnProp$3.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
160
|
+
if (__getOwnPropSymbols$3)
|
|
161
|
+
for (var prop of __getOwnPropSymbols$3(b))
|
|
162
|
+
__propIsEnum$3.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
163
|
+
return a;
|
|
164
|
+
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
165
|
+
const DocumentInternationalizationContext = createContext(DEFAULT_CONFIG);
|
|
145
166
|
function useDocumentInternationalizationContext() {
|
|
146
167
|
return useContext(DocumentInternationalizationContext);
|
|
147
168
|
}
|
|
@@ -153,7 +174,7 @@ function DocumentInternationalizationProvider(props) {
|
|
|
153
174
|
return /* @__PURE__ */ jsx(
|
|
154
175
|
DocumentInternationalizationContext.Provider,
|
|
155
176
|
{
|
|
156
|
-
value: {
|
|
177
|
+
value: __spreadProps$2(__spreadValues$3({}, pluginConfig), { supportedLanguages }),
|
|
157
178
|
children: props.renderDefault(props)
|
|
158
179
|
}
|
|
159
180
|
);
|
|
@@ -269,7 +290,7 @@ function __spreadArray(to, from, pack) {
|
|
|
269
290
|
(ar || !(i in from)) && (ar || (ar = Array.prototype.slice.call(from, 0, i)), ar[i] = from[i]);
|
|
270
291
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
271
292
|
}
|
|
272
|
-
function isFunction(value) {
|
|
293
|
+
function isFunction$2(value) {
|
|
273
294
|
return typeof value == "function";
|
|
274
295
|
}
|
|
275
296
|
function createErrorClass(createImpl) {
|
|
@@ -322,7 +343,7 @@ var Subscription = function() {
|
|
|
322
343
|
else
|
|
323
344
|
_parentage.remove(this);
|
|
324
345
|
var initialFinalizer = this.initialTeardown;
|
|
325
|
-
if (isFunction(initialFinalizer))
|
|
346
|
+
if (isFunction$2(initialFinalizer))
|
|
326
347
|
try {
|
|
327
348
|
initialFinalizer();
|
|
328
349
|
} catch (e) {
|
|
@@ -385,10 +406,10 @@ var Subscription = function() {
|
|
|
385
406
|
}(), Subscription2;
|
|
386
407
|
}();
|
|
387
408
|
function isSubscription(value) {
|
|
388
|
-
return value instanceof Subscription || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
|
|
409
|
+
return value instanceof Subscription || value && "closed" in value && isFunction$2(value.remove) && isFunction$2(value.add) && isFunction$2(value.unsubscribe);
|
|
389
410
|
}
|
|
390
411
|
function execFinalizer(finalizer) {
|
|
391
|
-
isFunction(finalizer) ? finalizer() : finalizer.unsubscribe();
|
|
412
|
+
isFunction$2(finalizer) ? finalizer() : finalizer.unsubscribe();
|
|
392
413
|
}
|
|
393
414
|
var config = {
|
|
394
415
|
onUnhandledError: null,
|
|
@@ -484,7 +505,7 @@ var ConsumerObserver = function() {
|
|
|
484
505
|
__extends(SafeSubscriber2, _super);
|
|
485
506
|
function SafeSubscriber2(observerOrNext, error, complete) {
|
|
486
507
|
var _this = _super.call(this) || this, partialObserver;
|
|
487
|
-
if (isFunction(observerOrNext) || !observerOrNext)
|
|
508
|
+
if (isFunction$2(observerOrNext) || !observerOrNext)
|
|
488
509
|
partialObserver = {
|
|
489
510
|
next: observerOrNext != null ? observerOrNext : void 0,
|
|
490
511
|
error: error != null ? error : void 0,
|
|
@@ -517,7 +538,7 @@ var EMPTY_OBSERVER = {
|
|
|
517
538
|
complete: noop
|
|
518
539
|
};
|
|
519
540
|
function hasLift(source) {
|
|
520
|
-
return isFunction(source == null ? void 0 : source.lift);
|
|
541
|
+
return isFunction$2(source == null ? void 0 : source.lift);
|
|
521
542
|
}
|
|
522
543
|
function operate(init) {
|
|
523
544
|
return function(source) {
|
|
@@ -576,7 +597,6 @@ var OperatorSubscriber = function(_super) {
|
|
|
576
597
|
};
|
|
577
598
|
});
|
|
578
599
|
function firstValueFrom(source, config2) {
|
|
579
|
-
var hasConfig = typeof config2 == "object";
|
|
580
600
|
return new Promise(function(resolve, reject) {
|
|
581
601
|
var subscriber = new SafeSubscriber({
|
|
582
602
|
next: function(value) {
|
|
@@ -584,7 +604,7 @@ function firstValueFrom(source, config2) {
|
|
|
584
604
|
},
|
|
585
605
|
error: reject,
|
|
586
606
|
complete: function() {
|
|
587
|
-
|
|
607
|
+
reject(new EmptyError());
|
|
588
608
|
}
|
|
589
609
|
});
|
|
590
610
|
source.subscribe(subscriber);
|
|
@@ -752,17 +772,23 @@ function useOpenInNewPane(id, type) {
|
|
|
752
772
|
routerContext.navigateUrl({ path: href });
|
|
753
773
|
}, [id, type, routerContext, routerPanesState, groupIndex]);
|
|
754
774
|
}
|
|
775
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
776
|
+
for (var prop in b || (b = {}))
|
|
777
|
+
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
778
|
+
if (__getOwnPropSymbols$2)
|
|
779
|
+
for (var prop of __getOwnPropSymbols$2(b))
|
|
780
|
+
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
781
|
+
return a;
|
|
782
|
+
};
|
|
755
783
|
function createReference(key, ref, type, strengthenOnPublish = !0) {
|
|
756
784
|
return {
|
|
757
785
|
_key: key,
|
|
758
786
|
_type: "internationalizedArrayReferenceValue",
|
|
759
|
-
value: {
|
|
787
|
+
value: __spreadValues$2({
|
|
760
788
|
_type: "reference",
|
|
761
789
|
_ref: ref,
|
|
762
|
-
_weak: !0
|
|
763
|
-
|
|
764
|
-
...strengthenOnPublish ? { _strengthenOnPublish: { type } } : {}
|
|
765
|
-
}
|
|
790
|
+
_weak: !0
|
|
791
|
+
}, strengthenOnPublish ? { _strengthenOnPublish: { type } } : {})
|
|
766
792
|
};
|
|
767
793
|
}
|
|
768
794
|
function LanguageManage(props) {
|
|
@@ -807,7 +833,7 @@ function LanguageManage(props) {
|
|
|
807
833
|
placement: "top",
|
|
808
834
|
portal: !0,
|
|
809
835
|
disabled: !!id || canCreate,
|
|
810
|
-
children: /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(
|
|
836
|
+
children: /* @__PURE__ */ jsx(Stack$1, { children: /* @__PURE__ */ jsx(
|
|
811
837
|
Button,
|
|
812
838
|
{
|
|
813
839
|
disabled: !id && !canCreate || canCreate && !sourceLanguageId || userHasClicked,
|
|
@@ -821,150 +847,2944 @@ function LanguageManage(props) {
|
|
|
821
847
|
}
|
|
822
848
|
);
|
|
823
849
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
850
|
+
var commonjsGlobal = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
851
|
+
function getDefaultExportFromCjs(x) {
|
|
852
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x.default : x;
|
|
853
|
+
}
|
|
854
|
+
function listCacheClear$1() {
|
|
855
|
+
this.__data__ = [], this.size = 0;
|
|
856
|
+
}
|
|
857
|
+
var _listCacheClear = listCacheClear$1;
|
|
858
|
+
function eq$1(value, other) {
|
|
859
|
+
return value === other || value !== value && other !== other;
|
|
860
|
+
}
|
|
861
|
+
var eq_1 = eq$1, eq = eq_1;
|
|
862
|
+
function assocIndexOf$4(array, key) {
|
|
863
|
+
for (var length = array.length; length--; )
|
|
864
|
+
if (eq(array[length][0], key))
|
|
865
|
+
return length;
|
|
866
|
+
return -1;
|
|
867
|
+
}
|
|
868
|
+
var _assocIndexOf = assocIndexOf$4, assocIndexOf$3 = _assocIndexOf, arrayProto = Array.prototype, splice = arrayProto.splice;
|
|
869
|
+
function listCacheDelete$1(key) {
|
|
870
|
+
var data = this.__data__, index = assocIndexOf$3(data, key);
|
|
871
|
+
if (index < 0)
|
|
872
|
+
return !1;
|
|
873
|
+
var lastIndex = data.length - 1;
|
|
874
|
+
return index == lastIndex ? data.pop() : splice.call(data, index, 1), --this.size, !0;
|
|
875
|
+
}
|
|
876
|
+
var _listCacheDelete = listCacheDelete$1, assocIndexOf$2 = _assocIndexOf;
|
|
877
|
+
function listCacheGet$1(key) {
|
|
878
|
+
var data = this.__data__, index = assocIndexOf$2(data, key);
|
|
879
|
+
return index < 0 ? void 0 : data[index][1];
|
|
880
|
+
}
|
|
881
|
+
var _listCacheGet = listCacheGet$1, assocIndexOf$1 = _assocIndexOf;
|
|
882
|
+
function listCacheHas$1(key) {
|
|
883
|
+
return assocIndexOf$1(this.__data__, key) > -1;
|
|
884
|
+
}
|
|
885
|
+
var _listCacheHas = listCacheHas$1, assocIndexOf = _assocIndexOf;
|
|
886
|
+
function listCacheSet$1(key, value) {
|
|
887
|
+
var data = this.__data__, index = assocIndexOf(data, key);
|
|
888
|
+
return index < 0 ? (++this.size, data.push([key, value])) : data[index][1] = value, this;
|
|
889
|
+
}
|
|
890
|
+
var _listCacheSet = listCacheSet$1, listCacheClear = _listCacheClear, listCacheDelete = _listCacheDelete, listCacheGet = _listCacheGet, listCacheHas = _listCacheHas, listCacheSet = _listCacheSet;
|
|
891
|
+
function ListCache$4(entries) {
|
|
892
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
893
|
+
for (this.clear(); ++index < length; ) {
|
|
894
|
+
var entry = entries[index];
|
|
895
|
+
this.set(entry[0], entry[1]);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
ListCache$4.prototype.clear = listCacheClear;
|
|
899
|
+
ListCache$4.prototype.delete = listCacheDelete;
|
|
900
|
+
ListCache$4.prototype.get = listCacheGet;
|
|
901
|
+
ListCache$4.prototype.has = listCacheHas;
|
|
902
|
+
ListCache$4.prototype.set = listCacheSet;
|
|
903
|
+
var _ListCache = ListCache$4, ListCache$3 = _ListCache;
|
|
904
|
+
function stackClear$1() {
|
|
905
|
+
this.__data__ = new ListCache$3(), this.size = 0;
|
|
906
|
+
}
|
|
907
|
+
var _stackClear = stackClear$1;
|
|
908
|
+
function stackDelete$1(key) {
|
|
909
|
+
var data = this.__data__, result = data.delete(key);
|
|
910
|
+
return this.size = data.size, result;
|
|
911
|
+
}
|
|
912
|
+
var _stackDelete = stackDelete$1;
|
|
913
|
+
function stackGet$1(key) {
|
|
914
|
+
return this.__data__.get(key);
|
|
915
|
+
}
|
|
916
|
+
var _stackGet = stackGet$1;
|
|
917
|
+
function stackHas$1(key) {
|
|
918
|
+
return this.__data__.has(key);
|
|
919
|
+
}
|
|
920
|
+
var _stackHas = stackHas$1, freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal, _freeGlobal = freeGlobal$1, freeGlobal = _freeGlobal, freeSelf = typeof self == "object" && self && self.Object === Object && self, root$7 = freeGlobal || freeSelf || Function("return this")(), _root = root$7, root$6 = _root, Symbol$4 = root$6.Symbol, _Symbol = Symbol$4, Symbol$3 = _Symbol, objectProto$5 = Object.prototype, hasOwnProperty$4 = objectProto$5.hasOwnProperty, nativeObjectToString$1 = objectProto$5.toString, symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : void 0;
|
|
921
|
+
function getRawTag$1(value) {
|
|
922
|
+
var isOwn = hasOwnProperty$4.call(value, symToStringTag$1), tag = value[symToStringTag$1];
|
|
923
|
+
try {
|
|
924
|
+
value[symToStringTag$1] = void 0;
|
|
925
|
+
var unmasked = !0;
|
|
926
|
+
} catch (e) {
|
|
927
|
+
}
|
|
928
|
+
var result = nativeObjectToString$1.call(value);
|
|
929
|
+
return unmasked && (isOwn ? value[symToStringTag$1] = tag : delete value[symToStringTag$1]), result;
|
|
930
|
+
}
|
|
931
|
+
var _getRawTag = getRawTag$1, objectProto$4 = Object.prototype, nativeObjectToString = objectProto$4.toString;
|
|
932
|
+
function objectToString$1(value) {
|
|
933
|
+
return nativeObjectToString.call(value);
|
|
934
|
+
}
|
|
935
|
+
var _objectToString = objectToString$1, Symbol$2 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString, nullTag = "[object Null]", undefinedTag = "[object Undefined]", symToStringTag = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
936
|
+
function baseGetTag$4(value) {
|
|
937
|
+
return value == null ? value === void 0 ? undefinedTag : nullTag : symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
938
|
+
}
|
|
939
|
+
var _baseGetTag = baseGetTag$4;
|
|
940
|
+
function isObject$2(value) {
|
|
941
|
+
var type = typeof value;
|
|
942
|
+
return value != null && (type == "object" || type == "function");
|
|
943
|
+
}
|
|
944
|
+
var isObject_1 = isObject$2, baseGetTag$3 = _baseGetTag, isObject$1 = isObject_1, asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
|
|
945
|
+
function isFunction$1(value) {
|
|
946
|
+
if (!isObject$1(value))
|
|
947
|
+
return !1;
|
|
948
|
+
var tag = baseGetTag$3(value);
|
|
949
|
+
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
|
950
|
+
}
|
|
951
|
+
var isFunction_1 = isFunction$1, root$5 = _root, coreJsData$1 = root$5["__core-js_shared__"], _coreJsData = coreJsData$1, coreJsData = _coreJsData, maskSrcKey = function() {
|
|
952
|
+
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
|
|
953
|
+
return uid ? "Symbol(src)_1." + uid : "";
|
|
954
|
+
}();
|
|
955
|
+
function isMasked$1(func) {
|
|
956
|
+
return !!maskSrcKey && maskSrcKey in func;
|
|
957
|
+
}
|
|
958
|
+
var _isMasked = isMasked$1, funcProto$1 = Function.prototype, funcToString$1 = funcProto$1.toString;
|
|
959
|
+
function toSource$2(func) {
|
|
960
|
+
if (func != null) {
|
|
961
|
+
try {
|
|
962
|
+
return funcToString$1.call(func);
|
|
963
|
+
} catch (e) {
|
|
831
964
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
965
|
+
try {
|
|
966
|
+
return func + "";
|
|
967
|
+
} catch (e) {
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
return "";
|
|
971
|
+
}
|
|
972
|
+
var _toSource = toSource$2, isFunction = isFunction_1, isMasked = _isMasked, isObject = isObject_1, toSource$1 = _toSource, reRegExpChar = /[\\^$.*+?()[\]{}|]/g, reIsHostCtor = /^\[object .+?Constructor\]$/, funcProto = Function.prototype, objectProto$3 = Object.prototype, funcToString = funcProto.toString, hasOwnProperty$3 = objectProto$3.hasOwnProperty, reIsNative = RegExp(
|
|
973
|
+
"^" + funcToString.call(hasOwnProperty$3).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
974
|
+
);
|
|
975
|
+
function baseIsNative$1(value) {
|
|
976
|
+
if (!isObject(value) || isMasked(value))
|
|
977
|
+
return !1;
|
|
978
|
+
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
|
979
|
+
return pattern.test(toSource$1(value));
|
|
980
|
+
}
|
|
981
|
+
var _baseIsNative = baseIsNative$1;
|
|
982
|
+
function getValue$1(object, key) {
|
|
983
|
+
return object == null ? void 0 : object[key];
|
|
984
|
+
}
|
|
985
|
+
var _getValue = getValue$1, baseIsNative = _baseIsNative, getValue = _getValue;
|
|
986
|
+
function getNative$6(object, key) {
|
|
987
|
+
var value = getValue(object, key);
|
|
988
|
+
return baseIsNative(value) ? value : void 0;
|
|
989
|
+
}
|
|
990
|
+
var _getNative = getNative$6, getNative$5 = _getNative, root$4 = _root, Map$4 = getNative$5(root$4, "Map"), _Map = Map$4, getNative$4 = _getNative, nativeCreate$4 = getNative$4(Object, "create"), _nativeCreate = nativeCreate$4, nativeCreate$3 = _nativeCreate;
|
|
991
|
+
function hashClear$1() {
|
|
992
|
+
this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {}, this.size = 0;
|
|
993
|
+
}
|
|
994
|
+
var _hashClear = hashClear$1;
|
|
995
|
+
function hashDelete$1(key) {
|
|
996
|
+
var result = this.has(key) && delete this.__data__[key];
|
|
997
|
+
return this.size -= result ? 1 : 0, result;
|
|
998
|
+
}
|
|
999
|
+
var _hashDelete = hashDelete$1, nativeCreate$2 = _nativeCreate, HASH_UNDEFINED$2 = "__lodash_hash_undefined__", objectProto$2 = Object.prototype, hasOwnProperty$2 = objectProto$2.hasOwnProperty;
|
|
1000
|
+
function hashGet$1(key) {
|
|
1001
|
+
var data = this.__data__;
|
|
1002
|
+
if (nativeCreate$2) {
|
|
1003
|
+
var result = data[key];
|
|
1004
|
+
return result === HASH_UNDEFINED$2 ? void 0 : result;
|
|
1005
|
+
}
|
|
1006
|
+
return hasOwnProperty$2.call(data, key) ? data[key] : void 0;
|
|
1007
|
+
}
|
|
1008
|
+
var _hashGet = hashGet$1, nativeCreate$1 = _nativeCreate, objectProto$1 = Object.prototype, hasOwnProperty$1 = objectProto$1.hasOwnProperty;
|
|
1009
|
+
function hashHas$1(key) {
|
|
1010
|
+
var data = this.__data__;
|
|
1011
|
+
return nativeCreate$1 ? data[key] !== void 0 : hasOwnProperty$1.call(data, key);
|
|
1012
|
+
}
|
|
1013
|
+
var _hashHas = hashHas$1, nativeCreate = _nativeCreate, HASH_UNDEFINED$1 = "__lodash_hash_undefined__";
|
|
1014
|
+
function hashSet$1(key, value) {
|
|
1015
|
+
var data = this.__data__;
|
|
1016
|
+
return this.size += this.has(key) ? 0 : 1, data[key] = nativeCreate && value === void 0 ? HASH_UNDEFINED$1 : value, this;
|
|
1017
|
+
}
|
|
1018
|
+
var _hashSet = hashSet$1, hashClear = _hashClear, hashDelete = _hashDelete, hashGet = _hashGet, hashHas = _hashHas, hashSet = _hashSet;
|
|
1019
|
+
function Hash$1(entries) {
|
|
1020
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
1021
|
+
for (this.clear(); ++index < length; ) {
|
|
1022
|
+
var entry = entries[index];
|
|
1023
|
+
this.set(entry[0], entry[1]);
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
Hash$1.prototype.clear = hashClear;
|
|
1027
|
+
Hash$1.prototype.delete = hashDelete;
|
|
1028
|
+
Hash$1.prototype.get = hashGet;
|
|
1029
|
+
Hash$1.prototype.has = hashHas;
|
|
1030
|
+
Hash$1.prototype.set = hashSet;
|
|
1031
|
+
var _Hash = Hash$1, Hash = _Hash, ListCache$2 = _ListCache, Map$3 = _Map;
|
|
1032
|
+
function mapCacheClear$1() {
|
|
1033
|
+
this.size = 0, this.__data__ = {
|
|
1034
|
+
hash: new Hash(),
|
|
1035
|
+
map: new (Map$3 || ListCache$2)(),
|
|
1036
|
+
string: new Hash()
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
var _mapCacheClear = mapCacheClear$1;
|
|
1040
|
+
function isKeyable$1(value) {
|
|
1041
|
+
var type = typeof value;
|
|
1042
|
+
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
|
|
1043
|
+
}
|
|
1044
|
+
var _isKeyable = isKeyable$1, isKeyable = _isKeyable;
|
|
1045
|
+
function getMapData$4(map, key) {
|
|
1046
|
+
var data = map.__data__;
|
|
1047
|
+
return isKeyable(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
|
|
1048
|
+
}
|
|
1049
|
+
var _getMapData = getMapData$4, getMapData$3 = _getMapData;
|
|
1050
|
+
function mapCacheDelete$1(key) {
|
|
1051
|
+
var result = getMapData$3(this, key).delete(key);
|
|
1052
|
+
return this.size -= result ? 1 : 0, result;
|
|
1053
|
+
}
|
|
1054
|
+
var _mapCacheDelete = mapCacheDelete$1, getMapData$2 = _getMapData;
|
|
1055
|
+
function mapCacheGet$1(key) {
|
|
1056
|
+
return getMapData$2(this, key).get(key);
|
|
1057
|
+
}
|
|
1058
|
+
var _mapCacheGet = mapCacheGet$1, getMapData$1 = _getMapData;
|
|
1059
|
+
function mapCacheHas$1(key) {
|
|
1060
|
+
return getMapData$1(this, key).has(key);
|
|
1061
|
+
}
|
|
1062
|
+
var _mapCacheHas = mapCacheHas$1, getMapData = _getMapData;
|
|
1063
|
+
function mapCacheSet$1(key, value) {
|
|
1064
|
+
var data = getMapData(this, key), size = data.size;
|
|
1065
|
+
return data.set(key, value), this.size += data.size == size ? 0 : 1, this;
|
|
1066
|
+
}
|
|
1067
|
+
var _mapCacheSet = mapCacheSet$1, mapCacheClear = _mapCacheClear, mapCacheDelete = _mapCacheDelete, mapCacheGet = _mapCacheGet, mapCacheHas = _mapCacheHas, mapCacheSet = _mapCacheSet;
|
|
1068
|
+
function MapCache$2(entries) {
|
|
1069
|
+
var index = -1, length = entries == null ? 0 : entries.length;
|
|
1070
|
+
for (this.clear(); ++index < length; ) {
|
|
1071
|
+
var entry = entries[index];
|
|
1072
|
+
this.set(entry[0], entry[1]);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
MapCache$2.prototype.clear = mapCacheClear;
|
|
1076
|
+
MapCache$2.prototype.delete = mapCacheDelete;
|
|
1077
|
+
MapCache$2.prototype.get = mapCacheGet;
|
|
1078
|
+
MapCache$2.prototype.has = mapCacheHas;
|
|
1079
|
+
MapCache$2.prototype.set = mapCacheSet;
|
|
1080
|
+
var _MapCache = MapCache$2, ListCache$1 = _ListCache, Map$2 = _Map, MapCache$1 = _MapCache, LARGE_ARRAY_SIZE = 200;
|
|
1081
|
+
function stackSet$1(key, value) {
|
|
1082
|
+
var data = this.__data__;
|
|
1083
|
+
if (data instanceof ListCache$1) {
|
|
1084
|
+
var pairs = data.__data__;
|
|
1085
|
+
if (!Map$2 || pairs.length < LARGE_ARRAY_SIZE - 1)
|
|
1086
|
+
return pairs.push([key, value]), this.size = ++data.size, this;
|
|
1087
|
+
data = this.__data__ = new MapCache$1(pairs);
|
|
1088
|
+
}
|
|
1089
|
+
return data.set(key, value), this.size = data.size, this;
|
|
1090
|
+
}
|
|
1091
|
+
var _stackSet = stackSet$1, ListCache = _ListCache, stackClear = _stackClear, stackDelete = _stackDelete, stackGet = _stackGet, stackHas = _stackHas, stackSet = _stackSet;
|
|
1092
|
+
function Stack(entries) {
|
|
1093
|
+
var data = this.__data__ = new ListCache(entries);
|
|
1094
|
+
this.size = data.size;
|
|
1095
|
+
}
|
|
1096
|
+
Stack.prototype.clear = stackClear;
|
|
1097
|
+
Stack.prototype.delete = stackDelete;
|
|
1098
|
+
Stack.prototype.get = stackGet;
|
|
1099
|
+
Stack.prototype.has = stackHas;
|
|
1100
|
+
Stack.prototype.set = stackSet;
|
|
1101
|
+
var HASH_UNDEFINED = "__lodash_hash_undefined__";
|
|
1102
|
+
function setCacheAdd$1(value) {
|
|
1103
|
+
return this.__data__.set(value, HASH_UNDEFINED), this;
|
|
1104
|
+
}
|
|
1105
|
+
var _setCacheAdd = setCacheAdd$1;
|
|
1106
|
+
function setCacheHas$1(value) {
|
|
1107
|
+
return this.__data__.has(value);
|
|
1108
|
+
}
|
|
1109
|
+
var _setCacheHas = setCacheHas$1, MapCache = _MapCache, setCacheAdd = _setCacheAdd, setCacheHas = _setCacheHas;
|
|
1110
|
+
function SetCache(values) {
|
|
1111
|
+
var index = -1, length = values == null ? 0 : values.length;
|
|
1112
|
+
for (this.__data__ = new MapCache(); ++index < length; )
|
|
1113
|
+
this.add(values[index]);
|
|
1114
|
+
}
|
|
1115
|
+
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
|
|
1116
|
+
SetCache.prototype.has = setCacheHas;
|
|
1117
|
+
function arrayPush$1(array, values) {
|
|
1118
|
+
for (var index = -1, length = values.length, offset = array.length; ++index < length; )
|
|
1119
|
+
array[offset + index] = values[index];
|
|
1120
|
+
return array;
|
|
1121
|
+
}
|
|
1122
|
+
var _arrayPush = arrayPush$1, isArray$1 = Array.isArray, isArray_1 = isArray$1;
|
|
1123
|
+
function isObjectLike$3(value) {
|
|
1124
|
+
return value != null && typeof value == "object";
|
|
1125
|
+
}
|
|
1126
|
+
var isObjectLike_1 = isObjectLike$3, baseGetTag$2 = _baseGetTag, isObjectLike$2 = isObjectLike_1, argsTag = "[object Arguments]";
|
|
1127
|
+
function baseIsArguments$1(value) {
|
|
1128
|
+
return isObjectLike$2(value) && baseGetTag$2(value) == argsTag;
|
|
1129
|
+
}
|
|
1130
|
+
var _baseIsArguments = baseIsArguments$1, baseIsArguments = _baseIsArguments, isObjectLike$1 = isObjectLike_1, objectProto = Object.prototype, hasOwnProperty = objectProto.hasOwnProperty, propertyIsEnumerable = objectProto.propertyIsEnumerable, isArguments$1 = baseIsArguments(/* @__PURE__ */ function() {
|
|
1131
|
+
return arguments;
|
|
1132
|
+
}()) ? baseIsArguments : function(value) {
|
|
1133
|
+
return isObjectLike$1(value) && hasOwnProperty.call(value, "callee") && !propertyIsEnumerable.call(value, "callee");
|
|
1134
|
+
}, isArguments_1 = isArguments$1, isBuffer = { exports: {} };
|
|
1135
|
+
function stubFalse() {
|
|
1136
|
+
return !1;
|
|
1137
|
+
}
|
|
1138
|
+
var stubFalse_1 = stubFalse;
|
|
1139
|
+
(function(module, exports) {
|
|
1140
|
+
var root2 = _root, stubFalse2 = stubFalse_1, freeExports = exports && !exports.nodeType && exports, freeModule = freeExports && !0 && module && !module.nodeType && module, moduleExports = freeModule && freeModule.exports === freeExports, Buffer2 = moduleExports ? root2.Buffer : void 0, nativeIsBuffer = Buffer2 ? Buffer2.isBuffer : void 0, isBuffer2 = nativeIsBuffer || stubFalse2;
|
|
1141
|
+
module.exports = isBuffer2;
|
|
1142
|
+
})(isBuffer, isBuffer.exports);
|
|
1143
|
+
var _nodeUtil = { exports: {} };
|
|
1144
|
+
(function(module, exports) {
|
|
1145
|
+
var freeGlobal2 = _freeGlobal, freeExports = exports && !exports.nodeType && exports, freeModule = freeExports && !0 && module && !module.nodeType && module, moduleExports = freeModule && freeModule.exports === freeExports, freeProcess = moduleExports && freeGlobal2.process, nodeUtil = function() {
|
|
1146
|
+
try {
|
|
1147
|
+
var types = freeModule && freeModule.require && freeModule.require("util").types;
|
|
1148
|
+
return types || freeProcess && freeProcess.binding && freeProcess.binding("util");
|
|
1149
|
+
} catch (e) {
|
|
1150
|
+
}
|
|
1151
|
+
}();
|
|
1152
|
+
module.exports = nodeUtil;
|
|
1153
|
+
})(_nodeUtil, _nodeUtil.exports);
|
|
1154
|
+
var getNative$3 = _getNative, root$3 = _root, DataView$1 = getNative$3(root$3, "DataView"), _DataView = DataView$1, getNative$2 = _getNative, root$2 = _root, Promise$2 = getNative$2(root$2, "Promise"), _Promise = Promise$2, getNative$1 = _getNative, root$1 = _root, Set$2 = getNative$1(root$1, "Set"), _Set = Set$2, getNative = _getNative, root = _root, WeakMap$1 = getNative(root, "WeakMap"), _WeakMap = WeakMap$1, DataView = _DataView, Map$1 = _Map, Promise$1 = _Promise, Set$1 = _Set, WeakMap = _WeakMap, baseGetTag$1 = _baseGetTag, toSource = _toSource, mapTag = "[object Map]", objectTag = "[object Object]", promiseTag = "[object Promise]", setTag = "[object Set]", weakMapTag = "[object WeakMap]", dataViewTag = "[object DataView]", dataViewCtorString = toSource(DataView), mapCtorString = toSource(Map$1), promiseCtorString = toSource(Promise$1), setCtorString = toSource(Set$1), weakMapCtorString = toSource(WeakMap), getTag = baseGetTag$1;
|
|
1155
|
+
(DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag || Map$1 && getTag(new Map$1()) != mapTag || Promise$1 && getTag(Promise$1.resolve()) != promiseTag || Set$1 && getTag(new Set$1()) != setTag || WeakMap && getTag(new WeakMap()) != weakMapTag) && (getTag = function(value) {
|
|
1156
|
+
var result = baseGetTag$1(value), Ctor = result == objectTag ? value.constructor : void 0, ctorString = Ctor ? toSource(Ctor) : "";
|
|
1157
|
+
if (ctorString)
|
|
1158
|
+
switch (ctorString) {
|
|
1159
|
+
case dataViewCtorString:
|
|
1160
|
+
return dataViewTag;
|
|
1161
|
+
case mapCtorString:
|
|
1162
|
+
return mapTag;
|
|
1163
|
+
case promiseCtorString:
|
|
1164
|
+
return promiseTag;
|
|
1165
|
+
case setCtorString:
|
|
1166
|
+
return setTag;
|
|
1167
|
+
case weakMapCtorString:
|
|
1168
|
+
return weakMapTag;
|
|
1169
|
+
}
|
|
1170
|
+
return result;
|
|
1171
|
+
});
|
|
1172
|
+
var src = { exports: {} }, browser$1 = { exports: {} }, ms, hasRequiredMs;
|
|
1173
|
+
function requireMs() {
|
|
1174
|
+
if (hasRequiredMs)
|
|
1175
|
+
return ms;
|
|
1176
|
+
hasRequiredMs = 1;
|
|
1177
|
+
var s = 1e3, m = s * 60, h = m * 60, d = h * 24, w = d * 7, y = d * 365.25;
|
|
1178
|
+
ms = function(val, options) {
|
|
1179
|
+
options = options || {};
|
|
1180
|
+
var type = typeof val;
|
|
1181
|
+
if (type === "string" && val.length > 0)
|
|
1182
|
+
return parse2(val);
|
|
1183
|
+
if (type === "number" && isFinite(val))
|
|
1184
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
1187
|
+
);
|
|
1188
|
+
};
|
|
1189
|
+
function parse2(str) {
|
|
1190
|
+
if (str = String(str), !(str.length > 100)) {
|
|
1191
|
+
var match2 = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
1192
|
+
str
|
|
1193
|
+
);
|
|
1194
|
+
if (match2) {
|
|
1195
|
+
var n = parseFloat(match2[1]), type = (match2[2] || "ms").toLowerCase();
|
|
1196
|
+
switch (type) {
|
|
1197
|
+
case "years":
|
|
1198
|
+
case "year":
|
|
1199
|
+
case "yrs":
|
|
1200
|
+
case "yr":
|
|
1201
|
+
case "y":
|
|
1202
|
+
return n * y;
|
|
1203
|
+
case "weeks":
|
|
1204
|
+
case "week":
|
|
1205
|
+
case "w":
|
|
1206
|
+
return n * w;
|
|
1207
|
+
case "days":
|
|
1208
|
+
case "day":
|
|
1209
|
+
case "d":
|
|
1210
|
+
return n * d;
|
|
1211
|
+
case "hours":
|
|
1212
|
+
case "hour":
|
|
1213
|
+
case "hrs":
|
|
1214
|
+
case "hr":
|
|
1215
|
+
case "h":
|
|
1216
|
+
return n * h;
|
|
1217
|
+
case "minutes":
|
|
1218
|
+
case "minute":
|
|
1219
|
+
case "mins":
|
|
1220
|
+
case "min":
|
|
1221
|
+
case "m":
|
|
1222
|
+
return n * m;
|
|
1223
|
+
case "seconds":
|
|
1224
|
+
case "second":
|
|
1225
|
+
case "secs":
|
|
1226
|
+
case "sec":
|
|
1227
|
+
case "s":
|
|
1228
|
+
return n * s;
|
|
1229
|
+
case "milliseconds":
|
|
1230
|
+
case "millisecond":
|
|
1231
|
+
case "msecs":
|
|
1232
|
+
case "msec":
|
|
1233
|
+
case "ms":
|
|
1234
|
+
return n;
|
|
1235
|
+
default:
|
|
1236
|
+
return;
|
|
839
1237
|
}
|
|
840
1238
|
}
|
|
841
|
-
|
|
842
|
-
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
function fmtShort(ms2) {
|
|
1242
|
+
var msAbs = Math.abs(ms2);
|
|
1243
|
+
return msAbs >= d ? Math.round(ms2 / d) + "d" : msAbs >= h ? Math.round(ms2 / h) + "h" : msAbs >= m ? Math.round(ms2 / m) + "m" : msAbs >= s ? Math.round(ms2 / s) + "s" : ms2 + "ms";
|
|
1244
|
+
}
|
|
1245
|
+
function fmtLong(ms2) {
|
|
1246
|
+
var msAbs = Math.abs(ms2);
|
|
1247
|
+
return msAbs >= d ? plural(ms2, msAbs, d, "day") : msAbs >= h ? plural(ms2, msAbs, h, "hour") : msAbs >= m ? plural(ms2, msAbs, m, "minute") : msAbs >= s ? plural(ms2, msAbs, s, "second") : ms2 + " ms";
|
|
1248
|
+
}
|
|
1249
|
+
function plural(ms2, msAbs, n, name) {
|
|
1250
|
+
var isPlural = msAbs >= n * 1.5;
|
|
1251
|
+
return Math.round(ms2 / n) + " " + name + (isPlural ? "s" : "");
|
|
1252
|
+
}
|
|
1253
|
+
return ms;
|
|
843
1254
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
let
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
};
|
|
877
|
-
arrayPaths = [...arrayPaths, arrayMember, ...innerFields];
|
|
1255
|
+
var common, hasRequiredCommon;
|
|
1256
|
+
function requireCommon() {
|
|
1257
|
+
if (hasRequiredCommon)
|
|
1258
|
+
return common;
|
|
1259
|
+
hasRequiredCommon = 1;
|
|
1260
|
+
function setup(env) {
|
|
1261
|
+
createDebug.debug = createDebug, createDebug.default = createDebug, createDebug.coerce = coerce, createDebug.disable = disable, createDebug.enable = enable, createDebug.enabled = enabled, createDebug.humanize = requireMs(), createDebug.destroy = destroy, Object.keys(env).forEach((key) => {
|
|
1262
|
+
createDebug[key] = env[key];
|
|
1263
|
+
}), createDebug.names = [], createDebug.skips = [], createDebug.formatters = {};
|
|
1264
|
+
function selectColor(namespace) {
|
|
1265
|
+
let hash = 0;
|
|
1266
|
+
for (let i = 0; i < namespace.length; i++)
|
|
1267
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i), hash |= 0;
|
|
1268
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1269
|
+
}
|
|
1270
|
+
createDebug.selectColor = selectColor;
|
|
1271
|
+
function createDebug(namespace) {
|
|
1272
|
+
let prevTime, enableOverride = null, namespacesCache, enabledCache;
|
|
1273
|
+
function debug2(...args) {
|
|
1274
|
+
if (!debug2.enabled)
|
|
1275
|
+
return;
|
|
1276
|
+
const self2 = debug2, curr = Number(/* @__PURE__ */ new Date()), ms2 = curr - (prevTime || curr);
|
|
1277
|
+
self2.diff = ms2, self2.prev = prevTime, self2.curr = curr, prevTime = curr, args[0] = createDebug.coerce(args[0]), typeof args[0] != "string" && args.unshift("%O");
|
|
1278
|
+
let index = 0;
|
|
1279
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match2, format) => {
|
|
1280
|
+
if (match2 === "%%")
|
|
1281
|
+
return "%";
|
|
1282
|
+
index++;
|
|
1283
|
+
const formatter = createDebug.formatters[format];
|
|
1284
|
+
if (typeof formatter == "function") {
|
|
1285
|
+
const val = args[index];
|
|
1286
|
+
match2 = formatter.call(self2, val), args.splice(index, 1), index--;
|
|
878
1287
|
}
|
|
1288
|
+
return match2;
|
|
1289
|
+
}), createDebug.formatArgs.call(self2, args), (self2.log || createDebug.log).apply(self2, args);
|
|
1290
|
+
}
|
|
1291
|
+
return debug2.namespace = namespace, debug2.useColors = createDebug.useColors(), debug2.color = createDebug.selectColor(namespace), debug2.extend = extend, debug2.destroy = createDebug.destroy, Object.defineProperty(debug2, "enabled", {
|
|
1292
|
+
enumerable: !0,
|
|
1293
|
+
configurable: !1,
|
|
1294
|
+
get: () => enableOverride !== null ? enableOverride : (namespacesCache !== createDebug.namespaces && (namespacesCache = createDebug.namespaces, enabledCache = createDebug.enabled(namespace)), enabledCache),
|
|
1295
|
+
set: (v) => {
|
|
1296
|
+
enableOverride = v;
|
|
879
1297
|
}
|
|
880
|
-
|
|
1298
|
+
}), typeof createDebug.init == "function" && createDebug.init(debug2), debug2;
|
|
881
1299
|
}
|
|
882
|
-
|
|
883
|
-
|
|
1300
|
+
function extend(namespace, delimiter) {
|
|
1301
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter > "u" ? ":" : delimiter) + namespace);
|
|
1302
|
+
return newDebug.log = this.log, newDebug;
|
|
1303
|
+
}
|
|
1304
|
+
function enable(namespaces) {
|
|
1305
|
+
createDebug.save(namespaces), createDebug.namespaces = namespaces, createDebug.names = [], createDebug.skips = [];
|
|
1306
|
+
const split = (typeof namespaces == "string" ? namespaces : "").trim().replace(" ", ",").split(",").filter(Boolean);
|
|
1307
|
+
for (const ns of split)
|
|
1308
|
+
ns[0] === "-" ? createDebug.skips.push(ns.slice(1)) : createDebug.names.push(ns);
|
|
1309
|
+
}
|
|
1310
|
+
function matchesTemplate(search, template) {
|
|
1311
|
+
let searchIndex = 0, templateIndex = 0, starIndex = -1, matchIndex = 0;
|
|
1312
|
+
for (; searchIndex < search.length; )
|
|
1313
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*"))
|
|
1314
|
+
template[templateIndex] === "*" ? (starIndex = templateIndex, matchIndex = searchIndex, templateIndex++) : (searchIndex++, templateIndex++);
|
|
1315
|
+
else if (starIndex !== -1)
|
|
1316
|
+
templateIndex = starIndex + 1, matchIndex++, searchIndex = matchIndex;
|
|
1317
|
+
else
|
|
1318
|
+
return !1;
|
|
1319
|
+
for (; templateIndex < template.length && template[templateIndex] === "*"; )
|
|
1320
|
+
templateIndex++;
|
|
1321
|
+
return templateIndex === template.length;
|
|
1322
|
+
}
|
|
1323
|
+
function disable() {
|
|
1324
|
+
const namespaces = [
|
|
1325
|
+
...createDebug.names,
|
|
1326
|
+
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
1327
|
+
].join(",");
|
|
1328
|
+
return createDebug.enable(""), namespaces;
|
|
1329
|
+
}
|
|
1330
|
+
function enabled(name) {
|
|
1331
|
+
for (const skip of createDebug.skips)
|
|
1332
|
+
if (matchesTemplate(name, skip))
|
|
1333
|
+
return !1;
|
|
1334
|
+
for (const ns of createDebug.names)
|
|
1335
|
+
if (matchesTemplate(name, ns))
|
|
1336
|
+
return !0;
|
|
1337
|
+
return !1;
|
|
1338
|
+
}
|
|
1339
|
+
function coerce(val) {
|
|
1340
|
+
return val instanceof Error ? val.stack || val.message : val;
|
|
1341
|
+
}
|
|
1342
|
+
function destroy() {
|
|
1343
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
1344
|
+
}
|
|
1345
|
+
return createDebug.enable(createDebug.load()), createDebug;
|
|
1346
|
+
}
|
|
1347
|
+
return common = setup, common;
|
|
884
1348
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1349
|
+
var hasRequiredBrowser$1;
|
|
1350
|
+
function requireBrowser$1() {
|
|
1351
|
+
return hasRequiredBrowser$1 || (hasRequiredBrowser$1 = 1, function(module, exports) {
|
|
1352
|
+
exports.formatArgs = formatArgs, exports.save = save, exports.load = load, exports.useColors = useColors, exports.storage = localstorage(), exports.destroy = /* @__PURE__ */ (() => {
|
|
1353
|
+
let warned = !1;
|
|
1354
|
+
return () => {
|
|
1355
|
+
warned || (warned = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));
|
|
1356
|
+
};
|
|
1357
|
+
})(), exports.colors = [
|
|
1358
|
+
"#0000CC",
|
|
1359
|
+
"#0000FF",
|
|
1360
|
+
"#0033CC",
|
|
1361
|
+
"#0033FF",
|
|
1362
|
+
"#0066CC",
|
|
1363
|
+
"#0066FF",
|
|
1364
|
+
"#0099CC",
|
|
1365
|
+
"#0099FF",
|
|
1366
|
+
"#00CC00",
|
|
1367
|
+
"#00CC33",
|
|
1368
|
+
"#00CC66",
|
|
1369
|
+
"#00CC99",
|
|
1370
|
+
"#00CCCC",
|
|
1371
|
+
"#00CCFF",
|
|
1372
|
+
"#3300CC",
|
|
1373
|
+
"#3300FF",
|
|
1374
|
+
"#3333CC",
|
|
1375
|
+
"#3333FF",
|
|
1376
|
+
"#3366CC",
|
|
1377
|
+
"#3366FF",
|
|
1378
|
+
"#3399CC",
|
|
1379
|
+
"#3399FF",
|
|
1380
|
+
"#33CC00",
|
|
1381
|
+
"#33CC33",
|
|
1382
|
+
"#33CC66",
|
|
1383
|
+
"#33CC99",
|
|
1384
|
+
"#33CCCC",
|
|
1385
|
+
"#33CCFF",
|
|
1386
|
+
"#6600CC",
|
|
1387
|
+
"#6600FF",
|
|
1388
|
+
"#6633CC",
|
|
1389
|
+
"#6633FF",
|
|
1390
|
+
"#66CC00",
|
|
1391
|
+
"#66CC33",
|
|
1392
|
+
"#9900CC",
|
|
1393
|
+
"#9900FF",
|
|
1394
|
+
"#9933CC",
|
|
1395
|
+
"#9933FF",
|
|
1396
|
+
"#99CC00",
|
|
1397
|
+
"#99CC33",
|
|
1398
|
+
"#CC0000",
|
|
1399
|
+
"#CC0033",
|
|
1400
|
+
"#CC0066",
|
|
1401
|
+
"#CC0099",
|
|
1402
|
+
"#CC00CC",
|
|
1403
|
+
"#CC00FF",
|
|
1404
|
+
"#CC3300",
|
|
1405
|
+
"#CC3333",
|
|
1406
|
+
"#CC3366",
|
|
1407
|
+
"#CC3399",
|
|
1408
|
+
"#CC33CC",
|
|
1409
|
+
"#CC33FF",
|
|
1410
|
+
"#CC6600",
|
|
1411
|
+
"#CC6633",
|
|
1412
|
+
"#CC9900",
|
|
1413
|
+
"#CC9933",
|
|
1414
|
+
"#CCCC00",
|
|
1415
|
+
"#CCCC33",
|
|
1416
|
+
"#FF0000",
|
|
1417
|
+
"#FF0033",
|
|
1418
|
+
"#FF0066",
|
|
1419
|
+
"#FF0099",
|
|
1420
|
+
"#FF00CC",
|
|
1421
|
+
"#FF00FF",
|
|
1422
|
+
"#FF3300",
|
|
1423
|
+
"#FF3333",
|
|
1424
|
+
"#FF3366",
|
|
1425
|
+
"#FF3399",
|
|
1426
|
+
"#FF33CC",
|
|
1427
|
+
"#FF33FF",
|
|
1428
|
+
"#FF6600",
|
|
1429
|
+
"#FF6633",
|
|
1430
|
+
"#FF9900",
|
|
1431
|
+
"#FF9933",
|
|
1432
|
+
"#FFCC00",
|
|
1433
|
+
"#FFCC33"
|
|
1434
|
+
];
|
|
1435
|
+
function useColors() {
|
|
1436
|
+
if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs))
|
|
1437
|
+
return !0;
|
|
1438
|
+
if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))
|
|
1439
|
+
return !1;
|
|
1440
|
+
let m;
|
|
1441
|
+
return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
1442
|
+
typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
1443
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
1444
|
+
typeof navigator < "u" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
1445
|
+
typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
1446
|
+
}
|
|
1447
|
+
function formatArgs(args) {
|
|
1448
|
+
if (args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff), !this.useColors)
|
|
1449
|
+
return;
|
|
1450
|
+
const c = "color: " + this.color;
|
|
1451
|
+
args.splice(1, 0, c, "color: inherit");
|
|
1452
|
+
let index = 0, lastC = 0;
|
|
1453
|
+
args[0].replace(/%[a-zA-Z%]/g, (match2) => {
|
|
1454
|
+
match2 !== "%%" && (index++, match2 === "%c" && (lastC = index));
|
|
1455
|
+
}), args.splice(lastC, 0, c);
|
|
1456
|
+
}
|
|
1457
|
+
exports.log = console.debug || console.log || (() => {
|
|
1458
|
+
});
|
|
1459
|
+
function save(namespaces) {
|
|
1460
|
+
try {
|
|
1461
|
+
namespaces ? exports.storage.setItem("debug", namespaces) : exports.storage.removeItem("debug");
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
function load() {
|
|
1466
|
+
let r;
|
|
1467
|
+
try {
|
|
1468
|
+
r = exports.storage.getItem("debug");
|
|
1469
|
+
} catch (error) {
|
|
1470
|
+
}
|
|
1471
|
+
return !r && typeof process < "u" && "env" in process && (r = process.env.DEBUG), r;
|
|
1472
|
+
}
|
|
1473
|
+
function localstorage() {
|
|
1474
|
+
try {
|
|
1475
|
+
return localStorage;
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
module.exports = requireCommon()(exports);
|
|
1480
|
+
const { formatters } = module.exports;
|
|
1481
|
+
formatters.j = function(v) {
|
|
1482
|
+
try {
|
|
1483
|
+
return JSON.stringify(v);
|
|
1484
|
+
} catch (error) {
|
|
1485
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
1486
|
+
}
|
|
914
1487
|
};
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1488
|
+
}(browser$1, browser$1.exports)), browser$1.exports;
|
|
1489
|
+
}
|
|
1490
|
+
var node = { exports: {} }, browser, hasRequiredBrowser;
|
|
1491
|
+
function requireBrowser() {
|
|
1492
|
+
if (hasRequiredBrowser)
|
|
1493
|
+
return browser;
|
|
1494
|
+
hasRequiredBrowser = 1;
|
|
1495
|
+
function getChromeVersion() {
|
|
1496
|
+
const matches = new RegExp("(Chrome|Chromium)\\/(?<chromeVersion>\\d+)\\.").exec(navigator.userAgent);
|
|
1497
|
+
if (matches)
|
|
1498
|
+
return Number.parseInt(matches.groups.chromeVersion, 10);
|
|
1499
|
+
}
|
|
1500
|
+
const colorSupport = getChromeVersion() >= 69 ? {
|
|
1501
|
+
level: 1,
|
|
1502
|
+
hasBasic: !0,
|
|
1503
|
+
has256: !1,
|
|
1504
|
+
has16m: !1
|
|
1505
|
+
} : !1;
|
|
1506
|
+
return browser = {
|
|
1507
|
+
stdout: colorSupport,
|
|
1508
|
+
stderr: colorSupport
|
|
1509
|
+
}, browser;
|
|
1510
|
+
}
|
|
1511
|
+
var hasRequiredNode;
|
|
1512
|
+
function requireNode() {
|
|
1513
|
+
return hasRequiredNode || (hasRequiredNode = 1, function(module, exports) {
|
|
1514
|
+
const tty = require$$0, util = require$$1;
|
|
1515
|
+
exports.init = init, exports.log = log, exports.formatArgs = formatArgs, exports.save = save, exports.load = load, exports.useColors = useColors, exports.destroy = util.deprecate(
|
|
1516
|
+
() => {
|
|
1517
|
+
},
|
|
1518
|
+
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
1519
|
+
), exports.colors = [6, 2, 3, 4, 5, 1];
|
|
1520
|
+
try {
|
|
1521
|
+
const supportsColor = requireBrowser();
|
|
1522
|
+
supportsColor && (supportsColor.stderr || supportsColor).level >= 2 && (exports.colors = [
|
|
1523
|
+
20,
|
|
1524
|
+
21,
|
|
1525
|
+
26,
|
|
1526
|
+
27,
|
|
1527
|
+
32,
|
|
1528
|
+
33,
|
|
1529
|
+
38,
|
|
1530
|
+
39,
|
|
1531
|
+
40,
|
|
1532
|
+
41,
|
|
1533
|
+
42,
|
|
1534
|
+
43,
|
|
1535
|
+
44,
|
|
1536
|
+
45,
|
|
1537
|
+
56,
|
|
1538
|
+
57,
|
|
1539
|
+
62,
|
|
1540
|
+
63,
|
|
1541
|
+
68,
|
|
1542
|
+
69,
|
|
1543
|
+
74,
|
|
1544
|
+
75,
|
|
1545
|
+
76,
|
|
1546
|
+
77,
|
|
1547
|
+
78,
|
|
1548
|
+
79,
|
|
1549
|
+
80,
|
|
1550
|
+
81,
|
|
1551
|
+
92,
|
|
1552
|
+
93,
|
|
1553
|
+
98,
|
|
1554
|
+
99,
|
|
1555
|
+
112,
|
|
1556
|
+
113,
|
|
1557
|
+
128,
|
|
1558
|
+
129,
|
|
1559
|
+
134,
|
|
1560
|
+
135,
|
|
1561
|
+
148,
|
|
1562
|
+
149,
|
|
1563
|
+
160,
|
|
1564
|
+
161,
|
|
1565
|
+
162,
|
|
1566
|
+
163,
|
|
1567
|
+
164,
|
|
1568
|
+
165,
|
|
1569
|
+
166,
|
|
1570
|
+
167,
|
|
1571
|
+
168,
|
|
1572
|
+
169,
|
|
1573
|
+
170,
|
|
1574
|
+
171,
|
|
1575
|
+
172,
|
|
1576
|
+
173,
|
|
1577
|
+
178,
|
|
1578
|
+
179,
|
|
1579
|
+
184,
|
|
1580
|
+
185,
|
|
1581
|
+
196,
|
|
1582
|
+
197,
|
|
1583
|
+
198,
|
|
1584
|
+
199,
|
|
1585
|
+
200,
|
|
1586
|
+
201,
|
|
1587
|
+
202,
|
|
1588
|
+
203,
|
|
1589
|
+
204,
|
|
1590
|
+
205,
|
|
1591
|
+
206,
|
|
1592
|
+
207,
|
|
1593
|
+
208,
|
|
1594
|
+
209,
|
|
1595
|
+
214,
|
|
1596
|
+
215,
|
|
1597
|
+
220,
|
|
1598
|
+
221
|
|
1599
|
+
]);
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
}
|
|
1602
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => /^debug_/i.test(key)).reduce((obj, key) => {
|
|
1603
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => k.toUpperCase());
|
|
1604
|
+
let val = process.env[key];
|
|
1605
|
+
return /^(yes|on|true|enabled)$/i.test(val) ? val = !0 : /^(no|off|false|disabled)$/i.test(val) ? val = !1 : val === "null" ? val = null : val = Number(val), obj[prop] = val, obj;
|
|
1606
|
+
}, {});
|
|
1607
|
+
function useColors() {
|
|
1608
|
+
return "colors" in exports.inspectOpts ? !!exports.inspectOpts.colors : tty.isatty(process.stderr.fd);
|
|
1609
|
+
}
|
|
1610
|
+
function formatArgs(args) {
|
|
1611
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
1612
|
+
if (useColors2) {
|
|
1613
|
+
const c = this.color, colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c), prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
1614
|
+
args[0] = prefix + args[0].split(`
|
|
1615
|
+
`).join(`
|
|
1616
|
+
` + prefix), args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
1617
|
+
} else
|
|
1618
|
+
args[0] = getDate() + name + " " + args[0];
|
|
1619
|
+
}
|
|
1620
|
+
function getDate() {
|
|
1621
|
+
return exports.inspectOpts.hideDate ? "" : (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
1622
|
+
}
|
|
1623
|
+
function log(...args) {
|
|
1624
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + `
|
|
1625
|
+
`);
|
|
1626
|
+
}
|
|
1627
|
+
function save(namespaces) {
|
|
1628
|
+
namespaces ? process.env.DEBUG = namespaces : delete process.env.DEBUG;
|
|
1629
|
+
}
|
|
1630
|
+
function load() {
|
|
1631
|
+
return process.env.DEBUG;
|
|
1632
|
+
}
|
|
1633
|
+
function init(debug2) {
|
|
1634
|
+
debug2.inspectOpts = {};
|
|
1635
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
1636
|
+
for (let i = 0; i < keys.length; i++)
|
|
1637
|
+
debug2.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
1638
|
+
}
|
|
1639
|
+
module.exports = requireCommon()(exports);
|
|
1640
|
+
const { formatters } = module.exports;
|
|
1641
|
+
formatters.o = function(v) {
|
|
1642
|
+
return this.inspectOpts.colors = this.useColors, util.inspect(v, this.inspectOpts).split(`
|
|
1643
|
+
`).map((str) => str.trim()).join(" ");
|
|
1644
|
+
}, formatters.O = function(v) {
|
|
1645
|
+
return this.inspectOpts.colors = this.useColors, util.inspect(v, this.inspectOpts);
|
|
934
1646
|
};
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1647
|
+
}(node, node.exports)), node.exports;
|
|
1648
|
+
}
|
|
1649
|
+
typeof process > "u" || process.type === "renderer" || process.browser === !0 || process.__nwjs ? src.exports = requireBrowser$1() : src.exports = requireNode();
|
|
1650
|
+
var srcExports = src.exports, debugIt = /* @__PURE__ */ getDefaultExportFromCjs(srcExports), Symbol$1 = _Symbol, isArguments = isArguments_1, isArray = isArray_1, spreadableSymbol = Symbol$1 ? Symbol$1.isConcatSpreadable : void 0;
|
|
1651
|
+
function isFlattenable$1(value) {
|
|
1652
|
+
return isArray(value) || isArguments(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
|
|
1653
|
+
}
|
|
1654
|
+
var _isFlattenable = isFlattenable$1, arrayPush = _arrayPush, isFlattenable = _isFlattenable;
|
|
1655
|
+
function baseFlatten$1(array, depth, predicate, isStrict, result) {
|
|
1656
|
+
var index = -1, length = array.length;
|
|
1657
|
+
for (predicate || (predicate = isFlattenable), result || (result = []); ++index < length; ) {
|
|
1658
|
+
var value = array[index];
|
|
1659
|
+
depth > 0 && predicate(value) ? depth > 1 ? baseFlatten$1(value, depth - 1, predicate, isStrict, result) : arrayPush(result, value) : isStrict || (result[result.length] = value);
|
|
1660
|
+
}
|
|
1661
|
+
return result;
|
|
1662
|
+
}
|
|
1663
|
+
var _baseFlatten = baseFlatten$1, baseFlatten = _baseFlatten;
|
|
1664
|
+
function flatten(array) {
|
|
1665
|
+
var length = array == null ? 0 : array.length;
|
|
1666
|
+
return length ? baseFlatten(array, 1) : [];
|
|
1667
|
+
}
|
|
1668
|
+
var flatten_1 = flatten, flatten$1 = /* @__PURE__ */ getDefaultExportFromCjs(flatten_1);
|
|
1669
|
+
function isHighSurrogate(char) {
|
|
1670
|
+
const charCode = char.charCodeAt(0);
|
|
1671
|
+
return charCode >= 55296 && charCode <= 56319;
|
|
1672
|
+
}
|
|
1673
|
+
function isLowSurrogate(char) {
|
|
1674
|
+
const charCode = char.charCodeAt(0);
|
|
1675
|
+
return charCode >= 56320 && charCode <= 57343;
|
|
1676
|
+
}
|
|
1677
|
+
function cloneDiff(diff2) {
|
|
1678
|
+
const [type, patch] = diff2;
|
|
1679
|
+
return [type, patch];
|
|
1680
|
+
}
|
|
1681
|
+
function getCommonOverlap(textA, textB) {
|
|
1682
|
+
let text1 = textA, text2 = textB;
|
|
1683
|
+
const text1Length = text1.length, text2Length = text2.length;
|
|
1684
|
+
if (text1Length === 0 || text2Length === 0)
|
|
1685
|
+
return 0;
|
|
1686
|
+
text1Length > text2Length ? text1 = text1.substring(text1Length - text2Length) : text1Length < text2Length && (text2 = text2.substring(0, text1Length));
|
|
1687
|
+
const textLength = Math.min(text1Length, text2Length);
|
|
1688
|
+
if (text1 === text2)
|
|
1689
|
+
return textLength;
|
|
1690
|
+
let best = 0, length = 1;
|
|
1691
|
+
for (let found = 0; found !== -1; ) {
|
|
1692
|
+
const pattern = text1.substring(textLength - length);
|
|
1693
|
+
if (found = text2.indexOf(pattern), found === -1)
|
|
1694
|
+
return best;
|
|
1695
|
+
length += found, (found === 0 || text1.substring(textLength - length) === text2.substring(0, length)) && (best = length, length++);
|
|
1696
|
+
}
|
|
1697
|
+
return best;
|
|
1698
|
+
}
|
|
1699
|
+
function getCommonPrefix(text1, text2) {
|
|
1700
|
+
if (!text1 || !text2 || text1[0] !== text2[0])
|
|
1701
|
+
return 0;
|
|
1702
|
+
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerStart = 0;
|
|
1703
|
+
for (; pointerMin < pointerMid; )
|
|
1704
|
+
text1.substring(pointerStart, pointerMid) === text2.substring(pointerStart, pointerMid) ? (pointerMin = pointerMid, pointerStart = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1705
|
+
return pointerMid;
|
|
1706
|
+
}
|
|
1707
|
+
function getCommonSuffix(text1, text2) {
|
|
1708
|
+
if (!text1 || !text2 || text1[text1.length - 1] !== text2[text2.length - 1])
|
|
1709
|
+
return 0;
|
|
1710
|
+
let pointerMin = 0, pointerMax = Math.min(text1.length, text2.length), pointerMid = pointerMax, pointerEnd = 0;
|
|
1711
|
+
for (; pointerMin < pointerMid; )
|
|
1712
|
+
text1.substring(text1.length - pointerMid, text1.length - pointerEnd) === text2.substring(text2.length - pointerMid, text2.length - pointerEnd) ? (pointerMin = pointerMid, pointerEnd = pointerMin) : pointerMax = pointerMid, pointerMid = Math.floor((pointerMax - pointerMin) / 2 + pointerMin);
|
|
1713
|
+
return pointerMid;
|
|
1714
|
+
}
|
|
1715
|
+
function cleanupSemantic(rawDiffs) {
|
|
1716
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2)), hasChanges = !1;
|
|
1717
|
+
const equalities = [];
|
|
1718
|
+
let equalitiesLength = 0, lastEquality = null, pointer = 0, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0;
|
|
1719
|
+
for (; pointer < diffs.length; )
|
|
1720
|
+
diffs[pointer][0] === DIFF_EQUAL ? (equalities[equalitiesLength++] = pointer, lengthInsertions1 = lengthInsertions2, lengthDeletions1 = lengthDeletions2, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = diffs[pointer][1]) : (diffs[pointer][0] === DIFF_INSERT ? lengthInsertions2 += diffs[pointer][1].length : lengthDeletions2 += diffs[pointer][1].length, lastEquality && lastEquality.length <= Math.max(lengthInsertions1, lengthDeletions1) && lastEquality.length <= Math.max(lengthInsertions2, lengthDeletions2) && (diffs.splice(equalities[equalitiesLength - 1], 0, [DIFF_DELETE, lastEquality]), diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT, equalitiesLength--, equalitiesLength--, pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1, lengthInsertions1 = 0, lengthDeletions1 = 0, lengthInsertions2 = 0, lengthDeletions2 = 0, lastEquality = null, hasChanges = !0)), pointer++;
|
|
1721
|
+
for (hasChanges && (diffs = cleanupMerge(diffs)), diffs = cleanupSemanticLossless(diffs), pointer = 1; pointer < diffs.length; ) {
|
|
1722
|
+
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
1723
|
+
const deletion = diffs[pointer - 1][1], insertion = diffs[pointer][1], overlapLength1 = getCommonOverlap(deletion, insertion), overlapLength2 = getCommonOverlap(insertion, deletion);
|
|
1724
|
+
overlapLength1 >= overlapLength2 ? (overlapLength1 >= deletion.length / 2 || overlapLength1 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, insertion.substring(0, overlapLength1)]), diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlapLength1), diffs[pointer + 1][1] = insertion.substring(overlapLength1), pointer++) : (overlapLength2 >= deletion.length / 2 || overlapLength2 >= insertion.length / 2) && (diffs.splice(pointer, 0, [DIFF_EQUAL, deletion.substring(0, overlapLength2)]), diffs[pointer - 1][0] = DIFF_INSERT, diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlapLength2), diffs[pointer + 1][0] = DIFF_DELETE, diffs[pointer + 1][1] = deletion.substring(overlapLength2), pointer++), pointer++;
|
|
1725
|
+
}
|
|
1726
|
+
pointer++;
|
|
1727
|
+
}
|
|
1728
|
+
return diffs;
|
|
1729
|
+
}
|
|
1730
|
+
const nonAlphaNumericRegex = /[^a-zA-Z0-9]/, whitespaceRegex = /\s/, linebreakRegex = /[\r\n]/, blanklineEndRegex = /\n\r?\n$/, blanklineStartRegex = /^\r?\n\r?\n/;
|
|
1731
|
+
function cleanupSemanticLossless(rawDiffs) {
|
|
1732
|
+
const diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1733
|
+
function diffCleanupSemanticScore(one, two) {
|
|
1734
|
+
if (!one || !two)
|
|
1735
|
+
return 6;
|
|
1736
|
+
const char1 = one.charAt(one.length - 1), char2 = two.charAt(0), nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex), nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex), whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex), whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex), lineBreak1 = whitespace1 && char1.match(linebreakRegex), lineBreak2 = whitespace2 && char2.match(linebreakRegex), blankLine1 = lineBreak1 && one.match(blanklineEndRegex), blankLine2 = lineBreak2 && two.match(blanklineStartRegex);
|
|
1737
|
+
return blankLine1 || blankLine2 ? 5 : lineBreak1 || lineBreak2 ? 4 : nonAlphaNumeric1 && !whitespace1 && whitespace2 ? 3 : whitespace1 || whitespace2 ? 2 : nonAlphaNumeric1 || nonAlphaNumeric2 ? 1 : 0;
|
|
1738
|
+
}
|
|
1739
|
+
let pointer = 1;
|
|
1740
|
+
for (; pointer < diffs.length - 1; ) {
|
|
1741
|
+
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
1742
|
+
let equality1 = diffs[pointer - 1][1], edit = diffs[pointer][1], equality2 = diffs[pointer + 1][1];
|
|
1743
|
+
const commonOffset = getCommonSuffix(equality1, edit);
|
|
1744
|
+
if (commonOffset) {
|
|
1745
|
+
const commonString = edit.substring(edit.length - commonOffset);
|
|
1746
|
+
equality1 = equality1.substring(0, equality1.length - commonOffset), edit = commonString + edit.substring(0, edit.length - commonOffset), equality2 = commonString + equality2;
|
|
1747
|
+
}
|
|
1748
|
+
let bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2, bestScore = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1749
|
+
for (; edit.charAt(0) === equality2.charAt(0); ) {
|
|
1750
|
+
equality1 += edit.charAt(0), edit = edit.substring(1) + equality2.charAt(0), equality2 = equality2.substring(1);
|
|
1751
|
+
const score = diffCleanupSemanticScore(equality1, edit) + diffCleanupSemanticScore(edit, equality2);
|
|
1752
|
+
score >= bestScore && (bestScore = score, bestEquality1 = equality1, bestEdit = edit, bestEquality2 = equality2);
|
|
1753
|
+
}
|
|
1754
|
+
diffs[pointer - 1][1] !== bestEquality1 && (bestEquality1 ? diffs[pointer - 1][1] = bestEquality1 : (diffs.splice(pointer - 1, 1), pointer--), diffs[pointer][1] = bestEdit, bestEquality2 ? diffs[pointer + 1][1] = bestEquality2 : (diffs.splice(pointer + 1, 1), pointer--));
|
|
1755
|
+
}
|
|
1756
|
+
pointer++;
|
|
1757
|
+
}
|
|
1758
|
+
return diffs;
|
|
1759
|
+
}
|
|
1760
|
+
function cleanupMerge(rawDiffs) {
|
|
1761
|
+
let diffs = rawDiffs.map((diff2) => cloneDiff(diff2));
|
|
1762
|
+
diffs.push([DIFF_EQUAL, ""]);
|
|
1763
|
+
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "", commonlength;
|
|
1764
|
+
for (; pointer < diffs.length; )
|
|
1765
|
+
switch (diffs[pointer][0]) {
|
|
1766
|
+
case DIFF_INSERT:
|
|
1767
|
+
countInsert++, textInsert += diffs[pointer][1], pointer++;
|
|
1768
|
+
break;
|
|
1769
|
+
case DIFF_DELETE:
|
|
1770
|
+
countDelete++, textDelete += diffs[pointer][1], pointer++;
|
|
1771
|
+
break;
|
|
1772
|
+
case DIFF_EQUAL:
|
|
1773
|
+
countDelete + countInsert > 1 ? (countDelete !== 0 && countInsert !== 0 && (commonlength = getCommonPrefix(textInsert, textDelete), commonlength !== 0 && (pointer - countDelete - countInsert > 0 && diffs[pointer - countDelete - countInsert - 1][0] === DIFF_EQUAL ? diffs[pointer - countDelete - countInsert - 1][1] += textInsert.substring(0, commonlength) : (diffs.splice(0, 0, [DIFF_EQUAL, textInsert.substring(0, commonlength)]), pointer++), textInsert = textInsert.substring(commonlength), textDelete = textDelete.substring(commonlength)), commonlength = getCommonSuffix(textInsert, textDelete), commonlength !== 0 && (diffs[pointer][1] = textInsert.substring(textInsert.length - commonlength) + diffs[pointer][1], textInsert = textInsert.substring(0, textInsert.length - commonlength), textDelete = textDelete.substring(0, textDelete.length - commonlength))), pointer -= countDelete + countInsert, diffs.splice(pointer, countDelete + countInsert), textDelete.length && (diffs.splice(pointer, 0, [DIFF_DELETE, textDelete]), pointer++), textInsert.length && (diffs.splice(pointer, 0, [DIFF_INSERT, textInsert]), pointer++), pointer++) : pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL ? (diffs[pointer - 1][1] += diffs[pointer][1], diffs.splice(pointer, 1)) : pointer++, countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
1774
|
+
break;
|
|
1775
|
+
default:
|
|
1776
|
+
throw new Error("Unknown diff operation");
|
|
1777
|
+
}
|
|
1778
|
+
diffs[diffs.length - 1][1] === "" && diffs.pop();
|
|
1779
|
+
let hasChanges = !1;
|
|
1780
|
+
for (pointer = 1; pointer < diffs.length - 1; )
|
|
1781
|
+
diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL && (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1] ? (diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length), diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1], diffs.splice(pointer - 1, 1), hasChanges = !0) : diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1] && (diffs[pointer - 1][1] += diffs[pointer + 1][1], diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1], diffs.splice(pointer + 1, 1), hasChanges = !0)), pointer++;
|
|
1782
|
+
return hasChanges && (diffs = cleanupMerge(diffs)), diffs;
|
|
1783
|
+
}
|
|
1784
|
+
function bisect(text1, text2, deadline) {
|
|
1785
|
+
const text1Length = text1.length, text2Length = text2.length, maxD = Math.ceil((text1Length + text2Length) / 2), vOffset = maxD, vLength = 2 * maxD, v1 = new Array(vLength), v2 = new Array(vLength);
|
|
1786
|
+
for (let x = 0; x < vLength; x++)
|
|
1787
|
+
v1[x] = -1, v2[x] = -1;
|
|
1788
|
+
v1[vOffset + 1] = 0, v2[vOffset + 1] = 0;
|
|
1789
|
+
const delta = text1Length - text2Length, front = delta % 2 !== 0;
|
|
1790
|
+
let k1start = 0, k1end = 0, k2start = 0, k2end = 0;
|
|
1791
|
+
for (let d = 0; d < maxD && !(Date.now() > deadline); d++) {
|
|
1792
|
+
for (let k1 = -d + k1start; k1 <= d - k1end; k1 += 2) {
|
|
1793
|
+
const k1Offset = vOffset + k1;
|
|
1794
|
+
let x1;
|
|
1795
|
+
k1 === -d || k1 !== d && v1[k1Offset - 1] < v1[k1Offset + 1] ? x1 = v1[k1Offset + 1] : x1 = v1[k1Offset - 1] + 1;
|
|
1796
|
+
let y1 = x1 - k1;
|
|
1797
|
+
for (; x1 < text1Length && y1 < text2Length && text1.charAt(x1) === text2.charAt(y1); )
|
|
1798
|
+
x1++, y1++;
|
|
1799
|
+
if (v1[k1Offset] = x1, x1 > text1Length)
|
|
1800
|
+
k1end += 2;
|
|
1801
|
+
else if (y1 > text2Length)
|
|
1802
|
+
k1start += 2;
|
|
1803
|
+
else if (front) {
|
|
1804
|
+
const k2Offset = vOffset + delta - k1;
|
|
1805
|
+
if (k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] !== -1) {
|
|
1806
|
+
const x2 = text1Length - v2[k2Offset];
|
|
1807
|
+
if (x1 >= x2)
|
|
1808
|
+
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
for (let k2 = -d + k2start; k2 <= d - k2end; k2 += 2) {
|
|
1813
|
+
const k2Offset = vOffset + k2;
|
|
1814
|
+
let x2;
|
|
1815
|
+
k2 === -d || k2 !== d && v2[k2Offset - 1] < v2[k2Offset + 1] ? x2 = v2[k2Offset + 1] : x2 = v2[k2Offset - 1] + 1;
|
|
1816
|
+
let y2 = x2 - k2;
|
|
1817
|
+
for (; x2 < text1Length && y2 < text2Length && text1.charAt(text1Length - x2 - 1) === text2.charAt(text2Length - y2 - 1); )
|
|
1818
|
+
x2++, y2++;
|
|
1819
|
+
if (v2[k2Offset] = x2, x2 > text1Length)
|
|
1820
|
+
k2end += 2;
|
|
1821
|
+
else if (y2 > text2Length)
|
|
1822
|
+
k2start += 2;
|
|
1823
|
+
else if (!front) {
|
|
1824
|
+
const k1Offset = vOffset + delta - k2;
|
|
1825
|
+
if (k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] !== -1) {
|
|
1826
|
+
const x1 = v1[k1Offset], y1 = vOffset + x1 - k1Offset;
|
|
1827
|
+
if (x2 = text1Length - x2, x1 >= x2)
|
|
1828
|
+
return bisectSplit(text1, text2, x1, y1, deadline);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1834
|
+
}
|
|
1835
|
+
function bisectSplit(text1, text2, x, y, deadline) {
|
|
1836
|
+
const text1a = text1.substring(0, x), text2a = text2.substring(0, y), text1b = text1.substring(x), text2b = text2.substring(y), diffs = doDiff(text1a, text2a, {
|
|
1837
|
+
checkLines: !1,
|
|
1838
|
+
deadline
|
|
1839
|
+
}), diffsb = doDiff(text1b, text2b, {
|
|
1840
|
+
checkLines: !1,
|
|
1841
|
+
deadline
|
|
1842
|
+
});
|
|
1843
|
+
return diffs.concat(diffsb);
|
|
1844
|
+
}
|
|
1845
|
+
function findHalfMatch(text1, text2) {
|
|
1846
|
+
if ((arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1) <= 0)
|
|
1847
|
+
return null;
|
|
1848
|
+
const longText = text1.length > text2.length ? text1 : text2, shortText = text1.length > text2.length ? text2 : text1;
|
|
1849
|
+
if (longText.length < 4 || shortText.length * 2 < longText.length)
|
|
1850
|
+
return null;
|
|
1851
|
+
const halfMatch1 = halfMatchI(longText, shortText, Math.ceil(longText.length / 4)), halfMatch2 = halfMatchI(longText, shortText, Math.ceil(longText.length / 2));
|
|
1852
|
+
let halfMatch;
|
|
1853
|
+
if (halfMatch1 && halfMatch2)
|
|
1854
|
+
halfMatch = halfMatch1[4].length > halfMatch2[4].length ? halfMatch1 : halfMatch2;
|
|
1855
|
+
else {
|
|
1856
|
+
if (!halfMatch1 && !halfMatch2)
|
|
1857
|
+
return null;
|
|
1858
|
+
halfMatch2 ? halfMatch1 || (halfMatch = halfMatch2) : halfMatch = halfMatch1;
|
|
1859
|
+
}
|
|
1860
|
+
if (!halfMatch)
|
|
1861
|
+
throw new Error("Unable to find a half match.");
|
|
1862
|
+
let text1A, text1B, text2A, text2B;
|
|
1863
|
+
text1.length > text2.length ? (text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3]) : (text2A = halfMatch[0], text2B = halfMatch[1], text1A = halfMatch[2], text1B = halfMatch[3]);
|
|
1864
|
+
const midCommon = halfMatch[4];
|
|
1865
|
+
return [text1A, text1B, text2A, text2B, midCommon];
|
|
1866
|
+
}
|
|
1867
|
+
function halfMatchI(longText, shortText, i) {
|
|
1868
|
+
const seed = longText.slice(i, i + Math.floor(longText.length / 4));
|
|
1869
|
+
let j = -1, bestCommon = "", bestLongTextA, bestLongTextB, bestShortTextA, bestShortTextB;
|
|
1870
|
+
for (; (j = shortText.indexOf(seed, j + 1)) !== -1; ) {
|
|
1871
|
+
const prefixLength = getCommonPrefix(longText.slice(i), shortText.slice(j)), suffixLength = getCommonSuffix(longText.slice(0, i), shortText.slice(0, j));
|
|
1872
|
+
bestCommon.length < suffixLength + prefixLength && (bestCommon = shortText.slice(j - suffixLength, j) + shortText.slice(j, j + prefixLength), bestLongTextA = longText.slice(0, i - suffixLength), bestLongTextB = longText.slice(i + prefixLength), bestShortTextA = shortText.slice(0, j - suffixLength), bestShortTextB = shortText.slice(j + prefixLength));
|
|
1873
|
+
}
|
|
1874
|
+
return bestCommon.length * 2 >= longText.length ? [bestLongTextA || "", bestLongTextB || "", bestShortTextA || "", bestShortTextB || "", bestCommon || ""] : null;
|
|
1875
|
+
}
|
|
1876
|
+
function charsToLines(diffs, lineArray) {
|
|
1877
|
+
for (let x = 0; x < diffs.length; x++) {
|
|
1878
|
+
const chars = diffs[x][1], text = [];
|
|
1879
|
+
for (let y = 0; y < chars.length; y++)
|
|
1880
|
+
text[y] = lineArray[chars.charCodeAt(y)];
|
|
1881
|
+
diffs[x][1] = text.join("");
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
function linesToChars(textA, textB) {
|
|
1885
|
+
const lineArray = [], lineHash = {};
|
|
1886
|
+
lineArray[0] = "";
|
|
1887
|
+
function diffLinesToMunge(text) {
|
|
1888
|
+
let chars = "", lineStart = 0, lineEnd = -1, lineArrayLength = lineArray.length;
|
|
1889
|
+
for (; lineEnd < text.length - 1; ) {
|
|
1890
|
+
lineEnd = text.indexOf(`
|
|
1891
|
+
`, lineStart), lineEnd === -1 && (lineEnd = text.length - 1);
|
|
1892
|
+
let line = text.slice(lineStart, lineEnd + 1);
|
|
1893
|
+
(lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : lineHash[line] !== void 0) ? chars += String.fromCharCode(lineHash[line]) : (lineArrayLength === maxLines && (line = text.slice(lineStart), lineEnd = text.length), chars += String.fromCharCode(lineArrayLength), lineHash[line] = lineArrayLength, lineArray[lineArrayLength++] = line), lineStart = lineEnd + 1;
|
|
1894
|
+
}
|
|
1895
|
+
return chars;
|
|
1896
|
+
}
|
|
1897
|
+
let maxLines = 4e4;
|
|
1898
|
+
const chars1 = diffLinesToMunge(textA);
|
|
1899
|
+
maxLines = 65535;
|
|
1900
|
+
const chars2 = diffLinesToMunge(textB);
|
|
1901
|
+
return {
|
|
1902
|
+
chars1,
|
|
1903
|
+
chars2,
|
|
1904
|
+
lineArray
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
function doLineModeDiff(textA, textB, opts) {
|
|
1908
|
+
let text1 = textA, text2 = textB;
|
|
1909
|
+
const a = linesToChars(text1, text2);
|
|
1910
|
+
text1 = a.chars1, text2 = a.chars2;
|
|
1911
|
+
const linearray = a.lineArray;
|
|
1912
|
+
let diffs = doDiff(text1, text2, {
|
|
1913
|
+
checkLines: !1,
|
|
1914
|
+
deadline: opts.deadline
|
|
1915
|
+
});
|
|
1916
|
+
charsToLines(diffs, linearray), diffs = cleanupSemantic(diffs), diffs.push([DIFF_EQUAL, ""]);
|
|
1917
|
+
let pointer = 0, countDelete = 0, countInsert = 0, textDelete = "", textInsert = "";
|
|
1918
|
+
for (; pointer < diffs.length; ) {
|
|
1919
|
+
switch (diffs[pointer][0]) {
|
|
1920
|
+
case DIFF_INSERT:
|
|
1921
|
+
countInsert++, textInsert += diffs[pointer][1];
|
|
1922
|
+
break;
|
|
1923
|
+
case DIFF_DELETE:
|
|
1924
|
+
countDelete++, textDelete += diffs[pointer][1];
|
|
1925
|
+
break;
|
|
1926
|
+
case DIFF_EQUAL:
|
|
1927
|
+
if (countDelete >= 1 && countInsert >= 1) {
|
|
1928
|
+
diffs.splice(pointer - countDelete - countInsert, countDelete + countInsert), pointer = pointer - countDelete - countInsert;
|
|
1929
|
+
const aa = doDiff(textDelete, textInsert, {
|
|
1930
|
+
checkLines: !1,
|
|
1931
|
+
deadline: opts.deadline
|
|
1932
|
+
});
|
|
1933
|
+
for (let j = aa.length - 1; j >= 0; j--)
|
|
1934
|
+
diffs.splice(pointer, 0, aa[j]);
|
|
1935
|
+
pointer += aa.length;
|
|
1936
|
+
}
|
|
1937
|
+
countInsert = 0, countDelete = 0, textDelete = "", textInsert = "";
|
|
1938
|
+
break;
|
|
1939
|
+
default:
|
|
1940
|
+
throw new Error("Unknown diff operation.");
|
|
1941
|
+
}
|
|
1942
|
+
pointer++;
|
|
1943
|
+
}
|
|
1944
|
+
return diffs.pop(), diffs;
|
|
1945
|
+
}
|
|
1946
|
+
function computeDiff(text1, text2, opts) {
|
|
1947
|
+
let diffs;
|
|
1948
|
+
if (!text1)
|
|
1949
|
+
return [[DIFF_INSERT, text2]];
|
|
1950
|
+
if (!text2)
|
|
1951
|
+
return [[DIFF_DELETE, text1]];
|
|
1952
|
+
const longtext = text1.length > text2.length ? text1 : text2, shorttext = text1.length > text2.length ? text2 : text1, i = longtext.indexOf(shorttext);
|
|
1953
|
+
if (i !== -1)
|
|
1954
|
+
return diffs = [[DIFF_INSERT, longtext.substring(0, i)], [DIFF_EQUAL, shorttext], [DIFF_INSERT, longtext.substring(i + shorttext.length)]], text1.length > text2.length && (diffs[0][0] = DIFF_DELETE, diffs[2][0] = DIFF_DELETE), diffs;
|
|
1955
|
+
if (shorttext.length === 1)
|
|
1956
|
+
return [[DIFF_DELETE, text1], [DIFF_INSERT, text2]];
|
|
1957
|
+
const halfMatch = findHalfMatch(text1, text2);
|
|
1958
|
+
if (halfMatch) {
|
|
1959
|
+
const text1A = halfMatch[0], text1B = halfMatch[1], text2A = halfMatch[2], text2B = halfMatch[3], midCommon = halfMatch[4], diffsA = doDiff(text1A, text2A, opts), diffsB = doDiff(text1B, text2B, opts);
|
|
1960
|
+
return diffsA.concat([[DIFF_EQUAL, midCommon]], diffsB);
|
|
1961
|
+
}
|
|
1962
|
+
return opts.checkLines && text1.length > 100 && text2.length > 100 ? doLineModeDiff(text1, text2, opts) : bisect(text1, text2, opts.deadline);
|
|
1963
|
+
}
|
|
1964
|
+
const DIFF_DELETE = -1, DIFF_INSERT = 1, DIFF_EQUAL = 0;
|
|
1965
|
+
function diff(textA, textB, opts) {
|
|
1966
|
+
if (textA === null || textB === null)
|
|
1967
|
+
throw new Error("Null input. (diff)");
|
|
1968
|
+
const diffs = doDiff(textA, textB, createInternalOpts(opts || {}));
|
|
1969
|
+
return adjustDiffForSurrogatePairs(diffs), diffs;
|
|
1970
|
+
}
|
|
1971
|
+
function doDiff(textA, textB, options) {
|
|
1972
|
+
let text1 = textA, text2 = textB;
|
|
1973
|
+
if (text1 === text2)
|
|
1974
|
+
return text1 ? [[DIFF_EQUAL, text1]] : [];
|
|
1975
|
+
let commonlength = getCommonPrefix(text1, text2);
|
|
1976
|
+
const commonprefix = text1.substring(0, commonlength);
|
|
1977
|
+
text1 = text1.substring(commonlength), text2 = text2.substring(commonlength), commonlength = getCommonSuffix(text1, text2);
|
|
1978
|
+
const commonsuffix = text1.substring(text1.length - commonlength);
|
|
1979
|
+
text1 = text1.substring(0, text1.length - commonlength), text2 = text2.substring(0, text2.length - commonlength);
|
|
1980
|
+
let diffs = computeDiff(text1, text2, options);
|
|
1981
|
+
return commonprefix && diffs.unshift([DIFF_EQUAL, commonprefix]), commonsuffix && diffs.push([DIFF_EQUAL, commonsuffix]), diffs = cleanupMerge(diffs), diffs;
|
|
1982
|
+
}
|
|
1983
|
+
function createDeadLine(timeout) {
|
|
1984
|
+
let t = 1;
|
|
1985
|
+
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
1986
|
+
}
|
|
1987
|
+
function createInternalOpts(opts) {
|
|
1988
|
+
return __spreadValues({
|
|
1989
|
+
checkLines: !0,
|
|
1990
|
+
deadline: createDeadLine(opts.timeout || 1)
|
|
1991
|
+
}, opts);
|
|
1992
|
+
}
|
|
1993
|
+
function combineChar(data, char, dir) {
|
|
1994
|
+
return dir === 1 ? data + char : char + data;
|
|
1995
|
+
}
|
|
1996
|
+
function splitChar(data, dir) {
|
|
1997
|
+
return dir === 1 ? [data.substring(0, data.length - 1), data[data.length - 1]] : [data.substring(1), data[0]];
|
|
1998
|
+
}
|
|
1999
|
+
function hasSharedChar(diffs, i, j, dir) {
|
|
2000
|
+
return dir === 1 ? diffs[i][1][diffs[i][1].length - 1] === diffs[j][1][diffs[j][1].length - 1] : diffs[i][1][0] === diffs[j][1][0];
|
|
2001
|
+
}
|
|
2002
|
+
function deisolateChar(diffs, i, dir) {
|
|
2003
|
+
const inv = dir === 1 ? -1 : 1;
|
|
2004
|
+
let insertIdx = null, deleteIdx = null, j = i + dir;
|
|
2005
|
+
for (; j >= 0 && j < diffs.length && (insertIdx === null || deleteIdx === null); j += dir) {
|
|
2006
|
+
const [op, text2] = diffs[j];
|
|
2007
|
+
if (text2.length !== 0) {
|
|
2008
|
+
if (op === DIFF_INSERT) {
|
|
2009
|
+
insertIdx === null && (insertIdx = j);
|
|
2010
|
+
continue;
|
|
2011
|
+
} else if (op === DIFF_DELETE) {
|
|
2012
|
+
deleteIdx === null && (deleteIdx = j);
|
|
2013
|
+
continue;
|
|
2014
|
+
} else if (op === DIFF_EQUAL) {
|
|
2015
|
+
if (insertIdx === null && deleteIdx === null) {
|
|
2016
|
+
const [rest, char2] = splitChar(diffs[i][1], dir);
|
|
2017
|
+
diffs[i][1] = rest, diffs[j][1] = combineChar(diffs[j][1], char2, inv);
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
break;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
if (insertIdx !== null && deleteIdx !== null && hasSharedChar(diffs, insertIdx, deleteIdx, dir)) {
|
|
2025
|
+
const [insertText, insertChar] = splitChar(diffs[insertIdx][1], inv), [deleteText] = splitChar(diffs[deleteIdx][1], inv);
|
|
2026
|
+
diffs[insertIdx][1] = insertText, diffs[deleteIdx][1] = deleteText, diffs[i][1] = combineChar(diffs[i][1], insertChar, dir);
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
const [text, char] = splitChar(diffs[i][1], dir);
|
|
2030
|
+
diffs[i][1] = text, insertIdx === null ? (diffs.splice(j, 0, [DIFF_INSERT, char]), deleteIdx !== null && deleteIdx >= j && deleteIdx++) : diffs[insertIdx][1] = combineChar(diffs[insertIdx][1], char, inv), deleteIdx === null ? diffs.splice(j, 0, [DIFF_DELETE, char]) : diffs[deleteIdx][1] = combineChar(diffs[deleteIdx][1], char, inv);
|
|
2031
|
+
}
|
|
2032
|
+
function adjustDiffForSurrogatePairs(diffs) {
|
|
2033
|
+
for (let i = 0; i < diffs.length; i++) {
|
|
2034
|
+
const [diffType, diffText] = diffs[i];
|
|
2035
|
+
if (diffText.length === 0)
|
|
2036
|
+
continue;
|
|
2037
|
+
const firstChar = diffText[0], lastChar = diffText[diffText.length - 1];
|
|
2038
|
+
isHighSurrogate(lastChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, 1), isLowSurrogate(firstChar) && diffType === DIFF_EQUAL && deisolateChar(diffs, i, -1);
|
|
2039
|
+
}
|
|
2040
|
+
for (let i = 0; i < diffs.length; i++)
|
|
2041
|
+
diffs[i][1].length === 0 && diffs.splice(i, 1);
|
|
2042
|
+
}
|
|
2043
|
+
const DEFAULT_OPTIONS = {
|
|
2044
|
+
/**
|
|
2045
|
+
* At what point is no match declared (0.0 = perfection, 1.0 = very loose).
|
|
2046
|
+
*/
|
|
2047
|
+
threshold: 0.5,
|
|
2048
|
+
/**
|
|
2049
|
+
* How far to search for a match (0 = exact location, 1000+ = broad match).
|
|
2050
|
+
* A match this many characters away from the expected location will add
|
|
2051
|
+
* 1.0 to the score (0.0 is a perfect match).
|
|
2052
|
+
*/
|
|
2053
|
+
distance: 1e3
|
|
2054
|
+
};
|
|
2055
|
+
function applyDefaults(options) {
|
|
2056
|
+
return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
2057
|
+
}
|
|
2058
|
+
const MAX_BITS$1 = 32;
|
|
2059
|
+
function bitap(text, pattern, loc) {
|
|
2060
|
+
let opts = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
|
2061
|
+
if (pattern.length > MAX_BITS$1)
|
|
2062
|
+
throw new Error("Pattern too long for this browser.");
|
|
2063
|
+
const options = applyDefaults(opts), s = getAlphabetFromPattern(pattern);
|
|
2064
|
+
function getBitapScore(e, x) {
|
|
2065
|
+
const accuracy = e / pattern.length, proximity = Math.abs(loc - x);
|
|
2066
|
+
return options.distance ? accuracy + proximity / options.distance : proximity ? 1 : accuracy;
|
|
2067
|
+
}
|
|
2068
|
+
let scoreThreshold = options.threshold, bestLoc = text.indexOf(pattern, loc);
|
|
2069
|
+
bestLoc !== -1 && (scoreThreshold = Math.min(getBitapScore(0, bestLoc), scoreThreshold), bestLoc = text.lastIndexOf(pattern, loc + pattern.length), bestLoc !== -1 && (scoreThreshold = Math.min(getBitapScore(0, bestLoc), scoreThreshold)));
|
|
2070
|
+
const matchmask = 1 << pattern.length - 1;
|
|
2071
|
+
bestLoc = -1;
|
|
2072
|
+
let binMin, binMid, binMax = pattern.length + text.length, lastRd = [];
|
|
2073
|
+
for (let d = 0; d < pattern.length; d++) {
|
|
2074
|
+
for (binMin = 0, binMid = binMax; binMin < binMid; )
|
|
2075
|
+
getBitapScore(d, loc + binMid) <= scoreThreshold ? binMin = binMid : binMax = binMid, binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
2076
|
+
binMax = binMid;
|
|
2077
|
+
let start = Math.max(1, loc - binMid + 1);
|
|
2078
|
+
const finish = Math.min(loc + binMid, text.length) + pattern.length, rd = new Array(finish + 2);
|
|
2079
|
+
rd[finish + 1] = (1 << d) - 1;
|
|
2080
|
+
for (let j = finish; j >= start; j--) {
|
|
2081
|
+
const charMatch = s[text.charAt(j - 1)];
|
|
2082
|
+
if (d === 0 ? rd[j] = (rd[j + 1] << 1 | 1) & charMatch : rd[j] = (rd[j + 1] << 1 | 1) & charMatch | ((lastRd[j + 1] | lastRd[j]) << 1 | 1) | lastRd[j + 1], rd[j] & matchmask) {
|
|
2083
|
+
const score = getBitapScore(d, j - 1);
|
|
2084
|
+
if (score <= scoreThreshold)
|
|
2085
|
+
if (scoreThreshold = score, bestLoc = j - 1, bestLoc > loc)
|
|
2086
|
+
start = Math.max(1, 2 * loc - bestLoc);
|
|
2087
|
+
else
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
if (getBitapScore(d + 1, loc) > scoreThreshold)
|
|
2092
|
+
break;
|
|
2093
|
+
lastRd = rd;
|
|
2094
|
+
}
|
|
2095
|
+
return bestLoc;
|
|
2096
|
+
}
|
|
2097
|
+
function getAlphabetFromPattern(pattern) {
|
|
2098
|
+
const s = {};
|
|
2099
|
+
for (let i = 0; i < pattern.length; i++)
|
|
2100
|
+
s[pattern.charAt(i)] = 0;
|
|
2101
|
+
for (let i = 0; i < pattern.length; i++)
|
|
2102
|
+
s[pattern.charAt(i)] |= 1 << pattern.length - i - 1;
|
|
2103
|
+
return s;
|
|
2104
|
+
}
|
|
2105
|
+
function match(text, pattern, searchLocation) {
|
|
2106
|
+
if (text === null || pattern === null || searchLocation === null)
|
|
2107
|
+
throw new Error("Null input. (match())");
|
|
2108
|
+
const loc = Math.max(0, Math.min(searchLocation, text.length));
|
|
2109
|
+
if (text === pattern)
|
|
2110
|
+
return 0;
|
|
2111
|
+
if (text.length) {
|
|
2112
|
+
if (text.substring(loc, loc + pattern.length) === pattern)
|
|
2113
|
+
return loc;
|
|
2114
|
+
} else
|
|
2115
|
+
return -1;
|
|
2116
|
+
return bitap(text, pattern, loc);
|
|
2117
|
+
}
|
|
2118
|
+
function createPatchObject(start1, start2) {
|
|
2119
|
+
return {
|
|
2120
|
+
diffs: [],
|
|
2121
|
+
start1,
|
|
2122
|
+
start2,
|
|
2123
|
+
utf8Start1: start1,
|
|
2124
|
+
utf8Start2: start2,
|
|
2125
|
+
length1: 0,
|
|
2126
|
+
length2: 0,
|
|
2127
|
+
utf8Length1: 0,
|
|
2128
|
+
utf8Length2: 0
|
|
2129
|
+
};
|
|
2130
|
+
}
|
|
2131
|
+
function diffText1(diffs) {
|
|
2132
|
+
const text = [];
|
|
2133
|
+
for (let x = 0; x < diffs.length; x++)
|
|
2134
|
+
diffs[x][0] !== DIFF_INSERT && (text[x] = diffs[x][1]);
|
|
2135
|
+
return text.join("");
|
|
2136
|
+
}
|
|
2137
|
+
function diffText2(diffs) {
|
|
2138
|
+
const text = [];
|
|
2139
|
+
for (let x = 0; x < diffs.length; x++)
|
|
2140
|
+
diffs[x][0] !== DIFF_DELETE && (text[x] = diffs[x][1]);
|
|
2141
|
+
return text.join("");
|
|
2142
|
+
}
|
|
2143
|
+
function countUtf8Bytes(str) {
|
|
2144
|
+
let bytes = 0;
|
|
2145
|
+
for (let i = 0; i < str.length; i++) {
|
|
2146
|
+
const codePoint = str.codePointAt(i);
|
|
2147
|
+
if (typeof codePoint > "u")
|
|
2148
|
+
throw new Error("Failed to get codepoint");
|
|
2149
|
+
bytes += utf8len(codePoint);
|
|
2150
|
+
}
|
|
2151
|
+
return bytes;
|
|
2152
|
+
}
|
|
2153
|
+
function adjustIndiciesToUcs2(patches, base) {
|
|
2154
|
+
let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, byteOffset = 0, idx = 0;
|
|
2155
|
+
function advanceTo(target) {
|
|
2156
|
+
for (; byteOffset < target; ) {
|
|
2157
|
+
const codePoint = base.codePointAt(idx);
|
|
2158
|
+
if (typeof codePoint > "u")
|
|
2159
|
+
return idx;
|
|
2160
|
+
byteOffset += utf8len(codePoint), codePoint > 65535 ? idx += 2 : idx += 1;
|
|
2161
|
+
}
|
|
2162
|
+
if (!options.allowExceedingIndices && byteOffset !== target)
|
|
2163
|
+
throw new Error("Failed to determine byte offset");
|
|
2164
|
+
return idx;
|
|
2165
|
+
}
|
|
2166
|
+
const adjusted = [];
|
|
2167
|
+
for (const patch of patches)
|
|
2168
|
+
adjusted.push({
|
|
2169
|
+
diffs: patch.diffs.map((diff2) => cloneDiff(diff2)),
|
|
2170
|
+
start1: advanceTo(patch.start1),
|
|
2171
|
+
start2: advanceTo(patch.start2),
|
|
2172
|
+
utf8Start1: patch.utf8Start1,
|
|
2173
|
+
utf8Start2: patch.utf8Start2,
|
|
2174
|
+
length1: patch.length1,
|
|
2175
|
+
length2: patch.length2,
|
|
2176
|
+
utf8Length1: patch.utf8Length1,
|
|
2177
|
+
utf8Length2: patch.utf8Length2
|
|
2178
|
+
});
|
|
2179
|
+
return adjusted;
|
|
2180
|
+
}
|
|
2181
|
+
function utf8len(codePoint) {
|
|
2182
|
+
return codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
2183
|
+
}
|
|
2184
|
+
const MAX_BITS = 32, DEFAULT_MARGIN = 4;
|
|
2185
|
+
function levenshtein(diffs) {
|
|
2186
|
+
let leven = 0, insertions = 0, deletions = 0;
|
|
2187
|
+
for (let x = 0; x < diffs.length; x++) {
|
|
2188
|
+
const op = diffs[x][0], data = diffs[x][1];
|
|
2189
|
+
switch (op) {
|
|
2190
|
+
case DIFF_INSERT:
|
|
2191
|
+
insertions += data.length;
|
|
2192
|
+
break;
|
|
2193
|
+
case DIFF_DELETE:
|
|
2194
|
+
deletions += data.length;
|
|
2195
|
+
break;
|
|
2196
|
+
case DIFF_EQUAL:
|
|
2197
|
+
leven += Math.max(insertions, deletions), insertions = 0, deletions = 0;
|
|
2198
|
+
break;
|
|
2199
|
+
default:
|
|
2200
|
+
throw new Error("Unknown diff operation.");
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
return leven += Math.max(insertions, deletions), leven;
|
|
2204
|
+
}
|
|
2205
|
+
function xIndex(diffs, loc) {
|
|
2206
|
+
let chars1 = 0, chars2 = 0, lastChars1 = 0, lastChars2 = 0, x;
|
|
2207
|
+
for (x = 0; x < diffs.length && (diffs[x][0] !== DIFF_INSERT && (chars1 += diffs[x][1].length), diffs[x][0] !== DIFF_DELETE && (chars2 += diffs[x][1].length), !(chars1 > loc)); x++)
|
|
2208
|
+
lastChars1 = chars1, lastChars2 = chars2;
|
|
2209
|
+
return diffs.length !== x && diffs[x][0] === DIFF_DELETE ? lastChars2 : lastChars2 + (loc - lastChars1);
|
|
2210
|
+
}
|
|
2211
|
+
function addPadding(patches) {
|
|
2212
|
+
const paddingLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
|
|
2213
|
+
let nullPadding = "";
|
|
2214
|
+
for (let x = 1; x <= paddingLength; x++)
|
|
2215
|
+
nullPadding += String.fromCharCode(x);
|
|
2216
|
+
for (const p of patches)
|
|
2217
|
+
p.start1 += paddingLength, p.start2 += paddingLength, p.utf8Start1 += paddingLength, p.utf8Start2 += paddingLength;
|
|
2218
|
+
let patch = patches[0], diffs = patch.diffs;
|
|
2219
|
+
if (diffs.length === 0 || diffs[0][0] !== DIFF_EQUAL)
|
|
2220
|
+
diffs.unshift([DIFF_EQUAL, nullPadding]), patch.start1 -= paddingLength, patch.start2 -= paddingLength, patch.utf8Start1 -= paddingLength, patch.utf8Start2 -= paddingLength, patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
2221
|
+
else if (paddingLength > diffs[0][1].length) {
|
|
2222
|
+
const firstDiffLength = diffs[0][1].length, extraLength = paddingLength - firstDiffLength;
|
|
2223
|
+
diffs[0][1] = nullPadding.substring(firstDiffLength) + diffs[0][1], patch.start1 -= extraLength, patch.start2 -= extraLength, patch.utf8Start1 -= extraLength, patch.utf8Start2 -= extraLength, patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
2224
|
+
}
|
|
2225
|
+
if (patch = patches[patches.length - 1], diffs = patch.diffs, diffs.length === 0 || diffs[diffs.length - 1][0] !== DIFF_EQUAL)
|
|
2226
|
+
diffs.push([DIFF_EQUAL, nullPadding]), patch.length1 += paddingLength, patch.length2 += paddingLength, patch.utf8Length1 += paddingLength, patch.utf8Length2 += paddingLength;
|
|
2227
|
+
else if (paddingLength > diffs[diffs.length - 1][1].length) {
|
|
2228
|
+
const extraLength = paddingLength - diffs[diffs.length - 1][1].length;
|
|
2229
|
+
diffs[diffs.length - 1][1] += nullPadding.substring(0, extraLength), patch.length1 += extraLength, patch.length2 += extraLength, patch.utf8Length1 += extraLength, patch.utf8Length2 += extraLength;
|
|
2230
|
+
}
|
|
2231
|
+
return nullPadding;
|
|
2232
|
+
}
|
|
2233
|
+
function splitMax(patches) {
|
|
2234
|
+
let margin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_MARGIN;
|
|
2235
|
+
const patchSize = MAX_BITS;
|
|
2236
|
+
for (let x = 0; x < patches.length; x++) {
|
|
2237
|
+
if (patches[x].length1 <= patchSize)
|
|
2238
|
+
continue;
|
|
2239
|
+
const bigpatch = patches[x];
|
|
2240
|
+
patches.splice(x--, 1);
|
|
2241
|
+
let start1 = bigpatch.start1, start2 = bigpatch.start2, preContext = "";
|
|
2242
|
+
for (; bigpatch.diffs.length !== 0; ) {
|
|
2243
|
+
const patch = createPatchObject(start1 - preContext.length, start2 - preContext.length);
|
|
2244
|
+
let empty = !0;
|
|
2245
|
+
if (preContext !== "") {
|
|
2246
|
+
const precontextByteCount = countUtf8Bytes(preContext);
|
|
2247
|
+
patch.length1 = preContext.length, patch.utf8Length1 = precontextByteCount, patch.length2 = preContext.length, patch.utf8Length2 = precontextByteCount, patch.diffs.push([DIFF_EQUAL, preContext]);
|
|
2248
|
+
}
|
|
2249
|
+
for (; bigpatch.diffs.length !== 0 && patch.length1 < patchSize - margin; ) {
|
|
2250
|
+
const diffType = bigpatch.diffs[0][0];
|
|
2251
|
+
let diffText = bigpatch.diffs[0][1], diffTextByteCount = countUtf8Bytes(diffText);
|
|
2252
|
+
if (diffType === DIFF_INSERT) {
|
|
2253
|
+
patch.length2 += diffText.length, patch.utf8Length2 += diffTextByteCount, start2 += diffText.length;
|
|
2254
|
+
const diff2 = bigpatch.diffs.shift();
|
|
2255
|
+
diff2 && patch.diffs.push(diff2), empty = !1;
|
|
2256
|
+
} else
|
|
2257
|
+
diffType === DIFF_DELETE && patch.diffs.length === 1 && patch.diffs[0][0] === DIFF_EQUAL && diffText.length > 2 * patchSize ? (patch.length1 += diffText.length, patch.utf8Length1 += diffTextByteCount, start1 += diffText.length, empty = !1, patch.diffs.push([diffType, diffText]), bigpatch.diffs.shift()) : (diffText = diffText.substring(0, patchSize - patch.length1 - margin), diffTextByteCount = countUtf8Bytes(diffText), patch.length1 += diffText.length, patch.utf8Length1 += diffTextByteCount, start1 += diffText.length, diffType === DIFF_EQUAL ? (patch.length2 += diffText.length, patch.utf8Length2 += diffTextByteCount, start2 += diffText.length) : empty = !1, patch.diffs.push([diffType, diffText]), diffText === bigpatch.diffs[0][1] ? bigpatch.diffs.shift() : bigpatch.diffs[0][1] = bigpatch.diffs[0][1].substring(diffText.length));
|
|
2258
|
+
}
|
|
2259
|
+
preContext = diffText2(patch.diffs), preContext = preContext.substring(preContext.length - margin);
|
|
2260
|
+
const postContext = diffText1(bigpatch.diffs).substring(0, margin), postContextByteCount = countUtf8Bytes(postContext);
|
|
2261
|
+
postContext !== "" && (patch.length1 += postContext.length, patch.length2 += postContext.length, patch.utf8Length1 += postContextByteCount, patch.utf8Length2 += postContextByteCount, patch.diffs.length !== 0 && patch.diffs[patch.diffs.length - 1][0] === DIFF_EQUAL ? patch.diffs[patch.diffs.length - 1][1] += postContext : patch.diffs.push([DIFF_EQUAL, postContext])), empty || patches.splice(++x, 0, patch);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
function apply(patches, originalText) {
|
|
2266
|
+
let opts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
2267
|
+
if (typeof patches == "string")
|
|
2268
|
+
throw new Error("Patches must be an array - pass the patch to `parsePatch()` first");
|
|
2269
|
+
let text = originalText;
|
|
2270
|
+
if (patches.length === 0)
|
|
2271
|
+
return [text, []];
|
|
2272
|
+
const parsed = adjustIndiciesToUcs2(patches, text, {
|
|
2273
|
+
allowExceedingIndices: opts.allowExceedingIndices
|
|
2274
|
+
}), margin = opts.margin || DEFAULT_MARGIN, deleteThreshold = opts.deleteThreshold || 0.4, nullPadding = addPadding(parsed, margin);
|
|
2275
|
+
text = nullPadding + text + nullPadding, splitMax(parsed, margin);
|
|
2276
|
+
let delta = 0;
|
|
2277
|
+
const results = [];
|
|
2278
|
+
for (let x = 0; x < parsed.length; x++) {
|
|
2279
|
+
const expectedLoc = parsed[x].start2 + delta, text1 = diffText1(parsed[x].diffs);
|
|
2280
|
+
let startLoc, endLoc = -1;
|
|
2281
|
+
if (text1.length > MAX_BITS ? (startLoc = match(text, text1.substring(0, MAX_BITS), expectedLoc), startLoc !== -1 && (endLoc = match(text, text1.substring(text1.length - MAX_BITS), expectedLoc + text1.length - MAX_BITS), (endLoc === -1 || startLoc >= endLoc) && (startLoc = -1))) : startLoc = match(text, text1, expectedLoc), startLoc === -1)
|
|
2282
|
+
results[x] = !1, delta -= parsed[x].length2 - parsed[x].length1;
|
|
2283
|
+
else {
|
|
2284
|
+
results[x] = !0, delta = startLoc - expectedLoc;
|
|
2285
|
+
let text2;
|
|
2286
|
+
if (endLoc === -1 ? text2 = text.substring(startLoc, startLoc + text1.length) : text2 = text.substring(startLoc, endLoc + MAX_BITS), text1 === text2)
|
|
2287
|
+
text = text.substring(0, startLoc) + diffText2(parsed[x].diffs) + text.substring(startLoc + text1.length);
|
|
2288
|
+
else {
|
|
2289
|
+
let diffs = diff(text1, text2, {
|
|
2290
|
+
checkLines: !1
|
|
2291
|
+
});
|
|
2292
|
+
if (text1.length > MAX_BITS && levenshtein(diffs) / text1.length > deleteThreshold)
|
|
2293
|
+
results[x] = !1;
|
|
2294
|
+
else {
|
|
2295
|
+
diffs = cleanupSemanticLossless(diffs);
|
|
2296
|
+
let index1 = 0, index2 = 0;
|
|
2297
|
+
for (let y = 0; y < parsed[x].diffs.length; y++) {
|
|
2298
|
+
const mod = parsed[x].diffs[y];
|
|
2299
|
+
mod[0] !== DIFF_EQUAL && (index2 = xIndex(diffs, index1)), mod[0] === DIFF_INSERT ? text = text.substring(0, startLoc + index2) + mod[1] + text.substring(startLoc + index2) : mod[0] === DIFF_DELETE && (text = text.substring(0, startLoc + index2) + text.substring(startLoc + xIndex(diffs, index1 + mod[1].length))), mod[0] !== DIFF_DELETE && (index1 += mod[1].length);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
return text = text.substring(nullPadding.length, text.length - nullPadding.length), [text, results];
|
|
2306
|
+
}
|
|
2307
|
+
const patchHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;
|
|
2308
|
+
function parse(textline) {
|
|
2309
|
+
if (!textline)
|
|
2310
|
+
return [];
|
|
2311
|
+
const patches = [], lines = textline.split(`
|
|
2312
|
+
`);
|
|
2313
|
+
let textPointer = 0;
|
|
2314
|
+
for (; textPointer < lines.length; ) {
|
|
2315
|
+
const m = lines[textPointer].match(patchHeader);
|
|
2316
|
+
if (!m)
|
|
2317
|
+
throw new Error("Invalid patch string: ".concat(lines[textPointer]));
|
|
2318
|
+
const patch = createPatchObject(toInt(m[1]), toInt(m[3]));
|
|
2319
|
+
for (patches.push(patch), m[2] === "" ? (patch.start1--, patch.utf8Start1--, patch.length1 = 1, patch.utf8Length1 = 1) : m[2] === "0" ? (patch.length1 = 0, patch.utf8Length1 = 0) : (patch.start1--, patch.utf8Start1--, patch.utf8Length1 = toInt(m[2]), patch.length1 = patch.utf8Length1), m[4] === "" ? (patch.start2--, patch.utf8Start2--, patch.length2 = 1, patch.utf8Length2 = 1) : m[4] === "0" ? (patch.length2 = 0, patch.utf8Length2 = 0) : (patch.start2--, patch.utf8Start2--, patch.utf8Length2 = toInt(m[4]), patch.length2 = patch.utf8Length2), textPointer++; textPointer < lines.length; ) {
|
|
2320
|
+
const currentLine = lines[textPointer], sign = currentLine.charAt(0);
|
|
2321
|
+
if (sign === "@")
|
|
2322
|
+
break;
|
|
2323
|
+
if (sign === "") {
|
|
2324
|
+
textPointer++;
|
|
2325
|
+
continue;
|
|
2326
|
+
}
|
|
2327
|
+
let line;
|
|
2328
|
+
try {
|
|
2329
|
+
line = decodeURI(currentLine.slice(1));
|
|
2330
|
+
} catch (ex) {
|
|
2331
|
+
throw new Error("Illegal escape in parse: ".concat(currentLine));
|
|
2332
|
+
}
|
|
2333
|
+
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
2334
|
+
if (sign === "-")
|
|
2335
|
+
patch.diffs.push([DIFF_DELETE, line]), patch.length1 -= utf8Diff;
|
|
2336
|
+
else if (sign === "+")
|
|
2337
|
+
patch.diffs.push([DIFF_INSERT, line]), patch.length2 -= utf8Diff;
|
|
2338
|
+
else if (sign === " ")
|
|
2339
|
+
patch.diffs.push([DIFF_EQUAL, line]), patch.length1 -= utf8Diff, patch.length2 -= utf8Diff;
|
|
2340
|
+
else
|
|
2341
|
+
throw new Error('Invalid patch mode "'.concat(sign, '" in: ').concat(line));
|
|
2342
|
+
textPointer++;
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
return patches;
|
|
2346
|
+
}
|
|
2347
|
+
function toInt(num) {
|
|
2348
|
+
return parseInt(num, 10);
|
|
2349
|
+
}
|
|
2350
|
+
var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1, symbolTag = "[object Symbol]";
|
|
2351
|
+
function isSymbol$1(value) {
|
|
2352
|
+
return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
|
|
2353
|
+
}
|
|
2354
|
+
var isSymbol_1 = isSymbol$1, isSymbol = isSymbol_1;
|
|
2355
|
+
function baseExtremum$2(array, iteratee, comparator) {
|
|
2356
|
+
for (var index = -1, length = array.length; ++index < length; ) {
|
|
2357
|
+
var value = array[index], current = iteratee(value);
|
|
2358
|
+
if (current != null && (computed === void 0 ? current === current && !isSymbol(current) : comparator(current, computed)))
|
|
2359
|
+
var computed = current, result = value;
|
|
2360
|
+
}
|
|
2361
|
+
return result;
|
|
2362
|
+
}
|
|
2363
|
+
var _baseExtremum = baseExtremum$2;
|
|
2364
|
+
function baseGt$1(value, other) {
|
|
2365
|
+
return value > other;
|
|
2366
|
+
}
|
|
2367
|
+
var _baseGt = baseGt$1;
|
|
2368
|
+
function identity$2(value) {
|
|
2369
|
+
return value;
|
|
2370
|
+
}
|
|
2371
|
+
var identity_1 = identity$2, baseExtremum$1 = _baseExtremum, baseGt = _baseGt, identity$1 = identity_1;
|
|
2372
|
+
function max(array) {
|
|
2373
|
+
return array && array.length ? baseExtremum$1(array, identity$1, baseGt) : void 0;
|
|
2374
|
+
}
|
|
2375
|
+
var max_1 = max, max$1 = /* @__PURE__ */ getDefaultExportFromCjs(max_1);
|
|
2376
|
+
function baseLt$1(value, other) {
|
|
2377
|
+
return value < other;
|
|
2378
|
+
}
|
|
2379
|
+
var _baseLt = baseLt$1, baseExtremum = _baseExtremum, baseLt = _baseLt, identity = identity_1;
|
|
2380
|
+
function min(array) {
|
|
2381
|
+
return array && array.length ? baseExtremum(array, identity, baseLt) : void 0;
|
|
2382
|
+
}
|
|
2383
|
+
var min_1 = min, min$1 = /* @__PURE__ */ getDefaultExportFromCjs(min_1);
|
|
2384
|
+
function compact(array) {
|
|
2385
|
+
for (var index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = []; ++index < length; ) {
|
|
2386
|
+
var value = array[index];
|
|
2387
|
+
value && (result[resIndex++] = value);
|
|
2388
|
+
}
|
|
2389
|
+
return result;
|
|
2390
|
+
}
|
|
2391
|
+
var compact_1 = compact, compact$1 = /* @__PURE__ */ getDefaultExportFromCjs(compact_1);
|
|
2392
|
+
const debug = debugIt("mutator-document");
|
|
2393
|
+
var __defProp$h = Object.defineProperty, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$h = (obj, key, value) => __defNormalProp$h(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
2394
|
+
class ImmutableAccessor {
|
|
2395
|
+
constructor(value, path) {
|
|
2396
|
+
__publicField$h(this, "_value"), __publicField$h(this, "path"), this._value = value, this.path = path || [];
|
|
2397
|
+
}
|
|
2398
|
+
containerType() {
|
|
2399
|
+
return Array.isArray(this._value) ? "array" : this._value !== null && typeof this._value == "object" ? "object" : "primitive";
|
|
2400
|
+
}
|
|
2401
|
+
// Common reader, supported by all containers
|
|
2402
|
+
get() {
|
|
2403
|
+
return this._value;
|
|
2404
|
+
}
|
|
2405
|
+
// Array reader
|
|
2406
|
+
length() {
|
|
2407
|
+
if (!Array.isArray(this._value))
|
|
2408
|
+
throw new Error("Won't return length of non-indexable _value");
|
|
2409
|
+
return this._value.length;
|
|
2410
|
+
}
|
|
2411
|
+
getIndex(i) {
|
|
2412
|
+
return Array.isArray(this._value) ? i >= this.length() ? null : new ImmutableAccessor(this._value[i], this.path.concat(i)) : !1;
|
|
2413
|
+
}
|
|
2414
|
+
// Object reader
|
|
2415
|
+
hasAttribute(key) {
|
|
2416
|
+
return isRecord$1(this._value) ? this._value.hasOwnProperty(key) : !1;
|
|
2417
|
+
}
|
|
2418
|
+
attributeKeys() {
|
|
2419
|
+
return isRecord$1(this._value) ? Object.keys(this._value) : [];
|
|
2420
|
+
}
|
|
2421
|
+
getAttribute(key) {
|
|
2422
|
+
if (!isRecord$1(this._value))
|
|
2423
|
+
throw new Error("getAttribute only applies to plain objects");
|
|
2424
|
+
return this.hasAttribute(key) ? new ImmutableAccessor(this._value[key], this.path.concat(key)) : null;
|
|
2425
|
+
}
|
|
2426
|
+
// Common writer, supported by all containers
|
|
2427
|
+
set(value) {
|
|
2428
|
+
return value === this._value ? this : new ImmutableAccessor(value, this.path);
|
|
2429
|
+
}
|
|
2430
|
+
// array writer interface
|
|
2431
|
+
setIndex(i, value) {
|
|
2432
|
+
if (!Array.isArray(this._value))
|
|
2433
|
+
throw new Error("setIndex only applies to arrays");
|
|
2434
|
+
if (Object.is(value, this._value[i]))
|
|
2435
|
+
return this;
|
|
2436
|
+
const nextValue = this._value.slice();
|
|
2437
|
+
return nextValue[i] = value, new ImmutableAccessor(nextValue, this.path);
|
|
2438
|
+
}
|
|
2439
|
+
setIndexAccessor(i, accessor) {
|
|
2440
|
+
return this.setIndex(i, accessor.get());
|
|
2441
|
+
}
|
|
2442
|
+
unsetIndices(indices) {
|
|
2443
|
+
if (!Array.isArray(this._value))
|
|
2444
|
+
throw new Error("unsetIndices only applies to arrays");
|
|
2445
|
+
const length = this._value.length, nextValue = [];
|
|
2446
|
+
for (let i = 0; i < length; i++)
|
|
2447
|
+
indices.indexOf(i) === -1 && nextValue.push(this._value[i]);
|
|
2448
|
+
return new ImmutableAccessor(nextValue, this.path);
|
|
2449
|
+
}
|
|
2450
|
+
insertItemsAt(pos, items) {
|
|
2451
|
+
if (!Array.isArray(this._value))
|
|
2452
|
+
throw new Error("insertItemsAt only applies to arrays");
|
|
2453
|
+
let nextValue;
|
|
2454
|
+
return this._value.length === 0 && pos === 0 ? nextValue = items : nextValue = this._value.slice(0, pos).concat(items).concat(this._value.slice(pos)), new ImmutableAccessor(nextValue, this.path);
|
|
2455
|
+
}
|
|
2456
|
+
// Object writer interface
|
|
2457
|
+
setAttribute(key, value) {
|
|
2458
|
+
if (!isRecord$1(this._value))
|
|
2459
|
+
throw new Error("Unable to set attribute of non-object container");
|
|
2460
|
+
if (Object.is(value, this._value[key]))
|
|
2461
|
+
return this;
|
|
2462
|
+
const nextValue = Object.assign({}, this._value, { [key]: value });
|
|
2463
|
+
return new ImmutableAccessor(nextValue, this.path);
|
|
2464
|
+
}
|
|
2465
|
+
setAttributeAccessor(key, accessor) {
|
|
2466
|
+
return this.setAttribute(key, accessor.get());
|
|
2467
|
+
}
|
|
2468
|
+
unsetAttribute(key) {
|
|
2469
|
+
if (!isRecord$1(this._value))
|
|
2470
|
+
throw new Error("Unable to unset attribute of non-object container");
|
|
2471
|
+
const nextValue = Object.assign({}, this._value);
|
|
2472
|
+
return delete nextValue[key], new ImmutableAccessor(nextValue, this.path);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
function isRecord$1(value) {
|
|
2476
|
+
return value !== null && typeof value == "object";
|
|
2477
|
+
}
|
|
2478
|
+
function isRecord(value) {
|
|
2479
|
+
return value !== null && typeof value == "object";
|
|
2480
|
+
}
|
|
2481
|
+
function descend$1(tail) {
|
|
2482
|
+
const [head, newTail] = splitIfPath(tail);
|
|
2483
|
+
if (!head)
|
|
2484
|
+
throw new Error("Head cannot be null");
|
|
2485
|
+
return spreadIfUnionHead(head, newTail);
|
|
2486
|
+
}
|
|
2487
|
+
function splitIfPath(tail) {
|
|
2488
|
+
if (tail.type !== "path")
|
|
2489
|
+
return [tail, null];
|
|
2490
|
+
const nodes = tail.nodes;
|
|
2491
|
+
return nodes.length === 0 ? [null, null] : nodes.length === 1 ? [nodes[0], null] : [nodes[0], { type: "path", nodes: nodes.slice(1) }];
|
|
2492
|
+
}
|
|
2493
|
+
function concatPaths(path1, path2) {
|
|
2494
|
+
if (!path1 && !path2)
|
|
2495
|
+
return null;
|
|
2496
|
+
const nodes1 = path1 ? path1.nodes : [], nodes2 = path2 ? path2.nodes : [];
|
|
2497
|
+
return {
|
|
2498
|
+
type: "path",
|
|
2499
|
+
nodes: nodes1.concat(nodes2)
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
function spreadIfUnionHead(head, tail) {
|
|
2503
|
+
return head.type !== "union" ? [[head, tail]] : head.nodes.map((node2) => {
|
|
2504
|
+
if (node2.type === "path") {
|
|
2505
|
+
const [subHead, subTail] = splitIfPath(node2);
|
|
2506
|
+
return [subHead, concatPaths(subTail, tail)];
|
|
2507
|
+
}
|
|
2508
|
+
return [node2, tail];
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
var __defProp$g = Object.defineProperty, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$g = (obj, key, value) => __defNormalProp$g(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
2512
|
+
const digitChar = /[0-9]/, attributeCharMatcher = /^[a-zA-Z0-9_]$/, attributeFirstCharMatcher = /^[a-zA-Z_]$/, symbols = {
|
|
2513
|
+
// NOTE: These are compared against in order of definition,
|
|
2514
|
+
// thus '==' must come before '=', '>=' before '>', etc.
|
|
2515
|
+
operator: ["..", ".", ",", ":", "?"],
|
|
2516
|
+
comparator: [">=", "<=", "<", ">", "==", "!="],
|
|
2517
|
+
keyword: ["$", "@"],
|
|
2518
|
+
boolean: ["true", "false"],
|
|
2519
|
+
paren: ["[", "]"]
|
|
2520
|
+
}, symbolClasses = Object.keys(symbols);
|
|
2521
|
+
class Tokenizer {
|
|
2522
|
+
constructor(path) {
|
|
2523
|
+
__publicField$g(this, "source"), __publicField$g(this, "i"), __publicField$g(this, "length"), __publicField$g(this, "tokenizers"), this.source = path, this.length = path.length, this.i = 0, this.tokenizers = [
|
|
2524
|
+
this.tokenizeSymbol,
|
|
2525
|
+
this.tokenizeIdentifier,
|
|
2526
|
+
this.tokenizeNumber,
|
|
2527
|
+
this.tokenizeQuoted
|
|
2528
|
+
].map((fn) => fn.bind(this));
|
|
2529
|
+
}
|
|
2530
|
+
tokenize() {
|
|
2531
|
+
const result = [];
|
|
2532
|
+
for (; !this.EOF(); ) {
|
|
2533
|
+
this.chompWhitespace();
|
|
2534
|
+
let token = null;
|
|
2535
|
+
if (!this.tokenizers.some((tokenizer) => (token = tokenizer(), !!token)) || !token)
|
|
2536
|
+
throw new Error(`Invalid tokens in jsonpath '${this.source}' @ ${this.i}`);
|
|
2537
|
+
result.push(token);
|
|
2538
|
+
}
|
|
2539
|
+
return result;
|
|
2540
|
+
}
|
|
2541
|
+
takeWhile(fn) {
|
|
2542
|
+
const start = this.i;
|
|
2543
|
+
let result = "";
|
|
2544
|
+
for (; !this.EOF(); ) {
|
|
2545
|
+
const nextChar = fn(this.source[this.i]);
|
|
2546
|
+
if (nextChar === null)
|
|
2547
|
+
break;
|
|
2548
|
+
result += nextChar, this.i++;
|
|
2549
|
+
}
|
|
2550
|
+
return this.i === start ? null : result;
|
|
2551
|
+
}
|
|
2552
|
+
EOF() {
|
|
2553
|
+
return this.i >= this.length;
|
|
2554
|
+
}
|
|
2555
|
+
peek() {
|
|
2556
|
+
return this.EOF() ? null : this.source[this.i];
|
|
2557
|
+
}
|
|
2558
|
+
consume(str) {
|
|
2559
|
+
if (this.i + str.length > this.length)
|
|
2560
|
+
throw new Error(`Expected ${str} at end of jsonpath`);
|
|
2561
|
+
if (str === this.source.slice(this.i, this.i + str.length))
|
|
2562
|
+
this.i += str.length;
|
|
2563
|
+
else
|
|
2564
|
+
throw new Error(`Expected "${str}", but source contained "${this.source.slice()}`);
|
|
2565
|
+
}
|
|
2566
|
+
// Tries to match the upcoming bit of string with the provided string. If it matches, returns
|
|
2567
|
+
// the string, then advances the read pointer to the next bit. If not, returns null and nothing
|
|
2568
|
+
// happens.
|
|
2569
|
+
tryConsume(str) {
|
|
2570
|
+
if (this.i + str.length > this.length)
|
|
2571
|
+
return null;
|
|
2572
|
+
if (str === this.source.slice(this.i, this.i + str.length)) {
|
|
2573
|
+
if (str[0].match(attributeCharMatcher) && this.length > this.i + str.length) {
|
|
2574
|
+
const nextChar = this.source[this.i + str.length];
|
|
2575
|
+
if (nextChar && nextChar.match(attributeCharMatcher))
|
|
2576
|
+
return null;
|
|
2577
|
+
}
|
|
2578
|
+
return this.i += str.length, str;
|
|
2579
|
+
}
|
|
2580
|
+
return null;
|
|
2581
|
+
}
|
|
2582
|
+
chompWhitespace() {
|
|
2583
|
+
this.takeWhile((char) => char === " " ? "" : null);
|
|
2584
|
+
}
|
|
2585
|
+
tokenizeQuoted() {
|
|
2586
|
+
const quote = this.peek();
|
|
2587
|
+
if (quote === "'" || quote === '"') {
|
|
2588
|
+
this.consume(quote);
|
|
2589
|
+
let escape = !1;
|
|
2590
|
+
const inner = this.takeWhile((char) => escape ? (escape = !1, char) : char === "\\" ? (escape = !0, "") : char != quote ? char : null);
|
|
2591
|
+
return this.consume(quote), {
|
|
2592
|
+
type: "quoted",
|
|
2593
|
+
value: inner,
|
|
2594
|
+
quote: quote === '"' ? "double" : "single"
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
return null;
|
|
2598
|
+
}
|
|
2599
|
+
tokenizeIdentifier() {
|
|
2600
|
+
let first = !0;
|
|
2601
|
+
const identifier = this.takeWhile((char) => first ? (first = !1, char.match(attributeFirstCharMatcher) ? char : null) : char.match(attributeCharMatcher) ? char : null);
|
|
2602
|
+
return identifier !== null ? {
|
|
2603
|
+
type: "identifier",
|
|
2604
|
+
name: identifier
|
|
2605
|
+
} : null;
|
|
2606
|
+
}
|
|
2607
|
+
tokenizeNumber() {
|
|
2608
|
+
const start = this.i;
|
|
2609
|
+
let dotSeen = !1, digitSeen = !1, negative = !1;
|
|
2610
|
+
this.peek() === "-" && (negative = !0, this.consume("-"));
|
|
2611
|
+
const number = this.takeWhile((char) => char === "." && !dotSeen && digitSeen ? (dotSeen = !0, char) : (digitSeen = !0, char.match(digitChar) ? char : null));
|
|
2612
|
+
return number !== null ? {
|
|
2613
|
+
type: "number",
|
|
2614
|
+
value: negative ? -number : +number,
|
|
2615
|
+
raw: negative ? `-${number}` : number
|
|
2616
|
+
} : (this.i = start, null);
|
|
2617
|
+
}
|
|
2618
|
+
tokenizeSymbol() {
|
|
2619
|
+
for (const symbolClass of symbolClasses) {
|
|
2620
|
+
const symbol = symbols[symbolClass].find((pattern) => this.tryConsume(pattern));
|
|
2621
|
+
if (symbol)
|
|
2622
|
+
return {
|
|
2623
|
+
type: symbolClass,
|
|
2624
|
+
symbol
|
|
2625
|
+
};
|
|
2626
|
+
}
|
|
2627
|
+
return null;
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
function tokenize(jsonpath) {
|
|
2631
|
+
return new Tokenizer(jsonpath).tokenize();
|
|
2632
|
+
}
|
|
2633
|
+
var __defProp$f = Object.defineProperty, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$f = (obj, key, value) => __defNormalProp$f(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
2634
|
+
class Parser {
|
|
2635
|
+
constructor(path) {
|
|
2636
|
+
__publicField$f(this, "tokens"), __publicField$f(this, "length"), __publicField$f(this, "i"), this.tokens = tokenize(path), this.length = this.tokens.length, this.i = 0;
|
|
2637
|
+
}
|
|
2638
|
+
parse() {
|
|
2639
|
+
return this.parsePath();
|
|
2640
|
+
}
|
|
2641
|
+
EOF() {
|
|
2642
|
+
return this.i >= this.length;
|
|
2643
|
+
}
|
|
2644
|
+
// Look at upcoming token
|
|
2645
|
+
peek() {
|
|
2646
|
+
return this.EOF() ? null : this.tokens[this.i];
|
|
2647
|
+
}
|
|
2648
|
+
consume() {
|
|
2649
|
+
const result = this.peek();
|
|
2650
|
+
return this.i += 1, result;
|
|
2651
|
+
}
|
|
2652
|
+
// Return next token if it matches the pattern
|
|
2653
|
+
probe(pattern) {
|
|
2654
|
+
const token = this.peek();
|
|
2655
|
+
if (!token)
|
|
2656
|
+
return null;
|
|
2657
|
+
const record = token;
|
|
2658
|
+
return Object.keys(pattern).every((key) => key in token && pattern[key] === record[key]) ? token : null;
|
|
2659
|
+
}
|
|
2660
|
+
// Return and consume next token if it matches the pattern
|
|
2661
|
+
match(pattern) {
|
|
2662
|
+
return this.probe(pattern) ? this.consume() : null;
|
|
2663
|
+
}
|
|
2664
|
+
parseAttribute() {
|
|
2665
|
+
const token = this.match({ type: "identifier" });
|
|
2666
|
+
if (token && token.type === "identifier")
|
|
2667
|
+
return {
|
|
2668
|
+
type: "attribute",
|
|
2669
|
+
name: token.name
|
|
2670
|
+
};
|
|
2671
|
+
const quoted = this.match({ type: "quoted", quote: "single" });
|
|
2672
|
+
return quoted && quoted.type === "quoted" ? {
|
|
2673
|
+
type: "attribute",
|
|
2674
|
+
name: quoted.value || ""
|
|
2675
|
+
} : null;
|
|
2676
|
+
}
|
|
2677
|
+
parseAlias() {
|
|
2678
|
+
return this.match({ type: "keyword", symbol: "@" }) || this.match({ type: "keyword", symbol: "$" }) ? {
|
|
2679
|
+
type: "alias",
|
|
2680
|
+
target: "self"
|
|
2681
|
+
} : null;
|
|
2682
|
+
}
|
|
2683
|
+
parseNumber() {
|
|
2684
|
+
const token = this.match({ type: "number" });
|
|
2685
|
+
return token && token.type === "number" ? {
|
|
2686
|
+
type: "number",
|
|
2687
|
+
value: token.value
|
|
2688
|
+
} : null;
|
|
2689
|
+
}
|
|
2690
|
+
parseNumberValue() {
|
|
2691
|
+
const expr = this.parseNumber();
|
|
2692
|
+
return expr ? expr.value : null;
|
|
2693
|
+
}
|
|
2694
|
+
parseSliceSelector() {
|
|
2695
|
+
const start = this.i, rangeStart = this.parseNumberValue();
|
|
2696
|
+
if (!this.match({ type: "operator", symbol: ":" }))
|
|
2697
|
+
return rangeStart === null ? (this.i = start, null) : { type: "index", value: rangeStart };
|
|
2698
|
+
const result = {
|
|
2699
|
+
type: "range",
|
|
2700
|
+
start: rangeStart,
|
|
2701
|
+
end: this.parseNumberValue()
|
|
2702
|
+
};
|
|
2703
|
+
return this.match({ type: "operator", symbol: ":" }) && (result.step = this.parseNumberValue()), result.start === null && result.end === null ? (this.i = start, null) : result;
|
|
2704
|
+
}
|
|
2705
|
+
parseValueReference() {
|
|
2706
|
+
return this.parseAttribute() || this.parseSliceSelector();
|
|
2707
|
+
}
|
|
2708
|
+
parseLiteralValue() {
|
|
2709
|
+
const literalString = this.match({ type: "quoted", quote: "double" });
|
|
2710
|
+
if (literalString && literalString.type === "quoted")
|
|
2711
|
+
return {
|
|
2712
|
+
type: "string",
|
|
2713
|
+
value: literalString.value || ""
|
|
2714
|
+
};
|
|
2715
|
+
const literalBoolean = this.match({ type: "boolean" });
|
|
2716
|
+
return literalBoolean && literalBoolean.type === "boolean" ? {
|
|
2717
|
+
type: "boolean",
|
|
2718
|
+
value: literalBoolean.symbol === "true"
|
|
2719
|
+
} : this.parseNumber();
|
|
2720
|
+
}
|
|
2721
|
+
// TODO: Reorder constraints so that literal value is always on rhs, and variable is always
|
|
2722
|
+
// on lhs.
|
|
2723
|
+
parseFilterExpression() {
|
|
2724
|
+
const start = this.i, expr = this.parseAttribute() || this.parseAlias();
|
|
2725
|
+
if (!expr)
|
|
2726
|
+
return null;
|
|
2727
|
+
if (this.match({ type: "operator", symbol: "?" }))
|
|
2728
|
+
return {
|
|
2729
|
+
type: "constraint",
|
|
2730
|
+
operator: "?",
|
|
2731
|
+
lhs: expr
|
|
2732
|
+
};
|
|
2733
|
+
const binOp = this.match({ type: "comparator" });
|
|
2734
|
+
if (!binOp || binOp.type !== "comparator")
|
|
2735
|
+
return this.i = start, null;
|
|
2736
|
+
const lhs = expr, rhs = this.parseLiteralValue();
|
|
2737
|
+
if (!rhs)
|
|
2738
|
+
throw new Error(`Operator ${binOp.symbol} needs a literal value at the right hand side`);
|
|
2739
|
+
return {
|
|
2740
|
+
type: "constraint",
|
|
2741
|
+
operator: binOp.symbol,
|
|
2742
|
+
lhs,
|
|
2743
|
+
rhs
|
|
2744
|
+
};
|
|
2745
|
+
}
|
|
2746
|
+
parseExpression() {
|
|
2747
|
+
return this.parseFilterExpression() || this.parseValueReference();
|
|
2748
|
+
}
|
|
2749
|
+
parseUnion() {
|
|
2750
|
+
if (!this.match({ type: "paren", symbol: "[" }))
|
|
2751
|
+
return null;
|
|
2752
|
+
const terms = [];
|
|
2753
|
+
let expr = this.parseFilterExpression() || this.parsePath() || this.parseValueReference();
|
|
2754
|
+
for (; expr && (terms.push(expr), !this.match({ type: "paren", symbol: "]" })); ) {
|
|
2755
|
+
if (!this.match({ type: "operator", symbol: "," }))
|
|
2756
|
+
throw new Error("Expected ]");
|
|
2757
|
+
if (expr = this.parseFilterExpression() || this.parsePath() || this.parseValueReference(), !expr)
|
|
2758
|
+
throw new Error("Expected expression following ','");
|
|
2759
|
+
}
|
|
2760
|
+
return {
|
|
2761
|
+
type: "union",
|
|
2762
|
+
nodes: terms
|
|
2763
|
+
};
|
|
2764
|
+
}
|
|
2765
|
+
parseRecursive() {
|
|
2766
|
+
if (!this.match({ type: "operator", symbol: ".." }))
|
|
2767
|
+
return null;
|
|
2768
|
+
const subpath = this.parsePath();
|
|
2769
|
+
if (!subpath)
|
|
2770
|
+
throw new Error("Expected path following '..' operator");
|
|
2771
|
+
return {
|
|
2772
|
+
type: "recursive",
|
|
2773
|
+
term: subpath
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
parsePath() {
|
|
2777
|
+
const nodes = [], expr = this.parseAttribute() || this.parseUnion() || this.parseRecursive();
|
|
2778
|
+
if (!expr)
|
|
2779
|
+
return null;
|
|
2780
|
+
for (nodes.push(expr); !this.EOF(); )
|
|
2781
|
+
if (this.match({ type: "operator", symbol: "." })) {
|
|
2782
|
+
const attr = this.parseAttribute();
|
|
2783
|
+
if (!attr)
|
|
2784
|
+
throw new Error("Expected attribute name following '.");
|
|
2785
|
+
nodes.push(attr);
|
|
2786
|
+
continue;
|
|
2787
|
+
} else if (this.probe({ type: "paren", symbol: "[" })) {
|
|
2788
|
+
const union = this.parseUnion();
|
|
2789
|
+
if (!union)
|
|
2790
|
+
throw new Error("Expected union following '['");
|
|
2791
|
+
nodes.push(union);
|
|
2792
|
+
} else {
|
|
2793
|
+
const recursive = this.parseRecursive();
|
|
2794
|
+
recursive && nodes.push(recursive);
|
|
2795
|
+
break;
|
|
2796
|
+
}
|
|
2797
|
+
return nodes.length === 1 ? nodes[0] : {
|
|
2798
|
+
type: "path",
|
|
2799
|
+
nodes
|
|
2800
|
+
};
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
function parseJsonPath(path) {
|
|
2804
|
+
const parsed = new Parser(path).parse();
|
|
2805
|
+
if (!parsed)
|
|
2806
|
+
throw new Error(`Failed to parse JSON path "${path}"`);
|
|
2807
|
+
return parsed;
|
|
2808
|
+
}
|
|
2809
|
+
function toPath(expr) {
|
|
2810
|
+
return toPathInner(expr, !1);
|
|
2811
|
+
}
|
|
2812
|
+
function toPathInner(expr, inUnion) {
|
|
2813
|
+
switch (expr.type) {
|
|
2814
|
+
case "attribute":
|
|
2815
|
+
return expr.name;
|
|
2816
|
+
case "alias":
|
|
2817
|
+
return expr.target === "self" ? "@" : "$";
|
|
2818
|
+
case "number":
|
|
2819
|
+
return `${expr.value}`;
|
|
2820
|
+
case "range": {
|
|
2821
|
+
const result = [];
|
|
2822
|
+
return inUnion || result.push("["), expr.start && result.push(`${expr.start}`), result.push(":"), expr.end && result.push(`${expr.end}`), expr.step && result.push(`:${expr.step}`), inUnion || result.push("]"), result.join("");
|
|
2823
|
+
}
|
|
2824
|
+
case "index":
|
|
2825
|
+
return inUnion ? `${expr.value}` : `[${expr.value}]`;
|
|
2826
|
+
case "constraint": {
|
|
2827
|
+
const rhs = expr.rhs ? ` ${toPathInner(expr.rhs, !1)}` : "", inner = `${toPathInner(expr.lhs, !1)} ${expr.operator}${rhs}`;
|
|
2828
|
+
return inUnion ? inner : `[${inner}]`;
|
|
2829
|
+
}
|
|
2830
|
+
case "string":
|
|
2831
|
+
return JSON.stringify(expr.value);
|
|
2832
|
+
case "path": {
|
|
2833
|
+
const result = [], nodes = expr.nodes.slice();
|
|
2834
|
+
for (; nodes.length > 0; ) {
|
|
2835
|
+
const node2 = nodes.shift();
|
|
2836
|
+
node2 && result.push(toPath(node2));
|
|
2837
|
+
const upcoming = nodes[0];
|
|
2838
|
+
upcoming && toPathInner(upcoming, !1)[0] !== "[" && result.push(".");
|
|
2839
|
+
}
|
|
2840
|
+
return result.join("");
|
|
2841
|
+
}
|
|
2842
|
+
case "union":
|
|
2843
|
+
return `[${expr.nodes.map((e) => toPathInner(e, !0)).join(",")}]`;
|
|
2844
|
+
default:
|
|
2845
|
+
throw new Error(`Unknown node type ${expr.type}`);
|
|
2846
|
+
case "recursive":
|
|
2847
|
+
return `..${toPathInner(expr.term, !1)}`;
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
var __defProp$e = Object.defineProperty, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$e = (obj, key, value) => __defNormalProp$e(obj, key + "", value);
|
|
2851
|
+
class Expression {
|
|
2852
|
+
constructor(expr) {
|
|
2853
|
+
if (__publicField$e(this, "expr"), !expr)
|
|
2854
|
+
throw new Error("Attempted to create Expression from null-value");
|
|
2855
|
+
if ("expr" in expr ? this.expr = expr.expr : this.expr = expr, !("type" in this.expr))
|
|
2856
|
+
throw new Error("Attempt to create Expression for expression with no type");
|
|
2857
|
+
}
|
|
2858
|
+
isPath() {
|
|
2859
|
+
return this.expr.type === "path";
|
|
2860
|
+
}
|
|
2861
|
+
isUnion() {
|
|
2862
|
+
return this.expr.type === "union";
|
|
2863
|
+
}
|
|
2864
|
+
isCollection() {
|
|
2865
|
+
return this.isPath() || this.isUnion();
|
|
2866
|
+
}
|
|
2867
|
+
isConstraint() {
|
|
2868
|
+
return this.expr.type === "constraint";
|
|
2869
|
+
}
|
|
2870
|
+
isRecursive() {
|
|
2871
|
+
return this.expr.type === "recursive";
|
|
2872
|
+
}
|
|
2873
|
+
isExistenceConstraint() {
|
|
2874
|
+
return this.expr.type === "constraint" && this.expr.operator === "?";
|
|
2875
|
+
}
|
|
2876
|
+
isIndex() {
|
|
2877
|
+
return this.expr.type === "index";
|
|
2878
|
+
}
|
|
2879
|
+
isRange() {
|
|
2880
|
+
return this.expr.type === "range";
|
|
2881
|
+
}
|
|
2882
|
+
expandRange(probe) {
|
|
2883
|
+
const probeLength = () => {
|
|
2884
|
+
if (!probe)
|
|
2885
|
+
throw new Error("expandRange() required a probe that was not passed");
|
|
2886
|
+
return probe.length();
|
|
2887
|
+
};
|
|
2888
|
+
let start = "start" in this.expr && this.expr.start || 0;
|
|
2889
|
+
start = interpretNegativeIndex(start, probe);
|
|
2890
|
+
let end = "end" in this.expr && this.expr.end || probeLength();
|
|
2891
|
+
end = interpretNegativeIndex(end, probe);
|
|
2892
|
+
const step = "step" in this.expr && this.expr.step || 1;
|
|
2893
|
+
return { start, end, step };
|
|
2894
|
+
}
|
|
2895
|
+
isAttributeReference() {
|
|
2896
|
+
return this.expr.type === "attribute";
|
|
2897
|
+
}
|
|
2898
|
+
// Is a range or index -> something referencing indexes
|
|
2899
|
+
isIndexReference() {
|
|
2900
|
+
return this.isIndex() || this.isRange();
|
|
2901
|
+
}
|
|
2902
|
+
name() {
|
|
2903
|
+
return "name" in this.expr ? this.expr.name : "";
|
|
2904
|
+
}
|
|
2905
|
+
isSelfReference() {
|
|
2906
|
+
return this.expr.type === "alias" && this.expr.target === "self";
|
|
2907
|
+
}
|
|
2908
|
+
constraintTargetIsSelf() {
|
|
2909
|
+
return this.expr.type === "constraint" && this.expr.lhs.type === "alias" && this.expr.lhs.target === "self";
|
|
2910
|
+
}
|
|
2911
|
+
constraintTargetIsAttribute() {
|
|
2912
|
+
return this.expr.type === "constraint" && this.expr.lhs.type === "attribute";
|
|
2913
|
+
}
|
|
2914
|
+
testConstraint(probe) {
|
|
2915
|
+
const expr = this.expr;
|
|
2916
|
+
if (expr.type === "constraint" && expr.lhs.type === "alias" && expr.lhs.target === "self") {
|
|
2917
|
+
if (probe.containerType() !== "primitive")
|
|
2918
|
+
return !1;
|
|
2919
|
+
if (expr.type === "constraint" && expr.operator === "?")
|
|
2920
|
+
return !0;
|
|
2921
|
+
const lhs2 = probe.get(), rhs2 = expr.rhs && "value" in expr.rhs ? expr.rhs.value : void 0;
|
|
2922
|
+
return testBinaryOperator(lhs2, expr.operator, rhs2);
|
|
2923
|
+
}
|
|
2924
|
+
if (expr.type !== "constraint")
|
|
2925
|
+
return !1;
|
|
2926
|
+
const lhs = expr.lhs;
|
|
2927
|
+
if (!lhs)
|
|
2928
|
+
throw new Error("No LHS of expression");
|
|
2929
|
+
if (lhs.type !== "attribute")
|
|
2930
|
+
throw new Error(`Constraint target ${lhs.type} not supported`);
|
|
2931
|
+
if (probe.containerType() !== "object")
|
|
2932
|
+
return !1;
|
|
2933
|
+
const lhsValue = probe.getAttribute(lhs.name);
|
|
2934
|
+
if (lhsValue == null || lhsValue.containerType() !== "primitive")
|
|
2935
|
+
return !1;
|
|
2936
|
+
if (this.isExistenceConstraint())
|
|
2937
|
+
return !0;
|
|
2938
|
+
const rhs = expr.rhs && "value" in expr.rhs ? expr.rhs.value : void 0;
|
|
2939
|
+
return testBinaryOperator(lhsValue.get(), expr.operator, rhs);
|
|
2940
|
+
}
|
|
2941
|
+
pathNodes() {
|
|
2942
|
+
return this.expr.type === "path" ? this.expr.nodes : [this.expr];
|
|
2943
|
+
}
|
|
2944
|
+
prepend(node2) {
|
|
2945
|
+
return node2 ? new Expression({
|
|
2946
|
+
type: "path",
|
|
2947
|
+
nodes: node2.pathNodes().concat(this.pathNodes())
|
|
2948
|
+
}) : this;
|
|
2949
|
+
}
|
|
2950
|
+
concat(other) {
|
|
2951
|
+
return other ? other.prepend(this) : this;
|
|
2952
|
+
}
|
|
2953
|
+
descend() {
|
|
2954
|
+
return descend$1(this.expr).map((headTail) => {
|
|
2955
|
+
const [head, tail] = headTail;
|
|
2956
|
+
return {
|
|
2957
|
+
head: head ? new Expression(head) : null,
|
|
2958
|
+
tail: tail ? new Expression(tail) : null
|
|
2959
|
+
};
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
2962
|
+
unwrapRecursive() {
|
|
2963
|
+
if (this.expr.type !== "recursive")
|
|
2964
|
+
throw new Error(`Attempt to unwrap recursive on type ${this.expr.type}`);
|
|
2965
|
+
return new Expression(this.expr.term);
|
|
2966
|
+
}
|
|
2967
|
+
toIndicies(probe) {
|
|
2968
|
+
if (this.expr.type !== "index" && this.expr.type !== "range")
|
|
2969
|
+
throw new Error("Node cannot be converted to indexes");
|
|
2970
|
+
if (this.expr.type === "index")
|
|
2971
|
+
return [interpretNegativeIndex(this.expr.value, probe)];
|
|
2972
|
+
const result = [], range = this.expandRange(probe);
|
|
2973
|
+
let { start, end } = range;
|
|
2974
|
+
range.step < 0 && ([start, end] = [end, start]);
|
|
2975
|
+
for (let i = start; i < end; i++)
|
|
2976
|
+
result.push(i);
|
|
2977
|
+
return result;
|
|
2978
|
+
}
|
|
2979
|
+
toFieldReferences() {
|
|
2980
|
+
if (this.isIndexReference())
|
|
2981
|
+
return this.toIndicies();
|
|
2982
|
+
if (this.expr.type === "attribute")
|
|
2983
|
+
return [this.expr.name];
|
|
2984
|
+
throw new Error(`Can't convert ${this.expr.type} to field references`);
|
|
2985
|
+
}
|
|
2986
|
+
toString() {
|
|
2987
|
+
return toPath(this.expr);
|
|
2988
|
+
}
|
|
2989
|
+
static fromPath(path) {
|
|
2990
|
+
const parsed = parseJsonPath(path);
|
|
2991
|
+
if (!parsed)
|
|
2992
|
+
throw new Error(`Failed to parse path "${path}"`);
|
|
2993
|
+
return new Expression(parsed);
|
|
2994
|
+
}
|
|
2995
|
+
static attributeReference(name) {
|
|
2996
|
+
return new Expression({
|
|
2997
|
+
type: "attribute",
|
|
2998
|
+
name
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
static indexReference(i) {
|
|
3002
|
+
return new Expression({
|
|
3003
|
+
type: "index",
|
|
3004
|
+
value: i
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
function testBinaryOperator(lhsValue, operator, rhsValue) {
|
|
3009
|
+
switch (operator) {
|
|
3010
|
+
case ">":
|
|
3011
|
+
return lhsValue > rhsValue;
|
|
3012
|
+
case ">=":
|
|
3013
|
+
return lhsValue >= rhsValue;
|
|
3014
|
+
case "<":
|
|
3015
|
+
return lhsValue < rhsValue;
|
|
3016
|
+
case "<=":
|
|
3017
|
+
return lhsValue <= rhsValue;
|
|
3018
|
+
case "==":
|
|
3019
|
+
return lhsValue === rhsValue;
|
|
3020
|
+
case "!=":
|
|
3021
|
+
return lhsValue !== rhsValue;
|
|
3022
|
+
default:
|
|
3023
|
+
throw new Error(`Unsupported binary operator ${operator}`);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3026
|
+
function interpretNegativeIndex(index, probe) {
|
|
3027
|
+
if (index >= 0)
|
|
3028
|
+
return index;
|
|
3029
|
+
if (!probe)
|
|
3030
|
+
throw new Error("interpretNegativeIndex() must have a probe when < 0");
|
|
3031
|
+
return index + probe.length();
|
|
3032
|
+
}
|
|
3033
|
+
var __defProp$d = Object.defineProperty, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$d = (obj, key, value) => __defNormalProp$d(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3034
|
+
class Descender {
|
|
3035
|
+
constructor(head, tail) {
|
|
3036
|
+
__publicField$d(this, "head"), __publicField$d(this, "tail"), this.head = head, this.tail = tail;
|
|
3037
|
+
}
|
|
3038
|
+
// Iterate this descender once processing any constraints that are
|
|
3039
|
+
// resolvable on the current value. Returns an array of new descenders
|
|
3040
|
+
// that are guaranteed to be without constraints in the head
|
|
3041
|
+
iterate(probe) {
|
|
3042
|
+
let result = [this];
|
|
3043
|
+
if (this.head && this.head.isConstraint()) {
|
|
3044
|
+
let anyConstraints = !0;
|
|
3045
|
+
for (; anyConstraints; )
|
|
3046
|
+
result = flatten$1(
|
|
3047
|
+
result.map((descender) => descender.iterateConstraints(probe))
|
|
3048
|
+
), anyConstraints = result.some((descender) => descender.head && descender.head.isConstraint());
|
|
3049
|
+
}
|
|
3050
|
+
return result;
|
|
3051
|
+
}
|
|
3052
|
+
isRecursive() {
|
|
3053
|
+
return !!(this.head && this.head.isRecursive());
|
|
3054
|
+
}
|
|
3055
|
+
hasArrived() {
|
|
3056
|
+
return this.head === null && this.tail === null;
|
|
3057
|
+
}
|
|
3058
|
+
extractRecursives() {
|
|
3059
|
+
if (this.head && this.head.isRecursive()) {
|
|
3060
|
+
const term = this.head.unwrapRecursive();
|
|
3061
|
+
return new Descender(null, term.concat(this.tail)).descend();
|
|
3062
|
+
}
|
|
3063
|
+
return [];
|
|
3064
|
+
}
|
|
3065
|
+
iterateConstraints(probe) {
|
|
3066
|
+
const head = this.head;
|
|
3067
|
+
if (head === null || !head.isConstraint())
|
|
3068
|
+
return [this];
|
|
3069
|
+
const result = [];
|
|
3070
|
+
if (probe.containerType() === "primitive" && head.constraintTargetIsSelf())
|
|
3071
|
+
return head.testConstraint(probe) && result.push(...this.descend()), result;
|
|
3072
|
+
if (probe.containerType() === "array") {
|
|
3073
|
+
const length = probe.length();
|
|
3074
|
+
for (let i = 0; i < length; i++) {
|
|
3075
|
+
const constraint = probe.getIndex(i);
|
|
3076
|
+
constraint && head.testConstraint(constraint) && result.push(new Descender(new Expression({ type: "index", value: i }), this.tail));
|
|
3077
|
+
}
|
|
3078
|
+
return result;
|
|
3079
|
+
}
|
|
3080
|
+
return probe.containerType() === "object" ? head.constraintTargetIsSelf() ? [] : head.testConstraint(probe) ? this.descend() : result : result;
|
|
3081
|
+
}
|
|
3082
|
+
descend() {
|
|
3083
|
+
return this.tail ? this.tail.descend().map((ht) => new Descender(ht.head, ht.tail)) : [new Descender(null, null)];
|
|
3084
|
+
}
|
|
3085
|
+
toString() {
|
|
3086
|
+
const result = ["<"];
|
|
3087
|
+
return this.head && result.push(this.head.toString()), result.push("|"), this.tail && result.push(this.tail.toString()), result.push(">"), result.join("");
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
var __defProp$c = Object.defineProperty, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$c = (obj, key, value) => __defNormalProp$c(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3091
|
+
class Matcher {
|
|
3092
|
+
constructor(active, parent) {
|
|
3093
|
+
__publicField$c(this, "active"), __publicField$c(this, "recursives"), __publicField$c(this, "payload"), this.active = active || [], parent ? (this.recursives = parent.recursives, this.payload = parent.payload) : this.recursives = [], this.extractRecursives();
|
|
3094
|
+
}
|
|
3095
|
+
setPayload(payload) {
|
|
3096
|
+
return this.payload = payload, this;
|
|
3097
|
+
}
|
|
3098
|
+
// Moves any recursive descenders onto the recursive track, removing them from
|
|
3099
|
+
// the active set
|
|
3100
|
+
extractRecursives() {
|
|
3101
|
+
this.active = this.active.filter((descender) => descender.isRecursive() ? (this.recursives.push(...descender.extractRecursives()), !1) : !0);
|
|
3102
|
+
}
|
|
3103
|
+
// Find recursives that are relevant now and should be considered part of the active set
|
|
3104
|
+
activeRecursives(probe) {
|
|
3105
|
+
return this.recursives.filter((descender) => {
|
|
3106
|
+
const head = descender.head;
|
|
3107
|
+
return head ? head.isConstraint() || probe.containerType() === "array" && head.isIndexReference() ? !0 : probe.containerType() === "object" ? head.isAttributeReference() && probe.hasAttribute(head.name()) : !1 : !1;
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
match(probe) {
|
|
3111
|
+
return this.iterate(probe).extractMatches(probe);
|
|
3112
|
+
}
|
|
3113
|
+
iterate(probe) {
|
|
3114
|
+
const newActiveSet = [];
|
|
3115
|
+
return this.active.concat(this.activeRecursives(probe)).forEach((descender) => {
|
|
3116
|
+
newActiveSet.push(...descender.iterate(probe));
|
|
3117
|
+
}), new Matcher(newActiveSet, this);
|
|
3118
|
+
}
|
|
3119
|
+
// Returns true if any of the descenders in the active or recursive set
|
|
3120
|
+
// consider the current state a final destination
|
|
3121
|
+
isDestination() {
|
|
3122
|
+
return this.active.some((descender) => descender.hasArrived());
|
|
3123
|
+
}
|
|
3124
|
+
hasRecursives() {
|
|
3125
|
+
return this.recursives.length > 0;
|
|
3126
|
+
}
|
|
3127
|
+
// Returns any payload delivieries and leads that needs to be followed to complete
|
|
3128
|
+
// the process.
|
|
3129
|
+
extractMatches(probe) {
|
|
3130
|
+
const leads = [], targets = [];
|
|
3131
|
+
if (this.active.forEach((descender) => {
|
|
3132
|
+
if (descender.hasArrived()) {
|
|
3133
|
+
targets.push(
|
|
3134
|
+
new Expression({
|
|
3135
|
+
type: "alias",
|
|
3136
|
+
target: "self"
|
|
3137
|
+
})
|
|
3138
|
+
);
|
|
3139
|
+
return;
|
|
3140
|
+
}
|
|
3141
|
+
const descenderHead = descender.head;
|
|
3142
|
+
if (descenderHead && !(probe.containerType() === "array" && !descenderHead.isIndexReference()) && !(probe.containerType() === "object" && !descenderHead.isAttributeReference()))
|
|
3143
|
+
if (descender.tail) {
|
|
3144
|
+
const matcher = new Matcher(descender.descend(), this);
|
|
3145
|
+
descenderHead.toFieldReferences().forEach(() => {
|
|
3146
|
+
leads.push({
|
|
3147
|
+
target: descenderHead,
|
|
3148
|
+
matcher
|
|
3149
|
+
});
|
|
3150
|
+
});
|
|
3151
|
+
} else
|
|
3152
|
+
targets.push(descenderHead);
|
|
3153
|
+
}), this.hasRecursives()) {
|
|
3154
|
+
const recursivesMatcher = new Matcher([], this);
|
|
3155
|
+
if (probe.containerType() === "array") {
|
|
3156
|
+
const length = probe.length();
|
|
3157
|
+
for (let i = 0; i < length; i++)
|
|
3158
|
+
leads.push({
|
|
3159
|
+
target: Expression.indexReference(i),
|
|
3160
|
+
matcher: recursivesMatcher
|
|
3161
|
+
});
|
|
3162
|
+
} else
|
|
3163
|
+
probe.containerType() === "object" && probe.attributeKeys().forEach((name) => {
|
|
3164
|
+
leads.push({
|
|
3165
|
+
target: Expression.attributeReference(name),
|
|
3166
|
+
matcher: recursivesMatcher
|
|
3167
|
+
});
|
|
3168
|
+
});
|
|
3169
|
+
}
|
|
3170
|
+
return targets.length > 0 ? { leads, delivery: { targets, payload: this.payload } } : { leads };
|
|
3171
|
+
}
|
|
3172
|
+
static fromPath(jsonpath) {
|
|
3173
|
+
const path = parseJsonPath(jsonpath);
|
|
3174
|
+
if (!path)
|
|
3175
|
+
throw new Error(`Failed to parse path from "${jsonpath}"`);
|
|
3176
|
+
const descender = new Descender(null, new Expression(path));
|
|
3177
|
+
return new Matcher(descender.descend());
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
var __defProp$b = Object.defineProperty, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$b = (obj, key, value) => __defNormalProp$b(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3181
|
+
class PlainProbe {
|
|
3182
|
+
constructor(value, path) {
|
|
3183
|
+
__publicField$b(this, "_value"), __publicField$b(this, "path"), this._value = value, this.path = path || [];
|
|
3184
|
+
}
|
|
3185
|
+
containerType() {
|
|
3186
|
+
return Array.isArray(this._value) ? "array" : this._value !== null && typeof this._value == "object" ? "object" : "primitive";
|
|
3187
|
+
}
|
|
3188
|
+
length() {
|
|
3189
|
+
if (!Array.isArray(this._value))
|
|
3190
|
+
throw new Error("Won't return length of non-indexable _value");
|
|
3191
|
+
return this._value.length;
|
|
3192
|
+
}
|
|
3193
|
+
getIndex(i) {
|
|
3194
|
+
return Array.isArray(this._value) ? i >= this.length() ? null : new PlainProbe(this._value[i], this.path.concat(i)) : !1;
|
|
3195
|
+
}
|
|
3196
|
+
hasAttribute(key) {
|
|
3197
|
+
return isRecord(this._value) ? this._value.hasOwnProperty(key) : !1;
|
|
3198
|
+
}
|
|
3199
|
+
attributeKeys() {
|
|
3200
|
+
return isRecord(this._value) ? Object.keys(this._value) : [];
|
|
3201
|
+
}
|
|
3202
|
+
getAttribute(key) {
|
|
3203
|
+
if (!isRecord(this._value))
|
|
3204
|
+
throw new Error("getAttribute only applies to plain objects");
|
|
3205
|
+
return this.hasAttribute(key) ? new PlainProbe(this._value[key], this.path.concat(key)) : null;
|
|
3206
|
+
}
|
|
3207
|
+
get() {
|
|
3208
|
+
return this._value;
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
function extractAccessors(path, value) {
|
|
3212
|
+
const result = [], matcher = Matcher.fromPath(path).setPayload(function(values) {
|
|
3213
|
+
result.push(...values);
|
|
3214
|
+
}), accessor = new PlainProbe(value);
|
|
3215
|
+
return descend(matcher, accessor), result;
|
|
3216
|
+
}
|
|
3217
|
+
function descend(matcher, accessor) {
|
|
3218
|
+
const { leads, delivery } = matcher.match(accessor);
|
|
3219
|
+
leads.forEach((lead) => {
|
|
3220
|
+
accessorsFromTarget(lead.target, accessor).forEach((childAccessor) => {
|
|
3221
|
+
descend(lead.matcher, childAccessor);
|
|
3222
|
+
});
|
|
3223
|
+
}), delivery && delivery.targets.forEach((target) => {
|
|
3224
|
+
typeof delivery.payload == "function" && delivery.payload(accessorsFromTarget(target, accessor));
|
|
3225
|
+
});
|
|
3226
|
+
}
|
|
3227
|
+
function accessorsFromTarget(target, accessor) {
|
|
3228
|
+
const result = [];
|
|
3229
|
+
if (target.isIndexReference())
|
|
3230
|
+
target.toIndicies(accessor).forEach((i) => {
|
|
3231
|
+
result.push(accessor.getIndex(i));
|
|
3232
|
+
});
|
|
3233
|
+
else if (target.isAttributeReference())
|
|
3234
|
+
result.push(accessor.getAttribute(target.name()));
|
|
3235
|
+
else if (target.isSelfReference())
|
|
3236
|
+
result.push(accessor);
|
|
3237
|
+
else
|
|
3238
|
+
throw new Error(`Unable to derive accessor for target ${target.toString()}`);
|
|
3239
|
+
return compact$1(result);
|
|
3240
|
+
}
|
|
3241
|
+
function extractWithPath(path, value) {
|
|
3242
|
+
return extractAccessors(path, value).map((acc) => ({ path: acc.path, value: acc.get() }));
|
|
3243
|
+
}
|
|
3244
|
+
var __defProp$a = Object.defineProperty, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3245
|
+
function applyPatch(patch, oldValue) {
|
|
3246
|
+
if (typeof oldValue != "string")
|
|
3247
|
+
return oldValue;
|
|
3248
|
+
const [result] = apply(patch, oldValue, { allowExceedingIndices: !0 });
|
|
3249
|
+
return result;
|
|
3250
|
+
}
|
|
3251
|
+
class DiffMatchPatch {
|
|
3252
|
+
constructor(id, path, dmpPatchSrc) {
|
|
3253
|
+
__publicField$a(this, "path"), __publicField$a(this, "dmpPatch"), __publicField$a(this, "id"), this.id = id, this.path = path, this.dmpPatch = parse(dmpPatchSrc);
|
|
3254
|
+
}
|
|
3255
|
+
apply(targets, accessor) {
|
|
3256
|
+
let result = accessor;
|
|
3257
|
+
if (result.containerType() === "primitive")
|
|
3258
|
+
return result;
|
|
3259
|
+
for (const target of targets) {
|
|
3260
|
+
if (target.isIndexReference()) {
|
|
3261
|
+
for (const index of target.toIndicies(accessor)) {
|
|
3262
|
+
const item = result.getIndex(index);
|
|
3263
|
+
if (!item)
|
|
3264
|
+
continue;
|
|
3265
|
+
const oldValue = item.get(), nextValue = applyPatch(this.dmpPatch, oldValue);
|
|
3266
|
+
result = result.setIndex(index, nextValue);
|
|
3267
|
+
}
|
|
3268
|
+
continue;
|
|
3269
|
+
}
|
|
3270
|
+
if (target.isAttributeReference() && result.hasAttribute(target.name())) {
|
|
3271
|
+
const attribute = result.getAttribute(target.name());
|
|
3272
|
+
if (!attribute)
|
|
3273
|
+
continue;
|
|
3274
|
+
const oldValue = attribute.get(), nextValue = applyPatch(this.dmpPatch, oldValue);
|
|
3275
|
+
result = result.setAttribute(target.name(), nextValue);
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
throw new Error(`Unable to apply diffMatchPatch to target ${target.toString()}`);
|
|
3279
|
+
}
|
|
3280
|
+
return result;
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
var __defProp$9 = Object.defineProperty, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3284
|
+
function performIncrement(previousValue, delta) {
|
|
3285
|
+
return typeof previousValue != "number" || !Number.isFinite(previousValue) ? previousValue : previousValue + delta;
|
|
3286
|
+
}
|
|
3287
|
+
class IncPatch {
|
|
3288
|
+
constructor(id, path, value) {
|
|
3289
|
+
__publicField$9(this, "path"), __publicField$9(this, "value"), __publicField$9(this, "id"), this.path = path, this.value = value, this.id = id;
|
|
3290
|
+
}
|
|
3291
|
+
apply(targets, accessor) {
|
|
3292
|
+
let result = accessor;
|
|
3293
|
+
if (result.containerType() === "primitive")
|
|
3294
|
+
return result;
|
|
3295
|
+
for (const target of targets) {
|
|
3296
|
+
if (target.isIndexReference()) {
|
|
3297
|
+
for (const index of target.toIndicies(accessor)) {
|
|
3298
|
+
const item = result.getIndex(index);
|
|
3299
|
+
if (!item)
|
|
3300
|
+
continue;
|
|
3301
|
+
const previousValue = item.get();
|
|
3302
|
+
result = result.setIndex(index, performIncrement(previousValue, this.value));
|
|
3303
|
+
}
|
|
3304
|
+
continue;
|
|
3305
|
+
}
|
|
3306
|
+
if (target.isAttributeReference()) {
|
|
3307
|
+
const attribute = result.getAttribute(target.name());
|
|
3308
|
+
if (!attribute)
|
|
3309
|
+
continue;
|
|
3310
|
+
const previousValue = attribute.get();
|
|
3311
|
+
result = result.setAttribute(target.name(), performIncrement(previousValue, this.value));
|
|
3312
|
+
continue;
|
|
3313
|
+
}
|
|
3314
|
+
throw new Error(`Unable to apply to target ${target.toString()}`);
|
|
3315
|
+
}
|
|
3316
|
+
return result;
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3319
|
+
function targetsToIndicies(targets, accessor) {
|
|
3320
|
+
const result = [];
|
|
3321
|
+
return targets.forEach((target) => {
|
|
3322
|
+
target.isIndexReference() && result.push(...target.toIndicies(accessor));
|
|
3323
|
+
}), result.sort();
|
|
3324
|
+
}
|
|
3325
|
+
var __defProp$8 = Object.defineProperty, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3326
|
+
class InsertPatch {
|
|
3327
|
+
constructor(id, location, path, items) {
|
|
3328
|
+
__publicField$8(this, "location"), __publicField$8(this, "path"), __publicField$8(this, "items"), __publicField$8(this, "id"), this.id = id, this.location = location, this.path = path, this.items = items;
|
|
3329
|
+
}
|
|
3330
|
+
apply(targets, accessor) {
|
|
3331
|
+
let result = accessor;
|
|
3332
|
+
if (accessor.containerType() !== "array")
|
|
3333
|
+
throw new Error("Attempt to apply insert patch to non-array value");
|
|
3334
|
+
switch (this.location) {
|
|
3335
|
+
case "before": {
|
|
3336
|
+
const pos = minIndex(targets, accessor);
|
|
3337
|
+
result = result.insertItemsAt(pos, this.items);
|
|
3338
|
+
break;
|
|
3339
|
+
}
|
|
3340
|
+
case "after": {
|
|
3341
|
+
const pos = maxIndex(targets, accessor);
|
|
3342
|
+
result = result.insertItemsAt(pos + 1, this.items);
|
|
3343
|
+
break;
|
|
3344
|
+
}
|
|
3345
|
+
case "replace": {
|
|
3346
|
+
const indicies = targetsToIndicies(targets, accessor);
|
|
3347
|
+
result = result.unsetIndices(indicies), result = result.insertItemsAt(indicies[0], this.items);
|
|
3348
|
+
break;
|
|
3349
|
+
}
|
|
3350
|
+
default:
|
|
3351
|
+
throw new Error(`Unsupported location atm: ${this.location}`);
|
|
3352
|
+
}
|
|
3353
|
+
return result;
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
function minIndex(targets, accessor) {
|
|
3357
|
+
let result = min$1(targetsToIndicies(targets, accessor)) || 0;
|
|
3358
|
+
return targets.forEach((target) => {
|
|
3359
|
+
if (target.isRange()) {
|
|
3360
|
+
const { start } = target.expandRange();
|
|
3361
|
+
start < result && (result = start);
|
|
3362
|
+
}
|
|
3363
|
+
}), result;
|
|
3364
|
+
}
|
|
3365
|
+
function maxIndex(targets, accessor) {
|
|
3366
|
+
let result = max$1(targetsToIndicies(targets, accessor)) || 0;
|
|
3367
|
+
return targets.forEach((target) => {
|
|
3368
|
+
if (target.isRange()) {
|
|
3369
|
+
const { end } = target.expandRange();
|
|
3370
|
+
end > result && (result = end);
|
|
3371
|
+
}
|
|
3372
|
+
}), result;
|
|
3373
|
+
}
|
|
3374
|
+
var __defProp$7 = Object.defineProperty, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3375
|
+
class SetIfMissingPatch {
|
|
3376
|
+
constructor(id, path, value) {
|
|
3377
|
+
__publicField$7(this, "id"), __publicField$7(this, "path"), __publicField$7(this, "value"), this.id = id, this.path = path, this.value = value;
|
|
3378
|
+
}
|
|
3379
|
+
apply(targets, accessor) {
|
|
3380
|
+
let result = accessor;
|
|
3381
|
+
return targets.forEach((target) => {
|
|
3382
|
+
if (!target.isIndexReference())
|
|
3383
|
+
if (target.isAttributeReference())
|
|
3384
|
+
result.containerType() === "primitive" ? result = result.set({ [target.name()]: this.value }) : result.hasAttribute(target.name()) || (result = accessor.setAttribute(target.name(), this.value));
|
|
3385
|
+
else
|
|
3386
|
+
throw new Error(`Unable to apply to target ${target.toString()}`);
|
|
3387
|
+
}), result;
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
var __defProp$6 = Object.defineProperty, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3391
|
+
class SetPatch {
|
|
3392
|
+
constructor(id, path, value) {
|
|
3393
|
+
__publicField$6(this, "id"), __publicField$6(this, "path"), __publicField$6(this, "value"), this.id = id, this.path = path, this.value = value;
|
|
3394
|
+
}
|
|
3395
|
+
apply(targets, accessor) {
|
|
3396
|
+
let result = accessor;
|
|
3397
|
+
return targets.forEach((target) => {
|
|
3398
|
+
if (target.isSelfReference())
|
|
3399
|
+
result = result.set(this.value);
|
|
3400
|
+
else if (target.isIndexReference())
|
|
3401
|
+
target.toIndicies(accessor).forEach((i) => {
|
|
3402
|
+
result = result.setIndex(i, this.value);
|
|
3403
|
+
});
|
|
3404
|
+
else if (target.isAttributeReference())
|
|
3405
|
+
result.containerType() === "primitive" ? result = result.set({ [target.name()]: this.value }) : result = result.setAttribute(target.name(), this.value);
|
|
3406
|
+
else
|
|
3407
|
+
throw new Error(`Unable to apply to target ${target.toString()}`);
|
|
3408
|
+
}), result;
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
var __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3412
|
+
class UnsetPatch {
|
|
3413
|
+
constructor(id, path) {
|
|
3414
|
+
__publicField$5(this, "id"), __publicField$5(this, "path"), __publicField$5(this, "value"), this.id = id, this.path = path;
|
|
3415
|
+
}
|
|
3416
|
+
// eslint-disable-next-line class-methods-use-this
|
|
3417
|
+
apply(targets, accessor) {
|
|
3418
|
+
let result = accessor;
|
|
3419
|
+
switch (accessor.containerType()) {
|
|
3420
|
+
case "array":
|
|
3421
|
+
result = result.unsetIndices(targetsToIndicies(targets, accessor));
|
|
3422
|
+
break;
|
|
3423
|
+
case "object":
|
|
3424
|
+
targets.forEach((target) => {
|
|
3425
|
+
result = result.unsetAttribute(target.name());
|
|
3426
|
+
});
|
|
3427
|
+
break;
|
|
3428
|
+
default:
|
|
3429
|
+
throw new Error(
|
|
3430
|
+
"Target value is neither indexable or an object. This error should potentially just be silently ignored?"
|
|
3431
|
+
);
|
|
3432
|
+
}
|
|
3433
|
+
return result;
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
function parsePatch(patch) {
|
|
3437
|
+
const result = [];
|
|
3438
|
+
if (Array.isArray(patch))
|
|
3439
|
+
return patch.reduce((r, p) => r.concat(parsePatch(p)), result);
|
|
3440
|
+
const { set, setIfMissing, unset: unset2, diffMatchPatch, inc, dec, insert } = patch;
|
|
3441
|
+
if (setIfMissing && Object.keys(setIfMissing).forEach((path) => {
|
|
3442
|
+
result.push(new SetIfMissingPatch(patch.id, path, setIfMissing[path]));
|
|
3443
|
+
}), set && Object.keys(set).forEach((path) => {
|
|
3444
|
+
result.push(new SetPatch(patch.id, path, set[path]));
|
|
3445
|
+
}), unset2 && unset2.forEach((path) => {
|
|
3446
|
+
result.push(new UnsetPatch(patch.id, path));
|
|
3447
|
+
}), diffMatchPatch && Object.keys(diffMatchPatch).forEach((path) => {
|
|
3448
|
+
result.push(new DiffMatchPatch(patch.id, path, diffMatchPatch[path]));
|
|
3449
|
+
}), inc && Object.keys(inc).forEach((path) => {
|
|
3450
|
+
result.push(new IncPatch(patch.id, path, inc[path]));
|
|
3451
|
+
}), dec && Object.keys(dec).forEach((path) => {
|
|
3452
|
+
result.push(new IncPatch(patch.id, path, -dec[path]));
|
|
3453
|
+
}), insert) {
|
|
3454
|
+
let location, path;
|
|
3455
|
+
const spec = insert;
|
|
3456
|
+
if ("before" in spec)
|
|
3457
|
+
location = "before", path = spec.before;
|
|
3458
|
+
else if ("after" in spec)
|
|
3459
|
+
location = "after", path = spec.after;
|
|
3460
|
+
else if ("replace" in spec)
|
|
3461
|
+
location = "replace", path = spec.replace;
|
|
3462
|
+
else
|
|
3463
|
+
throw new Error("Invalid insert patch");
|
|
3464
|
+
result.push(new InsertPatch(patch.id, location, path, spec.items));
|
|
3465
|
+
}
|
|
3466
|
+
return result;
|
|
3467
|
+
}
|
|
3468
|
+
var __defProp$4 = Object.defineProperty, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, key + "", value);
|
|
3469
|
+
class Patcher {
|
|
3470
|
+
constructor(patch) {
|
|
3471
|
+
__publicField$4(this, "patches"), this.patches = parsePatch(patch);
|
|
3472
|
+
}
|
|
3473
|
+
apply(value) {
|
|
3474
|
+
const accessor = new ImmutableAccessor(value);
|
|
3475
|
+
return this.applyViaAccessor(accessor).get();
|
|
3476
|
+
}
|
|
3477
|
+
// If you want to use your own accessor implementation, you can use this method
|
|
3478
|
+
// to invoke the patcher. Since all subsequent accessors for children of this accessor
|
|
3479
|
+
// are obtained through the methods in the accessors, you retain full control of the
|
|
3480
|
+
// implementation throguhgout the application. Have a look in ImmutableAccessor
|
|
3481
|
+
// to see an example of how accessors are implemented.
|
|
3482
|
+
applyViaAccessor(accessor) {
|
|
3483
|
+
let result = accessor;
|
|
3484
|
+
const idAccessor = accessor.getAttribute("_id");
|
|
3485
|
+
if (!idAccessor)
|
|
3486
|
+
throw new Error("Cannot apply patch to document with no _id");
|
|
3487
|
+
const id = idAccessor.get();
|
|
3488
|
+
for (const patch of this.patches) {
|
|
3489
|
+
if (patch.id !== id)
|
|
3490
|
+
continue;
|
|
3491
|
+
const matcher = Matcher.fromPath(patch.path).setPayload(patch);
|
|
3492
|
+
result = process$1(matcher, result);
|
|
3493
|
+
}
|
|
3494
|
+
return result;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
function process$1(matcher, accessor) {
|
|
3498
|
+
const isSetPatch = matcher.payload instanceof SetPatch || matcher.payload instanceof SetIfMissingPatch;
|
|
3499
|
+
let result = accessor;
|
|
3500
|
+
const { leads, delivery } = matcher.match(accessor);
|
|
3501
|
+
return leads.forEach((lead) => {
|
|
3502
|
+
if (lead.target.isIndexReference())
|
|
3503
|
+
lead.target.toIndicies().forEach((i) => {
|
|
3504
|
+
const item = result.getIndex(i);
|
|
3505
|
+
if (!item)
|
|
3506
|
+
throw new Error("Index out of bounds");
|
|
3507
|
+
result = result.setIndexAccessor(i, process$1(lead.matcher, item));
|
|
3508
|
+
});
|
|
3509
|
+
else if (lead.target.isAttributeReference()) {
|
|
3510
|
+
isSetPatch && result.containerType() === "primitive" && (result = result.set({}));
|
|
3511
|
+
let oldValueAccessor = result.getAttribute(lead.target.name());
|
|
3512
|
+
if (!oldValueAccessor && isSetPatch && (result = result.setAttribute(lead.target.name(), {}), oldValueAccessor = result.getAttribute(lead.target.name())), !oldValueAccessor)
|
|
3513
|
+
return;
|
|
3514
|
+
const newValueAccessor = process$1(lead.matcher, oldValueAccessor);
|
|
3515
|
+
oldValueAccessor !== newValueAccessor && (result = result.setAttributeAccessor(lead.target.name(), newValueAccessor));
|
|
3516
|
+
} else
|
|
3517
|
+
throw new Error(`Unable to handle target ${lead.target.toString()}`);
|
|
3518
|
+
}), delivery && isPatcher(delivery.payload) && (result = delivery.payload.apply(delivery.targets, result)), result;
|
|
3519
|
+
}
|
|
3520
|
+
function isPatcher(payload) {
|
|
3521
|
+
return !!(payload && typeof payload == "object" && payload !== null && "apply" in payload && typeof payload.apply == "function");
|
|
3522
|
+
}
|
|
3523
|
+
const luid = uuid;
|
|
3524
|
+
var __defProp$3 = Object.defineProperty, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
3525
|
+
class Mutation {
|
|
3526
|
+
constructor(options) {
|
|
3527
|
+
__publicField$3(this, "params"), __publicField$3(this, "compiled"), __publicField$3(this, "_appliesToMissingDocument"), this.params = options;
|
|
3528
|
+
}
|
|
3529
|
+
get transactionId() {
|
|
3530
|
+
return this.params.transactionId;
|
|
3531
|
+
}
|
|
3532
|
+
get transition() {
|
|
3533
|
+
return this.params.transition;
|
|
3534
|
+
}
|
|
3535
|
+
get identity() {
|
|
3536
|
+
return this.params.identity;
|
|
3537
|
+
}
|
|
3538
|
+
get previousRev() {
|
|
3539
|
+
return this.params.previousRev;
|
|
3540
|
+
}
|
|
3541
|
+
get resultRev() {
|
|
3542
|
+
return this.params.resultRev;
|
|
3543
|
+
}
|
|
3544
|
+
get mutations() {
|
|
3545
|
+
return this.params.mutations;
|
|
3546
|
+
}
|
|
3547
|
+
get timestamp() {
|
|
3548
|
+
if (typeof this.params.timestamp == "string")
|
|
3549
|
+
return new Date(this.params.timestamp);
|
|
3550
|
+
}
|
|
3551
|
+
get effects() {
|
|
3552
|
+
return this.params.effects;
|
|
3553
|
+
}
|
|
3554
|
+
assignRandomTransactionId() {
|
|
3555
|
+
this.params.transactionId = luid(), this.params.resultRev = this.params.transactionId;
|
|
3556
|
+
}
|
|
3557
|
+
appliesToMissingDocument() {
|
|
3558
|
+
if (typeof this._appliesToMissingDocument < "u")
|
|
3559
|
+
return this._appliesToMissingDocument;
|
|
3560
|
+
const firstMut = this.mutations[0];
|
|
3561
|
+
return firstMut ? this._appliesToMissingDocument = !!(firstMut.create || firstMut.createIfNotExists || firstMut.createOrReplace) : this._appliesToMissingDocument = !0, this._appliesToMissingDocument;
|
|
3562
|
+
}
|
|
3563
|
+
// Compiles all mutations into a handy function
|
|
3564
|
+
compile() {
|
|
3565
|
+
const operations = [], getGuaranteedCreatedAt = (doc) => (doc == null ? void 0 : doc._createdAt) || this.params.timestamp || (/* @__PURE__ */ new Date()).toISOString();
|
|
3566
|
+
this.mutations.forEach((mutation) => {
|
|
3567
|
+
if (mutation.create) {
|
|
3568
|
+
const create = mutation.create || {};
|
|
3569
|
+
operations.push((doc) => doc || Object.assign(create, {
|
|
3570
|
+
_createdAt: getGuaranteedCreatedAt(create)
|
|
3571
|
+
}));
|
|
3572
|
+
return;
|
|
3573
|
+
}
|
|
3574
|
+
if (mutation.createIfNotExists) {
|
|
3575
|
+
const createIfNotExists = mutation.createIfNotExists || {};
|
|
3576
|
+
operations.push(
|
|
3577
|
+
(doc) => doc === null ? Object.assign(createIfNotExists, {
|
|
3578
|
+
_createdAt: getGuaranteedCreatedAt(createIfNotExists)
|
|
3579
|
+
}) : doc
|
|
3580
|
+
);
|
|
3581
|
+
return;
|
|
3582
|
+
}
|
|
3583
|
+
if (mutation.createOrReplace) {
|
|
3584
|
+
const createOrReplace = mutation.createOrReplace || {};
|
|
3585
|
+
operations.push(
|
|
3586
|
+
() => Object.assign(createOrReplace, {
|
|
3587
|
+
_createdAt: getGuaranteedCreatedAt(createOrReplace)
|
|
3588
|
+
})
|
|
3589
|
+
);
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
if (mutation.delete) {
|
|
3593
|
+
operations.push(() => null);
|
|
3594
|
+
return;
|
|
3595
|
+
}
|
|
3596
|
+
if (mutation.patch) {
|
|
3597
|
+
if ("query" in mutation.patch)
|
|
3598
|
+
return;
|
|
3599
|
+
const patch = new Patcher(mutation.patch);
|
|
3600
|
+
operations.push((doc) => patch.apply(doc));
|
|
3601
|
+
return;
|
|
3602
|
+
}
|
|
3603
|
+
throw new Error(`Unsupported mutation ${JSON.stringify(mutation, null, 2)}`);
|
|
3604
|
+
}), typeof this.params.timestamp == "string" && operations.push((doc) => doc ? Object.assign(doc, { _updatedAt: this.params.timestamp }) : null);
|
|
3605
|
+
const prevRev = this.previousRev, rev = this.resultRev || this.transactionId;
|
|
3606
|
+
this.compiled = (doc) => {
|
|
3607
|
+
if (prevRev && doc && prevRev !== doc._rev)
|
|
3608
|
+
throw new Error(
|
|
3609
|
+
`Previous revision for this mutation was ${prevRev}, but the document revision is ${doc._rev}`
|
|
3610
|
+
);
|
|
3611
|
+
let result = doc;
|
|
3612
|
+
for (const operation of operations)
|
|
3613
|
+
result = operation(result);
|
|
3614
|
+
return result && rev && (result === doc && (result = Object.assign({}, doc)), result._rev = rev), result;
|
|
3615
|
+
};
|
|
3616
|
+
}
|
|
3617
|
+
apply(document2) {
|
|
3618
|
+
debug("Applying mutation %O to document %O", this.mutations, document2), this.compiled || this.compile();
|
|
3619
|
+
const result = this.compiled(document2);
|
|
3620
|
+
return debug(" => %O", result), result;
|
|
3621
|
+
}
|
|
3622
|
+
static applyAll(document2, mutations) {
|
|
3623
|
+
return mutations.reduce((doc, mutation) => mutation.apply(doc), document2);
|
|
3624
|
+
}
|
|
3625
|
+
// Given a number of yet-to-be-committed mutation objects, collects them into one big mutation
|
|
3626
|
+
// any metadata like transactionId is ignored and must be submitted by the client. It is assumed
|
|
3627
|
+
// that all mutations are on the same document.
|
|
3628
|
+
// TOOO: Optimize mutations, eliminating mutations that overwrite themselves!
|
|
3629
|
+
static squash(document2, mutations) {
|
|
3630
|
+
const squashed = mutations.reduce(
|
|
3631
|
+
(result, mutation) => result.concat(...mutation.mutations),
|
|
3632
|
+
[]
|
|
3633
|
+
);
|
|
3634
|
+
return new Mutation({ mutations: squashed });
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
function removeExcludedPaths(doc, schemaType) {
|
|
3638
|
+
if (!isDocumentSchemaType(schemaType) || !doc)
|
|
3639
|
+
return doc;
|
|
3640
|
+
const pathsToExclude = extractPaths(doc, schemaType, []).filter(
|
|
3641
|
+
(field) => {
|
|
3642
|
+
var _a, _b, _c;
|
|
3643
|
+
return ((_c = (_b = (_a = field.schemaType) == null ? void 0 : _a.options) == null ? void 0 : _b.documentInternationalization) == null ? void 0 : _c.exclude) === !0;
|
|
3644
|
+
}
|
|
3645
|
+
).map((field) => pathToString(field.path));
|
|
3646
|
+
return new Mutation({
|
|
3647
|
+
mutations: [
|
|
3648
|
+
{
|
|
3649
|
+
patch: {
|
|
3650
|
+
id: doc._id,
|
|
3651
|
+
unset: pathsToExclude
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
]
|
|
3655
|
+
}).apply(doc);
|
|
3656
|
+
}
|
|
3657
|
+
function extractPaths(doc, schemaType, path) {
|
|
3658
|
+
return schemaType.fields.reduce((acc, field) => {
|
|
3659
|
+
var _a, _b;
|
|
3660
|
+
const fieldPath = [...path, field.name], fieldSchema = field.type, { value } = (_a = extractWithPath(pathToString(fieldPath), doc)[0]) != null ? _a : {};
|
|
3661
|
+
if (!value)
|
|
3662
|
+
return acc;
|
|
3663
|
+
const thisFieldWithPath = {
|
|
3664
|
+
path: fieldPath,
|
|
3665
|
+
name: field.name,
|
|
3666
|
+
schemaType: fieldSchema,
|
|
3667
|
+
value
|
|
3668
|
+
};
|
|
3669
|
+
if (fieldSchema.jsonType === "object") {
|
|
3670
|
+
const innerFields = extractPaths(doc, fieldSchema, fieldPath);
|
|
3671
|
+
return [...acc, thisFieldWithPath, ...innerFields];
|
|
3672
|
+
} else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item)) {
|
|
3673
|
+
const { value: arrayValue } = (_b = extractWithPath(pathToString(fieldPath), doc)[0]) != null ? _b : {};
|
|
3674
|
+
let arrayPaths = [];
|
|
3675
|
+
if (arrayValue != null && arrayValue.length)
|
|
3676
|
+
for (const item of arrayValue) {
|
|
3677
|
+
const itemPath = [...fieldPath, { _key: item._key }];
|
|
3678
|
+
let itemSchema = fieldSchema.of.find((t) => t.name === item._type);
|
|
3679
|
+
if (item._type || (itemSchema = fieldSchema.of[0]), item._key && itemSchema) {
|
|
3680
|
+
const innerFields = extractPaths(
|
|
3681
|
+
doc,
|
|
3682
|
+
itemSchema,
|
|
3683
|
+
itemPath
|
|
3684
|
+
), arrayMember = {
|
|
3685
|
+
path: itemPath,
|
|
3686
|
+
name: item._key,
|
|
3687
|
+
schemaType: itemSchema,
|
|
3688
|
+
value: item
|
|
3689
|
+
};
|
|
3690
|
+
arrayPaths = [...arrayPaths, arrayMember, ...innerFields];
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
return [...acc, thisFieldWithPath, ...arrayPaths];
|
|
3694
|
+
}
|
|
3695
|
+
return [...acc, thisFieldWithPath];
|
|
3696
|
+
}, []);
|
|
3697
|
+
}
|
|
3698
|
+
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
3699
|
+
for (var prop in b || (b = {}))
|
|
3700
|
+
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
3701
|
+
if (__getOwnPropSymbols$1)
|
|
3702
|
+
for (var prop of __getOwnPropSymbols$1(b))
|
|
3703
|
+
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
3704
|
+
return a;
|
|
3705
|
+
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
3706
|
+
function LanguageOption(props) {
|
|
3707
|
+
var _a;
|
|
3708
|
+
const {
|
|
3709
|
+
language,
|
|
3710
|
+
schemaType,
|
|
3711
|
+
documentId,
|
|
3712
|
+
current,
|
|
3713
|
+
source,
|
|
3714
|
+
sourceLanguageId,
|
|
3715
|
+
metadata: metadata2,
|
|
3716
|
+
metadataId
|
|
3717
|
+
} = props, [userHasClicked, setUserHasClicked] = useState(!1), disabled = props.disabled || userHasClicked || current || !source || !sourceLanguageId || !metadataId, translation = metadata2 != null && metadata2.translations.length ? metadata2.translations.find((t) => t._key === language.id) : void 0, { apiVersion, languageField, weakReferences } = useDocumentInternationalizationContext(), client = useClient({ apiVersion }), toast = useToast(), open = useOpenInNewPane((_a = translation == null ? void 0 : translation.value) == null ? void 0 : _a._ref, schemaType.name), handleOpen = useCallback(() => open(), [open]);
|
|
3718
|
+
useEffect(() => {
|
|
3719
|
+
setUserHasClicked(!1);
|
|
3720
|
+
}, [!!translation]);
|
|
3721
|
+
const handleCreate = useCallback(async () => {
|
|
3722
|
+
if (!source)
|
|
3723
|
+
throw new Error("Cannot create translation without source document");
|
|
3724
|
+
if (!sourceLanguageId)
|
|
3725
|
+
throw new Error("Cannot create translation without source language ID");
|
|
3726
|
+
if (!metadataId)
|
|
3727
|
+
throw new Error("Cannot create translation without a metadata ID");
|
|
3728
|
+
setUserHasClicked(!0);
|
|
3729
|
+
const transaction = client.transaction(), newTranslationDocumentId = uuid();
|
|
3730
|
+
let newTranslationDocument = __spreadProps$1(__spreadValues$1({}, source), {
|
|
3731
|
+
_id: `drafts.${newTranslationDocumentId}`,
|
|
3732
|
+
// 2. Update language of the translation
|
|
3733
|
+
[languageField]: language.id
|
|
3734
|
+
});
|
|
3735
|
+
newTranslationDocument = removeExcludedPaths(
|
|
3736
|
+
newTranslationDocument,
|
|
3737
|
+
schemaType
|
|
3738
|
+
), transaction.create(newTranslationDocument);
|
|
3739
|
+
const sourceReference = createReference(
|
|
3740
|
+
sourceLanguageId,
|
|
3741
|
+
documentId,
|
|
3742
|
+
schemaType.name,
|
|
3743
|
+
!weakReferences
|
|
3744
|
+
), newTranslationReference = createReference(
|
|
3745
|
+
language.id,
|
|
3746
|
+
newTranslationDocumentId,
|
|
3747
|
+
schemaType.name,
|
|
3748
|
+
!weakReferences
|
|
3749
|
+
), newMetadataDocument = {
|
|
3750
|
+
_id: metadataId,
|
|
3751
|
+
_type: METADATA_SCHEMA_NAME,
|
|
3752
|
+
schemaTypes: [schemaType.name],
|
|
3753
|
+
translations: [sourceReference]
|
|
3754
|
+
};
|
|
3755
|
+
transaction.createIfNotExists(newMetadataDocument);
|
|
3756
|
+
const metadataPatch = client.patch(metadataId).setIfMissing({ translations: [sourceReference] }).insert("after", "translations[-1]", [newTranslationReference]);
|
|
3757
|
+
transaction.patch(metadataPatch), transaction.commit().then(() => {
|
|
3758
|
+
const metadataExisted = !!(metadata2 != null && metadata2._createdAt);
|
|
3759
|
+
return toast.push({
|
|
3760
|
+
status: "success",
|
|
3761
|
+
title: `Created "${language.title}" translation`,
|
|
3762
|
+
description: metadataExisted ? "Updated Translations Metadata" : "Created Translations Metadata"
|
|
3763
|
+
});
|
|
3764
|
+
}).catch((err) => (console.error(err), setUserHasClicked(!1), toast.push({
|
|
3765
|
+
status: "error",
|
|
3766
|
+
title: "Error creating translation",
|
|
3767
|
+
description: err.message
|
|
3768
|
+
})));
|
|
3769
|
+
}, [
|
|
3770
|
+
client,
|
|
3771
|
+
documentId,
|
|
3772
|
+
language.id,
|
|
3773
|
+
language.title,
|
|
3774
|
+
languageField,
|
|
3775
|
+
metadata2 == null ? void 0 : metadata2._createdAt,
|
|
3776
|
+
metadataId,
|
|
3777
|
+
schemaType,
|
|
3778
|
+
source,
|
|
3779
|
+
sourceLanguageId,
|
|
3780
|
+
toast,
|
|
3781
|
+
weakReferences
|
|
3782
|
+
]);
|
|
3783
|
+
let message;
|
|
3784
|
+
return current ? message = "Current document" : translation ? message = `Open ${language.title} translation` : translation || (message = `Create new ${language.title} translation`), /* @__PURE__ */ jsx(
|
|
3785
|
+
Tooltip,
|
|
3786
|
+
{
|
|
3787
|
+
animate: !0,
|
|
968
3788
|
content: /* @__PURE__ */ jsx(Box, { padding: 2, children: /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: message }) }),
|
|
969
3789
|
fallbackPlacements: ["right", "left"],
|
|
970
3790
|
placement: "top",
|
|
@@ -1037,7 +3857,7 @@ function DocumentInternationalizationMenu(props) {
|
|
|
1037
3857
|
'Not all languages are valid. It should be an array of objects with an "id" and "title" property. Or a function that returns an array of objects with an "id" and "title" property.',
|
|
1038
3858
|
supportedLanguages
|
|
1039
3859
|
), valid;
|
|
1040
|
-
}, [supportedLanguages]), content = /* @__PURE__ */ jsx(Box, { padding: 1, children: error ? /* @__PURE__ */ jsx(Card, { tone: "critical", padding: 1, children: /* @__PURE__ */ jsx(Text, { children: "There was an error returning translations metadata" }) }) : /* @__PURE__ */ jsxs(Stack, { space: 1, children: [
|
|
3860
|
+
}, [supportedLanguages]), content = /* @__PURE__ */ jsx(Box, { padding: 1, children: error ? /* @__PURE__ */ jsx(Card, { tone: "critical", padding: 1, children: /* @__PURE__ */ jsx(Text, { children: "There was an error returning translations metadata" }) }) : /* @__PURE__ */ jsxs(Stack$1, { space: 1, children: [
|
|
1041
3861
|
/* @__PURE__ */ jsx(
|
|
1042
3862
|
LanguageManage,
|
|
1043
3863
|
{
|
|
@@ -1244,7 +4064,7 @@ function InfoIcon(props) {
|
|
|
1244
4064
|
);
|
|
1245
4065
|
}
|
|
1246
4066
|
function Info() {
|
|
1247
|
-
return /* @__PURE__ */ jsx(InfoIcon, { icon: InfoOutlineIcon, tone: "primary", children: /* @__PURE__ */ jsxs(Stack, { padding: 3, space: 4, style: { maxWidth: 250 }, children: [
|
|
4067
|
+
return /* @__PURE__ */ jsx(InfoIcon, { icon: InfoOutlineIcon, tone: "primary", children: /* @__PURE__ */ jsxs(Stack$1, { padding: 3, space: 4, style: { maxWidth: 250 }, children: [
|
|
1248
4068
|
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Bulk publishing uses the Scheduling API." }) }),
|
|
1249
4069
|
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Customized Document Actions in the Studio will not execute. Webhooks will execute." }) }),
|
|
1250
4070
|
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: "Validation is checked before rendering the button below, but the Scheduling API will not check for \u2013 or enforce \u2013 validation." }) })
|
|
@@ -1288,12 +4108,12 @@ function BulkPublish(props) {
|
|
|
1288
4108
|
!!(invalidIds && (invalidIds == null ? void 0 : invalidIds.length) > 0) || // No documents are drafts
|
|
1289
4109
|
!draftIds.length
|
|
1290
4110
|
);
|
|
1291
|
-
return (translations == null ? void 0 : translations.length) > 0 ? /* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
4111
|
+
return (translations == null ? void 0 : translations.length) > 0 ? /* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, children: /* @__PURE__ */ jsxs(Stack$1, { space: 3, children: [
|
|
1292
4112
|
/* @__PURE__ */ jsxs(Inline, { space: 3, children: [
|
|
1293
4113
|
/* @__PURE__ */ jsx(Text, { weight: "bold", size: 1, children: "Bulk publishing" }),
|
|
1294
4114
|
/* @__PURE__ */ jsx(Info, {})
|
|
1295
4115
|
] }),
|
|
1296
|
-
/* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsx(
|
|
4116
|
+
/* @__PURE__ */ jsx(Stack$1, { children: /* @__PURE__ */ jsx(
|
|
1297
4117
|
Button,
|
|
1298
4118
|
{
|
|
1299
4119
|
onClick: onOpen,
|
|
@@ -1310,8 +4130,8 @@ function BulkPublish(props) {
|
|
|
1310
4130
|
onClose,
|
|
1311
4131
|
zOffset: 1e3,
|
|
1312
4132
|
width: 3,
|
|
1313
|
-
children: /* @__PURE__ */ jsxs(Stack, { space: 4, padding: 4, children: [
|
|
1314
|
-
draftIds.length > 0 ? /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
4133
|
+
children: /* @__PURE__ */ jsxs(Stack$1, { space: 4, padding: 4, children: [
|
|
4134
|
+
draftIds.length > 0 ? /* @__PURE__ */ jsxs(Stack$1, { space: 2, children: [
|
|
1315
4135
|
/* @__PURE__ */ jsxs(Text, { size: 1, children: [
|
|
1316
4136
|
"There",
|
|
1317
4137
|
" ",
|
|
@@ -1324,7 +4144,7 @@ function BulkPublish(props) {
|
|
|
1324
4144
|
"validation issues that must addressed first"
|
|
1325
4145
|
] }) : /* @__PURE__ */ jsx(TextWithTone, { tone: "positive", size: 1, children: "All drafts are valid and can be bulk published" })
|
|
1326
4146
|
] }) : null,
|
|
1327
|
-
/* @__PURE__ */ jsx(Stack, { space: 1, children: translations.filter((translation) => {
|
|
4147
|
+
/* @__PURE__ */ jsx(Stack$1, { space: 1, children: translations.filter((translation) => {
|
|
1328
4148
|
var _a;
|
|
1329
4149
|
return (_a = translation == null ? void 0 : translation.value) == null ? void 0 : _a._ref;
|
|
1330
4150
|
}).map((translation) => /* @__PURE__ */ jsx(
|
|
@@ -1432,10 +4252,17 @@ var metadata = (schemaTypes, metadataFields) => defineType({
|
|
|
1432
4252
|
};
|
|
1433
4253
|
}
|
|
1434
4254
|
}
|
|
1435
|
-
})
|
|
4255
|
+
}), __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
|
|
4256
|
+
for (var prop in b || (b = {}))
|
|
4257
|
+
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
4258
|
+
if (__getOwnPropSymbols2)
|
|
4259
|
+
for (var prop of __getOwnPropSymbols2(b))
|
|
4260
|
+
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
4261
|
+
return a;
|
|
4262
|
+
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1436
4263
|
const documentInternationalization = definePlugin(
|
|
1437
4264
|
(config2) => {
|
|
1438
|
-
const pluginConfig = {
|
|
4265
|
+
const pluginConfig = __spreadValues2(__spreadValues2({}, DEFAULT_CONFIG), config2), {
|
|
1439
4266
|
supportedLanguages,
|
|
1440
4267
|
schemaTypes,
|
|
1441
4268
|
languageField,
|
|
@@ -1450,7 +4277,7 @@ const documentInternationalization = definePlugin(
|
|
|
1450
4277
|
name: "@sanity/document-internationalization",
|
|
1451
4278
|
studio: {
|
|
1452
4279
|
components: {
|
|
1453
|
-
layout: (props) => DocumentInternationalizationProvider({
|
|
4280
|
+
layout: (props) => DocumentInternationalizationProvider(__spreadProps(__spreadValues2({}, props), { pluginConfig }))
|
|
1454
4281
|
}
|
|
1455
4282
|
},
|
|
1456
4283
|
i18n: {
|
|
@@ -1467,7 +4294,7 @@ const documentInternationalization = definePlugin(
|
|
|
1467
4294
|
const metadataId = (_a = props == null ? void 0 : props.value) == null ? void 0 : _a._id, translations = (_c = (_b = props == null ? void 0 : props.value) == null ? void 0 : _b.translations) != null ? _c : [], weakAndTypedTranslations = translations.filter(
|
|
1468
4295
|
({ value }) => (value == null ? void 0 : value._weak) && value._strengthenOnPublish
|
|
1469
4296
|
);
|
|
1470
|
-
return /* @__PURE__ */ jsxs(Stack, { space: 5, children: [
|
|
4297
|
+
return /* @__PURE__ */ jsxs(Stack$1, { space: 5, children: [
|
|
1471
4298
|
bulkPublish ? /* @__PURE__ */ jsx(BulkPublish, { translations }) : null,
|
|
1472
4299
|
weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(
|
|
1473
4300
|
OptimisticallyStrengthen,
|
|
@@ -1492,7 +4319,7 @@ const documentInternationalization = definePlugin(
|
|
|
1492
4319
|
const { schemaType, documentId } = ctx;
|
|
1493
4320
|
return schemaTypes.includes(schemaType) && documentId ? [
|
|
1494
4321
|
...prev,
|
|
1495
|
-
(props) => DocumentInternationalizationMenu({
|
|
4322
|
+
(props) => DocumentInternationalizationMenu(__spreadProps(__spreadValues2({}, props), { documentId }))
|
|
1496
4323
|
] : prev;
|
|
1497
4324
|
},
|
|
1498
4325
|
badges: (prev, { schemaType }) => schemaTypes.includes(schemaType) ? [(props) => LanguageBadge(props), ...prev] : prev,
|
|
@@ -1568,14 +4395,14 @@ const documentInternationalization = definePlugin(
|
|
|
1568
4395
|
),
|
|
1569
4396
|
options: {
|
|
1570
4397
|
// @ts-expect-error - Update type once it knows the values of this filter
|
|
1571
|
-
filter: ({ parent, document }) => {
|
|
4398
|
+
filter: ({ parent, document: document2 }) => {
|
|
1572
4399
|
if (!parent)
|
|
1573
4400
|
return null;
|
|
1574
4401
|
const language = (Array.isArray(parent) ? parent : [parent]).find((p) => p._key);
|
|
1575
|
-
return language != null && language._key ?
|
|
4402
|
+
return language != null && language._key ? document2.schemaTypes ? {
|
|
1576
4403
|
filter: `_type in $schemaTypes && ${languageField} == $language`,
|
|
1577
4404
|
params: {
|
|
1578
|
-
schemaTypes:
|
|
4405
|
+
schemaTypes: document2.schemaTypes,
|
|
1579
4406
|
language: language._key
|
|
1580
4407
|
}
|
|
1581
4408
|
} : {
|