element-vir 26.12.0 → 26.12.1
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/dist/declarative-element/custom-tag-name.js +1 -0
- package/dist/declarative-element/declarative-element-init.d.ts +56 -0
- package/dist/declarative-element/declarative-element-init.js +1 -0
- package/dist/declarative-element/declarative-element.d.ts +114 -0
- package/dist/declarative-element/declarative-element.js +36 -0
- package/dist/declarative-element/define-element.d.ts +41 -0
- package/dist/declarative-element/define-element.js +248 -0
- package/{src/declarative-element/definition-options.ts → dist/declarative-element/definition-options.d.ts} +2 -7
- package/dist/declarative-element/definition-options.js +9 -0
- package/dist/declarative-element/directives/assign.directive.d.ts +24 -0
- package/dist/declarative-element/directives/assign.directive.js +34 -0
- package/dist/declarative-element/directives/async-prop.d.ts +61 -0
- package/{src/declarative-element/directives/async-prop.ts → dist/declarative-element/directives/async-prop.js} +8 -42
- package/dist/declarative-element/directives/attributes.directive.d.ts +30 -0
- package/dist/declarative-element/directives/attributes.directive.js +35 -0
- package/dist/declarative-element/directives/create-attribute-directive.d.ts +28 -0
- package/dist/declarative-element/directives/create-attribute-directive.js +41 -0
- package/dist/declarative-element/directives/directive-helpers.d.ts +27 -0
- package/dist/declarative-element/directives/directive-helpers.js +37 -0
- package/dist/declarative-element/directives/listen-to-activate.d.ts +15 -0
- package/{src/declarative-element/directives/listen-to-activate.ts → dist/declarative-element/directives/listen-to-activate.js} +3 -8
- package/dist/declarative-element/directives/listen.directive.d.ts +92 -0
- package/dist/declarative-element/directives/listen.directive.js +48 -0
- package/dist/declarative-element/directives/mutate.directive.d.ts +38 -0
- package/dist/declarative-element/directives/mutate.directive.js +45 -0
- package/dist/declarative-element/directives/on-dom-created.directive.d.ts +44 -0
- package/dist/declarative-element/directives/on-dom-created.directive.js +51 -0
- package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +41 -0
- package/dist/declarative-element/directives/on-dom-rendered.directive.js +45 -0
- package/dist/declarative-element/directives/on-intersect.directive.d.ts +64 -0
- package/dist/declarative-element/directives/on-intersect.directive.js +89 -0
- package/dist/declarative-element/directives/on-resize.directive.d.ts +74 -0
- package/dist/declarative-element/directives/on-resize.directive.js +106 -0
- package/dist/declarative-element/directives/render-async.directive.d.ts +45 -0
- package/dist/declarative-element/directives/render-async.directive.js +33 -0
- package/dist/declarative-element/directives/render-if.directive.d.ts +32 -0
- package/{src/declarative-element/directives/render-if.directive.ts → dist/declarative-element/directives/render-if.directive.js} +3 -12
- package/dist/declarative-element/directives/test-id.directive.d.ts +52 -0
- package/{src/declarative-element/directives/test-id.directive.ts → dist/declarative-element/directives/test-id.directive.js} +2 -7
- package/dist/declarative-element/has-declarative-element-parent.d.ts +1 -0
- package/{src/declarative-element/has-declarative-element-parent.ts → dist/declarative-element/has-declarative-element-parent.js} +4 -7
- package/dist/declarative-element/is-declarative-element-definition.d.ts +17 -0
- package/{src/declarative-element/is-declarative-element-definition.ts → dist/declarative-element/is-declarative-element-definition.js} +11 -28
- package/dist/declarative-element/is-declarative-element.d.ts +15 -0
- package/{src/declarative-element/is-declarative-element.ts → dist/declarative-element/is-declarative-element.js} +5 -11
- package/dist/declarative-element/properties/assign-inputs.d.ts +1 -0
- package/dist/declarative-element/properties/assign-inputs.js +25 -0
- package/dist/declarative-element/properties/css-vars.d.ts +16 -0
- package/dist/declarative-element/properties/css-vars.js +1 -0
- package/dist/declarative-element/properties/element-events.d.ts +65 -0
- package/dist/declarative-element/properties/element-events.js +62 -0
- package/dist/declarative-element/properties/element-properties.js +1 -0
- package/dist/declarative-element/properties/host-classes.d.ts +36 -0
- package/dist/declarative-element/properties/host-classes.js +16 -0
- package/dist/declarative-element/properties/property-proxy.d.ts +22 -0
- package/{src/declarative-element/properties/property-proxy.ts → dist/declarative-element/properties/property-proxy.js} +21 -58
- package/dist/declarative-element/properties/string-names.d.ts +28 -0
- package/dist/declarative-element/properties/string-names.js +40 -0
- package/dist/declarative-element/properties/styles.d.ts +51 -0
- package/dist/declarative-element/properties/styles.js +41 -0
- package/dist/declarative-element/properties/tag-name.js +1 -0
- package/dist/declarative-element/render-callback.d.ts +56 -0
- package/dist/declarative-element/render-callback.js +27 -0
- package/dist/declarative-element/wrap-define-element.d.ts +36 -0
- package/dist/declarative-element/wrap-define-element.js +25 -0
- package/{src/index.ts → dist/index.d.ts} +0 -1
- package/dist/index.js +43 -0
- package/dist/lit-exports/all-lit-exports.js +2 -0
- package/{src/lit-exports/base-lit-exports.ts → dist/lit-exports/base-lit-exports.d.ts} +2 -10
- package/dist/lit-exports/base-lit-exports.js +24 -0
- package/{src/lit-exports/lit-repeat-fix.ts → dist/lit-exports/lit-repeat-fix.d.ts} +16 -45
- package/dist/lit-exports/lit-repeat-fix.js +37 -0
- package/dist/readme-examples/my-app.element.d.ts +1 -0
- package/{src/readme-examples/my-app.element.ts → dist/readme-examples/my-app.element.js} +4 -5
- 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/{src/readme-examples/my-custom-define.ts → dist/readme-examples/my-custom-define.js} +4 -9
- package/dist/readme-examples/my-simple.element.d.ts +1 -0
- package/{src/readme-examples/my-simple.element.ts → dist/readme-examples/my-simple.element.js} +3 -4
- package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
- package/dist/readme-examples/my-with-assignment.element.js +15 -0
- package/dist/readme-examples/my-with-async-prop.element.d.ts +10 -0
- package/{src/readme-examples/my-with-async-prop.element.ts → dist/readme-examples/my-with-async-prop.element.js} +16 -24
- package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
- package/{src/readme-examples/my-with-cleanup-callback.element.ts → dist/readme-examples/my-with-cleanup-callback.element.js} +4 -5
- package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
- package/{src/readme-examples/my-with-css-vars.element.ts → dist/readme-examples/my-with-css-vars.element.js} +4 -5
- package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
- package/dist/readme-examples/my-with-custom-events.element.js +22 -0
- package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
- package/{src/readme-examples/my-with-event-listening.element.ts → dist/readme-examples/my-with-event-listening.element.js} +9 -10
- package/dist/readme-examples/my-with-events.element.d.ts +4 -0
- package/dist/readme-examples/my-with-events.element.js +20 -0
- package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
- package/{src/readme-examples/my-with-host-class-definition.element.ts → dist/readme-examples/my-with-host-class-definition.element.js} +6 -7
- package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
- package/{src/readme-examples/my-with-host-class-usage.element.ts → dist/readme-examples/my-with-host-class-usage.element.js} +4 -5
- 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/{src/readme-examples/my-with-on-dom-created.element.ts → dist/readme-examples/my-with-on-dom-created.element.js} +6 -7
- package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
- package/dist/readme-examples/my-with-on-resize.element.js +18 -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/{src/readme-examples/my-with-styles-and-interpolated-selector.element.ts → dist/readme-examples/my-with-styles-and-interpolated-selector.element.js} +5 -6
- package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
- package/{src/readme-examples/my-with-styles.element.ts → dist/readme-examples/my-with-styles.element.js} +4 -5
- package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
- package/{src/readme-examples/my-with-update-state.element.ts → dist/readme-examples/my-with-update-state.element.js} +7 -8
- 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 +14 -0
- package/{src/require-declarative-element.ts → dist/require-declarative-element.js} +0 -1
- package/{src/template-transforms/minimal-element-definition.ts → dist/template-transforms/minimal-element-definition.d.ts} +7 -19
- package/dist/template-transforms/minimal-element-definition.js +19 -0
- package/dist/template-transforms/nested-mapped-templates.d.ts +6 -0
- package/dist/template-transforms/nested-mapped-templates.js +96 -0
- package/{src/template-transforms/template-transform-type.ts → dist/template-transforms/template-transform-type.d.ts} +1 -3
- package/dist/template-transforms/template-transform-type.js +1 -0
- package/dist/template-transforms/transform-template.d.ts +14 -0
- package/{src/template-transforms/transform-template.ts → dist/template-transforms/transform-template.js} +22 -70
- package/dist/template-transforms/vir-css/css-transform.d.ts +4 -0
- package/dist/template-transforms/vir-css/css-transform.js +15 -0
- package/dist/template-transforms/vir-css/vir-css.d.ts +12 -0
- package/dist/template-transforms/vir-css/vir-css.js +21 -0
- package/dist/template-transforms/vir-html/html-interpolation.d.ts +42 -0
- package/dist/template-transforms/vir-html/html-interpolation.js +1 -0
- package/dist/template-transforms/vir-html/html-transform.d.ts +5 -0
- package/dist/template-transforms/vir-html/html-transform.js +96 -0
- package/dist/template-transforms/vir-html/tag-name-keys.d.ts +7 -0
- package/{src/template-transforms/vir-html/tag-name-keys.ts → dist/template-transforms/vir-html/tag-name-keys.js} +1 -1
- package/dist/template-transforms/vir-html/vir-html.d.ts +11 -0
- package/{src/template-transforms/vir-html/vir-html.ts → dist/template-transforms/vir-html/vir-html.js} +5 -13
- package/dist/typed-event/typed-event.d.ts +55 -0
- package/dist/typed-event/typed-event.js +50 -0
- package/dist/util/array.d.ts +5 -0
- package/{src/util/array.ts → dist/util/array.js} +5 -18
- package/{src/util/increment.ts → dist/util/increment.d.ts} +5 -24
- package/dist/util/increment.js +1 -0
- package/dist/util/lit-template.d.ts +9 -0
- package/{src/util/lit-template.ts → dist/util/lit-template.js} +10 -30
- package/dist/util/map-async-value.d.ts +7 -0
- package/{src/util/map-async-value.ts → dist/util/map-async-value.js} +10 -12
- package/dist/util/type.js +1 -0
- package/package.json +4 -4
- package/src/declarative-element/declarative-element-init.ts +0 -115
- package/src/declarative-element/declarative-element.ts +0 -372
- package/src/declarative-element/define-element.ts +0 -515
- package/src/declarative-element/directives/assign.directive.ts +0 -89
- package/src/declarative-element/directives/attributes.directive.ts +0 -63
- package/src/declarative-element/directives/create-attribute-directive.ts +0 -47
- package/src/declarative-element/directives/directive-helpers.ts +0 -67
- package/src/declarative-element/directives/listen.directive.ts +0 -206
- package/src/declarative-element/directives/mutate.directive.ts +0 -78
- package/src/declarative-element/directives/on-dom-created.directive.ts +0 -68
- package/src/declarative-element/directives/on-dom-rendered.directive.ts +0 -61
- package/src/declarative-element/directives/on-intersect.directive.ts +0 -139
- package/src/declarative-element/directives/on-resize.directive.ts +0 -142
- package/src/declarative-element/directives/render-async.directive.ts +0 -111
- package/src/declarative-element/properties/assign-inputs.ts +0 -30
- package/src/declarative-element/properties/css-vars.ts +0 -24
- package/src/declarative-element/properties/element-events.ts +0 -161
- package/src/declarative-element/properties/host-classes.ts +0 -63
- package/src/declarative-element/properties/string-names.ts +0 -83
- package/src/declarative-element/properties/styles.ts +0 -112
- package/src/declarative-element/render-callback.ts +0 -196
- package/src/declarative-element/wrap-define-element.ts +0 -127
- package/src/readme-examples/my-custom-action.event.ts +0 -3
- package/src/readme-examples/my-with-assignment.element.ts +0 -16
- package/src/readme-examples/my-with-custom-events.element.ts +0 -23
- package/src/readme-examples/my-with-events.element.ts +0 -23
- package/src/readme-examples/my-with-inputs.element.ts +0 -13
- package/src/readme-examples/my-with-on-resize.element.ts +0 -19
- package/src/readme-examples/my-with-render-if.element.ts +0 -15
- package/src/readme-examples/require-declarative-element.ts +0 -3
- package/src/template-transforms/nested-mapped-templates.ts +0 -157
- package/src/template-transforms/vir-css/css-transform.ts +0 -30
- package/src/template-transforms/vir-css/vir-css.ts +0 -30
- package/src/template-transforms/vir-html/html-interpolation.ts +0 -103
- package/src/template-transforms/vir-html/html-transform.ts +0 -149
- package/src/typed-event/typed-event.ts +0 -90
- /package/{src/declarative-element/custom-tag-name.ts → dist/declarative-element/custom-tag-name.d.ts} +0 -0
- /package/{src/declarative-element/properties/element-properties.ts → dist/declarative-element/properties/element-properties.d.ts} +0 -0
- /package/{src/declarative-element/properties/tag-name.ts → dist/declarative-element/properties/tag-name.d.ts} +0 -0
- /package/{src/lit-exports/all-lit-exports.ts → dist/lit-exports/all-lit-exports.d.ts} +0 -0
- /package/{src/util/type.ts → dist/util/type.d.ts} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html } from '../index.js';
|
|
3
|
+
import { MyWithInputs } from './my-with-inputs.element.js';
|
|
4
|
+
export const MyWithAssignment = defineElement()({
|
|
5
|
+
tagName: 'my-with-assignment',
|
|
6
|
+
render() {
|
|
7
|
+
return html `
|
|
8
|
+
<h1>My App</h1>
|
|
9
|
+
<${MyWithInputs.assign({
|
|
10
|
+
email: 'user@example.com',
|
|
11
|
+
username: 'user',
|
|
12
|
+
})}></${MyWithInputs}>
|
|
13
|
+
`;
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type EndpointData = number[];
|
|
2
|
+
export declare const MyWithAsyncProp: import("../index.js").DeclarativeElementDefinition<"my-with-async-prop", {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
}, {
|
|
5
|
+
data: import("../index.js").AsyncProp<EndpointData, {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
}>;
|
|
8
|
+
hi: string;
|
|
9
|
+
}, {}, "my-with-async-prop-", "my-with-async-prop-", readonly [], readonly []>;
|
|
10
|
+
export {};
|
|
@@ -1,54 +1,46 @@
|
|
|
1
|
-
import {asyncProp, defineElement, html, listen, renderAsync} from '../index.js';
|
|
2
|
-
|
|
3
|
-
type EndpointData = number[];
|
|
4
|
-
|
|
5
|
-
async function loadSomething(endpoint: string): Promise<EndpointData> {
|
|
1
|
+
import { asyncProp, defineElement, html, listen, renderAsync } from '../index.js';
|
|
2
|
+
async function loadSomething(endpoint) {
|
|
6
3
|
// load something from the network
|
|
7
|
-
const data = await (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
endpoint,
|
|
13
|
-
].join('/'),
|
|
14
|
-
)
|
|
15
|
-
).json();
|
|
4
|
+
const data = await (await fetch([
|
|
5
|
+
'',
|
|
6
|
+
'api',
|
|
7
|
+
endpoint,
|
|
8
|
+
].join('/'))).json();
|
|
16
9
|
return data;
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
export const MyWithAsyncProp = defineElement<{endpoint: string}>()({
|
|
11
|
+
export const MyWithAsyncProp = defineElement()({
|
|
20
12
|
tagName: 'my-with-async-prop',
|
|
21
13
|
state() {
|
|
22
14
|
return {
|
|
23
15
|
data: asyncProp({
|
|
24
|
-
async updateCallback({
|
|
16
|
+
async updateCallback({ endpoint }) {
|
|
25
17
|
return loadSomething(endpoint);
|
|
26
18
|
},
|
|
27
19
|
}),
|
|
28
20
|
hi: '',
|
|
29
21
|
};
|
|
30
22
|
},
|
|
31
|
-
render({inputs, state}) {
|
|
23
|
+
render({ inputs, state }) {
|
|
32
24
|
/**
|
|
33
25
|
* This causes the a promise which automatically updates the state.data prop once the
|
|
34
26
|
* promise resolves. It only creates a new promise if the first input, the trigger, value
|
|
35
27
|
* changes from previous calls.
|
|
36
28
|
*/
|
|
37
29
|
state.data.update(inputs);
|
|
38
|
-
return html`
|
|
30
|
+
return html `
|
|
39
31
|
Here's the data:
|
|
40
32
|
<br />
|
|
41
33
|
${renderAsync(state.data, 'Loading...', (loadedData) => {
|
|
42
|
-
|
|
34
|
+
return html `
|
|
43
35
|
Got the data: ${loadedData}
|
|
44
36
|
`;
|
|
45
|
-
|
|
37
|
+
})}
|
|
46
38
|
<br />
|
|
47
39
|
<button
|
|
48
40
|
${listen('click', () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
/** You can force asyncProp to update by calling forceUpdate. */
|
|
42
|
+
state.data.forceUpdate(inputs);
|
|
43
|
+
})}
|
|
52
44
|
>
|
|
53
45
|
Refresh
|
|
54
46
|
</button>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {html} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html } from '../index.js';
|
|
4
3
|
export const MyWithAssignmentCleanupCallback = defineElement()({
|
|
5
4
|
tagName: 'my-with-cleanup-callback',
|
|
6
5
|
state() {
|
|
@@ -9,11 +8,11 @@ export const MyWithAssignmentCleanupCallback = defineElement()({
|
|
|
9
8
|
};
|
|
10
9
|
},
|
|
11
10
|
render() {
|
|
12
|
-
return html`
|
|
11
|
+
return html `
|
|
13
12
|
<h1>My App</h1>
|
|
14
13
|
`;
|
|
15
14
|
},
|
|
16
|
-
cleanup({state}) {
|
|
15
|
+
cleanup({ state }) {
|
|
17
16
|
window.clearInterval(state.intervalId);
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithCssVars: import("element-vir").DeclarativeElementDefinition<"my-with-css-vars", {}, {}, {}, "my-with-css-vars-", "my-with-css-vars-my-var", readonly [], readonly []>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {css, html} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { css, html } from '../index.js';
|
|
4
3
|
export const MyWithCssVars = defineElement()({
|
|
5
4
|
tagName: 'my-with-css-vars',
|
|
6
5
|
cssVars: {
|
|
7
6
|
/** The value assigned here ('blue') becomes the fallback value for this CSS var. */
|
|
8
7
|
'my-with-css-vars-my-var': 'blue',
|
|
9
8
|
},
|
|
10
|
-
styles: ({cssVars}) => css`
|
|
9
|
+
styles: ({ cssVars }) => css `
|
|
11
10
|
:host {
|
|
12
11
|
/*
|
|
13
12
|
Set CSS vars (or reference the name directly) via the ".name" property
|
|
@@ -21,6 +20,6 @@ export const MyWithCssVars = defineElement()({
|
|
|
21
20
|
}
|
|
22
21
|
`,
|
|
23
22
|
render() {
|
|
24
|
-
return html``;
|
|
23
|
+
return html ``;
|
|
25
24
|
},
|
|
26
25
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithCustomEvents: import("element-vir").DeclarativeElementDefinition<"my-with-custom-events", {}, {}, {}, "my-with-custom-events-", "my-with-custom-events-", readonly [], readonly []>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { randomInteger } from '@augment-vir/common';
|
|
2
|
+
import { defineElement } from 'element-vir';
|
|
3
|
+
import { html, listen } from '../index.js';
|
|
4
|
+
import { MyCustomActionEvent } from './my-custom-action.event.js';
|
|
5
|
+
export const MyWithCustomEvents = defineElement()({
|
|
6
|
+
tagName: 'my-with-custom-events',
|
|
7
|
+
render({ dispatch }) {
|
|
8
|
+
return html `
|
|
9
|
+
<div
|
|
10
|
+
${listen(MyCustomActionEvent, (event) => {
|
|
11
|
+
console.info(`Got a number! ${event.detail}`);
|
|
12
|
+
})}
|
|
13
|
+
>
|
|
14
|
+
<div
|
|
15
|
+
${listen('click', () => {
|
|
16
|
+
dispatch(new MyCustomActionEvent(randomInteger({ min: 0, max: 1_000_000 })));
|
|
17
|
+
})}
|
|
18
|
+
></div>
|
|
19
|
+
</div>
|
|
20
|
+
`;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {html, listen} from '../index.js';
|
|
3
|
-
import {MyWithEvents} from './my-with-events.element.js';
|
|
4
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html, listen } from '../index.js';
|
|
3
|
+
import { MyWithEvents } from './my-with-events.element.js';
|
|
5
4
|
export const MyWithEventListening = defineElement()({
|
|
6
5
|
tagName: 'my-with-event-listening',
|
|
7
6
|
state() {
|
|
@@ -9,16 +8,16 @@ export const MyWithEventListening = defineElement()({
|
|
|
9
8
|
myNumber: -1,
|
|
10
9
|
};
|
|
11
10
|
},
|
|
12
|
-
render({state, updateState}) {
|
|
13
|
-
return html`
|
|
11
|
+
render({ state, updateState }) {
|
|
12
|
+
return html `
|
|
14
13
|
<h1>My App</h1>
|
|
15
14
|
<${MyWithEvents}
|
|
16
15
|
${listen(MyWithEvents.events.logoutClick, () => {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
console.info('logout triggered');
|
|
17
|
+
})}
|
|
19
18
|
${listen(MyWithEvents.events.randomNumber, (event) => {
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
updateState({ myNumber: event.detail });
|
|
20
|
+
})}
|
|
22
21
|
></${MyWithEvents}>
|
|
23
22
|
<span>${state.myNumber}</span>
|
|
24
23
|
`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const MyWithEvents: import("element-vir").DeclarativeElementDefinition<"my-with-events", {}, {}, {
|
|
2
|
+
logoutClick: import("element-vir").DefineEvent<void>;
|
|
3
|
+
randomNumber: import("element-vir").DefineEvent<number>;
|
|
4
|
+
}, "my-with-events-", "my-with-events-", readonly [], readonly []>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { randomInteger } from '@augment-vir/common';
|
|
2
|
+
import { defineElement } from 'element-vir';
|
|
3
|
+
import { defineElementEvent, html, listen } from '../index.js';
|
|
4
|
+
export const MyWithEvents = defineElement()({
|
|
5
|
+
tagName: 'my-with-events',
|
|
6
|
+
events: {
|
|
7
|
+
logoutClick: defineElementEvent(),
|
|
8
|
+
randomNumber: defineElementEvent(),
|
|
9
|
+
},
|
|
10
|
+
render({ dispatch, events }) {
|
|
11
|
+
return html `
|
|
12
|
+
<button ${listen('click', () => dispatch(new events.logoutClick()))}>log out</button>
|
|
13
|
+
<button
|
|
14
|
+
${listen('click', () => dispatch(new events.randomNumber(randomInteger({ min: 0, max: 1_000_000 }))))}
|
|
15
|
+
>
|
|
16
|
+
generate random number
|
|
17
|
+
</button>
|
|
18
|
+
`;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const MyWithHostClassDefinition: import("element-vir").DeclarativeElementDefinition<"my-with-host-class-definition", {}, {
|
|
2
|
+
myProp: string;
|
|
3
|
+
}, {}, "my-with-host-class-definition-a" | "my-with-host-class-definition-automatic", "my-with-host-class-definition-", readonly [], readonly []>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {css, html} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { css, html } from '../index.js';
|
|
4
3
|
export const MyWithHostClassDefinition = defineElement()({
|
|
5
4
|
tagName: 'my-with-host-class-definition',
|
|
6
5
|
state() {
|
|
@@ -18,7 +17,7 @@ export const MyWithHostClassDefinition = defineElement()({
|
|
|
18
17
|
* This host class will be automatically applied if the given callback is evaluated to true
|
|
19
18
|
* after a call to render.
|
|
20
19
|
*/
|
|
21
|
-
'my-with-host-class-definition-automatic': ({state}) => {
|
|
20
|
+
'my-with-host-class-definition-automatic': ({ state }) => {
|
|
22
21
|
return state.myProp === 'foo';
|
|
23
22
|
},
|
|
24
23
|
},
|
|
@@ -26,7 +25,7 @@ export const MyWithHostClassDefinition = defineElement()({
|
|
|
26
25
|
* Apply styles to the host classes by using a callback for "styles". The callback's argument
|
|
27
26
|
* contains the host classes defined above in the "hostClasses" property.
|
|
28
27
|
*/
|
|
29
|
-
styles: ({hostClasses}) => css`
|
|
28
|
+
styles: ({ hostClasses }) => css `
|
|
30
29
|
${hostClasses['my-with-host-class-definition-automatic'].selector} {
|
|
31
30
|
color: blue;
|
|
32
31
|
}
|
|
@@ -35,8 +34,8 @@ export const MyWithHostClassDefinition = defineElement()({
|
|
|
35
34
|
color: red;
|
|
36
35
|
}
|
|
37
36
|
`,
|
|
38
|
-
render({state}) {
|
|
39
|
-
return html`
|
|
37
|
+
render({ state }) {
|
|
38
|
+
return html `
|
|
40
39
|
${state.myProp}
|
|
41
40
|
`;
|
|
42
41
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithHostClassUsage: import("element-vir").DeclarativeElementDefinition<"my-with-host-class-usage", {}, {}, {}, "my-with-host-class-usage-", "my-with-host-class-usage-", readonly [], readonly []>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {html} from '../index.js';
|
|
3
|
-
import {MyWithHostClassDefinition} from './my-with-host-class-definition.element.js';
|
|
4
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html } from '../index.js';
|
|
3
|
+
import { MyWithHostClassDefinition } from './my-with-host-class-definition.element.js';
|
|
5
4
|
export const MyWithHostClassUsage = defineElement()({
|
|
6
5
|
tagName: 'my-with-host-class-usage',
|
|
7
6
|
render() {
|
|
8
|
-
return html`
|
|
7
|
+
return html `
|
|
9
8
|
<${MyWithHostClassDefinition}
|
|
10
9
|
class=${MyWithHostClassDefinition.hostClasses['my-with-host-class-definition-a']}
|
|
11
10
|
></${MyWithHostClassDefinition}>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithOnDomCreated: import("element-vir").DeclarativeElementDefinition<"my-with-on-dom-created", {}, {}, {}, "my-with-on-dom-created-", "my-with-on-dom-created-", readonly [], readonly []>;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {html, onDomCreated} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html, onDomCreated } from '../index.js';
|
|
4
3
|
export const MyWithOnDomCreated = defineElement()({
|
|
5
4
|
tagName: 'my-with-on-dom-created',
|
|
6
5
|
render() {
|
|
7
|
-
return html`
|
|
6
|
+
return html `
|
|
8
7
|
<span
|
|
9
8
|
${onDomCreated((element) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// logs a span element
|
|
10
|
+
console.info(element);
|
|
11
|
+
})}
|
|
13
12
|
>
|
|
14
13
|
Hello there!
|
|
15
14
|
</span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithOnResize: import("element-vir").DeclarativeElementDefinition<"my-with-on-resize", {}, {}, {}, "my-with-on-resize-", "my-with-on-resize-", readonly [], readonly []>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html, onResize } from '../index.js';
|
|
3
|
+
export const MyWithOnResize = defineElement()({
|
|
4
|
+
tagName: 'my-with-on-resize',
|
|
5
|
+
render() {
|
|
6
|
+
return html `
|
|
7
|
+
<span
|
|
8
|
+
${onResize((entry) => {
|
|
9
|
+
// this will track resizing of this span
|
|
10
|
+
// the entry parameter contains target and contentRect properties
|
|
11
|
+
console.info(entry);
|
|
12
|
+
})}
|
|
13
|
+
>
|
|
14
|
+
Hello there!
|
|
15
|
+
</span>
|
|
16
|
+
`;
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineElement, html, renderIf } from '../index.js';
|
|
2
|
+
export const MyWithRenderIf = defineElement()({
|
|
3
|
+
tagName: 'my-with-render-if',
|
|
4
|
+
render({ inputs }) {
|
|
5
|
+
return html `
|
|
6
|
+
${renderIf(inputs.shouldRender, html `
|
|
7
|
+
I'm conditionally rendered!
|
|
8
|
+
`)}
|
|
9
|
+
`;
|
|
10
|
+
},
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithStylesAndInterpolatedSelector: import("element-vir").DeclarativeElementDefinition<"my-with-styles-and-interpolated-selector", {}, {}, {}, "my-with-styles-and-interpolated-selector-", "my-with-styles-and-interpolated-selector-", readonly [], readonly []>;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {css, html} from '../index.js';
|
|
3
|
-
import {MySimple} from './my-simple.element.js';
|
|
4
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { css, html } from '../index.js';
|
|
3
|
+
import { MySimple } from './my-simple.element.js';
|
|
5
4
|
export const MyWithStylesAndInterpolatedSelector = defineElement()({
|
|
6
5
|
tagName: 'my-with-styles-and-interpolated-selector',
|
|
7
|
-
styles: css`
|
|
6
|
+
styles: css `
|
|
8
7
|
${MySimple} {
|
|
9
8
|
background-color: blue;
|
|
10
9
|
}
|
|
11
10
|
`,
|
|
12
11
|
render() {
|
|
13
|
-
return html`
|
|
12
|
+
return html `
|
|
14
13
|
<${MySimple}></${MySimple}>
|
|
15
14
|
`;
|
|
16
15
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MyWithStyles: import("element-vir").DeclarativeElementDefinition<"my-with-styles", {}, {}, {}, "my-with-styles-", "my-with-styles-", readonly [], readonly []>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {css, html} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { css, html } from '../index.js';
|
|
4
3
|
export const MyWithStyles = defineElement()({
|
|
5
4
|
tagName: 'my-with-styles',
|
|
6
|
-
styles: css`
|
|
5
|
+
styles: css `
|
|
7
6
|
:host {
|
|
8
7
|
display: flex;
|
|
9
8
|
flex-direction: column;
|
|
@@ -15,7 +14,7 @@ export const MyWithStyles = defineElement()({
|
|
|
15
14
|
}
|
|
16
15
|
`,
|
|
17
16
|
render() {
|
|
18
|
-
return html`
|
|
17
|
+
return html `
|
|
19
18
|
<span>Hello there!</span>
|
|
20
19
|
<span>How are you doing?</span>
|
|
21
20
|
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const MyWithUpdateState: import("element-vir").DeclarativeElementDefinition<"my-with-update-state", {}, {
|
|
2
|
+
username: string;
|
|
3
|
+
/**
|
|
4
|
+
* Use "as" to create state properties that can be types other than the initial value's
|
|
5
|
+
* type. This is particularly useful when, as below, the initial value is undefined.
|
|
6
|
+
*/
|
|
7
|
+
email: string | undefined;
|
|
8
|
+
}, {}, "my-with-update-state-", "my-with-update-state-", readonly [], readonly []>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {defineElement} from 'element-vir';
|
|
2
|
-
import {html, listen} from '../index.js';
|
|
3
|
-
|
|
1
|
+
import { defineElement } from 'element-vir';
|
|
2
|
+
import { html, listen } from '../index.js';
|
|
4
3
|
export const MyWithUpdateState = defineElement()({
|
|
5
4
|
tagName: 'my-with-update-state',
|
|
6
5
|
state() {
|
|
@@ -10,15 +9,15 @@ export const MyWithUpdateState = defineElement()({
|
|
|
10
9
|
* Use "as" to create state properties that can be types other than the initial value's
|
|
11
10
|
* type. This is particularly useful when, as below, the initial value is undefined.
|
|
12
11
|
*/
|
|
13
|
-
email: undefined
|
|
12
|
+
email: undefined,
|
|
14
13
|
};
|
|
15
14
|
},
|
|
16
|
-
render({state, updateState}) {
|
|
17
|
-
return html`
|
|
15
|
+
render({ state, updateState }) {
|
|
16
|
+
return html `
|
|
18
17
|
<span
|
|
19
18
|
${listen('click', () => {
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
updateState({ username: 'new name!' });
|
|
20
|
+
})}
|
|
22
21
|
>
|
|
23
22
|
Hello there ${state.username}!
|
|
24
23
|
</span>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set by {@link requireAllCustomElementsToBeDeclarativeElements} and read in the HTML tagged
|
|
3
|
+
* template function.
|
|
4
|
+
*
|
|
5
|
+
* @category Internal
|
|
6
|
+
*/
|
|
7
|
+
export declare let declarativeElementRequired: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Calling this requires all custom element children to be declarative elements defined by
|
|
10
|
+
* element-vir.
|
|
11
|
+
*
|
|
12
|
+
* @category Util
|
|
13
|
+
*/
|
|
14
|
+
export declare function requireAllCustomElementsToBeDeclarativeElements(): void;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {type
|
|
3
|
-
import {type PropertyInitMapBase} from '../declarative-element/properties/element-properties.js';
|
|
4
|
-
|
|
1
|
+
import { type DeclarativeElementDefinitionOptions } from '../declarative-element/definition-options.js';
|
|
2
|
+
import { type PropertyInitMapBase } from '../declarative-element/properties/element-properties.js';
|
|
5
3
|
/**
|
|
6
4
|
* A minimal element definition used for interpolating element definitions into HTML templates with
|
|
7
5
|
* a more generic type (to prevent insane circular dependencies).
|
|
@@ -12,9 +10,10 @@ export type MinimalElementDefinition<TagName extends string = string> = {
|
|
|
12
10
|
tagName: TagName;
|
|
13
11
|
elementOptions?: DeclarativeElementDefinitionOptions | undefined;
|
|
14
12
|
/** This is used when wrapping interpolated raw tag name strings. */
|
|
15
|
-
tagInterpolationKey?: {
|
|
13
|
+
tagInterpolationKey?: {
|
|
14
|
+
tagName: string;
|
|
15
|
+
} | undefined;
|
|
16
16
|
};
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* A parent definition of {@link MinimalElementDefinition} with inputs also specified with allows the
|
|
20
19
|
* `.assign()` method to be used inside of HTML templates.
|
|
@@ -31,27 +30,16 @@ export type MinimalDefinitionWithInputs<TagName extends string = string> = {
|
|
|
31
30
|
definition: MinimalElementDefinition<TagName>;
|
|
32
31
|
inputs: PropertyInitMapBase;
|
|
33
32
|
};
|
|
34
|
-
|
|
35
33
|
/**
|
|
36
34
|
* Checks if the input is an instance of {@link MinimalDefinitionWithInputs}.
|
|
37
35
|
*
|
|
38
36
|
* @category Internal
|
|
39
37
|
*/
|
|
40
|
-
export function isMinimalDefinitionWithInputs(
|
|
41
|
-
value: unknown,
|
|
42
|
-
): value is MinimalDefinitionWithInputs {
|
|
43
|
-
return (
|
|
44
|
-
check.hasKey(value, '_elementVirIsMinimalDefinitionWithInputs') &&
|
|
45
|
-
!!value._elementVirIsMinimalDefinitionWithInputs
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
38
|
+
export declare function isMinimalDefinitionWithInputs(value: unknown): value is MinimalDefinitionWithInputs;
|
|
49
39
|
/**
|
|
50
40
|
* Checks if the input is an object that has a `tagName` property. Used inside of the HTML tagged
|
|
51
41
|
* template functions for checking if interpolated values should be treated as element tags.
|
|
52
42
|
*
|
|
53
43
|
* @category Internal
|
|
54
44
|
*/
|
|
55
|
-
export function hasTagName(value: unknown): value is MinimalElementDefinition
|
|
56
|
-
return check.hasKey(value, 'tagName') && !!value.tagName && typeof value.tagName === 'string';
|
|
57
|
-
}
|
|
45
|
+
export declare function hasTagName(value: unknown): value is MinimalElementDefinition;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the input is an instance of {@link MinimalDefinitionWithInputs}.
|
|
4
|
+
*
|
|
5
|
+
* @category Internal
|
|
6
|
+
*/
|
|
7
|
+
export function isMinimalDefinitionWithInputs(value) {
|
|
8
|
+
return (check.hasKey(value, '_elementVirIsMinimalDefinitionWithInputs') &&
|
|
9
|
+
!!value._elementVirIsMinimalDefinitionWithInputs);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the input is an object that has a `tagName` property. Used inside of the HTML tagged
|
|
13
|
+
* template functions for checking if interpolated values should be treated as element tags.
|
|
14
|
+
*
|
|
15
|
+
* @category Internal
|
|
16
|
+
*/
|
|
17
|
+
export function hasTagName(value) {
|
|
18
|
+
return check.hasKey(value, 'tagName') && !!value.tagName && typeof value.tagName === 'string';
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TemplateTransform } from './template-transform-type.js';
|
|
2
|
+
export declare function getAlreadyMappedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[]): TemplateTransform | undefined;
|
|
3
|
+
export declare function setMappedTemplate<PossibleValues>(templateStringsKey: TemplateStringsArray, values: PossibleValues[], valueToSet: TemplateTransform): {
|
|
4
|
+
result: boolean;
|
|
5
|
+
reason: string;
|
|
6
|
+
};
|