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.
Files changed (65) hide show
  1. package/README.md +7 -4
  2. package/dist/cedro-logo.png +0 -0
  3. package/dist/fangio.jpg +0 -0
  4. package/package.json +4 -2
  5. package/src/core/application.builder.tsx +121 -60
  6. package/src/core/application.core.tsx +110 -11
  7. package/src/core/themes.core.ts +160 -1
  8. package/src/core/uid.ts +3 -3
  9. package/src/interfaces/application.interface.ts +3 -2
  10. package/src/interfaces/widget.interface.ts +3 -0
  11. package/src/types/select.item.type.ts +11 -0
  12. package/src/ui/Icon.ui.tsx +158 -0
  13. package/src/ui/IconButton.ui.tsx +51 -9
  14. package/src/ui/{textbox.ui.tsx → Textbox.ui.tsx} +23 -15
  15. package/src/ui/accordion.ui.tsx +152 -0
  16. package/src/ui/button.ui.tsx +56 -14
  17. package/src/ui/buttonColor.ui.tsx +87 -0
  18. package/src/ui/buttonmenu.ui.tsx +134 -0
  19. package/src/ui/{buttonstack.ui.ts → buttonstack.ui.tsx} +67 -1
  20. package/src/ui/checkbox.ui.tsx +9 -13
  21. package/src/ui/container.ui.tsx +141 -76
  22. package/src/ui/datagrid.ui.tsx +518 -0
  23. package/src/ui/dialog.tsx +143 -56
  24. package/src/ui/hpanel.ui.tsx +37 -11
  25. package/src/ui/iconButtonMenu.ui.tsx +176 -0
  26. package/src/ui/image.ui.tsx +123 -112
  27. package/src/ui/index.ts +8 -8
  28. package/src/ui/label.ui.tsx +61 -3
  29. package/src/ui/loading.ui.ts +10 -10
  30. package/src/ui/menu.ui.ts +2 -2
  31. package/src/ui/progressbar.ui.tsx +9 -8
  32. package/src/ui/{radiobutton.tsx → radiobutton.ui.tsx} +9 -13
  33. package/src/ui/scroll.ui.ts +13 -12
  34. package/src/ui/select.ui.tsx +143 -0
  35. package/src/ui/styles/button.css +114 -32
  36. package/src/ui/styles/buttoncolor.css +8 -8
  37. package/src/ui/styles/container.css +29 -0
  38. package/src/ui/styles/icon.css +29 -0
  39. package/src/ui/styles/image.css +19 -19
  40. package/src/ui/styles/label.css +63 -0
  41. package/src/ui/styles/loading.css +12 -12
  42. package/src/ui/styles/main.css +5 -0
  43. package/src/ui/styles/progressbar.css +2 -1
  44. package/src/ui/styles/select.css +13 -0
  45. package/src/ui/styles/stackbutton.css +36 -0
  46. package/src/ui/styles/tabs.css +5 -7
  47. package/src/ui/styles/textarea.css +13 -13
  48. package/src/ui/switch.ui.tsx +9 -13
  49. package/src/ui/tabs.ui.tsx +43 -22
  50. package/src/ui/textarea.ui.tsx +48 -0
  51. package/src/ui/toolbar.ui.tsx +17 -12
  52. package/src/ui/valuebar.ui.tsx +11 -13
  53. package/src/ui/vpanel.ui.tsx +19 -13
  54. package/src/ui/widget.builder.ts +243 -159
  55. package/src/ui/widget.collection.ts +24 -2
  56. package/src/ui/widget.ui.ts +79 -19
  57. package/src/ui/Icon.ui.ts +0 -64
  58. package/src/ui/accordion.ui.ts +0 -71
  59. package/src/ui/buttonColor.ui.ts +0 -24
  60. package/src/ui/buttonmenu.ui.ts +0 -59
  61. package/src/ui/datagrid.ui.ts +0 -231
  62. package/src/ui/iconButtonMenu.ui.ts +0 -59
  63. package/src/ui/select.ui.ts +0 -73
  64. package/src/ui/textarea.ui.ts +0 -20
  65. /package/src/ui/{toggle.ui.ts → toggle.ui.tsx} +0 -0
