@lionweb/class-core 0.6.13-beta.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.
Files changed (143) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +157 -0
  3. package/dist/base-types.d.ts +167 -0
  4. package/dist/base-types.d.ts.map +1 -0
  5. package/dist/base-types.js +147 -0
  6. package/dist/base-types.js.map +1 -0
  7. package/dist/convenience.d.ts +49 -0
  8. package/dist/convenience.d.ts.map +1 -0
  9. package/dist/convenience.js +75 -0
  10. package/dist/convenience.js.map +1 -0
  11. package/dist/deltas/appliers.d.ts +42 -0
  12. package/dist/deltas/appliers.d.ts.map +1 -0
  13. package/dist/deltas/appliers.js +274 -0
  14. package/dist/deltas/appliers.js.map +1 -0
  15. package/dist/deltas/base.d.ts +6 -0
  16. package/dist/deltas/base.d.ts.map +1 -0
  17. package/dist/deltas/base.js +18 -0
  18. package/dist/deltas/base.js.map +1 -0
  19. package/dist/deltas/handlers.d.ts +17 -0
  20. package/dist/deltas/handlers.d.ts.map +1 -0
  21. package/dist/deltas/handlers.js +43 -0
  22. package/dist/deltas/handlers.js.map +1 -0
  23. package/dist/deltas/index.d.ts +7 -0
  24. package/dist/deltas/index.d.ts.map +1 -0
  25. package/dist/deltas/index.js +23 -0
  26. package/dist/deltas/index.js.map +1 -0
  27. package/dist/deltas/inverters.d.ts +7 -0
  28. package/dist/deltas/inverters.d.ts.map +1 -0
  29. package/dist/deltas/inverters.js +82 -0
  30. package/dist/deltas/inverters.js.map +1 -0
  31. package/dist/deltas/serialization/base.d.ts +7 -0
  32. package/dist/deltas/serialization/base.d.ts.map +1 -0
  33. package/dist/deltas/serialization/base.js +18 -0
  34. package/dist/deltas/serialization/base.js.map +1 -0
  35. package/dist/deltas/serialization/deserializer.g.d.ts +5 -0
  36. package/dist/deltas/serialization/deserializer.g.d.ts.map +1 -0
  37. package/dist/deltas/serialization/deserializer.g.js +164 -0
  38. package/dist/deltas/serialization/deserializer.g.js.map +1 -0
  39. package/dist/deltas/serialization/index.d.ts +5 -0
  40. package/dist/deltas/serialization/index.d.ts.map +1 -0
  41. package/dist/deltas/serialization/index.js +21 -0
  42. package/dist/deltas/serialization/index.js.map +1 -0
  43. package/dist/deltas/serialization/serializer-helpers.d.ts +12 -0
  44. package/dist/deltas/serialization/serializer-helpers.d.ts.map +1 -0
  45. package/dist/deltas/serialization/serializer-helpers.js +28 -0
  46. package/dist/deltas/serialization/serializer-helpers.js.map +1 -0
  47. package/dist/deltas/serialization/serializer.g.d.ts +4 -0
  48. package/dist/deltas/serialization/serializer.g.d.ts.map +1 -0
  49. package/dist/deltas/serialization/serializer.g.js +208 -0
  50. package/dist/deltas/serialization/serializer.g.js.map +1 -0
  51. package/dist/deltas/serialization/types.g.d.ts +147 -0
  52. package/dist/deltas/serialization/types.g.d.ts.map +1 -0
  53. package/dist/deltas/serialization/types.g.js +18 -0
  54. package/dist/deltas/serialization/types.g.js.map +1 -0
  55. package/dist/deltas/types.g.d.ts +149 -0
  56. package/dist/deltas/types.g.d.ts.map +1 -0
  57. package/dist/deltas/types.g.js +180 -0
  58. package/dist/deltas/types.g.js.map +1 -0
  59. package/dist/deserializer.d.ts +27 -0
  60. package/dist/deserializer.d.ts.map +1 -0
  61. package/dist/deserializer.js +168 -0
  62. package/dist/deserializer.js.map +1 -0
  63. package/dist/duplicator.d.ts +19 -0
  64. package/dist/duplicator.d.ts.map +1 -0
  65. package/dist/duplicator.js +87 -0
  66. package/dist/duplicator.js.map +1 -0
  67. package/dist/id-mapping.d.ts +19 -0
  68. package/dist/id-mapping.d.ts.map +1 -0
  69. package/dist/id-mapping.js +44 -0
  70. package/dist/id-mapping.js.map +1 -0
  71. package/dist/index.d.ts +11 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +28 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/linking.d.ts +20 -0
  76. package/dist/linking.d.ts.map +1 -0
  77. package/dist/linking.js +18 -0
  78. package/dist/linking.js.map +1 -0
  79. package/dist/lionCore_builtins.g.d.ts +35 -0
  80. package/dist/lionCore_builtins.g.d.ts.map +1 -0
  81. package/dist/lionCore_builtins.g.js +96 -0
  82. package/dist/lionCore_builtins.g.js.map +1 -0
  83. package/dist/serializer.d.ts +17 -0
  84. package/dist/serializer.d.ts.map +1 -0
  85. package/dist/serializer.js +70 -0
  86. package/dist/serializer.js.map +1 -0
  87. package/dist/textualizer.d.ts +7 -0
  88. package/dist/textualizer.d.ts.map +1 -0
  89. package/dist/textualizer.js +82 -0
  90. package/dist/textualizer.js.map +1 -0
  91. package/dist/value-managers/annotations.d.ts +33 -0
  92. package/dist/value-managers/annotations.d.ts.map +1 -0
  93. package/dist/value-managers/annotations.js +192 -0
  94. package/dist/value-managers/annotations.js.map +1 -0
  95. package/dist/value-managers/base.d.ts +53 -0
  96. package/dist/value-managers/base.d.ts.map +1 -0
  97. package/dist/value-managers/base.js +102 -0
  98. package/dist/value-managers/base.js.map +1 -0
  99. package/dist/value-managers/containments.d.ts +58 -0
  100. package/dist/value-managers/containments.d.ts.map +1 -0
  101. package/dist/value-managers/containments.js +408 -0
  102. package/dist/value-managers/containments.js.map +1 -0
  103. package/dist/value-managers/index.d.ts +6 -0
  104. package/dist/value-managers/index.d.ts.map +1 -0
  105. package/dist/value-managers/index.js +22 -0
  106. package/dist/value-managers/index.js.map +1 -0
  107. package/dist/value-managers/properties.d.ts +24 -0
  108. package/dist/value-managers/properties.d.ts.map +1 -0
  109. package/dist/value-managers/properties.js +191 -0
  110. package/dist/value-managers/properties.js.map +1 -0
  111. package/dist/value-managers/references.d.ts +58 -0
  112. package/dist/value-managers/references.d.ts.map +1 -0
  113. package/dist/value-managers/references.js +346 -0
  114. package/dist/value-managers/references.js.map +1 -0
  115. package/package.json +35 -0
  116. package/src/base-types.ts +353 -0
  117. package/src/convenience.ts +101 -0
  118. package/src/deltas/appliers.ts +317 -0
  119. package/src/deltas/base.ts +23 -0
  120. package/src/deltas/handlers.ts +64 -0
  121. package/src/deltas/index.ts +23 -0
  122. package/src/deltas/inverters.ts +111 -0
  123. package/src/deltas/serialization/base.ts +26 -0
  124. package/src/deltas/serialization/deserializer.g.ts +193 -0
  125. package/src/deltas/serialization/index.ts +22 -0
  126. package/src/deltas/serialization/serializer-helpers.ts +36 -0
  127. package/src/deltas/serialization/serializer.g.ts +272 -0
  128. package/src/deltas/serialization/types.g.ts +209 -0
  129. package/src/deltas/types.g.ts +231 -0
  130. package/src/deserializer.ts +234 -0
  131. package/src/duplicator.ts +111 -0
  132. package/src/id-mapping.ts +58 -0
  133. package/src/index.ts +29 -0
  134. package/src/linking.ts +39 -0
  135. package/src/lionCore_builtins.g.ts +141 -0
  136. package/src/serializer.ts +86 -0
  137. package/src/textualizer.ts +104 -0
  138. package/src/value-managers/annotations.ts +139 -0
  139. package/src/value-managers/base.ts +123 -0
  140. package/src/value-managers/containments.ts +323 -0
  141. package/src/value-managers/index.ts +22 -0
  142. package/src/value-managers/properties.ts +127 -0
  143. package/src/value-managers/references.ts +268 -0
