element-vir 6.3.4 → 7.0.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.
Files changed (56) hide show
  1. package/README.md +91 -2
  2. package/dist/augments/array.d.ts +1 -0
  3. package/dist/augments/type.d.ts +1 -0
  4. package/dist/declarative-element/declarative-element-init.d.ts +6 -5
  5. package/dist/declarative-element/declarative-element.d.ts +8 -7
  6. package/dist/declarative-element/define-element-no-inputs.d.ts +3 -2
  7. package/dist/declarative-element/define-element-no-inputs.js +6 -6
  8. package/dist/declarative-element/define-element.d.ts +3 -2
  9. package/dist/declarative-element/definition-options.d.ts +1 -0
  10. package/dist/declarative-element/directives/assign-with-clean-up.directive.d.ts +1 -0
  11. package/dist/declarative-element/directives/assign.directive.d.ts +1 -0
  12. package/dist/declarative-element/directives/directive-helpers.d.ts +2 -1
  13. package/dist/declarative-element/directives/directive-helpers.js +2 -2
  14. package/dist/declarative-element/directives/listen.directive.d.ts +1 -0
  15. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +1 -0
  16. package/dist/declarative-element/directives/on-dom-created.directive.js +3 -3
  17. package/dist/declarative-element/directives/on-resize.directive.d.ts +1 -0
  18. package/dist/declarative-element/directives/on-resize.directive.js +3 -3
  19. package/dist/declarative-element/directives/render-async-prop.directive.d.ts +10 -0
  20. package/dist/declarative-element/directives/render-async-prop.directive.js +12 -0
  21. package/dist/declarative-element/directives/render-if.directive.d.ts +2 -0
  22. package/dist/declarative-element/directives/render-if.directive.js +4 -0
  23. package/dist/declarative-element/has-declarative-element-parent.d.ts +1 -0
  24. package/dist/declarative-element/properties/async-prop.d.ts +27 -0
  25. package/dist/declarative-element/properties/async-prop.js +102 -0
  26. package/dist/declarative-element/{css-vars.d.ts → properties/css-vars.d.ts} +1 -0
  27. package/dist/declarative-element/{css-vars.js → properties/css-vars.js} +0 -0
  28. package/dist/declarative-element/{element-events.d.ts → properties/element-events.d.ts} +2 -1
  29. package/dist/declarative-element/{element-events.js → properties/element-events.js} +1 -1
  30. package/dist/declarative-element/{element-properties.d.ts → properties/element-properties.d.ts} +1 -2
  31. package/dist/declarative-element/properties/element-properties.js +21 -0
  32. package/dist/declarative-element/properties/element-updater-proxy.d.ts +4 -0
  33. package/dist/declarative-element/{element-properties.js → properties/element-updater-proxy.js} +15 -31
  34. package/dist/declarative-element/{host-classes.d.ts → properties/host-classes.d.ts} +1 -0
  35. package/dist/declarative-element/{host-classes.js → properties/host-classes.js} +0 -0
  36. package/dist/declarative-element/{styles.d.ts → properties/styles.d.ts} +1 -0
  37. package/dist/declarative-element/{styles.js → properties/styles.js} +0 -0
  38. package/dist/declarative-element/{tag-name.d.ts → properties/tag-name.d.ts} +1 -0
  39. package/dist/declarative-element/{tag-name.js → properties/tag-name.js} +0 -0
  40. package/dist/declarative-element/render-callback.d.ts +11 -6
  41. package/dist/declarative-element/render-callback.js +20 -10
  42. package/dist/declarative-element-marker-symbol.d.ts +1 -0
  43. package/dist/index.d.ts +6 -3
  44. package/dist/index.js +5 -3
  45. package/dist/require-declarative-element.d.ts +1 -0
  46. package/dist/template-transforms/has-static-tag-name.d.ts +1 -0
  47. package/dist/template-transforms/nested-mapped-templates.d.ts +1 -0
  48. package/dist/template-transforms/transform-template.d.ts +1 -0
  49. package/dist/template-transforms/vir-css/css-transform.d.ts +1 -0
  50. package/dist/template-transforms/vir-css/vir-css.d.ts +1 -0
  51. package/dist/template-transforms/vir-html/html-transform.d.ts +1 -0
  52. package/dist/template-transforms/vir-html/vir-html.d.ts +1 -0
  53. package/dist/typed-event/typed-event.d.ts +1 -0
  54. package/package.json +22 -25
  55. package/dist/declarative-element/directives/awaiting.directive.d.ts +0 -18
  56. package/dist/declarative-element/directives/awaiting.directive.js +0 -42
package/README.md CHANGED
@@ -317,7 +317,7 @@ import {MyCustomActionEvent} from './my-custom-action.event';
317
317
 