@@ -1,159 +1,243 @@
1
- import { UID } from "../core/uid";
2
- import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
3
- import { createTextbox } from "./textbox.ui";
4
- import { createButton } from "./button.ui";
5
- import { addNewWidget } from "./widget.collection";
6
- import { createLabel } from "./label.ui";
7
- import { OrientationTypes } from "src/types/orientation.type";
8
- import { createContainer } from "./container.ui";
9
- import { createIconButton } from "./IconButton.ui";
10
- import { createImage } from "./image.ui";
11
- import { createCheckbox } from "./checkbox.ui";
12
- import { createRadioButton } from "./radiobutton";
13
- import { createToolbar } from "./toolbar.ui";
14
- import { createProgressBar } from "./progressbar.ui";
15
- import { createValueBar } from "./valuebar.ui";
16
- import { VPanel, createVPanel } from "./vpanel.ui";
17
- import { HPanel, createHPanel } from "./hpanel.ui";
18
- import { Tabs, createTab } from "./tabs.ui";
19
- import { createSwitch } from "./switch.ui";
20
-
21
- export type WidgetEventProps = {
22
- onClick?: () => {} | void;
23
- onResize?: () => {} | void;
24
- onMouseDown?: () => {} | void;
25
- onMouseUp?: () => {} | void;
26
- onMouseMove?: () => {} | void;
27
- onMouseOut?: () => {} | void;
28
- onMouseLeave?: () => {} | void;
29
- onWheel?: () => {} | void;
30
- onDrag?: () => {} | void;
31
- };
32
-
33
- export type WidgetProps = {
34
- id: string;
35
- type?: WidgetTypes | null;
36
- padding?: number | null;
37
- classNames?: string | null;
38
- fixedSize?: number | null;
39
- orientation?: OrientationTypes | null;
40
- } & WidgetEventProps;
41
-
42
- export function createWidget(
43
- content: any,
44
- parent: Widget | null = null,
45
- freedom: boolean = false
46
- ): Widget | null {
47
- if (!content.tagName) {
48
- return null;
49
- }
50
-
51
- let widget: Widget | null = null;
52
- let widgetProps: WidgetProps = {
53
- id: content.id ? content.id : UID(),
54
- type:
55
- content.getAttribute("w-type") === null
56
- ? WidgetTypes.FILL
57
- : parseInt(content.getAttribute("w-type")),
58
- orientation:
59
- content.getAttribute("w-orientation") === null
60
- ? "horizontal"
61
- : content.getAttribute("w-orientation"),
62
- padding:
63
- content.getAttribute("w-padding") === null
64
- ? 0
65
- : parseInt(content.getAttribute("w-padding")),
66
- fixedSize:
67
- content.getAttribute("w-fixed-size") === null
68
- ? null
69
- : parseInt(content.getAttribute("w-fixed-size")),
70
- classNames:
71
- content.getAttribute("w-classes") === null ? null : content.getAttribute("w-classes"),
72
- };
73
-
74
- if (content.getAttribute("w-textbox")) {
75
- widget = createTextbox(widgetProps.id, content, parent);
76
- } else if (content.getAttribute("w-button")) {
77
- widget = createButton(widgetProps.id, content, parent);
78
- } else if (content.getAttribute("w-icon-button")) {
79
- widget = createIconButton(widgetProps.id, content, parent);
80
- } else if (content.getAttribute("w-label")) {
81
- widget = createLabel(widgetProps.id, content, parent);
82
- } else if (content.getAttribute("w-image")) {
83
- widget = createImage(widgetProps.id, content, parent);
84
- } else if (content.getAttribute("w-checkbox")) {
85
- widget = createCheckbox(widgetProps.id, content, parent);
86
- } else if (content.getAttribute("w-radiobutton")) {
87
- widget = createRadioButton(widgetProps.id, content, parent);
88
- } else if (content.getAttribute("w-switch")) {
89
- widget = createSwitch(widgetProps.id, content, parent);
90
- } else if (content.getAttribute("w-toolbar")) {
91
- widget = createToolbar(widgetProps.id, content, parent);
92
- } else if (content.getAttribute("w-progressbar")) {
93
- widget = createProgressBar(widgetProps.id, content, parent);
94
- } else if (content.getAttribute("w-valuebar")) {
95
- widget = createValueBar(widgetProps.id, content, parent);
96
- } else if (content.getAttribute("w-tab")) {
97
- widget = createTab(widgetProps.id, content, parent);
98
- } else if (content.getAttribute("w-vpanel")) {
99
- widget = createVPanel(widgetProps.id, content, parent);
100
- } else if (content.getAttribute("w-hpanel")) {
101
- widget = createHPanel(widgetProps.id, content, parent);
102
- } else if (content.getAttribute("w-container")) {
103
- widget = createContainer(content, parent);
104
- } else {
105
- widget = new Widget(widgetProps.id, content.tagName, parent);
106
-
107
- if (widgetProps.type === WidgetTypes.FREE) {
108
- freedom = true;
109
- }
110
-
111
- content.getAttributeNames().forEach((key: string) => {
112
- if (widget) widget.getBody().setAttribute(key, content.getAttribute(key));
113
- });
114
-
115
- (content as HTMLElement).childNodes.forEach((child) => {
116
- if (child.hasChildNodes() == true) {
117
- createWidget(child, widget, freedom);
118
- } else {
119
- if (widget) widget.getBody().appendChild(child);
120
- }
121
- });
122
- }
123
-
124
- if (widget) {
125
- if (!freedom && widgetProps.type) {
126
- widget.setType(widgetProps.type);
127
- } else {
128
- widget.setType(WidgetTypes.FREE);
129
- }
130
-
131
- if (
132
- widgetProps.orientation &&
133
- !(widget instanceof VPanel) &&
134
- !(widget instanceof HPanel) &&
135
- !(widget instanceof Tabs)
136
- ) {
137
- if (widgetProps.orientation === "vertical") {
138
- widget.setAlign(WidgetAlignTypes.VERTICAL);
139
- } else {
140
- widget.setAlign(WidgetAlignTypes.HORIZONTAL);
141
- }
142
- }
143
- if (widgetProps.padding) widget.setPadding(widgetProps.padding);
144
- if (widgetProps.fixedSize) widget.setFixedSize(widgetProps.fixedSize);
145
-
146
- if (widgetProps.classNames) {
147
- const clases = widgetProps.classNames.split(" ");
148
- for (const clase of clases) {
149
- widget.addClass(clase);
150
- }
151
- }
152
-
153
- addNewWidget(widgetProps.id, widget);
154
-
155
- return widget;
156
- }
157
-
158
- return null;
159
- }
1
+ import { UID } from "../core/uid";
2
+ import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
3
+ import { addNewWidget } from "./widget.collection";
4
+ import { createTextbox } from "./Textbox.ui";
5
+ import { createButton } from "./button.ui";
6
+ import { createLabel } from "./label.ui";
7
+ import { OrientationTypes } from "src/types/orientation.type";
8
+ import { createContainer } from "./container.ui";
9
+ import { createIconButton } from "./IconButton.ui";
10
+ import { createImage } from "./image.ui";
11
+ import { createCheckbox } from "./checkbox.ui";
12
+ import { createRadioButton } from "./radiobutton.ui";
13
+ import { createToolbar } from "./toolbar.ui";
14
+ import { createProgressBar } from "./progressbar.ui";
15
+ import { createValueBar } from "./valuebar.ui";
16
+ import { VPanel, createVPanel } from "./vpanel.ui";
17
+ import { HPanel, createHPanel } from "./hpanel.ui";
18
+ import { Tabs, createTab } from "./tabs.ui";
19
+ import { createSwitch } from "./switch.ui";
20
+ import { Accordion, createAccordion } from "./accordion.ui";
21
+ import { createButtonStack } from "./buttonstack.ui";
22
+ import { createButtonColor } from "./buttonColor.ui";
23
+ import { createButtonMenu } from "./buttonmenu.ui";
24
+ import { createIconButtonMenu } from "./iconButtonMenu.ui";
25
+ import { createIcon } from "./Icon.ui";
26
+ import { createTextarea } from "./textarea.ui";
27
+ import { createSelect } from "./select.ui";
28
+ import { createDialog, Dialog } from "./dialog";
29
+ import { createDataGrid, DataGrid } from "./datagrid.ui";
30
+
31
+ export type WidgetEventProps = {
32
+ onClick?: (args: any) => {} | void;
33
+ onResize?: (args: any) => {} | void;
34
+ onMouseDown?: (args: any) => {} | void;
35
+ onMouseUp?: (args: any) => {} | void;
36
+ onMouseMove?: (args: any) => {} | void;
37
+ onMouseOut?: (args: any) => {} | void;
38
+ onMouseLeave?: (args: any) => {} | void;
39
+ onWheel?: (args: any) => {} | void;
40
+ onDrag?: (args: any) => {} | void;
41
+ onRender?: (args: any) => {} | void;
42
+ };
43
+
44
+ export type WidgetProps = {
45
+ id?: string | null;
46
+ type?: WidgetTypes | null;
47
+ padding?: number | null;
48
+ classNames?: string | null;
49
+ fixedSize?: number | null;
50
+ orientation?: OrientationTypes | null;
51
+ hidden?: boolean | null;
52
+ } & WidgetEventProps;
53
+
54
+ export function createWidget(
55
+ content: any,
56
+ parent: Widget | null = null,
57
+ freedom: boolean = false
58
+ ): Widget | null {
59
+ if (!content.tagName) {
60
+ return null;
61
+ }
62
+
63
+ let widget: Widget | null = null;
64
+ let widgetProps: WidgetProps = {
65
+ id: content.id ? content.id : UID(),
66
+ type:
67
+ content.getAttribute("w-type") === null
68
+ ? WidgetTypes.FILL
69
+ : parseInt(content.getAttribute("w-type")),
70
+ orientation:
71
+ content.getAttribute("w-orientation") === null
72
+ ? "horizontal"
73
+ : content.getAttribute("w-orientation"),
74
+ hidden: content.getAttribute("w-hidden") !== null ? true : false,
75
+ padding:
76
+ content.getAttribute("w-padding") === null
77
+ ? 0
78
+ : parseInt(content.getAttribute("w-padding")),
79
+ fixedSize:
80
+ content.getAttribute("w-fixed-size") === null
81
+ ? null
82
+ : parseInt(content.getAttribute("w-fixed-size")),
83
+ classNames:
84
+ content.getAttribute("w-classes") === null ? null : content.getAttribute("w-classes"),
85
+ };
86
+
87
+ if (!widgetProps.id) {
88
+ widgetProps.id = UID();
89
+ }
90
+
91
+ if (content.getAttribute("w-textbox")) {
92
+ widget = createTextbox(widgetProps.id, content, parent);
93
+ } else if (content.getAttribute("w-textarea")) {
94
+ widget = createTextarea(widgetProps.id, content, parent);
95
+ } else if (content.getAttribute("w-button")) {
96
+ widget = createButton(widgetProps.id, content, parent);
97
+ } else if (content.getAttribute("w-icon-button")) {
98
+ widget = createIconButton(widgetProps.id, content, parent);
99
+ } else if (content.getAttribute("w-button-stack")) {
100
+ widget = createButtonStack(widgetProps.id, content, parent);
101
+ } else if (content.getAttribute("w-button-color")) {
102
+ widget = createButtonColor(widgetProps.id, content, parent);
103
+ } else if (content.getAttribute("w-button-menu")) {
104
+ widget = createButtonMenu(widgetProps.id, content, parent);
105
+ } else if (content.getAttribute("w-icon-button-menu")) {
106
+ widget = createIconButtonMenu(widgetProps.id, content, parent);
107
+ } else if (content.getAttribute("w-label")) {
108
+ widget = createLabel(widgetProps.id, content, parent);
109
+ } else if (content.getAttribute("w-image")) {
110
+ widget = createImage(widgetProps.id, content, parent);
111
+ } else if (content.getAttribute("w-icon")) {
112
+ widget = createIcon(widgetProps.id, content, parent);
113
+ } else if (content.getAttribute("w-checkbox")) {
114
+ widget = createCheckbox(widgetProps.id, content, parent);
115
+ } else if (content.getAttribute("w-radiobutton")) {
116
+ widget = createRadioButton(widgetProps.id, content, parent);
117
+ } else if (content.getAttribute("w-switch")) {
118
+ widget = createSwitch(widgetProps.id, content, parent);
119
+ } else if (content.getAttribute("w-toolbar")) {
120
+ widget = createToolbar(widgetProps.id, content, parent);
121
+ } else if (content.getAttribute("w-progressbar")) {
122
+ widget = createProgressBar(widgetProps.id, content, parent);
123
+ } else if (content.getAttribute("w-valuebar")) {
124
+ widget = createValueBar(widgetProps.id, content, parent);
125
+ } else if (content.getAttribute("w-tab")) {
126
+ widget = createTab(widgetProps.id, content, parent);
127
+ } else if (content.getAttribute("w-accordion")) {
128
+ widget = createAccordion(widgetProps.id, content, parent);
129
+ } else if (content.getAttribute("w-vpanel")) {
130
+ widget = createVPanel(widgetProps.id, content, parent);
131
+ } else if (content.getAttribute("w-hpanel")) {
132
+ widget = createHPanel(widgetProps.id, content, parent);
133
+ } else if (content.getAttribute("w-container")) {
134
+ widget = createContainer(content, parent);
135
+ } else if (content.getAttribute("w-select")) {
136
+ widget = createSelect(widgetProps.id, content, parent);
137
+ } else if (content.getAttribute("w-dialog")) {
138
+ widget = createDialog(widgetProps.id, content, null);
139
+ } else if (content.getAttribute("w-data-grid")) {
140
+ widget = createDataGrid(widgetProps.id, content, parent);
141
+ } else {
142
+ widget = new Widget(widgetProps.id, content.tagName, parent);
143
+
144
+ if (widgetProps.type === WidgetTypes.FREE) {
145
+ freedom = true;
146
+ }
147
+
148
+ content.getAttributeNames().forEach((key: string) => {
149
+ if (widget) widget.getBody().setAttribute(key, content.getAttribute(key));
150
+ });
151
+
152
+ (content as HTMLElement).childNodes.forEach((child) => {
153
+ if (child.hasChildNodes() == true) {
154
+ createWidget(child, widget, freedom);
155
+ } else {
156
+ if (widget) widget.getBody().appendChild(child);
157
+ }
158
+ });
159
+ }
160
+
161
+ if (widget) {
162
+ if (!freedom && widgetProps.type) {
163
+ widget.setType(widgetProps.type);
164
+ } else {
165
+ widget.setType(WidgetTypes.FREE);
166
+ }
167
+
168
+ if (widget instanceof Dialog) {
169
+ widget.setType(WidgetTypes.CUSTOM);
170
+ }
171
+
172
+ if (
173
+ widgetProps.orientation &&
174
+ !(widget instanceof VPanel) &&
175
+ !(widget instanceof HPanel) &&
176
+ !(widget instanceof Dialog) &&
177
+ !(widget instanceof DataGrid) &&
178
+ !(widget instanceof Tabs)
179
+ ) {
180
+ if (widgetProps.orientation === "vertical") {
181
+ widget.setAlign(WidgetAlignTypes.VERTICAL);
182
+ } else {
183
+ widget.setAlign(WidgetAlignTypes.HORIZONTAL);
184
+ }
185
+ }
186
+
187
+ if (widget instanceof Accordion) {
188
+ widget.setAlign(WidgetAlignTypes.VERTICAL);
189
+ }
190
+
191
+ if (widget instanceof DataGrid) {
192
+ widget.setAlign(WidgetAlignTypes.VERTICAL);
193
+ }
194
+
195
+ if (widgetProps.padding) widget.setPadding(widgetProps.padding);
196
+ if (widgetProps.fixedSize) widget.setFixedSize(widgetProps.fixedSize);
197
+
198
+ if (widgetProps.classNames) {
199
+ const clases = widgetProps.classNames.split(" ");
200
+ for (const clase of clases) {
201
+ widget.addClass(clase);
202
+ }
203
+ }
204
+
205
+ if (widgetProps.hidden) {
206
+ widget.setVisible(false);
207
+ }
208
+
209
+ addNewWidget(widgetProps.id, widget);
210
+
211
+ return widget;
212
+ }
213
+
214
+ return null;
215
+ }
216
+
217
+ export function normalizeWidget(widget: any, props: WidgetProps) {
218
+ if (props.fixedSize !== undefined) {
219
+ widget.setAttribute("w-fixed-size", props.fixedSize);
220
+ }
221
+
222
+ if (props.padding !== undefined) {
223
+ widget.setAttribute("w-padding", props.padding);
224
+ }
225
+
226
+ if (props.type !== undefined) {
227
+ widget.setAttribute("w-type", props.type);
228
+ }
229
+
230
+ if (props.hidden !== undefined) {
231
+ widget.setAttribute("w-hidden", props.hidden);
232
+ }
233
+
234
+ if (props.classNames !== undefined) {
235
+ widget.setAttribute("w-classes", props.classNames);
236
+ }
237
+
238
+ if (props.orientation !== undefined) {
239
+ widget.setAttribute("w-orientation", props.orientation);
240
+ }
241
+
242
+ return widget;
243
+ }
@@ -11,6 +11,7 @@ declare global {
11
11
  var w: Map<string, IWidget>;
12
12
  var app: WApplication | undefined;
13
13
  var widgetConnections: Map<string, WUICallback>;
14
+ var widgetCustomConnections: Map<string, WUICallback>;
14
15
  }
