@likec4/core 1.44.0 → 1.45.0
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/dist/builder/index.d.mts +14 -13
- package/dist/builder/index.mjs +29 -14
- package/dist/compute-view/index.d.mts +6 -6
- package/dist/compute-view/index.mjs +6 -5
- package/dist/compute-view/relationships-view/index.d.mts +6 -6
- package/dist/compute-view/relationships-view/index.mjs +2 -2
- package/dist/index.d.mts +25 -5
- package/dist/index.mjs +2 -1
- package/dist/model/connection/deployment/index.d.mts +8 -8
- package/dist/model/connection/deployment/index.mjs +2 -2
- package/dist/model/connection/index.d.mts +9 -9
- package/dist/model/connection/index.mjs +3 -3
- package/dist/model/connection/model/index.d.mts +8 -8
- package/dist/model/connection/model/index.mjs +2 -2
- package/dist/model/index.d.mts +11 -25
- package/dist/model/index.mjs +4 -4
- package/dist/shared/{core.BnOetIAR.d.mts → core.0zAQeenX.d.mts} +2 -2
- package/dist/shared/{core.Bv3cd-jC.mjs → core.3ZhnKAlZ.mjs} +9 -5
- package/dist/shared/{core.CDOKQTW6.d.mts → core.B73yxfPi.d.mts} +2 -2
- package/dist/shared/{core.DTJYgLXI.d.mts → core.BGFjN3nv.d.mts} +3 -3
- package/dist/shared/core.BhNcrwzK.mjs +7 -0
- package/dist/shared/core.BkVA6gjl.mjs +5 -0
- package/dist/shared/{core.bKIs4oDO.mjs → core.CQPEY2wQ.mjs} +5 -4
- package/dist/shared/{core.h4TqqSC0.mjs → core.CRI1AjFj.mjs} +67 -1172
- package/dist/shared/{core.23WeDKcI.mjs → core.CWwSgOzF.mjs} +224 -224
- package/dist/shared/{core.6VsRBhGY.mjs → core.CdNCAwq7.mjs} +1 -1
- package/dist/shared/{core.BnDbAOR2.d.mts → core.Cog93roC.d.mts} +2 -2
- package/dist/shared/core.Coi_LOUZ.mjs +7 -0
- package/dist/shared/{core.DjAM-S6a.d.mts → core.CpURdWRM.d.mts} +14 -13
- package/dist/shared/{core.DFCHU59b.mjs → core.DViDmiAu.mjs} +2 -2
- package/dist/shared/{core.CHwVhuc9.mjs → core.D_f4F48-.mjs} +10 -13
- package/dist/shared/{core.CbsSAn1j.mjs → core.DbfO90vF.mjs} +1 -12
- package/dist/shared/{core.CKNmSm2W.d.mts → core.DnCLhN8C.d.mts} +7 -14
- package/dist/shared/{core.C0Ye2OCr.mjs → core.DqlrMlsf.mjs} +1 -1
- package/dist/shared/{core.8mmHFn9g.d.mts → core.Dvh1H0T2.d.mts} +2 -2
- package/dist/shared/{core.BMtVqKl7.d.mts → core.mUnpvHtA.d.mts} +11 -5
- package/dist/shared/core.oSV6SRfk.mjs +13 -0
- package/dist/shared/{core.WwMWeiFL.d.mts → core.t3qfsVvn.d.mts} +3 -3
- package/dist/shared/core.vzLtp8i3.mjs +1282 -0
- package/dist/styles/index.d.mts +5 -5
- package/dist/styles/index.mjs +3 -3
- package/dist/types/_aux.d.mts +1 -1
- package/dist/types/expression-model.d.mts +2 -2
- package/dist/types/expression.d.mts +2 -2
- package/dist/types/fqnRef.d.mts +1 -1
- package/dist/types/index.d.mts +7 -7
- package/dist/types/index.mjs +23 -9
- package/dist/utils/index.mjs +5 -4
- package/package.json +8 -8
- package/dist/shared/core.B9BjmjuH.mjs +0 -9
- package/dist/shared/core.OHD4KXm9.mjs +0 -5
|
@@ -1,49 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { e as e$
|
|
1
|
+
import { t as t$3, e as e$2, a as DeploymentNodeModel, b as DeployedInstanceModel, c as DeploymentRelationModel, N as NestedElementOfDeployedInstanceModel } from './core.D_f4F48-.mjs';
|
|
2
|
+
import { e as e$1 } from './core.BKlholso.mjs';
|
|
3
|
+
import { n as n$1 } from './core.BhNcrwzK.mjs';
|
|
3
4
|
import { c as splitGlobalFqn, g as extractStep, e as isStepEdgeId, i as isGroupElementKind, b as isGlobalFqn, a as GlobalFqn } from './core.C_Ni6yHl.mjs';
|
|
4
|
-
import { m as hierarchyLevel, n as nameFromFqn, i as isAncestor, g as commonAncestor, s as sortNaturalByFqn, f as sortParentsFirst, p as parentFqn, a as ancestorsFqn } from './core.
|
|
5
|
+
import { m as hierarchyLevel, n as nameFromFqn, i as isAncestor, g as commonAncestor, s as sortNaturalByFqn, f as sortParentsFirst, p as parentFqn, a as ancestorsFqn } from './core.CdNCAwq7.mjs';
|
|
5
6
|
import { m as memoizeProp } from './core.BR4zXDH-.mjs';
|
|
6
7
|
import { R as RichText, e as exact } from './core.M9ayqQZa.mjs';
|
|
7
8
|
import { preferSummary, preferDescription } from '../types/_aux.mjs';
|
|
8
9
|
import { i as ihead } from './core.uFk_o9X6.mjs';
|
|
9
|
-
import {
|
|
10
|
-
import { t as t$
|
|
11
|
-
import {
|
|
12
|
-
import { t as t$
|
|
13
|
-
import {
|
|
10
|
+
import { t as t$6, b as compareNaturalHierarchically, c as compareNatural } from './core.3ZhnKAlZ.mjs';
|
|
11
|
+
import { t as t$2, a as t$4 } from './core.BsSXS-_R.mjs';
|
|
12
|
+
import { t as t$5, e as e$3 } from './core.Coi_LOUZ.mjs';
|
|
13
|
+
import { t as t$8 } from './core.CbT8JVYL.mjs';
|
|
14
|
+
import { t as t$7 } from './core.BkVA6gjl.mjs';
|
|
15
|
+
import { c as calcDriftsFromSnapshot, a as applyManualLayout, h as t$9 } from './core.vzLtp8i3.mjs';
|
|
16
|
+
import { L as LikeC4Styles } from './core.DEieYfbG.mjs';
|
|
14
17
|
import { g as getOrCreate } from './core.DcS-0zys.mjs';
|
|
15
18
|
import { D as DefaultMap } from './core.BbE4y-yl.mjs';
|
|
16
19
|
import { i as invariant, a as nonNullable } from './core.D4npX2q8.mjs';
|
|
17
20
|
import { FqnRef } from '../types/fqnRef.mjs';
|
|
18
|
-
import { c as isDeploymentNode,
|
|
19
|
-
import { s as symmetricDifference } from './core.CbsSAn1j.mjs';
|
|
21
|
+
import { c as isDeploymentNode, a as _type, _ as _stage, i as isOnStage, w as whereOperatorAsPredicate } from './core.DH7TXqXf.mjs';
|
|
20
22
|
import { i as ifind } from './core.CmPXpJ8l.mjs';
|
|
21
23
|
import { i as ifilter } from './core.DRJma0Ol.mjs';
|
|
22
|
-
import
|
|
23
|
-
import './core.
|
|
24
|
-
import './core.bKIs4oDO.mjs';
|
|
24
|
+
import './core.DqlrMlsf.mjs';
|
|
25
|
+
import './core.CQPEY2wQ.mjs';
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function n$5(...t){return t$8(r$1,t,i)}const r$1=(e,t)=>e.filter(t),i=e=>(n,r,i)=>e(n,r,i)?{done:false,hasNext:true,next:n}:t$9;
|
|
29
|
-
|
|
30
|
-
function t$6(...t){return t$8(n$4,t,r)}const n$4=(e,t)=>e.flatMap(t),r=e=>(t,n,r)=>{let i=e(t,n,r);return Array.isArray(i)?{done:false,hasNext:true,hasMany:true,next:i}:{done:false,hasNext:true,next:i}};
|
|
31
|
-
|
|
32
|
-
function t$5(...t){return t$8(n$3,t)}const n$3=(e,t)=>{let n=Object.create(null);for(let r=0;r<e.length;r++){let i=e[r],a=t(i,r,e);if(a!==void 0){let e=n[a];e===void 0?n[a]=[i]:e.push(i);}}return Object.setPrototypeOf(n,Object.prototype),n};
|
|
33
|
-
|
|
34
|
-
function e$1(e){return typeof e==`number`&&!Number.isNaN(e)}
|
|
35
|
-
|
|
36
|
-
function t$4(...t){return t$8(n$2,t)}const n$2=e=>e.at(-1);
|
|
37
|
-
|
|
38
|
-
function t$3(...t){return t$8(n$1,t)}function n$1(e,t){let n={};for(let[r,i]of Object.entries(e))n[r]=t(i,r,e);return n}
|
|
39
|
-
|
|
40
|
-
function t$2(...t){return n=>t$a(n,...t)}
|
|
41
|
-
|
|
42
|
-
function t$1(...t){return t$7(n,t)}const n=(e,t)=>[...e].sort(t);
|
|
27
|
+
function t$1(...t){return t$2(n,t)}const n=e=>e.at(-1);
|
|
43
28
|
|
|
44
29
|
function e(e,t,n){return typeof t==`number`||t===void 0?n=>n.split(e,t):e.split(t,n)}
|
|
45
30
|
|
|
46
|
-
function t(...t){return t$
|
|
31
|
+
function t(...t){return t$2(Object.values,t)}
|
|
47
32
|
|
|
48
33
|
class ElementModel {
|
|
49
34
|
constructor($model, $element) {
|
|
@@ -95,7 +80,7 @@ class ElementModel {
|
|
|
95
80
|
*/
|
|
96
81
|
get tags() {
|
|
97
82
|
return memoizeProp(this, Symbol.for("tags"), () => {
|
|
98
|
-
return n$
|
|
83
|
+
return n$1([
|
|
99
84
|
...this.$element.tags ?? [],
|
|
100
85
|
...this.$model.specification.elements[this.$element.kind]?.tags ?? []
|
|
101
86
|
]);
|
|
@@ -109,7 +94,7 @@ class ElementModel {
|
|
|
109
94
|
* (if one is missing - it falls back to another)
|
|
110
95
|
*/
|
|
111
96
|
get hasSummary() {
|
|
112
|
-
return !!this.$element.summary && !!this.$element.description && !t$
|
|
97
|
+
return !!this.$element.summary && !!this.$element.description && !t$3(this.$element.summary, this.$element.description);
|
|
113
98
|
}
|
|
114
99
|
/**
|
|
115
100
|
* Short description of the element.
|
|
@@ -277,13 +262,13 @@ class ElementModel {
|
|
|
277
262
|
* @returns true if the element is deployed
|
|
278
263
|
*/
|
|
279
264
|
isDeployed() {
|
|
280
|
-
return e$
|
|
265
|
+
return e$1(ihead(this.deployments()));
|
|
281
266
|
}
|
|
282
267
|
deployments() {
|
|
283
268
|
return this.$model.deployment.instancesOf(this);
|
|
284
269
|
}
|
|
285
270
|
hasMetadata() {
|
|
286
|
-
return !!this.$element.metadata && !e$
|
|
271
|
+
return !!this.$element.metadata && !e$2(this.$element.metadata);
|
|
287
272
|
}
|
|
288
273
|
getMetadata(field) {
|
|
289
274
|
if (field) {
|
|
@@ -308,7 +293,7 @@ const splitViewTitle = (title) => {
|
|
|
308
293
|
invariant(!title.includes("\n"), "View title cannot contain newlines");
|
|
309
294
|
if (title.includes(VIEW_FOLDERS_SEPARATOR)) {
|
|
310
295
|
const segments = title.split(VIEW_FOLDERS_SEPARATOR).map((s) => s.trim()).filter((s) => s.length > 0);
|
|
311
|
-
if (t$
|
|
296
|
+
if (t$4(segments, 1)) {
|
|
312
297
|
return segments;
|
|
313
298
|
}
|
|
314
299
|
return [""];
|
|
@@ -320,7 +305,7 @@ const normalizeViewPath = (title) => {
|
|
|
320
305
|
};
|
|
321
306
|
const getViewFolderPath = (title) => {
|
|
322
307
|
const segments = splitViewTitle(title);
|
|
323
|
-
if (!t$
|
|
308
|
+
if (!t$4(segments, 2)) {
|
|
324
309
|
return null;
|
|
325
310
|
}
|
|
326
311
|
return segments.slice(0, -1).join(VIEW_FOLDERS_SEPARATOR);
|
|
@@ -662,13 +647,13 @@ class RelationshipModel {
|
|
|
662
647
|
return `${this.source.id} -> ${this.target.id}`;
|
|
663
648
|
}
|
|
664
649
|
get title() {
|
|
665
|
-
if (!e$
|
|
650
|
+
if (!e$1(this.$relationship.title)) {
|
|
666
651
|
return null;
|
|
667
652
|
}
|
|
668
653
|
return this.$relationship.title;
|
|
669
654
|
}
|
|
670
655
|
get technology() {
|
|
671
|
-
if (!e$
|
|
656
|
+
if (!e$1(this.$relationship.technology)) {
|
|
672
657
|
return null;
|
|
673
658
|
}
|
|
674
659
|
return this.$relationship.technology;
|
|
@@ -678,7 +663,7 @@ class RelationshipModel {
|
|
|
678
663
|
* (if one is missing - it falls back to another)
|
|
679
664
|
*/
|
|
680
665
|
get hasSummary() {
|
|
681
|
-
return !!this.$relationship.summary && !!this.$relationship.description && !t$
|
|
666
|
+
return !!this.$relationship.summary && !!this.$relationship.description && !t$3(this.$relationship.summary, this.$relationship.description);
|
|
682
667
|
}
|
|
683
668
|
/**
|
|
684
669
|
* Short description of the relationship.
|
|
@@ -736,7 +721,7 @@ class RelationshipModel {
|
|
|
736
721
|
return true;
|
|
737
722
|
}
|
|
738
723
|
hasMetadata() {
|
|
739
|
-
return !!this.$relationship.metadata && !e$
|
|
724
|
+
return !!this.$relationship.metadata && !e$2(this.$relationship.metadata);
|
|
740
725
|
}
|
|
741
726
|
getMetadata(field) {
|
|
742
727
|
if (field) {
|
|
@@ -752,1103 +737,6 @@ class RelationshipModel {
|
|
|
752
737
|
}
|
|
753
738
|
}
|
|
754
739
|
|
|
755
|
-
// src/utils/env.ts
|
|
756
|
-
var NOTHING = Symbol.for("immer-nothing");
|
|
757
|
-
var DRAFTABLE = Symbol.for("immer-draftable");
|
|
758
|
-
var DRAFT_STATE = Symbol.for("immer-state");
|
|
759
|
-
|
|
760
|
-
// src/utils/errors.ts
|
|
761
|
-
var errors = process.env.NODE_ENV !== "production" ? [
|
|
762
|
-
// All error codes, starting by 0:
|
|
763
|
-
function(plugin) {
|
|
764
|
-
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
765
|
-
},
|
|
766
|
-
function(thing) {
|
|
767
|
-
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
768
|
-
},
|
|
769
|
-
"This object has been frozen and should not be mutated",
|
|
770
|
-
function(data) {
|
|
771
|
-
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
772
|
-
},
|
|
773
|
-
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
774
|
-
"Immer forbids circular references",
|
|
775
|
-
"The first or second argument to `produce` must be a function",
|
|
776
|
-
"The third argument to `produce` must be a function or undefined",
|
|
777
|
-
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
778
|
-
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
779
|
-
function(thing) {
|
|
780
|
-
return `'current' expects a draft, got: ${thing}`;
|
|
781
|
-
},
|
|
782
|
-
"Object.defineProperty() cannot be used on an Immer draft",
|
|
783
|
-
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
784
|
-
"Immer only supports deleting array indices",
|
|
785
|
-
"Immer only supports setting array indices and the 'length' property",
|
|
786
|
-
function(thing) {
|
|
787
|
-
return `'original' expects a draft, got: ${thing}`;
|
|
788
|
-
}
|
|
789
|
-
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
790
|
-
// See Patches.ts for additional errors
|
|
791
|
-
] : [];
|
|
792
|
-
function die(error, ...args) {
|
|
793
|
-
if (process.env.NODE_ENV !== "production") {
|
|
794
|
-
const e = errors[error];
|
|
795
|
-
const msg = typeof e === "function" ? e.apply(null, args) : e;
|
|
796
|
-
throw new Error(`[Immer] ${msg}`);
|
|
797
|
-
}
|
|
798
|
-
throw new Error(
|
|
799
|
-
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// src/utils/common.ts
|
|
804
|
-
var getPrototypeOf = Object.getPrototypeOf;
|
|
805
|
-
function isDraft(value) {
|
|
806
|
-
return !!value && !!value[DRAFT_STATE];
|
|
807
|
-
}
|
|
808
|
-
function isDraftable(value) {
|
|
809
|
-
if (!value)
|
|
810
|
-
return false;
|
|
811
|
-
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
812
|
-
}
|
|
813
|
-
var objectCtorString = Object.prototype.constructor.toString();
|
|
814
|
-
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
815
|
-
function isPlainObject(value) {
|
|
816
|
-
if (!value || typeof value !== "object")
|
|
817
|
-
return false;
|
|
818
|
-
const proto = Object.getPrototypeOf(value);
|
|
819
|
-
if (proto === null || proto === Object.prototype)
|
|
820
|
-
return true;
|
|
821
|
-
const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
822
|
-
if (Ctor === Object)
|
|
823
|
-
return true;
|
|
824
|
-
if (typeof Ctor !== "function")
|
|
825
|
-
return false;
|
|
826
|
-
let ctorString = cachedCtorStrings.get(Ctor);
|
|
827
|
-
if (ctorString === void 0) {
|
|
828
|
-
ctorString = Function.toString.call(Ctor);
|
|
829
|
-
cachedCtorStrings.set(Ctor, ctorString);
|
|
830
|
-
}
|
|
831
|
-
return ctorString === objectCtorString;
|
|
832
|
-
}
|
|
833
|
-
function each(obj, iter, strict = true) {
|
|
834
|
-
if (getArchtype(obj) === 0 /* Object */) {
|
|
835
|
-
const keys = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
836
|
-
keys.forEach((key) => {
|
|
837
|
-
iter(key, obj[key], obj);
|
|
838
|
-
});
|
|
839
|
-
} else {
|
|
840
|
-
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
function getArchtype(thing) {
|
|
844
|
-
const state = thing[DRAFT_STATE];
|
|
845
|
-
return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
|
|
846
|
-
}
|
|
847
|
-
function has(thing, prop) {
|
|
848
|
-
return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
|
|
849
|
-
}
|
|
850
|
-
function set(thing, propOrOldValue, value) {
|
|
851
|
-
const t = getArchtype(thing);
|
|
852
|
-
if (t === 2 /* Map */)
|
|
853
|
-
thing.set(propOrOldValue, value);
|
|
854
|
-
else if (t === 3 /* Set */) {
|
|
855
|
-
thing.add(value);
|
|
856
|
-
} else
|
|
857
|
-
thing[propOrOldValue] = value;
|
|
858
|
-
}
|
|
859
|
-
function is(x, y) {
|
|
860
|
-
if (x === y) {
|
|
861
|
-
return x !== 0 || 1 / x === 1 / y;
|
|
862
|
-
} else {
|
|
863
|
-
return x !== x && y !== y;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function isMap(target) {
|
|
867
|
-
return target instanceof Map;
|
|
868
|
-
}
|
|
869
|
-
function isSet(target) {
|
|
870
|
-
return target instanceof Set;
|
|
871
|
-
}
|
|
872
|
-
function latest(state) {
|
|
873
|
-
return state.copy_ || state.base_;
|
|
874
|
-
}
|
|
875
|
-
function shallowCopy(base, strict) {
|
|
876
|
-
if (isMap(base)) {
|
|
877
|
-
return new Map(base);
|
|
878
|
-
}
|
|
879
|
-
if (isSet(base)) {
|
|
880
|
-
return new Set(base);
|
|
881
|
-
}
|
|
882
|
-
if (Array.isArray(base))
|
|
883
|
-
return Array.prototype.slice.call(base);
|
|
884
|
-
const isPlain = isPlainObject(base);
|
|
885
|
-
if (strict === true || strict === "class_only" && !isPlain) {
|
|
886
|
-
const descriptors = Object.getOwnPropertyDescriptors(base);
|
|
887
|
-
delete descriptors[DRAFT_STATE];
|
|
888
|
-
let keys = Reflect.ownKeys(descriptors);
|
|
889
|
-
for (let i = 0; i < keys.length; i++) {
|
|
890
|
-
const key = keys[i];
|
|
891
|
-
const desc = descriptors[key];
|
|
892
|
-
if (desc.writable === false) {
|
|
893
|
-
desc.writable = true;
|
|
894
|
-
desc.configurable = true;
|
|
895
|
-
}
|
|
896
|
-
if (desc.get || desc.set)
|
|
897
|
-
descriptors[key] = {
|
|
898
|
-
configurable: true,
|
|
899
|
-
writable: true,
|
|
900
|
-
// could live with !!desc.set as well here...
|
|
901
|
-
enumerable: desc.enumerable,
|
|
902
|
-
value: base[key]
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
return Object.create(getPrototypeOf(base), descriptors);
|
|
906
|
-
} else {
|
|
907
|
-
const proto = getPrototypeOf(base);
|
|
908
|
-
if (proto !== null && isPlain) {
|
|
909
|
-
return { ...base };
|
|
910
|
-
}
|
|
911
|
-
const obj = Object.create(proto);
|
|
912
|
-
return Object.assign(obj, base);
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
function freeze(obj, deep = false) {
|
|
916
|
-
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
917
|
-
return obj;
|
|
918
|
-
if (getArchtype(obj) > 1) {
|
|
919
|
-
Object.defineProperties(obj, {
|
|
920
|
-
set: dontMutateMethodOverride,
|
|
921
|
-
add: dontMutateMethodOverride,
|
|
922
|
-
clear: dontMutateMethodOverride,
|
|
923
|
-
delete: dontMutateMethodOverride
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
Object.freeze(obj);
|
|
927
|
-
if (deep)
|
|
928
|
-
Object.values(obj).forEach((value) => freeze(value, true));
|
|
929
|
-
return obj;
|
|
930
|
-
}
|
|
931
|
-
function dontMutateFrozenCollections() {
|
|
932
|
-
die(2);
|
|
933
|
-
}
|
|
934
|
-
var dontMutateMethodOverride = {
|
|
935
|
-
value: dontMutateFrozenCollections
|
|
936
|
-
};
|
|
937
|
-
function isFrozen(obj) {
|
|
938
|
-
if (obj === null || typeof obj !== "object")
|
|
939
|
-
return true;
|
|
940
|
-
return Object.isFrozen(obj);
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
// src/utils/plugins.ts
|
|
944
|
-
var plugins = {};
|
|
945
|
-
function getPlugin(pluginKey) {
|
|
946
|
-
const plugin = plugins[pluginKey];
|
|
947
|
-
if (!plugin) {
|
|
948
|
-
die(0, pluginKey);
|
|
949
|
-
}
|
|
950
|
-
return plugin;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// src/core/scope.ts
|
|
954
|
-
var currentScope;
|
|
955
|
-
function getCurrentScope() {
|
|
956
|
-
return currentScope;
|
|
957
|
-
}
|
|
958
|
-
function createScope(parent_, immer_) {
|
|
959
|
-
return {
|
|
960
|
-
drafts_: [],
|
|
961
|
-
parent_,
|
|
962
|
-
immer_,
|
|
963
|
-
// Whenever the modified draft contains a draft from another scope, we
|
|
964
|
-
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
965
|
-
canAutoFreeze_: true,
|
|
966
|
-
unfinalizedDrafts_: 0
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
function usePatchesInScope(scope, patchListener) {
|
|
970
|
-
if (patchListener) {
|
|
971
|
-
getPlugin("Patches");
|
|
972
|
-
scope.patches_ = [];
|
|
973
|
-
scope.inversePatches_ = [];
|
|
974
|
-
scope.patchListener_ = patchListener;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
function revokeScope(scope) {
|
|
978
|
-
leaveScope(scope);
|
|
979
|
-
scope.drafts_.forEach(revokeDraft);
|
|
980
|
-
scope.drafts_ = null;
|
|
981
|
-
}
|
|
982
|
-
function leaveScope(scope) {
|
|
983
|
-
if (scope === currentScope) {
|
|
984
|
-
currentScope = scope.parent_;
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
function enterScope(immer2) {
|
|
988
|
-
return currentScope = createScope(currentScope, immer2);
|
|
989
|
-
}
|
|
990
|
-
function revokeDraft(draft) {
|
|
991
|
-
const state = draft[DRAFT_STATE];
|
|
992
|
-
if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
|
|
993
|
-
state.revoke_();
|
|
994
|
-
else
|
|
995
|
-
state.revoked_ = true;
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
// src/core/finalize.ts
|
|
999
|
-
function processResult(result, scope) {
|
|
1000
|
-
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
1001
|
-
const baseDraft = scope.drafts_[0];
|
|
1002
|
-
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
1003
|
-
if (isReplaced) {
|
|
1004
|
-
if (baseDraft[DRAFT_STATE].modified_) {
|
|
1005
|
-
revokeScope(scope);
|
|
1006
|
-
die(4);
|
|
1007
|
-
}
|
|
1008
|
-
if (isDraftable(result)) {
|
|
1009
|
-
result = finalize(scope, result);
|
|
1010
|
-
if (!scope.parent_)
|
|
1011
|
-
maybeFreeze(scope, result);
|
|
1012
|
-
}
|
|
1013
|
-
if (scope.patches_) {
|
|
1014
|
-
getPlugin("Patches").generateReplacementPatches_(
|
|
1015
|
-
baseDraft[DRAFT_STATE].base_,
|
|
1016
|
-
result,
|
|
1017
|
-
scope.patches_,
|
|
1018
|
-
scope.inversePatches_
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
} else {
|
|
1022
|
-
result = finalize(scope, baseDraft, []);
|
|
1023
|
-
}
|
|
1024
|
-
revokeScope(scope);
|
|
1025
|
-
if (scope.patches_) {
|
|
1026
|
-
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
1027
|
-
}
|
|
1028
|
-
return result !== NOTHING ? result : void 0;
|
|
1029
|
-
}
|
|
1030
|
-
function finalize(rootScope, value, path) {
|
|
1031
|
-
if (isFrozen(value))
|
|
1032
|
-
return value;
|
|
1033
|
-
const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
|
|
1034
|
-
const state = value[DRAFT_STATE];
|
|
1035
|
-
if (!state) {
|
|
1036
|
-
each(
|
|
1037
|
-
value,
|
|
1038
|
-
(key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path),
|
|
1039
|
-
useStrictIteration
|
|
1040
|
-
);
|
|
1041
|
-
return value;
|
|
1042
|
-
}
|
|
1043
|
-
if (state.scope_ !== rootScope)
|
|
1044
|
-
return value;
|
|
1045
|
-
if (!state.modified_) {
|
|
1046
|
-
maybeFreeze(rootScope, state.base_, true);
|
|
1047
|
-
return state.base_;
|
|
1048
|
-
}
|
|
1049
|
-
if (!state.finalized_) {
|
|
1050
|
-
state.finalized_ = true;
|
|
1051
|
-
state.scope_.unfinalizedDrafts_--;
|
|
1052
|
-
const result = state.copy_;
|
|
1053
|
-
let resultEach = result;
|
|
1054
|
-
let isSet2 = false;
|
|
1055
|
-
if (state.type_ === 3 /* Set */) {
|
|
1056
|
-
resultEach = new Set(result);
|
|
1057
|
-
result.clear();
|
|
1058
|
-
isSet2 = true;
|
|
1059
|
-
}
|
|
1060
|
-
each(
|
|
1061
|
-
resultEach,
|
|
1062
|
-
(key, childValue) => finalizeProperty(
|
|
1063
|
-
rootScope,
|
|
1064
|
-
state,
|
|
1065
|
-
result,
|
|
1066
|
-
key,
|
|
1067
|
-
childValue,
|
|
1068
|
-
path,
|
|
1069
|
-
isSet2
|
|
1070
|
-
),
|
|
1071
|
-
useStrictIteration
|
|
1072
|
-
);
|
|
1073
|
-
maybeFreeze(rootScope, result, false);
|
|
1074
|
-
if (path && rootScope.patches_) {
|
|
1075
|
-
getPlugin("Patches").generatePatches_(
|
|
1076
|
-
state,
|
|
1077
|
-
path,
|
|
1078
|
-
rootScope.patches_,
|
|
1079
|
-
rootScope.inversePatches_
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
return state.copy_;
|
|
1084
|
-
}
|
|
1085
|
-
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
|
|
1086
|
-
if (childValue == null) {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
if (typeof childValue !== "object" && !targetIsSet) {
|
|
1090
|
-
return;
|
|
1091
|
-
}
|
|
1092
|
-
const childIsFrozen = isFrozen(childValue);
|
|
1093
|
-
if (childIsFrozen && !targetIsSet) {
|
|
1094
|
-
return;
|
|
1095
|
-
}
|
|
1096
|
-
if (process.env.NODE_ENV !== "production" && childValue === targetObject)
|
|
1097
|
-
die(5);
|
|
1098
|
-
if (isDraft(childValue)) {
|
|
1099
|
-
const path = rootPath && parentState && parentState.type_ !== 3 /* Set */ && // Set objects are atomic since they have no keys.
|
|
1100
|
-
!has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
|
|
1101
|
-
const res = finalize(rootScope, childValue, path);
|
|
1102
|
-
set(targetObject, prop, res);
|
|
1103
|
-
if (isDraft(res)) {
|
|
1104
|
-
rootScope.canAutoFreeze_ = false;
|
|
1105
|
-
} else
|
|
1106
|
-
return;
|
|
1107
|
-
} else if (targetIsSet) {
|
|
1108
|
-
targetObject.add(childValue);
|
|
1109
|
-
}
|
|
1110
|
-
if (isDraftable(childValue) && !childIsFrozen) {
|
|
1111
|
-
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) {
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
finalize(rootScope, childValue);
|
|
1118
|
-
if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop)))
|
|
1119
|
-
maybeFreeze(rootScope, childValue);
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
function maybeFreeze(scope, value, deep = false) {
|
|
1123
|
-
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
1124
|
-
freeze(value, deep);
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
// src/core/proxy.ts
|
|
1129
|
-
function createProxyProxy(base, parent) {
|
|
1130
|
-
const isArray = Array.isArray(base);
|
|
1131
|
-
const state = {
|
|
1132
|
-
type_: isArray ? 1 /* Array */ : 0 /* Object */,
|
|
1133
|
-
// Track which produce call this is associated with.
|
|
1134
|
-
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
1135
|
-
// True for both shallow and deep changes.
|
|
1136
|
-
modified_: false,
|
|
1137
|
-
// Used during finalization.
|
|
1138
|
-
finalized_: false,
|
|
1139
|
-
// Track which properties have been assigned (true) or deleted (false).
|
|
1140
|
-
assigned_: {},
|
|
1141
|
-
// The parent draft state.
|
|
1142
|
-
parent_: parent,
|
|
1143
|
-
// The base state.
|
|
1144
|
-
base_: base,
|
|
1145
|
-
// The base proxy.
|
|
1146
|
-
draft_: null,
|
|
1147
|
-
// set below
|
|
1148
|
-
// The base copy with any updated values.
|
|
1149
|
-
copy_: null,
|
|
1150
|
-
// Called by the `produce` function.
|
|
1151
|
-
revoke_: null,
|
|
1152
|
-
isManual_: false
|
|
1153
|
-
};
|
|
1154
|
-
let target = state;
|
|
1155
|
-
let traps = objectTraps;
|
|
1156
|
-
if (isArray) {
|
|
1157
|
-
target = [state];
|
|
1158
|
-
traps = arrayTraps;
|
|
1159
|
-
}
|
|
1160
|
-
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
1161
|
-
state.draft_ = proxy;
|
|
1162
|
-
state.revoke_ = revoke;
|
|
1163
|
-
return proxy;
|
|
1164
|
-
}
|
|
1165
|
-
var objectTraps = {
|
|
1166
|
-
get(state, prop) {
|
|
1167
|
-
if (prop === DRAFT_STATE)
|
|
1168
|
-
return state;
|
|
1169
|
-
const source = latest(state);
|
|
1170
|
-
if (!has(source, prop)) {
|
|
1171
|
-
return readPropFromProto(state, source, prop);
|
|
1172
|
-
}
|
|
1173
|
-
const value = source[prop];
|
|
1174
|
-
if (state.finalized_ || !isDraftable(value)) {
|
|
1175
|
-
return value;
|
|
1176
|
-
}
|
|
1177
|
-
if (value === peek(state.base_, prop)) {
|
|
1178
|
-
prepareCopy(state);
|
|
1179
|
-
return state.copy_[prop] = createProxy(value, state);
|
|
1180
|
-
}
|
|
1181
|
-
return value;
|
|
1182
|
-
},
|
|
1183
|
-
has(state, prop) {
|
|
1184
|
-
return prop in latest(state);
|
|
1185
|
-
},
|
|
1186
|
-
ownKeys(state) {
|
|
1187
|
-
return Reflect.ownKeys(latest(state));
|
|
1188
|
-
},
|
|
1189
|
-
set(state, prop, value) {
|
|
1190
|
-
const desc = getDescriptorFromProto(latest(state), prop);
|
|
1191
|
-
if (desc?.set) {
|
|
1192
|
-
desc.set.call(state.draft_, value);
|
|
1193
|
-
return true;
|
|
1194
|
-
}
|
|
1195
|
-
if (!state.modified_) {
|
|
1196
|
-
const current2 = peek(latest(state), prop);
|
|
1197
|
-
const currentState = current2?.[DRAFT_STATE];
|
|
1198
|
-
if (currentState && currentState.base_ === value) {
|
|
1199
|
-
state.copy_[prop] = value;
|
|
1200
|
-
state.assigned_[prop] = false;
|
|
1201
|
-
return true;
|
|
1202
|
-
}
|
|
1203
|
-
if (is(value, current2) && (value !== void 0 || has(state.base_, prop)))
|
|
1204
|
-
return true;
|
|
1205
|
-
prepareCopy(state);
|
|
1206
|
-
markChanged(state);
|
|
1207
|
-
}
|
|
1208
|
-
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
1209
|
-
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
1210
|
-
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
1211
|
-
return true;
|
|
1212
|
-
state.copy_[prop] = value;
|
|
1213
|
-
state.assigned_[prop] = true;
|
|
1214
|
-
return true;
|
|
1215
|
-
},
|
|
1216
|
-
deleteProperty(state, prop) {
|
|
1217
|
-
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
1218
|
-
state.assigned_[prop] = false;
|
|
1219
|
-
prepareCopy(state);
|
|
1220
|
-
markChanged(state);
|
|
1221
|
-
} else {
|
|
1222
|
-
delete state.assigned_[prop];
|
|
1223
|
-
}
|
|
1224
|
-
if (state.copy_) {
|
|
1225
|
-
delete state.copy_[prop];
|
|
1226
|
-
}
|
|
1227
|
-
return true;
|
|
1228
|
-
},
|
|
1229
|
-
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
1230
|
-
// the same guarantee in ES5 mode.
|
|
1231
|
-
getOwnPropertyDescriptor(state, prop) {
|
|
1232
|
-
const owner = latest(state);
|
|
1233
|
-
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
1234
|
-
if (!desc)
|
|
1235
|
-
return desc;
|
|
1236
|
-
return {
|
|
1237
|
-
writable: true,
|
|
1238
|
-
configurable: state.type_ !== 1 /* Array */ || prop !== "length",
|
|
1239
|
-
enumerable: desc.enumerable,
|
|
1240
|
-
value: owner[prop]
|
|
1241
|
-
};
|
|
1242
|
-
},
|
|
1243
|
-
defineProperty() {
|
|
1244
|
-
die(11);
|
|
1245
|
-
},
|
|
1246
|
-
getPrototypeOf(state) {
|
|
1247
|
-
return getPrototypeOf(state.base_);
|
|
1248
|
-
},
|
|
1249
|
-
setPrototypeOf() {
|
|
1250
|
-
die(12);
|
|
1251
|
-
}
|
|
1252
|
-
};
|
|
1253
|
-
var arrayTraps = {};
|
|
1254
|
-
each(objectTraps, (key, fn) => {
|
|
1255
|
-
arrayTraps[key] = function() {
|
|
1256
|
-
arguments[0] = arguments[0][0];
|
|
1257
|
-
return fn.apply(this, arguments);
|
|
1258
|
-
};
|
|
1259
|
-
});
|
|
1260
|
-
arrayTraps.deleteProperty = function(state, prop) {
|
|
1261
|
-
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
1262
|
-
die(13);
|
|
1263
|
-
return arrayTraps.set.call(this, state, prop, void 0);
|
|
1264
|
-
};
|
|
1265
|
-
arrayTraps.set = function(state, prop, value) {
|
|
1266
|
-
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
1267
|
-
die(14);
|
|
1268
|
-
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
1269
|
-
};
|
|
1270
|
-
function peek(draft, prop) {
|
|
1271
|
-
const state = draft[DRAFT_STATE];
|
|
1272
|
-
const source = state ? latest(state) : draft;
|
|
1273
|
-
return source[prop];
|
|
1274
|
-
}
|
|
1275
|
-
function readPropFromProto(state, source, prop) {
|
|
1276
|
-
const desc = getDescriptorFromProto(source, prop);
|
|
1277
|
-
return desc ? `value` in desc ? desc.value : (
|
|
1278
|
-
// This is a very special case, if the prop is a getter defined by the
|
|
1279
|
-
// prototype, we should invoke it with the draft as context!
|
|
1280
|
-
desc.get?.call(state.draft_)
|
|
1281
|
-
) : void 0;
|
|
1282
|
-
}
|
|
1283
|
-
function getDescriptorFromProto(source, prop) {
|
|
1284
|
-
if (!(prop in source))
|
|
1285
|
-
return void 0;
|
|
1286
|
-
let proto = getPrototypeOf(source);
|
|
1287
|
-
while (proto) {
|
|
1288
|
-
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
1289
|
-
if (desc)
|
|
1290
|
-
return desc;
|
|
1291
|
-
proto = getPrototypeOf(proto);
|
|
1292
|
-
}
|
|
1293
|
-
return void 0;
|
|
1294
|
-
}
|
|
1295
|
-
function markChanged(state) {
|
|
1296
|
-
if (!state.modified_) {
|
|
1297
|
-
state.modified_ = true;
|
|
1298
|
-
if (state.parent_) {
|
|
1299
|
-
markChanged(state.parent_);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
function prepareCopy(state) {
|
|
1304
|
-
if (!state.copy_) {
|
|
1305
|
-
state.copy_ = shallowCopy(
|
|
1306
|
-
state.base_,
|
|
1307
|
-
state.scope_.immer_.useStrictShallowCopy_
|
|
1308
|
-
);
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
// src/core/immerClass.ts
|
|
1313
|
-
var Immer2 = class {
|
|
1314
|
-
constructor(config) {
|
|
1315
|
-
this.autoFreeze_ = true;
|
|
1316
|
-
this.useStrictShallowCopy_ = false;
|
|
1317
|
-
this.useStrictIteration_ = true;
|
|
1318
|
-
/**
|
|
1319
|
-
* The `produce` function takes a value and a "recipe function" (whose
|
|
1320
|
-
* return value often depends on the base state). The recipe function is
|
|
1321
|
-
* free to mutate its first argument however it wants. All mutations are
|
|
1322
|
-
* only ever applied to a __copy__ of the base state.
|
|
1323
|
-
*
|
|
1324
|
-
* Pass only a function to create a "curried producer" which relieves you
|
|
1325
|
-
* from passing the recipe function every time.
|
|
1326
|
-
*
|
|
1327
|
-
* Only plain objects and arrays are made mutable. All other objects are
|
|
1328
|
-
* considered uncopyable.
|
|
1329
|
-
*
|
|
1330
|
-
* Note: This function is __bound__ to its `Immer` instance.
|
|
1331
|
-
*
|
|
1332
|
-
* @param {any} base - the initial state
|
|
1333
|
-
* @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
|
|
1334
|
-
* @param {Function} patchListener - optional function that will be called with all the patches produced here
|
|
1335
|
-
* @returns {any} a new state, or the initial state if nothing was modified
|
|
1336
|
-
*/
|
|
1337
|
-
this.produce = (base, recipe, patchListener) => {
|
|
1338
|
-
if (typeof base === "function" && typeof recipe !== "function") {
|
|
1339
|
-
const defaultBase = recipe;
|
|
1340
|
-
recipe = base;
|
|
1341
|
-
const self = this;
|
|
1342
|
-
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
1343
|
-
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
1344
|
-
};
|
|
1345
|
-
}
|
|
1346
|
-
if (typeof recipe !== "function")
|
|
1347
|
-
die(6);
|
|
1348
|
-
if (patchListener !== void 0 && typeof patchListener !== "function")
|
|
1349
|
-
die(7);
|
|
1350
|
-
let result;
|
|
1351
|
-
if (isDraftable(base)) {
|
|
1352
|
-
const scope = enterScope(this);
|
|
1353
|
-
const proxy = createProxy(base, void 0);
|
|
1354
|
-
let hasError = true;
|
|
1355
|
-
try {
|
|
1356
|
-
result = recipe(proxy);
|
|
1357
|
-
hasError = false;
|
|
1358
|
-
} finally {
|
|
1359
|
-
if (hasError)
|
|
1360
|
-
revokeScope(scope);
|
|
1361
|
-
else
|
|
1362
|
-
leaveScope(scope);
|
|
1363
|
-
}
|
|
1364
|
-
usePatchesInScope(scope, patchListener);
|
|
1365
|
-
return processResult(result, scope);
|
|
1366
|
-
} else if (!base || typeof base !== "object") {
|
|
1367
|
-
result = recipe(base);
|
|
1368
|
-
if (result === void 0)
|
|
1369
|
-
result = base;
|
|
1370
|
-
if (result === NOTHING)
|
|
1371
|
-
result = void 0;
|
|
1372
|
-
if (this.autoFreeze_)
|
|
1373
|
-
freeze(result, true);
|
|
1374
|
-
if (patchListener) {
|
|
1375
|
-
const p = [];
|
|
1376
|
-
const ip = [];
|
|
1377
|
-
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
|
|
1378
|
-
patchListener(p, ip);
|
|
1379
|
-
}
|
|
1380
|
-
return result;
|
|
1381
|
-
} else
|
|
1382
|
-
die(1, base);
|
|
1383
|
-
};
|
|
1384
|
-
this.produceWithPatches = (base, recipe) => {
|
|
1385
|
-
if (typeof base === "function") {
|
|
1386
|
-
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
1387
|
-
}
|
|
1388
|
-
let patches, inversePatches;
|
|
1389
|
-
const result = this.produce(base, recipe, (p, ip) => {
|
|
1390
|
-
patches = p;
|
|
1391
|
-
inversePatches = ip;
|
|
1392
|
-
});
|
|
1393
|
-
return [result, patches, inversePatches];
|
|
1394
|
-
};
|
|
1395
|
-
if (typeof config?.autoFreeze === "boolean")
|
|
1396
|
-
this.setAutoFreeze(config.autoFreeze);
|
|
1397
|
-
if (typeof config?.useStrictShallowCopy === "boolean")
|
|
1398
|
-
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
1399
|
-
if (typeof config?.useStrictIteration === "boolean")
|
|
1400
|
-
this.setUseStrictIteration(config.useStrictIteration);
|
|
1401
|
-
}
|
|
1402
|
-
createDraft(base) {
|
|
1403
|
-
if (!isDraftable(base))
|
|
1404
|
-
die(8);
|
|
1405
|
-
if (isDraft(base))
|
|
1406
|
-
base = current(base);
|
|
1407
|
-
const scope = enterScope(this);
|
|
1408
|
-
const proxy = createProxy(base, void 0);
|
|
1409
|
-
proxy[DRAFT_STATE].isManual_ = true;
|
|
1410
|
-
leaveScope(scope);
|
|
1411
|
-
return proxy;
|
|
1412
|
-
}
|
|
1413
|
-
finishDraft(draft, patchListener) {
|
|
1414
|
-
const state = draft && draft[DRAFT_STATE];
|
|
1415
|
-
if (!state || !state.isManual_)
|
|
1416
|
-
die(9);
|
|
1417
|
-
const { scope_: scope } = state;
|
|
1418
|
-
usePatchesInScope(scope, patchListener);
|
|
1419
|
-
return processResult(void 0, scope);
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* Pass true to automatically freeze all copies created by Immer.
|
|
1423
|
-
*
|
|
1424
|
-
* By default, auto-freezing is enabled.
|
|
1425
|
-
*/
|
|
1426
|
-
setAutoFreeze(value) {
|
|
1427
|
-
this.autoFreeze_ = value;
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Pass true to enable strict shallow copy.
|
|
1431
|
-
*
|
|
1432
|
-
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
1433
|
-
*/
|
|
1434
|
-
setUseStrictShallowCopy(value) {
|
|
1435
|
-
this.useStrictShallowCopy_ = value;
|
|
1436
|
-
}
|
|
1437
|
-
/**
|
|
1438
|
-
* Pass false to use faster iteration that skips non-enumerable properties
|
|
1439
|
-
* but still handles symbols for compatibility.
|
|
1440
|
-
*
|
|
1441
|
-
* By default, strict iteration is enabled (includes all own properties).
|
|
1442
|
-
*/
|
|
1443
|
-
setUseStrictIteration(value) {
|
|
1444
|
-
this.useStrictIteration_ = value;
|
|
1445
|
-
}
|
|
1446
|
-
shouldUseStrictIteration() {
|
|
1447
|
-
return this.useStrictIteration_;
|
|
1448
|
-
}
|
|
1449
|
-
applyPatches(base, patches) {
|
|
1450
|
-
let i;
|
|
1451
|
-
for (i = patches.length - 1; i >= 0; i--) {
|
|
1452
|
-
const patch = patches[i];
|
|
1453
|
-
if (patch.path.length === 0 && patch.op === "replace") {
|
|
1454
|
-
base = patch.value;
|
|
1455
|
-
break;
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
if (i > -1) {
|
|
1459
|
-
patches = patches.slice(i + 1);
|
|
1460
|
-
}
|
|
1461
|
-
const applyPatchesImpl = getPlugin("Patches").applyPatches_;
|
|
1462
|
-
if (isDraft(base)) {
|
|
1463
|
-
return applyPatchesImpl(base, patches);
|
|
1464
|
-
}
|
|
1465
|
-
return this.produce(
|
|
1466
|
-
base,
|
|
1467
|
-
(draft) => applyPatchesImpl(draft, patches)
|
|
1468
|
-
);
|
|
1469
|
-
}
|
|
1470
|
-
};
|
|
1471
|
-
function createProxy(value, parent) {
|
|
1472
|
-
const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1473
|
-
const scope = parent ? parent.scope_ : getCurrentScope();
|
|
1474
|
-
scope.drafts_.push(draft);
|
|
1475
|
-
return draft;
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
// src/core/current.ts
|
|
1479
|
-
function current(value) {
|
|
1480
|
-
if (!isDraft(value))
|
|
1481
|
-
die(10, value);
|
|
1482
|
-
return currentImpl(value);
|
|
1483
|
-
}
|
|
1484
|
-
function currentImpl(value) {
|
|
1485
|
-
if (!isDraftable(value) || isFrozen(value))
|
|
1486
|
-
return value;
|
|
1487
|
-
const state = value[DRAFT_STATE];
|
|
1488
|
-
let copy;
|
|
1489
|
-
let strict = true;
|
|
1490
|
-
if (state) {
|
|
1491
|
-
if (!state.modified_)
|
|
1492
|
-
return state.base_;
|
|
1493
|
-
state.finalized_ = true;
|
|
1494
|
-
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1495
|
-
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
1496
|
-
} else {
|
|
1497
|
-
copy = shallowCopy(value, true);
|
|
1498
|
-
}
|
|
1499
|
-
each(
|
|
1500
|
-
copy,
|
|
1501
|
-
(key, childValue) => {
|
|
1502
|
-
set(copy, key, currentImpl(childValue));
|
|
1503
|
-
},
|
|
1504
|
-
strict
|
|
1505
|
-
);
|
|
1506
|
-
if (state) {
|
|
1507
|
-
state.finalized_ = false;
|
|
1508
|
-
}
|
|
1509
|
-
return copy;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
// src/immer.ts
|
|
1513
|
-
var immer = new Immer2();
|
|
1514
|
-
var produce = immer.produce;
|
|
1515
|
-
|
|
1516
|
-
function buildElementNotations(nodes) {
|
|
1517
|
-
return t$a(
|
|
1518
|
-
nodes,
|
|
1519
|
-
n$5((n) => !!n.notation),
|
|
1520
|
-
t$5(e$5("notation")),
|
|
1521
|
-
t$3(
|
|
1522
|
-
t$2(
|
|
1523
|
-
t$5(e$5("shape")),
|
|
1524
|
-
t$3(
|
|
1525
|
-
t$2(
|
|
1526
|
-
t$5(e$5("color")),
|
|
1527
|
-
t$3(
|
|
1528
|
-
t$2(
|
|
1529
|
-
t$e(e$5("kind")),
|
|
1530
|
-
n$6()
|
|
1531
|
-
)
|
|
1532
|
-
),
|
|
1533
|
-
t$d(),
|
|
1534
|
-
t$e(([color, kinds]) => ({
|
|
1535
|
-
kinds,
|
|
1536
|
-
color
|
|
1537
|
-
}))
|
|
1538
|
-
)
|
|
1539
|
-
),
|
|
1540
|
-
t$d(),
|
|
1541
|
-
t$6(
|
|
1542
|
-
([shape, colors]) => colors.map(({ color, kinds }) => ({
|
|
1543
|
-
shape,
|
|
1544
|
-
color,
|
|
1545
|
-
kinds
|
|
1546
|
-
}))
|
|
1547
|
-
)
|
|
1548
|
-
)
|
|
1549
|
-
),
|
|
1550
|
-
t$d(),
|
|
1551
|
-
t$6(
|
|
1552
|
-
([title, shapes]) => shapes.map(({ shape, color, kinds }) => ({
|
|
1553
|
-
title,
|
|
1554
|
-
shape,
|
|
1555
|
-
color,
|
|
1556
|
-
kinds
|
|
1557
|
-
}))
|
|
1558
|
-
),
|
|
1559
|
-
t$1(
|
|
1560
|
-
e$5("shape"),
|
|
1561
|
-
e$5("title"),
|
|
1562
|
-
[
|
|
1563
|
-
(n) => n.kinds.length,
|
|
1564
|
-
"desc"
|
|
1565
|
-
]
|
|
1566
|
-
)
|
|
1567
|
-
);
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
const changed = (a, b) => {
|
|
1571
|
-
if (a === b || e$6(a) && e$6(b)) {
|
|
1572
|
-
return false;
|
|
1573
|
-
}
|
|
1574
|
-
return !t$f(a, b);
|
|
1575
|
-
};
|
|
1576
|
-
const MAX_ALLOWED_DRIFT = 5;
|
|
1577
|
-
function autoApplyMetaAndStyles(draft, next) {
|
|
1578
|
-
draft.color = next.color;
|
|
1579
|
-
draft.kind = next.kind;
|
|
1580
|
-
draft.navigateTo = next.navigateTo ?? null;
|
|
1581
|
-
draft.links = next.links ? [...next.links] : null;
|
|
1582
|
-
draft.tags = [...next.tags];
|
|
1583
|
-
if (e$6(next.style.border)) {
|
|
1584
|
-
delete draft.style.border;
|
|
1585
|
-
} else {
|
|
1586
|
-
draft.style.border = next.style.border;
|
|
1587
|
-
}
|
|
1588
|
-
if (e$1(next.style.opacity)) {
|
|
1589
|
-
draft.style.opacity = next.style.opacity;
|
|
1590
|
-
} else {
|
|
1591
|
-
delete draft.style.opacity;
|
|
1592
|
-
}
|
|
1593
|
-
if (e$6(next.style.multiple)) {
|
|
1594
|
-
delete draft.style.multiple;
|
|
1595
|
-
} else {
|
|
1596
|
-
draft.style.multiple = next.style.multiple;
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
function autoApplyIcon(draft, next, sizeNotChanged) {
|
|
1600
|
-
if (changed(next.icon ?? "none", draft.icon ?? "none")) {
|
|
1601
|
-
const iconWasSet = e$3(draft.icon) && draft.icon !== "none";
|
|
1602
|
-
switch (true) {
|
|
1603
|
-
// Icon was set before and changed, auto-apply
|
|
1604
|
-
case (iconWasSet && e$3(next.icon) && next.icon !== "none"): {
|
|
1605
|
-
draft.icon = next.icon;
|
|
1606
|
-
return true;
|
|
1607
|
-
}
|
|
1608
|
-
// Icon was set before and now removed, auto-apply
|
|
1609
|
-
case (iconWasSet && (e$6(next.icon) || next.icon === "none")): {
|
|
1610
|
-
draft.icon = "none";
|
|
1611
|
-
return true;
|
|
1612
|
-
}
|
|
1613
|
-
// Icon was added
|
|
1614
|
-
case (!iconWasSet && e$3(next.icon) && next.icon !== "none"): {
|
|
1615
|
-
if (sizeNotChanged) {
|
|
1616
|
-
draft.icon = next.icon;
|
|
1617
|
-
return true;
|
|
1618
|
-
} else {
|
|
1619
|
-
return false;
|
|
1620
|
-
}
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
return true;
|
|
1625
|
-
}
|
|
1626
|
-
function autoApplyLabelsToLeaf(draft, next, sizeNotChanged) {
|
|
1627
|
-
let applied = true;
|
|
1628
|
-
if (changed(draft.title, next.title)) {
|
|
1629
|
-
if (sizeNotChanged) {
|
|
1630
|
-
draft.title = next.title;
|
|
1631
|
-
} else {
|
|
1632
|
-
applied = false;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
if (changed(draft.description, next.description)) {
|
|
1636
|
-
if (e$6(next.description)) {
|
|
1637
|
-
delete draft.description;
|
|
1638
|
-
} else if (sizeNotChanged) {
|
|
1639
|
-
draft.description = next.description;
|
|
1640
|
-
} else {
|
|
1641
|
-
applied = false;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
if (changed(draft.technology, next.technology)) {
|
|
1645
|
-
if (e$6(next.technology)) {
|
|
1646
|
-
delete draft.technology;
|
|
1647
|
-
} else if (sizeNotChanged) {
|
|
1648
|
-
draft.technology = next.technology;
|
|
1649
|
-
} else {
|
|
1650
|
-
applied = false;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
return applied;
|
|
1654
|
-
}
|
|
1655
|
-
function autoApplyLabelsToCompound(draft, next, _sizeNotChanged) {
|
|
1656
|
-
draft.title = next.title;
|
|
1657
|
-
if (e$6(next.description)) {
|
|
1658
|
-
delete draft.description;
|
|
1659
|
-
} else {
|
|
1660
|
-
draft.description = next.description;
|
|
1661
|
-
}
|
|
1662
|
-
if (e$6(next.technology)) {
|
|
1663
|
-
delete draft.technology;
|
|
1664
|
-
} else {
|
|
1665
|
-
draft.technology = next.technology;
|
|
1666
|
-
}
|
|
1667
|
-
return true;
|
|
1668
|
-
}
|
|
1669
|
-
function applyManualLayout(autoLayouted, snapshot) {
|
|
1670
|
-
invariant(autoLayouted.id === snapshot.id, "applyManualLayout: view ids do not match");
|
|
1671
|
-
invariant(autoLayouted._stage === "layouted", "applyManualLayout: expected layouted view");
|
|
1672
|
-
invariant(snapshot._stage === "layouted", "applyManualLayout: expected layouted snapshot");
|
|
1673
|
-
invariant(autoLayouted._layout !== "manual", "applyManualLayout: expected auto-layouted view");
|
|
1674
|
-
const viewDrifts = /* @__PURE__ */ new Set();
|
|
1675
|
-
if (autoLayouted._type !== snapshot._type) {
|
|
1676
|
-
viewDrifts.add("type-changed");
|
|
1677
|
-
}
|
|
1678
|
-
const nextNodes = new Map(autoLayouted.nodes.map((n) => [n.id, n]));
|
|
1679
|
-
const nextEdges = new Map(autoLayouted.edges.map((e) => [e.id, e]));
|
|
1680
|
-
const nextNodeIds = new Set(nextNodes.keys());
|
|
1681
|
-
const nextEdgeIds = new Set(nextEdges.keys());
|
|
1682
|
-
const snapshotNodeIds = new Set(snapshot.nodes.map((n) => n.id));
|
|
1683
|
-
const snapshotEdgeIds = new Set(snapshot.edges.map((e) => e.id));
|
|
1684
|
-
if (symmetricDifference(nextNodeIds, snapshotNodeIds).size > 0) {
|
|
1685
|
-
viewDrifts.add("nodes-mismatch");
|
|
1686
|
-
}
|
|
1687
|
-
if (symmetricDifference(nextEdgeIds, snapshotEdgeIds).size > 0) {
|
|
1688
|
-
viewDrifts.add("edges-mismatch");
|
|
1689
|
-
}
|
|
1690
|
-
const nodes = snapshot.nodes.map((node) => {
|
|
1691
|
-
const next = nextNodes.get(node.id);
|
|
1692
|
-
return produce(node, (draft) => {
|
|
1693
|
-
if (!next) {
|
|
1694
|
-
draft.drifts = ["missing"];
|
|
1695
|
-
return;
|
|
1696
|
-
}
|
|
1697
|
-
autoApplyMetaAndStyles(draft, next);
|
|
1698
|
-
const nodeDrifts = /* @__PURE__ */ new Set();
|
|
1699
|
-
const wasCompound = node.children.length > 0;
|
|
1700
|
-
const willBeCompound = next.children.length > 0;
|
|
1701
|
-
if (changed(draft.modelRef, next.modelRef) || changed(draft.deploymentRef, next.deploymentRef)) {
|
|
1702
|
-
nodeDrifts.add("modelRef-changed");
|
|
1703
|
-
}
|
|
1704
|
-
if (willBeCompound && !wasCompound) {
|
|
1705
|
-
nodeDrifts.add("became-compound");
|
|
1706
|
-
}
|
|
1707
|
-
if (!willBeCompound && wasCompound) {
|
|
1708
|
-
nodeDrifts.add("became-leaf");
|
|
1709
|
-
}
|
|
1710
|
-
if (changed(draft.parent, next.parent)) {
|
|
1711
|
-
nodeDrifts.add("parent-changed");
|
|
1712
|
-
}
|
|
1713
|
-
const sizeNotChanged = draft.width + MAX_ALLOWED_DRIFT >= next.width && draft.height + MAX_ALLOWED_DRIFT >= next.height;
|
|
1714
|
-
if (changed(draft.shape, next.shape)) {
|
|
1715
|
-
if (sizeNotChanged) {
|
|
1716
|
-
draft.shape = next.shape;
|
|
1717
|
-
} else {
|
|
1718
|
-
nodeDrifts.add("shape-changed");
|
|
1719
|
-
}
|
|
1720
|
-
}
|
|
1721
|
-
if (!autoApplyIcon(draft, next, sizeNotChanged && willBeCompound === wasCompound)) {
|
|
1722
|
-
nodeDrifts.add("label-changed");
|
|
1723
|
-
}
|
|
1724
|
-
const autoApplyLabels = wasCompound ? autoApplyLabelsToCompound : autoApplyLabelsToLeaf;
|
|
1725
|
-
if (!autoApplyLabels(draft, next, sizeNotChanged)) {
|
|
1726
|
-
nodeDrifts.add("label-changed");
|
|
1727
|
-
}
|
|
1728
|
-
if (changed(node.notation, next.notation)) {
|
|
1729
|
-
draft.notation = next.notation ?? null;
|
|
1730
|
-
}
|
|
1731
|
-
if (wasCompound && willBeCompound && symmetricDifference(new Set(node.children), new Set(next.children)).size > 0) {
|
|
1732
|
-
nodeDrifts.add("children-changed");
|
|
1733
|
-
}
|
|
1734
|
-
const _drifts = [...nodeDrifts];
|
|
1735
|
-
if (t$c(_drifts, 1)) {
|
|
1736
|
-
viewDrifts.add("nodes-mismatch");
|
|
1737
|
-
draft.drifts = _drifts;
|
|
1738
|
-
}
|
|
1739
|
-
});
|
|
1740
|
-
});
|
|
1741
|
-
const edges = snapshot.edges.map((edge) => {
|
|
1742
|
-
const next = nextEdges.get(edge.id);
|
|
1743
|
-
return produce(edge, (draft) => {
|
|
1744
|
-
if (!next) {
|
|
1745
|
-
draft.drifts = ["missing"];
|
|
1746
|
-
return;
|
|
1747
|
-
}
|
|
1748
|
-
const edgeDrifts = /* @__PURE__ */ new Set();
|
|
1749
|
-
if (draft.source === next.target && draft.target === next.source) {
|
|
1750
|
-
edgeDrifts.add("direction-changed");
|
|
1751
|
-
} else {
|
|
1752
|
-
if (draft.source !== next.source) {
|
|
1753
|
-
edgeDrifts.add("source-changed");
|
|
1754
|
-
}
|
|
1755
|
-
if (draft.target !== next.target) {
|
|
1756
|
-
edgeDrifts.add("target-changed");
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
if (edgeDrifts.size === 0 && changed(draft.dir ?? "forward", next.dir ?? "forward")) {
|
|
1760
|
-
edgeDrifts.add("direction-changed");
|
|
1761
|
-
}
|
|
1762
|
-
draft.color = next.color;
|
|
1763
|
-
draft.line = next.line;
|
|
1764
|
-
draft.navigateTo = next.navigateTo ?? null;
|
|
1765
|
-
draft.tags = next.tags ? [...next.tags] : null;
|
|
1766
|
-
if (e$6(next.notes)) {
|
|
1767
|
-
delete draft.notes;
|
|
1768
|
-
} else {
|
|
1769
|
-
draft.notes = next.notes;
|
|
1770
|
-
}
|
|
1771
|
-
if (next.astPath) {
|
|
1772
|
-
draft.astPath = next.astPath;
|
|
1773
|
-
}
|
|
1774
|
-
if (next.labelBBox) {
|
|
1775
|
-
if (!draft.labelBBox || !e$3(draft.label) && e$3(next.label)) {
|
|
1776
|
-
edgeDrifts.add("label-changed");
|
|
1777
|
-
}
|
|
1778
|
-
draft.labelBBox = {
|
|
1779
|
-
// Preserve x,y if possible
|
|
1780
|
-
x: draft.labelBBox?.x ?? next.labelBBox.x,
|
|
1781
|
-
y: draft.labelBBox?.y ?? next.labelBBox.y,
|
|
1782
|
-
// Take width/height from next
|
|
1783
|
-
width: next.labelBBox.width,
|
|
1784
|
-
height: next.labelBBox.height
|
|
1785
|
-
};
|
|
1786
|
-
draft.label = next.label;
|
|
1787
|
-
draft.description = next.description ?? null;
|
|
1788
|
-
draft.technology = next.technology ?? null;
|
|
1789
|
-
} else if (edge.labelBBox) {
|
|
1790
|
-
edgeDrifts.add("label-changed");
|
|
1791
|
-
}
|
|
1792
|
-
const _drifts = [...edgeDrifts];
|
|
1793
|
-
if (t$c(_drifts, 1)) {
|
|
1794
|
-
viewDrifts.add("edges-mismatch");
|
|
1795
|
-
draft.drifts = _drifts;
|
|
1796
|
-
}
|
|
1797
|
-
});
|
|
1798
|
-
});
|
|
1799
|
-
const nodeNotations = buildElementNotations(nodes);
|
|
1800
|
-
const result = { ...snapshot };
|
|
1801
|
-
Object.assign(
|
|
1802
|
-
result,
|
|
1803
|
-
{
|
|
1804
|
-
// Auto-layouted properties
|
|
1805
|
-
title: autoLayouted.title ?? snapshot.title,
|
|
1806
|
-
description: autoLayouted.description ?? snapshot.description,
|
|
1807
|
-
tags: autoLayouted.tags ? [...autoLayouted.tags] : null,
|
|
1808
|
-
links: autoLayouted.links ? [...autoLayouted.links] : null,
|
|
1809
|
-
[_layout]: "manual",
|
|
1810
|
-
...nodeNotations && nodeNotations.length > 0 ? { notation: { nodes: nodeNotations } } : {},
|
|
1811
|
-
nodes,
|
|
1812
|
-
edges
|
|
1813
|
-
}
|
|
1814
|
-
);
|
|
1815
|
-
if (isDynamicView(autoLayouted) && result._type === "dynamic") {
|
|
1816
|
-
Object.assign(
|
|
1817
|
-
result,
|
|
1818
|
-
{
|
|
1819
|
-
variant: autoLayouted.variant
|
|
1820
|
-
}
|
|
1821
|
-
);
|
|
1822
|
-
}
|
|
1823
|
-
const drifts = [...viewDrifts];
|
|
1824
|
-
if (t$c(drifts, 1)) {
|
|
1825
|
-
result.drifts = drifts;
|
|
1826
|
-
} else {
|
|
1827
|
-
if ("drifts" in result) {
|
|
1828
|
-
delete result.drifts;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
return result;
|
|
1832
|
-
}
|
|
1833
|
-
function applyLayoutDriftReasons(autoLayouted, snapshot) {
|
|
1834
|
-
const { drifts } = applyManualLayout(autoLayouted, snapshot);
|
|
1835
|
-
if (drifts) {
|
|
1836
|
-
Object.assign(
|
|
1837
|
-
autoLayouted,
|
|
1838
|
-
{
|
|
1839
|
-
[_layout]: "auto",
|
|
1840
|
-
drifts
|
|
1841
|
-
}
|
|
1842
|
-
);
|
|
1843
|
-
} else {
|
|
1844
|
-
const mutable = autoLayouted;
|
|
1845
|
-
if ("drifts" in autoLayouted) {
|
|
1846
|
-
delete mutable.drifts;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
return autoLayouted;
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
740
|
class EdgeModel {
|
|
1853
741
|
constructor($viewModel, $edge, source, target) {
|
|
1854
742
|
this.source = source;
|
|
@@ -2079,13 +967,13 @@ class NodeModel {
|
|
|
2079
967
|
* Check if this node references to logical model element.
|
|
2080
968
|
*/
|
|
2081
969
|
hasElement() {
|
|
2082
|
-
return e$
|
|
970
|
+
return e$1(this.$node.modelRef);
|
|
2083
971
|
}
|
|
2084
972
|
/**
|
|
2085
973
|
* Check if this node references to deployment element (Node or Instance).
|
|
2086
974
|
*/
|
|
2087
975
|
hasDeployment() {
|
|
2088
|
-
return e$
|
|
976
|
+
return e$1(this.$node.deploymentRef);
|
|
2089
977
|
}
|
|
2090
978
|
/**
|
|
2091
979
|
* Check if this node references to deployed instance
|
|
@@ -2267,7 +1155,8 @@ class LikeC4ViewModel {
|
|
|
2267
1155
|
return [...this.#allTags.keys()];
|
|
2268
1156
|
}
|
|
2269
1157
|
/**
|
|
2270
|
-
* The original view
|
|
1158
|
+
* The original view from the model.
|
|
1159
|
+
* In case of layouted model, this is the latest auto-layouted view without manual changes applied
|
|
2271
1160
|
* @see {@link $layouted} should be used for rendering in the UI
|
|
2272
1161
|
*/
|
|
2273
1162
|
get $view() {
|
|
@@ -2277,7 +1166,7 @@ class LikeC4ViewModel {
|
|
|
2277
1166
|
const snapshot = this.#manualLayoutSnapshot;
|
|
2278
1167
|
if (snapshot) {
|
|
2279
1168
|
return memoizeProp(this, "withDriftReasons", () => {
|
|
2280
|
-
return
|
|
1169
|
+
return calcDriftsFromSnapshot(this.#view, snapshot);
|
|
2281
1170
|
});
|
|
2282
1171
|
}
|
|
2283
1172
|
return this.#view;
|
|
@@ -2290,15 +1179,22 @@ class LikeC4ViewModel {
|
|
|
2290
1179
|
if (!this.isLayouted()) {
|
|
2291
1180
|
throw new Error("View is not layouted");
|
|
2292
1181
|
}
|
|
2293
|
-
return this
|
|
1182
|
+
return this.$manual ?? this.#view;
|
|
2294
1183
|
}
|
|
2295
1184
|
get hasManualLayout() {
|
|
2296
1185
|
return this.#manualLayoutSnapshot !== void 0;
|
|
2297
1186
|
}
|
|
1187
|
+
get hasLayoutDrifts() {
|
|
1188
|
+
if (!this.isLayouted()) {
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1191
|
+
const manualLayout = this.$manual;
|
|
1192
|
+
return !!manualLayout?.drifts && manualLayout.drifts.length > 0;
|
|
1193
|
+
}
|
|
2298
1194
|
/**
|
|
2299
1195
|
* If view has manual layout, returns it with manual layout applied
|
|
2300
1196
|
*/
|
|
2301
|
-
get
|
|
1197
|
+
get $manual() {
|
|
2302
1198
|
if (!this.isLayouted()) {
|
|
2303
1199
|
return null;
|
|
2304
1200
|
}
|
|
@@ -2310,16 +1206,6 @@ class LikeC4ViewModel {
|
|
|
2310
1206
|
}
|
|
2311
1207
|
return null;
|
|
2312
1208
|
}
|
|
2313
|
-
/**
|
|
2314
|
-
* Returns the layout drift reasons, if any
|
|
2315
|
-
* (Only for layouted views with manual layout)
|
|
2316
|
-
*/
|
|
2317
|
-
get driftReasons() {
|
|
2318
|
-
if (!this.isLayouted()) {
|
|
2319
|
-
return [];
|
|
2320
|
-
}
|
|
2321
|
-
return this.$view.drifts ?? [];
|
|
2322
|
-
}
|
|
2323
1209
|
roots() {
|
|
2324
1210
|
return this.#rootnodes.values();
|
|
2325
1211
|
}
|
|
@@ -2445,7 +1331,7 @@ class LikeC4ViewModel {
|
|
|
2445
1331
|
return this.#view[_type] === "element";
|
|
2446
1332
|
}
|
|
2447
1333
|
isScopedElementView() {
|
|
2448
|
-
return this.#view[_type] === "element" && e$
|
|
1334
|
+
return this.#view[_type] === "element" && e$1(this.#view.viewOf);
|
|
2449
1335
|
}
|
|
2450
1336
|
isDeploymentView() {
|
|
2451
1337
|
return this.#view[_type] === "deployment";
|
|
@@ -2487,7 +1373,7 @@ class LikeC4ViewsFolder {
|
|
|
2487
1373
|
this.$model = $model;
|
|
2488
1374
|
this.path = path.join("/");
|
|
2489
1375
|
this.isRoot = this.path === "";
|
|
2490
|
-
this.title = t$
|
|
1376
|
+
this.title = t$1(path);
|
|
2491
1377
|
if (this.isRoot) {
|
|
2492
1378
|
this.parentPath = void 0;
|
|
2493
1379
|
} else {
|
|
@@ -2542,7 +1428,7 @@ class LikeC4ViewsFolder {
|
|
|
2542
1428
|
*/
|
|
2543
1429
|
get parent() {
|
|
2544
1430
|
invariant(!this.isRoot, "Root view folder has no parent");
|
|
2545
|
-
if (e$
|
|
1431
|
+
if (e$2(this.parentPath)) {
|
|
2546
1432
|
return null;
|
|
2547
1433
|
}
|
|
2548
1434
|
return this.$model.viewFolder(this.parentPath);
|
|
@@ -2659,13 +1545,13 @@ class LikeC4Model {
|
|
|
2659
1545
|
$data;
|
|
2660
1546
|
constructor($data) {
|
|
2661
1547
|
this.$data = $data;
|
|
2662
|
-
for (const [, element] of t$
|
|
1548
|
+
for (const [, element] of t$5($data.elements)) {
|
|
2663
1549
|
const el = this.addElement(element);
|
|
2664
1550
|
for (const tag of el.tags) {
|
|
2665
1551
|
this._allTags.get(tag).add(el);
|
|
2666
1552
|
}
|
|
2667
1553
|
}
|
|
2668
|
-
for (const [projectId, elements] of t$
|
|
1554
|
+
for (const [projectId, elements] of t$5($data.imports ?? {})) {
|
|
2669
1555
|
for (const element of sortParentsFirst(elements)) {
|
|
2670
1556
|
const el = this.addImportedElement(projectId, element);
|
|
2671
1557
|
for (const tag of el.tags) {
|
|
@@ -2682,22 +1568,21 @@ class LikeC4Model {
|
|
|
2682
1568
|
this.deployment = new LikeC4DeploymentModel(this);
|
|
2683
1569
|
if (isOnStage($data, "computed") || isOnStage($data, "layouted")) {
|
|
2684
1570
|
const compare = compareNaturalHierarchically(VIEW_FOLDERS_SEPARATOR);
|
|
2685
|
-
t(
|
|
2686
|
-
const views = t$a(
|
|
1571
|
+
const views = t$6(
|
|
2687
1572
|
t($data.views),
|
|
2688
|
-
t$
|
|
1573
|
+
t$8((view) => ({
|
|
2689
1574
|
view,
|
|
2690
1575
|
path: normalizeViewPath(view.title ?? view.id),
|
|
2691
1576
|
folderPath: view.title && getViewFolderPath(view.title) || ""
|
|
2692
1577
|
})),
|
|
2693
1578
|
// Sort hierarchically by groups, but keep same order within groups
|
|
2694
|
-
t$
|
|
1579
|
+
t$7((a, b) => compare(a.folderPath, b.folderPath))
|
|
2695
1580
|
);
|
|
2696
1581
|
const getOrCreateFolder = (path) => {
|
|
2697
1582
|
let folder = this._viewFolders.get(path);
|
|
2698
1583
|
if (!folder) {
|
|
2699
1584
|
const segments = e(path, VIEW_FOLDERS_SEPARATOR);
|
|
2700
|
-
invariant(t$
|
|
1585
|
+
invariant(t$4(segments, 1), `View group path "${path}" must have at least one element`);
|
|
2701
1586
|
let defaultView;
|
|
2702
1587
|
if (path === "") {
|
|
2703
1588
|
defaultView = views.find((view) => view.view.id === "index");
|
|
@@ -2716,7 +1601,7 @@ class LikeC4Model {
|
|
|
2716
1601
|
}
|
|
2717
1602
|
e(folderPath, VIEW_FOLDERS_SEPARATOR).reduce((segments, segment) => {
|
|
2718
1603
|
const parent = segments.join(VIEW_FOLDERS_SEPARATOR);
|
|
2719
|
-
const path = e$
|
|
1604
|
+
const path = e$2(parent) ? segment : parent + VIEW_FOLDERS_SEPARATOR + segment;
|
|
2720
1605
|
const folder = getOrCreateFolder(path);
|
|
2721
1606
|
this._viewFolderItems.get(parent).add(folder);
|
|
2722
1607
|
segments.push(segment);
|
|
@@ -2945,6 +1830,16 @@ class LikeC4Model {
|
|
|
2945
1830
|
findView(viewId) {
|
|
2946
1831
|
return this._views.get(viewId) ?? null;
|
|
2947
1832
|
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Returns manual layout snapshot for given view ID, if any.
|
|
1835
|
+
*/
|
|
1836
|
+
findManualLayout(viewId) {
|
|
1837
|
+
if ("manualLayouts" in this.$data) {
|
|
1838
|
+
const view = this.$data.manualLayouts?.[viewId];
|
|
1839
|
+
return view ?? null;
|
|
1840
|
+
}
|
|
1841
|
+
return null;
|
|
1842
|
+
}
|
|
2948
1843
|
/**
|
|
2949
1844
|
* Returns a view folder by its path.
|
|
2950
1845
|
* Path is extracted from the view title, e.g. "Group 1/Group 2/View" -> "Group 1/Group 2"
|
|
@@ -3068,22 +1963,22 @@ class LikeC4Model {
|
|
|
3068
1963
|
* Use {@link specification.tags} to get all defined tags
|
|
3069
1964
|
*/
|
|
3070
1965
|
get tags() {
|
|
3071
|
-
return memoizeProp(this, "tags", () => t$
|
|
1966
|
+
return memoizeProp(this, "tags", () => t$7([...this._allTags.keys()], compareNatural));
|
|
3072
1967
|
}
|
|
3073
1968
|
/**
|
|
3074
1969
|
* Returns all tags used in the model, sorted by usage count (descending).
|
|
3075
1970
|
*/
|
|
3076
1971
|
get tagsSortedByUsage() {
|
|
3077
|
-
return memoizeProp(this, "tagsSortedByUsage", () => t$
|
|
1972
|
+
return memoizeProp(this, "tagsSortedByUsage", () => t$6(
|
|
3078
1973
|
[...this._allTags.entries()],
|
|
3079
|
-
t$
|
|
1974
|
+
t$8(([tag, tagged]) => ({
|
|
3080
1975
|
tag,
|
|
3081
1976
|
count: tagged.size,
|
|
3082
1977
|
tagged
|
|
3083
1978
|
})),
|
|
3084
|
-
t$
|
|
3085
|
-
t$
|
|
3086
|
-
[e$
|
|
1979
|
+
t$7((a, b) => compareNatural(a.tag, b.tag)),
|
|
1980
|
+
t$9(
|
|
1981
|
+
[e$3("count"), "desc"]
|
|
3087
1982
|
)
|
|
3088
1983
|
));
|
|
3089
1984
|
}
|
|
@@ -3299,4 +2194,4 @@ function isEdgeModel(edge) {
|
|
|
3299
2194
|
return edge instanceof EdgeModel;
|
|
3300
2195
|
}
|
|
3301
2196
|
|
|
3302
|
-
export {
|
|
2197
|
+
export { ElementModel as E, LikeC4Model as L, NodeModel as N, RelationshipModel as R, VIEW_FOLDERS_SEPARATOR as V, t$1 as a, isNestedElementOfDeployedInstanceModel as b, isDeployedInstanceModel as c, isDeploymentNodeModel as d, isDeploymentElementModel as e, LikeC4DeploymentModel as f, EdgeModel as g, LikeC4ViewModel as h, isElementModel as i, LikeC4ViewsFolder as j, extractViewTitleFromPath as k, getViewFolderPath as l, isDeploymentRelationModel as m, normalizeViewPath as n, isRelationModel as o, isLikeC4ViewModel as p, isNodeModel as q, isEdgeModel as r, t };
|