element-vir 25.3.1 → 25.4.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.
@@ -0,0 +1,30 @@
1
+ import { type Primitive } from 'type-fest';
2
+ import { nothing } from '../../lit-exports/all-lit-exports.js';
3
+ /**
4
+ * Possible attribute values for {@link AttributeValues}.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export type AttributeValue = Exclude<Primitive, symbol> | string | typeof nothing;
9
+ /**
10
+ * Parameters object for applying attributes to an HTML element via the {@link attributes} directive.
11
+ * Make sure that all keys (attribute names) are lowercase.
12
+ *
13
+ * @category Internal
14
+ */
15
+ export type AttributeValues = {
16
+ [LowercaseKey in Lowercase<string>]: AttributeValue;
17
+ };
18
+ /**
19
+ * A directive applies multiple HTML attributes to the parent element all at once.
20
+ *
21
+ * @category Directives
22
+ */
23
+ export declare const attributes: (values_0: AttributeValues) => import("lit-html/directive.js").DirectiveResult<{
24
+ new (partInfo: import("lit-html/directive.js").PartInfo): {
25
+ readonly element: HTMLElement;
26
+ render(params_0: AttributeValues): symbol;
27
+ readonly _$isConnected: boolean;
28
+ update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
29
+ };
30
+ }>;
@@ -0,0 +1,32 @@
1
+ import { getObjectTypedKeys, getOrSet } from '@augment-vir/common';
2
+ import { nothing } from '../../lit-exports/all-lit-exports.js';
3
+ import { createMutateDirective } from './mutate.directive.js';
4
+ /**
5
+ * A directive applies multiple HTML attributes to the parent element all at once.
6
+ *
7
+ * @category Directives
8
+ */
9
+ export const attributes = createMutateDirective('attributes', ({ element, params: [attributesToApply], directive: rawDirective }) => {
10
+ const directive = rawDirective;
11
+ const allAttributeNames = getOrSet(directive, 'allAttributesApplied', () => new Set());
12
+ getObjectTypedKeys(attributesToApply).forEach((attributeName) => {
13
+ if (attributeName.toLowerCase() !== attributeName) {
14
+ throw new Error(`Cannot assign attribute name with uppercase letters: ${attributeName}`);
15
+ }
16
+ allAttributeNames.add(attributeName);
17
+ });
18
+ allAttributeNames.forEach((attributeName) => {
19
+ const attributeValue = attributesToApply[attributeName];
20
+ if (attributeValue == undefined ||
21
+ attributeValue === false ||
22
+ attributeValue === nothing) {
23
+ element.removeAttribute(attributeName);
24
+ }
25
+ else if (attributeValue === '' || attributeValue === true) {
26
+ element.setAttribute(attributeName, '');
27
+ }
28
+ else {
29
+ element.setAttribute(attributeName, String(attributeValue));
30
+ }
31
+ });
32
+ });
@@ -0,0 +1,38 @@
1
+ import { Directive, type PartInfo } from '../../lit-exports/all-lit-exports.js';
2
+ /**
3
+ * Parameters for the callback given to the {@link mutate} directive.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export type MutateDirectiveParams<Params extends any[] = []> = {
8
+ directive: Directive;
9
+ element: HTMLElement;
10
+ params: Params;
11
+ };
12
+ /**
13
+ * A directive that allows arbitrary modifications to be made to the element that it's attached to.
14
+ *
15
+ * @category Directives
16
+ */
17
+ export declare const mutate: (callback: (params: Omit<MutateDirectiveParams, "params">) => void) => import("lit-html/directive.js").DirectiveResult<{
18
+ new (partInfo: PartInfo): {
19
+ readonly element: HTMLElement;
20
+ lastKey: string | undefined;
21
+ render(callback: (params: Omit<MutateDirectiveParams, "params">) => void): symbol;
22
+ readonly _$isConnected: boolean;
23
+ update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
24
+ };
25
+ }>;
26
+ /**
27
+ * A helper for making new directives.
28
+ *
29
+ * @category Internal
30
+ */
31
+ export declare function createMutateDirective<Params extends any[]>(directiveName: string, callback: (this: void, params: MutateDirectiveParams<Params>) => void): (...values: Params) => import("lit-html/directive.js").DirectiveResult<{
32
+ new (partInfo: PartInfo): {
33
+ readonly element: HTMLElement;
34
+ render(...params: Params): symbol;
35
+ readonly _$isConnected: boolean;
36
+ update(_part: import("lit-html").Part, props: Array<unknown>): unknown;
37
+ };
38
+ }>;
@@ -0,0 +1,45 @@
1
+ import { assertWrap } from '@augment-vir/assert';
2
+ import { directive, Directive, noChange } from '../../lit-exports/all-lit-exports.js';
3
+ import { extractElement } from './directive-helpers.js';
4
+ /**
5
+ * A directive that allows arbitrary modifications to be made to the element that it's attached to.
6
+ *
7
+ * @category Directives
8
+ */
9
+ export const mutate = directive(class extends Directive {
10
+ element;
11
+ lastKey;
12
+ constructor(partInfo) {
13
+ super(partInfo);
14
+ this.element = assertWrap.instanceOf(extractElement(partInfo, 'modifyElement'), HTMLElement);
15
+ }
16
+ render(callback) {
17
+ callback({
18
+ directive: this,
19
+ element: this.element,
20
+ });
21
+ return noChange;
22
+ }
23
+ });
24
+ /**
25
+ * A helper for making new directives.
26
+ *
27
+ * @category Internal
28
+ */
29
+ export function createMutateDirective(directiveName, callback) {
30
+ return directive(class extends Directive {
31
+ element;
32
+ constructor(partInfo) {
33
+ super(partInfo);
34
+ this.element = assertWrap.instanceOf(extractElement(partInfo, directiveName), HTMLElement);
35
+ }
36
+ render(...params) {
37
+ callback({
38
+ params: params,
39
+ directive: this,
40
+ element: this.element,
41
+ });
42
+ return noChange;
43
+ }
44
+ });
45
+ }
package/dist/index.d.ts CHANGED
@@ -6,9 +6,11 @@ export * from './declarative-element/define-element-no-inputs.js';
6
6
  export * from './declarative-element/define-element.js';
