cx 24.7.1 → 24.7.3

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.
Files changed (41) hide show
  1. package/dist/charts.js +10 -0
  2. package/dist/data.js +49 -19
  3. package/dist/manifest.js +731 -731
  4. package/dist/svg.js +6 -0
  5. package/dist/ui.js +3 -3
  6. package/package.json +1 -1
  7. package/src/charts/Legend.js +151 -151
  8. package/src/charts/LegendEntry.d.ts +17 -3
  9. package/src/charts/LegendEntry.js +4 -0
  10. package/src/charts/Marker.d.ts +14 -0
  11. package/src/charts/Marker.js +8 -0
  12. package/src/charts/PieLabel.js +71 -71
  13. package/src/charts/axis/Axis.d.ts +96 -96
  14. package/src/charts/axis/NumericAxis.js +347 -347
  15. package/src/charts/axis/Stack.js +55 -55
  16. package/src/data/ArrayElementView.js +37 -19
  17. package/src/data/ArrayElementView.spec.js +18 -0
  18. package/src/data/AugmentedViewBase.js +22 -14
  19. package/src/data/Binding.spec.js +69 -69
  20. package/src/data/StringTemplate.spec.js +105 -105
  21. package/src/data/getAccessor.spec.js +11 -11
  22. package/src/svg/Rectangle.d.ts +20 -7
  23. package/src/svg/Rectangle.js +7 -2
  24. package/src/svg/Text.d.ts +40 -40
  25. package/src/ui/Controller.d.ts +182 -182
  26. package/src/ui/Culture.js +129 -129
  27. package/src/ui/Cx.js +313 -313
  28. package/src/ui/DataProxy.spec.js +26 -23
  29. package/src/ui/FocusManager.js +171 -171
  30. package/src/ui/Instance.d.ts +72 -72
  31. package/src/ui/VDOM.d.ts +12 -12
  32. package/src/ui/app/startAppLoop.js +58 -58
  33. package/src/ui/index.d.ts +42 -42
  34. package/src/util/Console.d.ts +4 -4
  35. package/src/widgets/drag-drop/DropZone.js +214 -214
  36. package/src/widgets/form/TextField.js +289 -289
  37. package/src/widgets/form/UploadButton.d.ts +34 -34
  38. package/src/widgets/grid/variables.scss +88 -88
  39. package/src/widgets/overlay/Dropdown.js +612 -612
  40. package/src/widgets/overlay/Window.js +196 -196
  41. package/src/widgets/overlay/variables.scss +83 -83
