cx 24.3.11 → 24.4.1

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/src/ui/Format.js CHANGED
@@ -1,107 +1,107 @@
1
- import { Culture, getCurrentCultureCache } from "./Culture";
2
- import { Format as Fmt, resolveMinMaxFractionDigits, setGetFormatCacheCallback } from "../util/Format";
3
- import { GlobalCacheIdentifier } from "../util/GlobalCacheIdentifier";
4
- import { setGetExpressionCacheCallback } from "../data/Expression";
5
- import { setGetStringTemplateCacheCallback } from "../data/StringTemplate";
6
-
7
- export const Format = Fmt;
8
-
9
- let cultureSensitiveFormatsRegistered = false;
10
-
11
- export function resolveNumberFormattingFlags(flags) {
12
- if (!flags) return null;
13
- let result = {};
14
- if (flags.indexOf("+") >= 0) result.signDisplay = "exceptZero";
15
- if (flags.indexOf("c") >= 0) result.notation = "compact";
16
- if (flags.indexOf("a") >= 0) result.currencySign = "accounting";
17
- return result;
18
- }
19
-
20
- export function enableCultureSensitiveFormatting() {
21
- if (cultureSensitiveFormatsRegistered) return;
22
-
23
- cultureSensitiveFormatsRegistered = true;
24
-
25
- Fmt.registerFactory(["number", "n"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
26
- let culture = Culture.getNumberCulture();
27
-
28
- let formatter = culture.getFormatter({
29
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
30
- ...resolveNumberFormattingFlags(flags),
31
- });
32
-
33
- return (value) => formatter.format(value);
34
- });
35
-
36
- Fmt.registerFactory("currency", (format, currency, minimumFractionDigits, maximumFractionDigits, flags) => {
37
- let culture = Culture.getNumberCulture();
38
- currency = currency || Culture.defaultCurrency;
39
-
40
- let formatter = culture.getFormatter({
41
- style: "currency",
42
- currency: currency,
43
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
44
- ...resolveNumberFormattingFlags(flags),
45
- });
46
-
47
- return (value) => formatter.format(value);
48
- });
49
-
50
- Fmt.registerFactory(["percentage", "p", "%"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
51
- let culture = Culture.getNumberCulture();
52
- let formatter = culture.getFormatter({
53
- style: "percent",
54
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
55
- ...resolveNumberFormattingFlags(flags),
56
- });
57
- return (value) => formatter.format(value);
58
- });
59
-
60
- Fmt.registerFactory(["percentSign", "ps"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
61
- let culture = Culture.getNumberCulture();
62
- let formatter = culture.getFormatter({
63
- style: "percent",
64
- ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
65
- ...resolveNumberFormattingFlags(flags),
66
- });
67
- return (value) => formatter.format(value / 100);
68
- });
69
-
70
- Fmt.registerFactory(["date", "d"], (fmt, format = "yyyyMMdd") => {
71
- let culture = Culture.getDateTimeCulture();
72
- let formatter = culture.getFormatter(format);
73
- return (value) => formatter.format(new Date(value));
74
- });
75
-
76
- Fmt.registerFactory(["time", "t"], (fmt, format = "hhmmss") => {
77
- let culture = Culture.getDateTimeCulture();
78
- let formatter = culture.getFormatter(format);
79
- return (value) => formatter.format(new Date(value));
80
- });
81
-
82
- Fmt.registerFactory(["datetime", "dt"], (fmt, format = "yyyyMd hhmm") => {
83
- let culture = Culture.getDateTimeCulture();
84
- let formatter = culture.getFormatter(format);
85
- return (value) => formatter.format(new Date(value));
86
- });
87
-
88
- setGetFormatCacheCallback(() => {
89
- let cache = getCurrentCultureCache();
90
- if (!cache.formatCache) cache.formatCache = {};
91
- return cache.formatCache;
92
- });
93
-
94
- setGetExpressionCacheCallback(() => {
95
- let cache = getCurrentCultureCache();
96
- if (!cache.exprCache) cache.exprCache = {};
97
- return cache.exprCache;
98
- });
99
-
100
- setGetStringTemplateCacheCallback(() => {
101
- let cache = getCurrentCultureCache();
102
- if (!cache.strTplCache) cache.strTplCache = {};
103
- return cache.strTplCache;
104
- });
105
-
106
- GlobalCacheIdentifier.change();
107
- }
1
+ import { Culture, getCurrentCultureCache } from "./Culture";
2
+ import { Format as Fmt, resolveMinMaxFractionDigits, setGetFormatCacheCallback } from "../util/Format";
3
+ import { GlobalCacheIdentifier } from "../util/GlobalCacheIdentifier";
4
+ import { setGetExpressionCacheCallback } from "../data/Expression";
5
+ import { setGetStringTemplateCacheCallback } from "../data/StringTemplate";
6
+
7
+ export const Format = Fmt;
8
+
9
+ let cultureSensitiveFormatsRegistered = false;
10
+
11
+ export function resolveNumberFormattingFlags(flags) {
12
+ if (!flags) return null;
13
+ let result = {};
14
+ if (flags.indexOf("+") >= 0) result.signDisplay = "exceptZero";
15
+ if (flags.indexOf("c") >= 0) result.notation = "compact";
16
+ if (flags.indexOf("a") >= 0) result.currencySign = "accounting";
17
+ return result;
18
+ }
19
+
20
+ export function enableCultureSensitiveFormatting() {
21
+ if (cultureSensitiveFormatsRegistered) return;
22
+
23
+ cultureSensitiveFormatsRegistered = true;
24
+
25
+ Fmt.registerFactory(["number", "n"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
26
+ let culture = Culture.getNumberCulture();
27
+
28
+ let formatter = culture.getFormatter({
29
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
30
+ ...resolveNumberFormattingFlags(flags),
31
+ });
32
+
33
+ return (value) => formatter.format(value);
34
+ });
35
+
36
+ Fmt.registerFactory("currency", (format, currency, minimumFractionDigits, maximumFractionDigits, flags) => {
37
+ let culture = Culture.getNumberCulture();
38
+ currency = currency || Culture.defaultCurrency;
39
+
40
+ let formatter = culture.getFormatter({
41
+ style: "currency",
42
+ currency: currency,
43
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
44
+ ...resolveNumberFormattingFlags(flags),
45
+ });
46
+
47
+ return (value) => formatter.format(value);
48
+ });
49
+
50
+ Fmt.registerFactory(["percentage", "p", "%"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
51
+ let culture = Culture.getNumberCulture();
52
+ let formatter = culture.getFormatter({
53
+ style: "percent",
54
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
55
+ ...resolveNumberFormattingFlags(flags),
56
+ });
57
+ return (value) => formatter.format(value);
58
+ });
59
+
60
+ Fmt.registerFactory(["percentSign", "ps"], (format, minimumFractionDigits, maximumFractionDigits, flags) => {
61
+ let culture = Culture.getNumberCulture();
62
+ let formatter = culture.getFormatter({
63
+ style: "percent",
64
+ ...resolveMinMaxFractionDigits(minimumFractionDigits, maximumFractionDigits),
65
+ ...resolveNumberFormattingFlags(flags),
66
+ });
67
+ return (value) => formatter.format(value / 100);
68
+ });
69
+
70
+ Fmt.registerFactory(["date", "d"], (fmt, format = "yyyyMMdd") => {
71
+ let culture = Culture.getDateTimeCulture();
72
+ let formatter = culture.getFormatter(format);
73
+ return (value) => formatter.format(new Date(value));
74
+ });
75
+
76
+ Fmt.registerFactory(["time", "t"], (fmt, format = "hhmmss") => {
77
+ let culture = Culture.getDateTimeCulture();
78
+ let formatter = culture.getFormatter(format);
79
+ return (value) => formatter.format(new Date(value));
80
+ });
81
+
82
+ Fmt.registerFactory(["datetime", "dt"], (fmt, format = "yyyyMd hhmm") => {
83
+ let culture = Culture.getDateTimeCulture();
84
+ let formatter = culture.getFormatter(format);
85
+ return (value) => formatter.format(new Date(value));
86
+ });
87
+
88
+ setGetFormatCacheCallback(() => {
89
+ let cache = getCurrentCultureCache();
90
+ if (!cache.formatCache) cache.formatCache = {};
91
+ return cache.formatCache;
92
+ });
93
+
94
+ setGetExpressionCacheCallback(() => {
95
+ let cache = getCurrentCultureCache();
96
+ if (!cache.exprCache) cache.exprCache = {};
97
+ return cache.exprCache;
98
+ });
99
+
100
+ setGetStringTemplateCacheCallback(() => {
101
+ let cache = getCurrentCultureCache();
102
+ if (!cache.strTplCache) cache.strTplCache = {};
103
+ return cache.strTplCache;
104
+ });
105
+
106
+ GlobalCacheIdentifier.change();
107
+ }
@@ -1,21 +1,21 @@
1
- import { Instance } from "./Instance";
2
- import * as Cx from "../core";
3
- import { CultureInfo } from "./Culture";
4
-
5
- interface RestateProps extends Cx.PureContainerProps {
6
- data?: Cx.StructuredProp;
7
- detached?: boolean;
8
- deferredUntilIdle?: Cx.BooleanProp;
9
- idleTimeout?: Cx.NumberProp;
10
- cacheKey?: Cx.StringProp;
11
-
12
- /* Set to true to disable batching of updates. */
13
- immediate?: boolean;
14
-
15
- onError?: (err: Error, instance: Instance) => void;
16
-
17
- culture?: CultureInfo;
18
- }
19
-
20
- export class Restate extends Cx.Widget<RestateProps> {}
21
- export class PrivateStore extends Cx.Widget<RestateProps> {}
1
+ import { Instance } from "./Instance";
2
+ import * as Cx from "../core";
3
+ import { CultureInfo } from "./Culture";
4
+
5
+ interface RestateProps extends Cx.PureContainerProps {
6
+ data?: Cx.StructuredProp;
7
+ detached?: boolean;
8
+ deferredUntilIdle?: Cx.BooleanProp;
9
+ idleTimeout?: Cx.NumberProp;
10
+ cacheKey?: Cx.StringProp;
11
+
12
+ /* Set to true to disable batching of updates. */
13
+ immediate?: boolean;
14
+
15
+ onError?: (err: Error, instance: Instance) => void;
16
+
17
+ culture?: CultureInfo;
18
+ }
19
+
20
+ export class Restate extends Cx.Widget<RestateProps> {}
21
+ export class PrivateStore extends Cx.Widget<RestateProps> {}
package/src/ui/Restate.js CHANGED
@@ -1,163 +1,163 @@
1
- import { PureContainer } from "./PureContainer";
2
- import { Store } from "../data/Store";
3
- import { Cx } from "./Cx";
4
- import { VDOM } from "./VDOM";
5
- import { isObject } from "../util/isObject";
6
- import { isUndefined } from "../util/isUndefined";
7
- import { Binding } from "../data/Binding";
8
- import { StructuredSelector } from "../data/StructuredSelector";
9
- import { getCurrentCulture } from "./Culture";
10
-
11
- let persistenceCache = {};
12
-
13
- export class Restate extends PureContainer {
14
- declareData() {
15
- return super.declareData(...arguments, {
16
- deferredUntilIdle: undefined,
17
- idleTimeout: undefined,
18
- cacheKey: undefined,
19
- });
20
- }
21
-
22
- init() {
23
- this.container = PureContainer.create({
24
- type: PureContainer,
25
- items: this.children || this.items,
26
- layout: this.layout,
27
- controller: this.controller,
28
- outerLayout: this.outerLayout,
29
- useParentLayout: !this.detached,
30
- ws: this.ws,
31
- });
32
- this.privateDataSelector = new StructuredSelector({
33
- props: this.data || {},
34
- values: this.data,
35
- });
36
- delete this.items;
37
- delete this.children;
38
- delete this.controller;
39
- delete this.outerLayout;
40
- delete this.layout;
41
- if (this.useParentLayout == null) this.useParentLayout = !this.detached;
42
- super.init();
43
- }
44
-
45
- initSubStore(context, instance) {
46
- let { cacheKey } = instance.data;
47
- this.privateDataSelector.init(instance.store);
48
- instance.subStore = new RestateStore({
49
- store: instance.store,
50
- detached: this.detached,
51
- privateData: this.data || {},
52
- data: cacheKey ? persistenceCache[cacheKey] || {} : {},
53
- dataSelector: this.privateDataSelector.create(),
54
- onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
55
- });
56
-
57
- instance.setStore = (store) => {
58
- instance.store = store;
59
- instance.subStore.setStore(store);
60
- };
61
-
62
- if (cacheKey) {
63
- instance.subscribeOnDestroy(() => {
64
- persistenceCache[cacheKey] = instance.subStore.getData();
65
- });
66
- }
67
- }
68
-
69
- explore(context, instance) {
70
- if (!instance.subStore) this.initSubStore(context, instance);
71
- if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
72
- instance.cultureInfo = this.culture ?? getCurrentCulture();
73
- if (instance.cache("cultureInfo", instance.culture)) instance.markShouldUpdate();
74
- super.explore(context, instance);
75
- }
76
-
77
- exploreItems(context, instance, items) {
78
- if (!this.detached) {
79
- instance.container = instance.getChild(context, this.container, "container", instance.subStore);
80
- instance.container.scheduleExploreIfVisible(context);
81
- instance.children = [instance.container];
82
- }
83
- }
84
-
85
- render(context, instance, key) {
86
- if (!this.detached) return instance.container.render(context);
87
-
88
- return (
89
- <Cx
90
- key={key}
91
- widget={this.container}
92
- parentInstance={instance}
93
- store={instance.subStore}
94
- subscribe
95
- options={this.options}
96
- onError={this.onError}
97
- deferredUntilIdle={instance.data.deferredUntilIdle}
98
- idleTimeout={instance.data.idleTimeout}
99
- immediate={this.immediate}
100
- cultureInfo={instance.cultureInfo}
101
- />
102
- );
103
- }
104
- }
105
-
106
- Restate.prototype.detached = false;
107
- Restate.prototype.waitForIdle = false;
108
- Restate.prototype.immediate = false;
109
- Restate.prototype.culture = null;
110
-
111
- export const PrivateStore = Restate;
112
-
113
- class RestateStore extends Store {
114
- constructor(config) {
115
- super(config);
116
- this.parentDataVersion = -1;
117
- }
118
-
119
- getData() {
120
- this.silently(() => {
121
- this.parentDataCheck();
122
- });
123
- return super.getData();
124
- }
125
-
126
- parentDataCheck() {
127
- if (this.parentDataVersion == this.store.meta.version) return false;
128
- this.parentDataVersion = this.store.meta.version;
129
- this.parentData = this.dataSelector(this.store.getData());
130
- return this.batch(() => {
131
- for (let key in this.parentData) {
132
- super.setItem(key, this.parentData[key]);
133
- }
134
- });
135
- }
136
-
137
- setItem(path, value) {
138
- let binding = Binding.get(path);
139
- let bindingRoot = binding.parts[0];
140
- if (!isObject(this.privateData) || !this.privateData.hasOwnProperty(bindingRoot)) {
141
- let changed = isUndefined(value) ? super.deleteItem(path) : super.setItem(path, value);
142
- return changed;
143
- }
144
-
145
- let newValue = value;
146
- if (binding.parts.length > 1) newValue = binding.set(this.getData(), value)[bindingRoot];
147
- this.onSet(bindingRoot, newValue);
148
- this.batch(() => {
149
- super.setItem(bindingRoot, newValue);
150
- this.parentDataCheck();
151
- });
152
- return true;
153
- }
154
-
155
- deleteItem(path) {
156
- return this.setItem(path, undefined);
157
- }
158
-
159
- doNotify() {
160
- if (!this.detached) this.store.notify();
161
- super.doNotify();
162
- }
163
- }
1
+ import { PureContainer } from "./PureContainer";
2
+ import { Store } from "../data/Store";
3
+ import { Cx } from "./Cx";
4
+ import { VDOM } from "./VDOM";
5
+ import { isObject } from "../util/isObject";
6
+ import { isUndefined } from "../util/isUndefined";
7
+ import { Binding } from "../data/Binding";
8
+ import { StructuredSelector } from "../data/StructuredSelector";
9
+ import { getCurrentCulture } from "./Culture";
10
+
11
+ let persistenceCache = {};
12
+
13
+ export class Restate extends PureContainer {
14
+ declareData() {
15
+ return super.declareData(...arguments, {
16
+ deferredUntilIdle: undefined,
17
+ idleTimeout: undefined,
18
+ cacheKey: undefined,
19
+ });
20
+ }
21
+
22
+ init() {
23
+ this.container = PureContainer.create({
24
+ type: PureContainer,
25
+ items: this.children || this.items,
26
+ layout: this.layout,
27
+ controller: this.controller,
28
+ outerLayout: this.outerLayout,
29
+ useParentLayout: !this.detached,
30
+ ws: this.ws,
31
+ });
32
+ this.privateDataSelector = new StructuredSelector({
33
+ props: this.data || {},
34
+ values: this.data,
35
+ });
36
+ delete this.items;
37
+ delete this.children;
38
+ delete this.controller;
39
+ delete this.outerLayout;
40
+ delete this.layout;
41
+ if (this.useParentLayout == null) this.useParentLayout = !this.detached;
42
+ super.init();
43
+ }
44
+
45
+ initSubStore(context, instance) {
46
+ let { cacheKey } = instance.data;
47
+ this.privateDataSelector.init(instance.store);
48
+ instance.subStore = new RestateStore({
49
+ store: instance.store,
50
+ detached: this.detached,
51
+ privateData: this.data || {},
52
+ data: cacheKey ? persistenceCache[cacheKey] || {} : {},
53
+ dataSelector: this.privateDataSelector.create(),
54
+ onSet: (path, value) => instance.nestedDataSet(path, value, this.data),
55
+ });
56
+
57
+ instance.setStore = (store) => {
58
+ instance.store = store;
59
+ instance.subStore.setStore(store);
60
+ };
61
+
62
+ if (cacheKey) {
63
+ instance.subscribeOnDestroy(() => {
64
+ persistenceCache[cacheKey] = instance.subStore.getData();
65
+ });
66
+ }
67
+ }
68
+
69
+ explore(context, instance) {
70
+ if (!instance.subStore) this.initSubStore(context, instance);
71
+ if (instance.subStore.parentDataCheck()) instance.markShouldUpdate();
72
+ instance.cultureInfo = this.culture ?? getCurrentCulture();
73
+ if (instance.cache("cultureInfo", instance.culture)) instance.markShouldUpdate();
74
+ super.explore(context, instance);
75
+ }
76
+
77
+ exploreItems(context, instance, items) {
78
+ if (!this.detached) {
79
+ instance.container = instance.getChild(context, this.container, "container", instance.subStore);
80
+ instance.container.scheduleExploreIfVisible(context);
81
+ instance.children = [instance.container];
82
+ }
83
+ }
84
+
85
+ render(context, instance, key) {
86
+ if (!this.detached) return instance.container.render(context);
87
+
88
+ return (
89
+ <Cx
90
+ key={key}
91
+ widget={this.container}
92
+ parentInstance={instance}
93
+ store={instance.subStore}
94
+ subscribe
95
+ options={this.options}
96
+ onError={this.onError}
97
+ deferredUntilIdle={instance.data.deferredUntilIdle}
98
+ idleTimeout={instance.data.idleTimeout}
99
+ immediate={this.immediate}
100
+ cultureInfo={instance.cultureInfo}
101
+ />
102
+ );
103
+ }
104
+ }
105
+
106
+ Restate.prototype.detached = false;
107
+ Restate.prototype.waitForIdle = false;
108
+ Restate.prototype.immediate = false;
109
+ Restate.prototype.culture = null;
110
+
111
+ export const PrivateStore = Restate;
112
+
113
+ class RestateStore extends Store {
114
+ constructor(config) {
115
+ super(config);
116
+ this.parentDataVersion = -1;
117
+ }
118
+
119
+ getData() {
120
+ this.silently(() => {
121
+ this.parentDataCheck();
122
+ });
123
+ return super.getData();
124
+ }
125
+
126
+ parentDataCheck() {
127
+ if (this.parentDataVersion == this.store.meta.version) return false;
128
+ this.parentDataVersion = this.store.meta.version;
129
+ this.parentData = this.dataSelector(this.store.getData());
130
+ return this.batch(() => {
131
+ for (let key in this.parentData) {
132
+ super.setItem(key, this.parentData[key]);
133
+ }
134
+ });
135
+ }
136
+
137
+ setItem(path, value) {
138
+ let binding = Binding.get(path);
139
+ let bindingRoot = binding.parts[0];
140
+ if (!isObject(this.privateData) || !this.privateData.hasOwnProperty(bindingRoot)) {
141
+ let changed = isUndefined(value) ? super.deleteItem(path) : super.setItem(path, value);
142
+ return changed;
143
+ }
144
+
145
+ let newValue = value;
146
+ if (binding.parts.length > 1) newValue = binding.set(this.getData(), value)[bindingRoot];
147
+ this.onSet(bindingRoot, newValue);
148
+ this.batch(() => {
149
+ super.setItem(bindingRoot, newValue);
150
+ this.parentDataCheck();
151
+ });
152
+ return true;
153
+ }
154
+
155
+ deleteItem(path) {
156
+ return this.setItem(path, undefined);
157
+ }
158
+
159
+ doNotify() {
160
+ if (!this.detached) this.store.notify();
161
+ super.doNotify();
162
+ }
163
+ }
package/src/ui/index.d.ts CHANGED
@@ -27,7 +27,6 @@ export * from "./keyboardShortcuts";
27
27
  export * from "./createFunctionalComponent";
28
28
  export * from "./StructuredInstanceDataAccessor";
29
29
  export * from "./HoverSync";
30
- export * from "./CultureScope";
31
30
 
32
31
  export * from "./selection/index";
33
32
  export * from "./layout/index";