element-vir 14.2.2 → 15.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.
@@ -30,7 +30,7 @@ export type DeclarativeElementInit<TagName extends CustomElementTagName, Inputs
30
30
  * based on current instance state or inputs, or just false to indicate that the host class will
31
31
  * only be manually set.
32
32
  */
33
- hostClasses?: HostClassesInitMap<TagName, HostClassKeys, FlattenObservablePropertyGetters<Inputs>, FlattenObservablePropertyGetters<StateInit>>;
33
+ hostClasses?: HostClassesInitMap<TagName, HostClassKeys, Inputs, FlattenObservablePropertyGetters<StateInit>>;
34
34
  /**
35
35
  * CSS Vars for the component. Keys of this object should be kebab-case and start with the
36
36
  * element's tag name.
@@ -1,6 +1,6 @@
1
1
  import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
2
- import { AllowObservablePropertySetter } from 'element-vir';
3
2
  import { CSSResult, LitElement } from 'lit';
3
+ import { Exact } from 'type-fest';
4
4
  import { WrappedMinimalDefinition } from '../template-transforms/minimal-element-definition';
5
5
  import { CustomElementTagName, DeclarativeElementInit } from './declarative-element-init';
6
6
  import { BaseCssPropertyName } from './properties/css-properties';
@@ -33,7 +33,7 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
33
33
  abstract render(): unknown;
34
34
  abstract readonly instanceState: FlattenObservablePropertyGetters<StateInit>;
35
35
  abstract readonly observablePropertyHandlerMap: ObservablePropertyHandlerMap<StateInit>;
36
- abstract readonly instanceInputs: FlattenObservablePropertyGetters<Inputs>;
36
+ abstract readonly instanceInputs: Inputs;
37
37
  abstract assignInputs(inputs: {} extends Required<Inputs> ? never : Partial<Inputs>): void;
38
38
  abstract haveInputsBeenSet: boolean;
39
39
  abstract markInputsAsHavingBeenSet(): void;
@@ -41,7 +41,7 @@ export declare abstract class DeclarativeElement<TagName extends CustomElementTa
41
41
  }
42
42
  export interface StaticDeclarativeElementProperties<TagName extends CustomElementTagName, Inputs extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInit extends EventsInitMap, HostClassKeys extends BaseCssPropertyName<TagName>, CssVarKeys extends BaseCssPropertyName<TagName>, RenderOutputGeneric> {
43
43
  /** Assign inputs to an element directly on its interpolated tag. */
44
- readonly assign: <const SpecificInputs extends AllowObservablePropertySetter<Inputs, SpecificInputs>>(inputsObject: {} extends Required<Inputs> ? never : SpecificInputs) => WrappedMinimalDefinition;
44
+ readonly assign: <SpecificInputs extends Exact<Inputs, SpecificInputs>>(inputsObject: {} extends Required<Inputs> ? never : SpecificInputs) => WrappedMinimalDefinition;
45
45
  assignedInputs: Inputs | undefined;
46
46
  /** Pass through the render callback for direct unit testability */
47
47
  readonly renderCallback: RenderCallback<TagName, Inputs, StateInit, EventsInit, HostClassKeys, CssVarKeys, RenderOutputGeneric>;
