cedro 0.1.2 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cedro",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@types/node": "^20.4.4",
@@ -50,6 +50,7 @@ class WApplication implements IApplication {
50
50
 
51
51
  window.addEventListener("load", () => {
52
52
  this.screen.updateSize();
53
+ this.getRoot().resize();
53
54
  });
54
55
 
55
56
  this.alertDialog = new Dialog("Dialog.alert", null);
@@ -58,11 +59,7 @@ class WApplication implements IApplication {
58
59
  this.theme.load();
59
60
  }
60
61
 
61
- alert(
62
- msg: string,
63
- onOk: () => void = () => {},
64
- onCancell: () => void = () => {}
65
- ): void {
62
+ alert(msg: string, onOk: () => void = () => {}, onCancell: () => void = () => {}): void {
66
63
  const mesageLabel = new Label("alert.label", "span");
67
64
 
68
65
  mesageLabel.setType(WidgetTypes.FILL);
@@ -80,11 +77,7 @@ class WApplication implements IApplication {
80
77
  this.alertDialog.show();
81
78
  }
82
79
 
83
- confirm(
84
- msg: string,
85
- onOk: () => void = () => {},
86
- onCancell: () => void = () => {}
87
- ): void {
80
+ confirm(msg: string, onOk: () => void = () => {}, onCancell: () => void = () => {}): void {
88
81
  const mesageLabel = new Label("alert.label", "span");
89
82
 
90
83
  mesageLabel.setType(WidgetTypes.FILL);
@@ -123,12 +116,7 @@ class WApplication implements IApplication {
123
116
  this.root.render();
124
117
  }
125
118
 
126
- addMediaQuery(
127
- query: string,
128
- minWidth: number,
129
- maxWidth: number,
130
- cb: (app: IApplication) => void
131
- ): void {
119
+ addMediaQuery(query: string, minWidth: number, maxWidth: number, cb: (app: IApplication) => void): void {
132
120
  this.mediaQueries.set(query, { minWidth, maxWidth, cb });
133
121
  }
134
122
 
@@ -145,10 +133,7 @@ class WApplication implements IApplication {
145
133
 
146
134
  for (let query of app.mediaQueries.entries()) {
147
135
  const { minWidth, maxWidth, cb } = query[1];
148
- if (
149
- minWidth <= app.screen.dimensions.x &&
150
- maxWidth > app.screen.dimensions.x
151
- ) {
136
+ if (minWidth <= app.screen.dimensions.x && maxWidth > app.screen.dimensions.x) {
152
137
  cb(this as IApplication);
153
138
  //break; quite el break para dar soporte a mas de un media quiery del mismo tipo.
154
139
  }
@@ -1,5 +1,5 @@
1
1
  import "./styles/button.css";
2
- import { Widget, WidgetTypes } from "./widget.ui";
2
+ import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
3
3
  import { Button } from "./button.ui";
4
4
  import { Icon } from "./Icon.ui";
5
5
  import { Label } from "./label.ui";
@@ -8,19 +8,13 @@ export class IconButton extends Button {
8
8
  icon: Icon;
9
9
  label: Label;
10
10
 
11
- constructor(
12
- id: string,
13
- icon: string = "dark_mode",
14
- parent: Widget | null = null
15
- ) {
11
+ constructor(id: string, icon: string = "dark_mode", parent: Widget | null = null) {
16
12
  super(id, parent);
17
13
 
14
+ this.setAlign(WidgetAlignTypes.HORIZONTAL);
18
15
  this.icon = new Icon(id + ".icon", icon, undefined, this);
19
16
  this.label = new Label(id + ".label", undefined, this);
20
17
 
21
- this.icon.setType(WidgetTypes.FREE);
22
- this.label.setType(WidgetTypes.FREE);
23
-
24
18
  this.init();
25
19
  }
26
20
 
@@ -28,35 +22,49 @@ export class IconButton extends Button {
28
22
  super.init();
29
23
  }
30
24
 
25
+ public onlyIcon(): boolean {
26
+ if (this.label.getText().length > 0) return false;
27
+ return true;
28
+ }
29
+
31
30
  public render(): void {
32
31
  super.render();
33
32
 
34
- this.label.getBody().style.position = "absolute";
35
- this.icon.getBody().style.position = "absolute";
33
+ const iconWidth = 24;
34
+ const padding = 5;
36
35
 
37
- const labelHeight = this.label.getBody().clientHeight;
38
- const labelWidth = this.label.getBody().clientWidth;
36
+ if (this.onlyIcon()) {
37
+ this.icon.getBody().style.position = "absolute";
39
38
 
40
- //const iconHeight = this.icon.getBody().clientHeight;
41
- const iconWidth = 24;
39
+ const startX = this.getBody().clientWidth / 2 - iconWidth / 2;
40
+ const startY = this.getH() / 2 - iconWidth / 2;
42
41
 
43
- const startX =
44
- this.getBody().clientWidth / 2 - (iconWidth + labelWidth) / 2;
45
- const startY = this.getH() / 2 - 24 / 2;
46
- const startLabelY = this.getH() / 2 - labelHeight / 2;
42
+ this.icon.setX(startX);
43
+ this.icon.setY(startY);
44
+ } else {
45
+ this.label.getBody().style.position = "absolute";
46
+ this.icon.getBody().style.position = "absolute";
47
47
 
48
- if (startX < 0 || startY < 0) {
49
- setTimeout(() => {
50
- this.render();
51
- }, 500);
52
- return;
53
- }
48
+ const labelHeight = this.label.getBody().clientHeight;
49
+
50
+ const startX = padding; //this.getBody().clientWidth / 2 - (iconWidth + labelWidth) / 2;
51
+ const startLabelX = startX + iconWidth + padding;
52
+ const startY = this.getH() / 2 - iconWidth / 2;
53
+ const startLabelY = this.getH() / 2 - labelHeight / 2;
54
54
 
55
- this.icon.setX(startX);
56
- this.label.setX(startX + iconWidth + 5);
55
+ if (startX < 0 || startY < 0) {
56
+ setTimeout(() => {
57
+ this.render();
58
+ }, 500);
59
+ return;
60
+ }
57
61
 
58
- this.icon.setY(startY);
59
- this.label.setY(startLabelY);
62
+ this.icon.setX(startX);
63
+ this.label.setX(startLabelX + padding);
64
+
65
+ this.icon.setY(startY);
66
+ this.label.setY(startLabelY);
67
+ }
60
68
  }
61
69
 
62
70
  public setText(text: string): void {
package/src/ui/index.ts CHANGED
@@ -1,24 +1,13 @@
1
- import { Button } from "./button.ui"
2
- import { Widget } from "./widget.ui"
3
- import { Dialog } from "./dialog"
4
- import { Icon } from "./Icon.ui"
5
- import { IconButton } from "./IconButton.ui"
6
- import { Label } from "./label.ui"
7
- import { Menu } from "./menu.ui"
8
- import { Select } from "./select.ui"
9
- import { Textbox } from "./textbox.ui"
10
- import {createWidget} from "./widget.builder.ui"
1
+ import { Button } from "./button.ui";
2
+ import { Widget } from "./widget.ui";
3
+ import { Dialog } from "./dialog";
4
+ import { Icon } from "./Icon.ui";
5
+ import { IconButton } from "./IconButton.ui";
6
+ import { Label } from "./label.ui";
7
+ import { Menu } from "./menu.ui";
8
+ import { Select } from "./select.ui";
9
+ import { Textbox } from "./textbox.ui";
10
+ import { Toolbar } from "./toolbar.ui";
11
+ import { createWidget } from "./widget.builder.ui";
11
12
 
12
-
13
- export{
14
- Button,
15
- Widget,
16
- Dialog,
17
- Icon,
18
- IconButton,
19
- Label,
20
- Menu,
21
- Select,
22
- Textbox,
23
- createWidget,
24
- }
13
+ export { Button, Widget, Dialog, Icon, IconButton, Label, Menu, Select, Textbox, Toolbar, createWidget };
package/src/ui/menu.ui.ts CHANGED
@@ -10,11 +10,7 @@ export class Menu extends Widget {
10
10
  triggeredBy: IWidget | null;
11
11
  triggeredBySearchCode: any;
12
12
  withCalculation: boolean;
13
- constructor(
14
- id: string,
15
- trigeredById: string | null,
16
- parent: IWidget | null = null
17
- ) {
13
+ constructor(id: string, trigeredById: string | null, parent: IWidget | null = null) {
18
14
  super(id, "div", parent);
19
15
 
20
16
  this.background = new Widget(this.id + ".background", "div", null);
@@ -39,6 +35,7 @@ export class Menu extends Widget {
39
35
  clearInterval(this.triggeredBySearchCode);
40
36
  return;
41
37
  }
38
+
42
39
  if (window.w.get(this.triggeredById)) {
43
40
  this.triggeredBy = window.w.get(this.triggeredById) as IWidget;
44
41
 
@@ -61,6 +58,7 @@ export class Menu extends Widget {
61
58
  }
62
59
 
63
60
  public close(): void {
61
+ this.deleteClass("WUIMenuTransparent");
64
62
  this.deleteClass("WUIMenuVisible");
65
63
  this.addClass("WUIMenuHidden");
66
64
  this.background.setVisible(false);
@@ -96,6 +94,7 @@ export class Menu extends Widget {
96
94
  for (const [, dataOption] of this.options) {
97
95
  const option = dataOption as IconButton;
98
96
  option.addClass("WUIMenuOptions100w");
97
+ option.render();
99
98
  }
100
99
  this.deleteClass("WUIMenuTransparent");
101
100
  this.addClass("WUIMenuHidden");
@@ -37,9 +37,7 @@ export class Select extends Textbox {
37
37
 
38
38
  this.menu.wakeUp();
39
39
 
40
- if (
41
- this.getBody().clientWidth > this.menu.getBody().clientWidth
42
- ) {
40
+ if (this.getBody().clientWidth > this.menu.getBody().clientWidth) {
43
41
  this.menu.setW(this.getBody().clientWidth);
44
42
  }
45
43
  },
@@ -50,9 +48,7 @@ export class Select extends Textbox {
50
48
  then: (_e, clickedOption) => {
51
49
  const option = clickedOption as IconButton;
52
50
 
53
- const fintOption = this.items.find(
54
- (item) => item.id === option.id
55
- );
51
+ const fintOption = this.items.find((item) => item.id === option.id);
56
52
 
57
53
  if (fintOption) {
58
54
  this.selectedItem = fintOption;
@@ -14,7 +14,7 @@
14
14
  .WUIDialogHide {
15
15
  background-color: transparent;
16
16
  box-shadow: none;
17
- display: none;
17
+ display: none !important;
18
18
  }
19
19
 
20
20
  .WUITitlebar {
@@ -14,8 +14,8 @@
14
14
  }
15
15
 
16
16
  .WUIMenuHidden {
17
- display: none;
18
17
  opacity: 0;
18
+ display: none !important;
19
19
  }
20
20
 
21
21
  .WUIMenuVisible {
@@ -0,0 +1,203 @@
1
+ import { IWidget } from "src/interfaces/widget.interface";
2
+ import { Widget, WidgetTypes } from "./widget.ui";
3
+ import { IconButton } from "./IconButton.ui";
4
+
5
+ export type ToolbarOrientationTypes = "horizontal" | "vertical";
6
+ const TOOLBAR_SIZE = 40;
7
+ const TOOLBAR_BUTTON_SIZE = 40;
8
+
9
+ export class Toolbar extends Widget {
10
+ orientation: ToolbarOrientationTypes;
11
+ items: Map<string, IWidget>;
12
+ size: number; //Indica el alto o ancho de la toolbar.
13
+
14
+ itemsContainer: Widget;
15
+ btnLeft: IconButton;
16
+ btnRight: IconButton;
17
+
18
+ constructor(id: string, parent: Widget | null = null, orientationType: ToolbarOrientationTypes = "horizontal") {
19
+ super(id, "div", parent);
20
+ this.orientation = orientationType;
21
+ this.size = TOOLBAR_SIZE;
22
+ this.items = new Map<string, IWidget>();
23
+
24
+ this.itemsContainer = new Widget(this.id + ".itemsContainer", "div", this);
25
+ this.itemsContainer.setType(WidgetTypes.CUSTOM);
26
+ this.itemsContainer.getBody().style.position = "absolute";
27
+ this.itemsContainer.getBody().style.overflow = "hidden";
28
+
29
+ this.setType(WidgetTypes.FILL);
30
+ this.getBody().style.overflow = "hidden";
31
+
32
+ this.btnLeft = new IconButton(this.id + ".btnLeft", this.getIconLeft());
33
+ this.btnLeft.setType(WidgetTypes.CUSTOM);
34
+ this.btnLeft.getBody().style.position = "absolute";
35
+ this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
36
+ this.btnLeft.setH(TOOLBAR_SIZE);
37
+ this.addChild(this.btnLeft);
38
+
39
+ this.btnRight = new IconButton(this.id + ".btnRight", this.getIconRight());
40
+ this.btnRight.setType(WidgetTypes.CUSTOM);
41
+ this.btnRight.getBody().style.position = "absolute";
42
+ this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
43
+ this.btnRight.setH(TOOLBAR_SIZE);
44
+ this.addChild(this.btnRight);
45
+
46
+ this.btnLeft.subscribe({
47
+ event: "click",
48
+ then: () => {
49
+ if (this.orientation === "horizontal") {
50
+ this.itemsContainer.getBody().scrollLeft -= TOOLBAR_SIZE;
51
+ } else {
52
+ this.itemsContainer.getBody().scrollTop -= TOOLBAR_SIZE;
53
+ }
54
+ },
55
+ });
56
+
57
+ this.btnRight.subscribe({
58
+ event: "click",
59
+ then: () => {
60
+ if (this.orientation === "horizontal") {
61
+ this.itemsContainer.getBody().scrollLeft += TOOLBAR_SIZE;
62
+ } else {
63
+ this.itemsContainer.getBody().scrollTop += TOOLBAR_SIZE;
64
+ }
65
+ },
66
+ });
67
+ }
68
+
69
+ public getIconLeft(): string {
70
+ if (this.orientation === "horizontal") {
71
+ return "arrow_left";
72
+ }
73
+ return "arrow_drop_up";
74
+ }
75
+
76
+ public getIconRight(): string {
77
+ if (this.orientation === "horizontal") {
78
+ return "arrow_right";
79
+ }
80
+ return "arrow_drop_down";
81
+ }
82
+
83
+ /**
84
+ * Set the orientation of the toolbar.
85
+ *
86
+ * @param {ToolbarOrientationTypes} orientationType - the type of orientation to set
87
+ * @return {void}
88
+ */
89
+ public setOrientation(orientationType: ToolbarOrientationTypes, size: number = TOOLBAR_SIZE): void {
90
+ this.orientation = orientationType;
91
+ this.size = size;
92
+ }
93
+
94
+ public setSize(size: number): void {
95
+ this.size = size;
96
+ }
97
+
98
+ /**
99
+ * Adds an item to the collection.
100
+ *
101
+ * @param {string} id - The ID of the item.
102
+ * @param {IWidget} widget - The widget to be added.
103
+ */
104
+ addItem(id: string, widget: IWidget) {
105
+ widget.setParent(this.itemsContainer);
106
+
107
+ widget.setType(WidgetTypes.CUSTOM);
108
+
109
+ if (this.orientation === "vertical") {
110
+ widget.setW(this.size);
111
+ } else {
112
+ widget.setH(this.size);
113
+ }
114
+
115
+ this.items.set(id, widget);
116
+ }
117
+
118
+ public init(): void {
119
+ super.init();
120
+ }
121
+
122
+ public getFullSize(): number {
123
+ //Devuelve el tamaño que tiene la toolbar para mostrar todos los botones.
124
+
125
+ let size = 0;
126
+ for (const item of this.items.values()) {
127
+ if (this.orientation === "horizontal") {
128
+ size += item.getW();
129
+ } else if (this.orientation === "vertical") {
130
+ size += item.getH();
131
+ }
132
+ }
133
+ return size;
134
+ }
135
+
136
+ public render(): void {
137
+ const fullSize = this.getFullSize();
138
+ const availableSize = this.orientation === "horizontal" ? this.getW() : this.getH();
139
+
140
+ if (fullSize > availableSize) {
141
+ this.btnLeft.setVisible(true);
142
+ this.btnRight.setVisible(true);
143
+
144
+ if (this.orientation === "horizontal") {
145
+ this.itemsContainer.setY(0);
146
+ this.itemsContainer.setX(TOOLBAR_BUTTON_SIZE);
147
+ this.itemsContainer.setW(availableSize - TOOLBAR_BUTTON_SIZE * 2);
148
+ this.itemsContainer.setH(TOOLBAR_SIZE);
149
+
150
+ this.btnLeft.setX(0);
151
+ this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
152
+ this.btnLeft.setH(TOOLBAR_SIZE);
153
+ this.btnRight.setX(availableSize - TOOLBAR_BUTTON_SIZE);
154
+ this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
155
+ this.btnRight.setH(TOOLBAR_SIZE);
156
+ } else {
157
+ this.itemsContainer.setY(TOOLBAR_BUTTON_SIZE);
158
+ this.itemsContainer.setX(0);
159
+ this.itemsContainer.setW(TOOLBAR_SIZE);
160
+ this.itemsContainer.setH(availableSize - TOOLBAR_BUTTON_SIZE * 2);
161
+
162
+ this.btnLeft.setY(0);
163
+ this.btnLeft.setW(TOOLBAR_SIZE);
164
+ this.btnLeft.setH(TOOLBAR_BUTTON_SIZE);
165
+ this.btnRight.setY(availableSize - TOOLBAR_BUTTON_SIZE);
166
+ this.btnRight.setW(TOOLBAR_SIZE);
167
+ this.btnRight.setH(TOOLBAR_BUTTON_SIZE);
168
+ }
169
+ } else {
170
+ this.btnLeft.setVisible(false);
171
+ this.btnRight.setVisible(false);
172
+
173
+ if (this.orientation === "horizontal") {
174
+ this.itemsContainer.setY(0);
175
+ this.itemsContainer.setX(0);
176
+ this.itemsContainer.setW(fullSize);
177
+ this.itemsContainer.setH(TOOLBAR_SIZE);
178
+ } else {
179
+ this.itemsContainer.setY(0);
180
+ this.itemsContainer.setX(0);
181
+ this.itemsContainer.setW(TOOLBAR_SIZE);
182
+ this.itemsContainer.setH(fullSize);
183
+ }
184
+ }
185
+
186
+ let currentPosition: number = 0;
187
+
188
+ for (const item of this.items.values()) {
189
+ if (this.orientation === "vertical") {
190
+ item.setY(currentPosition);
191
+ currentPosition += item.getH();
192
+ item.setX(0);
193
+ } else {
194
+ item.setX(currentPosition);
195
+ item.setY(0);
196
+ currentPosition += item.getW();
197
+ }
198
+ item.render();
199
+ }
200
+
201
+ super.render();
202
+ }
203
+ }
@@ -42,11 +42,7 @@ export class Widget implements IWidget {
42
42
  bodyTagName: string;
43
43
  body: HTMLElement;
44
44
 
45
- constructor(
46
- id: string,
47
- bodyTagName: string = "div",
48
- parent: IWidget | null = null
49
- ) {
45
+ constructor(id: string, bodyTagName: string = "div", parent: IWidget | null = null) {
50
46
  this.id = id;
51
47
 
52
48
  this.overflow = false;
@@ -120,12 +116,12 @@ export class Widget implements IWidget {
120
116
  this.init();
121
117
 
122
118
  this.getMaxZIndex();
119
+
120
+ window.w.set(this.id, this);
123
121
  }
124
122
 
125
123
  public subscribe(cb: WUICallback) {
126
- const randomId =
127
- Math.random().toString(36).substring(2, 15) +
128
- Math.random().toString(36).substring(2, 15);
124
+ const randomId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
129
125
 
130
126
  this.subscribers.set(`${randomId}.${cb.event}`, cb);
131
127
  }
@@ -268,10 +264,7 @@ export class Widget implements IWidget {
268
264
  this.body.style.bottom = "";
269
265
  this.body.style.right = "";
270
266
  } else {
271
- if (
272
- this.type === WidgetTypes.CUSTOM ||
273
- this.type === WidgetTypes.FILL
274
- ) {
267
+ if (this.type === WidgetTypes.CUSTOM || this.type === WidgetTypes.FILL) {
275
268
  this.body.style.position = "absolute";
276
269
  this.body.style.overflow = "hidden";
277
270
  }
@@ -461,7 +454,6 @@ export class Widget implements IWidget {
461
454
  var clientLeft = docElem.clientLeft || body.clientLeft || 0;
462
455
  var top = box.top + scrollTop - clientTop;
463
456
  var left = box.left + scrollLeft - clientLeft;
464
-
465
457
  return { x: Math.round(left), y: Math.round(top) };
466
458
  }
467
459
 
@@ -629,10 +621,7 @@ export class Widget implements IWidget {
629
621
 
630
622
  const padding = this.padding;
631
623
 
632
- const size =
633
- this.align === WidgetAlignTypes.HORIZONTAL
634
- ? this.width
635
- : this.height;
624
+ const size = this.align === WidgetAlignTypes.HORIZONTAL ? this.width : this.height;
636
625
 
637
626
  let currentPosition = padding;
638
627
 
@@ -699,29 +688,17 @@ export class Widget implements IWidget {
699
688
  child.setX(currentPosition);
700
689
 
701
690
  if (child.type === WidgetTypes.FILL) {
702
- child.setWH(
703
- elementSize - padding,
704
- this.getH() - padding * 2
705
- );
691
+ child.setWH(elementSize - padding, this.getH() - padding * 2);
706
692
  } else {
707
- child.setWH(
708
- elementSize - padding,
709
- this.getH() - padding * 2
710
- );
693
+ child.setWH(elementSize - padding, this.getH() - padding * 2);
711
694
  }
712
695
  } else if (this.align === WidgetAlignTypes.VERTICAL) {
713
696
  child.setX(padding);
714
697
  child.setY(currentPosition);
715
698
  if (child.type === WidgetTypes.FILL) {
716
- child.setWH(
717
- this.getW() - padding * 2,
718
- elementSize - padding
719
- );
699
+ child.setWH(this.getW() - padding * 2, elementSize - padding);
720
700
  } else {
721
- child.setWH(
722
- this.getW() - padding * 2,
723
- elementSize - padding
724
- );
701
+ child.setWH(this.getW() - padding * 2, elementSize - padding);
725
702
  }
726
703
  }
727
704
  currentPosition += elementSize;
@@ -761,10 +738,7 @@ export class Widget implements IWidget {
761
738
  return content as HTMLElement;
762
739
  }
763
740
 
764
- private getMaxZIndex(
765
- maxZindex: number = 0,
766
- node: ChildNode | null = null
767
- ): number {
741
+ private getMaxZIndex(maxZindex: number = 0, node: ChildNode | null = null): number {
768
742
  const parent = node ? node : document.body;
769
743
 
770
744
  if (parent instanceof HTMLElement) {
package/tsconfig.json CHANGED
@@ -26,5 +26,8 @@
26
26
  "noFallthroughCasesInSwitch": true,
27
27
 
28
28
  "baseUrl": ".",
29
- }
29
+
30
+ },
31
+ "include": ["src"]
32
+
30
33
  }
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/icon.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>cedro</title>
8
- <link rel="stylesheet" href="src/ui/styles/main.css" />
9
- </head>
10
- <body>
11
- <script type="module" src="/src/main.tsx"></script>
12
- </body>
13
- </html>