@@ -1,55 +1,55 @@
1
- export class Stack {
2
- constructor() {
3
- this.reset();
4
- }
5
-
6
- reset() {
7
- this.stacks = {};
8
- this.values = {};
9
- this.normalized = false;
10
- this.invalid = {};
11
- }
12
-
13
- acknowledge(ordinal, value) {
14
- if (value != null) {
15
- let s = this.stacks[ordinal];
16
- if (!s) this.stacks[ordinal] = s = { total: 0, min: 0, max: 0 };
17
- s.total += value;
18
- if (s.total < s.min) s.min = s.total;
19
- if (s.total > s.max) s.max = s.total;
20
- } else {
21
- this.invalid[ordinal] = true;
22
- }
23
- }
24
-
25
- measure(normalized) {
26
- if (normalized) {
27
- this.normalized = true;
28
- return [0, 1];
29
- }
30
-
31
- let max = 0,
32
- min = 0;
33
- for (let key in this.stacks) {
34
- if (this.stacks[key].max > max) max = this.stacks[key].max;
35
- if (this.stacks[key].min < min) min = this.stacks[key].min;
36
- }
37
- return [min, max];
38
- }
39
-
40
- stack(ordinal, value) {
41
- if (value == null || this.invalid[ordinal]) return null;
42
-
43
- let base = this.values[ordinal] || 0;
44
-
45
- let result = (this.values[ordinal] = base + value);
46
-
47
- if (!this.normalized) return result;
48
-
49
- let total = this.stacks[ordinal].total;
50
-
51
- if (total > 0) return result / total;
52
-
53
- return null;
54
- }
55
- }
1
+ export class Stack {
2
+ constructor() {
3
+ this.reset();
4
+ }
5
+
6
+ reset() {
7
+ this.stacks = {};
8
+ this.values = {};
9
+ this.normalized = false;
10
+ this.invalid = {};
11
+ }
12
+
13
+ acknowledge(ordinal, value) {
14
+ if (value != null) {
15
+ let s = this.stacks[ordinal];
16
+ if (!s) this.stacks[ordinal] = s = { total: 0, min: 0, max: 0 };
17
+ s.total += value;
18
+ if (s.total < s.min) s.min = s.total;
19
+ if (s.total > s.max) s.max = s.total;
20
+ } else {
21
+ this.invalid[ordinal] = true;
22
+ }
23
+ }
24
+
25
+ measure(normalized) {
26
+ if (normalized) {
27
+ this.normalized = true;
28
+ return [0, 1];
29
+ }
30
+
31
+ let max = 0,
32
+ min = 0;
33
+ for (let key in this.stacks) {
34
+ if (this.stacks[key].max > max) max = this.stacks[key].max;
35
+ if (this.stacks[key].min < min) min = this.stacks[key].min;
36
+ }
37
+ return [min, max];
38
+ }
39
+
40
+ stack(ordinal, value) {
41
+ if (value == null || this.invalid[ordinal]) return null;
42
+
43
+ let base = this.values[ordinal] || 0;
44
+
45
+ let result = (this.values[ordinal] = base + value);
46
+
47
+ if (!this.normalized) return result;
48
+
49
+ let total = this.stacks[ordinal].total;
50
+
51
+ if (total > 0) return result / total;
52
+
53
+ return null;
54
+ }
55
+ }
@@ -1,29 +1,37 @@
1
- import {AugmentedViewBase} from "./AugmentedViewBase";
2
- import { isArray} from "../util/isArray";
1
+ import { AugmentedViewBase } from "./AugmentedViewBase";
2
+ import { isArray } from "../util/isArray";
3
+ import { Binding } from "./Binding";
3
4
 
