element-vir 0.0.1 → 0.0.5

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.
@@ -14,22 +14,22 @@ export function defineFunctionalElement(functionalElementInit) {
14
14
  const initProps = functionalElementInit.props || {};
15
15
  Object.keys(initProps).forEach((propName) => {
16
16
  const functionalElementInstance = this;
17
- if (propName in functionalElementInstance) {
18
- throw new Error(`${functionalElementInit.tagName} already has a property named ${propName}. Don't add a new property to it with that name.`);
19
- }
20
17
  property()(functionalElementInstance, propName);
21
18
  functionalElementInstance[propName] = initProps[propName];
22
19
  });
23
20
  }
21
+ createRenderParams() {
22
+ return createRenderParams(this, eventsMap);
23
+ }
24
24
  render() {
25
- return functionalElementInit.renderCallback(createRenderParams(this, eventsMap));
25
+ return functionalElementInit.renderCallback(this.createRenderParams());
26
26
  }
27
27
  connectedCallback() {
28
28
  var _a;
29
29
  super.connectedCallback();
30
30
  (_a = functionalElementInit.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(functionalElementInit, {
31
31
  element: this,
32
- props: this.instanceProps,
32
+ ...this.createRenderParams(),
33
33
  });
34
34
  }
35
35
  disconnectedCallback() {
@@ -37,7 +37,14 @@ export function defineFunctionalElement(functionalElementInit) {
37
37
  super.disconnectedCallback();
38
38
  (_a = functionalElementInit.disconnectedCallback) === null || _a === void 0 ? void 0 : _a.call(functionalElementInit, {
39
39
  element: this,
40
- props: this.instanceProps,
40
+ ...this.createRenderParams(),
41
+ });
42
+ }
43
+ firstUpdated() {
44
+ var _a;
45
+ (_a = functionalElementInit.firstUpdated) === null || _a === void 0 ? void 0 : _a.call(functionalElementInit, {
46
+ element: this,
47
+ ...this.createRenderParams(),
41
48
  });
42
49
  }
43
50
  },
@@ -1,7 +1,7 @@
1
1
  import { CSSResult } from 'lit';
2
- import { ConnectionCallback } from './connection-callback';
3
2
  import { EventsInitMap } from './element-events';
4
3
  import { PropertyInitMapBase } from './element-properties';
4
+ import { LifecycleCallback } from './lifecycle-callback';
5
5
  import { RenderCallback } from './render-callback';
6
6
  export declare type FunctionalElementInit<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
7
7
  /**
@@ -15,7 +15,8 @@ export declare type FunctionalElementInit<PropertyInitGeneric extends PropertyIn
15
15
  props?: PropertyInitGeneric | undefined;
16
16
  /** Initializer for events that the element can dispatch. (These can be thought of as "outputs".) */
17
17
  events?: EventsInitGeneric | undefined;
18
- connectedCallback?: ConnectionCallback<PropertyInitGeneric>;
19
- disconnectedCallback?: ConnectionCallback<PropertyInitGeneric>;
18
+ connectedCallback?: LifecycleCallback<PropertyInitGeneric, EventsInitGeneric>;
19
+ disconnectedCallback?: LifecycleCallback<PropertyInitGeneric, EventsInitGeneric>;
20
+ firstUpdated?: LifecycleCallback<PropertyInitGeneric, EventsInitGeneric>;
20
21
  renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
21
22
  };
@@ -11,9 +11,16 @@ export declare abstract class FunctionalElementBaseClass<PropertyInitGeneric ext
11
11
  }
12
12
  export declare type FunctionalElementInstance<PropertyInitGeneric extends PropertyInitMapBase> = FunctionalElementBaseClass<PropertyInitGeneric> & PropertyInitGeneric;
13
13
  export declare type FunctionalElementConstructor<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (new () => FunctionalElementInstance<PropertyInitGeneric>) & ExtraStaticFunctionalElementProperties<PropertyInitGeneric, EventsInitGeneric>;
14
- export declare type ExtraStaticFunctionalElementProperties<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
14
+ export declare type ExtraStaticFunctionalElementProperties<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = Readonly<{
15
15
  /** Pass through the render callback for direct unit testability */
16
16
  renderCallback: RenderCallback<PropertyInitGeneric, EventsInitGeneric>;
17
17
  events: EventDescriptorMap<EventsInitGeneric>;
18
18
  props: ElementPropertyDescriptorMap<PropertyInitGeneric>;
19
- };
19
+ /**
20
+ * Static properties have to be copied here cause they get nuked in the "new () =>
21
+ * FunctionalElementInstance<PropertyInitGeneric>" type.
22
+ */
23
+ tagName: string;
24
+ styles: CSSResult;
25
+ propNames: string[];
26
+ }>;
@@ -0,0 +1,8 @@
1
+ import { EventsInitMap } from './element-events';
2
+ import { PropertyInitMapBase } from './element-properties';
3
+ import { FunctionalElementInstance } from './functional-element';
4
+ import { RenderParams } from './render-callback';
5
+ export declare type LifecycleCallbackParams<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = {
6
+ element: FunctionalElementInstance<PropertyInitGeneric>;
7
+ } & RenderParams<PropertyInitGeneric, EventsInitGeneric>;
8
+ export declare type LifecycleCallback<PropertyInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap> = (params: LifecycleCallbackParams<PropertyInitGeneric, EventsInitGeneric>) => void;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './functional-element/connection-callback';
2
1
  export * from './functional-element/define-functional-element';
3
2
  export * from './functional-element/directives/event-listen.directive';
4
3
  export * from './functional-element/directives/property-assign.directive';
@@ -6,6 +5,7 @@ export * from './functional-element/element-events';
6
5
  export * from './functional-element/element-properties';
7
6
  export * from './functional-element/functional-element';
8
7
  export * from './functional-element/functional-element-init';
8
+ export * from './functional-element/lifecycle-callback';
9
9
  export * from './functional-element/render-callback';
10
10
  export * from './vir-html/directive';
11
11
  export * from './vir-html/vir-html';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from './functional-element/connection-callback';
2
1
  export * from './functional-element/define-functional-element';
3
2
  export * from './functional-element/directives/event-listen.directive';
4
3
  export * from './functional-element/directives/property-assign.directive';
@@ -6,6 +5,7 @@ export * from './functional-element/element-events';
6
5
  export * from './functional-element/element-properties';
7
6
  export * from './functional-element/functional-element';
8
7
  export * from './functional-element/functional-element-init';
8
+ export * from './functional-element/lifecycle-callback';
9
9
  export * from './functional-element/render-callback';
10
10
  export * from './vir-html/directive';
11
11
  export * from './vir-html/vir-html';
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "0.0.1",
3
+ "version": "0.0.5",
4
+ "keywords": [
5
+ "custom",
6
+ "web",
7
+ "components",
8
+ "elements",
9
+ "functional",
10
+ "lit"
11
+ ],
4
12
  "homepage": "https://github.com/electrovir/element-vir#readme",
5
13
  "bugs": {
6
14
  "url": "https://github.com/electrovir/element-vir/issues"
@@ -1,7 +0,0 @@
1
- import { PropertyInitMapBase } from './element-properties';
2
- import { FunctionalElementInstance } from './functional-element';
3
- export declare type ConnectionCallbackParams<PropertyInitGeneric extends PropertyInitMapBase> = {
4
- element: FunctionalElementInstance<PropertyInitGeneric>;
5
- props: PropertyInitGeneric;
6
- };
7
- export declare type ConnectionCallback<PropertyInitGeneric extends PropertyInitMapBase> = (params: ConnectionCallbackParams<PropertyInitGeneric>) => void;