cx 24.4.6 → 24.4.7

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,72 +1,72 @@
1
- import { Record } from "../core";
2
- import { RenderingContext } from "./RenderingContext";
3
- import { View } from "../data/View";
4
- import { Widget } from "./Widget";
5
-
6
- export class Instance<ViewModel = any, Controller = any> {
7
- store: View<ViewModel>;
8
- data: Record;
9
- widget: Widget;
10
- key: number;
11
- id: string;
12
- controller: Controller;
13
- parentOptions: any;
14
- children?: Instance[];
15
-
16
- constructor(widget: Widget, key: string | number, parent?: Instance, store?: View);
17
-
18
- setStore(store: View): void;
19
-
20
- init(context: RenderingContext): void;
21
-
22
- explore(context: RenderingContext): boolean;
23
-
24
- prepare(context: RenderingContext): void;
25
-
26
- cleanup(context: RenderingContext): void;
27
-
28
- render(context: RenderingContext, keyPrefix?: string): JSX.Element | void;
29
-
30
- setState(state: Cx.Record): void;
31
-
32
- set(prop: string, value: any, internal?: boolean);
33
-
34
- definePropertySetter(prop: string, setter: (value: any) => void): boolean;
35
-
36
- /**
37
- * @protected
38
- * @param prop
39
- * @param value
40
- * @returns {boolean}
41
- */
42
- protected doSet(prop: string, value: any): boolean;
43
-
44
- replaceState(state: Cx.Config);
45
-
46
- getInstanceCache(): InstanceCache;
47
-
48
- clearChildrenCache();
49
-
50
- getChild(context: RenderingContext | null, widget: Widget, keyPrefix?: string, store?: View): Instance;
51
-
52
- getDetachedChild(widget: Widget, key: number | string, store?: View): Instance;
53
-
54
- // TODO: check return type
55
- prepareRenderCleanupChild(widget: Widget, store?: View, keyPrefix?: string, options?: object): JSX.Element | void;
56
-
57
- getJsxEventProps(): Cx.Config;
58
-
59
- nestedDataSet(key: string, value: any, dataConfig: Cx.Config): boolean;
60
-
61
- invokeControllerMethod(methodName: string, ...args: any[]);
62
- }
63
-
64
- export class InstanceCache {
65
- constructor(parent: Instance);
66
-
67
- getChild(widget: Widget, store: View, keyPrefix?: string): Instance;
68
-
69
- mark();
70
-
71
- sweep();
72
- }
1
+ import { Record } from "../core";
2
+ import { RenderingContext } from "./RenderingContext";
3
+ import { View } from "../data/View";
4
+ import { Widget } from "./Widget";
5
+
6
+ export class Instance<ViewModel = any, Controller = any> {
7
+ store: View<ViewModel>;
8
+ data: Record;
9
+ widget: Widget;
10
+ key: number;
11
+ id: string;
12
+ controller: Controller;
13
+ parentOptions: any;
14
+ children?: Instance[];
15
+
16
+ constructor(widget: Widget, key: string | number, parent?: Instance, store?: View);
17
+
18
+ setStore(store: View): void;
19
+
20
+ init(context: RenderingContext): void;
21
+
22
+ explore(context: RenderingContext): boolean;
23
+
24
+ prepare(context: RenderingContext): void;
25
+
26
+ cleanup(context: RenderingContext): void;
27
+
28
+ render(context: RenderingContext, keyPrefix?: string): JSX.Element | void;
29
+
30
+ setState(state: Cx.Record): void;
31
+
32
+ set(prop: string, value: any, internal?: boolean);
33
+
34
+ definePropertySetter(prop: string, setter: (value: any) => void): boolean;
35
+
36
+ /**
37
+ * @protected
38
+ * @param prop
39
+ * @param value
40
+ * @returns {boolean}
41
+ */
42
+ protected doSet(prop: string, value: any): boolean;
43
+
44
+ replaceState(state: Cx.Config);
45
+
46
+ getInstanceCache(): InstanceCache;
47
+
48
+ clearChildrenCache();
49
+
50
+ getChild(context: RenderingContext | null, widget: Widget, keyPrefix?: string, store?: View): Instance;
51
+
52
+ getDetachedChild(widget: Widget, key: number | string, store?: View): Instance;
53
+
54
+ // TODO: check return type
55
+ prepareRenderCleanupChild(widget: Widget, store?: View, keyPrefix?: string, options?: object): JSX.Element | void;
56
+
57
+ getJsxEventProps(): Cx.Config;
58
+
59
+ nestedDataSet(key: string, value: any, dataConfig: Cx.Config): boolean;
60
+
61
+ invokeControllerMethod(methodName: string, ...args: any[]);
62
+ }
63
+
64
+ export class InstanceCache {
65
+ constructor(parent: Instance);
66
+
67
+ getChild(widget: Widget, store: View, keyPrefix?: string): Instance;
68
+
69
+ mark();
70
+
71
+ sweep();
72
+ }
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,4 +1,4 @@
1
- export class Console {
2
- static log(...args: unknown[]): void;
3
- static warn(...args: unknown[]): void;
4
- }
1
+ export class Console {
2
+ static log(...args: unknown[]): void;
3
+ static warn(...args: unknown[]): void;
4
+ }
@@ -1,213 +1,214 @@
1
- import { Widget, VDOM } from "../../ui/Widget";
2
- import { Container } from "../../ui/Container";
3
- import { parseStyle } from "../../util/parseStyle";
4
- import { registerDropZone, DragDropContext } from "./ops";
5
- import { findScrollableParent } from "../../util/findScrollableParent";
6
- import { isNumber } from "../../util/isNumber";
7
- import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
8
-
9
- export class DropZone extends Container {
10
- init() {
11
- this.overStyle = parseStyle(this.overStyle);
12
- this.nearStyle = parseStyle(this.nearStyle);
13
- this.farStyle = parseStyle(this.farStyle);
14
-
15
- if (isNumber(this.inflate)) {
16
- this.hinflate = this.inflate;
17
- this.vinflate = this.inflate;
18
- }
19
-
20
- super.init();
21
- }
22
-
23
- declareData() {
24
- return super.declareData(...arguments, {
25
- overClass: { structured: true },
26
- nearClass: { structured: true },
27
- farClass: { structured: true },
28
- overStyle: { structured: true },
29
- nearStyle: { structured: true },
30
- farStyle: { structured: true },
31
- data: { structured: true },
32
- });
33
- }
34
-
35
- render(context, instance, key) {
36
- return (
37
- <DropZoneComponent key={key} instance={instance}>
38
- {this.renderChildren(context, instance)}
39
- </DropZoneComponent>
40
- );
41
- }
42
- }
43
-
44
- DropZone.prototype.styled = true;
45
- DropZone.prototype.nearDistance = 0;
46
- DropZone.prototype.hinflate = 0;
47
- DropZone.prototype.vinflate = 0;
48
- DropZone.prototype.baseClass = "dropzone";
49
-
50
- Widget.alias("dropzone", DropZone);
51
-
52
- class DropZoneComponent extends VDOM.Component {
53
- constructor(props) {
54
- super(props);
55
- this.state = {
56
- state: false,
57
- };
58
- }
59
-
60
- render() {
61
- let { instance, children } = this.props;
62
- let { data, widget } = instance;
63
- let { CSS } = widget;
64
-
65
- let classes = [data.classNames, CSS.state(this.state.state)];
66
-
67
- let stateStyle;
68
-
69
- switch (this.state.state) {
70
- case "over":
71
- classes.push(data.overClass);
72
- stateStyle = parseStyle(data.overStyle);
73
- break;
74
- case "near":
75
- classes.push(data.nearClass);
76
- stateStyle = parseStyle(data.nearStyle);
77
- break;
78
- case "far":
79
- classes.push(data.farClass);
80
- stateStyle = parseStyle(data.farStyle);
81
- break;
82
- }
83
-
84
- return (
85
- <div
86
- className={CSS.expand(classes)}
87
- style={{ ...data.style, ...this.state.style, ...stateStyle }}
88
- ref={(el) => {
89
- this.el = el;
90
- }}
91
- >
92
- {children}
93
- </div>
94
- );
95
- }
96
-
97
- componentDidMount() {
98
- let dragDropOptions = this.context;
99
- let disabled = dragDropOptions && dragDropOptions.disabled;
100
- if (!disabled) this.unregister = registerDropZone(this);
101
- }
102
-
103
- componentWillUnmount() {
104
- this.unregister && this.unregister();
105
- }
106
-
107
- onDropTest(e) {
108
- let { instance } = this.props;
109
- let { widget } = instance;
110
- return !widget.onDropTest || instance.invoke("onDropTest", e, instance);
111
- }
112
-
113
- onDragStart(e) {
114
- this.setState({
115
- state: "far",
116
- });
117
- }
118
-
119
- onDragNear(e) {
120
- this.setState({
121
- state: "near",
122
- });
123
- }
124
-
125
- onDragAway(e) {
126
- this.setState({
127
- state: "far",
128
- });
129
- }
130
-
131
- onDragLeave(e) {
132
- let { nearDistance } = this.props.instance.widget;
133
- this.setState({
134
- state: nearDistance ? "near" : "far",
135
- style: null,
136
- });
137
- }
138
-
139
- onDragMeasure(e) {
140
- let rect = getTopLevelBoundingClientRect(this.el);
141
-
142
- let { instance } = this.props;
143
- let { widget } = instance;
144
-
145
- let { clientX, clientY } = e.cursor;
146
- let distance =
147
- Math.max(0, rect.left - clientX, clientX - rect.right) +
148
- Math.max(0, rect.top - clientY, clientY - rect.bottom);
149
-
150
- if (widget.hinflate > 0) {
151
- rect.left -= widget.hinflate;
152
- rect.right += widget.hinflate;
153
- }
154
-
155
- if (widget.vinflate > 0) {
156
- rect.top -= widget.vinflate;
157
- rect.bottom += widget.vinflate;
158
- }
159
-
160
- let { nearDistance } = widget;
161
-
162
- let over = rect.left <= clientX && clientX < rect.right && rect.top <= clientY && clientY < rect.bottom;
163
-
164
- return {
165
- over: over && distance,
166
- near: nearDistance && (over || distance < nearDistance),
167
- };
168
- }
169
-
170
- onDragEnter(e) {
171
- let { instance } = this.props;
172
- let { widget } = instance;
173
- let style = {};
174
-
175
- if (widget.matchWidth) style.width = `${e.source.width}px`;
176
-
177
- if (widget.matchHeight) style.height = `${e.source.height}px`;
178
-
179
- if (widget.matchMargin) style.margin = e.source.margin.join(" ");
180
-
181
- if (this.state != "over")
182
- this.setState({
183
- state: "over",
184
- style,
185
- });
186
- }
187
-
188
- onDragOver(e) {}
189
-
190
- onGetHScrollParent() {
191
- return findScrollableParent(this.el, true);
192
- }
193
-
194
- onGetVScrollParent() {
195
- return findScrollableParent(this.el);
196
- }
197
-
198
- onDrop(e) {
199
- let { instance } = this.props;
200
- let { widget } = instance;
201
-
202
- if (this.state.state == "over" && widget.onDrop) instance.invoke("onDrop", e, instance);
203
- }
204
-
205
- onDragEnd(e) {
206
- this.setState({
207
- state: false,
208
- style: null,
209
- });
210
- }
211
- }
212
-
213
- DropZoneComponent.contextType = DragDropContext;
1
+ import { Widget, VDOM } from "../../ui/Widget";
2
+ import { Container } from "../../ui/Container";
3
+ import { parseStyle } from "../../util/parseStyle";
4
+ import { registerDropZone, DragDropContext } from "./ops";
5
+ import { findScrollableParent } from "../../util/findScrollableParent";
6
+ import { isNumber } from "../../util/isNumber";
7
+ import { getTopLevelBoundingClientRect } from "../../util/getTopLevelBoundingClientRect";
8
+
9
+ export class DropZone extends Container {
10
+ init() {
11
+ this.overStyle = parseStyle(this.overStyle);
12
+ this.nearStyle = parseStyle(this.nearStyle);
13
+ this.farStyle = parseStyle(this.farStyle);
14
+
15
+ if (isNumber(this.inflate)) {
16
+ this.hinflate = this.inflate;
17
+ this.vinflate = this.inflate;
18
+ }
19
+
20
+ super.init();
21
+ }
22
+
23
+ declareData() {
24
+ return super.declareData(...arguments, {
25
+ overClass: { structured: true },
26
+ nearClass: { structured: true },
27
+ farClass: { structured: true },
28
+ overStyle: { structured: true },
29
+ nearStyle: { structured: true },
30
+ farStyle: { structured: true },
31
+ data: { structured: true },
32
+ });
33
+ }
34
+
35
+ render(context, instance, key) {
36
+ return (
37
+ <DropZoneComponent key={key} instance={instance}>
38
+ {this.renderChildren(context, instance)}
39
+ </DropZoneComponent>
40
+ );
41
+ }
42
+ }
43
+
44
+ DropZone.prototype.styled = true;
45
+ DropZone.prototype.nearDistance = 0;
46
+ DropZone.prototype.hinflate = 0;
47
+ DropZone.prototype.vinflate = 0;
48
+ DropZone.prototype.baseClass = "dropzone";
49
+
50
+ Widget.alias("dropzone", DropZone);
51
+
52
+ class DropZoneComponent extends VDOM.Component {
53
+ constructor(props) {
54
+ super(props);
55
+ this.state = {
56
+ state: false,
57
+ };
58
+ }
59
+
60
+ render() {
61
+ let { instance, children } = this.props;
62
+ let { data, widget } = instance;
63
+ let { CSS } = widget;
64
+
65
+ let classes = [data.classNames, CSS.state(this.state.state)];
66
+
67
+ let stateStyle;
68
+
69
+ switch (this.state.state) {
70
+ case "over":
71
+ classes.push(data.overClass);
72
+ stateStyle = parseStyle(data.overStyle);
73
+ break;
74
+ case "near":
75
+ classes.push(data.nearClass);
76
+ stateStyle = parseStyle(data.nearStyle);
77
+ break;
78
+ case "far":
79
+ classes.push(data.farClass);
80
+ stateStyle = parseStyle(data.farStyle);
81
+ break;
82
+ }
83
+
84
+ return (
85
+ <div
86
+ className={CSS.expand(classes)}
87
+ style={{ ...data.style, ...this.state.style, ...stateStyle }}
88
+ ref={(el) => {
89
+ this.el = el;
90
+ }}
91
+ >
92
+ {children}
93
+ </div>
94
+ );
95
+ }
96
+
97
+ componentDidMount() {
98
+ let dragDropOptions = this.context;
99
+ let disabled = dragDropOptions && dragDropOptions.disabled;
100
+ if (!disabled) this.unregister = registerDropZone(this);
101
+ }
102
+
103
+ componentWillUnmount() {
104
+ this.unregister && this.unregister();
105
+ }
106
+
107
+ onDropTest(e) {
108
+ let { instance } = this.props;
109
+ let { widget } = instance;
110
+ return !widget.onDropTest || instance.invoke("onDropTest", e, instance);
111
+ }
112
+
113
+ onDragStart(e) {
114
+ this.setState({
115
+ state: "far",
116
+ });
117
+ }
118
+
119
+ onDragNear(e) {
120
+ this.setState({
121
+ state: "near",
122
+ });
123
+ }
124
+
125
+ onDragAway(e) {
126
+ this.setState({
127
+ state: "far",
128
+ });
129
+ }
130
+
131
+ onDragLeave(e) {
132
+ let { nearDistance } = this.props.instance.widget;
133
+ this.setState({
134
+ state: nearDistance ? "near" : "far",
135
+ style: null,
136
+ });
137
+ }
138
+
139
+ onDragMeasure(e) {
140
+ let rect = getTopLevelBoundingClientRect(this.el);
141
+
142
+ let { instance } = this.props;
143
+ let { widget } = instance;
144
+
145
+ let { clientX, clientY } = e.cursor;
146
+ let distance =
147
+ Math.max(0, rect.left - clientX, clientX - rect.right) +
148
+ Math.max(0, rect.top - clientY, clientY - rect.bottom);
149
+
150
+ if (widget.hinflate > 0) {
151
+ rect.left -= widget.hinflate;
152
+ rect.right += widget.hinflate;
153
+ }
154
+
155
+ if (widget.vinflate > 0) {
156
+ rect.top -= widget.vinflate;
157
+ rect.bottom += widget.vinflate;
158
+ }
159
+
160
+ let { nearDistance } = widget;
161
+
162
+ let over = rect.left <= clientX && clientX < rect.right && rect.top <= clientY && clientY < rect.bottom;
163
+
164
+ return {
165
+ over:
166
+ over && Math.abs(clientX - (rect.left + rect.right) / 2) + Math.abs(clientY - (rect.top + rect.bottom) / 2),
167
+ near: nearDistance && (over || distance < nearDistance),
168
+ };
169
+ }
170
+
171
+ onDragEnter(e) {
172
+ let { instance } = this.props;
173
+ let { widget } = instance;
174
+ let style = {};
175
+
176
+ if (widget.matchWidth) style.width = `${e.source.width}px`;
177
+
178
+ if (widget.matchHeight) style.height = `${e.source.height}px`;
179
+
180
+ if (widget.matchMargin) style.margin = e.source.margin.join(" ");
181
+
182
+ if (this.state != "over")
183
+ this.setState({
184
+ state: "over",
185
+ style,
186
+ });
187
+ }
188
+
189
+ onDragOver(e) {}
190
+
191
+ onGetHScrollParent() {
192
+ return findScrollableParent(this.el, true);
193
+ }
194
+
195
+ onGetVScrollParent() {
196
+ return findScrollableParent(this.el);
197
+ }
198
+
199
+ onDrop(e) {
200
+ let { instance } = this.props;
201
+ let { widget } = instance;
202
+
203
+ if (this.state.state == "over" && widget.onDrop) instance.invoke("onDrop", e, instance);
204
+ }
205
+
206
+ onDragEnd(e) {
207
+ this.setState({
208
+ state: false,
209
+ style: null,
210
+ });
211
+ }
212
+ }
213
+
214
+ DropZoneComponent.contextType = DragDropContext;