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,614 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Full Screen Select - v26.11
|
|
6
|
+
|
|
7
|
+
A select field that opens its list on the whole screen: a search box at the top, a close button, the items under it
|
|
8
|
+
(a phone app, a long list).
|
|
9
|
+
- The field: the text of the selected item, two small arrows at the right side. A click (or Enter, Space, the down
|
|
10
|
+
arrow) opens the list. autoWidth: 1 -> the field is as wide as its text.
|
|
11
|
+
- The list: it comes in from below with a fade. The search box (comp/search-input.js SearchInput, load it
|
|
12
|
+
first; without it there is no search box) shows only the items with the typed text (Turkish letters are found
|
|
13
|
+
without their marks); Enter selects the first one. The selected item has a soft yellow color.
|
|
14
|
+
searchIconFile / clearIconFile: the icons of the search box ("": the default files of SearchInput, which are
|
|
15
|
+
found from a page one folder under the repository: a page in another place gives its own paths).
|
|
16
|
+
- Keyboard in the list: Escape closes, the arrow keys move over the items, Enter selects. The focus goes back to
|
|
17
|
+
the field when the list closes.
|
|
18
|
+
- Only one list is open at a time (FullScreenSelect.openedSelect). The list is made on page when it first opens,
|
|
19
|
+
hidden when it closes and removed with the field (box.own); setItems() makes it again at the next open.
|
|
20
|
+
- Motion: the list comes in from below with a fade in 0.2 s (transform and opacity) and goes out at once
|
|
21
|
+
; no motion when the system asks for reduced motion.
|
|
22
|
+
- Style packages: "light" (default; the old name "classic" works too), "dark". (FullScreenSelect.styles)
|
|
23
|
+
|
|
24
|
+
USAGE:
|
|
25
|
+
const fruits = FullScreenSelect({
|
|
26
|
+
width: 320,
|
|
27
|
+
items: [{ key: "banana", text: "Banana" }, { key: "peach", text: "Peach" }, "Kiwi"],
|
|
28
|
+
selectedKey: "banana",
|
|
29
|
+
onChange: function (self) { println(self.selectedKey); },
|
|
30
|
+
});
|
|
31
|
+
fruits.setSelectedKey("peach"); // onChange runs (silent: fruits.setSelectedKey("peach", 1))
|
|
32
|
+
fruits.setItems(otherItems);
|
|
33
|
+
fruits.getSelectedItem(); // { key, text } or null
|
|
34
|
+
fruits.open(); fruits.close();
|
|
35
|
+
FullScreenSelect({ styleName: "dark", ... });
|
|
36
|
+
|
|
37
|
+
Started Date: October 2026
|
|
38
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
39
|
+
|
|
40
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
41
|
+
Licensed under the Apache License, Version 2.0
|
|
42
|
+
SPDX-License-Identifier: Apache-2.0
|
|
43
|
+
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
"use strict";
|
|
47
|
+
|
|
48
|
+
// Default values:
|
|
49
|
+
const FullScreenSelectDefaults = {
|
|
50
|
+
width: 200,
|
|
51
|
+
height: 50,
|
|
52
|
+
items: [], // [{ key, text }] or ["Text"] (the text is its key)
|
|
53
|
+
selectedKey: null, // null: the first item
|
|
54
|
+
placeholder: "Search",
|
|
55
|
+
emptyText: "No results",
|
|
56
|
+
autoWidth: 0, // 1: the field is as wide as the text of the selected item
|
|
57
|
+
showSearch: 1, // 0: no search box (a short list)
|
|
58
|
+
arrowIconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" id="Outline" viewBox="0 0 24 24" width="512" height="512"><path d="M18.71,8.21a1,1,0,0,0-1.42,0l-4.58,4.58a1,1,0,0,1-1.42,0L6.71,8.21a1,1,0,0,0-1.42,0,1,1,0,0,0,0,1.41l4.59,4.59a3,3,0,0,0,4.24,0l4.59-4.59A1,1,0,0,0,18.71,8.21Z"/></svg>'),
|
|
59
|
+
closeIconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="512" height="512"><g id="_01_align_center" data-name="01 align center"><polygon points="24 1.414 22.586 0 12 10.586 1.414 0 0 1.414 10.586 12 0 22.586 1.414 24 12 13.414 22.586 24 24 22.586 13.414 12 24 1.414"/></g></svg>'),
|
|
60
|
+
searchIconFile: "", // The icons of the search box. "": the files of SearchInput (or of its style package)
|
|
61
|
+
clearIconFile: "",
|
|
62
|
+
ariaLabel: "", // "": the text of the selected item is read
|
|
63
|
+
onChange: function (self) {}, // self.selectedKey changed (not at create time, not with silent: 1)
|
|
64
|
+
onOpen: function (self) {},
|
|
65
|
+
onClose: function (self) {},
|
|
66
|
+
styleName: "light", // "light" ("classic": its old name), "dark" or a name added to FullScreenSelect.styles
|
|
67
|
+
style: { // Light style package (default)
|
|
68
|
+
box: { color: "whitesmoke", round: 4, border: 0 },
|
|
69
|
+
focus: { ringColor: "rgba(95, 158, 160, 0.6)" },
|
|
70
|
+
label: { left: 10, fontSize: 20, textColor: Black(0.8) },
|
|
71
|
+
arrow: { size: 16, right: 8, gap: 7, opacity: 0.7, invert: 0 }, // gap: from the middle to each arrow
|
|
72
|
+
panel: { color: "white", zIndex: 3000, slide: 150 }, // slide: px, from below when it opens
|
|
73
|
+
search: { left: 20, top: 40, height: 50, closeGap: 10, color: "whitesmoke", textColor: "gray", round: 25, fontSize: 20, iconOpacity: 0.4 }, // closeGap: to the close button
|
|
74
|
+
searchStyleName: "original", // the first look of SearchInput
|
|
75
|
+
closeButton: { size: 30, right: 20, top: 50, color: "#D8D8D8", iconSize: 14, iconOpacity: 0.5, invert: 0 },
|
|
76
|
+
list: { left: 10, top: 110, gap: 0 },
|
|
77
|
+
item: { height: 60, sideSpace: 20, round: 4, color: "white", fontSize: 20, textColor: "#4A4A4A", textLeft: 30 },
|
|
78
|
+
itemHover: { color: "#F7F7F7" },
|
|
79
|
+
itemFocus: { color: "#F2F2F2" },
|
|
80
|
+
itemSelected: { color: "#FFF0C2" },
|
|
81
|
+
empty: { fontSize: 16, textColor: Black(0.4), top: 30 },
|
|
82
|
+
scrollBar: { neverHide: 0, showDots: 0 },
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const FullScreenSelect = function (params = {}) {
|
|
87
|
+
|
|
88
|
+
// Merge style package: params.style > FullScreenSelect.styles[styleName] > FullScreenSelectDefaults.style (light)
|
|
89
|
+
basic.applyStylePackage(params, FullScreenSelect.styles, FullScreenSelectDefaults);
|
|
90
|
+
|
|
91
|
+
// Merge params:
|
|
92
|
+
mergeIntoIfMissing(params, FullScreenSelectDefaults);
|
|
93
|
+
|
|
94
|
+
// Edit params: a copy, the caller's list does not change
|
|
95
|
+
params.items = FullScreenSelect.toItems(params.items);
|
|
96
|
+
|
|
97
|
+
// BOX: Component container (the field)
|
|
98
|
+
let box = startObject(params);
|
|
99
|
+
|
|
100
|
+
// *** PRIVATE VARIABLES:
|
|
101
|
+
const _s = box.style;
|
|
102
|
+
const PANEL_MOTION = "transform 0.2s, opacity 0.2s"; // the list comes in (it goes out at once)
|
|
103
|
+
const ARROW_UP = 180; // deg
|
|
104
|
+
const ARROWS_ROOM = 30; // the text ends before the arrows (it fades out there)
|
|
105
|
+
const TEXT_FADE = 40; // px
|
|
106
|
+
const AUTO_WIDTH_SPACE = 50; // autoWidth: 1 -> the field is the text + this (the left space and the arrows)
|
|
107
|
+
let focusedKey = null; // the item of the arrow keys in the open list
|
|
108
|
+
let searchText = null; // the search of the open list (null: not filtered yet)
|
|
109
|
+
|
|
110
|
+
// *** PUBLIC VARIABLES:
|
|
111
|
+
box.isOpen = 0;
|
|
112
|
+
box.panel = null; // The full screen list while it is open
|
|
113
|
+
// NOTE: Default values are also public variables. (box.items, box.selectedKey...)
|
|
114
|
+
|
|
115
|
+
// *** PRIVATE FUNCTIONS:
|
|
116
|
+
|
|
117
|
+
const findItem = function (key) {
|
|
118
|
+
return box.items.find(function (item) { return item.key == key; }) || null;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// The rows that are seen (the search), in their order
|
|
122
|
+
const getShownRows = function () {
|
|
123
|
+
if (!box.panel) return [];
|
|
124
|
+
return box.panel.rows.filter(function (row) { return row.visible == 1; });
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// *** THE FIELD:
|
|
128
|
+
|
|
129
|
+
const applyContent = function () {
|
|
130
|
+
const item = findItem(box.selectedKey);
|
|
131
|
+
box.lblText.plainText = item ? item.text : "";
|
|
132
|
+
box.aria = { label: box.ariaLabel || (item ? item.text : ""), expanded: !!box.isOpen };
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const fitAutoWidth = function () {
|
|
136
|
+
if (box.autoWidth != 1) return;
|
|
137
|
+
box.width = box.lblText.width + AUTO_WIDTH_SPACE;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const createArrow = function (isUp) {
|
|
141
|
+
const arrow = Icon({ right: _s.arrow.right, width: _s.arrow.size, height: _s.arrow.size, opacity: _s.arrow.opacity });
|
|
142
|
+
arrow.load(box.arrowIconFile);
|
|
143
|
+
if (isUp) arrow.rotate = ARROW_UP;
|
|
144
|
+
if (_s.arrow.invert) arrow.css = { filter: "invert(1)" };
|
|
145
|
+
arrow.css = { top: "calc(50% - " + (_s.arrow.size / 2) + "px " + (isUp ? "- " : "+ ") + _s.arrow.gap + "px)" };
|
|
146
|
+
return arrow;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// *** THE LIST (made on page when it first opens; made again by setItems):
|
|
150
|
+
|
|
151
|
+
const isReducedMotion = function () {
|
|
152
|
+
return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// The list comes in from below with a fade (0.2 s, at once: no timer of basic.js); it goes out at once.
|
|
156
|
+
const showPanel = function (isShown) {
|
|
157
|
+
|
|
158
|
+
const panel = box.panel;
|
|
159
|
+
panel.setMotionNow("");
|
|
160
|
+
|
|
161
|
+
if (!isShown) {
|
|
162
|
+
panel.visible = 0;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
panel.opacity = 0;
|
|
167
|
+
panel.css = { transform: "translateY(" + _s.panel.slide + "px)" };
|
|
168
|
+
panel.visible = 1;
|
|
169
|
+
if (isReducedMotion()) {
|
|
170
|
+
panel.opacity = 1;
|
|
171
|
+
panel.css = { transform: "none" };
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// WHY: the start look must be drawn before the motion is turned on, or the browser shows the end at once
|
|
176
|
+
void panel.elem.offsetHeight;
|
|
177
|
+
panel.setMotionNow(PANEL_MOTION);
|
|
178
|
+
panel.opacity = 1;
|
|
179
|
+
panel.css = { transform: "none" };
|
|
180
|
+
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// Only the list scrolls to the row: "center" (in the middle) or "nearest" (just into sight).
|
|
184
|
+
// WHY not elem.scrollIntoView(): it scrolls every box around the row too. While the list was still 150 px
|
|
185
|
+
// down (the slide), it scrolled the main box of the page: the page behind jumped and the list did not slide.
|
|
186
|
+
const scrollToRow = function (row, place) {
|
|
187
|
+
const listElem = box.panel.listBox.elem;
|
|
188
|
+
const rowTop = row.elem.offsetTop;
|
|
189
|
+
const rowBottom = rowTop + row.elem.offsetHeight;
|
|
190
|
+
if (place == "center") {
|
|
191
|
+
listElem.scrollTop = rowTop - (listElem.clientHeight - row.elem.offsetHeight) / 2;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (rowTop < listElem.scrollTop) listElem.scrollTop = rowTop;
|
|
195
|
+
else if (rowBottom > listElem.scrollTop + listElem.clientHeight) listElem.scrollTop = rowBottom - listElem.clientHeight;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// Every open starts with an empty search and the selected item in sight.
|
|
199
|
+
const resetPanel = function () {
|
|
200
|
+
if (box.panel.searchInput) box.panel.searchInput.setValue("", 1);
|
|
201
|
+
searchText = null;
|
|
202
|
+
filterRows("");
|
|
203
|
+
box.panel.listBox.elem.scrollTop = 0;
|
|
204
|
+
const selectedRow = box.panel.rows.find(function (row) { return row.item.key == box.selectedKey; });
|
|
205
|
+
if (selectedRow) scrollToRow(selectedRow, "center");
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const removePanel = function () {
|
|
209
|
+
if (!box.panel) return;
|
|
210
|
+
box.panel.remove();
|
|
211
|
+
box.panel = null;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const createPanel = function () {
|
|
215
|
+
|
|
216
|
+
box.panel = createIn(page, function () {
|
|
217
|
+
|
|
218
|
+
// BOX: Full screen list
|
|
219
|
+
const panel = startBox(0, 0, "100%", "100%", { color: _s.panel.color, zIndex: _s.panel.zIndex, role: "dialog", aria: { modal: true, label: box.ariaLabel || box.placeholder } });
|
|
220
|
+
panel.rows = [];
|
|
221
|
+
|
|
222
|
+
createSearch(panel);
|
|
223
|
+
createCloseButton(panel);
|
|
224
|
+
|
|
225
|
+
// BOX: Scrolling list
|
|
226
|
+
panel.listBox = startBox(_s.list.left, _s.list.top, "calc(100% - " + _s.list.left + "px)", "calc(100% - " + _s.list.top + "px)", { color: "transparent", scrollY: 1, role: "listbox" });
|
|
227
|
+
|
|
228
|
+
// GROUP: Items
|
|
229
|
+
panel.listGroup = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.list.gap });
|
|
230
|
+
box.items.forEach(function (item) {
|
|
231
|
+
panel.rows.push(createRow(item));
|
|
232
|
+
});
|
|
233
|
+
endGroup();
|
|
234
|
+
|
|
235
|
+
// LABEL: Nothing found
|
|
236
|
+
panel.lblEmpty = Label({ left: 0, top: _s.empty.top, width: "100%", plainText: box.emptyText, textAlign: "center", fontSize: _s.empty.fontSize, textColor: _s.empty.textColor, visible: 0 });
|
|
237
|
+
|
|
238
|
+
endBox();
|
|
239
|
+
|
|
240
|
+
if (typeof ScrollBar !== "undefined") {
|
|
241
|
+
panel.scrollBar = ScrollBar(Object.assign({ scrollableBox: panel.listBox }, _s.scrollBar));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
endBox();
|
|
245
|
+
|
|
246
|
+
return panel;
|
|
247
|
+
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
box.own(box.panel);
|
|
251
|
+
box.panel.visible = 0;
|
|
252
|
+
box.panel.listenTo(window, "keydown", onPanelKeyDown);
|
|
253
|
+
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const createSearch = function (panel) {
|
|
257
|
+
|
|
258
|
+
if (box.showSearch != 1 || typeof SearchInput === "undefined") return;
|
|
259
|
+
|
|
260
|
+
const search = _s.search;
|
|
261
|
+
const searchParams = {
|
|
262
|
+
styleName: _s.searchStyleName,
|
|
263
|
+
left: search.left,
|
|
264
|
+
top: search.top,
|
|
265
|
+
width: "calc(100% - " + (search.left + search.closeGap + _s.closeButton.size + _s.closeButton.right) + "px)",
|
|
266
|
+
height: search.height,
|
|
267
|
+
color: search.color,
|
|
268
|
+
textColor: search.textColor,
|
|
269
|
+
round: search.round,
|
|
270
|
+
fontSize: search.fontSize,
|
|
271
|
+
searchIconOpacity: search.iconOpacity,
|
|
272
|
+
border: 0,
|
|
273
|
+
borderBottomStyle: "none",
|
|
274
|
+
placeholder: box.placeholder,
|
|
275
|
+
onChange: function (self) { filterRows(self.getSearchText()); },
|
|
276
|
+
};
|
|
277
|
+
// WHY only when given: a file given here would win over the icon of the style package of SearchInput
|
|
278
|
+
if (box.searchIconFile) searchParams.searchIconFile = box.searchIconFile;
|
|
279
|
+
if (box.clearIconFile) searchParams.clearIconFile = box.clearIconFile;
|
|
280
|
+
panel.searchInput = SearchInput(searchParams);
|
|
281
|
+
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const createCloseButton = function (panel) {
|
|
285
|
+
|
|
286
|
+
const button = _s.closeButton;
|
|
287
|
+
|
|
288
|
+
// BOX: Close button
|
|
289
|
+
panel.btnClose = startBox({
|
|
290
|
+
right: button.right,
|
|
291
|
+
top: button.top,
|
|
292
|
+
width: button.size,
|
|
293
|
+
height: button.size,
|
|
294
|
+
round: button.size / 2,
|
|
295
|
+
color: button.color,
|
|
296
|
+
clickable: 1,
|
|
297
|
+
cursor: "pointer",
|
|
298
|
+
role: "button",
|
|
299
|
+
tabIndex: 0,
|
|
300
|
+
aria: { label: "Close" },
|
|
301
|
+
});
|
|
302
|
+
panel.btnClose.setFocusRing(_s.focus.ringColor);
|
|
303
|
+
|
|
304
|
+
// ICON: Close
|
|
305
|
+
Icon({ width: button.iconSize, height: button.iconSize, opacity: button.iconOpacity });
|
|
306
|
+
that.load(box.closeIconFile);
|
|
307
|
+
if (button.invert) that.css = { filter: "invert(1)" };
|
|
308
|
+
that.center();
|
|
309
|
+
|
|
310
|
+
endBox();
|
|
311
|
+
|
|
312
|
+
panel.btnClose.on("click", function () { box.close(); });
|
|
313
|
+
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// One item of the list. Its container must be set (createIn).
|
|
317
|
+
const createRow = function (item) {
|
|
318
|
+
|
|
319
|
+
const itemStyle = _s.item;
|
|
320
|
+
|
|
321
|
+
// BOX: Item
|
|
322
|
+
const row = startBox({
|
|
323
|
+
width: "calc(100% - " + (itemStyle.sideSpace * 1.5) + "px)",
|
|
324
|
+
height: itemStyle.height,
|
|
325
|
+
round: itemStyle.round,
|
|
326
|
+
color: itemStyle.color,
|
|
327
|
+
clickable: 1,
|
|
328
|
+
cursor: "pointer",
|
|
329
|
+
role: "option",
|
|
330
|
+
css: { marginLeft: (itemStyle.sideSpace / 2) + "px", flex: "0 0 auto" },
|
|
331
|
+
});
|
|
332
|
+
row.item = item;
|
|
333
|
+
row.isHover = 0;
|
|
334
|
+
|
|
335
|
+
// LABEL: Item text
|
|
336
|
+
row.lblText = Label({
|
|
337
|
+
left: itemStyle.textLeft,
|
|
338
|
+
width: "calc(100% - " + (itemStyle.textLeft * 2) + "px)",
|
|
339
|
+
plainText: item.text,
|
|
340
|
+
fontSize: itemStyle.fontSize,
|
|
341
|
+
textColor: itemStyle.textColor,
|
|
342
|
+
ellipsis: 1,
|
|
343
|
+
});
|
|
344
|
+
row.lblText.css = { top: "50%", transform: "translateY(-50%)" };
|
|
345
|
+
|
|
346
|
+
endBox();
|
|
347
|
+
|
|
348
|
+
row.onHoverChange(function (self, isOver) {
|
|
349
|
+
row.isHover = isOver;
|
|
350
|
+
paintRow(row);
|
|
351
|
+
});
|
|
352
|
+
row.on("click", function () {
|
|
353
|
+
selectFromList(item.key);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
paintRow(row);
|
|
357
|
+
return row;
|
|
358
|
+
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// The color of an item: selected > the arrow keys > under the mouse
|
|
362
|
+
const paintRow = function (row) {
|
|
363
|
+
const isSelected = (row.item.key == box.selectedKey);
|
|
364
|
+
row.aria = { selected: isSelected };
|
|
365
|
+
if (isSelected) {
|
|
366
|
+
row.color = _s.itemSelected.color;
|
|
367
|
+
} else if (row.item.key == focusedKey) {
|
|
368
|
+
row.color = _s.itemFocus.color;
|
|
369
|
+
} else if (row.isHover) {
|
|
370
|
+
row.color = _s.itemHover.color;
|
|
371
|
+
} else {
|
|
372
|
+
row.color = _s.item.color;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const paintRows = function () {
|
|
377
|
+
if (!box.panel) return;
|
|
378
|
+
box.panel.rows.forEach(paintRow);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
const filterRows = function (text) {
|
|
382
|
+
const newSearchText = FullScreenSelect.toSearchText(text).trim();
|
|
383
|
+
// WHY: the same text again (a search that is asked again) must not reset the focused item
|
|
384
|
+
if (newSearchText === searchText) return;
|
|
385
|
+
searchText = newSearchText;
|
|
386
|
+
box.panel.rows.forEach(function (row) {
|
|
387
|
+
const isShown = (searchText == "") || FullScreenSelect.toSearchText(row.item.text).includes(searchText);
|
|
388
|
+
row.visible = isShown ? 1 : 0;
|
|
389
|
+
});
|
|
390
|
+
box.panel.lblEmpty.visible = (getShownRows().length == 0) ? 1 : 0;
|
|
391
|
+
focusedKey = null;
|
|
392
|
+
paintRows();
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// The arrow keys move a soft color over the items that are seen.
|
|
396
|
+
const moveFocus = function (step) {
|
|
397
|
+
const rows = getShownRows();
|
|
398
|
+
if (rows.length == 0) return;
|
|
399
|
+
let index = rows.findIndex(function (row) { return row.item.key == focusedKey; });
|
|
400
|
+
if (index == -1) index = rows.findIndex(function (row) { return row.item.key == box.selectedKey; });
|
|
401
|
+
index = (index == -1) ? 0 : Math.max(0, Math.min(rows.length - 1, index + step));
|
|
402
|
+
focusedKey = rows[index].item.key;
|
|
403
|
+
paintRows();
|
|
404
|
+
scrollToRow(rows[index], "nearest");
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const onPanelKeyDown = function (self, event) {
|
|
408
|
+
|
|
409
|
+
if (!box.isOpen) return;
|
|
410
|
+
// WHY: the Enter that opened the list from the field comes here too (window), it must not select at once
|
|
411
|
+
if (event.target == box.elem) return;
|
|
412
|
+
|
|
413
|
+
if (event.key == "Escape") {
|
|
414
|
+
event.preventDefault();
|
|
415
|
+
box.close();
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (event.key == "ArrowDown" || event.key == "ArrowUp") {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
moveFocus(event.key == "ArrowDown" ? 1 : -1);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (event.key != "Enter") return;
|
|
424
|
+
if (event.target == box.panel.btnClose.elem) return; // (its own click)
|
|
425
|
+
|
|
426
|
+
// Enter: the item of the arrow keys, or the first item that is seen (after a search)
|
|
427
|
+
const rows = getShownRows();
|
|
428
|
+
const row = rows.find(function (r) { return r.item.key == focusedKey; }) || rows[0];
|
|
429
|
+
if (!row) return;
|
|
430
|
+
event.preventDefault();
|
|
431
|
+
selectFromList(row.item.key);
|
|
432
|
+
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const selectFromList = function (key) {
|
|
436
|
+
box.setSelectedKey(key);
|
|
437
|
+
box.close();
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// *** PUBLIC FUNCTIONS:
|
|
441
|
+
|
|
442
|
+
// silent: 1 -> onChange is not called.
|
|
443
|
+
box.setSelectedKey = function (key, silent = 0) {
|
|
444
|
+
if (!findItem(key)) return;
|
|
445
|
+
if (box.selectedKey == key) return;
|
|
446
|
+
box.selectedKey = key;
|
|
447
|
+
applyContent();
|
|
448
|
+
paintRows();
|
|
449
|
+
if (!silent) box.onChange(box);
|
|
450
|
+
};
|
|
451
|
+
// USAGE: get: select.selectedKey, set: select.setSelectedKey("peach")
|
|
452
|
+
|
|
453
|
+
box.setSelectedIndex = function (index, silent = 0) {
|
|
454
|
+
const item = box.items[index];
|
|
455
|
+
if (item) box.setSelectedKey(item.key, silent);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
box.getSelectedIndex = function () {
|
|
459
|
+
return box.items.indexOf(findItem(box.selectedKey));
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
box.getSelectedItem = function () {
|
|
463
|
+
return findItem(box.selectedKey);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// A new list. The selected key stays when it is in the new list; else the first item. (onChange is not called)
|
|
467
|
+
box.setItems = function (items) {
|
|
468
|
+
box.close();
|
|
469
|
+
removePanel(); // (made again with the new items at the next open)
|
|
470
|
+
box.items = FullScreenSelect.toItems(items);
|
|
471
|
+
if (!findItem(box.selectedKey)) box.selectedKey = box.items.length ? box.items[0].key : null;
|
|
472
|
+
applyContent();
|
|
473
|
+
};
|
|
474
|
+
// USAGE: select.setItems(["On", "Off", "Automatic"])
|
|
475
|
+
|
|
476
|
+
box.open = function () {
|
|
477
|
+
|
|
478
|
+
if (box.isOpen || box.items.length == 0) return;
|
|
479
|
+
if (FullScreenSelect.openedSelect) FullScreenSelect.openedSelect.close();
|
|
480
|
+
|
|
481
|
+
box.isOpen = 1;
|
|
482
|
+
FullScreenSelect.openedSelect = box;
|
|
483
|
+
if (!box.panel) createPanel();
|
|
484
|
+
box.panel.zIndex = basic.zIndexAbove(box, _s.panel.zIndex); // WHY at open: a field in a Dialog (4000 and up) opens its list over it
|
|
485
|
+
applyContent();
|
|
486
|
+
showPanel(1);
|
|
487
|
+
resetPanel(); // (after showPanel: a hidden list can not scroll to the selected item)
|
|
488
|
+
|
|
489
|
+
if (box.panel.searchInput) box.panel.searchInput.focus();
|
|
490
|
+
else box.panel.btnClose.elem.focus();
|
|
491
|
+
box.onOpen(box);
|
|
492
|
+
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
box.close = function () {
|
|
496
|
+
|
|
497
|
+
if (!box || !box.isOpen) return;
|
|
498
|
+
|
|
499
|
+
box.isOpen = 0;
|
|
500
|
+
if (FullScreenSelect.openedSelect == box) FullScreenSelect.openedSelect = null;
|
|
501
|
+
applyContent();
|
|
502
|
+
showPanel(0);
|
|
503
|
+
|
|
504
|
+
box.elem.focus();
|
|
505
|
+
box.onClose(box);
|
|
506
|
+
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// REMOVE: the static openedSelect must not keep a removed select. (The list goes with box.own.)
|
|
510
|
+
const superRemove = box.remove;
|
|
511
|
+
box.superRemove = superRemove;
|
|
512
|
+
box.remove = function () {
|
|
513
|
+
if (!box) return;
|
|
514
|
+
if (FullScreenSelect.openedSelect == box) FullScreenSelect.openedSelect = null;
|
|
515
|
+
superRemove.call(box);
|
|
516
|
+
box = null;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// *** OBJECT VIEW:
|
|
520
|
+
|
|
521
|
+
box.props(_s.box);
|
|
522
|
+
box.clickable = 1;
|
|
523
|
+
box.cursor = "pointer";
|
|
524
|
+
box.role = "combobox";
|
|
525
|
+
box.tabIndex = 0;
|
|
526
|
+
box.aria = { haspopup: "listbox" };
|
|
527
|
+
box.setFocusRing(_s.focus.ringColor);
|
|
528
|
+
|
|
529
|
+
// LABEL: The text of the selected item (it fades out at the right side, before the arrows)
|
|
530
|
+
box.lblText = Label({
|
|
531
|
+
left: _s.label.left,
|
|
532
|
+
width: (box.autoWidth == 1) ? "auto" : "calc(100% - " + (_s.label.left + ARROWS_ROOM) + "px)",
|
|
533
|
+
fontSize: _s.label.fontSize,
|
|
534
|
+
textColor: _s.label.textColor,
|
|
535
|
+
css: { top: "50%", transform: "translateY(-50%)", whiteSpace: "nowrap", overflow: "hidden" },
|
|
536
|
+
});
|
|
537
|
+
if (box.autoWidth != 1) {
|
|
538
|
+
// WHY a mask: a long text fades out before the arrows on any color of the field
|
|
539
|
+
const fade = "linear-gradient(to right, black calc(100% - " + TEXT_FADE + "px), transparent)";
|
|
540
|
+
box.lblText.css = { maskImage: fade, webkitMaskImage: fade };
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// ICON: Up and down arrows
|
|
544
|
+
box.imgArrowUp = createArrow(1);
|
|
545
|
+
box.imgArrowDown = createArrow(0);
|
|
546
|
+
|
|
547
|
+
// *** OBJECT INIT CODE:
|
|
548
|
+
|
|
549
|
+
if (box.selectedKey === null || !findItem(box.selectedKey)) {
|
|
550
|
+
box.selectedKey = box.items.length ? box.items[0].key : null;
|
|
551
|
+
}
|
|
552
|
+
applyContent();
|
|
553
|
+
box.lblText.onResize(fitAutoWidth);
|
|
554
|
+
|
|
555
|
+
box.on("click", function () { box.open(); });
|
|
556
|
+
box.on("keydown", function (self, event) {
|
|
557
|
+
if (event.key != "Enter" && event.key != " " && event.key != "ArrowDown") return;
|
|
558
|
+
event.preventDefault();
|
|
559
|
+
box.open();
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
return endObject(box);
|
|
563
|
+
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
567
|
+
|
|
568
|
+
FullScreenSelect.openedSelect = null; // The select whose list is open
|
|
569
|
+
|
|
570
|
+
// [{ key, text }] from items: objects { key, text } or texts
|
|
571
|
+
FullScreenSelect.toItems = function (items) {
|
|
572
|
+
if (!Array.isArray(items)) return [];
|
|
573
|
+
return items.map(function (item) {
|
|
574
|
+
if (item === null || typeof item !== "object") return { key: String(item), text: String(item) };
|
|
575
|
+
const text = (item.text === undefined || item.text === null) ? String(item.key) : String(item.text);
|
|
576
|
+
return { key: item.key, text: text };
|
|
577
|
+
});
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// Lower case, the Turkish letters without their marks: "İstanbul" is found with "istanbul".
|
|
581
|
+
FullScreenSelect.toSearchText = function (value) {
|
|
582
|
+
const text = (value === undefined || value === null) ? "" : String(value);
|
|
583
|
+
return text.toLocaleLowerCase("tr").normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/ı/g, "i");
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// *** STYLE PACKAGES:
|
|
587
|
+
// USAGE: FullScreenSelect({ styleName: "dark" })
|
|
588
|
+
// USAGE: FullScreenSelect({ style: { itemSelected: { color: "#BFDBC9" } } }) // Change only some keys.
|
|
589
|
+
// NOTE: A new package needs only the keys that differ from the light style.
|
|
590
|
+
FullScreenSelect.styles = {
|
|
591
|
+
|
|
592
|
+
// A whitesmoke field, a white list, a soft yellow selected item.
|
|
593
|
+
light: FullScreenSelectDefaults.style,
|
|
594
|
+
|
|
595
|
+
// For a dark page.
|
|
596
|
+
dark: {
|
|
597
|
+
box: { color: "#2B2D31", round: 4, border: 0 },
|
|
598
|
+
focus: { ringColor: "rgba(95, 179, 181, 0.7)" },
|
|
599
|
+
label: { left: 10, fontSize: 20, textColor: "rgba(255, 255, 255, 0.88)" },
|
|
600
|
+
arrow: { size: 16, right: 8, gap: 7, opacity: 0.7, invert: 1 },
|
|
601
|
+
panel: { color: "#1E1F22", zIndex: 3000, slide: 150 },
|
|
602
|
+
search: { left: 20, top: 40, height: 50, closeGap: 10, color: "#2B2D31", textColor: "rgba(255, 255, 255, 0.85)", round: 25, fontSize: 20, iconOpacity: 0.5 },
|
|
603
|
+
searchStyleName: "ozdenDark",
|
|
604
|
+
closeButton: { size: 30, right: 20, top: 50, color: "#3A3C41", iconSize: 14, iconOpacity: 0.7, invert: 1 },
|
|
605
|
+
item: { height: 60, sideSpace: 20, round: 4, color: "#1E1F22", fontSize: 20, textColor: "rgba(255, 255, 255, 0.8)", textLeft: 30 },
|
|
606
|
+
itemHover: { color: "#26282C" },
|
|
607
|
+
itemFocus: { color: "#2B2D31" },
|
|
608
|
+
itemSelected: { color: "#4A4128" },
|
|
609
|
+
empty: { fontSize: 16, textColor: "rgba(255, 255, 255, 0.45)", top: 30 },
|
|
610
|
+
scrollBar: { neverHide: 0, showDots: 0, bar_color: "#A0A0A0", bar_mouseOverColor: "#D0D0D0" },
|
|
611
|
+
},
|
|
612
|
+
|
|
613
|
+
};
|
|
614
|
+
FullScreenSelect.styles.classic = FullScreenSelect.styles.light; // the old name of light: the pages made with it keep their look
|