@patternfly/pfe-core 2.4.1 → 4.0.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.
Files changed (104) hide show
  1. package/README.md +0 -1
  2. package/controllers/activedescendant-controller.d.ts +99 -0
  3. package/controllers/activedescendant-controller.js +230 -0
  4. package/controllers/activedescendant-controller.js.map +1 -0
  5. package/controllers/at-focus-controller.d.ts +56 -0
  6. package/controllers/at-focus-controller.js +168 -0
  7. package/controllers/at-focus-controller.js.map +1 -0
  8. package/controllers/cascade-controller.d.ts +11 -0
  9. package/controllers/cascade-controller.js +10 -3
  10. package/controllers/cascade-controller.js.map +1 -1
  11. package/controllers/combobox-controller.d.ts +117 -0
  12. package/controllers/combobox-controller.js +611 -0
  13. package/controllers/combobox-controller.js.map +1 -0
  14. package/controllers/css-variable-controller.js +1 -1
  15. package/controllers/css-variable-controller.js.map +1 -1
  16. package/controllers/floating-dom-controller.d.ts +10 -3
  17. package/controllers/floating-dom-controller.js +93 -83
  18. package/controllers/floating-dom-controller.js.map +1 -1
  19. package/controllers/internals-controller.d.ts +104 -42
  20. package/controllers/internals-controller.js +354 -36
  21. package/controllers/internals-controller.js.map +1 -1
  22. package/controllers/light-dom-controller.js +2 -2
  23. package/controllers/light-dom-controller.js.map +1 -1
  24. package/controllers/listbox-controller.d.ts +143 -0
  25. package/controllers/listbox-controller.js +443 -0
  26. package/controllers/listbox-controller.js.map +1 -0
  27. package/controllers/logger.d.ts +33 -6
  28. package/controllers/logger.js +58 -13
  29. package/controllers/logger.js.map +1 -1
  30. package/controllers/overflow-controller.d.ts +10 -3
  31. package/controllers/overflow-controller.js +79 -44
  32. package/controllers/overflow-controller.js.map +1 -1
  33. package/controllers/perf-controller.js.map +1 -1
  34. package/controllers/property-observer-controller.d.ts +13 -16
  35. package/controllers/property-observer-controller.js +55 -27
  36. package/controllers/property-observer-controller.js.map +1 -1
  37. package/controllers/roving-tabindex-controller.d.ts +19 -50
  38. package/controllers/roving-tabindex-controller.js +64 -183
  39. package/controllers/roving-tabindex-controller.js.map +1 -1
  40. package/controllers/scroll-spy-controller.d.ts +4 -1
  41. package/controllers/scroll-spy-controller.js +94 -93
  42. package/controllers/scroll-spy-controller.js.map +1 -1
  43. package/controllers/slot-controller.d.ts +26 -19
  44. package/controllers/slot-controller.js +94 -83
  45. package/controllers/slot-controller.js.map +1 -1
  46. package/controllers/style-controller.js +3 -1
  47. package/controllers/style-controller.js.map +1 -1
  48. package/controllers/tabs-aria-controller.d.ts +31 -0
  49. package/controllers/tabs-aria-controller.js +97 -0
  50. package/controllers/tabs-aria-controller.js.map +1 -0
  51. package/controllers/test/combobox-controller.spec.d.ts +1 -0
  52. package/controllers/test/combobox-controller.spec.js +282 -0
  53. package/controllers/test/combobox-controller.spec.js.map +1 -0
  54. package/controllers/timestamp-controller.js +73 -70
  55. package/controllers/timestamp-controller.js.map +1 -1
  56. package/core.d.ts +3 -23
  57. package/core.js +1 -38
  58. package/core.js.map +1 -1
  59. package/custom-elements.json +7302 -2817
  60. package/decorators/bound.d.ts +3 -1
  61. package/decorators/bound.js +3 -1
  62. package/decorators/bound.js.map +1 -1
  63. package/decorators/cascades.d.ts +2 -0
  64. package/decorators/cascades.js +2 -0
  65. package/decorators/cascades.js.map +1 -1
  66. package/decorators/deprecation.d.ts +6 -5
  67. package/decorators/deprecation.js +6 -5
  68. package/decorators/deprecation.js.map +1 -1
  69. package/decorators/initializer.js.map +1 -1
  70. package/decorators/listen.d.ts +8 -0
  71. package/decorators/listen.js +22 -0
  72. package/decorators/listen.js.map +1 -0
  73. package/decorators/observed.d.ts +12 -16
  74. package/decorators/observed.js +39 -44
  75. package/decorators/observed.js.map +1 -1
  76. package/decorators/observes.d.ts +15 -0
  77. package/decorators/observes.js +30 -0
  78. package/decorators/observes.js.map +1 -0
  79. package/decorators/time.d.ts +1 -0
  80. package/decorators/time.js +6 -9
  81. package/decorators/time.js.map +1 -1
  82. package/decorators/trace.d.ts +4 -1
  83. package/decorators/trace.js +4 -1
  84. package/decorators/trace.js.map +1 -1
  85. package/decorators.d.ts +2 -0
  86. package/decorators.js +2 -0
  87. package/decorators.js.map +1 -1
  88. package/functions/arraysAreEquivalent.d.ts +9 -0
  89. package/functions/arraysAreEquivalent.js +28 -0
  90. package/functions/arraysAreEquivalent.js.map +1 -0
  91. package/functions/containsDeep.d.ts +8 -0
  92. package/functions/containsDeep.js +23 -0
  93. package/functions/containsDeep.js.map +1 -0
  94. package/functions/context.d.ts +8 -0
  95. package/functions/context.js +21 -0
  96. package/functions/context.js.map +1 -0
  97. package/functions/debounce.js.map +1 -1
  98. package/functions/isElementInView.d.ts +4 -6
  99. package/functions/isElementInView.js +9 -11
  100. package/functions/isElementInView.js.map +1 -1
  101. package/package.json +10 -4
  102. package/functions/deprecatedCustomEvent.d.ts +0 -5
  103. package/functions/deprecatedCustomEvent.js +0 -12
  104. package/functions/deprecatedCustomEvent.js.map +0 -1
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Binds a class method to the instance
3
- *
3
+ * @param _
4
+ * @param key
5
+ * @param descriptor
4
6
  * @example Binding an event listener
5
7
  * ```ts
6
8
  * private mo = new MutationObserver(this.onMutation);
@@ -1,7 +1,9 @@
1
1
  const configurable = true;
2
2
  /**
3
3
  * Binds a class method to the instance
4
- *
4
+ * @param _
5
+ * @param key
6
+ * @param descriptor
5
7
  * @example Binding an event listener
6
8
  * ```ts
7
9
  * private mo = new MutationObserver(this.onMutation);
