@neovici/cosmoz-utils 5.0.0 → 5.1.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.
@@ -1,10 +1,19 @@
1
- export class UntilDirective extends AsyncDirective {
2
- __lastRenderedIndex: number;
3
- __values: any[];
4
- __weakThis: PseudoWeakRef;
5
- __pauser: Pauser;
6
- render(...args: any[]): any;
7
- update(_part: any, args: any): any;
1
+ /**
2
+ * @license
3
+ * Copyright 2017 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ import { Part } from 'lit-html';
7
+ import { AsyncDirective } from 'lit-html/async-directive.js';
8
+ export declare class UntilDirective extends AsyncDirective {
9
+ private __lastRenderedIndex;
10
+ private __values;
11
+ private __weakThis;
12
+ private __pauser;
13
+ render(...args: Array<unknown>): unknown;
14
+ update(_part: Part, args: Array<unknown>): unknown;
15
+ disconnected(): void;
16
+ reconnected(): void;
8
17
  }
9
18
  /**
10
19
  * Renders one of a series of values, including Promises, to a Part.
@@ -27,20 +36,8 @@ export class UntilDirective extends AsyncDirective {
27
36
  * html`${until(content, html`<span>Loading...</span>`)}`
28
37
  * ```
29
38
  */
30
- export const lazyUntil: (...values: any[]) => import("lit-html/directive.js").DirectiveResult<typeof UntilDirective>;
31
- import { AsyncDirective } from "lit-html/async-directive.js";
32
- declare class PseudoWeakRef {
33
- constructor(ref: any);
34
- _ref: any;
35
- disconnect(): void;
36
- reconnect(ref: any): void;
37
- deref(): any;
38
- }
39
- declare class Pauser {
40
- _promise: undefined;
41
- _resolve: undefined;
42
- get(): undefined;
43
- pause(): void;
44
- resume(): void;
45
- }
46
- export {};
39
+ export declare const lazyUntil: (...values: unknown[]) => import("lit-html/directive.js").DirectiveResult<typeof UntilDirective>;
40
+ /**
41
+ * The type of the class that powers this directive. Necessary for naming the
42
+ * directive's return type.
43
+ */
@@ -9,6 +9,7 @@ import { directive } from 'lit-html/directive.js';
9
9
  import { isPrimitive } from 'lit-html/directive-helpers.js';
10
10
  import { AsyncDirective } from 'lit-html/async-directive.js';
11
11
  class PseudoWeakRef {
12
+ _ref;
12
13
  constructor(ref) {
13
14
  this._ref = ref;
14
15
  }
@@ -37,10 +38,8 @@ class Pauser {
37
38
  }
38
39
  }
39
40
  const isPromise = (x) => {
40
- return !isPrimitive(x) && typeof x.then === 'function';
41
- },
42
- // Effectively infinity, but a SMI.
43
- _infinity = 0x3fffffff;
41
+ return (!isPrimitive(x) && typeof x.then === 'function');
42
+ }, _infinity = 0x3fffffff;
44
43
  export class UntilDirective extends AsyncDirective {
45
44
  __lastRenderedIndex = _infinity;
46
45
  __values = [];
@@ -1,9 +1,12 @@
1
- export const measure: () => import("lit-html/directive.js").DirectiveResult<typeof MeasureDirective>;
1
+ import { AttributePart } from 'lit-html';
2
+ import { Directive } from 'lit-html/directive.js';
3
+ declare type OnMeasure = (rects: DOMRectReadOnly[]) => void;
4
+ declare type Select = (el: HTMLElement) => HTMLElement[];
2
5
  declare class MeasureDirective extends Directive {
6
+ _observer?: ResizeObserver;
3
7
  render(): symbol;
4
- update(part: any, [select, onMeasure]: [any, any]): symbol;
5
- measure(element: any, select: any, onMeasure: any): symbol;
6
- _observer: ResizeObserver | undefined;
8
+ update(part: AttributePart, [select, onMeasure]: [Select, OnMeasure]): symbol;
9
+ measure(element: HTMLElement, select: Select, onMeasure: OnMeasure): symbol;
7
10
  }
8
- import { Directive } from "lit-html/directive.js";
11
+ export declare const measure: () => import("lit-html/directive.js").DirectiveResult<typeof MeasureDirective>;
9
12
  export {};
@@ -1,13 +1,14 @@
1
- import { nothing } from 'lit-html';
1
+ import { noChange } from 'lit-html';
2
2
  import { Directive, directive } from 'lit-html/directive.js';
3
3
  import { array } from '../array';
4
4
  class MeasureDirective extends Directive {
5
+ _observer;
5
6
  render() {
6
- return nothing;
7
+ return noChange;
7
8
  }
8
9
  update(part, [select, onMeasure]) {
9
10
  this.measure(part.element, select, onMeasure);
10
- return nothing;
11
+ return noChange;
11
12
  }
12
13
  measure(element, select, onMeasure) {
13
14
  this._observer?.disconnect();
@@ -17,7 +18,7 @@ class MeasureDirective extends Directive {
17
18
  .map((e) => e.contentRect));
18
19
  }));
