@telia-ace/widget-core 1.0.9 → 1.0.12

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/index.js CHANGED
@@ -1,1047 +1,646 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { createConfigurationApi } from "@webprovisions/platform";
21
- import { uuid, Logger } from "@telia-ace/widget-utilities";
22
- class ActionResolver {
23
- constructor(container) {
24
- const { events } = container.get("$widget");
25
- this.events = events.createChild(this);
26
- }
27
- action(target, action, value) {
28
- this.events.dispatch("data:action", { action, value, target }, { bubbles: true });
29
- }
30
- subscribe(origin, fn) {
31
- return this.events.subscribe("data:action", (e, { action, value, target }) => origin === target && fn(origin, action, value));
1
+ var M = Object.defineProperty, V = Object.defineProperties;
2
+ var _ = Object.getOwnPropertyDescriptors;
3
+ var I = Object.getOwnPropertySymbols;
4
+ var z = Object.prototype.hasOwnProperty, Q = Object.prototype.propertyIsEnumerable;
5
+ var L = (n, t, e) => t in n ? M(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, S = (n, t) => {
6
+ for (var e in t || (t = {}))
7
+ z.call(t, e) && L(n, e, t[e]);
8
+ if (I)
9
+ for (var e of I(t))
10
+ Q.call(t, e) && L(n, e, t[e]);
11
+ return n;
12
+ }, j = (n, t) => V(n, _(t));
13
+ import { createConfigurationApi as q } from "@webprovisions/platform";
14
+ import { uuid as E, Logger as O } from "@telia-ace/widget-utilities";
15
+ class ct {
16
+ constructor(t) {
17
+ const { events: e } = t.get("$widget");
18
+ this.events = e.createChild(this);
19
+ }
20
+ action(t, e, s) {
21
+ this.events.dispatch("data:action", { action: e, value: s, target: t }, { bubbles: !0 });
22
+ }
23
+ subscribe(t, e) {
24
+ return this.events.subscribe("data:action", (s, { action: r, value: c, target: o }) => t === o && e(t, r, c));
32
25
  }
33
26
  }
34
- const createEventSubscriber = (events) => {
35
- const subs = [];
36
- const subscribe = (type, listener) => {
37
- subs.push(events.subscribe(type, listener));
38
- };
27
+ const K = (n) => {
28
+ const t = [];
39
29
  return [
40
- subscribe,
30
+ (s, r) => {
31
+ t.push(n.subscribe(s, r));
32
+ },
41
33
  () => {
42
- subs.forEach((sub) => {
43
- sub();
34
+ t.forEach((s) => {
35
+ s();
44
36
  });
45
37
  }
46
38
  ];
47
39
  };
48
- class ComponentQuery {
49
- constructor(platform, rules = []) {
50
- this.platform = platform;
51
- this.rules = rules;
52
- }
53
- match(node) {
54
- return this.rules.every((rule) => {
55
- if (rule.id && rule.id !== node.id) {
56
- return false;
57
- }
58
- if (rule.type && rule.type !== node.type) {
59
- return false;
60
- }
61
- return true;
62
- });
40
+ class N {
41
+ constructor(t, e = []) {
42
+ this.platform = t, this.rules = e;
43
+ }
44
+ match(t) {
45
+ return this.rules.every((e) => !(e.id && e.id !== t.id || e.type && e.type !== t.type));
63
46
  }
64
- ofType(type) {
65
- this.rules.push({ type });
66
- return this;
47
+ ofType(t) {
48
+ return this.rules.push({ type: t }), this;
67
49
  }
68
- withId(id) {
69
- this.rules.push({ id });
70
- return this;
50
+ withId(t) {
51
+ return this.rules.push({ id: t }), this;
71
52
  }
72
53
  select() {
73
- return new AbstractComponentController(this.platform, this);
54
+ return new U(this.platform, this);
74
55
  }
75
56
  }
76
- class ComponentNodeController {
77
- constructor(platform, node, ns) {
78
- this.platform = platform;
79
- this.node = node;
80
- this.actions = new ActionsController(platform, new ComponentQuery(platform).withId(node.id), ns);
81
- const [subscribe, unsubscribe] = createEventSubscriber(this.platform.events);
82
- this.subscribe = subscribe;
83
- this.unsubscribe = unsubscribe;
84
- }
85
- properties(updated) {
86
- if (updated) {
87
- this.node.touchProperties((properties) => updated(properties));
88
- }
89
- return this.node.attributes.properties;
90
- }
91
- context(updated) {
92
- if (updated) {
93
- this.subscribe("components:context-changed", (event, { node }) => {
94
- if (node === this.node) {
95
- updated(this.node.attributes.context);
96
- }
97
- });
98
- }
99
- return this.node.attributes.context;
100
- }
101
- layout(updated) {
102
- if (updated) {
103
- this.subscribe("components:layout-changed", (event, { node }) => {
104
- if (node === this.node) {
105
- updated(this.node.attributes.layout);
106
- }
107
- });
108
- }
109
- return this.node.attributes.layout;
57
+ class $ {
58
+ constructor(t, e, s) {
59
+ this.platform = t, this.node = e, this.actions = new k(t, new N(t).withId(e.id), s);
60
+ const [r, c] = K(this.platform.events);
61
+ this.subscribe = r, this.unsubscribe = c;
62
+ }
63
+ properties(t) {
64
+ return t && this.node.touchProperties((e) => t(e)), this.node.attributes.properties;
65
+ }
66
+ context(t) {
67
+ return t && this.subscribe("components:context-changed", (e, { node: s }) => {
68
+ s === this.node && t(this.node.attributes.context);
69
+ }), this.node.attributes.context;
70
+ }
71
+ layout(t) {
72
+ return t && this.subscribe("components:layout-changed", (e, { node: s }) => {
73
+ s === this.node && t(this.node.attributes.layout);
74
+ }), this.node.attributes.layout;
110
75
  }
111
- writeProperties(properties, options) {
112
- this.node.writeProperties(properties, options);
76
+ writeProperties(t, e) {
77
+ this.node.writeProperties(t, e);
113
78
  }
114
- writeContext(context, options) {
115
- this.node.writeProperties(context, options);
79
+ writeContext(t, e) {
80
+ this.node.writeProperties(t, e);
116
81
  }
117
- writeLayout(layout, options) {
118
- this.node.writeLayout(layout, options);
82
+ writeLayout(t, e) {
83
+ this.node.writeLayout(t, e);
119
84
  }
120
85
  dispose() {
121
- this.unsubscribe();
122
- this.actions.dispose();
86
+ this.unsubscribe(), this.actions.dispose();
123
87
  }
124
88
  }
125
- class AbstractComponentController {
126
- constructor(platform, target, clearOnDispose = true) {
127
- this.platform = platform;
128
- this.target = target;
129
- this.clearOnDispose = clearOnDispose;
130
- this.removes = [];
131
- this.actions = new ActionsController(this.platform, this.target);
132
- }
133
- writeProperties(properties, options) {
89
+ class U {
90
+ constructor(t, e, s = !0) {
91
+ this.platform = t, this.target = e, this.clearOnDispose = s, this.removes = [], this.actions = new k(this.platform, this.target);
92
+ }
93
+ writeProperties(t, e) {
134
94
  this.removes.push(this.platform.write({
135
- options,
136
- attributes: { properties },
95
+ options: e,
96
+ attributes: { properties: t },
137
97
  target: this.target,
138
98
  removable: this.clearOnDispose
139
99
  }));
140
100
  }
141
- writeContext(context, options) {
101
+ writeContext(t, e) {
142
102
  this.removes.push(this.platform.write({
143
- options,
144
- attributes: { context },
103
+ options: e,
104
+ attributes: { context: t },
145
105
  target: this.target,
146
106
  removable: this.clearOnDispose
147
107
  }));
148
108
  }
149
- writeLayout(layout, options) {
109
+ writeLayout(t, e) {
150
110
  this.removes.push(this.platform.write({
151
- options,
152
- attributes: { layout },
111
+ options: e,
112
+ attributes: { layout: t },
153
113
  target: this.target,
154
114
  removable: this.clearOnDispose
155
115
  }));
156
116
  }
157
117
  dispose() {
158
- this.removes.forEach((remove) => {
159
- remove();
160
- });
161
- this.actions.dispose();
118
+ this.removes.forEach((t) => {
119
+ t();
120
+ }), this.actions.dispose();
162
121
  }
163
122
  }
164
- const executeActionListeners = (listeners, data, controller) => {
165
- const stack = listeners.concat();
166
- const dispatch = (data2, globalOptions, controller2) => {
167
- let cancelled = true;
168
- if (stack.length) {
169
- const handler = stack.shift();
170
- const next = (data3, options) => {
171
- cancelled = false;
172
- return dispatch(data3, Object.assign({}, globalOptions, options), controller2);
173
- };
174
- return Promise.resolve(handler(data2, next, controller2)).then((result) => __spreadProps(__spreadValues({}, result), {
175
- cancelled
123
+ const Y = (n, t, e) => {
124
+ const s = n.concat(), r = (c, o, a) => {
125
+ let u = !0;
126
+ if (s.length) {
127
+ const h = s.shift(), i = (p, l) => (u = !1, r(p, Object.assign({}, o, l), a));
128
+ return Promise.resolve(h(c, i, a)).then((p) => j(S({}, p), {
129
+ cancelled: u
176
130
  }));
177
131
  }
178
- return Promise.resolve({ data: data2, cancelled: false, options: globalOptions });
132
+ return Promise.resolve({ data: c, cancelled: !1, options: o });
179
133
  };
180
- return dispatch(data, {}, controller);
134
+ return r(t, {}, e);
181
135
  };
182
- class ActionsController {
183
- constructor(platform, target, ns) {
184
- this.platform = platform;
185
- this.target = target;
186
- this.ns = ns;
187
- this.subscriptions = [];
188
- this.create = this.create.bind(this);
189
- }
190
- create(key, fn = () => {
136
+ class k {
137
+ constructor(t, e, s) {
138
+ this.platform = t, this.target = e, this.ns = s, this.subscriptions = [], this.create = this.create.bind(this);
139
+ }
140
+ create(t, e = () => {
191
141
  }) {
192
- const handler = {
193
- key,
194
- fn,
142
+ const s = {
143
+ key: t,
144
+ fn: e,
195
145
  target: this.target,
196
146
  ns: this.ns
197
147
  };
198
- this.platform.actionsState.handlers.push(handler);
199
- const subscription = () => {
200
- const index = this.platform.actionsState.handlers.indexOf(handler);
201
- if (index > -1) {
202
- this.platform.actionsState.handlers.splice(index, 1);
203
- }
148
+ this.platform.actionsState.handlers.push(s);
149
+ const r = () => {
150
+ const c = this.platform.actionsState.handlers.indexOf(s);
151
+ c > -1 && this.platform.actionsState.handlers.splice(c, 1);
204
152
  };
205
- this.subscriptions.push(subscription);
206
- return subscription;
207
- }
208
- dispatch(key, data) {
209
- const instances = this.platform.nodes.all.concat(this.platform.nodes.detached);
210
- const output = {};
211
- const handlers = this.platform.actionsState.handlers.filter((handler) => handler.key === key && (!handler.ns || !this.ns || handler.ns === this.ns));
212
- return Promise.all(handlers.map((handler) => {
213
- const matchedInstances = instances.filter((instance) => handler.target.match(instance) && this.target.match(instance));
214
- const watchers = this.platform.actionsState.watchers.filter((watcher) => {
215
- return watcher.key === key && (!watcher.ns || !this.ns || watcher.ns === this.ns) && matchedInstances.some((instance) => watcher.target.match(instance));
216
- }).map((watcher) => watcher.fn);
217
- return Promise.all(matchedInstances.map((node) => {
218
- const controller = new ComponentNodeController(this.platform, node, this.ns);
219
- return executeActionListeners(watchers, data, controller).then((input) => {
220
- const { data: data2 = {}, options, cancelled } = input;
221
- return Promise.resolve(cancelled ? {} : handler.fn(data2, options, controller)).then((handlerResponse) => {
222
- output[node.id] = handlerResponse;
153
+ return this.subscriptions.push(r), r;
154
+ }
155
+ dispatch(t, e) {
156
+ const s = this.platform.nodes.all.concat(this.platform.nodes.detached), r = {}, c = this.platform.actionsState.handlers.filter((o) => o.key === t && (!o.ns || !this.ns || o.ns === this.ns));
157
+ return Promise.all(c.map((o) => {
158
+ const a = s.filter((h) => o.target.match(h) && this.target.match(h)), u = this.platform.actionsState.watchers.filter((h) => h.key === t && (!h.ns || !this.ns || h.ns === this.ns) && a.some((i) => h.target.match(i))).map((h) => h.fn);
159
+ return Promise.all(a.map((h) => {
160
+ const i = new $(this.platform, h, this.ns);
161
+ return Y(u, e, i).then((p) => {
162
+ const { data: l = {}, options: d, cancelled: v } = p;
163
+ return Promise.resolve(v ? {} : o.fn(l, d, i)).then((g) => {
164
+ r[h.id] = g;
223
165
  });
224
166
  });
225
167
  }));
226
- })).then(() => output);
227
- }
228
- watch(key, fn) {
229
- let parsedKey = key;
230
- let parsedNs = this.ns;
231
- const sections = key.split(".");
232
- if (sections.length > 1) {
233
- parsedNs = sections[0];
234
- parsedKey = sections.splice(1).join(".");
235
- }
236
- const watcher = {
237
- fn,
168
+ })).then(() => r);
169
+ }
170
+ watch(t, e) {
171
+ let s = t, r = this.ns;
172
+ const c = t.split(".");
173
+ c.length > 1 && (r = c[0], s = c.splice(1).join("."));
174
+ const o = {
175
+ fn: e,
238
176
  target: this.target,
239
- key: parsedKey,
240
- ns: parsedNs
177
+ key: s,
178
+ ns: r
241
179
  };
242
- this.platform.actionsState.watchers.push(watcher);
243
- const subscription = () => {
244
- const index = this.platform.actionsState.watchers.indexOf(watcher);
245
- if (index > -1) {
246
- this.platform.actionsState.watchers.splice(index, 1);
247
- }
180
+ this.platform.actionsState.watchers.push(o);
181
+ const a = () => {
182
+ const u = this.platform.actionsState.watchers.indexOf(o);
183
+ u > -1 && this.platform.actionsState.watchers.splice(u, 1);
248
184
  };
249
- this.subscriptions.push(subscription);
250
- return subscription;
185
+ return this.subscriptions.push(a), a;
251
186
  }
252
187
  dispose() {
253
- this.subscriptions.forEach((unsubscribe) => unsubscribe());
188
+ this.subscriptions.forEach((t) => t());
254
189
  }
255
190
  }
256
- var componentConfigurationApi = createConfigurationApi((builder) => {
257
- builder.createCommand("components", (context) => (config) => {
258
- context.events.subscribeOnce("components:platform-created", (event, { platform }) => {
259
- if (config.handlers) {
260
- config.handlers.forEach(([key, handler]) => {
261
- platform.addComponentHandler(key, handler);
262
- });
263
- }
191
+ const ht = q((n) => {
192
+ n.createCommand("components", (t) => (e) => {
193
+ t.events.subscribeOnce("components:platform-created", (s, { platform: r }) => {
194
+ e.handlers && e.handlers.forEach(([c, o]) => {
195
+ r.addComponentHandler(c, o);
196
+ });
264
197
  });
265
198
  });
266
199
  });
267
- class ComponentNode {
268
- constructor(events, type) {
269
- this.events = events;
270
- this.tags = [];
271
- this.children = {};
272
- this.changesets = [];
273
- this.mountCount = 0;
274
- this.id = uuid();
275
- this.type = type;
276
- this.attributes = {
200
+ class H {
201
+ constructor(t, e) {
202
+ this.events = t, this.tags = [], this.children = {}, this.changesets = [], this.mountCount = 0, this.id = E(), this.type = e, this.attributes = {
277
203
  context: {},
278
204
  properties: {},
279
205
  layout: {},
280
206
  tags: []
281
- };
282
- this.writeLayout({ size: "full", indent: 0 });
207
+ }, this.writeLayout({ size: "full", indent: 0 });
283
208
  }
284
- mount(viewOutletContainer, element) {
285
- let mountedNodes = viewOutletContainer.get("mounted-nodes");
286
- if (!mountedNodes) {
287
- mountedNodes = /* @__PURE__ */ new Map();
288
- viewOutletContainer.register("mounted-nodes", mountedNodes);
289
- }
290
- if (mountedNodes.has(this)) {
291
- return () => {
292
- };
293
- }
294
- this.events.dispatch("components:node-mounted", { node: this });
295
- if (this.mountCount === 0) {
296
- this.mountCount = this.mountCount + 1;
297
- this.events.dispatch("components:node-enter", { node: this });
298
- }
299
- return () => {
300
- mountedNodes.delete(this);
301
- this.events.dispatch("components:node-unmounted", { node: this });
302
- this.mountCount = this.mountCount - 1;
303
- if (this.mountCount === 0) {
304
- this.events.dispatch("components:node-exit", { node: this });
305
- }
306
- };
209
+ mount(t, e) {
210
+ let s = t.get("mounted-nodes");
211
+ return s || (s = /* @__PURE__ */ new Map(), t.register("mounted-nodes", s)), s.has(this) ? (process.env.NODE_ENV !== "production" && O.error("Trying to mount an already mounted component node.", this), () => {
212
+ }) : (this.events.dispatch("components:node-mounted", { node: this }), this.mountCount === 0 && (this.mountCount = this.mountCount + 1, this.events.dispatch("components:node-enter", { node: this })), () => {
213
+ s.delete(this), this.events.dispatch("components:node-unmounted", { node: this }), this.mountCount = this.mountCount - 1, this.mountCount === 0 && this.events.dispatch("components:node-exit", { node: this });
214
+ });
307
215
  }
308
- appendChild(node, branch = "default") {
309
- if (node.parent) {
310
- if (node.parent === this) {
216
+ appendChild(t, e = "default") {
217
+ if (t.parent) {
218
+ if (t.parent === this)
311
219
  return;
312
- }
313
- node.parent.removeChild(node);
220
+ t.parent.removeChild(t);
314
221
  }
315
- node.parent = this;
316
- if (!this.children[branch]) {
317
- this.children[branch] = [];
318
- }
319
- this.children[branch].push(node);
320
- this.events.dispatch("components:node-appended", { node });
222
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].push(t), this.events.dispatch("components:node-appended", { node: t });
321
223
  }
322
- prependChild(node, branch = "default") {
323
- if (node.parent) {
324
- if (node.parent === this) {
224
+ prependChild(t, e = "default") {
225
+ if (t.parent) {
226
+ if (t.parent === this)
325
227
  return;
326
- }
327
- node.parent.removeChild(node);
328
- }
329
- node.parent = this;
330
- if (!this.children[branch]) {
331
- this.children[branch] = [];
228
+ t.parent.removeChild(t);
332
229
  }
333
- this.children[branch].unshift(node);
334
- this.events.dispatch("components:node-appended", { node });
335
- }
336
- touchProperties(properties, options = {}, removable) {
337
- const attributes = { properties };
338
- const changeset = [attributes, options];
339
- this.changesets.push(changeset);
340
- this.events.dispatch("components:set-properties", { node: this });
341
- return () => {
342
- if (removable) {
343
- const indexToRemove = this.changesets.indexOf(changeset);
344
- if (indexToRemove > -1) {
345
- this.changesets.splice(indexToRemove, 1);
346
- this.events.dispatch("components:set-properties", { node: this });
347
- }
230
+ t.parent = this, this.children[e] || (this.children[e] = []), this.children[e].unshift(t), this.events.dispatch("components:node-appended", { node: t });
231
+ }
232
+ touchProperties(t, e = {}, s) {
233
+ const c = [{ properties: t }, e];
234
+ return this.changesets.push(c), this.events.dispatch("components:set-properties", { node: this }), () => {
235
+ if (s) {
236
+ const o = this.changesets.indexOf(c);
237
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
348
238
  }
349
239
  };
350
240
  }
351
- writeProperties(properties, options = {}, removable) {
352
- const attributes = { properties };
353
- const changeset = [attributes, options];
354
- this.changesets.push(changeset);
355
- this.events.dispatch("components:set-properties", { node: this });
356
- return () => {
357
- if (removable) {
358
- const indexToRemove = this.changesets.indexOf(changeset);
359
- if (indexToRemove > -1) {
360
- this.changesets.splice(indexToRemove, 1);
361
- this.events.dispatch("components:set-properties", { node: this });
362
- }
241
+ writeProperties(t, e = {}, s) {
242
+ const c = [{ properties: t }, e];
243
+ return this.changesets.push(c), this.events.dispatch("components:set-properties", { node: this }), () => {
244
+ if (s) {
245
+ const o = this.changesets.indexOf(c);
246
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-properties", { node: this }));
363
247
  }
364
248
  };
365
249
  }
366
- writeLayout(layout, options = {}, removable) {
367
- const attributes = { layout };
368
- const changeset = [attributes, options];
369
- this.changesets.push(changeset);
370
- this.events.dispatch("components:set-layout", { node: this });
371
- return () => {
372
- if (!removable) {
250
+ writeLayout(t, e = {}, s) {
251
+ const c = [{ layout: t }, e];
252
+ return this.changesets.push(c), this.events.dispatch("components:set-layout", { node: this }), () => {
253
+ if (!s)
373
254
  return;
374
- }
375
- const indexToRemove = this.changesets.indexOf(changeset);
376
- if (indexToRemove > -1) {
377
- this.changesets.splice(indexToRemove, 1);
378
- this.events.dispatch("components:set-layout", { node: this });
379
- }
255
+ const o = this.changesets.indexOf(c);
256
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-layout", { node: this }));
380
257
  };
381
258
  }
382
- writeContext(context, options = {}, removable) {
383
- const attributes = { context };
384
- const changeset = [attributes, options];
385
- this.changesets.push(changeset);
386
- this.events.dispatch("components:set-context", { node: this });
387
- return () => {
388
- if (!removable) {
259
+ writeContext(t, e = {}, s) {
260
+ const c = [{ context: t }, e];
261
+ return this.changesets.push(c), this.events.dispatch("components:set-context", { node: this }), () => {
262
+ if (!s)
389
263
  return;
390
- }
391
- const indexToRemove = this.changesets.indexOf(changeset);
392
- if (indexToRemove > -1) {
393
- this.changesets.splice(indexToRemove, 1);
394
- this.events.dispatch("components:set-context", { node: this });
395
- }
264
+ const o = this.changesets.indexOf(c);
265
+ o > -1 && (this.changesets.splice(o, 1), this.events.dispatch("components:set-context", { node: this }));
396
266
  };
397
267
  }
398
- getChildren(branch = "default") {
399
- const children = this.children[branch] || [];
400
- return children.reduce((acc, node, i) => {
401
- const { order: index = i } = node.attributes.layout;
402
- if (!acc[index]) {
403
- acc[index] = node;
404
- } else {
405
- acc.splice(index, 0, node);
406
- }
407
- return acc;
408
- }, Array(children.length));
268
+ getChildren(t = "default") {
269
+ const e = this.children[t] || [];
270
+ return e.reduce((s, r, c) => {
271
+ const { order: o = c } = r.attributes.layout;
272
+ return s[o] ? s.splice(o, 0, r) : s[o] = r, s;
273
+ }, Array(e.length));
409
274
  }
410
275
  remove() {
411
- if (this.parent) {
412
- this.parent.removeChild(this);
413
- }
276
+ this.parent && this.parent.removeChild(this);
414
277
  }
415
- removeChild(node) {
416
- Object.keys(this.children).forEach((branch) => {
417
- const children = this.children[branch];
418
- const indexToRemove = children.indexOf(node);
419
- if (indexToRemove > -1) {
420
- children.splice(indexToRemove, 1);
421
- this.events.dispatch("components:node-removed", { node, parentNode: this });
422
- }
423
- });
424
- delete node.parent;
278
+ removeChild(t) {
279
+ Object.keys(this.children).forEach((e) => {
280
+ const s = this.children[e], r = s.indexOf(t);
281
+ r > -1 && (s.splice(r, 1), this.events.dispatch("components:node-removed", { node: t, parentNode: this }));
282
+ }), delete t.parent;
425
283
  }
426
284
  }
427
- const traverseComponentsRecursive = (nodes, switches, fn) => {
428
- for (let i = 0, y = nodes.length; i < y; i++) {
429
- if (fn(nodes[i]) === true) {
430
- break;
431
- }
432
- const branch = switches[nodes[i].id] || "default";
433
- const children = nodes[i].getChildren(branch);
434
- traverseComponentsRecursive(children, switches, fn);
435
- }
436
- };
437
- const traverseComponents = (root, switches, fn) => {
438
- if (fn(root) !== true) {
439
- const branch = switches[root.id] || "default";
440
- const children = root.children[branch];
441
- traverseComponentsRecursive(children, switches, fn);
442
- }
285
+ const B = (n, t, e) => {
286
+ for (let s = 0, r = n.length; s < r && e(n[s]) !== !0; s++) {
287
+ const c = t[n[s].id] || "default", o = n[s].getChildren(c);
288
+ B(o, t, e);
289
+ }
290
+ }, P = (n, t, e) => {
291
+ if (e(n) !== !0) {
292
+ const s = t[n.id] || "default", r = n.children[s];
293
+ B(r, t, e);
294
+ }
295
+ }, x = (n, t) => {
296
+ const e = [];
297
+ return P(n, t, (s) => {
298
+ e.push(s);
299
+ }), e;
300
+ }, F = (n, t, e) => {
301
+ let s;
302
+ return P(n, t, (r) => {
303
+ if (e(r))
304
+ return s = r, !0;
305
+ }), s;
443
306
  };
444
- const findVisibleComponents = (root, switches) => {
445
- const nodes = [];
446
- traverseComponents(root, switches, (node) => {
447
- nodes.push(node);
448
- });
449
- return nodes;
450
- };
451
- const findComponent = (root, switches, fn) => {
452
- let matched;
453
- traverseComponents(root, switches, (node) => {
454
- if (fn(node)) {
455
- matched = node;
456
- return true;
457
- }
458
- });
459
- return matched;
460
- };
461
- class ComponentNodeCollection {
462
- constructor(root, switches, events) {
463
- this.root = root;
464
- this.switches = switches;
465
- this.all = [];
466
- this.visible = [];
467
- this.detached = [];
468
- events.subscribe("components:node-appended", (event, data) => {
469
- this.all.push(data.node);
470
- this.visible = findVisibleComponents(root, switches);
471
- });
472
- events.subscribe("components:node-removed", (event, data) => {
473
- let indexToRemove = this.all.indexOf(data.node);
474
- if (indexToRemove > -1) {
475
- this.all.splice(indexToRemove, 1);
476
- }
477
- indexToRemove = this.visible.indexOf(data.node);
478
- if (indexToRemove > -1) {
479
- this.visible.splice(indexToRemove, 1);
480
- }
481
- this.visible = findVisibleComponents(root, switches);
482
- });
483
- events.subscribe("components:node-switched", (event, data) => {
484
- this.visible = findVisibleComponents(root, switches);
307
+ class G {
308
+ constructor(t, e, s) {
309
+ this.root = t, this.switches = e, this.all = [], this.visible = [], this.detached = [], s.subscribe("components:node-appended", (r, c) => {
310
+ this.all.push(c.node), this.visible = x(t, e);
311
+ }), s.subscribe("components:node-removed", (r, c) => {
312
+ let o = this.all.indexOf(c.node);
313
+ o > -1 && this.all.splice(o, 1), o = this.visible.indexOf(c.node), o > -1 && this.visible.splice(o, 1), this.visible = x(t, e);
314
+ }), s.subscribe("components:node-switched", (r, c) => {
315
+ this.visible = x(t, e);
485
316
  });
486
317
  }
487
- query(query = {}) {
488
- const nodes = [];
489
- traverseComponents(this.root, this.switches, (node) => {
490
- const match = Object.keys(query).every((member) => {
491
- return query[member] === node[member];
492
- });
493
- if (match) {
494
- nodes.push(node);
495
- }
496
- });
497
- return nodes;
318
+ query(t = {}) {
319
+ const e = [];
320
+ return P(this.root, this.switches, (s) => {
321
+ Object.keys(t).every((c) => t[c] === s[c]) && e.push(s);
322
+ }), e;
498
323
  }
499
- get(id) {
500
- return findComponent(this.root, this.switches, (node) => node.id === id) || this.detached.find((node) => node.id === id);
324
+ get(t) {
325
+ return F(this.root, this.switches, (e) => e.id === t) || this.detached.find((e) => e.id === t);
501
326
  }
502
327
  }
503
- class CustomComponentHandler {
328
+ class J {
504
329
  constructor() {
505
330
  this.handlers = /* @__PURE__ */ new Map();
506
331
  }
507
- add(name, fn) {
508
- this.handlers.set(name, fn);
332
+ add(t, e) {
333
+ this.handlers.set(t, e);
509
334
  }
510
- get(name) {
511
- return this.handlers.get(name);
335
+ get(t) {
336
+ return this.handlers.get(t);
512
337
  }
513
338
  }
514
- const calculateNodeIndex = (node) => {
515
- let currentNode = node;
516
- let index = 0;
517
- while (currentNode.parent) {
518
- index = index + 1;
519
- currentNode = currentNode.parent;
520
- }
521
- return index;
522
- };
523
- const sortQueue = (queue) => {
524
- const mapped = queue.map(([node, options]) => {
525
- return [calculateNodeIndex(node), node, options];
526
- });
527
- return mapped.sort(([a], [b]) => a - b).map(([, node, options]) => {
528
- return [node, options];
529
- });
530
- };
531
- const isObject = (item) => {
532
- return item && typeof item === "object" && !Array.isArray(item);
533
- };
534
- const mergeDeep = (target, ...sources) => {
535
- if (!sources.length)
536
- return target;
537
- const source = sources.shift();
538
- if (isObject(target) && isObject(source)) {
539
- for (const key in source) {
540
- if (isObject(source[key])) {
541
- if (!target[key])
542
- Object.assign(target, { [key]: {} });
543
- mergeDeep(target[key], source[key]);
544
- } else {
545
- Object.assign(target, { [key]: source[key] });
546
- }
547
- }
548
- }
549
- return mergeDeep(target, ...sources);
550
- };
551
- const matchesBreakpoint = (b1, b2) => {
552
- if (!b1 || b1 === "all") {
553
- return true;
554
- }
555
- return b1.some((b12) => b2.indexOf(b12) > -1);
556
- };
557
- const createStateProcessor = (platform, callback) => {
558
- let nodeQueue = [];
559
- let optionsQueue = [];
560
- let timeout;
561
- const flush = () => {
562
- const processHistory = /* @__PURE__ */ new Map();
563
- const sortedQueue = sortQueue(nodeQueue.map((node, i) => [node, optionsQueue[i]]));
564
- const processNode = (node, options) => {
565
- var _a;
566
- const history = processHistory.get(node) || {};
567
- const processContext = options.context && !history.context;
568
- const processProperties = options.properties && !history.properties;
569
- const processLayout = options.layout && !history.layout;
570
- processHistory.set(node, {
571
- context: history.context || processContext,
572
- properties: history.properties || processProperties,
573
- layout: history.layout || processLayout
574
- });
575
- if (processProperties) {
576
- node.attributes.properties = {};
577
- }
578
- if (processLayout) {
579
- node.attributes.layout = {};
580
- }
581
- if (processContext) {
582
- node.attributes.context = mergeDeep({}, (_a = node.parent) == null ? void 0 : _a.attributes.context);
583
- }
584
- const propertyResolvers = [];
585
- const layoutResolvers = [];
586
- const contextResolvers = [];
587
- node.changesets.forEach((changeset) => {
588
- const [change, options2] = changeset;
589
- if (matchesBreakpoint(options2.breakpoints, platform.breakpoints)) {
590
- if (processProperties) {
591
- if (typeof change.properties === "function") {
592
- propertyResolvers.push(change.properties);
593
- } else {
594
- mergeDeep(node.attributes.properties, change.properties);
595
- }
596
- }
597
- if (processLayout) {
598
- if (typeof change.layout === "function") {
599
- layoutResolvers.push(change.layout);
600
- } else {
601
- mergeDeep(node.attributes.layout, change.layout);
602
- }
603
- }
604
- if (processContext) {
605
- if (typeof change.context === "function") {
606
- contextResolvers.push(change.context);
607
- } else {
608
- mergeDeep(node.attributes.context, change.context);
609
- }
610
- }
611
- }
612
- });
613
- propertyResolvers.forEach((resolver) => {
614
- mergeDeep(node.attributes.properties, resolver(node.attributes.properties));
615
- });
616
- layoutResolvers.forEach((resolver) => {
617
- mergeDeep(node.attributes.layout, resolver(node.attributes.layout));
618
- });
619
- contextResolvers.forEach((resolver) => {
620
- mergeDeep(node.attributes.context, resolver(node.attributes.context));
621
- });
622
- if (processContext || options.recursive) {
623
- const branch = platform.getBranch(node);
624
- const childOptions = options.recursive ? options : {
625
- context: !!processContext
339
+ const X = (n) => {
340
+ let t = n, e = 0;
341
+ for (; t.parent; )
342
+ e = e + 1, t = t.parent;
343
+ return e;
344
+ }, Z = (n) => n.map(([e, s]) => [X(e), e, s]).sort(([e], [s]) => e - s).map(([, e, s]) => [e, s]), w = (n) => n && typeof n == "object" && !Array.isArray(n), b = (n, ...t) => {
345
+ if (!t.length)
346
+ return n;
347
+ const e = t.shift();
348
+ if (w(n) && w(e))
349
+ for (const s in e)
350
+ w(e[s]) ? (n[s] || Object.assign(n, { [s]: {} }), b(n[s], e[s])) : Object.assign(n, { [s]: e[s] });
351
+ return b(n, ...t);
352
+ }, W = (n, t) => !n || n === "all" ? !0 : n.some((e) => t.indexOf(e) > -1), tt = (n, t) => {
353
+ let e = [], s = [], r;
354
+ const c = () => {
355
+ process.env.NODE_ENV !== "production" && console.time("state-processor.flush");
356
+ const a = /* @__PURE__ */ new Map(), u = Z(e.map((i, p) => [i, s[p]])), h = (i, p) => {
357
+ var T;
358
+ const l = a.get(i) || {}, d = p.context && !l.context, v = p.properties && !l.properties, g = p.layout && !l.layout;
359
+ a.set(i, {
360
+ context: l.context || d,
361
+ properties: l.properties || v,
362
+ layout: l.layout || g
363
+ }), v && (i.attributes.properties = {}), g && (i.attributes.layout = {}), d && (i.attributes.context = b({}, (T = i.parent) == null ? void 0 : T.attributes.context));
364
+ const R = [], A = [], D = [];
365
+ if (i.changesets.forEach((m) => {
366
+ const [f, y] = m;
367
+ W(y.breakpoints, n.breakpoints) && (v && (typeof f.properties == "function" ? R.push(f.properties) : b(i.attributes.properties, f.properties)), g && (typeof f.layout == "function" ? A.push(f.layout) : b(i.attributes.layout, f.layout)), d && (typeof f.context == "function" ? D.push(f.context) : b(i.attributes.context, f.context)));
368
+ }), R.forEach((m) => {
369
+ b(i.attributes.properties, m(i.attributes.properties));
370
+ }), A.forEach((m) => {
371
+ b(i.attributes.layout, m(i.attributes.layout));
372
+ }), D.forEach((m) => {
373
+ b(i.attributes.context, m(i.attributes.context));
374
+ }), d || p.recursive) {
375
+ const m = n.getBranch(i), f = p.recursive ? p : {
376
+ context: !!d
626
377
  };
627
- node.getChildren(branch).forEach((child) => {
628
- processNode(child, childOptions);
378
+ i.getChildren(m).forEach((y) => {
379
+ h(y, f);
629
380
  });
630
381
  }
631
382
  };
632
- sortedQueue.forEach(([node, options]) => {
633
- processNode(node, options);
634
- });
635
- nodeQueue = [];
636
- optionsQueue = [];
637
- callback(processHistory);
383
+ process.env.NODE_ENV !== "production" && console.timeEnd("state-processor.flush"), u.forEach(([i, p]) => {
384
+ h(i, p);
385
+ }), e = [], s = [], t(a);
386
+ }, o = () => {
387
+ clearTimeout(r), r = setTimeout(c, 0);
638
388
  };
639
- const schedule = () => {
640
- clearTimeout(timeout);
641
- timeout = setTimeout(flush, 0);
642
- };
643
- return (node, options) => {
644
- const index = nodeQueue.indexOf(node);
645
- if (index > -1) {
646
- const summary = optionsQueue[index];
647
- if (options.context) {
648
- summary.context = true;
649
- }
650
- if (options.properties) {
651
- summary.properties = true;
652
- }
653
- if (options.layout) {
654
- summary.layout = true;
655
- }
656
- if (options.recursive) {
657
- summary.recursive = true;
658
- }
659
- return schedule();
389
+ return (a, u) => {
390
+ const h = e.indexOf(a);
391
+ if (h > -1) {
392
+ const i = s[h];
393
+ return u.context && (i.context = !0), u.properties && (i.properties = !0), u.layout && (i.layout = !0), u.recursive && (i.recursive = !0), o();
660
394
  }
661
- nodeQueue.push(node);
662
- optionsQueue.push(options);
663
- return schedule();
395
+ return e.push(a), s.push(u), o();
664
396
  };
665
397
  };
666
- class ComponentPlatform {
667
- constructor(widget, providers = {}) {
668
- this.providers = providers;
669
- this.breakpoints = [];
670
- this.actionsState = { handlers: [], watchers: [] };
671
- this.switches = {};
672
- this.changesets = [];
673
- this.subscriptions = [];
674
- this.customComponentHandler = new CustomComponentHandler();
675
- this.events = widget.events.createChild(this);
676
- const root = new ComponentNode(this.events, "root");
677
- root.name = `root-${widget.name}`;
678
- this.nodes = new ComponentNodeCollection(root, this.switches, this.events);
679
- const processNode = this.processNode = createStateProcessor(this, (report) => {
680
- const nodes = Array.from(report.keys());
681
- nodes.forEach((node) => {
682
- const options = report.get(node);
683
- if (node.parent && node.parent.type === "root") {
684
- this.events.dispatch("components:root-children-changed", { node });
685
- }
686
- if (options == null ? void 0 : options.context) {
687
- this.events.dispatch("components:context-changed", { node });
688
- }
689
- if (options == null ? void 0 : options.properties) {
690
- this.events.dispatch("components:properties-changed", { node });
691
- }
692
- if (options == null ? void 0 : options.layout) {
693
- this.events.dispatch("components:layout-changed", { node });
694
- }
695
- });
696
- this.events.dispatch("components:component-model-initialized", {}, { bubbles: true });
398
+ class et {
399
+ constructor(t, e = {}) {
400
+ this.providers = e, this.breakpoints = [], this.actionsState = { handlers: [], watchers: [] }, this.switches = {}, this.changesets = [], this.subscriptions = [], this.customComponentHandler = new J(), this.events = t.events.createChild(this);
401
+ const s = new H(this.events, "root");
402
+ s.name = `root-${t.name}`, this.nodes = new G(s, this.switches, this.events);
403
+ const r = this.processNode = tt(this, (c) => {
404
+ const o = Array.from(c.keys());
405
+ process.env.NODE_ENV !== "production" && console.info(`STATE PROCESSOR: ${o.length} node(s) processed:
406
+ ${o.map((a) => `${a.name || "<no name>"} (${a.id})
407
+ `)}`), o.forEach((a) => {
408
+ const u = c.get(a);
409
+ a.parent && a.parent.type === "root" && this.events.dispatch("components:root-children-changed", { node: a }), u != null && u.context && this.events.dispatch("components:context-changed", { node: a }), u != null && u.properties && this.events.dispatch("components:properties-changed", { node: a }), u != null && u.layout && this.events.dispatch("components:layout-changed", { node: a });
410
+ }), this.events.dispatch("components:component-model-initialized", {}, { bubbles: !0 });
697
411
  });
698
- Promise.all(Object.keys(providers).map((key) => {
699
- const provider = providers[key];
700
- return provider.load(this);
701
- }));
702
- this.subscriptions.push(this.events.subscribe("components:node-appended", (event, data) => {
703
- const { node } = data;
704
- this.changesets.forEach((record) => {
705
- const { changeset, target, removes } = record;
706
- const [change, options] = changeset;
707
- if (target.match(data.node)) {
708
- if (change.properties) {
709
- removes.push(node.writeProperties(change.properties, options));
710
- }
711
- if (change.context) {
712
- removes.push(node.writeContext(change.context, options));
713
- }
714
- if (change.layout) {
715
- removes.push(node.writeLayout(change.layout, options));
716
- }
717
- }
412
+ Promise.all(Object.keys(e).map((c) => e[c].load(this))), this.subscriptions.push(this.events.subscribe("components:node-appended", (c, o) => {
413
+ const { node: a } = o;
414
+ this.changesets.forEach((u) => {
415
+ const { changeset: h, target: i, removes: p } = u, [l, d] = h;
416
+ i.match(o.node) && (l.properties && p.push(a.writeProperties(l.properties, d)), l.context && p.push(a.writeContext(l.context, d)), l.layout && p.push(a.writeLayout(l.layout, d)));
718
417
  });
719
- }));
720
- this.subscriptions.push(this.events.subscribe("components:node-appended", (event, data) => {
721
- processNode(data.node, { properties: true, context: true });
722
- }));
723
- this.subscriptions.push(this.events.subscribe("components:set-properties", (event, data) => {
724
- processNode(data.node, { properties: true });
725
- }));
726
- this.subscriptions.push(this.events.subscribe("components:set-context", (event, data) => {
727
- processNode(data.node, { properties: true, context: true });
728
- }));
729
- this.subscriptions.push(this.events.subscribe("components:set-indent", (event, data) => {
730
- processNode(data.node, { layout: true });
731
- }));
732
- this.subscriptions.push(this.events.subscribe("components:set-layout", (event, data) => {
733
- processNode(data.node, { layout: true });
734
- }));
735
- this.subscriptions.push(this.events.subscribe("components:node-switched", (event, { node, branch }) => {
736
- processNode(node, {
737
- layout: true,
738
- recursive: true,
739
- properties: true,
740
- context: true
418
+ })), this.subscriptions.push(this.events.subscribe("components:node-appended", (c, o) => {
419
+ r(o.node, { properties: !0, context: !0 });
420
+ })), this.subscriptions.push(this.events.subscribe("components:set-properties", (c, o) => {
421
+ r(o.node, { properties: !0 });
422
+ })), this.subscriptions.push(this.events.subscribe("components:set-context", (c, o) => {
423
+ r(o.node, { properties: !0, context: !0 });
424
+ })), this.subscriptions.push(this.events.subscribe("components:set-indent", (c, o) => {
425
+ r(o.node, { layout: !0 });
426
+ })), this.subscriptions.push(this.events.subscribe("components:set-layout", (c, o) => {
427
+ r(o.node, { layout: !0 });
428
+ })), this.subscriptions.push(this.events.subscribe("components:node-switched", (c, { node: o, branch: a }) => {
429
+ r(o, {
430
+ layout: !0,
431
+ recursive: !0,
432
+ properties: !0,
433
+ context: !0
741
434
  });
435
+ })), this.subscriptions.push(this.events.subscribe("components:node-removed", (c, { parentNode: o }) => {
436
+ r(o, { properties: !0 });
437
+ })), this.events.parent && this.events.parent.dispatch("components:platform-created", { platform: this });
438
+ }
439
+ static getInstance(t) {
440
+ return t.getAsync("components");
441
+ }
442
+ addBreakpoint(t) {
443
+ this.breakpoints.indexOf(t) === -1 && (this.breakpoints.push(t), this.processNode(this.nodes.root, {
444
+ context: !0,
445
+ properties: !0,
446
+ layout: !0,
447
+ recursive: !0
742
448
  }));
743
- this.subscriptions.push(this.events.subscribe("components:node-removed", (event, { parentNode }) => {
744
- processNode(parentNode, { properties: true });
449
+ }
450
+ removeBreakpoint(t) {
451
+ const e = this.breakpoints.indexOf(t);
452
+ e > -1 && (this.breakpoints.splice(e, 1), this.processNode(this.nodes.root, {
453
+ context: !0,
454
+ properties: !0,
455
+ layout: !0,
456
+ recursive: !0
745
457
  }));
746
- if (this.events.parent) {
747
- this.events.parent.dispatch("components:platform-created", { platform: this });
748
- }
749
458
  }
750
- static getInstance(container) {
751
- return container.getAsync("components");
752
- }
753
- addBreakpoint(name) {
754
- if (this.breakpoints.indexOf(name) === -1) {
755
- this.breakpoints.push(name);
756
- this.processNode(this.nodes.root, {
757
- context: true,
758
- properties: true,
759
- layout: true,
760
- recursive: true
761
- });
762
- }
459
+ setSwitch(t, e) {
460
+ this.switches[t.id] = e, this.events.dispatch("components:node-switched", { node: t, branch: e });
763
461
  }
764
- removeBreakpoint(name) {
765
- const indexToRemove = this.breakpoints.indexOf(name);
766
- if (indexToRemove > -1) {
767
- this.breakpoints.splice(indexToRemove, 1);
768
- this.processNode(this.nodes.root, {
769
- context: true,
770
- properties: true,
771
- layout: true,
772
- recursive: true
773
- });
774
- }
462
+ getBranch(t) {
463
+ return this.switches[t.id];
775
464
  }
776
- setSwitch(node, branch) {
777
- this.switches[node.id] = branch;
778
- this.events.dispatch("components:node-switched", { node, branch });
465
+ createNode(t, e = {}) {
466
+ const s = new H(this.events, t);
467
+ return e.detached && this.nodes.detached.push(s), s;
779
468
  }
780
- getBranch(node) {
781
- return this.switches[node.id];
469
+ components() {
470
+ return new N(this);
782
471
  }
783
- createNode(type, options = {}) {
784
- const node = new ComponentNode(this.events, type);
785
- if (options.detached) {
786
- this.nodes.detached.push(node);
787
- }
788
- return node;
472
+ actions(t, e) {
473
+ return new k(this, t, e);
789
474
  }
790
- components() {
791
- return new ComponentQuery(this);
792
- }
793
- actions(target, ns) {
794
- return new ActionsController(this, target, ns);
795
- }
796
- write(data) {
797
- const { provider: providerName, target, attributes, options = {}, removable } = data;
798
- const key = data.key || uuid();
799
- const changeset = [attributes, options];
800
- const record = { changeset, target, removes: [] };
801
- if (providerName) {
802
- const provider = this.providers[providerName];
803
- provider.write(key, target, attributes, options);
804
- record.removes.push(() => {
805
- provider.remove(key);
475
+ write(t) {
476
+ const { provider: e, target: s, attributes: r, options: c = {}, removable: o } = t, a = t.key || E(), h = { changeset: [r, c], target: s, removes: [] };
477
+ if (e) {
478
+ const i = this.providers[e];
479
+ i.write(a, s, r, c), h.removes.push(() => {
480
+ i.remove(a);
806
481
  });
807
482
  }
808
- this.changesets.push(record);
809
- this.nodes.all.forEach((node) => {
810
- if (target.match(node)) {
811
- let remove = () => {
483
+ return this.changesets.push(h), this.nodes.all.forEach((i) => {
484
+ if (s.match(i)) {
485
+ let p = () => {
812
486
  };
813
- if (attributes.properties) {
814
- remove = node.writeProperties(attributes.properties, options, removable);
815
- }
816
- if (attributes.context) {
817
- remove = node.writeContext(attributes.context, options, removable);
818
- }
819
- if (attributes.layout) {
820
- remove = node.writeContext(attributes.layout, options, removable);
821
- }
822
- record.removes.push(remove);
487
+ r.properties && (p = i.writeProperties(r.properties, c, o)), r.context && (p = i.writeContext(r.context, c, o)), r.layout && (p = i.writeContext(r.layout, c, o)), h.removes.push(p);
823
488
  }
824
- });
825
- return () => {
826
- if (removable) {
827
- record.removes.forEach((remove) => remove());
828
- const indexToRemove = this.changesets.indexOf(record);
829
- if (indexToRemove > -1) {
830
- this.changesets.splice(indexToRemove, 1);
831
- }
489
+ }), () => {
490
+ if (o) {
491
+ h.removes.forEach((p) => p());
492
+ const i = this.changesets.indexOf(h);
493
+ i > -1 && this.changesets.splice(i, 1);
832
494
  }
833
495
  };
834
496
  }
835
- addComponentHandler(definitionType, fn) {
836
- this.customComponentHandler.add(definitionType, fn);
497
+ addComponentHandler(t, e) {
498
+ this.customComponentHandler.add(t, e);
837
499
  }
838
- getComponentHandler(definitionType) {
839
- return this.customComponentHandler.get(definitionType);
500
+ getComponentHandler(t) {
501
+ return this.customComponentHandler.get(t);
840
502
  }
841
503
  dispose() {
842
- this.subscriptions.forEach((sub) => sub());
504
+ this.subscriptions.forEach((t) => t());
843
505
  }
844
506
  }
845
- const normalizeReference = (reference) => {
846
- if (Array.isArray(reference)) {
847
- const [definitionId, ...overrides] = reference;
507
+ const st = (n) => {
508
+ if (Array.isArray(n)) {
509
+ const [t, ...e] = n;
848
510
  return {
849
- definitionId,
850
- overrides
511
+ definitionId: t,
512
+ overrides: e
851
513
  };
852
514
  }
853
515
  return {
854
- definitionId: reference,
516
+ definitionId: n,
855
517
  overrides: []
856
518
  };
857
- };
858
- const createChildren = (platform, node, references, definitions, views, branch) => {
859
- references.forEach((ref) => {
860
- const childRef = normalizeReference(ref);
861
- const childDef = definitions[childRef.definitionId];
862
- if (childRef.definitionId === "view") {
863
- const viewNode = platform.createNode("view");
864
- viewNode.name = "view";
865
- Object.keys(views).forEach((key) => {
866
- const viewDef = views[key];
867
- createChildren(platform, viewNode, [viewDef.entry], definitions, views, key);
519
+ }, C = (n, t, e, s, r, c) => {
520
+ e.forEach((o) => {
521
+ const a = st(o), u = s[a.definitionId];
522
+ if (a.definitionId === "view") {
523
+ const h = n.createNode("view");
524
+ h.name = "view", Object.keys(r).forEach((i) => {
525
+ const p = r[i];
526
+ C(n, h, [p.entry], s, r, i);
527
+ }), t.appendChild(h), a.overrides.forEach((i) => {
528
+ i.properties && h.writeProperties(i.properties, {
529
+ breakpoints: i.breakpoints
530
+ }), i.context && h.writeContext(i.context, { breakpoints: i.breakpoints }), i.layout && h.writeLayout(i.layout, { breakpoints: i.breakpoints });
868
531
  });
869
- node.appendChild(viewNode);
870
- childRef.overrides.forEach((override) => {
871
- if (override.properties) {
872
- viewNode.writeProperties(override.properties, {
873
- breakpoints: override.breakpoints
874
- });
875
- }
876
- if (override.context) {
877
- viewNode.writeContext(override.context, { breakpoints: override.breakpoints });
878
- }
879
- if (override.layout) {
880
- viewNode.writeLayout(override.layout, { breakpoints: override.breakpoints });
881
- }
532
+ } else if (n.getComponentHandler(u.type)) {
533
+ const h = n.getComponentHandler(u.type);
534
+ h && h(a, {
535
+ platform: n,
536
+ node: t,
537
+ references: e,
538
+ definitions: s,
539
+ views: r,
540
+ branch: c
882
541
  });
883
- } else if (platform.getComponentHandler(childDef.type)) {
884
- const handle = platform.getComponentHandler(childDef.type);
885
- if (handle) {
886
- handle(childRef, {
887
- platform,
888
- node,
889
- references,
890
- definitions,
891
- views,
892
- branch
893
- });
894
- }
895
542
  } else {
896
- const childDef2 = definitions[childRef.definitionId];
897
- const childNode = platform.createNode(childDef2.type);
898
- childNode.name = childRef.definitionId;
899
- childNode.tags = childDef2.tags || [];
900
- if (childDef2.properties) {
901
- childNode.writeProperties(childDef2.properties);
902
- }
903
- if (childDef2.context) {
904
- childNode.writeContext(childDef2.context);
905
- }
906
- if (childDef2.layout) {
907
- childNode.writeLayout(childDef2.layout);
908
- }
909
- node.appendChild(childNode, branch);
910
- childRef.overrides.forEach((override) => {
911
- const options = { breakpoints: override.breakpoints };
912
- if (override.properties) {
913
- childNode.writeProperties(override.properties, options);
914
- }
915
- if (override.context) {
916
- childNode.writeContext(override.context, options);
917
- }
918
- if (override.layout) {
919
- childNode.writeLayout(override.layout, options);
920
- }
921
- });
922
- if (childDef2.children) {
923
- createChildren(platform, childNode, childDef2.children, definitions, views);
543
+ const h = s[a.definitionId];
544
+ if (process.env.NODE_ENV !== "production" && !h) {
545
+ O.error(`No definition found for component type '${a.definitionId}'.`);
546
+ return;
924
547
  }
548
+ const i = n.createNode(h.type);
549
+ i.name = a.definitionId, i.tags = h.tags || [], h.properties && i.writeProperties(h.properties), h.context && i.writeContext(h.context), h.layout && i.writeLayout(h.layout), t.appendChild(i, c), a.overrides.forEach((p) => {
550
+ const l = { breakpoints: p.breakpoints };
551
+ p.properties && i.writeProperties(p.properties, l), p.context && i.writeContext(p.context, l), p.layout && i.writeLayout(p.layout, l);
552
+ }), h.children && C(n, i, h.children, s, r);
925
553
  }
926
554
  });
927
- };
928
- const createComponentModel = (platform, settings) => {
929
- const { entry, components, breakpoints, views } = settings;
930
- const subscriptions = [];
931
- Object.keys(breakpoints).forEach((name) => {
932
- const query = breakpoints[name];
933
- const list = window.matchMedia(query);
934
- if (list.matches) {
935
- platform.breakpoints.push(name);
936
- }
937
- const listener = (event) => {
938
- if (event.matches) {
939
- platform.addBreakpoint(name);
940
- } else {
941
- platform.removeBreakpoint(name);
942
- }
555
+ }, at = (n, t) => {
556
+ const { entry: e, components: s, breakpoints: r, views: c } = t, o = [];
557
+ return Object.keys(r).forEach((a) => {
558
+ const u = r[a], h = window.matchMedia(u);
559
+ h.matches && n.breakpoints.push(a);
560
+ const i = (p) => {
561
+ p.matches ? n.addBreakpoint(a) : n.removeBreakpoint(a);
943
562
  };
944
- list.addListener(listener);
945
- subscriptions.push(() => list.removeListener(listener));
946
- });
947
- createChildren(platform, platform.nodes.root, [entry], components, views);
948
- return () => subscriptions.forEach((sub) => {
949
- sub();
563
+ h.addListener(i), o.push(() => h.removeListener(i));
564
+ }), C(n, n.nodes.root, [e], s, c), () => o.forEach((a) => {
565
+ a();
950
566
  });
951
- };
952
- const asDescriptor = (node, branch) => {
953
- return {
954
- id: node.id,
955
- type: node.type,
956
- name: node.name,
957
- branch: branch || "default"
567
+ }, pt = (n, t) => ({
568
+ id: n.id,
569
+ type: n.type,
570
+ name: n.name,
571
+ branch: t || "default"
572
+ }), ut = (n, t, e, s = E(), r = {}) => n.getAsync("components").then((c) => {
573
+ let o;
574
+ if (typeof t == "string") {
575
+ const h = new N(c);
576
+ h.ofType(t), o = h;
577
+ } else
578
+ o = t;
579
+ const a = {}, u = (h) => {
580
+ const i = a[h.id];
581
+ return i ? Promise.resolve(i.controller) : et.getInstance(n).then((p) => new $(p, h, s));
958
582
  };
959
- };
960
- const extendComponent = (container, typeOrQuery, handler, ns = uuid(), options = {}) => {
961
- return container.getAsync("components").then((components) => {
962
- let target;
963
- if (typeof typeOrQuery === "string") {
964
- const collection = new ComponentQuery(components);
965
- collection.ofType(typeOrQuery);
966
- target = collection;
967
- } else {
968
- target = typeOrQuery;
969
- }
970
- const managedInstances = {};
971
- const getOrCreateController = (node) => {
972
- const existing = managedInstances[node.id];
973
- if (existing) {
974
- return Promise.resolve(existing.controller);
975
- }
976
- return ComponentPlatform.getInstance(container).then((platform) => {
977
- return new ComponentNodeController(platform, node, ns);
583
+ c.events.subscribe("components:node-enter", (h, { node: i }) => {
584
+ o.match(i) && u(i).then((p) => {
585
+ Promise.resolve(e(p)).then((l) => {
586
+ a[i.id] = {
587
+ dispose: l,
588
+ controller: p
589
+ };
978
590
  });
979
- };
980
- components.events.subscribe("components:node-enter", (event, { node }) => {
981
- if (target.match(node)) {
982
- getOrCreateController(node).then((controller) => {
983
- Promise.resolve(handler(controller)).then((dispose) => {
984
- managedInstances[node.id] = {
985
- dispose,
986
- controller
987
- };
988
- });
989
- });
990
- }
991
- });
992
- components.events.subscribe("components:node-exit", (event, { node }) => {
993
- const instance = managedInstances[node.id];
994
- if (instance) {
995
- instance.dispose && instance.dispose();
996
- if (!options.reuseController) {
997
- instance.controller.dispose();
998
- delete managedInstances[node.id];
999
- }
1000
- }
1001
591
  });
592
+ }), c.events.subscribe("components:node-exit", (h, { node: i }) => {
593
+ const p = a[i.id];
594
+ p && (p.dispose && p.dispose(), r.reuseController || (p.controller.dispose(), delete a[i.id]));
1002
595
  });
1003
- };
1004
- class ComponentResolver {
1005
- constructor(container) {
1006
- this.aliases = /* @__PURE__ */ new Map();
1007
- this.components = /* @__PURE__ */ new Map();
1008
- this.logger = new Logger();
1009
- const { events } = container.get("$widget");
1010
- this.events = events;
1011
- }
1012
- getComponent(key) {
1013
- const alias = this.aliases.get(key);
1014
- const component = this.components.get(alias || key) || null;
1015
- return component;
1016
- }
1017
- registerComponent(key, component) {
1018
- this.components.set(key, component);
1019
- this.events.dispatch("component-resolver:resolve", key);
1020
- return () => {
1021
- this.components.delete(key);
596
+ });
597
+ class lt {
598
+ constructor(t) {
599
+ this.aliases = /* @__PURE__ */ new Map(), this.components = /* @__PURE__ */ new Map(), this.logger = new O();
600
+ const { events: e } = t.get("$widget");
601
+ this.events = e;
602
+ }
603
+ getComponent(t) {
604
+ const e = this.aliases.get(t), s = this.components.get(e || t) || null;
605
+ return process.env.NODE_ENV !== "production" && (s || this.logger.warn(e || t, `Unable to resolve component: "${e || t}". You most likely forgot to register the required plugin for: ${e || t}.`)), s;
606
+ }
607
+ registerComponent(t, e) {
608
+ return this.components.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
609
+ this.components.delete(t);
1022
610
  };
1023
611
  }
1024
- registerResolver(key, fn) {
1025
- return this.events.subscribe("component-resolver:resolve", (e, data) => {
1026
- if (data === key) {
1027
- const component = this.getComponent(key);
1028
- fn(component);
612
+ registerResolver(t, e) {
613
+ return this.events.subscribe("component-resolver:resolve", (s, r) => {
614
+ if (r === t) {
615
+ const c = this.getComponent(t);
616
+ e(c);
1029
617
  }
1030
618
  });
1031
619
  }
1032
- registerAlias(alias, key) {
1033
- this.aliases.set(alias, key);
1034
- this.events.dispatch("component-resolver:resolve", alias);
1035
- return () => {
1036
- this.aliases.delete(alias);
620
+ registerAlias(t, e) {
621
+ return this.aliases.set(t, e), this.events.dispatch("component-resolver:resolve", t), () => {
622
+ this.aliases.delete(t);
1037
623
  };
1038
624
  }
1039
625
  }
1040
- var WidgetRenderState = /* @__PURE__ */ ((WidgetRenderState2) => {
1041
- WidgetRenderState2["open"] = "open";
1042
- WidgetRenderState2["closed"] = "closed";
1043
- WidgetRenderState2["hidden"] = "hidden";
1044
- return WidgetRenderState2;
1045
- })(WidgetRenderState || {});
1046
- export { ActionResolver, ActionsController, ComponentNode, ComponentNodeController, ComponentPlatform, ComponentQuery, ComponentResolver, WidgetRenderState, asDescriptor, componentConfigurationApi, createChildren, createComponentModel, createEventSubscriber, extendComponent, findComponent, findVisibleComponents, traverseComponents };
626
+ var nt = /* @__PURE__ */ ((n) => (n.open = "open", n.closed = "closed", n.hidden = "hidden", n))(nt || {});
627
+ export {
628
+ ct as ActionResolver,
629
+ k as ActionsController,
630
+ H as ComponentNode,
631
+ $ as ComponentNodeController,
632
+ et as ComponentPlatform,
633
+ N as ComponentQuery,
634
+ lt as ComponentResolver,
635
+ nt as WidgetRenderState,
636
+ pt as asDescriptor,
637
+ ht as componentConfigurationApi,
638
+ C as createChildren,
639
+ at as createComponentModel,
640
+ K as createEventSubscriber,
641
+ ut as extendComponent,
642
+ F as findComponent,
643
+ x as findVisibleComponents,
644
+ P as traverseComponents
645
+ };
1047
646
  //# sourceMappingURL=index.js.map