@wirestate/lit 0.7.0-experimental.1 → 0.7.0-experimental.3

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 (123) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/README.md +49 -31
  3. package/cjs/development/index.js +420 -362
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/production/index.js +1 -1
  6. package/cjs/production/index.js.map +1 -1
  7. package/esm/development/commands/on-command-controller.js +19 -22
  8. package/esm/development/commands/on-command-controller.js.map +1 -1
  9. package/esm/development/commands/on-command.js +4 -9
  10. package/esm/development/commands/on-command.js.map +1 -1
  11. package/esm/development/commands/use-on-command.js +4 -3
  12. package/esm/development/commands/use-on-command.js.map +1 -1
  13. package/esm/development/consumption/injection.js +14 -13
  14. package/esm/development/consumption/injection.js.map +1 -1
  15. package/esm/development/consumption/use-container.js +40 -0
  16. package/esm/development/consumption/use-container.js.map +1 -0
  17. package/esm/development/consumption/use-injection.js +12 -10
  18. package/esm/development/consumption/use-injection.js.map +1 -1
  19. package/esm/development/consumption/use-scope.js +44 -0
  20. package/esm/development/consumption/use-scope.js.map +1 -0
  21. package/esm/development/context/container-context.js +17 -0
  22. package/esm/development/context/container-context.js.map +1 -0
  23. package/esm/development/error/error-code.js +1 -1
  24. package/esm/development/error/error-code.js.map +1 -1
  25. package/esm/development/events/on-event-controller.js +22 -26
  26. package/esm/development/events/on-event-controller.js.map +1 -1
  27. package/esm/development/events/on-event.js +5 -11
  28. package/esm/development/events/on-event.js.map +1 -1
  29. package/esm/development/events/use-on-events.js +5 -5
  30. package/esm/development/events/use-on-events.js.map +1 -1
  31. package/esm/development/index.js +9 -7
  32. package/esm/development/index.js.map +1 -1
  33. package/esm/development/provision/container-provide.js +68 -0
  34. package/esm/development/provision/container-provide.js.map +1 -0
  35. package/esm/development/provision/container-provider.js +68 -0
  36. package/esm/development/provision/container-provider.js.map +1 -0
  37. package/esm/development/provision/sub-container-provide.js +56 -0
  38. package/esm/development/provision/sub-container-provide.js.map +1 -0
  39. package/esm/development/provision/sub-container-provider.js +90 -0
  40. package/esm/development/provision/sub-container-provider.js.map +1 -0
  41. package/esm/development/provision/use-container-provision.js +44 -0
  42. package/esm/development/provision/use-container-provision.js.map +1 -0
  43. package/esm/development/provision/use-sub-container-provider.js +34 -0
  44. package/esm/development/provision/use-sub-container-provider.js.map +1 -0
  45. package/esm/development/queries/on-query-controller.js +19 -22
  46. package/esm/development/queries/on-query-controller.js.map +1 -1
  47. package/esm/development/queries/on-query.js +4 -9
  48. package/esm/development/queries/on-query.js.map +1 -1
  49. package/esm/development/queries/use-on-query.js +4 -3
  50. package/esm/development/queries/use-on-query.js.map +1 -1
  51. package/esm/production/commands/on-command-controller.js +1 -1
  52. package/esm/production/commands/on-command-controller.js.map +1 -1
  53. package/esm/production/commands/on-command.js +1 -1
  54. package/esm/production/commands/on-command.js.map +1 -1
  55. package/esm/production/commands/use-on-command.js +1 -1
  56. package/esm/production/commands/use-on-command.js.map +1 -1
  57. package/esm/production/consumption/injection.js +1 -1
  58. package/esm/production/consumption/injection.js.map +1 -1
  59. package/esm/production/consumption/use-container.js +1 -0
  60. package/esm/production/consumption/use-container.js.map +1 -0
  61. package/esm/production/consumption/use-injection.js +1 -1
  62. package/esm/production/consumption/use-injection.js.map +1 -1
  63. package/esm/production/consumption/use-scope.js +1 -0
  64. package/esm/production/consumption/use-scope.js.map +1 -0
  65. package/esm/production/context/container-context.js +1 -0
  66. package/esm/production/context/container-context.js.map +1 -0
  67. package/esm/production/error/error-code.js +1 -1
  68. package/esm/production/error/error-code.js.map +1 -1
  69. package/esm/production/events/on-event-controller.js +1 -1
  70. package/esm/production/events/on-event-controller.js.map +1 -1
  71. package/esm/production/events/on-event.js +1 -1
  72. package/esm/production/events/on-event.js.map +1 -1
  73. package/esm/production/events/use-on-events.js +1 -1
  74. package/esm/production/events/use-on-events.js.map +1 -1
  75. package/esm/production/index.js +1 -1
  76. package/esm/production/provision/container-provide.js +1 -0
  77. package/esm/production/provision/container-provide.js.map +1 -0
  78. package/esm/production/provision/container-provider.js +1 -0
  79. package/esm/production/provision/container-provider.js.map +1 -0
  80. package/esm/production/provision/sub-container-provide.js +1 -0
  81. package/esm/production/provision/sub-container-provide.js.map +1 -0
  82. package/esm/production/provision/sub-container-provider.js +1 -0
  83. package/esm/production/provision/sub-container-provider.js.map +1 -0
  84. package/esm/production/provision/use-container-provision.js +1 -0
  85. package/esm/production/provision/use-container-provision.js.map +1 -0
  86. package/esm/production/provision/use-sub-container-provider.js +1 -0
  87. package/esm/production/provision/use-sub-container-provider.js.map +1 -0
  88. package/esm/production/queries/on-query-controller.js +1 -1
  89. package/esm/production/queries/on-query-controller.js.map +1 -1
  90. package/esm/production/queries/on-query.js +1 -1
  91. package/esm/production/queries/on-query.js.map +1 -1
  92. package/esm/production/queries/use-on-query.js +1 -1
  93. package/esm/production/queries/use-on-query.js.map +1 -1
  94. package/index.d.ts +271 -176
  95. package/package.json +2 -2
  96. package/esm/development/context/ioc-context.js +0 -17
  97. package/esm/development/context/ioc-context.js.map +0 -1
  98. package/esm/development/provision/injectables-provide.js +0 -47
  99. package/esm/development/provision/injectables-provide.js.map +0 -1
  100. package/esm/development/provision/injectables-provider-controller.js +0 -123
  101. package/esm/development/provision/injectables-provider-controller.js.map +0 -1
  102. package/esm/development/provision/ioc-provide.js +0 -58
  103. package/esm/development/provision/ioc-provide.js.map +0 -1
  104. package/esm/development/provision/ioc-provider-controller.js +0 -75
  105. package/esm/development/provision/ioc-provider-controller.js.map +0 -1
  106. package/esm/development/provision/use-injectables-provider.js +0 -27
  107. package/esm/development/provision/use-injectables-provider.js.map +0 -1
  108. package/esm/development/provision/use-ioc-provision.js +0 -27
  109. package/esm/development/provision/use-ioc-provision.js.map +0 -1
  110. package/esm/production/context/ioc-context.js +0 -1
  111. package/esm/production/context/ioc-context.js.map +0 -1
  112. package/esm/production/provision/injectables-provide.js +0 -1
  113. package/esm/production/provision/injectables-provide.js.map +0 -1
  114. package/esm/production/provision/injectables-provider-controller.js +0 -1
  115. package/esm/production/provision/injectables-provider-controller.js.map +0 -1
  116. package/esm/production/provision/ioc-provide.js +0 -1
  117. package/esm/production/provision/ioc-provide.js.map +0 -1
  118. package/esm/production/provision/ioc-provider-controller.js +0 -1
  119. package/esm/production/provision/ioc-provider-controller.js.map +0 -1
  120. package/esm/production/provision/use-injectables-provider.js +0 -1
  121. package/esm/production/provision/use-injectables-provider.js.map +0 -1
  122. package/esm/production/provision/use-ioc-provision.js +0 -1
  123. package/esm/production/provision/use-ioc-provision.js.map +0 -1
