@neovici/cosmoz-utils 6.24.0 → 6.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ interface RefObject<T> {
2
+ current?: T;
3
+ }
4
+ export declare const assignedRef: (ref: RefObject<Element[]>) => unknown;
5
+ export {};
@@ -0,0 +1,41 @@
1
+ import { noChange } from 'lit-html';
2
+ import { AsyncDirective, directive } from 'lit-html/async-directive.js';
3
+ /**
4
+ * Writes the slot's flattened assigned elements into the ref object,
5
+ * like ref() writes the element.
6
+ *
7
+ * Consumers read refObject.current at event time; a ref does not
8
+ * trigger renders.
9
+ */
10
+ class AssignedRefDirective extends AsyncDirective {
11
+ _slot;
12
+ _ref;
13
+ #project = () => {
14
+ if (!this._slot || !this._ref) {
15
+ return;
16
+ }
17
+ this._ref.current = this._slot.assignedElements({ flatten: true });
18
+ };
19
+ #onSlotChange = () => this.#project();
20
+ update(part, [ref]) {
21
+ this._ref = ref;
22
+ const slot = part.element;
23
+ if (this._slot !== slot) {
24
+ this._slot?.removeEventListener('slotchange', this.#onSlotChange);
25
+ this._slot = slot;
26
+ slot.addEventListener('slotchange', this.#onSlotChange);
27
+ }
28
+ this.#project();
29
+ }
30
+ disconnected() {
31
+ // the slot outlives renders; the listener is owned for its lifetime
32
+ // and removed when the part is cleared (template swap, disconnect)
33
+ this._slot?.removeEventListener('slotchange', this.#onSlotChange);
34
+ this._slot = undefined;
35
+ }
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
+ render(ref) {
38
+ return noChange;
39
+ }
40
+ }
41
+ export const assignedRef = directive(AssignedRefDirective);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "6.24.0",
3
+ "version": "6.25.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",