cx 23.4.3 → 23.4.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx",
3
- "version": "23.4.3",
3
+ "version": "23.4.5",
4
4
  "description": "Advanced JavaScript UI framework for admin and dashboard applications with ready to use grid, form and chart components.",
5
5
  "main": "index.js",
6
6
  "jsnext:main": "src/index.js",
@@ -7,18 +7,8 @@ export class Binding {
7
7
  constructor(path) {
8
8
  this.path = path;
9
9
  this.parts = path.split(".");
10
- let body = "return (x";
11
- let selector = "x";
12
-
13
- for (let i = 0; i < this.parts.length; i++) {
14
- if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
15
- else selector += "." + this.parts[i];
16
-
17
- if (i + 1 < this.parts.length) body += " && " + selector;
18
- else body += " ? " + selector + " : undefined";
19
- }
20
-
21
- body += ")";
10
+ let body = "return x";
11
+ for (let i = 0; i < this.parts.length; i++) body += '?.["' + this.parts[i] + '"]';
22
12
  this.value = new Function("x", body);
23
13
  }
24
14
 
@@ -1,49 +1,59 @@
1
- import {Binding} from './Binding';
2
- import assert from 'assert';
3
-
4
- describe('Binding', function() {
5
-
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
- });
1
+ import { Binding } from "./Binding";
2
+ import assert from "assert";
3
+
4
+ describe("Binding", function () {
5
+ describe("#get()", function () {
6
+ it("should get value if value is defined", function () {
7
+ var state = { person: { name: "Joe" } };
8
+ var b = Binding.get("person.name");
9
+ assert.equal(b.value(state), "Joe");
10
+ });
13
11
 
14
- describe('#set()', function () {
12
+ it("allows non-standard property identifiers", function () {
13
+ var state = { person: { "@schema": "Person" } };
14
+ var b = Binding.get("person.@schema");
15
+ assert.equal(b.value(state), "Person");
16
+ });
17
+ });
15
18
 
16
- it('produces new objects along the binding path', function () {
17
- var state = {person: {name: 'Joe'}};
18
- var b = Binding.get('person.name');
19
- var ns = b.set(state, 'Jack');
20
- assert.equal(ns.person.name, 'Jack');
21
- assert.notEqual(state, ns);
22
- assert.notEqual(state.person, ns.person);
23
- assert.notEqual(state.person.name, ns.person.name);
24
- });
19
+ describe("#set()", function () {
20
+ it("produces new objects along the binding path", function () {
21
+ var state = { person: { name: "Joe" } };
22
+ var b = Binding.get("person.name");
23
+ var ns = b.set(state, "Jack");
24
+ assert.equal(ns.person.name, "Jack");
25
+ assert.notEqual(state, ns);
26
+ assert.notEqual(state.person, ns.person);
27
+ assert.notEqual(state.person.name, ns.person.name);
28
+ });
25
29
 
26
- it('returns same state object if value does not change', function () {
27
- var state = {person: {name: 'Joe'}};
28
- var b = Binding.get('person.name');
29
- var ns = b.set(state, 'Joe');
30
- assert.equal(state, ns);
31
- });
32
- });
30
+ it("returns same state object if value does not change", function () {
31
+ var state = { person: { name: "Joe" } };
32
+ var b = Binding.get("person.name");
33
+ var ns = b.set(state, "Joe");
34
+ assert.equal(state, ns);
35
+ });
33
36
 
34
- describe('.delete()', function () {
37
+ it("allows non-standard property identifiers", function () {
38
+ var state = { person: { "@schema": "Person" } };
39
+ var b = Binding.get("person.@schema");
40
+ var ns = b.set(state, "Test");
41
+ assert.equal(ns.person["@schema"], "Test");
42
+ });
43
+ });
35
44
 
36
- it('correctly removes pointed properties', function () {
37
- var state = {person: {name: 'Joe'}};
38
- var b = Binding.get('person.name');
45
+ describe(".delete()", function () {
46
+ it("correctly removes pointed properties", function () {
47
+ var state = { person: { name: "Joe" } };
48
+ var b = Binding.get("person.name");
39
49
  var ns = b.delete(state);
40
- assert('person' in ns);
41
- assert(!('name' in ns.person));
50
+ assert("person" in ns);
51
+ assert(!("name" in ns.person));
42
52
  });
43
53
 
44
- it('does not change state if property is non-existent', function () {
45
- var state = {person: {name: 'Joe'}};
46
- var b = Binding.get('person.name2');
54
+ it("does not change state if property is non-existent", function () {
55
+ var state = { person: { name: "Joe" } };
56
+ var b = Binding.get("person.name2");
47
57
  var ns = b.delete(state);
48
58
  assert(ns == state);
49
59
  });
@@ -7,6 +7,7 @@ interface Model {
7
7
  city: string;
8
8
  streetNumber: number;
9
9
  };
10
+ "@crazy": string;
10
11
  }
11
12
 
12
13
  describe("createAccessorModelProxy", () => {
@@ -35,4 +36,9 @@ describe("createAccessorModelProxy", () => {
35
36
  assert.strictEqual(streetNumber.nameOf(), "streetNumber");
36
37
  assert.strictEqual(city.nameOf(), "city");
37
38
  });
39
+
40
+ it("allows non-standard property identifiers ", () => {
41
+ let model = createAccessorModelProxy<Model>();
42
+ assert.strictEqual(model["@crazy"].nameOf(), "@crazy");
43
+ });
38
44
  });
package/src/ui/Restate.js CHANGED
@@ -1,158 +1,158 @@
1
- import { PureContainer } from "./PureContainer";
2
- import { Store } from "../data/Store";
3
- import { Cx } from "./Cx";
4
- import { isString } from "../util/isString";
5
- import { VDOM } from "./VDOM";
6
- import { isFunction } from "../util/isFunction";
7
- import { isObject } from "../util/isObject";
8
- import { isUndefined } from "../util/isUndefined";
9
- import { Binding } from "../data/Binding";
10
- import { StructuredSelector } from "../data/StructuredSelector";
11
-
12
- let persistenceCache = {};
13
-
14
- export class Restate extends PureContainer {
15
- declareData() {
16
- return super.declareData(...arguments, {
17
- deferredUntilIdle: undefined,
18
- idleTimeout: undefined,
19
- cacheKey: undefined,
20
- });
21
- }
22
-
23
- init() {
24
- this.container = PureContainer.create({
25
- type: PureContainer,
26
- items: this.children || this.items,
27
- layout: this.layout,
28
- controller: this.controller,
29
- outerLayout: this.outerLayout,
30
- useParentLayout: !this.detached,
31
- ws: this.ws,
32
- });
33
- this.privateDataSelector = new StructuredSelector({
34
- props: this.data || {},
35
- values: this.data,
36
- });
37
- delete this.items;
38
- delete this.children;
39
- delete this.controller;
40
- delete this.outerLayout;
41
- delete this.layout;
42
- if (this.useParentLayout == null) this.useParentLayout = !this.detached;
43
- super.init();
44
- }
45
-
46
- initSubStore(context, instance) {
47
- let { cacheKey } = instance.data;
48
- this.privateDataSelector.init(instance.store);
49
- instance.subStore = new RestateStore({
50
- store: instance.store,
51
- detached: this.detached,
52
- privateData: this.data || {},
53
- data: cacheKey ? persistenceCache[cacheKey] || {} : {},
54
- dataSelector: this.privateDataSelector.create(),
55
- onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
56
- });
57
-
58
- instance.setStore = (store) => {
59
- instance.store = store;
60
- instance.subStore.setStore(store);
61
- };
62
-
63
- if (cacheKey) {
64
- instance.subscribeOnDestroy(() => {
65
- persistenceCache[cacheKey] = instance.subStore.getData();
66
- });
67
- }
68
- }
69
-
70
- explore(context, instance) {
71
- if (!instance.subStore) this.initSubStore(context, instance);
72
- if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
73
- super.explore(context, instance);
74
- }
75
-
76
- exploreItems(context, instance, items) {
77
- if (!this.detached) {
78
- instance.container = instance.getChild(context, this.container, "container", instance.subStore);
79
- instance.container.scheduleExploreIfVisible(context);
80
- instance.children = [instance.container];
81
- }
82
- }
83
-
84
- render(context, instance, key) {
85
- if (!this.detached) return instance.container.render(context);
86
-
87
- return (
88
- <Cx
89
- key={key}
90
- widget={this.container}
91
- parentInstance={instance}
92
- store={instance.subStore}
93
- subscribe
94
- options={this.options}
95
- onError={this.onError}
96
- deferredUntilIdle={instance.data.deferredUntilIdle}
97
- idleTimeout={instance.data.idleTimeout}
98
- />
99
- );
100
- }
101
- }
102
-
103
- Restate.prototype.detached = false;
104
- Restate.prototype.waitForIdle = false;
105
-
106
- export const PrivateStore = Restate;
107
-
108
- class RestateStore extends Store {
109
- constructor(config) {
110
- super(config);
111
- this.parentDataVersion = -1;
112
- }
113
-
114
- getData() {
115
- this.silently(() => {
116
- this.parentDataCheck();
117
- });
118
- return super.getData();
119
- }
120
-
121
- parentDataCheck() {
122
- if (this.parentDataVersion == this.store.meta.version) return false;
123
- this.parentDataVersion = this.store.meta.version;
124
- this.parentData = this.dataSelector(this.store.getData());
125
- return this.batch(() => {
126
- for (let key in this.parentData) {
127
- super.setItem(key, this.parentData[key]);
128
- }
129
- });
130
- }
131
-
132
- setItem(path, value) {
133
- let binding = Binding.get(path);
134
- let bindingRoot = binding.parts[0];
135
- if (!isObject(this.privateData) || !this.privateData.hasOwnProperty(bindingRoot)) {
136
- let changed = isUndefined(value) ? super.deleteItem(path) : super.setItem(path, value);
137
- return changed;
138
- }
139
-
140
- let newValue = value;
141
- if (binding.parts.length > 1) newValue = binding.set(this.getData(), value)[bindingRoot];
142
- this.onSet(bindingRoot, newValue);
143
- this.batch(() => {
144
- super.setItem(bindingRoot, newValue);
145
- this.parentDataCheck();
146
- });
147
- return true;
148
- }
149
-
150
- deleteItem(path) {
151
- return this.setItem(path, undefined);
152
- }
153
-
154
- doNotify() {
155
- if (!this.detached) this.store.notify();
156
- super.doNotify();
157
- }
158
- }
1
+ import { PureContainer } from "./PureContainer";
2
+ import { Store } from "../data/Store";
3
+ import { Cx } from "./Cx";
4
+ import { isString } from "../util/isString";
5
+ import { VDOM } from "./VDOM";
6
+ import { isFunction } from "../util/isFunction";
7
+ import { isObject } from "../util/isObject";
8
+ import { isUndefined } from "../util/isUndefined";
9
+ import { Binding } from "../data/Binding";
10
+ import { StructuredSelector } from "../data/StructuredSelector";
11
+
12
+ let persistenceCache = {};
13
+
14
+ export class Restate extends PureContainer {
15
+ declareData() {
16
+ return super.declareData(...arguments, {
17
+ deferredUntilIdle: undefined,
18
+ idleTimeout: undefined,
19
+ cacheKey: undefined,
20
+ });
21
+ }
22
+
23
+ init() {
24
+ this.container = PureContainer.create({
25
+ type: PureContainer,
26
+ items: this.children || this.items,
27
+ layout: this.layout,
28
+ controller: this.controller,
29
+ outerLayout: this.outerLayout,
30
+ useParentLayout: !this.detached,
31
+ ws: this.ws,
32
+ });
33
+ this.privateDataSelector = new StructuredSelector({
34
+ props: this.data || {},
35
+ values: this.data,
36
+ });
37
+ delete this.items;
38
+ delete this.children;
39
+ delete this.controller;
40
+ delete this.outerLayout;
41
+ delete this.layout;
42
+ if (this.useParentLayout == null) this.useParentLayout = !this.detached;
43
+ super.init();
44
+ }
45
+
46
+ initSubStore(context, instance) {
47
+ let { cacheKey } = instance.data;
48
+ this.privateDataSelector.init(instance.store);
49
+ instance.subStore = new RestateStore({
50
+ store: instance.store,
51
+ detached: this.detached,
52
+ privateData: this.data || {},
53
+ data: cacheKey ? persistenceCache[cacheKey] || {} : {},
54
+ dataSelector: this.privateDataSelector.create(),
55
+ onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
56
+ });
57
+
58
+ instance.setStore = (store) => {
59
+ instance.store = store;
60
+ instance.subStore.setStore(store);
61
+ };
62
+
63
+ if (cacheKey) {
64
+ instance.subscribeOnDestroy(() => {
65
+ persistenceCache[cacheKey] = instance.subStore.getData();
66
+ });
67
+ }
68
+ }
69
+
70
+ explore(context, instance) {
71
+ if (!instance.subStore) this.initSubStore(context, instance);
72
+ if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
73
+ super.explore(context, instance);
74
+ }
75
+
76
+ exploreItems(context, instance, items) {
77
+ if (!this.detached) {
78
+ instance.container = instance.getChild(context, this.container, "container", instance.subStore);
79
+ instance.container.scheduleExploreIfVisible(context);
80
+ instance.children = [instance.container];
81
+ }
82
+ }
83
+
84
+ render(context, instance, key) {
85
+ if (!this.detached) return instance.container.render(context);
86
+
87
+ return (
88
+ <Cx
89
+ key={key}
90
+ widget={this.container}
91
+ parentInstance={instance}
92
+ store={instance.subStore}
93
+ subscribe
94
+ options={this.options}
95
+ onError={this.onError}
96
+ deferredUntilIdle={instance.data.deferredUntilIdle}
97
+ idleTimeout={instance.data.idleTimeout}
98
+ />
99
+ );
100
+ }
101
+ }
102
+
103
+ Restate.prototype.detached = false;
104
+ Restate.prototype.waitForIdle = false;
105
+
106
+ export const PrivateStore = Restate;
107
+
108
+ class RestateStore extends Store {
109
+ constructor(config) {
110
+ super(config);
111
+ this.parentDataVersion = -1;
112
+ }
113
+
114
+ getData() {
115
+ this.silently(() => {
116
+ this.parentDataCheck();
117
+ });
118
+ return super.getData();
119
+ }
120
+
121
+ parentDataCheck() {
122
+ if (this.parentDataVersion == this.store.meta.version) return false;
123
+ this.parentDataVersion = this.store.meta.version;
124
+ this.parentData = this.dataSelector(this.store.getData());
125
+ return this.batch(() => {
126
+ for (let key in this.parentData) {
127
+ super.setItem(key, this.parentData[key]);
128
+ }
129
+ });
130
+ }
131
+
132
+ setItem(path, value) {
133
+ let binding = Binding.get(path);
134
+ let bindingRoot = binding.parts[0];
135
+ if (!isObject(this.privateData) || !this.privateData.hasOwnProperty(bindingRoot)) {
136
+ let changed = isUndefined(value) ? super.deleteItem(path) : super.setItem(path, value);
137
+ return changed;
138
+ }
139
+
140
+ let newValue = value;
141
+ if (binding.parts.length > 1) newValue = binding.set(this.getData(), value)[bindingRoot];
142
+ this.onSet(bindingRoot, newValue);
143
+ this.batch(() => {
144
+ super.setItem(bindingRoot, newValue);
145
+ this.parentDataCheck();
146
+ });
147
+ return true;
148
+ }
149
+
150
+ deleteItem(path) {
151
+ return this.setItem(path, undefined);
152
+ }
153
+
154
+ doNotify() {
155
+ if (!this.detached) this.store.notify();
156
+ super.doNotify();
157
+ }
158
+ }
@@ -42,6 +42,7 @@ import { StaticText } from "../../ui/StaticText";
42
42
  import { unfocusElement } from "../../ui/FocusManager";
43
43
  import { tooltipMouseMove, tooltipMouseLeave } from "../overlay/tooltip-ops";
44
44
  import { Container } from "../../ui/Container";
45
+ import { findFirstChild } from "../../util/DOM";
45
46
 
46
47
  export class Grid extends Container {
47
48
  declareData(...args) {
@@ -510,13 +511,16 @@ export class Grid extends Container {
510
511
  onClick={(e) => {
511
512
  e.stopPropagation();
512
513
  }}
514
+ data-unique-col-id={hdwidget.uniqueColumnId}
513
515
  onMouseDown={(e) => {
514
516
  if (e.buttons != 1) return;
515
517
  let resizeOverlayEl = document.createElement("div");
516
- let headerCell = e.target.parentElement;
517
- if (forPreviousColumn) headerCell = headerCell.previousSibling;
518
+
519
+ let headerTBody = e.target.parentElement.parentElement.parentElement;
520
+ let uniqueColId = e.currentTarget.dataset.uniqueColId;
518
521
 
519
- let scrollAreaEl = headerCell.parentElement.parentElement.parentElement.parentElement;
522
+ let headerCell = findFirstChild(headerTBody, el => el.tagName == 'TH' && el.dataset?.uniqueColId == uniqueColId);
523
+ let scrollAreaEl = headerTBody.parentElement.parentElement;
520
524
  let gridEl = scrollAreaEl.parentElement;
521
525
  let initialWidth = headerCell.offsetWidth;
522
526
  let initialPosition = getCursorPos(e);
@@ -640,15 +644,17 @@ export class Grid extends Container {
640
644
  }
641
645
  }
642
646
 
647
+ let uniqueColumnId = header.data.colSpan > 1 ? null : hdwidget.uniqueColumnId;
648
+
643
649
  style = header.data.style;
644
650
  let customWidth =
645
651
  header.data.width ||
646
- instance.state.colWidth[hdwidget.uniqueColumnId] ||
652
+ instance.state.colWidth[uniqueColumnId] ||
647
653
  header.data.defaultWidth ||
648
- instance.state.lockedColWidth[hdwidget.uniqueColumnId];
654
+ instance.state.lockedColWidth[uniqueColumnId];
649
655
  if (customWidth) {
650
- if (instance.state.colWidth[hdwidget.uniqueColumnId] != customWidth)
651
- instance.state.colWidth[hdwidget.uniqueColumnId] = customWidth;
656
+ if (instance.state.colWidth[uniqueColumnId] != customWidth)
657
+ instance.state.colWidth[uniqueColumnId] = customWidth;
652
658
  let s = `${customWidth}px`;
653
659
  style = {
654
660
  ...style,
@@ -686,10 +692,15 @@ export class Grid extends Container {
686
692
 
687
693
  if (colIndex > 0) {
688
694
  let hdinstPrev = line.children[colIndex - 1];
689
- let headerPrev = hdinstPrev.components[`header${l + 1}`];
695
+ let prevLine = 3;
696
+ let headerPrev;
697
+ while (!headerPrev && prevLine >= 0) {
698
+ headerPrev = hdinstPrev.components[`header${prevLine + 1}`];
699
+ prevLine--;
700
+ }
690
701
  if (
691
- (hdinstPrev.widget.resizable || (headerPrev && headerPrev.data.resizable)) &&
692
- headerPrev.data.colSpan < 2
702
+ (hdinstPrev.widget.resizable || headerPrev?.data?.resizable) &&
703
+ headerPrev?.data?.colSpan < 2
693
704
  ) {
694
705
  prevColumnResizer = this.renderResizer(instance, hdinstPrev, headerPrev, colIndex - 1, true);
695
706
  }
@@ -714,7 +725,7 @@ export class Grid extends Container {
714
725
  onMouseLeave={(e) => this.onHeaderMouseLeave(e, hdinst, l)}
715
726
  onClick={(e) => this.onHeaderClick(e, hdwidget, instance, l)}
716
727
  onContextMenu={onContextMenu}
717
- data-unique-col-id={hdwidget.uniqueColumnId}
728
+ data-unique-col-id={colSpan > 1 ? null: hdwidget.uniqueColumnId}
718
729
  >
719
730
  {getContent(content)}
720
731
  {sortIcon}