19
20
  elements.forEach((el) => observer.observe(el));
20
- return nothing;
21
+ return noChange;
21
22
  }
22
23
  }
23
24
  export const measure = directive(MeasureDirective);
@@ -1,12 +1,15 @@
1
- export const portal: () => import("lit-html/directive").DirectiveResult<typeof PortalDirective>;
1
+ import { Part, ChildPart } from 'lit-html';
2
+ import { AsyncDirective } from 'lit-html/async-directive.js';
2
3
  declare class PortalDirective extends AsyncDirective {
4
+ _op?: ChildPart;
5
+ _outlet?: HTMLElement;
6
+ _content?: Part;
3
7
  render(): import("lit-html").TemplateResult<1>;
4
- update(part: any, [content, outlet]: [any, (HTMLElement | undefined)?]): import("lit-html").TemplateResult<1>;
5
- updateOutlet(outlet: any, content: any): void;
6
- _outlet: any;
7
- content: any;
8
+ update(part: Part, [content, outlet]: [Part, HTMLElement]): import("lit-html").TemplateResult<1>;
9
+ updateOutlet(outlet: HTMLElement, content: Part): void;
8
10
  clearOutlet(): void;
9
- _op: any;
11
+ disconnected(): void;
12
+ reconnected(): void;
10
13
  }
11
- import { AsyncDirective } from "lit-html/async-directive.js";
14
+ export declare const portal: () => import("lit-html/directive").DirectiveResult<typeof PortalDirective>;
12
15
  export {};
@@ -1,17 +1,22 @@
1
1
  import { html, nothing, render } from 'lit-html';
2
2
  import { AsyncDirective, directive } from 'lit-html/async-directive.js';
3
3
  import { setChildPartValue, clearPart, removePart, } from 'lit-html/directive-helpers.js';
4
- const createMarker = () => document.createComment(''), ChildPart = render(nothing, new DocumentFragment()).constructor;
4
+ const createMarker = () => document.createComment(''), ChildPartC = render(nothing, new DocumentFragment())
5
+ .constructor;
5
6
  /**
6
7
  * Helper element with a customizable disconnect behavior.
7
8
  */
8
9
  class DisconnectObserver extends HTMLElement {
10
+ onDisconnect;
9
11
  disconnectedCallback() {
10
- this.onDisconnect();
12
+ this.onDisconnect?.();
11
13
  }
12
14
  }
13
15
  customElements.define('disconnect-observer', DisconnectObserver);
