element-vir 26.16.0 → 26.17.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 +26 -38
- package/dist/declarative-element/declarative-element.d.ts +1 -1
- package/dist/declarative-element/define-element.js +19 -10
- package/dist/declarative-element/directives/directive-helpers.js +0 -4
- package/dist/declarative-element/directives/on-intersect.directive.d.ts +5 -0
- package/dist/declarative-element/directives/on-intersect.directive.js +10 -2
- package/dist/declarative-element/directives/on-resize.directive.d.ts +5 -0
- package/dist/declarative-element/directives/on-resize.directive.js +10 -2
- package/dist/declarative-element/properties/property-proxy.js +1 -1
- package/dist/declarative-element/properties/string-names.d.ts +6 -8
- package/dist/declarative-element/properties/styles.d.ts +1 -1
- package/dist/declarative-element/render-callback.d.ts +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/template-transforms/vir-html/html-transform.js +2 -22
- package/package.json +1 -1
- package/dist/readme-examples/my-app.element.d.ts +0 -1
- package/dist/readme-examples/my-app.element.js +0 -12
- package/dist/readme-examples/my-custom-action.event.d.ts +0 -1
- package/dist/readme-examples/my-custom-action.event.js +0 -2
- package/dist/readme-examples/my-custom-define.d.ts +0 -4
- package/dist/readme-examples/my-custom-define.js +0 -19
- package/dist/readme-examples/my-simple.element.d.ts +0 -1
- package/dist/readme-examples/my-simple.element.js +0 -10
- package/dist/readme-examples/my-with-assignment.element.d.ts +0 -1
- package/dist/readme-examples/my-with-assignment.element.js +0 -15
- package/dist/readme-examples/my-with-async-prop.element.d.ts +0 -10
- package/dist/readme-examples/my-with-async-prop.element.js +0 -49
- package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +0 -3
- package/dist/readme-examples/my-with-cleanup-callback.element.js +0 -18
- package/dist/readme-examples/my-with-css-vars.element.d.ts +0 -1
- package/dist/readme-examples/my-with-css-vars.element.js +0 -25
- package/dist/readme-examples/my-with-custom-events.element.d.ts +0 -1
- package/dist/readme-examples/my-with-custom-events.element.js +0 -25
- package/dist/readme-examples/my-with-event-listening.element.d.ts +0 -3
- package/dist/readme-examples/my-with-event-listening.element.js +0 -27
- package/dist/readme-examples/my-with-events.element.d.ts +0 -4
- package/dist/readme-examples/my-with-events.element.js +0 -23
- package/dist/readme-examples/my-with-host-class-definition.element.d.ts +0 -3
- package/dist/readme-examples/my-with-host-class-definition.element.js +0 -42
- package/dist/readme-examples/my-with-host-class-usage.element.d.ts +0 -1
- package/dist/readme-examples/my-with-host-class-usage.element.js +0 -13
- package/dist/readme-examples/my-with-inputs.element.d.ts +0 -4
- package/dist/readme-examples/my-with-inputs.element.js +0 -9
- package/dist/readme-examples/my-with-on-dom-created.element.d.ts +0 -1
- package/dist/readme-examples/my-with-on-dom-created.element.js +0 -17
- package/dist/readme-examples/my-with-on-resize.element.d.ts +0 -1
- package/dist/readme-examples/my-with-on-resize.element.js +0 -18
- package/dist/readme-examples/my-with-render-if.element.d.ts +0 -3
- package/dist/readme-examples/my-with-render-if.element.js +0 -11
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +0 -1
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.js +0 -16
- package/dist/readme-examples/my-with-styles.element.d.ts +0 -1
- package/dist/readme-examples/my-with-styles.element.js +0 -22
- package/dist/readme-examples/my-with-update-state.element.d.ts +0 -8
- package/dist/readme-examples/my-with-update-state.element.js +0 -28
- package/dist/readme-examples/require-declarative-element.d.ts +0 -1
- package/dist/readme-examples/require-declarative-element.js +0 -2
- package/dist/require-declarative-element.d.ts +0 -14
- package/dist/require-declarative-element.js +0 -16
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ All of [`lit`](https://lit.dev)'s syntax and functionality is available for use
|
|
|
38
38
|
|
|
39
39
|
Use `defineElement` to define your element. Here is a bare-minimum example custom element:
|
|
40
40
|
|
|
41
|
-
<!-- example-link: src/readme-examples/my-simple.
|
|
41
|
+
<!-- example-link: src/readme-examples/my-simple.example.ts -->
|
|
42
42
|
|
|
43
43
|
```TypeScript
|
|
44
44
|
import {defineElement} from 'element-vir';
|
|
@@ -60,12 +60,12 @@ Make sure to export your element definition if you need to use it in other files
|
|
|
60
60
|
|
|
61
61
|
To use already defined elements (like the example above), they must be interpolated into HTML templates like so:
|
|
62
62
|
|
|
63
|
-
<!-- example-link: src/readme-examples/my-app.
|
|
63
|
+
<!-- example-link: src/readme-examples/my-app.example.ts -->
|
|
64
64
|
|
|
65
65
|
```TypeScript
|
|
66
66
|
import {defineElement} from 'element-vir';
|
|
67
67
|
import {html} from 'element-vir';
|
|
68
|
-
import {MySimple} from './my-simple.
|
|
68
|
+
import {MySimple} from './my-simple.example.js';
|
|
69
69
|
|
|
70
70
|
export const MyApp = defineElement()({
|
|
71
71
|
tagName: 'my-app',
|
|
@@ -84,7 +84,7 @@ This requirement ensures that the element is properly imported and registered wi
|
|
|
84
84
|
|
|
85
85
|
Styles are added through the `styles` property when defining a declarative element (similar to [how they are defined in `lit`](https://lit.dev/docs/components/styles/)):
|
|
86
86
|
|
|
87
|
-
<!-- example-link: src/readme-examples/my-with-styles.
|
|
87
|
+
<!-- example-link: src/readme-examples/my-with-styles.example.ts -->
|
|
88
88
|
|
|
89
89
|
```TypeScript
|
|
90
90
|
import {defineElement} from 'element-vir';
|
|
@@ -116,12 +116,12 @@ export const MyWithStyles = defineElement()({
|
|
|
116
116
|
|
|
117
117
|
Declarative element definitions can be used in the `css` tagged template just like in the `html` tagged template. This will be replaced by the element's tag name:
|
|
118
118
|
|
|
119
|
-
<!-- example-link: src/readme-examples/my-with-styles-and-interpolated-selector.
|
|
119
|
+
<!-- example-link: src/readme-examples/my-with-styles-and-interpolated-selector.example.ts -->
|
|
120
120
|
|
|
121
121
|
```TypeScript
|
|
122
122
|
import {defineElement} from 'element-vir';
|
|
123
123
|
import {css, html} from 'element-vir';
|
|
124
|
-
import {MySimple} from './my-simple.
|
|
124
|
+
import {MySimple} from './my-simple.example.js';
|
|
125
125
|
|
|
126
126
|
export const MyWithStylesAndInterpolatedSelector = defineElement()({
|
|
127
127
|
tagName: 'my-with-styles-and-interpolated-selector',
|
|
@@ -144,7 +144,7 @@ Define element inputs by using `defineElement` to define a declarative element.
|
|
|
144
144
|
|
|
145
145
|
To use an element's inputs for use in its template, grab `inputs` from `render`'s parameters and interpolate it into your HTML template:
|
|
146
146
|
|
|
147
|
-
<!-- example-link: src/readme-examples/my-with-inputs.
|
|
147
|
+
<!-- example-link: src/readme-examples/my-with-inputs.example.ts -->
|
|
148
148
|
|
|
149
149
|
```TypeScript
|
|
150
150
|
import {defineElement, html} from 'element-vir';
|
|
@@ -166,7 +166,7 @@ export const MyWithInputs = defineElement<{
|
|
|
166
166
|
|
|
167
167
|
Define initial internal state values and types with the `stateInit` property when defining an element. Grab it with `state` in `render` to use state. Grab `updateState` in `render` to update state:
|
|
168
168
|
|
|
169
|
-
<!-- example-link: src/readme-examples/my-with-update-state.
|
|
169
|
+
<!-- example-link: src/readme-examples/my-with-update-state.example.ts -->
|
|
170
170
|
|
|
171
171
|
```TypeScript
|
|
172
172
|
import {defineElement} from 'element-vir';
|
|
@@ -204,12 +204,12 @@ export const MyWithUpdateState = defineElement()({
|
|
|
204
204
|
|
|
205
205
|
Use the `assign` directive to assign values to child custom elements inputs:
|
|
206
206
|
|
|
207
|
-
<!-- example-link: src/readme-examples/my-with-assignment.
|
|
207
|
+
<!-- example-link: src/readme-examples/my-with-assignment.example.ts -->
|
|
208
208
|
|
|
209
209
|
```TypeScript
|
|
210
210
|
import {defineElement} from 'element-vir';
|
|
211
211
|
import {html} from 'element-vir';
|
|
212
|
-
import {MyWithInputs} from './my-with-inputs.
|
|
212
|
+
import {MyWithInputs} from './my-with-inputs.example.js';
|
|
213
213
|
|
|
214
214
|
export const MyWithAssignment = defineElement()({
|
|
215
215
|
tagName: 'my-with-assignment',
|
|
@@ -232,7 +232,7 @@ There are two other callbacks you can define that are sort of similar to lifecyc
|
|
|
232
232
|
- `init`: called right before the first render and has all state and inputs setup. (This is similar to `connectedCallback` in standard HTMLElement classes but is fired much later, after inputs are assigned, to avoid race conditions.)
|
|
233
233
|
- `cleanup`: called when an element is removed from the DOM. (This is the same as the `disconnectedCallback` in standard HTMLElement classes.)
|
|
234
234
|
|
|
235
|
-
<!-- example-link: src/readme-examples/my-with-cleanup-callback.
|
|
235
|
+
<!-- example-link: src/readme-examples/my-with-cleanup-callback.example.ts -->
|
|
236
236
|
|
|
237
237
|
```TypeScript
|
|
238
238
|
import {defineElement} from 'element-vir';
|
|
@@ -262,7 +262,7 @@ When defining a declarative element, use `events` to setup event names and types
|
|
|
262
262
|
|
|
263
263
|
To dispatch an event, grab `dispatch` and `events` from `render`'s parameters.
|
|
264
264
|
|
|
265
|
-
<!-- example-link: src/readme-examples/my-with-events.
|
|
265
|
+
<!-- example-link: src/readme-examples/my-with-events.example.ts -->
|
|
266
266
|
|
|
267
267
|
```TypeScript
|
|
268
268
|
import {randomInteger} from '@augment-vir/common';
|
|
@@ -301,12 +301,12 @@ export const MyWithEvents = defineElement()({
|
|
|
301
301
|
|
|
302
302
|
Use the `listen` directive to listen to events emitted by your custom elements:
|
|
303
303
|
|
|
304
|
-
<!-- example-link: src/readme-examples/my-with-event-listening.
|
|
304
|
+
<!-- example-link: src/readme-examples/my-with-event-listening.example.ts -->
|
|
305
305
|
|
|
306
306
|
```TypeScript
|
|
307
307
|
import {defineElement} from 'element-vir';
|
|
308
308
|
import {html, listen} from 'element-vir';
|
|
309
|
-
import {MyWithEvents} from './my-with-events.
|
|
309
|
+
import {MyWithEvents} from './my-with-events.example.js';
|
|
310
310
|
|
|
311
311
|
export const MyWithEventListening = defineElement()({
|
|
312
312
|
tagName: 'my-with-event-listening',
|
|
@@ -340,7 +340,7 @@ export const MyWithEventListening = defineElement()({
|
|
|
340
340
|
|
|
341
341
|
Create a custom event type with `defineTypedEvent`. Make sure to include the type parameter and call it twice, the second time with the event type name string to ensure type safety when using your event. Note that event type names should be unique, or they will clash with each other.
|
|
342
342
|
|
|
343
|
-
<!-- example-link: src/readme-examples/my-custom-action.
|
|
343
|
+
<!-- example-link: src/readme-examples/my-custom-action.example.ts -->
|
|
344
344
|
|
|
345
345
|
```TypeScript
|
|
346
346
|
import {defineTypedEvent} from 'element-vir';
|
|
@@ -352,13 +352,13 @@ export const MyCustomActionEvent = defineTypedEvent<number>()('my-custom-action'
|
|
|
352
352
|
|
|
353
353
|
Dispatching a custom event and listening to a custom event is the same as doing so for element events:
|
|
354
354
|
|
|
355
|
-
<!-- example-link: src/readme-examples/my-with-custom-events.
|
|
355
|
+
<!-- example-link: src/readme-examples/my-with-custom-events.example.ts -->
|
|
356
356
|
|
|
357
357
|
```TypeScript
|
|
358
358
|
import {randomInteger} from '@augment-vir/common';
|
|
359
359
|
import {defineElement} from 'element-vir';
|
|
360
360
|
import {html, listen} from 'element-vir';
|
|
361
|
-
import {MyCustomActionEvent} from './my-custom-action.
|
|
361
|
+
import {MyCustomActionEvent} from './my-custom-action.example.js';
|
|
362
362
|
|
|
363
363
|
export const MyWithCustomEvents = defineElement()({
|
|
364
364
|
tagName: 'my-with-custom-events',
|
|
@@ -400,7 +400,7 @@ Host classes are defined by passing an object to `hostClasses` at element defini
|
|
|
400
400
|
|
|
401
401
|
Apply host classes in the element's stylesheet by using a callback for the styles property:
|
|
402
402
|
|
|
403
|
-
<!-- example-link: src/readme-examples/my-with-host-class-definition.
|
|
403
|
+
<!-- example-link: src/readme-examples/my-with-host-class-definition.example.ts -->
|
|
404
404
|
|
|
405
405
|
```TypeScript
|
|
406
406
|
import {defineElement} from 'element-vir';
|
|
@@ -452,12 +452,12 @@ export const MyWithHostClassDefinition = defineElement()({
|
|
|
452
452
|
|
|
453
453
|
To apply a host class in a consumer, access the child element's `.hostClasses` property:
|
|
454
454
|
|
|
455
|
-
<!-- example-link: src/readme-examples/my-with-host-class-usage.
|
|
455
|
+
<!-- example-link: src/readme-examples/my-with-host-class-usage.example.ts -->
|
|
456
456
|
|
|
457
457
|
```TypeScript
|
|
458
458
|
import {defineElement} from 'element-vir';
|
|
459
459
|
import {html} from 'element-vir';
|
|
460
|
-
import {MyWithHostClassDefinition} from './my-with-host-class-definition.
|
|
460
|
+
import {MyWithHostClassDefinition} from './my-with-host-class-definition.example.js';
|
|
461
461
|
|
|
462
462
|
export const MyWithHostClassUsage = defineElement()({
|
|
463
463
|
tagName: 'my-with-host-class-usage',
|
|
@@ -475,7 +475,7 @@ export const MyWithHostClassUsage = defineElement()({
|
|
|
475
475
|
|
|
476
476
|
Typed CSS variables are created in a similar manner to host classes:
|
|
477
477
|
|
|
478
|
-
<!-- example-link: src/readme-examples/my-with-css-vars.
|
|
478
|
+
<!-- example-link: src/readme-examples/my-with-css-vars.example.ts -->
|
|
479
479
|
|
|
480
480
|
```TypeScript
|
|
481
481
|
import {defineElement} from 'element-vir';
|
|
@@ -510,7 +510,7 @@ export const MyWithCssVars = defineElement()({
|
|
|
510
510
|
|
|
511
511
|
Use `wrapDefineElement` to compose `defineElement`. This is particularly useful to adding restrictions on the element `tagName`, but it can be used for restricting any of the type parameters:
|
|
512
512
|
|
|
513
|
-
<!-- example-link: src/readme-examples/my-custom-define.ts -->
|
|
513
|
+
<!-- example-link: src/readme-examples/my-custom-define.example.ts -->
|
|
514
514
|
|
|
515
515
|
```TypeScript
|
|
516
516
|
import {wrapDefineElement} from 'element-vir';
|
|
@@ -549,7 +549,7 @@ All [built-in `lit` directives](https://lit.dev/docs/templates/directives/) are
|
|
|
549
549
|
|
|
550
550
|
This triggers only once when the element it's attached to has actually been created in the DOM. If the attached element changes, the callback will be triggered again.
|
|
551
551
|
|
|
552
|
-
<!-- example-link: src/readme-examples/my-with-on-dom-created.
|
|
552
|
+
<!-- example-link: src/readme-examples/my-with-on-dom-created.example.ts -->
|
|
553
553
|
|
|
554
554
|
```TypeScript
|
|
555
555
|
import {defineElement} from 'element-vir';
|
|
@@ -576,7 +576,7 @@ export const MyWithOnDomCreated = defineElement()({
|
|
|
576
576
|
|
|
577
577
|
This directive fires its callback whenever the element it's attached to resizes. The callback is passed an object with a portion of the [`ResizeObserverEntry`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry) properties.
|
|
578
578
|
|
|
579
|
-
<!-- example-link: src/readme-examples/my-with-on-resize.
|
|
579
|
+
<!-- example-link: src/readme-examples/my-with-on-resize.example.ts -->
|
|
580
580
|
|
|
581
581
|
```TypeScript
|
|
582
582
|
import {defineElement} from 'element-vir';
|
|
@@ -608,7 +608,7 @@ Listen to a specific event. This is explained in the **Listening to element even
|
|
|
608
608
|
|
|
609
609
|
Use the `renderIf` directive to easily render a template if a given condition is true.
|
|
610
610
|
|
|
611
|
-
<!-- example-link: src/readme-examples/my-with-render-if.
|
|
611
|
+
<!-- example-link: src/readme-examples/my-with-render-if.example.ts -->
|
|
612
612
|
|
|
613
613
|
```TypeScript
|
|
614
614
|
import {defineElement, html, renderIf} from 'element-vir';
|
|
@@ -632,7 +632,7 @@ export const MyWithRenderIf = defineElement<{shouldRender: boolean}>()({
|
|
|
632
632
|
|
|
633
633
|
Use `renderAsync` or `isResolved` in conjunction with `asyncProp` to seamlessly render and update element state based on async values:
|
|
634
634
|
|
|
635
|
-
<!-- example-link: src/readme-examples/my-with-async-prop.
|
|
635
|
+
<!-- example-link: src/readme-examples/my-with-async-prop.example.ts -->
|
|
636
636
|
|
|
637
637
|
```TypeScript
|
|
638
638
|
import {asyncProp, defineElement, html, listen, renderAsync} from 'element-vir';
|
|
@@ -694,18 +694,6 @@ export const MyWithAsyncProp = defineElement<{endpoint: string}>()({
|
|
|
694
694
|
});
|
|
695
695
|
```
|
|
696
696
|
|
|
697
|
-
## Require all child custom elements to be declarative elements
|
|
698
|
-
|
|
699
|
-
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).
|
|
700
|
-
|
|
701
|
-
<!-- example-link: src/readme-examples/require-declarative-element.ts -->
|
|
702
|
-
|
|
703
|
-
```TypeScript
|
|
704
|
-
import {requireAllCustomElementsToBeDeclarativeElements} from 'element-vir';
|
|
705
|
-
|
|
706
|
-
requireAllCustomElementsToBeDeclarativeElements();
|
|
707
|
-
```
|
|
708
|
-
|
|
709
697
|
# Dev
|
|
710
698
|
|
|
711
699
|
## markdown out of date
|
|
@@ -100,7 +100,7 @@ export type StaticDeclarativeElementProperties<TagName extends CustomElementTagN
|
|
|
100
100
|
/** Pass through the render callback for direct unit testability */
|
|
101
101
|
readonly render: RenderCallback<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
102
102
|
readonly events: EventDescriptorMap<TagName, EventsInit>;
|
|
103
|
-
readonly slotNames: SlotNamesMap<SlotNames>;
|
|
103
|
+
readonly slotNames: SlotNamesMap<TagName, SlotNames>;
|
|
104
104
|
readonly testIds: Readonly<StringNameMap<TagName, 'test-id', TestIds>>;
|
|
105
105
|
readonly init: DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
106
106
|
readonly elementOptions: DeclarativeElementDefinitionOptions;
|
|
@@ -42,7 +42,7 @@ export function defineElement(
|
|
|
42
42
|
return (initInput) => {
|
|
43
43
|
const init = initInput;
|
|
44
44
|
if (!check.isObject(init)) {
|
|
45
|
-
throw new TypeError(
|
|
45
|
+
throw new TypeError(`Cannot define element with non-object init: ${String(init)}`);
|
|
46
46
|
}
|
|
47
47
|
return internalDefineElement({
|
|
48
48
|
...init,
|
|
@@ -54,7 +54,7 @@ export function defineElement(
|
|
|
54
54
|
}
|
|
55
55
|
function internalDefineElement(init) {
|
|
56
56
|
if (!check.isObject(init)) {
|
|
57
|
-
throw new TypeError(
|
|
57
|
+
throw new TypeError(`Cannot define element with non-object init: ${String(init)}`);
|
|
58
58
|
}
|
|
59
59
|
else if (!check.isString(init.tagName)) {
|
|
60
60
|
throw new TypeError('Missing valid tagName (expected a string).');
|
|
@@ -148,7 +148,7 @@ function internalDefineElement(init) {
|
|
|
148
148
|
this._stateCalled = true;
|
|
149
149
|
const stateInit = init.state(renderParams);
|
|
150
150
|
if (stateInit instanceof Promise) {
|
|
151
|
-
throw new TypeError('
|
|
151
|
+
throw new TypeError('state cannot be asynchronous');
|
|
152
152
|
}
|
|
153
153
|
getObjectTypedKeys(stateInit).forEach((stateKey) => {
|
|
154
154
|
bindReactiveProperty(this, stateKey);
|
|
@@ -206,18 +206,27 @@ function internalDefineElement(init) {
|
|
|
206
206
|
stateValue.destroy();
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
|
+
this._initCalled = false;
|
|
210
|
+
this._stateCalled = false;
|
|
209
211
|
}
|
|
210
212
|
disconnectedCallback() {
|
|
211
213
|
super.disconnectedCallback();
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Always reset bookkeeping and run `destroy()`, even when `cleanup` throws — otherwise
|
|
216
|
+
* a throwing cleanup leaves `_initCalled` / `_stateCalled` stuck and corrupts the next
|
|
217
|
+
* mount.
|
|
218
|
+
*/
|
|
219
|
+
try {
|
|
220
|
+
if (init.cleanup && this._stateCalled) {
|
|
221
|
+
const renderParams = this.createRenderParams();
|
|
222
|
+
if (init.cleanup(renderParams) instanceof Promise) {
|
|
223
|
+
throw new TypeError(`cleanup in '${init.tagName}' cannot be asynchronous`);
|
|
224
|
+
}
|
|
216
225
|
}
|
|
217
226
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
227
|
+
finally {
|
|
228
|
+
this.destroy();
|
|
229
|
+
}
|
|
221
230
|
}
|
|
222
231
|
// this is set below in Object.defineProperties
|
|
223
232
|
definition = {};
|
|
@@ -29,9 +29,5 @@ export function assertIsElementPartInfo(partInfo, directiveName) {
|
|
|
29
29
|
const hostTagMessage = hostTagName ? `: in ${hostTagName}` : '';
|
|
30
30
|
if (partInfo.type !== PartType.ELEMENT) {
|
|
31
31
|
throw new Error(`${directiveName} directive can only be attached directly to an element${hostTagMessage}.`);
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
33
|
-
}
|
|
34
|
-
else if (!partInfo.element) {
|
|
35
|
-
throw new Error(`${directiveName} directive found no element${hostTagMessage}.`);
|
|
36
32
|
}
|
|
37
33
|
}
|
|
@@ -59,6 +59,11 @@ export declare const onIntersect: (options: IntersectionObserverInit, callback:
|
|
|
59
59
|
fireCallback(entries: IntersectionObserverEntry[], observer: IntersectionObserver): void;
|
|
60
60
|
update(partInfo: PartInfo, [options, callback,]: [OnIntersectOptions, OnIntersectCallback]): undefined;
|
|
61
61
|
render(options: OnIntersectOptions, callback: OnIntersectCallback): undefined;
|
|
62
|
+
disconnected(): void;
|
|
63
|
+
reconnected(): void;
|
|
64
|
+
isConnected: boolean;
|
|
65
|
+
_$initialize(part: import("lit-html").Part, parent: import("lit-html").Disconnectable, attributeIndex: number | undefined): void;
|
|
66
|
+
setValue(value: unknown): void;
|
|
62
67
|
get _$isConnected(): boolean;
|
|
63
68
|
};
|
|
64
69
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert, assertWrap, check } from '@augment-vir/assert';
|
|
2
|
-
import {
|
|
2
|
+
import { AsyncDirective, directive } from '../../lit-exports/all-lit-exports.js';
|
|
3
3
|
import { assertIsElementPartInfo } from './directive-helpers.js';
|
|
4
4
|
const directiveName = 'onIntersect';
|
|
5
5
|
/**
|
|
@@ -35,7 +35,7 @@ const directiveName = 'onIntersect';
|
|
|
35
35
|
* });
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export const onIntersect = directive(class extends
|
|
38
|
+
export const onIntersect = directive(class extends AsyncDirective {
|
|
39
39
|
element;
|
|
40
40
|
options;
|
|
41
41
|
intersectionObserver;
|
|
@@ -86,4 +86,12 @@ export const onIntersect = directive(class extends Directive {
|
|
|
86
86
|
render(options, callback) {
|
|
87
87
|
return undefined;
|
|
88
88
|
}
|
|
89
|
+
disconnected() {
|
|
90
|
+
this.intersectionObserver?.disconnect();
|
|
91
|
+
}
|
|
92
|
+
reconnected() {
|
|
93
|
+
if (this.element && this.intersectionObserver) {
|
|
94
|
+
this.intersectionObserver.observe(this.element);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
89
97
|
});
|
|
@@ -42,6 +42,11 @@ export declare const onResize: (callback: OnResizeCallback) => import("lit-html/
|
|
|
42
42
|
callback: OnResizeCallback | undefined;
|
|
43
43
|
update(partInfo: PartInfo, [callback]: [OnResizeCallback]): undefined;
|
|
44
44
|
render(callback: OnResizeCallback): undefined;
|
|
45
|
+
disconnected(): void;
|
|
46
|
+
reconnected(): void;
|
|
47
|
+
isConnected: boolean;
|
|
48
|
+
_$initialize(part: import("lit-html").Part, parent: import("lit-html").Disconnectable, attributeIndex: number | undefined): void;
|
|
49
|
+
setValue(value: unknown): void;
|
|
45
50
|
get _$isConnected(): boolean;
|
|
46
51
|
};
|
|
47
52
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncDirective, directive } from '../../lit-exports/all-lit-exports.js';
|
|
2
2
|
import { assertIsElementPartInfo } from './directive-helpers.js';
|
|
3
3
|
const directiveName = 'onResize';
|
|
4
4
|
/**
|
|
@@ -28,7 +28,7 @@ const directiveName = 'onResize';
|
|
|
28
28
|
* });
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export const onResize = directive(class extends
|
|
31
|
+
export const onResize = directive(class extends AsyncDirective {
|
|
32
32
|
element;
|
|
33
33
|
resizeObserver = new ResizeObserver((entries) => {
|
|
34
34
|
if (this.element && this.callback) {
|
|
@@ -59,6 +59,14 @@ export const onResize = directive(class extends Directive {
|
|
|
59
59
|
render(callback) {
|
|
60
60
|
return undefined;
|
|
61
61
|
}
|
|
62
|
+
disconnected() {
|
|
63
|
+
this.resizeObserver.disconnect();
|
|
64
|
+
}
|
|
65
|
+
reconnected() {
|
|
66
|
+
if (this.element) {
|
|
67
|
+
this.resizeObserver.observe(this.element);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
62
70
|
});
|
|
63
71
|
function handleOnResizeCallback(element, callback, entries) {
|
|
64
72
|
const resizeEntry = entries[0];
|
|
@@ -77,7 +77,7 @@ export function createElementPropertyProxy(element, shouldAlreadyExist) {
|
|
|
77
77
|
}
|
|
78
78
|
else if (isObservableBase(oldValue)) {
|
|
79
79
|
/** Clear out old listener that is no longer used. */
|
|
80
|
-
element.observablePropertyListenerMap[propertyKey]
|
|
80
|
+
delete element.observablePropertyListenerMap[propertyKey];
|
|
81
81
|
}
|
|
82
82
|
setValueOnElement(newValue);
|
|
83
83
|
return true;
|
|
@@ -27,16 +27,14 @@ export type StringNameMap<ElementTagName extends CustomElementTagName, NameType
|
|
|
27
27
|
*/
|
|
28
28
|
export declare function createStringNameMap<ElementTagName extends CustomElementTagName, NameType extends string, StringNames extends ReadonlyArray<string>>(elementTagName: ElementTagName, nameType: NameType, stringNames: StringNames | undefined): StringNameMap<ElementTagName, NameType, StringNames>;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* Note that if a slot name is _incorrectly_ defined without the element's tag name as the prefix,
|
|
34
|
-
* then the runtime value will actually be `${ElementTagName}-slot-${Name}`.
|
|
30
|
+
* Map of slot names to their runtime values. Slot names that already start with the element's tag
|
|
31
|
+
* name are kept as-is; legacy slot names without the tag-name prefix are auto-rewritten at runtime
|
|
32
|
+
* to `${ElementTagName}-slot-${Name}` and this type reflects that.
|
|
35
33
|
*
|
|
36
34
|
* @category Internal
|
|
37
35
|
*/
|
|
38
|
-
export type SlotNamesMap<SlotNames extends ReadonlyArray<string>> = Readonly<{
|
|
39
|
-
[Name in ArrayElement<SlotNames>]: Name
|
|
36
|
+
export type SlotNamesMap<ElementTagName extends string, SlotNames extends ReadonlyArray<string>> = Readonly<{
|
|
37
|
+
[Name in ArrayElement<SlotNames>]: Name extends `${ElementTagName}-${string}` ? Name : `${ElementTagName}-slot-${Name}`;
|
|
40
38
|
}>;
|
|
41
39
|
/**
|
|
42
40
|
* Converts an array of slot names into a {@link SlotNamesMap}.
|
|
@@ -47,4 +45,4 @@ export type SlotNamesMap<SlotNames extends ReadonlyArray<string>> = Readonly<{
|
|
|
47
45
|
*
|
|
48
46
|
* @category Internal
|
|
49
47
|
*/
|
|
50
|
-
export declare function createSlotNamesMap<ElementTagName extends CustomElementTagName, SlotNames extends ReadonlyArray<string>>(elementTagName: ElementTagName, slotNames: SlotNames | undefined): SlotNamesMap<SlotNames>;
|
|
48
|
+
export declare function createSlotNamesMap<ElementTagName extends CustomElementTagName, SlotNames extends ReadonlyArray<string>>(elementTagName: ElementTagName, slotNames: SlotNames | undefined): SlotNamesMap<ElementTagName, SlotNames>;
|
|
@@ -38,7 +38,7 @@ export type StylesCallback<TagName extends CustomElementTagName, HostClassKeys e
|
|
|
38
38
|
export declare function createStylesCallbackInput<TagName extends CustomElementTagName, HostClassKeys extends BaseStringName<NoInfer<TagName>>, CssVarKeys extends BaseStringName<NoInfer<TagName>>, SlotNames extends ReadonlyArray<string>>({ hostClassNames, cssVars, slotNamesMap, }: {
|
|
39
39
|
hostClassNames: HostClassNamesMap<TagName, HostClassKeys>;
|
|
40
40
|
cssVars: Readonly<CssVars<TagName, CssVarKeys>>;
|
|
41
|
-
slotNamesMap: SlotNamesMap<SlotNames>;
|
|
41
|
+
slotNamesMap: SlotNamesMap<TagName, SlotNames>;
|
|
42
42
|
}): StylesCallbackInput<TagName, HostClassKeys, CssVarKeys, SlotNames>;
|
|
43
43
|
/**
|
|
44
44
|
* Used inside of an element instance to apply host classes on each render.
|
|
@@ -35,7 +35,7 @@ export type RenderParams<TagName extends CustomElementTagName, Inputs extends Pr
|
|
|
35
35
|
updateState: UpdateStateCallback<State>;
|
|
36
36
|
events: EventDescriptorMap<TagName, EventsInit>;
|
|
37
37
|
host: DeclarativeElementHost<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
38
|
-
slotNames: SlotNamesMap<SlotNames>;
|
|
38
|
+
slotNames: SlotNamesMap<TagName, SlotNames>;
|
|
39
39
|
testIds: Readonly<StringNameMap<TagName, 'test-id', TestIds>>;
|
|
40
40
|
/** Dispatch an event from the current element. */
|
|
41
41
|
dispatch: <EventTypeName extends keyof EventsInit>(event: TypedEvent<EventTypeName extends string ? EventTypeName : never, EventInitMapEventDetailExtractor<EventTypeName, EventsInit>> | Event) => boolean;
|
|
@@ -51,6 +51,6 @@ export declare function createRenderParams<TagName extends CustomElementTagName,
|
|
|
51
51
|
element: DeclarativeElement<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
52
52
|
eventsMap: EventDescriptorMap<TagName, EventsInit>;
|
|
53
53
|
cssVars: Readonly<CssVars<TagName, CssVarKeys>>;
|
|
54
|
-
slotNamesMap: SlotNamesMap<SlotNames>;
|
|
54
|
+
slotNamesMap: SlotNamesMap<TagName, SlotNames>;
|
|
55
55
|
testIdsMap: Readonly<StringNameMap<TagName, 'test-id', TestIds>>;
|
|
56
56
|
}): RenderParams<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export * from './declarative-element/properties/tag-name.js';
|
|
|
32
32
|
export * from './declarative-element/render-callback.js';
|
|
33
33
|
export * from './declarative-element/wrap-define-element.js';
|
|
34
34
|
export * from './lit-exports/all-lit-exports.js';
|
|
35
|
-
export * from './require-declarative-element.js';
|
|
36
35
|
export * from './template-transforms/minimal-element-definition.js';
|
|
37
36
|
export * from './template-transforms/vir-css/vir-css.js';
|
|
38
37
|
export * from './template-transforms/vir-html/html-interpolation.js';
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,6 @@ export * from './declarative-element/properties/tag-name.js';
|
|
|
32
32
|
export * from './declarative-element/render-callback.js';
|
|
33
33
|
export * from './declarative-element/wrap-define-element.js';
|
|
34
34
|
export * from './lit-exports/all-lit-exports.js';
|
|
35
|
-
export * from './require-declarative-element.js';
|
|
36
35
|
export * from './template-transforms/minimal-element-definition.js';
|
|
37
36
|
export * from './template-transforms/vir-css/vir-css.js';
|
|
38
37
|
export * from './template-transforms/vir-html/html-interpolation.js';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
2
|
import { check } from '@augment-vir/assert';
|
|
3
|
-
import {
|
|
3
|
+
import { getOrSet } from '@augment-vir/common';
|
|
4
4
|
import { assign } from '../../declarative-element/directives/assign.directive.js';
|
|
5
|
-
import { declarativeElementRequired } from '../../require-declarative-element.js';
|
|
6
5
|
import { hasTagName, isMinimalDefinitionWithInputs, } from '../minimal-element-definition.js';
|
|
7
6
|
import { transformTemplate } from '../transform-template.js';
|
|
8
7
|
import { tagNameKeys } from './tag-name-keys.js';
|
|
@@ -74,25 +73,6 @@ function transformHtml(...[lastNewString, currentTemplateString, rawCurrentValue
|
|
|
74
73
|
},
|
|
75
74
|
};
|
|
76
75
|
}
|
|
77
|
-
function extractCustomElementTags(input) {
|
|
78
|
-
const tagNameMatches = safeMatch(input, /<\/\s*[^\s><]+\s*>/g);
|
|
79
|
-
return tagNameMatches.reduce((accum, match) => {
|
|
80
|
-
const tagName = collapseWhiteSpace(match.replace(/\n/g, ' ')).replace(/<\/|>/g, '');
|
|
81
|
-
// custom elements always have a dash in them
|
|
82
|
-
if (tagName.includes('-')) {
|
|
83
|
-
return accum.concat(tagName);
|
|
84
|
-
}
|
|
85
|
-
return accum;
|
|
86
|
-
}, []);
|
|
87
|
-
}
|
|
88
|
-
function stringValidator(input) {
|
|
89
|
-
if (declarativeElementRequired) {
|
|
90
|
-
const customElementTagNames = extractCustomElementTags(input);
|
|
91
|
-
if (customElementTagNames.length) {
|
|
92
|
-
console.error(`Custom element tags must be interpolated from declarative elements: ${customElementTagNames.join(', ')}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
76
|
export function transformHtmlTemplate(litTemplate) {
|
|
97
|
-
return transformTemplate(litTemplate.strings, litTemplate.values, transformHtml
|
|
77
|
+
return transformTemplate(litTemplate.strings, litTemplate.values, transformHtml);
|
|
98
78
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyApp: import("element-vir").DeclarativeElementDefinition<"my-app", {}, {}, {}, "my-app-", "my-app-", readonly [], readonly []>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html } from '../index.js';
|
|
3
|
-
import { MySimple } from './my-simple.element.js';
|
|
4
|
-
export const MyApp = defineElement()({
|
|
5
|
-
tagName: 'my-app',
|
|
6
|
-
render() {
|
|
7
|
-
return html `
|
|
8
|
-
<h1>My App</h1>
|
|
9
|
-
<${MySimple}></${MySimple}>
|
|
10
|
-
`;
|
|
11
|
-
},
|
|
12
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyCustomActionEvent: import("../index.js").DefinedTypedEvent<"my-custom-action", number>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type VirTagName = `vir-${string}`;
|
|
2
|
-
export declare const defineVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>, const TestIds extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
3
|
-
export declare const defineVerifiedVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>, const TestIds extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
4
|
-
export declare const defineTransformedVirElement: <Inputs extends {}>(...errorParams: import("../index.js").DeclarativeElementInputErrorParams<Inputs>) => <const TagName extends `vir-${string}`, State extends {}, EventsInit extends {}, const HostClassKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const CssVarKeys extends import("../index.js").BaseStringName<TagName> = `${TagName}-`, const SlotNames extends ReadonlyArray<string> = Readonly<[]>, const TestIds extends ReadonlyArray<string> = Readonly<[]>>(inputs: import("../index.js").DeclarativeElementInit<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>) => import("../index.js").DeclarativeElementDefinition<TagName, Inputs, State, EventsInit, HostClassKeys, CssVarKeys, SlotNames, TestIds>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { wrapDefineElement } from '../index.js';
|
|
2
|
-
export const defineVirElement = wrapDefineElement();
|
|
3
|
-
// add an optional assert callback
|
|
4
|
-
export const defineVerifiedVirElement = wrapDefineElement({
|
|
5
|
-
assertInputs: (inputs) => {
|
|
6
|
-
if (!inputs.tagName.startsWith('vir-')) {
|
|
7
|
-
throw new Error('all custom elements must start with "vir-"');
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
// add an optional transform callback
|
|
12
|
-
export const defineTransformedVirElement = wrapDefineElement({
|
|
13
|
-
transformInputs: (inputs) => {
|
|
14
|
-
return {
|
|
15
|
-
...inputs,
|
|
16
|
-
tagName: inputs.tagName.startsWith('vir-') ? `vir-${inputs.tagName}` : inputs.tagName,
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MySimple: import("element-vir").DeclarativeElementDefinition<"my-simple", {}, {}, {}, "my-simple-", "my-simple-", readonly [], readonly []>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyWithAssignment: import("element-vir").DeclarativeElementDefinition<"my-with-assignment", {}, {}, {}, "my-with-assignment-", "my-with-assignment-", readonly [], readonly []>;
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
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,49 +0,0 @@
|
|
|
1
|
-
import { asyncProp, defineElement, html, listen, renderAsync } from '../index.js';
|
|
2
|
-
async function loadSomething(endpoint) {
|
|
3
|
-
// load something from the network
|
|
4
|
-
const data = await (await fetch([
|
|
5
|
-
'',
|
|
6
|
-
'api',
|
|
7
|
-
endpoint,
|
|
8
|
-
].join('/'))).json();
|
|
9
|
-
return data;
|
|
10
|
-
}
|
|
11
|
-
export const MyWithAsyncProp = defineElement()({
|
|
12
|
-
tagName: 'my-with-async-prop',
|
|
13
|
-
state() {
|
|
14
|
-
return {
|
|
15
|
-
data: asyncProp({
|
|
16
|
-
async updateCallback({ endpoint }) {
|
|
17
|
-
return loadSomething(endpoint);
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
hi: '',
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
render({ inputs, state }) {
|
|
24
|
-
/**
|
|
25
|
-
* This causes the a promise which automatically updates the state.data prop once the
|
|
26
|
-
* promise resolves. It only creates a new promise if the first input, the trigger, value
|
|
27
|
-
* changes from previous calls.
|
|
28
|
-
*/
|
|
29
|
-
state.data.update(inputs);
|
|
30
|
-
return html `
|
|
31
|
-
Here's the data:
|
|
32
|
-
<br />
|
|
33
|
-
${renderAsync(state.data, 'Loading...', (loadedData) => {
|
|
34
|
-
return html `
|
|
35
|
-
Got the data: ${loadedData}
|
|
36
|
-
`;
|
|
37
|
-
})}
|
|
38
|
-
<br />
|
|
39
|
-
<button
|
|
40
|
-
${listen('click', () => {
|
|
41
|
-
/** You can force asyncProp to update by calling forceUpdate. */
|
|
42
|
-
state.data.forceUpdate(inputs);
|
|
43
|
-
})}
|
|
44
|
-
>
|
|
45
|
-
Refresh
|
|
46
|
-
</button>
|
|
47
|
-
`;
|
|
48
|
-
},
|
|
49
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html } from '../index.js';
|
|
3
|
-
export const MyWithAssignmentCleanupCallback = defineElement()({
|
|
4
|
-
tagName: 'my-with-cleanup-callback',
|
|
5
|
-
state() {
|
|
6
|
-
return {
|
|
7
|
-
intervalId: window.setInterval(() => console.info('hi'), 1000),
|
|
8
|
-
};
|
|
9
|
-
},
|
|
10
|
-
render() {
|
|
11
|
-
return html `
|
|
12
|
-
<h1>My App</h1>
|
|
13
|
-
`;
|
|
14
|
-
},
|
|
15
|
-
cleanup({ state }) {
|
|
16
|
-
window.clearInterval(state.intervalId);
|
|
17
|
-
},
|
|
18
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
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,25 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { css, html } from '../index.js';
|
|
3
|
-
export const MyWithCssVars = defineElement()({
|
|
4
|
-
tagName: 'my-with-css-vars',
|
|
5
|
-
cssVars: {
|
|
6
|
-
/** The value assigned here ('blue') becomes the fallback value for this CSS var. */
|
|
7
|
-
'my-with-css-vars-my-var': 'blue',
|
|
8
|
-
},
|
|
9
|
-
styles: ({ cssVars }) => css `
|
|
10
|
-
:host {
|
|
11
|
-
/*
|
|
12
|
-
Set CSS vars (or reference the name directly) via the ".name" property
|
|
13
|
-
*/
|
|
14
|
-
${cssVars['my-with-css-vars-my-var'].name}: yellow;
|
|
15
|
-
/*
|
|
16
|
-
Use CSS vars with the ".value" property. This includes a "var" wrapper and the
|
|
17
|
-
assigned fallback value (which in this case is 'blue').
|
|
18
|
-
*/
|
|
19
|
-
color: ${cssVars['my-with-css-vars-my-var'].value};
|
|
20
|
-
}
|
|
21
|
-
`,
|
|
22
|
-
render() {
|
|
23
|
-
return html ``;
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyWithCustomEvents: import("element-vir").DeclarativeElementDefinition<"my-with-custom-events", {}, {}, {}, "my-with-custom-events-", "my-with-custom-events-", readonly [], readonly []>;
|
|
@@ -1,25 +0,0 @@
|
|
|
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({
|
|
17
|
-
min: 0,
|
|
18
|
-
max: 1_000_000,
|
|
19
|
-
})));
|
|
20
|
-
})}
|
|
21
|
-
></div>
|
|
22
|
-
</div>
|
|
23
|
-
`;
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html, listen } from '../index.js';
|
|
3
|
-
import { MyWithEvents } from './my-with-events.element.js';
|
|
4
|
-
export const MyWithEventListening = defineElement()({
|
|
5
|
-
tagName: 'my-with-event-listening',
|
|
6
|
-
state() {
|
|
7
|
-
return {
|
|
8
|
-
myNumber: -1,
|
|
9
|
-
};
|
|
10
|
-
},
|
|
11
|
-
render({ state, updateState }) {
|
|
12
|
-
return html `
|
|
13
|
-
<h1>My App</h1>
|
|
14
|
-
<${MyWithEvents}
|
|
15
|
-
${listen(MyWithEvents.events.logoutClick, () => {
|
|
16
|
-
console.info('logout triggered');
|
|
17
|
-
})}
|
|
18
|
-
${listen(MyWithEvents.events.randomNumber, (event) => {
|
|
19
|
-
updateState({
|
|
20
|
-
myNumber: event.detail,
|
|
21
|
-
});
|
|
22
|
-
})}
|
|
23
|
-
></${MyWithEvents}>
|
|
24
|
-
<span>${state.myNumber}</span>
|
|
25
|
-
`;
|
|
26
|
-
},
|
|
27
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
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 []>;
|
|
@@ -1,23 +0,0 @@
|
|
|
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({
|
|
15
|
-
min: 0,
|
|
16
|
-
max: 1_000_000,
|
|
17
|
-
}))))}
|
|
18
|
-
>
|
|
19
|
-
generate random number
|
|
20
|
-
</button>
|
|
21
|
-
`;
|
|
22
|
-
},
|
|
23
|
-
});
|
|
@@ -1,3 +0,0 @@
|
|
|
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,42 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { css, html } from '../index.js';
|
|
3
|
-
export const MyWithHostClassDefinition = defineElement()({
|
|
4
|
-
tagName: 'my-with-host-class-definition',
|
|
5
|
-
state() {
|
|
6
|
-
return {
|
|
7
|
-
myProp: 'hello there',
|
|
8
|
-
};
|
|
9
|
-
},
|
|
10
|
-
hostClasses: {
|
|
11
|
-
/**
|
|
12
|
-
* Setting the value to false means this host class will never be automatically applied. It
|
|
13
|
-
* will simply be a static member on the element for manual application in consumers.
|
|
14
|
-
*/
|
|
15
|
-
'my-with-host-class-definition-a': false,
|
|
16
|
-
/**
|
|
17
|
-
* This host class will be automatically applied if the given callback is evaluated to true
|
|
18
|
-
* after a call to render.
|
|
19
|
-
*/
|
|
20
|
-
'my-with-host-class-definition-automatic': ({ state }) => {
|
|
21
|
-
return state.myProp === 'foo';
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
/**
|
|
25
|
-
* Apply styles to the host classes by using a callback for "styles". The callback's argument
|
|
26
|
-
* contains the host classes defined above in the "hostClasses" property.
|
|
27
|
-
*/
|
|
28
|
-
styles: ({ hostClasses }) => css `
|
|
29
|
-
${hostClasses['my-with-host-class-definition-automatic'].selector} {
|
|
30
|
-
color: blue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
${hostClasses['my-with-host-class-definition-a'].selector} {
|
|
34
|
-
color: red;
|
|
35
|
-
}
|
|
36
|
-
`,
|
|
37
|
-
render({ state }) {
|
|
38
|
-
return html `
|
|
39
|
-
${state.myProp}
|
|
40
|
-
`;
|
|
41
|
-
},
|
|
42
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
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,13 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html } from '../index.js';
|
|
3
|
-
import { MyWithHostClassDefinition } from './my-with-host-class-definition.element.js';
|
|
4
|
-
export const MyWithHostClassUsage = defineElement()({
|
|
5
|
-
tagName: 'my-with-host-class-usage',
|
|
6
|
-
render() {
|
|
7
|
-
return html `
|
|
8
|
-
<${MyWithHostClassDefinition}
|
|
9
|
-
class=${MyWithHostClassDefinition.hostClasses['my-with-host-class-definition-a']}
|
|
10
|
-
></${MyWithHostClassDefinition}>
|
|
11
|
-
`;
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
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,17 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html, onDomCreated } from '../index.js';
|
|
3
|
-
export const MyWithOnDomCreated = defineElement()({
|
|
4
|
-
tagName: 'my-with-on-dom-created',
|
|
5
|
-
render() {
|
|
6
|
-
return html `
|
|
7
|
-
<span
|
|
8
|
-
${onDomCreated((element) => {
|
|
9
|
-
// logs a span element
|
|
10
|
-
console.info(element);
|
|
11
|
-
})}
|
|
12
|
-
>
|
|
13
|
-
Hello there!
|
|
14
|
-
</span>
|
|
15
|
-
`;
|
|
16
|
-
},
|
|
17
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyWithOnResize: import("element-vir").DeclarativeElementDefinition<"my-with-on-resize", {}, {}, {}, "my-with-on-resize-", "my-with-on-resize-", readonly [], readonly []>;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { css, html } from '../index.js';
|
|
3
|
-
import { MySimple } from './my-simple.element.js';
|
|
4
|
-
export const MyWithStylesAndInterpolatedSelector = defineElement()({
|
|
5
|
-
tagName: 'my-with-styles-and-interpolated-selector',
|
|
6
|
-
styles: css `
|
|
7
|
-
${MySimple} {
|
|
8
|
-
background-color: blue;
|
|
9
|
-
}
|
|
10
|
-
`,
|
|
11
|
-
render() {
|
|
12
|
-
return html `
|
|
13
|
-
<${MySimple}></${MySimple}>
|
|
14
|
-
`;
|
|
15
|
-
},
|
|
16
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MyWithStyles: import("element-vir").DeclarativeElementDefinition<"my-with-styles", {}, {}, {}, "my-with-styles-", "my-with-styles-", readonly [], readonly []>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { css, html } from '../index.js';
|
|
3
|
-
export const MyWithStyles = defineElement()({
|
|
4
|
-
tagName: 'my-with-styles',
|
|
5
|
-
styles: css `
|
|
6
|
-
:host {
|
|
7
|
-
display: flex;
|
|
8
|
-
flex-direction: column;
|
|
9
|
-
font-family: sans-serif;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
span + span {
|
|
13
|
-
margin-top: 16px;
|
|
14
|
-
}
|
|
15
|
-
`,
|
|
16
|
-
render() {
|
|
17
|
-
return html `
|
|
18
|
-
<span>Hello there!</span>
|
|
19
|
-
<span>How are you doing?</span>
|
|
20
|
-
`;
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
1
|
-
import { defineElement } from 'element-vir';
|
|
2
|
-
import { html, listen } from '../index.js';
|
|
3
|
-
export const MyWithUpdateState = defineElement()({
|
|
4
|
-
tagName: 'my-with-update-state',
|
|
5
|
-
state() {
|
|
6
|
-
return {
|
|
7
|
-
username: 'dev',
|
|
8
|
-
/**
|
|
9
|
-
* Use "as" to create state properties that can be types other than the initial value's
|
|
10
|
-
* type. This is particularly useful when, as below, the initial value is undefined.
|
|
11
|
-
*/
|
|
12
|
-
email: undefined,
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
render({ state, updateState }) {
|
|
16
|
-
return html `
|
|
17
|
-
<span
|
|
18
|
-
${listen('click', () => {
|
|
19
|
-
updateState({
|
|
20
|
-
username: 'new name!',
|
|
21
|
-
});
|
|
22
|
-
})}
|
|
23
|
-
>
|
|
24
|
-
Hello there ${state.username}!
|
|
25
|
-
</span>
|
|
26
|
-
`;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
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,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set by {@link requireAllCustomElementsToBeDeclarativeElements} and read in the HTML tagged
|
|
3
|
-
* template function.
|
|
4
|
-
*
|
|
5
|
-
* @category Internal
|
|
6
|
-
*/
|
|
7
|
-
export let declarativeElementRequired = false;
|
|
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 function requireAllCustomElementsToBeDeclarativeElements() {
|
|
15
|
-
declarativeElementRequired = true;
|
|
16
|
-
}
|