element-vir 22.2.2 → 23.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -38
- package/dist/declarative-element/custom-tag-name.d.ts +6 -0
- package/dist/declarative-element/declarative-element-init.d.ts +20 -14
- package/dist/declarative-element/declarative-element.d.ts +70 -24
- package/dist/declarative-element/declarative-element.js +34 -1
- package/dist/declarative-element/define-element-no-inputs.d.ts +31 -6
- package/dist/declarative-element/define-element-no-inputs.js +154 -257
- package/dist/declarative-element/define-element.d.ts +35 -7
- package/dist/declarative-element/define-element.js +26 -4
- package/dist/declarative-element/definition-options.d.ts +10 -0
- package/dist/declarative-element/definition-options.js +5 -0
- package/dist/declarative-element/directives/assign.directive.d.ts +8 -11
- package/dist/declarative-element/directives/assign.directive.js +6 -13
- package/dist/declarative-element/directives/async-prop.d.ts +19 -4
- package/dist/declarative-element/directives/async-prop.js +14 -4
- package/dist/declarative-element/directives/create-attribute-directive.d.ts +19 -4
- package/dist/declarative-element/directives/create-attribute-directive.js +18 -8
- package/dist/declarative-element/directives/directive-helpers.d.ts +19 -4
- package/dist/declarative-element/directives/directive-helpers.js +14 -2
- package/dist/declarative-element/directives/is-resolved.directive.d.ts +107 -1
- package/dist/declarative-element/directives/is-resolved.directive.js +107 -1
- package/dist/declarative-element/directives/listen.directive.d.ts +84 -10
- package/dist/declarative-element/directives/listen.directive.js +5 -15
- package/dist/declarative-element/directives/on-dom-created.directive.d.ts +37 -4
- package/dist/declarative-element/directives/on-dom-created.directive.js +32 -12
- package/dist/declarative-element/directives/on-dom-rendered.directive.d.ts +33 -3
- package/dist/declarative-element/directives/on-dom-rendered.directive.js +29 -6
- package/dist/declarative-element/directives/on-resize.directive.d.ts +37 -4
- package/dist/declarative-element/directives/on-resize.directive.js +37 -24
- package/dist/declarative-element/directives/render-async.directive.d.ts +44 -4
- package/dist/declarative-element/directives/render-async.directive.js +13 -3
- package/dist/declarative-element/directives/render-if.directive.d.ts +31 -0
- package/dist/declarative-element/directives/render-if.directive.js +32 -1
- package/dist/declarative-element/directives/test-id.directive.d.ts +48 -4
- package/dist/declarative-element/directives/test-id.directive.js +47 -2
- package/dist/declarative-element/has-declarative-element-parent.js +1 -1
- package/dist/declarative-element/is-declarative-element-definition.d.ts +15 -1
- package/dist/declarative-element/is-declarative-element-definition.js +21 -18
- package/dist/declarative-element/is-declarative-element.d.ts +5 -1
- package/dist/declarative-element/is-declarative-element.js +7 -3
- package/dist/declarative-element/properties/assign-inputs.js +1 -1
- package/dist/declarative-element/properties/css-properties.d.ts +11 -1
- package/dist/declarative-element/properties/css-properties.js +5 -0
- package/dist/declarative-element/properties/css-vars.d.ts +14 -4
- package/dist/declarative-element/properties/element-events.d.ts +61 -7
- package/dist/declarative-element/properties/element-events.js +40 -5
- package/dist/declarative-element/properties/element-properties.d.ts +15 -6
- package/dist/declarative-element/properties/element-properties.js +1 -21
- package/dist/declarative-element/properties/element-vir-state-setup.d.ts +43 -3
- package/dist/declarative-element/properties/element-vir-state-setup.js +17 -3
- package/dist/declarative-element/properties/host-classes.d.ts +25 -12
- package/dist/declarative-element/properties/host-classes.js +5 -0
- package/dist/declarative-element/properties/per-instance.d.ts +23 -2
- package/dist/declarative-element/properties/per-instance.js +24 -3
- package/dist/declarative-element/properties/property-proxy.d.ts +19 -4
- package/dist/declarative-element/properties/property-proxy.js +14 -4
- package/dist/declarative-element/properties/styles.d.ts +33 -8
- package/dist/declarative-element/properties/styles.js +12 -2
- package/dist/declarative-element/properties/tag-name.d.ts +5 -0
- package/dist/declarative-element/render-callback.d.ts +38 -11
- package/dist/declarative-element/render-callback.js +6 -0
- package/dist/declarative-element/slot-names.d.ts +10 -2
- package/dist/declarative-element/slot-names.js +5 -1
- package/dist/declarative-element/wrap-define-element.d.ts +38 -11
- package/dist/declarative-element/wrap-define-element.js +17 -2
- package/dist/index.d.ts +40 -40
- package/dist/index.js +40 -39
- package/dist/lit-exports/all-lit-exports.d.ts +2 -2
- package/dist/lit-exports/all-lit-exports.js +2 -2
- package/dist/lit-exports/lit-repeat-fix.d.ts +60 -4
- package/dist/lit-exports/lit-repeat-fix.js +35 -1
- package/dist/readme-examples/my-app.element.d.ts +1 -0
- package/dist/readme-examples/my-app.element.js +11 -0
- package/dist/readme-examples/my-custom-action.event.d.ts +1 -0
- package/dist/readme-examples/my-custom-action.event.js +2 -0
- package/dist/readme-examples/my-custom-define.d.ts +4 -0
- package/dist/readme-examples/my-custom-define.js +19 -0
- package/dist/readme-examples/my-simple.element.d.ts +1 -0
- package/dist/readme-examples/my-simple.element.js +9 -0
- package/dist/readme-examples/my-with-assignment.element.d.ts +1 -0
- package/dist/readme-examples/my-with-assignment.element.js +14 -0
- package/dist/readme-examples/my-with-async-prop.element.d.ts +9 -0
- package/dist/readme-examples/my-with-async-prop.element.js +46 -0
- package/dist/readme-examples/my-with-cleanup-callback.element.d.ts +3 -0
- package/dist/readme-examples/my-with-cleanup-callback.element.js +23 -0
- package/dist/readme-examples/my-with-css-vars.element.d.ts +1 -0
- package/dist/readme-examples/my-with-css-vars.element.js +24 -0
- package/dist/readme-examples/my-with-custom-events.element.d.ts +1 -0
- package/dist/readme-examples/my-with-custom-events.element.js +21 -0
- package/dist/readme-examples/my-with-event-listening.element.d.ts +3 -0
- package/dist/readme-examples/my-with-event-listening.element.js +22 -0
- package/dist/readme-examples/my-with-events.element.d.ts +4 -0
- package/dist/readme-examples/my-with-events.element.js +19 -0
- package/dist/readme-examples/my-with-host-class-definition.element.d.ts +3 -0
- package/dist/readme-examples/my-with-host-class-definition.element.js +39 -0
- package/dist/readme-examples/my-with-host-class-usage.element.d.ts +1 -0
- package/dist/readme-examples/my-with-host-class-usage.element.js +12 -0
- package/dist/readme-examples/my-with-inputs.element.d.ts +4 -0
- package/dist/readme-examples/my-with-inputs.element.js +9 -0
- package/dist/readme-examples/my-with-on-dom-created.element.d.ts +1 -0
- package/dist/readme-examples/my-with-on-dom-created.element.js +16 -0
- package/dist/readme-examples/my-with-on-resize.element.d.ts +1 -0
- package/dist/readme-examples/my-with-on-resize.element.js +17 -0
- package/dist/readme-examples/my-with-render-if.element.d.ts +3 -0
- package/dist/readme-examples/my-with-render-if.element.js +11 -0
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.d.ts +1 -0
- package/dist/readme-examples/my-with-styles-and-interpolated-selector.element.js +15 -0
- package/dist/readme-examples/my-with-styles.element.d.ts +1 -0
- package/dist/readme-examples/my-with-styles.element.js +21 -0
- package/dist/readme-examples/my-with-update-state.element.d.ts +8 -0
- package/dist/readme-examples/my-with-update-state.element.js +23 -0
- package/dist/readme-examples/require-declarative-element.d.ts +1 -0
- package/dist/readme-examples/require-declarative-element.js +2 -0
- package/dist/require-declarative-element.d.ts +12 -0
- package/dist/require-declarative-element.js +12 -0
- package/dist/template-transforms/minimal-element-definition.d.ts +30 -2
- package/dist/template-transforms/minimal-element-definition.js +14 -3
- package/dist/template-transforms/nested-mapped-templates.d.ts +1 -1
- package/dist/template-transforms/nested-mapped-templates.js +4 -3
- package/dist/template-transforms/template-transform-type.d.ts +1 -1
- package/dist/template-transforms/transform-template.d.ts +1 -1
- package/dist/template-transforms/transform-template.js +17 -21
- package/dist/template-transforms/vir-css/css-transform.d.ts +3 -3
- package/dist/template-transforms/vir-css/css-transform.js +3 -2
- package/dist/template-transforms/vir-css/vir-css.d.ts +11 -2
- package/dist/template-transforms/vir-css/vir-css.js +11 -2
- package/dist/template-transforms/vir-html/html-interpolation.d.ts +9 -5
- package/dist/template-transforms/vir-html/html-transform.d.ts +3 -3
- package/dist/template-transforms/vir-html/html-transform.js +14 -12
- package/dist/template-transforms/vir-html/vir-html.d.ts +4 -2
- package/dist/template-transforms/vir-html/vir-html.js +4 -2
- package/dist/typed-event/typed-event.d.ts +42 -6
- package/dist/typed-event/typed-event.js +31 -28
- package/dist/util/lit-template.d.ts +6 -1
- package/dist/util/lit-template.js +10 -7
- package/dist/util/type.d.ts +5 -0
- package/package.json +37 -35
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { hasTagName } from '../minimal-element-definition.js';
|
|
3
|
+
import { transformTemplate } from '../transform-template.js';
|
|
3
4
|
function transformCss(...[lastNewString, currentLitString, currentValue,]) {
|
|
4
5
|
if (!hasTagName(currentValue)) {
|
|
5
6
|
return undefined;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import { CSSResult, CSSResultGroup } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { MinimalElementDefinition } from '../minimal-element-definition';
|
|
1
|
+
import { CSSResult, CSSResultGroup } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { MinimalElementDefinition } from '../minimal-element-definition.js';
|
|
3
|
+
/**
|
|
4
|
+
* A template literal tag used to define styles for element definitions. In particular, this is used
|
|
5
|
+
* for the `styles` property in an element definitions init object.
|
|
6
|
+
*
|
|
7
|
+
* For security reasons, only literal string or number values may be interpolated inside of this
|
|
8
|
+
* taggedTemplate. To incorporate non-literal values, wrap the value in a call to `unsafeCSS`.
|
|
9
|
+
*
|
|
10
|
+
* @category Element Definition
|
|
11
|
+
*/
|
|
3
12
|
export declare function css(inputTemplateStrings: TemplateStringsArray, ...inputValues: (number | CSSResultGroup | MinimalElementDefinition | CSSResult)[]): CSSResult;
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { css as litCss } from 'lit';
|
|
2
|
-
import { getTransformedTemplate } from '../transform-template';
|
|
3
|
-
import { transformCssTemplate } from './css-transform';
|
|
2
|
+
import { getTransformedTemplate } from '../transform-template.js';
|
|
3
|
+
import { transformCssTemplate } from './css-transform.js';
|
|
4
|
+
/**
|
|
5
|
+
* A template literal tag used to define styles for element definitions. In particular, this is used
|
|
6
|
+
* for the `styles` property in an element definitions init object.
|
|
7
|
+
*
|
|
8
|
+
* For security reasons, only literal string or number values may be interpolated inside of this
|
|
9
|
+
* taggedTemplate. To incorporate non-literal values, wrap the value in a call to `unsafeCSS`.
|
|
10
|
+
*
|
|
11
|
+
* @category Element Definition
|
|
12
|
+
*/
|
|
4
13
|
export function css(inputTemplateStrings, ...inputValues) {
|
|
5
14
|
const transformedTemplate = getTransformedTemplate(inputTemplateStrings, inputValues, () => {
|
|
6
15
|
return transformCssTemplate(inputTemplateStrings, inputValues);
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { AnyFunction } from '@augment-vir/common';
|
|
2
|
-
import { CSSResult, TemplateResult, nothing } from 'lit';
|
|
3
|
-
import { EmptyObject } from 'type-fest';
|
|
4
|
-
import { DeclarativeElementDefinition } from '../../declarative-element/declarative-element';
|
|
5
|
-
import { MinimalDefinitionWithInputs, MinimalElementDefinition } from '../minimal-element-definition';
|
|
1
|
+
import { type AnyFunction } from '@augment-vir/common';
|
|
2
|
+
import { type CSSResult, type TemplateResult, type nothing } from 'lit';
|
|
3
|
+
import { type EmptyObject } from 'type-fest';
|
|
4
|
+
import { type DeclarativeElementDefinition } from '../../declarative-element/declarative-element.js';
|
|
5
|
+
import { type MinimalDefinitionWithInputs, type MinimalElementDefinition } from '../minimal-element-definition.js';
|
|
6
6
|
/**
|
|
7
7
|
* Unfortunately the type for `DirectiveResult` means it's just an empty object. So in order to
|
|
8
8
|
* block actual objects, we have to narrow `DirectiveResult` further to this empty object type.
|
|
9
|
+
*
|
|
10
|
+
* @category Internal
|
|
9
11
|
*/
|
|
10
12
|
export type DirectiveOutput = EmptyObject;
|
|
11
13
|
/**
|
|
12
14
|
* This is used in order to block accidental object interpolations into HTML, which get stringified
|
|
13
15
|
* into `'[object Object]'`, which nobody ever wants that.
|
|
16
|
+
*
|
|
17
|
+
* @category Internal
|
|
14
18
|
*/
|
|
15
19
|
export type HtmlInterpolation = null | undefined | string | number | boolean | bigint | CSSResult | Readonly<CSSResult> | Element | Readonly<Element> | TemplateResult | Readonly<TemplateResult> | MinimalElementDefinition | Readonly<MinimalElementDefinition> | MinimalDefinitionWithInputs | Readonly<MinimalDefinitionWithInputs> | DeclarativeElementDefinition | Readonly<DeclarativeElementDefinition> | DirectiveOutput | Readonly<DirectiveOutput> | AnyFunction | typeof nothing | HtmlInterpolation[] | ReadonlyArray<HtmlInterpolation>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HTMLTemplateResult } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { TemplateTransform } from '../template-transform-type';
|
|
3
|
-
import { HtmlInterpolation } from './html-interpolation';
|
|
1
|
+
import { HTMLTemplateResult } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { TemplateTransform } from '../template-transform-type.js';
|
|
3
|
+
import { HtmlInterpolation } from './html-interpolation.js';
|
|
4
4
|
export declare function mapHtmlValues(inputTemplateStrings: TemplateStringsArray, inputValues: HtmlInterpolation[]): HtmlInterpolation[];
|
|
5
5
|
export declare function transformHtmlTemplate(litTemplate: HTMLTemplateResult): TemplateTransform;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
+
/* eslint-disable sonarjs/deprecation */
|
|
3
|
+
import { check } from '@augment-vir/assert';
|
|
4
|
+
import { collapseWhiteSpace, getOrSet, safeMatch } from '@augment-vir/common';
|
|
5
|
+
import { assign } from '../../declarative-element/directives/assign.directive.js';
|
|
6
|
+
import { declarativeElementRequired } from '../../require-declarative-element.js';
|
|
7
|
+
import { hasTagName, isMinimalDefinitionWithInputs, } from '../minimal-element-definition.js';
|
|
8
|
+
import { transformTemplate } from '../transform-template.js';
|
|
9
|
+
import { tagNameKeys } from './tag-name-keys.js';
|
|
8
10
|
export function mapHtmlValues(inputTemplateStrings, inputValues) {
|
|
9
11
|
return inputValues.map((currentValue, currentValueIndex) => {
|
|
10
12
|
const lastString = inputTemplateStrings[currentValueIndex];
|
|
11
13
|
const nextString = inputTemplateStrings[currentValueIndex + 1];
|
|
12
14
|
if (lastString && nextString) {
|
|
13
15
|
const { shouldHaveTagNameHere } = classifyValue(lastString, nextString);
|
|
14
|
-
if (shouldHaveTagNameHere &&
|
|
16
|
+
if (shouldHaveTagNameHere && check.isString(currentValue)) {
|
|
15
17
|
const replacement = {
|
|
16
18
|
tagName: currentValue,
|
|
17
19
|
tagInterpolationKey: getOrSet(tagNameKeys, currentValue, () => {
|
|
@@ -25,8 +27,8 @@ export function mapHtmlValues(inputTemplateStrings, inputValues) {
|
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
function classifyValue(lastNewString, currentTemplateString) {
|
|
28
|
-
const isOpeningTag = lastNewString.trim().endsWith('<') && !!currentTemplateString.match(/^[\s
|
|
29
|
-
const isClosingTag = lastNewString
|
|
30
|
+
const isOpeningTag = lastNewString.trim().endsWith('<') && !!currentTemplateString.match(/^[\s>]/);
|
|
31
|
+
const isClosingTag = lastNewString.trim().endsWith('</') && currentTemplateString.trim().startsWith('>');
|
|
30
32
|
const shouldHaveTagNameHere = isOpeningTag || isClosingTag;
|
|
31
33
|
return {
|
|
32
34
|
isOpeningTag,
|
|
@@ -73,12 +75,12 @@ function transformHtml(...[lastNewString, currentTemplateString, rawCurrentValue
|
|
|
73
75
|
: undefined;
|
|
74
76
|
return [
|
|
75
77
|
isOpeningTag && assignedInputs ? assign(assignedInputs) : undefined,
|
|
76
|
-
].filter(isTruthy);
|
|
78
|
+
].filter(check.isTruthy);
|
|
77
79
|
},
|
|
78
80
|
};
|
|
79
81
|
}
|
|
80
82
|
function extractCustomElementTags(input) {
|
|
81
|
-
const tagNameMatches = safeMatch(input,
|
|
83
|
+
const tagNameMatches = safeMatch(input, /<\/\s*[^\s><]+\s*>/g);
|
|
82
84
|
return tagNameMatches.reduce((accum, match) => {
|
|
83
85
|
const tagName = collapseWhiteSpace(match.replace(/\n/g, ' ')).replace(/<\/|>/g, '');
|
|
84
86
|
// custom elements always have a dash in them
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { HTMLTemplateResult } from '../../lit-exports/all-lit-exports';
|
|
2
|
-
import { HtmlInterpolation } from './html-interpolation';
|
|
1
|
+
import { HTMLTemplateResult } from '../../lit-exports/all-lit-exports.js';
|
|
2
|
+
import { HtmlInterpolation } from './html-interpolation.js';
|
|
3
3
|
/**
|
|
4
4
|
* Interprets a template literal as an HTML template which is lazily rendered to the DOM.
|
|
5
5
|
*
|
|
6
6
|
* Wraps lit-html's html tagged template and enables interpolations of
|
|
7
7
|
* `DeclarativeElementDefinition` for tag names.
|
|
8
|
+
*
|
|
9
|
+
* @category Element Definition
|
|
8
10
|
*/
|
|
9
11
|
export declare function html(inputTemplateStrings: TemplateStringsArray, ...inputValues: HtmlInterpolation[]): HTMLTemplateResult;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { html as litHtml } from 'lit';
|
|
2
|
-
import { getTransformedTemplate } from '../transform-template';
|
|
3
|
-
import { mapHtmlValues, transformHtmlTemplate } from './html-transform';
|
|
2
|
+
import { getTransformedTemplate } from '../transform-template.js';
|
|
3
|
+
import { mapHtmlValues, transformHtmlTemplate } from './html-transform.js';
|
|
4
4
|
/**
|
|
5
5
|
* Interprets a template literal as an HTML template which is lazily rendered to the DOM.
|
|
6
6
|
*
|
|
7
7
|
* Wraps lit-html's html tagged template and enables interpolations of
|
|
8
8
|
* `DeclarativeElementDefinition` for tag names.
|
|
9
|
+
*
|
|
10
|
+
* @category Element Definition
|
|
9
11
|
*/
|
|
10
12
|
export function html(inputTemplateStrings, ...inputValues) {
|
|
11
13
|
const mappedValues = mapHtmlValues(inputTemplateStrings, inputValues);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { NonEmptyString } from '../util/type';
|
|
1
|
+
import { NonEmptyString } from '../util/type.js';
|
|
2
|
+
/**
|
|
3
|
+
* A custom event with strict types for details and the event's `type` property.
|
|
4
|
+
*
|
|
5
|
+
* @category Internal
|
|
6
|
+
*/
|
|
2
7
|
export declare class TypedEvent<EventTypeNameGeneric extends string = '', EventDetailGeneric = undefined> extends CustomEvent<EventDetailGeneric> {
|
|
3
8
|
readonly _type: EventTypeNameGeneric;
|
|
4
9
|
get type(): EventTypeNameGeneric;
|
|
@@ -6,14 +11,45 @@ export declare class TypedEvent<EventTypeNameGeneric extends string = '', EventD
|
|
|
6
11
|
type: EventTypeNameGeneric;
|
|
7
12
|
}, value: EventDetailGeneric);
|
|
8
13
|
}
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* A function that defines a typed event, used for defining element events in an element's
|
|
16
|
+
* definition.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export type DefineEvent<EventDetailGeneric> = <EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
|
|
21
|
+
/**
|
|
22
|
+
* A concrete typed event definition.
|
|
23
|
+
*
|
|
24
|
+
* @category Internal
|
|
25
|
+
*/
|
|
10
26
|
export type DefinedTypedEvent<EventTypeNameGeneric extends string, EventDetailGeneric> = (new (eventValue: EventDetailGeneric) => TypedEvent<EventTypeNameGeneric, EventDetailGeneric>) & {
|
|
11
27
|
type: EventTypeNameGeneric;
|
|
12
28
|
};
|
|
13
29
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
30
|
+
* Define a stand-alone typed event that can be emitted and listened to inside of HTML templates.
|
|
31
|
+
*
|
|
32
|
+
* Make sure to use currying and call this function twice! (This is required by TypeScript's type
|
|
33
|
+
* parameter inference system.)
|
|
34
|
+
*
|
|
35
|
+
* @category Element Definition
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import {defineTypedEvent} from 'element-vir';
|
|
16
40
|
*
|
|
17
|
-
*
|
|
41
|
+
* const myCustomEvent = defineTypedEvent<number>()('my-custom-event');
|
|
42
|
+
*
|
|
43
|
+
* const myCustomEvent2 = defineTypedEvent<// the event's `.detail` type
|
|
44
|
+
* number>()(
|
|
45
|
+
* // the event's `.type` string
|
|
46
|
+
* 'my-custom-event2',
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function defineTypedEvent<EventDetailGeneric>(): <
|
|
51
|
+
/**
|
|
52
|
+
* EventTypeNameGeneric is used for the event type property but not for the event value
|
|
53
|
+
* type... so it's named "name" instead of "type" cause type is overloaded here.
|
|
18
54
|
*/
|
|
19
|
-
|
|
55
|
+
EventTypeNameGeneric extends string>(eventType: NonEmptyString<EventTypeNameGeneric>) => DefinedTypedEvent<EventTypeNameGeneric, EventDetailGeneric>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A custom event with strict types for details and the event's `type` property.
|
|
3
|
+
*
|
|
4
|
+
* @category Internal
|
|
5
|
+
*/
|
|
1
6
|
export class TypedEvent extends CustomEvent {
|
|
7
|
+
_type = '';
|
|
2
8
|
get type() {
|
|
3
9
|
return this._type;
|
|
4
10
|
}
|
|
@@ -8,40 +14,37 @@ export class TypedEvent extends CustomEvent {
|
|
|
8
14
|
bubbles: true,
|
|
9
15
|
composed: true,
|
|
10
16
|
});
|
|
11
|
-
Object.defineProperty(this, "_type", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
configurable: true,
|
|
14
|
-
writable: true,
|
|
15
|
-
value: ''
|
|
16
|
-
});
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Define a stand-alone typed event that can be emitted and listened to inside of HTML templates.
|
|
21
|
+
*
|
|
22
|
+
* Make sure to use currying and call this function twice! (This is required by TypeScript's type
|
|
23
|
+
* parameter inference system.)
|
|
24
|
+
*
|
|
25
|
+
* @category Element Definition
|
|
26
|
+
* @example
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import {defineTypedEvent} from 'element-vir';
|
|
30
|
+
*
|
|
31
|
+
* const myCustomEvent = defineTypedEvent<number>()('my-custom-event');
|
|
22
32
|
*
|
|
23
|
-
*
|
|
33
|
+
* const myCustomEvent2 = defineTypedEvent<// the event's `.detail` type
|
|
34
|
+
* number>()(
|
|
35
|
+
* // the event's `.type` string
|
|
36
|
+
* 'my-custom-event2',
|
|
37
|
+
* );
|
|
38
|
+
* ```
|
|
24
39
|
*/
|
|
25
40
|
export function defineTypedEvent() {
|
|
26
41
|
return (eventType) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
writable: true,
|
|
35
|
-
value: eventType
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
Object.defineProperty(_a, "type", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: eventType
|
|
44
|
-
}),
|
|
45
|
-
_a;
|
|
42
|
+
return class extends TypedEvent {
|
|
43
|
+
static type = eventType;
|
|
44
|
+
_type = eventType;
|
|
45
|
+
constructor(value) {
|
|
46
|
+
super(eventType, value);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
46
49
|
};
|
|
47
50
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { TemplateResult, unsafeHTML, unsafeSVG } from '../lit-exports/all-lit-exports';
|
|
1
|
+
import type { TemplateResult, unsafeHTML, unsafeSVG } from '../lit-exports/all-lit-exports.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an HTML or SVG template into a raw string.
|
|
4
|
+
*
|
|
5
|
+
* @category Util
|
|
6
|
+
*/
|
|
2
7
|
export declare function convertTemplateToString(template: TemplateResult | ReturnType<typeof unsafeSVG> | ReturnType<typeof unsafeHTML> | {
|
|
3
8
|
templateString: string;
|
|
4
9
|
}): string;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { collapseWhiteSpace } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an HTML or SVG template into a raw string.
|
|
4
|
+
*
|
|
5
|
+
* @category Util
|
|
6
|
+
*/
|
|
2
7
|
export function convertTemplateToString(template) {
|
|
3
8
|
if ('templateString' in template) {
|
|
4
9
|
return template.templateString;
|
|
5
10
|
}
|
|
6
11
|
const { strings, values } = template;
|
|
7
|
-
if (
|
|
12
|
+
if (!strings?.length && !values?.length) {
|
|
8
13
|
return '';
|
|
9
14
|
}
|
|
10
15
|
const valueList = [
|
|
@@ -28,12 +33,10 @@ function extractValue(previousString, value) {
|
|
|
28
33
|
const values = value.map((innerValue) => convertTemplateToString(innerValue));
|
|
29
34
|
return values.join('');
|
|
30
35
|
}
|
|
36
|
+
else if (previousString.endsWith('=')) {
|
|
37
|
+
return `"${value}"`;
|
|
38
|
+
}
|
|
31
39
|
else {
|
|
32
|
-
|
|
33
|
-
return `"${value}"`;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
40
|
+
return value;
|
|
38
41
|
}
|
|
39
42
|
}
|
package/dist/util/type.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-vir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.1.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"custom",
|
|
6
6
|
"web",
|
|
@@ -18,55 +18,57 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/electrovir/element-vir"
|
|
21
|
+
"url": "git+https://github.com/electrovir/element-vir.git"
|
|
22
22
|
},
|
|
23
23
|
"license": "(MIT or CC0 1.0)",
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "electrovir",
|
|
26
26
|
"url": "https://github.com/electrovir"
|
|
27
27
|
},
|
|
28
|
+
"type": "module",
|
|
28
29
|
"main": "dist/index.js",
|
|
30
|
+
"module": "dist/index.js",
|
|
29
31
|
"types": "dist/index.d.ts",
|
|
30
32
|
"scripts": {
|
|
31
|
-
"build
|
|
32
|
-
"compile": "
|
|
33
|
+
"build": "npm run docs",
|
|
34
|
+
"compile": "virmator compile",
|
|
33
35
|
"docs": "virmator docs",
|
|
34
|
-
"
|
|
35
|
-
"test": "
|
|
36
|
-
"test:docs": "virmator docs check"
|
|
37
|
-
"test:types": "tsc --pretty --noEmit"
|
|
36
|
+
"test": "virmator test web",
|
|
37
|
+
"test:coverage": "npm run test coverage",
|
|
38
|
+
"test:docs": "virmator docs check"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@augment-vir/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"lit
|
|
44
|
-
"lit-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"typed-event-target": "^
|
|
41
|
+
"@augment-vir/assert": "^31.0.1",
|
|
42
|
+
"@augment-vir/common": "^31.0.1",
|
|
43
|
+
"date-vir": "^7.0.3",
|
|
44
|
+
"lit": "^3.2.1",
|
|
45
|
+
"lit-css-vars": "^3.0.11",
|
|
46
|
+
"lit-html": "^3.2.1",
|
|
47
|
+
"object-shape-tester": "^3.1.4",
|
|
48
|
+
"observavir": "^2.0.4",
|
|
49
|
+
"typed-event-target": "^4.0.2"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@augment-vir/
|
|
52
|
-
"@augment-vir/
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@open-wc/testing": "^4.0.0",
|
|
56
|
-
"@types/chai": "^4.3.16",
|
|
57
|
-
"@types/mocha": "^10.0.6",
|
|
58
|
-
"@web/dev-server-esbuild": "^1.0.2",
|
|
59
|
-
"@web/test-runner": "^0.18.1",
|
|
52
|
+
"@augment-vir/test": "^31.0.1",
|
|
53
|
+
"@augment-vir/web": "^31.0.1",
|
|
54
|
+
"@web/dev-server-esbuild": "^1.0.3",
|
|
55
|
+
"@web/test-runner": "^0.19.0",
|
|
60
56
|
"@web/test-runner-commands": "^0.9.0",
|
|
61
57
|
"@web/test-runner-playwright": "^0.11.0",
|
|
62
|
-
"@web/test-runner-visual-regression": "^0.
|
|
63
|
-
"html-spec-tags": "^2.2.
|
|
64
|
-
"istanbul-smart-text-reporter": "^1.1.
|
|
65
|
-
"markdown-code-example-inserter": "^
|
|
66
|
-
"type-fest": "^4.
|
|
67
|
-
"typedoc": "^0.
|
|
68
|
-
"typescript": "5.
|
|
69
|
-
"vite": "^
|
|
70
|
-
"vite-tsconfig-paths": "^
|
|
58
|
+
"@web/test-runner-visual-regression": "^0.10.0",
|
|
59
|
+
"html-spec-tags": "^2.2.2",
|
|
60
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
61
|
+
"markdown-code-example-inserter": "^3.0.3",
|
|
62
|
+
"type-fest": "^4.30.0",
|
|
63
|
+
"typedoc": "^0.27.4",
|
|
64
|
+
"typescript": "5.7.2",
|
|
65
|
+
"vite": "^6.0.3",
|
|
66
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=22"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
71
73
|
}
|
|
72
74
|
}
|