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,760 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
ToolBar - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT
|
|
8
|
+
- The row of small buttons of a window, under its menus: icons with a hint, lines between the groups of buttons, buttons
|
|
9
|
+
that stay pressed (bold, a view), a button that opens a menu.
|
|
10
|
+
- NEEDS comp/context-menu.js (its menus) and comp/menu-bar.js (its shortcuts), loaded first. comp/tooltip.js, when it is
|
|
11
|
+
loaded, draws the hints (else: the title of the browser).
|
|
12
|
+
- Too many buttons for the window: the last ones go into a "..." menu at the end, and come back when there is room.
|
|
13
|
+
- A shortcut runs its item and is written in its hint: "Ctrl+S" (Ctrl is also Cmd on a Mac; the rules are the ones of MenuBar).
|
|
14
|
+
The same shortcut in a ToolBar and a MenuBar runs only one of them.
|
|
15
|
+
- Keyboard: Tab comes to the bar (one stop); ArrowLeft, ArrowRight, Home and End go between the buttons; Enter or Space press
|
|
16
|
+
a button; ArrowDown opens its menu.
|
|
17
|
+
- Style packages: "light" (default), "dark", "minimal", "minimalDark" (a package of params: its height too; setTheme()
|
|
18
|
+
changes only the colors and the shapes). Select with styleName (ToolBar.styles), or later with setTheme().
|
|
19
|
+
|
|
20
|
+
AN ITEM: { key, text, icon, iconFile, hint, shortcut, toggle, group, checked, enabled, items, data, onClick }
|
|
21
|
+
- "-" or { type: "separator" }: a line between the buttons. " " or { type: "space" }: the next items stand at the right end.
|
|
22
|
+
- A text is also accepted: "Save" -> { text: "Save" }.
|
|
23
|
+
- text: plain text next to its icon (never read as HTML). No text: an icon button.
|
|
24
|
+
- icon: a name of ToolBar.ICONS ("save", "undo", "bold"...), or an SVG text (your own code, not a user text) that uses
|
|
25
|
+
stroke="currentColor". iconFile: an image file.
|
|
26
|
+
- hint: its bubble, and its name for a screen reader. A button with a text needs none.
|
|
27
|
+
- toggle: 1: it stays pressed and a click changes it: read item.checked. group: "align": one button of the group stays pressed.
|
|
28
|
+
checked alone: it is pressed only when the page says so (setItemChecked()).
|
|
29
|
+
- items: it opens a menu: the items of a ContextMenu, each with its own onClick.
|
|
30
|
+
- onClick: function (self, item) {}. The onClick of the ToolBar is called too.
|
|
31
|
+
|
|
32
|
+
USAGE:
|
|
33
|
+
const bar = ToolBar({
|
|
34
|
+
items: [
|
|
35
|
+
{ key: "new", icon: "new", hint: "New", onClick: function (self, item) { println("New"); } },
|
|
36
|
+
{ key: "save", icon: "save", hint: "Save", shortcut: "Ctrl+S" },
|
|
37
|
+
"-",
|
|
38
|
+
{ key: "bold", icon: "bold", hint: "Bold", toggle: 1 },
|
|
39
|
+
{ key: "left", icon: "alignLeft", hint: "Left", group: "align", checked: 1 },
|
|
40
|
+
{ key: "right", icon: "alignRight", hint: "Right", group: "align" },
|
|
41
|
+
"-",
|
|
42
|
+
{ key: "insert", text: "Insert", items: ["A picture", "A table"] },
|
|
43
|
+
" ",
|
|
44
|
+
{ key: "run", icon: "play", text: "Run", shortcut: "F9" },
|
|
45
|
+
],
|
|
46
|
+
onClick: function (self, item) { println(item.key); },
|
|
47
|
+
});
|
|
48
|
+
bar.setItemEnabled("save", 0);
|
|
49
|
+
bar.setItemChecked("bold", 1); // onClick is not called
|
|
50
|
+
bar.isItemChecked("bold"); // true
|
|
51
|
+
bar.getCheckedKeys(); // ["bold", "left"]
|
|
52
|
+
bar.clickItem("run"); // as a click
|
|
53
|
+
bar.setItems([...]);
|
|
54
|
+
bar.setTheme("dark");
|
|
55
|
+
|
|
56
|
+
Started Date: November 2026
|
|
57
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
58
|
+
|
|
59
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
60
|
+
Licensed under the Apache License, Version 2.0
|
|
61
|
+
SPDX-License-Identifier: Apache-2.0
|
|
62
|
+
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
"use strict";
|
|
66
|
+
|
|
67
|
+
// Default values:
|
|
68
|
+
const ToolBarDefaults = {
|
|
69
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
70
|
+
left: 0,
|
|
71
|
+
top: 0,
|
|
72
|
+
width: "100%",
|
|
73
|
+
height: 42,
|
|
74
|
+
shrink: 0, // WHY: In a full group its row must not get thinner: its height is its buttons.
|
|
75
|
+
items: [], // [ITEM] (See AN ITEM above)
|
|
76
|
+
enabled: 1,
|
|
77
|
+
ariaLabel: "Tool bar",
|
|
78
|
+
moreText: "More", // The name of the "..." button
|
|
79
|
+
onClick: function (self, item) { }, // An item (with a click, the keyboard, its shortcut or clickItem())
|
|
80
|
+
styleName: "light", // "light", "dark", "minimal", "minimalDark" or a name added to ToolBar.styles
|
|
81
|
+
style: { // Light style package (default)
|
|
82
|
+
box: { color: "#F4F4F2", lineColor: Black(0.12) },
|
|
83
|
+
layout: { padding: 6, gap: 2 },
|
|
84
|
+
button: { height: 30, padding: 8, gap: 6, round: 6, fontSize: 13, iconSize: 18, textColor: Black(0.72) },
|
|
85
|
+
buttonHover: { color: Black(0.07), borderColor: "" }, // borderColor: the edge (button.border). "": its own
|
|
86
|
+
buttonOn: { color: Black(0.13), textColor: Black(0.92), borderColor: "" }, // It stays pressed, or its menu is open.
|
|
87
|
+
separator: { height: 18, space: 4, color: Black(0.16) },
|
|
88
|
+
bubble: { fontSize: 12, padding: [9, 5], color: "#2B2B2A", textColor: White(0.95), round: 6, border: 0, shadow: "0 2px 8px " + Black(0.18) }, // Its hint
|
|
89
|
+
disabled: { opacity: 0.35 },
|
|
90
|
+
focus: { ringColor: "rgba(63, 141, 148, 0.8)" },
|
|
91
|
+
menuStyleName: "light", // The package of its menu
|
|
92
|
+
menu: { item: { height: 30, fontSize: 13 } }, // Over that package
|
|
93
|
+
menuMinWidth: 170,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const ToolBar = function (params = {}) {
|
|
98
|
+
|
|
99
|
+
// Merge style package: params.style > ToolBar.styles[styleName] > ToolBarDefaults.style (light)
|
|
100
|
+
const pageStyle = params.style; // WHY: setTheme() puts it over another package.
|
|
101
|
+
basic.applyStylePackage(params, ToolBar.styles, ToolBarDefaults);
|
|
102
|
+
|
|
103
|
+
// Merge params:
|
|
104
|
+
mergeIntoIfMissing(params, ToolBarDefaults);
|
|
105
|
+
|
|
106
|
+
// BOX: Component container
|
|
107
|
+
const box = startObject(params);
|
|
108
|
+
|
|
109
|
+
// *** PRIVATE VARIABLES:
|
|
110
|
+
let _s = box.style;
|
|
111
|
+
let entries = []; // { kind: "button", "more", "separator", "space"; item, object, isHovered, tooltip }: what is on the row
|
|
112
|
+
let hiddenEntries = []; // The ones that did not fit: they are in the "..." menu.
|
|
113
|
+
let moreEntry = null;
|
|
114
|
+
let tabEntry = null; // The button that the Tab key comes to
|
|
115
|
+
let openEntry = null; // The button whose menu is open
|
|
116
|
+
let openEntryAtPress = null; // The one that was open when the mouse was pressed
|
|
117
|
+
let isUsedWithKeys = 0; // 1: the last thing was a key, not the mouse
|
|
118
|
+
|
|
119
|
+
// *** PUBLIC VARIABLES:
|
|
120
|
+
// NOTE: box.items are the items of the bar, item.checked is their state. Default values are also public variables.
|
|
121
|
+
|
|
122
|
+
// *** PRIVATE FUNCTIONS:
|
|
123
|
+
|
|
124
|
+
// The style of a package, with the style of the page over it. (setTheme)
|
|
125
|
+
const styleOfPackage = function (styleName) {
|
|
126
|
+
const fresh = { styleName: styleName, style: pageStyle };
|
|
127
|
+
basic.applyStylePackage(fresh, ToolBar.styles, ToolBarDefaults);
|
|
128
|
+
mergeIntoIfMissing(fresh, ToolBarDefaults);
|
|
129
|
+
return fresh.style;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const toItem = function (given) {
|
|
133
|
+
if (given === "-") return { type: "separator" };
|
|
134
|
+
if (given === " ") return { type: "space" };
|
|
135
|
+
if (typeof given != "object" || given === null) return { text: String(given) };
|
|
136
|
+
return MenuBar.copyItem(given);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// A click changes it.
|
|
140
|
+
const isToggle = function (item) {
|
|
141
|
+
return (basic.isOn(item.toggle) || !!item.group);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const isChecked = function (item) {
|
|
145
|
+
return basic.isOn(item.checked);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const canStayPressed = function (item) {
|
|
149
|
+
return (isToggle(item) || item.checked !== undefined);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const isItemEnabled = function (item) {
|
|
153
|
+
return (box.enabled == 1 && !(item.enabled !== undefined && !basic.isOn(item.enabled)));
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const hasMenu = function (entry) {
|
|
157
|
+
return (entry.kind === "more" || Array.isArray(entry.item.items));
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const isEntryEnabled = function (entry) {
|
|
161
|
+
return (entry.kind === "more") ? box.enabled == 1 : isItemEnabled(entry.item);
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const isPressButton = function (entry) {
|
|
165
|
+
return (entry.kind === "button" || entry.kind === "more");
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// The buttons the keys go between: on the row, and enabled.
|
|
169
|
+
const getUsableEntries = function () {
|
|
170
|
+
return entries.filter(function (entry) {
|
|
171
|
+
return isPressButton(entry) && entry.object.visible != 0 && isEntryEnabled(entry);
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const chooseTabEntry = function () {
|
|
176
|
+
const usable = getUsableEntries();
|
|
177
|
+
if (!usable.includes(tabEntry)) tabEntry = usable[0] || null;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// The edge of a button (button.border: the minimal packages): on, under the mouse, or its own
|
|
181
|
+
const getButtonEdge = function (isOn, isOver) {
|
|
182
|
+
if (isOn && _s.buttonOn.borderColor) return _s.buttonOn.borderColor;
|
|
183
|
+
if (isOver && _s.buttonHover.borderColor) return _s.buttonHover.borderColor;
|
|
184
|
+
return _s.button.borderColor || "transparent";
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// PAINT: a button: the mouse on it, pressed, its menu open, disabled; only one of them is reached with Tab.
|
|
188
|
+
const paintButton = function (entry) {
|
|
189
|
+
const button = entry.object;
|
|
190
|
+
const isEnabled = isEntryEnabled(entry);
|
|
191
|
+
const isOn = (entry === openEntry || (entry.kind === "button" && isChecked(entry.item)));
|
|
192
|
+
let color = "transparent";
|
|
193
|
+
if (entry.isHovered && isEnabled) color = _s.buttonHover.color;
|
|
194
|
+
if (isOn) color = _s.buttonOn.color;
|
|
195
|
+
button.color = color;
|
|
196
|
+
if (_s.button.border) button.borderColor = getButtonEdge(isOn, entry.isHovered && isEnabled);
|
|
197
|
+
button.textColor = (isOn) ? _s.buttonOn.textColor : _s.button.textColor;
|
|
198
|
+
button.opacity = (isEnabled) ? 1 : _s.disabled.opacity;
|
|
199
|
+
button.cursor = (isEnabled) ? "pointer" : "default";
|
|
200
|
+
button.tabIndex = (entry === tabEntry) ? 0 : -1;
|
|
201
|
+
button.aria = { disabled: (isEnabled) ? "false" : "true" };
|
|
202
|
+
if (entry.kind === "button" && canStayPressed(entry.item)) button.aria = { pressed: (isChecked(entry.item)) ? "true" : "false" };
|
|
203
|
+
if (hasMenu(entry)) button.aria = { expanded: (entry === openEntry) ? "true" : "false" };
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const paintButtons = function () {
|
|
207
|
+
chooseTabEntry();
|
|
208
|
+
entries.filter(isPressButton).forEach(paintButton);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// The look of an object of the row that comes from the style (the first drawing and setTheme).
|
|
212
|
+
const applyEntryLook = function (entry) {
|
|
213
|
+
if (entry.kind === "separator") {
|
|
214
|
+
entry.object.props({ height: _s.separator.height, color: _s.separator.color });
|
|
215
|
+
entry.object.css.margin = "0 " + _s.separator.space + "px";
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (!isPressButton(entry)) return;
|
|
219
|
+
const hasText = (entry.kind === "button" && !!entry.item.text);
|
|
220
|
+
entry.object.props({ height: _s.button.height, fontSize: _s.button.fontSize, round: _s.button.round });
|
|
221
|
+
if (_s.button.border) entry.object.props({ border: _s.button.border, borderColor: _s.button.borderColor || "transparent" });
|
|
222
|
+
// WHY minWidth and no padding: an icon button is a square.
|
|
223
|
+
entry.object.css = {
|
|
224
|
+
minWidth: _s.button.height + "px",
|
|
225
|
+
padding: (hasText) ? "0 " + _s.button.padding + "px" : "0",
|
|
226
|
+
gap: _s.button.gap + "px",
|
|
227
|
+
};
|
|
228
|
+
entry.object.setFocusRing(_s.focus.ringColor);
|
|
229
|
+
if (entry.tooltip) entry.tooltip.look = _s.bubble;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const applyBarLook = function () {
|
|
233
|
+
box.color = _s.box.color;
|
|
234
|
+
box.css.borderBottom = "1px solid " + _s.box.lineColor;
|
|
235
|
+
box.layout.gap = _s.layout.gap;
|
|
236
|
+
box.layout.padding = [_s.layout.padding, 0];
|
|
237
|
+
box.elem.style.setProperty("--tool-bar-icon", _s.button.iconSize + "px");
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const createTooltip = function (entry, text) {
|
|
241
|
+
return Tooltip({ target: entry.object, hintText: text, hintPosition: "bottom", look: _s.bubble });
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// The bubble of a button, and its name. WHY aria: an icon button has no other name for a screen reader.
|
|
245
|
+
const applyHint = function (entry) {
|
|
246
|
+
const text = ToolBar.getHintText(entry.item);
|
|
247
|
+
entry.object.aria = { label: entry.item.hint || entry.item.text || "" };
|
|
248
|
+
if (typeof Tooltip === "undefined") {
|
|
249
|
+
entry.object.elem.title = text;
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (entry.tooltip && text) {
|
|
253
|
+
entry.tooltip.setHintText(text);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (entry.tooltip) entry.tooltip.remove(); // WHY: A Tooltip with no text draws an empty bubble.
|
|
257
|
+
entry.tooltip = (text) ? createIn(box.layout, function () { return createTooltip(entry, text); }) : null;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// BUTTON: A button of the row (an item, or the "...")
|
|
261
|
+
const createButtonObject = function (entry, html) {
|
|
262
|
+
entry.object = Button({
|
|
263
|
+
width: "auto",
|
|
264
|
+
color: "transparent",
|
|
265
|
+
shrink: 0,
|
|
266
|
+
css: { display: "flex", alignItems: "center", justifyContent: "center", whiteSpace: "nowrap" },
|
|
267
|
+
});
|
|
268
|
+
entry.object.minimal = 1;
|
|
269
|
+
entry.object.text = html;
|
|
270
|
+
entry.object.onHoverChange(function (self, isOver) {
|
|
271
|
+
entry.isHovered = isOver;
|
|
272
|
+
paintButton(entry);
|
|
273
|
+
});
|
|
274
|
+
entry.object.on("click", function (self, event) { onButtonClick(entry, event); });
|
|
275
|
+
entry.object.on("keydown", function (self, event) { onButtonKeyDown(entry, event); });
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const createEntry = function (item) {
|
|
279
|
+
const entry = { kind: "button", item: item, isHovered: 0, tooltip: null };
|
|
280
|
+
if (item.type === "separator" || item.type === "space") {
|
|
281
|
+
entry.kind = item.type;
|
|
282
|
+
// BOX: A line, or an empty place that takes the rest of the row
|
|
283
|
+
entry.object = (item.type === "separator")
|
|
284
|
+
? Box({ width: 1, shrink: 0 })
|
|
285
|
+
: Box({ width: 0, height: 1, grow: 1, shrink: 0, color: "transparent" });
|
|
286
|
+
} else {
|
|
287
|
+
createButtonObject(entry, ToolBar.getButtonHtml(item));
|
|
288
|
+
if (Array.isArray(item.items)) entry.object.aria = { haspopup: "menu" };
|
|
289
|
+
applyHint(entry);
|
|
290
|
+
}
|
|
291
|
+
applyEntryLook(entry);
|
|
292
|
+
return entry;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const createMoreEntry = function () {
|
|
296
|
+
const entry = { kind: "more", item: { hint: box.moreText }, isHovered: 0, tooltip: null };
|
|
297
|
+
createButtonObject(entry, ToolBar.getButtonHtml({ icon: "more" }));
|
|
298
|
+
entry.object.aria = { haspopup: "menu" };
|
|
299
|
+
applyHint(entry);
|
|
300
|
+
applyEntryLook(entry);
|
|
301
|
+
entry.object.visible = 0; // WHY: fitItems() shows it, also when the bar is drawn later.
|
|
302
|
+
return entry;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const removeEntries = function () {
|
|
306
|
+
entries.forEach(function (entry) {
|
|
307
|
+
if (entry.tooltip) entry.tooltip.remove();
|
|
308
|
+
entry.object.remove();
|
|
309
|
+
});
|
|
310
|
+
entries = [];
|
|
311
|
+
hiddenEntries = [];
|
|
312
|
+
moreEntry = null;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const createEntries = function () {
|
|
316
|
+
createIn(box.layout, function () {
|
|
317
|
+
entries = box.items.map(createEntry);
|
|
318
|
+
moreEntry = createMoreEntry();
|
|
319
|
+
entries.push(moreEntry);
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const isRowFull = function () {
|
|
324
|
+
return (box.layout.elem.scrollWidth > box.layout.elem.clientWidth);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// The last items go into the "..." menu until the row has room.
|
|
328
|
+
// WHY the measure of the page, one by one: icons, texts, lines and gaps all count, and the row knows their sum.
|
|
329
|
+
const fitItems = function () {
|
|
330
|
+
if (box.layout.elem.clientWidth === 0) return; // WHY: Not drawn yet: box.onResize comes back.
|
|
331
|
+
const itemEntries = entries.filter(function (entry) { return entry !== moreEntry; });
|
|
332
|
+
itemEntries.forEach(function (entry) { entry.object.visible = 1; });
|
|
333
|
+
moreEntry.object.visible = 0;
|
|
334
|
+
hiddenEntries = [];
|
|
335
|
+
if (isRowFull()) {
|
|
336
|
+
moreEntry.object.visible = 1;
|
|
337
|
+
for (let index = itemEntries.length - 1; index >= 0 && isRowFull(); index--) {
|
|
338
|
+
itemEntries[index].object.visible = 0;
|
|
339
|
+
hiddenEntries.unshift(itemEntries[index]);
|
|
340
|
+
}
|
|
341
|
+
hideLinesAtTheEnd(itemEntries);
|
|
342
|
+
}
|
|
343
|
+
paintButtons();
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// WHY: A line or an empty place with no button after it means nothing.
|
|
347
|
+
const hideLinesAtTheEnd = function (itemEntries) {
|
|
348
|
+
const shown = itemEntries.filter(function (entry) { return entry.object.visible != 0; });
|
|
349
|
+
for (let index = shown.length - 1; index >= 0 && !isPressButton(shown[index]); index--) {
|
|
350
|
+
shown[index].object.visible = 0;
|
|
351
|
+
hiddenEntries.unshift(shown[index]);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// An item as its menu takes it. WHY a copy that knows the item: a ContextMenu copies its items, and the press needs the real one.
|
|
356
|
+
const toMenuItem = function (item) {
|
|
357
|
+
if (typeof item != "object" || item === null) return item;
|
|
358
|
+
if (item.type === "separator") return "-";
|
|
359
|
+
const copy = Object.assign({}, item);
|
|
360
|
+
copy.toolItem = item;
|
|
361
|
+
copy.onClick = null;
|
|
362
|
+
copy.text = String(item.text || item.hint || item.key || "");
|
|
363
|
+
if (item.icon) copy.icon = ToolBar.getIconSvg(item.icon);
|
|
364
|
+
if (item.shortcut) copy.shortcut = MenuBar.shortcutText(item.shortcut);
|
|
365
|
+
if (isToggle(item)) copy.checked = (isChecked(item)) ? 1 : 0;
|
|
366
|
+
if (Array.isArray(item.items)) copy.items = item.items.map(toMenuItem);
|
|
367
|
+
return copy;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// The items of the "..." menu. WHY no empty places and no line at the ends: a menu has no use for them.
|
|
371
|
+
const getHiddenItems = function () {
|
|
372
|
+
const items = hiddenEntries.map(function (entry) { return entry.item; }).filter(function (item) { return item.type !== "space"; });
|
|
373
|
+
while (items.length && items[0].type === "separator") items.shift();
|
|
374
|
+
while (items.length && items[items.length - 1].type === "separator") items.pop();
|
|
375
|
+
return items;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const openMenuOf = function (entry, withKeyboard) {
|
|
379
|
+
const items = (entry.kind === "more") ? getHiddenItems() : entry.item.items;
|
|
380
|
+
if (items.length === 0) return; // WHY: A ContextMenu with no items does not open: the button must not stay "open".
|
|
381
|
+
box.menu.setItems(items.map(toMenuItem));
|
|
382
|
+
openEntry = entry;
|
|
383
|
+
tabEntry = entry;
|
|
384
|
+
box.menu.openBelow(entry.object);
|
|
385
|
+
if (withKeyboard) box.menu.activateFirst();
|
|
386
|
+
paintButtons();
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const onMenuClose = function () {
|
|
390
|
+
const closedEntry = openEntry;
|
|
391
|
+
openEntry = null;
|
|
392
|
+
paintButtons();
|
|
393
|
+
// WHY the keys: the focus was in the menu. After the mouse a focus by code would show the ring of the keyboard.
|
|
394
|
+
if (closedEntry && isUsedWithKeys) closedEntry.object.elem.focus({ preventScroll: true });
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const setItemCheckedInGroup = function (item, value) {
|
|
398
|
+
if (!item.group || !value) {
|
|
399
|
+
item.checked = (value) ? 1 : 0;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
MenuBar.forEachItem(box.items, function (other) {
|
|
403
|
+
if (other.group === item.group) other.checked = (other === item) ? 1 : 0;
|
|
404
|
+
});
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const pressItem = function (item) {
|
|
408
|
+
if (!isItemEnabled(item)) return;
|
|
409
|
+
// WHY group: one button of a group always stays pressed: a click on it changes nothing.
|
|
410
|
+
if (isToggle(item)) setItemCheckedInGroup(item, (item.group) ? 1 : !isChecked(item));
|
|
411
|
+
paintButtons();
|
|
412
|
+
if (typeof item.onClick === "function") item.onClick(box, item);
|
|
413
|
+
if (!box.isRemoved) box.onClick(box, item); // WHY: The item may have removed the bar (a window drawn again).
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const onButtonClick = function (entry, event) {
|
|
417
|
+
if (entry.tooltip) entry.tooltip.hideHint(); // WHY: The menu opens where the bubble is, and the button was found.
|
|
418
|
+
if (!isEntryEnabled(entry)) return;
|
|
419
|
+
tabEntry = entry;
|
|
420
|
+
if (!hasMenu(entry)) {
|
|
421
|
+
pressItem(entry.item);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const isFromKeyboard = (event.detail === 0); // WHY: Enter and Space make a click without a mouse.
|
|
425
|
+
// WHY: The press closed this open menu just before this click (ContextMenu closes on a press outside it).
|
|
426
|
+
const wasOpenAtPress = (!isFromKeyboard && openEntryAtPress === entry);
|
|
427
|
+
openEntryAtPress = null;
|
|
428
|
+
if (!wasOpenAtPress) openMenuOf(entry, isFromKeyboard);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// The button a key goes to, or null for another key.
|
|
432
|
+
const entryOfKey = function (entry, key) {
|
|
433
|
+
const usable = getUsableEntries();
|
|
434
|
+
const place = usable.indexOf(entry);
|
|
435
|
+
if (key === "ArrowRight") return usable[(place + 1) % usable.length];
|
|
436
|
+
if (key === "ArrowLeft") return usable[(place - 1 + usable.length) % usable.length];
|
|
437
|
+
if (key === "Home") return usable[0];
|
|
438
|
+
if (key === "End") return usable[usable.length - 1];
|
|
439
|
+
return null;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const focusEntry = function (entry) {
|
|
443
|
+
tabEntry = entry;
|
|
444
|
+
paintButtons();
|
|
445
|
+
entry.object.elem.focus();
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
const onButtonKeyDown = function (entry, event) {
|
|
449
|
+
if (openEntry) return; // WHY: The open menu reads the keys.
|
|
450
|
+
const target = entryOfKey(entry, event.key);
|
|
451
|
+
if (target) {
|
|
452
|
+
event.preventDefault();
|
|
453
|
+
focusEntry(target);
|
|
454
|
+
} else if (event.key === "ArrowDown" && hasMenu(entry) && isEntryEnabled(entry)) {
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
openMenuOf(entry, 1);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const onWindowKeyDown = function (self, event) {
|
|
461
|
+
if (box.enabled != 1 || event.defaultPrevented) return; // WHY defaultPrevented: a MenuBar has run this shortcut.
|
|
462
|
+
if (box.elem.getClientRects().length === 0) return; // WHY: A bar in a hidden tab: its Ctrl+S belongs to the tab in front.
|
|
463
|
+
const item = MenuBar.findShortcutItem(box.items, event);
|
|
464
|
+
if (!item || MenuBar.isDialogOpen()) return;
|
|
465
|
+
event.preventDefault(); // WHY: Ctrl+S must not also open the save window of the browser.
|
|
466
|
+
if (event.repeat) return; // WHY: A held key runs it once.
|
|
467
|
+
box.closeMenu();
|
|
468
|
+
pressItem(item);
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// The first item with this key, in the bar or in a menu of it.
|
|
472
|
+
const findItem = function (key) {
|
|
473
|
+
let found = null;
|
|
474
|
+
MenuBar.forEachItem(box.items, function (item) {
|
|
475
|
+
if (!found && item.key == key) found = item;
|
|
476
|
+
});
|
|
477
|
+
return found;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const findEntry = function (item) {
|
|
481
|
+
return entries.find(function (entry) { return entry.item === item; });
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const createMenu = function () {
|
|
485
|
+
return ContextMenu({
|
|
486
|
+
styleName: _s.menuStyleName,
|
|
487
|
+
style: _s.menu,
|
|
488
|
+
minWidth: _s.menuMinWidth,
|
|
489
|
+
ariaLabel: box.ariaLabel,
|
|
490
|
+
onClick: function (self, menuItem) { pressItem(menuItem.toolItem || menuItem); },
|
|
491
|
+
onClose: onMenuClose,
|
|
492
|
+
});
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// *** PUBLIC FUNCTIONS:
|
|
496
|
+
|
|
497
|
+
box.setItems = function (items) {
|
|
498
|
+
box.closeMenu();
|
|
499
|
+
removeEntries();
|
|
500
|
+
box.items = (Array.isArray(items)) ? items.map(toItem) : [];
|
|
501
|
+
createEntries();
|
|
502
|
+
fitItems();
|
|
503
|
+
paintButtons();
|
|
504
|
+
};
|
|
505
|
+
// USAGE: bar.setItems([{ icon: "save", hint: "Save" }, "-", "Reset"])
|
|
506
|
+
|
|
507
|
+
box.setItemEnabled = function (key, value) {
|
|
508
|
+
const item = findItem(key);
|
|
509
|
+
if (!item) return;
|
|
510
|
+
item.enabled = basic.isOn(value) ? 1 : 0;
|
|
511
|
+
paintButtons();
|
|
512
|
+
};
|
|
513
|
+
// USAGE: bar.setItemEnabled("save", 0)
|
|
514
|
+
|
|
515
|
+
// onClick is not called. In a group the others go off.
|
|
516
|
+
box.setItemChecked = function (key, value) {
|
|
517
|
+
const item = findItem(key);
|
|
518
|
+
if (!item) return;
|
|
519
|
+
setItemCheckedInGroup(item, basic.isOn(value));
|
|
520
|
+
paintButtons();
|
|
521
|
+
};
|
|
522
|
+
// USAGE: bar.setItemChecked("bold", 1)
|
|
523
|
+
|
|
524
|
+
box.setItemText = function (key, text) {
|
|
525
|
+
const item = findItem(key);
|
|
526
|
+
if (!item) return;
|
|
527
|
+
item.text = text;
|
|
528
|
+
const entry = findEntry(item);
|
|
529
|
+
if (!entry) return;
|
|
530
|
+
entry.object.text = ToolBar.getButtonHtml(item);
|
|
531
|
+
applyEntryLook(entry);
|
|
532
|
+
applyHint(entry);
|
|
533
|
+
fitItems();
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
box.setItemHint = function (key, text) {
|
|
537
|
+
const item = findItem(key);
|
|
538
|
+
if (!item) return;
|
|
539
|
+
item.hint = text;
|
|
540
|
+
const entry = findEntry(item);
|
|
541
|
+
if (entry) applyHint(entry);
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
box.isItemChecked = function (key) {
|
|
545
|
+
const item = findItem(key);
|
|
546
|
+
return (!!item && isChecked(item));
|
|
547
|
+
};
|
|
548
|
+
// USAGE: bar.isItemChecked("bold")
|
|
549
|
+
|
|
550
|
+
box.getCheckedKeys = function () {
|
|
551
|
+
const keys = [];
|
|
552
|
+
MenuBar.forEachItem(box.items, function (item) {
|
|
553
|
+
if (isChecked(item)) keys.push(item.key);
|
|
554
|
+
});
|
|
555
|
+
return keys;
|
|
556
|
+
};
|
|
557
|
+
// USAGE: bar.getCheckedKeys()
|
|
558
|
+
|
|
559
|
+
// As a click on it (onClick is called). WHY not a button with a menu: it can be in the "..." menu, with no place to open under.
|
|
560
|
+
box.clickItem = function (key) {
|
|
561
|
+
const item = findItem(key);
|
|
562
|
+
if (item && !Array.isArray(item.items)) pressItem(item);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
box.closeMenu = function () {
|
|
566
|
+
if (openEntry) box.menu.close();
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
box.setEnabled = function (value) {
|
|
570
|
+
box.enabled = basic.isOn(value) ? 1 : 0;
|
|
571
|
+
if (box.enabled != 1) box.closeMenu();
|
|
572
|
+
paintButtons();
|
|
573
|
+
};
|
|
574
|
+
// USAGE: get: bar.enabled, set: bar.setEnabled(0)
|
|
575
|
+
|
|
576
|
+
// Another style package while it is on the page. A style given by the page stays over it.
|
|
577
|
+
// WHY the menu is made again: a ContextMenu keeps the style it was made with.
|
|
578
|
+
box.setTheme = function (styleName) {
|
|
579
|
+
box.closeMenu();
|
|
580
|
+
box.styleName = styleName;
|
|
581
|
+
_s = styleOfPackage(styleName);
|
|
582
|
+
box.style = _s;
|
|
583
|
+
box.menu.remove();
|
|
584
|
+
box.menu = createMenu();
|
|
585
|
+
applyBarLook();
|
|
586
|
+
entries.forEach(applyEntryLook);
|
|
587
|
+
paintButtons();
|
|
588
|
+
};
|
|
589
|
+
// USAGE: bar.setTheme("dark")
|
|
590
|
+
|
|
591
|
+
// WHY: box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
|
|
592
|
+
const superRemove = box.remove;
|
|
593
|
+
box.superRemove = superRemove;
|
|
594
|
+
box.remove = function () {
|
|
595
|
+
// WHY isRemoved and box is not set to null: an item can remove the bar in its onClick, and the code of its click goes on.
|
|
596
|
+
if (box.isRemoved) return; // WHY: remove() can be called twice (also by the parent's remove()).
|
|
597
|
+
box.menu.remove(); // WHY: not with box.own(): setTheme() makes a new one, and own() would keep the old one to the end.
|
|
598
|
+
superRemove.call(box);
|
|
599
|
+
};
|
|
600
|
+
// USAGE: bar.remove();
|
|
601
|
+
|
|
602
|
+
// *** OBJECT VIEW:
|
|
603
|
+
|
|
604
|
+
// BOX: The bar
|
|
605
|
+
box.css.boxSizing = "border-box";
|
|
606
|
+
box.role = "toolbar";
|
|
607
|
+
box.aria = { label: box.ariaLabel };
|
|
608
|
+
|
|
609
|
+
// GROUP: The buttons (made by createEntries)
|
|
610
|
+
box.layout = HGroup({ width: "100%", height: "100%", align: "left center" });
|
|
611
|
+
endGroup();
|
|
612
|
+
|
|
613
|
+
// *** OBJECT INIT CODE:
|
|
614
|
+
|
|
615
|
+
basic.addCss("tool-bar-icon",
|
|
616
|
+
".tool-bar-icon { display: block; flex-shrink: 0; width: var(--tool-bar-icon); height: var(--tool-bar-icon); }" +
|
|
617
|
+
".tool-bar-icon svg, .tool-bar-icon img { display: block; width: 100%; height: 100%; }" +
|
|
618
|
+
".tool-bar-arrow { display: block; flex-shrink: 0; width: 12px; height: 12px; margin-right: -2px; }" +
|
|
619
|
+
".tool-bar-arrow svg { display: block; width: 100%; height: 100%; }" +
|
|
620
|
+
// WHY: The mouse going from the icon to the text would close and open the bubble of its button.
|
|
621
|
+
".tool-bar-icon, .tool-bar-text, .tool-bar-arrow { pointer-events: none; }");
|
|
622
|
+
|
|
623
|
+
box.menu = createMenu();
|
|
624
|
+
|
|
625
|
+
// WHY capture on window: it runs before the capture of ContextMenu on document, which closes the menu.
|
|
626
|
+
box.listenTo(window, "pointerdown", function () {
|
|
627
|
+
openEntryAtPress = openEntry;
|
|
628
|
+
isUsedWithKeys = 0;
|
|
629
|
+
}, true);
|
|
630
|
+
box.listenTo(window, "keydown", function () { isUsedWithKeys = 1; }, true);
|
|
631
|
+
box.listenTo(window, "keydown", onWindowKeyDown);
|
|
632
|
+
|
|
633
|
+
applyBarLook();
|
|
634
|
+
box.setItems(params.items);
|
|
635
|
+
box.onResize(fitItems);
|
|
636
|
+
|
|
637
|
+
// WHY: A text measured before its font came is narrower: the row may be full when the font comes.
|
|
638
|
+
if (document.fonts && document.fonts.status !== "loaded") {
|
|
639
|
+
document.fonts.ready.then(function () {
|
|
640
|
+
if (!box.isRemoved) fitItems();
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return endObject(box);
|
|
645
|
+
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
649
|
+
|
|
650
|
+
ToolBar.SVG_START = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"' +
|
|
651
|
+
' stroke-linecap="round" stroke-linejoin="round">';
|
|
652
|
+
|
|
653
|
+
// The inside of the icons of a bar. USAGE: { icon: "save" }. Your own one: ToolBar.ICONS.star = '<path d="..."/>';
|
|
654
|
+
ToolBar.ICONS = {
|
|
655
|
+
new: '<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>',
|
|
656
|
+
open: '<path d="M3 7a2 2 0 0 1 2-2h4l2 2.5h8a2 2 0 0 1 2 2V17a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>',
|
|
657
|
+
save: '<path d="M5 3h11l5 5v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"/><path d="M8 3v5h7V3"/><path d="M7 21v-7h10v7"/>',
|
|
658
|
+
undo: '<path d="M9 14L4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>',
|
|
659
|
+
redo: '<path d="M15 14l5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/>',
|
|
660
|
+
cut: '<circle cx="6" cy="6.5" r="2.5"/><circle cx="6" cy="17.5" r="2.5"/><path d="M8 8.2 20 17"/><path d="M8 15.8 20 7"/>',
|
|
661
|
+
copy: '<rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15h-.5A1.5 1.5 0 0 1 3 13.5v-9A1.5 1.5 0 0 1 4.5 3h9A1.5 1.5 0 0 1 15 4.5V5"/>',
|
|
662
|
+
paste: '<rect x="5" y="4.5" width="14" height="16.5" rx="2"/><rect x="9" y="2.5" width="6" height="4" rx="1"/>',
|
|
663
|
+
delete: '<path d="M4 7h16"/><path d="M9 7V4.5h6V7"/><path d="M6.5 7l1 13h9l1-13"/><path d="M10.5 11v5"/><path d="M13.5 11v5"/>',
|
|
664
|
+
search: '<circle cx="10.5" cy="10.5" r="6.5"/><path d="m15.5 15.5 5 5"/>',
|
|
665
|
+
refresh: '<path d="M20 11a8 8 0 1 0-2.3 6.7"/><path d="M20 4.5V11h-6.5"/>',
|
|
666
|
+
settings: '<path d="M4 7h9"/><path d="M17 7h3"/><circle cx="15" cy="7" r="2"/><path d="M4 17h3"/><path d="M11 17h9"/><circle cx="9" cy="17" r="2"/>',
|
|
667
|
+
play: '<path d="M7 4.5v15l12-7.5z"/>',
|
|
668
|
+
stop: '<rect x="6" y="6" width="12" height="12" rx="2"/>',
|
|
669
|
+
plus: '<path d="M12 5v14"/><path d="M5 12h14"/>',
|
|
670
|
+
minus: '<path d="M5 12h14"/>',
|
|
671
|
+
bold: '<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7z"/><path d="M7 12h7a3.5 3.5 0 0 1 0 7H7z"/>',
|
|
672
|
+
italic: '<path d="M14.5 5H10"/><path d="M14 19H9.5"/><path d="M13 5l-2 14"/>',
|
|
673
|
+
underline: '<path d="M7 4v7a5 5 0 0 0 10 0V4"/><path d="M5 20.5h14"/>',
|
|
674
|
+
alignLeft: '<path d="M4 6h16"/><path d="M4 12h10"/><path d="M4 18h13"/>',
|
|
675
|
+
alignCenter: '<path d="M4 6h16"/><path d="M7 12h10"/><path d="M5.5 18h13"/>',
|
|
676
|
+
alignRight: '<path d="M4 6h16"/><path d="M10 12h10"/><path d="M7 18h13"/>',
|
|
677
|
+
more: '<circle cx="5.5" cy="12" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="18.5" cy="12" r="1"/>',
|
|
678
|
+
arrowDown: '<path d="m7 10 5 5 5-5"/>',
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// An icon as an SVG text: a name of ToolBar.ICONS, or an SVG text as it is.
|
|
682
|
+
ToolBar.getIconSvg = function (icon) {
|
|
683
|
+
const text = String(icon).trim();
|
|
684
|
+
if (text.startsWith("<")) return text;
|
|
685
|
+
const inside = ToolBar.ICONS[text];
|
|
686
|
+
if (inside === undefined) {
|
|
687
|
+
console.warn("ToolBar: There is no icon named " + text);
|
|
688
|
+
return "";
|
|
689
|
+
}
|
|
690
|
+
return ToolBar.SVG_START + inside + "</svg>";
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
// The inside of a button: its icon, its text and, for a menu, a small arrow. WHY escape: its text can be a text of a user.
|
|
694
|
+
ToolBar.getButtonHtml = function (item) {
|
|
695
|
+
let html = "";
|
|
696
|
+
if (item.iconFile) html += '<span class="tool-bar-icon"><img alt="" src="' + basic.escapeHtml(item.iconFile) + '"></span>';
|
|
697
|
+
else if (item.icon) html += '<span class="tool-bar-icon">' + ToolBar.getIconSvg(item.icon) + "</span>";
|
|
698
|
+
if (item.text) html += '<span class="tool-bar-text">' + basic.escapeHtml(String(item.text)) + "</span>";
|
|
699
|
+
if (Array.isArray(item.items)) html += '<span class="tool-bar-arrow">' + ToolBar.getIconSvg("arrowDown") + "</span>";
|
|
700
|
+
return html;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// The text of its bubble: its name and its shortcut. WHY none for a button with only a text: it would repeat the button.
|
|
704
|
+
ToolBar.getHintText = function (item) {
|
|
705
|
+
if (!item.shortcut) return item.hint || "";
|
|
706
|
+
const shortcut = MenuBar.shortcutText(item.shortcut);
|
|
707
|
+
const name = item.hint || item.text;
|
|
708
|
+
return (name) ? name + " (" + shortcut + ")" : shortcut;
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
// *** STYLE PACKAGES:
|
|
712
|
+
// USAGE: ToolBar({ styleName: "dark" })
|
|
713
|
+
// USAGE: ToolBar({ style: { button: { iconSize: 20 } } }) // Change only some keys.
|
|
714
|
+
// NOTE: A new package needs only the keys that differ from the default (light) style.
|
|
715
|
+
// USAGE: ToolBar.styles.myStyle = { box: { color: "tomato" } };
|
|
716
|
+
ToolBar.styles = {
|
|
717
|
+
|
|
718
|
+
// The ground of MenuBar, a soft line under it, gray icons.
|
|
719
|
+
light: ToolBarDefaults.style,
|
|
720
|
+
|
|
721
|
+
// For a dark window; a dark menu.
|
|
722
|
+
dark: {
|
|
723
|
+
box: { color: "#232322", lineColor: White(0.1) },
|
|
724
|
+
button: { textColor: White(0.74) },
|
|
725
|
+
buttonHover: { color: White(0.09) },
|
|
726
|
+
buttonOn: { color: White(0.17), textColor: White(0.95) },
|
|
727
|
+
separator: { color: White(0.16) },
|
|
728
|
+
bubble: { color: "#4A4A48", shadow: "0 2px 8px " + Black(0.45) },
|
|
729
|
+
focus: { ringColor: "rgba(111, 198, 205, 0.8)" },
|
|
730
|
+
menuStyleName: "dark",
|
|
731
|
+
},
|
|
732
|
+
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
// The minimal theme (_designs/minimal-theme.htm): no fill (the ground of the window), one line under it, 28 px quiet
|
|
736
|
+
// buttons with a 14 px icon: a line around the one under the mouse, an ink line around the one that is on; its hint is
|
|
737
|
+
// a bubble on the ground with a line, its menu ContextMenu minimal. minimalDark: the same on a dark window.
|
|
738
|
+
ToolBar.createMinimalStyle = function (colors) {
|
|
739
|
+
return {
|
|
740
|
+
height: 36,
|
|
741
|
+
style: {
|
|
742
|
+
box: { color: "transparent", lineColor: colors.line },
|
|
743
|
+
layout: { padding: 4, gap: 2 },
|
|
744
|
+
button: { height: 28, padding: 8, gap: 6, round: 4, fontSize: 13, iconSize: 14, textColor: colors.text, border: 1, borderColor: "transparent" },
|
|
745
|
+
buttonHover: { color: "transparent", borderColor: colors.lineHover },
|
|
746
|
+
buttonOn: { color: "transparent", textColor: colors.ink, borderColor: colors.ink },
|
|
747
|
+
separator: { height: 16, space: 4, color: colors.line },
|
|
748
|
+
bubble: { fontSize: 12, padding: [8, 4], color: colors.ground, textColor: colors.text, round: 4, border: 1, borderColor: colors.line, shadow: "none" },
|
|
749
|
+
disabled: { opacity: 0.35 },
|
|
750
|
+
focus: { ringColor: colors.focus },
|
|
751
|
+
menuStyleName: colors.menuStyleName,
|
|
752
|
+
menu: { item: { height: 28, fontSize: 13 } },
|
|
753
|
+
menuMinWidth: 170,
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
};
|
|
757
|
+
ToolBar.MINIMAL_COLORS = { ground: "#FFFFFF", text: Black(0.85), line: Black(0.2), lineHover: Black(0.45), ink: "#1F1F1F", focus: "#3D8BD9", menuStyleName: "minimal" };
|
|
758
|
+
ToolBar.styles.minimal = ToolBar.createMinimalStyle(ToolBar.MINIMAL_COLORS);
|
|
759
|
+
ToolBar.MINIMAL_DARK_COLORS = { ground: "#1A1A19", text: White(0.88), line: White(0.18), lineHover: White(0.42), ink: "#EDEDEB", focus: "#7FB6DE", menuStyleName: "minimalDark" };
|
|
760
|
+
ToolBar.styles.minimalDark = ToolBar.createMinimalStyle(ToolBar.MINIMAL_DARK_COLORS);
|