element-vir 6.2.0 → 6.2.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/README.md CHANGED
@@ -359,7 +359,8 @@ export const MyAppWithHostClasses = defineElementNoInputs({
359
359
  hostClasses: {
360
360
  /**
361
361
  * Setting the value to false means this host class will not ever automatically be applied.
362
- * It will simply be a static member on the element for manual application in consumers when desired.
362
+ * It will simply be a static member on the element for manual application in consumers when
363
+ * desired.
363
364
  */
364
365
  styleVariationA: false,
365
366
  /**
@@ -0,0 +1,18 @@
1
+ export declare type MaybePromise<T> = (T extends Promise<infer ValueType> ? T | ValueType : Promise<T> | T) | undefined | {
2
+ error: Error;
3
+ };
4
+ export declare type CreateStateUpdatingPromiseInputs<InnerValueGeneric, KeyGeneric extends PropertyKey, StateGeneric extends Readonly<Record<KeyGeneric, MaybePromise<InnerValueGeneric>>>> = {
5
+ updateState: (newState: Partial<StateGeneric>) => void;
6
+ stateKey: KeyGeneric;
7
+ } & ({
8
+ createPromiseCallback: () => Promise<InnerValueGeneric>;
9
+ promise?: undefined;
10
+ } | {
11
+ promise: Promise<InnerValueGeneric>;
12
+ createPromiseCallback?: undefined;
13
+ });
14
+ export declare function createStateUpdatingPromiseIfUndefined<InnerValueGeneric, KeyGeneric extends PropertyKey, StateGeneric extends Readonly<Record<KeyGeneric, MaybePromise<InnerValueGeneric>>>>(inputs: CreateStateUpdatingPromiseInputs<InnerValueGeneric, KeyGeneric, StateGeneric> & {
15
+ state: StateGeneric;
16
+ }): void;
17
+ export declare function awaiting<ValueGeneric, FallbackGeneric, CallbackReturnGeneric>(input: MaybePromise<ValueGeneric>, notResolvedYetFallback: FallbackGeneric, resolvedCallback: (resolved: ValueGeneric) => CallbackReturnGeneric): CallbackReturnGeneric | FallbackGeneric | Error | undefined;
18
+ export declare function ensureError(input: unknown): Error;
@@ -0,0 +1,42 @@
1
+ import { extractErrorMessage, isPromiseLike, typedHasProperty } from 'augment-vir';
2
+ export function createStateUpdatingPromiseIfUndefined(inputs) {
3
+ const { state, stateKey } = inputs;
4
+ const currentValue = state[stateKey];
5
+ if (currentValue === undefined) {
6
+ createStateUpdatingPromise(inputs);
7
+ }
8
+ }
9
+ function createStateUpdatingPromise({ updateState, stateKey, createPromiseCallback: promiseCallback, promise, }) {
10
+ const output = promise !== null && promise !== void 0 ? promise : promiseCallback();
11
+ // as casts below are required because, even though all the generics agree, TypeScript can't figure that out here
12
+ if (output instanceof Promise) {
13
+ output
14
+ .then((result) => {
15
+ updateState({ [stateKey]: result });
16
+ })
17
+ .catch((thrownError) => {
18
+ const guaranteedError = ensureError(thrownError);
19
+ updateState({ [stateKey]: { error: guaranteedError } });
20
+ });
21
+ }
22
+ updateState({ [stateKey]: output });
23
+ }
24
+ export function awaiting(input, notResolvedYetFallback, resolvedCallback) {
25
+ if (isPromiseLike(input) || input == undefined) {
26
+ return notResolvedYetFallback;
27
+ }
28
+ else if (typedHasProperty(input, 'error')) {
29
+ return input.error;
30
+ }
31
+ else {
32
+ return resolvedCallback(input);
33
+ }
34
+ }
35
+ export function ensureError(input) {
36
+ if (input instanceof Error) {
37
+ return input;
38
+ }
39
+ else {
40
+ return new Error(extractErrorMessage(input));
41
+ }
42
+ }
@@ -5,7 +5,8 @@ import { DefinedTypedEvent, TypedEvent } from '../../typed-event/typed-event';
5
5
  * typed events (pass in a return value from defineTypedEvent).
6
6
  *
7
7
  * @param definedTypedEvent Needs to come either from a declarative element (like
8
- * MyDeclarativeElement.events.eventName) or from a typed event created via the defineTypedEvent function.
8
+ * MyDeclarativeElement.events.eventName) or from a typed event created via the defineTypedEvent
9
+ * function.
9
10
  * @param listener The callback to fire when an event is caught. Assuming the definedTypedEvent
10
11
  * input is properly typed, the event given to this callback will also be typed.
11
12
  */
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './declarative-element/define-element-no-inputs';
4
4
  export type { DeclarativeElementDefinitionOptions } from './declarative-element/definition-options';
5
5
  export * from './declarative-element/directives/assign-with-clean-up.directive';
6
6
  export * from './declarative-element/directives/assign.directive';
7
+ export * from './declarative-element/directives/awaiting.directive';
7
8
  export * from './declarative-element/directives/directive-helpers';
8
9
  export * from './declarative-element/directives/listen.directive';
9
10
  export * from './declarative-element/directives/on-dom-created.directive';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './declarative-element/define-element';
3
3
  export * from './declarative-element/define-element-no-inputs';
4
4
  export * from './declarative-element/directives/assign-with-clean-up.directive';
5
5
  export * from './declarative-element/directives/assign.directive';
6
+ export * from './declarative-element/directives/awaiting.directive';
6
7
  export * from './declarative-element/directives/directive-helpers';
7
8
  export * from './declarative-element/directives/listen.directive';
8
9
  export * from './declarative-element/directives/on-dom-created.directive';
@@ -1,8 +1,8 @@
1
- import { typedHasOwnProperties } from 'augment-vir';
1
+ import { typedHasProperties } from 'augment-vir';
2
2
  import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
3
3
  function extractElementKeys(values) {
4
4
  return values.filter((value) => {
5
- return (typedHasOwnProperties(value, [
5
+ return (typedHasProperties(value, [
6
6
  'tagName',
7
7
  DeclarativeElementMarkerSymbol,
8
8
  ]) &&
@@ -1,4 +1,4 @@
1
- import { typedHasOwnProperties } from 'augment-vir';
1
+ import { typedHasProperties } from 'augment-vir';
2
2
  import { filterOutArrayIndexes } from '../augments/array';
3
3
  import { DeclarativeElementMarkerSymbol } from '../declarative-element-marker-symbol';
4
4
  import { getAlreadyMappedTemplate, setMappedTemplate } from './nested-mapped-templates';
@@ -20,7 +20,7 @@ export function makeCheckTransform(name, check, transform) {
20
20
  const transformedTemplateStrings = new WeakMap();
21
21
  function extractElementValues(values) {
22
22
  return values.filter((value) => {
23
- return (typedHasOwnProperties(value, [
23
+ return (typedHasProperties(value, [
24
24
  'tagName',
25
25
  DeclarativeElementMarkerSymbol,
26
26
  ]) &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "element-vir",
3
- "version": "6.2.0",
3
+ "version": "6.2.2",
4
4
  "keywords": [
5
5
  "custom",
6
6
  "web",
@@ -25,24 +25,51 @@
25
25
  "main": "dist/index.js",
26
26
  "types": "dist/index.d.ts",
27
27
  "scripts": {
28
+ "build": "virmator frontend build",
28
29
  "compile": "rm -rf dist && tsc --project tsconfig.json",
30
+ "docs:update": "virmator code-in-markdown",
29
31
  "format": "virmator format",
30
- "prepublishOnly": "npm run compile && npm run test:full",
32
+ "prepublishOnly": "npm run compile && npm run test:all",
33
+ "preview": "virmator frontend preview",
31
34
  "spellcheck": "virmator spellcheck",
32
35
  "start": "npm install && virmator frontend",
33
36
  "test": "npm run test:types && virmator test-web",
34
- "test:full": "npm test && npm run spellcheck && virmator format check && npm run update-docs -- --check",
37
+ "test:all": "npm run test:types && npm test && npm run spellcheck && npm run test:format && npm run test:docs",
38
+ "test:docs": "virmator code-in-markdown check",
39
+ "test:format": "virmator format check",
35
40
  "test:types": "tsc --noEmit",
36
- "update-docs": "virmator code-in-markdown README.md --index src/index.ts"
41
+ "test:web": "virmator test-web"
37
42
  },
38
43
  "dependencies": {
39
- "augment-vir": "2.5.0",
44
+ "augment-vir": "^3.0.5",
40
45
  "lit": "2.4.0"
41
46
  },
42
47
  "devDependencies": {
43
- "@open-wc/testing": "3.1.6",
44
- "@web/dev-server-esbuild": "0.3.2",
45
- "@web/test-runner": "0.14.0",
46
- "virmator": "3.0.6"
48
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
49
+ "@open-wc/testing": "^3.1.6",
50
+ "@types/chai": "^4.3.3",
51
+ "@types/mocha": "^10.0.0",
52
+ "@web/dev-server-esbuild": "^0.3.3",
53
+ "@web/test-runner": "^0.15.0",
54
+ "@web/test-runner-commands": "^0.6.5",
55
+ "@web/test-runner-playwright": "^0.9.0",
56
+ "ansi-colors": "^4.1.3",
57
+ "chai": "^4.3.6",
58
+ "cspell": "^6.13.3",
59
+ "istanbul-smart-text-reporter": "^0.0.1",
60
+ "markdown-code-example-inserter": "^0.1.11",
61
+ "mocha": "^10.1.0",
62
+ "mocha-spec-reporter-with-file-names": "^0.0.0",
63
+ "nyc": "^15.1.0",
64
+ "prettier": "^2.7.1",
65
+ "prettier-plugin-jsdoc": "^0.4.2",
66
+ "prettier-plugin-multiline-arrays": "^1.1.1",
67
+ "prettier-plugin-organize-imports": "^3.1.1",
68
+ "prettier-plugin-packagejson": "^2.3.0",
69
+ "prettier-plugin-sort-json": "^0.0.3",
70
+ "prettier-plugin-toml": "^0.3.1",
71
+ "ts-node": "^10.9.1",
72
+ "virmator": "^4.2.14",
73
+ "vite": "^3.2.2"
47
74
  }
48
75
  }