@player-ui/player 0.15.5 → 0.15.7

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/package.json CHANGED
@@ -6,12 +6,12 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-ui/player",
9
- "version": "0.15.5",
9
+ "version": "0.15.7",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@player-ui/partial-match-registry": "0.15.5",
13
- "@player-ui/make-flow": "0.15.5",
14
- "@player-ui/types": "0.15.5",
12
+ "@player-ui/partial-match-registry": "0.15.7",
13
+ "@player-ui/make-flow": "0.15.7",
14
+ "@player-ui/types": "0.15.7",
15
15
  "@types/dlv": "^1.1.4",
16
16
  "dequal": "^2.0.2",
17
17
  "dlv": "^1.1.3",
@@ -845,4 +845,94 @@ describe("templates", () => {
845
845
  // Make sure the ordering is preserved in the snapshot
846
846
  expect(resolved.asset.values).toMatchSnapshot();
847
847
  });
848
+
849
+ it("Should respect placement for a template nested under a non-asset/view value node (e.g. topicGroup.values[x].topics)", () => {
850
+ const model = withParser(new LocalModel({}), parseBinding);
851
+ const evaluator = new ExpressionEvaluator({ model });
852
+ const schema = new SchemaController();
853
+
854
+ // "values" here is generated by an outer template, so each item (e.g. the object
855
+ // at topicGroup.values[x]) is parsed as a plain NodeType.Value node rather than an
856
+ // Asset/View node. That item has its own static "topics" array plus a nested
857
+ // template targeting "topics" with a placement - which needs to be sorted just like
858
+ // it would be on an Asset/View node.
859
+ const view = new ViewInstance(
860
+ {
861
+ id: "my-view",
862
+ asset: {
863
+ id: "topicGroup",
864
+ type: "collection",
865
+ template: [
866
+ {
867
+ dynamic: false,
868
+ data: "groups",
869
+ output: "values",
870
+ value: {
871
+ id: "group-_index_",
872
+ topics: [
873
+ {
874
+ asset: {
875
+ id: "static-topic-1-_index_",
876
+ type: "text",
877
+ value: "static topic 1",
878
+ },
879
+ },
880
+ {
881
+ asset: {
882
+ id: "static-topic-2-_index_",
883
+ type: "text",
884
+ value: "static topic 2",
885
+ },
886
+ },
887
+ ],
888
+ template: [
889
+ {
890
+ dynamic: false,
891
+ data: "foo.topics",
892
+ output: "topics",
893
+ placement: "prepend",
894
+ value: {
895
+ asset: {
896
+ id: "topic-_index1_",
897
+ type: "text",
898
+ value: "topic {{foo.topics._index1_}}",
899
+ },
900
+ },
901
+ },
902
+ ],
903
+ },
904
+ },
905
+ ],
906
+ },
907
+ } as any,
908
+ {
909
+ model,
910
+ parseBinding,
911
+ evaluator,
912
+ schema,
913
+ },
914
+ );
915
+
916
+ const pluginOptions = toNodeResolveOptions(view.resolverOptions);
917
+ new TemplatePlugin(pluginOptions).apply(view);
918
+ new StringResolverPlugin().apply(view);
919
+ new AssetPlugin().apply(view);
920
+ new MultiNodePlugin().apply(view);
921
+
922
+ model.set([
923
+ ["groups", [{}]],
924
+ ["foo.topics", ["A", "B"]],
925
+ ]);
926
+
927
+ const resolved: any = view.update();
928
+ const topics = resolved.asset.values[0].topics;
929
+
930
+ expect(topics).toHaveLength(4);
931
+ // Prepend placement means the templated topics should come before the static ones,
932
+ // even though "topics" is declared before "template" in the source.
933
+ expect(topics[0].asset.value).toBe("topic A");
934
+ expect(topics[1].asset.value).toBe("topic B");
935
+ expect(topics[2].asset.value).toBe("static topic 1");
936
+ expect(topics[3].asset.value).toBe("static topic 2");
937
+ });
848
938
  });
@@ -146,7 +146,9 @@ export class TemplatePlugin implements ViewPlugin {
146
146
 
147
147
  if (
148
148
  node &&
149
- (node.type === NodeType.View || node.type === NodeType.Asset) &&
149
+ (node.type === NodeType.View ||
150
+ node.type === NodeType.Asset ||
151
+ node.type === NodeType.Value) &&
150
152
  Array.isArray(node.children)
151
153
  ) {
152
154
  node.children = node.children.sort((a, b) => {