@@ -2,20 +2,19 @@
2
2
 
3
3
  var context = require('@lit/context');
4
4
  var core = require('@wirestate/core');
5
- var tslib = require('tslib');
6
5
 
7
6
  /**
8
7
  * Unique symbol used as a key for the IoC context.
9
8
  *
10
9
  * @group Context
11
10
  */
12
- var IOC_CONTAINER_KEY = Symbol("ContainerContext");
11
+ const CONTAINER_KEY = Symbol("ContainerContext");
13
12
  /**
14
- * Lit context object for providing and consuming the IoC container.
13
+ * Lit context object for providing and consuming the container.
15
14
  *
16
15
  * @group Context
17
16
  */
18
- var IocContextObject = context.createContext(IOC_CONTAINER_KEY);
17
+ const ContainerContext = context.createContext(CONTAINER_KEY);
19
18
 
20
19
  /**
21
20
  * Decorator to inject a service from the IoC container into a Lit element property.
@@ -50,31 +49,32 @@ var IocContextObject = context.createContext(IOC_CONTAINER_KEY);
50
49
  * ```
51
50
  */
52
51
  function injection(optionsOrInjectionId) {
53
- var options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
52
+ const options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
54
53
  injectionId: optionsOrInjectionId
55
54
  };
56
- return function (protoOrTarget, nameOrContext) {
57
- var injectionId = options.injectionId,
58
- once = options.once;
55
+ return (protoOrTarget, nameOrContext) => {
56
+ const {
57
+ injectionId,
58
+ once
59
+ } = options;
59
60
  // Standard decorators branch.
60
61
  if (typeof nameOrContext === "object") {
61
62
  nameOrContext.addInitializer(function () {
62
- var _this = this;
63
63
  new context.ContextConsumer(this, {
64
- context: IocContextObject,
65
- callback: function (it) {
66
- protoOrTarget.set.call(_this, it.container.get(injectionId));
64
+ context: ContainerContext,
65
+ callback: container => {
66
+ protoOrTarget.set.call(this, container.get(injectionId));
67
67
  },
68
68
  subscribe: !once
69
69
  });
70
70
  });
71
71
  } else {
72
72
  // Experimental decorators branch.
73
- protoOrTarget.constructor.addInitializer(function (element) {
73
+ protoOrTarget.constructor.addInitializer(element => {
74
74
  new context.ContextConsumer(element, {
75
- context: IocContextObject,
76
- callback: function (it) {
77
- element[nameOrContext] = it.container.get(injectionId);
75
+ context: ContainerContext,
76
+ callback: container => {
77
+ element[nameOrContext] = container.get(injectionId);
78
78
  },
79
79
  subscribe: !once
80
80
  });
@@ -83,6 +83,41 @@ function injection(optionsOrInjectionId) {
83
83
  };
84
84
  }
85
85
 
86
+ /**
87
+ * Hook (consumer) to access the active container from the nearest parent context.
88
+ *
89
+ * @remarks
90
+ * The returned value updates when the nearest provided container changes.
91
+ *
92
+ * @group Consumption
93
+ *
94
+ * @param host - The host element.
95
+ * @returns An instance of {@link UseContainerValue}.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * class MyElement extends LitElement {
100
+ * private container: UseContainerValue = useContainer(this);
101
+ *
102
+ * public render() {
103
+ * return html`<div>${this.container.value.isBound(MyService)}</div>`;
104
+ * }
105
+ * }
106
+ * ```
107
+ */
108
+ function useContainer(host) {
109
+ const current = {
110
+ value: null
111
+ };
112
+ new context.ContextConsumer(host, {
113
+ context: ContainerContext,
114
+ callback: container => {
115
+ current.value = container;
116
+ }
117
+ });
118
+ return current;
119
+ }
120
+
86
121
  /**
87
122
  * Hook (controller) to inject a service from the IoC container.
88
123
  *
@@ -115,21 +150,61 @@ function injection(optionsOrInjectionId) {
115
150
  * ```
116
151
  */
117
152
  function useInjection(host, optionsOrInjectionId) {
118
- var options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
153
+ const options = typeof optionsOrInjectionId === "object" && optionsOrInjectionId !== null && "injectionId" in optionsOrInjectionId ? optionsOrInjectionId : {
119
154
  injectionId: optionsOrInjectionId
120
155
  };
121
- var once = options.once,
122
- injectionId = options.injectionId,
123
- value = options.value;
124
- var current = {
156
+ const {
157
+ once,
158
+ injectionId,
159
+ value
160
+ } = options;
161
+ const current = {
125
162
  value: value,
126
- injectionId: injectionId
163
+ injectionId
127
164
  };
128
165
  new context.ContextConsumer(host, {
129
- context: IocContextObject,
166
+ context: ContainerContext,
130
167
  subscribe: !once,
131
- callback: function (it) {
132
- current.value = it.container.get(injectionId);
168
+ callback: container => {
169
+ current.value = container.get(injectionId);
170
+ }
171
+ });
172
+ return current;
173
+ }
174
+
175
+ /**
176
+ * Hook (consumer) to access the active {@link WireScope} from the nearest parent context.
177
+ *
178
+ * @remarks
179
+ * The returned value updates when the nearest provided container changes.
180
+ *
181
+ * @group Consumption
182
+ *
183
+ * @param host - The host element.
184
+ * @returns An instance of {@link UseScopeValue}.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * class MyElement extends LitElement {
189
+ * private scope: UseScopeValue = useScope(this);
190
+ *
191
+ * public connectedCallback(): void {
192
+ * super.connectedCallback();
193
+ * this.scope.value.emitEvent("UI_READY");
194
+ * }
195
+ * }
196
+ * ```
197
+ */
198
+ function useScope(host) {
199
+ const current = {
200
+ value: undefined,
201
+ injectionId: core.WireScope
202
+ };
203
+ new context.ContextConsumer(host, {
204
+ context: ContainerContext,
205
+ subscribe: true,
206
+ callback: container => {
207
+ current.value = container.get(core.WireScope);
133
208
  }
134
209
  });
135
210
  return current;
@@ -144,49 +219,46 @@ function useInjection(host, optionsOrInjectionId) {
144
219
  *
145
220
  * @group Commands
146
221
  */
147
- var OnCommandController = /** @class */function () {
222
+ class OnCommandController {
223
+ bus = null;
224
+ unregister = null;
148
225
  /**
149
226
  * @param host - The host element.
150
227
  * @param type - Unique identifier of the command to handle.
151
228
  * @param handler - The command handler function.
152
229
  */
153
- function OnCommandController(host, type, handler) {
154
- var _this = this;
155
- this.bus = null;
156
- this.unregister = null;
230
+ constructor(host, type, handler) {
157
231
  host.addController(this);
158
232
  this.type = type;
159
233
  this.handler = handler;
160
234
  new context.ContextConsumer(host, {
161
- context: IocContextObject,
235
+ context: ContainerContext,
162
236
  subscribe: true,
163
- callback: function (context) {
164
- _this.bus = context.container.get(core.CommandBus);
237
+ callback: container => {
238
+ this.bus = container.get(core.CommandBus);
165
239
  if (host.isConnected) {
166
- _this.reregister();
240
+ this.reregister();
167
241
  }
168
242
  }
169
243
  });
170
244
  }
171
- OnCommandController.prototype.hostConnected = function () {
245
+ hostConnected() {
172
246
  this.reregister();
173
- };
174
- OnCommandController.prototype.hostDisconnected = function () {
247
+ }
248
+ hostDisconnected() {
175
249
  this.cleanup();
176
- };
177
- OnCommandController.prototype.reregister = function () {
250
+ }
251
+ reregister() {
178
252
  this.cleanup();
179
253
  if (this.bus) {
180
254
  this.unregister = this.bus.register(this.type, this.handler);
181
255
  }
182
- };
183
- OnCommandController.prototype.cleanup = function () {
184
- var _a;
185
- (_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
256
+ }
257
+ cleanup() {
258
+ this.unregister?.();
186
259
  this.unregister = null;
187
- };
188
- return OnCommandController;
189
- }();
260
+ }
261
+ }
190
262
 
191
263
  /**
192
264
  * Decorator for Lit element methods that handle a specific command.
@@ -210,21 +282,16 @@ var OnCommandController = /** @class */function () {
210
282
  * ```
211
283
  */
212
284
  function onCommand(type) {
213
- return function (protoOrTarget, nameOrContext) {
285
+ return (protoOrTarget, nameOrContext) => {
214
286
  if (typeof nameOrContext === "object") {
215
287
  // Standard decorators:
216
288
  nameOrContext.addInitializer(function () {
217
- var _this = this;
218
- new OnCommandController(this, type, function (data) {
219
- return _this[nameOrContext.name](data);
220
- });
289
+ new OnCommandController(this, type, data => this[nameOrContext.name](data));
221
290
  });
222
291
  } else {
223
292
  // Experimental legacy decorators:
224
- protoOrTarget.constructor.addInitializer(function (element) {
225
- new OnCommandController(element, type, function (data) {
226
- return element[nameOrContext](data);
227
- });
293
+ protoOrTarget.constructor.addInitializer(element => {
294
+ new OnCommandController(element, type, data => element[nameOrContext](data));
228
295
  });
229
296
  }
230
297
  };
@@ -251,9 +318,10 @@ function onCommand(type) {
251
318
  * }
252
319
  * ```
253
320
  */
254
- function useOnCommand(host, _a) {
255
- var type = _a.type,
256
- handler = _a.handler;
321
+ function useOnCommand(host, {
322
+ type,
323
+ handler
324
+ }) {
257
325
  return new OnCommandController(host, type, handler);
258
326
  }
259
327
 
@@ -266,58 +334,54 @@ function useOnCommand(host, _a) {
266
334
  *
267
335
  * @group Events
268
336
  */
269
- var OnEventController = /** @class */function () {
337
+ class OnEventController {
338
+ bus = null;
339
+ unsubscriber = null;
270
340
  /**
271
341
  * @param host - The host element.
272
342
  * @param types - Event types to listen for. If null, all events will be handled.
273
343
  * @param handler - The event handler function.
274
344
  */
275
- function OnEventController(host, types, handler) {
276
- var _this = this;
277
- this.bus = null;
278
- this.unsubscriber = null;
345
+ constructor(host, types, handler) {
279
346
  host.addController(this);
280
347
  this.types = types;
281
348
  this.handler = handler;
282
349
  new context.ContextConsumer(host, {
283
- context: IocContextObject,
350
+ context: ContainerContext,
284
351
  subscribe: true,
285
- callback: function (context) {
286
- _this.bus = context.container.get(core.EventBus);
352
+ callback: container => {
353
+ this.bus = container.get(core.EventBus);
287
354
  if (host.isConnected) {
288
- _this.resubscribe();
355
+ this.resubscribe();
289
356
  }
290
357
  }
291
358
  });
292
359
  }
293
- OnEventController.prototype.hostConnected = function () {
360
+ hostConnected() {
294
361
  this.resubscribe();
295
- };
296
- OnEventController.prototype.hostDisconnected = function () {
362
+ }
363
+ hostDisconnected() {
297
364
  this.cleanup();
298
- };
299
- OnEventController.prototype.resubscribe = function () {
300
- var _this = this;
365
+ }
366
+ resubscribe() {
301
367
  this.cleanup();
302
368
  if (this.bus) {
303
369
  if (this.types === null) {
304
370
  this.unsubscriber = this.bus.subscribe(this.handler);
305
371
  } else {
306
- this.unsubscriber = this.bus.subscribe(function (event) {
307
- if (_this.types.includes(event.type)) {
308
- _this.handler(event);
372
+ this.unsubscriber = this.bus.subscribe(event => {
373
+ if (this.types.includes(event.type)) {
374
+ this.handler(event);
309
375
  }
310
376
  });
311
377
  }
312
378
  }
313
- };
314
- OnEventController.prototype.cleanup = function () {
315
- var _a;
316
- (_a = this.unsubscriber) === null || _a === void 0 ? void 0 : _a.call(this);
379
+ }
380
+ cleanup() {
381
+ this.unsubscriber?.();
317
382
  this.unsubscriber = null;
318
- };
319
- return OnEventController;
320
- }();
383
+ }
384
+ }
321
385
 
322
386
  /**
323
387
  * Decorator for Lit element methods that handle events from the event bus.
@@ -361,22 +425,17 @@ var OnEventController = /** @class */function () {
361
425
  * ```
362
426
  */
363
427
  function onEvent(types) {
364
- var normalized = types === undefined ? null : Array.isArray(types) ? tslib.__spreadArray([], types, true) : [types];
365
- return function (protoOrTarget, nameOrContext) {
428
+ const normalized = types === undefined ? null : Array.isArray(types) ? [...types] : [types];
429
+ return (protoOrTarget, nameOrContext) => {
366
430
  if (typeof nameOrContext === "object") {
367
431
  // Standard decorators:
368
432
  nameOrContext.addInitializer(function () {
369
- var _this = this;
370
- new OnEventController(this, normalized, function (event) {
371
- return _this[nameOrContext.name](event);
372
- });
433
+ new OnEventController(this, normalized, event => this[nameOrContext.name](event));
373
434
  });
374
435
  } else {
375
436
  // Experimental legacy decorators:
376
- protoOrTarget.constructor.addInitializer(function (element) {
377
- new OnEventController(element, normalized, function (event) {
378
- return element[nameOrContext](event);
379
- });
437
+ protoOrTarget.constructor.addInitializer(element => {
438
+ new OnEventController(element, normalized, event => element[nameOrContext](event));
380
439
  });
381
440
  }
382
441
  };
@@ -412,10 +471,11 @@ function onEvent(types) {
412
471
  * }
413
472
  * ```
414
473
  */
415
- function useOnEvents(host, _a) {
416
- var types = _a.types,
417
- handler = _a.handler;
418
- var normalized = types ? Array.isArray(types) ? tslib.__spreadArray([], types, true) : [types] : null;
474
+ function useOnEvents(host, {
475
+ types,
476
+ handler
477
+ }) {
478
+ const normalized = types ? Array.isArray(types) ? [...types] : [types] : null;
419
479
  return new OnEventController(host, normalized, handler);
420
480
  }
421
481
 
@@ -428,49 +488,46 @@ function useOnEvents(host, _a) {
428
488
  *
429
489
  * @group Queries
430
490
  */
431
- var OnQueryController = /** @class */function () {
491
+ class OnQueryController {
492
+ bus = null;
493
+ unregister = null;
432
494
  /**
433
495
  * @param host - The host element.
434
496
  * @param type - Unique identifier of the query to handle.
435
497
  * @param handler - The query handler function.
436
498
  */
437
- function OnQueryController(host, type, handler) {
438
- var _this = this;
439
- this.bus = null;
440
- this.unregister = null;
499
+ constructor(host, type, handler) {
441
500
  host.addController(this);
442
501
  this.type = type;
443
502
  this.handler = handler;
444
503
  new context.ContextConsumer(host, {
445
- context: IocContextObject,
504
+ context: ContainerContext,
446
505
  subscribe: true,
447
- callback: function (context) {
448
- _this.bus = context.container.get(core.QueryBus);
506
+ callback: container => {
507
+ this.bus = container.get(core.QueryBus);
449
508
  if (host.isConnected) {
450
- _this.reregister();
509
+ this.reregister();
451
510
  }
452
511
  }
453
512
  });
454
513
  }
455
- OnQueryController.prototype.hostConnected = function () {
514
+ hostConnected() {
456
515
  this.reregister();
457
- };
458
- OnQueryController.prototype.hostDisconnected = function () {
516
+ }
517
+ hostDisconnected() {
459
518
  this.cleanup();
460
- };
461
- OnQueryController.prototype.reregister = function () {
519
+ }
520
+ reregister() {
462
521
  this.cleanup();
463
522
  if (this.bus) {
464
523
  this.unregister = this.bus.register(this.type, this.handler);
465
524
  }
466
- };
467
- OnQueryController.prototype.cleanup = function () {
468
- var _a;
469
- (_a = this.unregister) === null || _a === void 0 ? void 0 : _a.call(this);
525
+ }
526
+ cleanup() {
527
+ this.unregister?.();
470
528
  this.unregister = null;
471
- };
472
- return OnQueryController;
473
- }();
529
+ }
530
+ }
474
531
 
475
532
  /**
476
533
  * Decorator for Lit element methods that handle a specific query.
@@ -494,21 +551,16 @@ var OnQueryController = /** @class */function () {
494
551
  * ```
495
552
  */
496
553
  function onQuery(type) {
497
- return function (protoOrTarget, nameOrContext) {
554
+ return (protoOrTarget, nameOrContext) => {
498
555
  if (typeof nameOrContext === "object") {
499
556
  // Standard decorators:
500
557
  nameOrContext.addInitializer(function () {
501
- var _this = this;
502
- new OnQueryController(this, type, function (data) {
503
- return _this[nameOrContext.name](data);
504
- });
558
+ new OnQueryController(this, type, data => this[nameOrContext.name](data));
505
559
  });
506
560
  } else {
507
561
  // Experimental legacy decorators:
508
- protoOrTarget.constructor.addInitializer(function (element) {
509
- new OnQueryController(element, type, function (data) {
510
- return element[nameOrContext](data);
511
- });
562
+ protoOrTarget.constructor.addInitializer(element => {
563
+ new OnQueryController(element, type, data => element[nameOrContext](data));
512
564
  });
513
565
  }
514
566
  };
@@ -535,128 +587,217 @@ function onQuery(type) {
535
587
  * }
536
588
  * ```
537
589
  */
538
- function useOnQuery(host, _a) {
539
- var type = _a.type,
540
- handler = _a.handler;
590
+ function useOnQuery(host, {
591
+ type,
592
+ handler
593
+ }) {
541
594
  return new OnQueryController(host, type, handler);
542
595
  }
543
596
 
597
+ const ERROR_CODE_INVALID_ARGUMENTS = 2051;
598
+
544
599
  /**
545
- * Controller that provides an IoC container context to the host element and its children.
600
+ * Provider that exposes an IoC container context to the host element and its children.
546
601
  *
547
602
  * @remarks
548
- * It manages the lifecycle of the container and handles revision updates to notify consumers.
549
- * The container is created (or used from options) when the controller is instantiated.
550
- * Seed data is applied when the host connects.
603
+ * The provider supports two modes:
604
+ *
605
+ * - External mode: `container` is an existing {@link Container}. The
606
+ * provider passes it through context and does not alter its lifecycle.
607
+ * - Managed mode: `options` is {@link CreateContainerOptions}. The provider
608
+ * creates a container during construction without eager activation,
609
+ * activates configured entries when the host connects, disposes the
610
+ * container when the host disconnects, and recreates it on reconnect.
551
611
  *
552
612
  * @group Provision
553
613
  */
554
- var IocProviderController = /** @class */function () {
614
+ class ContainerProvider extends context.ContextProvider {
615
+ destroyed = false;
555
616
  /**
556
617
  * @param host - The host element.
557
618
  * @param options - Provisioning options.
558
- * @param options.container - Optional existing container to use. If not provided, a new one will be created.
559
- * @param options.seed - Optional seed data to apply to the container.
619
+ * @param options.container - External container instance to provide.
620
+ * @param options.options - Managed container creation options.
560
621
  */
561
- function IocProviderController(host, _a) {
562
- var _b = _a === void 0 ? {} : _a,
563
- container = _b.container,
564
- seed = _b.seed;
565
- var _this = this;
566
- this.host = host;
567
- this.revision = 1;
568
- this.host.addController(this);
569
- this.container = container !== null && container !== void 0 ? container : core.createContainer();
570
- this.seed = seed;
571
- this.provider = new context.ContextProvider(host, {
572
- context: IocContextObject,
573
- initialValue: {
574
- container: this.container,
575
- revision: this.revision,
576
- nextRevision: function () {
577
- return _this.nextRevision();
622
+ constructor(host, options) {
623
+ if (!options.container && !options.options) {
624
+ throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires a valid container instance or creation options.");
625
+ } else if (options.container && options.options) {
626
+ throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "ContainerProvider requires only container or valid options object to be provided.");
627
+ }
628
+ super(host, {
629
+ context: ContainerContext,
630
+ initialValue: options.container ? options.container : core.createContainer({
631
+ ...options.options,
632
+ activate: []
633
+ })
634
+ });
635
+ this.options = options.options;
636
+ }
637
+ hostConnected() {
638
+ if (this.options) {
639
+ if (this.destroyed) {
640
+ this.value = core.createContainer(this.options);
641
+ this.destroyed = false;
642
+ } else {
643
+ if (this.options?.activate) {
644
+ for (const entry of this.options.activate) {
645
+ this.value.get(entry);
646
+ }
578
647
  }
579
648
  }
580
- });
649
+ }
650
+ super.hostConnected();
581
651
  }
582
- Object.defineProperty(IocProviderController.prototype, "value", {
583
- /**
584
- * @returns Current {@link IocContext} value served to child consumers.
585
- */
586
- get: function () {
587
- return this.provider.value;
588
- },
589
- enumerable: false,
590
- configurable: true
591
- });
592
- IocProviderController.prototype.hostConnected = function () {
593
- if (this.seed) {
594
- core.applySharedSeed(this.container, this.seed);
652
+ hostDisconnected() {
653
+ if (this.options) {
654
+ this.value.unbindAll();
655
+ this.destroyed = true;
595
656
  }
596
- };
597
- IocProviderController.prototype.hostDisconnected = function () {};
598
- IocProviderController.prototype.nextRevision = function () {
599
- var _this = this;
600
- this.revision += 1;
601
- this.provider.setValue({
602
- container: this.container,
603
- revision: this.revision,
604
- nextRevision: function () {
605
- return _this.nextRevision();
657
+ }
658
+ }
659
+
660
+ /**
661
+ * Provider that exposes a managed child container for the host element's lifetime.
662
+ *
663
+ * @remarks
664
+ * The provider always owns a child container derived from the nearest parent
665
+ * {@link ContainerContext}. When connected, it creates a child container using
666
+ * the latest parent context, provides it to descendants, destroys it when the
667
+ * host disconnects, and replaces it whenever the parent container changes.
668
+ *
669
+ * @group Provision
670
+ *
671
+ * @example
672
+ * ```typescript
673
+ * class MyComponent extends LitElement {
674
+ * private container = new SubContainerProvider(this, {
675
+ * options: {
676
+ * entries: [AuthService, UserService],
677
+ * activate: [AuthService],
678
+ * seeds: [[AuthService, { role: "admin" }]],
679
+ * },
680
+ * });
681
+ * }
682
+ * ```
683
+ */
684
+ class SubContainerProvider extends context.ContextProvider {
685
+ parent = null;
686
+ destroyed = true;
687
+ /**
688
+ * @param host - The host element.
689
+ * @param options - Provisioning options, including child entries, eager activations, and seeds.
690
+ */
691
+ constructor(host, options) {
692
+ super(host, {
693
+ context: ContainerContext
694
+ });
695
+ this.options = options.options;
696
+ this.consumer = new context.ContextConsumer(host, {
697
+ context: ContainerContext,
698
+ subscribe: true,
699
+ callback: context => {
700
+ const previousParent = this.parent;
701
+ this.parent = context;
702
+ if (host.isConnected) {
703
+ if (this.destroyed || !this.value || previousParent !== context) {
704
+ this.destroyContainer();
705
+ this.createContainer();
706
+ }
707
+ }
606
708
  }
607
709
  });
608
- return this.revision;
609
- };
610
- return IocProviderController;
611
- }();
710
+ }
711
+ hostConnected() {
712
+ if (this.parent && (this.destroyed || !this.value)) {
713
+ this.destroyContainer();
714
+ this.createContainer();
715
+ }
716
+ super.hostConnected();
717
+ }
718
+ hostDisconnected() {
719
+ this.destroyContainer();
720
+ }
721
+ /**
722
+ * Replaces the currently provided child container with a new one derived
723
+ * from the latest parent context.
724
+ */
725
+ createContainer() {
726
+ const container = core.createContainer({
727
+ ...this.options,
728
+ parent: this.parent
729
+ });
730
+ this.destroyed = false;
731
+ this.value = container;
732
+ }
733
+ /**
734
+ * Destroys the currently provided child container.
735
+ */
736
+ destroyContainer() {
737
+ if (this.value && !this.destroyed) {
738
+ this.value.unbindAll();
739
+ this.destroyed = true;
740
+ }
741
+ }
742
+ }
612
743
 
613
744
  /**
614
745
  * Decorator that provides an IoC container to child components.
615
746
  *
616
747
  * @remarks
617
- * The container is provided via Lit context. It is created (or used from options) when the host connects.
748
+ * The container is provided via Lit context.
749
+ *
750
+ * - Pass `container` to expose an external container without taking
751
+ * ownership.
752
+ * - Pass `options` to create a managed container during construction,
753
+ * activate configured entries on connect, destroy it on disconnect, and
754
+ * recreate it on reconnect.
618
755
  *
619
756
  * @group Provision
620
757
  *
621
758
  * @param options - Provisioning options.
622
- * @param options.container - Optional existing container to use, if not provided, a new one will be created.
623
- * @param options.seed - Optional seed data to apply to the container.
624
- * @returns An instance of {@link IocProviderDecorator}.
759
+ * @param options.container - External container instance to provide.
760
+ * @param options.options - Managed container creation options.
761
+ * @returns An instance of {@link ContainerProviderDecorator}.
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * class MyRootElement extends LitElement {
766
+ * @containerProvide({
767
+ * options: {
768
+ * seed: { someData: "value" },
769
+ * entries: [LoggerService],
770
+ * },
771
+ * })
772
+ * private containerProvider!: ContainerProvider;
773
+ * }
774
+ * ```
625
775
  *
626
776
  * @example
627
777
  * ```typescript
628
778
  * class MyRootElement extends LitElement {
629
- * @iocProvide({ seed: { someData: "value" } })
630
- * private ioc!: IocProviderController;
779
+ * @containerProvide({ container: container })
780
+ * private containerProvider!: ContainerProvider;
631
781
  * }
632
782
  * ```
633
783
  */
634
- function iocProvide(_a) {
635
- var _b = _a === void 0 ? {} : _a,
636
- container = _b.container,
637
- seed = _b.seed;
638
- return function (protoOrTarget, nameOrContext) {
784
+ function containerProvide(options) {
785
+ return (protoOrTarget, nameOrContext) => {
639
786
  if (typeof nameOrContext === "object") {
640
787
  // Standard decorators:
641
788
  nameOrContext.addInitializer(function () {
642
- protoOrTarget.set.call(this, new IocProviderController(this, {
643
- container: container,
644
- seed: seed
645
- }));
789
+ protoOrTarget.set.call(this, new ContainerProvider(this, options));
646
790
  });
647
791
  } else {
648
- var controller_1;
649
- protoOrTarget.constructor.addInitializer(function (element) {
650
- controller_1 = new IocProviderController(element, {
651
- container: container,
652
- seed: seed
653
- });
792
+ let controller;
793
+ protoOrTarget.constructor.addInitializer(element => {
794
+ controller = new ContainerProvider(element, options);
654
795
  });
655
796
  return {
656
- get: function () {
657
- return controller_1;
797
+ get() {
798
+ return controller;
658
799
  },
659
- set: function () {},
800
+ set() {},
660
801
  configurable: true,
661
802
  enumerable: true
662
803
  };
@@ -664,160 +805,51 @@ function iocProvide(_a) {
664
805
  };
665
806
  }
666
807
 
667
- var ERROR_CODE_INVALID_ARGUMENTS = 2051;
668
-
669
- /**
670
- * Controller that binds injectables to an IoC container for the host element's lifetime.
671
- *
672
- * @remarks
673
- * Entries are bound when the host connects and unbound when it disconnects.
674
- * If no `into` context is provided, it uses the nearest {@link IocProviderController}.
675
- * Seeds are applied before entries are bound.
676
- *
677
- * @group Provision
678
- *
679
- * @example
680
- * ```typescript
681
- * class MyComponent extends LitElement {
682
- * private services = new InjectablesProviderController(this, {
683
- * entries: [AuthService, UserService],
684
- * activate: [AuthService],
685
- * seeds: [[AuthService, { role: "admin" }]],
686
- * });
687
- * }
688
- * ```
689
- */
690
- var InjectablesProviderController = /** @class */function () {
691
- /**
692
- * @param host - The host element.
693
- * @param options - Provisioning options.
694
- * @param options.entries - List of service entries to bind to the container.
695
- * @param options.into - Target IoC context; if omitted, uses the nearest provider context.
696
- * @param options.activate - List of service identifiers to activate immediately after binding.
697
- * @param options.seeds - Seed data applied before binding.
698
- */
699
- function InjectablesProviderController(host, options) {
700
- var _this = this;
701
- var _a, _b, _c;
702
- this.host = host;
703
- /**
704
- * Tracks the context to which entries are currently bound, for correct cleanup on disconnect.
705
- */
706
- this.boundContext = null;
707
- this.host.addController(this);
708
- this.entries = options.entries;
709
- this.activate = (_a = options.activate) !== null && _a !== void 0 ? _a : null;
710
- this.seeds = (_b = options.seeds) !== null && _b !== void 0 ? _b : null;
711
- this.into = (_c = options.into) !== null && _c !== void 0 ? _c : null;
712
- if (!this.into) {
713
- // subscribe: false — binding happens once per connect, not on every revision update.
714
- this.consumer = new context.ContextConsumer(host, {
715
- context: IocContextObject,
716
- subscribe: false,
717
- callback: function (context) {
718
- if (!host.isConnected) {
719
- return;
720
- }
721
- _this.bind(context);
722
- }
723
- });
724
- }
725
- }
726
- InjectablesProviderController.prototype.hostConnected = function () {
727
- var _a;
728
- if (!this.into) {
729
- // ContextConsumer with subscribe:false only invokes the user callback once (provided flag stays true
730
- // after disconnect). On reconnect we fall back to the cached consumer.value so bind() still fires.
731
- if ((_a = this.consumer) === null || _a === void 0 ? void 0 : _a.value) {
732
- this.bind(this.consumer.value);
733
- }
734
- return;
735
- }
736
- var context = typeof this.into === "function" ? this.into() : this.into;
737
- if (!context) {
738
- throw new core.WirestateError(ERROR_CODE_INVALID_ARGUMENTS, "InjectablesProviderController: the 'into' option resolved to null or undefined. " + "Ensure the value or resolver function returns a valid IocContext.");
739
- }
740
- this.bind(context);
741
- };
742
- InjectablesProviderController.prototype.hostDisconnected = function () {
743
- if (!this.boundContext) {
744
- return;
745
- }
746
- this.unbind(this.boundContext);
747
- };
748
- InjectablesProviderController.prototype.bind = function (context) {
749
- if (this.boundContext) {
750
- // Re-binding without unbinding first would leave stale entries; unbind the previous context.
751
- this.unbind(this.boundContext);
752
- }
753
- this.boundContext = context;
754
- // Seeds must be applied before binding so @Inject(SEEDS_TOKEN) resolves during activation.
755
- if (this.seeds) {
756
- core.applySeeds(context.container, this.seeds);
757
- }
758
- for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
759
- var entry = _a[_i];
760
- core.bindEntry(context.container, entry);
761
- }
762
- if (this.activate) {
763
- for (var _b = 0, _c = this.activate; _b < _c.length; _b++) {
764
- var token = _c[_b];
765
- context.container.get(token);
766
- }
767
- }
768
- };
769
- InjectablesProviderController.prototype.unbind = function (context) {
770
- for (var _i = 0, _a = this.entries; _i < _a.length; _i++) {
771
- var entry = _a[_i];
772
- var token = core.getEntryToken(entry);
773
- if (context.container.isBound(token)) {
774
- context.container.unbind(token);
775
- }
776
- }
777
- if (this.seeds) {
778
- core.unapplySeeds(context.container, this.seeds);
779
- }
780
- this.boundContext = null;
781
- };
782
- return InjectablesProviderController;
783
- }();
784
-
785
808
  /**
786
- * Decorator that binds a set of injectables to the nearest IoC container for the host element's lifetime.
809
+ * Decorator that provides a managed child container derived from the nearest
810
+ * parent container context.
787
811
  *
788
812
  * @remarks
789
- * Entries are bound when the host connects and unbound when it disconnects.
813
+ * The child container is created from the current parent context when the host
814
+ * connects, destroyed when it disconnects, and recreated when the parent
815
+ * container changes.
790
816
  *
791
817
  * @group Provision
792
818
  *
793
819
  * @param options - Provisioning options.
794
- * @returns An instance of {@link InjectablesProviderDecorator}.
820
+ * @param options.options - Child-container creation options.
821
+ * @returns An instance of {@link SubContainerProviderDecorator}.
795
822
  *
796
823
  * @example
797
824
  * ```typescript
798
825
  * class MyComponent extends LitElement {
799
- * @injectablesProvide({ entries: [AuthService, UserService], activate: [AuthService] })
800
- * public controller!: InjectablesProviderController<MyComponent>;
826
+ * @subContainerProvide({
827
+ * options: {
828
+ * entries: [AuthService, UserService],
829
+ * activate: [AuthService],
830
+ * },
831
+ * })
832
+ * public containerProvider!: SubContainerProvider<MyComponent>;
801
833
  * }
802
834
  * ```
803
835
  */
804
- function injectablesProvide(options) {
805
- return function (protoOrTarget, nameOrContext) {
836
+ function subContainerProvide(options) {
837
+ return (protoOrTarget, nameOrContext) => {
806
838
  if (typeof nameOrContext === "object") {
807
839
  // Standard decorators:
808
840
  nameOrContext.addInitializer(function () {
809
- protoOrTarget.set.call(this, new InjectablesProviderController(this, options));
841
+ protoOrTarget.set.call(this, new SubContainerProvider(this, options));
810
842
  });
811
843
  } else {
812
- var controller_1;
813
- protoOrTarget.constructor.addInitializer(function (element) {
814
- controller_1 = new InjectablesProviderController(element, options);
844
+ let provider;
845
+ protoOrTarget.constructor.addInitializer(element => {
846
+ provider = new SubContainerProvider(element, options);
815
847
  });
816
848
  return {
817
- get: function () {
818
- return controller_1;
849
+ get() {
850
+ return provider;
819
851
  },
820
- set: function () {},
852
+ set() {},
821
853
  configurable: true,
822
854
  enumerable: true
823
855
  };
@@ -826,67 +858,93 @@ function injectablesProvide(options) {
826
858
  }
827
859
 
828
860
  /**
829
- * Hook that binds injectables to the nearest IoC container for the host element's lifetime.
861
+ * Hook that provides a container to the host element and its children.
862
+ *
863
+ * @remarks
864
+ * Pass `container` to expose an external `Container` without taking
865
+ * ownership. Pass `options` to create a managed container during
866
+ * construction, activate configured entries on connect, destroy it on
867
+ * disconnect, and recreate it on reconnect.
830
868
  *
831
869
  * @group Provision
832
870
  *
833
871
  * @param host - The host element.
834
872
  * @param options - Provisioning options.
835
- * @returns An instance of {@link InjectablesProviderController}.
873
+ * @param options.container - External container instance to provide.
874
+ * @param options.options - Managed container creation options.
875
+ * @returns An instance of {@link ContainerProvider}.
836
876
  *
837
877
  * @example
838
878
  * ```typescript
839
- * class MyComponent extends LitElement {
840
- * private services = useInjectablesProvider(this, {
841
- * entries: [AuthService, UserService],
842
- * activate: [AuthService],
879
+ * class MyRootElement extends LitElement {
880
+ * private containerProvider: ContainerProvider = useContainerProvision(this, {
881
+ * options: {
882
+ * entries: [LoggerService],
883
+ * activate: [LoggerService],
884
+ * },
843
885
  * });
844
886
  * }
845
887
  * ```
888
+ *
889
+ * @example
890
+ * ```typescript
891
+ * class MyRootElement extends LitElement {
892
+ * private containerProvider: ContainerProvider = useContainerProvision(this, { container: container });
893
+ * }
894
+ * ```
846
895
  */
847
- function useInjectablesProvider(host, options) {
848
- return new InjectablesProviderController(host, options);
896
+ function useContainerProvision(host, options) {
897
+ return new ContainerProvider(host, options);
849
898
  }
850
899
 
851
900
  /**
852
- * Hook that provides an IoC container to the host element and its children.
901
+ * Hook that provides a managed child container for the host element's lifetime.
902
+ *
903
+ * @remarks
904
+ * The child container is derived from the current parent
905
+ * {@link ContainerContext}, recreated when that parent context changes, and
906
+ * destroyed when the host disconnects.
853
907
  *
854
908
  * @group Provision
855
909
  *
856
910
  * @param host - The host element.
857
911
  * @param options - Provisioning options.
858
- * @returns An instance of {@link IocProviderController}.
912
+ * @param options.options - Child-container creation options.
913
+ * @returns An instance of {@link SubContainerProvider}.
859
914
  *
860
915
  * @example
861
916
  * ```typescript
862
- * class MyRootElement extends LitElement {
863
- * private ioc = useIocProvision(this, { seed: { initialData: "..." } });
917
+ * class MyComponent extends LitElement {
918
+ * private containerProvider: SubContainerProvider = useSubContainerProvider(this, {
919
+ * options: {
920
+ * entries: [AuthService, UserService],
921
+ * },
922
+ * });
864
923
  * }
865
924
  * ```
866
925
  */
867
- function useIocProvision(host, options) {
868
- if (options === void 0) {
869
- options = {};
870
- }
871
- return new IocProviderController(host, options);
926
+ function useSubContainerProvider(host, options) {
927
+ return new SubContainerProvider(host, options);
872
928
  }
873
929
 
874
- exports.InjectablesProviderController = InjectablesProviderController;
875
- exports.IocContextObject = IocContextObject;
876
- exports.IocProviderController = IocProviderController;
930
+ exports.ContainerContext = ContainerContext;
931
+ exports.ContainerProvider = ContainerProvider;
877
932
  exports.OnCommandController = OnCommandController;
878
933
  exports.OnEventController = OnEventController;
879
934
  exports.OnQueryController = OnQueryController;
880
- exports.injectablesProvide = injectablesProvide;
935
+ exports.SubContainerProvider = SubContainerProvider;
936
+ exports.containerProvide = containerProvide;
881
937
  exports.injection = injection;
882
- exports.iocProvide = iocProvide;
883
938
  exports.onCommand = onCommand;
884
939
  exports.onEvent = onEvent;
885
940
  exports.onQuery = onQuery;
886
- exports.useInjectablesProvider = useInjectablesProvider;
941
+ exports.subContainerProvide = subContainerProvide;
942
+ exports.useContainer = useContainer;
943
+ exports.useContainerProvision = useContainerProvision;
887
944
  exports.useInjection = useInjection;
888
- exports.useIocProvision = useIocProvision;
889
945
  exports.useOnCommand = useOnCommand;
890
946
  exports.useOnEvents = useOnEvents;
891
947
  exports.useOnQuery = useOnQuery;
948
+ exports.useScope = useScope;
949
+ exports.useSubContainerProvider = useSubContainerProvider;
892
950
  //# sourceMappingURL=index.js.map