@neovici/cosmoz-utils 6.24.0 → 6.25.1

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);
@@ -6,5 +6,11 @@ export declare function constant(): () => undefined;
6
6
  export declare function constant<T>(v: T): () => T;
7
7
  export declare const constTrue: () => true, constUndefined: () => undefined, noop: () => undefined, identity: <T>(obj: T) => T, or: <A, F extends OrFn<A>>(...fns: F[]) => (...args: A[]) => boolean;
8
8
  export declare const once: <A extends Arr, R, F extends OnceFn<A, R> = OnceFn<A, R>>(fn: F, check?: OnceCheckFn<A>) => (...args: A) => any;
9
- export declare const invoke: <T, A extends unknown[]>(fn: T | ((...args: A) => T), ...args: A) => T;
9
+ type Invoked<F> = F extends (...args: any[]) => infer R ? R : F;
10
+ /**
11
+ * The args of a known function are checked against its tuple; for a
12
+ * value-or-function union the runtime dispatch decides the member, so
13
+ * the args cannot be typed.
14
+ */
15
+ export declare const invoke: <F>(fn: F, ...args: F extends (...args: infer P) => unknown ? P : unknown[]) => Invoked<F>;
10
16
  export {};
package/dist/function.js CHANGED
@@ -6,4 +6,11 @@ export const once = (fn, check = constTrue) => {
6
6
  let result;
7
7
  return (...args) => (result ??= check(args) ? fn(...args) : undefined);
8
8
  };
9
- export const invoke = (fn, ...args) => (typeof fn === 'function' ? fn(...args) : fn);
9
+ /**
10
+ * The args of a known function are checked against its tuple; for a
11
+ * value-or-function union the runtime dispatch decides the member, so
12
+ * the args cannot be typed.
13
+ */
14
+ export const invoke = (fn, ...args) => typeof fn === 'function'
15
+ ? fn(...args)
16
+ : fn;
package/dist/promise.d.ts CHANGED
@@ -29,5 +29,5 @@ export declare const debounce$: <T extends unknown[], P>(fn: (...args: T) => P |
29
29
  export declare const share$: <T extends unknown[], P>(fn: (...args: T) => P | PromiseLike<P>) => (...args: T) => Promise<P>;
30
30
  export declare const log$: <T extends unknown[], P>(fn: (...args: T) => PromiseLike<P>) => (...args: T) => PromiseLike<P>;
31
31
  export declare const retry$: <T extends unknown[], P>(fn: (...args: T) => P | PromiseLike<P>, n: number) => (...args: T) => Promise<P>;
32
- export declare const invoke$: <T, A extends unknown[]>(fn: T | ((...args: A) => T | PromiseLike<T>), ...args: A) => Promise<Awaited<T> | Awaited<T>>;
32
+ export declare const invoke$: <T, A extends unknown[]>(fn: T | ((...args: A) => T | PromiseLike<T>), ...args: A) => Promise<Awaited<T> | Awaited<T> | Awaited<T extends (...args: any[]) => infer R ? R : T>>;
33
33
  export {};
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.1",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",