ozdenui 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,1140 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
LabelEditor - v26.09
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- An object based editor for labels.
|
|
9
|
+
- "Add label" adds a label to the list. The labels are stacked one under the other.
|
|
10
|
+
- Click a label: the properties panel opens at the right side of the screen (full height, SidePanel).
|
|
11
|
+
Text, font size, bold, italic, alignment, width (auto / full), text color, background, padding,
|
|
12
|
+
corner radius and border are changed there. The panel has no backdrop: another label can be
|
|
13
|
+
clicked while it is open.
|
|
14
|
+
- The panel is made of components: SidePanel, Stepper, ColorPicker, Tabs (pill), CheckBox and the
|
|
15
|
+
Input / Button of basic.js.
|
|
16
|
+
- Saved styles: give the properties of a label a name and save them. Click a saved style to apply it
|
|
17
|
+
to the selected label. The chips show a preview of each style.
|
|
18
|
+
- A style is linked: saving a style again with the same name updates every label that uses it.
|
|
19
|
+
A label that was changed after its style was applied shows "(changed)" in the panel.
|
|
20
|
+
- storageKey: "..." -> The saved styles are kept in basic.storage (localStorage) and loaded next time.
|
|
21
|
+
- Keyboard: Tab to a label, Enter / Space selects it, Delete removes it, Escape closes the panel.
|
|
22
|
+
- getLabels() / setLabels() give and take plain objects, to save the work or to draw it somewhere else.
|
|
23
|
+
- The label texts are shown as plain text (not HTML).
|
|
24
|
+
- Style packages: "light" (default; the old name "classic" works too), "dark". Select with styleName. (LabelEditor.styles)
|
|
25
|
+
|
|
26
|
+
NEEDS: basic.js v26.10.27 (its "dark" package is a package of params).
|
|
27
|
+
NEEDS (load them before this file):
|
|
28
|
+
comp/side-panel.js, comp/stepper.js, comp/color-picker.js, comp/tabs.js, comp/check-box.js
|
|
29
|
+
|
|
30
|
+
USAGE:
|
|
31
|
+
const editor = LabelEditor({
|
|
32
|
+
width: 860,
|
|
33
|
+
height: 540,
|
|
34
|
+
storageKey: "my-label-styles",
|
|
35
|
+
onChange: function (self) { println(self.getLabels()); },
|
|
36
|
+
});
|
|
37
|
+
editor.addLabel({ text: "Monthly report", fontSize: 26, bold: 1 });
|
|
38
|
+
editor.saveStyle("Title", 0); // The style of label 0 is saved as "Title"
|
|
39
|
+
editor.addLabel({ text: "Sales" });
|
|
40
|
+
editor.applyStyle("Title", 1); // Label 1 gets the "Title" style
|
|
41
|
+
editor.getLabels(); // [{ text, fontSize, textColor, color, bold, italic, textAlign, fullWidth, padding, round, border, borderColor, styleName }, ...]
|
|
42
|
+
editor.remove(); // Also removes its panel from the page.
|
|
43
|
+
|
|
44
|
+
Started Date: September 2026
|
|
45
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
46
|
+
|
|
47
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
48
|
+
Licensed under the Apache License, Version 2.0
|
|
49
|
+
SPDX-License-Identifier: Apache-2.0
|
|
50
|
+
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
"use strict";
|
|
54
|
+
|
|
55
|
+
// Default values:
|
|
56
|
+
const LabelEditorDefaults = {
|
|
57
|
+
key: "0",
|
|
58
|
+
width: 860,
|
|
59
|
+
height: 540,
|
|
60
|
+
labels: [], // Start labels: [{ text, fontSize, ... , styleName }]
|
|
61
|
+
savedStyles: [], // Start styles: [{ name, props: { fontSize, textColor, ... } }] (storageKey wins when it has data)
|
|
62
|
+
storageKey: "", // "": the saved styles are not kept. Ex: "label-editor-styles"
|
|
63
|
+
newLabel: { // Properties of a new label
|
|
64
|
+
text: "Label {n}", // {n}: the number of the label
|
|
65
|
+
fontSize: 16,
|
|
66
|
+
textColor: "#1F2328",
|
|
67
|
+
color: "", // "": transparent
|
|
68
|
+
bold: 0,
|
|
69
|
+
italic: 0,
|
|
70
|
+
textAlign: "left", // "left", "center", "right"
|
|
71
|
+
fullWidth: 0, // 1: the label is as wide as the list
|
|
72
|
+
padding: 0,
|
|
73
|
+
round: 0,
|
|
74
|
+
border: 0,
|
|
75
|
+
borderColor: "#1F2328",
|
|
76
|
+
},
|
|
77
|
+
colorPalette: [ // The colors of the color pickers in the panel
|
|
78
|
+
"#1F2328", "#5A5A5A", "#9A9A9A", "#D0D0D0", "#FFFFFF",
|
|
79
|
+
"#C0392B", "#E0A038", "#8A5A00", "#3E8E62", "#1F6F6B",
|
|
80
|
+
"#2F6FB0", "#5AA9E6", "#7B61D9", "#B45FC0", "#E06AA0",
|
|
81
|
+
"#FFE0E0", "#FFF3C4", "#E3F4E8", "#E1EEFB", "#EFE7FB",
|
|
82
|
+
],
|
|
83
|
+
panelWidth: 340,
|
|
84
|
+
useScrollBar: 1,
|
|
85
|
+
texts: {
|
|
86
|
+
title: "Labels",
|
|
87
|
+
addButton: "+ Add label",
|
|
88
|
+
empty: "No labels yet. Click \"Add label\" to create one.",
|
|
89
|
+
panelTitle: "Properties",
|
|
90
|
+
text: "Text",
|
|
91
|
+
fontSize: "Font size",
|
|
92
|
+
fontStyle: "Font style",
|
|
93
|
+
bold: "Bold",
|
|
94
|
+
italic: "Italic",
|
|
95
|
+
align: "Alignment",
|
|
96
|
+
left: "Left",
|
|
97
|
+
center: "Center",
|
|
98
|
+
right: "Right",
|
|
99
|
+
width: "Width",
|
|
100
|
+
widthAuto: "Auto",
|
|
101
|
+
widthFull: "Full",
|
|
102
|
+
textColor: "Text color",
|
|
103
|
+
background: "Background",
|
|
104
|
+
none: "None",
|
|
105
|
+
colorOn: "Color",
|
|
106
|
+
backgroundColor: "Background color",
|
|
107
|
+
padding: "Padding",
|
|
108
|
+
round: "Corner radius",
|
|
109
|
+
border: "Border",
|
|
110
|
+
borderColor: "Border color",
|
|
111
|
+
savedStyles: "Saved styles",
|
|
112
|
+
styleNamePlaceholder: "Style name",
|
|
113
|
+
save: "Save",
|
|
114
|
+
noStyles: "No saved styles yet. Style a label, write a name and save it.",
|
|
115
|
+
applyHint: "Click a style to apply it to the selected label.",
|
|
116
|
+
currentStyle: "Style: {name}",
|
|
117
|
+
changed: "(changed)",
|
|
118
|
+
noStyle: "No style",
|
|
119
|
+
duplicate: "Duplicate",
|
|
120
|
+
remove: "Delete",
|
|
121
|
+
removeStyle: "Delete style",
|
|
122
|
+
},
|
|
123
|
+
onChange: function (self) { }, // The labels changed. self.getLabels()
|
|
124
|
+
onSelect: function (self, index) { }, // index: -1 when nothing is selected
|
|
125
|
+
onStylesChange: function (self) { }, // The saved styles changed. self.getSavedStyles()
|
|
126
|
+
styleName: "light", // "light" ("classic": its old name), "dark" or a name added to LabelEditor.styles
|
|
127
|
+
style: { // Light style package (default)
|
|
128
|
+
box: { color: "#F4F5F2", border: 1, borderColor: Black(0.12), round: 10 },
|
|
129
|
+
header: { color: White(1), dividerColor: Black(0.08), titleColor: "#1F2328", titleSize: 15 },
|
|
130
|
+
list: { color: "#F4F5F2", padding: 24, gap: 12, emptyColor: Black(0.4) },
|
|
131
|
+
selection: { color: "#2F6FB0", hoverColor: "rgba(47, 111, 176, 0.35)" },
|
|
132
|
+
button: { color: "#1F2328", textColor: White(1), hoverColor: "#3A3F45", round: 6, fontSize: 13, height: 36 },
|
|
133
|
+
secondaryButton: { color: Black(0.06), textColor: "#1F2328", hoverColor: Black(0.1), dangerTextColor: "#C0392B" },
|
|
134
|
+
panel: { dividerColor: Black(0.08), gap: 18, captionColor: Black(0.5), textColor: "#1F2328", hintColor: Black(0.4) },
|
|
135
|
+
input: { color: White(1), borderColor: Black(0.2), focusColor: "#141414", textColor: "#1F2328", round: 6, height: 38 },
|
|
136
|
+
chip: { color: White(1), borderColor: Black(0.14), activeBorderColor: "#2F6FB0", round: 16, closeColor: Black(0.4) },
|
|
137
|
+
// The components in the panel: their style package names and their style changes.
|
|
138
|
+
// WHY: Not nested deeper (Ex: parts.checkBox.style.label): mergeIntoIfMissing stops at 4 levels.
|
|
139
|
+
sidePanelStyleName: "light",
|
|
140
|
+
stepperStyleName: "light",
|
|
141
|
+
tabsStyleName: "light",
|
|
142
|
+
checkBoxStyleName: "light",
|
|
143
|
+
selectColorStyleName: "light",
|
|
144
|
+
sidePanelStyle: {},
|
|
145
|
+
stepperStyle: {},
|
|
146
|
+
tabsStyle: {},
|
|
147
|
+
checkBoxStyle: { label: { fontSize: 14 } },
|
|
148
|
+
selectColorStyle: { fieldText: { fontSize: 13 } },
|
|
149
|
+
scrollBar: { bar_color: "#9A9A98", bar_mouseOverColor: "#6A6A68", bar_width: 4, bar_round: 3, bar_opacity: 0.4, bar_mouseOverOpacity: 0.9, bar_padding: 2 },
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const LabelEditor = function (params = {}) {
|
|
154
|
+
|
|
155
|
+
// WHY: The panel is made of these components. Without them it can not be drawn.
|
|
156
|
+
const _missing = [
|
|
157
|
+
["SidePanel", typeof SidePanel], ["Stepper", typeof Stepper], ["ColorPicker", typeof ColorPicker],
|
|
158
|
+
["Tabs", typeof Tabs], ["CheckBox", typeof CheckBox],
|
|
159
|
+
].filter(function (pair) { return pair[1] === "undefined"; }).map(function (pair) { return pair[0]; });
|
|
160
|
+
if (_missing.length) console.error("LabelEditor: Load these components before label-editor.js: " + _missing.join(", "));
|
|
161
|
+
|
|
162
|
+
// Merge style package: your params > LabelEditor.styles[styleName] > LabelEditorDefaults (light)
|
|
163
|
+
basic.applyStylePackage(params, LabelEditor.styles, LabelEditorDefaults);
|
|
164
|
+
|
|
165
|
+
// Merge params:
|
|
166
|
+
mergeIntoIfMissing(params, LabelEditorDefaults);
|
|
167
|
+
|
|
168
|
+
// Edit params, if needed:
|
|
169
|
+
const _bs = params.style.box;
|
|
170
|
+
params.color = _bs.color;
|
|
171
|
+
params.border = _bs.border;
|
|
172
|
+
params.borderColor = _bs.borderColor;
|
|
173
|
+
params.round = _bs.round;
|
|
174
|
+
const startLabels = params.labels;
|
|
175
|
+
const startStyles = params.savedStyles;
|
|
176
|
+
params.labels = []; // WHY: The default arrays must not be shared by the instances.
|
|
177
|
+
params.savedStyles = [];
|
|
178
|
+
|
|
179
|
+
// BOX: Component container
|
|
180
|
+
let box = startObject(params);
|
|
181
|
+
|
|
182
|
+
// *** PRIVATE VARIABLES:
|
|
183
|
+
const _s = box.style;
|
|
184
|
+
// Every component gets its own copy.
|
|
185
|
+
const copyStyle = function (style) {
|
|
186
|
+
return JSON.parse(JSON.stringify(style || {}));
|
|
187
|
+
};
|
|
188
|
+
const PROP_KEYS = ["text", "fontSize", "textColor", "color", "bold", "italic", "textAlign", "fullWidth", "padding", "round", "border", "borderColor"];
|
|
189
|
+
const STYLE_KEYS = PROP_KEYS.filter(function (k) { return k !== "text"; }); // A style has everything but the text.
|
|
190
|
+
let items = []; // { props, styleName, styleChanged, label }
|
|
191
|
+
let styles = []; // { name, props }
|
|
192
|
+
let selected = null; // The selected item
|
|
193
|
+
let labelCount = 0; // For "Label {n}"
|
|
194
|
+
let isClosingPanel = 0; // WHY: selectItem(null) closes the panel, and the panel's onClose calls selectItem(null).
|
|
195
|
+
const controls = {}; // Panel controls
|
|
196
|
+
const LIMITS = {
|
|
197
|
+
fontSize: { min: 8, max: 120 },
|
|
198
|
+
padding: { min: 0, max: 80 },
|
|
199
|
+
round: { min: 0, max: 100 },
|
|
200
|
+
border: { min: 0, max: 20 },
|
|
201
|
+
};
|
|
202
|
+
const DEFAULT_BACKGROUND = "#FFF3C4"; // The first background color, when "Color" is chosen
|
|
203
|
+
const CHIP_FONT_MIN = 11; // The name in a chip is drawn with the style, between these sizes
|
|
204
|
+
const CHIP_FONT_MAX = 15;
|
|
205
|
+
const BUTTON_MOTION = "background-color 0.12s";
|
|
206
|
+
|
|
207
|
+
// *** PRIVATE FUNCTIONS:
|
|
208
|
+
|
|
209
|
+
const toNumber = function (value, min, max, fallback) {
|
|
210
|
+
const n = Number(value);
|
|
211
|
+
if (isNaN(n)) return fallback;
|
|
212
|
+
return Math.max(min, Math.min(max, Math.round(n)));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// Any object -> full, valid label properties.
|
|
216
|
+
const normalizeProps = function (source, base) {
|
|
217
|
+
const p = Object.assign({}, base || box.newLabel, source || {});
|
|
218
|
+
return {
|
|
219
|
+
text: String(p.text ?? ""),
|
|
220
|
+
fontSize: toNumber(p.fontSize, LIMITS.fontSize.min, LIMITS.fontSize.max, 16),
|
|
221
|
+
textColor: String(p.textColor || "#1F2328"),
|
|
222
|
+
color: String(p.color || ""),
|
|
223
|
+
bold: p.bold ? 1 : 0,
|
|
224
|
+
italic: p.italic ? 1 : 0,
|
|
225
|
+
textAlign: (["left", "center", "right"].indexOf(p.textAlign) > -1) ? p.textAlign : "left",
|
|
226
|
+
fullWidth: p.fullWidth ? 1 : 0,
|
|
227
|
+
padding: toNumber(p.padding, LIMITS.padding.min, LIMITS.padding.max, 0),
|
|
228
|
+
round: toNumber(p.round, LIMITS.round.min, LIMITS.round.max, 0),
|
|
229
|
+
border: toNumber(p.border, LIMITS.border.min, LIMITS.border.max, 0),
|
|
230
|
+
borderColor: String(p.borderColor || "#1F2328"),
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const pickStyleProps = function (props) {
|
|
235
|
+
const out = {};
|
|
236
|
+
STYLE_KEYS.forEach(function (k) { out[k] = props[k]; });
|
|
237
|
+
return out;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const findStyle = function (name) {
|
|
241
|
+
return styles.find(function (st) { return st.name === name; }) || null;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const indexOfItem = function (item) {
|
|
245
|
+
return items.indexOf(item);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const saveStylesToStorage = function () {
|
|
249
|
+
if (!box.storageKey) return;
|
|
250
|
+
try {
|
|
251
|
+
basic.storage.save(box.storageKey, styles);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
console.warn("LabelEditor: The styles could not be saved.");
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const stylesChanged = function () {
|
|
258
|
+
box.savedStyles = box.getSavedStyles();
|
|
259
|
+
saveStylesToStorage();
|
|
260
|
+
renderChips();
|
|
261
|
+
updatePanelStyleInfo();
|
|
262
|
+
box.onStylesChange(box);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const labelsChanged = function () {
|
|
266
|
+
box.labels = box.getLabels();
|
|
267
|
+
box.onChange(box);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// *** LIST:
|
|
271
|
+
|
|
272
|
+
// Properties -> the view of the label.
|
|
273
|
+
const applyProps = function (item) {
|
|
274
|
+
const lbl = item.label;
|
|
275
|
+
const props = item.props;
|
|
276
|
+
lbl.plainText = props.text;
|
|
277
|
+
lbl.fontSize = props.fontSize;
|
|
278
|
+
lbl.textColor = props.textColor;
|
|
279
|
+
lbl.color = props.color || "transparent";
|
|
280
|
+
lbl.bold = props.bold;
|
|
281
|
+
lbl.italic = props.italic;
|
|
282
|
+
lbl.textAlign = props.textAlign;
|
|
283
|
+
lbl.width = props.fullWidth ? "100%" : "auto";
|
|
284
|
+
lbl.padding = props.padding;
|
|
285
|
+
lbl.round = props.round;
|
|
286
|
+
lbl.border = props.border;
|
|
287
|
+
lbl.borderColor = props.borderColor;
|
|
288
|
+
lbl.css.borderStyle = "solid";
|
|
289
|
+
lbl.aria = { label: props.text || "Label" };
|
|
290
|
+
lbl.elem.title = item.styleName ? box.texts.currentStyle.replace("{name}", item.styleName) : "";
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const getOutline = function (item, isSelected) {
|
|
294
|
+
if (isSelected) return "2px solid " + _s.selection.color;
|
|
295
|
+
if (item.isHover) return "1px dashed " + _s.selection.hoverColor;
|
|
296
|
+
return "none";
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const paintSelection = function (item) {
|
|
300
|
+
const isSelected = (item === selected);
|
|
301
|
+
item.label.css = {
|
|
302
|
+
outline: getOutline(item, isSelected),
|
|
303
|
+
outlineOffset: isSelected ? "3px" : "2px",
|
|
304
|
+
};
|
|
305
|
+
item.label.aria = { selected: isSelected ? "true" : "false" };
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const focusNextItem = function (item, step) {
|
|
309
|
+
const next = items[indexOfItem(item) + step];
|
|
310
|
+
if (next) next.label.elem.focus();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const onItemKeyDown = function (item, event) {
|
|
314
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
selectItem(item);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if ((event.key === "Delete" || event.key === "Backspace") && item === selected) {
|
|
320
|
+
event.preventDefault();
|
|
321
|
+
box.removeLabel(indexOfItem(item));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
325
|
+
event.preventDefault();
|
|
326
|
+
focusNextItem(item, (event.key === "ArrowDown") ? 1 : -1);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const createItemView = function (item) {
|
|
331
|
+
createIn(box.listWrapper, function () {
|
|
332
|
+
// LABEL: The label that is edited
|
|
333
|
+
item.label = Label({ plainText: "", clickable: 1 });
|
|
334
|
+
item.label.css = {
|
|
335
|
+
maxWidth: "100%",
|
|
336
|
+
boxSizing: "border-box",
|
|
337
|
+
whiteSpace: "pre-wrap",
|
|
338
|
+
overflowWrap: "break-word",
|
|
339
|
+
minHeight: "1em",
|
|
340
|
+
};
|
|
341
|
+
item.label.cursor = "pointer";
|
|
342
|
+
item.label.shrink = 0;
|
|
343
|
+
item.label.tabIndex = 0;
|
|
344
|
+
item.label.role = "option";
|
|
345
|
+
});
|
|
346
|
+
applyProps(item);
|
|
347
|
+
paintSelection(item);
|
|
348
|
+
item.label.on("click", function (self, event) {
|
|
349
|
+
event.stopPropagation();
|
|
350
|
+
selectItem(item);
|
|
351
|
+
});
|
|
352
|
+
item.label.on("mouseenter", function () {
|
|
353
|
+
item.isHover = 1;
|
|
354
|
+
paintSelection(item);
|
|
355
|
+
});
|
|
356
|
+
item.label.on("mouseleave", function () {
|
|
357
|
+
item.isHover = 0;
|
|
358
|
+
paintSelection(item);
|
|
359
|
+
});
|
|
360
|
+
item.label.on("keydown", function (self, event) {
|
|
361
|
+
onItemKeyDown(item, event);
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const updateEmpty = function () {
|
|
366
|
+
box.lblEmpty.visible = (items.length == 0) ? 1 : 0;
|
|
367
|
+
if (box.listScrollBar) box.listScrollBar.refreshScroll();
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const renderList = function () {
|
|
371
|
+
if (box.listWrapper) box.listWrapper.remove();
|
|
372
|
+
createIn(box.listArea, function () {
|
|
373
|
+
// GROUP: Labels, one under the other
|
|
374
|
+
box.listWrapper = VGroup({
|
|
375
|
+
width: "100%",
|
|
376
|
+
height: "auto",
|
|
377
|
+
align: "left top",
|
|
378
|
+
gap: _s.list.gap,
|
|
379
|
+
padding: _s.list.padding,
|
|
380
|
+
});
|
|
381
|
+
box.listWrapper.position = "relative"; // WHY: The scroll box grows with it.
|
|
382
|
+
box.listWrapper.role = "listbox";
|
|
383
|
+
box.listWrapper.aria = { label: box.texts.title };
|
|
384
|
+
endGroup();
|
|
385
|
+
});
|
|
386
|
+
items.forEach(createItemView);
|
|
387
|
+
updateEmpty();
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const selectItem = function (item) {
|
|
391
|
+
const previous = selected;
|
|
392
|
+
selected = item || null;
|
|
393
|
+
if (previous && previous.label) paintSelection(previous);
|
|
394
|
+
if (selected) {
|
|
395
|
+
paintSelection(selected);
|
|
396
|
+
selected.label.elem.scrollIntoView({ block: "nearest" });
|
|
397
|
+
loadPanel();
|
|
398
|
+
box.sidePanel.open();
|
|
399
|
+
} else if (box.sidePanel.isOpened === 1) {
|
|
400
|
+
isClosingPanel = 1;
|
|
401
|
+
box.sidePanel.close();
|
|
402
|
+
isClosingPanel = 0;
|
|
403
|
+
}
|
|
404
|
+
if (previous !== selected) box.onSelect(box, indexOfItem(selected));
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// A property was changed in the panel.
|
|
408
|
+
const setProp = function (key, value) {
|
|
409
|
+
if (!selected) return;
|
|
410
|
+
const next = normalizeProps(Object.assign({}, selected.props, { [key]: value }), selected.props);
|
|
411
|
+
if (next[key] === selected.props[key]) return;
|
|
412
|
+
selected.props = next;
|
|
413
|
+
if (key !== "text" && selected.styleName) selected.styleChanged = 1;
|
|
414
|
+
applyProps(selected);
|
|
415
|
+
updatePanelStyleInfo();
|
|
416
|
+
labelsChanged();
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// *** PANEL:
|
|
420
|
+
|
|
421
|
+
// The values of the selected label -> the controls. (silent: the controls do not call onChange)
|
|
422
|
+
const loadPanel = function () {
|
|
423
|
+
if (!selected) return;
|
|
424
|
+
const p = selected.props;
|
|
425
|
+
controls.text.text = p.text;
|
|
426
|
+
controls.fontSize.setValue(p.fontSize, 1);
|
|
427
|
+
controls.bold.setChecked(p.bold, 1);
|
|
428
|
+
controls.italic.setChecked(p.italic, 1);
|
|
429
|
+
controls.align.setValue(p.textAlign, 1);
|
|
430
|
+
controls.width.setValue(p.fullWidth ? "full" : "auto", 1);
|
|
431
|
+
controls.textColor.setColor(p.textColor, 1);
|
|
432
|
+
controls.background.setValue(p.color ? "color" : "none", 1);
|
|
433
|
+
controls.bgColor.setColor(p.color || DEFAULT_BACKGROUND, 1);
|
|
434
|
+
controls.bgField.visible = p.color ? 1 : 0;
|
|
435
|
+
controls.padding.setValue(p.padding, 1);
|
|
436
|
+
controls.round.setValue(p.round, 1);
|
|
437
|
+
controls.border.setValue(p.border, 1);
|
|
438
|
+
controls.borderColor.setColor(p.borderColor, 1);
|
|
439
|
+
controls.styleName.text = selected.styleName || "";
|
|
440
|
+
updatePanelStyleInfo();
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const updatePanelStyleInfo = function () {
|
|
444
|
+
if (!box.lblStyleInfo) return;
|
|
445
|
+
if (selected && selected.styleName) {
|
|
446
|
+
const changedText = (selected.styleChanged) ? " " + box.texts.changed : "";
|
|
447
|
+
box.lblStyleInfo.plainText = box.texts.currentStyle.replace("{name}", selected.styleName) + changedText;
|
|
448
|
+
} else {
|
|
449
|
+
box.lblStyleInfo.plainText = box.texts.noStyle;
|
|
450
|
+
}
|
|
451
|
+
renderChips();
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const applyStyleToSelected = function (name) {
|
|
455
|
+
if (!selected) return;
|
|
456
|
+
box.applyStyle(name, indexOfItem(selected));
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// GROUP: Chip of a saved style (name drawn with the style, delete button)
|
|
460
|
+
const createChip = function (st) {
|
|
461
|
+
|
|
462
|
+
const isCurrent = (selected && selected.styleName === st.name);
|
|
463
|
+
const chip = HGroup({
|
|
464
|
+
width: "auto",
|
|
465
|
+
height: "auto",
|
|
466
|
+
align: "left center",
|
|
467
|
+
gap: 4,
|
|
468
|
+
padding: [10, 4],
|
|
469
|
+
color: _s.chip.color,
|
|
470
|
+
round: _s.chip.round,
|
|
471
|
+
border: isCurrent ? 2 : 1,
|
|
472
|
+
borderColor: isCurrent ? _s.chip.activeBorderColor : _s.chip.borderColor,
|
|
473
|
+
});
|
|
474
|
+
chip.cursor = "pointer";
|
|
475
|
+
chip.css.maxWidth = "100%";
|
|
476
|
+
chip.role = "button";
|
|
477
|
+
chip.elem.setAttribute("title", box.texts.applyHint);
|
|
478
|
+
chip.tabIndex = 0;
|
|
479
|
+
chip.clickable = 1;
|
|
480
|
+
|
|
481
|
+
// LABEL: Name, drawn with the style (preview)
|
|
482
|
+
const props = st.props;
|
|
483
|
+
const lblPreview = Label({
|
|
484
|
+
plainText: st.name,
|
|
485
|
+
fontSize: Math.min(CHIP_FONT_MAX, Math.max(CHIP_FONT_MIN, props.fontSize)),
|
|
486
|
+
textColor: props.textColor,
|
|
487
|
+
color: props.color || "transparent",
|
|
488
|
+
bold: props.bold,
|
|
489
|
+
italic: props.italic,
|
|
490
|
+
padding: props.color ? [6, 1] : 0,
|
|
491
|
+
round: 4,
|
|
492
|
+
ellipsis: 1,
|
|
493
|
+
});
|
|
494
|
+
lblPreview.css.maxWidth = "160px";
|
|
495
|
+
|
|
496
|
+
// LABEL: Delete the style
|
|
497
|
+
const btnX = Label({ text: LabelEditor.getCloseSvg(_s.chip.closeColor, 12), width: 18, height: 18, round: 9, clickable: 1 });
|
|
498
|
+
btnX.elem.style.display = "flex";
|
|
499
|
+
btnX.css = { alignItems: "center", justifyContent: "center" };
|
|
500
|
+
btnX.lineHeight = "0";
|
|
501
|
+
btnX.role = "button";
|
|
502
|
+
btnX.aria = { label: box.texts.removeStyle + ": " + st.name };
|
|
503
|
+
btnX.on("click", function (self, event) {
|
|
504
|
+
event.stopPropagation();
|
|
505
|
+
box.removeStyle(st.name);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
endGroup();
|
|
509
|
+
|
|
510
|
+
chip.on("click", function () {
|
|
511
|
+
applyStyleToSelected(st.name);
|
|
512
|
+
});
|
|
513
|
+
chip.on("keydown", function (self, event) {
|
|
514
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
515
|
+
event.preventDefault();
|
|
516
|
+
applyStyleToSelected(st.name);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// Chips of the saved styles (with a small preview of each style).
|
|
522
|
+
const renderChips = function () {
|
|
523
|
+
if (!box.chipHolder) return;
|
|
524
|
+
if (box.chipWrapper) box.chipWrapper.remove();
|
|
525
|
+
createIn(box.chipHolder, function () {
|
|
526
|
+
box.chipWrapper = HGroup({ width: "100%", height: "auto", align: "left top", gap: 6, wrap: 1 });
|
|
527
|
+
box.chipWrapper.position = "relative";
|
|
528
|
+
if (styles.length == 0) {
|
|
529
|
+
Label({ plainText: box.texts.noStyles, width: "100%", fontSize: 12, textColor: _s.panel.hintColor });
|
|
530
|
+
}
|
|
531
|
+
styles.forEach(createChip);
|
|
532
|
+
endGroup();
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// *** PANEL CONTROLS (views):
|
|
537
|
+
|
|
538
|
+
// GROUP: A caption and its control(s). Close it with endGroup().
|
|
539
|
+
const startField = function (caption) {
|
|
540
|
+
const group = VGroup({ width: "100%", height: "auto", align: "left top", gap: 6 });
|
|
541
|
+
group.css.alignItems = "stretch";
|
|
542
|
+
Label({ plainText: caption, fontSize: 12, textColor: _s.panel.captionColor });
|
|
543
|
+
return group;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// GROUP: Two fields side by side
|
|
547
|
+
const startRow = function () {
|
|
548
|
+
const row = HGroup({ width: "100%", height: "auto", align: "left top", gap: 12 });
|
|
549
|
+
row.css.alignItems = "flex-start";
|
|
550
|
+
return row;
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
// GROUP: A field in a row (half of it)
|
|
554
|
+
const startHalfField = function (caption) {
|
|
555
|
+
const group = startField(caption);
|
|
556
|
+
group.width = "auto";
|
|
557
|
+
group.css = { flex: "1 1 0", minWidth: "0" };
|
|
558
|
+
return group;
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// INPUT: basic.js Input
|
|
562
|
+
const createTextInput = function (onInput) {
|
|
563
|
+
const input = Input({
|
|
564
|
+
width: "100%",
|
|
565
|
+
height: _s.input.height,
|
|
566
|
+
minimal: 1,
|
|
567
|
+
fontSize: 14,
|
|
568
|
+
color: _s.input.color,
|
|
569
|
+
textColor: _s.input.textColor,
|
|
570
|
+
round: _s.input.round,
|
|
571
|
+
border: 1,
|
|
572
|
+
borderColor: _s.input.borderColor,
|
|
573
|
+
});
|
|
574
|
+
const el = input.inputElement;
|
|
575
|
+
el.style.width = "100%";
|
|
576
|
+
el.style.height = "100%";
|
|
577
|
+
el.style.boxSizing = "border-box";
|
|
578
|
+
el.style.padding = "0px 10px";
|
|
579
|
+
el.style.backgroundColor = "transparent";
|
|
580
|
+
el.style.color = _s.input.textColor;
|
|
581
|
+
input.shrink = 0;
|
|
582
|
+
el.addEventListener("focus", function () {
|
|
583
|
+
input.borderColor = _s.input.focusColor;
|
|
584
|
+
});
|
|
585
|
+
el.addEventListener("blur", function () {
|
|
586
|
+
input.borderColor = _s.input.borderColor;
|
|
587
|
+
});
|
|
588
|
+
el.addEventListener("input", function () {
|
|
589
|
+
onInput(input.text);
|
|
590
|
+
});
|
|
591
|
+
return input;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// STEPPER: A number
|
|
595
|
+
const createStepper = function (min, max, ariaLabel, key) {
|
|
596
|
+
return Stepper({
|
|
597
|
+
width: "100%", height: _s.input.height, value: min, minValue: min, maxValue: max, ariaLabel: ariaLabel,
|
|
598
|
+
styleName: _s.stepperStyleName, style: copyStyle(_s.stepperStyle),
|
|
599
|
+
onChange: function (self) { setProp(key, self.value); },
|
|
600
|
+
});
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// SELECT COLOR: A color from the palette
|
|
604
|
+
const createColor = function (key, onPick) {
|
|
605
|
+
const picker = ColorPicker({
|
|
606
|
+
width: "100%", height: _s.input.height, colors: box.colorPalette.slice(),
|
|
607
|
+
styleName: _s.selectColorStyleName, style: copyStyle(_s.selectColorStyle),
|
|
608
|
+
onChange: function (self) {
|
|
609
|
+
if (!self.value) return;
|
|
610
|
+
if (onPick) {
|
|
611
|
+
onPick(self.value);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
setProp(key, self.value);
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
return picker;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// TABS: Pill tabs, one is on (like a segmented control)
|
|
621
|
+
const createPills = function (tabs, onPick) {
|
|
622
|
+
return Tabs({
|
|
623
|
+
scale: 1, // WHY: the rest of this component is not scaled (basic.uiScale): its tab bar must not be either
|
|
624
|
+
width: "100%", variant: "pill", fullWidth: 1, tabs: tabs, value: tabs[0].key,
|
|
625
|
+
styleName: _s.tabsStyleName, style: copyStyle(_s.tabsStyle),
|
|
626
|
+
onChange: function (self) { onPick(self.value); },
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
// CHECKBOX: On / off
|
|
631
|
+
const createCheck = function (text, key) {
|
|
632
|
+
return CheckBox({
|
|
633
|
+
labelText: text, styleName: _s.checkBoxStyleName, style: copyStyle(_s.checkBoxStyle),
|
|
634
|
+
onChange: function (self) { setProp(key, self.checked); },
|
|
635
|
+
});
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// BUTTON: basic.js Button in the colors of the editor
|
|
639
|
+
const createEditorButton = function (text, isPrimary, onClick) {
|
|
640
|
+
const colors = isPrimary ? _s.button : _s.secondaryButton;
|
|
641
|
+
const btn = Button({
|
|
642
|
+
text: text,
|
|
643
|
+
width: "auto",
|
|
644
|
+
height: _s.button.height,
|
|
645
|
+
fontSize: _s.button.fontSize,
|
|
646
|
+
color: colors.color,
|
|
647
|
+
textColor: colors.textColor,
|
|
648
|
+
round: _s.button.round,
|
|
649
|
+
});
|
|
650
|
+
// WHY: basic.css gives a Button an image and an inner shadow.
|
|
651
|
+
btn.css = {
|
|
652
|
+
backgroundImage: "none",
|
|
653
|
+
boxShadow: "none",
|
|
654
|
+
border: "0",
|
|
655
|
+
padding: "0px 16px",
|
|
656
|
+
whiteSpace: "nowrap",
|
|
657
|
+
transition: BUTTON_MOTION,
|
|
658
|
+
};
|
|
659
|
+
btn.shrink = 0;
|
|
660
|
+
btn.on("mouseenter", function () {
|
|
661
|
+
btn.color = colors.hoverColor;
|
|
662
|
+
});
|
|
663
|
+
btn.on("mouseleave", function () {
|
|
664
|
+
btn.color = colors.color;
|
|
665
|
+
});
|
|
666
|
+
btn.on("click", onClick);
|
|
667
|
+
return btn;
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
// *** PUBLIC FUNCTIONS:
|
|
671
|
+
|
|
672
|
+
// Adds a label at the end. select: 1 -> it is selected (the panel opens). Returns its index.
|
|
673
|
+
box.addLabel = function (props = {}, select = 0) {
|
|
674
|
+
labelCount++;
|
|
675
|
+
const p = normalizeProps(props);
|
|
676
|
+
if (!props || props.text === undefined) p.text = String(box.newLabel.text || "").replace("{n}", String(labelCount));
|
|
677
|
+
const item = { props: p, styleName: "", styleChanged: 0, label: null };
|
|
678
|
+
const styleName = props && props.styleName;
|
|
679
|
+
if (styleName && findStyle(styleName)) item.styleName = styleName;
|
|
680
|
+
items.push(item);
|
|
681
|
+
createItemView(item);
|
|
682
|
+
updateEmpty();
|
|
683
|
+
if (select) {
|
|
684
|
+
selectItem(item);
|
|
685
|
+
item.label.elem.focus({ preventScroll: true });
|
|
686
|
+
}
|
|
687
|
+
labelsChanged();
|
|
688
|
+
return items.length - 1;
|
|
689
|
+
};
|
|
690
|
+
// USAGE: editor.addLabel({ text: "Hello", fontSize: 24, bold: 1 })
|
|
691
|
+
|
|
692
|
+
box.removeLabel = function (index) {
|
|
693
|
+
const item = items[index];
|
|
694
|
+
if (!item) return;
|
|
695
|
+
if (item === selected) selectItem(null);
|
|
696
|
+
items.splice(index, 1);
|
|
697
|
+
item.label.remove();
|
|
698
|
+
updateEmpty();
|
|
699
|
+
const next = items[Math.min(index, items.length - 1)];
|
|
700
|
+
if (next && box.elem.contains(document.activeElement) === false) next.label.elem.focus({ preventScroll: true });
|
|
701
|
+
labelsChanged();
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
box.duplicateLabel = function (index) {
|
|
705
|
+
const item = items[index];
|
|
706
|
+
if (!item) return -1;
|
|
707
|
+
const copy = Object.assign({}, item.props, { styleName: item.styleName });
|
|
708
|
+
const newIndex = box.addLabel(copy, 0);
|
|
709
|
+
items[newIndex].styleChanged = item.styleChanged;
|
|
710
|
+
// The copy goes right under the original.
|
|
711
|
+
box.moveLabel(newIndex, index + 1);
|
|
712
|
+
selectItem(items[index + 1]);
|
|
713
|
+
return index + 1;
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
box.moveLabel = function (fromIndex, toIndex) {
|
|
717
|
+
const item = items[fromIndex];
|
|
718
|
+
if (!item) return;
|
|
719
|
+
const to = Math.max(0, Math.min(toIndex, items.length - 1));
|
|
720
|
+
items.splice(fromIndex, 1);
|
|
721
|
+
items.splice(to, 0, item);
|
|
722
|
+
const next = items[to + 1];
|
|
723
|
+
box.listWrapper.elem.insertBefore(item.label.elem, next ? next.label.elem : null);
|
|
724
|
+
labelsChanged();
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
// index: -1 -> nothing is selected (the panel closes).
|
|
728
|
+
box.selectLabel = function (index) {
|
|
729
|
+
selectItem(items[index] || null);
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
box.getSelectedIndex = function () {
|
|
733
|
+
return indexOfItem(selected);
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
box.getLabels = function () {
|
|
737
|
+
return items.map(function (item) { return Object.assign({}, item.props, { styleName: item.styleName }); });
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// onChange is not called.
|
|
741
|
+
box.setLabels = function (list) {
|
|
742
|
+
selectItem(null);
|
|
743
|
+
labelCount = 0;
|
|
744
|
+
items = (Array.isArray(list) ? list : []).map(function (src) {
|
|
745
|
+
labelCount++;
|
|
746
|
+
const styleName = (src && src.styleName && findStyle(src.styleName)) ? src.styleName : "";
|
|
747
|
+
return { props: normalizeProps(src), styleName: styleName, styleChanged: 0, label: null };
|
|
748
|
+
});
|
|
749
|
+
renderList();
|
|
750
|
+
box.labels = box.getLabels();
|
|
751
|
+
};
|
|
752
|
+
// USAGE: editor.setLabels(savedWork) // savedWork = editor.getLabels() from before
|
|
753
|
+
|
|
754
|
+
// Saves the style of the label at index (default: the selected one) with a name.
|
|
755
|
+
// The same name again: the style is updated, and every label that uses it gets the new style.
|
|
756
|
+
box.saveStyle = function (name, index = -1) {
|
|
757
|
+
const item = (index >= 0) ? items[index] : selected;
|
|
758
|
+
name = String(name ?? "").trim();
|
|
759
|
+
if (!item || !name) return 0;
|
|
760
|
+
const props = pickStyleProps(item.props);
|
|
761
|
+
const existing = findStyle(name);
|
|
762
|
+
if (existing) existing.props = props;
|
|
763
|
+
else styles.push({ name: name, props: props });
|
|
764
|
+
item.styleName = name;
|
|
765
|
+
item.styleChanged = 0;
|
|
766
|
+
// Linked labels follow the style.
|
|
767
|
+
let changedOthers = 0;
|
|
768
|
+
items.forEach(function (other) {
|
|
769
|
+
if (other !== item && other.styleName === name) {
|
|
770
|
+
other.props = normalizeProps(Object.assign({}, other.props, props), other.props);
|
|
771
|
+
other.styleChanged = 0;
|
|
772
|
+
applyProps(other);
|
|
773
|
+
changedOthers = 1;
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
applyProps(item);
|
|
777
|
+
stylesChanged();
|
|
778
|
+
if (changedOthers || existing) labelsChanged();
|
|
779
|
+
return 1;
|
|
780
|
+
};
|
|
781
|
+
// USAGE: editor.saveStyle("Title") // the selected label
|
|
782
|
+
|
|
783
|
+
box.applyStyle = function (name, index = -1) {
|
|
784
|
+
const item = (index >= 0) ? items[index] : selected;
|
|
785
|
+
const st = findStyle(name);
|
|
786
|
+
if (!item || !st) return 0;
|
|
787
|
+
item.props = normalizeProps(Object.assign({}, item.props, st.props), item.props);
|
|
788
|
+
item.styleName = st.name;
|
|
789
|
+
item.styleChanged = 0;
|
|
790
|
+
applyProps(item);
|
|
791
|
+
if (item === selected) loadPanel();
|
|
792
|
+
else renderChips();
|
|
793
|
+
labelsChanged();
|
|
794
|
+
return 1;
|
|
795
|
+
};
|
|
796
|
+
// USAGE: editor.applyStyle("Title", 2)
|
|
797
|
+
|
|
798
|
+
// The labels that used it keep their look, they only lose the link.
|
|
799
|
+
box.removeStyle = function (name) {
|
|
800
|
+
const index = styles.findIndex(function (st) { return st.name === name; });
|
|
801
|
+
if (index < 0) return;
|
|
802
|
+
styles.splice(index, 1);
|
|
803
|
+
items.forEach(function (item) {
|
|
804
|
+
if (item.styleName !== name) return;
|
|
805
|
+
item.styleName = "";
|
|
806
|
+
item.styleChanged = 0;
|
|
807
|
+
applyProps(item);
|
|
808
|
+
});
|
|
809
|
+
stylesChanged();
|
|
810
|
+
labelsChanged();
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
box.getSavedStyles = function () {
|
|
814
|
+
return styles.map(function (st) { return { name: st.name, props: Object.assign({}, st.props) }; });
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
// onStylesChange is not called. (It is saved to storageKey.)
|
|
818
|
+
box.setSavedStyles = function (list) {
|
|
819
|
+
styles = [];
|
|
820
|
+
(Array.isArray(list) ? list : []).forEach(function (st) {
|
|
821
|
+
const name = String((st && st.name) ?? "").trim();
|
|
822
|
+
if (!name || findStyle(name)) return;
|
|
823
|
+
styles.push({ name: name, props: pickStyleProps(normalizeProps(st.props)) });
|
|
824
|
+
});
|
|
825
|
+
box.savedStyles = box.getSavedStyles();
|
|
826
|
+
saveStylesToStorage();
|
|
827
|
+
renderChips();
|
|
828
|
+
updatePanelStyleInfo();
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
box.refresh = function () {
|
|
832
|
+
items.forEach(applyProps);
|
|
833
|
+
updateEmpty();
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
// *** OBJECT VIEW:
|
|
838
|
+
|
|
839
|
+
box.clipContent = 1;
|
|
840
|
+
|
|
841
|
+
// GROUP: Header and list
|
|
842
|
+
box.layout = VGroup({ width: "100%", height: "100%", align: "left top", gap: 0 });
|
|
843
|
+
box.layout.css.alignItems = "stretch";
|
|
844
|
+
|
|
845
|
+
// GROUP: Header (title, add button)
|
|
846
|
+
box.header = HGroup({
|
|
847
|
+
width: "100%",
|
|
848
|
+
height: "auto",
|
|
849
|
+
align: "left center",
|
|
850
|
+
gap: 8,
|
|
851
|
+
padding: [16, 10],
|
|
852
|
+
color: _s.header.color,
|
|
853
|
+
});
|
|
854
|
+
box.header.shrink = 0;
|
|
855
|
+
box.header.css.borderBottom = "1px solid " + _s.header.dividerColor;
|
|
856
|
+
|
|
857
|
+
box.lblTitle = Label({ plainText: box.texts.title, fontSize: _s.header.titleSize, textColor: _s.header.titleColor, bold: 1 });
|
|
858
|
+
box.lblTitle.css.flex = "1 1 0";
|
|
859
|
+
|
|
860
|
+
box.btnAdd = createEditorButton(box.texts.addButton, 1, function () { box.addLabel({}, 1); });
|
|
861
|
+
|
|
862
|
+
endGroup();
|
|
863
|
+
|
|
864
|
+
// BOX: Holder of the list (and its ScrollBar)
|
|
865
|
+
box.listHolder = startBox({ width: "100%", height: "auto", color: _s.list.color });
|
|
866
|
+
box.listHolder.css = { flex: "1 1 0", minHeight: "0" };
|
|
867
|
+
|
|
868
|
+
// BOX: Scrolling list area
|
|
869
|
+
box.listArea = Box(0, 0, "100%", "100%", { color: "transparent", scrollY: 1 });
|
|
870
|
+
box.listArea.clickable = 1;
|
|
871
|
+
|
|
872
|
+
// LABEL: Empty text
|
|
873
|
+
box.lblEmpty = Label({
|
|
874
|
+
plainText: box.texts.empty,
|
|
875
|
+
width: "100%",
|
|
876
|
+
top: 40,
|
|
877
|
+
fontSize: 14,
|
|
878
|
+
textColor: _s.list.emptyColor,
|
|
879
|
+
textAlign: "center",
|
|
880
|
+
padding: [24, 0],
|
|
881
|
+
visible: 0,
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
if (box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
|
|
885
|
+
const scrollBarParams = { scrollableBox: box.listArea, neverHide: 0, showDots: 0 };
|
|
886
|
+
box.listScrollBar = ScrollBar(Object.assign(scrollBarParams, _s.scrollBar));
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
endBox();
|
|
890
|
+
|
|
891
|
+
endGroup();
|
|
892
|
+
|
|
893
|
+
// The focus is in the panel, or nowhere: it can go back to the label.
|
|
894
|
+
const isFocusInPanelOrNowhere = function () {
|
|
895
|
+
const active = document.activeElement;
|
|
896
|
+
if (!active || active === document.body) return true;
|
|
897
|
+
return !!(box.sidePanel && box.sidePanel.elem.contains(active));
|
|
898
|
+
};
|
|
899
|
+
|
|
900
|
+
// SIDE PANEL: Properties. Created on the page (SidePanel does it), at the right side of the screen.
|
|
901
|
+
box.sidePanel = SidePanel({
|
|
902
|
+
side: "right",
|
|
903
|
+
panelSize: box.panelWidth,
|
|
904
|
+
titleText: box.texts.panelTitle,
|
|
905
|
+
ariaLabel: box.texts.panelTitle,
|
|
906
|
+
showBackdrop: 0, // WHY: The labels stay clickable while the panel is open.
|
|
907
|
+
closeOnEscape: 1,
|
|
908
|
+
styleName: _s.sidePanelStyleName,
|
|
909
|
+
style: copyStyle(_s.sidePanelStyle),
|
|
910
|
+
onClose: function () {
|
|
911
|
+
if (isClosingPanel || !box || !selected) return;
|
|
912
|
+
const item = selected;
|
|
913
|
+
selectItem(null);
|
|
914
|
+
if (item.label && isFocusInPanelOrNowhere()) item.label.elem.focus({ preventScroll: true });
|
|
915
|
+
},
|
|
916
|
+
});
|
|
917
|
+
box.own(box.sidePanel); // WHY: It is on the page, not in the box: removed with the box.
|
|
918
|
+
|
|
919
|
+
box.sidePanel.startBody();
|
|
920
|
+
|
|
921
|
+
// GROUP: Panel content
|
|
922
|
+
box.panelContent = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.panel.gap });
|
|
923
|
+
box.panelContent.css.alignItems = "stretch";
|
|
924
|
+
|
|
925
|
+
startField(box.texts.text);
|
|
926
|
+
controls.text = createTextInput(function (value) { setProp("text", value); });
|
|
927
|
+
controls.text.inputElement.setAttribute("aria-label", box.texts.text);
|
|
928
|
+
endGroup();
|
|
929
|
+
|
|
930
|
+
startRow();
|
|
931
|
+
startHalfField(box.texts.fontSize);
|
|
932
|
+
controls.fontSize = createStepper(LIMITS.fontSize.min, LIMITS.fontSize.max, box.texts.fontSize, "fontSize");
|
|
933
|
+
endGroup();
|
|
934
|
+
startHalfField(box.texts.fontStyle);
|
|
935
|
+
// GROUP: Bold, italic
|
|
936
|
+
VGroup({ width: "100%", height: "auto", align: "left top", gap: 4 });
|
|
937
|
+
controls.bold = createCheck(box.texts.bold, "bold");
|
|
938
|
+
controls.italic = createCheck(box.texts.italic, "italic");
|
|
939
|
+
endGroup();
|
|
940
|
+
endGroup();
|
|
941
|
+
endGroup();
|
|
942
|
+
|
|
943
|
+
startField(box.texts.align);
|
|
944
|
+
const alignTabs = [
|
|
945
|
+
{ key: "left", text: box.texts.left },
|
|
946
|
+
{ key: "center", text: box.texts.center },
|
|
947
|
+
{ key: "right", text: box.texts.right },
|
|
948
|
+
];
|
|
949
|
+
controls.align = createPills(alignTabs, function (value) {
|
|
950
|
+
setProp("textAlign", value);
|
|
951
|
+
});
|
|
952
|
+
endGroup();
|
|
953
|
+
|
|
954
|
+
startField(box.texts.width);
|
|
955
|
+
const widthTabs = [
|
|
956
|
+
{ key: "auto", text: box.texts.widthAuto },
|
|
957
|
+
{ key: "full", text: box.texts.widthFull },
|
|
958
|
+
];
|
|
959
|
+
controls.width = createPills(widthTabs, function (value) {
|
|
960
|
+
setProp("fullWidth", (value === "full") ? 1 : 0);
|
|
961
|
+
});
|
|
962
|
+
endGroup();
|
|
963
|
+
|
|
964
|
+
startField(box.texts.textColor);
|
|
965
|
+
controls.textColor = createColor("textColor");
|
|
966
|
+
endGroup();
|
|
967
|
+
|
|
968
|
+
startField(box.texts.background);
|
|
969
|
+
controls.background = createPills([{ key: "none", text: box.texts.none }, { key: "color", text: box.texts.colorOn }], function (value) {
|
|
970
|
+
setProp("color", (value === "color") ? controls.bgColor.value || DEFAULT_BACKGROUND : "");
|
|
971
|
+
controls.bgField.visible = (value === "color") ? 1 : 0;
|
|
972
|
+
});
|
|
973
|
+
endGroup();
|
|
974
|
+
|
|
975
|
+
controls.bgField = startField(box.texts.backgroundColor);
|
|
976
|
+
controls.bgColor = createColor("color");
|
|
977
|
+
endGroup();
|
|
978
|
+
|
|
979
|
+
startRow();
|
|
980
|
+
startHalfField(box.texts.padding);
|
|
981
|
+
controls.padding = createStepper(LIMITS.padding.min, LIMITS.padding.max, box.texts.padding, "padding");
|
|
982
|
+
endGroup();
|
|
983
|
+
startHalfField(box.texts.round);
|
|
984
|
+
controls.round = createStepper(LIMITS.round.min, LIMITS.round.max, box.texts.round, "round");
|
|
985
|
+
endGroup();
|
|
986
|
+
endGroup();
|
|
987
|
+
|
|
988
|
+
startRow();
|
|
989
|
+
startHalfField(box.texts.border);
|
|
990
|
+
controls.border = createStepper(LIMITS.border.min, LIMITS.border.max, box.texts.border, "border");
|
|
991
|
+
endGroup();
|
|
992
|
+
startHalfField(box.texts.borderColor);
|
|
993
|
+
controls.borderColor = createColor("borderColor");
|
|
994
|
+
endGroup();
|
|
995
|
+
endGroup();
|
|
996
|
+
|
|
997
|
+
// GROUP: Duplicate, delete
|
|
998
|
+
HGroup({ width: "100%", height: "auto", align: "left center", gap: 8 });
|
|
999
|
+
box.btnDuplicate = createEditorButton(box.texts.duplicate, 0, function () {
|
|
1000
|
+
if (!selected) return;
|
|
1001
|
+
box.duplicateLabel(indexOfItem(selected));
|
|
1002
|
+
});
|
|
1003
|
+
box.btnRemove = createEditorButton(box.texts.remove, 0, function () {
|
|
1004
|
+
if (!selected) return;
|
|
1005
|
+
box.removeLabel(indexOfItem(selected));
|
|
1006
|
+
});
|
|
1007
|
+
box.btnRemove.textColor = _s.secondaryButton.dangerTextColor;
|
|
1008
|
+
endGroup();
|
|
1009
|
+
|
|
1010
|
+
// BOX: Divider
|
|
1011
|
+
Box({ width: "100%", height: 1, color: _s.panel.dividerColor });
|
|
1012
|
+
that.shrink = 0;
|
|
1013
|
+
|
|
1014
|
+
// GROUP: Saved styles
|
|
1015
|
+
startField(box.texts.savedStyles);
|
|
1016
|
+
box.lblStyleInfo = Label({ plainText: "", width: "100%", fontSize: 12, textColor: _s.panel.textColor });
|
|
1017
|
+
HGroup({ width: "100%", height: "auto", align: "left center", gap: 8 });
|
|
1018
|
+
controls.styleName = createTextInput(function () { controls.styleName.borderColor = _s.input.focusColor; });
|
|
1019
|
+
controls.styleName.width = "auto";
|
|
1020
|
+
controls.styleName.css = { flex: "1 1 0", minWidth: "0" };
|
|
1021
|
+
controls.styleName.inputElement.placeholder = box.texts.styleNamePlaceholder;
|
|
1022
|
+
controls.styleName.inputElement.setAttribute("aria-label", box.texts.styleNamePlaceholder);
|
|
1023
|
+
box.btnSaveStyle = createEditorButton(box.texts.save, 1, function () {
|
|
1024
|
+
const name = String(controls.styleName.text || "").trim();
|
|
1025
|
+
if (!name) {
|
|
1026
|
+
controls.styleName.inputElement.focus();
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
box.saveStyle(name);
|
|
1030
|
+
});
|
|
1031
|
+
endGroup();
|
|
1032
|
+
// BOX: Chips of the saved styles
|
|
1033
|
+
box.chipHolder = startBox({ width: "100%", height: "auto", color: "transparent" });
|
|
1034
|
+
endBox();
|
|
1035
|
+
Label({ plainText: box.texts.applyHint, width: "100%", fontSize: 11, textColor: _s.panel.hintColor });
|
|
1036
|
+
endGroup();
|
|
1037
|
+
|
|
1038
|
+
endGroup();
|
|
1039
|
+
|
|
1040
|
+
box.sidePanel.endBody();
|
|
1041
|
+
|
|
1042
|
+
// *** OBJECT INIT CODE:
|
|
1043
|
+
|
|
1044
|
+
controls.styleName.inputElement.addEventListener("keydown", function (event) {
|
|
1045
|
+
if (event.key !== "Enter") return;
|
|
1046
|
+
event.preventDefault();
|
|
1047
|
+
box.btnSaveStyle.elem.click();
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
const isClickOnEmptyList = function (event) {
|
|
1051
|
+
if (!box.listWrapper) return true;
|
|
1052
|
+
if (!box.listWrapper.elem.contains(event.target)) return true;
|
|
1053
|
+
return event.target === box.listWrapper.elem;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
// A click on the empty part of the list closes the panel.
|
|
1057
|
+
box.listArea.on("click", function (self, event) {
|
|
1058
|
+
if (isClickOnEmptyList(event)) selectItem(null);
|
|
1059
|
+
});
|
|
1060
|
+
box.on("keydown", function (self, event) {
|
|
1061
|
+
if (event.key !== "Escape" || !selected) return;
|
|
1062
|
+
event.preventDefault();
|
|
1063
|
+
const item = selected;
|
|
1064
|
+
selectItem(null);
|
|
1065
|
+
item.label.elem.focus({ preventScroll: true });
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// Saved styles: storage first, then the savedStyles parameter.
|
|
1069
|
+
let storedStyles = null;
|
|
1070
|
+
if (box.storageKey) {
|
|
1071
|
+
try {
|
|
1072
|
+
storedStyles = basic.storage.load(box.storageKey);
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
storedStyles = null;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
box.setSavedStyles(Array.isArray(storedStyles) ? storedStyles : startStyles);
|
|
1078
|
+
box.setLabels(startLabels);
|
|
1079
|
+
|
|
1080
|
+
return endObject(box);
|
|
1081
|
+
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
// *** STATIC FUNCTIONS:
|
|
1085
|
+
|
|
1086
|
+
LabelEditor.getCloseSvg = function (color, size) {
|
|
1087
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.4" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>';
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
// *** STYLE PACKAGES:
|
|
1091
|
+
// USAGE: LabelEditor({ styleName: "dark" })
|
|
1092
|
+
// USAGE: LabelEditor({ style: { selection: { color: "tomato" } } }) // Change only some keys.
|
|
1093
|
+
// USAGE: LabelEditor({ style: LabelEditor.styles.light }) // The same as styleName: "light". (The package is copied, never changed.)
|
|
1094
|
+
// NOTE: "dark" is a package of params (it has a "style" key): it also gives new labels a light text color and a palette for the dark list. Use it with styleName: "dark".
|
|
1095
|
+
// NOTE: A new package needs only the keys that differ from the default (classic) style.
|
|
1096
|
+
// NOTE: xxxStyleName / xxxStyle: the style package and the style changes of the components in the panel.
|
|
1097
|
+
LabelEditor.styles = {
|
|
1098
|
+
|
|
1099
|
+
// Light gray work area, white header and panel.
|
|
1100
|
+
light: LabelEditorDefaults.style,
|
|
1101
|
+
|
|
1102
|
+
// Dark theme, same colors as SidePanel, Stepper and Tabs "dark".
|
|
1103
|
+
// A package of params (basic.js v26.10.27): "style" is the look, "newLabel" the new labels, "colorPalette" the color pickers.
|
|
1104
|
+
dark: {
|
|
1105
|
+
style: {
|
|
1106
|
+
box: { color: "#1C1C1B", border: 1, borderColor: "rgba(255, 255, 255, 0.10)", round: 10 },
|
|
1107
|
+
header: { color: "#232322", dividerColor: "rgba(255, 255, 255, 0.08)", titleColor: "rgba(255, 255, 255, 0.9)", titleSize: 15 },
|
|
1108
|
+
list: { color: "#1C1C1B", padding: 24, gap: 12, emptyColor: "rgba(255, 255, 255, 0.4)" },
|
|
1109
|
+
selection: { color: "#65A293", hoverColor: "rgba(101, 162, 147, 0.45)" },
|
|
1110
|
+
button: { color: "#3D7A6B", textColor: White(1), hoverColor: "#4A8A7A", round: 6, fontSize: 13, height: 36 },
|
|
1111
|
+
secondaryButton: { color: "rgba(255, 255, 255, 0.08)", textColor: "rgba(255, 255, 255, 0.85)", hoverColor: "rgba(255, 255, 255, 0.14)", dangerTextColor: "#E57B6B" },
|
|
1112
|
+
panel: { dividerColor: "rgba(255, 255, 255, 0.08)", gap: 18, captionColor: "rgba(255, 255, 255, 0.5)", textColor: "rgba(255, 255, 255, 0.9)", hintColor: "rgba(255, 255, 255, 0.4)" },
|
|
1113
|
+
input: { color: "#2A2A29", borderColor: "rgba(255, 255, 255, 0.12)", focusColor: "#65A293", textColor: "rgba(255, 255, 255, 0.9)", round: 6, height: 38 },
|
|
1114
|
+
chip: { color: "#2A2A29", borderColor: "rgba(255, 255, 255, 0.12)", activeBorderColor: "#65A293", round: 16, closeColor: "rgba(255, 255, 255, 0.5)" },
|
|
1115
|
+
sidePanelStyleName: "dark",
|
|
1116
|
+
stepperStyleName: "dark",
|
|
1117
|
+
tabsStyleName: "dark",
|
|
1118
|
+
checkBoxStyleName: "dark",
|
|
1119
|
+
selectColorStyleName: "dark",
|
|
1120
|
+
// WHY: the field is like the other inputs of the panel (input: #2A2A29, round 6).
|
|
1121
|
+
selectColorStyle: {
|
|
1122
|
+
field: { color: "#2A2A29", borderColor: "rgba(255, 255, 255, 0.12)", round: 6 },
|
|
1123
|
+
fieldText: { fontSize: 13 },
|
|
1124
|
+
},
|
|
1125
|
+
scrollBar: { bar_color: "#8A8A88", bar_mouseOverColor: "#BFBFBD", bar_width: 4, bar_round: 3, bar_opacity: 0.4, bar_mouseOverOpacity: 0.9, bar_padding: 2 },
|
|
1126
|
+
},
|
|
1127
|
+
// WHY: the default text color of a new label (#1F2328) is not seen on the dark list.
|
|
1128
|
+
newLabel: { textColor: "#E8E8E6", borderColor: "#E8E8E6" },
|
|
1129
|
+
// WHY: the first colors of the default palette are dark: a text in them is not seen on the dark list.
|
|
1130
|
+
// Light grays and bright colors for the text, dark tints for the backgrounds.
|
|
1131
|
+
colorPalette: [
|
|
1132
|
+
"#FFFFFF", "#E8E8E6", "#B5B5B3", "#7A7A78", "#2A2A29",
|
|
1133
|
+
"#E57B6B", "#F2B45A", "#D9C36A", "#7CC49A", "#65A293",
|
|
1134
|
+
"#6FA8DC", "#8CC8F0", "#A38BEA", "#C98AD6", "#F08DB8",
|
|
1135
|
+
"#3A2523", "#3A3220", "#233528", "#1F2E3A", "#2E2840",
|
|
1136
|
+
],
|
|
1137
|
+
},
|
|
1138
|
+
|
|
1139
|
+
};
|
|
1140
|
+
LabelEditor.styles.classic = LabelEditor.styles.light; // the old name of light: the pages made with it keep their look
|