element-vir 23.4.2 → 25.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 (36) hide show
  1. package/README.md +34 -31
  2. package/dist/declarative-element/declarative-element-init.d.ts +17 -15
  3. package/dist/declarative-element/declarative-element.d.ts +18 -21
  4. package/dist/declarative-element/declarative-element.js +3 -4
  5. package/dist/declarative-element/define-element-no-inputs.d.ts +1 -8
  6. package/dist/declarative-element/define-element-no-inputs.js +22 -17
  7. package/dist/declarative-element/define-element.d.ts +12 -6
  8. package/dist/declarative-element/define-element.js +8 -2
  9. package/dist/declarative-element/directives/assign.directive.d.ts +3 -3
  10. package/dist/declarative-element/directives/async-prop.d.ts +59 -12
  11. package/dist/declarative-element/directives/async-prop.js +71 -11
  12. package/dist/declarative-element/is-declarative-element-definition.js +3 -4
  13. package/dist/declarative-element/properties/element-properties.d.ts +0 -17
  14. package/dist/declarative-element/properties/host-classes.d.ts +2 -3
  15. package/dist/declarative-element/properties/property-proxy.js +1 -5
  16. package/dist/declarative-element/properties/styles.d.ts +3 -4
  17. package/dist/declarative-element/render-callback.d.ts +10 -11
  18. package/dist/declarative-element/wrap-define-element.d.ts +7 -8
  19. package/dist/declarative-element/wrap-define-element.js +2 -2
  20. package/dist/index.d.ts +0 -3
  21. package/dist/index.js +0 -3
  22. package/dist/readme-examples/my-custom-define.d.ts +3 -3
  23. package/dist/readme-examples/my-with-async-prop.element.d.ts +3 -2
  24. package/dist/readme-examples/my-with-async-prop.element.js +9 -6
  25. package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +1 -1
  26. package/dist/readme-examples/my-with-cleanup-callback.element.js +4 -10
  27. package/dist/readme-examples/my-with-event-listening.element.js +4 -2
  28. package/dist/readme-examples/my-with-host-class-definition.element.js +4 -2
  29. package/dist/readme-examples/my-with-update-state.element.js +9 -7
  30. package/package.json +11 -11
  31. package/dist/declarative-element/directives/is-resolved.directive.d.ts +0 -110
  32. package/dist/declarative-element/directives/is-resolved.directive.js +0 -127
  33. package/dist/declarative-element/properties/element-vir-state-setup.d.ts +0 -54
  34. package/dist/declarative-element/properties/element-vir-state-setup.js +0 -22
  35. package/dist/declarative-element/properties/per-instance.d.ts +0 -26
  36. package/dist/declarative-element/properties/per-instance.js +0 -32
@@ -1,23 +1,83 @@
1
1
  import { CallbackObservable } from 'observavir';
2
- import { stateSetupKey } from '../properties/element-vir-state-setup.js';
3
- /** Class for constructing async props. Should not be referenced directly, use `AsyncProp` instead. */
4
- class InternalAsyncPropClass extends CallbackObservable {
5
- }
6
2
  /**
7
- * An async property created by {@link asyncProp} for use within declarative elements.
3
+ * The current state of an {@link AsyncProp}'s value.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export var AsyncValueState;
8
+ (function (AsyncValueState) {
9
+ /** The `.value` Promise has been rejected. */
10
+ AsyncValueState["Rejected"] = "rejected";
11
+ /** The `.value` Promise has not settled yet. */
12
+ AsyncValueState["Waiting"] = "waiting";
13
+ /** The `.value` Promise has been resolved into an awaited value. */
14
+ AsyncValueState["Resolved"] = "resolved";
15
+ })(AsyncValueState || (AsyncValueState = {}));
16
+ /**
17
+ * Class for constructing async props. Do not use this directly as its internal types won't be
18
+ * inferred correctly. Instead use {@link asyncProp} an async prop or {@link AsyncProp} for types.
8
19
  *
9
20
  * @category Internal
10
21
  */