15
16
 
16
17
  export const initWidgetCollection = () => {
@@ -26,12 +27,19 @@ export const initWidgetConnections = () => {
26
27
  if (!window.widgetConnections) {
27
28
  window.widgetConnections = new Map<string, WUICallback>();
28
29
  }
30
+
31
+ if (!window.widgetCustomConnections) {
32
+ window.widgetCustomConnections = new Map<string, WUICallback>();
33
+ }
29
34
  };
30
35
 
31
36
  export const addNewWidget = (id: string, widget: IWidget) => {
32
37
  initWidgetCollection();
33
- w.set(id, widget);
34
- run("widget-added-" + id);
38
+ if (!w.get(id)) w.set(id, widget);
39
+ setTimeout(() => {
40
+ run("widget-added-" + id);
41
+ runCustom("widget-custom-added-" + id);
42
+ });
35
43
  };
36
44
 
37
45
  export const connectWidget = (id: string, callback: WUICallback) => {
@@ -39,6 +47,11 @@ export const connectWidget = (id: string, callback: WUICallback) => {
39
47
  widgetConnections.set(id, callback);
40
48
  };
41
49
 
50
+ export const connectCustomWidget = (id: string, callback: WUICallback) => {
51
+ initWidgetConnections();
52
+ widgetCustomConnections.set(id, callback);
53
+ };
54
+
42
55
  export const run = (eventId: string) => {
43
56
  for (const [key, value] of widgetConnections.entries()) {
44
57
  if (key == eventId) {
@@ -47,3 +60,12 @@ export const run = (eventId: string) => {
47
60
  }
48
61
  widgetConnections.delete(eventId);
49
62
  };
63
+
64
+ export const runCustom = (eventId: string) => {
65
+ for (const [key, value] of widgetCustomConnections.entries()) {
66
+ if (key == eventId) {
67
+ value.then(new Event(eventId), null);
68
+ }
69
+ }
70
+ widgetCustomConnections.delete(eventId);
71
+ };