7
7
  export * from './declarative-element/definition-options.js';
8
8
  export * from './declarative-element/directives/async-prop.js';
9
+ export * from './declarative-element/directives/attributes.directive.js';
9
10
  export * from './declarative-element/directives/create-attribute-directive.js';
10
11
  export * from './declarative-element/directives/directive-helpers.js';
11
12
  export * from './declarative-element/directives/listen.directive.js';
13
+ export * from './declarative-element/directives/mutate.directive.js';
12
14
  export * from './declarative-element/directives/on-dom-created.directive.js';
13
15
  export * from './declarative-element/directives/on-dom-rendered.directive.js';
14
16
  export * from './declarative-element/directives/on-intersect.directive.js';
package/dist/index.js CHANGED
@@ -6,9 +6,11 @@ export * from './declarative-element/define-element-no-inputs.js';
6
6
  export * from './declarative-element/define-element.js';
7
7
  export * from './declarative-element/definition-options.js';
8
8
  export * from './declarative-element/directives/async-prop.js';
9
+ export * from './declarative-element/directives/attributes.directive.js';
9
10
  export * from './declarative-element/directives/create-attribute-directive.js';
10
11
  export * from './declarative-element/directives/directive-helpers.js';
11
12
  export * from './declarative-element/directives/listen.directive.js';
13
+ export * from './declarative-element/directives/mutate.directive.js';
12
14
  export * from './declarative-element/directives/on-dom-created.directive.js';
13
15
  export * from './declarative-element/directives/on-dom-rendered.directive.js';
14
16
  export * from './declarative-element/directives/on-intersect.directive.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "25.3.1",
3
+ "version": "25.4.1",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -38,21 +38,21 @@
38
38
  "test:docs": "virmator docs check"
39
39
  },
40
40
  "dependencies": {
41
- "@augment-vir/assert": "^31.18.0",
42
- "@augment-vir/common": "^31.18.0",
41
+ "@augment-vir/assert": "^31.20.0",
42
+ "@augment-vir/common": "^31.20.0",
43
43
  "date-vir": "^7.3.1",
44
44
  "lit": "^3.3.0",
45
45
  "lit-css-vars": "^3.0.11",
46
46
  "lit-html": "^3.3.0",
47
47
  "object-shape-tester": "^5.1.5",
48
48
  "observavir": "^2.0.5",
49
- "typed-event-target": "^4.0.4"
49
+ "typed-event-target": "^4.1.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@augment-vir/test": "^31.18.0",
53
- "@augment-vir/web": "^31.18.0",
52
+ "@augment-vir/test": "^31.20.0",
53
+ "@augment-vir/web": "^31.20.0",
54
54
  "@web/dev-server-esbuild": "^1.0.4",
55
- "@web/test-runner": "^0.20.1",
55
+ "@web/test-runner": "^0.20.2",
56
56
  "@web/test-runner-commands": "^0.9.0",
57
57
  "@web/test-runner-playwright": "^0.11.0",
58
58
  "@web/test-runner-visual-regression": "^0.10.0",