cx 26.3.1 → 26.3.3

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,354 +1,320 @@
1
- /** @jsxImportSource react */
2
- import { Widget, VDOM, getContent } from "../../ui/Widget";
3
- import {
4
- Overlay,
5
- OverlayBase,
6
- OverlayBeacon,
7
- OverlayComponent,
8
- OverlayComponentProps,
9
- OverlayComponentState,
10
- OverlayConfig,
11
- OverlayInstance,
12
- } from "./Overlay";
13
- import {
14
- ContentPlaceholder,
15
- ContentPlaceholderInstance,
16
- } from "../../ui/layout/ContentPlaceholder";
17
- import { ZIndexManager } from "../../ui/ZIndexManager";
18
- import { Button } from "../Button";
19
- import { parseStyle } from "../../util/parseStyle";
20
- import { Localization } from "../../ui/Localization";
21
- import { stopPropagation } from "../../util/eventCallbacks";
22
- import { ddMouseDown, ddDetect, ddMouseUp } from "../drag-drop/ops";
23
- import { isDefined } from "../../util/isDefined";
24
- import { isString } from "../../util/isString";
25
- import { BooleanProp, StringProp, StyleProp, ClassProp } from "../../ui/Prop";
26
- import { RenderingContext } from "../../ui/RenderingContext";
27
-
28
- export interface WindowConfig extends OverlayConfig {
29
- /** Text to be displayed in the header. */
30
- title?: StringProp;
31
-
32
- /** Controls the close button visibility. Defaults to `true`. */
33
- closable?: BooleanProp;
34
-
35
- /** A custom style which will be applied to the body. */
36
- bodyStyle?: StyleProp;
37
-
38
- /** A custom style which will be applied to the header. */
39
- headerStyle?: StyleProp;
40
-
41
- /** A custom style which will be applied to the footer. */
42
- footerStyle?: StyleProp;
43
-
44
- /** Base CSS class to be applied to the field. Defaults to `window`. */
45
- baseClass?: string;
46
-
47
- /** Additional CSS class to be applied to the section body. */
48
- bodyClass?: ClassProp;
49
-
50
- /** Set to `true` to enable resizing. */
51
- resizable?: boolean;
52
-
53
- /** Set to `true` to automatically focus the field, after it renders for the first time. */
54
- autoFocus?: boolean;
55
-
56
- /** Set to `false` to prevent the window itself to be focusable. Default value is true.*/
57
- focusable?: boolean;
58
-
59
- /** Set to `true` to disable moving the window by dragging the header. */
60
- fixed?: boolean;
61
-
62
- /** Set to `true` to add default padding to the window body. */
63
- pad?: boolean;
64
-
65
- /** Optional header widget. */
66
- header?: any;
67
-
68
- /** Optional footer widget. */
69
- footer?: any;
70
-
71
- /** Custom event handler for closeable. */
72
- closeable?: BooleanProp;
73
- }
74
-
75
- export class WindowInstance extends OverlayInstance<Window> {
76
- headerEl?: HTMLElement;
77
- footerEl?: HTMLElement;
78
- bodyEl?: HTMLElement;
79
- containerEl?: HTMLElement;
80
- }
81
-
82
- export class Window extends OverlayBase<WindowConfig, WindowInstance> {
83
- declare closable?: BooleanProp;
84
- declare closeable?: BooleanProp;
85
- declare resizable?: boolean;
86
- declare fixed?: boolean;
87
- declare autoFocus?: boolean;
88
- declare focusable?: boolean;
89
- declare pad?: boolean;
90
- declare bodyStyle?: StyleProp;
91
- declare headerStyle?: StyleProp;
92
- declare footerStyle?: StyleProp;
93
- declare bodyClass?: ClassProp;
94
- declare title?: StringProp;
95
- declare header?: any;
96
- declare footer?: any;
97
- declare baseClass: string;
98
-
99
- init() {
100
- if (isDefined(this.closeable)) this.closable = this.closeable;
101
-
102
- if (isString(this.headerStyle))
103
- this.headerStyle = parseStyle(this.headerStyle);
104
-
105
- if (isString(this.footerStyle))
106
- this.footerStyle = parseStyle(this.footerStyle);
107
-
108
- if (isString(this.bodyStyle)) this.bodyStyle = parseStyle(this.bodyStyle);
109
-
110
- super.init();
111
- }
112
-
113
- declareData(...args: any) {
114
- return super.declareData(...args, {
115
- title: undefined,
116
- closable: undefined,
117
- bodyStyle: { structured: true },
118
- bodyClass: { structured: true },
119
- headerStyle: { structured: true },
120
- footerStyle: { structured: true },
121
- });
122
- }
123
-
124
- initHelpers(...args: any) {
125
- return super.initHelpers(...args, {
126
- header: Widget.create(
127
- this.header || {
128
- type: ContentPlaceholder,
129
- name: "header",
130
- scoped: true,
131
- },
132
- ),
133
- footer: Widget.create(
134
- this.footer || {
135
- type: ContentPlaceholder,
136
- name: "footer",
137
- scoped: true,
138
- },
139
- ),
140
- close:
141
- this.closable &&
142
- Button.create({
143
- mod: "hollow",
144
- dismiss: true,
145
- icon: "close",
146
- style: "margin-left: auto",
147
- onTouchStart: stopPropagation,
148
- onMouseDown: stopPropagation,
149
- }),
150
- });
151
- }
152
-
153
- exploreCleanup(context: RenderingContext, instance: WindowInstance): void {
154
- super.exploreCleanup(context, instance);
155
-
156
- let { helpers } = instance;
157
- let unregisterHeader =
158
- helpers!.header &&
159
- (helpers!.header as ContentPlaceholderInstance)
160
- .unregisterContentPlaceholder;
161
- if (unregisterHeader) unregisterHeader();
162
-
163
- let unregisterFooter =
164
- helpers!.footer &&
165
- (helpers!.footer as ContentPlaceholderInstance)
166
- .unregisterContentPlaceholder;
167
- if (unregisterFooter) unregisterFooter();
168
- }
169
-
170
- renderHeader(
171
- context: RenderingContext,
172
- instance: WindowInstance,
173
- key: string,
174
- ): any[] {
175
- let { data } = instance;
176
- let result = [];
177
- if (data.title) result.push(data.title);
178
- if (instance.helpers) {
179
- let header = getContent(
180
- instance.helpers.header && instance.helpers.header.render(context),
181
- );
182
- if (header) result.push(header);
183
- if (data.closable && instance.helpers.close)
184
- result.push(getContent(instance.helpers.close.render(context)));
185
- }
186
- return result;
187
- }
188
-
189
- renderFooter(
190
- context: RenderingContext,
191
- instance: WindowInstance,
192
- key: string,
193
- ): any {
194
- return getContent(
195
- instance.helpers &&
196
- instance.helpers.footer &&
197
- instance.helpers.footer.render(context),
198
- );
199
- }
200
-
201
- render(
202
- context: RenderingContext,
203
- instance: WindowInstance,
204
- key: string,
205
- ): any {
206
- var header = this.renderHeader(context, instance, "header");
207
- var footer = this.renderFooter(context, instance, "footer");
208
- return (
209
- <OverlayBeacon
210
- childrenFactory={(beaconEl) => (
211
- <WindowComponent
212
- beaconEl={beaconEl}
213
- key={key}
214
- instance={instance}
215
- header={header}
216
- footer={footer}
217
- subscribeToBeforeDismiss={context.options.subscribeToBeforeDismiss}
218
- parentEl={context.options.parentEl}
219
- >
220
- {this.renderContents(context, instance)}
221
- </WindowComponent>
222
- )}
223
- />
224
- );
225
- }
226
- }
227
-
228
- Window.prototype.baseClass = "window";
229
- Window.prototype.closable = true;
230
- Window.prototype.resizable = false;
231
- Window.prototype.fixed = false;
232
- Window.prototype.autoFocus = true;
233
- Window.prototype.focusable = true;
234
- Window.prototype.pad = true;
235
- Window.prototype.needsBeacon = true;
236
-
237
- Widget.alias("window", Window);
238
- Localization.registerPrototype("cx/widgets/Window", Window);
239
-
240
- interface WindowComponentProps extends OverlayComponentProps {
241
- header: any[];
242
- footer: any;
243
- instance: WindowInstance;
244
- }
245
-
246
- interface WindowComponentState extends OverlayComponentState {
247
- active?: boolean;
248
- }
249
-
250
- class WindowComponent extends OverlayComponent<
251
- WindowComponentProps,
252
- WindowComponentState
253
- > {
254
- headerEl?: HTMLElement | null;
255
- footerEl?: HTMLElement | null;
256
- bodyEl?: HTMLElement | null;
257
-
258
- renderOverlayBody() {
259
- var { widget, data } = this.props.instance;
260
- var { CSS, baseClass, pad } = widget;
261
-
262
- let header, footer;
263
-
264
- if (this.props.header.length > 0) {
265
- header = (
266
- <header
267
- key="header"
268
- ref={(c) => {
269
- this.headerEl = c;
270
- }}
271
- className={CSS.element(baseClass, "header")}
272
- style={data.headerStyle}
273
- onMouseDown={this.onHeaderMouseDown.bind(this)}
274
- onMouseUp={ddMouseUp}
275
- onMouseMove={this.onHeaderMouseMove.bind(this)}
276
- onTouchStart={this.onHeaderMouseDown.bind(this)}
277
- onTouchEnd={ddMouseUp}
278
- onTouchMove={this.onHeaderMouseMove.bind(this)}
279
- >
280
- {this.props.header}
281
- </header>
282
- );
283
- }
284
-
285
- if (this.props.footer) {
286
- footer = (
287
- <footer
288
- key="footer"
289
- ref={(c) => {
290
- this.footerEl = c;
291
- }}
292
- className={CSS.element(baseClass, "footer")}
293
- style={data.footerStyle}
294
- >
295
- {this.props.footer}
296
- </footer>
297
- );
298
- }
299
-
300
- var body = (
301
- <div
302
- key="body"
303
- ref={(c) => {
304
- this.bodyEl = c;
305
- }}
306
- className={CSS.expand(
307
- CSS.element(baseClass, "body", { pad }),
308
- data.bodyClass,
309
- )}
310
- style={data.bodyStyle}
311
- >
312
- {this.props.children}
313
- </div>
314
- );
315
-
316
- return [header, body, footer];
317
- }
318
-
319
- getOverlayCssClass() {
320
- var cls = super.getOverlayCssClass();
321
- if (this.state.active) cls += " cxs-active";
322
- return cls;
323
- }
324
-
325
- onFocusIn() {
326
- super.onFocusIn();
327
- if (!this.state.active) {
328
- if (this.containerEl?.contains(document.activeElement))
329
- this.setZIndex(ZIndexManager.next());
330
- this.setState({ active: true });
331
- }
332
- }
333
-
334
- onFocusOut() {
335
- super.onFocusOut();
336
- if (this.state.active) {
337
- this.setState({
338
- active: false,
339
- });
340
- }
341
- }
342
-
343
- onHeaderMouseDown(e: any) {
344
- e.stopPropagation();
345
- ddMouseDown(e);
346
- }
347
-
348
- onHeaderMouseMove(e: any) {
349
- e.stopPropagation();
350
- if (!(this.props.instance.widget as Window).fixed && ddDetect(e)) {
351
- this.startMoveOperation(e);
352
- }
353
- }
354
- }
1
+ /** @jsxImportSource react */
2
+ import { Widget, VDOM, getContent } from "../../ui/Widget";
3
+ import {
4
+ Overlay,
5
+ OverlayBase,
6
+ OverlayBeacon,
7
+ OverlayComponent,
8
+ OverlayComponentProps,
9
+ OverlayComponentState,
10
+ OverlayConfig,
11
+ OverlayInstance,
12
+ } from "./Overlay";
13
+ import { ContentPlaceholder, ContentPlaceholderInstance } from "../../ui/layout/ContentPlaceholder";
14
+ import { ZIndexManager } from "../../ui/ZIndexManager";
15
+ import { Button } from "../Button";
16
+ import { parseStyle } from "../../util/parseStyle";
17
+ import { Localization } from "../../ui/Localization";
18
+ import { stopPropagation } from "../../util/eventCallbacks";
19
+ import { ddMouseDown, ddDetect, ddMouseUp } from "../drag-drop/ops";
20
+ import { isDefined } from "../../util/isDefined";
21
+ import { isString } from "../../util/isString";
22
+ import { BooleanProp, StringProp, StyleProp, ClassProp } from "../../ui/Prop";
23
+ import { RenderingContext } from "../../ui/RenderingContext";
24
+
25
+ export interface WindowConfig extends OverlayConfig {
26
+ /** Text to be displayed in the header. */
27
+ title?: StringProp;
28
+
29
+ /** Controls the close button visibility. Defaults to `true`. */
30
+ closable?: BooleanProp;
31
+
32
+ /** A custom style which will be applied to the body. */
33
+ bodyStyle?: StyleProp;
34
+
35
+ /** A custom style which will be applied to the header. */
36
+ headerStyle?: StyleProp;
37
+
38
+ /** A custom style which will be applied to the footer. */
39
+ footerStyle?: StyleProp;
40
+
41
+ /** Base CSS class to be applied to the field. Defaults to `window`. */
42
+ baseClass?: string;
43
+
44
+ /** Additional CSS class to be applied to the section body. */
45
+ bodyClass?: ClassProp;
46
+
47
+ /** Set to `true` to enable resizing. */
48
+ resizable?: boolean;
49
+
50
+ /** Set to `true` to automatically focus the field, after it renders for the first time. */
51
+ autoFocus?: boolean;
52
+
53
+ /** Set to `false` to prevent the window itself to be focusable. Default value is true.*/
54
+ focusable?: boolean;
55
+
56
+ /** Set to `true` to disable moving the window by dragging the header. */
57
+ fixed?: boolean;
58
+
59
+ /** Set to `true` to add default padding to the window body. */
60
+ pad?: boolean;
61
+
62
+ /** Optional header widget. */
63
+ header?: any;
64
+
65
+ /** Optional footer widget. */
66
+ footer?: any;
67
+
68
+ /** Custom event handler for closeable. */
69
+ closeable?: BooleanProp;
70
+ }
71
+
72
+ export class WindowInstance extends OverlayInstance<Window> {
73
+ headerEl?: HTMLElement;
74
+ footerEl?: HTMLElement;
75
+ bodyEl?: HTMLElement;
76
+ containerEl?: HTMLElement;
77
+ }
78
+
79
+ export class Window extends OverlayBase<WindowConfig, WindowInstance> {
80
+ declare closable?: BooleanProp;
81
+ declare closeable?: BooleanProp;
82
+ declare resizable?: boolean;
83
+ declare fixed?: boolean;
84
+ declare autoFocus?: boolean;
85
+ declare focusable?: boolean;
86
+ declare pad?: boolean;
87
+ declare bodyStyle?: StyleProp;
88
+ declare headerStyle?: StyleProp;
89
+ declare footerStyle?: StyleProp;
90
+ declare bodyClass?: ClassProp;
91
+ declare title?: StringProp;
92
+ declare header?: any;
93
+ declare footer?: any;
94
+ declare baseClass: string;
95
+
96
+ init() {
97
+ if (isDefined(this.closeable)) this.closable = this.closeable;
98
+
99
+ if (isString(this.headerStyle)) this.headerStyle = parseStyle(this.headerStyle);
100
+
101
+ if (isString(this.footerStyle)) this.footerStyle = parseStyle(this.footerStyle);
102
+
103
+ if (isString(this.bodyStyle)) this.bodyStyle = parseStyle(this.bodyStyle);
104
+
105
+ super.init();
106
+ }
107
+
108
+ declareData(...args: any) {
109
+ return super.declareData(...args, {
110
+ title: undefined,
111
+ closable: undefined,
112
+ bodyStyle: { structured: true },
113
+ bodyClass: { structured: true },
114
+ headerStyle: { structured: true },
115
+ footerStyle: { structured: true },
116
+ });
117
+ }
118
+
119
+ initHelpers(...args: any) {
120
+ return super.initHelpers(...args, {
121
+ header: Widget.create(
122
+ this.header || {
123
+ type: ContentPlaceholder,
124
+ name: "header",
125
+ scoped: true,
126
+ },
127
+ ),
128
+ footer: Widget.create(
129
+ this.footer || {
130
+ type: ContentPlaceholder,
131
+ name: "footer",
132
+ scoped: true,
133
+ },
134
+ ),
135
+ close:
136
+ this.closable &&
137
+ Button.create({
138
+ mod: "hollow",
139
+ dismiss: true,
140
+ icon: "close",
141
+ style: "margin-left: auto",
142
+ onTouchStart: stopPropagation,
143
+ onMouseDown: stopPropagation,
144
+ }),
145
+ });
146
+ }
147
+
148
+ exploreCleanup(context: RenderingContext, instance: WindowInstance): void {
149
+ super.exploreCleanup(context, instance);
150
+
151
+ let { helpers } = instance;
152
+ let unregisterHeader =
153
+ helpers!.header && (helpers!.header as ContentPlaceholderInstance).unregisterContentPlaceholder;
154
+ if (unregisterHeader) unregisterHeader();
155
+
156
+ let unregisterFooter =
157
+ helpers!.footer && (helpers!.footer as ContentPlaceholderInstance).unregisterContentPlaceholder;
158
+ if (unregisterFooter) unregisterFooter();
159
+ }
160
+
161
+ renderHeader(context: RenderingContext, instance: WindowInstance, key: string): any[] {
162
+ let { data } = instance;
163
+ let result = [];
164
+ if (data.title) result.push(data.title);
165
+ if (instance.helpers) {
166
+ let header = getContent(instance.helpers.header && instance.helpers.header.render(context));
167
+ if (header) result.push(header);
168
+ if (data.closable && instance.helpers.close) result.push(getContent(instance.helpers.close.render(context)));
169
+ }
170
+ return result;
171
+ }
172
+
173
+ renderFooter(context: RenderingContext, instance: WindowInstance, key: string): any {
174
+ return getContent(instance.helpers && instance.helpers.footer && instance.helpers.footer.render(context));
175
+ }
176
+
177
+ render(context: RenderingContext, instance: WindowInstance, key: string): any {
178
+ var header = this.renderHeader(context, instance, "header");
179
+ var footer = this.renderFooter(context, instance, "footer");
180
+
181
+ return (
182
+ <OverlayBeacon
183
+ key={key}
184
+ childrenFactory={(beaconEl) => (
185
+ <WindowComponent
186
+ beaconEl={beaconEl}
187
+ instance={instance}
188
+ header={header}
189
+ footer={footer}
190
+ subscribeToBeforeDismiss={context.options.subscribeToBeforeDismiss}
191
+ parentEl={context.options.parentEl}
192
+ >
193
+ {this.renderContents(context, instance)}
194
+ </WindowComponent>
195
+ )}
196
+ />
197
+ );
198
+ }
199
+ }
200
+
201
+ Window.prototype.baseClass = "window";
202
+ Window.prototype.closable = true;
203
+ Window.prototype.resizable = false;
204
+ Window.prototype.fixed = false;
205
+ Window.prototype.autoFocus = true;
206
+ Window.prototype.focusable = true;
207
+ Window.prototype.pad = true;
208
+ Window.prototype.needsBeacon = true;
209
+
210
+ Widget.alias("window", Window);
211
+ Localization.registerPrototype("cx/widgets/Window", Window);
212
+
213
+ interface WindowComponentProps extends OverlayComponentProps {
214
+ header: any[];
215
+ footer: any;
216
+ instance: WindowInstance;
217
+ }
218
+
219
+ interface WindowComponentState extends OverlayComponentState {
220
+ active?: boolean;
221
+ }
222
+
223
+ class WindowComponent extends OverlayComponent<WindowComponentProps, WindowComponentState> {
224
+ headerEl?: HTMLElement | null;
225
+ footerEl?: HTMLElement | null;
226
+ bodyEl?: HTMLElement | null;
227
+
228
+ renderOverlayBody() {
229
+ var { widget, data } = this.props.instance;
230
+ var { CSS, baseClass, pad } = widget;
231
+
232
+ let header, footer;
233
+
234
+ if (this.props.header.length > 0) {
235
+ header = (
236
+ <header
237
+ key="header"
238
+ ref={(c) => {
239
+ this.headerEl = c;
240
+ }}
241
+ className={CSS.element(baseClass, "header")}
242
+ style={data.headerStyle}
243
+ onMouseDown={this.onHeaderMouseDown.bind(this)}
244
+ onMouseUp={ddMouseUp}
245
+ onMouseMove={this.onHeaderMouseMove.bind(this)}
246
+ onTouchStart={this.onHeaderMouseDown.bind(this)}
247
+ onTouchEnd={ddMouseUp}
248
+ onTouchMove={this.onHeaderMouseMove.bind(this)}
249
+ >
250
+ {this.props.header}
251
+ </header>
252
+ );
253
+ }
254
+
255
+ if (this.props.footer) {
256
+ footer = (
257
+ <footer
258
+ key="footer"
259
+ ref={(c) => {
260
+ this.footerEl = c;
261
+ }}
262
+ className={CSS.element(baseClass, "footer")}
263
+ style={data.footerStyle}
264
+ >
265
+ {this.props.footer}
266
+ </footer>
267
+ );
268
+ }
269
+
270
+ var body = (
271
+ <div
272
+ key="body"
273
+ ref={(c) => {
274
+ this.bodyEl = c;
275
+ }}
276
+ className={CSS.expand(CSS.element(baseClass, "body", { pad }), data.bodyClass)}
277
+ style={data.bodyStyle}
278
+ >
279
+ {this.props.children}
280
+ </div>
281
+ );
282
+
283
+ return [header, body, footer];
284
+ }
285
+
286
+ getOverlayCssClass() {
287
+ var cls = super.getOverlayCssClass();
288
+ if (this.state.active) cls += " cxs-active";
289
+ return cls;
290
+ }
291
+
292
+ onFocusIn() {
293
+ super.onFocusIn();
294
+ if (!this.state.active) {
295
+ if (this.containerEl?.contains(document.activeElement)) this.setZIndex(ZIndexManager.next());
296
+ this.setState({ active: true });
297
+ }
298
+ }
299
+
300
+ onFocusOut() {
301
+ super.onFocusOut();
302
+ if (this.state.active) {
303
+ this.setState({
304
+ active: false,
305
+ });
306
+ }
307
+ }
308
+
309
+ onHeaderMouseDown(e: any) {
310
+ e.stopPropagation();
311
+ ddMouseDown(e);
312
+ }
313
+
314
+ onHeaderMouseMove(e: any) {
315
+ e.stopPropagation();
316
+ if (!(this.props.instance.widget as Window).fixed && ddDetect(e)) {
317
+ this.startMoveOperation(e);
318
+ }
319
+ }
320
+ }