@likec4/core 1.43.0 → 1.44.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 +7 -7
- package/dist/builder/index.mjs +10 -8
- package/dist/compute-view/index.d.mts +9 -9
- package/dist/compute-view/index.mjs +7 -7
- package/dist/compute-view/relationships-view/index.d.mts +7 -7
- package/dist/compute-view/relationships-view/index.mjs +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +7 -7
- package/dist/model/connection/deployment/index.d.mts +9 -9
- package/dist/model/connection/deployment/index.mjs +2 -2
- package/dist/model/connection/index.d.mts +10 -10
- package/dist/model/connection/index.mjs +3 -3
- package/dist/model/connection/model/index.d.mts +9 -9
- package/dist/model/connection/model/index.mjs +2 -2
- package/dist/model/index.d.mts +26 -12
- package/dist/model/index.mjs +4 -4
- package/dist/shared/{core.CXWsKEDr.mjs → core.23WeDKcI.mjs} +269 -632
- package/dist/shared/{core.CwsG7hOw.d.mts → core.5ZQ-r3Oa.d.mts} +1 -1
- package/dist/shared/{core.727Qoh_W.mjs → core.6VsRBhGY.mjs} +2 -101
- package/dist/shared/{core.CT1xBp4R.d.mts → core.8mmHFn9g.d.mts} +2 -2
- package/dist/shared/core.B9BjmjuH.mjs +9 -0
- package/dist/shared/{core.CvLjw3bH.d.mts → core.BMtVqKl7.d.mts} +89 -11
- package/dist/shared/{core.rCeaAqgW.mjs → core.BdPcbSkN.mjs} +1 -1
- package/dist/shared/{core.DTdfiejA.d.mts → core.BnDbAOR2.d.mts} +2 -2
- package/dist/shared/{core.CDvVInBp.d.mts → core.BnOetIAR.d.mts} +2 -2
- package/dist/shared/core.BuQZczj6.mjs +38 -0
- package/dist/shared/core.Bv3cd-jC.mjs +102 -0
- package/dist/shared/{core.BouyJs63.mjs → core.C0Ye2OCr.mjs} +1 -1
- package/dist/shared/{core.hNWo20Ym.d.mts → core.CDOKQTW6.d.mts} +54 -35
- package/dist/shared/{core.Be05qJwN.mjs → core.CHwVhuc9.mjs} +36 -10
- package/dist/shared/{core.BT-9gaqQ.d.mts → core.CKNmSm2W.d.mts} +85 -89
- package/dist/shared/{core.DFi2dOTl.mjs → core.CR3PmPzr.mjs} +85 -1
- package/dist/shared/{core.C2TiyjI6.mjs → core.CbsSAn1j.mjs} +19 -19
- package/dist/shared/{core.QJD_fcrc.mjs → core.CmPXpJ8l.mjs} +1 -14
- package/dist/shared/{core.D5fzJWbF.d.mts → core.DB0Ue5Wx.d.mts} +1 -1
- package/dist/shared/{core.DNbUPnve.mjs → core.DEieYfbG.mjs} +27 -25
- package/dist/shared/{core.D0NziuvN.mjs → core.DFCHU59b.mjs} +4 -4
- package/dist/shared/{core.BYNkXQ8A.mjs → core.DH7TXqXf.mjs} +30 -1
- package/dist/shared/{core.DMMOWQqc.mjs → core.DIE3F6sw.mjs} +2 -2
- package/dist/shared/{core.Cq2kxOI-.d.mts → core.DTJYgLXI.d.mts} +3 -3
- package/dist/shared/{core.CcJ1FZ7h.d.mts → core.DjAM-S6a.d.mts} +174 -77
- package/dist/shared/{core.CNgZvKb8.mjs → core.DrUt0Lbi.mjs} +1 -1
- package/dist/shared/core.M9ayqQZa.mjs +1207 -0
- package/dist/shared/{core.BXs4wY7R.d.mts → core.WwMWeiFL.d.mts} +4 -4
- package/dist/shared/{core.2N_9BzyD.mjs → core.bKIs4oDO.mjs} +3 -3
- package/dist/shared/{core.DyToofsP.mjs → core.h4TqqSC0.mjs} +1360 -124
- package/dist/shared/core.q10OP9oJ.mjs +5 -0
- package/dist/shared/core.uFk_o9X6.mjs +13 -0
- package/dist/styles/index.d.mts +18 -8
- package/dist/styles/index.mjs +63 -1
- package/dist/types/_aux.d.mts +2 -2
- package/dist/types/_aux.mjs +8 -1
- package/dist/types/expression-model.d.mts +3 -3
- package/dist/types/expression.d.mts +3 -3
- package/dist/types/fqnRef.d.mts +7 -8
- package/dist/types/index.d.mts +17 -13
- package/dist/types/index.mjs +28 -5
- package/dist/utils/graphology/index.mjs +1 -1
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.mjs +8 -6
- package/dist/utils/iterable/index.d.mts +1 -1
- package/dist/utils/iterable/index.mjs +2 -1
- package/package.json +18 -17
- package/dist/shared/core.01VTr9qu.mjs +0 -170
- package/dist/shared/core.1vX5a9AY.mjs +0 -86
- package/dist/shared/core.BazD6cot.mjs +0 -14
- package/dist/shared/core.BzTakU3I.mjs +0 -67
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
import { n as n$
|
|
2
|
-
import { t as t$8, a as t$9 } from './core.BsSXS-_R.mjs';
|
|
1
|
+
import { n as n$6, t as t$b, e as e$4, a as DeploymentNodeModel, b as DeployedInstanceModel, c as DeploymentRelationModel, N as NestedElementOfDeployedInstanceModel } from './core.CHwVhuc9.mjs';
|
|
3
2
|
import { e as e$3 } from './core.BKlholso.mjs';
|
|
4
3
|
import { c as splitGlobalFqn, g as extractStep, e as isStepEdgeId, i as isGroupElementKind, b as isGlobalFqn, a as GlobalFqn } from './core.C_Ni6yHl.mjs';
|
|
5
|
-
import {
|
|
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.6VsRBhGY.mjs';
|
|
6
5
|
import { m as memoizeProp } from './core.BR4zXDH-.mjs';
|
|
7
|
-
import { R as RichText, e as exact } from './core.
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { t as t$a } from './core.OHD4KXm9.mjs';
|
|
11
|
-
import { t as t$
|
|
12
|
-
import {
|
|
6
|
+
import { R as RichText, e as exact } from './core.M9ayqQZa.mjs';
|
|
7
|
+
import { preferSummary, preferDescription } from '../types/_aux.mjs';
|
|
8
|
+
import { i as ihead } from './core.uFk_o9X6.mjs';
|
|
9
|
+
import { a as t$9, t as t$a } from './core.OHD4KXm9.mjs';
|
|
10
|
+
import { t as t$8, a as t$c } from './core.BsSXS-_R.mjs';
|
|
11
|
+
import { e as e$5, t as t$d, a as t$g } from './core.B9BjmjuH.mjs';
|
|
12
|
+
import { t as t$e } from './core.CbT8JVYL.mjs';
|
|
13
|
+
import { a as t$f, L as LikeC4Styles } from './core.DEieYfbG.mjs';
|
|
13
14
|
import { g as getOrCreate } from './core.DcS-0zys.mjs';
|
|
14
|
-
import { i as invariant, a as nonNullable } from './core.D4npX2q8.mjs';
|
|
15
15
|
import { D as DefaultMap } from './core.BbE4y-yl.mjs';
|
|
16
|
+
import { i as invariant, a as nonNullable } from './core.D4npX2q8.mjs';
|
|
16
17
|
import { FqnRef } from '../types/fqnRef.mjs';
|
|
17
|
-
import {
|
|
18
|
+
import { c as isDeploymentNode, b as _layout, u as e$6, t as isDynamicView, a as _type, _ as _stage, i as isOnStage, w as whereOperatorAsPredicate } from './core.DH7TXqXf.mjs';
|
|
19
|
+
import { s as symmetricDifference } from './core.CbsSAn1j.mjs';
|
|
20
|
+
import { i as ifind } from './core.CmPXpJ8l.mjs';
|
|
18
21
|
import { i as ifilter } from './core.DRJma0Ol.mjs';
|
|
19
|
-
import './core.
|
|
20
|
-
import './core.
|
|
22
|
+
import { a as compareNaturalHierarchically, c as compareNatural } from './core.Bv3cd-jC.mjs';
|
|
23
|
+
import './core.C0Ye2OCr.mjs';
|
|
24
|
+
import './core.bKIs4oDO.mjs';
|
|
25
|
+
|
|
26
|
+
const e$2={asc:(e,t)=>e>t,desc:(e,t)=>e<t};function t$7(e,t){let[n,...a]=t;if(!i$1(n)){let t=r$2(...a);return e(n,t)}let o=r$2(n,...a);return t=>e(t,o)}function r$2(t,n,...i){let a=typeof t==`function`?t:t[0],o=typeof t==`function`?`asc`:t[1],{[o]:s}=e$2,c=n===void 0?void 0:r$2(n,...i);return (e,t)=>{let n=a(e),r=a(t);return s(n,r)?1:s(r,n)?-1:c?.(e,t)??0}}function i$1(t){if(a(t))return true;if(typeof t!=`object`||!Array.isArray(t))return false;let[n,r,...i]=t;return a(n)&&typeof r==`string`&&r in e$2&&i.length===0}const a=e=>typeof e==`function`&&e.length===1;
|
|
21
27
|
|
|
22
|
-
|
|
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;
|
|
23
29
|
|
|
24
|
-
function t$6(...t){return t$8(
|
|
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}};
|
|
25
31
|
|
|
26
|
-
function t$5(...t){return t$8(n$3,t)}
|
|
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)}
|
|
27
35
|
|
|
28
36
|
function t$4(...t){return t$8(n$2,t)}const n$2=e=>e.at(-1);
|
|
29
37
|
|
|
30
|
-
function
|
|
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}
|
|
31
39
|
|
|
32
|
-
function t$2(...t){return
|
|
40
|
+
function t$2(...t){return n=>t$a(n,...t)}
|
|
33
41
|
|
|
34
42
|
function t$1(...t){return t$7(n,t)}const n=(e,t)=>[...e].sort(t);
|
|
35
43
|
|
|
@@ -55,6 +63,10 @@ class ElementModel {
|
|
|
55
63
|
this.hierarchyLevel = hierarchyLevel(this.id);
|
|
56
64
|
}
|
|
57
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Don't use in runtime, only for type inference
|
|
68
|
+
*/
|
|
69
|
+
Aux;
|
|
58
70
|
id;
|
|
59
71
|
_literalId;
|
|
60
72
|
hierarchyLevel;
|
|
@@ -83,7 +95,7 @@ class ElementModel {
|
|
|
83
95
|
*/
|
|
84
96
|
get tags() {
|
|
85
97
|
return memoizeProp(this, Symbol.for("tags"), () => {
|
|
86
|
-
return n$
|
|
98
|
+
return n$6([
|
|
87
99
|
...this.$element.tags ?? [],
|
|
88
100
|
...this.$model.specification.elements[this.$element.kind]?.tags ?? []
|
|
89
101
|
]);
|
|
@@ -97,7 +109,7 @@ class ElementModel {
|
|
|
97
109
|
* (if one is missing - it falls back to another)
|
|
98
110
|
*/
|
|
99
111
|
get hasSummary() {
|
|
100
|
-
return !!this.$element.summary && !!this.$element.description && !t$
|
|
112
|
+
return !!this.$element.summary && !!this.$element.description && !t$b(this.$element.summary, this.$element.description);
|
|
101
113
|
}
|
|
102
114
|
/**
|
|
103
115
|
* Short description of the element.
|
|
@@ -290,12 +302,13 @@ class ElementModel {
|
|
|
290
302
|
const getId = (element) => {
|
|
291
303
|
return typeof element === "string" ? element : element.id;
|
|
292
304
|
};
|
|
305
|
+
|
|
293
306
|
const VIEW_FOLDERS_SEPARATOR = "/";
|
|
294
307
|
const splitViewTitle = (title) => {
|
|
295
308
|
invariant(!title.includes("\n"), "View title cannot contain newlines");
|
|
296
309
|
if (title.includes(VIEW_FOLDERS_SEPARATOR)) {
|
|
297
310
|
const segments = title.split(VIEW_FOLDERS_SEPARATOR).map((s) => s.trim()).filter((s) => s.length > 0);
|
|
298
|
-
if (t$
|
|
311
|
+
if (t$c(segments, 1)) {
|
|
299
312
|
return segments;
|
|
300
313
|
}
|
|
301
314
|
return [""];
|
|
@@ -307,7 +320,7 @@ const normalizeViewPath = (title) => {
|
|
|
307
320
|
};
|
|
308
321
|
const getViewFolderPath = (title) => {
|
|
309
322
|
const segments = splitViewTitle(title);
|
|
310
|
-
if (!t$
|
|
323
|
+
if (!t$c(segments, 2)) {
|
|
311
324
|
return null;
|
|
312
325
|
}
|
|
313
326
|
return segments.slice(0, -1).join(VIEW_FOLDERS_SEPARATOR);
|
|
@@ -660,8 +673,26 @@ class RelationshipModel {
|
|
|
660
673
|
}
|
|
661
674
|
return this.$relationship.technology;
|
|
662
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* Returns true if the relationship has a summary and a description
|
|
678
|
+
* (if one is missing - it falls back to another)
|
|
679
|
+
*/
|
|
680
|
+
get hasSummary() {
|
|
681
|
+
return !!this.$relationship.summary && !!this.$relationship.description && !t$b(this.$relationship.summary, this.$relationship.description);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Short description of the relationship.
|
|
685
|
+
* Falls back to description if summary is not provided.
|
|
686
|
+
*/
|
|
687
|
+
get summary() {
|
|
688
|
+
return RichText.memoize(this, "summary", preferSummary(this.$relationship));
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Long description of the relationship.
|
|
692
|
+
* Falls back to summary if description is not provided.
|
|
693
|
+
*/
|
|
663
694
|
get description() {
|
|
664
|
-
return RichText.memoize(this, "description", this.$relationship
|
|
695
|
+
return RichText.memoize(this, "description", preferDescription(this.$relationship));
|
|
665
696
|
}
|
|
666
697
|
get navigateTo() {
|
|
667
698
|
return this.$relationship.navigateTo ? this.model.view(this.$relationship.navigateTo) : null;
|
|
@@ -721,73 +752,1173 @@ class RelationshipModel {
|
|
|
721
752
|
}
|
|
722
753
|
}
|
|
723
754
|
|
|
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
|
+
|
|
724
1852
|
class EdgeModel {
|
|
725
|
-
constructor(
|
|
726
|
-
this.view = view;
|
|
727
|
-
this.$edge = $edge;
|
|
1853
|
+
constructor($viewModel, $edge, source, target) {
|
|
728
1854
|
this.source = source;
|
|
729
1855
|
this.target = target;
|
|
730
|
-
this
|
|
1856
|
+
this.$viewModel = $viewModel;
|
|
1857
|
+
this.$view = $viewModel.$view;
|
|
1858
|
+
this.$edge = $edge;
|
|
731
1859
|
}
|
|
732
|
-
|
|
1860
|
+
Aux;
|
|
1861
|
+
$viewModel;
|
|
1862
|
+
$view;
|
|
1863
|
+
$edge;
|
|
733
1864
|
get id() {
|
|
734
|
-
return this
|
|
1865
|
+
return this.$edge.id;
|
|
735
1866
|
}
|
|
736
1867
|
get parent() {
|
|
737
|
-
return this
|
|
1868
|
+
return this.$edge.parent ? this.$viewModel.node(this.$edge.parent) : null;
|
|
738
1869
|
}
|
|
739
1870
|
get label() {
|
|
740
|
-
return this
|
|
1871
|
+
return this.$edge.label ?? null;
|
|
741
1872
|
}
|
|
742
1873
|
get description() {
|
|
743
|
-
return RichText.memoize(this, "description", this
|
|
1874
|
+
return RichText.memoize(this, "description", this.$edge.description);
|
|
744
1875
|
}
|
|
745
1876
|
get technology() {
|
|
746
|
-
return this
|
|
1877
|
+
return this.$edge.technology ?? null;
|
|
747
1878
|
}
|
|
748
1879
|
hasParent() {
|
|
749
|
-
return this
|
|
1880
|
+
return this.$edge.parent !== null;
|
|
750
1881
|
}
|
|
751
1882
|
get tags() {
|
|
752
|
-
return this
|
|
1883
|
+
return this.$edge.tags ?? [];
|
|
753
1884
|
}
|
|
754
1885
|
get stepNumber() {
|
|
755
1886
|
return this.isStep() ? extractStep(this.id) : null;
|
|
756
1887
|
}
|
|
757
1888
|
get navigateTo() {
|
|
758
|
-
return this
|
|
1889
|
+
return this.$edge.navigateTo ? this.$viewModel.$model.view(this.$edge.navigateTo) : null;
|
|
759
1890
|
}
|
|
760
1891
|
get color() {
|
|
761
|
-
return this
|
|
1892
|
+
return this.$edge.color;
|
|
762
1893
|
}
|
|
763
1894
|
get line() {
|
|
764
|
-
return this
|
|
1895
|
+
return this.$edge.line ?? this.$viewModel.$styles.defaults.relationship.line;
|
|
765
1896
|
}
|
|
766
1897
|
get head() {
|
|
767
|
-
return this
|
|
1898
|
+
return this.$edge.head ?? this.$viewModel.$styles.defaults.relationship.arrow;
|
|
768
1899
|
}
|
|
769
1900
|
get tail() {
|
|
770
|
-
return this
|
|
1901
|
+
return this.$edge.tail;
|
|
771
1902
|
}
|
|
772
1903
|
isStep() {
|
|
773
1904
|
return isStepEdgeId(this.id);
|
|
774
1905
|
}
|
|
775
1906
|
*relationships(type) {
|
|
776
|
-
for (const id of this
|
|
1907
|
+
for (const id of this.$edge.relations) {
|
|
777
1908
|
if (type) {
|
|
778
|
-
const rel = this
|
|
1909
|
+
const rel = this.$viewModel.$model.findRelationship(id, type);
|
|
779
1910
|
if (rel) {
|
|
780
1911
|
yield rel;
|
|
781
1912
|
}
|
|
782
1913
|
} else {
|
|
783
|
-
yield this
|
|
1914
|
+
yield this.$viewModel.$model.relationship(id);
|
|
784
1915
|
}
|
|
785
1916
|
}
|
|
786
1917
|
return;
|
|
787
1918
|
}
|
|
788
1919
|
includesRelation(rel) {
|
|
789
1920
|
const id = typeof rel === "string" ? rel : rel.id;
|
|
790
|
-
return this
|
|
1921
|
+
return this.$edge.relations.includes(id);
|
|
791
1922
|
}
|
|
792
1923
|
isTagged(tag) {
|
|
793
1924
|
return this.tags.includes(tag);
|
|
@@ -795,61 +1926,76 @@ class EdgeModel {
|
|
|
795
1926
|
}
|
|
796
1927
|
|
|
797
1928
|
class NodeModel {
|
|
798
|
-
|
|
799
|
-
|
|
1929
|
+
Aux;
|
|
1930
|
+
$viewModel;
|
|
1931
|
+
$view;
|
|
1932
|
+
$node;
|
|
1933
|
+
constructor($viewModel, $node) {
|
|
1934
|
+
this.$viewModel = $viewModel;
|
|
1935
|
+
this.$view = $viewModel.$view;
|
|
800
1936
|
this.$node = $node;
|
|
801
|
-
this.#node = $node;
|
|
802
1937
|
}
|
|
803
|
-
#node;
|
|
804
1938
|
get id() {
|
|
805
|
-
return this
|
|
1939
|
+
return this.$node.id;
|
|
806
1940
|
}
|
|
807
1941
|
get title() {
|
|
808
|
-
return this
|
|
1942
|
+
return this.$node.title;
|
|
809
1943
|
}
|
|
810
1944
|
get kind() {
|
|
811
|
-
return this
|
|
1945
|
+
return this.$node.kind;
|
|
812
1946
|
}
|
|
813
1947
|
get description() {
|
|
814
|
-
return RichText.memoize(this, "description", this
|
|
1948
|
+
return RichText.memoize(this, "description", this.$node.description);
|
|
815
1949
|
}
|
|
816
1950
|
get technology() {
|
|
817
|
-
return this
|
|
1951
|
+
return this.$node.technology ?? null;
|
|
818
1952
|
}
|
|
819
1953
|
get parent() {
|
|
820
|
-
return this
|
|
1954
|
+
return this.$node.parent ? this.$viewModel.node(this.$node.parent) : null;
|
|
821
1955
|
}
|
|
822
1956
|
get element() {
|
|
823
|
-
const modelRef = this
|
|
824
|
-
return modelRef ? this.$
|
|
1957
|
+
const modelRef = this.$node.modelRef;
|
|
1958
|
+
return modelRef ? this.$viewModel.$model.element(modelRef) : null;
|
|
825
1959
|
}
|
|
826
1960
|
get deployment() {
|
|
827
|
-
const modelRef = this
|
|
828
|
-
return modelRef ? this.$
|
|
1961
|
+
const modelRef = this.$node.deploymentRef;
|
|
1962
|
+
return modelRef ? this.$viewModel.$model.deployment.element(modelRef) : null;
|
|
829
1963
|
}
|
|
830
1964
|
get shape() {
|
|
831
|
-
return this
|
|
1965
|
+
return this.$node.shape;
|
|
832
1966
|
}
|
|
833
1967
|
get color() {
|
|
834
|
-
return this
|
|
1968
|
+
return this.$node.color;
|
|
835
1969
|
}
|
|
836
1970
|
get icon() {
|
|
837
|
-
return this
|
|
1971
|
+
return this.$node.icon ?? null;
|
|
838
1972
|
}
|
|
839
1973
|
get tags() {
|
|
840
|
-
return this
|
|
1974
|
+
return this.$node.tags;
|
|
841
1975
|
}
|
|
842
1976
|
get links() {
|
|
843
|
-
return this
|
|
1977
|
+
return this.$node.links ?? [];
|
|
844
1978
|
}
|
|
845
1979
|
get navigateTo() {
|
|
846
|
-
return this
|
|
1980
|
+
return this.$node.navigateTo ? this.$viewModel.$model.view(this.$node.navigateTo) : null;
|
|
847
1981
|
}
|
|
848
1982
|
get style() {
|
|
849
|
-
return this
|
|
1983
|
+
return this.$node.style;
|
|
1984
|
+
}
|
|
1985
|
+
get x() {
|
|
1986
|
+
return "x" in this.$node ? this.$node.x : void 0;
|
|
1987
|
+
}
|
|
1988
|
+
get y() {
|
|
1989
|
+
return "y" in this.$node ? this.$node.y : void 0;
|
|
1990
|
+
}
|
|
1991
|
+
get width() {
|
|
1992
|
+
return "width" in this.$node ? this.$node.width : void 0;
|
|
1993
|
+
}
|
|
1994
|
+
get height() {
|
|
1995
|
+
return "height" in this.$node ? this.$node.height : void 0;
|
|
850
1996
|
}
|
|
851
1997
|
children() {
|
|
852
|
-
return memoizeProp(this, "children", () => new Set(this
|
|
1998
|
+
return memoizeProp(this, "children", () => new Set(this.$node.children.map((child) => this.$viewModel.node(child))));
|
|
853
1999
|
}
|
|
854
2000
|
/**
|
|
855
2001
|
* Get all ancestor elements (i.e. parent, parent’s parent, etc.)
|
|
@@ -864,7 +2010,7 @@ class NodeModel {
|
|
|
864
2010
|
return;
|
|
865
2011
|
}
|
|
866
2012
|
*siblings() {
|
|
867
|
-
const siblings = this.parent?.children() ?? this.$
|
|
2013
|
+
const siblings = this.parent?.children() ?? this.$viewModel.roots();
|
|
868
2014
|
for (const sibling of siblings) {
|
|
869
2015
|
if (sibling.id !== this.id) {
|
|
870
2016
|
yield sibling;
|
|
@@ -873,8 +2019,8 @@ class NodeModel {
|
|
|
873
2019
|
return;
|
|
874
2020
|
}
|
|
875
2021
|
*incoming(filter = "all") {
|
|
876
|
-
for (const edgeId of this
|
|
877
|
-
const edge = this.$
|
|
2022
|
+
for (const edgeId of this.$node.inEdges) {
|
|
2023
|
+
const edge = this.$viewModel.edge(edgeId);
|
|
878
2024
|
switch (true) {
|
|
879
2025
|
case filter === "all":
|
|
880
2026
|
case (filter === "direct" && edge.target.id === this.id):
|
|
@@ -897,8 +2043,8 @@ class NodeModel {
|
|
|
897
2043
|
return;
|
|
898
2044
|
}
|
|
899
2045
|
*outgoing(filter = "all") {
|
|
900
|
-
for (const edgeId of this
|
|
901
|
-
const edge = this.$
|
|
2046
|
+
for (const edgeId of this.$node.outEdges) {
|
|
2047
|
+
const edge = this.$viewModel.edge(edgeId);
|
|
902
2048
|
switch (true) {
|
|
903
2049
|
case filter === "all":
|
|
904
2050
|
case (filter === "direct" && edge.source.id === this.id):
|
|
@@ -920,26 +2066,26 @@ class NodeModel {
|
|
|
920
2066
|
}
|
|
921
2067
|
return;
|
|
922
2068
|
}
|
|
923
|
-
|
|
924
|
-
return "width" in this
|
|
2069
|
+
isLayouted() {
|
|
2070
|
+
return "width" in this.$node && "height" in this.$node;
|
|
925
2071
|
}
|
|
926
2072
|
hasChildren() {
|
|
927
|
-
return this
|
|
2073
|
+
return this.$node.children.length > 0;
|
|
928
2074
|
}
|
|
929
2075
|
hasParent() {
|
|
930
|
-
return this
|
|
2076
|
+
return this.$node.parent !== null;
|
|
931
2077
|
}
|
|
932
2078
|
/**
|
|
933
2079
|
* Check if this node references to logical model element.
|
|
934
2080
|
*/
|
|
935
2081
|
hasElement() {
|
|
936
|
-
return e$3(this
|
|
2082
|
+
return e$3(this.$node.modelRef);
|
|
937
2083
|
}
|
|
938
2084
|
/**
|
|
939
2085
|
* Check if this node references to deployment element (Node or Instance).
|
|
940
2086
|
*/
|
|
941
2087
|
hasDeployment() {
|
|
942
|
-
return e$3(this
|
|
2088
|
+
return e$3(this.$node.deploymentRef);
|
|
943
2089
|
}
|
|
944
2090
|
/**
|
|
945
2091
|
* Check if this node references to deployed instance
|
|
@@ -949,7 +2095,7 @@ class NodeModel {
|
|
|
949
2095
|
return this.hasElement() && this.hasDeployment();
|
|
950
2096
|
}
|
|
951
2097
|
isGroup() {
|
|
952
|
-
return isGroupElementKind(this
|
|
2098
|
+
return isGroupElementKind(this.$node);
|
|
953
2099
|
}
|
|
954
2100
|
/**
|
|
955
2101
|
* Checks if the node has the given tag.
|
|
@@ -964,6 +2110,7 @@ class LikeC4ViewModel {
|
|
|
964
2110
|
* Don't use in runtime, only for type inference
|
|
965
2111
|
*/
|
|
966
2112
|
Aux;
|
|
2113
|
+
#view;
|
|
967
2114
|
#rootnodes = /* @__PURE__ */ new Set();
|
|
968
2115
|
#nodes = /* @__PURE__ */ new Map();
|
|
969
2116
|
#edges = /* @__PURE__ */ new Map();
|
|
@@ -971,8 +2118,15 @@ class LikeC4ViewModel {
|
|
|
971
2118
|
#includeDeployments = /* @__PURE__ */ new Set();
|
|
972
2119
|
#includeRelations = /* @__PURE__ */ new Set();
|
|
973
2120
|
#allTags = new DefaultMap((_key) => /* @__PURE__ */ new Set());
|
|
974
|
-
|
|
2121
|
+
#manualLayoutSnapshot;
|
|
2122
|
+
id;
|
|
2123
|
+
/**
|
|
2124
|
+
* The model this view belongs to
|
|
2125
|
+
*/
|
|
975
2126
|
$model;
|
|
2127
|
+
/**
|
|
2128
|
+
* The title of the view
|
|
2129
|
+
*/
|
|
976
2130
|
title;
|
|
977
2131
|
/**
|
|
978
2132
|
* View folder this view belongs to.
|
|
@@ -986,27 +2140,29 @@ class LikeC4ViewModel {
|
|
|
986
2140
|
* "Group 1/Group 2/View"
|
|
987
2141
|
*/
|
|
988
2142
|
viewPath;
|
|
989
|
-
constructor(model, view,
|
|
2143
|
+
constructor(model, folder, view, manualLayoutSnapshot) {
|
|
990
2144
|
this.$model = model;
|
|
991
|
-
this
|
|
2145
|
+
this.#view = view;
|
|
2146
|
+
this.id = view.id;
|
|
992
2147
|
this.folder = folder;
|
|
993
|
-
|
|
2148
|
+
this.#manualLayoutSnapshot = manualLayoutSnapshot;
|
|
2149
|
+
for (const node of this.#view.nodes) {
|
|
994
2150
|
const el = new NodeModel(this, Object.freeze(node));
|
|
995
2151
|
this.#nodes.set(node.id, el);
|
|
996
2152
|
if (!node.parent) {
|
|
997
2153
|
this.#rootnodes.add(el);
|
|
998
2154
|
}
|
|
999
|
-
if (
|
|
1000
|
-
this.#includeDeployments.add(
|
|
2155
|
+
if (node.deploymentRef) {
|
|
2156
|
+
this.#includeDeployments.add(node.deploymentRef);
|
|
1001
2157
|
}
|
|
1002
|
-
if (
|
|
1003
|
-
this.#includeElements.add(
|
|
2158
|
+
if (node.modelRef) {
|
|
2159
|
+
this.#includeElements.add(node.modelRef);
|
|
1004
2160
|
}
|
|
1005
2161
|
for (const tag of el.tags) {
|
|
1006
2162
|
this.#allTags.get(tag).add(el);
|
|
1007
2163
|
}
|
|
1008
2164
|
}
|
|
1009
|
-
for (const edge of view.edges) {
|
|
2165
|
+
for (const edge of this.#view.edges) {
|
|
1010
2166
|
const edgeModel = new EdgeModel(
|
|
1011
2167
|
this,
|
|
1012
2168
|
Object.freeze(edge),
|
|
@@ -1021,14 +2177,29 @@ class LikeC4ViewModel {
|
|
|
1021
2177
|
}
|
|
1022
2178
|
this.#edges.set(edge.id, edgeModel);
|
|
1023
2179
|
}
|
|
1024
|
-
this.title =
|
|
1025
|
-
this.viewPath =
|
|
2180
|
+
this.title = view.title ? extractViewTitleFromPath(view.title) : null;
|
|
2181
|
+
this.viewPath = view.title ? normalizeViewPath(view.title) : view.id;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Returns the styles configuration for the project.
|
|
2185
|
+
*/
|
|
2186
|
+
get $styles() {
|
|
2187
|
+
return this.$model.$styles;
|
|
1026
2188
|
}
|
|
1027
2189
|
get _type() {
|
|
1028
|
-
return this
|
|
2190
|
+
return this.#view[_type];
|
|
1029
2191
|
}
|
|
1030
|
-
get
|
|
1031
|
-
return this
|
|
2192
|
+
get stage() {
|
|
2193
|
+
return this.#view[_stage];
|
|
2194
|
+
}
|
|
2195
|
+
get bounds() {
|
|
2196
|
+
if ("bounds" in this.#view) {
|
|
2197
|
+
return this.#view.bounds;
|
|
2198
|
+
}
|
|
2199
|
+
if (this.#manualLayoutSnapshot) {
|
|
2200
|
+
return this.#manualLayoutSnapshot.bounds;
|
|
2201
|
+
}
|
|
2202
|
+
throw new Error("View is not layouted");
|
|
1032
2203
|
}
|
|
1033
2204
|
/**
|
|
1034
2205
|
* Returns title if defined, otherwise returns title of the element it is based on, otherwise returns its {@link id}
|
|
@@ -1064,17 +2235,17 @@ class LikeC4ViewModel {
|
|
|
1064
2235
|
});
|
|
1065
2236
|
}
|
|
1066
2237
|
get description() {
|
|
1067
|
-
return RichText.memoize(this, "description", this
|
|
2238
|
+
return RichText.memoize(this, "description", this.#view.description);
|
|
1068
2239
|
}
|
|
1069
2240
|
get tags() {
|
|
1070
|
-
return this
|
|
2241
|
+
return this.#view.tags ?? [];
|
|
1071
2242
|
}
|
|
1072
2243
|
get links() {
|
|
1073
|
-
return this
|
|
2244
|
+
return this.#view.links ?? [];
|
|
1074
2245
|
}
|
|
1075
2246
|
get viewOf() {
|
|
1076
2247
|
if (this.isElementView()) {
|
|
1077
|
-
const viewOf = this
|
|
2248
|
+
const viewOf = this.#view.viewOf;
|
|
1078
2249
|
return viewOf ? this.$model.element(viewOf) : null;
|
|
1079
2250
|
}
|
|
1080
2251
|
return null;
|
|
@@ -1085,9 +2256,9 @@ class LikeC4ViewModel {
|
|
|
1085
2256
|
*/
|
|
1086
2257
|
get mode() {
|
|
1087
2258
|
if (this.isDynamicView()) {
|
|
1088
|
-
return this
|
|
2259
|
+
return this.#view.variant ?? "diagram";
|
|
1089
2260
|
}
|
|
1090
|
-
|
|
2261
|
+
return null;
|
|
1091
2262
|
}
|
|
1092
2263
|
/**
|
|
1093
2264
|
* All tags from nodes and edges.
|
|
@@ -1095,6 +2266,60 @@ class LikeC4ViewModel {
|
|
|
1095
2266
|
get includedTags() {
|
|
1096
2267
|
return [...this.#allTags.keys()];
|
|
1097
2268
|
}
|
|
2269
|
+
/**
|
|
2270
|
+
* The original view (auto-layouted).
|
|
2271
|
+
* @see {@link $layouted} should be used for rendering in the UI
|
|
2272
|
+
*/
|
|
2273
|
+
get $view() {
|
|
2274
|
+
if (!this.isLayouted() || "drifts" in this.#view) {
|
|
2275
|
+
return this.#view;
|
|
2276
|
+
}
|
|
2277
|
+
const snapshot = this.#manualLayoutSnapshot;
|
|
2278
|
+
if (snapshot) {
|
|
2279
|
+
return memoizeProp(this, "withDriftReasons", () => {
|
|
2280
|
+
return applyLayoutDriftReasons(this.#view, snapshot);
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
return this.#view;
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Returns the view with manual layout applied if it exists, otherwise returns the original view
|
|
2287
|
+
* This should be used for rendering in the UI
|
|
2288
|
+
*/
|
|
2289
|
+
get $layouted() {
|
|
2290
|
+
if (!this.isLayouted()) {
|
|
2291
|
+
throw new Error("View is not layouted");
|
|
2292
|
+
}
|
|
2293
|
+
return this.manualLayouted ?? this.#view;
|
|
2294
|
+
}
|
|
2295
|
+
get hasManualLayout() {
|
|
2296
|
+
return this.#manualLayoutSnapshot !== void 0;
|
|
2297
|
+
}
|
|
2298
|
+
/**
|
|
2299
|
+
* If view has manual layout, returns it with manual layout applied
|
|
2300
|
+
*/
|
|
2301
|
+
get manualLayouted() {
|
|
2302
|
+
if (!this.isLayouted()) {
|
|
2303
|
+
return null;
|
|
2304
|
+
}
|
|
2305
|
+
const snapshot = this.#manualLayoutSnapshot;
|
|
2306
|
+
if (snapshot) {
|
|
2307
|
+
return memoizeProp(this, "snapshotWithManualLayout", () => {
|
|
2308
|
+
return applyManualLayout(this.#view, snapshot);
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
return null;
|
|
2312
|
+
}
|
|
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
|
+
}
|
|
1098
2323
|
roots() {
|
|
1099
2324
|
return this.#rootnodes.values();
|
|
1100
2325
|
}
|
|
@@ -1115,7 +2340,7 @@ class LikeC4ViewModel {
|
|
|
1115
2340
|
*/
|
|
1116
2341
|
node(node) {
|
|
1117
2342
|
const nodeId = getId(node);
|
|
1118
|
-
return nonNullable(this.#nodes.get(nodeId), `Node ${nodeId} not found in view ${this
|
|
2343
|
+
return nonNullable(this.#nodes.get(nodeId), `Node ${nodeId} not found in view ${this.#view.id}`);
|
|
1119
2344
|
}
|
|
1120
2345
|
/**
|
|
1121
2346
|
* Find node by id.
|
|
@@ -1125,6 +2350,9 @@ class LikeC4ViewModel {
|
|
|
1125
2350
|
}
|
|
1126
2351
|
findNodeWithElement(element) {
|
|
1127
2352
|
const id = getId(element);
|
|
2353
|
+
if (!this.#includeElements.has(id)) {
|
|
2354
|
+
return null;
|
|
2355
|
+
}
|
|
1128
2356
|
return ifind(
|
|
1129
2357
|
this.#nodes.values(),
|
|
1130
2358
|
(node) => node.hasElement() && node.element.id === id
|
|
@@ -1145,7 +2373,7 @@ class LikeC4ViewModel {
|
|
|
1145
2373
|
*/
|
|
1146
2374
|
edge(edge) {
|
|
1147
2375
|
const edgeId = getId(edge);
|
|
1148
|
-
return nonNullable(this.#edges.get(edgeId), `Edge ${edgeId} not found in view ${this
|
|
2376
|
+
return nonNullable(this.#edges.get(edgeId), `Edge ${edgeId} not found in view ${this.#view.id}`);
|
|
1149
2377
|
}
|
|
1150
2378
|
/**
|
|
1151
2379
|
* Find edge by id.
|
|
@@ -1202,22 +2430,28 @@ class LikeC4ViewModel {
|
|
|
1202
2430
|
* Below are type guards.
|
|
1203
2431
|
*/
|
|
1204
2432
|
isComputed() {
|
|
1205
|
-
return this
|
|
2433
|
+
return this.#view[_stage] === "computed";
|
|
2434
|
+
}
|
|
2435
|
+
isLayouted() {
|
|
2436
|
+
return this.#view[_stage] === "layouted";
|
|
1206
2437
|
}
|
|
2438
|
+
/**
|
|
2439
|
+
* @deprecated Use {@link isLayouted} instead
|
|
2440
|
+
*/
|
|
1207
2441
|
isDiagram() {
|
|
1208
|
-
return this
|
|
2442
|
+
return this.#view[_stage] === "layouted";
|
|
1209
2443
|
}
|
|
1210
2444
|
isElementView() {
|
|
1211
|
-
return this
|
|
2445
|
+
return this.#view[_type] === "element";
|
|
1212
2446
|
}
|
|
1213
2447
|
isScopedElementView() {
|
|
1214
|
-
return this
|
|
2448
|
+
return this.#view[_type] === "element" && e$3(this.#view.viewOf);
|
|
1215
2449
|
}
|
|
1216
2450
|
isDeploymentView() {
|
|
1217
|
-
return this
|
|
2451
|
+
return this.#view[_type] === "deployment";
|
|
1218
2452
|
}
|
|
1219
2453
|
isDynamicView() {
|
|
1220
|
-
return this
|
|
2454
|
+
return this.#view[_type] === "dynamic";
|
|
1221
2455
|
}
|
|
1222
2456
|
}
|
|
1223
2457
|
|
|
@@ -1372,14 +2606,10 @@ class LikeC4Model {
|
|
|
1372
2606
|
_views = /* @__PURE__ */ new Map();
|
|
1373
2607
|
_rootViewFolder;
|
|
1374
2608
|
_viewFolders = /* @__PURE__ */ new Map();
|
|
1375
|
-
_viewFolderItems = new DefaultMap(
|
|
1376
|
-
|
|
1377
|
-
);
|
|
1378
|
-
_allTags = new DefaultMap(
|
|
1379
|
-
() => /* @__PURE__ */ new Set()
|
|
1380
|
-
);
|
|
2609
|
+
_viewFolderItems = new DefaultMap(() => /* @__PURE__ */ new Set());
|
|
2610
|
+
_allTags = new DefaultMap(() => /* @__PURE__ */ new Set());
|
|
1381
2611
|
static fromParsed(model) {
|
|
1382
|
-
return new LikeC4Model(model)
|
|
2612
|
+
return new LikeC4Model(model);
|
|
1383
2613
|
}
|
|
1384
2614
|
static create(model) {
|
|
1385
2615
|
return new LikeC4Model(model);
|
|
@@ -1429,13 +2659,13 @@ class LikeC4Model {
|
|
|
1429
2659
|
$data;
|
|
1430
2660
|
constructor($data) {
|
|
1431
2661
|
this.$data = $data;
|
|
1432
|
-
for (const [, element] of t$
|
|
2662
|
+
for (const [, element] of t$d($data.elements)) {
|
|
1433
2663
|
const el = this.addElement(element);
|
|
1434
2664
|
for (const tag of el.tags) {
|
|
1435
2665
|
this._allTags.get(tag).add(el);
|
|
1436
2666
|
}
|
|
1437
2667
|
}
|
|
1438
|
-
for (const [projectId, elements] of t$
|
|
2668
|
+
for (const [projectId, elements] of t$d($data.imports ?? {})) {
|
|
1439
2669
|
for (const element of sortParentsFirst(elements)) {
|
|
1440
2670
|
const el = this.addImportedElement(projectId, element);
|
|
1441
2671
|
for (const tag of el.tags) {
|
|
@@ -1452,21 +2682,22 @@ class LikeC4Model {
|
|
|
1452
2682
|
this.deployment = new LikeC4DeploymentModel(this);
|
|
1453
2683
|
if (isOnStage($data, "computed") || isOnStage($data, "layouted")) {
|
|
1454
2684
|
const compare = compareNaturalHierarchically(VIEW_FOLDERS_SEPARATOR);
|
|
2685
|
+
t($data.views);
|
|
1455
2686
|
const views = t$a(
|
|
1456
2687
|
t($data.views),
|
|
1457
|
-
t$
|
|
2688
|
+
t$e((view) => ({
|
|
1458
2689
|
view,
|
|
1459
2690
|
path: normalizeViewPath(view.title ?? view.id),
|
|
1460
2691
|
folderPath: view.title && getViewFolderPath(view.title) || ""
|
|
1461
2692
|
})),
|
|
1462
2693
|
// Sort hierarchically by groups, but keep same order within groups
|
|
1463
|
-
t$
|
|
2694
|
+
t$g((a, b) => compare(a.folderPath, b.folderPath))
|
|
1464
2695
|
);
|
|
1465
2696
|
const getOrCreateFolder = (path) => {
|
|
1466
2697
|
let folder = this._viewFolders.get(path);
|
|
1467
2698
|
if (!folder) {
|
|
1468
2699
|
const segments = e(path, VIEW_FOLDERS_SEPARATOR);
|
|
1469
|
-
invariant(t$
|
|
2700
|
+
invariant(t$c(segments, 1), `View group path "${path}" must have at least one element`);
|
|
1470
2701
|
let defaultView;
|
|
1471
2702
|
if (path === "") {
|
|
1472
2703
|
defaultView = views.find((view) => view.view.id === "index");
|
|
@@ -1493,7 +2724,12 @@ class LikeC4Model {
|
|
|
1493
2724
|
}, []);
|
|
1494
2725
|
}
|
|
1495
2726
|
for (const { view, folderPath } of views) {
|
|
1496
|
-
const vm = new LikeC4ViewModel(
|
|
2727
|
+
const vm = new LikeC4ViewModel(
|
|
2728
|
+
this,
|
|
2729
|
+
getOrCreateFolder(folderPath),
|
|
2730
|
+
view,
|
|
2731
|
+
$data.manualLayouts?.[view.id]
|
|
2732
|
+
);
|
|
1497
2733
|
this._viewFolderItems.get(folderPath).add(vm);
|
|
1498
2734
|
this._views.set(view.id, vm);
|
|
1499
2735
|
for (const tag of vm.tags) {
|
|
@@ -1832,7 +3068,7 @@ class LikeC4Model {
|
|
|
1832
3068
|
* Use {@link specification.tags} to get all defined tags
|
|
1833
3069
|
*/
|
|
1834
3070
|
get tags() {
|
|
1835
|
-
return memoizeProp(this, "tags", () => t$
|
|
3071
|
+
return memoizeProp(this, "tags", () => t$g([...this._allTags.keys()], compareNatural));
|
|
1836
3072
|
}
|
|
1837
3073
|
/**
|
|
1838
3074
|
* Returns all tags used in the model, sorted by usage count (descending).
|
|
@@ -1840,14 +3076,14 @@ class LikeC4Model {
|
|
|
1840
3076
|
get tagsSortedByUsage() {
|
|
1841
3077
|
return memoizeProp(this, "tagsSortedByUsage", () => t$a(
|
|
1842
3078
|
[...this._allTags.entries()],
|
|
1843
|
-
t$
|
|
3079
|
+
t$e(([tag, tagged]) => ({
|
|
1844
3080
|
tag,
|
|
1845
3081
|
count: tagged.size,
|
|
1846
3082
|
tagged
|
|
1847
3083
|
})),
|
|
1848
|
-
t$
|
|
3084
|
+
t$g((a, b) => compareNatural(a.tag, b.tag)),
|
|
1849
3085
|
t$1(
|
|
1850
|
-
[e$
|
|
3086
|
+
[e$5("count"), "desc"]
|
|
1851
3087
|
)
|
|
1852
3088
|
));
|
|
1853
3089
|
}
|
|
@@ -2063,4 +3299,4 @@ function isEdgeModel(edge) {
|
|
|
2063
3299
|
return edge instanceof EdgeModel;
|
|
2064
3300
|
}
|
|
2065
3301
|
|
|
2066
|
-
export { ElementModel as E, LikeC4Model as L, NodeModel as N, RelationshipModel as R, VIEW_FOLDERS_SEPARATOR as V, t$
|
|
3302
|
+
export { isEdgeModel as A, ElementModel as E, LikeC4Model as L, NodeModel as N, RelationshipModel as R, VIEW_FOLDERS_SEPARATOR as V, t$3 as a, t$4 as b, t$2 as c, t$5 as d, t$6 as e, isNestedElementOfDeployedInstanceModel as f, isDeployedInstanceModel as g, isDeploymentNodeModel as h, isElementModel as i, isDeploymentElementModel as j, buildElementNotations as k, LikeC4DeploymentModel as l, EdgeModel as m, n$5 as n, LikeC4ViewModel as o, LikeC4ViewsFolder as p, extractViewTitleFromPath as q, getViewFolderPath as r, normalizeViewPath as s, t, applyLayoutDriftReasons as u, applyManualLayout as v, isDeploymentRelationModel as w, isRelationModel as x, isLikeC4ViewModel as y, isNodeModel as z };
|