4
5
  export class ArrayElementView extends AugmentedViewBase {
6
+ constructor(config) {
7
+ super(config);
8
+ this.hasNestedAliases =
9
+ this.recordAlias.indexOf(".") >= 0 || this.indexAlias.indexOf(".") >= 0 || this.lengthAlias.indexOf(".") >= 0;
10
+ this.recordBinding = Binding.get(this.recordAlias);
11
+ if (this.hasNestedAliases) {
12
+ this.indexBinding = Binding.get(this.indexAlias);
13
+ this.lengthAlias = Binding.get(this.lengthAlias);
14
+ }
15
+ }
5
16
 
6
- isExtraKey(key) {
7
- return key == this.recordAlias || key == this.indexAlias || key == this.lengthAlias;
17
+ getExtraKeyBinding(key) {
18
+ if (!key.startsWith(this.recordAlias)) return null;
19
+ if (key.length == this.recordAlias.length || key[this.recordAlias.length] == ".") return this.recordBinding;
20
+ return null;
8
21
  }
9
22
 
10
23
  deleteExtraKeyValue(key) {
11
- if (key != this.recordAlias)
12
- throw new Error(`Field ${key} cannot be deleted.`);
24
+ if (key != this.recordAlias) throw new Error(`Field ${key} cannot be deleted.`);
13
25
  const array = this.arrayAccessor.get(this.store.getData());
14
- if (!array)
15
- return false;
26
+ if (!array) return false;
16
27
  const newArray = [...array.slice(0, this.itemIndex), ...array.slice(this.itemIndex + 1)];
17
28
  return this.arrayAccessor.set(newArray, this.store);
18
29
  }
19
30
 
20
31
  setExtraKeyValue(key, value) {
21
- if (key != this.recordAlias)
22
- throw new Error(`Field ${key} is read-only.`);
23
-
32
+ if (key != this.recordAlias) throw new Error(`Field ${key} is read-only.`);
24
33
  const array = this.arrayAccessor.get(this.store.getData());
25
- if (!array || value === array[this.itemIndex])
26
- return false;
34
+ if (!array || value === array[this.itemIndex]) return false;
27
35
  const newArray = [...array.slice(0, this.itemIndex), value, ...array.slice(this.itemIndex + 1)];
28
36
  return this.arrayAccessor.set(newArray, this.store);
29
37
  }
@@ -31,9 +39,19 @@ export class ArrayElementView extends AugmentedViewBase {
31
39
  embedAugmentData(result, parentStoreData) {
32
40
  let array = this.arrayAccessor.get(parentStoreData);
33
41
  if (!isArray(array)) return;
34
- result[this.recordAlias] = array[this.itemIndex];
35
- result[this.indexAlias] = this.itemIndex;
36
- result[this.lengthAlias] = array.length;
42
+ if (!this.hasNestedAliases) {
43
+ result[this.recordAlias] = array[this.itemIndex];
44
+ result[this.indexAlias] = this.itemIndex;
45
+ result[this.lengthAlias] = array.length;
46
+ } else {
47
+ let copy = result;
48
+ copy = this.recordBinding.set(copy, array[this.itemIndex]);
49
+ copy = this.indexBinding.set(copy, this.itemIndex);
50
+ copy = this.lengthAlias.set(copy, array.length);
51
+ result[this.recordBinding.parts[0]] = copy[this.recordBinding.parts[0]];
52
+ result[this.indexBinding.parts[0]] = copy[this.indexBinding.parts[0]];
53
+ result[this.lengthAlias.parts[0]] = copy[this.lengthAlias.parts[0]];
54
+ }
37
55
  }
38
56
 
39
57
  setIndex(itemIndex) {
@@ -41,6 +59,6 @@ export class ArrayElementView extends AugmentedViewBase {
41
59
  }
42
60
  }
43
61
 
44
- ArrayElementView.prototype.recordAlias = '$record';
45
- ArrayElementView.prototype.indexAlias = '$index';
46
- ArrayElementView.prototype.lengthAlias = '$length';
62
+ ArrayElementView.prototype.recordAlias = "$record";
63
+ ArrayElementView.prototype.indexAlias = "$index";
64
+ ArrayElementView.prototype.lengthAlias = "$length";
@@ -41,6 +41,24 @@ describe("ArrayElementView", function () {
41
41
  assert.equal(record, letters[1]);
42
42
  });
43
43
 
44
+ it("aliases allow nesting", function () {
45
+ let letters = [{ letter: "A" }, { letter: "B" }];
46
+ let store = new Store({ data: { letters } });
47
+ let elementView = new ArrayElementView({
48
+ store,
49
+ itemIndex: 1,
50
+ arrayAccessor: getAccessor({ bind: "letters" }),
51
+ recordAlias: "$iter.letter",
52
+ indexAlias: "$iter.index.letter",
53
+ });
54
+ let record = elementView.get("$iter.letter");
55
+ assert.equal(record, letters[1]);
56
+ assert.equal(elementView.get("$iter.index.letter"), 1);
57
+
58
+ elementView.set("$iter.letter.letter", "C");
59
+ assert.equal(store.get("letters.1.letter"), "C");
60
+ });
61
+
44
62
  it("when immutable preserves the parent data object", function () {
45
63
  let letters = [{ letter: "A" }, { letter: "B" }];
46
64
  let store = new Store({ data: { letters } });
@@ -3,8 +3,7 @@ import { Binding } from "./Binding";
3
3
 
4
4
  export class AugmentedViewBase extends View {
5
5
  getData() {
6
- if (this.meta.version === this.cache.version && this.sealed)
7
- return this.cache.result;
6
+ if (this.meta.version === this.cache.version && this.sealed) return this.cache.result;
8
7
  let parentStoreData = this.store.getData();
9
8
  let result = this.getBaseData(parentStoreData);
10
9
  this.embedAugmentData(result, parentStoreData);
@@ -27,6 +26,12 @@ export class AugmentedViewBase extends View {
27
26
  throw new Error("abstract");
28
27
  }
29
28
 
29
+ // Stores which need to support nested aliases should override this method
30
+ getExtraKeyBinding(key) {
31
+ let binding = Binding.get(key);
32
+ return this.isExtraKey(binding.parts[0]) ? Binding.get(binding.parts[0]) : null;
33
+ }
34
+
30
35
  setExtraKeyValue(key, value) {
31
36
  throw new Error("abstract");
32
37
  }
@@ -36,29 +41,32 @@ export class AugmentedViewBase extends View {
36
41
  }
37
42
 
38
43
  setItem(path, value) {
39
- let binding = Binding.get(path);
40
- if (this.isExtraKey(binding.parts[0])) {
41
- let bindingRoot = binding.parts[0];
44
+ let extraKeyBinding = this.getExtraKeyBinding(path);
45
+ if (extraKeyBinding) {
46
+ let binding = Binding.get(path);
42
47
  let newValue = value;
43
- if (binding.parts.length > 1) {
48
+ if (binding.parts.length > extraKeyBinding.parts.length) {
44
49
  let data = {};
45
50
  this.embedAugmentData(data, this.store.getData());
46
- newValue = binding.set(data, value)[bindingRoot];
51
+ let binding = Binding.get(path);
52
+ data = binding.set(data, value);
53
+ newValue = extraKeyBinding.value(data);
47
54
  }
48
- return this.setExtraKeyValue(bindingRoot, newValue);
55
+ return this.setExtraKeyValue(extraKeyBinding.path, newValue);
49
56
  }
50
57
  return super.setItem(path, value);
51
58
  }
52
59
 
53
60
  deleteItem(path) {
54
- let binding = Binding.get(path);
55
- if (this.isExtraKey(binding.parts[0])) {
56
- let bindingRoot = binding.parts[0];
57
- if (binding.parts.length == 1) return this.deleteExtraKeyValue(bindingRoot);
61
+ let extraKeyBinding = this.getExtraKeyBinding(path);
62
+ if (extraKeyBinding) {
63
+ if (path == extraKeyBinding.path) return this.deleteExtraKeyValue(extraKeyBinding.path);
58
64
  let data = {};
59
65
  this.embedAugmentData(data, this.store.getData());
60
- let newValue = binding.delete(data)[bindingRoot];
61
- return this.setExtraKeyValue(bindingRoot, newValue);
66
+ let binding = Binding.get(path);
67
+ data = binding.delete(data);
68
+ let newValue = extraKeyBinding.value(data);
69
+ return this.setExtraKeyValue(extraKeyBinding.path, newValue);
62
70
  }
63
71
  return super.deleteItem(path);
64
72
  }
@@ -1,69 +1,69 @@
1
- import { Binding } from "./Binding";
2
- import assert from "assert";
3
- import { createAccessorModelProxy } from "./createAccessorModelProxy";
4
-
5
- describe("Binding", function () {
6
- describe("#get()", function () {
7
- it("should get value if value is defined", function () {
8
- var state = { person: { name: "Joe" } };
9
- var b = Binding.get("person.name");
10
- assert.equal(b.value(state), "Joe");
11
- });
12
-
13
- it("allows non-standard property identifiers", function () {
14
- var state = { person: { "@schema": "Person" } };
15
- var b = Binding.get("person.@schema");
16
- assert.equal(b.path, "person.@schema");
17
- assert.equal(b.value(state), "Person");
18
- });
19
-
20
- it("properly resolves accessor models", function () {
21
- var state = { person: { schema: "Person" } };
22
- var b = Binding.get(createAccessorModelProxy("person.schema"));
23
- assert.equal(b.value(state), "Person");
24
- });
25
- });
26
-
27
- describe("#set()", function () {
28
- it("produces new objects along the binding path", function () {
29
- var state = { person: { name: "Joe" } };
30
- var b = Binding.get("person.name");
31
- var ns = b.set(state, "Jack");
32
- assert.equal(ns.person.name, "Jack");
33
- assert.notEqual(state, ns);
34
- assert.notEqual(state.person, ns.person);
35
- assert.notEqual(state.person.name, ns.person.name);
36
- });
37
-
38
- it("returns same state object if value does not change", function () {
39
- var state = { person: { name: "Joe" } };
40
- var b = Binding.get("person.name");
41
- var ns = b.set(state, "Joe");
42
- assert.equal(state, ns);
43
- });
44
-
45
- it("allows non-standard property identifiers", function () {
46
- var state = { person: { "@schema": "Person" } };
47
- var b = Binding.get("person.@schema");
48
- var ns = b.set(state, "Test");
49
- assert.equal(ns.person["@schema"], "Test");
50
- });
51
- });
52
-
53
- describe(".delete()", function () {
54
- it("correctly removes pointed properties", function () {
55
- var state = { person: { name: "Joe" } };
56
- var b = Binding.get("person.name");
57
- var ns = b.delete(state);
58
- assert("person" in ns);
59
- assert(!("name" in ns.person));
60
- });
61
-
62
- it("does not change state if property is non-existent", function () {
63
- var state = { person: { name: "Joe" } };
64
- var b = Binding.get("person.name2");
65
- var ns = b.delete(state);
66
- assert(ns == state);
67
- });
68
- });
69
- });
1
+ import { Binding } from "./Binding";
2
+ import assert from "assert";
3
+ import { createAccessorModelProxy } from "./createAccessorModelProxy";
4
+
5
+ describe("Binding", function () {
6
+ describe("#get()", function () {
7
+ it("should get value if value is defined", function () {
8
+ var state = { person: { name: "Joe" } };
9
+ var b = Binding.get("person.name");
10
+ assert.equal(b.value(state), "Joe");
11
+ });
12
+
13
+ it("allows non-standard property identifiers", function () {
14
+ var state = { person: { "@schema": "Person" } };
15
+ var b = Binding.get("person.@schema");
16
+ assert.equal(b.path, "person.@schema");
17
+ assert.equal(b.value(state), "Person");
18
+ });
19
+
20
+ it("properly resolves accessor models", function () {
21
+ var state = { person: { schema: "Person" } };
22
+ var b = Binding.get(createAccessorModelProxy("person.schema"));
23
+ assert.equal(b.value(state), "Person");
24
+ });
25
+ });
26
+
27
+ describe("#set()", function () {
28
+ it("produces new objects along the binding path", function () {
29
+ var state = { person: { name: "Joe" } };
30
+ var b = Binding.get("person.name");
31
+ var ns = b.set(state, "Jack");
32
+ assert.equal(ns.person.name, "Jack");
33
+ assert.notEqual(state, ns);
34
+ assert.notEqual(state.person, ns.person);
35
+ assert.notEqual(state.person.name, ns.person.name);
36
+ });
37
+
38
+ it("returns same state object if value does not change", function () {
39
+ var state = { person: { name: "Joe" } };
40
+ var b = Binding.get("person.name");
41
+ var ns = b.set(state, "Joe");
42
+ assert.equal(state, ns);
43
+ });
44
+
45
+ it("allows non-standard property identifiers", function () {
46
+ var state = { person: { "@schema": "Person" } };
47
+ var b = Binding.get("person.@schema");
48
+ var ns = b.set(state, "Test");
49
+ assert.equal(ns.person["@schema"], "Test");
50
+ });
51
+ });
52
+
53
+ describe(".delete()", function () {
54
+ it("correctly removes pointed properties", function () {
55
+ var state = { person: { name: "Joe" } };
56
+ var b = Binding.get("person.name");
57
+ var ns = b.delete(state);
58
+ assert("person" in ns);
59
+ assert(!("name" in ns.person));
60
+ });
61
+
62
+ it("does not change state if property is non-existent", function () {
63
+ var state = { person: { name: "Joe" } };
64
+ var b = Binding.get("person.name2");
65
+ var ns = b.delete(state);
66
+ assert(ns == state);
67
+ });
68
+ });
69
+ });
@@ -1,105 +1,105 @@
1
- import { StringTemplate } from "./StringTemplate";
2
- import assert from "assert";
3
-
4
- describe("StringTemplate", function () {
5
- describe("#compile()", function () {
6
- it("returns a selector", function () {
7
- var e = StringTemplate.compile("Hello {person.name}");
8
- var state = {
9
- person: {
10
- name: "Jim",
11
- },
12
- };
13
- assert.equal(e(state), "Hello Jim");
14
- });
15
-
16
- it("properly encodes ' and \"", function () {
17
- var e = StringTemplate.compile('It\'s "working"!');
18
- assert.equal(e({}), 'It\'s "working"!');
19
- });
20
-
21
- it("supports multi-line strings", function () {
22
- var e = StringTemplate.compile("a\nb");
23
- assert.equal(e(), "a\nb");
24
-
25
- var e = StringTemplate.compile("a\r\nb");
26
- assert.equal(e(), "a\r\nb");
27
- });
28
- });
29
-
30
- describe("double brackets are used to escape brackets", function () {
31
- it("double brackets are preserved", function () {
32
- var e = StringTemplate.compile("Hello {{person.name}}");
33
- var state = {
34
- person: {
35
- name: "Jim",
36
- },
37
- };
38
- assert.equal(e(state), "Hello {person.name}");
39
- });
40
-
41
- it("triple brackets are converted to single brackets and a binding", function () {
42
- var e = StringTemplate.compile("Hello {{{person.name}}}");
43
- var state = {
44
- person: {
45
- name: "Jim",
46
- },
47
- };
48
- assert.equal(e(state), "Hello {Jim}");
49
- });
50
- });
51
-
52
- describe("supports formatting", function () {
53
- it("with colon", function () {
54
- var e = StringTemplate.compile("{str:suffix;kg}");
55
- assert.equal(e({ str: "5" }), "5kg");
56
- });
57
-
58
- it("with multiple formats", function () {
59
- var e = StringTemplate.compile("{str:suffix;kg:wrap;(;)}");
60
- assert.equal(e({ str: "5" }), "(5kg)");
61
- });
62
-
63
- it("with null values", function () {
64
- var e = StringTemplate.compile("{str:suffix;kg:|N/A}");
65
- assert.equal(e({ str: null }), "N/A");
66
- });
67
-
68
- it("of null values", function () {
69
- var e = StringTemplate.compile("{str|N/A}");
70
- assert.equal(e({ str: null }), "N/A");
71
- });
72
- });
73
-
74
- describe("supports expressions", function () {
75
- it("using []", function () {
76
- var e = StringTemplate.compile("1 + 2 = {[1+2]}");
77
- assert.equal(e(), "1 + 2 = 3");
78
- });
79
-
80
- it("using %", function () {
81
- var e = StringTemplate.compile("1 + 2 = %{1+2}");
82
- assert.equal(e(), "1 + 2 = 3");
83
- });
84
-
85
- it("with subexpressions", function () {
86
- var e = StringTemplate.compile("1 + 2 = {[%{1+2}]}");
87
- assert.equal(e(), "1 + 2 = 3");
88
- });
89
-
90
- it("with a conditional operator", function () {
91
- var e = StringTemplate.compile("1 + 2 = {[true ? 3 : 2]:s}");
92
- assert.equal(e(), "1 + 2 = 3");
93
- });
94
-
95
- it("with sub-expression formatting", function () {
96
- var e = StringTemplate.compile("{[!!{person.age} ? {person.age:suffix; years old} : 'Age unknown']}");
97
- var state = {
98
- person: {
99
- age: 32,
100
- },
101
- };
102
- assert.equal(e(state), "32 years old");
103
- });
104
- });
105
- });
1
+ import { StringTemplate } from "./StringTemplate";
2
+ import assert from "assert";
3
+
4
+ describe("StringTemplate", function () {
5
+ describe("#compile()", function () {
6
+ it("returns a selector", function () {
7
+ var e = StringTemplate.compile("Hello {person.name}");
8
+ var state = {
9
+ person: {
10
+ name: "Jim",
11
+ },
12
+ };
13
+ assert.equal(e(state), "Hello Jim");
14
+ });
15
+
16
+ it("properly encodes ' and \"", function () {
17
+ var e = StringTemplate.compile('It\'s "working"!');
18
+ assert.equal(e({}), 'It\'s "working"!');
19
+ });
20
+
21
+ it("supports multi-line strings", function () {
22
+ var e = StringTemplate.compile("a\nb");
23
+ assert.equal(e(), "a\nb");
24
+
25
+ var e = StringTemplate.compile("a\r\nb");
26
+ assert.equal(e(), "a\r\nb");
27
+ });
28
+ });
29
+
30
+ describe("double brackets are used to escape brackets", function () {
31
+ it("double brackets are preserved", function () {
32
+ var e = StringTemplate.compile("Hello {{person.name}}");
33
+ var state = {
34
+ person: {
35
+ name: "Jim",
36
+ },
37
+ };
38
+ assert.equal(e(state), "Hello {person.name}");
39
+ });
40
+
41
+ it("triple brackets are converted to single brackets and a binding", function () {
42
+ var e = StringTemplate.compile("Hello {{{person.name}}}");
43
+ var state = {
44
+ person: {
45
+ name: "Jim",
46
+ },
47
+ };
48
+ assert.equal(e(state), "Hello {Jim}");
49
+ });
50
+ });
51
+
52
+ describe("supports formatting", function () {
53
+ it("with colon", function () {
54
+ var e = StringTemplate.compile("{str:suffix;kg}");
55
+ assert.equal(e({ str: "5" }), "5kg");
56
+ });
57
+
58
+ it("with multiple formats", function () {
59
+ var e = StringTemplate.compile("{str:suffix;kg:wrap;(;)}");
60
+ assert.equal(e({ str: "5" }), "(5kg)");
61
+ });
62
+
63
+ it("with null values", function () {
64
+ var e = StringTemplate.compile("{str:suffix;kg:|N/A}");
65
+ assert.equal(e({ str: null }), "N/A");
66
+ });
67
+
68
+ it("of null values", function () {
69
+ var e = StringTemplate.compile("{str|N/A}");
70
+ assert.equal(e({ str: null }), "N/A");
71
+ });
72
+ });
73
+
74
+ describe("supports expressions", function () {
75
+ it("using []", function () {
76
+ var e = StringTemplate.compile("1 + 2 = {[1+2]}");
77
+ assert.equal(e(), "1 + 2 = 3");
78
+ });
79
+
80
+ it("using %", function () {
81
+ var e = StringTemplate.compile("1 + 2 = %{1+2}");
82
+ assert.equal(e(), "1 + 2 = 3");
83
+ });
84
+
85
+ it("with subexpressions", function () {
86
+ var e = StringTemplate.compile("1 + 2 = {[%{1+2}]}");
87
+ assert.equal(e(), "1 + 2 = 3");
88
+ });
89
+
90
+ it("with a conditional operator", function () {
91
+ var e = StringTemplate.compile("1 + 2 = {[true ? 3 : 2]:s}");
92
+ assert.equal(e(), "1 + 2 = 3");
93
+ });
94
+
95
+ it("with sub-expression formatting", function () {
96
+ var e = StringTemplate.compile("{[!!{person.age} ? {person.age:suffix; years old} : 'Age unknown']}");
97
+ var state = {
98
+ person: {
99
+ age: 32,
100
+ },
101
+ };
102
+ assert.equal(e(state), "32 years old");
103
+ });
104
+ });
105
+ });
@@ -1,11 +1,11 @@
1
- import assert from "assert";
2
- import { createAccessorModelProxy } from "./createAccessorModelProxy";
3
- import { getAccessor } from "./getAccessor";
4
-
5
- describe("getAccessor", function () {
6
- it("works with accessor chains", function () {
7
- let m = createAccessorModelProxy();
8
- let accessor = getAccessor(m.a.b);
9
- assert(typeof accessor.set == "function");
10
- });
11
- });
1
+ import assert from "assert";
2
+ import { createAccessorModelProxy } from "./createAccessorModelProxy";
3
+ import { getAccessor } from "./getAccessor";
4
+
5
+ describe("getAccessor", function () {
6
+ it("works with accessor chains", function () {
7
+ let m = createAccessorModelProxy();
8
+ let accessor = getAccessor(m.a.b);
9
+ assert(typeof accessor.set == "function");
10
+ });
11
+ });