318
318
  export const MyWithCustomEventsElement = defineElementNoInputs({
319
319
  tagName: 'my-with-custom-events',
320
- renderCallback: ({genericDispatch}) => html`
320
+ renderCallback: ({dispatch}) => html`
321
321
  <div
322
322
  ${listen(MyCustomActionEvent, (event) => {
323
323
  console.info(`Got a number! ${event.detail}`);
@@ -325,7 +325,7 @@ export const MyWithCustomEventsElement = defineElementNoInputs({
325
325
  >
326
326
  <div
327
327
  ${listen('click', () => {
328
- genericDispatch(new MyCustomActionEvent(Math.random()));
328
+ dispatch(new MyCustomActionEvent(Math.random()));
329
329
  })}
330
330
  ></div>
331
331
  </div>
@@ -534,6 +534,85 @@ export const MyWithCleanupElement = defineElementNoInputs({
534
534
  });
535
535
  ```
536
536
 
537
+ ### renderIf
538
+
539
+ Use the `renderIf` directive to easily render a template if a given condition is true.
540
+
541
+ <!-- example-link: src/readme-examples/my-with-render-if.element.ts -->
542
+
543
+ ```TypeScript
544
+ import {defineElement, html, renderIf} from 'element-vir';
545
+
546
+ export const MyWithRenderIfElement = defineElement<{shouldRender: boolean}>()({
547
+ tagName: 'my-simple-with-render-if',
548
+ renderCallback: ({inputs}) => html`
549
+ ${renderIf(
550
+ inputs.shouldRender,
551
+ html`
552
+ I'm conditionally rendered!
553
+ `,
554
+ )}
555
+ `,
556
+ });
557
+ ```
558
+
559
+ ### renderAsyncProp
560
+
561
+ Use the `renderAsyncProp` directive in conjunction with the `asyncProp` property definer and the `ensureAsyncProp` render callback property to seamlessly render and update element state:
562
+
563
+ <!-- example-link: src/readme-examples/my-with-async-prop.element.ts -->
564
+
565
+ ```TypeScript
566
+ import {asyncProp, defineElement, html, renderAsyncProp} from 'element-vir';
567
+
568
+ async function loadSomething(endpoint: string) {
569
+ // load something from the network
570
+ const data = await (
571
+ await fetch(
572
+ [
573
+ '',
574
+ 'api',
575
+ endpoint,
576
+ ].join('/'),
577
+ )
578
+ ).json();
579
+ return data;
580
+ }
581
+
582
+ export const MyWithAsyncPropElement = defineElement<{endpointToHit: string}>()({
583
+ tagName: 'my-simple-with-render-if',
584
+ stateInit: {
585
+ data: asyncProp(),
586
+ },
587
+ renderCallback: ({inputs, state, ensureAsyncProp}) => {
588
+ /**
589
+ * This creates a promise which automatically updates the state.loadsLater prop once the
590
+ * promise resolves.
591
+ */
592
+ ensureAsyncProp({
593
+ data: {
594
+ createPromise: () => loadSomething(inputs.endpointToHit),
595
+ updateIfThisChanges: inputs.endpointToHit,
596
+ },
597
+ });
598
+
599
+ return html`
600
+ Here's the data:
601
+ <br />
602
+ ${renderAsyncProp({
603
+ asyncProp: state.data,
604
+ fallback: 'Loading...',
605
+ resolutionRender: (loadedData) => {
606
+ return html`
607
+ Got the data: ${loadedData}
608
+ `;
609
+ },
610
+ })}
611
+ `;
612
+ },
613
+ });
614
+ ```
615
+
537
616
  ## Require all child custom elements to be declarative elements
538
617
 
539
618
  To require all child elements to be declarative elements defined by this package, call `requireAllCustomElementsToBeDeclarativeElements` anywhere in your app. This is a global setting so do not enable it unless you want it to be true _everywhere_ in your current run-time. This should not be used if you're using custom elements from other libraries (unless they happen to also use this package to define their custom elements).
@@ -551,3 +630,13 @@ requireAllCustomElementsToBeDeclarativeElements();
551
630
  ## markdown out of date
552
631
 
553
632
  If you see this: `Code in Markdown file(s) is out of date. Run without --check to update. code-in-markdown failed.`, run `npm run update-docs` to fix it.
633
+
634
+ ## Testing source map errors
635
+
636
+ If you see
637
+
638
+ ```
639
+ Error while reading source maps for ...
640
+ ```
641
+
642
+ While running `npm test`, don't worry about it. Those only happen when tests fail.
@@ -1 +1,2 @@
1
1
  export declare function filterOutArrayIndexes<T>(array: Readonly<T[]>, indexes: Readonly<number[]>): T[];
2
+ //# sourceMappingURL=array.d.ts.map
@@ -6,3 +6,4 @@ export type NonEmptyString<T> = T extends '' ? never : T;
6
6
  * testing packages.
7
7
  */
8
8
  export declare function ensureInstanceOf<T>(value: unknown, constructor: new (...args: any) => T, message?: string): asserts value is T;
9
+ //# sourceMappingURL=type.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { CSSResult } from 'lit';
2
- import { CssVarsInitMap } from './css-vars';
3
2
  import { DeclarativeElementDefinitionOptions } from './definition-options';
4
- import { EventsInitMap } from './element-events';
5
- import { PropertyInitMapBase } from './element-properties';
6
- import { HostClassesInitMap } from './host-classes';
3
+ import { CssVarsInitMap } from './properties/css-vars';
4
+ import { EventsInitMap } from './properties/element-events';
5
+ import { PropertyInitMapBase } from './properties/element-properties';
6
+ import { HostClassesInitMap } from './properties/host-classes';
7
+ import { StylesCallback } from './properties/styles';
7
8
  import { InitCallback, RenderCallback } from './render-callback';
8
- import { StylesCallback } from './styles';
9
9
  export type CustomElementTagName = `${string}-${string}`;
10
10
  export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
11
11
  /**
@@ -42,3 +42,4 @@ export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, St
42
42
  cleanupCallback?: InitCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
43
43
  options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
44
44
  };
45
+ //# sourceMappingURL=declarative-element-init.d.ts.map
@@ -1,16 +1,16 @@
1
1
  import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
2
2
  import { CSSResult, LitElement, TemplateResult } from 'lit';
3
- import { CssVarNameOrValueMap } from './css-vars';
4
3
  import { DeclarativeElementInit } from './declarative-element-init';
5
- import { EventDescriptorMap, EventsInitMap } from './element-events';
6
- import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './element-properties';
7
- import { HostClassNamesMap } from './host-classes';
4
+ import { CssVarNameOrValueMap } from './properties/css-vars';
5
+ import { EventDescriptorMap, EventsInitMap } from './properties/element-events';
6
+ import { ElementPropertyDescriptorMap, PropertyInitMapBase } from './properties/element-properties';
7
+ import { HostClassNamesMap } from './properties/host-classes';
8
8
  import { RenderCallback } from './render-callback';
9
9
  export type HostInstanceType<InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = RequiredAndNotNullBy<DeclarativeElement<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'shadowRoot'>;
10
10
  export type DeclarativeElementDefinition<InputsGeneric extends PropertyInitMapBase = any, StateInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> = (new () => HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) & StaticDeclarativeElementProperties<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys> & {
11
11
  instanceType: HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
12
12
  };
13
- export declare abstract class DeclarativeElement<InputsGeneric extends PropertyInitMapBase = any, PropertyInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> extends LitElement {
13
+ export declare abstract class DeclarativeElement<InputsGeneric extends PropertyInitMapBase = any, StateInitGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = string, CssVarKeys extends string = string> extends LitElement {
14
14
  static readonly tagName: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['tagName'];
15
15
  static readonly styles: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['styles'];
16
16
  static readonly isStrictInstance: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['isStrictInstance'];
@@ -24,12 +24,12 @@ export declare abstract class DeclarativeElement<InputsGeneric extends PropertyI
24
24
  static readonly cssVarNames: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarNames'];
25
25
  static readonly cssVarValues: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarValues'];
26
26
  abstract render(): TemplateResult | Promise<TemplateResult>;
27
- abstract readonly instanceState: PropertyInitGeneric;
27
+ abstract readonly instanceState: StateInitGeneric;
28
28
  abstract readonly instanceInputs: InputsGeneric;
29
29
  abstract assignInputs(inputs: InputsGeneric): void;
30
30
  abstract readonly haveInputsBeenSet: boolean;
31
31
  abstract markInputsAsHavingBeenSet(): void;
32
- abstract readonly definition: DeclarativeElementDefinition<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
32
+ abstract readonly definition: DeclarativeElementDefinition<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
33
33
  }
34
34
  export interface StaticDeclarativeElementProperties<InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> {
35
35
  /** Pass through the render callback for direct unit testability */
@@ -46,3 +46,4 @@ export interface StaticDeclarativeElementProperties<InputsGeneric extends Proper
46
46
  tagName: string;
47
47
  styles: CSSResult;
48
48
  }
49
+ //# sourceMappingURL=declarative-element.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { DeclarativeElementDefinition } from './declarative-element';
2
2
  import { DeclarativeElementInit } from './declarative-element-init';
3
- import { EventsInitMap } from './element-events';
4
- import { PropertyInitMapBase } from './element-properties';
3
+ import { EventsInitMap } from './properties/element-events';
4
+ import { PropertyInitMapBase } from './properties/element-properties';
5
5
  export declare function defineElementNoInputs<InputsGeneric extends PropertyInitMapBase = {}, StateGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = '', CssVarKeys extends string = ''>(initInput: DeclarativeElementInit<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>): DeclarativeElementDefinition<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
6
+ //# sourceMappingURL=define-element-no-inputs.d.ts.map
@@ -2,16 +2,16 @@ import { getObjectTypedKeys, kebabCaseToCamelCase } from '@augment-vir/common';
2
2
  import { css } from 'lit';
3
3
  import { property } from 'lit/decorators.js';
4
4
  import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
5
- import { createCssVarNamesMap, createCssVarValuesMap } from './css-vars';
6
5
  import { DeclarativeElement, } from './declarative-element';
7
6
  import { defaultDeclarativeElementDefinitionOptions, IgnoreInputsNotBeenSetBeforeRenderWarningSymbol, } from './definition-options';
8
7
  import { assign } from './directives/assign.directive';
9
- import { createEventDescriptorMap } from './element-events';
10
- import { createElementUpdaterProxy } from './element-properties';
11
8
  import { hasDeclarativeElementParent } from './has-declarative-element-parent';
12
- import { createHostClassNamesMap } from './host-classes';
9
+ import { createCssVarNamesMap, createCssVarValuesMap } from './properties/css-vars';
10
+ import { createEventDescriptorMap } from './properties/element-events';
11
+ import { createElementUpdaterProxy } from './properties/element-updater-proxy';
12
+ import { createHostClassNamesMap } from './properties/host-classes';
13
+ import { applyHostClasses, hostClassNamesToStylesInput } from './properties/styles';
13
14
  import { createRenderParams } from './render-callback';
14
- import { applyHostClasses, hostClassNamesToStylesInput } from './styles';
15
15
  export function defineElementNoInputs(initInput) {
16
16
  var _a;
17
17
  const eventsMap = createEventDescriptorMap(initInput.events);
@@ -94,7 +94,7 @@ export function defineElementNoInputs(initInput) {
94
94
  const stateInit = initInput.stateInit || {};
95
95
  Object.keys(stateInit).forEach((propName) => {
96
96
  property()(this, propName);
97
- this[propName] = stateInit[propName];
97
+ this.instanceState[propName] = stateInit[propName];
98
98
  });
99
99
  this.definition = anonymousClass;
100
100
  }
@@ -1,5 +1,6 @@
1
1
  import { DeclarativeElementDefinition } from './declarative-element';
2
2
  import { DeclarativeElementInit } from './declarative-element-init';
3
- import { EventsInitMap } from './element-events';
4
- import { PropertyInitMapBase } from './element-properties';
3
+ import { EventsInitMap } from './properties/element-events';
4
+ import { PropertyInitMapBase } from './properties/element-properties';
5
5
  export declare function defineElement<InputsGeneric extends PropertyInitMapBase = {}>(): <PropertyInitGeneric extends PropertyInitMapBase = {}, EventsInitGeneric extends EventsInitMap = {}, HostClassKeys extends string = "", CssVarKeys extends string = "">(initInput: DeclarativeElementInit<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => DeclarativeElementDefinition<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
6
+ //# sourceMappingURL=define-element.d.ts.map
@@ -3,3 +3,4 @@ export type DeclarativeElementDefinitionOptions = {
3
3
  [IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: boolean;
4
4
  };
5
5
  export declare const defaultDeclarativeElementDefinitionOptions: DeclarativeElementDefinitionOptions;
6
+ //# sourceMappingURL=definition-options.d.ts.map
@@ -21,3 +21,4 @@ declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
21
21
  render(elementDefinition: DeclarativeElementDefinition, inputsObject: Record<PropertyKey, unknown>, cleanupCallback: CleanupCallback<any>): symbol;
22
22
  }
23
23
  export {};
24
+ //# sourceMappingURL=assign-with-clean-up.directive.d.ts.map
@@ -10,3 +10,4 @@ export declare function assign<DeclarativeElementGeneric extends DeclarativeElem
10
10
  };
11
11
  }>;
12
12
  export declare function assignInputsObject<DeclarativeElementInstanceGeneric extends DeclarativeElement, DeclarativeElementDefinitionGeneric extends DeclarativeElementDefinition>(expectedElementConstructor: DeclarativeElementDefinitionGeneric, element: DeclarativeElementInstanceGeneric, assignmentObject: DeclarativeElementDefinitionGeneric['inputsType']): void;
13
+ //# sourceMappingURL=assign.directive.d.ts.map
@@ -11,4 +11,5 @@ export type ExtraPartInfoProperties = {
11
11
  };
12
12
  export declare function extractDeclarativeElement(partInfo: PartInfo, directiveName: string): DeclarativeElement;
13
13
  export declare function extractElement<ElementType = HTMLElement>(partInfo: PartInfo, directiveName: string, constructorClass: (new () => ElementType) | (abstract new () => ElementType)): ElementType;
14
- export declare function assertsIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
14
+ export declare function assertIsElementPartInfo(partInfo: PartInfo, directiveName: string): asserts partInfo is ElementPartInfo & ExtraPartInfoProperties;
15
+ //# sourceMappingURL=directive-helpers.d.ts.map
@@ -4,14 +4,14 @@ export function extractDeclarativeElement(partInfo, directiveName) {
4
4
  return extractElement(partInfo, directiveName, DeclarativeElement);
5
5
  }
6
6
  export function extractElement(partInfo, directiveName, constructorClass) {
7
- assertsIsElementPartInfo(partInfo, directiveName);
7
+ assertIsElementPartInfo(partInfo, directiveName);
8
8
  const element = partInfo.element;
9
9
  if (!(element instanceof constructorClass)) {
10
10
  throw new Error(`${directiveName} attached to non ${constructorClass.name} element.`);
11
11
  }
12
12
  return element;
13
13
  }
14
- export function assertsIsElementPartInfo(partInfo, directiveName) {
14
+ export function assertIsElementPartInfo(partInfo, directiveName) {
15
15
  if (partInfo.type !== PartType.ELEMENT) {
16
16
  throw new Error(`${directiveName} directive can only be attached directly to an element.`);
17
17
  }
@@ -12,3 +12,4 @@ import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
12
12
  */
13
13
  export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: DefinedTypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>, listener: (event: TypedEvent<TypedEventTypeNameGeneric, TypedEventDetailGeneric>) => void): DirectiveResult<any>;
14
14
  export declare function listen<TypedEventTypeNameGeneric extends string, TypedEventDetailGeneric, NativeElementEventNameGeneric extends keyof HTMLElementEventMap>(eventType: NativeElementEventNameGeneric, listener: (event: HTMLElementEventMap[NativeElementEventNameGeneric]) => void): DirectiveResult<any>;
15
+ //# sourceMappingURL=listen.directive.d.ts.map
@@ -9,3 +9,4 @@ export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("l
9
9
  readonly _$isConnected: boolean;
10
10
  };
11
11
  }>;
12
+ //# sourceMappingURL=on-dom-created.directive.d.ts.map
@@ -1,14 +1,14 @@
1
1
  import { directive, Directive } from 'lit/directive.js';
2
- import { assertsIsElementPartInfo } from './directive-helpers';
2
+ import { assertIsElementPartInfo } from './directive-helpers';
3
3
  const directiveName = 'onDomCreated';
4
4
  /** Only fires once, when the element has been created. */
5
5
  export const onDomCreated = directive(class extends Directive {
6
6
  constructor(partInfo) {
7
7
  super(partInfo);
8
- assertsIsElementPartInfo(partInfo, directiveName);
8
+ assertIsElementPartInfo(partInfo, directiveName);
9
9
  }
10
10
  update(partInfo, [callback]) {
11
- assertsIsElementPartInfo(partInfo, directiveName);
11
+ assertIsElementPartInfo(partInfo, directiveName);
12
12
  const newElement = partInfo.element;
13
13
  if (newElement !== this.element) {
14
14
  // use requestAnimationFrame here so it can fire property changes outside of a render loop
@@ -13,3 +13,4 @@ export declare const onResize: (callback: OnResizeCallback) => import("lit-html/
13
13
  readonly _$isConnected: boolean;
14
14
  };
15
15
  }>;
16
+ //# sourceMappingURL=on-resize.directive.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { directive, Directive } from 'lit/directive.js';
2
- import { assertsIsElementPartInfo } from './directive-helpers';
2
+ import { assertIsElementPartInfo } from './directive-helpers';
3
3
  const directiveName = 'onResize';
4
4
  export const onResize = directive(class extends Directive {
5
5
  constructor(partInfo) {
6
6
  super(partInfo);
7
7
  this.resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
8
- assertsIsElementPartInfo(partInfo, directiveName);
8
+ assertIsElementPartInfo(partInfo, directiveName);
9
9
  }
10
10
  fireCallback(entries) {
11
11
  var _a;
@@ -17,7 +17,7 @@ export const onResize = directive(class extends Directive {
17
17
  (_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this, { target: resizeEntry.target, contentRect: resizeEntry.contentRect });
18
18
  }
19
19
  update(partInfo, [callback]) {
20
- assertsIsElementPartInfo(partInfo, directiveName);
20
+ assertIsElementPartInfo(partInfo, directiveName);
21
21
  this.callback = callback;
22
22
  const newElement = partInfo.element;
23
23
  // if the element changes we need to observe the new one
@@ -0,0 +1,10 @@
1
+ import { UnPromise } from '@augment-vir/common';
2
+ import { AsyncProp } from '../properties/async-prop';
3
+ export declare function renderAsyncProp<T>({ asyncProp, fallback, resolutionRender, errorRender, }: {
4
+ asyncProp: AsyncProp<T>;
5
+ /** This value will be rendered if the async state has not settled yet. */
6
+ fallback: unknown;
7
+ resolutionRender: (resolved: UnPromise<T>) => unknown;
8
+ errorRender?: (error: Error) => unknown;
9
+ }): unknown;
10
+ //# sourceMappingURL=render-async-prop.directive.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { extractErrorMessage } from '@augment-vir/common';
2
+ export function renderAsyncProp({ asyncProp, fallback, resolutionRender, errorRender, }) {
3
+ if (asyncProp === null || asyncProp === void 0 ? void 0 : asyncProp.error) {
4
+ return errorRender ? errorRender(asyncProp.error) : extractErrorMessage(asyncProp.error);
5
+ }
6
+ else if (asyncProp === null || asyncProp === void 0 ? void 0 : asyncProp.resolution) {
7
+ return resolutionRender(asyncProp.resolution);
8
+ }
9
+ else {
10
+ return fallback;
11
+ }
12
+ }
@@ -0,0 +1,2 @@
1
+ export declare function renderIf<T>(condition: boolean, result: T): T | undefined;
2
+ //# sourceMappingURL=render-if.directive.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { when } from 'lit/directives/when.js';
2
+ export function renderIf(condition, result) {
3
+ return when(condition, () => result);
4
+ }
@@ -1 +1,2 @@
1
1
  export declare function hasDeclarativeElementParent(input: Element): boolean;
2
+ //# sourceMappingURL=has-declarative-element-parent.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { UnPromise } from '@augment-vir/common';
2
+ import { JsonValue } from 'type-fest';
3
+ export type AsyncProp<ValueGeneric> = {
4
+ error?: Error;
5
+ promise?: Promise<UnPromise<ValueGeneric>>;
6
+ resolution?: UnPromise<ValueGeneric>;
7
+ isChainedAlready?: true;
8
+ lastTrigger?: JsonValue;
9
+ } | undefined | null;
10
+ declare const unsetSymbol: unique symbol;
11
+ export declare function asyncProp<ValueGeneric>(initialValue?: UnPromise<ValueGeneric> | Promise<UnPromise<ValueGeneric>> | typeof unsetSymbol): AsyncProp<ValueGeneric>;
12
+ export type SetAsyncPropInputs<ValueGeneric> = {
13
+ updateIfThisChanges?: JsonValue;
14
+ } & ({
15
+ createPromise: () => Promise<UnPromise<ValueGeneric>>;
16
+ } | {
17
+ resolution: UnPromise<ValueGeneric>;
18
+ } | {
19
+ promise: Promise<UnPromise<ValueGeneric>>;
20
+ });
21
+ export declare function ensureAsyncProp<ValueGeneric, StatePropGeneric extends PropertyKey>({ state, stateProp, updateState: inputUpdateState, ...newValue }: {
22
+ state: Record<StatePropGeneric, AsyncProp<ValueGeneric>>;
23
+ stateProp: StatePropGeneric;
24
+ updateState: (newState: Record<StatePropGeneric, AsyncProp<ValueGeneric>>) => void;
25
+ } & SetAsyncPropInputs<ValueGeneric>): void;
26
+ export {};
27
+ //# sourceMappingURL=async-prop.d.ts.map
@@ -0,0 +1,102 @@
1
+ import { areJsonEqual, ensureError, isPromiseLike, typedHasProperty, } from '@augment-vir/common';
2
+ const unsetSymbol = Symbol('unset');
3
+ export function asyncProp(initialValue = unsetSymbol) {
4
+ if (initialValue === unsetSymbol) {
5
+ return undefined;
6
+ }
7
+ else if (isPromiseLike(initialValue)) {
8
+ return {
9
+ promise: initialValue,
10
+ };
11
+ }
12
+ else {
13
+ return {
14
+ resolution: initialValue,
15
+ };
16
+ }
17
+ }
18
+ function shouldForceUpdate(newValue, currentValue) {
19
+ if (!currentValue) {
20
+ return true;
21
+ }
22
+ if (typedHasProperty(newValue, 'updateIfThisChanges')) {
23
+ if (typedHasProperty(currentValue, 'lastTrigger')) {
24
+ return !areJsonEqual(currentValue.lastTrigger, newValue.updateIfThisChanges);
25
+ }
26
+ else {
27
+ return true;
28
+ }
29
+ }
30
+ return false;
31
+ }
32
+ export function ensureAsyncProp({ state, stateProp, updateState: inputUpdateState, ...newValue }) {
33
+ function updateState(newStateValue) {
34
+ /**
35
+ * As cast needed here because the RecordGeneric type isn't strong enough to narrow its keys
36
+ * to StatePropGeneric, it just thinks they're all strings
37
+ */
38
+ inputUpdateState({ [stateProp]: newStateValue });
39
+ }
40
+ const forceUpdate = shouldForceUpdate(newValue, state[stateProp]);
41
+ const currentValue = forceUpdate ? undefined : state[stateProp];
42
+ if (currentValue === null || currentValue === void 0 ? void 0 : currentValue.error) {
43
+ // abort if there's an error
44
+ return;
45
+ }
46
+ if (currentValue && 'resolution' in currentValue) {
47
+ // abort if the async value has already been resolved
48
+ return;
49
+ }
50
+ const lastTriggerObject = typedHasProperty(newValue, 'updateIfThisChanges')
51
+ ? { lastTrigger: newValue.updateIfThisChanges }
52
+ : {};
53
+ // if given a resolution value, set that
54
+ if ('resolution' in newValue) {
55
+ return updateState({
56
+ resolution: newValue.resolution,
57
+ ...lastTriggerObject,
58
+ });
59
+ }
60
+ // if there is no promise or resolution, set a promise
61
+ const needsNewPromise = currentValue == undefined || !('promise' in currentValue);
62
+ const needsChaining = currentValue == undefined || !currentValue.isChainedAlready;
63
+ if (!needsNewPromise && !needsChaining) {
64
+ // abort, there is nothing to do
65
+ return;
66
+ }
67
+ const newPromise = needsNewPromise
68
+ ? 'promise' in newValue
69
+ ? newValue.promise
70
+ : 'createPromise' in newValue
71
+ ? newValue.createPromise()
72
+ : undefined
73
+ : undefined;
74
+ if (needsNewPromise && !newPromise) {
75
+ throw new Error(`Was not able to create a new promise for state.${String(stateProp)}: missing "promise" or "createPromise" key for ${ensureAsyncProp.name}`);
76
+ }
77
+ const promiseToChain = newPromise !== null && newPromise !== void 0 ? newPromise : currentValue === null || currentValue === void 0 ? void 0 : currentValue.promise;
78
+ if (!promiseToChain) {
79
+ // at this point there is definitely a promise to chain
80
+ throw new Error('Failed to find promise to chain.');
81
+ }
82
+ promiseToChain
83
+ .then((value) => {
84
+ updateState({
85
+ promise: promiseToChain,
86
+ resolution: value,
87
+ ...lastTriggerObject,
88
+ });
89
+ })
90
+ .catch((error) => {
91
+ updateState({
92
+ promise: promiseToChain,
93
+ error: ensureError(error),
94
+ ...lastTriggerObject,
95
+ });
96
+ });
97
+ updateState({
98
+ promise: promiseToChain,
99
+ isChainedAlready: true,
100
+ ...lastTriggerObject,
101
+ });
102
+ }
@@ -4,3 +4,4 @@ export type CssVarName<TagName extends string> = `--${TagName}-string`;
4
4
  export type CssVarNameOrValueMap<CssVarKeys extends string> = Record<CssVarKeys, CSSResult>;
5
5
  export declare function createCssVarNamesMap<TagName extends string, CssVarKeys extends string>(tagName: TagName, cssVarsInit: CssVarsInitMap<CssVarKeys> | undefined): CssVarNameOrValueMap<CssVarKeys>;
6
6
  export declare function createCssVarValuesMap<CssVarKeys extends string>(cssVarInitMap: CssVarsInitMap<CssVarKeys> | undefined, cssVarNamesMap: CssVarNameOrValueMap<CssVarKeys>): CssVarNameOrValueMap<CssVarKeys>;
7
+ //# sourceMappingURL=css-vars.d.ts.map
@@ -1,4 +1,4 @@
1
- import { DefinedTypedEvent, DefinedTypedEventNameDefinition, TypedEvent } from '../typed-event/typed-event';
1
+ import { DefinedTypedEvent, DefinedTypedEventNameDefinition, TypedEvent } from '../../typed-event/typed-event';
2
2
  export type EventsInitMap = Record<string, DefinedTypedEventNameDefinition<any>>;
3
3
  export declare function defineElementEvent<EventDetailGeneric>(): DefinedTypedEventNameDefinition<EventDetailGeneric>;
4
4
  export type EventInitMapEventDetailExtractor<EventTypeNameGeneric extends keyof EventsInitGeneric, EventsInitGeneric extends EventsInitMap> = EventsInitGeneric[EventTypeNameGeneric] extends DefinedTypedEventNameDefinition<infer R> ? R : never;
@@ -8,3 +8,4 @@ export type EventDescriptorMap<EventsInitGeneric extends EventsInitMap> = {
8
8
  export type EventObjectEventDetailExtractor<EventObjectGeneric extends DefinedTypedEvent<any, any>> = EventObjectGeneric extends DefinedTypedEvent<string, infer R> ? R : never;
9
9
  export type ElementEventDetailExtractor<ElementEventGeneric extends TypedEvent<any, any>> = ElementEventGeneric extends TypedEvent<string, infer R> ? R : never;
10
10
  export declare function createEventDescriptorMap<EventsInitGeneric extends EventsInitMap>(eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<EventsInitGeneric>;
11
+ //# sourceMappingURL=element-events.d.ts.map
@@ -1,4 +1,4 @@
1
- import { defineTypedEvent, } from '../typed-event/typed-event';
1
+ import { defineTypedEvent, } from '../../typed-event/typed-event';
2
2
  export function defineElementEvent() {
3
3
  return defineTypedEvent();
4
4
  }
@@ -1,4 +1,3 @@
1
- import { DeclarativeElement } from './declarative-element';
2
1
  export type PropertyInitMapBase = Record<PropertyKey, unknown>;
3
2
  export type ElementProperty<KeyGeneric extends string | number | symbol, ValueGeneric> = {
4
3
  name: KeyGeneric;
@@ -12,5 +11,5 @@ export type StaticElementPropertyDescriptor<PropName extends string, PropValue>
12
11
  export type ElementPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase> = {
13
12
  [Property in keyof PropertyInitGeneric]: StaticElementPropertyDescriptor<string, PropertyInitGeneric[Property]>;
14
13
  };
15
- export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean): PropertyInitGeneric;
16
14
  export declare function createPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase>(propertyInit: PropertyInitGeneric | undefined): ElementPropertyDescriptorMap<PropertyInitGeneric>;
15
+ //# sourceMappingURL=element-properties.d.ts.map
@@ -0,0 +1,21 @@
1
+ export function createPropertyDescriptorMap(propertyInit) {
2
+ if (!propertyInit) {
3
+ return {};
4
+ }
5
+ return Object.keys(propertyInit)
6
+ .filter((key) => {
7
+ if (typeof key === 'string') {
8
+ return true;
9
+ }
10
+ else {
11
+ throw new Error(`Property init cannot have non string keys: "${key}"`);
12
+ }
13
+ })
14
+ .reduce((accum, currentKey) => {
15
+ accum[currentKey] = {
16
+ propName: currentKey,
17
+ initValue: propertyInit[currentKey],
18
+ };
19
+ return accum;
20
+ }, {});
21
+ }
@@ -0,0 +1,4 @@
1
+ import { DeclarativeElement } from '../declarative-element';
2
+ import { PropertyInitMapBase } from './element-properties';
3
+ export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean): PropertyInitGeneric;
4
+ //# sourceMappingURL=element-updater-proxy.d.ts.map
@@ -18,26 +18,29 @@ export function createElementUpdaterProxy(element, verifyExists) {
18
18
  if (verifyExists) {
19
19
  assertValidPropertyName(propertyName, element, element.tagName);
20
20
  }
21
- const targetValue = target[propertyName];
22
- if (typeof targetValue === 'function') {
23
- return targetValue.bind(target);
24
- }
25
21
  return elementAsProps[propertyName];
26
22
  },
27
- set: (target, propertyName, value) => {
23
+ set: (target, propertyName, newValue) => {
28
24
  if (verifyExists) {
29
25
  assertValidPropertyName(propertyName, element, element.tagName);
30
26
  }
31
- target[propertyName] = value;
32
- elementAsProps[propertyName] = value;
27
+ /**
28
+ * Don't worry about storing the value (no need to have duplicates of teh values) but at
29
+ * least set the property on target so we can detect it in "ownKeys" and
30
+ * "getOwnPropertyDescriptor".
31
+ */
32
+ target[propertyName] = undefined;
33
+ elementAsProps[propertyName] = newValue;
33
34
  return true;
34
35
  },
35
- ownKeys: (target) => Reflect.ownKeys(target),
36
+ ownKeys: (target) => {
37
+ return Reflect.ownKeys(target);
38
+ },
36
39
  getOwnPropertyDescriptor(target, propertyName) {
37
40
  if (propertyName in target) {
38
41
  return {
39
42
  get value() {
40
- return target[propertyName];
43
+ return elementAsProps[propertyName];
41
44
  },
42
45
  configurable: true,
43
46
  enumerable: true,
@@ -45,28 +48,9 @@ export function createElementUpdaterProxy(element, verifyExists) {
45
48
  }
46
49
  return undefined;
47
50
  },
48
- has: (target, propertyName) => Reflect.has(target, propertyName),
51
+ has: (target, propertyName) => {
52
+ return Reflect.has(target, propertyName);
53
+ },
49
54
  });
50
55
  return propsProxy;
51
56
  }
52
- export function createPropertyDescriptorMap(propertyInit) {
53
- if (!propertyInit) {
54
- return {};
55
- }
56
- return Object.keys(propertyInit)
57
- .filter((key) => {
58
- if (typeof key === 'string') {
59
- return true;
60
- }
61
- else {
62
- throw new Error(`Property init cannot have non string keys: "${key}"`);
63
- }
64
- })
65
- .reduce((accum, currentKey) => {
66
- accum[currentKey] = {
67
- propName: currentKey,
68
- initValue: propertyInit[currentKey],
69
- };
70
- return accum;
71
- }, {});
72
- }
@@ -19,3 +19,4 @@ export declare function createHostClassNamesMap<TagName extends string, HostClas
19
19
  * what the host class names are
20
20
  */
21
21
  any, any>>(tagName: TagName, hostClassesInit?: HostClassesInitGeneric): HostClassNamesMap<TagName, HostClassKeys>;
22
+ //# sourceMappingURL=host-classes.d.ts.map
@@ -21,3 +21,4 @@ export declare function applyHostClasses<InputsGeneric extends PropertyInitMapBa
21
21
  state: Readonly<StateGeneric>;
22
22
  inputs: Readonly<InputsGeneric>;
23
23
  }): void;
24
+ //# sourceMappingURL=styles.d.ts.map
@@ -1,2 +1,3 @@
1
1
  export type WithTagName<TagName extends string, Suffix extends string> = `${TagName}-${Suffix}`;
2
2
  export declare function toHtmlSafeWithTagName<TagName extends string>(tagName: TagName, forHtmlSafe: string): WithTagName<TagName, string>;
3
+ //# sourceMappingURL=tag-name.d.ts.map
@@ -1,8 +1,9 @@
1
1
  import { TemplateResult } from 'lit';
2
2
  import { TypedEvent } from '../typed-event/typed-event';
3
3
  import { DeclarativeElement, HostInstanceType } from './declarative-element';
4
- import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './element-events';
5
- import { PropertyInitMapBase } from './element-properties';
4
+ import { AsyncProp, SetAsyncPropInputs } from './properties/async-prop';
5
+ import { EventDescriptorMap, EventInitMapEventDetailExtractor, EventsInitMap } from './properties/element-events';
6
+ import { PropertyInitMapBase } from './properties/element-properties';
6
7
  export type RenderCallback<InputsGeneric extends PropertyInitMapBase = any, StateGeneric extends PropertyInitMapBase = any, EventsInitGeneric extends EventsInitMap = any, HostClassKeys extends string = any, CssVarKeys extends string = any> = (params: RenderParams<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => TemplateResult;
7
8
  export type InitCallback<InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = (params: RenderParams<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>) => void;
8
9
  export type UpdateStateCallback<StateGeneric extends PropertyInitMapBase> = (newState: Partial<StateGeneric>) => void;
@@ -11,12 +12,16 @@ export type RenderParams<InputsGeneric extends PropertyInitMapBase, StateInitGen
11
12
  updateState: UpdateStateCallback<StateInitGeneric>;
12
13
  events: EventDescriptorMap<EventsInitGeneric>;
13
14
  host: HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
14
- dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>>) => boolean;
15
+ dispatch: <EventTypeNameGeneric extends keyof EventsInitGeneric>(event: TypedEvent<EventTypeNameGeneric extends string ? EventTypeNameGeneric : never, EventInitMapEventDetailExtractor<EventTypeNameGeneric, EventsInitGeneric>> | Event) => boolean;
15
16
  inputs: InputsGeneric;
16
17
  /**
17
- * Same as dispatchElementEvent but without the extra types. This allows you to emit any events,
18
- * even events from other custom elements.
18
+ * Updates async props in the state if they have not already been set. Once promises settle,
19
+ * this automatically updates the state. In order to re-trigger an async prop, set it to
20
+ * undefined first.
19
21
  */
20
- genericDispatch: (event: Event) => boolean;
22
+ ensureAsyncProp: (values: Partial<{
23
+ [StateKey in keyof StateInitGeneric as StateInitGeneric[StateKey] extends AsyncProp<any> ? StateKey : never]: StateInitGeneric[StateKey] extends AsyncProp<infer ValueGeneric> ? SetAsyncPropInputs<ValueGeneric> : never;
24
+ }>) => void;
21
25
  };
22
26
  export declare function createRenderParams<InputsGeneric extends PropertyInitMapBase, StateGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string>(element: DeclarativeElement<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, eventsMap: EventDescriptorMap<EventsInitGeneric>): RenderParams<InputsGeneric, StateGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
27
+ //# sourceMappingURL=render-callback.d.ts.map
@@ -1,21 +1,31 @@
1
1
  import { getObjectTypedKeys } from '@augment-vir/common';
2
+ import { ensureAsyncProp } from './properties/async-prop';
2
3
  export function createRenderParams(element, eventsMap) {
4
+ function updateState(partialProps) {
5
+ getObjectTypedKeys(partialProps).forEach((propKey) => {
6
+ element.instanceState[propKey] = partialProps[propKey];
7
+ });
8
+ }
3
9
  const renderParams = {
4
- /**
5
- * These two dispatch properties do the same thing but their interfaces are different.
6
- * DispatchEvent's type interface is much stricter.
7
- */
8
10
  dispatch: (event) => element.dispatchEvent(event),
9
- genericDispatch: (event) => element.dispatchEvent(event),
10
- updateState: (partialProps) => {
11
- getObjectTypedKeys(partialProps).forEach((propKey) => {
12
- element.instanceState[propKey] = partialProps[propKey];
13
- });
14
- },
11
+ updateState,
15
12
  inputs: element.instanceInputs,
16
13
  host: element,
17
14
  state: element.instanceState,
18
15
  events: eventsMap,
16
+ ensureAsyncProp: (values) => {
17
+ Object.entries(values).forEach(([stateKey, newSet,]) => {
18
+ if (!(stateKey in element.instanceState)) {
19
+ throw new Error(`Invalid key given to ensureAsyncProp: ${stateKey}`);
20
+ }
21
+ ensureAsyncProp({
22
+ state: element.instanceState,
23
+ updateState: updateState,
24
+ stateProp: stateKey,
25
+ ...newSet,
26
+ });
27
+ });
28
+ },
19
29
  };
20
30
  return renderParams;
21
31
  }
@@ -1 +1,2 @@
1
1
  export declare const DeclarativeElementMarkerSymbol: unique symbol;
2
+ //# sourceMappingURL=declarative-element-marker-symbol.d.ts.map
package/dist/index.d.ts CHANGED
@@ -4,15 +4,18 @@ export * from './declarative-element/define-element-no-inputs';
4
4
  export type { DeclarativeElementDefinitionOptions } from './declarative-element/definition-options';
5
5
  export * from './declarative-element/directives/assign-with-clean-up.directive';
6
6
  export * from './declarative-element/directives/assign.directive';
7
- export * from './declarative-element/directives/awaiting.directive';
8
7
  export * from './declarative-element/directives/directive-helpers';
9
8
  export * from './declarative-element/directives/listen.directive';
10
9
  export * from './declarative-element/directives/on-dom-created.directive';
11
10
  export * from './declarative-element/directives/on-resize.directive';
12
- export * from './declarative-element/element-events';
13
- export * from './declarative-element/element-properties';
11
+ export * from './declarative-element/directives/render-async-prop.directive';
12
+ export * from './declarative-element/directives/render-if.directive';
13
+ export * from './declarative-element/properties/async-prop';
14
+ export * from './declarative-element/properties/element-events';
15
+ export * from './declarative-element/properties/element-properties';
14
16
  export * from './declarative-element/render-callback';
15
17
  export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
16
18
  export * from './template-transforms/vir-css/vir-css';
17
19
  export * from './template-transforms/vir-html/vir-html';
18
20
  export * from './typed-event/typed-event';
21
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -3,13 +3,15 @@ export * from './declarative-element/define-element';
3
3
  export * from './declarative-element/define-element-no-inputs';
4
4
  export * from './declarative-element/directives/assign-with-clean-up.directive';
5
5
  export * from './declarative-element/directives/assign.directive';
6
- export * from './declarative-element/directives/awaiting.directive';
7
6
  export * from './declarative-element/directives/directive-helpers';
8
7
  export * from './declarative-element/directives/listen.directive';
9
8
  export * from './declarative-element/directives/on-dom-created.directive';
10
9
  export * from './declarative-element/directives/on-resize.directive';
11
- export * from './declarative-element/element-events';
12
- export * from './declarative-element/element-properties';
10
+ export * from './declarative-element/directives/render-async-prop.directive';
11
+ export * from './declarative-element/directives/render-if.directive';
12
+ export * from './declarative-element/properties/async-prop';
13
+ export * from './declarative-element/properties/element-events';
14
+ export * from './declarative-element/properties/element-properties';
13
15
  export * from './declarative-element/render-callback';
14
16
  export { requireAllCustomElementsToBeDeclarativeElements } from './require-declarative-element';
15
17
  export * from './template-transforms/vir-css/vir-css';
@@ -1,2 +1,3 @@
1
1
  export declare let declarativeElementRequired: boolean;
2
2
  export declare function requireAllCustomElementsToBeDeclarativeElements(): void;
3
+ //# sourceMappingURL=require-declarative-element.d.ts.map
@@ -2,3 +2,4 @@ export type ConstructorWithTagName = Function & {
2
2
  tagName: string;
3
3
  };
4
4
  export declare function hasStaticTagName(value: unknown): value is ConstructorWithTagName;
5
+ //# sourceMappingURL=has-static-tag-name.d.ts.map
@@ -4,3 +4,4 @@ export declare function setMappedTemplate<PossibleValues>(templateStringsKey: Te
4
4
  result: boolean;
5
5
  reason: string;
6
6
  };
7
+ //# sourceMappingURL=nested-mapped-templates.d.ts.map
@@ -14,3 +14,4 @@ export declare function getTransformedTemplate<PossibleValues>(templateStringsKe
14
14
  values: PossibleValues[];
15
15
  };
16
16
  export declare function transformTemplate<TransformsGeneric extends CheckAndTransform<any>[], PossibleValues>(inputTemplateStrings: TemplateStringsArray, inputValues: PossibleValues[], checksAndTransforms: TransformsGeneric, assertValidString?: (templateStringPart: string) => void): TemplateTransform;
17
+ //# sourceMappingURL=transform-template.d.ts.map
@@ -5,3 +5,4 @@ export type CssTemplateTransform = {
5
5
  valueIndexDeletions: number[];
6
6
  };
7
7
  export declare function transformCssTemplate(inputTemplateStrings: TemplateStringsArray, inputValues: (number | CSSResultGroup | DeclarativeElementDefinition)[]): CssTemplateTransform;
8
+ //# sourceMappingURL=css-transform.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import { CSSResult, CSSResultGroup } from 'lit';
2
2
  import { DeclarativeElementDefinition } from '../../declarative-element/declarative-element';
3
3
  export declare function css(inputTemplateStrings: TemplateStringsArray, ...inputValues: (number | CSSResultGroup | DeclarativeElementDefinition)[]): CSSResult;
4
+ //# sourceMappingURL=vir-css.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import { HTMLTemplateResult } from 'lit';
2
2
  import { TemplateTransform } from '../transform-template';
3
3
  export declare function transformHtmlTemplate(litTemplate: HTMLTemplateResult): TemplateTransform;
4
+ //# sourceMappingURL=html-transform.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import { HTMLTemplateResult } from 'lit';
2
2
  /** Enables interpolation of DeclarativeElement tag names */
3
3
  export declare function html(inputTemplateStrings: TemplateStringsArray, ...inputValues: unknown[]): HTMLTemplateResult;
4
+ //# sourceMappingURL=vir-html.d.ts.map
@@ -17,3 +17,4 @@ export type DefinedTypedEvent<EventTypeNameGeneric extends string, EventDetailGe
17
17
  * Example: const myCustomEvent = defineTypedEvent<number>()('my-custom-event')
18
18
  */
19
19
  export declare function defineTypedEvent<EventDetailGeneric>(): <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
20
+ //# sourceMappingURL=typed-event.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "6.3.4",
3
+ "version": "7.0.1",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -25,53 +25,50 @@
25
25
  "main": "dist/index.js",
26
26
  "types": "dist/index.d.ts",
27
27
  "scripts": {
28
- "build": "virmator frontend build",
29
- "compile": "rm -rf dist && tsc --project tsconfig.json",
28
+ "compile": "rm -rf dist && rm tsconfig.tsbuildinfo && tsc --project tsconfig.json",
30
29
  "docs:update": "virmator code-in-markdown",
31
30
  "format": "virmator format",
32
- "preview": "virmator frontend preview",
33
- "publish": "npm run compile && npm run test:all && virmator publish",
34
- "spellcheck": "virmator spellcheck",
31
+ "publish": "virmator publish \"npm run compile && npm run test:all\"",
35
32
  "start": "npm install && virmator frontend",
36
33
  "test": "npm run test:types && virmator test-web",
37
- "test:all": "npm run test:types && npm test && npm run spellcheck && npm run test:format && npm run test:docs",
34
+ "test:all": "npm run test:types && npm test && npm run test:spelling && npm run test:format && npm run test:docs",
38
35
  "test:docs": "virmator code-in-markdown check",
39
36
  "test:format": "virmator format check",
40
- "test:types": "tsc --noEmit",
41
- "test:web": "virmator test-web"
37
+ "test:spelling": "virmator spellcheck",
38
+ "test:types": "tsc --noEmit"
42
39
  },
43
40
  "dependencies": {
44
- "@augment-vir/browser": "^6.1.5",
45
- "@augment-vir/common": "^6.1.5",
46
- "lit": "2.5.0"
41
+ "@augment-vir/browser": "^10.0.0",
42
+ "@augment-vir/common": "^10.0.0",
43
+ "lit": "2.6.1"
47
44
  },
48
45
  "devDependencies": {
49
- "@augment-vir/browser-testing": "^6.1.5",
46
+ "@augment-vir/browser-testing": "^10.0.0",
47
+ "@augment-vir/node-js": "^10.0.0",
50
48
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
51
49
  "@open-wc/testing": "^3.1.7",
52
- "@types/chai": "^4.3.4",
53
50
  "@types/mocha": "^10.0.1",
54
51
  "@web/dev-server-esbuild": "^0.3.3",
55
52
  "@web/test-runner": "^0.15.0",
56
53
  "@web/test-runner-commands": "^0.6.5",
57
54
  "@web/test-runner-playwright": "^0.9.0",
58
55
  "ansi-colors": "^4.1.3",
59
- "chai": "^4.3.7",
60
- "cspell": "^6.17.0",
61
- "istanbul-smart-text-reporter": "^1.0.1",
56
+ "cspell": "^6.19.2",
57
+ "istanbul-smart-text-reporter": "^1.1.1",
62
58
  "markdown-code-example-inserter": "^0.1.13",
63
- "mocha": "^10.2.0",
64
59
  "mocha-spec-reporter-with-file-names": "^0.0.3",
65
60
  "nyc": "^15.1.0",
66
- "prettier": "^2.8.1",
61
+ "prettier": "^2.8.3",
67
62
  "prettier-plugin-jsdoc": "^0.4.2",
68
- "prettier-plugin-multiline-arrays": "^1.1.2",
69
- "prettier-plugin-organize-imports": "^3.2.1",
70
- "prettier-plugin-packagejson": "^2.3.0",
71
- "prettier-plugin-sort-json": "^0.0.3",
63
+ "prettier-plugin-multiline-arrays": "^1.1.3",
64
+ "prettier-plugin-organize-imports": "^3.2.2",
65
+ "prettier-plugin-packagejson": "^2.4.0",
66
+ "prettier-plugin-sort-json": "^1.0.0",
72
67
  "prettier-plugin-toml": "^0.3.1",
73
68
  "ts-node": "^10.9.1",
74
- "virmator": "^5.2.1",
75
- "vite": "^4.0.1"
69
+ "type-fest": "^3.5.2",
70
+ "typescript": "^4.9.4",
71
+ "virmator": "^5.3.3",
72
+ "vite": "^4.0.4"
76
73
  }
77
74
  }
@@ -1,18 +0,0 @@
1
- export type MaybePromise<T> = (T extends Promise<infer ValueType> ? T | ValueType : Promise<T> | T) | undefined | {
2
- error: Error;
3
- };
4
- export type CreateStateUpdatingPromiseInputs<InnerValueGeneric, KeyGeneric extends PropertyKey, StateGeneric extends Readonly<Record<KeyGeneric, MaybePromise<InnerValueGeneric>>>> = {
5
- updateState: (newState: Partial<StateGeneric>) => void;
6
- stateKey: KeyGeneric;
7
- } & ({
8
- createPromiseCallback: () => Promise<InnerValueGeneric>;
9
- promise?: undefined;
10
- } | {
11
- promise: Promise<InnerValueGeneric>;
12
- createPromiseCallback?: undefined;
13
- });
14
- export declare function createStateUpdatingPromiseIfUndefined<InnerValueGeneric, KeyGeneric extends PropertyKey, StateGeneric extends Readonly<Record<KeyGeneric, MaybePromise<InnerValueGeneric>>>>(inputs: CreateStateUpdatingPromiseInputs<InnerValueGeneric, KeyGeneric, StateGeneric> & {
15
- state: StateGeneric;
16
- }): void;
17
- export declare function awaiting<ValueGeneric, FallbackGeneric, CallbackReturnGeneric>(input: MaybePromise<ValueGeneric>, notResolvedYetFallback: FallbackGeneric, resolvedCallback: (resolved: ValueGeneric) => CallbackReturnGeneric): CallbackReturnGeneric | FallbackGeneric | Error | undefined;
18
- export declare function ensureError(input: unknown): Error;
@@ -1,42 +0,0 @@
1
- import { extractErrorMessage, isPromiseLike, typedHasProperty } from '@augment-vir/common';
2
- export function createStateUpdatingPromiseIfUndefined(inputs) {
3
- const { state, stateKey } = inputs;
4
- const currentValue = state[stateKey];
5
- if (currentValue === undefined) {
6
- createStateUpdatingPromise(inputs);
7
- }
8
- }
9
- function createStateUpdatingPromise({ updateState, stateKey, createPromiseCallback: promiseCallback, promise, }) {
10
- const output = promise !== null && promise !== void 0 ? promise : promiseCallback();
11
- // as casts below are required because, even though all the generics agree, TypeScript can't figure that out here
12
- if (output instanceof Promise) {
13
- output
14
- .then((result) => {
15
- updateState({ [stateKey]: result });
16
- })
17
- .catch((thrownError) => {
18
- const guaranteedError = ensureError(thrownError);
19
- updateState({ [stateKey]: { error: guaranteedError } });
20
- });
21
- }
22
- updateState({ [stateKey]: output });
23
- }
24
- export function awaiting(input, notResolvedYetFallback, resolvedCallback) {
25
- if (isPromiseLike(input) || input == undefined) {
26
- return notResolvedYetFallback;
27
- }
28
- else if (typedHasProperty(input, 'error')) {
29
- return input.error;
30
- }
31
- else {
32
- return resolvedCallback(input);
33
- }
34
- }
35
- export function ensureError(input) {
36
- if (input instanceof Error) {
37
- return input;
38
- }
39
- else {
40
- return new Error(extractErrorMessage(input));
41
- }
42
- }