@wirestate/lit 0.6.1 → 0.7.0-experimental.2

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