11
- export const AsyncProp = InternalAsyncPropClass;
22
+ export class InternalAsyncPropClass extends CallbackObservable {
23
+ /**
24
+ * The current `.value` if it has settled (into either a resolved value or an Error), or
25
+ * `undefined` if it has not.
26
+ */
27
+ get resolvedValue() {
28
+ if (this.isResolved()) {
29
+ return this.value;
30
+ }
31
+ else {
32
+ return undefined;
33
+ }
34
+ }
35
+ /** The state of the current `.value`. */
36
+ get state() {
37
+ if (this.isResolved()) {
38
+ return AsyncValueState.Resolved;
39
+ }
40
+ else if (this.isError()) {
41
+ return AsyncValueState.Rejected;
42
+ }
43
+ else {
44
+ return AsyncValueState.Waiting;
45
+ }
46
+ }
47
+ /**
48
+ * Checks if the current `.value` has resolved (meaning the Promise has settled and it was not
49
+ * rejected). This type guards the current instance's `.value` property.
50
+ */
51
+ isResolved() {
52
+ return !(this.value instanceof Promise);
53
+ }
54
+ /**
55
+ * Checks if the current `.value` has settled (meaning it is either a rejection error or a
56
+ * resolved value). This type guards the current instance's `.value` property.
57
+ */
58
+ isSettled() {
59
+ return !(this.value instanceof Promise);
60
+ }
61
+ /**
62
+ * Checks if the current `.value` has not settled yet settled (meaning it is still an unsettled
63
+ * Promise). This type guards the current instance's `.value` property.
64
+ */
65
+ isWaiting() {
66
+ return this.value instanceof Promise;
67
+ }
68
+ /**
69
+ * Checks if the current `.value` is a rejection error. This type guards the current instance's
70
+ * `.value` property.
71
+ */
72
+ isError() {
73
+ return this.value instanceof Error;
74
+ }
75
+ }
12
76
  /**
13
77
  * Create an async prop for a declarative element's state.
14
78
  *
15
79
  * @category Async
16
80
  */
17
81
  export function asyncProp(init) {
18
- return {
19
- [stateSetupKey]() {
20
- return new InternalAsyncPropClass(init);
21
- },
22
- };
82
+ return new InternalAsyncPropClass(init);
23
83
  }
@@ -8,14 +8,13 @@ const expectedStaticProperties = getObjectTypedKeys({
8
8
  events: '',
9
9
  hostClasses: '',
10
10
  init: '',
11
- inputsType: '',
11
+ InputsType: '',
12
12
  render: '',
13
13
  slotNames: '',
14
- stateInitStatic: '',
15
- stateType: '',
14
+ StateType: '',
16
15
  styles: '',
17
16
  tagName: '',
18
- updateStateType: '',
17
+ UpdateStateType: '',
19
18
  });
20
19
  /**
21
20
  * Asserts that the given input is a declarative element definition.
@@ -4,20 +4,3 @@
4
4
  * @category Internal
5
5
  */
6
6
  export type PropertyInitMapBase = Record<PropertyKey, unknown>;
7
- /**
8
- * Describes a static element property.
9
- *
10
- * @category Internal
11
- */
12
- export type StaticElementPropertyDescriptor<PropName extends string, PropValue> = {
13
- propName: PropName;
14
- initValue: PropValue;
15
- };
16
- /**
17
- * Maps a property init map into static element descriptions.
18
- *
19
- * @category Internal
20
- */
21
- export type ElementPropertyDescriptorMap<PropertyInitGeneric extends PropertyInitMapBase> = {
22
- [Property in keyof PropertyInitGeneric]: StaticElementPropertyDescriptor<string, PropertyInitGeneric[Property]>;
23
- };
@@ -1,20 +1,19 @@
1
1
  import { CustomElementTagName } from '../custom-tag-name.js';
