element-vir 6.1.0 → 6.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/declarative-element/declarative-element.d.ts +1 -0
- package/dist/declarative-element/define-element-no-inputs.js +8 -1
- package/dist/declarative-element/directives/assign.directive.js +1 -6
- package/package.json +1 -1
- package/dist/augments/testing.d.ts +0 -15
- package/dist/augments/testing.js +0 -76
- package/index.html +0 -14
- package/public/index.css +0 -7
|
@@ -24,6 +24,7 @@ export declare abstract class DeclarativeElement<InputsGeneric extends PropertyI
|
|
|
24
24
|
abstract render(): TemplateResult | Promise<TemplateResult>;
|
|
25
25
|
abstract readonly instanceState: PropertyInitGeneric;
|
|
26
26
|
abstract readonly instanceInputs: InputsGeneric;
|
|
27
|
+
abstract assignInputs(inputs: InputsGeneric): void;
|
|
27
28
|
abstract readonly haveInputsBeenSet: boolean;
|
|
28
29
|
abstract markInputsAsHavingBeenSet(): void;
|
|
29
30
|
abstract readonly creator: DeclarativeElementDefinition<InputsGeneric, PropertyInitGeneric, EventsInitGeneric, HostClassKeys, CssVarKeys>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { kebabCaseToCamelCase } from 'augment-vir';
|
|
1
|
+
import { getObjectTypedKeys, kebabCaseToCamelCase } from 'augment-vir';
|
|
2
2
|
import { css } from 'lit';
|
|
3
3
|
import { property } from 'lit/decorators.js';
|
|
4
4
|
import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
|
|
@@ -79,6 +79,13 @@ export function defineElementNoInputs(initInput) {
|
|
|
79
79
|
});
|
|
80
80
|
return renderResult;
|
|
81
81
|
}
|
|
82
|
+
assignInputs(inputs) {
|
|
83
|
+
getObjectTypedKeys(inputs).forEach((key) => {
|
|
84
|
+
property()(this, key);
|
|
85
|
+
this.instanceInputs[key] = inputs[key];
|
|
86
|
+
});
|
|
87
|
+
this.markInputsAsHavingBeenSet();
|
|
88
|
+
}
|
|
82
89
|
},
|
|
83
90
|
_a.tagName = initInput.tagName,
|
|
84
91
|
_a.styles = calculatedStyles,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { noChange } from 'lit';
|
|
2
|
-
import { property } from 'lit/decorators.js';
|
|
3
2
|
import { directive, Directive } from 'lit/directive.js';
|
|
4
3
|
import { extractDeclarativeElement } from './directive-helpers';
|
|
5
4
|
/** Assign an object matching an element's inputs to its inputs. */
|
|
@@ -25,9 +24,5 @@ export function assignInputsObject(expectedElementConstructor, element, assignme
|
|
|
25
24
|
console.error(element, expectedElementConstructor);
|
|
26
25
|
throw new Error(`Assignment mismatch. Assignment was made for ${element.tagName.toLowerCase()} but it's attached to ${expectedElementConstructor.tagName.toLowerCase()}`);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
property()(element, key);
|
|
30
|
-
element.instanceInputs[key] = assignmentObject[key];
|
|
31
|
-
});
|
|
32
|
-
element.markInputsAsHavingBeenSet();
|
|
27
|
+
element.assignInputs(assignmentObject);
|
|
33
28
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { DeclarativeElementDefinition } from '../declarative-element/declarative-element';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper for assert.instanceOf that also works with TypeScript in setting the proper types.
|
|
4
|
-
*
|
|
5
|
-
* Do not use this in production code! It should only be used in testing code.
|
|
6
|
-
*/
|
|
7
|
-
export declare function assertInstanceOf<T>(value: unknown, constructor: new (...args: any) => T, message?: string): asserts value is T;
|
|
8
|
-
export declare function isInstanceOf<T>(value: unknown, constructor: new (...args: any) => T): value is T;
|
|
9
|
-
export declare function getAssertedDeclarativeElement<DeclarativeElementGeneric extends DeclarativeElementDefinition>(searchFor: DeclarativeElementGeneric, searchIn: Element): DeclarativeElementGeneric['instanceType'];
|
|
10
|
-
export declare function testIdSelector(testId: string): string;
|
|
11
|
-
export declare function getCenterOfElement(element: Element): [number, number];
|
|
12
|
-
export declare function queryWithAssert<T extends Element>(query: string | [string, ...string[]], constructor: new (...args: any) => T, searchIn: Element | Document): T;
|
|
13
|
-
export declare function assertRejects(input: () => PromiseLike<any>, message?: string): Promise<void>;
|
|
14
|
-
export declare function assertRejects(input: () => PromiseLike<any>, errType: RegExp | ErrorConstructor, message?: string): Promise<void>;
|
|
15
|
-
export declare function assertRejects(input: () => PromiseLike<any>, errType: ErrorConstructor, regExp: RegExp): Promise<void>;
|
package/dist/augments/testing.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { assert } from '@open-wc/testing';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper for assert.instanceOf that also works with TypeScript in setting the proper types.
|
|
4
|
-
*
|
|
5
|
-
* Do not use this in production code! It should only be used in testing code.
|
|
6
|
-
*/
|
|
7
|
-
export function assertInstanceOf(value, constructor, message) {
|
|
8
|
-
assert.instanceOf(value, constructor, message);
|
|
9
|
-
}
|
|
10
|
-
export function isInstanceOf(value, constructor) {
|
|
11
|
-
return value instanceof constructor;
|
|
12
|
-
}
|
|
13
|
-
export function getAssertedDeclarativeElement(searchFor, searchIn) {
|
|
14
|
-
if (searchIn.tagName.toLowerCase() === searchFor.tagName.toLowerCase()) {
|
|
15
|
-
assertInstanceOf(searchIn, searchFor);
|
|
16
|
-
return searchIn;
|
|
17
|
-
}
|
|
18
|
-
const result = queryTree(searchIn, [searchFor.tagName]);
|
|
19
|
-
assertInstanceOf(result, searchFor);
|
|
20
|
-
assert.strictEqual(result.tagName, searchFor.tagName);
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
export function testIdSelector(testId) {
|
|
24
|
-
return `[data-test-id="${testId}"]`;
|
|
25
|
-
}
|
|
26
|
-
export function getCenterOfElement(element) {
|
|
27
|
-
const rect = element.getBoundingClientRect();
|
|
28
|
-
return [
|
|
29
|
-
Math.floor((rect.left + rect.right) / 2),
|
|
30
|
-
Math.floor((rect.bottom + rect.top) / 2),
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
export function queryWithAssert(query, constructor, searchIn) {
|
|
34
|
-
if (!Array.isArray(query)) {
|
|
35
|
-
query = [query];
|
|
36
|
-
}
|
|
37
|
-
const result = queryTree(searchIn, query);
|
|
38
|
-
assertInstanceOf(result, constructor);
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
/** Accounts for shadow DOM */
|
|
42
|
-
function queryTree(context,
|
|
43
|
-
// at least one string is required or this function makes no sense
|
|
44
|
-
selectors) {
|
|
45
|
-
/**
|
|
46
|
-
* The callback is split out here to appease the Type Gods. Without it, finalElement will be the
|
|
47
|
-
* type of the internal currentContext (which is incorrect).
|
|
48
|
-
*/
|
|
49
|
-
const reduceCallback = (currentContext, selector) => {
|
|
50
|
-
var _a;
|
|
51
|
-
if (!currentContext) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
if ('shadowRoot' in currentContext && currentContext.shadowRoot) {
|
|
55
|
-
currentContext = currentContext.shadowRoot;
|
|
56
|
-
}
|
|
57
|
-
return (_a = currentContext.querySelector(selector)) !== null && _a !== void 0 ? _a : undefined;
|
|
58
|
-
};
|
|
59
|
-
const finalElement = selectors.reduce(reduceCallback, context);
|
|
60
|
-
return finalElement;
|
|
61
|
-
}
|
|
62
|
-
export async function assertRejects(input, messageOrRegExpOrError, messageOrRegExp) {
|
|
63
|
-
let thrown = undefined;
|
|
64
|
-
let errorThrown = false;
|
|
65
|
-
try {
|
|
66
|
-
await input();
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
errorThrown = true;
|
|
70
|
-
thrown = error;
|
|
71
|
-
}
|
|
72
|
-
assert.isTrue(errorThrown, 'No error was thrown.');
|
|
73
|
-
assert.throws(() => {
|
|
74
|
-
throw thrown;
|
|
75
|
-
}, messageOrRegExpOrError, messageOrRegExp);
|
|
76
|
-
}
|
package/index.html
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>Element Vir Test</title>
|
|
5
|
-
<script type="module" src="/src/test/elements/app.element.ts"></script>
|
|
6
|
-
<link rel="stylesheet" type="text/css" href="/index.css" />
|
|
7
|
-
<script>
|
|
8
|
-
console.info('yo');
|
|
9
|
-
</script>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<element-vir-test-app></element-vir-test-app>
|
|
13
|
-
</body>
|
|
14
|
-
</html>
|