cx 25.5.0 → 25.5.2

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,154 +1,154 @@
1
- import { contentAppend, Widget } from "./Widget";
2
- import { StaticText } from "./StaticText";
3
- import { Text } from "./Text";
4
- import { innerTextTrim } from "../util/innerTextTrim";
5
- import { isString } from "../util/isString";
6
- import { isArray } from "../util/isArray";
7
- import { exploreChildren } from "./layout/exploreChildren";
8
-
9
- export class Container extends Widget {
10
- init(context) {
11
- if (typeof this.ws !== "undefined") this.preserveWhitespace = this.ws;
12
-
13
- if (this.preserveWhitespace) this.trimWhitespace = false;
14
-
15
- let items = this.items || this.children || [];
16
- delete this.children;
17
- this.items = [];
18
-
19
- if (this.layout) {
20
- let layout = Widget.create({ type: this.layout, items });
21
- layout.init(context);
22
- this.layout = null;
23
- if (layout.noLayout) {
24
- this.useParentLayout = true;
25
- this.add(items);
26
- } else {
27
- this.add(layout);
28
- this.layout = layout;
29
- }
30
- } else {
31
- this.add(items);
32
- }
33
-
34
- super.init(context);
35
- }
36
-
37
- exploreItems(context, instance, items) {
38
- instance.children = exploreChildren(context, instance, items, instance.cached.children, null, instance.store);
39
- if (instance.cache("children", instance.children)) instance.markShouldUpdate(context);
40
- }
41
-
42
- explore(context, instance) {
43
- super.explore(context, instance);
44
- this.exploreItems(context, instance, this.items);
45
- }
46
-
47
- render(context, instance) {
48
- return this.renderChildren(context, instance);
49
- }
50
-
51
- renderChildren(context, instance) {
52
- let preserveComplexContent = this.useParentLayout;
53
-
54
- function append(result, r) {
55
- if (r == null) return;
56
-
57
- //react element
58
- if (!r.hasOwnProperty("content")) {
59
- contentAppend(result, r);
60
- return;
61
- }
62
-
63
- if (r.useParentLayout) return r.content.forEach((x) => append(result, x));
64
-
65
- if (r.atomic || preserveComplexContent) {
66
- result.push(r);
67
- } else {
68
- let first = true;
69
- for (let k in r) if (contentAppend(result, r[k], !first)) first = false;
70
- }
71
- }
72
-
73
- let result = [];
74
- for (let i = 0; i < instance.children.length; i++) {
75
- append(result, instance.children[i].vdom);
76
- }
77
-
78
- if (this.useParentLayout)
79
- return {
80
- useParentLayout: true,
81
- content: result,
82
- };
83
-
84
- return result;
85
- }
86
-
87
- clear() {
88
- if (this.layout) this.layout.clear();
89
- else this.items = [];
90
- }
91
-
92
- add(...args) {
93
- if (this.layout) return this.layout.add(...args);
94
-
95
- args.forEach((a) => {
96
- if (!a) return;
97
- if (isArray(a)) a.forEach((c) => this.add(c));
98
- else if (isString(a)) {
99
- if (this.trimWhitespace) a = innerTextTrim(a);
100
- if (a) this.addText(a);
101
- } else if (a.isComponent) this.items.push(this.wrapItem(a));
102
- else {
103
- this.add(Widget.create(a, this.itemDefaults));
104
- }
105
- });
106
- }
107
-
108
- wrapItem(item) {
109
- return item;
110
- }
111
-
112
- addText(text) {
113
- if (this.plainText || text.indexOf("{") == -1 || text.indexOf("}") == -1)
114
- this.add(Widget.create(StaticText, { text: text }));
115
- else this.add(Widget.create(Text, { text: { tpl: text } }));
116
- }
117
-
118
- find(filter, options) {
119
- if (!options) options = {};
120
-
121
- if (!filter || !this.items) return [];
122
-
123
- let alias = filter;
124
-
125
- if (isString(filter)) filter = (w) => w.componentAlias == alias;
126
-
127
- if (filter.isComponentType) filter = (w) => w instanceof alias;
128
-
129
- let results = [];
130
-
131
- for (let i = 0; i < this.items.length; i++) {
132
- let w = this.items[i];
133
-
134
- if (!w.initialized) w.init();
135
-
136
- if (filter(w)) {
137
- results.push(w);
138
- if (options.first) break;
139
- }
140
-
141
- if (w.find) results.push(...w.find(filter, options));
142
- }
143
-
144
- return results;
145
- }
146
-
147
- findFirst(filter, options) {
148
- return this.find(filter, { ...options, first: true })[0];
149
- }
150
- }
151
-
152
- Container.prototype.trimWhitespace = true;
153
- Container.prototype.plainText = true;
154
- Container.prototype.styled = false;
1
+ import { contentAppend, Widget } from "./Widget";
2
+ import { StaticText } from "./StaticText";
3
+ import { Text } from "./Text";
4
+ import { innerTextTrim } from "../util/innerTextTrim";
5
+ import { isString } from "../util/isString";
6
+ import { isArray } from "../util/isArray";
7
+ import { exploreChildren } from "./layout/exploreChildren";
8
+
9
+ export class Container extends Widget {
10
+ init(context) {
11
+ if (typeof this.ws !== "undefined") this.preserveWhitespace = this.ws;
12
+
13
+ if (this.preserveWhitespace) this.trimWhitespace = false;
14
+
15
+ let items = this.items || this.children || [];
16
+ delete this.children;
17
+ this.items = [];
18
+
19
+ if (this.layout) {
20
+ let layout = Widget.create({ type: this.layout, items });
21
+ layout.init(context);
22
+ this.layout = null;
23
+ if (layout.noLayout) {
24
+ this.useParentLayout = true;
25
+ this.add(items);
26
+ } else {
27
+ this.add(layout);
28
+ this.layout = layout;
29
+ }
30
+ } else {
31
+ this.add(items);
32
+ }
33
+
34
+ super.init(context);
35
+ }
36
+
37
+ exploreItems(context, instance, items) {
38
+ instance.children = exploreChildren(context, instance, items, instance.cached.children, null, instance.store);
39
+ if (instance.cache("children", instance.children)) instance.markShouldUpdate(context);
40
+ }
41
+
42
+ explore(context, instance) {
43
+ super.explore(context, instance);
44
+ this.exploreItems(context, instance, this.items);
45
+ }
46
+
47
+ render(context, instance) {
48
+ return this.renderChildren(context, instance);
49
+ }
50
+
51
+ renderChildren(context, instance) {
52
+ let preserveComplexContent = this.useParentLayout;
53
+
54
+ function append(result, r) {
55
+ if (r == null) return;
56
+
57
+ //react element
58
+ if (!r.hasOwnProperty("content")) {
59
+ contentAppend(result, r);
60
+ return;
61
+ }
62
+
63
+ if (r.useParentLayout) return r.content.forEach((x) => append(result, x));
64
+
65
+ if (r.atomic || preserveComplexContent) {
66
+ result.push(r);
67
+ } else {
68
+ let first = true;
69
+ for (let k in r) if (contentAppend(result, r[k], !first)) first = false;
70
+ }
71
+ }
72
+
73
+ let result = [];
74
+ for (let i = 0; i < instance.children.length; i++) {
75
+ append(result, instance.children[i].vdom);
76
+ }
77
+
78
+ if (this.useParentLayout)
79
+ return {
80
+ useParentLayout: true,
81
+ content: result,
82
+ };
83
+
84
+ return result;
85
+ }
86
+
87
+ clear() {
88
+ if (this.layout) this.layout.clear();
89
+ else this.items = [];
90
+ }
91
+
92
+ add(...args) {
93
+ if (this.layout) return this.layout.add(...args);
94
+
95
+ args.forEach((a) => {
96
+ if (!a) return;
97
+ if (isArray(a)) a.forEach((c) => this.add(c));
98
+ else if (isString(a)) {
99
+ if (this.trimWhitespace) a = innerTextTrim(a);
100
+ if (a) this.addText(a);
101
+ } else if (a.isComponent) this.items.push(this.wrapItem(a));
102
+ else {
103
+ this.add(Widget.create(a, this.itemDefaults));
104
+ }
105
+ });
106
+ }
107
+
108
+ wrapItem(item) {
109
+ return item;
110
+ }
111
+
112
+ addText(text) {
113
+ if (this.plainText || text.indexOf("{") == -1 || text.indexOf("}") == -1)
114
+ this.add(Widget.create(StaticText, { text: text }));
115
+ else this.add(Widget.create(Text, { text: { tpl: text } }));
116
+ }
117
+
118
+ find(filter, options) {
119
+ if (!options) options = {};
120
+
121
+ if (!filter || !this.items) return [];
122
+
123
+ let alias = filter;
124
+
125
+ if (isString(filter)) filter = (w) => w.componentAlias == alias;
126
+
127
+ if (filter.isComponentType) filter = (w) => w instanceof alias;
128
+
129
+ let results = [];
130
+
131
+ for (let i = 0; i < this.items.length; i++) {
132
+ let w = this.items[i];
133
+
134
+ if (!w.initialized) w.init();
135
+
136
+ if (filter(w)) {
137
+ results.push(w);
138
+ if (options.first) break;
139
+ }
140
+
141
+ if (w.find) results.push(...w.find(filter, options));
142
+ }
143
+
144
+ return results;
145
+ }
146
+
147
+ findFirst(filter, options) {
148
+ return this.find(filter, { ...options, first: true })[0];
149
+ }
150
+ }
151
+
152
+ Container.prototype.trimWhitespace = true;
153
+ Container.prototype.plainText = true;
154
+ Container.prototype.styled = false;
@@ -1,45 +1,31 @@
1
- import { NestedDataView } from "../data/NestedDataView";
2
- import { UseParentLayout } from "../ui/layout/UseParentLayout";
3
- import { PureContainer } from "./PureContainer";
4
- import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
5
-
6
- export class DataProxy extends PureContainer {
7
- init() {
8
- if (!this.data) this.data = {};
9
-
10
- if (this.alias) this.data[this.alias] = this.value;
11
-
12
- // nesting is required to avoid resetting the store on every render and recalculating the data
13
- this.container = PureContainer.create({
14
- type: PureContainer,
15
- items: this.children || this.items,
16
- layout: this.layout,
17
- controller: this.controller,
18
- outerLayout: this.outerLayout,
19
- ws: this.ws,
20
- });
21
- this.children = [this.container];
22
- delete this.items;
23
- delete this.controller;
24
- delete this.outerLayout;
25
- this.layout = UseParentLayout;
26
- super.init();
27
- }
28
-
29
- initInstance(context, instance) {
30
- instance.store = new NestedDataView({
31
- store: instance.parentStore,
32
- nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
33
- immutable: this.immutable,
34
- sealed: this.sealed,
35
- });
36
- super.initInstance(context, instance);
37
- }
38
-
39
- applyParentStore(instance) {
40
- instance.store.setStore(instance.parentStore);
41
- }
42
- }
43
-
44
- DataProxy.prototype.immutable = false;
45
- DataProxy.prototype.sealed = false;
1
+ import { NestedDataView } from "../data/NestedDataView";
2
+ import { UseParentLayout } from "../ui/layout/UseParentLayout";
3
+ import { PureContainer } from "./PureContainer";
4
+ import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
5
+
6
+ export class DataProxy extends PureContainer {
7
+ init() {
8
+ if (!this.data) this.data = {};
9
+
10
+ if (this.alias) this.data[this.alias] = this.value;
11
+
12
+ super.init();
13
+ }
14
+
15
+ initInstance(context, instance) {
16
+ instance.store = new NestedDataView({
17
+ store: instance.parentStore,
18
+ nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
19
+ immutable: this.immutable,
20
+ sealed: this.sealed,
21
+ });
22
+ super.initInstance(context, instance);
23
+ }
24
+
25
+ applyParentStore(instance) {
26
+ instance.store.setStore(instance.parentStore);
27
+ }
28
+ }
29
+
30
+ DataProxy.prototype.immutable = false;
31
+ DataProxy.prototype.sealed = false;
@@ -1,98 +1,98 @@
1
- import { PureContainer } from "./PureContainer";
2
- import { SubscribableView } from "../data/SubscribableView";
3
- import { getSelector } from "../data/getSelector";
4
- import { Cx } from "./Cx";
5
- import { VDOM } from "./Widget";
6
- import { IsolatedScope } from "./IsolatedScope";
7
-
8
- export class DetachedScope extends IsolatedScope {
9
- declareData() {
10
- return super.declareData(...arguments, {
11
- exclusiveData: { structured: true },
12
- });
13
- }
14
-
15
- init() {
16
- if (typeof this.exclusive === "string") this.exclusiveData = { bind: this.exclusive };
17
- if (Array.isArray(this.exclusive)) {
18
- this.exclusiveData = {};
19
- this.exclusive.forEach((x, i) => {
20
- this.exclusiveData[String(i)] = { bind: x };
21
- });
22
- }
23
-
24
- this.container = PureContainer.create({
25
- type: PureContainer,
26
- items: this.children || this.items,
27
- });
28
- delete this.items;
29
- delete this.children;
30
-
31
- if (this.name)
32
- this.options = {
33
- ...this.options,
34
- name: this.name,
35
- };
36
-
37
- super.init();
38
- }
39
-
40
- initInstance(context, instance) {
41
- instance.subStore = new ContainmentStore({
42
- store: instance.store,
43
- selector: getSelector(this.exclusiveData || this.data),
44
- });
45
- }
46
-
47
- applyParentStore(instance) {
48
- instance.store = instance.parentStore;
49
- instance.subStore.setStore(instance.parentStore);
50
- }
51
-
52
- render(context, instance, key) {
53
- return (
54
- <Cx
55
- key={key}
56
- widget={this.container}
57
- store={instance.subStore}
58
- parentInstance={instance}
59
- subscribe
60
- options={this.options}
61
- onError={this.onError}
62
- />
63
- );
64
- }
65
- }
66
-
67
- class ContainmentStore extends SubscribableView {
68
- getData() {
69
- return this.store.getData();
70
- }
71
-
72
- setItem(...args) {
73
- return this.wrapper(() => {
74
- this.store.setItem(...args);
75
- });
76
- }
77
-
78
- deleteItem(...args) {
79
- return this.wrapper(() => {
80
- this.store.deleteItem(...args);
81
- });
82
- }
83
-
84
- wrapper(callback) {
85
- if (this.store.silently(callback)) {
86
- let data = this.getData();
87
- let containedData = this.selector(data);
88
- if (containedData === this.cache.containedData) {
89
- this.store.notify();
90
- } else {
91
- this.cache.containedData = containedData;
92
- this.notify();
93
- }
94
- return true;
95
- }
96
- return false;
97
- }
98
- }
1
+ import { PureContainer } from "./PureContainer";
2
+ import { SubscribableView } from "../data/SubscribableView";
3
+ import { getSelector } from "../data/getSelector";
4
+ import { Cx } from "./Cx";
5
+ import { VDOM } from "./Widget";
6
+ import { IsolatedScope } from "./IsolatedScope";
7
+
8
+ export class DetachedScope extends IsolatedScope {
9
+ declareData() {
10
+ return super.declareData(...arguments, {
11
+ exclusiveData: { structured: true },
12
+ });
13
+ }
14
+
15
+ init() {
16
+ if (typeof this.exclusive === "string") this.exclusiveData = { bind: this.exclusive };
17
+ if (Array.isArray(this.exclusive)) {
18
+ this.exclusiveData = {};
19
+ this.exclusive.forEach((x, i) => {
20
+ this.exclusiveData[String(i)] = { bind: x };
21
+ });
22
+ }
23
+
24
+ this.container = PureContainer.create({
25
+ type: PureContainer,
26
+ items: this.children || this.items,
27
+ });
28
+ delete this.items;
29
+ delete this.children;
30
+
31
+ if (this.name)
32
+ this.options = {
33
+ ...this.options,
34
+ name: this.name,
35
+ };
36
+
37
+ super.init();
38
+ }
39
+
40
+ initInstance(context, instance) {
41
+ instance.subStore = new ContainmentStore({
42
+ store: instance.store,
43
+ selector: getSelector(this.exclusiveData || this.data),
44
+ });
45
+ }
46
+
47
+ applyParentStore(instance) {
48
+ instance.store = instance.parentStore;
49
+ instance.subStore.setStore(instance.parentStore);
50
+ }
51
+
52
+ render(context, instance, key) {
53
+ return (
54
+ <Cx
55
+ key={key}
56
+ widget={this.container}
57
+ store={instance.subStore}
58
+ parentInstance={instance}
59
+ subscribe
60
+ options={this.options}
61
+ onError={this.onError}
62
+ />
63
+ );
64
+ }
65
+ }
66
+
67
+ class ContainmentStore extends SubscribableView {
68
+ getData() {
69
+ return this.store.getData();
70
+ }
71
+
72
+ setItem(...args) {
73
+ return this.wrapper(() => {
74
+ this.store.setItem(...args);
75
+ });
76
+ }
77
+
78
+ deleteItem(...args) {
79
+ return this.wrapper(() => {
80
+ this.store.deleteItem(...args);
81
+ });
82
+ }
83
+
84
+ wrapper(callback) {
85
+ if (this.store.silently(callback)) {
86
+ let data = this.getData();
87
+ let containedData = this.selector(data);
88
+ if (containedData === this.cache.containedData) {
89
+ this.store.notify();
90
+ } else {
91
+ this.cache.containedData = containedData;
92
+ this.notify();
93
+ }
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+ }