2
2
  import { BaseCssPropertyName } from './css-properties.js';
3
3
  import { PropertyInitMapBase } from './element-properties.js';
4
- import { FlattenElementVirStateSetup } from './element-vir-state-setup.js';
5
4
  import { WithTagName } from './tag-name.js';
6
5
  /**
7
6
  * Base init map for defining host classes in an element definition.
8
7
  *
9
8
  * @category Internal
10
9
  */
11
- export type HostClassesInitMap<TagName extends CustomElementTagName, HostClassKeys extends BaseCssPropertyName<TagName>, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase> = Record<HostClassKeys,
10
+ export type HostClassesInitMap<TagName extends CustomElementTagName, HostClassKeys extends BaseCssPropertyName<TagName>, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase> = Record<HostClassKeys,
12
11
  /**
13
12
  * Callback to determine when host class should be enabled (based on current inputs and state),
14
13
  * or just undefined to mark that this host class name will only be manually applied.
15
14
  */
16
15
  ((inputs: {
17
- state: Readonly<FlattenElementVirStateSetup<StateInit>>;
16
+ state: Readonly<State>;
18
17
  inputs: Readonly<Inputs>;
19
18
  }) => boolean) | false>;
20
19
  /**
@@ -1,6 +1,5 @@
1
1
  import { isObservableBase } from 'observavir';
2
2
  import { property } from '../../lit-exports/base-lit-exports.js';
3
- import { isElementVirStateSetup, stateSetupKey } from './element-vir-state-setup.js';
4
3
  /**
5
4
  * Binds the given property key as a reactive property on the given element.
6
5
  *
@@ -46,10 +45,7 @@ export function createElementPropertyProxy(element, shouldAlreadyExist) {
46
45
  }
47
46
  const propsProxy = new Proxy({}, {
48
47
  get: valueGetter,
49
- set(target, propertyKey, rawNewValue) {
50
- const newValue = isElementVirStateSetup(rawNewValue)
51
- ? rawNewValue[stateSetupKey]()
52
- : rawNewValue;
48
+ set(target, propertyKey, newValue) {
53
49
  verifyProperty(propertyKey);
54
50
  const oldValue = elementAsProps[propertyKey];
55
51
  function setValueOnElement(value) {
@@ -3,7 +3,6 @@ import { type CustomElementTagName } from '../custom-tag-name.js';
3
3
  import { type BaseCssPropertyName } from './css-properties.js';
4
4
  import { type CssVars } from './css-vars.js';
5
5
  import { type PropertyInitMapBase } from './element-properties.js';
6
- import { type FlattenElementVirStateSetup } from './element-vir-state-setup.js';
7
6
  import { type HostClassNamesMap, type HostClassesInitMap } from './host-classes.js';
8
7
  /**
9
8
  * A host class instance to be referenced inside of an element definition's `styles` callback.
@@ -43,10 +42,10 @@ export declare function createStylesCallbackInput<TagName extends CustomElementT
43
42
  *
44
43
  * @category Internal
45
44
  */