@@ -1 +1 @@
1
- {"version":3,"file":"bound.js","sourceRoot":"","sources":["bound.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,KAAK,CAAC,CAAU,EAAE,GAAW,EAAE,UAA8B;IAC3E,IAAI,OAAO,UAAU,EAAE,KAAK,KAAK,UAAU,EAAE;QAC3C,MAAM,IAAI,SAAS,CAAC,+CAA+C,GAAG,IAAK,CAAgB,CAAC,IAAI,oBAAoB,CAAC,CAAC;KACvH,CAAC,oBAAoB;IACtB,OAAO;QACL,YAAY;QACZ,GAAG;YACD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["const configurable = true;\n\n/**\n * Binds a class method to the instance\n *\n * @example Binding an event listener\n * ```ts\n * private mo = new MutationObserver(this.onMutation);\n *\n * @bound onMutation(records: MutationRecord[]) {\n * this.count = this.children.length;\n * }\n * ```\n */\nexport function bound(_: unknown, key: string, descriptor: PropertyDescriptor): PropertyDescriptor {\n if (typeof descriptor?.value !== 'function') {\n throw new TypeError(`Only methods can be decorated with @bound. <${key ?? (_ as () => void).name}> is not a method!`);\n } /* c8 ignore next */\n return {\n configurable,\n get() {\n const value = descriptor.value.bind(this);\n Object.defineProperty(this, key, { value, configurable, writable: true });\n return value;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"bound.js","sourceRoot":"","sources":["bound.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,KAAK,CAAC,CAAU,EAAE,GAAW,EAAE,UAA8B;IAC3E,IAAI,OAAO,UAAU,EAAE,KAAK,KAAK,UAAU,EAAE,CAAC;QAC5C,MAAM,IAAI,SAAS,CAAC,+CAA+C,GAAG,IAAK,CAAgB,CAAC,IAAI,oBAAoB,CAAC,CAAC;IACxH,CAAC,CAAC,oBAAoB;IACtB,OAAO;QACL,YAAY;QACZ,GAAG;YACD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["const configurable = true;\n\n/**\n * Binds a class method to the instance\n * @param _\n * @param key\n * @param descriptor\n * @example Binding an event listener\n * ```ts\n * private mo = new MutationObserver(this.onMutation);\n *\n * @bound onMutation(records: MutationRecord[]) {\n * this.count = this.children.length;\n * }\n * ```\n */\nexport function bound(_: unknown, key: string, descriptor: PropertyDescriptor): PropertyDescriptor {\n if (typeof descriptor?.value !== 'function') {\n throw new TypeError(`Only methods can be decorated with @bound. <${key ?? (_ as () => void).name}> is not a method!`);\n } /* c8 ignore next */\n return {\n configurable,\n get() {\n const value = descriptor.value.bind(this);\n Object.defineProperty(this, key, { value, configurable, writable: true });\n return value;\n },\n };\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { ReactiveElement } from 'lit';
2
2
  /**
3
3
  * Cascades the decorated attribute to children
4
+ * @param items
5
+ * @deprecated use context, especially via `@patternfly/pfe-core/functions/context.js`;
4
6
  */
5
7
  export declare function cascades<T extends ReactiveElement>(...items: string[]): PropertyDecorator;
@@ -1,6 +1,8 @@
1
1
  import { CascadeController } from '../controllers/cascade-controller.js';
2
2
  /**
3
3
  * Cascades the decorated attribute to children
4
+ * @param items
5
+ * @deprecated use context, especially via `@patternfly/pfe-core/functions/context.js`;
4
6
  */
5
7
  export function cascades(...items) {
6
8
  return function (proto, key) {
@@ -1 +1 @@
1
- {"version":3,"file":"cascades.js","sourceRoot":"","sources":["cascades.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE;;GAEG;AACH,MAAM,UAAU,QAAQ,CAA4B,GAAG,KAAe;IACpE,OAAO,UAAS,KAAQ,EAAE,GAAqB;QAC5C,KAAK,CAAC,WAAsC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;YAC/D,MAAM,QAAQ,GAAG,CAAoB,CAAC;YACtC,6DAA6D;YAC7D,6DAA6D;YAC7D,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;gBAC9C,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;aAC5E;YAED,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAsB,CAAC;AACzB,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\n\nimport { CascadeController } from '../controllers/cascade-controller.js';\n\n/**\n * Cascades the decorated attribute to children\n */\nexport function cascades<T extends ReactiveElement>(...items: string[]): PropertyDecorator {\n return function(proto: T, key: string & keyof T) {\n (proto.constructor as typeof ReactiveElement).addInitializer(x => {\n const instance = x as ReactiveElement;\n // You can have multiple `@cascades` decorators on an element\n // and it will only get one CascadeController for all of them\n if (!CascadeController.instances.has(instance)) {\n CascadeController.instances.set(instance, new CascadeController(instance));\n }\n\n CascadeController.instances.get(instance)?.initProp(key, items);\n });\n } as PropertyDecorator;\n}\n"]}
1
+ {"version":3,"file":"cascades.js","sourceRoot":"","sources":["cascades.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAA4B,GAAG,KAAe;IACpE,OAAO,UAAS,KAAQ,EAAE,GAAqB;QAC5C,KAAK,CAAC,WAAsC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE;YAC/D,MAAM,QAAQ,GAAG,CAAoB,CAAC;YACtC,6DAA6D;YAC7D,6DAA6D;YAC7D,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC/C,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC7E,CAAC;YAED,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAsB,CAAC;AACzB,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\n\nimport { CascadeController } from '../controllers/cascade-controller.js';\n\n/**\n * Cascades the decorated attribute to children\n * @param items\n * @deprecated use context, especially via `@patternfly/pfe-core/functions/context.js`;\n */\nexport function cascades<T extends ReactiveElement>(...items: string[]): PropertyDecorator {\n return function(proto: T, key: string & keyof T) {\n (proto.constructor as typeof ReactiveElement).addInitializer(x => {\n const instance = x as ReactiveElement;\n // You can have multiple `@cascades` decorators on an element\n // and it will only get one CascadeController for all of them\n if (!CascadeController.instances.has(instance)) {\n CascadeController.instances.set(instance, new CascadeController(instance));\n }\n\n CascadeController.instances.get(instance)?.initProp(key, items);\n });\n } as PropertyDecorator;\n}\n"]}
@@ -5,12 +5,13 @@ export type DeprecationDeclaration<K extends PropertyKey> = PropertyDeclaration
5
5
  };
6
6
  /**
7
7
  * Aliases the decorated field to an existing property, and logs a warning if it is used
8
+ * @param options alias is a drop in replacement
8
9
  * @example deprecating an attribute
9
- * ```ts
10
- * @property({ reflect: true, attribute: 'color-palette'})
11
- * colorPalette: ColorPalette = 'base';
10
+ * ```ts
11
+ * @property({ reflect: true, attribute: 'color-palette'})
12
+ * colorPalette: ColorPalette = 'base';
12
13
  *
13
- * @deprecation('colorPalette') color?: ColorPalette;
14
- * ```
14
+ * @deprecation('colorPalette') color?: ColorPalette;
15
+ * ```
15
16
  */
16
17
  export declare function deprecation<K extends PropertyKey>(options: DeprecationDeclaration<K>): <T extends ReactiveElement, L extends PropertyKey>(proto: Partial<Record<K | L, T>>, key: string & keyof T) => void;
@@ -1,13 +1,14 @@
1
1
  import { Logger } from '../controllers/logger.js';
2
2
  /**
3
3
  * Aliases the decorated field to an existing property, and logs a warning if it is used
4
+ * @param options alias is a drop in replacement
4
5
  * @example deprecating an attribute
5
- * ```ts
6
- * @property({ reflect: true, attribute: 'color-palette'})
7
- * colorPalette: ColorPalette = 'base';
6
+ * ```ts
7
+ * @property({ reflect: true, attribute: 'color-palette'})
8
+ * colorPalette: ColorPalette = 'base';
8
9
  *
9
- * @deprecation('colorPalette') color?: ColorPalette;
10
- * ```
10
+ * @deprecation('colorPalette') color?: ColorPalette;
11
+ * ```
11
12
  */
12
13
  export function deprecation(options) {
13
14
  return function (proto, key) {
@@ -1 +1 @@
1
- {"version":3,"file":"deprecation.js","sourceRoot":"","sources":["deprecation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAOlD;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAwB,OAAkC;IACnF,OAAO,UACL,KAAgC,EAChC,GAAqB;QAErB,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;QACjD,MAAM,KAAK,GAAI,KAAK,CAAC,WAAsC,CAAC;QAC5D,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACpD,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAC,CAAC;QACrE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YAC9B,QAAQ,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAa,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,WAAW;IAKf,YACU,IAAO,EACP,OAAkC,EAClC,aAA+B;QAF/B,SAAI,GAAJ,IAAI,CAAG;QACP,YAAO,GAAP,OAAO,CAA2B;QAClC,kBAAa,GAAb,aAAa,CAAkB;QALjC,WAAM,GAAG,KAAK,CAAC;QAOrB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,UAAU;QACR,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC;QACnD,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;YAC5B,IAAI,IAAI,CAAC,IAAI,CAAC,KAAgB,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;gBAC5D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;oBAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,uBAAuB,KAAK,UAAU,CAAC,CAAC;oBACzE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;iBACpB;gBACD,IAAI,CAAC,IAAI,CAAC,KAAgB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aACxD;SACF;IACH,CAAC;CACF","sourcesContent":["import type { ReactiveElement, PropertyDeclaration, ReactiveController } from 'lit';\n\nimport { Logger } from '../controllers/logger.js';\n\nexport type DeprecationDeclaration<K extends PropertyKey> = PropertyDeclaration & {\n alias: string & K;\n attribute: string;\n}\n\n/**\n * Aliases the decorated field to an existing property, and logs a warning if it is used\n * @example deprecating an attribute\n * ```ts\n * @property({ reflect: true, attribute: 'color-palette'})\n * colorPalette: ColorPalette = 'base';\n *\n * @deprecation('colorPalette') color?: ColorPalette;\n * ```\n */\nexport function deprecation<K extends PropertyKey>(options: DeprecationDeclaration<K>) {\n return function<T extends ReactiveElement, L extends PropertyKey>(\n proto: Partial<Record<K | L, T>>,\n key: string & keyof T\n ) {\n const { alias, ...deprecationOptions } = options;\n const klass = (proto.constructor as typeof ReactiveElement);\n const declaration = klass.getPropertyOptions(alias);\n klass.createProperty(key, { ...declaration, ...deprecationOptions });\n klass.addInitializer(instance => {\n instance.addController(new Deprecation(instance as T, options, key));\n });\n };\n}\n\nclass Deprecation<T extends ReactiveElement, K extends PropertyKey> implements ReactiveController {\n private logger: Logger;\n\n private logged = false;\n\n constructor(\n private host: T,\n private options: DeprecationDeclaration<K>,\n private deprecatedKey: string & keyof T\n ) {\n this.logger = new Logger(host);\n }\n\n hostUpdate() {\n const { deprecatedKey, options: { alias } } = this;\n if (this.host[deprecatedKey]) {\n if (this.host[alias as keyof T] !== this.host[deprecatedKey]) {\n if (!this.logged) {\n this.logger.warn(`${deprecatedKey} is deprecated, use ${alias} instead`);\n this.logged = true;\n }\n this.host[alias as keyof T] = this.host[deprecatedKey];\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"deprecation.js","sourceRoot":"","sources":["deprecation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAOlD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,OAAkC;IAElC,OAAO,UACL,KAAgC,EAChC,GAAqB;QAErB,MAAM,EAAE,KAAK,EAAE,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;QACjD,MAAM,KAAK,GAAI,KAAK,CAAC,WAAsC,CAAC;QAC5D,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACpD,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,kBAAkB,EAAE,CAAC,CAAC;QACrE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YAC9B,QAAQ,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAa,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,WAAW;IAKf,YACU,IAAO,EACP,OAAkC,EAClC,aAA+B;QAF/B,SAAI,GAAJ,IAAI,CAAG;QACP,YAAO,GAAP,OAAO,CAA2B;QAClC,kBAAa,GAAb,aAAa,CAAkB;QALjC,WAAM,GAAG,KAAK,CAAC;QAOrB,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,UAAU;QACR,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC;QACnD,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,IAAI,CAAC,KAAgB,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC7D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;oBACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,uBAAuB,KAAK,UAAU,CAAC,CAAC;oBACzE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;gBACrB,CAAC;gBACD,IAAI,CAAC,IAAI,CAAC,KAAgB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { ReactiveElement, PropertyDeclaration, ReactiveController } from 'lit';\n\nimport { Logger } from '../controllers/logger.js';\n\nexport type DeprecationDeclaration<K extends PropertyKey> = PropertyDeclaration & {\n alias: string & K;\n attribute: string;\n};\n\n/**\n * Aliases the decorated field to an existing property, and logs a warning if it is used\n * @param options alias is a drop in replacement\n * @example deprecating an attribute\n * ```ts\n * @property({ reflect: true, attribute: 'color-palette'})\n * colorPalette: ColorPalette = 'base';\n *\n * @deprecation('colorPalette') color?: ColorPalette;\n * ```\n */\nexport function deprecation<K extends PropertyKey>(\n options: DeprecationDeclaration<K>,\n) {\n return function<T extends ReactiveElement, L extends PropertyKey>(\n proto: Partial<Record<K | L, T>>,\n key: string & keyof T\n ): void {\n const { alias, ...deprecationOptions } = options;\n const klass = (proto.constructor as typeof ReactiveElement);\n const declaration = klass.getPropertyOptions(alias);\n klass.createProperty(key, { ...declaration, ...deprecationOptions });\n klass.addInitializer(instance => {\n instance.addController(new Deprecation(instance as T, options, key));\n });\n };\n}\n\nclass Deprecation<T extends ReactiveElement, K extends PropertyKey> implements ReactiveController {\n private logger: Logger;\n\n private logged = false;\n\n constructor(\n private host: T,\n private options: DeprecationDeclaration<K>,\n private deprecatedKey: string & keyof T\n ) {\n this.logger = new Logger(host);\n }\n\n hostUpdate() {\n const { deprecatedKey, options: { alias } } = this;\n if (this.host[deprecatedKey]) {\n if (this.host[alias as keyof T] !== this.host[deprecatedKey]) {\n if (!this.logged) {\n this.logger.warn(`${deprecatedKey} is deprecated, use ${alias} instead`);\n this.logged = true;\n }\n this.host[alias as keyof T] = this.host[deprecatedKey];\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"initializer.js","sourceRoot":"","sources":["initializer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAA4B,OAAiB;IACtE,OAAO,UAAS,KAAQ,EAAE,GAAW;QACnC,qCAAqC;QACpC,KAAK,CAAC,WAAsC,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YACtE,MAAM,WAAW,GAAG,KAAK,CAAC,GAAc,CAA0B,CAAC;YACnE,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,QAA2B,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;YAC7F,IAAI,QAAQ,CAAC,WAAW,EAAE;gBACxB,UAAU,CAAC,aAAa,EAAE,CAAC;aAC5B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\nimport type { Options } from '../controllers/light-dom-controller.js';\n\nimport { LightDOMController } from '../controllers/light-dom-controller.js';\n\n/**\n * Runs the decorated method in `connectedCallback`,\n * provided the element has light children, and sets\n * up a mutation observer to re-run the callback,\n * unless opted-out with `{ observe: false }`\n * @param options Set `observe` to `false` to skip mutation observer setup, or pass a MutationObserverInit as options\n */\nexport function initializer<T extends ReactiveElement>(options?: Options) {\n return function(proto: T, key: string) {\n // @TODO: allow multiple initializers\n (proto.constructor as typeof ReactiveElement).addInitializer(instance => {\n const initializer = proto[key as keyof T] as unknown as () => void;\n const controller = new LightDOMController(instance as ReactiveElement, initializer, options);\n if (instance.isConnected) {\n controller.hostConnected();\n }\n });\n };\n}\n"]}
1
+ {"version":3,"file":"initializer.js","sourceRoot":"","sources":["initializer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAA4B,OAAiB;IACtE,OAAO,UAAS,KAAQ,EAAE,GAAW;QACnC,qCAAqC;QACpC,KAAK,CAAC,WAAsC,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YACtE,MAAM,WAAW,GAAG,KAAK,CAAC,GAAc,CAA0B,CAAC;YACnE,MAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,QAA2B,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;YAC7F,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;gBACzB,UAAU,CAAC,aAAa,EAAE,CAAC;YAC7B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\nimport type { Options } from '../controllers/light-dom-controller.js';\n\nimport { LightDOMController } from '../controllers/light-dom-controller.js';\n\n/**\n * Runs the decorated method in `connectedCallback`,\n * provided the element has light children, and sets\n * up a mutation observer to re-run the callback,\n * unless opted-out with `{ observe: false }`\n * @param options Set `observe` to `false` to skip mutation observer setup, or pass a MutationObserverInit as options\n */\nexport function initializer<T extends ReactiveElement>(options?: Options) {\n return function(proto: T, key: string): void {\n // @TODO: allow multiple initializers\n (proto.constructor as typeof ReactiveElement).addInitializer(instance => {\n const initializer = proto[key as keyof T] as unknown as () => void;\n const controller = new LightDOMController(instance as ReactiveElement, initializer, options);\n if (instance.isConnected) {\n controller.hostConnected();\n }\n });\n };\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { LitElement } from 'lit';
2
+ /**
3
+ * Listens for a given event on the custom element.
4
+ * equivalent to calling `this.addEventListener` in the constructor
5
+ * @param type event type e.g. `click`
6
+ * @param options event listener options object e.g. `{ passive: true }`
7
+ */
8
+ export declare function listen<P extends LitElement>(type: keyof HTMLElementEventMap, options?: AddEventListenerOptions): (proto: LitElement, methodName: string) => void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Listens for a given event on the custom element.
3
+ * equivalent to calling `this.addEventListener` in the constructor
4
+ * @param type event type e.g. `click`
5
+ * @param options event listener options object e.g. `{ passive: true }`
6
+ */
7
+ export function listen(type, options) {
8
+ return function (proto, methodName) {
9
+ const origConnected = proto.connectedCallback;
10
+ const origDisconnected = proto.disconnectedCallback;
11
+ const listener = proto[methodName];
12
+ proto.connectedCallback = function () {
13
+ origConnected?.call(this);
14
+ this.addEventListener(type, listener, options);
15
+ };
16
+ proto.disconnectedCallback = function () {
17
+ origDisconnected?.call(this);
18
+ this.removeEventListener(type, listener, options);
19
+ };
20
+ };
21
+ }
22
+ //# sourceMappingURL=listen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listen.js","sourceRoot":"","sources":["listen.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CACpB,IAA+B,EAC/B,OAAiC;IAEjC,OAAO,UACL,KAAiB,EACjB,UAAkB;QAElB,MAAM,aAAa,GAAG,KAAK,CAAC,iBAAiB,CAAC;QAC9C,MAAM,gBAAgB,GAAG,KAAK,CAAC,oBAAoB,CAAC;QACpD,MAAM,QAAQ,GAAI,KAAW,CAAC,UAAqB,CAAkB,CAAC;QACtE,KAAK,CAAC,iBAAiB,GAAG;YACxB,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC;QACF,KAAK,CAAC,oBAAoB,GAAG;YAC3B,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { LitElement } from 'lit';\n\n/**\n * Listens for a given event on the custom element.\n * equivalent to calling `this.addEventListener` in the constructor\n * @param type event type e.g. `click`\n * @param options event listener options object e.g. `{ passive: true }`\n */\nexport function listen<P extends LitElement>(\n type: keyof HTMLElementEventMap,\n options?: AddEventListenerOptions,\n) {\n return function(\n proto: LitElement,\n methodName: string,\n ): void {\n const origConnected = proto.connectedCallback;\n const origDisconnected = proto.disconnectedCallback;\n const listener = (proto as P)[methodName as keyof P] as EventListener;\n proto.connectedCallback = function() {\n origConnected?.call(this);\n this.addEventListener(type, listener, options);\n };\n proto.disconnectedCallback = function() {\n origDisconnected?.call(this);\n this.removeEventListener(type, listener, options);\n };\n };\n}\n"]}
@@ -6,28 +6,24 @@ type TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void;
6
6
  * Works on any class field. When using on lit observed properties,
7
7
  * Make sure `@observed` is to the left (i.e. called after) the `@property`
8
8
  * or `@state` decorator.
9
- *
10
9
  * @example observing a lit property
11
- * ```ts
12
- * @observed @property() foo = 'bar';
13
- *
14
- * protected _fooChanged(oldValue?: string, newValue?: string) {}
15
- * ```
10
+ * ```ts
11
+ * @observed @property() foo = 'bar';
16
12
  *
13
+ * protected _fooChanged(oldValue?: string, newValue?: string) {}
14
+ * ```
17
15
  * @example using a custom callback
18
- * ```ts
19
- * @observed('_myCallback') size = 'lg';
20
- *
21
- * _myCallback(_, size) {...}
22
- * ```
16
+ * ```ts
17
+ * @observed('_myCallback') size = 'lg';
23
18
  *
19
+ * _myCallback(_, size) {...}
20
+ * ```
24
21
  * @example using an arrow function
25
- * ```ts
26
- * @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))
27
- * ```
22
+ * ```ts
23
+ * @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))
24
+ * ```
28
25
  */
26
+ export declare function observed<T extends ReactiveElement, V>(cb: ChangeCallback<T, V>): TypedFieldDecorator<T>;
29
27
  export declare function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>;
30
- export declare function observed<T extends ReactiveElement>(cb: ChangeCallback<T>): TypedFieldDecorator<T>;
31
28
  export declare function observed<T extends ReactiveElement>(proto: T, key: string): void;
32
- export declare function observeProperty<T extends ReactiveElement>(proto: T, key: string & keyof T, callbackOrMethod?: ChangeCallback<T>): void;
33
29
  export {};
@@ -1,52 +1,47 @@
1
- import { observedController, PropertyObserverController, } from '../controllers/property-observer-controller.js';
1
+ import { PropertyObserverController } from '../controllers/property-observer-controller.js';
2
+ // eslint-disable-next-line jsdoc/require-jsdoc
2
3
  export function observed(...as) {
3
- /** @observed('_myCustomChangeCallback') */
4
4
  if (as.length === 1) {
5
- const [methodNameOrCallback] = as;
6
- return function (proto, key) {
7
- proto.constructor
8
- .addInitializer(x => new PropertyObserverController(x));
9
- observeProperty(proto, key, methodNameOrCallback);
10
- };
5
+ const [methodNameOrCb] = as;
6
+ return configuredDecorator(methodNameOrCb);
11
7
  }
12
8
  else {
13
- const [proto, key] = as;
14
- proto.constructor
15
- .addInitializer(x => new PropertyObserverController(x));
16
- observeProperty(proto, key);
9
+ return executeBareDecorator(...as);
17
10
  }
18
11
  }
19
- export function observeProperty(proto, key, callbackOrMethod) {
20
- const descriptor = Object.getOwnPropertyDescriptor(proto, key);
21
- Object.defineProperty(proto, key, {
22
- ...descriptor,
23
- configurable: true,
24
- set(newVal) {
25
- const oldVal = this[key];
26
- // first, call any pre-existing setters, e.g. `@property`
27
- descriptor?.set?.call(this, newVal);
28
- // if the user passed a callback, call it
29
- // e.g. `@observed((_, newVal) => console.log(newVal))`
30
- // safe to call before connectedCallback, because it's impossible to get a `this` ref.
31
- if (typeof callbackOrMethod === 'function') {
32
- callbackOrMethod.call(this, oldVal, newVal);
33
- }
34
- else {
35
- // if the user passed a string method name, call it on `this`
36
- // e.g. `@observed('_renderOptions')`
37
- // otherwise, use a default method name e.g. `_fooChanged`
38
- const actualMethodName = callbackOrMethod || `_${key}Changed`;
39
- // if the component has already connected to the DOM, run the callback
40
- // otherwise, If the component has not yet connected to the DOM,
41
- // cache the old and new values. See PropertyObserverController above
42
- if (this.hasUpdated) {
43
- this[actualMethodName]?.(oldVal, newVal);
44
- }
45
- else {
46
- this[observedController].cache(key, actualMethodName, oldVal, newVal);
47
- }
48
- }
49
- },
50
- });
12
+ /**
13
+ * @param proto element prototype
14
+ * @param propertyName propertyName
15
+ * @example ```typescript
16
+ * @observed @property() foo?: string;
17
+ * ```
18
+ */
19
+ function executeBareDecorator(proto, propertyName) {
20
+ const klass = proto.constructor;
21
+ klass.addInitializer(x => initialize(x, propertyName, x[`_${propertyName}Changed`]));
22
+ }
23
+ /**
24
+ * @param methodNameOrCb string name of callback or function
25
+ * @example ```typescript
26
+ * @observed('_myCallback') @property() foo?: string;
27
+ * @observed((old) => console.log(old)) @property() bar?: string;
28
+ * ```
29
+ */
30
+ function configuredDecorator(methodNameOrCb) {
31
+ return function (proto, key) {
32
+ const propertyName = key;
33
+ const klass = proto.constructor;
34
+ if (typeof methodNameOrCb === 'function') {
35
+ const callback = methodNameOrCb;
36
+ klass.addInitializer(x => initialize(x, propertyName, callback));
37
+ }
38
+ else {
39
+ klass.addInitializer(x => initialize(x, propertyName, x[methodNameOrCb]));
40
+ }
41
+ };
42
+ }
43
+ function initialize(instance, propertyName, callback) {
44
+ const controller = new PropertyObserverController(instance, { propertyName, callback });
45
+ instance.addController(controller);
51
46
  }
52
47
  //# sourceMappingURL=observed.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observed.js","sourceRoot":"","sources":["observed.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,gDAAgD,CAAC;AAgCxD,MAAM,UAAU,QAAQ,CAA4B,GAAG,EAAS;IAC9D,2CAA2C;IAC3C,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QACnB,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC;QAClC,OAAO,UAAS,KAAK,EAAE,GAAG;YACvB,KAAK,CAAC,WAAsC;iBAC1C,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1D,eAAe,CAAC,KAAK,EAAE,GAAuB,EAAE,oBAAoB,CAAC,CAAC;QACxE,CAAC,CAAC;KACH;SAAM;QACL,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,CAAC,WAAsC;aAC1C,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1D,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;KAC7B;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,KAAQ,EACR,GAAqB,EACrB,gBAAoC;IAEpC,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE;QAChC,GAAG,UAAU;QACb,YAAY,EAAE,IAAI;QAClB,GAAG,CAAgC,MAAkB;YACnD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAc,CAAC,CAAC;YACpC,yDAAyD;YACzD,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAEpC,yCAAyC;YACzC,uDAAuD;YACvD,sFAAsF;YACtF,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE;gBAC1C,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;aAC7C;iBAAM;gBACL,6DAA6D;gBAC7D,qCAAqC;gBACrC,0DAA0D;gBAC1D,MAAM,gBAAgB,GAAG,gBAAgB,IAAI,IAAI,GAAG,SAAS,CAAC;gBAE9D,sEAAsE;gBACtE,gEAAgE;gBAChE,qEAAqE;gBACrE,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,IAAI,CAAC,gBAAsC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;iBAChE;qBAAM;oBACL,IAAI,CAAC,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;iBACjF;aACF;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\nimport type {\n ChangeCallback,\n ChangeCallbackName,\n PropertyObserverHost,\n} from '../controllers/property-observer-controller.js';\n\nimport {\n observedController,\n PropertyObserverController,\n} from '../controllers/property-observer-controller.js';\n\ntype TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void ;\n\n/**\n * Calls a _fooChanged method on the instance when the value changes.\n * Works on any class field. When using on lit observed properties,\n * Make sure `@observed` is to the left (i.e. called after) the `@property`\n * or `@state` decorator.\n *\n * @example observing a lit property\n * ```ts\n * @observed @property() foo = 'bar';\n *\n * protected _fooChanged(oldValue?: string, newValue?: string) {}\n * ```\n *\n * @example using a custom callback\n * ```ts\n * @observed('_myCallback') size = 'lg';\n *\n * _myCallback(_, size) {...}\n * ```\n *\n * @example using an arrow function\n * ```ts\n * @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))\n * ```\n */\nexport function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>\nexport function observed<T extends ReactiveElement>(cb: ChangeCallback<T>): TypedFieldDecorator<T>\nexport function observed<T extends ReactiveElement>(proto: T, key: string): void\nexport function observed<T extends ReactiveElement>(...as: any[]): void | TypedFieldDecorator<T> {\n /** @observed('_myCustomChangeCallback') */\n if (as.length === 1) {\n const [methodNameOrCallback] = as;\n return function(proto, key) {\n (proto.constructor as typeof ReactiveElement)\n .addInitializer(x => new PropertyObserverController(x));\n observeProperty(proto, key as string & keyof T, methodNameOrCallback);\n };\n } else {\n const [proto, key] = as;\n (proto.constructor as typeof ReactiveElement)\n .addInitializer(x => new PropertyObserverController(x));\n observeProperty(proto, key);\n }\n}\n\nexport function observeProperty<T extends ReactiveElement>(\n proto: T,\n key: string & keyof T,\n callbackOrMethod?: ChangeCallback<T>\n) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, key);\n Object.defineProperty(proto, key, {\n ...descriptor,\n configurable: true,\n set(this: PropertyObserverHost<T>, newVal: T[keyof T]) {\n const oldVal = this[key as keyof T];\n // first, call any pre-existing setters, e.g. `@property`\n descriptor?.set?.call(this, newVal);\n\n // if the user passed a callback, call it\n // e.g. `@observed((_, newVal) => console.log(newVal))`\n // safe to call before connectedCallback, because it's impossible to get a `this` ref.\n if (typeof callbackOrMethod === 'function') {\n callbackOrMethod.call(this, oldVal, newVal);\n } else {\n // if the user passed a string method name, call it on `this`\n // e.g. `@observed('_renderOptions')`\n // otherwise, use a default method name e.g. `_fooChanged`\n const actualMethodName = callbackOrMethod || `_${key}Changed`;\n\n // if the component has already connected to the DOM, run the callback\n // otherwise, If the component has not yet connected to the DOM,\n // cache the old and new values. See PropertyObserverController above\n if (this.hasUpdated) {\n this[actualMethodName as ChangeCallbackName]?.(oldVal, newVal);\n } else {\n this[observedController].cache(key as string, actualMethodName, oldVal, newVal);\n }\n }\n },\n });\n}\n"]}
1
+ {"version":3,"file":"observed.js","sourceRoot":"","sources":["observed.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAgC5F,+CAA+C;AAC/C,MAAM,UAAU,QAAQ,CAA4B,GAAG,EAAS;IAC9D,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;QAC5B,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,OAAO,oBAAoB,CAAC,GAAG,EAA2B,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,oBAAoB,CAA4B,KAAQ,EAAE,YAA8B;IAC/F,MAAM,KAAK,GAAG,KAAK,CAAC,WAAqC,CAAC;IAC1D,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAClC,CAAM,EACN,YAAY,EACZ,CAAC,CAAC,IAAI,YAAY,SAA2B,CAAsB,CACpE,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAC1B,cAA0C;IAE1C,OAAO,UAAS,KAAK,EAAE,GAAG;QACxB,MAAM,YAAY,GAAG,GAAuB,CAAC;QAC7C,MAAM,KAAK,GAAG,KAAK,CAAC,WAAqC,CAAC;QAC1D,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE,CAAC;YACzC,MAAM,QAAQ,GAAG,cAAc,CAAC;YAChC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAM,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAClC,CAAM,EACN,YAAY,EACZ,CAAC,CAAC,cAAuC,CAAsB,CAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CACjB,QAAW,EACX,YAA8B,EAC9B,QAA2B;IAE3B,MAAM,UAAU,GAAG,IAAI,0BAA0B,CAAI,QAAa,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChG,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\nimport type { ChangeCallback } from '../controllers/property-observer-controller.js';\n\nimport { PropertyObserverController } from '../controllers/property-observer-controller.js';\n\ntype TypedFieldDecorator<T> = (proto: T, key: string | keyof T) => void ;\n\n// eslint-disable-next-line jsdoc/require-param\n/**\n * Calls a _fooChanged method on the instance when the value changes.\n * Works on any class field. When using on lit observed properties,\n * Make sure `@observed` is to the left (i.e. called after) the `@property`\n * or `@state` decorator.\n * @example observing a lit property\n * ```ts\n * @observed @property() foo = 'bar';\n *\n * protected _fooChanged(oldValue?: string, newValue?: string) {}\n * ```\n * @example using a custom callback\n * ```ts\n * @observed('_myCallback') size = 'lg';\n *\n * _myCallback(_, size) {...}\n * ```\n * @example using an arrow function\n * ```ts\n * @observed((oldVal, newVal) => console.log(`Size changed from ${oldVal} to ${newVal}`))\n * ```\n */\nexport function observed<T extends ReactiveElement, V>(\n cb: ChangeCallback<T, V>,\n): TypedFieldDecorator<T>;\nexport function observed<T extends ReactiveElement>(methodName: string): TypedFieldDecorator<T>;\nexport function observed<T extends ReactiveElement>(proto: T, key: string): void;\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport function observed<T extends ReactiveElement>(...as: any[]): void | TypedFieldDecorator<T> {\n if (as.length === 1) {\n const [methodNameOrCb] = as;\n return configuredDecorator(methodNameOrCb);\n } else {\n return executeBareDecorator(...as as [T, string & keyof T]);\n }\n}\n\n/**\n * @param proto element prototype\n * @param propertyName propertyName\n * @example ```typescript\n * @observed @property() foo?: string;\n * ```\n */\nfunction executeBareDecorator<T extends ReactiveElement>(proto: T, propertyName: string & keyof T) {\n const klass = proto.constructor as typeof ReactiveElement;\n klass.addInitializer(x => initialize(\n x as T,\n propertyName,\n x[`_${propertyName}Changed` as keyof typeof x] as ChangeCallback<T>,\n ));\n}\n\n/**\n * @param methodNameOrCb string name of callback or function\n * @example ```typescript\n * @observed('_myCallback') @property() foo?: string;\n * @observed((old) => console.log(old)) @property() bar?: string;\n * ```\n */\nfunction configuredDecorator<T extends ReactiveElement>(\n methodNameOrCb: string | ChangeCallback<T>,\n): TypedFieldDecorator<T> {\n return function(proto, key) {\n const propertyName = key as string & keyof T;\n const klass = proto.constructor as typeof ReactiveElement;\n if (typeof methodNameOrCb === 'function') {\n const callback = methodNameOrCb;\n klass.addInitializer(x => initialize(x as T, propertyName, callback));\n } else {\n klass.addInitializer(x => initialize(\n x as T,\n propertyName,\n x[methodNameOrCb as keyof ReactiveElement] as ChangeCallback<T>,\n ));\n }\n };\n}\n\nfunction initialize<T extends ReactiveElement>(\n instance: T,\n propertyName: string & keyof T,\n callback: ChangeCallback<T>,\n) {\n const controller = new PropertyObserverController<T>(instance as T, { propertyName, callback });\n instance.addController(controller);\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { ReactiveElement } from 'lit';
2
+ import { type PropertyObserverOptions } from '@patternfly/pfe-core/controllers/property-observer-controller.js';
3
+ /**
4
+ * Observes changes on the given property and calls the decorated method
5
+ * with the old and new values when it changes. In cases where the decorated method
6
+ * needs to access uninitialized class fields, You may need to wait for the element to connect
7
+ * before running your effects. In that case, you can optionally specify which
8
+ * lifecycle state to wait for. e.g.:
9
+ * - `waitFor: 'firstUpdate'` waits until the first update cycle has completed
10
+ * - `waitFor: 'updated'` waits until the next update cycle has completed
11
+ * - `waitFor: 'connected'` waits until the element connects
12
+ * @param propertyName property to react to
13
+ * @param [options] options including lifecycle to wait on.
14
+ */
15
+ export declare function observes<T extends ReactiveElement>(propertyName: string & keyof T, options?: Partial<Exclude<PropertyObserverOptions<T>, 'callback' | 'propertyName'>>): (proto: T, methodName: string) => void;
@@ -0,0 +1,30 @@
1
+ import { PropertyObserverController, } from '@patternfly/pfe-core/controllers/property-observer-controller.js';
2
+ /**
3
+ * Observes changes on the given property and calls the decorated method
4
+ * with the old and new values when it changes. In cases where the decorated method
5
+ * needs to access uninitialized class fields, You may need to wait for the element to connect
6
+ * before running your effects. In that case, you can optionally specify which
7
+ * lifecycle state to wait for. e.g.:
8
+ * - `waitFor: 'firstUpdate'` waits until the first update cycle has completed
9
+ * - `waitFor: 'updated'` waits until the next update cycle has completed
10
+ * - `waitFor: 'connected'` waits until the element connects
11
+ * @param propertyName property to react to
12
+ * @param [options] options including lifecycle to wait on.
13
+ */
14
+ export function observes(propertyName, options) {
15
+ return function (proto, methodName) {
16
+ const callback = proto[methodName];
17
+ if (typeof callback !== 'function') {
18
+ throw new Error('@observes must decorate a class method');
19
+ }
20
+ const klass = proto.constructor;
21
+ klass.addInitializer(instance => {
22
+ instance.addController(new PropertyObserverController(instance, {
23
+ ...options,
24
+ propertyName,
25
+ callback,
26
+ }));
27
+ });
28
+ };
29
+ }
30
+ //# sourceMappingURL=observes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observes.js","sourceRoot":"","sources":["observes.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,GAG3B,MAAM,kEAAkE,CAAC;AAE1E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CACtB,YAA8B,EAC9B,OAAmF;IAEnF,OAAO,UAAS,KAAQ,EAAE,UAAkB;QAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAqB,CAAsB,CAAC;QACnE,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,KAAK,GAAG,KAAK,CAAC,WAAqC,CAAC;QAC1D,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;YAC9B,QAAQ,CAAC,aAAa,CAAC,IAAI,0BAA0B,CAAC,QAAa,EAAE;gBACnE,GAAG,OAAO;gBACV,YAAY;gBACZ,QAAQ;aACT,CAAC,CAAC,CAAC;QACN,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { ReactiveElement } from 'lit';\n\nimport {\n PropertyObserverController,\n type ChangeCallback,\n type PropertyObserverOptions,\n} from '@patternfly/pfe-core/controllers/property-observer-controller.js';\n\n/**\n * Observes changes on the given property and calls the decorated method\n * with the old and new values when it changes. In cases where the decorated method\n * needs to access uninitialized class fields, You may need to wait for the element to connect\n * before running your effects. In that case, you can optionally specify which\n * lifecycle state to wait for. e.g.:\n * - `waitFor: 'firstUpdate'` waits until the first update cycle has completed\n * - `waitFor: 'updated'` waits until the next update cycle has completed\n * - `waitFor: 'connected'` waits until the element connects\n * @param propertyName property to react to\n * @param [options] options including lifecycle to wait on.\n */\nexport function observes<T extends ReactiveElement>(\n propertyName: string & keyof T,\n options?: Partial<Exclude<PropertyObserverOptions<T>, 'callback' | 'propertyName'>>,\n) {\n return function(proto: T, methodName: string): void {\n const callback = proto[methodName as keyof T] as ChangeCallback<T>;\n if (typeof callback !== 'function') {\n throw new Error('@observes must decorate a class method');\n }\n const klass = proto.constructor as typeof ReactiveElement;\n klass.addInitializer(instance => {\n instance.addController(new PropertyObserverController(instance as T, {\n ...options,\n propertyName,\n callback,\n }));\n });\n };\n}\n\n"]}
@@ -1,4 +1,5 @@
1
1
  /**
2
2
  * Tracks the time a method takes to complete using the [performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)
3
+ * @param tag - short string to identify the method name
3
4
  */
4
5
  export declare function time(tag?: string): (_: unknown, key: string, descriptor: PropertyDescriptor) => void;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Tracks the time a method takes to complete using the [performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)
3
+ * @param tag - short string to identify the method name
3
4
  */
4
5
  export function time(tag) {
5
6
  return function (_, key, descriptor) {
@@ -11,17 +12,13 @@ export function time(tag) {
11
12
  const TAG = tag ?? `${this.constructor.name}-${key}`;
12
13
  const START_TAG = `start-${TAG}`;
13
14
  const END_TAG = `end-${TAG}`;
14
- if (window.PfeConfig.trackPerformance) {
15
- performance.mark(START_TAG);
16
- }
15
+ performance.mark(START_TAG);
17
16
  const x = f.call(this, ...args);
18
17
  const ret = () => {
19
- if (window.PfeConfig.trackPerformance) {
20
- performance.mark(END_TAG);
21
- performance.measure(TAG, START_TAG, END_TAG);
22
- // eslint-disable-next-line no-console
23
- console.log(Array.from(performance.getEntriesByName(TAG)).pop());
24
- }
18
+ performance.mark(END_TAG);
19
+ performance.measure(TAG, START_TAG, END_TAG);
20
+ // eslint-disable-next-line no-console
21
+ console.log(Array.from(performance.getEntriesByName(TAG)).pop());
25
22
  return x;
26
23
  };
27
24
  if (x instanceof Promise) {
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","sourceRoot":"","sources":["time.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,GAAY;IAC/B,OAAO,UAAS,CAAU,EAAE,GAAW,EAAE,UAA8B;QACrE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;QAEtC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC5D;QAED,UAAU,CAAC,KAAK,GAAG,UAAS,GAAG,IAAW;YACxC,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;YACrD,MAAM,SAAS,GAAG,SAAS,GAAG,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,OAAO,GAAG,EAAE,CAAC;YAE7B,IAAI,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE;gBACrC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC7B;YAED,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YAEhC,MAAM,GAAG,GAAG,GAAG,EAAE;gBACf,IAAI,MAAM,CAAC,SAAS,CAAC,gBAAgB,EAAE;oBACrC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBAC1B,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;oBAC7C,sCAAsC;oBACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;iBAClE;gBACD,OAAO,CAAC,CAAC;YACX,CAAC,CAAC;YAEF,IAAI,CAAC,YAAY,OAAO,EAAE;gBACxB,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACpB;iBAAM;gBACL,OAAO,GAAG,EAAE,CAAC;aACd;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Tracks the time a method takes to complete using the [performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)\n */\nexport function time(tag?: string) {\n return function(_: unknown, key: string, descriptor: PropertyDescriptor) {\n const { value: f } = descriptor ?? {};\n\n if (!(typeof f === 'function')) {\n throw new Error('@time() may only decorate class methods');\n }\n\n descriptor.value = function(...args: any[]) {\n const TAG = tag ?? `${this.constructor.name}-${key}`;\n const START_TAG = `start-${TAG}`;\n const END_TAG = `end-${TAG}`;\n\n if (window.PfeConfig.trackPerformance) {\n performance.mark(START_TAG);\n }\n\n const x = f.call(this, ...args);\n\n const ret = () => {\n if (window.PfeConfig.trackPerformance) {\n performance.mark(END_TAG);\n performance.measure(TAG, START_TAG, END_TAG);\n // eslint-disable-next-line no-console\n console.log(Array.from(performance.getEntriesByName(TAG)).pop());\n }\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"]}
1
+ {"version":3,"file":"time.js","sourceRoot":"","sources":["time.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,GAAY;IAC/B,OAAO,UACL,CAAU,EACV,GAAW,EACX,UAA8B;QAE9B,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,UAAU,IAAI,EAAE,CAAC;QAEtC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,UAAU,CAAC,KAAK,GAAG,UAAS,GAAG,IAAW;YACxC,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;YACrD,MAAM,SAAS,GAAG,SAAS,GAAG,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,OAAO,GAAG,EAAE,CAAC;YAE7B,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAE5B,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YAEhC,MAAM,GAAG,GAAG,GAAG,EAAE;gBACf,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC1B,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC7C,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;gBACjE,OAAO,CAAC,CAAC;YACX,CAAC,CAAC;YAEF,IAAI,CAAC,YAAY,OAAO,EAAE,CAAC;gBACzB,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,EAAE,CAAC;YACf,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Tracks the time a method takes to complete using the [performance API](https://developer.mozilla.org/en-US/docs/Web/API/Performance)\n * @param tag - short string to identify the method name\n */\nexport function time(tag?: string) {\n return function(\n _: unknown,\n key: string,\n descriptor: PropertyDescriptor,\n ): void {\n const { value: f } = descriptor ?? {};\n\n if (!(typeof f === 'function')) {\n throw new Error('@time() may only decorate class methods');\n }\n\n descriptor.value = function(...args: any[]) {\n const TAG = tag ?? `${this.constructor.name}-${key}`;\n const START_TAG = `start-${TAG}`;\n const END_TAG = `end-${TAG}`;\n\n performance.mark(START_TAG);\n\n const x = f.call(this, ...args);\n\n const ret = () => {\n performance.mark(END_TAG);\n performance.measure(TAG, START_TAG, END_TAG);\n // eslint-disable-next-line no-console\n console.log(Array.from(performance.getEntriesByName(TAG)).pop());\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"]}
@@ -1,2 +1,5 @@
1
- /** Logs the result of a class method */
1
+ /**
2
+ * Logs the result of a class method
3
+ * @param tag log tag, prepended to outputs
4
+ */
2
5
  export declare function trace(tag?: string): (_: unknown, key: string, descriptor: PropertyDescriptor) => void;
@@ -1,4 +1,7 @@
1
- /** Logs the result of a class method */
1
+ /**
2
+ * Logs the result of a class method
3
+ * @param tag log tag, prepended to outputs
4
+ */
2
5
  export function trace(tag) {
3
6
  return function (_, key, descriptor) {
4
7
  const { value: f } = descriptor;
@@ -1 +1 @@
1
- {"version":3,"file":"trace.js","sourceRoot":"","sources":["trace.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,UAAU,KAAK,CAAC,GAAY;IAChC,OAAO,UAAS,CAAU,EAAE,GAAW,EAAE,UAA8B;QACrE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,UAAU,CAAC;QAChC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAG,IAAW;YACxC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YAEhC,MAAM,GAAG,GAAG,GAAG,EAAE;gBACf,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;gBAC3B,OAAO,CAAC,CAAC;YACX,CAAC,CAAC;YAEF,IAAI,CAAC,YAAY,OAAO,EAAE;gBACxB,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACpB;iBAAM;gBACL,OAAO,GAAG,EAAE,CAAC;aACd;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/** Logs the result of a class method */\nexport function trace(tag?: string) {\n return function(_: unknown, key: string, descriptor: PropertyDescriptor) {\n const { value: f } = descriptor;\n descriptor.value = function(...args: any[]) {\n const x = f.call(this, ...args);\n\n const ret = () => {\n // eslint-disable-next-line no-console\n console.log(tag ?? key, x);\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"]}
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["trace.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,KAAK,CAAC,GAAY;IAChC,OAAO,UACL,CAAU,EACV,GAAW,EACX,UAA8B;QAE9B,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,UAAU,CAAC;QAChC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAG,IAAW;YACxC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YAEhC,MAAM,GAAG,GAAG,GAAG,EAAE;gBACf,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC;gBAC3B,OAAO,CAAC,CAAC;YACX,CAAC,CAAC;YAEF,IAAI,CAAC,YAAY,OAAO,EAAE,CAAC;gBACzB,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,EAAE,CAAC;YACf,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Logs the result of a class method\n * @param tag log tag, prepended to outputs\n */\nexport function trace(tag?: string) {\n return function(\n _: unknown,\n key: string,\n descriptor: PropertyDescriptor,\n ): void {\n const { value: f } = descriptor;\n descriptor.value = function(...args: any[]) {\n const x = f.call(this, ...args);\n\n const ret = () => {\n // eslint-disable-next-line no-console\n console.log(tag ?? key, x);\n return x;\n };\n\n if (x instanceof Promise) {\n return x.then(ret);\n } else {\n return ret();\n }\n };\n };\n}\n"]}
package/decorators.d.ts CHANGED
@@ -2,6 +2,8 @@ export * from './decorators/bound.js';
2
2
  export * from './decorators/cascades.js';
3
3
  export * from './decorators/deprecation.js';
4
4
  export * from './decorators/initializer.js';
5
+ export * from './decorators/listen.js';
5
6
  export * from './decorators/observed.js';
7
+ export * from './decorators/observes.js';
6
8
  export * from './decorators/time.js';
7
9
  export * from './decorators/trace.js';
package/decorators.js CHANGED
@@ -2,7 +2,9 @@ export * from './decorators/bound.js';
2
2
  export * from './decorators/cascades.js';
3
3
  export * from './decorators/deprecation.js';
4
4
  export * from './decorators/initializer.js';
5
+ export * from './decorators/listen.js';
5
6
  export * from './decorators/observed.js';
7
+ export * from './decorators/observes.js';
6
8
  export * from './decorators/time.js';
7
9
  export * from './decorators/trace.js';
8
10
  //# sourceMappingURL=decorators.js.map
package/decorators.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './decorators/bound.js';\nexport * from './decorators/cascades.js';\nexport * from './decorators/deprecation.js';\nexport * from './decorators/initializer.js';\nexport * from './decorators/observed.js';\nexport * from './decorators/time.js';\nexport * from './decorators/trace.js';\n"]}
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["decorators.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './decorators/bound.js';\nexport * from './decorators/cascades.js';\nexport * from './decorators/deprecation.js';\nexport * from './decorators/initializer.js';\nexport * from './decorators/listen.js';\nexport * from './decorators/observed.js';\nexport * from './decorators/observes.js';\nexport * from './decorators/time.js';\nexport * from './decorators/trace.js';\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Whether the two arrays are equivalent
3
+ * Arrays are equivalent when they are both empty, or when their lengths are equal and each of
4
+ * their members is equal (===) to the corresponding member in the other array.
5
+ * If either argument is not an array, the result will be strict equivalence (===)
6
+ * @param a first array
7
+ * @param b second array
8
+ */
9
+ export declare function arraysAreEquivalent(a: unknown, b: unknown): boolean;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Whether the two arrays are equivalent
3
+ * Arrays are equivalent when they are both empty, or when their lengths are equal and each of
4
+ * their members is equal (===) to the corresponding member in the other array.
5
+ * If either argument is not an array, the result will be strict equivalence (===)
6
+ * @param a first array
7
+ * @param b second array
8
+ */
9
+ export function arraysAreEquivalent(a, b) {
10
+ if (!Array.isArray(a) || !Array.isArray(b)) {
11
+ return a === b;
12
+ }
13
+ else if (a.length !== b.length) { // lengths are different
14
+ return false;
15
+ }
16
+ else if (!a.length && !b.length) { // both are empty
17
+ return true;
18
+ }
19
+ else { // multi and length of both is equal
20
+ for (const [i, element] of a.entries()) {
21
+ if (element !== b[i]) {
22
+ return false;
23
+ }
24
+ }
25
+ return true;
26
+ }
27
+ }
28
+ //# sourceMappingURL=arraysAreEquivalent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arraysAreEquivalent.js","sourceRoot":"","sources":["arraysAreEquivalent.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAU,EAAE,CAAU;IACxD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,OAAO,CAAC,KAAK,CAAC,CAAC;IACjB,CAAC;SAAM,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,wBAAwB;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,IAAI,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,iBAAiB;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC,CAAC,oCAAoC;QAC3C,KAAK,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;YACvC,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrB,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * Whether the two arrays are equivalent\n * Arrays are equivalent when they are both empty, or when their lengths are equal and each of\n * their members is equal (===) to the corresponding member in the other array.\n * If either argument is not an array, the result will be strict equivalence (===)\n * @param a first array\n * @param b second array\n */\nexport function arraysAreEquivalent(a: unknown, b: unknown): boolean {\n if (!Array.isArray(a) || !Array.isArray(b)) {\n return a === b;\n } else if (a.length !== b.length) { // lengths are different\n return false;\n } else if (!a.length && !b.length) { // both are empty\n return true;\n } else { // multi and length of both is equal\n for (const [i, element] of a.entries()) {\n if (element !== b[i]) {\n return false;\n }\n }\n return true;\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Whether or not the container contains the node,
3
+ * and if not, whether the node is contained by any element
4
+ * slotted in to the container
5
+ * @param container haystack
6
+ * @param node needle
7
+ */
8
+ export declare function containsDeep(container: Element, node: Node): boolean;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Whether or not the container contains the node,
3
+ * and if not, whether the node is contained by any element
4
+ * slotted in to the container
5
+ * @param container haystack
6
+ * @param node needle
7
+ */
8
+ export function containsDeep(container, node) {
9
+ if (container.contains(node)) {
10
+ return true;
11
+ }
12
+ else {
13
+ for (const slot of container.querySelectorAll('slot') ?? []) {
14
+ for (const el of slot.assignedElements()) {
15
+ if (el.contains(node)) {
16
+ return true;
17
+ }
18
+ }
19
+ }
20
+ return false;
21
+ }
22
+ }
23
+ //# sourceMappingURL=containsDeep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"containsDeep.js","sourceRoot":"","sources":["containsDeep.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAkB,EAClB,IAAU;IAEV,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YAC5D,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,gBAAgB,EAAE,EAAE,CAAC;gBACzC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACtB,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["/**\n * Whether or not the container contains the node,\n * and if not, whether the node is contained by any element\n * slotted in to the container\n * @param container haystack\n * @param node needle\n */\nexport function containsDeep(\n container: Element,\n node: Node,\n): boolean {\n if (container.contains(node)) {\n return true;\n } else {\n for (const slot of container.querySelectorAll('slot') ?? []) {\n for (const el of slot.assignedElements()) {\n if (el.contains(node)) {\n return true;\n }\n }\n }\n return false;\n }\n}\n"]}