element-vir 18.0.0 → 19.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 (31) hide show
  1. package/README.md +1 -1
  2. package/dist/declarative-element/declarative-element.d.ts +1 -1
  3. package/dist/declarative-element/define-element-no-inputs.js +4 -5
  4. package/dist/declarative-element/directives/assign-with-clean-up.directive.d.ts +1 -2
  5. package/dist/declarative-element/directives/assign-with-clean-up.directive.js +1 -3
  6. package/dist/declarative-element/directives/assign.directive.d.ts +1 -1
  7. package/dist/declarative-element/directives/assign.directive.js +1 -2
  8. package/dist/declarative-element/directives/create-attribute-directive.d.ts +1 -1
  9. package/dist/declarative-element/directives/create-attribute-directive.js +1 -2
  10. package/dist/declarative-element/directives/directive-helpers.d.ts +1 -1
  11. package/dist/declarative-element/directives/directive-helpers.js +1 -1
  12. package/dist/declarative-element/directives/is-resolved.directive.d.ts +4 -0
  13. package/dist/declarative-element/directives/is-resolved.directive.js +15 -0
  14. package/dist/declarative-element/directives/listen.directive.d.ts +1 -1
  15. package/dist/declarative-element/directives/listen.directive.js +1 -2
  16. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +1 -1
  17. package/dist/declarative-element/directives/on-dom-created.directive.js +1 -1
  18. package/dist/declarative-element/directives/on-resize.directive.d.ts +1 -1
  19. package/dist/declarative-element/directives/on-resize.directive.js +1 -1
  20. package/dist/declarative-element/directives/render-if.directive.js +1 -2
  21. package/dist/declarative-element/properties/element-events.d.ts +3 -3
  22. package/dist/declarative-element/properties/element-events.js +1 -1
  23. package/dist/declarative-element/properties/element-updater-proxy.js +1 -1
  24. package/dist/declarative-element/render-callback.d.ts +2 -2
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/lit-exports.d.ts +2 -0
  28. package/dist/lit-exports.js +2 -0
  29. package/package.json +9 -9
  30. package/dist/declarative-element/directives/is-render-ready.directive.d.ts +0 -4
  31. package/dist/declarative-element/directives/is-render-ready.directive.js +0 -28
