@player-ui/player 0.10.4-next.2 → 0.10.4
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/Player.native.js +41 -6
- package/dist/Player.native.js.map +1 -1
- package/dist/cjs/index.cjs +32 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +32 -3
- package/dist/index.mjs +32 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/view/builder/index.test.ts +38 -0
- package/src/view/builder/index.ts +27 -2
- package/src/view/parser/types.ts +4 -0
- package/src/view/resolver/index.ts +23 -3
- package/types/view/builder/index.d.ts +9 -2
- package/types/view/parser/types.d.ts +4 -0
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-ui/player",
|
|
9
|
-
"version": "0.10.4
|
|
9
|
+
"version": "0.10.4",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-ui/partial-match-registry": "0.10.4
|
|
13
|
-
"@player-ui/make-flow": "0.10.4
|
|
14
|
-
"@player-ui/types": "0.10.4
|
|
12
|
+
"@player-ui/partial-match-registry": "0.10.4",
|
|
13
|
+
"@player-ui/make-flow": "0.10.4",
|
|
14
|
+
"@player-ui/types": "0.10.4",
|
|
15
15
|
"@types/dlv": "^1.1.4",
|
|
16
16
|
"dequal": "^2.0.2",
|
|
17
17
|
"dlv": "^1.1.3",
|
|
@@ -32,6 +32,44 @@ describe("multiNode", () => {
|
|
|
32
32
|
expect(v1.parent).toBe(result);
|
|
33
33
|
expect(v2.parent).toBe(result);
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
test("multinode with async node", () => {
|
|
37
|
+
const v1 = Builder.asyncNode("1");
|
|
38
|
+
const v2 = Builder.asyncNode("2");
|
|
39
|
+
const result = Builder.multiNode(v1, v2);
|
|
40
|
+
|
|
41
|
+
expect(result.type).toBe(NodeType.MultiNode);
|
|
42
|
+
expect(result.values[0]?.type).toBe("async");
|
|
43
|
+
expect(result.values[1]?.type).toBe("async");
|
|
44
|
+
expect(v1.parent).toBe(result);
|
|
45
|
+
expect(v2.parent).toBe(result);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("async node", () => {
|
|
50
|
+
const result = Builder.asyncNode("1", false);
|
|
51
|
+
expect(result.type).toBe(NodeType.Async);
|
|
52
|
+
expect(result.id).toBe("1");
|
|
53
|
+
expect(result.flatten).toBe(false);
|
|
54
|
+
|
|
55
|
+
const result2 = Builder.asyncNode("2");
|
|
56
|
+
expect(result2.type).toBe(NodeType.Async);
|
|
57
|
+
expect(result2.id).toBe("2");
|
|
58
|
+
expect(result2.flatten).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("asset wrapper", () => {
|
|
62
|
+
const result = Builder.assetWrapper({
|
|
63
|
+
type: NodeType.Asset,
|
|
64
|
+
value: {
|
|
65
|
+
id: "1",
|
|
66
|
+
type: "text",
|
|
67
|
+
value: "chat message",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result.type).toBe(NodeType.Value);
|
|
72
|
+
expect(result.children?.[0]?.value.type).toBe("asset");
|
|
35
73
|
});
|
|
36
74
|
|
|
37
75
|
describe("addChild", () => {
|
|
@@ -17,6 +17,12 @@ export class Builder {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
static assetWrapper<T extends Node.Node>(value: T): Node.Value {
|
|
21
|
+
const valueNode = Builder.value();
|
|
22
|
+
Builder.addChild(valueNode, "asset", value);
|
|
23
|
+
return valueNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
/**
|
|
21
27
|
* Creates a value node
|
|
22
28
|
*
|
|
@@ -33,10 +39,10 @@ export class Builder {
|
|
|
33
39
|
* Creates a multiNode and associates the multiNode as the parent
|
|
34
40
|
* of all the value nodes
|
|
35
41
|
*
|
|
36
|
-
* @param values - the value or
|
|
42
|
+
* @param values - the value, applicability or async nodes to put in the multinode
|
|
37
43
|
*/
|
|
38
44
|
static multiNode(
|
|
39
|
-
...values: (Node.Value | Node.Applicability)[]
|
|
45
|
+
...values: (Node.Value | Node.Applicability | Node.Async)[]
|
|
40
46
|
): Node.MultiNode {
|
|
41
47
|
const m: Node.MultiNode = {
|
|
42
48
|
type: NodeType.MultiNode,
|
|
@@ -52,6 +58,25 @@ export class Builder {
|
|
|
52
58
|
return m;
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Creates an async node
|
|
63
|
+
*
|
|
64
|
+
* @param id - the id of async node. It should be identical for each async node
|
|
65
|
+
*/
|
|
66
|
+
static asyncNode(id: string, flatten = true): Node.Async {
|
|
67
|
+
return {
|
|
68
|
+
id,
|
|
69
|
+
type: NodeType.Async,
|
|
70
|
+
flatten: flatten,
|
|
71
|
+
value: {
|
|
72
|
+
type: NodeType.Value,
|
|
73
|
+
value: {
|
|
74
|
+
id,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
55
80
|
/**
|
|
56
81
|
* Adds a child node to a node
|
|
57
82
|
*
|
package/src/view/parser/types.ts
CHANGED
|
@@ -116,6 +116,10 @@ export declare namespace Node {
|
|
|
116
116
|
id: string;
|
|
117
117
|
/** The value representing the node */
|
|
118
118
|
value: Node;
|
|
119
|
+
/**
|
|
120
|
+
* Should the content streamed in be flattened during resolving
|
|
121
|
+
*/
|
|
122
|
+
flatten?: boolean;
|
|
119
123
|
}
|
|
120
124
|
|
|
121
125
|
export interface PluginOptions {
|
|
@@ -12,7 +12,11 @@ import { DependencyModel, withParser } from "../../data";
|
|
|
12
12
|
import type { Logger } from "../../logger";
|
|
13
13
|
import type { Node } from "../parser";
|
|
14
14
|
import { NodeType } from "../parser";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
caresAboutDataChanges,
|
|
17
|
+
toNodeResolveOptions,
|
|
18
|
+
unpackAndPush,
|
|
19
|
+
} from "./utils";
|
|
16
20
|
import type { Resolve } from "./types";
|
|
17
21
|
import { getNodeID } from "../parser/utils";
|
|
18
22
|
|
|
@@ -163,7 +167,6 @@ export class Resolver {
|
|
|
163
167
|
);
|
|
164
168
|
this.resolveCache = resolveCache;
|
|
165
169
|
this.hooks.afterUpdate.call(updated.value);
|
|
166
|
-
|
|
167
170
|
return updated.value;
|
|
168
171
|
}
|
|
169
172
|
|
|
@@ -408,7 +411,24 @@ export class Resolver {
|
|
|
408
411
|
);
|
|
409
412
|
|
|
410
413
|
if (mTree.value !== undefined && mTree.value !== null) {
|
|
411
|
-
|
|
414
|
+
/**
|
|
415
|
+
* async nodes' parent is a multi-node
|
|
416
|
+
* When the node to resolve is an async node and the flatten flag is true
|
|
417
|
+
* Add the content streamed in to the childValue of parent multi-node
|
|
418
|
+
* Array.isArray(mTree.value.asset.values) is the case when the content is an async asset
|
|
419
|
+
*/
|
|
420
|
+
if (
|
|
421
|
+
mValue.type === NodeType.Async &&
|
|
422
|
+
mValue.flatten &&
|
|
423
|
+
mTree.value.asset &&
|
|
424
|
+
Array.isArray(mTree.value.asset.values)
|
|
425
|
+
) {
|
|
426
|
+
mTree.value.asset.values.forEach((v: any) => {
|
|
427
|
+
unpackAndPush(v, childValue);
|
|
428
|
+
});
|
|
429
|
+
} else {
|
|
430
|
+
childValue.push(mTree.value);
|
|
431
|
+
}
|
|
412
432
|
}
|
|
413
433
|
|
|
414
434
|
mTree.dependencies.forEach((bindingDep) =>
|
|
@@ -10,6 +10,7 @@ export declare class Builder {
|
|
|
10
10
|
* @param value - the value to put in the asset node
|
|
11
11
|
*/
|
|
12
12
|
static asset<T extends AnyAssetType>(value: T): Node.Asset<T>;
|
|
13
|
+
static assetWrapper<T extends Node.Node>(value: T): Node.Value;
|
|
13
14
|
/**
|
|
14
15
|
* Creates a value node
|
|
15
16
|
*
|
|
@@ -20,9 +21,15 @@ export declare class Builder {
|
|
|
20
21
|
* Creates a multiNode and associates the multiNode as the parent
|
|
21
22
|
* of all the value nodes
|
|
22
23
|
*
|
|
23
|
-
* @param values - the value or
|
|
24
|
+
* @param values - the value, applicability or async nodes to put in the multinode
|
|
24
25
|
*/
|
|
25
|
-
static multiNode(...values: (Node.Value | Node.Applicability)[]): Node.MultiNode;
|
|
26
|
+
static multiNode(...values: (Node.Value | Node.Applicability | Node.Async)[]): Node.MultiNode;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an async node
|
|
29
|
+
*
|
|
30
|
+
* @param id - the id of async node. It should be identical for each async node
|
|
31
|
+
*/
|
|
32
|
+
static asyncNode(id: string, flatten?: boolean): Node.Async;
|
|
26
33
|
/**
|
|
27
34
|
* Adds a child node to a node
|
|
28
35
|
*
|
|
@@ -87,6 +87,10 @@ export declare namespace Node {
|
|
|
87
87
|
id: string;
|
|
88
88
|
/** The value representing the node */
|
|
89
89
|
value: Node;
|
|
90
|
+
/**
|
|
91
|
+
* Should the content streamed in be flattened during resolving
|
|
92
|
+
*/
|
|
93
|
+
flatten?: boolean;
|
|
90
94
|
}
|
|
91
95
|
interface PluginOptions {
|
|
92
96
|
/** A list of plugins */
|