element-vir 6.3.4 → 7.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 (68) hide show
  1. package/README.md +91 -2
  2. package/package.json +21 -24
  3. package/dist/augments/array.d.ts +0 -1
  4. package/dist/augments/array.js +0 -3
  5. package/dist/augments/type.d.ts +0 -8
  6. package/dist/augments/type.js +0 -13
  7. package/dist/declarative-element/css-vars.d.ts +0 -6
  8. package/dist/declarative-element/css-vars.js +0 -22
  9. package/dist/declarative-element/declarative-element-init.d.ts +0 -44
  10. package/dist/declarative-element/declarative-element-init.js +0 -1
  11. package/dist/declarative-element/declarative-element.d.ts +0 -48
  12. package/dist/declarative-element/declarative-element.js +0 -18
  13. package/dist/declarative-element/define-element-no-inputs.d.ts +0 -5
  14. package/dist/declarative-element/define-element-no-inputs.js +0 -133
  15. package/dist/declarative-element/define-element.d.ts +0 -5
  16. package/dist/declarative-element/define-element.js +0 -13
  17. package/dist/declarative-element/definition-options.d.ts +0 -5
  18. package/dist/declarative-element/definition-options.js +0 -4
  19. package/dist/declarative-element/directives/assign-with-clean-up.directive.d.ts +0 -23
  20. package/dist/declarative-element/directives/assign-with-clean-up.directive.js +0 -43
  21. package/dist/declarative-element/directives/assign.directive.d.ts +0 -12
  22. package/dist/declarative-element/directives/assign.directive.js +0 -28
  23. package/dist/declarative-element/directives/awaiting.directive.d.ts +0 -18
  24. package/dist/declarative-element/directives/awaiting.directive.js +0 -42
  25. package/dist/declarative-element/directives/directive-helpers.d.ts +0 -14
  26. package/dist/declarative-element/directives/directive-helpers.js +0 -21
  27. package/dist/declarative-element/directives/listen.directive.d.ts +0 -14
  28. package/dist/declarative-element/directives/listen.directive.js +0 -47
  29. package/dist/declarative-element/directives/on-dom-created.directive.d.ts +0 -11
  30. package/dist/declarative-element/directives/on-dom-created.directive.js +0 -23
  31. package/dist/declarative-element/directives/on-resize.directive.d.ts +0 -15
  32. package/dist/declarative-element/directives/on-resize.directive.js +0 -36
  33. package/dist/declarative-element/element-events.d.ts +0 -10
  34. package/dist/declarative-element/element-events.js +0 -24
  35. package/dist/declarative-element/element-properties.d.ts +0 -16
  36. package/dist/declarative-element/element-properties.js +0 -72
  37. package/dist/declarative-element/has-declarative-element-parent.d.ts +0 -1
  38. package/dist/declarative-element/has-declarative-element-parent.js +0 -16
  39. package/dist/declarative-element/host-classes.d.ts +0 -21
  40. package/dist/declarative-element/host-classes.js +0 -12
  41. package/dist/declarative-element/render-callback.d.ts +0 -22
  42. package/dist/declarative-element/render-callback.js +0 -21
  43. package/dist/declarative-element/styles.d.ts +0 -23
  44. package/dist/declarative-element/styles.js +0 -32
  45. package/dist/declarative-element/tag-name.d.ts +0 -2
  46. package/dist/declarative-element/tag-name.js +0 -4
  47. package/dist/declarative-element-marker-symbol.d.ts +0 -1
  48. package/dist/declarative-element-marker-symbol.js +0 -1
  49. package/dist/index.d.ts +0 -18
  50. package/dist/index.js +0 -17
  51. package/dist/require-declarative-element.d.ts +0 -2
  52. package/dist/require-declarative-element.js +0 -4
  53. package/dist/template-transforms/has-static-tag-name.d.ts +0 -4
  54. package/dist/template-transforms/has-static-tag-name.js +0 -6
  55. package/dist/template-transforms/nested-mapped-templates.d.ts +0 -6
  56. package/dist/template-transforms/nested-mapped-templates.js +0 -96
  57. package/dist/template-transforms/transform-template.d.ts +0 -16
  58. package/dist/template-transforms/transform-template.js +0 -87
  59. package/dist/template-transforms/vir-css/css-transform.d.ts +0 -7
  60. package/dist/template-transforms/vir-css/css-transform.js +0 -12
  61. package/dist/template-transforms/vir-css/vir-css.d.ts +0 -3
  62. package/dist/template-transforms/vir-css/vir-css.js +0 -12
  63. package/dist/template-transforms/vir-html/html-transform.d.ts +0 -3
  64. package/dist/template-transforms/vir-html/html-transform.js +0 -44
  65. package/dist/template-transforms/vir-html/vir-html.d.ts +0 -3
  66. package/dist/template-transforms/vir-html/vir-html.js +0 -16
  67. package/dist/typed-event/typed-event.d.ts +0 -19
  68. package/dist/typed-event/typed-event.js +0 -32
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "6.3.4",
3
+ "version": "7.0.0",
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
28
  "compile": "rm -rf dist && 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 +0,0 @@
