@neovici/cosmoz-utils 5.34.0 → 5.36.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.
@@ -51,11 +51,15 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
51
51
  readonly offsetTop: number;
52
52
  readonly offsetWidth: number;
53
53
  outerText: string;
54
+ popover: string | null;
54
55
  spellcheck: boolean;
55
56
  title: string;
56
57
  translate: boolean;
57
58
  attachInternals(): ElementInternals;
58
59
  click(): void;
60
+ hidePopover(): void;
61
+ showPopover(): void;
62
+ togglePopover(force?: boolean | undefined): void;
59
63
  addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
60
64
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
61
65
  removeEventListener<K_1 extends keyof HTMLElementEventMap>(type: K_1, listener: (this: HTMLElement, ev: HTMLElementEventMap[K_1]) => any, options?: boolean | EventListenerOptions | undefined): void;
@@ -89,6 +93,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
89
93
  closest<K_3 extends keyof SVGElementTagNameMap>(selector: K_3): SVGElementTagNameMap[K_3] | null;
90
94
  closest<K_4 extends keyof MathMLElementTagNameMap>(selector: K_4): MathMLElementTagNameMap[K_4] | null;
91
95
  closest<E extends Element = Element>(selectors: string): E | null;
96
+ computedStyleMap(): StylePropertyMapReadOnly;
92
97
  getAttribute(qualifiedName: string): string | null;
93
98
  getAttributeNS(namespace: string | null, localName: string): string | null;
94
99
  getAttributeNames(): string[];
@@ -246,6 +251,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
246
251
  querySelectorAll<E_2 extends Element = Element>(selectors: string): NodeListOf<E_2>;
247
252
  replaceChildren(...nodes: (string | Node)[]): void;
248
253
  readonly assignedSlot: HTMLSlotElement | null;
254
+ readonly attributeStyleMap: StylePropertyMap;
249
255
  readonly style: CSSStyleDeclaration;
250
256
  contentEditable: string;
251
257
  enterKeyHint: string;
@@ -318,6 +324,7 @@ export declare const hauntedPolymer: (outputPath: string | Hook, hook?: Hook) =>
318
324
  onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null;
319
325
  onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
320
326
  onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
327
+ onscrollend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
321
328
  onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null;
322
329
  onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null;
323
330
  onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null;
@@ -1,2 +1,2 @@
1
- declare const notifyProperty: <K extends string, T extends HTMLElement & { [key in K]?: unknown; }>(host: T, name: K, value: T[K]) => void, useNotifyProperty: <T extends HTMLElement, K extends Extract<keyof T, string>, V extends T[K]>(name: K, value: V, deps?: unknown[]) => void;
2
- export { notifyProperty, useNotifyProperty };
1
+ export declare const notifyProperty: <K extends string, T extends HTMLElement & { [key in K]?: unknown; }>(host: T, name: K, value: T[K]) => void;
2
+ export declare const useNotifyProperty: <K extends string, V>(name: K, value: V, deps?: unknown[]) => void;
@@ -1,8 +1,8 @@
1
1
  import { useEffect } from 'haunted';
2
2
  import { useHost } from './use-host';
3
- const UPPER = /([A-Z])/gu,
3
+ const UPPER = /([A-Z])/gu;
4
4
  /* Emulate polymer notify props */
5
- notifyProperty = (host, name, value) => {
5
+ export const notifyProperty = (host, name, value) => {
6
6
  // this is required to make polymer double-binding recognize the change
7
7
  // @see https://github.com/Polymer/polymer/blob/76c71e186ecc605294c3575dd31ac7983a8b3ae3/lib/mixins/property-effects.js#L382
8
8
  host[name] = value;
@@ -10,10 +10,10 @@ notifyProperty = (host, name, value) => {
10
10
  host.dispatchEvent(new CustomEvent(name.replace(UPPER, '-$1').toLowerCase() + '-changed', {
11
11
  detail: { value },
12
12
  }));
13
- }, useNotifyProperty = (name, value, deps = [value]) => {
13
+ };
14
+ export const useNotifyProperty = (name, value, deps = [value]) => {
14
15
  const host = useHost();
15
16
  useEffect(() => {
16
17
  notifyProperty(host, name, value);
17
18
  }, deps);
18
19
  };
19
- export { notifyProperty, useNotifyProperty };
@@ -0,0 +1,8 @@
1
+ type Init<T> = T | (() => T);
2
+ type UpdateFn<T> = (prev: T) => T;
3
+ type Update<T> = T | UpdateFn<T>;
4
+ type Setter<T> = (update: Update<T>) => void;
5
+ type Result<T> = [T, Setter<T>];
6
+ export declare function useProperty<T>(prop: string): Result<T | undefined>;
7
+ export declare function useProperty<T>(prop: string, init: Init<T>): Result<T>;
8
+ export {};
@@ -0,0 +1,25 @@
1
+ import { useEffect, useCallback } from 'haunted';
2
+ import { useMeta } from './use-meta';
3
+ import { useHost } from './use-host';
4
+ import { invoke } from '../function';
5
+ import { notifyProperty } from './use-notify-property';
6
+ export function useProperty(prop, init) {
7
+ const host = useHost();
8
+ const value = host[prop];
9
+ const setValue = useCallback((update) => {
10
+ const val = host[prop];
11
+ const newVal = typeof update === 'function' ? update(val) : update;
12
+ if (Object.is(val, newVal)) {
13
+ return;
14
+ }
15
+ notifyProperty(host, prop, newVal);
16
+ }, []);
17
+ const meta = useMeta({ init });
18
+ useEffect(() => {
19
+ const { init } = meta;
20
+ if (init == null)
21
+ return;
22
+ setValue(invoke(init));
23
+ }, []);
24
+ return [value, setValue];
25
+ }
package/dist/promise.js CHANGED
@@ -5,7 +5,7 @@ export class ManagedPromise extends Promise {
5
5
  Object.assign(this, handles);
6
6
  callback?.(handles.resolve, handles.reject);
7
7
  }
8
- // eslint-disable-next-line @typescript-eslint/no-empty-function
8
+ // eslint-disable-next-line no-empty-function
9
9
  resolve = () => { };
10
10
  }
11
11
  export const timeout$ = (ms) => new Promise((res) => setTimeout(res, ms));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "5.34.0",
3
+ "version": "5.36.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",