element-vir 26.14.0 → 26.14.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.
|
@@ -1,4 +1,23 @@
|
|
|
1
|
+
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
1
2
|
import { type AsyncProp } from './async-prop.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link renderAsync}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export type RenderAsyncOptions = PartialWithUndefined<{
|
|
9
|
+
/**
|
|
10
|
+
* When set to `true`, uses `lastResolvedValue` instead of `value` from the async prop. This is
|
|
11
|
+
* useful when you want to keep showing the last resolved value while a new promise is pending.
|
|
12
|
+
*/
|
|
13
|
+
useLastResolvedValue: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Properties from AsyncProp used by {@link renderAsync}.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export type RenderAsyncPropInput<T> = Pick<AsyncProp<T, any>, 'value' | 'lastResolvedValue'>;
|
|
2
21
|
/**
|
|
3
22
|
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
4
23
|
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
@@ -9,7 +28,7 @@ import { type AsyncProp } from './async-prop.js';
|
|
|
9
28
|
*
|
|
10
29
|
* @category Async
|
|
11
30
|
*/
|
|
12
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp:
|
|
31
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never, ErrorRenderResult = never>(asyncProp: RenderAsyncPropInput<T>, fallback: FallbackResult, resolutionRender: (resolved: Awaited<T>) => ResolutionRenderResult, errorRender: (error: Error) => ErrorRenderResult, options?: RenderAsyncOptions): FallbackResult | ResolutionRenderResult | ErrorRenderResult;
|
|
13
32
|
/**
|
|
14
33
|
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
15
34
|
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
@@ -20,7 +39,7 @@ export declare function renderAsync<T, FallbackResult, ResolutionRenderResult =
|
|
|
20
39
|
*
|
|
21
40
|
* @category Async
|
|
22
41
|
*/
|
|
23
|
-
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never>(asyncProp:
|
|
42
|
+
export declare function renderAsync<T, FallbackResult, ResolutionRenderResult = never>(asyncProp: RenderAsyncPropInput<T>, fallback: FallbackResult, resolutionRender: (resolved: Awaited<T>) => ResolutionRenderResult, errorRender?: undefined, options?: RenderAsyncOptions): FallbackResult | ResolutionRenderResult | string;
|
|
24
43
|
/**
|
|
25
44
|
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
26
45
|
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
@@ -31,7 +50,7 @@ export declare function renderAsync<T, FallbackResult, ResolutionRenderResult =
|
|
|
31
50
|
*
|
|
32
51
|
* @category Async
|
|
33
52
|
*/
|
|
34
|
-
export declare function renderAsync<T, FallbackResult, ErrorRenderResult = never>(asyncProp:
|
|
53
|
+
export declare function renderAsync<T, FallbackResult, ErrorRenderResult = never>(asyncProp: RenderAsyncPropInput<T>, fallback: FallbackResult, resolutionRender: undefined, errorRender: (error: Error) => ErrorRenderResult, options?: RenderAsyncOptions): FallbackResult | Awaited<T> | ErrorRenderResult;
|
|
35
54
|
/**
|
|
36
55
|
* Given a {@link AsyncProp} instance, call and return the output of the `resolutionRender` parameter
|
|
37
56
|
* once the {@link AsyncProp} has been resolved, call and return the output of the `errorRender`
|
|
@@ -42,4 +61,4 @@ export declare function renderAsync<T, FallbackResult, ErrorRenderResult = never
|
|
|
42
61
|
*
|
|
43
62
|
* @category Async
|
|
44
63
|
*/
|
|
45
|
-
export declare function renderAsync<T, FallbackResult>(asyncProp:
|
|
64
|
+
export declare function renderAsync<T, FallbackResult>(asyncProp: RenderAsyncPropInput<T>, fallback: FallbackResult, resolutionRender?: undefined, errorRender?: undefined, options?: RenderAsyncOptions): FallbackResult | Awaited<T> | string;
|
|
@@ -12,15 +12,18 @@ import { extractErrorMessage } from '@augment-vir/common';
|
|
|
12
12
|
*/
|
|
13
13
|
export function renderAsync(asyncProp,
|
|
14
14
|
/** This value will be rendered if the async prop has not settled yet. */
|
|
15
|
-
fallback, resolutionRender, errorRender) {
|
|
16
|
-
const asyncPropValue =
|
|
15
|
+
fallback, resolutionRender, errorRender, options = {}) {
|
|
16
|
+
const asyncPropValue = options.useLastResolvedValue
|
|
17
|
+
? asyncProp.lastResolvedValue
|
|
18
|
+
: asyncProp.value;
|
|
17
19
|
if (asyncPropValue instanceof Error) {
|
|
18
20
|
const errorResult = errorRender
|
|
19
21
|
? errorRender(asyncPropValue)
|
|
20
22
|
: extractErrorMessage(asyncPropValue);
|
|
21
23
|
return errorResult;
|
|
22
24
|
}
|
|
23
|
-
else if (check.isPromiseLike(asyncPropValue)
|
|
25
|
+
else if (check.isPromiseLike(asyncPropValue) ||
|
|
26
|
+
(options.useLastResolvedValue && asyncPropValue === undefined)) {
|
|
24
27
|
const fallbackResult = fallback;
|
|
25
28
|
return fallbackResult;
|
|
26
29
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type { KeyFn } from 'lit/directives/repeat.js';
|
|
2
2
|
export type { RepeatDirective };
|
|
3
|
+
import { type ChildPart, type noChange } from 'lit-html';
|
|
3
4
|
import { type Directive, type PartInfo } from 'lit-html/directive.js';
|
|
4
5
|
import { type KeyFn } from 'lit-html/directives/repeat.js';
|
|
5
|
-
import { type ChildPart, type noChange } from 'lit-html/lit-html.js';
|
|
6
6
|
import { type HtmlInterpolation } from '../template-transforms/vir-html/html-interpolation.js';
|
|
7
7
|
/**
|
|
8
8
|
* A modified class type for the built-in lit `repeat` directive which works for element-vir
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "element-vir",
|
|
3
|
-
"version": "26.14.
|
|
3
|
+
"version": "26.14.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"custom",
|
|
6
6
|
"web",
|
|
@@ -39,19 +39,19 @@
|
|
|
39
39
|
"test:docs": "virmator docs check"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@augment-vir/assert": "^31.
|
|
43
|
-
"@augment-vir/common": "^31.
|
|
42
|
+
"@augment-vir/assert": "^31.58.0",
|
|
43
|
+
"@augment-vir/common": "^31.58.0",
|
|
44
44
|
"date-vir": "^8.1.0",
|
|
45
45
|
"lit": "^3.3.2",
|
|
46
46
|
"lit-css-vars": "^3.0.11",
|
|
47
47
|
"lit-html": "^3.3.2",
|
|
48
48
|
"object-shape-tester": "^6.11.0",
|
|
49
|
-
"observavir": "^2.3.
|
|
49
|
+
"observavir": "^2.3.1",
|
|
50
50
|
"typed-event-target": "^4.1.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@augment-vir/test": "^31.
|
|
54
|
-
"@augment-vir/web": "^31.
|
|
53
|
+
"@augment-vir/test": "^31.58.0",
|
|
54
|
+
"@augment-vir/web": "^31.58.0",
|
|
55
55
|
"@web/dev-server-esbuild": "^1.0.4",
|
|
56
56
|
"@web/test-runner": "^0.20.2",
|
|
57
57
|
"@web/test-runner-commands": "^0.9.0",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
62
62
|
"markdown-code-example-inserter": "^3.0.3",
|
|
63
63
|
"type-fest": "^5.3.1",
|
|
64
|
-
"typedoc": "^0.28.
|
|
64
|
+
"typedoc": "^0.28.16",
|
|
65
65
|
"typescript": "5.9.3",
|
|
66
|
-
"vite": "^7.3.
|
|
67
|
-
"vite-tsconfig-paths": "^6.0.
|
|
66
|
+
"vite": "^7.3.1",
|
|
67
|
+
"vite-tsconfig-paths": "^6.0.4"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=22"
|