1
- export declare function filterOutArrayIndexes<T>(array: Readonly<T[]>, indexes: Readonly<number[]>): T[];
@@ -1,3 +0,0 @@
1
- export function filterOutArrayIndexes(array, indexes) {
2
- return array.filter((_, index) => !indexes.includes(index));
3
- }
@@ -1,8 +0,0 @@
1
- export type NonEmptyString<T> = T extends '' ? never : T;
2
- /**
3
- * If the given value is not an instance of the given constructor, an error is thrown.
4
- *
5
- * This is a variation of assertInstanceOf that can be run in run-time code and doesn't require
6
- * testing packages.
7
- */
8
- export declare function ensureInstanceOf<T>(value: unknown, constructor: new (...args: any) => T, message?: string): asserts value is T;
@@ -1,13 +0,0 @@
1
- /**
2
- * If the given value is not an instance of the given constructor, an error is thrown.
3
- *
4
- * This is a variation of assertInstanceOf that can be run in run-time code and doesn't require
5
- * testing packages.
6
- */
7
- export function ensureInstanceOf(value, constructor, message) {
8
- if (!(value instanceof constructor)) {
9
- const extraMessage = message ? `: ${message}` : '';
10
- const errorMessage = `${value} is not an instanceof of ${constructor.name}${extraMessage}`;
11
- throw new TypeError(errorMessage);
12
- }
13
- }
@@ -1,6 +0,0 @@
1
- import { CSSResult } from 'lit';
2
- export type CssVarsInitMap<CssVarKeys extends string> = Record<CssVarKeys, string | CSSResult>;
3
- export type CssVarName<TagName extends string> = `--${TagName}-string`;
4
- export type CssVarNameOrValueMap<CssVarKeys extends string> = Record<CssVarKeys, CSSResult>;
5
- export declare function createCssVarNamesMap<TagName extends string, CssVarKeys extends string>(tagName: TagName, cssVarsInit: CssVarsInitMap<CssVarKeys> | undefined): CssVarNameOrValueMap<CssVarKeys>;
6
- export declare function createCssVarValuesMap<CssVarKeys extends string>(cssVarInitMap: CssVarsInitMap<CssVarKeys> | undefined, cssVarNamesMap: CssVarNameOrValueMap<CssVarKeys>): CssVarNameOrValueMap<CssVarKeys>;
@@ -1,22 +0,0 @@
1
- import { mapObjectValues } from '@augment-vir/common';
2
- import { unsafeCSS } from 'lit';
3
- import { toHtmlSafeWithTagName } from './tag-name';
4
- export function createCssVarNamesMap(tagName, cssVarsInit) {
5
- if (cssVarsInit) {
6
- return mapObjectValues(cssVarsInit, (key) => {
7
- return unsafeCSS(`--${toHtmlSafeWithTagName(tagName, String(key))}`);
8
- });
9
- }
10
- else {
11
- return {};
12
- }
13
- }
14
- export function createCssVarValuesMap(cssVarInitMap, cssVarNamesMap) {
15
- if (!cssVarInitMap) {
16
- return {};
17
- }
18
- return mapObjectValues(cssVarInitMap, (key, fallbackValue) => {
19
- const name = cssVarNamesMap[key];
20
- return unsafeCSS(`var(${name}, ${fallbackValue})`);
21
- });
22
- }
@@ -1,44 +0,0 @@
1
- import { CSSResult } from 'lit';
2
- import { CssVarsInitMap } from './css-vars';
3
- import { DeclarativeElementDefinitionOptions } from './definition-options';
4
- import { EventsInitMap } from './element-events';
5
- import { PropertyInitMapBase } from './element-properties';
6
- import { HostClassesInitMap } from './host-classes';
7
- import { InitCallback, RenderCallback } from './render-callback';
8
- import { StylesCallback } from './styles';
9
- export type CustomElementTagName = `${string}-${string}`;
10
- export type DeclarativeElementInit<InputsGeneric extends PropertyInitMapBase, StateInit extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> = {
11
- /**
12
- * HTML tag name. This should not be used directly, as interpolating it with the html tagged
13
- * template from this package is preferred.
14
- */
15
- tagName: CustomElementTagName;
16
- /** Static styles. These should not and cannot change. */
17
- styles?: CSSResult | StylesCallback<HostClassKeys, CssVarKeys>;
18
- /** Element properties. (These can be thought of as "inputs".) */
19
- stateInit?: StateInit;
20
- /** Events that the element can dispatch. (These can be thought of as "outputs".) */
21
- events?: EventsInitGeneric;
22
- /**
23
- * CSS host classes. Values can be callbacks to determine when a host class should be defined,
24
- * based on current instance state or inputs, or just undefined to indicate that the host class
25
- * will only be manually set.
26
- */
27
- hostClasses?: HostClassesInitMap<HostClassKeys, InputsGeneric, StateInit>;
28
- /**
29
- * CSS Vars for the component. Keys of this object should be camelCased (or whatever your casing
30
- * convention is). They will be transformed, at runtime, to CSS vars with kebab-casing, to match
31
- * CSS standards.
32
- *
33
- * Values of this object represent the default fallback value for the given CSS var. These are
34
- * then passed to the styles property, which must be a callback to take advantage of these.
35
- * cssVarValues or cssVarNames can then be destructured from the styles property's callback
36
- * input.
37
- */
38
- cssVars?: CssVarsInitMap<CssVarKeys>;
39
- /** Called as part of the first renderCallback call, before the first renderCallback call. */
40
- initCallback?: InitCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
41
- renderCallback: RenderCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
42
- cleanupCallback?: InitCallback<InputsGeneric, StateInit, EventsInitGeneric, HostClassKeys, CssVarKeys>;
43
- options?: Partial<DeclarativeElementDefinitionOptions> | undefined;
44
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- import { RequiredAndNotNullBy, RequiredBy } from '@augment-vir/common';
2
- import { CSSResult, LitElement, TemplateResult } from 'lit';
3
- import { CssVarNameOrValueMap } from './css-vars';
4
- 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';
8
- import { RenderCallback } from './render-callback';
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
- 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
- instanceType: HostInstanceType<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
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 {
14
- static readonly tagName: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['tagName'];
15
- static readonly styles: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['styles'];
16
- static readonly isStrictInstance: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['isStrictInstance'];
17
- static readonly renderCallback: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['renderCallback'];
18
- static readonly inputsType: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['inputsType'];
19
- static readonly stateType: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateType'];
20
- static readonly events: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['events'];
21
- static readonly stateInit: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['stateInit'];
22
- static readonly init: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['init'];
23
- static readonly hostClasses: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['hostClasses'];
24
- static readonly cssVarNames: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarNames'];
25
- static readonly cssVarValues: StaticDeclarativeElementProperties<PropertyInitMapBase, PropertyInitMapBase, EventsInitMap, string, string>['cssVarValues'];
26
- abstract render(): TemplateResult | Promise<TemplateResult>;
27
- abstract readonly instanceState: PropertyInitGeneric;
28
- abstract readonly instanceInputs: InputsGeneric;
29
- abstract assignInputs(inputs: InputsGeneric): void;
30
- abstract readonly haveInputsBeenSet: boolean;
31
- abstract markInputsAsHavingBeenSet(): void;
32
- abstract readonly definition: DeclarativeElementDefinition<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
33
- }
34
- export interface StaticDeclarativeElementProperties<InputsGeneric extends PropertyInitMapBase, StateInitGeneric extends PropertyInitMapBase, EventsInitGeneric extends EventsInitMap, HostClassKeys extends string, CssVarKeys extends string> {
35
- /** Pass through the render callback for direct unit testability */
36
- readonly renderCallback: RenderCallback<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
37
- events: EventDescriptorMap<EventsInitGeneric>;
38
- stateInit: ElementPropertyDescriptorMap<StateInitGeneric>;
39
- init: RequiredBy<DeclarativeElementInit<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>, 'stateInit' | 'events'>;
40
- inputsType: InputsGeneric;
41
- stateType: StateInitGeneric;
42
- isStrictInstance: (element: unknown) => element is DeclarativeElement<InputsGeneric, StateInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
43
- hostClasses: HostClassNamesMap<string, HostClassKeys>;
44
- cssVarNames: CssVarNameOrValueMap<CssVarKeys>;
45
- cssVarValues: CssVarNameOrValueMap<CssVarKeys>;
46
- tagName: string;
47
- styles: CSSResult;
48
- }
@@ -1,18 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { LitElement } from 'lit';
8
- function staticImplements() {
9
- return (constructor) => {
10
- constructor;
11
- };
12
- }
13
- let DeclarativeElement = class DeclarativeElement extends LitElement {
14
- };
15
- DeclarativeElement = __decorate([
16
- staticImplements()
17
- ], DeclarativeElement);
18
- export { DeclarativeElement };
@@ -1,5 +0,0 @@
1
- import { DeclarativeElementDefinition } from './declarative-element';
2
- import { DeclarativeElementInit } from './declarative-element-init';
3
- import { EventsInitMap } from './element-events';
4
- import { PropertyInitMapBase } from './element-properties';
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>;
@@ -1,133 +0,0 @@
1
- import { getObjectTypedKeys, kebabCaseToCamelCase } from '@augment-vir/common';
2
- import { css } from 'lit';
3
- import { property } from 'lit/decorators.js';
4
- import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
5
- import { createCssVarNamesMap, createCssVarValuesMap } from './css-vars';
6
- import { DeclarativeElement, } from './declarative-element';
7
- import { defaultDeclarativeElementDefinitionOptions, IgnoreInputsNotBeenSetBeforeRenderWarningSymbol, } from './definition-options';
8
- import { assign } from './directives/assign.directive';
9
- import { createEventDescriptorMap } from './element-events';
10
- import { createElementUpdaterProxy } from './element-properties';
11
- import { hasDeclarativeElementParent } from './has-declarative-element-parent';
12
- import { createHostClassNamesMap } from './host-classes';
13
- import { createRenderParams } from './render-callback';
14
- import { applyHostClasses, hostClassNamesToStylesInput } from './styles';
15
- export function defineElementNoInputs(initInput) {
16
- var _a;
17
- const eventsMap = createEventDescriptorMap(initInput.events);
18
- const hostClassNames = createHostClassNamesMap(initInput.tagName, initInput.hostClasses);
19
- const cssVarNames = createCssVarNamesMap(initInput.tagName, initInput.cssVars);
20
- const cssVarValues = createCssVarValuesMap(initInput.cssVars, cssVarNames);
21
- const elementOptions = {
22
- ...defaultDeclarativeElementDefinitionOptions,
23
- ...initInput.options,
24
- };
25
- const calculatedStyles = typeof initInput.styles === 'function'
26
- ? initInput.styles(hostClassNamesToStylesInput({ hostClassNames, cssVarNames, cssVarValues }))
27
- : initInput.styles || css ``;
28
- const typedRenderCallback = initInput.renderCallback;
29
- const anonymousClass = (_a = class extends DeclarativeElement {
30
- createRenderParams() {
31
- return createRenderParams(this, eventsMap);
32
- }
33
- get instanceType() {
34
- throw new Error(`"instanceType" was called on ${initInput.tagName} as a value but it is only for types.`);
35
- }
36
- static get inputsType() {
37
- throw new Error(`"inputsType" was called on ${initInput.tagName} as a value but it is only for types.`);
38
- }
39
- static get stateType() {
40
- throw new Error(`"stateType" was called on ${initInput.tagName} as a value but it is only for types.`);
41
- }
42
- markInputsAsHavingBeenSet() {
43
- if (!this.haveInputsBeenSet) {
44
- this.haveInputsBeenSet = true;
45
- }
46
- }
47
- render() {
48
- if (
49
- // This ignores elements at the root of a page, as they can't receive inputs from
50
- // other elements (cause they have no custom element ancestors).
51
- hasDeclarativeElementParent(this) &&
52
- !this.haveInputsBeenSet &&
53
- !elementOptions[IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]) {
54
- console.warn(this, `${initInput.tagName} got rendered before its input object was set. This was most likely caused by forgetting to use the "${assign.name}" directive on it. If no inputs are intended, use "${defineElementNoInputs.name}" to define ${initInput.tagName}.`);
55
- }
56
- const renderParams = this.createRenderParams();
57
- if (!this.initCalled && initInput.initCallback) {
58
- this.initCalled = true;
59
- initInput.initCallback(renderParams);
60
- }
61
- const renderResult = initInput.renderCallback(renderParams);
62
- applyHostClasses({
63
- host: renderParams.host,
64
- hostClassesInit: initInput.hostClasses,
65
- hostClassNames,
66
- state: renderParams.state,
67
- inputs: renderParams.inputs,
68
- });
69
- return renderResult;
70
- }
71
- disconnectedCallback() {
72
- super.disconnectedCallback();
73
- if (initInput.cleanupCallback) {
74
- const renderParams = this.createRenderParams();
75
- initInput.cleanupCallback(renderParams);
76
- }
77
- this.initCalled = false;
78
- }
79
- assignInputs(inputs) {
80
- getObjectTypedKeys(inputs).forEach((key) => {
81
- property()(this, key);
82
- this.instanceInputs[key] = inputs[key];
83
- });
84
- this.markInputsAsHavingBeenSet();
85
- }
86
- constructor() {
87
- super();
88
- this.initCalled = false;
89
- this.haveInputsBeenSet = false;
90
- // this is set below in Object.defineProperties
91
- this.definition = {};
92
- this.instanceInputs = createElementUpdaterProxy(this, false);
93
- this.instanceState = createElementUpdaterProxy(this, true);
94
- const stateInit = initInput.stateInit || {};
95
- Object.keys(stateInit).forEach((propName) => {
96
- property()(this, propName);
97
- this[propName] = stateInit[propName];
98
- });
99
- this.definition = anonymousClass;
100
- }
101
- },
102
- _a.tagName = initInput.tagName,
103
- _a.styles = calculatedStyles,
104
- // this gets set below in Object.defineProperties
105
- _a.isStrictInstance = () => false,
106
- _a.events = eventsMap,
107
- _a.renderCallback = typedRenderCallback,
108
- _a.hostClasses = hostClassNames,
109
- _a.cssVarNames = cssVarNames,
110
- _a.stateInit = initInput.stateInit,
111
- _a.cssVarValues = cssVarNames,
112
- _a);
113
- Object.defineProperties(anonymousClass, {
114
- [DeclarativeElementMarkerSymbol]: {
115
- value: true,
116
- writable: false,
117
- },
118
- name: {
119
- value: kebabCaseToCamelCase(initInput.tagName, {
120
- capitalizeFirstLetter: true,
121
- }),
122
- writable: true,
123
- },
124
- isStrictInstance: {
125
- value: (element) => {
126
- return element instanceof anonymousClass;
127
- },
128
- writable: false,
129
- },
130
- });
131
- window.customElements.define(initInput.tagName, anonymousClass);
132
- return anonymousClass;
133
- }
@@ -1,5 +0,0 @@
1
- import { DeclarativeElementDefinition } from './declarative-element';
2
- import { DeclarativeElementInit } from './declarative-element-init';
3
- import { EventsInitMap } from './element-events';
4
- import { PropertyInitMapBase } from './element-properties';
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>;
@@ -1,13 +0,0 @@
1
- import { defineElementNoInputs } from './define-element-no-inputs';
2
- import { IgnoreInputsNotBeenSetBeforeRenderWarningSymbol } from './definition-options';
3
- export function defineElement() {
4
- return (initInput) => {
5
- return defineElementNoInputs({
6
- ...initInput,
7
- options: {
8
- [IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: false,
9
- },
10
- ...initInput.options,
11
- });
12
- };
13
- }
@@ -1,5 +0,0 @@
1
- export declare const IgnoreInputsNotBeenSetBeforeRenderWarningSymbol: unique symbol;
2
- export type DeclarativeElementDefinitionOptions = {
3
- [IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: boolean;
4
- };
5
- export declare const defaultDeclarativeElementDefinitionOptions: DeclarativeElementDefinitionOptions;
@@ -1,4 +0,0 @@
1
- export const IgnoreInputsNotBeenSetBeforeRenderWarningSymbol = Symbol('key for ignoring inputs not having been set yet');
2
- export const defaultDeclarativeElementDefinitionOptions = {
3
- [IgnoreInputsNotBeenSetBeforeRenderWarningSymbol]: true,
4
- };
@@ -1,23 +0,0 @@
1
- import { AsyncDirective } from 'lit/async-directive.js';
2
- import { PartInfo } from 'lit/directive.js';
3
- import { DeclarativeElementDefinition } from '../declarative-element';
4
- export type CleanupCallback<T> = (oldValue: T) => void;
5
- /**
6
- * Assign values but include a cleanup callback which gets called when a new value gets assigned so
7
- * the previous value can get cleaned up. An optional equality check callback can be provided. If it
8
- * is provided, the clean up callback will then only be called if the equality check callback
9
- * resolves to false (which indicates that the previous value and the new value are not equal).
10
- *
11
- * Example use case: 3D graphics applications with classes that setup buffers and the like.
12
- */
13
- export declare function assignWithCleanup<DeclarativeElementGeneric extends DeclarativeElementDefinition>(elementDefinition: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric extends DeclarativeElementDefinition<infer InputsGeneric> ? InputsGeneric : never, cleanupCallback: CleanupCallback<DeclarativeElementGeneric extends DeclarativeElementDefinition<infer InputsGeneric> ? InputsGeneric : never>): import("lit-html/directive").DirectiveResult<typeof AssignWithCleanupDirectiveClass>;
14
- declare class AssignWithCleanupDirectiveClass extends AsyncDirective {
15
- private readonly element;
16
- private lastValue;
17
- private lastCallback;
18
- private hasBeenAssigned;
19
- constructor(partInfo: PartInfo);
20
- disconnected(): void;
21
- render(elementDefinition: DeclarativeElementDefinition, inputsObject: Record<PropertyKey, unknown>, cleanupCallback: CleanupCallback<any>): symbol;
22
- }
23
- export {};
@@ -1,43 +0,0 @@
1
- import { noChange } from 'lit';
2
- import { AsyncDirective } from 'lit/async-directive.js';
3
- import { directive } from 'lit/directive.js';
4
- import { assignInputsObject } from './assign.directive';
5
- import { extractDeclarativeElement } from './directive-helpers';
6
- /**
7
- * Assign values but include a cleanup callback which gets called when a new value gets assigned so
8
- * the previous value can get cleaned up. An optional equality check callback can be provided. If it
9
- * is provided, the clean up callback will then only be called if the equality check callback
10
- * resolves to false (which indicates that the previous value and the new value are not equal).
11
- *
12
- * Example use case: 3D graphics applications with classes that setup buffers and the like.
13
- */
14
- export function assignWithCleanup(elementDefinition, inputsObject, cleanupCallback) {
15
- /**
16
- * The directive generics (in listenDirective) are not strong enough to maintain their values.
17
- * Thus, the directive call is wrapped in this function.
18
- */
19
- return assignWithCleanupDirective(elementDefinition, inputsObject, cleanupCallback);
20
- }
21
- class AssignWithCleanupDirectiveClass extends AsyncDirective {
22
- constructor(partInfo) {
23
- super(partInfo);
24
- this.hasBeenAssigned = false;
25
- this.element = extractDeclarativeElement(partInfo, 'assign');
26
- }
27
- disconnected() {
28
- if (this.lastValue != undefined && this.lastCallback != undefined) {
29
- this.lastCallback(this.lastValue);
30
- }
31
- }
32
- render(elementDefinition, inputsObject, cleanupCallback) {
33
- if (this.hasBeenAssigned) {
34
- cleanupCallback(this.lastValue);
35
- }
36
- assignInputsObject(elementDefinition, this.element, inputsObject);
37
- this.hasBeenAssigned = true;
38
- this.lastValue = inputsObject;
39
- this.lastCallback = cleanupCallback;
40
- return noChange;
41
- }
42
- }
43
- const assignWithCleanupDirective = directive(AssignWithCleanupDirectiveClass);
@@ -1,12 +0,0 @@
1
- import { PartInfo } from 'lit/directive.js';
2
- import { DeclarativeElement, DeclarativeElementDefinition } from '../declarative-element';
3
- /** Assign an object matching an element's inputs to its inputs. */
4
- export declare function assign<DeclarativeElementGeneric extends DeclarativeElementDefinition>(declarativeElement: DeclarativeElementGeneric, inputsObject: DeclarativeElementGeneric['inputsType']): import("lit-html/directive").DirectiveResult<{
5
- new (partInfo: PartInfo): {
6
- readonly element: DeclarativeElement<any, any, any, string, string>;
7
- render(elementDefinition: DeclarativeElementDefinition<any, any, any, string, string>, inputsObject: Record<PropertyKey, unknown>): symbol;
8
- readonly _$isConnected: boolean;
9
- update(_part: import("lit-html").Part, props: unknown[]): unknown;
10
- };
11
- }>;
12
- export declare function assignInputsObject<DeclarativeElementInstanceGeneric extends DeclarativeElement, DeclarativeElementDefinitionGeneric extends DeclarativeElementDefinition>(expectedElementConstructor: DeclarativeElementDefinitionGeneric, element: DeclarativeElementInstanceGeneric, assignmentObject: DeclarativeElementDefinitionGeneric['inputsType']): void;