cedro 0.1.8 → 0.1.10
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/README.md +7 -4
- package/dist/cedro-logo.png +0 -0
- package/dist/fangio.jpg +0 -0
- package/package.json +4 -2
- package/src/core/application.builder.tsx +121 -0
- package/src/core/{application.core.ts → application.core.tsx} +175 -9
- package/src/core/themes.core.ts +160 -1
- package/src/core/uid.ts +3 -3
- package/src/index.ts +1 -1
- package/src/interfaces/application.interface.ts +10 -3
- package/src/interfaces/widget.interface.ts +6 -1
- package/src/types/select.item.type.ts +11 -0
- package/src/ui/Icon.ui.tsx +158 -0
- package/src/ui/IconButton.ui.tsx +233 -0
- package/src/ui/{textbox.ui.ts → Textbox.ui.tsx} +69 -8
- package/src/ui/accordion.ui.tsx +152 -0
- package/src/ui/button.ui.tsx +209 -0
- package/src/ui/buttonColor.ui.tsx +87 -0
- package/src/ui/buttonmenu.ui.tsx +134 -0
- package/src/ui/{buttonstack.ui.ts → buttonstack.ui.tsx} +67 -1
- package/src/ui/checkbox.ui.tsx +43 -0
- package/src/ui/container.ui.tsx +141 -0
- package/src/ui/datagrid.ui.tsx +518 -0
- package/src/ui/dialog.tsx +143 -56
- package/src/ui/{hpanel.ui.ts → hpanel.ui.tsx} +64 -1
- package/src/ui/iconButtonMenu.ui.tsx +176 -0
- package/src/ui/image.ui.tsx +123 -0
- package/src/ui/index.ts +9 -9
- package/src/ui/label.ui.tsx +184 -0
- package/src/ui/loading.ui.ts +10 -10
- package/src/ui/menu.ui.ts +2 -2
- package/src/ui/progressbar.ui.tsx +135 -0
- package/src/ui/radiobutton.ui.tsx +47 -0
- package/src/ui/scroll.ui.ts +13 -12
- package/src/ui/select.ui.tsx +143 -0
- package/src/ui/styles/button.css +114 -32
- package/src/ui/styles/buttoncolor.css +8 -8
- package/src/ui/styles/container.css +29 -0
- package/src/ui/styles/hpanel.css +1 -1
- package/src/ui/styles/icon.css +29 -0
- package/src/ui/styles/image.css +19 -19
- package/src/ui/styles/label.css +63 -0
- package/src/ui/styles/loading.css +12 -12
- package/src/ui/styles/main.css +5 -0
- package/src/ui/styles/progressbar.css +3 -2
- package/src/ui/styles/select.css +13 -0
- package/src/ui/styles/stackbutton.css +36 -0
- package/src/ui/styles/tabs.css +5 -7
- package/src/ui/styles/textarea.css +13 -13
- package/src/ui/styles/valuebar.css +1 -1
- package/src/ui/styles/vpanel.css +1 -1
- package/src/ui/switch.ui.tsx +42 -0
- package/src/ui/{tabs.ui.ts → tabs.ui.tsx} +114 -8
- package/src/ui/textarea.ui.tsx +48 -0
- package/src/ui/{toolbar.ui.ts → toolbar.ui.tsx} +44 -1
- package/src/ui/{valuebar.ui.ts → valuebar.ui.tsx} +35 -1
- package/src/ui/{vpanel.ui.ts → vpanel.ui.tsx} +44 -1
- package/src/ui/widget.builder.ts +243 -0
- package/src/ui/widget.collection.ts +57 -5
- package/src/ui/widget.ui.ts +176 -24
- package/src/ui/Icon.ui.ts +0 -64
- package/src/ui/IconButton.ui.ts +0 -114
- package/src/ui/accordion.ui.ts +0 -71
- package/src/ui/button.ui.ts +0 -105
- package/src/ui/buttonColor.ui.ts +0 -24
- package/src/ui/buttonmenu.ui.ts +0 -59
- package/src/ui/checkbox.ui.ts +0 -8
- package/src/ui/container.ui.ts +0 -38
- package/src/ui/datagrid.ui.ts +0 -231
- package/src/ui/iconButtonMenu.ui.ts +0 -59
- package/src/ui/image.ui.ts +0 -49
- package/src/ui/label.ui.ts +0 -82
- package/src/ui/progressbar.ui.ts +0 -74
- package/src/ui/radiobutton.ts +0 -8
- package/src/ui/select.ui.ts +0 -73
- package/src/ui/switch.ui.ts +0 -7
- package/src/ui/textarea.ui.ts +0 -20
- package/src/ui/widget.builder.ui.tsx +0 -676
- /package/src/ui/{toggle.ui.ts → toggle.ui.tsx} +0 -0
package/src/ui/dialog.tsx
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { UID } from "../core/uid";
|
|
1
2
|
import { WUICallback } from "../interfaces/widget.interface";
|
|
2
3
|
import { Button } from "./button.ui";
|
|
4
|
+
import { Spacer } from "./container.ui";
|
|
3
5
|
import { Label } from "./label.ui";
|
|
4
6
|
import "./styles/dialog.css";
|
|
7
|
+
import { createWidget, normalizeWidget, WidgetProps } from "./widget.builder";
|
|
5
8
|
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
6
9
|
|
|
7
10
|
const TITLE_BAR_HEIGHT = 40;
|
|
@@ -34,6 +37,9 @@ export class Dialog extends Widget {
|
|
|
34
37
|
draging: boolean;
|
|
35
38
|
resizing: boolean;
|
|
36
39
|
|
|
40
|
+
startX: number;
|
|
41
|
+
startY: number;
|
|
42
|
+
|
|
37
43
|
constructor(
|
|
38
44
|
id: string,
|
|
39
45
|
parent: Widget | null = null,
|
|
@@ -42,6 +48,9 @@ export class Dialog extends Widget {
|
|
|
42
48
|
) {
|
|
43
49
|
super(id, "div", parent);
|
|
44
50
|
|
|
51
|
+
this.startX = -1;
|
|
52
|
+
this.startY = -1;
|
|
53
|
+
|
|
45
54
|
this.buttonContainer = null;
|
|
46
55
|
this.handlerResizable = null;
|
|
47
56
|
|
|
@@ -71,23 +80,11 @@ export class Dialog extends Widget {
|
|
|
71
80
|
this.setType(WidgetTypes.CUSTOM);
|
|
72
81
|
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
73
82
|
|
|
74
|
-
this.titleContainer = new Widget(
|
|
75
|
-
|
|
76
|
-
"div",
|
|
77
|
-
this
|
|
78
|
-
);
|
|
79
|
-
this.contentCntainer = new Widget(
|
|
80
|
-
this.id + ".contentCntainer",
|
|
81
|
-
"div",
|
|
82
|
-
this
|
|
83
|
-
);
|
|
83
|
+
this.titleContainer = new Widget(this.id + ".titleContainer", "div", null);
|
|
84
|
+
this.contentCntainer = new Widget(this.id + ".contentCntainer", "div", null);
|
|
84
85
|
|
|
85
86
|
if (hasButtons) {
|
|
86
|
-
this.buttonContainer = new Widget(
|
|
87
|
-
this.id + ".buttonContainer",
|
|
88
|
-
"div",
|
|
89
|
-
this
|
|
90
|
-
);
|
|
87
|
+
this.buttonContainer = new Widget(this.id + ".buttonContainer", "div", null);
|
|
91
88
|
|
|
92
89
|
this.buttonContainer.setType(WidgetTypes.FILL);
|
|
93
90
|
this.buttonContainer.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
@@ -96,11 +93,7 @@ export class Dialog extends Widget {
|
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
if (resizable) {
|
|
99
|
-
this.handlerResizable = new Widget(
|
|
100
|
-
this.id + ".handlerResizable",
|
|
101
|
-
"div",
|
|
102
|
-
this
|
|
103
|
-
);
|
|
96
|
+
this.handlerResizable = new Widget(this.id + ".handlerResizable", "div", this);
|
|
104
97
|
this.handlerResizable.setType(WidgetTypes.CUSTOM);
|
|
105
98
|
this.handlerResizable.getBody().innerHTML = " ";
|
|
106
99
|
this.handlerResizable.addClass("WUIDialogResizeHandler");
|
|
@@ -117,55 +110,37 @@ export class Dialog extends Widget {
|
|
|
117
110
|
|
|
118
111
|
this.titleContainer.setFixedSize(TITLE_BAR_HEIGHT);
|
|
119
112
|
|
|
120
|
-
this.titleBar = new Label(
|
|
121
|
-
this.id + ".titleBar",
|
|
122
|
-
"span",
|
|
123
|
-
this.titleContainer
|
|
124
|
-
);
|
|
113
|
+
this.titleBar = new Label(this.id + ".titleBar", "span", null);
|
|
125
114
|
this.titleBar.setType(WidgetTypes.FILL);
|
|
126
115
|
this.titleBar.setText("Title");
|
|
127
116
|
this.titleBar.addClass("WUITitlebar");
|
|
128
117
|
|
|
129
|
-
this.close = new Button(this.id + ".close",
|
|
118
|
+
this.close = new Button(this.id + ".close", null);
|
|
130
119
|
this.close.setType(WidgetTypes.FILL);
|
|
131
120
|
this.close.setColor("primary");
|
|
132
121
|
this.close.setVariant("text");
|
|
133
122
|
this.close.setText("X");
|
|
134
123
|
this.close.setFixedSize(40);
|
|
135
124
|
|
|
136
|
-
this.btnSpacerLeft = new Widget(
|
|
137
|
-
this.id + ".btnSpacerLeft",
|
|
138
|
-
"div",
|
|
139
|
-
this.buttonContainer
|
|
140
|
-
);
|
|
141
|
-
this.btnSpacerLeft.setType(WidgetTypes.FILL);
|
|
142
|
-
this.btnSpacerLeft.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
143
|
-
|
|
144
125
|
if (this.buttonContainer) {
|
|
145
|
-
this.cancell = new Button(
|
|
146
|
-
this.id + ".cancell",
|
|
147
|
-
this.buttonContainer
|
|
148
|
-
);
|
|
126
|
+
this.cancell = new Button(this.id + ".cancell", null);
|
|
149
127
|
this.cancell.setType(WidgetTypes.FILL);
|
|
150
128
|
this.cancell.setColor("error");
|
|
151
129
|
this.cancell.setText("Cancel");
|
|
152
130
|
this.cancell.setVariant("contained");
|
|
153
131
|
this.cancell.setFixedSize(100);
|
|
154
132
|
|
|
155
|
-
this.ok = new Button(this.id + ".ok",
|
|
133
|
+
this.ok = new Button(this.id + ".ok", null);
|
|
156
134
|
this.ok.setType(WidgetTypes.FILL);
|
|
157
135
|
this.ok.setText("OK");
|
|
158
136
|
this.ok.setVariant("contained");
|
|
159
137
|
this.ok.setColor("success");
|
|
160
138
|
this.ok.setFixedSize(100);
|
|
161
139
|
|
|
162
|
-
this.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
167
|
-
this.btnSpacerRight.setType(WidgetTypes.FILL);
|
|
168
|
-
this.btnSpacerRight.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
140
|
+
this.buttonContainer.addChild(Spacer());
|
|
141
|
+
this.buttonContainer.addChild(this.cancell);
|
|
142
|
+
this.buttonContainer.addChild(this.ok);
|
|
143
|
+
this.buttonContainer.addChild(Spacer());
|
|
169
144
|
|
|
170
145
|
this.ok.subscribe({
|
|
171
146
|
event: "click",
|
|
@@ -256,12 +231,8 @@ export class Dialog extends Widget {
|
|
|
256
231
|
if (!this.handlerResizable) return;
|
|
257
232
|
const mouseX = (e as MouseEvent).clientX;
|
|
258
233
|
const mouseY = (e as MouseEvent).clientY;
|
|
259
|
-
this.dragDistX = Math.abs(
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
this.dragDistY = Math.abs(
|
|
263
|
-
this.handlerResizable.getPosition().y - mouseY
|
|
264
|
-
);
|
|
234
|
+
this.dragDistX = Math.abs(this.handlerResizable.getPosition().x - mouseX);
|
|
235
|
+
this.dragDistY = Math.abs(this.handlerResizable.getPosition().y - mouseY);
|
|
265
236
|
|
|
266
237
|
this.resizing = true;
|
|
267
238
|
this.background.setVisible(true);
|
|
@@ -272,6 +243,13 @@ export class Dialog extends Widget {
|
|
|
272
243
|
});
|
|
273
244
|
}
|
|
274
245
|
|
|
246
|
+
this.titleContainer.addChild(this.titleBar);
|
|
247
|
+
this.titleContainer.addChild(this.close);
|
|
248
|
+
|
|
249
|
+
this.addChild(this.titleContainer);
|
|
250
|
+
this.addChild(this.contentCntainer);
|
|
251
|
+
if (hasButtons) this.addChild(this.buttonContainer);
|
|
252
|
+
|
|
275
253
|
this.init();
|
|
276
254
|
}
|
|
277
255
|
|
|
@@ -322,7 +300,13 @@ export class Dialog extends Widget {
|
|
|
322
300
|
this.deleteClass("WUIDialogHide");
|
|
323
301
|
this.addClass("WUIDialogDisplayed");
|
|
324
302
|
this.render();
|
|
325
|
-
|
|
303
|
+
|
|
304
|
+
if (this.startX > 0 && this.startY > 0) {
|
|
305
|
+
this.setX(this.startX);
|
|
306
|
+
this.setY(this.startY);
|
|
307
|
+
} else {
|
|
308
|
+
this.center();
|
|
309
|
+
}
|
|
326
310
|
|
|
327
311
|
this.background.setVisible(true);
|
|
328
312
|
this.background.raisteTop();
|
|
@@ -345,7 +329,7 @@ export class Dialog extends Widget {
|
|
|
345
329
|
this.raiseBottom();
|
|
346
330
|
}
|
|
347
331
|
|
|
348
|
-
init() {
|
|
332
|
+
public init() {
|
|
349
333
|
super.init();
|
|
350
334
|
}
|
|
351
335
|
|
|
@@ -354,7 +338,7 @@ export class Dialog extends Widget {
|
|
|
354
338
|
*
|
|
355
339
|
* @param {number} height - The height of the title bar.
|
|
356
340
|
*/
|
|
357
|
-
setTitlebarHeight(height: number) {
|
|
341
|
+
public setTitlebarHeight(height: number) {
|
|
358
342
|
this.titleBarHeight = height;
|
|
359
343
|
}
|
|
360
344
|
|
|
@@ -363,7 +347,7 @@ export class Dialog extends Widget {
|
|
|
363
347
|
*
|
|
364
348
|
* @param {number} height - The height of the button bar.
|
|
365
349
|
*/
|
|
366
|
-
setButtonbarHeight(height: number) {
|
|
350
|
+
public setButtonbarHeight(height: number) {
|
|
367
351
|
this.buttonBarHeight = height;
|
|
368
352
|
}
|
|
369
353
|
|
|
@@ -395,4 +379,107 @@ export class Dialog extends Widget {
|
|
|
395
379
|
if (!this.cancell) return;
|
|
396
380
|
this.cancell.subscribe({ event: "click", then: cb.then });
|
|
397
381
|
}
|
|
382
|
+
|
|
383
|
+
public setStartX(x: number): void {
|
|
384
|
+
this.startX = x;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
public setStartY(y: number): void {
|
|
388
|
+
this.startY = y;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export type WDialogProps = Omit<WidgetProps, "orientation" | "hidden"> & {
|
|
393
|
+
hasButtons?: boolean;
|
|
394
|
+
resizable?: boolean;
|
|
395
|
+
visible?: boolean;
|
|
396
|
+
titleBarHeight?: number;
|
|
397
|
+
buttonBarHeight?: number;
|
|
398
|
+
positionX?: number;
|
|
399
|
+
positionY?: number;
|
|
400
|
+
width?: number;
|
|
401
|
+
height?: number;
|
|
402
|
+
children: any;
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
export const WDialog = (props: WDialogProps) => {
|
|
406
|
+
if (!props.id) {
|
|
407
|
+
props.id = "Dialog." + UID();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return normalizeWidget(
|
|
411
|
+
<div
|
|
412
|
+
id={props.id}
|
|
413
|
+
w-dialog
|
|
414
|
+
w-position-x={props.positionX}
|
|
415
|
+
w-position-y={props.positionY}
|
|
416
|
+
w-dialog-width={props.width}
|
|
417
|
+
w-dialog-height={props.height}
|
|
418
|
+
w-has-buttons={props.hasButtons}
|
|
419
|
+
w-resizable={props.resizable}
|
|
420
|
+
w-visible={props.visible}
|
|
421
|
+
w-titlebar-height={props.titleBarHeight}
|
|
422
|
+
w-buttonbar-height={props.buttonBarHeight}
|
|
423
|
+
>
|
|
424
|
+
{props.children}
|
|
425
|
+
</div>,
|
|
426
|
+
props
|
|
427
|
+
);
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
export function createDialog(id: string, content: any, _parent: Widget | null = null): Dialog {
|
|
431
|
+
const dataHasButtons = content.getAttribute("w-has-buttons") ? true : false;
|
|
432
|
+
const dataResizable = content.getAttribute("w-resizable") ? true : false;
|
|
433
|
+
const dataVisible = content.getAttribute("w-visible") ? true : false;
|
|
434
|
+
const dataTitlebarHeight = content.getAttribute("w-titlebar-height")
|
|
435
|
+
? parseInt(content.getAttribute("w-titlebar-height"))
|
|
436
|
+
: null;
|
|
437
|
+
const dataButtonbarHeight = content.getAttribute("w-buttonbar-height")
|
|
438
|
+
? parseInt(content.getAttribute("w-buttonbar-height"))
|
|
439
|
+
: null;
|
|
440
|
+
|
|
441
|
+
const dataPositionX = content.getAttribute("w-position-x")
|
|
442
|
+
? parseInt(content.getAttribute("w-position-x"))
|
|
443
|
+
: null;
|
|
444
|
+
|
|
445
|
+
const dataPositionY = content.getAttribute("w-position-y")
|
|
446
|
+
? parseInt(content.getAttribute("w-position-y"))
|
|
447
|
+
: null;
|
|
448
|
+
|
|
449
|
+
const dataWidth = content.getAttribute("w-dialog-width")
|
|
450
|
+
? parseInt(content.getAttribute("w-dialog-width"))
|
|
451
|
+
: null;
|
|
452
|
+
|
|
453
|
+
const dataHeight = content.getAttribute("w-dialog-height")
|
|
454
|
+
? parseInt(content.getAttribute("w-dialog-height"))
|
|
455
|
+
: null;
|
|
456
|
+
|
|
457
|
+
let newDialog = new Dialog(id, null, dataHasButtons, dataResizable);
|
|
458
|
+
|
|
459
|
+
if (dataTitlebarHeight !== null) newDialog.setTitlebarHeight(dataTitlebarHeight);
|
|
460
|
+
if (dataButtonbarHeight !== null) newDialog.setButtonbarHeight(dataButtonbarHeight);
|
|
461
|
+
if (dataPositionX !== null) newDialog.setStartX(dataPositionX);
|
|
462
|
+
if (dataPositionY !== null) newDialog.setStartY(dataPositionY);
|
|
463
|
+
if (dataHeight !== null) newDialog.setY(dataHeight);
|
|
464
|
+
if (dataWidth !== null) newDialog.setW(dataWidth);
|
|
465
|
+
|
|
466
|
+
if (content.childNodes.length > 1) {
|
|
467
|
+
throw new Error("Dialog must have only one child");
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
const childWidget = content.firstChild;
|
|
471
|
+
|
|
472
|
+
if (childWidget !== null) {
|
|
473
|
+
const widget = createWidget(childWidget);
|
|
474
|
+
if (widget) {
|
|
475
|
+
newDialog.getContentCntainer().setPadding(0);
|
|
476
|
+
newDialog.getContentCntainer().attachWidget(widget);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (dataVisible) newDialog.show();
|
|
481
|
+
|
|
482
|
+
newDialog.background.setVisible(false);
|
|
483
|
+
|
|
484
|
+
return newDialog;
|
|
398
485
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { UID } from "../core/uid";
|
|
1
2
|
import { Draggable } from "./draggable.ui";
|
|
2
3
|
import "./styles/hpanel.css";
|
|
3
|
-
import {
|
|
4
|
+
import { WidgetProps, createWidget, normalizeWidget } from "./widget.builder";
|
|
5
|
+
import {
|
|
6
|
+
connectWidgetCallback,
|
|
7
|
+
getOnlyEventProps,
|
|
8
|
+
Widget,
|
|
9
|
+
WidgetAlignTypes,
|
|
10
|
+
WidgetTypes,
|
|
11
|
+
} from "./widget.ui";
|
|
4
12
|
|
|
5
13
|
const HPANEL_HANDLER_SIZE = 4;
|
|
6
14
|
|
|
@@ -100,6 +108,16 @@ export class HPanel extends Widget {
|
|
|
100
108
|
this.render();
|
|
101
109
|
}
|
|
102
110
|
|
|
111
|
+
public setLeftWidth(width: number): void {
|
|
112
|
+
this.leftWidth = width;
|
|
113
|
+
this.rightWidth = null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public setRightWidth(width: number): void {
|
|
117
|
+
this.leftWidth = null;
|
|
118
|
+
this.rightWidth = width;
|
|
119
|
+
}
|
|
120
|
+
|
|
103
121
|
public render(): void {
|
|
104
122
|
super.render();
|
|
105
123
|
this.handler.setW(HPANEL_HANDLER_SIZE);
|
|
@@ -124,4 +142,49 @@ export class HPanel extends Widget {
|
|
|
124
142
|
|
|
125
143
|
this.handler.setY(this.getY(true));
|
|
126
144
|
}
|
|
145
|
+
|
|
146
|
+
public free(): void {
|
|
147
|
+
this.handler.free();
|
|
148
|
+
this.leftContent?.free();
|
|
149
|
+
this.rightContent?.free();
|
|
150
|
+
//this.draggable.free();
|
|
151
|
+
super.free();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type WHPanelProps = WidgetProps & {
|
|
156
|
+
children: any;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const WHPanel = (props: WHPanelProps) => {
|
|
160
|
+
if (!props.id) {
|
|
161
|
+
props.id = "Icon." + UID();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
165
|
+
|
|
166
|
+
return normalizeWidget(
|
|
167
|
+
<div id={props.id} w-hpanel>
|
|
168
|
+
{props.children}
|
|
169
|
+
</div>,
|
|
170
|
+
props
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export function createHPanel(id: string, content: any, parent: Widget | null = null): HPanel {
|
|
175
|
+
let newPanel = new HPanel(id, parent);
|
|
176
|
+
|
|
177
|
+
content.childNodes.forEach((item: HTMLElement, index: number) => {
|
|
178
|
+
const widget = createWidget(item);
|
|
179
|
+
|
|
180
|
+
if (widget !== null) {
|
|
181
|
+
if (index === 0) {
|
|
182
|
+
newPanel.setLeft(widget, widget.getFixedSize());
|
|
183
|
+
} else if (index === 1) {
|
|
184
|
+
newPanel.setRight(widget);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return newPanel;
|
|
127
190
|
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { IconButton, wIconButtonProps } from "./IconButton.ui";
|
|
2
|
+
import { Menu } from "./menu.ui";
|
|
3
|
+
import { SelectItem } from "../types/select.item.type";
|
|
4
|
+
import { normalizeWidget, WidgetProps } from "./widget.builder";
|
|
5
|
+
import { connectWidgetCallback, getOnlyEventProps, Widget } from "./widget.ui";
|
|
6
|
+
import { UID } from "../core/uid";
|
|
7
|
+
import { connectCustomWidget } from "./widget.collection";
|
|
8
|
+
import { IWidget } from "../interfaces/widget.interface";
|
|
9
|
+
|
|
10
|
+
export class IconButtonMenu extends IconButton {
|
|
11
|
+
menu: Menu;
|
|
12
|
+
items: Array<SelectItem>;
|
|
13
|
+
selectedItem: SelectItem | null;
|
|
14
|
+
|
|
15
|
+
whenOptionClicked: (args: any) => {} | void;
|
|
16
|
+
|
|
17
|
+
public constructor(id: string, icon: string) {
|
|
18
|
+
super(id, icon);
|
|
19
|
+
|
|
20
|
+
this.whenOptionClicked = () => {};
|
|
21
|
+
|
|
22
|
+
this.menu = new Menu(this.id + ".menu", this.id, null);
|
|
23
|
+
|
|
24
|
+
this.items = new Array<SelectItem>();
|
|
25
|
+
this.selectedItem = null;
|
|
26
|
+
|
|
27
|
+
this.subscribe({
|
|
28
|
+
event: "click",
|
|
29
|
+
then: () => {
|
|
30
|
+
this.menu.clearOptions();
|
|
31
|
+
this.items.forEach((item) => {
|
|
32
|
+
this.menu.addOption(item.id, item.icon, item.label);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this.menu.wakeUp();
|
|
36
|
+
|
|
37
|
+
if (this.getW() > this.menu.getW()) {
|
|
38
|
+
this.menu.setW(this.getBody().clientWidth);
|
|
39
|
+
console.log("cambiando ancho...");
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
this.menu.subscribe({
|
|
45
|
+
event: "option-clicked",
|
|
46
|
+
then: (_e, clickedOption) => {
|
|
47
|
+
const option = clickedOption as IconButton;
|
|
48
|
+
const fintOption = this.items.find((item) => item.id === option.id);
|
|
49
|
+
|
|
50
|
+
if (fintOption) {
|
|
51
|
+
this.selectedItem = fintOption;
|
|
52
|
+
this.whenOptionClicked({ id: fintOption.id });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// const selectedText = this.selectedItem?.label;
|
|
56
|
+
// if (selectedText) {
|
|
57
|
+
// this.setText(selectedText);
|
|
58
|
+
// } else {
|
|
59
|
+
// this.setText("");
|
|
60
|
+
// }
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public setOnOptionClicked(cb: ({}) => {} | void) {
|
|
66
|
+
this.whenOptionClicked = cb;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public addItem(id: string, label: string, icon: string): void {
|
|
70
|
+
this.items.push(new SelectItem(id, label, icon));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type WIconButtonMenuProps = WidgetProps &
|
|
75
|
+
wIconButtonProps & {
|
|
76
|
+
icon?: string | null;
|
|
77
|
+
onOptionClicked?: (args: any) => {} | void;
|
|
78
|
+
children: any;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type WIconButtonMenuItemProps = {
|
|
82
|
+
id: string;
|
|
83
|
+
label?: string | null;
|
|
84
|
+
icon?: string | null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const WIconButtonMenu = (props: WIconButtonMenuProps) => {
|
|
88
|
+
if (!props.id) {
|
|
89
|
+
props.id = "IconButtonMenu." + UID();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
93
|
+
|
|
94
|
+
connectCustomWidget("widget-custom-added-" + props.id, {
|
|
95
|
+
event: "widget-load",
|
|
96
|
+
then: (_e: Event, _w: IWidget | null) => {
|
|
97
|
+
if (!props.id) return;
|
|
98
|
+
const widget = w.get(props.id) as IconButtonMenu;
|
|
99
|
+
|
|
100
|
+
if (props.onOptionClicked) {
|
|
101
|
+
widget.setOnOptionClicked(props.onOptionClicked);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return normalizeWidget(
|
|
107
|
+
<div
|
|
108
|
+
id={props.id}
|
|
109
|
+
w-icon-button-menu
|
|
110
|
+
w-text={props.text}
|
|
111
|
+
w-icon={props.icon}
|
|
112
|
+
w-variant={props.variant}
|
|
113
|
+
w-color={props.color}
|
|
114
|
+
w-width={props.width}
|
|
115
|
+
w-height={props.height}
|
|
116
|
+
>
|
|
117
|
+
{props.children}
|
|
118
|
+
</div>,
|
|
119
|
+
props
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const WIconButtonMenuItem = (props: WIconButtonMenuItemProps) => {
|
|
124
|
+
return (
|
|
125
|
+
<div w-icon-button-menu-item id={props.id} w-label={props.label} w-icon={props.icon}></div>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export function createIconButtonMenu(
|
|
130
|
+
id: string,
|
|
131
|
+
content: any,
|
|
132
|
+
_parent: Widget | null = null
|
|
133
|
+
): IconButtonMenu {
|
|
134
|
+
const btnIcon = content.getAttribute("w-icon");
|
|
135
|
+
const btnText = content.getAttribute("w-text");
|
|
136
|
+
const btnColor = content.getAttribute("w-color");
|
|
137
|
+
const btnVariant = content.getAttribute("w-variant");
|
|
138
|
+
const dataWidth = content.getAttribute("w-width");
|
|
139
|
+
const dataHeight = content.getAttribute("w-height");
|
|
140
|
+
|
|
141
|
+
let newIconButtonMenu = new IconButtonMenu(id, btnIcon || "home");
|
|
142
|
+
|
|
143
|
+
if (btnText) {
|
|
144
|
+
newIconButtonMenu.setText(btnText);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (btnColor) {
|
|
148
|
+
newIconButtonMenu.setColor(btnColor);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (btnVariant) {
|
|
152
|
+
newIconButtonMenu.setVariant(btnVariant);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (dataWidth) {
|
|
156
|
+
newIconButtonMenu.setInitialW(dataWidth);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (dataHeight) {
|
|
160
|
+
newIconButtonMenu.setInitialH(dataHeight);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
content.childNodes.forEach((menuItem: HTMLElement, index: number) => {
|
|
164
|
+
if (menuItem.getAttribute("w-icon-button-menu-item") !== null) {
|
|
165
|
+
const itemId = menuItem.getAttribute("id");
|
|
166
|
+
const itemLabel = menuItem.getAttribute("w-label");
|
|
167
|
+
const itemIcon = menuItem.getAttribute("w-icon");
|
|
168
|
+
|
|
169
|
+
if (itemId !== null) {
|
|
170
|
+
newIconButtonMenu.addItem(itemId, itemLabel || "Unnamed" + index, itemIcon || "");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return newIconButtonMenu;
|
|
176
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { UID } from "../core/uid";
|
|
2
|
+
import "./styles/image.css";
|
|
3
|
+
import { normalizeWidget, WidgetProps } from "./widget.builder";
|
|
4
|
+
import { Widget, WidgetTypes, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
|
|
5
|
+
import { decode } from "html-entities";
|
|
6
|
+
|
|
7
|
+
export class Image extends Widget {
|
|
8
|
+
imageContainer: Widget;
|
|
9
|
+
image: Widget;
|
|
10
|
+
constructor(id: string, src: string = "", parent: Widget | null = null) {
|
|
11
|
+
super(id, "div", parent);
|
|
12
|
+
|
|
13
|
+
this.imageContainer = new Widget(id + ".imageContainer", "div", this);
|
|
14
|
+
this.imageContainer.addClass("WUIImageContainer");
|
|
15
|
+
|
|
16
|
+
this.image = new Widget(id + ".image", "img", this.imageContainer);
|
|
17
|
+
this.image.setType(WidgetTypes.CUSTOM);
|
|
18
|
+
this.image.getBody().setAttribute("src", src);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public render(): void {
|
|
22
|
+
super.render();
|
|
23
|
+
|
|
24
|
+
this.imageContainer.setX(0);
|
|
25
|
+
this.imageContainer.setY(0);
|
|
26
|
+
this.imageContainer.setWH(this.getW(), this.getH());
|
|
27
|
+
|
|
28
|
+
this.image.getBody().style.position = "relative";
|
|
29
|
+
|
|
30
|
+
const imageH = this.image.getH();
|
|
31
|
+
|
|
32
|
+
this.image.setX(0);
|
|
33
|
+
this.image.setY(this.getH() / 2 - imageH / 2);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public fillWidth(): void {
|
|
37
|
+
this.image.addClass("WUIImageFillWidth");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public fillHeight(): void {
|
|
41
|
+
this.image.addClass("WUIImageFillHeight");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public setAlternateText(text: string): void {
|
|
45
|
+
this.image.getBody().setAttribute("alt", text);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public setImageUrl(url: string): void {
|
|
49
|
+
this.image.getBody().setAttribute("src", url);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public getImageUrl(): string | null {
|
|
53
|
+
return this.image.getBody().getAttribute("src");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public getAlternateText(): string | null {
|
|
57
|
+
return this.image.getBody().getAttribute("alt");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type wImageProps = WidgetProps & {
|
|
62
|
+
src: string;
|
|
63
|
+
alt?: string | null;
|
|
64
|
+
fillWidth?: boolean | null;
|
|
65
|
+
fillHeight?: boolean | null;
|
|
66
|
+
width?: number | null;
|
|
67
|
+
height?: number | null;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const WImage = (props: wImageProps) => {
|
|
71
|
+
if (!props.id) {
|
|
72
|
+
props.id = "Image." + UID();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
76
|
+
|
|
77
|
+
return normalizeWidget(
|
|
78
|
+
<div
|
|
79
|
+
id={props.id}
|
|
80
|
+
w-image
|
|
81
|
+
w-src={props.src}
|
|
82
|
+
w-alt={props.alt}
|
|
83
|
+
w-fill-width={props.fillWidth}
|
|
84
|
+
w-fill-height={props.fillHeight}
|
|
85
|
+
w-width={props.width}
|
|
86
|
+
w-height={props.height}
|
|
87
|
+
></div>,
|
|
88
|
+
props
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export function createImage(id: string, content: any, parent: Widget | null = null): Image {
|
|
93
|
+
const dataSrc = content.getAttribute("w-src");
|
|
94
|
+
const dataAlt = content.getAttribute("w-alt");
|
|
95
|
+
const dataFillWidth = content.getAttribute("w-fill-width");
|
|
96
|
+
const dataFillHeight = content.getAttribute("w-fill-height");
|
|
97
|
+
const dataWidth = content.getAttribute("w-width");
|
|
98
|
+
const dataHeight = content.getAttribute("w-height");
|
|
99
|
+
|
|
100
|
+
let newImage = new Image(id, decode(dataSrc), parent);
|
|
101
|
+
|
|
102
|
+
if (dataAlt) {
|
|
103
|
+
newImage.setAlternateText(dataAlt);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (dataFillWidth) {
|
|
107
|
+
newImage.fillWidth();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (dataFillHeight) {
|
|
111
|
+
newImage.fillHeight();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (dataWidth) {
|
|
115
|
+
newImage.setInitialW(dataWidth);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (dataHeight) {
|
|
119
|
+
newImage.setInitialH(dataHeight);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return newImage;
|
|
123
|
+
}
|