cx 25.5.2 → 25.6.0

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,54 +1,54 @@
1
- import { View } from "./View";
2
- import { SubscriberList } from "../util/SubscriberList";
3
-
4
- export class SubscribableView extends View {
5
- constructor(config) {
6
- super(config);
7
- this.subscribers = new SubscriberList();
8
- this.changes = [];
9
- }
10
-
11
- subscribe(callback) {
12
- return this.subscribers.subscribe(callback);
13
- }
14
-
15
- unsubscribeAll() {
16
- this.subscribers.clear();
17
- }
18
-
19
- doNotify(path) {
20
- if (this.notificationsSuspended) return;
21
-
22
- if (!this.async) {
23
- this.subscribers.notify([path]);
24
- } else {
25
- this.changes.push(path || "");
26
- if (!this.scheduled) {
27
- this.scheduled = true;
28
- setTimeout(() => {
29
- this.scheduled = false;
30
- let changes = this.changes;
31
- this.changes = [];
32
- this.subscribers.notify(changes);
33
- }, 0);
34
- }
35
- }
36
- }
37
-
38
- silently(callback) {
39
- this.notificationsSuspended = (this.notificationsSuspended || 0) + 1;
40
- let wasDirty = this.dirty,
41
- dirty;
42
- this.dirty = false;
43
- try {
44
- callback(this);
45
- } finally {
46
- this.notificationsSuspended--;
47
- dirty = this.dirty;
48
- this.dirty = wasDirty;
49
- }
50
- return dirty;
51
- }
52
- }
53
-
54
- SubscribableView.prototype.async = false;
1
+ import { View } from "./View";
2
+ import { SubscriberList } from "../util/SubscriberList";
3
+
4
+ export class SubscribableView extends View {
5
+ constructor(config) {
6
+ super(config);
7
+ this.subscribers = new SubscriberList();
8
+ this.changes = [];
9
+ }
10
+
11
+ subscribe(callback) {
12
+ return this.subscribers.subscribe(callback);
13
+ }
14
+
15
+ unsubscribeAll() {
16
+ this.subscribers.clear();
17
+ }
18
+
19
+ doNotify(path) {
20
+ if (this.notificationsSuspended) return;
21
+
22
+ if (!this.async) {
23
+ this.subscribers.notify([path]);
24
+ } else {
25
+ this.changes.push(path || "");
26
+ if (!this.scheduled) {
27
+ this.scheduled = true;
28
+ setTimeout(() => {
29
+ this.scheduled = false;
30
+ let changes = this.changes;
31
+ this.changes = [];
32
+ this.subscribers.notify(changes);
33
+ }, 0);
34
+ }
35
+ }
36
+ }
37
+
38
+ silently(callback) {
39
+ this.notificationsSuspended = (this.notificationsSuspended || 0) + 1;
40
+ let wasDirty = this.dirty,
41
+ dirty;
42
+ this.dirty = false;
43
+ try {
44
+ callback(this);
45
+ } finally {
46
+ this.notificationsSuspended--;
47
+ dirty = this.dirty;
48
+ this.dirty = wasDirty;
49
+ }
50
+ return dirty;
51
+ }
52
+ }
53
+
54
+ SubscribableView.prototype.async = false;
@@ -1 +1 @@
1
- export function createFunctionalComponent<T, X>(factory: (props: T) => X): (props: T) => X;
1
+ export function createFunctionalComponent<T, X>(factory: (props: T) => X): (props: T) => X;
package/src/ui/index.d.ts CHANGED
@@ -1,42 +1,42 @@
1
- export * from "./Controller";
2
- export * from "./Widget";
3
- export * from "./Container";
4
- export * from "./PureContainer";
5
- export * from "./Repeater";
6
- export * from "./Rescope";
7
- export * from "./StaticText";
8
- export * from "./Text";
9
- export * from "./CSS";
10
- export * from "./CSSHelper";
11
- export * from "./FocusManager";
12
- export * from "./ResizeManager";
13
- export * from "./ZIndexManager";
14
- export * from "./Format";
15
- export * from "./Culture";
16
- export * from "./Localization";
17
- export * from "./Cx";
18
- export * from "./Instance";
19
- export * from "./RenderingContext";
20
- export * from "./ContentResolver";
21
- export * from "./batchUpdates";
22
- export * from "./IsolatedScope";
23
- export * from "./DetachedScope";
24
- export * from "./Restate";
25
- export * from "./DataProxy";
26
- export * from "./keyboardShortcuts";
27
- export * from "./createFunctionalComponent";
28
- export * from "./StructuredInstanceDataAccessor";
29
- export * from "./HoverSync";
30
-
31
- export * from "./selection/index";
32
- export * from "./layout/index";
33
- export * from "./app/index";
34
- export * from "./adapter/index";
35
-
36
- export * from "./bind";
37
- export * from "./tpl";
38
- export * from "./expr";
39
-
40
- //re-export computable here
41
- import { computable } from "../data/computable";
42
- export { computable };
1
+ export * from "./Controller";
2
+ export * from "./Widget";
3
+ export * from "./Container";
4
+ export * from "./PureContainer";
5
+ export * from "./Repeater";
6
+ export * from "./Rescope";
7
+ export * from "./StaticText";
8
+ export * from "./Text";
9
+ export * from "./CSS";
10
+ export * from "./CSSHelper";
11
+ export * from "./FocusManager";
12
+ export * from "./ResizeManager";
13
+ export * from "./ZIndexManager";
14
+ export * from "./Format";
15
+ export * from "./Culture";
16
+ export * from "./Localization";
17
+ export * from "./Cx";
18
+ export * from "./Instance";
19
+ export * from "./RenderingContext";
20
+ export * from "./ContentResolver";
21
+ export * from "./batchUpdates";
22
+ export * from "./IsolatedScope";
23
+ export * from "./DetachedScope";
24
+ export * from "./Restate";
25
+ export * from "./DataProxy";
26
+ export * from "./keyboardShortcuts";
27
+ export * from "./createFunctionalComponent";
28
+ export * from "./StructuredInstanceDataAccessor";
29
+ export * from "./HoverSync";
30
+
31
+ export * from "./selection/index";
32
+ export * from "./layout/index";
33
+ export * from "./app/index";
34
+ export * from "./adapter/index";
35
+
36
+ export * from "./bind";
37
+ export * from "./tpl";
38
+ export * from "./expr";
39
+
40
+ //re-export computable here
41
+ import { computable } from "../data/computable";
42
+ export { computable };
@@ -1,18 +1,18 @@
1
- export function debounce(callback, delay) {
2
- let timer;
3
-
4
- let result = function (...args) {
5
- let context = this;
6
- clearTimeout(timer);
7
- timer = setTimeout(function () {
8
- callback.apply(context, args);
9
- }, delay);
10
- };
11
-
12
- result.reset = function reset(...args) {
13
- clearTimeout(timer);
14
- callback.apply(this, args);
15
- };
16
-
17
- return result;
18
- }
1
+ export function debounce(callback, delay) {
2
+ let timer;
3
+
4
+ let result = function (...args) {
5
+ let context = this;
6
+ clearTimeout(timer);
7
+ timer = setTimeout(function () {
8
+ callback.apply(context, args);
9
+ }, delay);
10
+ };
11
+
12
+ result.reset = function reset(...args) {
13
+ clearTimeout(timer);
14
+ callback.apply(this, args);
15
+ };
16
+
17
+ return result;
18
+ }
@@ -1,19 +1,19 @@
1
- export function validatedDebounce(callback, valueGetter, delay) {
2
- let timer;
3
- let result = function (...args) {
4
- clearTimeout(timer);
5
- let prev = valueGetter();
6
- timer = setTimeout(function () {
7
- let now = valueGetter();
8
- if (prev !== now) return;
9
- callback(...args);
10
- }, delay);
11
- };
12
-
13
- result.reset = function reset(...args) {
14
- clearTimeout(timer);
15
- callback(...args);
16
- };
17
-
18
- return result;
19
- }
1
+ export function validatedDebounce(callback, valueGetter, delay) {
2
+ let timer;
3
+ let result = function (...args) {
4
+ clearTimeout(timer);
5
+ let prev = valueGetter();
6
+ timer = setTimeout(function () {
7
+ let now = valueGetter();
8
+ if (prev !== now) return;
9
+ callback(...args);
10
+ }, delay);
11
+ };
12
+
13
+ result.reset = function reset(...args) {
14
+ clearTimeout(timer);
15
+ callback(...args);
16
+ };
17
+
18
+ return result;
19
+ }
@@ -1,118 +1,118 @@
1
- import { Widget, VDOM, getContentArray } from "../ui/Widget";
2
- import { HtmlElement } from "./HtmlElement";
3
- import { yesNo } from "./overlay/alerts";
4
- import { Icon } from "./Icon";
5
- import { preventFocus } from "../ui/FocusManager";
6
- import { isFunction } from "../util/isFunction";
7
- import { isDefined } from "../util/isDefined";
8
- import { coalesce } from "../util/coalesce";
9
-
10
- export class Button extends HtmlElement {
11
- declareData() {
12
- super.declareData(...arguments, {
13
- confirm: { structured: true },
14
- pressed: undefined,
15
- icon: undefined,
16
- disabled: undefined,
17
- enabled: undefined,
18
- });
19
- }
20
-
21
- prepareData(context, instance) {
22
- let { data } = instance;
23
- data.stateMods = {
24
- ...data.stateMods,
25
- pressed: data.pressed,
26
- };
27
- if (isDefined(data.enabled)) data.disabled = !data.enabled;
28
-
29
- super.prepareData(context, instance);
30
- }
31
-
32
- explore(context, instance) {
33
- instance.data.parentDisabled = context.parentDisabled;
34
- instance.data.parentStrict = context.parentStrict;
35
-
36
- if (instance.cache("parentDisabled", context.parentDisabled)) instance.markShouldUpdate(context);
37
- if (instance.cache("parentStrict", context.parentStrict)) instance.markShouldUpdate(context);
38
-
39
- super.explore(context, instance);
40
- }
41
-
42
- attachProps(context, instance, props) {
43
- super.attachProps(context, instance, props);
44
-
45
- if (!this.focusOnMouseDown) {
46
- props.onMouseDown = (e) => {
47
- if (this.onMouseDown && instance.invoke("onMouseDown", e, instance) == false) return;
48
- preventFocus(e);
49
- };
50
- }
51
-
52
- if (this.dismiss) {
53
- let { onClick } = props;
54
-
55
- props.onClick = (...args) => {
56
- if (onClick && onClick(...args) === false) return;
57
-
58
- if (instance.parentOptions && isFunction(instance.parentOptions.dismiss)) instance.parentOptions.dismiss();
59
- };
60
- }
61
-
62
- if (this.tag === "button") props.type = this.submit ? "submit" : "button";
63
-
64
- delete props.confirm;
65
- delete props.dismiss;
66
- delete props.pressed;
67
- delete props.submit;
68
- delete props.focusOnMouseDown;
69
- delete props.icon;
70
- delete props.enabled;
71
-
72
- let oldOnClick,
73
- { data } = instance;
74
-
75
- props.disabled = coalesce(data.parentStrict ? data.parentDisabled : null, data.disabled, data.parentDisabled);
76
-
77
- if (data.confirm) {
78
- oldOnClick = props.onClick;
79
- props.onClick = () => {
80
- yesNo(data.confirm).then((btn) => {
81
- if (btn == "yes") oldOnClick.call(this, null, instance);
82
- });
83
- };
84
- }
85
-
86
- let icon, children;
87
-
88
- if (data.icon) {
89
- icon = Icon.render(data.icon, {
90
- key: "icon",
91
- className: this.CSS.element(this.baseClass, "icon"),
92
- });
93
- children = getContentArray(props.children);
94
- props.children = [icon, ...children];
95
- props.className = this.CSS.expand(
96
- props.className,
97
- this.CSS.state("icon"),
98
- children.length == 0 && this.CSS.state("empty")
99
- );
100
-
101
- if (children.length == 0) {
102
- props.children.push(
103
- <span key="baseline" className={this.CSS.element(this.baseClass, "baseline")}>
104
- &nbsp;
105
- </span>
106
- );
107
- }
108
- }
109
- }
110
- }
111
-
112
- Button.prototype.tag = "button";
113
- Button.prototype.baseClass = "button";
114
- Button.prototype.icon = false;
115
- Button.prototype.focusOnMouseDown = false;
116
- Button.prototype.submit = false;
117
-
118
- Widget.alias("button", Button);
1
+ import { Widget, VDOM, getContentArray } from "../ui/Widget";
2
+ import { HtmlElement } from "./HtmlElement";
3
+ import { yesNo } from "./overlay/alerts";
4
+ import { Icon } from "./Icon";
5
+ import { preventFocus } from "../ui/FocusManager";
6
+ import { isFunction } from "../util/isFunction";
7
+ import { isDefined } from "../util/isDefined";
8
+ import { coalesce } from "../util/coalesce";
9
+
10
+ export class Button extends HtmlElement {
11
+ declareData() {
12
+ super.declareData(...arguments, {
13
+ confirm: { structured: true },
14
+ pressed: undefined,
15
+ icon: undefined,
16
+ disabled: undefined,
17
+ enabled: undefined,
18
+ });
19
+ }
20
+
21
+ prepareData(context, instance) {
22
+ let { data } = instance;
23
+ data.stateMods = {
24
+ ...data.stateMods,
25
+ pressed: data.pressed,
26
+ };
27
+ if (isDefined(data.enabled)) data.disabled = !data.enabled;
28
+
29
+ super.prepareData(context, instance);
30
+ }
31
+
32
+ explore(context, instance) {
33
+ instance.data.parentDisabled = context.parentDisabled;
34
+ instance.data.parentStrict = context.parentStrict;
35
+
36
+ if (instance.cache("parentDisabled", context.parentDisabled)) instance.markShouldUpdate(context);
37
+ if (instance.cache("parentStrict", context.parentStrict)) instance.markShouldUpdate(context);
38
+
39
+ super.explore(context, instance);
40
+ }
41
+
42
+ attachProps(context, instance, props) {
43
+ super.attachProps(context, instance, props);
44
+
45
+ if (!this.focusOnMouseDown) {
46
+ props.onMouseDown = (e) => {
47
+ if (this.onMouseDown && instance.invoke("onMouseDown", e, instance) == false) return;
48
+ preventFocus(e);
49
+ };
50
+ }
51
+
52
+ if (this.dismiss) {
53
+ let { onClick } = props;
54
+
55
+ props.onClick = (...args) => {
56
+ if (onClick && onClick(...args) === false) return;
57
+
58
+ if (instance.parentOptions && isFunction(instance.parentOptions.dismiss)) instance.parentOptions.dismiss();
59
+ };
60
+ }
61
+
62
+ if (this.tag === "button") props.type = this.submit ? "submit" : "button";
63
+
64
+ delete props.confirm;
65
+ delete props.dismiss;
66
+ delete props.pressed;
67
+ delete props.submit;
68
+ delete props.focusOnMouseDown;
69
+ delete props.icon;
70
+ delete props.enabled;
71
+
72
+ let oldOnClick,
73
+ { data } = instance;
74
+
75
+ props.disabled = coalesce(data.parentStrict ? data.parentDisabled : null, data.disabled, data.parentDisabled);
76
+
77
+ if (data.confirm) {
78
+ oldOnClick = props.onClick;
79
+ props.onClick = () => {
80
+ yesNo(data.confirm).then((btn) => {
81
+ if (btn == "yes") oldOnClick.call(this, null, instance);
82
+ });
83
+ };
84
+ }
85
+
86
+ let icon, children;
87
+
88
+ if (data.icon) {
89
+ icon = Icon.render(data.icon, {
90
+ key: "icon",
91
+ className: this.CSS.element(this.baseClass, "icon"),
92
+ });
93
+ children = getContentArray(props.children);
94
+ props.children = [icon, ...children];
95
+ props.className = this.CSS.expand(
96
+ props.className,
97
+ this.CSS.state("icon"),
98
+ children.length == 0 && this.CSS.state("empty")
99
+ );
100
+
101
+ if (children.length == 0) {
102
+ props.children.push(
103
+ <span key="baseline" className={this.CSS.element(this.baseClass, "baseline")}>
104
+ &nbsp;
105
+ </span>
106
+ );
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ Button.prototype.tag = "button";
113
+ Button.prototype.baseClass = "button";
114
+ Button.prototype.icon = false;
115
+ Button.prototype.focusOnMouseDown = false;
116
+ Button.prototype.submit = false;
117
+
118
+ Widget.alias("button", Button);