14
16
  class PortalDirective extends AsyncDirective {
17
+ _op;
18
+ _outlet;
19
+ _content;
15
20
  render() {
16
21
  return html `<disconnect-observer
17
22
  .onDisconnect=${() => {
@@ -29,8 +34,8 @@ class PortalDirective extends AsyncDirective {
29
34
  this.clearOutlet();
30
35
  }
31
36
  this._outlet = outlet;
32
- const part = (this._op ??= new ChildPart(outlet.appendChild(createMarker()), outlet.appendChild(createMarker())));
33
- setChildPartValue(part, (this.content = content));
37
+ const part = (this._op ??= new ChildPartC(outlet.appendChild(createMarker()), outlet.appendChild(createMarker())));
38
+ setChildPartValue(part, (this._content = content));
34
39
  }
35
40
  clearOutlet() {
36
41
  const part = this._op;
@@ -45,7 +50,9 @@ class PortalDirective extends AsyncDirective {
45
50
  this.clearOutlet();
46
51
  }
47
52
  reconnected() {
48
- this.updateOutlet(this._outlet, this._content);
53
+ if (this._outlet && this._content) {
54
+ this.updateOutlet(this._outlet, this._content);
55
+ }
49
56
  }
50
57
  }
51
58
  export const portal = directive(PortalDirective);
@@ -1,8 +1,9 @@
1
- export const spreadProps: () => import("lit-html/directive.js").DirectiveResult<typeof SpreadPropsDirective>;
2
- declare class SpreadPropsDirective extends Directive {
1
+ import { AttributePart } from 'lit-html';
2
+ import { Directive } from 'lit-html/directive.js';
3
+ declare class SpreadPropsDirective<T extends object> extends Directive {
4
+ _props?: T;
3
5
  render(): symbol;
4
- update(part: any, [props]: [any]): symbol;
5
- _props: any;
6
+ update(part: AttributePart, [props]: [T]): symbol;
6
7
  }
7
- import { Directive } from "lit-html/directive.js";
8
+ export declare const spreadProps: () => import("lit-html/directive.js").DirectiveResult<typeof SpreadPropsDirective>;
8
9
  export {};
@@ -1,4 +1,4 @@
1
- import { nothing } from 'lit-html';
1
+ import { noChange } from 'lit-html';
2
2
  import { Directive, directive } from 'lit-html/directive.js';
3
3
  const undefs = (prev, obj) => {
4
4
  if (!prev || !obj) {
@@ -8,14 +8,15 @@ const undefs = (prev, obj) => {
8
8
  return Object.fromEntries(Object.keys(prev).flatMap((k) => (keys.includes(k) ? [] : [[k, undefined]])));
9
9
  };
10
10
  class SpreadPropsDirective extends Directive {
11
+ _props;
11
12
  render() {
12
- return nothing;
13
+ return noChange;
13
14
  }
14
15
  update(part, [props]) {
15
16
  if (this._props !== props) {
16
17
  Object.assign(part.element, undefs(this._props, props), (this._props = props));
17
18
  }
18
- return nothing;
19
+ return noChange;
19
20
  }
20
21
  }
21
22
  export const spreadProps = directive(SpreadPropsDirective);
@@ -1 +1 @@
1
- export function useDroppedFiles(el: any): never[];
1
+ export declare const useDroppedFiles: <T extends HTMLElement>(el: T) => File[];
@@ -1,7 +1,7 @@
1
1
  import { useState, useCallback } from 'haunted';
2
2
  import { useHandleDrop } from './use-handle-drop';
3
- export const useDroppedFiles = el => {
4
- const [files, setFiles] = useState([]), handleDrop = useCallback(event => setFiles(event.dataTransfer.files), [setFiles]);
3
+ export const useDroppedFiles = (el) => {
4
+ const [files, setFiles] = useState([]), handleDrop = useCallback((event) => setFiles(Array.from(event.dataTransfer?.files ?? [])), [setFiles]);
5
5
  useHandleDrop(el, handleDrop);
6
6
  return files;
7
7
  };
@@ -1 +1 @@
1
- export function useHandleDrop(el: any, callback: any): void;
1
+ export declare const useHandleDrop: <T extends HTMLElement>(el: T, callback: (e: DragEvent) => void) => void;
@@ -1,9 +1,9 @@
1
1
  import { useEffect } from 'haunted';
2
2
  export const useHandleDrop = (el, callback) => useEffect(() => {
3
- const dragStop = event => {
3
+ const dragStop = (event) => {
4
4
  event.stopPropagation();
5
5
  event.preventDefault();
6
- }, handleDrop = event => {
6
+ }, handleDrop = (event) => {
7
7
  dragStop(event);
8
8
  callback(event);
9
9
  };
@@ -1 +1 @@
1
- export const useImperativeApi: (api?: any, values?: any) => void;
1
+ export declare const useImperativeApi: <A, D extends unknown[] = unknown[]>(api: A, values: D[]) => void;
@@ -1,5 +1,6 @@
1
1
  import { Hook, hook } from 'haunted';
2
2
  export const useImperativeApi = hook(class extends Hook {
3
+ values;
3
4
  constructor(id, state, api, values) {
4
5
  super(id, state);
5
6
  Object.assign(state.host, api);
@@ -1,2 +1,2 @@
1
- export function notifyProperty(host: any, name: any, value: any): void;
2
- export function useNotifyProperty(name: any, value: any): void;
1
+ declare const notifyProperty: <T extends HTMLElement, K extends Extract<keyof T, string>, V extends T[K]>(host: T, name: K, value: V) => void, useNotifyProperty: <T extends HTMLElement, K extends Extract<keyof T, string>, V extends T[K]>(name: K, value: V) => void;
2
+ export { notifyProperty, useNotifyProperty };
@@ -7,7 +7,9 @@ notifyProperty = (host, name, value) => {
7
7
  // @see https://github.com/Polymer/polymer/blob/76c71e186ecc605294c3575dd31ac7983a8b3ae3/lib/mixins/property-effects.js#L382
8
8
  host[name] = value;
9
9
  // emulate polymer notify event
10
- host.dispatchEvent(new CustomEvent(name.replace(UPPER, '-$1').toLowerCase() + '-changed', { detail: { value } }));
10
+ host.dispatchEvent(new CustomEvent(name.replace(UPPER, '-$1').toLowerCase() + '-changed', {
11
+ detail: { value },
12
+ }));
11
13
  }, useNotifyProperty = (name, value) => {
12
14
  const host = useHost();
13
15
  useEffect(() => {
@@ -1,8 +1,13 @@
1
- export function action(type: any, create?: () => {}): ((...args: any[]) => {
2
- type: any;
3
- toString(): any;
1
+ declare type Creator<T extends [], R extends object> = (...args: T) => R;
2
+ export interface Action<T = unknown> {
3
+ type?: T;
4
+ toString: () => string;
5
+ }
6
+ declare const action: <T, A extends [], R extends object>(type: T, create?: Creator<A, R>) => ((...args: A) => R & {
7
+ type: T;
8
+ toString(): T;
4
9
  }) & {
5
- type: any;
6
- toString(): any;
7
- };
8
- export function type(action: any): any;
10
+ type: T;
11
+ toString(): T;
12
+ }, type: <T>(action: Action<T>) => string | T;
13
+ export { action, type };
@@ -3,8 +3,8 @@ const action = (type, create = () => ({})) => {
3
3
  type,
4
4
  toString() {
5
5
  return type;
6
- }
6
+ },
7
7
  }, callable = (...args) => Object.assign(create(...args), common);
8
8
  return Object.assign(callable, common);
9
- }, type = action => action.type || action.toString();
9
+ }, type = (action) => action.type || action.toString();
10
10
  export { action, type };
@@ -1,2 +1,2 @@
1
- export * from "./action";
2
- export * from "./reduce";
1
+ export * from './action';
2
+ export * from './reduce';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",