@@ -142,8 +142,8 @@ export function defineElementNoInputs(initInput) {
142
142
  // this is set below in Object.defineProperties
143
143
  this.definition = {};
144
144
  this.observablePropertyHandlerMap = {};
145
- this.instanceInputs = createElementUpdaterProxy(this, false);
146
- this.instanceState = createElementUpdaterProxy(this, !initInput.options?.allowPolymorphicState);
145
+ this.instanceInputs = createElementUpdaterProxy(this, false, false);
146
+ this.instanceState = createElementUpdaterProxy(this, !initInput.options?.allowPolymorphicState, true);
147
147
  const stateInitStatic = initInput.stateInitStatic ||
148
148
  {};
149
149
  getObjectTypedKeys(stateInitStatic).forEach((stateKey) => {
@@ -1,6 +1,5 @@
1
1
  import { DirectiveResult } from 'lit/directive.js';
2
2
  import { PropertyInitMapBase } from '../properties/element-properties';
3
- import { AllowObservablePropertySetter } from '../properties/observable-property/observable-property-handler';
4
3
  export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBase = PropertyInitMapBase> = {
5
4
  inputsType: InputsType;
6
5
  };
@@ -14,9 +13,7 @@ export type ElementDefinitionWithInputsType<InputsType extends PropertyInitMapBa
14
13
  * should be
15
14
  * html`<${MyElement.assign({value: 1})}>...`
16
15
  */
17
- export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType, const SpecificInput extends {
18
- [Prop in keyof SpecificDeclarativeElement['inputsType']]: unknown;
19
- }>(declarativeElement: SpecificDeclarativeElement, inputsObject: {} extends Required<SpecificDeclarativeElement['inputsType']> ? never : AllowObservablePropertySetter<SpecificDeclarativeElement['inputsType'], SpecificInput>): DirectiveResult;
16
+ export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType>(declarativeElement: SpecificDeclarativeElement, inputsObject: {} extends Required<SpecificDeclarativeElement['inputsType']> ? never : SpecificDeclarativeElement['inputsType']): DirectiveResult;
20
17
  /**
21
18
  * Assign an object matching an element's inputs to its inputs.
22
19
  *
@@ -27,6 +24,4 @@ export declare function assign<const SpecificDeclarativeElement extends ElementD
27
24
  * should be
28
25
  * html`<${MyElement.assign({value: 1})}>...`
29
26
  */
30
- export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType, const SpecificInput extends {
31
- [Prop in keyof SpecificDeclarativeElement['inputsType']]: unknown;
32
- }>(inputsObject: SpecificInput extends typeof HTMLElement ? never : SpecificInput): DirectiveResult;
27
+ export declare function assign<const SpecificDeclarativeElement extends ElementDefinitionWithInputsType, const SpecificInput extends SpecificDeclarativeElement['inputsType']>(inputsObject: SpecificInput extends typeof HTMLElement ? never : SpecificInput): DirectiveResult;
@@ -1,3 +1,3 @@
1
1
  import { DeclarativeElement } from '../declarative-element';
2
2
  import { PropertyInitMapBase } from './element-properties';
3
- export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean): PropertyInitGeneric;
3
+ export declare function createElementUpdaterProxy<PropertyInitGeneric extends PropertyInitMapBase>(element: DeclarativeElement, verifyExists: boolean, unwrapObservables: boolean): PropertyInitGeneric;
@@ -8,7 +8,7 @@ function assertValidPropertyName(propKey, element, elementTagName) {
8
8
  throw new Error(`Property '${String(propKey)}' does not exist on '${elementTagName.toLowerCase()}'.`);
9
9
  }
10
10
  }
11
- export function createElementUpdaterProxy(element, verifyExists) {
11
+ export function createElementUpdaterProxy(element, verifyExists, unwrapObservables) {
12
12
  /**
13
13
  * Lit element updates state and inputs by setting them directly on the element, so we must do
14
14
  * that here. DeclarativeElement's types, however, do not expose this behavior, so we add that
@@ -45,11 +45,11 @@ export function createElementUpdaterProxy(element, verifyExists) {
45
45
  target[propertyKey] = value;
46
46
  elementAsProps[propertyKey] = value;
47
47
  }
48
- if (isObservablePropertyHandlerCreator(newValue)) {
48
+ if (unwrapObservables && isObservablePropertyHandlerCreator(newValue)) {
49
49
  newValue = newValue.init();
50
50
  }
51
51
  /** If we're using an existing observable property */
52
- if (isObservablePropertyHandlerInstance(newValue)) {
52
+ if (unwrapObservables && isObservablePropertyHandlerInstance(newValue)) {
53
53
  if (existingObservablePropertyHandler &&
54
54
  newValue !== existingObservablePropertyHandler) {
55
55
  newValue.addMultipleListeners(existingObservablePropertyHandler.getAllListeners());
@@ -64,7 +64,7 @@ export function createElementUpdaterProxy(element, verifyExists) {
64
64
  element.observablePropertyHandlerMap[propertyKey] = newValue;
65
65
  }
66
66
  else {
67
- if (existingObservablePropertyHandler) {
67
+ if (unwrapObservables && existingObservablePropertyHandler) {
68
68
  existingObservablePropertyHandler.setValue(newValue);
69
69
  }
70
70
  else {
@@ -14,6 +14,6 @@ export type RenderParams<TagName extends CustomElementTagName, Inputs extends Pr
14
14
  events: EventDescriptorMap<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
- inputs: Readonly<FlattenObservablePropertyGetters<Inputs>>;
17
+ inputs: Readonly<Inputs>;
18
18
  };
19
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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "14.2.2",
3
+ "version": "15.0.0",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -41,7 +41,6 @@
41
41
  "dependencies": {
42
42
  "@augment-vir/browser": "^15.4.1",
43
43
  "@augment-vir/common": "^15.4.1",
44
- "element-vir": "^14.2.1",
45
44
  "lit": "2.7.6",
46
45
  "lit-css-vars": "^2.0.3"
47
46
  },
@@ -78,7 +77,7 @@
78
77
  "type-fest": "^4.0.0",
79
78
  "typescript": "~5.1.6",
80
79
  "virmator": "^7.2.5",
81
- "vite": "^4.4.5",
80
+ "vite": "^4.4.6",
82
81
  "vite-tsconfig-paths": "^4.2.0"
83
82
  },
84
83
  "overrides": {