@@ -0,0 +1,127 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {Property} from "@lionweb/core";
19
+ import {action, IObservableValue, observable} from "mobx";
20
+
21
+ import {FeatureValueManager} from "./base.js";
22
+ import {INodeBase} from "../base-types.js";
23
+ import {PropertyAddedDelta, PropertyChangedDelta, PropertyDeletedDelta} from "../deltas/index.js";
24
+
25
+
26
+ /**
27
+ * An instance manages the value of a particular property feature on a particular instance of a classifier.
28
+ */
29
+ export abstract class PropertyValueManager<T> extends FeatureValueManager<Property> {
30
+
31
+ private readonly observableValue: IObservableValue<T | undefined> = observable.box<T | undefined>(undefined, {deep: false});
32
+
33
+ get property(): Property {
34
+ return this.feature;
35
+ }
36
+
37
+ getDirectly(): T | undefined {
38
+ return this.observableValue.get();
39
+ }
40
+
41
+ @action setDirectly(newValue: T | undefined) {
42
+ this.observableValue.set(newValue);
43
+ }
44
+
45
+ isSet(): boolean {
46
+ return this.observableValue.get() !== undefined;
47
+ }
48
+
49
+ }
50
+
51
+
52
+ export class RequiredPropertyValueManager<T> extends PropertyValueManager<T> {
53
+
54
+ constructor(property: Property, container: INodeBase) {
55
+ super(property, container);
56
+ this.checkRequired(true);
57
+ }
58
+
59
+ get(): T {
60
+ const value = this.getDirectly();
61
+ if (value === undefined) {
62
+ this.throwOnReadOfUnset();
63
+ }
64
+ return value;
65
+ }
66
+
67
+ @action set(newValue: T) {
68
+ const oldValue = this.getDirectly();
69
+ if (oldValue === newValue) {
70
+ return
71
+ }
72
+ this.setDirectly(newValue);
73
+ if (oldValue === undefined) {
74
+ if (newValue === undefined) {
75
+ // (doesn't happen)
76
+ } else {
77
+ this.emitDelta(() => new PropertyAddedDelta(this.container, this.property, newValue));
78
+ }
79
+ } else {
80
+ if (newValue === undefined) {
81
+ this.throwOnUnset();
82
+ } else {
83
+ this.emitDelta(() => new PropertyChangedDelta(this.container, this.property, oldValue, newValue));
84
+ }
85
+ }
86
+ }
87
+
88
+ }
89
+
90
+
91
+ export class OptionalPropertyValueManager<T> extends PropertyValueManager<T> {
92
+
93
+ constructor(property: Property, container: INodeBase) {
94
+ super(property, container);
95
+ this.checkRequired(false);
96
+ }
97
+
98
+ get(): T | undefined {
99
+ return this.getDirectly();
100
+ }
101
+
102
+ @action set(newValue: T | undefined) {
103
+ const oldValue = this.getDirectly();
104
+ if (oldValue === undefined) {
105
+ if (newValue === undefined) {
106
+ // do nothing
107
+ } else {
108
+ this.setDirectly(newValue);
109
+ this.emitDelta(() => new PropertyAddedDelta(this.container, this.property, newValue));
110
+ }
111
+ } else {
112
+ if (newValue === undefined) {
113
+ this.setDirectly(undefined);
114
+ this.emitDelta(() => new PropertyDeletedDelta(this.container, this.property, oldValue));
115
+ } else {
116
+ if (oldValue !== newValue) {
117
+ this.setDirectly(newValue);
118
+ this.emitDelta(() => new PropertyChangedDelta(this.container, this.property, oldValue, newValue));
119
+ } else {
120
+ // do nothing
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ }
127
+
@@ -0,0 +1,268 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {Reference, SingleRef} from "@lionweb/core";
19
+ import {action, observable} from "mobx";
20
+
21
+ import {INodeBase} from "../base-types.js";
22
+ import {checkIndex, FeatureValueManager} from "./base.js";
23
+ import {
24
+ ReferenceAddedDelta,
25
+ ReferenceDeletedDelta,
26
+ ReferenceMovedInSameReferenceDelta,
27
+ ReferenceReplacedDelta
28
+ } from "../deltas/index.js";
29
+
30
+
31
+ /**
32
+ * An instance manages the value of a particular reference feature on a particular instance of a classifier.
33
+ */
34
+ export abstract class ReferenceValueManager<T extends INodeBase> extends FeatureValueManager<Reference> {
35
+
36
+ get reference(): Reference {
37
+ return this.feature;
38
+ }
39
+
40
+ abstract getDirectly(): (SingleRef<T> | undefined) | (SingleRef<T> | undefined)[];
41
+
42
+ /**
43
+ * Adds the given target to the reference.
44
+ * For a single-valued reference, this replaces an already-present target.
45
+ */
46
+ abstract addDirectly(newTarget: SingleRef<T> | undefined): void;
47
+
48
+ }
49
+
50
+
51
+ export abstract class SingleReferenceValueManager<T extends INodeBase> extends ReferenceValueManager<T> {
52
+
53
+ protected constructor(reference: Reference, container: INodeBase) {
54
+ super(reference, container);
55
+ this.checkMultiple(false);
56
+ }
57
+
58
+ private readonly target = observable.box<SingleRef<T> | undefined>(undefined, {deep: false});
59
+
60
+ getDirectly(): SingleRef<T> | undefined {
61
+ return this.target.get();
62
+ }
63
+
64
+ isSet(): boolean {
65
+ return this.target.get() !== undefined;
66
+ }
67
+
68
+ @action setDirectly(newTarget: SingleRef<T> | undefined) {
69
+ this.target.set(newTarget); // (this _replaces_ an already-set target value)
70
+ }
71
+
72
+ @action addDirectly(newTarget: SingleRef<T> | undefined) {
73
+ this.setDirectly(newTarget);
74
+ }
75
+
76
+ }
77
+
78
+
79
+ export class OptionalSingleReferenceValueManager<T extends INodeBase> extends SingleReferenceValueManager<T> {
80
+
81
+ constructor(reference: Reference, container: INodeBase) {
82
+ super(reference, container);
83
+ this.checkRequired(false);
84
+ }
85
+
86
+ get(): SingleRef<T> | undefined {
87
+ return this.getDirectly();
88
+ }
89
+
90
+ @action set(newTarget: SingleRef<T> | undefined) {
91
+ const oldTarget = this.getDirectly();
92
+ if (oldTarget === newTarget) {
93
+ // do nothing as nothing changes
94
+ return
95
+ }
96
+ if (newTarget === undefined) {
97
+ this.addDirectly(undefined);
98
+ if (oldTarget === undefined) {
99
+ // (nothing)
100
+ } else {
101
+ this.emitDelta(() => new ReferenceDeletedDelta(this.container, this.reference, 0, oldTarget));
102
+ }
103
+ } else {
104
+ this.addDirectly(newTarget);
105
+ if (oldTarget === undefined) {
106
+ this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, 0, newTarget));
107
+ } else {
108
+ this.emitDelta(() => new ReferenceReplacedDelta(this.container, this.reference, 0, oldTarget, newTarget));
109
+ }
110
+ }
111
+ }
112
+
113
+ }
114
+
115
+
116
+ export class RequiredSingleReferenceValueManager<T extends INodeBase> extends SingleReferenceValueManager<T> {
117
+
118
+ constructor(reference: Reference, container: INodeBase) {
119
+ super(reference, container);
120
+ this.checkRequired(true);
121
+ }
122
+
123
+ get(): SingleRef<T> {
124
+ const target = this.getDirectly();
125
+ if (target === undefined) {
126
+ this.throwOnReadOfUnset();
127
+ }
128
+ return target;
129
+ }
130
+
131
+ @action set(newTarget: SingleRef<T> | undefined) {
132
+ const oldTarget = this.getDirectly();
133
+ if (oldTarget === newTarget) {
134
+ // do nothing as nothing changes
135
+ return
136
+ }
137
+ if (newTarget === undefined) {
138
+ this.throwOnUnset();
139
+ } else {
140
+ this.addDirectly(newTarget);
141
+ if (oldTarget === undefined) {
142
+ this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, 0, newTarget));
143
+ } else {
144
+ this.emitDelta(() => new ReferenceReplacedDelta(this.container, this.reference, 0, oldTarget, newTarget));
145
+ }
146
+ }
147
+ }
148
+
149
+ }
150
+
151
+
152
+ export abstract class MultiReferenceValueManager<T extends INodeBase> extends ReferenceValueManager<T> {
153
+
154
+ protected constructor(reference: Reference, container: INodeBase) {
155
+ super(reference, container);
156
+ this.checkMultiple(true);
157
+ }
158
+
159
+ private readonly targets = observable.array<SingleRef<T>>([], {deep: false});
160
+
161
+ getDirectly(): SingleRef<T>[] {
162
+ return this.targets;
163
+ }
164
+
165
+ get(): SingleRef<T>[] {
166
+ return this.getDirectly().slice();
167
+ }
168
+
169
+ isSet(): boolean {
170
+ return this.targets.length > 0;
171
+ }
172
+
173
+ @action addDirectly(newTarget: SingleRef<T>) {
174
+ this.targets.push(newTarget);
175
+ }
176
+
177
+ @action add(newTarget: SingleRef<T>) {
178
+ this.insertAtIndex(newTarget, this.getDirectly().length);
179
+ }
180
+
181
+ @action insertAtIndexDirectly(newTarget: SingleRef<T>, index: number) {
182
+ checkIndex(index, this.targets.length, true);
183
+ this.targets.splice(index, 0, newTarget);
184
+ }
185
+
186
+ @action insertAtIndex(newTarget: SingleRef<T>, index: number) {
187
+ this.insertAtIndexDirectly(newTarget, index);
188
+ this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, index, newTarget));
189
+ }
190
+
191
+ @action removeDirectly(targetToRemove: SingleRef<T>): number {
192
+ const targets = this.getDirectly();
193
+ const index = targets.findIndex((target) => target === targetToRemove);
194
+ if (index > -1) {
195
+ targets.splice(index, 1);
196
+ }
197
+ return index;
198
+ }
199
+
200
+ abstract remove(targetToRemove: SingleRef<T>): void;
201
+
202
+ @action moveDirectly(oldIndex: number, newIndex: number): SingleRef<T> | undefined {
203
+ checkIndex(oldIndex, this.targets.length, false);
204
+ checkIndex(newIndex, this.targets.length, false);
205
+ if (oldIndex !== newIndex) {
206
+ const [target] = this.targets.splice(oldIndex, 1);
207
+ this.targets.splice(newIndex, 0, target);
208
+ return target;
209
+ }
210
+ return undefined;
211
+ }
212
+
213
+ @action move(oldIndex: number, newIndex: number) {
214
+ const target = this.moveDirectly(oldIndex, newIndex);
215
+ if (target !== undefined) {
216
+ this.emitDelta(() => new ReferenceMovedInSameReferenceDelta(this.container, this.reference, oldIndex, newIndex, target));
217
+ }
218
+ }
219
+
220
+ }
221
+
222
+
223
+ export class OptionalMultiReferenceValueManager<T extends INodeBase> extends MultiReferenceValueManager<T> {
224
+
225
+ constructor(reference: Reference, container: INodeBase) {
226
+ super(reference, container);
227
+ this.checkRequired(false);
228
+ }
229
+
230
+ @action remove(targetToRemove: SingleRef<T>) {
231
+ const index = this.removeDirectly(targetToRemove);
232
+ if (index > -1) {
233
+ this.emitDelta(() => new ReferenceDeletedDelta(this.container, this.reference, index, targetToRemove));
234
+ }
235
+ }
236
+
237
+ }
238
+
239
+
240
+ export class RequiredMultiReferenceValueManager<T extends INodeBase> extends MultiReferenceValueManager<T> {
241
+
242
+ constructor(reference: Reference, container: INodeBase) {
243
+ super(reference, container);
244
+ this.checkRequired(true);
245
+ }
246
+
247
+ get(): SingleRef<T>[] {
248
+ const targets = this.getDirectly();
249
+ if (targets.length === 0) {
250
+ this.throwOnReadOfUnset();
251
+ }
252
+ return targets;
253
+ }
254
+
255
+ @action remove(targetToRemove: SingleRef<T>) {
256
+ const targets = this.getDirectly();
257
+ const index = targets.findIndex((target) => target === targetToRemove);
258
+ if (index > -1) {
259
+ if (targets.length === 1) {
260
+ this.throwOnUnset();
261
+ }
262
+ targets.splice(index, 1);
263
+ this.emitDelta(() => new ReferenceDeletedDelta(this.container, this.reference, index, targetToRemove));
264
+ }
265
+ }
266
+
267
+ }
268
+