46
- export declare function applyHostClasses<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, HostClassKeys extends BaseCssPropertyName<TagName>>({ host, hostClassesInit, hostClassNames, state, inputs, }: {
45
+ export declare function applyHostClasses<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, HostClassKeys extends BaseCssPropertyName<TagName>>({ host, hostClassesInit, hostClassNames, state, inputs, }: {
47
46
  host: HTMLElement;
48
- hostClassesInit: Readonly<HostClassesInitMap<TagName, HostClassKeys, Inputs, StateInit>> | undefined;
47
+ hostClassesInit: Readonly<HostClassesInitMap<TagName, HostClassKeys, Inputs, State>> | undefined;
49
48
  hostClassNames: HostClassNamesMap<string, HostClassKeys>;
50
- state: Readonly<FlattenElementVirStateSetup<StateInit>>;
49
+ state: Readonly<State>;
51
50
  inputs: Readonly<Inputs>;
52
51
  }): void;
@@ -6,37 +6,36 @@ import { type BaseCssPropertyName } from './properties/css-properties.js';
6
6
  import { type CssVars } from './properties/css-vars.js';
7
7
  import { type EventDescriptorMap, type EventInitMapEventDetailExtractor, type EventsInitMap } from './properties/element-events.js';
8
8
  import { type PropertyInitMapBase } from './properties/element-properties.js';
9
- import { type AllowElementVirStateSetup, type FlattenElementVirStateSetup } from './properties/element-vir-state-setup.js';
10
9
  import { type SlotNameMap } from './slot-names.js';
11
10
  /**
12
11
  * Type for the `render` element definition method.
13
12
  *
14
13
  * @category Internal
15
14
  */
16
- export type RenderCallback<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, StateInit extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseCssPropertyName<TagName> = any, CssVarKeys extends BaseCssPropertyName<TagName> = any, SlotNames extends ReadonlyArray<string> = any> = (params: RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => HtmlInterpolation;
15
+ export type RenderCallback<TagName extends CustomElementTagName = any, Inputs extends PropertyInitMapBase = any, State extends PropertyInitMapBase = any, EventsInit extends EventsInitMap = any, HostClassKeys extends BaseCssPropertyName<TagName> = any, CssVarKeys extends BaseCssPropertyName<TagName> = any, SlotNames extends ReadonlyArray<string> = any> = (params: RenderParams<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => HtmlInterpolation;
17
16
  /**
18
17
  * Type for the `init` and `cleanup` element definition methods.
19
18
  *
20
19
  * @category Internal
21
20
  */
22
- export type InitCallback<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>> = (params: RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => undefined | void;
21
+ export type InitCallback<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>> = (params: RenderParams<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => undefined | void;
23
22
  /**
24
23
  * Type for the `updateState` render parameter.
25
24
  *
26
25
  * @category Internal
27
26
  */
28
- export type UpdateStateCallback<StateInit extends PropertyInitMapBase> = (newState: Partial<AllowElementVirStateSetup<StateInit>>) => void;
27
+ export type UpdateStateCallback<State extends PropertyInitMapBase> = (newState: Partial<State>) => void;
29
28
  /**
30
29
  * The full parameters object passed to `render`, `init`, and `cleanup` element definition methods.
31
30
  *
32
31
  * @category Internal
33
32
  */
34
- export type RenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>> = {
35
- state: Readonly<FlattenElementVirStateSetup<StateInit>>;
33
+ export type RenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>> = {
34
+ state: Readonly<State>;
36
35
  cssVars: Readonly<CssVars<TagName, CssVarKeys>>;
37
- updateState: UpdateStateCallback<StateInit>;
36
+ updateState: UpdateStateCallback<State>;
38
37
  events: EventDescriptorMap<TagName, EventsInit>;
39
- host: DeclarativeElementHost<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
38
+ host: DeclarativeElementHost<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
40
39
  slotNames: SlotNameMap<SlotNames>;
41
40
  /** Dispatch an event from the current element. */
42
41
  dispatch: <EventTypeName extends keyof EventsInit>(event: TypedEvent<EventTypeName extends string ? EventTypeName : never, EventInitMapEventDetailExtractor<EventTypeName, EventsInit>> | Event) => boolean;
@@ -48,9 +47,9 @@ export type RenderParams<TagName extends CustomElementTagName, Inputs extends Pr
48
47
  *
49
48
  * @category Internal
50
49
  */
51
- export declare function createRenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>>({ element, eventsMap, cssVars, slotNamesMap, }: {
52
- element: DeclarativeElement<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
50
+ export declare function createRenderParams<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, State extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, SlotNames extends ReadonlyArray<string>>({ element, eventsMap, cssVars, slotNamesMap, }: {
51
+ element: DeclarativeElement<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
53
52
  eventsMap: EventDescriptorMap<TagName, EventsInit>;
54
53
  cssVars: Readonly<CssVars<TagName, CssVarKeys>>;
55
54
  slotNamesMap: SlotNameMap<SlotNames>;
56
- }): RenderParams<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
55
+ }): RenderParams<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
@@ -1,8 +1,7 @@
1
1
  import { PartialWithNullable } from '@augment-vir/common';
2
2
  import { CustomElementTagName } from './custom-tag-name.js';
3
3
  import { DeclarativeElementInit } from './declarative-element-init.js';
4
- import { VerifiedElementNoInputsInit } from './define-element-no-inputs.js';
5
- import { VerifiedElementInit } from './define-element.js';
4
+ import { DeclarativeElementInputErrorParams } from './define-element.js';
6
5
  import { BaseCssPropertyName } from './properties/css-properties.js';
7
6
  import { EventsInitMap } from './properties/element-events.js';
8
7
  import { PropertyInitMapBase } from './properties/element-properties.js';
@@ -11,17 +10,17 @@ import { PropertyInitMapBase } from './properties/element-properties.js';
11
10
  *
12
11
  * @category Internal
13
12
  */
14
- export type WrapDefineElementOptions<TagNameRequirement extends CustomElementTagName = CustomElementTagName, InputsRequirement extends PropertyInitMapBase = {}, StateInitRequirement extends PropertyInitMapBase = {}, EventsInitRequirement extends EventsInitMap = {}> = PartialWithNullable<{
13
+ export type WrapDefineElementOptions<TagNameRequirement extends CustomElementTagName = CustomElementTagName, InputsRequirement extends PropertyInitMapBase = {}, StateRequirement extends PropertyInitMapBase = {}, EventsInitRequirement extends EventsInitMap = {}> = PartialWithNullable<{
15
14
  /**
16
15
  * An optional callback which asserts that an element definition init object given to the
17
16
  * wrapped element definition functions is valid.
18
17
  */
19
- assertInputs: (inputInit: DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateInitRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>) => void;
18
+ assertInputs: (inputInit: DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>) => void;
20
19
  /**
21
20
  * An optional callback which transforms a element definition init object given to the wrapped
22
21
  * element definition.
23
22
  */
24
- transformInputs: (inputInit: DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateInitRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>) => DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateInitRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>;
23
+ transformInputs: (inputInit: DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>) => DeclarativeElementInit<TagNameRequirement, InputsRequirement, StateRequirement, EventsInitRequirement, BaseCssPropertyName<TagNameRequirement>, BaseCssPropertyName<TagNameRequirement>, ReadonlyArray<string>>;
25
24
  }>;
26
25
  /**
27
26
  * Wraps {@link defineElement} and {@link defineElementNoInputs} in a superset of requirements. For
@@ -35,9 +34,9 @@ export type WrapDefineElementOptions<TagNameRequirement extends CustomElementTag
35
34
  *
36
35
  * @category Element Definition
37
36
  */
38
- export declare function wrapDefineElement<TagNameRequirement extends CustomElementTagName = CustomElementTagName, InputsRequirement extends PropertyInitMapBase = {}, StateInitRequirement extends PropertyInitMapBase = {}, EventsInitRequirement extends EventsInitMap = {}>(options?: WrapDefineElementOptions | undefined): {
37
+ export declare function wrapDefineElement<TagNameRequirement extends CustomElementTagName = CustomElementTagName, InputsRequirement extends PropertyInitMapBase = {}, StateRequirement extends PropertyInitMapBase = {}, EventsInitRequirement extends EventsInitMap = {}>(options?: WrapDefineElementOptions | undefined): {
39
38
  /** A wrapped function for defining an element with inputs. */
40
- defineElement: <Inputs extends InputsRequirement>() => <const TagName extends TagNameRequirement, StateInit extends StateInitRequirement, EventsInit extends EventsInitRequirement, const HostClassKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: VerifiedElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("./declarative-element.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
39
+ defineElement: <Inputs extends InputsRequirement>(...errorParams: DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends TagNameRequirement, State extends StateRequirement, EventsInit extends EventsInitRequirement, const HostClassKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>>(inputs: DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("./declarative-element.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
41
40
  /** A wrapped function for defining an element without inputs. */
42
- defineElementNoInputs: <const TagName extends TagNameRequirement, Inputs extends InputsRequirement, StateInit extends StateInitRequirement, EventsInit extends EventsInitRequirement, const HostClassKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: VerifiedElementNoInputsInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("./declarative-element.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
41
+ defineElementNoInputs: <const TagName extends TagNameRequirement, Inputs extends InputsRequirement, State extends StateRequirement, EventsInit extends EventsInitRequirement, const HostClassKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("./declarative-element.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
43
42
  };
@@ -20,10 +20,10 @@ export function wrapDefineElement(options) {
20
20
  };
21
21
  return {
22
22
  /** A wrapped function for defining an element with inputs. */
23
- defineElement: () => {
23
+ defineElement: (...errorParams) => {
24
24
  return (inputs) => {
25
25
  assertInputs(inputs);
26
- return defineElement()(transformInputs(inputs));
26
+ return defineElement(...errorParams)(transformInputs(inputs));
27
27
  };
28
28
  },
29
29
  /** A wrapped function for defining an element without inputs. */
package/dist/index.d.ts CHANGED
@@ -8,7 +8,6 @@ export * from './declarative-element/definition-options.js';
8
8
  export * from './declarative-element/directives/async-prop.js';
9
9
  export * from './declarative-element/directives/create-attribute-directive.js';
10
10
  export * from './declarative-element/directives/directive-helpers.js';
11
- export * from './declarative-element/directives/is-resolved.directive.js';
12
11
  export * from './declarative-element/directives/listen.directive.js';
13
12
  export * from './declarative-element/directives/on-dom-created.directive.js';
14
13
  export * from './declarative-element/directives/on-dom-rendered.directive.js';
@@ -23,9 +22,7 @@ export * from './declarative-element/properties/css-properties.js';
23
22
  export * from './declarative-element/properties/css-vars.js';
24
23
  export * from './declarative-element/properties/element-events.js';
25
24
  export * from './declarative-element/properties/element-properties.js';
26
- export * from './declarative-element/properties/element-vir-state-setup.js';
27
25
  export * from './declarative-element/properties/host-classes.js';
28
- export * from './declarative-element/properties/per-instance.js';
29
26
  export * from './declarative-element/properties/styles.js';
30
27
  export * from './declarative-element/properties/tag-name.js';
31
28
  export * from './declarative-element/render-callback.js';
package/dist/index.js CHANGED
@@ -8,7 +8,6 @@ export * from './declarative-element/definition-options.js';
8
8
  export * from './declarative-element/directives/async-prop.js';
9
9
  export * from './declarative-element/directives/create-attribute-directive.js';
10
10
  export * from './declarative-element/directives/directive-helpers.js';
11
- export * from './declarative-element/directives/is-resolved.directive.js';
12
11
  export * from './declarative-element/directives/listen.directive.js';
13
12
  export * from './declarative-element/directives/on-dom-created.directive.js';
14
13
  export * from './declarative-element/directives/on-dom-rendered.directive.js';
@@ -23,9 +22,7 @@ export * from './declarative-element/properties/css-properties.js';
23
22
  export * from './declarative-element/properties/css-vars.js';
24
23
  export * from './declarative-element/properties/element-events.js';
25
24
  export * from './declarative-element/properties/element-properties.js';
26
- export * from './declarative-element/properties/element-vir-state-setup.js';
27
25
  export * from './declarative-element/properties/host-classes.js';
28
- export * from './declarative-element/properties/per-instance.js';
29
26
  export * from './declarative-element/properties/styles.js';
30
27
  export * from './declarative-element/properties/tag-name.js';
31
28
  export * from './declarative-element/render-callback.js';
@@ -1,4 +1,4 @@
1
1
  export type VirTagName = `vir-${string}`;
2
- export declare const defineVirElement: <Inputs extends {}>() => <const TagName extends `vir-${string}`, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementNoInputsInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
3
- export declare const defineVerifiedVirElement: <Inputs extends {}>() => <const TagName extends `vir-${string}`, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineVerifiedVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementNoInputsInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
4
- export declare const defineTransformedVirElement: <Inputs extends {}>() => <const TagName extends `vir-${string}`, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineTransformedVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, StateInit extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").VerifiedElementNoInputsInit<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
2
+ export declare const defineVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, State extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
3
+ export declare const defineVerifiedVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineVerifiedVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, State extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
4
+ export declare const defineTransformedVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseCssPropertyName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>, defineTransformedVirElementNoInputs: <const TagName extends `vir-${string}`, Inputs extends {}, State extends {}, EventsInit extends {}, const HostClassKeys extends `${TagName}-${string}` = `${TagName}-`, const CssVarKeys extends `${TagName}-${string}` = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = readonly []>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames>;
@@ -2,8 +2,9 @@ type EndpointData = number[];
2
2
  export declare const MyWithAsyncProp: import("../index.js").DeclarativeElementDefinition<"my-with-async-prop", {
3
3
  endpoint: string;
4
4
  }, {
5
- data: import("../index.js").ElementVirStateSetup<import("../index.js").AsyncProp<EndpointData, {
5
+ data: import("../index.js").AsyncProp<EndpointData, {
6
6
  endpoint: string;
7
- }>>;
7
+ }>;
8
+ hi: string;
8
9
  }, {}, "my-with-async-prop-", "my-with-async-prop-", readonly []>;
9
10
  export {};
@@ -10,12 +10,15 @@ async function loadSomething(endpoint) {
10
10
  }
11
11
  export const MyWithAsyncProp = defineElement()({
12
12
  tagName: 'my-with-async-prop',
13
- stateInitStatic: {
14
- data: asyncProp({
15
- async updateCallback({ endpoint }) {
16
- return loadSomething(endpoint);
17
- },
18
- }),
13
+ state() {
14
+ return {
15
+ data: asyncProp({
16
+ async updateCallback({ endpoint }) {
17
+ return loadSomething(endpoint);
18
+ },
19
+ }),
20
+ hi: '',
21
+ };
19
22
  },
20
23
  render({ inputs, state }) {
21
24
  /**
@@ -1,3 +1,3 @@
1
1
  export declare const MyWithAssignmentCleanupCallback: import("../index.js").DeclarativeElementDefinition<"my-with-cleanup-callback", {}, {
2
- intervalId: undefined | number;
2
+ intervalId: number;
3
3
  }, {}, "my-with-cleanup-callback-", "my-with-cleanup-callback-", readonly []>;
@@ -1,23 +1,17 @@
1
1
  import { defineElementNoInputs, html } from '../index.js';
2
2
  export const MyWithAssignmentCleanupCallback = defineElementNoInputs({
3
3
  tagName: 'my-with-cleanup-callback',
4
- stateInitStatic: {
5
- intervalId: undefined,
6
- },
7
- init: ({ updateState }) => {
8
- updateState({
4
+ state() {
5
+ return {
9
6
  intervalId: window.setInterval(() => console.info('hi'), 1000),
10
- });
7
+ };
11
8
  },
12
9
  render() {
13
10
  return html `
14
11
  <h1>My App</h1>
15
12
  `;
16
13
  },
17
- cleanup: ({ state, updateState }) => {
14
+ cleanup({ state }) {
18
15
  window.clearInterval(state.intervalId);
19
- updateState({
20
- intervalId: undefined,
21
- });
22
16
  },
23
17
  });
@@ -2,8 +2,10 @@ import { defineElementNoInputs, html, listen } from '../index.js';
2
2
  import { MyWithEvents } from './my-with-events.element.js';
3
3
  export const MyWithEventListening = defineElementNoInputs({
4
4
  tagName: 'my-with-event-listening',
5
- stateInitStatic: {
6
- myNumber: -1,
5
+ state() {
6
+ return {
7
+ myNumber: -1,
8
+ };
7
9
  },
8
10
  render({ state, updateState }) {
9
11
  return html `
@@ -1,8 +1,10 @@
1
1
  import { css, defineElementNoInputs, html } from '../index.js';
2
2
  export const MyWithHostClassDefinition = defineElementNoInputs({
3
3
  tagName: 'my-with-host-class-definition',
4
- stateInitStatic: {
5
- myProp: 'hello there',
4
+ state() {
5
+ return {
6
+ myProp: 'hello there',
7
+ };
6
8
  },
7
9
  hostClasses: {
8
10
  /**
@@ -1,13 +1,15 @@
1
1
  import { defineElementNoInputs, html, listen } from '../index.js';
2
2
  export const MyWithUpdateState = defineElementNoInputs({
3
3
  tagName: 'my-with-update-state',
4
- stateInitStatic: {
5
- username: 'dev',
6
- /**
7
- * Use "as" to create state properties that can be types other than the initial value's
8
- * type. This is particularly useful when, as below, the initial value is undefined.
9
- */
10
- email: undefined,
4
+ state() {
5
+ return {
6
+ username: 'dev',
7
+ /**
8
+ * Use "as" to create state properties that can be types other than the initial value's
9
+ * type. This is particularly useful when, as below, the initial value is undefined.
10
+ */
11
+ email: undefined,
12
+ };
11
13
  },
12
14
  render({ state, updateState }) {
13
15
  return html `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "23.4.2",
3
+ "version": "25.0.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -38,19 +38,19 @@
38
38
  "test:docs": "virmator docs check"
39
39
  },
40
40
  "dependencies": {
41
- "@augment-vir/assert": "^31.9.2",
42
- "@augment-vir/common": "^31.9.2",
43
- "date-vir": "^7.2.1",
41
+ "@augment-vir/assert": "^31.10.0",
42
+ "@augment-vir/common": "^31.10.0",
43
+ "date-vir": "^7.3.1",
44
44
  "lit": "^3.2.1",
45
45
  "lit-css-vars": "^3.0.11",
46
46
  "lit-html": "^3.2.1",
47
- "object-shape-tester": "^5.1.4",
47
+ "object-shape-tester": "^5.1.5",
48
48
  "observavir": "^2.0.5",
49
- "typed-event-target": "^4.0.2"
49
+ "typed-event-target": "^4.0.3"
50
50
  },
51
51
  "devDependencies": {
52
- "@augment-vir/test": "^31.9.2",
53
- "@augment-vir/web": "^31.9.2",
52
+ "@augment-vir/test": "^31.10.0",
53
+ "@augment-vir/web": "^31.10.0",
54
54
  "@web/dev-server-esbuild": "^1.0.4",
55
55
  "@web/test-runner": "^0.20.0",
56
56
  "@web/test-runner-commands": "^0.9.0",
@@ -59,10 +59,10 @@
59
59
  "html-spec-tags": "^2.2.2",
60
60
  "istanbul-smart-text-reporter": "^1.1.5",
61
61
  "markdown-code-example-inserter": "^3.0.3",
62
- "type-fest": "^4.35.0",
62
+ "type-fest": "^4.37.0",
63
63
  "typedoc": "^0.27.9",
64
- "typescript": "5.7.3",
65
- "vite": "^6.2.0",
64
+ "typescript": "5.8.2",
65
+ "vite": "^6.2.1",
66
66
  "vite-tsconfig-paths": "^5.1.4"
67
67
  },
68
68
  "engines": {