element-vir 22.2.2 → 23.1.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.
- package/README.md +44 -38
- package/dist/declarative-element/custom-tag-name.d.ts +6 -0
- package/dist/declarative-element/declarative-element-init.d.ts +20 -14
- package/dist/declarative-element/declarative-element.d.ts +70 -24
- package/dist/declarative-element/declarative-element.js +34 -1
- package/dist/declarative-element/define-element-no-inputs.d.ts +31 -6
- package/dist/declarative-element/define-element-no-inputs.js +154 -257
- package/dist/declarative-element/define-element.d.ts +35 -7
- package/dist/declarative-element/define-element.js +26 -4
- package/dist/declarative-element/definition-options.d.ts +10 -0
- package/dist/declarative-element/definition-options.js +5 -0
- package/dist/declarative-element/directives/assign.directive.d.ts +8 -11
- package/dist/declarative-element/directives/assign.directive.js +6 -13
- package/dist/declarative-element/directives/async-prop.d.ts +19 -4
- package/dist/declarative-element/directives/async-prop.js +14 -4
- package/dist/declarative-element/directives/create-attribute-directive.d.ts +19 -4
- package/dist/declarative-element/directives/create-attribute-directive.js +18 -8
- package/dist/declarative-element/directives/directive-helpers.d.ts +19 -4
- package/dist/declarative-element/directives/directive-helpers.js +14 -2
- package/dist/declarative-element/directives/is-resolved.directive.d.ts +107 -1
- package/dist/declarative-element/directives/is-resolved.directive.js +107 -1
- package/dist/declarative-element/directives/listen.directive.d.ts +84 -10
- package/dist/declarative-element/directives/listen.directive.js +5 -15
- package/dist/declarative-element/directives/on-dom-created.directive.d.ts +37 -4
- package/dist/declarative-element/directives/on-dom-created.directive.js +32 -12
- package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +33 -3
- package/dist/declarative-element/directives/on-dom-rendered.directive.js +29 -6
- package/dist/declarative-element/directives/on-resize.directive.d.ts +37 -4
- package/dist/declarative-element/directives/on-resize.directive.js +37 -24
- package/dist/declarative-element/directives/render-async.directive.d.ts +44 -4
- package/dist/declarative-element/directives/render-async.directive.js +13 -3
- package/dist/declarative-element/directives/render-if.directive.d.ts +31 -0
- package/dist/declarative-element/directives/render-if.directive.js +32 -1
- package/dist/declarative-element/directives/test-id.directive.d.ts +48 -4
- package/dist/declarative-element/directives/test-id.directive.js +47 -2
- package/dist/declarative-element/has-declarative-element-parent.js +1 -1
- package/dist/declarative-element/is-declarative-element-definition.d.ts +15 -1
- package/dist/declarative-element/is-declarative-element-definition.js +21 -18
- package/dist/declarative-element/is-declarative-element.d.ts +5 -1
- package/dist/declarative-element/is-declarative-element.js +7 -3
- package/dist/declarative-element/properties/assign-inputs.js +1 -1
- package/dist/declarative-element/properties/css-properties.d.ts +11 -1
- package/dist/declarative-element/properties/css-properties.js +5 -0
- package/dist/declarative-element/properties/css-vars.d.ts +14 -4
- package/dist/declarative-element/properties/element-events.d.ts +61 -7
- package/dist/declarative-element/properties/element-events.js +40 -5
- package/dist/declarative-element/properties/element-properties.d.ts +15 -6
- package/dist/declarative-element/properties/element-properties.js +1 -21
- package/dist/declarative-element/properties/element-vir-state-setup.d.ts +43 -3
- package/dist/declarative-element/properties/element-vir-state-setup.js +17 -3
- package/dist/declarative-element/properties/host-classes.d.ts +25 -12
- package/dist/declarative-element/properties/host-classes.js +5 -0
- package/dist/declarative-element/properties/per-instance.d.ts +23 -2
- package/dist/declarative-element/properties/per-instance.js +24 -3
- package/dist/declarative-element/properties/property-proxy.d.ts +19 -4
- package/dist/declarative-element/properties/property-proxy.js +14 -4
- package/dist/declarative-element/properties/styles.d.ts +33 -8
- package/dist/declarative-element/properties/styles.js +12 -2
- package/dist/declarative-element/properties/tag-name.d.ts +5 -0
- package/dist/declarative-element/render-callback.d.ts +38 -11
- package/dist/declarative-element/render-callback.js +6 -0
- package/dist/declarative-element/slot-names.d.ts +10 -2
- package/dist/declarative-element/slot-names.js +5 -1
- package/dist/declarative-element/wrap-define-element.d.ts +38 -11
- package/dist/declarative-element/wrap-define-element.js +17 -2
- package/dist/index.d.ts +40 -40
- package/dist/index.js +40 -39
- package/dist/lit-exports/all-lit-exports.d.ts +2 -2
- package/dist/lit-exports/all-lit-exports.js +2 -2
- package/dist/lit-exports/lit-repeat-fix.d.ts +60 -4
- package/dist/lit-exports/lit-repeat-fix.js +35 -1
- package/dist/readme-examples/my-app.element.d.ts +1 -0
- package/dist/readme-examples/my-app.element.js +11 -0
- package/dist/readme-examples/my-custom-action.event.d.ts +1 -0
- package/dist/readme-examples/my-custom-action.event.js +2 -0
- package/dist/readme-examples/my-custom-define.d.ts +4 -0
- package/dist/readme-examples/my-custom-define.js +19 -0
- package/dist/readme-examples/my-simple.element.d.ts +1 -0
- package/dist/readme-examples/my-simple.element.js +9 -0
- package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
- package/dist/readme-examples/my-with-assignment.element.js +14 -0
- package/dist/readme-examples/my-with-async-prop.element.d.ts +9 -0
- package/dist/readme-examples/my-with-async-prop.element.js +46 -0
- package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
- package/dist/readme-examples/my-with-cleanup-callback.element.js +23 -0
- package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
- package/dist/readme-examples/my-with-css-vars.element.js +24 -0
- package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
- package/dist/readme-examples/my-with-custom-events.element.js +21 -0
- package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
- package/dist/readme-examples/my-with-event-listening.element.js +22 -0
- package/dist/readme-examples/my-with-events.element.d.ts +4 -0
- package/dist/readme-examples/my-with-events.element.js +19 -0
- package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
- package/dist/readme-examples/my-with-host-class-definition.element.js +39 -0
- package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
- package/dist/readme-examples/my-with-host-class-usage.element.js +12 -0
- package/dist/readme-examples/my-with-inputs.element.d.ts +4 -0
- package/dist/readme-examples/my-with-inputs.element.js +9 -0
- package/dist/readme-examples/my-with-on-dom-created.element.d.ts +1 -0
- package/dist/readme-examples/my-with-on-dom-created.element.js +16 -0
- package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
- package/dist/readme-examples/my-with-on-resize.element.js +17 -0
- package/dist/readme-examples/my-with-render-if.element.d.ts +3 -0
- package/dist/readme-examples/my-with-render-if.element.js +11 -0
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +1 -0
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.js +15 -0
- package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
- package/dist/readme-examples/my-with-styles.element.js +21 -0
- package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
- package/dist/readme-examples/my-with-update-state.element.js +23 -0
- package/dist/readme-examples/require-declarative-element.d.ts +1 -0
- package/dist/readme-examples/require-declarative-element.js +2 -0
- package/dist/require-declarative-element.d.ts +12 -0
- package/dist/require-declarative-element.js +12 -0
- package/dist/template-transforms/minimal-element-definition.d.ts +30 -2
- package/dist/template-transforms/minimal-element-definition.js +14 -3
- package/dist/template-transforms/nested-mapped-templates.d.ts +1 -1
- package/dist/template-transforms/nested-mapped-templates.js +4 -3
- package/dist/template-transforms/template-transform-type.d.ts +1 -1
- package/dist/template-transforms/transform-template.d.ts +1 -1
- package/dist/template-transforms/transform-template.js +17 -21
- package/dist/template-transforms/vir-css/css-transform.d.ts +3 -3
- package/dist/template-transforms/vir-css/css-transform.js +3 -2
- package/dist/template-transforms/vir-css/vir-css.d.ts +11 -2
- package/dist/template-transforms/vir-css/vir-css.js +11 -2
- package/dist/template-transforms/vir-html/html-interpolation.d.ts +9 -5
- package/dist/template-transforms/vir-html/html-transform.d.ts +3 -3
- package/dist/template-transforms/vir-html/html-transform.js +14 -12
- package/dist/template-transforms/vir-html/vir-html.d.ts +4 -2
- package/dist/template-transforms/vir-html/vir-html.js +4 -2
- package/dist/typed-event/typed-event.d.ts +42 -6
- package/dist/typed-event/typed-event.js +31 -28
- package/dist/util/lit-template.d.ts +6 -1
- package/dist/util/lit-template.js +10 -7
- package/dist/util/type.d.ts +5 -0
- package/package.json +37 -35
|
@@ -1,18 +1,37 @@
|
|
|
1
|
-
import { directive, Directive } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { assertIsElementPartInfo } from './directive-helpers';
|
|
1
|
+
import { directive, Directive } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { assertIsElementPartInfo } from './directive-helpers.js';
|
|
3
3
|
const directiveName = 'onDomCreated';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A directive that fires its listener only once, when the element that it's attached to is
|
|
6
|
+
* constructed. This is particularly useful for getting references to internal elements immediately
|
|
7
|
+
* after they've rendered.
|
|
8
|
+
*
|
|
9
|
+
* @category Directives
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {html, defineElementNoInputs, onDomCreated} from 'element-vir';
|
|
14
|
+
*
|
|
15
|
+
* const MyElement = defineElementNoInputs({
|
|
16
|
+
* tagName: 'my-element',
|
|
17
|
+
* render() {
|
|
18
|
+
* return html`
|
|
19
|
+
* <div
|
|
20
|
+
* ${onDomCreated((element) => {
|
|
21
|
+
* console.log('created!', element);
|
|
22
|
+
* })}
|
|
23
|
+
* >
|
|
24
|
+
* Some div
|
|
25
|
+
* </div>
|
|
26
|
+
* `;
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const onDomCreated = directive(class extends Directive {
|
|
32
|
+
element;
|
|
8
33
|
constructor(partInfo) {
|
|
9
34
|
super(partInfo);
|
|
10
|
-
Object.defineProperty(this, "element", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value: void 0
|
|
15
|
-
});
|
|
16
35
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
17
36
|
}
|
|
18
37
|
update(partInfo, [callback]) {
|
|
@@ -25,6 +44,7 @@ class extends Directive {
|
|
|
25
44
|
}
|
|
26
45
|
return this.render(callback);
|
|
27
46
|
}
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
48
|
render(callback) {
|
|
29
49
|
return undefined;
|
|
30
50
|
}
|
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
import { MaybePromise } from '@augment-vir/common';
|
|
2
|
-
import { PartInfo } from '../../lit-exports/all-lit-exports';
|
|
2
|
+
import { PartInfo } from '../../lit-exports/all-lit-exports.js';
|
|
3
|
+
/**
|
|
4
|
+
* The callback / listener passed to {@link onDomRendered}. The `element` parameter is a reference to
|
|
5
|
+
* the DOM element that the directive was attached to.
|
|
6
|
+
*
|
|
7
|
+
* @category Internal
|
|
8
|
+
*/
|
|
3
9
|
export type OnDomRenderedCallback = (element: Element) => MaybePromise<void>;
|
|
4
|
-
/**
|
|
5
|
-
|
|
10
|
+
/**
|
|
11
|
+
* A directive that fires its listener each time the element that it's attached to is rendered.
|
|
12
|
+
*
|
|
13
|
+
* @category Directives
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import {html, defineElementNoInputs, onDomRendered} from 'element-vir';
|
|
18
|
+
*
|
|
19
|
+
* const MyElement = defineElementNoInputs({
|
|
20
|
+
* tagName: 'my-element',
|
|
21
|
+
* render() {
|
|
22
|
+
* return html`
|
|
23
|
+
* <div
|
|
24
|
+
* ${onDomRendered((element) => {
|
|
25
|
+
* console.log('rendered!', element);
|
|
26
|
+
* })}
|
|
27
|
+
* >
|
|
28
|
+
* Some div
|
|
29
|
+
* </div>
|
|
30
|
+
* `;
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const onDomRendered: (callback: OnDomRenderedCallback) => import("lit-html/directive.js").DirectiveResult<{
|
|
6
36
|
new (partInfo: PartInfo): {
|
|
7
37
|
update(partInfo: PartInfo, [callback]: [OnDomRenderedCallback]): undefined;
|
|
8
38
|
render(callback: OnDomRenderedCallback): undefined;
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
import { directive, Directive } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { assertIsElementPartInfo } from './directive-helpers';
|
|
1
|
+
import { directive, Directive } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { assertIsElementPartInfo } from './directive-helpers.js';
|
|
3
3
|
const directiveName = 'onDomRendered';
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A directive that fires its listener each time the element that it's attached to is rendered.
|
|
6
|
+
*
|
|
7
|
+
* @category Directives
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {html, defineElementNoInputs, onDomRendered} from 'element-vir';
|
|
12
|
+
*
|
|
13
|
+
* const MyElement = defineElementNoInputs({
|
|
14
|
+
* tagName: 'my-element',
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div
|
|
18
|
+
* ${onDomRendered((element) => {
|
|
19
|
+
* console.log('rendered!', element);
|
|
20
|
+
* })}
|
|
21
|
+
* >
|
|
22
|
+
* Some div
|
|
23
|
+
* </div>
|
|
24
|
+
* `;
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const onDomRendered = directive(class extends Directive {
|
|
8
30
|
constructor(partInfo) {
|
|
9
31
|
super(partInfo);
|
|
10
32
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
@@ -16,6 +38,7 @@ class extends Directive {
|
|
|
16
38
|
window.requestAnimationFrame(() => callback(element));
|
|
17
39
|
return this.render(callback);
|
|
18
40
|
}
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
42
|
render(callback) {
|
|
20
43
|
return undefined;
|
|
21
44
|
}
|
|
@@ -1,8 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { MaybePromise } from '@augment-vir/common';
|
|
2
|
+
import { PartInfo } from '../../lit-exports/all-lit-exports.js';
|
|
3
|
+
/**
|
|
4
|
+
* Callback called by the {@link onResize} directive.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export type OnResizeCallback = (size: Readonly<Pick<ResizeObserverEntry,
|
|
3
9
|
/** Only these two properties are supported in all major modern browsers */
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
'target' | 'contentRect'>>, element: Element) => MaybePromise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* A directive that fires its listener any time the element that it's attached to is resized. This
|
|
13
|
+
* uses the [built-in `ResizeObserver`
|
|
14
|
+
* API](https://developer.mozilla.org/docs/Web/API/ResizeObserver), so it is very efficient.
|
|
15
|
+
*
|
|
16
|
+
* @category Directives
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import {html, defineElementNoInputs, onResize} from 'element-vir';
|
|
21
|
+
*
|
|
22
|
+
* const MyElement = defineElementNoInputs({
|
|
23
|
+
* tagName: 'my-element',
|
|
24
|
+
* render() {
|
|
25
|
+
* return html`
|
|
26
|
+
* <div
|
|
27
|
+
* ${onResize((size, element) => {
|
|
28
|
+
* console.log('resized!', element, size);
|
|
29
|
+
* })}
|
|
30
|
+
* >
|
|
31
|
+
* Some div
|
|
32
|
+
* </div>
|
|
33
|
+
* `;
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const onResize: (callback: OnResizeCallback) => import("lit-html/directive.js").DirectiveResult<{
|
|
6
39
|
new (partInfo: PartInfo): {
|
|
7
40
|
element: Element | undefined;
|
|
8
41
|
readonly resizeObserver: ResizeObserver;
|
|
@@ -1,29 +1,39 @@
|
|
|
1
|
-
import { directive, Directive } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { assertIsElementPartInfo } from './directive-helpers';
|
|
1
|
+
import { directive, Directive } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { assertIsElementPartInfo } from './directive-helpers.js';
|
|
3
3
|
const directiveName = 'onResize';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* A directive that fires its listener any time the element that it's attached to is resized. This
|
|
6
|
+
* uses the [built-in `ResizeObserver`
|
|
7
|
+
* API](https://developer.mozilla.org/docs/Web/API/ResizeObserver), so it is very efficient.
|
|
8
|
+
*
|
|
9
|
+
* @category Directives
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* import {html, defineElementNoInputs, onResize} from 'element-vir';
|
|
14
|
+
*
|
|
15
|
+
* const MyElement = defineElementNoInputs({
|
|
16
|
+
* tagName: 'my-element',
|
|
17
|
+
* render() {
|
|
18
|
+
* return html`
|
|
19
|
+
* <div
|
|
20
|
+
* ${onResize((size, element) => {
|
|
21
|
+
* console.log('resized!', element, size);
|
|
22
|
+
* })}
|
|
23
|
+
* >
|
|
24
|
+
* Some div
|
|
25
|
+
* </div>
|
|
26
|
+
* `;
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const onResize = directive(class extends Directive {
|
|
32
|
+
element;
|
|
33
|
+
resizeObserver = new ResizeObserver((entries) => this.fireCallback(entries));
|
|
34
|
+
callback;
|
|
7
35
|
constructor(partInfo) {
|
|
8
36
|
super(partInfo);
|
|
9
|
-
Object.defineProperty(this, "element", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
writable: true,
|
|
13
|
-
value: void 0
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(this, "resizeObserver", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: new ResizeObserver((entries) => this.fireCallback(entries))
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "callback", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
37
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
28
38
|
}
|
|
29
39
|
fireCallback(entries) {
|
|
@@ -32,7 +42,9 @@ class extends Directive {
|
|
|
32
42
|
console.error(entries);
|
|
33
43
|
throw new Error(`${directiveName} observation triggered but the first entry was empty.`);
|
|
34
44
|
}
|
|
35
|
-
this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect },
|
|
45
|
+
void this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect },
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
47
|
+
this.element);
|
|
36
48
|
}
|
|
37
49
|
update(partInfo, [callback]) {
|
|
38
50
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
@@ -49,6 +61,7 @@ class extends Directive {
|
|
|
49
61
|
}
|
|
50
62
|
return this.render(callback);
|
|
51
63
|
}
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
65
|
render(callback) {
|
|
53
66
|
return undefined;
|
|
54
67
|
}
|
|
@@ -1,5 +1,45 @@
|
|
|
1
|
-
import { AsyncProp } from './async-prop';
|
|
1
|
+
import { AsyncProp } from './async-prop.js';
|
|
2
|
+
/**
|
|
3
|
+
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
4
|
+
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
5
|
+
* parameter if the {@link AsyncProp} errored out, return the `fallback` parameter in all other
|
|
6
|
+
* cases.
|
|
7
|
+
*
|
|
8
|
+
* This is the overload for when `resolutionRender` and `errorRender` are both provided.
|
|
9
|
+
*
|
|
10
|
+
* @category Async
|
|
11
|
+
*/
|
|
2
12
|
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: Pick<AsyncProp<T, any>, 'value'>, fallback: FallbackResult, resolutionRender: (resolved: Awaited<T>) => ResolutionRenderResult, errorRender: (error: Error) => ErrorRenderResult): FallbackResult | ResolutionRenderResult | ErrorRenderResult;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
15
|
+
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
16
|
+
* parameter if the {@link AsyncProp} errored out, return the `fallback` parameter in all other
|
|
17
|
+
* cases.
|
|
18
|
+
*
|
|
19
|
+
* This is the overload for when `resolutionRender` is provided but `errorRender` is not.
|
|
20
|
+
*
|
|
21
|
+
* @category Async
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never>(asyncProp: Pick<AsyncProp<T, any>, 'value'>, fallback: FallbackResult, resolutionRender: (resolved: Awaited<T>) => ResolutionRenderResult, errorRender?: undefined): FallbackResult | ResolutionRenderResult | string;
|
|
24
|
+
/**
|
|
25
|
+
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
26
|
+
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
27
|
+
* parameter if the {@link AsyncProp} errored out, return the `fallback` parameter in all other
|
|
28
|
+
* cases.
|
|
29
|
+
*
|
|
30
|
+
* This is the overload for when `resolutionRender` is not provided but `errorRender` is.
|
|
31
|
+
*
|
|
32
|
+
* @category Async
|
|
33
|
+
*/
|
|
34
|
+
export declare function renderAsync<T, FallbackResult, ErrorRenderResult = never>(asyncProp: Pick<AsyncProp<T, any>, 'value'>, fallback: FallbackResult, resolutionRender: undefined, errorRender: (error: Error) => ErrorRenderResult): FallbackResult | Awaited<T> | ErrorRenderResult;
|
|
35
|
+
/**
|
|
36
|
+
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
37
|
+
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
38
|
+
* parameter if the {@link AsyncProp} errored out, return the `fallback` parameter in all other
|
|
39
|
+
* cases.
|
|
40
|
+
*
|
|
41
|
+
* This is the overload for when neither `resolutionRender` or `errorRender` are provided.
|
|
42
|
+
*
|
|
43
|
+
* @category Async
|
|
44
|
+
*/
|
|
45
|
+
export declare function renderAsync<T, FallbackResult>(asyncProp: Pick<AsyncProp<T, any>, 'value'>, fallback: FallbackResult, resolutionRender?: undefined, errorRender?: undefined): FallbackResult | Awaited<T> | string;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { extractErrorMessage } from '@augment-vir/common';
|
|
3
|
+
/**
|
|
4
|
+
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
5
|
+
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
6
|
+
* parameter if the {@link AsyncProp} errored out, return the `fallback` parameter in all other
|
|
7
|
+
* cases.
|
|
8
|
+
*
|
|
9
|
+
* This is the full function definition and implementation.
|
|
10
|
+
*
|
|
11
|
+
* @category Async
|
|
12
|
+
*/
|
|
3
13
|
export function renderAsync(asyncProp,
|
|
4
14
|
/** This value will be rendered if the async prop has not settled yet. */
|
|
5
15
|
fallback, resolutionRender, errorRender) {
|
|
@@ -10,7 +20,7 @@ fallback, resolutionRender, errorRender) {
|
|
|
10
20
|
: extractErrorMessage(asyncPropValue);
|
|
11
21
|
return errorResult;
|
|
12
22
|
}
|
|
13
|
-
else if (isPromiseLike(asyncPropValue)) {
|
|
23
|
+
else if (check.isPromiseLike(asyncPropValue)) {
|
|
14
24
|
const fallbackResult = fallback;
|
|
15
25
|
return fallbackResult;
|
|
16
26
|
}
|
|
@@ -1 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A directive that, given a condition, chooses between two inputs: `ifTrue` and `ifFalse`. If
|
|
3
|
+
* `ifFalse` is omitted (which is allowed), the false case defaults to `undefined`, which won't get
|
|
4
|
+
* rendered at all inside of an HTML template.
|
|
5
|
+
*
|
|
6
|
+
* @category Directives
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {html, defineElementNoInputs, renderIf} from 'element-vir';
|
|
11
|
+
*
|
|
12
|
+
* const MyElement = defineElementNoInputs({
|
|
13
|
+
* tagName: 'my-element',
|
|
14
|
+
* render() {
|
|
15
|
+
* return html`
|
|
16
|
+
* <div>
|
|
17
|
+
* ${renderIf(
|
|
18
|
+
* Math.random() > 0.5,
|
|
19
|
+
* html`
|
|
20
|
+
* True!
|
|
21
|
+
* `,
|
|
22
|
+
* html`
|
|
23
|
+
* False!
|
|
24
|
+
* `,
|
|
25
|
+
* )}
|
|
26
|
+
* </div>
|
|
27
|
+
* `;
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
1
32
|
export declare function renderIf<TrueCondition = unknown, FalseCondition = undefined>(condition: boolean, ifTrue: TrueCondition, ifFalse?: FalseCondition): TrueCondition | FalseCondition;
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
import { when } from '../../lit-exports/all-lit-exports';
|
|
1
|
+
import { when } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
/**
|
|
3
|
+
* A directive that, given a condition, chooses between two inputs: `ifTrue` and `ifFalse`. If
|
|
4
|
+
* `ifFalse` is omitted (which is allowed), the false case defaults to `undefined`, which won't get
|
|
5
|
+
* rendered at all inside of an HTML template.
|
|
6
|
+
*
|
|
7
|
+
* @category Directives
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {html, defineElementNoInputs, renderIf} from 'element-vir';
|
|
12
|
+
*
|
|
13
|
+
* const MyElement = defineElementNoInputs({
|
|
14
|
+
* tagName: 'my-element',
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div>
|
|
18
|
+
* ${renderIf(
|
|
19
|
+
* Math.random() > 0.5,
|
|
20
|
+
* html`
|
|
21
|
+
* True!
|
|
22
|
+
* `,
|
|
23
|
+
* html`
|
|
24
|
+
* False!
|
|
25
|
+
* `,
|
|
26
|
+
* )}
|
|
27
|
+
* </div>
|
|
28
|
+
* `;
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
2
33
|
export function renderIf(condition, ifTrue, ifFalse) {
|
|
3
34
|
return when(condition, () => ifTrue, () => ifFalse);
|
|
4
35
|
}
|
|
@@ -1,8 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Assigns the given id as a test id attribute to the attached element.
|
|
3
|
+
*
|
|
4
|
+
* @category Test
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import {html, defineElementNoInputs, testId} from 'element-vir';
|
|
9
|
+
*
|
|
10
|
+
* const MyElement = defineElementNoInputs({
|
|
11
|
+
* tagName: 'my-element',
|
|
12
|
+
* render() {
|
|
13
|
+
* return html`
|
|
14
|
+
* <div ${testId('my-test')}>Some div</div>
|
|
15
|
+
* `;
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const testId: (this: void, attributeValue: string) => import("lit-html/directive.js").DirectiveResult<{
|
|
21
|
+
new (partInfo: import("lit-html/directive.js").PartInfo): {
|
|
3
22
|
readonly element: Element;
|
|
4
23
|
render(attributeValue: string): symbol;
|
|
5
24
|
readonly _$isConnected: boolean;
|
|
6
|
-
update(_part: import("lit-html").Part, props: unknown
|
|
25
|
+
update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
|
|
7
26
|
};
|
|
8
|
-
}
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Construct an attribute selector for the given test id.
|
|
30
|
+
*
|
|
31
|
+
* @category Test
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import {html, selectTestId} from 'element-vir';
|
|
36
|
+
* import {testWeb} from '@augment-vir/test';
|
|
37
|
+
* import {assert} from '@augment-vir/assert';
|
|
38
|
+
*
|
|
39
|
+
* const instance = testWeb.render(html`
|
|
40
|
+
* <${MyElement}></${MyElement}>
|
|
41
|
+
* `);
|
|
42
|
+
* assert.instanceOf(instance, MyElement);
|
|
43
|
+
* instance.shadowRoot.querySelector(selectTestId('my-test'));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const testIdSelector: (this: void, attributeValue: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* The test id attribute name.
|
|
49
|
+
*
|
|
50
|
+
* @category Test
|
|
51
|
+
*/
|
|
52
|
+
export declare const testIdAttributeName: string;
|
|
@@ -1,2 +1,47 @@
|
|
|
1
|
-
import { createAttributeDirective } from './create-attribute-directive';
|
|
2
|
-
|
|
1
|
+
import { createAttributeDirective } from './create-attribute-directive.js';
|
|
2
|
+
const { attributeDirective, attributeSelector, attributeName } = createAttributeDirective('data-test-id');
|
|
3
|
+
/**
|
|
4
|
+
* Assigns the given id as a test id attribute to the attached element.
|
|
5
|
+
*
|
|
6
|
+
* @category Test
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import {html, defineElementNoInputs, testId} from 'element-vir';
|
|
11
|
+
*
|
|
12
|
+
* const MyElement = defineElementNoInputs({
|
|
13
|
+
* tagName: 'my-element',
|
|
14
|
+
* render() {
|
|
15
|
+
* return html`
|
|
16
|
+
* <div ${testId('my-test')}>Some div</div>
|
|
17
|
+
* `;
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const testId = attributeDirective;
|
|
23
|
+
/**
|
|
24
|
+
* Construct an attribute selector for the given test id.
|
|
25
|
+
*
|
|
26
|
+
* @category Test
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import {html, selectTestId} from 'element-vir';
|
|
31
|
+
* import {testWeb} from '@augment-vir/test';
|
|
32
|
+
* import {assert} from '@augment-vir/assert';
|
|
33
|
+
*
|
|
34
|
+
* const instance = testWeb.render(html`
|
|
35
|
+
* <${MyElement}></${MyElement}>
|
|
36
|
+
* `);
|
|
37
|
+
* assert.instanceOf(instance, MyElement);
|
|
38
|
+
* instance.shadowRoot.querySelector(selectTestId('my-test'));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const testIdSelector = attributeSelector;
|
|
42
|
+
/**
|
|
43
|
+
* The test id attribute name.
|
|
44
|
+
*
|
|
45
|
+
* @category Test
|
|
46
|
+
*/
|
|
47
|
+
export const testIdAttributeName = attributeName;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
import { DeclarativeElementDefinition } from './declarative-element';
|
|
1
|
+
import { DeclarativeElementDefinition } from './declarative-element.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that the given input is a declarative element definition.
|
|
4
|
+
*
|
|
5
|
+
* @category Util
|
|
6
|
+
* @see
|
|
7
|
+
* - {@link isDeclarativeElementDefinition}
|
|
8
|
+
*/
|
|
2
9
|
export declare function assertDeclarativeElementDefinition(input: unknown, failMessage?: string | undefined): asserts input is DeclarativeElementDefinition;
|
|
10
|
+
/**
|
|
11
|
+
* Checks that the given input is a declarative element definition.
|
|
12
|
+
*
|
|
13
|
+
* @category Util
|
|
14
|
+
* @see
|
|
15
|
+
* - {@link assertDeclarativeElementDefinition}
|
|
16
|
+
*/
|
|
3
17
|
export declare function isDeclarativeElementDefinition(input: unknown): input is DeclarativeElementDefinition;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AssertionError, check } from '@augment-vir/assert';
|
|
2
|
+
import { getObjectTypedKeys, wrapInTry } from '@augment-vir/common';
|
|
3
3
|
const expectedStaticProperties = getObjectTypedKeys({
|
|
4
4
|
assign: '',
|
|
5
5
|
assignedInputs: '',
|
|
@@ -9,8 +9,7 @@ const expectedStaticProperties = getObjectTypedKeys({
|
|
|
9
9
|
hostClasses: '',
|
|
10
10
|
init: '',
|
|
11
11
|
inputsType: '',
|
|
12
|
-
|
|
13
|
-
renderCallback: '',
|
|
12
|
+
render: '',
|
|
14
13
|
slotNames: '',
|
|
15
14
|
stateInitStatic: '',
|
|
16
15
|
stateType: '',
|
|
@@ -18,26 +17,30 @@ const expectedStaticProperties = getObjectTypedKeys({
|
|
|
18
17
|
tagName: '',
|
|
19
18
|
updateStateType: '',
|
|
20
19
|
});
|
|
20
|
+
/**
|
|
21
|
+
* Asserts that the given input is a declarative element definition.
|
|
22
|
+
*
|
|
23
|
+
* @category Util
|
|
24
|
+
* @see
|
|
25
|
+
* - {@link isDeclarativeElementDefinition}
|
|
26
|
+
*/
|
|
21
27
|
export function assertDeclarativeElementDefinition(input, failMessage) {
|
|
22
|
-
if (!
|
|
23
|
-
throw new AssertionError(
|
|
24
|
-
'input is not an element constructor',
|
|
25
|
-
failMessage,
|
|
26
|
-
]
|
|
27
|
-
.filter(isTruthy)
|
|
28
|
-
.join(': '));
|
|
28
|
+
if (!check.isFunction(input)) {
|
|
29
|
+
throw new AssertionError('Input is not a declarative element constructor', failMessage);
|
|
29
30
|
}
|
|
30
31
|
expectedStaticProperties.forEach((expectedProperty) => {
|
|
31
|
-
if (!
|
|
32
|
-
throw new AssertionError(
|
|
33
|
-
`missing prop '${expectedProperty}'`,
|
|
34
|
-
failMessage,
|
|
35
|
-
]
|
|
36
|
-
.filter(isTruthy)
|
|
37
|
-
.join(': '));
|
|
32
|
+
if (!check.hasKey(input, expectedProperty)) {
|
|
33
|
+
throw new AssertionError(`missing prop '${expectedProperty}'`, failMessage);
|
|
38
34
|
}
|
|
39
35
|
});
|
|
40
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Checks that the given input is a declarative element definition.
|
|
39
|
+
*
|
|
40
|
+
* @category Util
|
|
41
|
+
* @see
|
|
42
|
+
* - {@link assertDeclarativeElementDefinition}
|
|
43
|
+
*/
|
|
41
44
|
export function isDeclarativeElementDefinition(input) {
|
|
42
45
|
return wrapInTry(() => {
|
|
43
46
|
assertDeclarativeElementDefinition(input);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { DeclarativeElement } from './declarative-element';
|
|
1
|
+
import { DeclarativeElement } from './declarative-element.js';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the input is an instance of a DeclarativeElement, the super class of all custom
|
|
4
4
|
* elements defined with element-vir.
|
|
5
|
+
*
|
|
6
|
+
* @category Util
|
|
5
7
|
*/
|
|
6
8
|
export declare function isDeclarativeElement(input: unknown): input is DeclarativeElement;
|
|
7
9
|
/**
|
|
8
10
|
* Checks if the input is an instance of a DeclarativeElement, the super class of all custom
|
|
9
11
|
* elements defined with element-vir.
|
|
12
|
+
*
|
|
13
|
+
* @category Util
|
|
10
14
|
*/
|
|
11
15
|
export declare function assertIsDeclarativeElement(input: unknown): asserts input is DeclarativeElement;
|