cedro 0.1.9 → 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 -60
- package/src/core/application.core.tsx +110 -11
- package/src/core/themes.core.ts +160 -1
- package/src/core/uid.ts +3 -3
- package/src/interfaces/application.interface.ts +3 -2
- package/src/interfaces/widget.interface.ts +3 -0
- package/src/types/select.item.type.ts +11 -0
- package/src/ui/Icon.ui.tsx +158 -0
- package/src/ui/IconButton.ui.tsx +51 -9
- package/src/ui/{textbox.ui.tsx → Textbox.ui.tsx} +23 -15
- package/src/ui/accordion.ui.tsx +152 -0
- package/src/ui/button.ui.tsx +56 -14
- 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 +9 -13
- package/src/ui/container.ui.tsx +141 -76
- package/src/ui/datagrid.ui.tsx +518 -0
- package/src/ui/dialog.tsx +143 -56
- package/src/ui/hpanel.ui.tsx +37 -11
- package/src/ui/iconButtonMenu.ui.tsx +176 -0
- package/src/ui/image.ui.tsx +123 -112
- package/src/ui/index.ts +8 -8
- package/src/ui/label.ui.tsx +61 -3
- package/src/ui/loading.ui.ts +10 -10
- package/src/ui/menu.ui.ts +2 -2
- package/src/ui/progressbar.ui.tsx +9 -8
- package/src/ui/{radiobutton.tsx → radiobutton.ui.tsx} +9 -13
- 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/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 +2 -1
- 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/switch.ui.tsx +9 -13
- package/src/ui/tabs.ui.tsx +43 -22
- package/src/ui/textarea.ui.tsx +48 -0
- package/src/ui/toolbar.ui.tsx +17 -12
- package/src/ui/valuebar.ui.tsx +11 -13
- package/src/ui/vpanel.ui.tsx +19 -13
- package/src/ui/widget.builder.ts +243 -159
- package/src/ui/widget.collection.ts +24 -2
- package/src/ui/widget.ui.ts +79 -19
- package/src/ui/Icon.ui.ts +0 -64
- package/src/ui/accordion.ui.ts +0 -71
- package/src/ui/buttonColor.ui.ts +0 -24
- package/src/ui/buttonmenu.ui.ts +0 -59
- package/src/ui/datagrid.ui.ts +0 -231
- package/src/ui/iconButtonMenu.ui.ts +0 -59
- package/src/ui/select.ui.ts +0 -73
- package/src/ui/textarea.ui.ts +0 -20
- /package/src/ui/{toggle.ui.ts → toggle.ui.tsx} +0 -0
package/src/ui/widget.ui.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UID } from "../core/uid";
|
|
1
2
|
import { IWidget, WUIEvent, WUICallback } from "../interfaces/widget.interface";
|
|
2
3
|
import { Vector2D } from "../types/vector2d.type";
|
|
3
4
|
import { WidgetEventProps, WidgetProps } from "./widget.builder";
|
|
@@ -44,8 +45,12 @@ export class Widget implements IWidget {
|
|
|
44
45
|
bodyTagName: string;
|
|
45
46
|
body: HTMLElement;
|
|
46
47
|
|
|
47
|
-
constructor(
|
|
48
|
-
|
|
48
|
+
constructor(
|
|
49
|
+
id: string | null = "",
|
|
50
|
+
bodyTagName: string = "div",
|
|
51
|
+
parent: IWidget | null = null
|
|
52
|
+
) {
|
|
53
|
+
this.id = id ? id : UID();
|
|
49
54
|
|
|
50
55
|
this.overflow = false;
|
|
51
56
|
|
|
@@ -289,9 +294,8 @@ export class Widget implements IWidget {
|
|
|
289
294
|
}
|
|
290
295
|
|
|
291
296
|
if (freeStyle) {
|
|
292
|
-
|
|
297
|
+
this.deleteClass("WUINonFreePosition");
|
|
293
298
|
this.addClass("WUIFixPosition");
|
|
294
|
-
//this.body.style.overflow = "auto";
|
|
295
299
|
this.body.style.left = "";
|
|
296
300
|
this.body.style.top = "";
|
|
297
301
|
this.body.style.width = "";
|
|
@@ -301,8 +305,10 @@ export class Widget implements IWidget {
|
|
|
301
305
|
this.body.style.right = "";
|
|
302
306
|
} else {
|
|
303
307
|
if (this.type === WidgetTypes.CUSTOM || this.type === WidgetTypes.FILL) {
|
|
304
|
-
this.body.style.position = "absolute";
|
|
305
|
-
this.body.style.overflow = "hidden";
|
|
308
|
+
// this.body.style.position = "absolute";
|
|
309
|
+
// this.body.style.overflow = "hidden";
|
|
310
|
+
this.deleteClass("WUIFixPosition");
|
|
311
|
+
this.addClass("WUINonFreePosition");
|
|
306
312
|
}
|
|
307
313
|
}
|
|
308
314
|
|
|
@@ -362,6 +368,8 @@ export class Widget implements IWidget {
|
|
|
362
368
|
this.parent = parent;
|
|
363
369
|
this.parent?.body.appendChild(this.body);
|
|
364
370
|
|
|
371
|
+
this.setType(this.type); //TODO: revisar, se coloca para tratar de que reconozca al padre como freestyle en caso de serlo.
|
|
372
|
+
|
|
365
373
|
//this.parent?.addChild(this);
|
|
366
374
|
}
|
|
367
375
|
|
|
@@ -596,6 +604,7 @@ export class Widget implements IWidget {
|
|
|
596
604
|
public addChild(child: IWidget | null = null): void {
|
|
597
605
|
if (!child) return;
|
|
598
606
|
this.childs.push(child);
|
|
607
|
+
|
|
599
608
|
child.setParent(this);
|
|
600
609
|
|
|
601
610
|
child.init();
|
|
@@ -603,6 +612,17 @@ export class Widget implements IWidget {
|
|
|
603
612
|
child.render();*/
|
|
604
613
|
}
|
|
605
614
|
|
|
615
|
+
public populate(): void {
|
|
616
|
+
//se agrega a si mismo a window.w y a sus hijos.
|
|
617
|
+
if (!window.w.get(this.id)) {
|
|
618
|
+
window.w.set(this.id, this);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
for (const child of this.childs) {
|
|
622
|
+
child.populate();
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
606
626
|
/**
|
|
607
627
|
* Disables the selection feature.
|
|
608
628
|
*
|
|
@@ -638,9 +658,25 @@ export class Widget implements IWidget {
|
|
|
638
658
|
* @return {type} description of return value
|
|
639
659
|
*/
|
|
640
660
|
public init(): void {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
661
|
+
let freeStyle = false;
|
|
662
|
+
|
|
663
|
+
if (this.type === WidgetTypes.FREE) {
|
|
664
|
+
freeStyle = true;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const parent = this.getParent();
|
|
668
|
+
|
|
669
|
+
if (parent) {
|
|
670
|
+
if (parent.type === WidgetTypes.FREE) {
|
|
671
|
+
freeStyle = true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
if (!freeStyle) {
|
|
676
|
+
this.deleteClass("WUIFixPosition");
|
|
677
|
+
this.addClass("WUINonFreePosition");
|
|
678
|
+
// this.body.style.position = "absolute";
|
|
679
|
+
// this.body.style.overflow = "hidden";
|
|
644
680
|
}
|
|
645
681
|
|
|
646
682
|
this.initPosition();
|
|
@@ -758,6 +794,12 @@ export class Widget implements IWidget {
|
|
|
758
794
|
currentPosition += elementSize;
|
|
759
795
|
child.render();
|
|
760
796
|
}
|
|
797
|
+
|
|
798
|
+
this.subscribers.forEach((callback) => {
|
|
799
|
+
if (callback.event == "render") {
|
|
800
|
+
callback.then(new Event("render"), this);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
761
803
|
}
|
|
762
804
|
|
|
763
805
|
/**
|
|
@@ -855,7 +897,13 @@ export class Widget implements IWidget {
|
|
|
855
897
|
child.free();
|
|
856
898
|
}
|
|
857
899
|
}
|
|
900
|
+
|
|
858
901
|
window.w.delete(this.id);
|
|
902
|
+
|
|
903
|
+
const body = this.getBody();
|
|
904
|
+
const parent = body.parentNode;
|
|
905
|
+
if (!parent && !body) return;
|
|
906
|
+
parent?.removeChild(body);
|
|
859
907
|
}
|
|
860
908
|
|
|
861
909
|
public dispose(): void {
|
|
@@ -877,12 +925,17 @@ export function getOnlyEventProps(props: WidgetProps): WidgetEventProps {
|
|
|
877
925
|
onMouseOut: props.onMouseOut,
|
|
878
926
|
onMouseLeave: props.onMouseLeave,
|
|
879
927
|
onWheel: props.onWheel,
|
|
928
|
+
onRender: props.onRender,
|
|
880
929
|
};
|
|
881
930
|
|
|
882
931
|
return eventProps;
|
|
883
932
|
}
|
|
884
933
|
|
|
885
|
-
export function connectWidgetCallback(
|
|
934
|
+
export function connectWidgetCallback(
|
|
935
|
+
id: string | null | undefined,
|
|
936
|
+
props: WidgetEventProps
|
|
937
|
+
): void {
|
|
938
|
+
if (!id) return;
|
|
886
939
|
connectWidget("widget-added-" + id, {
|
|
887
940
|
event: "widget-load",
|
|
888
941
|
then: (_e, _w) => {
|
|
@@ -892,63 +945,70 @@ export function connectWidgetCallback(id: string, props: WidgetEventProps): void
|
|
|
892
945
|
widget.subscribe({
|
|
893
946
|
event: "click",
|
|
894
947
|
then: (_e, _w) => {
|
|
895
|
-
props.onClick ? props.onClick() : null;
|
|
948
|
+
props.onClick ? props.onClick({}) : null;
|
|
896
949
|
},
|
|
897
950
|
});
|
|
898
951
|
|
|
899
952
|
widget.subscribe({
|
|
900
953
|
event: "drag",
|
|
901
954
|
then: (_e, _w) => {
|
|
902
|
-
props.onDrag ? props.onDrag() : null;
|
|
955
|
+
props.onDrag ? props.onDrag({}) : null;
|
|
903
956
|
},
|
|
904
957
|
});
|
|
905
958
|
|
|
906
959
|
widget.subscribe({
|
|
907
960
|
event: "resize",
|
|
908
961
|
then: (_e, _w) => {
|
|
909
|
-
props.onResize ? props.onResize() : null;
|
|
962
|
+
props.onResize ? props.onResize({}) : null;
|
|
910
963
|
},
|
|
911
964
|
});
|
|
912
965
|
|
|
913
966
|
widget.subscribe({
|
|
914
967
|
event: "mousedown",
|
|
915
968
|
then: (_e, _w) => {
|
|
916
|
-
props.onMouseDown ? props.onMouseDown() : null;
|
|
969
|
+
props.onMouseDown ? props.onMouseDown({}) : null;
|
|
917
970
|
},
|
|
918
971
|
});
|
|
919
972
|
|
|
920
973
|
widget.subscribe({
|
|
921
974
|
event: "mouseup",
|
|
922
975
|
then: (_e, _w) => {
|
|
923
|
-
props.onMouseUp ? props.onMouseUp() : null;
|
|
976
|
+
props.onMouseUp ? props.onMouseUp({}) : null;
|
|
924
977
|
},
|
|
925
978
|
});
|
|
926
979
|
|
|
927
980
|
widget.subscribe({
|
|
928
981
|
event: "mousemove",
|
|
929
982
|
then: (_e, _w) => {
|
|
930
|
-
props.onMouseMove ? props.onMouseMove() : null;
|
|
983
|
+
props.onMouseMove ? props.onMouseMove({}) : null;
|
|
931
984
|
},
|
|
932
985
|
});
|
|
933
986
|
|
|
934
987
|
widget.subscribe({
|
|
935
988
|
event: "mouseout",
|
|
936
989
|
then: (_e, _w) => {
|
|
937
|
-
props.onMouseOut ? props.onMouseOut() : null;
|
|
990
|
+
props.onMouseOut ? props.onMouseOut({}) : null;
|
|
938
991
|
},
|
|
939
992
|
});
|
|
940
993
|
|
|
941
994
|
widget.subscribe({
|
|
942
995
|
event: "mouseleave",
|
|
943
996
|
then: (_e, _w) => {
|
|
944
|
-
props.onMouseLeave ? props.onMouseLeave() : null;
|
|
997
|
+
props.onMouseLeave ? props.onMouseLeave({}) : null;
|
|
945
998
|
},
|
|
946
999
|
});
|
|
947
1000
|
|
|
948
1001
|
widget.subscribe({
|
|
949
1002
|
event: "wheel",
|
|
950
1003
|
then: (_e, _w) => {
|
|
951
|
-
props.onWheel ? props.onWheel() : null;
|
|
1004
|
+
props.onWheel ? props.onWheel({}) : null;
|
|
1005
|
+
},
|
|
1006
|
+
});
|
|
1007
|
+
|
|
1008
|
+
widget.subscribe({
|
|
1009
|
+
event: "render",
|
|
1010
|
+
then: (_e, _w) => {
|
|
1011
|
+
props.onRender ? props.onRender({}) : null;
|
|
952
1012
|
},
|
|
953
1013
|
});
|
|
954
1014
|
}
|
package/src/ui/Icon.ui.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Colors } from "./colors.ui";
|
|
2
|
-
import { Widget } from "./widget.ui";
|
|
3
|
-
|
|
4
|
-
export type IconVariants = "Filled" | "Outlined" | "Round" | "Sharp" | "Two Tone";
|
|
5
|
-
|
|
6
|
-
export class Icon extends Widget {
|
|
7
|
-
variant: IconVariants;
|
|
8
|
-
color: Colors;
|
|
9
|
-
icon: string;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
id: string,
|
|
13
|
-
icon: string,
|
|
14
|
-
variant: IconVariants = "Filled",
|
|
15
|
-
parent: Widget | null = null
|
|
16
|
-
) {
|
|
17
|
-
super(id, "span", parent);
|
|
18
|
-
|
|
19
|
-
this.variant = variant;
|
|
20
|
-
this.color = "primary";
|
|
21
|
-
this.icon = icon;
|
|
22
|
-
|
|
23
|
-
if (this.variant === "Filled") {
|
|
24
|
-
this.addClass("material-icons");
|
|
25
|
-
} else {
|
|
26
|
-
this.addClass(
|
|
27
|
-
"material-icons-" + this.variant.toString().replace(" ", "-").toLowerCase()
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.setIcon(icon);
|
|
32
|
-
|
|
33
|
-
this.init();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public init(): void {
|
|
37
|
-
super.init();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
setIcon(icon: string): void {
|
|
41
|
-
this.icon = icon;
|
|
42
|
-
this.body.innerHTML = icon;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
setVariant(variant: IconVariants = "Filled"): void {
|
|
46
|
-
this.variant = variant;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setColor(color: Colors = "primary"): void {
|
|
50
|
-
this.color = color;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
getVariant(): IconVariants {
|
|
54
|
-
return this.variant;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
getColor(): Colors {
|
|
58
|
-
return this.color;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
getIcon(): string {
|
|
62
|
-
return this.icon;
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/ui/accordion.ui.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import "./styles/accordion.css";
|
|
2
|
-
import { IconButton } from "./IconButton.ui";
|
|
3
|
-
import { Label } from "./label.ui";
|
|
4
|
-
import { Widget, WidgetTypes } from "./widget.ui";
|
|
5
|
-
|
|
6
|
-
const ACCORDION_HEADER_HEIGHT = 40;
|
|
7
|
-
|
|
8
|
-
type AccordionItem = {
|
|
9
|
-
header: Widget;
|
|
10
|
-
content: Widget;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class Accordion extends Widget {
|
|
14
|
-
items: Map<string, AccordionItem>;
|
|
15
|
-
selectedItemId: string | null;
|
|
16
|
-
constructor(id: string, parent: Widget | null = null) {
|
|
17
|
-
super(id, "div", parent);
|
|
18
|
-
|
|
19
|
-
this.items = new Map<string, AccordionItem>();
|
|
20
|
-
|
|
21
|
-
this.selectedItemId = null;
|
|
22
|
-
|
|
23
|
-
this.addClass("WUIAccordion");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public selectItem(id: string): void {
|
|
27
|
-
const selected = this.items.get(id);
|
|
28
|
-
|
|
29
|
-
if (this.selectedItemId !== null) {
|
|
30
|
-
//deseleccionamos
|
|
31
|
-
const previous = this.items.get(this.selectedItemId);
|
|
32
|
-
|
|
33
|
-
if (previous) {
|
|
34
|
-
previous.content.setFixedSize(0);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (selected) {
|
|
39
|
-
this.selectedItemId = id;
|
|
40
|
-
selected.content.setFixedSize(null);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.render();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public addItem(title: string, icon: string, content: Widget): void {
|
|
47
|
-
const header =
|
|
48
|
-
icon !== ""
|
|
49
|
-
? new IconButton(content.id + ".header", icon, null)
|
|
50
|
-
: new Label(content.id + ".header", "span", null);
|
|
51
|
-
|
|
52
|
-
header.setType(WidgetTypes.FILL);
|
|
53
|
-
header.setFixedSize(ACCORDION_HEADER_HEIGHT);
|
|
54
|
-
header.setText(title);
|
|
55
|
-
|
|
56
|
-
header.subscribe({
|
|
57
|
-
event: "click",
|
|
58
|
-
then: (_e, _w) => {
|
|
59
|
-
this.selectItem(content.id);
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
content.setType(WidgetTypes.FILL);
|
|
64
|
-
content.setFixedSize(0);
|
|
65
|
-
|
|
66
|
-
this.items.set(content.id, { header, content });
|
|
67
|
-
|
|
68
|
-
this.addChild(header);
|
|
69
|
-
this.addChild(content);
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/ui/buttonColor.ui.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import "./styles/buttoncolor.css";
|
|
2
|
-
import { Button } from "./button.ui";
|
|
3
|
-
import { Widget } from "./widget.ui";
|
|
4
|
-
|
|
5
|
-
export class ButtonColor extends Button {
|
|
6
|
-
inputColor: Widget;
|
|
7
|
-
constructor(id: string, parent: Widget | null = null) {
|
|
8
|
-
super(id, parent);
|
|
9
|
-
|
|
10
|
-
this.inputColor = new Widget(id + ".inputColor", "input", this);
|
|
11
|
-
this.inputColor.getBody().setAttribute("type", "color");
|
|
12
|
-
this.inputColor.addClass("WUIButtonColorInput");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public setValue(value: string): void {
|
|
16
|
-
this.inputColor.getBody().setAttribute("value", value);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public getValue(): string {
|
|
20
|
-
const value = this.inputColor.getBody().getAttribute("value");
|
|
21
|
-
|
|
22
|
-
return value ? value : "";
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/ui/buttonmenu.ui.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Button } from "./button.ui";
|
|
2
|
-
import { Menu } from "./menu.ui";
|
|
3
|
-
import { SelectItem } from "./select.ui";
|
|
4
|
-
|
|
5
|
-
export class ButtonMenu extends Button {
|
|
6
|
-
menu: Menu;
|
|
7
|
-
items: Array<SelectItem>;
|
|
8
|
-
selectedItem: SelectItem | null;
|
|
9
|
-
|
|
10
|
-
public constructor(id: string) {
|
|
11
|
-
super(id);
|
|
12
|
-
|
|
13
|
-
this.menu = new Menu(this.id + ".menu", this.id, null);
|
|
14
|
-
|
|
15
|
-
this.items = new Array<SelectItem>();
|
|
16
|
-
this.selectedItem = null;
|
|
17
|
-
|
|
18
|
-
this.subscribe({
|
|
19
|
-
event: "click",
|
|
20
|
-
then: () => {
|
|
21
|
-
this.menu.clearOptions();
|
|
22
|
-
this.items.forEach((item) => {
|
|
23
|
-
this.menu.addOption(item.id, item.icon, item.label);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
this.menu.wakeUp();
|
|
27
|
-
|
|
28
|
-
if (this.getW() > this.menu.getW()) {
|
|
29
|
-
this.menu.setW(this.getBody().clientWidth);
|
|
30
|
-
console.log("cambiando ancho...");
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
/*this.menu.subscribe({
|
|
36
|
-
event: "option-clicked",
|
|
37
|
-
then: (_e, clickedOption) => {
|
|
38
|
-
const option = clickedOption as IconButton;
|
|
39
|
-
|
|
40
|
-
const fintOption = this.items.find((item) => item.id === option.id);
|
|
41
|
-
|
|
42
|
-
if (fintOption) {
|
|
43
|
-
this.selectedItem = fintOption;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const selectedText = this.selectedItem?.label;
|
|
47
|
-
if (selectedText) {
|
|
48
|
-
this.setText(selectedText);
|
|
49
|
-
} else {
|
|
50
|
-
this.setText("");
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
});*/
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public addItem(id: string, label: string, icon: string): void {
|
|
57
|
-
this.items.push(new SelectItem(id, label, icon));
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/ui/datagrid.ui.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import "./styles/datagrid.css";
|
|
2
|
-
import { Label } from "./label.ui";
|
|
3
|
-
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
4
|
-
import { Scroll } from "./scroll.ui";
|
|
5
|
-
|
|
6
|
-
const DATA_GRID_HEADER_HEIGHT = 30;
|
|
7
|
-
const DATA_GRID_FOOTER_HEIGHT = 40;
|
|
8
|
-
const DATA_GRID_ROW_HEIGHT = 20;
|
|
9
|
-
const DATA_GRID_MIN_COLUMN_WIDTH = 24;
|
|
10
|
-
|
|
11
|
-
type DataGridColumn = {
|
|
12
|
-
header: string;
|
|
13
|
-
width: number | null;
|
|
14
|
-
handler: (args: any) => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export class DataGrid extends Widget {
|
|
18
|
-
headerContainer: Widget;
|
|
19
|
-
dataContainer: Widget;
|
|
20
|
-
footerContainer: Widget;
|
|
21
|
-
data: Array<any>;
|
|
22
|
-
verticalScrollbar: Scroll;
|
|
23
|
-
horizontalScrollbar: Scroll;
|
|
24
|
-
|
|
25
|
-
rowHeight: number;
|
|
26
|
-
|
|
27
|
-
columns: Array<DataGridColumn>;
|
|
28
|
-
|
|
29
|
-
constructor(id: string, parent: Widget | null = null) {
|
|
30
|
-
super(id, "div", parent);
|
|
31
|
-
|
|
32
|
-
this.rowHeight = DATA_GRID_ROW_HEIGHT;
|
|
33
|
-
|
|
34
|
-
this.headerContainer = new Widget(id + ".header", "div");
|
|
35
|
-
this.headerContainer.setType(WidgetTypes.FILL);
|
|
36
|
-
this.headerContainer.setFixedSize(DATA_GRID_HEADER_HEIGHT);
|
|
37
|
-
this.headerContainer.addClass("WUIDataGrid-Header");
|
|
38
|
-
|
|
39
|
-
this.dataContainer = new Widget(id + ".data", "div");
|
|
40
|
-
this.dataContainer.setType(WidgetTypes.FILL);
|
|
41
|
-
|
|
42
|
-
this.footerContainer = new Widget(id + ".footer", "div");
|
|
43
|
-
this.footerContainer.setType(WidgetTypes.FILL);
|
|
44
|
-
this.footerContainer.setFixedSize(DATA_GRID_FOOTER_HEIGHT);
|
|
45
|
-
|
|
46
|
-
this.setType(WidgetTypes.FILL);
|
|
47
|
-
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
48
|
-
|
|
49
|
-
this.addChild(this.headerContainer);
|
|
50
|
-
this.addChild(this.dataContainer);
|
|
51
|
-
this.addChild(this.footerContainer);
|
|
52
|
-
|
|
53
|
-
this.verticalScrollbar = new Scroll(id + ".VerticalScrollbar", this.dataContainer);
|
|
54
|
-
this.horizontalScrollbar = new Scroll(
|
|
55
|
-
id + ".HorizontalScrollbar",
|
|
56
|
-
this.dataContainer,
|
|
57
|
-
"horizontal"
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
this.columns = new Array<DataGridColumn>();
|
|
61
|
-
|
|
62
|
-
this.data = new Array<any>();
|
|
63
|
-
|
|
64
|
-
this.addClass("WUIDataGrid");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public hideFooter(): void {
|
|
68
|
-
this.footerContainer.setFixedSize(0);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public showFooter(): void {
|
|
72
|
-
this.footerContainer.setFixedSize(DATA_GRID_FOOTER_HEIGHT);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private getFreeWidth(): number {
|
|
76
|
-
let freeW = 0;
|
|
77
|
-
for (let i = 0; i < this.columns.length; i++) {
|
|
78
|
-
let width = this.columns[i].width;
|
|
79
|
-
if (width) {
|
|
80
|
-
freeW += width;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
freeW = this.dataContainer.getW() - freeW;
|
|
85
|
-
|
|
86
|
-
if (freeW < DATA_GRID_MIN_COLUMN_WIDTH) {
|
|
87
|
-
freeW = DATA_GRID_MIN_COLUMN_WIDTH;
|
|
88
|
-
}
|
|
89
|
-
return freeW;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private getAllColumnsWidth(): number {
|
|
93
|
-
let returnValue = 0;
|
|
94
|
-
for (let i = 0; i < this.columns.length; i++) {
|
|
95
|
-
let width = this.columns[i].width;
|
|
96
|
-
if (width) {
|
|
97
|
-
returnValue += width;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return returnValue;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
public init(): void {
|
|
104
|
-
super.init();
|
|
105
|
-
|
|
106
|
-
this.createHeaders();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private createHeaders(): void {
|
|
110
|
-
if (!this.columns) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < this.columns.length; i++) {
|
|
115
|
-
const btn = new Label(this.id + "header." + i, "span");
|
|
116
|
-
btn.addClass("WUIDataGrid-HeaderLabel");
|
|
117
|
-
this.headerContainer.addChild(btn);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.buildRows();
|
|
121
|
-
this.renderHeaders();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private renderHeaders(): void {
|
|
125
|
-
if (!this.columns) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let startX = 0;
|
|
130
|
-
for (let i = 0; i < this.columns.length; i++) {
|
|
131
|
-
const column = this.columns[i];
|
|
132
|
-
const btn = window.w.get(this.id + "header." + i) as Label;
|
|
133
|
-
const width = column.width ? column.width : this.getFreeWidth();
|
|
134
|
-
btn.setType(WidgetTypes.CUSTOM);
|
|
135
|
-
btn.setX(startX);
|
|
136
|
-
btn.setY(0);
|
|
137
|
-
btn.setW(width);
|
|
138
|
-
btn.setH(DATA_GRID_HEADER_HEIGHT);
|
|
139
|
-
btn.getBody().style.lineHeight = DATA_GRID_HEADER_HEIGHT + "px";
|
|
140
|
-
btn.setText(column.header);
|
|
141
|
-
this.headerContainer.addChild(btn);
|
|
142
|
-
startX += width;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
private buildRows(): void {
|
|
147
|
-
let rowY = 0;
|
|
148
|
-
|
|
149
|
-
for (let i = 0; i < this.data.length; i++) {
|
|
150
|
-
const row = new Widget(this.id + ".row." + i, "div");
|
|
151
|
-
|
|
152
|
-
row.setType(WidgetTypes.CUSTOM);
|
|
153
|
-
row.getBody().style.position = "absolute";
|
|
154
|
-
row.getBody().style.overflow = "hidden";
|
|
155
|
-
row.addClass("WUIDataGrid-Row");
|
|
156
|
-
|
|
157
|
-
this.dataContainer.addChild(row);
|
|
158
|
-
|
|
159
|
-
for (let j = 0; j < this.columns.length; j++) {
|
|
160
|
-
const column = this.columns[j];
|
|
161
|
-
const fieldId = this.id + ".row." + i + ".column." + j;
|
|
162
|
-
column.handler({
|
|
163
|
-
data: this.data[i],
|
|
164
|
-
index: i,
|
|
165
|
-
fieldId: fieldId,
|
|
166
|
-
row: row,
|
|
167
|
-
});
|
|
168
|
-
const columnWidget = window.w.get(fieldId) as Widget;
|
|
169
|
-
columnWidget.getBody().style.position = "absolute";
|
|
170
|
-
}
|
|
171
|
-
rowY += this.rowHeight;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
private renderRows(): void {
|
|
176
|
-
let rowY = 0;
|
|
177
|
-
|
|
178
|
-
for (let i = 0; i < this.data.length; i++) {
|
|
179
|
-
const row = window.w.get(this.id + ".row." + i) as Widget;
|
|
180
|
-
|
|
181
|
-
row.setX(0);
|
|
182
|
-
row.setY(rowY);
|
|
183
|
-
row.setW(this.getAllColumnsWidth());
|
|
184
|
-
row.setH(this.rowHeight);
|
|
185
|
-
|
|
186
|
-
let widgetX = 0;
|
|
187
|
-
for (let j = 0; j < this.columns.length; j++) {
|
|
188
|
-
const column = this.columns[j];
|
|
189
|
-
const fieldId = this.id + ".row." + i + ".column." + j;
|
|
190
|
-
const columnWidget = window.w.get(fieldId) as Widget;
|
|
191
|
-
columnWidget.setY(0);
|
|
192
|
-
columnWidget.setX(widgetX);
|
|
193
|
-
columnWidget.setH(this.rowHeight);
|
|
194
|
-
if (column.width) {
|
|
195
|
-
columnWidget.setW(column.width);
|
|
196
|
-
} else {
|
|
197
|
-
columnWidget.setW(this.getFreeWidth());
|
|
198
|
-
}
|
|
199
|
-
widgetX += column.width ? column.width : columnWidget.getW();
|
|
200
|
-
}
|
|
201
|
-
rowY += this.rowHeight;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
public render(): void {
|
|
206
|
-
super.render();
|
|
207
|
-
this.renderHeaders();
|
|
208
|
-
this.renderRows();
|
|
209
|
-
this.verticalScrollbar.render();
|
|
210
|
-
this.horizontalScrollbar.render();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public setRowHeight(rowHeight: number): void {
|
|
214
|
-
this.rowHeight = rowHeight;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
public addColumn(header: string, width: number | null, handler: (args: any) => void) {
|
|
218
|
-
this.columns.push({ header, width, handler });
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
public getHeader(index: number): Label {
|
|
222
|
-
return window.w.get(this.id + "header." + index) as Label;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
public setData(data: Array<any>): void {
|
|
226
|
-
this.data = data;
|
|
227
|
-
|
|
228
|
-
this.buildRows();
|
|
229
|
-
this.renderRows();
|
|
230
|
-
}
|
|
231
|
-
}
|