@fluid-topics/ft-wc-utils 2.0.26 → 2.0.28

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,7 +1,7 @@
1
1
  export declare class CanceledPromiseError<T> extends Error {
2
- canceledPromiseResult?: T | PromiseLike<T> | undefined;
3
- canceledPromiseError?: any;
4
- constructor(message: string, canceledPromiseResult?: T | PromiseLike<T> | undefined, canceledPromiseError?: any);
2
+ canceledPromiseResult?: (T | PromiseLike<T>) | undefined;
3
+ canceledPromiseError?: any | undefined;
4
+ constructor(message: string, canceledPromiseResult?: (T | PromiseLike<T>) | undefined, canceledPromiseError?: any | undefined);
5
5
  }
6
6
  export declare class CancelablePromise<T> extends Promise<T> {
7
7
  isCanceled: boolean;
@@ -18,5 +18,12 @@ export type ElementDefinitionsMap = {
18
18
  export declare class ScopedRegistryLitElement extends LitElement {
19
19
  static elementDefinitions?: ElementDefinitionsMap;
20
20
  static registry?: CustomElementRegistry;
21
+ private get scopedRegistryConstructor();
21
22
  createRenderRoot(): ShadowRoot;
23
+ static canDefineScopedElement(tagName: string): boolean;
24
+ static defineScopedElements(definitions: ElementDefinitionsMap): void;
25
+ static defineScopedElement(tagName: string, klass: typeof HTMLElement): void;
26
+ canDefineScopedElement(tagName: string): boolean;
27
+ defineScopedElements(definitions: ElementDefinitionsMap): void;
28
+ defineScopedElement(tagName: string, klass: typeof HTMLElement): void;
22
29
  }
@@ -6,11 +6,14 @@ import { adoptStyles } from "@lit/reactive-element/css-tag.js";
6
6
  * From https://github.com/lit/lit/blob/main/packages/labs/scoped-registry-mixin/
7
7
  */
8
8
  export class ScopedRegistryLitElement extends LitElement {
9
+ get scopedRegistryConstructor() {
10
+ return this.constructor;
11
+ }
9
12
  createRenderRoot() {
10
- const constructor = this.constructor;
13
+ const constructor = this.scopedRegistryConstructor;
11
14
  if (constructor.elementDefinitions && !constructor.registry) {
12
15
  constructor.registry = new CustomElementRegistry();
13
- Object.entries(constructor.elementDefinitions).forEach(([tagName, klass]) => constructor.registry.define(tagName, klass));
16
+ constructor.defineScopedElements(constructor.elementDefinitions);
14
17
  }
15
18
  const init = {
16
19
  ...constructor.shadowRootOptions,
@@ -20,4 +23,24 @@ export class ScopedRegistryLitElement extends LitElement {
20
23
  adoptStyles(renderRoot, constructor.elementStyles);
21
24
  return renderRoot;
22
25
  }
26
+ static canDefineScopedElement(tagName) {
27
+ return !!this.registry && !this.registry.get(tagName);
28
+ }
29
+ static defineScopedElements(definitions) {
30
+ Object.entries(definitions).forEach(([tagName, klass]) => this.defineScopedElement(tagName, klass));
31
+ }
32
+ static defineScopedElement(tagName, klass) {
33
+ if (this.canDefineScopedElement(tagName)) {
34
+ this.registry.define(tagName, klass);
35
+ }
36
+ }
37
+ canDefineScopedElement(tagName) {
38
+ return this.scopedRegistryConstructor.canDefineScopedElement(tagName);
39
+ }
40
+ defineScopedElements(definitions) {
41
+ this.scopedRegistryConstructor.defineScopedElements(definitions);
42
+ }
43
+ defineScopedElement(tagName, klass) {
44
+ this.scopedRegistryConstructor.defineScopedElement(tagName, klass);
45
+ }
23
46
  }
@@ -1,24 +1,23 @@
1
1
  import { property } from "lit/decorators.js";
2
- import { hasChanged, minmax } from "./helpers";
2
+ import { deepCopy, hasChanged, minmax, } from "./helpers";
3
3
  export const customElement = (tagName) => (clazz) => {
4
4
  if (!window.customElements.get(tagName)) {
5
5
  window.customElements.define(tagName, clazz);
6
6
  }
7
7
  };
8
8
  export function jsonProperty(defaultValue, options) {
9
- const fallback = () => JSON.parse(JSON.stringify(defaultValue));
10
9
  return property({
11
10
  type: Object,
12
11
  converter: {
13
12
  fromAttribute: (value) => {
14
13
  if (value == null) {
15
- return fallback();
14
+ return deepCopy(defaultValue);
16
15
  }
17
16
  try {
18
17
  return JSON.parse(value);
19
18
  }
20
19
  catch {
21
- return fallback();
20
+ return deepCopy(defaultValue);
22
21
  }
23
22
  },
24
23
  toAttribute: (value) => {