cedro 0.1.7 → 0.1.9
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 +1 -1
- package/src/core/application.builder.tsx +60 -0
- package/src/core/{application.core.ts → application.core.tsx} +68 -1
- package/src/index.ts +1 -1
- package/src/interfaces/application.interface.ts +7 -1
- package/src/interfaces/widget.interface.ts +3 -1
- package/src/ui/{IconButton.ui.ts → IconButton.ui.tsx} +79 -2
- package/src/ui/{button.ui.ts → button.ui.tsx} +63 -1
- package/src/ui/checkbox.ui.tsx +47 -0
- package/src/ui/container.ui.tsx +76 -0
- package/src/ui/{hpanel.ui.ts → hpanel.ui.tsx} +37 -0
- package/src/ui/image.ui.tsx +112 -0
- package/src/ui/index.ts +1 -1
- package/src/ui/label.ui.tsx +126 -0
- package/src/ui/progressbar.ui.tsx +134 -0
- package/src/ui/radiobutton.tsx +51 -0
- package/src/ui/styles/hpanel.css +1 -1
- package/src/ui/styles/progressbar.css +1 -1
- package/src/ui/styles/valuebar.css +1 -1
- package/src/ui/styles/vpanel.css +1 -1
- package/src/ui/switch.ui.tsx +46 -0
- package/src/ui/{tabs.ui.ts → tabs.ui.tsx} +86 -1
- package/src/ui/{textbox.ui.ts → textbox.ui.tsx} +54 -1
- package/src/ui/{toolbar.ui.ts → toolbar.ui.tsx} +38 -0
- package/src/ui/{valuebar.ui.ts → valuebar.ui.tsx} +37 -1
- package/src/ui/{vpanel.ui.ts → vpanel.ui.tsx} +37 -0
- package/src/ui/widget.builder.ts +159 -0
- package/src/ui/widget.collection.ts +35 -5
- package/src/ui/widget.ui.ts +107 -15
- package/src/ui/checkbox.ui.ts +0 -8
- package/src/ui/container.ui.ts +0 -33
- package/src/ui/image.ui.ts +0 -49
- package/src/ui/label.ui.ts +0 -57
- package/src/ui/progressbar.ui.ts +0 -74
- package/src/ui/radiobutton.ts +0 -8
- package/src/ui/switch.ui.ts +0 -7
- package/src/ui/widget.builder.ui.tsx +0 -676
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//import { createWidget } from "src/ui/builder/widget.builder";
|
|
2
|
+
import { WidgetAlignTypes } from "../ui";
|
|
3
|
+
import { createWidget } from "../ui/widget.builder";
|
|
4
|
+
import Application, { ApplicationProps } from "./application.core";
|
|
5
|
+
|
|
6
|
+
function getApplicationProps(content: any): ApplicationProps {
|
|
7
|
+
let props: ApplicationProps = {
|
|
8
|
+
title: content.title,
|
|
9
|
+
padding: 0,
|
|
10
|
+
orientation: null,
|
|
11
|
+
children: null,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
if (content.getAttribute("w-title") !== null) {
|
|
15
|
+
props.title = content.getAttribute("w-title");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (content.getAttribute("w-padding") !== null) {
|
|
19
|
+
props.padding = parseInt(content.getAttribute("w-padding"));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (content.getAttribute("w-orientation") !== null) {
|
|
23
|
+
props.orientation = content.getAttribute("w-orientation");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return props;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createApplication(content: any): Application {
|
|
30
|
+
const appProps = getApplicationProps(content);
|
|
31
|
+
const newApp = new Application(appProps.title);
|
|
32
|
+
|
|
33
|
+
if (appProps.padding) {
|
|
34
|
+
newApp.getRoot().setPadding(appProps.padding);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (appProps.orientation) {
|
|
38
|
+
if (appProps.orientation === "horizontal") {
|
|
39
|
+
newApp.getRoot().setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
40
|
+
} else {
|
|
41
|
+
newApp.getRoot().setAlign(WidgetAlignTypes.VERTICAL);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
content.childNodes.forEach((item: HTMLElement) => {
|
|
46
|
+
if (item.getAttribute("w-widget-collection")) {
|
|
47
|
+
item.childNodes.forEach((ietmWidget: any) => {
|
|
48
|
+
const appWidgets = createWidget(ietmWidget);
|
|
49
|
+
|
|
50
|
+
if (appWidgets !== null) {
|
|
51
|
+
newApp.getRoot().addChild(appWidgets);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
} else if (item.getAttribute("w-routes")) {
|
|
55
|
+
console.log("routes:", item);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return newApp;
|
|
60
|
+
}
|
|
@@ -9,17 +9,20 @@ import "material-icons/iconfont/material-icons.css";
|
|
|
9
9
|
import { Widget, WidgetAlignTypes, WidgetTypes } from "../ui/widget.ui";
|
|
10
10
|
import { Screen } from "./screeen.core";
|
|
11
11
|
import { IApplication, IScreenSize } from "../interfaces/application.interface";
|
|
12
|
-
import { IWidget } from "../interfaces/widget.interface";
|
|
12
|
+
import { IWidget, WUICallback, WUIEvent } from "../interfaces/widget.interface";
|
|
13
13
|
import Navigo from "navigo";
|
|
14
14
|
import { Dialog } from "../ui/dialog";
|
|
15
15
|
import { Label } from "../ui/label.ui";
|
|
16
16
|
import { Seo } from "./seo";
|
|
17
17
|
import { DarkTheme, LightTheme, ThemeManager } from "./themes.core";
|
|
18
18
|
import { Loading } from "../ui/loading.ui";
|
|
19
|
+
import { OrientationTypes } from "../types/orientation.type";
|
|
19
20
|
|
|
20
21
|
class WApplication implements IApplication {
|
|
21
22
|
seo: Seo;
|
|
22
23
|
|
|
24
|
+
subscribers: Map<string, WUICallback>;
|
|
25
|
+
|
|
23
26
|
screen: Screen;
|
|
24
27
|
root: Widget;
|
|
25
28
|
router: Navigo;
|
|
@@ -35,7 +38,10 @@ class WApplication implements IApplication {
|
|
|
35
38
|
constructor(title: string) {
|
|
36
39
|
this.seo = new Seo(title);
|
|
37
40
|
|
|
41
|
+
this.subscribers = new Map<string, WUICallback>();
|
|
42
|
+
|
|
38
43
|
this.root = new Widget("root");
|
|
44
|
+
|
|
39
45
|
this.root.setType(WidgetTypes.FILL);
|
|
40
46
|
this.screen = new Screen();
|
|
41
47
|
this.router = new Navigo("/");
|
|
@@ -53,6 +59,7 @@ class WApplication implements IApplication {
|
|
|
53
59
|
window.addEventListener("load", () => {
|
|
54
60
|
this.screen.updateSize();
|
|
55
61
|
this.getRoot().resize();
|
|
62
|
+
this.run("load");
|
|
56
63
|
});
|
|
57
64
|
|
|
58
65
|
this.alertDialog = new Dialog("Dialog.alert", null);
|
|
@@ -63,6 +70,26 @@ class WApplication implements IApplication {
|
|
|
63
70
|
this.theme.load();
|
|
64
71
|
}
|
|
65
72
|
|
|
73
|
+
public run(eventId: WUIEvent): void {
|
|
74
|
+
this.subscribers.forEach((callback) => {
|
|
75
|
+
if (callback.event == eventId) {
|
|
76
|
+
callback.then(new Event(eventId), null);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public subscribe(cb: WUICallback) {
|
|
82
|
+
const randomId =
|
|
83
|
+
Math.random().toString(36).substring(2, 15) +
|
|
84
|
+
Math.random().toString(36).substring(2, 15);
|
|
85
|
+
|
|
86
|
+
this.subscribers.set(`${randomId}.${cb.event}`, cb);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public unsubscribe(event: WUIEvent) {
|
|
90
|
+
this.subscribers.delete(`${event}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
66
93
|
alert(msg: string, onOk: () => void = () => {}, onCancell: () => void = () => {}): void {
|
|
67
94
|
const mesageLabel = new Label("alert.label", "span");
|
|
68
95
|
|
|
@@ -151,6 +178,7 @@ class WApplication implements IApplication {
|
|
|
151
178
|
});
|
|
152
179
|
|
|
153
180
|
this.root.render();
|
|
181
|
+
this.seo.setTitle(this.seo.getTitle());
|
|
154
182
|
}
|
|
155
183
|
|
|
156
184
|
/**
|
|
@@ -182,4 +210,43 @@ class WApplication implements IApplication {
|
|
|
182
210
|
}
|
|
183
211
|
}
|
|
184
212
|
|
|
213
|
+
export type ApplicationProps = {
|
|
214
|
+
title: string;
|
|
215
|
+
padding?: number | null;
|
|
216
|
+
orientation?: OrientationTypes | null;
|
|
217
|
+
children: any;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export const Application = (props: ApplicationProps) => {
|
|
221
|
+
return (
|
|
222
|
+
<div title={props.title} w-padding={props.padding} w-orientation={props.orientation}>
|
|
223
|
+
{props.children}
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
export type WidgetsProps = {
|
|
229
|
+
children: any;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export const Widgets = (props: WidgetsProps) => {
|
|
233
|
+
return <div w-widget-collection>{props.children}</div>;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
export type RoutesProps = {
|
|
237
|
+
children: any;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
export const Routes = (props: RoutesProps) => {
|
|
241
|
+
return <div w-routes>{props.children}</div>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export type RouteProps = {
|
|
245
|
+
src: string;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export const Route = (props: RouteProps) => {
|
|
249
|
+
return <a w-path href={props.src}></a>;
|
|
250
|
+
};
|
|
251
|
+
|
|
185
252
|
export default WApplication;
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Application from "./core/application.core";
|
|
|
2
2
|
import { DOMcreateElement, DOMcreateFragment } from "./core/jsxsupport";
|
|
3
3
|
import { Widget, WidgetTypes, WidgetAlignTypes } from "./ui/widget.ui";
|
|
4
4
|
import { initWidgetCollection } from "./ui/widget.collection";
|
|
5
|
-
import { createWidget } from "./ui/widget.builder
|
|
5
|
+
import { createWidget } from "./ui/widget.builder";
|
|
6
6
|
|
|
7
7
|
initWidgetCollection();
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Navigo from "navigo";
|
|
2
2
|
import { IScreen } from "./screen.interface";
|
|
3
|
-
import { IWidget } from "./widget.interface";
|
|
3
|
+
import { IWidget, WUICallback, WUIEvent } from "./widget.interface";
|
|
4
4
|
import { Dialog } from "../ui/dialog";
|
|
5
5
|
import { Seo } from "../core/seo";
|
|
6
6
|
import { ThemeManager } from "../core/themes.core";
|
|
@@ -26,10 +26,16 @@ export interface IApplication {
|
|
|
26
26
|
confirmDialog: Dialog;
|
|
27
27
|
mediaQueries: Map<string, IScreenSize>;
|
|
28
28
|
|
|
29
|
+
subscribers: Map<string, WUICallback>;
|
|
30
|
+
|
|
29
31
|
theme: ThemeManager;
|
|
30
32
|
|
|
31
33
|
attachWidget(guest: IWidget, host: IWidget): void;
|
|
32
34
|
|
|
35
|
+
subscribe: (cb: WUICallback) => void;
|
|
36
|
+
unsubscribe: (event: WUIEvent) => void;
|
|
37
|
+
run(eventId: WUIEvent): void;
|
|
38
|
+
|
|
33
39
|
addMediaQuery(
|
|
34
40
|
query: string,
|
|
35
41
|
minWidth: number,
|
|
@@ -2,6 +2,8 @@ import { WidgetAlignTypes, WidgetTypes } from "../ui/widget.ui";
|
|
|
2
2
|
import { Vector2D } from "../types/vector2d.type";
|
|
3
3
|
|
|
4
4
|
export type WUIEvent =
|
|
5
|
+
| "widget-load"
|
|
6
|
+
| "load"
|
|
5
7
|
| "click"
|
|
6
8
|
| "resize"
|
|
7
9
|
| "mousedown"
|
|
@@ -15,7 +17,7 @@ export type WUIEvent =
|
|
|
15
17
|
|
|
16
18
|
export type WUICallback = {
|
|
17
19
|
event: WUIEvent;
|
|
18
|
-
then: (event: Event, wuie: IWidget) => void;
|
|
20
|
+
then: (event: Event, wuie: IWidget | null) => void;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export interface IWidget {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import "./styles/button.css";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
Widget,
|
|
4
|
+
WidgetAlignTypes,
|
|
5
|
+
WidgetTypes,
|
|
6
|
+
connectWidgetCallback,
|
|
7
|
+
getOnlyEventProps,
|
|
8
|
+
} from "./widget.ui";
|
|
9
|
+
import { Button, wButtonProps } from "./button.ui";
|
|
4
10
|
import { Icon } from "./Icon.ui";
|
|
5
11
|
import { Label } from "./label.ui";
|
|
6
12
|
|
|
@@ -112,3 +118,74 @@ export class IconButton extends Button {
|
|
|
112
118
|
this.icon.setIcon(icon);
|
|
113
119
|
}
|
|
114
120
|
}
|
|
121
|
+
|
|
122
|
+
export type wIconButtonProps = Omit<wButtonProps, "text"> & {
|
|
123
|
+
icon?: string | null;
|
|
124
|
+
text?: string | null;
|
|
125
|
+
onlyIcon?: boolean | null;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const WIconButton = (props: wIconButtonProps) => {
|
|
129
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<button
|
|
133
|
+
id={props.id}
|
|
134
|
+
w-icon-button
|
|
135
|
+
w-icon={props.icon}
|
|
136
|
+
w-text={props.text}
|
|
137
|
+
w-only-icon={props.onlyIcon}
|
|
138
|
+
w-variant={props.variant}
|
|
139
|
+
w-color={props.color}
|
|
140
|
+
w-width={props.width}
|
|
141
|
+
w-height={props.height}
|
|
142
|
+
w-class={props.classNames}
|
|
143
|
+
w-orientation={props.orientation}
|
|
144
|
+
w-fixed-size={props.fixedSize}
|
|
145
|
+
w-padding={props.padding}
|
|
146
|
+
w-type={props.type}
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export function createIconButton(
|
|
152
|
+
id: string,
|
|
153
|
+
content: any,
|
|
154
|
+
parent: Widget | null = null
|
|
155
|
+
): IconButton {
|
|
156
|
+
const dataIcon = content.getAttribute("w-icon");
|
|
157
|
+
const dataText = content.getAttribute("w-text");
|
|
158
|
+
const dataVariant = content.getAttribute("w-variant");
|
|
159
|
+
const dataColor = content.getAttribute("w-color");
|
|
160
|
+
const dataWidth = content.getAttribute("w-width");
|
|
161
|
+
const dataHeight = content.getAttribute("w-height");
|
|
162
|
+
const dataOnlyIcon = content.getAttribute("w-only-icon");
|
|
163
|
+
|
|
164
|
+
let newIconButton = new IconButton(id, dataIcon, parent);
|
|
165
|
+
|
|
166
|
+
if (dataText) {
|
|
167
|
+
newIconButton.setText(dataText);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (dataVariant) {
|
|
171
|
+
newIconButton.setVariant(dataVariant);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (dataColor) {
|
|
175
|
+
newIconButton.setColor(dataColor);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (dataWidth) {
|
|
179
|
+
newIconButton.setInitialW(dataWidth);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (dataHeight) {
|
|
183
|
+
newIconButton.setInitialH(dataHeight);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (dataOnlyIcon) {
|
|
187
|
+
newIconButton.onlyIcon();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return newIconButton;
|
|
191
|
+
}
|
|
@@ -2,7 +2,8 @@ import "./styles/button.css";
|
|
|
2
2
|
import "./styles/stackbutton.css";
|
|
3
3
|
import "./styles/vstackbutton.css";
|
|
4
4
|
import { Colors } from "./colors.ui";
|
|
5
|
-
import { Widget } from "./widget.ui";
|
|
5
|
+
import { Widget, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
|
|
6
|
+
import { WidgetProps } from "./widget.builder";
|
|
6
7
|
|
|
7
8
|
export type ButonVariants =
|
|
8
9
|
| "contained"
|
|
@@ -103,3 +104,64 @@ export class Button extends Widget {
|
|
|
103
104
|
return this.text;
|
|
104
105
|
}
|
|
105
106
|
}
|
|
107
|
+
|
|
108
|
+
export type wButtonProps = WidgetProps & {
|
|
109
|
+
text: string;
|
|
110
|
+
variant?: ButonVariants | null;
|
|
111
|
+
color?: Colors | null;
|
|
112
|
+
width?: number | null;
|
|
113
|
+
height?: number | null;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const WButton = (props: wButtonProps) => {
|
|
117
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<button
|
|
121
|
+
id={props.id}
|
|
122
|
+
w-button
|
|
123
|
+
w-text={props.text}
|
|
124
|
+
w-variant={props.variant}
|
|
125
|
+
w-color={props.color}
|
|
126
|
+
w-width={props.width}
|
|
127
|
+
w-height={props.height}
|
|
128
|
+
w-class={props.classNames}
|
|
129
|
+
w-orientation={props.orientation}
|
|
130
|
+
w-fixed-size={props.fixedSize}
|
|
131
|
+
w-padding={props.padding}
|
|
132
|
+
w-type={props.type}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export function createButton(id: string, content: any, parent: Widget | null = null): Button {
|
|
138
|
+
let newButton = new Button(id, parent);
|
|
139
|
+
|
|
140
|
+
const dataText = content.getAttribute("w-text");
|
|
141
|
+
const dataVariant = content.getAttribute("w-variant");
|
|
142
|
+
const dataColor = content.getAttribute("w-color");
|
|
143
|
+
const dataWidth = content.getAttribute("w-width");
|
|
144
|
+
const dataHeight = content.getAttribute("w-height");
|
|
145
|
+
|
|
146
|
+
if (dataText) {
|
|
147
|
+
newButton.setText(dataText);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (dataVariant) {
|
|
151
|
+
newButton.setVariant(dataVariant);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (dataColor) {
|
|
155
|
+
newButton.setColor(dataColor);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (dataWidth) {
|
|
159
|
+
newButton.setInitialW(dataWidth);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (dataHeight) {
|
|
163
|
+
newButton.setInitialH(dataHeight);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return newButton;
|
|
167
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ToggleButton } from "./toggle.ui";
|
|
2
|
+
import { WidgetProps } from "./widget.builder";
|
|
3
|
+
import { Widget, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
|
|
4
|
+
|
|
5
|
+
export class Checkbox extends ToggleButton {
|
|
6
|
+
constructor(id: string, text: string = "", parent: Widget | null = null) {
|
|
7
|
+
super(id, text, "check_box_outlined", "check_box_outline_blank", parent);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type wCheckboxProps = WidgetProps & {
|
|
12
|
+
text: string;
|
|
13
|
+
checked?: boolean | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const WCheckbox = (props: wCheckboxProps) => {
|
|
17
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
id={props.id}
|
|
22
|
+
w-checkbox
|
|
23
|
+
w-text={props.text}
|
|
24
|
+
w-checked={props.checked}
|
|
25
|
+
w-class={props.classNames}
|
|
26
|
+
w-orientation={props.orientation}
|
|
27
|
+
w-fixed-size={props.fixedSize}
|
|
28
|
+
w-padding={props.padding}
|
|
29
|
+
w-type={props.type}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function createCheckbox(id: string, content: any, parent: Widget | null = null): Checkbox {
|
|
35
|
+
const dataText = content.getAttribute("w-text");
|
|
36
|
+
const dataChecked = content.getAttribute("w-checked");
|
|
37
|
+
|
|
38
|
+
let newCheckbox = new Checkbox(id, dataText, parent);
|
|
39
|
+
|
|
40
|
+
if (dataChecked !== null) {
|
|
41
|
+
newCheckbox.setState(true);
|
|
42
|
+
} else {
|
|
43
|
+
newCheckbox.setState(false);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return newCheckbox;
|
|
47
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OrientationTypes } from "src/types/orientation.type";
|
|
2
|
+
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
3
|
+
import { UID } from "../core/uid";
|
|
4
|
+
import { WidgetProps, createWidget } from "./widget.builder";
|
|
5
|
+
|
|
6
|
+
export type ContainerParams = {
|
|
7
|
+
orientation?: OrientationTypes;
|
|
8
|
+
parent?: Widget | null;
|
|
9
|
+
size?: number | null;
|
|
10
|
+
padding?: number | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class Container extends Widget {
|
|
14
|
+
constructor(params: ContainerParams) {
|
|
15
|
+
const { orientation = "horizontal", parent = null, size = null, padding = null } = params;
|
|
16
|
+
|
|
17
|
+
super(UID(), "div", parent);
|
|
18
|
+
|
|
19
|
+
if (orientation === "horizontal") {
|
|
20
|
+
this.setAlign(WidgetAlignTypes.HORIZONTAL);
|
|
21
|
+
} else {
|
|
22
|
+
this.setAlign(WidgetAlignTypes.VERTICAL);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (size !== null) {
|
|
26
|
+
this.setFixedSize(size);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (padding !== null) {
|
|
30
|
+
this.setPadding(padding);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.setType(WidgetTypes.FILL);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function Spacer(): Container {
|
|
38
|
+
return new Container({});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ContainerProps = Omit<WidgetProps, "id"> & {
|
|
42
|
+
children: any;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const WContainer = (props: ContainerProps) => {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
w-container
|
|
49
|
+
w-class={props.classNames}
|
|
50
|
+
w-orientation={props.orientation}
|
|
51
|
+
w-fixed-size={props.fixedSize}
|
|
52
|
+
w-padding={props.padding}
|
|
53
|
+
w-type={props.type}
|
|
54
|
+
>
|
|
55
|
+
{props.children}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function createContainer(content: any, parent: Widget | null = null): Container {
|
|
61
|
+
const dataOrientation = content.getAttribute("w-orientation");
|
|
62
|
+
|
|
63
|
+
let orientation: OrientationTypes = dataOrientation ? dataOrientation : "horizontal";
|
|
64
|
+
|
|
65
|
+
let newContainer = new Container({ orientation, parent });
|
|
66
|
+
|
|
67
|
+
content.childNodes.forEach((item: HTMLElement) => {
|
|
68
|
+
const widget = createWidget(item);
|
|
69
|
+
|
|
70
|
+
if (widget !== null) {
|
|
71
|
+
newContainer.addChild(widget);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return newContainer;
|
|
76
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Draggable } from "./draggable.ui";
|
|
2
2
|
import "./styles/hpanel.css";
|
|
3
|
+
import { WidgetProps, createWidget } from "./widget.builder";
|
|
3
4
|
import { Widget, WidgetAlignTypes, WidgetTypes } from "./widget.ui";
|
|
4
5
|
|
|
5
6
|
const HPANEL_HANDLER_SIZE = 4;
|
|
@@ -125,3 +126,39 @@ export class HPanel extends Widget {
|
|
|
125
126
|
this.handler.setY(this.getY(true));
|
|
126
127
|
}
|
|
127
128
|
}
|
|
129
|
+
|
|
130
|
+
export type WHPanelProps = WidgetProps & {
|
|
131
|
+
children: any;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const WHPanel = (props: WHPanelProps) => {
|
|
135
|
+
return (
|
|
136
|
+
<div
|
|
137
|
+
w-hpanel
|
|
138
|
+
w-class={props.classNames}
|
|
139
|
+
w-fixed-size={props.fixedSize}
|
|
140
|
+
w-padding={props.padding}
|
|
141
|
+
w-type={props.type}
|
|
142
|
+
>
|
|
143
|
+
{props.children}
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export function createHPanel(id: string, content: any, parent: Widget | null = null): HPanel {
|
|
149
|
+
let newPanel = new HPanel(id, parent);
|
|
150
|
+
|
|
151
|
+
content.childNodes.forEach((item: HTMLElement, index: number) => {
|
|
152
|
+
const widget = createWidget(item);
|
|
153
|
+
|
|
154
|
+
if (widget !== null) {
|
|
155
|
+
if (index === 0) {
|
|
156
|
+
newPanel.setLeft(widget, widget.getFixedSize());
|
|
157
|
+
} else if (index === 1) {
|
|
158
|
+
newPanel.setRight(widget);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return newPanel;
|
|
164
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import "./styles/image.css";
|
|
2
|
+
import { WidgetProps } from "./widget.builder";
|
|
3
|
+
import { Widget, WidgetTypes, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
|
|
4
|
+
|
|
5
|
+
export class Image extends Widget {
|
|
6
|
+
imageContainer: Widget;
|
|
7
|
+
image: Widget;
|
|
8
|
+
constructor(id: string, src: string = "", parent: Widget | null = null) {
|
|
9
|
+
super(id, "div", parent);
|
|
10
|
+
|
|
11
|
+
this.imageContainer = new Widget(id + ".imageContainer", "div", this);
|
|
12
|
+
this.imageContainer.addClass("WUIImageContainer");
|
|
13
|
+
|
|
14
|
+
this.image = new Widget(id + ".image", "img", this.imageContainer);
|
|
15
|
+
this.image.setType(WidgetTypes.CUSTOM);
|
|
16
|
+
this.image.getBody().setAttribute("src", src);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public render(): void {
|
|
20
|
+
super.render();
|
|
21
|
+
|
|
22
|
+
this.imageContainer.setX(0);
|
|
23
|
+
this.imageContainer.setY(0);
|
|
24
|
+
this.imageContainer.setWH(this.getW(), this.getH());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public fillWidth(): void {
|
|
28
|
+
this.image.addClass("WUIImageFillWidth");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public fillHeight(): void {
|
|
32
|
+
this.image.addClass("WUIImageFillHeight");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public setAlternateText(text: string): void {
|
|
36
|
+
this.image.getBody().setAttribute("alt", text);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public setImageUrl(url: string): void {
|
|
40
|
+
this.image.getBody().setAttribute("src", url);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public getImageUrl(): string | null {
|
|
44
|
+
return this.image.getBody().getAttribute("src");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public getAlternateText(): string | null {
|
|
48
|
+
return this.image.getBody().getAttribute("alt");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type wImageProps = WidgetProps & {
|
|
53
|
+
src: string;
|
|
54
|
+
alt?: string | null;
|
|
55
|
+
fillWidth?: boolean | null;
|
|
56
|
+
fillHeight?: boolean | null;
|
|
57
|
+
width?: number | null;
|
|
58
|
+
height?: number | null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const WImage = (props: wImageProps) => {
|
|
62
|
+
connectWidgetCallback(props.id, getOnlyEventProps(props));
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
id={props.id}
|
|
67
|
+
w-image
|
|
68
|
+
w-src={props.src}
|
|
69
|
+
w-alt={props.alt}
|
|
70
|
+
w-fill-width={props.fillWidth}
|
|
71
|
+
w-fill-height={props.fillHeight}
|
|
72
|
+
w-width={props.width}
|
|
73
|
+
w-height={props.height}
|
|
74
|
+
w-fixed-size={props.fixedSize}
|
|
75
|
+
w-padding={props.padding}
|
|
76
|
+
w-type={props.type}
|
|
77
|
+
></div>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export function createImage(id: string, content: any, parent: Widget | null = null): Image {
|
|
82
|
+
const dataSrc = content.getAttribute("w-src");
|
|
83
|
+
const dataAlt = content.getAttribute("w-alt");
|
|
84
|
+
const dataFillWidth = content.getAttribute("w-fill-width");
|
|
85
|
+
const dataFillHeight = content.getAttribute("w-fill-height");
|
|
86
|
+
const dataWidth = content.getAttribute("w-width");
|
|
87
|
+
const dataHeight = content.getAttribute("w-height");
|
|
88
|
+
|
|
89
|
+
let newImage = new Image(id, dataSrc, parent);
|
|
90
|
+
|
|
91
|
+
if (dataAlt) {
|
|
92
|
+
newImage.setAlternateText(dataAlt);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (dataFillWidth) {
|
|
96
|
+
newImage.fillWidth();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (dataFillHeight) {
|
|
100
|
+
newImage.fillHeight();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (dataWidth) {
|
|
104
|
+
newImage.setInitialW(dataWidth);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (dataHeight) {
|
|
108
|
+
newImage.setInitialH(dataHeight);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return newImage;
|
|
112
|
+
}
|
package/src/ui/index.ts
CHANGED
|
@@ -24,7 +24,7 @@ import { DataGrid } from "./datagrid.ui";
|
|
|
24
24
|
import { RadioButton } from "./radiobutton";
|
|
25
25
|
import { ValueBar } from "./valuebar.ui";
|
|
26
26
|
import { VPanel } from "./vpanel.ui";
|
|
27
|
-
import { createWidget } from "./widget.builder
|
|
27
|
+
import { createWidget } from "./widget.builder";
|
|
28
28
|
import { IconButtonMenu } from "./iconButtonMenu.ui";
|
|
29
29
|
|
|
30
30
|
export type { ContainerParams };
|