package/README.md CHANGED
@@ -637,7 +637,7 @@ export const MyWithRenderIf = defineElement<{shouldRender: boolean}>()({
637
637
 
638
638
  ### `asyncProp`
639
639
 
640
- Use `renderAsync` or `isRenderReady` in conjunction with `asyncProp` to seamlessly render and update element state based on async values:
640
+ Use `renderAsync` or `isResolved` in conjunction with `asyncProp` to seamlessly render and update element state based on async values:
641
641
 
642
642
  <!-- example-link: src/readme-examples/my-with-async-prop.element.ts -->
643
643
 
@@ -47,7 +47,7 @@ export interface StaticDeclarativeElementProperties<TagName extends CustomElemen
47
47
  assignedInputs: Inputs | undefined;
48
48
  /** Pass through the render callback for direct unit testability */
49
49
  readonly renderCallback: RenderCallback<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
50
- readonly events: EventDescriptorMap<EventsInit>;
50
+ readonly events: EventDescriptorMap<TagName, EventsInit>;
51
51
  readonly stateInitStatic: ElementPropertyDescriptorMap<StateInit>;
52
52
  readonly init: RequiredBy<DeclarativeElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric>, 'stateInitStatic' | 'events'>;
53
53
  readonly inputsType: Inputs;
@@ -2,7 +2,7 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
2
2
  if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
3
3
  return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
4
4
  };
5
- import { ensureError, getObjectTypedKeys, kebabCaseToCamelCase, } from '@augment-vir/common';
5
+ import { ensureErrorAndPrependMessage, extractErrorMessage, getObjectTypedKeys, kebabCaseToCamelCase, } from '@augment-vir/common';
6
6
  import { defineCssVars } from 'lit-css-vars';
7
7
  import { css } from '../template-transforms/vir-css/vir-css';
8
8
  import { DeclarativeElement, } from './declarative-element';
@@ -10,7 +10,7 @@ import { IgnoreInputsNotBeenSetBeforeWarningSymbol, defaultDeclarativeElementDef
10
10
  import { hasDeclarativeElementParent } from './has-declarative-element-parent';
11
11
  import { assignInputs } from './properties/assign-inputs';
12
12
  import { assertValidCssProperties } from './properties/css-properties';
13
- import { createEventDescriptorMap } from './properties/element-events';
13
+ import { createEventDescriptorMap, } from './properties/element-events';
14
14
  import { bindReactiveProperty, createElementUpdaterProxy } from './properties/element-updater-proxy';
15
15
  import { createHostClassNamesMap } from './properties/host-classes';
16
16
  import { applyHostClasses, hostClassNamesToStylesInput } from './properties/styles';
@@ -101,10 +101,9 @@ export function defineElementNoInputs(initInput) {
101
101
  return renderResult;
102
102
  }
103
103
  catch (caught) {
104
- const error = ensureError(caught);
105
- error.message = `Failed to render '${initInput.tagName}': ${error.message}`;
104
+ const error = ensureErrorAndPrependMessage(caught, `Failed to render ${initInput.tagName}`);
106
105
  this._lastRenderError = error;
107
- throw error;
106
+ return extractErrorMessage(error);
108
107
  }
109
108
  }
110
109
  connectedCallback() {
@@ -1,5 +1,4 @@
1
- import { AsyncDirective } from 'lit/async-directive.js';
2
- import { PartInfo } from 'lit/directive.js';
1
+ import { AsyncDirective, PartInfo } from '../../lit-exports';
3
2
  import { ElementDefinitionWithInputsType } from './assign.directive';
4
3
  export type CleanupCallback<T> = (oldValue: T) => void;
5
4
  /**
@@ -1,6 +1,4 @@
1
- import { AsyncDirective } from 'lit/async-directive.js';
2
- import { directive } from 'lit/directive.js';
3
- import { noChange } from '../../lit-exports';
1
+ import { AsyncDirective, directive, noChange } from '../../lit-exports';
4
2
  import { assignInputs } from '../properties/assign-inputs';
5
3
  import { extractElement } from './directive-helpers';
6
4
  /**
@@ -1,4 +1,4 @@
1
- import { DirectiveResult } from 'lit/directive.js';
1
+ import { DirectiveResult } from '../../lit-exports';
2
2
  import { PropertyInitMapBase } from '../properties/element-properties';
3
3
  export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBase = PropertyInitMapBase> = {
4
4
  inputsType: InputsType;
@@ -1,5 +1,4 @@
1
- import { directive, Directive } from 'lit/directive.js';
2
- import { noChange } from '../../lit-exports';
1
+ import { directive, Directive, noChange } from '../../lit-exports';
3
2
  import { assignInputs } from '../properties/assign-inputs';
4
3
  import { extractElement } from './directive-helpers';
5
4
  /**
@@ -1,4 +1,4 @@
1
- import { PartInfo } from 'lit/directive.js';
1
+ import { PartInfo } from '../../lit-exports';
2
2
  export declare function createAttributeDirective(attributeName: string): {
3
3
  attributeSelector(attributeValue: string): string;
4
4
  attributeDirective(attributeValue: string): import("lit-html/directive").DirectiveResult<{
@@ -1,5 +1,4 @@
1
- import { directive, Directive } from 'lit/directive.js';
2
- import { noChange } from '../../lit-exports';
1
+ import { directive, Directive, noChange } from '../../lit-exports';
3
2
  import { extractElement } from './directive-helpers';
4
3
  export function createAttributeDirective(attributeName) {
5
4
  const newDirective = directive(
@@ -1,4 +1,4 @@
1
- import { ElementPartInfo, PartInfo } from 'lit/directive.js';
1
+ import { ElementPartInfo, PartInfo } from '../../lit-exports';
2
2
  /** For some reason these aren't defined in lit's types already. */
3
3
  export type ExtraPartInfoProperties = {
4
4
  element: Element;
@@ -1,4 +1,4 @@
1
- import { PartType } from 'lit/directive.js';
1
+ import { PartType } from '../../lit-exports';
2
2
  export function extractElement(partInfo, directiveName) {
3
3
  assertIsElementPartInfo(partInfo, directiveName);
4
4
  const element = partInfo.element;
@@ -0,0 +1,4 @@
1
+ import { AsyncPropValue } from './async-prop';
2
+ export declare function isResolved<Value extends AsyncPropValue<any>>(asyncPropInput: Value): asyncPropInput is Exclude<Value, Promise<any>>;
3
+ export declare function isError(asyncPropInput: unknown): asyncPropInput is Error;
4
+ export declare function resolvedOrUndefined<Value extends AsyncPropValue<any>>(asyncPropInput: Value): Exclude<Value, Promise<any>> | undefined;
@@ -0,0 +1,15 @@
1
+ import { isPromiseLike } from '@augment-vir/common';
2
+ export function isResolved(asyncPropInput) {
3
+ return !isPromiseLike(asyncPropInput);
4
+ }
5
+ export function isError(asyncPropInput) {
6
+ return asyncPropInput instanceof Error;
7
+ }
8
+ export function resolvedOrUndefined(asyncPropInput) {
9
+ if (isResolved(asyncPropInput)) {
10
+ return asyncPropInput;
11
+ }
12
+ else {
13
+ return undefined;
14
+ }
15
+ }
@@ -1,4 +1,4 @@
1
- import { DirectiveResult } from 'lit/directive.js';
1
+ import { DirectiveResult } from '../../lit-exports';
2
2
  import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
3
3
  /**
4
4
  * Listen to events. These can be native DOM events (use a string for the inputType argument) or
@@ -1,5 +1,4 @@
1
- import { directive, Directive } from 'lit/directive.js';
2
- import { noChange } from '../../lit-exports';
1
+ import { directive, Directive, noChange } from '../../lit-exports';
3
2
  import { extractElement } from './directive-helpers';
4
3
  export function listen(eventType, listener) {
5
4
  return listenDirective(eventType, listener);
@@ -1,4 +1,4 @@
1
- import { PartInfo } from 'lit/directive.js';
1
+ import { PartInfo } from '../../lit-exports';
2
2
  export type OnDomCreatedCallback = (element: Element) => void;
3
3
  /** Only fires once, when the element has been created. */
4
4
  export declare const onDomCreated: (callback: OnDomCreatedCallback) => import("lit-html/directive").DirectiveResult<{
@@ -1,4 +1,4 @@
1
- import { directive, Directive } from 'lit/directive.js';
1
+ import { directive, Directive } from '../../lit-exports';
2
2
  import { assertIsElementPartInfo } from './directive-helpers';
3
3
  const directiveName = 'onDomCreated';
4
4
  /** Only fires once, when the element has been created. */
@@ -1,4 +1,4 @@
1
- import { PartInfo } from 'lit/directive.js';
1
+ import { PartInfo } from '../../lit-exports';
2
2
  export type OnResizeCallback = (
3
3
  /** Only these two properties are supported in all major modern browsers */
4
4
  size: Readonly<Pick<ResizeObserverEntry, 'target' | 'contentRect'>>, element: Element) => void;
@@ -1,4 +1,4 @@
1
- import { directive, Directive } from 'lit/directive.js';
1
+ import { directive, Directive } from '../../lit-exports';
2
2
  import { assertIsElementPartInfo } from './directive-helpers';
3
3
  const directiveName = 'onResize';
4
4
  export const onResize = directive(
@@ -1,5 +1,4 @@
1
- import { when } from 'lit/directives/when.js';
2
- const notSetSymbol = Symbol('not set');
1
+ import { when } from '../../lit-exports';
3
2
  export function renderIf(condition, ifTrue, ifFalse) {
4
3
  return when(condition, () => ifTrue, () => ifFalse);
5
4
  }
@@ -3,9 +3,9 @@ import { CustomElementTagName } from '../custom-tag-name';
3
3
  export type EventsInitMap = Record<string, DefinedTypedEventNameDefinition<any>>;
4
4
  export declare function defineElementEvent<EventDetailGeneric>(): DefinedTypedEventNameDefinition<EventDetailGeneric>;
5
5
  export type EventInitMapEventDetailExtractor<EventTypeNameGeneric extends keyof EventsInitGeneric, EventsInitGeneric extends EventsInitMap> = EventsInitGeneric[EventTypeNameGeneric] extends DefinedTypedEventNameDefinition<infer R> ? R : never;
6
- export type EventDescriptorMap<EventsInitGeneric extends EventsInitMap> = {
7
- [CurrentEventTypeName in keyof EventsInitGeneric]: DefinedTypedEvent<CurrentEventTypeName extends string ? CurrentEventTypeName : never, EventInitMapEventDetailExtractor<CurrentEventTypeName, EventsInitGeneric>>;
6
+ export type EventDescriptorMap<TagName extends CustomElementTagName, EventsInitGeneric extends EventsInitMap> = {
7
+ [CurrentEventTypeName in keyof EventsInitGeneric]: DefinedTypedEvent<CurrentEventTypeName extends string ? `${TagName}-${CurrentEventTypeName}` : never, EventInitMapEventDetailExtractor<CurrentEventTypeName, EventsInitGeneric>>;
8
8
  };
9
9
  export type EventObjectEventDetailExtractor<EventObjectGeneric extends DefinedTypedEvent<any, any>> = EventObjectGeneric extends DefinedTypedEvent<string, infer R> ? R : never;
10
10
  export type ElementEventDetailExtractor<ElementEventGeneric extends TypedEvent<any, any>> = ElementEventGeneric extends TypedEvent<string, infer R> ? R : never;
11
- export declare function createEventDescriptorMap<EventsInitGeneric extends EventsInitMap>(tagName: CustomElementTagName, eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<EventsInitGeneric>;
11
+ export declare function createEventDescriptorMap<TagName extends CustomElementTagName, EventsInitGeneric extends EventsInitMap>(tagName: CustomElementTagName, eventsInit: EventsInitGeneric | undefined): EventDescriptorMap<TagName, EventsInitGeneric>;
@@ -20,7 +20,7 @@ export function createEventDescriptorMap(tagName, eventsInit) {
20
20
  const eventObject = defineTypedEvent()([
21
21
  tagName,
22
22
  currentElementEventKey,
23
- ].join('_'));
23
+ ].join('-'));
24
24
  accum[currentElementEventKey] = eventObject;
25
25
  return accum;
26
26
  }, {});
@@ -1,4 +1,4 @@
1
- import { property } from 'lit/decorators.js';
1
+ import { property } from '../../lit-exports';
2
2
  import { isElementVirStateSetup } from './element-vir-state-setup';
3
3
  import { isObservableProp } from './observable-prop/observable-prop';
4
4
  /** Binds the given property key as a reactive property on the given element. */
@@ -11,9 +11,9 @@ export type UpdateStateCallback<StateInit extends PropertyInitMapBase> = <const
11
11
  export type RenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>> = {
12
12
  state: Readonly<FlattenElementVirStateSetup<StateInit>>;
13
13
  updateState: UpdateStateCallback<StateInit>;
14
- events: EventDescriptorMap<EventsInit>;
14
+ events: EventDescriptorMap<TagName, EventsInit>;
15
15
  host: DeclarativeElementHost<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>;
16
16
  dispatch: <EventTypeName extends keyof EventsInit>(event: TypedEvent<EventTypeName extends string ? EventTypeName : never, EventInitMapEventDetailExtractor<EventTypeName, EventsInit>> | Event) => boolean;
17
17
  inputs: Readonly<Inputs>;
18
18
  };
19
- export declare function createRenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutput>(element: DeclarativeElement<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutput>, eventsMap: EventDescriptorMap<EventsInit>): RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>;
19
+ export declare function createRenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutput>(element: DeclarativeElement<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutput>, eventsMap: EventDescriptorMap<TagName, EventsInit>): RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys>;
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export * from './declarative-element/directives/assign.directive';
9
9
  export * from './declarative-element/directives/async-prop';
10
10
  export * from './declarative-element/directives/create-attribute-directive';
11
11
  export * from './declarative-element/directives/directive-helpers';
12
- export * from './declarative-element/directives/is-render-ready.directive';
12
+ export * from './declarative-element/directives/is-resolved.directive';
13
13
  export * from './declarative-element/directives/listen.directive';
14
14
  export * from './declarative-element/directives/on-dom-created.directive';
15
15
  export * from './declarative-element/directives/on-resize.directive';
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ export * from './declarative-element/directives/assign.directive';
8
8
  export * from './declarative-element/directives/async-prop';
9
9
  export * from './declarative-element/directives/create-attribute-directive';
10
10
  export * from './declarative-element/directives/directive-helpers';
11
- export * from './declarative-element/directives/is-render-ready.directive';
11
+ export * from './declarative-element/directives/is-resolved.directive';
12
12
  export * from './declarative-element/directives/listen.directive';
13
13
  export * from './declarative-element/directives/on-dom-created.directive';
14
14
  export * from './declarative-element/directives/on-resize.directive';
@@ -1,5 +1,7 @@
1
1
  export { LitElement, noChange, svg, unsafeCSS } from 'lit';
2
2
  export type { CSSResult, CSSResultGroup, CompiledTemplate, CompiledTemplateResult, HTMLTemplateResult, SVGTemplateResult, TemplateResult, } from 'lit';
3
+ export * from 'lit/async-directive.js';
4
+ export * from 'lit/decorators.js';
3
5
  export * from 'lit/directive.js';
4
6
  export * from 'lit/directives/async-append.js';
5
7
  export * from 'lit/directives/async-replace.js';
@@ -1,4 +1,6 @@
1
1
  export { LitElement, noChange, svg, unsafeCSS } from 'lit';
2
+ export * from 'lit/async-directive.js';
3
+ export * from 'lit/decorators.js';
2
4
  export * from 'lit/directive.js';
3
5
  export * from 'lit/directives/async-append.js';
4
6
  export * from 'lit/directives/async-replace.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "18.0.0",
3
+ "version": "19.0.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -40,7 +40,7 @@
40
40
  "test:types": "tsc --noEmit"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/common": "^22.1.0",
43
+ "@augment-vir/common": "^22.1.1",
44
44
  "date-vir": "^5.0.0",
45
45
  "lit": "^3.1.0",
46
46
  "lit-css-vars": "^3.0.7",
@@ -49,8 +49,8 @@
49
49
  "run-time-assertions": "^0.2.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@augment-vir/browser-testing": "^22.1.0",
53
- "@augment-vir/node-js": "^22.1.0",
52
+ "@augment-vir/browser-testing": "^22.1.1",
53
+ "@augment-vir/node-js": "^22.1.1",
54
54
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
55
55
  "@open-wc/testing": "^4.0.0",
56
56
  "@types/chai": "^4.3.11",
@@ -62,11 +62,11 @@
62
62
  "@web/test-runner-visual-regression": "^0.9.0",
63
63
  "ansi-colors": "^4.1.3",
64
64
  "concurrently": "^8.2.2",
65
- "cspell": "^8.1.3",
65
+ "cspell": "^8.2.1",
66
66
  "dependency-cruiser": "^15.5.0",
67
- "element-book": "^10.1.9",
67
+ "element-book": "^10.1.10",
68
68
  "element-vir": "file:./",
69
- "esbuild": "^0.19.9",
69
+ "esbuild": "^0.19.10",
70
70
  "istanbul-smart-text-reporter": "^1.1.3",
71
71
  "markdown-code-example-inserter": "^0.3.3",
72
72
  "mocha-spec-reporter-with-file-names": "^0.0.3",
@@ -84,8 +84,8 @@
84
84
  "type-fest": "^4.8.3",
85
85
  "typedoc": "^0.25.4",
86
86
  "typescript": "~5.2.2",
87
- "vira": "^2.5.4",
88
- "virmator": "^11.1.4",
87
+ "vira": "^2.5.5",
88
+ "virmator": "^11.1.5",
89
89
  "vite": "^4.5.0",
90
90
  "vite-tsconfig-paths": "^4.2.2"
91
91
  },
@@ -1,4 +0,0 @@
1
- import { AsyncPropValue } from './async-prop';
2
- export declare function isRenderReady<T>(asyncPropInput: AsyncPropValue<T>): asyncPropInput is Awaited<T>;
3
- export declare function isResolved<T>(asyncPropInput: AsyncPropValue<T>): asyncPropInput is Exclude<AsyncPropValue<T>, Promise<T>>;
4
- export declare function readyOrUndefined<T>(asyncPropInput: AsyncPropValue<T>): Awaited<T> | undefined;
@@ -1,28 +0,0 @@
1
- import { isPromiseLike } from '@augment-vir/common';
2
- export function isRenderReady(asyncPropInput) {
3
- if (asyncPropInput instanceof Error) {
4
- return false;
5
- }
6
- else if (isPromiseLike(asyncPropInput)) {
7
- return false;
8
- }
9
- else {
10
- return true;
11
- }
12
- }
13
- export function isResolved(asyncPropInput) {
14
- if (isPromiseLike(asyncPropInput)) {
15
- return false;
16
- }
17
- else {
18
- return true;
19
- }
20
- }
21
- export function readyOrUndefined(asyncPropInput) {
22
- if (isRenderReady(asyncPropInput)) {
23
- return asyncPropInput;
24
- }
25
- else {
26
- return undefined;
27
- }
28
- }