cedro 0.1.35 → 0.1.36

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
@@ -16,7 +16,7 @@
16
16
  "ui-library",
17
17
  "widget-based"
18
18
  ],
19
- "version": "0.1.35",
19
+ "version": "0.1.36",
20
20
  "type": "module",
21
21
  "devDependencies": {
22
22
  "@fontsource/roboto": "^5.0.5",
@@ -10,7 +10,7 @@
10
10
  * Entonces a las rutas le podemos agregar la propiedad de label o breadcumbLabel que
11
11
  * indicaria el texto a mostrar cuando se esta en esa ruta.
12
12
  * Ademas tambien le podemos definir un icono a cada ruta.
13
- *
13
+ *
14
14
  * Luego el widget Breadcumbs puede buscar en las rutas de la aplicacion, cual es la ruta actual
15
15
  * y actualizarse mostrando graficamente donde se encuentra el usuario.
16
16
  * Para esto podriamos agregar algun evento en las rutas o en la aplicacion que se dispare cuando
@@ -22,7 +22,7 @@
22
22
  *
23
23
  * */
24
24
 
25
- import { Toolbar } from "./toolbar.ui";
25
+ import { Toolbar } from "./toolbar.class";
26
26
  import { connectWidgetCallback, getOnlyEventProps, Widget } from "./widget.ui";
27
27
  import { WidgetProps } from "./widget.types";
28
28
  import { normalizeWidget } from "./widget.normalize";
@@ -40,12 +40,13 @@ export class Breadcumbs extends Toolbar {
40
40
  setTimeout(connectEvent, 500);
41
41
  }
42
42
  window.app?.subscribe({
43
- event: "location-change", then: () => {
43
+ event: "location-change",
44
+ then: () => {
44
45
  this.configItems();
45
- }
46
- })
46
+ },
47
+ });
47
48
  this.configItems();
48
- }
49
+ };
49
50
  connectEvent();
50
51
  }
51
52
 
@@ -54,7 +55,6 @@ export class Breadcumbs extends Toolbar {
54
55
  const app = window.app;
55
56
 
56
57
  for (const route of app.routes) {
57
-
58
58
  const parts = route.src.split("/").filter((item) => item != "");
59
59
  const last = parts[parts.length - 1];
60
60
 
@@ -63,7 +63,6 @@ export class Breadcumbs extends Toolbar {
63
63
  if (last == name) {
64
64
  return route;
65
65
  }
66
-
67
66
  }
68
67
 
69
68
  return null;
@@ -87,20 +86,25 @@ export class Breadcumbs extends Toolbar {
87
86
  if (!route) continue;
88
87
  const newWidget = new Button("item." + itemName, this);
89
88
  let widgetText = route.label ? route.label : itemName;
90
- newWidget.setText(widgetText.replaceAll(" ", " "))
89
+ newWidget.setText(widgetText.replaceAll(" ", " "));
91
90
  newWidget.setVariant("text");
92
91
  newWidget.subscribe({
93
- event: "click", then: () => {
92
+ event: "click",
93
+ then: () => {
94
94
  app.goTo(route.src);
95
- }
96
- })
95
+ },
96
+ });
97
97
  this.addItem(newWidget.id, newWidget);
98
98
 
99
99
  if (i == path.length - 1) {
100
100
  //El ultimo no lleva separador
101
101
  break;
102
102
  }
103
- const separator = new IconButton("icon." + itemName, "keyboard_double_arrow_right", this);
103
+ const separator = new IconButton(
104
+ "icon." + itemName,
105
+ "keyboard_double_arrow_right",
106
+ this
107
+ );
104
108
  separator.setVariant("text");
105
109
  separator.setW(50);
106
110
  this.addItem(separator.id, separator);
@@ -111,8 +115,7 @@ export class Breadcumbs extends Toolbar {
111
115
  }
112
116
  }
113
117
 
114
- export type wBreadcumbProps = WidgetProps & {
115
- };
118
+ export type wBreadcumbProps = WidgetProps & {};
116
119
 
