@nebularstreams/libmui 3.1.1 → 4.0.1
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/dist/libmui.esm.js +3 -0
- package/dist/libmui.esm.min.js +3 -0
- package/package.json +6 -2
- package/dist/libui.esm.js +0 -3
- package/rollup.config.js +0 -20
- package/src/app/MainState.js +0 -22
- package/src/app/app.js +0 -9
- package/src/css/a-measures.css +0 -6
- package/src/css/b-colors.css +0 -12
- package/src/css/b-root-bootstrap-ext.css +0 -81
- package/src/css/b-root-bootstrap.css +0 -178
- package/src/css/b-root-semantic-flex.css +0 -87
- package/src/css/b-root-semantic-size-new.css +0 -37
- package/src/css/b-root-semantic-size.css +0 -75
- package/src/css/b-root-semantic-skin.css +0 -48
- package/src/css/b-root-semantic.css +0 -111
- package/src/css/b-root.css +0 -3
- package/src/css/cardie.css +0 -6
- package/src/css/flex.css +0 -46
- package/src/css/fontawesome/brands.min.css +0 -16
- package/src/css/fontawesome/fontawesome-ext.css +0 -7
- package/src/css/fontawesome/fontawesome-solid.css +0 -17
- package/src/css/fontawesome/fontawesome.css +0 -4359
- package/src/css/ui.notifications.css +0 -23
- package/src/css/ui.popup.css +0 -127
- package/src/css/ui.witharia.css +0 -25
- package/src/index.js +0 -112
- package/src/meta/InputTemplates.js +0 -3
- package/src/style.js +0 -37
- package/src/util/colorjoe.js +0 -1370
- package/src/util/filepath.js +0 -10
- package/src/util/fuckingconfirm.js +0 -28
- package/src/util/mithril-range.js +0 -445
- package/src/util/tainter.js +0 -39
- package/src/util/util.clone.js +0 -8
- package/src/util/util.tokenizer.js +0 -266
- package/src/util/widgets.core.js +0 -314
- package/src/util/widgets.js +0 -79
- package/src/util/widgets.utils.js +0 -10
- package/src/widgets/Basic.js +0 -352
- package/src/widgets/ButtonChoiceWidget.js +0 -72
- package/src/widgets/CardieWidget.js +0 -168
- package/src/widgets/ColorJoePack.js +0 -108
- package/src/widgets/ColorJoeWidget.js +0 -140
- package/src/widgets/ComboPrompt.js +0 -112
- package/src/widgets/ComboWidget.js +0 -156
- package/src/widgets/CoolContentTicker.js +0 -244
- package/src/widgets/CoolerEmpty.js +0 -37
- package/src/widgets/EmptyButton.js +0 -36
- package/src/widgets/FontSelectorButton.js +0 -37
- package/src/widgets/InputWidget.js +0 -254
- package/src/widgets/NoticeWidget.js +0 -31
- package/src/widgets/OverflowUtils.js +0 -449
- package/src/widgets/PlusMinusWidget.js +0 -55
- package/src/widgets/RangeWidget.js +0 -200
- package/src/widgets/SelectFileMiniButton.js +0 -170
- package/src/widgets/Separator.js +0 -21
- package/src/widgets/SmileysButton.js +0 -19
- package/src/widgets/SwitchWidget.js +0 -42
- package/src/widgets/TemplatedInputWidget.js +0 -1395
- package/src/widgets/TitleBarWidget.js +0 -71
- package/src/widgets/css/buttonchoice.css +0 -62
- package/src/widgets/css/buttonchoice.toggle.css +0 -37
- package/src/widgets/css/choicer.css +0 -24
- package/src/widgets/css/colorjoe.css +0 -230
- package/src/widgets/css/colorjoewidget.css +0 -105
- package/src/widgets/css/combo-ellipsis.css +0 -29
- package/src/widgets/css/fileminibutton.css +0 -12
- package/src/widgets/css/input.css +0 -35
- package/src/widgets/css/mithril-range.css +0 -69
- package/src/widgets/css/progressstrip.css +0 -31
- package/src/widgets/css/range-anims.css +0 -23
- package/src/widgets/css/separator.css +0 -21
- package/src/widgets/css/smileys.css +0 -85
- package/src/widgets/css/templatedinput.css +0 -67
- package/src/widgets/css/ui.titlebar.css +0 -44
- package/src/widgets/css/uploadfile.css +0 -5
- /package/dist/{libui.css → libmui.css} +0 -0
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import m from "mithril";
|
|
2
|
-
import MithrilRange from "../util/mithril-range";
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
__timer;
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
resetMultiplier = (state) => {
|
|
9
|
-
/*
|
|
10
|
-
if (state.curMultiplier > 1 && state.value < state.curMax * (state.curMultiplier - 1)) {
|
|
11
|
-
state.curMultiplier = Math.ceil(state.value / state.curMax);
|
|
12
|
-
m.redraw();
|
|
13
|
-
}
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
// req multiplier to show value within negative bounds
|
|
18
|
-
maxMultiplier = state.value > state.curMax ? Math.ceil(state.value / state.curMax) : 1,
|
|
19
|
-
// req multiplier to show value within positive bounds
|
|
20
|
-
minMultiplier = (state.curMin < 0 && state.value < state.curMin) ? Math.abs(Math.ceil(state.value / state.curMin)) : 1,
|
|
21
|
-
// chosen
|
|
22
|
-
multiplier = Math.min(Math.max(minMultiplier, maxMultiplier), state.maxMultiplier);
|
|
23
|
-
|
|
24
|
-
if (state.curMultiplier !== multiplier) {
|
|
25
|
-
state.curMultiplier = multiplier;
|
|
26
|
-
m.redraw();
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
increaseMultiplier = (state) => {
|
|
30
|
-
if (
|
|
31
|
-
state.value >= (state.curMax * state.curMultiplier) * 0.9
|
|
32
|
-
&& state.maxMultiplier > 1
|
|
33
|
-
&& state.curMultiplier <= state.maxMultiplier - 1
|
|
34
|
-
) {
|
|
35
|
-
state.curMultiplier++;
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
if (state.curMin < 0) return increaseMinMultiplier(state);
|
|
39
|
-
},
|
|
40
|
-
increaseMinMultiplier = (state) => {
|
|
41
|
-
if (state.value <= (state.curMin * state.curMultiplier) * 0.9
|
|
42
|
-
&& state.maxMultiplier > 1
|
|
43
|
-
&& state.curMultiplier <= state.maxMultiplier - 1
|
|
44
|
-
) {
|
|
45
|
-
state.curMultiplier++;
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
RangeSlider = {
|
|
50
|
-
|
|
51
|
-
oninit: ({attrs, state}) => {
|
|
52
|
-
Object.assign(state, {
|
|
53
|
-
value: attrs.value || 0,
|
|
54
|
-
initial: attrs.value || 0,
|
|
55
|
-
curMax: attrs.max,
|
|
56
|
-
curMin: attrs.min,
|
|
57
|
-
curMultiplier: 1,
|
|
58
|
-
maxMultiplier: attrs.multiplier || 1,
|
|
59
|
-
id: "I" + Date.now()
|
|
60
|
-
});
|
|
61
|
-
// adjust initial multiplier
|
|
62
|
-
if (state.maxMultiplier > 1) {
|
|
63
|
-
if (state.value > attrs.max) {
|
|
64
|
-
state.curMultiplier = Math.ceil(state.value / attrs.max);
|
|
65
|
-
} else if (attrs.min < 0 && state.value < attrs.min) {
|
|
66
|
-
state.curMultiplier = Math.abs(Math.ceil(state.value / attrs.min));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
onupdate: ({attrs, state}) => {
|
|
71
|
-
const
|
|
72
|
-
attrsMultiplier = attrs.multiplier || 1,
|
|
73
|
-
attrsValue = attrs.value || 0;
|
|
74
|
-
|
|
75
|
-
if (state.curMax !== attrs.max || state.maxMultiplier !== attrsMultiplier) {
|
|
76
|
-
|
|
77
|
-
Object.assign(state, {
|
|
78
|
-
curMax: attrs.max,
|
|
79
|
-
curMin: attrs.min,
|
|
80
|
-
maxMultiplier: attrsMultiplier,
|
|
81
|
-
value: attrs.value,
|
|
82
|
-
initial: attrsValue
|
|
83
|
-
});
|
|
84
|
-
if (!increaseMultiplier(state)) {
|
|
85
|
-
clearTimeout(state.timer);
|
|
86
|
-
state.timer = setTimeout(resetMultiplier, 1000, state);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
m.redraw();
|
|
90
|
-
|
|
91
|
-
} else if (state.initial !== attrsValue) {
|
|
92
|
-
|
|
93
|
-
Object.assign(state, {
|
|
94
|
-
value: attrsValue,
|
|
95
|
-
initial: attrsValue
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
clearTimeout(__timer);
|
|
99
|
-
__timer = setTimeout(() => m.redraw(), 50);
|
|
100
|
-
|
|
101
|
-
/*
|
|
102
|
-
if (!increaseMultiplier(state)) {
|
|
103
|
-
state.timer = setTimeout(resetMultiplier, 1000, state);
|
|
104
|
-
clearTimeout(state.timer);
|
|
105
|
-
}
|
|
106
|
-
*/
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
view: ({attrs, state}) => m(
|
|
110
|
-
".range.flexcol.control.relative" + (attrs.multiplier > 1 ? ".withmultiplier" : ""),
|
|
111
|
-
{
|
|
112
|
-
...attrs.class && {class: attrs.class},
|
|
113
|
-
title: attrs.hint || "Click, then use arrows to finetune value if needed"
|
|
114
|
-
},
|
|
115
|
-
[
|
|
116
|
-
...attrs.title ? [m("label", {class: "rangelabel", htmlFor: state.id}, attrs.title)] : [],
|
|
117
|
-
m(MithrilRange, {
|
|
118
|
-
onchange: (value) => {
|
|
119
|
-
|
|
120
|
-
state.value = value;
|
|
121
|
-
|
|
122
|
-
const increased = increaseMultiplier(state);
|
|
123
|
-
|
|
124
|
-
if (!increased && state.curMultiplier > 1) {
|
|
125
|
-
clearTimeout(state.timer);
|
|
126
|
-
state.timer = setTimeout(resetMultiplier, 1000, state);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (attrs.onchange) {
|
|
130
|
-
attrs.onchange(value);
|
|
131
|
-
} else {
|
|
132
|
-
m.redraw();
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
ondrag: (value) => {
|
|
136
|
-
if (value !== state.value) {
|
|
137
|
-
state.value = value;
|
|
138
|
-
if (attrs.ondrag) attrs.ondrag(value);
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
return false;
|
|
142
|
-
},
|
|
143
|
-
value: state.value || 0,
|
|
144
|
-
min: (attrs.min || 0) * state.curMultiplier,
|
|
145
|
-
max: (state.curMax * state.curMultiplier) || 100,
|
|
146
|
-
step: attrs.step || 1,
|
|
147
|
-
relative: attrs.relative,
|
|
148
|
-
factor: attrs.factor
|
|
149
|
-
}, [
|
|
150
|
-
m(".currentval", attrs.parser
|
|
151
|
-
? attrs.parser(state.value, attrs.step < 1)
|
|
152
|
-
: state.value
|
|
153
|
-
? attrs.step < 1
|
|
154
|
-
? state.value.toFixed(2)
|
|
155
|
-
: ("" + Math.floor(state.value)) : "")
|
|
156
|
-
])
|
|
157
|
-
/*
|
|
158
|
-
m(".datalist.flexrow", [
|
|
159
|
-
m("div", attrs.getLabel(0)),
|
|
160
|
-
m(".ismax", attrs.getLabel(attrs.max || 100))
|
|
161
|
-
])
|
|
162
|
-
*/
|
|
163
|
-
]
|
|
164
|
-
)
|
|
165
|
-
},
|
|
166
|
-
RangeWidget = {
|
|
167
|
-
view: ({attrs, state}) => m(RangeSlider, {
|
|
168
|
-
value: attrs.value || 0,
|
|
169
|
-
min: attrs.min || 0,
|
|
170
|
-
max: attrs.max || 100,
|
|
171
|
-
step: attrs.step || 0.1,
|
|
172
|
-
class: (attrs.disabled ? "disabled " : "") + (attrs.class || ""),
|
|
173
|
-
title: attrs.title,
|
|
174
|
-
multiplier: attrs.multiplier,
|
|
175
|
-
hint: attrs.hint,
|
|
176
|
-
parser: attrs.parser,
|
|
177
|
-
relative: attrs.relative,
|
|
178
|
-
factor: attrs.factor,
|
|
179
|
-
|
|
180
|
-
// values: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
181
|
-
getLabel: (value) => (value ? "" + value : "default"),
|
|
182
|
-
ondrag: (value) => {
|
|
183
|
-
state.changed = true;
|
|
184
|
-
state.value = value;
|
|
185
|
-
if (attrs.onchange) attrs.onchange(value, true);
|
|
186
|
-
return true;
|
|
187
|
-
},
|
|
188
|
-
onchange: (value) => {
|
|
189
|
-
if (attrs.auto0) {
|
|
190
|
-
value = 0;
|
|
191
|
-
} else if (attrs.autoValue) value = attrs.autoValue;
|
|
192
|
-
state.changed = true;
|
|
193
|
-
state.value = value;
|
|
194
|
-
if (attrs.onchange) attrs.onchange(value, false);
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
})
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
export default RangeWidget;
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* A Button to read a text file
|
|
4
|
-
* @typedef {{ root:string, key:string, format:string, type:string, onUpload:function(boolean,Error?), quality:number}} UploadImageAttrs
|
|
5
|
-
*
|
|
6
|
-
* @author Rodolfo Lopez Pintor, 2019
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import m from "mithril";
|
|
11
|
-
import {defineWidget, Icon, ButtonNew, Notification} from "./Basic";
|
|
12
|
-
import MainState from "../app/MainState.js"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function processDataUrl(file) {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
|
|
18
|
-
const reader = new FileReader();
|
|
19
|
-
reader.onload = function (evt) {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
data = evt.target.result;
|
|
23
|
-
|
|
24
|
-
if (data) resolve({name: file.name, url: data}); else reject(new Error("no data"));
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
reader.readAsDataURL(file);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function processImage(file) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
|
|
35
|
-
const reader = new FileReader();
|
|
36
|
-
reader.onload = function (evt) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
data = evt.target.result,
|
|
40
|
-
pict = new Image();
|
|
41
|
-
|
|
42
|
-
pict.onerror = function (error) {
|
|
43
|
-
evt.target.value = "";
|
|
44
|
-
reject(error);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
pict.onload = function () {
|
|
48
|
-
resolve(pict);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// noinspection JSValidateTypes
|
|
52
|
-
pict.src = data;
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
reader.readAsDataURL(file);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
MediaSelectButton = defineWidget(
|
|
62
|
-
({attrs}) => m(ButtonNew, {
|
|
63
|
-
class: "unitsizesmall rectbutton ohidden",
|
|
64
|
-
icon: "images",
|
|
65
|
-
onClick: () => MainState.setTransState("image", undefined, {
|
|
66
|
-
giphyQuery: "frame",
|
|
67
|
-
onOverride: (global, item) => {
|
|
68
|
-
const translated = item ? attrs.parse ? attrs.parse(item) : item : undefined;
|
|
69
|
-
if (translated) {
|
|
70
|
-
attrs.onImage(translated);
|
|
71
|
-
m.redraw();
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// noinspection JSValidateTypes
|
|
79
|
-
const
|
|
80
|
-
FileSelectButton = defineWidget(
|
|
81
|
-
(vnode) => {
|
|
82
|
-
|
|
83
|
-
const {attrs} = vnode;
|
|
84
|
-
|
|
85
|
-
return m(
|
|
86
|
-
"button.selectfile.relative",
|
|
87
|
-
{
|
|
88
|
-
...attrs.class && {class: attrs.class}
|
|
89
|
-
},
|
|
90
|
-
[
|
|
91
|
-
m(Icon, {icon: attrs.icon || "upload", iconClass: attrs.iconClass}),
|
|
92
|
-
...attrs.text ? [m("span.text", {class: attrs.textClass}, attrs.text)] : [],
|
|
93
|
-
m("input", {
|
|
94
|
-
class: "absolute w-100 h-100 ohidden",
|
|
95
|
-
type: "file",
|
|
96
|
-
accept: attrs.accept || null,
|
|
97
|
-
title: attrs.title,
|
|
98
|
-
onchange: (event) => {
|
|
99
|
-
if (event.target.files && event.target.files.length) {
|
|
100
|
-
attrs.onFile(event.target.files[0]);
|
|
101
|
-
event.target.value = "";
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
]
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
),
|
|
110
|
-
|
|
111
|
-
ImageSelectButton = defineWidget(
|
|
112
|
-
({attrs}) => m(FileSelectButton, {
|
|
113
|
-
class: attrs.class,
|
|
114
|
-
accept: attrs.accept || "image/*",
|
|
115
|
-
icon: attrs.icon || "image",
|
|
116
|
-
iconClass: attrs.iconClass,
|
|
117
|
-
textClass: attrs.textClass,
|
|
118
|
-
text: attrs.text,
|
|
119
|
-
onFile: (file) => attrs.onImageFiles([{type: "image", file}])
|
|
120
|
-
})
|
|
121
|
-
),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
ImageProcessButton = defineWidget(
|
|
125
|
-
({attrs}) => m(ImageSelectButton, {
|
|
126
|
-
class: attrs.class,
|
|
127
|
-
icon: attrs.icon,
|
|
128
|
-
text: attrs.text,
|
|
129
|
-
accept: attrs.accept,
|
|
130
|
-
iconClass: attrs.iconClass,
|
|
131
|
-
textClass: attrs.textClass,
|
|
132
|
-
onImageFiles: (files) => {
|
|
133
|
-
if (files.length) {
|
|
134
|
-
processImage(files[0].file)
|
|
135
|
-
.then(attrs.onImage)
|
|
136
|
-
.catch((e) => {
|
|
137
|
-
if (attrs.onError) attrs.onError(e);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
),
|
|
143
|
-
ImageDataButton = defineWidget(
|
|
144
|
-
({attrs}) => m(ImageSelectButton, {
|
|
145
|
-
class: attrs.class,
|
|
146
|
-
icon: attrs.icon,
|
|
147
|
-
text: attrs.text,
|
|
148
|
-
accept: attrs.accept,
|
|
149
|
-
iconClass: attrs.iconClass,
|
|
150
|
-
textClass: attrs.textClass,
|
|
151
|
-
onImageFiles: (files) => {
|
|
152
|
-
if (files.length) {
|
|
153
|
-
processDataUrl(files[0].file)
|
|
154
|
-
.then(attrs.onImageUrl)
|
|
155
|
-
.catch((e) => {
|
|
156
|
-
if (attrs.onError) attrs.onError(e);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
export {
|
|
164
|
-
FileSelectButton,
|
|
165
|
-
ImageDataButton,
|
|
166
|
-
ImageSelectButton,
|
|
167
|
-
ImageProcessButton,
|
|
168
|
-
MediaSelectButton,
|
|
169
|
-
processImage
|
|
170
|
-
};
|
package/src/widgets/Separator.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import m from "mithril";
|
|
2
|
-
import defineWidget from "../util/widgets.utils";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
Separator = defineWidget(
|
|
8
|
-
({ attrs, children }) => m(
|
|
9
|
-
".separator",
|
|
10
|
-
{
|
|
11
|
-
class: attrs.class || "mini",
|
|
12
|
-
...attrs.onClick && { onclick: attrs.onClick }
|
|
13
|
-
},
|
|
14
|
-
[
|
|
15
|
-
m("span.grows", attrs.text),
|
|
16
|
-
...(children || [])
|
|
17
|
-
]
|
|
18
|
-
)
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export default Separator;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import m from "mithril";
|
|
2
|
-
import {defineWidget, ButtonNew} from "./Basic";
|
|
3
|
-
import MainState from "../app/MainState.js"
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
SmileysButton = defineWidget(
|
|
7
|
-
({attrs}) => {
|
|
8
|
-
const {icon, onchange, icons, state} = attrs;
|
|
9
|
-
return m(ButtonNew, {
|
|
10
|
-
title: "Click to select icon or emoji for this marker",
|
|
11
|
-
class: "chequered " + (attrs.class || "font-200"),
|
|
12
|
-
icon: icon && icon.icon,
|
|
13
|
-
text: icon && icon.glyph,
|
|
14
|
-
onClick: () => MainState.setTransState("emoji", onchange, {icons})
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export default SmileysButton;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import m from "mithril";
|
|
2
|
-
import defineWidget from "../util/widgets.utils";
|
|
3
|
-
import {Icon} from "./Basic";
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
SwitchWidget = defineWidget(
|
|
7
|
-
({attrs, state}) => m((attrs.unit || "") + ".flexrow" + (attrs.subline ? " withsubline" : ""),
|
|
8
|
-
{
|
|
9
|
-
class: attrs.class,
|
|
10
|
-
text: attrs.text,
|
|
11
|
-
title: attrs.title || null,
|
|
12
|
-
onclick: () => {
|
|
13
|
-
state.checked = !state.checked;
|
|
14
|
-
if (attrs.onchange) {
|
|
15
|
-
attrs.onchange(state.checked);
|
|
16
|
-
}
|
|
17
|
-
m.redraw();
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
attrs.right
|
|
21
|
-
? [
|
|
22
|
-
...attrs.text ? [m("span.grows.caption", attrs.subline ? {"data-subline": attrs.subline} : {}, attrs.text)] : [],
|
|
23
|
-
m(Icon, {iconClass: "pad-2 pad-h", icon: state.checked ? "toggle-on" : "toggle-off"})
|
|
24
|
-
]
|
|
25
|
-
: [
|
|
26
|
-
m(Icon, {iconClass: "pad-2 pad-h", icon: state.checked ? "toggle-on" : "toggle-off"}),
|
|
27
|
-
...attrs.text ? [m("span.grows.caption", attrs.subline ? {"data-subline": attrs.subline} : {}, attrs.text)] : []
|
|
28
|
-
]),
|
|
29
|
-
({attrs, state}) => {
|
|
30
|
-
state.checked = state.original = attrs.checked;
|
|
31
|
-
},
|
|
32
|
-
null,
|
|
33
|
-
null,
|
|
34
|
-
({attrs, state}) => {
|
|
35
|
-
if (attrs.checked !== state.original) {
|
|
36
|
-
state.checked = state.original = attrs.checked;
|
|
37
|
-
m.redraw();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
export default SwitchWidget;
|