117
120
  export const WBreadcumbs = (props: wBreadcumbProps) => {
118
121
  if (!props.id) {
@@ -121,16 +124,14 @@ export const WBreadcumbs = (props: wBreadcumbProps) => {
121
124
 
122
125
  connectWidgetCallback(props.id, getOnlyEventProps(props));
123
126
 
124
- return normalizeWidget(
125
- <div
126
- id={props.id}
127
- w-breadcumbs
128
- ></div>,
129
- props
130
- );
127
+ return normalizeWidget(<div id={props.id} w-breadcumbs></div>, props);
131
128
  };
132
129
 
133
- export function createBreadcumbs(id: string, _content: any, parent: Widget | null = null): Breadcumbs {
130
+ export function createBreadcumbs(
131
+ id: string,
132
+ _content: any,
133
+ parent: Widget | null = null
134
+ ): Breadcumbs {
134
135
  let newBreadcumbs = new Breadcumbs(id, parent);
135
136
 
136
137
  return newBreadcumbs;
@@ -2,7 +2,7 @@ import "./styles/tabs.css";
2
2
 
3
3
  import { OrientationTypes } from "../types/orientation.type";
4
4
  import { Widget } from "./widget.ui";
5
- import { Toolbar } from "./toolbar.ui";
5
+ import { Toolbar } from "./toolbar.class";
6
6
  import { Label } from "./label.ui";
7
7
  import { Icon } from "./Icon.ui";
8
8
  import { Scroll } from "./scroll.ui";
@@ -0,0 +1,242 @@
1
+ import "./styles/toolbar.css";
2
+ import { IWidget } from "../interfaces/widget.interface";
3
+ import { Widget } from "./widget.ui";
4
+ import { IconButton } from "./IconButton.ui";
5
+ import { OrientationTypes } from "../types/orientation.type";
6
+ import { WidgetAlignTypes, WidgetTypes } from "./widget.types";
7
+
8
+ export type ToolbarVariants = "contained" | "outlined";
9
+
10
+ const TOOLBAR_SIZE = 48;
11
+ const TOOLBAR_BUTTON_SIZE = 40;
12
+
13
+ export class Toolbar extends Widget {
14
+ orientation: OrientationTypes;
15
+ variant: ToolbarVariants;
16
+ items: Map<string, IWidget>;
17
+ size: number; //Indica el alto o ancho de la toolbar.
18
+
19
+ itemsContainer: Widget;
20
+ btnLeft: IconButton;
21
+ btnRight: IconButton;
22
+
23
+ constructor(
24
+ id: string,
25
+ parent: Widget | null = null,
26
+ orientationType: OrientationTypes = "horizontal"
27
+ ) {
28
+ super(id, "div", parent);
29
+ this.orientation = orientationType;
30
+ this.size = TOOLBAR_SIZE;
31
+ this.items = new Map<string, IWidget>();
32
+
33
+ this.variant = "outlined";
34
+
35
+ if (this.orientation === "vertical") {
36
+ this.setAlign(WidgetAlignTypes.VERTICAL);
37
+ } else {
38
+ this.setAlign(WidgetAlignTypes.HORIZONTAL);
39
+ }
40
+
41
+ this.setType(WidgetTypes.FILL);
42
+ //this.setFixedSize(TOOLBAR_SIZE);
43
+ this.addClass("WUIToolbar-" + this.variant);
44
+
45
+ this.itemsContainer = new Widget(this.id + ".itemsContainer", "div", this);
46
+ this.itemsContainer.setType(WidgetTypes.CUSTOM);
47
+ this.itemsContainer.getBody().style.position = "absolute";
48
+ this.itemsContainer.getBody().style.overflow = "hidden";
49
+
50
+ this.getBody().style.overflow = "hidden";
51
+
52
+ this.btnLeft = new IconButton(this.id + ".btnLeft", this.getIconLeft());
53
+ this.btnLeft.setType(WidgetTypes.CUSTOM);
54
+ this.btnLeft.getBody().style.position = "absolute";
55
+ this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
56
+ this.btnLeft.setH(TOOLBAR_SIZE);
57
+ this.addChild(this.btnLeft);
58
+
59
+ this.btnRight = new IconButton(this.id + ".btnRight", this.getIconRight());
60
+ this.btnRight.setType(WidgetTypes.CUSTOM);
61
+ this.btnRight.getBody().style.position = "absolute";
62
+ this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
63
+ this.btnRight.setH(TOOLBAR_SIZE);
64
+ this.addChild(this.btnRight);
65
+
66
+ this.btnLeft.subscribe({
67
+ event: "click",
68
+ then: () => {
69
+ if (this.orientation === "horizontal") {
70
+ this.itemsContainer.getBody().scrollLeft -= TOOLBAR_SIZE;
71
+ } else {
72
+ this.itemsContainer.getBody().scrollTop -= TOOLBAR_SIZE;
73
+ }
74
+ },
75
+ });
76
+
77
+ this.btnRight.subscribe({
78
+ event: "click",
79
+ then: () => {
80
+ if (this.orientation === "horizontal") {
81
+ this.itemsContainer.getBody().scrollLeft += TOOLBAR_SIZE;
82
+ } else {
83
+ this.itemsContainer.getBody().scrollTop += TOOLBAR_SIZE;
84
+ }
85
+ },
86
+ });
87
+ }
88
+
89
+ public setVariant(variant: ToolbarVariants): void {
90
+ this.deleteClass("WUIToolbar-" + this.variant);
91
+ this.variant = variant;
92
+ this.addClass("WUIToolbar-" + this.variant);
93
+ }
94
+
95
+ public getIconLeft(): string {
96
+ if (this.orientation === "horizontal") {
97
+ return "arrow_left";
98
+ }
99
+ return "arrow_drop_up";
100
+ }
101
+
102
+ public getIconRight(): string {
103
+ if (this.orientation === "horizontal") {
104
+ return "arrow_right";
105
+ }
106
+ return "arrow_drop_down";
107
+ }
108
+
109
+ /**
110
+ * Set the orientation of the toolbar.
111
+ *
112
+ * @param {ToolbarOrientationTypes} orientationType - the type of orientation to set
113
+ * @return {void}
114
+ */
115
+ public setOrientation(orientationType: OrientationTypes, size: number = TOOLBAR_SIZE): void {
116
+ this.orientation = orientationType;
117
+ this.size = size;
118
+ }
119
+
120
+ public setSize(size: number): void {
121
+ this.size = size;
122
+ }
123
+
124
+ /**
125
+ * Adds an item to the collection.
126
+ *
127
+ * @param {string} id - The ID of the item.
128
+ * @param {IWidget} widget - The widget to be added.
129
+ */
130
+ addItem(id: string, widget: IWidget) {
131
+ widget.setParent(this.itemsContainer);
132
+
133
+ widget.setType(WidgetTypes.CUSTOM);
134
+
135
+ if (this.orientation === "vertical") {
136
+ widget.setW(this.size);
137
+ } else {
138
+ widget.setH(this.size);
139
+ }
140
+
141
+ this.items.set(id, widget);
142
+ }
143
+
144
+ public deleteItem(id: string) {
145
+ const item = this.items.get(id);
146
+
147
+ if (!item) return;
148
+
149
+ item.free();
150
+
151
+ this.items.delete(id);
152
+ }
153
+
154
+ public init(): void {
155
+ super.init();
156
+ }
157
+
158
+ public getFullSize(): number {
159
+ //Devuelve el tamaño que tiene la toolbar para mostrar todos los botones.
160
+
161
+ let size = 0;
162
+ for (const item of this.items.values()) {
163
+ if (this.orientation === "horizontal") {
164
+ size += item.getW();
165
+ } else if (this.orientation === "vertical") {
166
+ size += item.getH();
167
+ }
168
+ }
169
+ return size;
170
+ }
171
+
172
+ public render(): void {
173
+ super.render();
174
+ const fullSize = this.getFullSize();
175
+ const parent = this.getParent();
176
+ const parentH = parent?.getH() || 0;
177
+ const availableSize = this.orientation === "horizontal" ? this.getW() : parentH;
178
+
179
+ if (fullSize > availableSize) {
180
+ this.btnLeft.setVisible(true);
181
+ this.btnRight.setVisible(true);
182
+
183
+ if (this.orientation === "horizontal") {
184
+ this.itemsContainer.setY(0);
185
+ this.itemsContainer.setX(TOOLBAR_BUTTON_SIZE);
186
+ this.itemsContainer.setW(availableSize - TOOLBAR_BUTTON_SIZE * 2);
187
+ this.itemsContainer.setH(TOOLBAR_SIZE);
188
+
189
+ this.btnLeft.setX(0);
190
+ this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
191
+ this.btnLeft.setH(TOOLBAR_SIZE);
192
+ this.btnRight.setX(availableSize - TOOLBAR_BUTTON_SIZE);
193
+ this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
194
+ this.btnRight.setH(TOOLBAR_SIZE);
195
+ } else {
196
+ this.itemsContainer.setY(TOOLBAR_BUTTON_SIZE);
197
+ this.itemsContainer.setX(0);
198
+ this.itemsContainer.setW(TOOLBAR_SIZE);
199
+ this.itemsContainer.setH(availableSize - TOOLBAR_BUTTON_SIZE * 2);
200
+
201
+ this.btnLeft.setY(0);
202
+ this.btnLeft.setW(TOOLBAR_SIZE);
203
+ this.btnLeft.setH(TOOLBAR_BUTTON_SIZE);
204
+ this.btnRight.setY(availableSize - TOOLBAR_BUTTON_SIZE);
205
+ this.btnRight.setW(TOOLBAR_SIZE);
206
+ this.btnRight.setH(TOOLBAR_BUTTON_SIZE);
207
+ }
208
+ } else {
209
+ this.btnLeft.setVisible(false);
210
+ this.btnRight.setVisible(false);
211
+
212
+ if (this.orientation === "horizontal") {
213
+ this.itemsContainer.setY(0);
214
+ this.itemsContainer.setX(0);
215
+ this.itemsContainer.setW(fullSize);
216
+ this.itemsContainer.setH(TOOLBAR_SIZE);
217
+ } else {
218
+ this.itemsContainer.setY(0);
219
+ this.itemsContainer.setX(0);
220
+ this.itemsContainer.setW(TOOLBAR_SIZE);
221
+ this.itemsContainer.setH(fullSize);
222
+ }
223
+ }
224
+
225
+ let currentPosition: number = 0;
226
+
227
+ for (const item of this.items.values()) {
228
+ if (this.orientation === "vertical") {
229
+ item.setY(currentPosition);
230
+ currentPosition += item.getH();
231
+ item.setX(0);
232
+ item.setW(TOOLBAR_BUTTON_SIZE);
233
+ } else {
234
+ item.setX(currentPosition);
235
+ item.setY(0);
236
+ item.setH(TOOLBAR_BUTTON_SIZE);
237
+ currentPosition += item.getW();
238
+ }
239
+ item.render();
240
+ }
241
+ }
242
+ }
@@ -1,248 +1,14 @@
1
1
  import "./styles/toolbar.css";
2
- import { IWidget } from "../interfaces/widget.interface";
3
2
  import { Widget } from "./widget.ui";
4
- import { IconButton } from "./IconButton.ui";
5
3
  import { OrientationTypes } from "../types/orientation.type";
6
4
  import { createWidget } from "./widget.builder";
7
5
  import { UID } from "../core/uid";
8
- import { WidgetAlignTypes, WidgetProps, WidgetTypes } from "./widget.types";
6
+ import { WidgetProps } from "./widget.types";
9
7
  import { normalizeWidget } from "./widget.normalize";
10
8
 
11
- export type ToolbarVariants = "contained" | "outlined";
9
+ import { Toolbar, ToolbarVariants } from "./toolbar.class";
12
10
 
13
- const TOOLBAR_SIZE = 48;
14
- const TOOLBAR_BUTTON_SIZE = 40;
15
-
16
- export class Toolbar extends Widget {
17
- orientation: OrientationTypes;
18
- variant: ToolbarVariants;
19
- items: Map<string, IWidget>;
20
- size: number; //Indica el alto o ancho de la toolbar.
21
-
22
- itemsContainer: Widget;
23
- btnLeft: IconButton;
24
- btnRight: IconButton;
25
-
26
- constructor(
27
- id: string,
28
- parent: Widget | null = null,
29
- orientationType: OrientationTypes = "horizontal"
30
- ) {
31
- super(id, "div", parent);
32
- this.orientation = orientationType;
33
- this.size = TOOLBAR_SIZE;
34
- this.items = new Map<string, IWidget>();
35
-
36
- this.variant = "outlined";
37
-
38
- if (this.orientation === "vertical") {
39
- this.setAlign(WidgetAlignTypes.VERTICAL);
40
- } else {
41
- this.setAlign(WidgetAlignTypes.HORIZONTAL);
42
- }
43
-
44
- this.setType(WidgetTypes.FILL);
45
- //this.setFixedSize(TOOLBAR_SIZE);
46
- this.addClass("WUIToolbar-" + this.variant);
47
-
48
- this.itemsContainer = new Widget(this.id + ".itemsContainer", "div", this);
49
- this.itemsContainer.setType(WidgetTypes.CUSTOM);
50
- this.itemsContainer.getBody().style.position = "absolute";
51
- this.itemsContainer.getBody().style.overflow = "hidden";
52
-
53
- this.getBody().style.overflow = "hidden";
54
-
55
- this.btnLeft = new IconButton(this.id + ".btnLeft", this.getIconLeft());
56
- this.btnLeft.setType(WidgetTypes.CUSTOM);
57
- this.btnLeft.getBody().style.position = "absolute";
58
- this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
59
- this.btnLeft.setH(TOOLBAR_SIZE);
60
- this.addChild(this.btnLeft);
61
-
62
- this.btnRight = new IconButton(this.id + ".btnRight", this.getIconRight());
63
- this.btnRight.setType(WidgetTypes.CUSTOM);
64
- this.btnRight.getBody().style.position = "absolute";
65
- this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
66
- this.btnRight.setH(TOOLBAR_SIZE);
67
- this.addChild(this.btnRight);
68
-
69
- this.btnLeft.subscribe({
70
- event: "click",
71
- then: () => {
72
- if (this.orientation === "horizontal") {
73
- this.itemsContainer.getBody().scrollLeft -= TOOLBAR_SIZE;
74
- } else {
75
- this.itemsContainer.getBody().scrollTop -= TOOLBAR_SIZE;
76
- }
77
- },
78
- });
79
-
80
- this.btnRight.subscribe({
81
- event: "click",
82
- then: () => {
83
- if (this.orientation === "horizontal") {
84
- this.itemsContainer.getBody().scrollLeft += TOOLBAR_SIZE;
85
- } else {
86
- this.itemsContainer.getBody().scrollTop += TOOLBAR_SIZE;
87
- }
88
- },
89
- });
90
- }
91
-
92
- public setVariant(variant: ToolbarVariants): void {
93
- this.deleteClass("WUIToolbar-" + this.variant);
94
- this.variant = variant;
95
- this.addClass("WUIToolbar-" + this.variant);
96
- }
97
-
98
- public getIconLeft(): string {
99
- if (this.orientation === "horizontal") {
100
- return "arrow_left";
101
- }
102
- return "arrow_drop_up";
103
- }
104
-
105
- public getIconRight(): string {
106
- if (this.orientation === "horizontal") {
107
- return "arrow_right";
108
- }
109
- return "arrow_drop_down";
110
- }
111
-
112
- /**
113
- * Set the orientation of the toolbar.
114
- *
115
- * @param {ToolbarOrientationTypes} orientationType - the type of orientation to set
116
- * @return {void}
117
- */
118
- public setOrientation(orientationType: OrientationTypes, size: number = TOOLBAR_SIZE): void {
119
- this.orientation = orientationType;
120
- this.size = size;
121
- }
122
-
123
- public setSize(size: number): void {
124
- this.size = size;
125
- }
126
-
127
- /**
128
- * Adds an item to the collection.
129
- *
130
- * @param {string} id - The ID of the item.
131
- * @param {IWidget} widget - The widget to be added.
132
- */
133
- addItem(id: string, widget: IWidget) {
134
- widget.setParent(this.itemsContainer);
135
-
136
- widget.setType(WidgetTypes.CUSTOM);
137
-
138
- if (this.orientation === "vertical") {
139
- widget.setW(this.size);
140
- } else {
141
- widget.setH(this.size);
142
- }
143
-
144
- this.items.set(id, widget);
145
- }
146
-
147
- public deleteItem(id: string) {
148
- const item = this.items.get(id);
149
-
150
- if (!item) return;
151
-
152
- item.free();
153
-
154
- this.items.delete(id);
155
- }
156
-
157
- public init(): void {
158
- super.init();
159
- }
160
-
161
- public getFullSize(): number {
162
- //Devuelve el tamaño que tiene la toolbar para mostrar todos los botones.
163
-
164
- let size = 0;
165
- for (const item of this.items.values()) {
166
- if (this.orientation === "horizontal") {
167
- size += item.getW();
168
- } else if (this.orientation === "vertical") {
169
- size += item.getH();
170
- }
171
- }
172
- return size;
173
- }
174
-
175
- public render(): void {
176
- super.render();
177
- const fullSize = this.getFullSize();
178
- const parent = this.getParent();
179
- const parentH = parent?.getH() || 0;
180
- const availableSize = this.orientation === "horizontal" ? this.getW() : parentH;
181
-
182
- if (fullSize > availableSize) {
183
- this.btnLeft.setVisible(true);
184
- this.btnRight.setVisible(true);
185
-
186
- if (this.orientation === "horizontal") {
187
- this.itemsContainer.setY(0);
188
- this.itemsContainer.setX(TOOLBAR_BUTTON_SIZE);
189
- this.itemsContainer.setW(availableSize - TOOLBAR_BUTTON_SIZE * 2);
190
- this.itemsContainer.setH(TOOLBAR_SIZE);
191
-
192
- this.btnLeft.setX(0);
193
- this.btnLeft.setW(TOOLBAR_BUTTON_SIZE);
194
- this.btnLeft.setH(TOOLBAR_SIZE);
195
- this.btnRight.setX(availableSize - TOOLBAR_BUTTON_SIZE);
196
- this.btnRight.setW(TOOLBAR_BUTTON_SIZE);
197
- this.btnRight.setH(TOOLBAR_SIZE);
198
- } else {
199
- this.itemsContainer.setY(TOOLBAR_BUTTON_SIZE);
200
- this.itemsContainer.setX(0);
201
- this.itemsContainer.setW(TOOLBAR_SIZE);
202
- this.itemsContainer.setH(availableSize - TOOLBAR_BUTTON_SIZE * 2);
203
-
204
- this.btnLeft.setY(0);
205
- this.btnLeft.setW(TOOLBAR_SIZE);
206
- this.btnLeft.setH(TOOLBAR_BUTTON_SIZE);
207
- this.btnRight.setY(availableSize - TOOLBAR_BUTTON_SIZE);
208
- this.btnRight.setW(TOOLBAR_SIZE);
209
- this.btnRight.setH(TOOLBAR_BUTTON_SIZE);
210
- }
211
- } else {
212
- this.btnLeft.setVisible(false);
213
- this.btnRight.setVisible(false);
214
-
215
- if (this.orientation === "horizontal") {
216
- this.itemsContainer.setY(0);
217
- this.itemsContainer.setX(0);
218
- this.itemsContainer.setW(fullSize);
219
- this.itemsContainer.setH(TOOLBAR_SIZE);
220
- } else {
221
- this.itemsContainer.setY(0);
222
- this.itemsContainer.setX(0);
223
- this.itemsContainer.setW(TOOLBAR_SIZE);
224
- this.itemsContainer.setH(fullSize);
225
- }
226
- }
227
-
228
- let currentPosition: number = 0;
229
-
230
- for (const item of this.items.values()) {
231
- if (this.orientation === "vertical") {
232
- item.setY(currentPosition);
233
- currentPosition += item.getH();
234
- item.setX(0);
235
- item.setW(TOOLBAR_BUTTON_SIZE);
236
- } else {
237
- item.setX(currentPosition);
238
- item.setY(0);
239
- item.setH(TOOLBAR_BUTTON_SIZE);
240
- currentPosition += item.getW();
241
- }
242
- item.render();
243
- }
244
- }
245
- }
11
+ export { Toolbar, type ToolbarVariants };
246
12
 
247
13
  export type ToolbarProps = WidgetProps & {
248
14
  variant?: ToolbarVariants;