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 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#141414"><path d="M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z"/></svg>
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Tiny Select - v24.06
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- You can customize, this template code as you need:
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Started Date: June 2024
|
|
12
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
13
|
+
|
|
14
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
15
|
+
Licensed under the Apache License, Version 2.0
|
|
16
|
+
SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
// Default values
|
|
23
|
+
const TinySelectDefaults = {
|
|
24
|
+
titleText: "",
|
|
25
|
+
list: [], // [{ value: "1", label: "(none)" },]
|
|
26
|
+
onChange: function(self) {}, // Another item is chosen: self.selectedIndex, self.getSelectedItem() ({ value, label }). Not at create time; setSelectedIndex(index) calls it, setSelectedIndex(index, 1) does not.
|
|
27
|
+
selectedIndex: 0,
|
|
28
|
+
fontSize: 20,
|
|
29
|
+
border: 0,
|
|
30
|
+
color: "transparent", // "whitesmoke"
|
|
31
|
+
round: 3,
|
|
32
|
+
width: "auto",
|
|
33
|
+
height: 50,
|
|
34
|
+
paddingX: 12,
|
|
35
|
+
enabled: 1, // 0: it can not be opened, a little transparent (setEnabled)
|
|
36
|
+
arrowIconFile: "data:image/svg+xml;utf8," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#141414"><path d="M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z"/></svg>'),
|
|
37
|
+
arrowBorder: 0, // 1
|
|
38
|
+
arrowBorderColor: "rgba(0, 0, 0, 0.2)",
|
|
39
|
+
arrowBackgroundColor: "transparent", // "white"
|
|
40
|
+
arrowRound: 3, // 30
|
|
41
|
+
arrowSize: 24,
|
|
42
|
+
listFontSize: 14,
|
|
43
|
+
listTextColor: "rgba(0, 0, 0, 0.8)",
|
|
44
|
+
listOverTextColor: "indianred",
|
|
45
|
+
listBackgroundColor: "whitesmoke",
|
|
46
|
+
listBorder: 1,
|
|
47
|
+
listBorderColor: "rgba(0, 0, 0, 0.6)",
|
|
48
|
+
emptyText: "Empty",
|
|
49
|
+
allowHtml: 0, // 1: titleText, emptyText and the labels of the list are HTML (only for your own texts)
|
|
50
|
+
invertIconColor: 0,
|
|
51
|
+
labelBold: 1,
|
|
52
|
+
labelTextColor: "rgba(0,0,0,0.8)",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const TinySelect = function(params = {}) {
|
|
56
|
+
|
|
57
|
+
// Merge params:
|
|
58
|
+
mergeIntoIfMissing(params, TinySelectDefaults);
|
|
59
|
+
|
|
60
|
+
// BOX: Component container
|
|
61
|
+
const box = startObject(params);
|
|
62
|
+
|
|
63
|
+
// *** PRIVATE VARIABLES:
|
|
64
|
+
const DISABLED_OPACITY = 0.6;
|
|
65
|
+
|
|
66
|
+
// *** PRIVATE FUNCTIONS:
|
|
67
|
+
|
|
68
|
+
const setText = function (label, text) {
|
|
69
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
70
|
+
if (box.allowHtml == 1) label.text = value;
|
|
71
|
+
else label.plainText = value;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// *** PUBLIC VARIABLES:
|
|
75
|
+
|
|
76
|
+
// To close listBox if opened (when listBox created will also put a function in this)
|
|
77
|
+
box.closeListBox = null;
|
|
78
|
+
|
|
79
|
+
/*
|
|
80
|
+
- the list again, and the item of the given index selected
|
|
81
|
+
|
|
82
|
+
list: [{ value: "1", label: "(none)" },]
|
|
83
|
+
selectedIndex: 0
|
|
84
|
+
|
|
85
|
+
object.setList([{ value: "1", label: "(none)" },], 0);
|
|
86
|
+
|
|
87
|
+
*/
|
|
88
|
+
box.setList = function(list, selectedIndex = 0) {
|
|
89
|
+
|
|
90
|
+
box.list = list;
|
|
91
|
+
box.setSelectedIndex(selectedIndex);
|
|
92
|
+
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Chooses the item at index; an index that is not in the list shows emptyText. silent: 1 -> onChange is not called.
|
|
96
|
+
box.setSelectedIndex = function(index, silent = 0) {
|
|
97
|
+
|
|
98
|
+
box.selectedIndex = index;
|
|
99
|
+
|
|
100
|
+
// WHY not list.length > index: -1 (getIndexByValue of a value not in the list) passed it and threw.
|
|
101
|
+
const item = box.getSelectedItem();
|
|
102
|
+
if (item) {
|
|
103
|
+
setText(box.lblLabel, item.label);
|
|
104
|
+
if (!silent) box.onChange(box);
|
|
105
|
+
} else {
|
|
106
|
+
setText(box.lblLabel, box.emptyText);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (box.closeListBox != null) box.closeListBox();
|
|
110
|
+
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Change the title
|
|
114
|
+
box.setTitleText = function(titleText) {
|
|
115
|
+
|
|
116
|
+
box.titleText = titleText;
|
|
117
|
+
setText(box.lblTitle, (box.titleText) ? box.titleText + ":" : "");
|
|
118
|
+
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// 0: it can not be opened (a little transparent)
|
|
122
|
+
box.setEnabled = function(value) {
|
|
123
|
+
|
|
124
|
+
box.enabled = basic.isOn(value) ? 1 : 0;
|
|
125
|
+
box.clickable = box.enabled;
|
|
126
|
+
box.opacity = (box.enabled) ? 1 : DISABLED_OPACITY;
|
|
127
|
+
|
|
128
|
+
};
|
|
129
|
+
// USAGE: tinySelect.setEnabled(0)
|
|
130
|
+
|
|
131
|
+
// The chosen item ({ value, label }), or null
|
|
132
|
+
box.getSelectedItem = function() {
|
|
133
|
+
return box.list[box.selectedIndex] || null;
|
|
134
|
+
};
|
|
135
|
+
// USAGE: const item = tinySelect.getSelectedItem();
|
|
136
|
+
|
|
137
|
+
box.getIndexByValue = function(value) {
|
|
138
|
+
return box.list.findIndex(item => item.value === value);
|
|
139
|
+
};
|
|
140
|
+
// USAGE: tinySelect.setSelectedIndex(tinySelect.getIndexByValue("tr"))
|
|
141
|
+
|
|
142
|
+
box.setColor = function(color) {
|
|
143
|
+
box.color = color;
|
|
144
|
+
};
|
|
145
|
+
// USAGE: get: componentName.color, set: componentName.setColor("red")
|
|
146
|
+
|
|
147
|
+
// *** OBJECT VIEW:
|
|
148
|
+
// WHY: In a row (the protocol of UrlField), a box shrinks for its "100%" neighbour and cut "https://www.".
|
|
149
|
+
// A flex group does not shrink (flexShrink 0): the same here.
|
|
150
|
+
box.shrink = 0;
|
|
151
|
+
box.css.whiteSpace = "nowrap";
|
|
152
|
+
box.cursor = "pointer";
|
|
153
|
+
box.clickable = 1;
|
|
154
|
+
|
|
155
|
+
// GROUP: title, label, arrow
|
|
156
|
+
// WHY: A box with width "auto" does not grow with its children; a relative group inside it does (as CheckBox).
|
|
157
|
+
box.contentBox = HGroup({
|
|
158
|
+
width: "auto",
|
|
159
|
+
height: "100%",
|
|
160
|
+
position: "relative",
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// LABEL: Title
|
|
164
|
+
box.lblTitle = Label({
|
|
165
|
+
fontSize: box.fontSize,
|
|
166
|
+
});
|
|
167
|
+
that.css.marginLeft = box.paddingX + "px";
|
|
168
|
+
|
|
169
|
+
// LABEL: Label
|
|
170
|
+
box.lblLabel = Label({
|
|
171
|
+
fontSize: box.fontSize,
|
|
172
|
+
textColor: box.labelTextColor,
|
|
173
|
+
});
|
|
174
|
+
if (box.labelBold == 1) that.css.fontFamily = "opensans-bold";
|
|
175
|
+
that.css = { marginLeft: "6px", marginRight: "4px" };
|
|
176
|
+
|
|
177
|
+
// ICON: Arrow
|
|
178
|
+
box.icoArrow = Icon({
|
|
179
|
+
width: box.arrowSize,
|
|
180
|
+
height: box.arrowSize,
|
|
181
|
+
color: box.arrowBackgroundColor,
|
|
182
|
+
border: box.arrowBorder,
|
|
183
|
+
borderColor: box.arrowBorderColor,
|
|
184
|
+
round: box.arrowRound,
|
|
185
|
+
space: 0,
|
|
186
|
+
});
|
|
187
|
+
that.load(box.arrowIconFile);
|
|
188
|
+
that.setMotion("transform 0.3s");
|
|
189
|
+
that.css = { marginTop: "2px", marginRight: box.paddingX + "px" };
|
|
190
|
+
if (box.invertIconColor == 1) that.css.filter = "invert(100%)";
|
|
191
|
+
|
|
192
|
+
endGroup();
|
|
193
|
+
|
|
194
|
+
// WHY: The open list is on the page (TinySelect.createList). A remove() while it was open left it there.
|
|
195
|
+
const superRemove = box.remove;
|
|
196
|
+
box.superRemove = superRemove;
|
|
197
|
+
let isRemoved = 0;
|
|
198
|
+
box.remove = function() {
|
|
199
|
+
if (isRemoved) return;
|
|
200
|
+
isRemoved = 1;
|
|
201
|
+
if (box.closeListBox) box.closeListBox();
|
|
202
|
+
superRemove.call(box);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// *** OBJECT INIT CODE:
|
|
206
|
+
box.on("click", function() {
|
|
207
|
+
TinySelect.createList(box);
|
|
208
|
+
});
|
|
209
|
+
box.setTitleText(box.titleText);
|
|
210
|
+
// WHY: Silent: onChange is a choice of the user, not the start value (the pages that use it
|
|
211
|
+
// guarded against this first call with isReady / isRendering).
|
|
212
|
+
box.setSelectedIndex(box.selectedIndex, 1);
|
|
213
|
+
box.setEnabled(box.enabled);
|
|
214
|
+
|
|
215
|
+
return endObject(box);
|
|
216
|
+
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
TinySelect.Z_INDEX = 1000; // the list on page; over a Dialog or a SidePanel that holds the field (basic.zIndexAbove)
|
|
220
|
+
TinySelect.PAGE_MARGIN = 8; // px: the list stays this far from the top and the bottom of the page
|
|
221
|
+
TinySelect.MIN_LIST_HEIGHT = 80; // px: the list is not made shorter than this to fit the page (it scrolls)
|
|
222
|
+
|
|
223
|
+
// Create a tiny list to user selection
|
|
224
|
+
TinySelect.createList = function(connectedUI) {
|
|
225
|
+
|
|
226
|
+
if (connectedUI.list.length <= 0) return null;
|
|
227
|
+
|
|
228
|
+
connectedUI.icoArrow.rotate = 180;
|
|
229
|
+
|
|
230
|
+
connectedUI.closeListBox = function() {
|
|
231
|
+
connectedUI.icoArrow.rotate = 0;
|
|
232
|
+
listBox.remove();
|
|
233
|
+
connectedUI.closeListBox = null;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const listBox = startFlexBox();
|
|
237
|
+
that.color = "transparent";
|
|
238
|
+
that.css.whiteSpace = "nowrap";
|
|
239
|
+
page.add(that);
|
|
240
|
+
listBox.zIndex = basic.zIndexAbove(connectedUI, TinySelect.Z_INDEX); // WHY: it had none: under a Dialog or a SidePanel
|
|
241
|
+
|
|
242
|
+
listBox.grp = startFlexBox({
|
|
243
|
+
flexDirection: "column",
|
|
244
|
+
alignItems: "flex-start",
|
|
245
|
+
color: connectedUI.listBackgroundColor,
|
|
246
|
+
width: "auto",
|
|
247
|
+
height: "auto",
|
|
248
|
+
border: connectedUI.listBorder,
|
|
249
|
+
borderColor: connectedUI.listBorderColor,
|
|
250
|
+
round: 3,
|
|
251
|
+
});
|
|
252
|
+
that.css.padding = "5px";
|
|
253
|
+
that.cursor = "pointer";
|
|
254
|
+
that.position = "absolute";
|
|
255
|
+
|
|
256
|
+
for (let i = 0; i < connectedUI.list.length; i++) {
|
|
257
|
+
const lbl = Label({
|
|
258
|
+
fontSize: connectedUI.listFontSize,
|
|
259
|
+
index: i,
|
|
260
|
+
spaceX: 6,
|
|
261
|
+
textColor: connectedUI.listTextColor,
|
|
262
|
+
});
|
|
263
|
+
if (connectedUI.allowHtml == 1) lbl.text = connectedUI.list[i].label;
|
|
264
|
+
else lbl.plainText = connectedUI.list[i].label;
|
|
265
|
+
lbl.elem.style.flexShrink = "0"; // WHY: in a list made shorter to fit the page, the items scroll, not shrink
|
|
266
|
+
|
|
267
|
+
if (connectedUI.selectedIndex != lbl.index) {
|
|
268
|
+
|
|
269
|
+
that.on("click", function() {
|
|
270
|
+
connectedUI.setSelectedIndex(lbl.index);
|
|
271
|
+
});
|
|
272
|
+
that.on("mouseover", function() {
|
|
273
|
+
lbl.textColor = connectedUI.listOverTextColor;
|
|
274
|
+
});
|
|
275
|
+
that.on("mouseout", function() {
|
|
276
|
+
lbl.textColor = connectedUI.listTextColor;
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
} else {
|
|
280
|
+
lbl.opacity = 0.5;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
endFlexBox();
|
|
285
|
+
|
|
286
|
+
listBox.on("click", function() {
|
|
287
|
+
if (connectedUI.closeListBox != null) connectedUI.closeListBox();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// WHY: totalLeft/totalTop do not count the scroll of parent boxes. In a scrolled page, the list was opened at a wrong place.
|
|
291
|
+
const rect = connectedUI.elem.getBoundingClientRect();
|
|
292
|
+
const fieldTop = withPageZoom(rect.top);
|
|
293
|
+
const fieldBottom = withPageZoom(rect.bottom);
|
|
294
|
+
// WHY the room: the list was always under the field, with no limit: near the bottom of the page (it never scrolls)
|
|
295
|
+
// its items were below the page and could not be chosen
|
|
296
|
+
const listHeight = listBox.grp.height;
|
|
297
|
+
const roomBelow = page.height - fieldBottom - TinySelect.PAGE_MARGIN;
|
|
298
|
+
const roomAbove = fieldTop - TinySelect.PAGE_MARGIN;
|
|
299
|
+
const isAbove = (listHeight > roomBelow && roomAbove > roomBelow);
|
|
300
|
+
const room = Math.max(TinySelect.MIN_LIST_HEIGHT, isAbove ? roomAbove : roomBelow);
|
|
301
|
+
if (listHeight > room) {
|
|
302
|
+
listBox.grp.height = room;
|
|
303
|
+
listBox.grp.scrollY = 1;
|
|
304
|
+
}
|
|
305
|
+
listBox.grp.left = withPageZoom(rect.right) - listBox.grp.width;
|
|
306
|
+
listBox.grp.top = isAbove ? fieldTop - Math.min(listHeight, room) : fieldBottom;
|
|
307
|
+
|
|
308
|
+
endFlexBox();
|
|
309
|
+
|
|
310
|
+
// When the size of the page changes, an open list closes.
|
|
311
|
+
// NOTE: The first two calls are not a page resize: they come from opening the list.
|
|
312
|
+
let resizeCount = 0;
|
|
313
|
+
|
|
314
|
+
listBox.onResize(function() {
|
|
315
|
+
if (resizeCount > 1 && connectedUI.closeListBox != null) connectedUI.closeListBox();
|
|
316
|
+
resizeCount++;
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
makeBasicObject(listBox);
|
|
320
|
+
return listBox;
|
|
321
|
+
|
|
322
|
+
};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Tiny Table - v26.10
|
|
6
|
+
|
|
7
|
+
A light table for short lists: a colored title row, one line rows (a long text ends with "..."), a soft color under
|
|
8
|
+
the mouse.
|
|
9
|
+
WHEN TO USE IT: a small table between the lines of a page, like a table in a text, for small
|
|
10
|
+
data that needs nothing more: it has no sorting, no search and no selection. A table with them: comp/data-table.js
|
|
11
|
+
(DataTable); very big data: comp/smart-table.js (SmartTable).
|
|
12
|
+
- columns: [{ title, width, align }]; rows: [["1", "404", "Not found"], ...]. The texts are plain text;
|
|
13
|
+
allowHtml: 1 lets them be HTML (Ex: <b>bold</b>), only for texts of your own code, never for user input.
|
|
14
|
+
- bodyHeight: "auto" (as high as the rows) or a number: the rows scroll (basic/scroll-bar.js ScrollBar when loaded).
|
|
15
|
+
- A text that does not fit ends with "..." and slides under the mouse (comp/scrolling-text.js ScrollingText,
|
|
16
|
+
mode "hover"; load it first. Without it: only "..."). The text of a cell or a title is cell.label.
|
|
17
|
+
- onCellCreate(cell, self): change a cell when it is made (cell.rowIndex, cell.columnIndex, cell.value, cell.label).
|
|
18
|
+
- onRowClick(self, rowIndex): a click on a row.
|
|
19
|
+
- setRows(rows): new rows (the cells are made again).
|
|
20
|
+
- Style packages: "classic" (default), "light", "dark". (TinyTable.styles)
|
|
21
|
+
|
|
22
|
+
USAGE:
|
|
23
|
+
TinyTable({
|
|
24
|
+
columns: [{ title: "ID", width: 50, align: "center" }, { title: "VALUE", width: 80 }, { title: "DESCRIPTION", width: 380 }],
|
|
25
|
+
rows: [["1", "404", "HTTP status code for Not Found"], ["2", "null", "The absence of a value"]],
|
|
26
|
+
style: { header: { color: "indianred" } },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Started Date: October 2026
|
|
30
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
31
|
+
|
|
32
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
33
|
+
Licensed under the Apache License, Version 2.0
|
|
34
|
+
SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
"use strict";
|
|
39
|
+
|
|
40
|
+
// Default values:
|
|
41
|
+
const TinyTableDefaults = {
|
|
42
|
+
width: "auto", // As wide as the columns
|
|
43
|
+
height: "auto",
|
|
44
|
+
columns: [], // [{ title, width (px), align: "left" | "center" | "right" }]
|
|
45
|
+
rows: [], // [["text", "text", ...], ...]
|
|
46
|
+
bodyHeight: "auto", // "auto" or a number: the rows scroll
|
|
47
|
+
allowHtml: 0, // 1: the titles and the cells are HTML (only for your own texts)
|
|
48
|
+
onCellCreate: function (cell, self) {}, // cell.rowIndex, cell.columnIndex, cell.value, cell.label (Ex: cell.label.bold = 1)
|
|
49
|
+
onRowClick: function (self, rowIndex) {},
|
|
50
|
+
styleName: "classic", // "classic", "light", "dark" or a name added to TinyTable.styles
|
|
51
|
+
style: { // Classic style package (default)
|
|
52
|
+
box: { color: "white", border: 2, borderColor: "#141414", round: 4 },
|
|
53
|
+
header: { color: "#141414", lineColor: "#141414", textColor: "white", fontSize: 18, padding: [8, 8] },
|
|
54
|
+
body: { color: "white", paddingY: 10 },
|
|
55
|
+
cell: { textColor: "rgba(0, 0, 0, 0.9)", fontSize: 16, padding: [8, 4] },
|
|
56
|
+
rowHover: { color: "whitesmoke", lineColor: "rgba(0, 0, 0, 0.2)" },
|
|
57
|
+
scrollBar: { neverHide: 0, showDots: 0 },
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const TinyTable = function (params = {}) {
|
|
62
|
+
|
|
63
|
+
// Merge style package: params.style > TinyTable.styles[styleName] > TinyTableDefaults.style (classic)
|
|
64
|
+
basic.applyStylePackage(params, TinyTable.styles, TinyTableDefaults);
|
|
65
|
+
|
|
66
|
+
// Merge params:
|
|
67
|
+
mergeIntoIfMissing(params, TinyTableDefaults);
|
|
68
|
+
|
|
69
|
+
// Edit params: copies, the caller's lists do not change
|
|
70
|
+
params.columns = Array.isArray(params.columns) ? params.columns.slice() : [];
|
|
71
|
+
params.rows = Array.isArray(params.rows) ? params.rows.slice() : [];
|
|
72
|
+
|
|
73
|
+
// BOX: Component container
|
|
74
|
+
let box = startObject(params);
|
|
75
|
+
|
|
76
|
+
// *** PRIVATE VARIABLES:
|
|
77
|
+
const _s = box.style;
|
|
78
|
+
const LINE_WIDTH = 1; // between two titles / two cells
|
|
79
|
+
const isScrolling = (params.bodyHeight !== "auto");
|
|
80
|
+
|
|
81
|
+
// *** PUBLIC VARIABLES:
|
|
82
|
+
box.rowList = []; // The row groups (row.cells: the labels)
|
|
83
|
+
|
|
84
|
+
// *** PRIVATE FUNCTIONS:
|
|
85
|
+
|
|
86
|
+
const toText = function (value) {
|
|
87
|
+
return (value === undefined || value === null) ? "" : String(value);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// A text of a cell or a title. A text that does not fit: "..." and it slides under the mouse (ScrollingText).
|
|
91
|
+
// The text itself is item.label (the same with a plain Label).
|
|
92
|
+
const createTextItem = function (value, width, look, align) {
|
|
93
|
+
|
|
94
|
+
if (typeof ScrollingText !== "undefined") {
|
|
95
|
+
const item = ScrollingText({
|
|
96
|
+
width: width,
|
|
97
|
+
labelText: toText(value),
|
|
98
|
+
allowHtml: box.allowHtml,
|
|
99
|
+
mode: "hover",
|
|
100
|
+
style: {
|
|
101
|
+
box: { color: look.color || "transparent", padding: look.padding },
|
|
102
|
+
label: { fontSize: look.fontSize, textColor: look.textColor, textAlign: align },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
item.shrink = 0;
|
|
106
|
+
return item;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const label = Label({
|
|
110
|
+
width: width,
|
|
111
|
+
padding: look.padding,
|
|
112
|
+
color: look.color || "transparent",
|
|
113
|
+
textColor: look.textColor,
|
|
114
|
+
fontSize: look.fontSize,
|
|
115
|
+
textAlign: align,
|
|
116
|
+
ellipsis: 1,
|
|
117
|
+
shrink: 0,
|
|
118
|
+
});
|
|
119
|
+
if (box.allowHtml == 1) label.text = toText(value);
|
|
120
|
+
else label.plainText = toText(value);
|
|
121
|
+
label.label = label;
|
|
122
|
+
return label;
|
|
123
|
+
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const getColumnWidth = function (index) {
|
|
127
|
+
const column = box.columns[index];
|
|
128
|
+
return (column && column.width) ? column.width : "auto";
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// One cell of a row. Its container must be set.
|
|
132
|
+
const createCell = function (value, rowIndex, columnIndex) {
|
|
133
|
+
const column = box.columns[columnIndex] || {};
|
|
134
|
+
const cell = createTextItem(value, getColumnWidth(columnIndex), _s.cell, column.align || "left");
|
|
135
|
+
cell.rowIndex = rowIndex;
|
|
136
|
+
cell.columnIndex = columnIndex;
|
|
137
|
+
cell.value = value;
|
|
138
|
+
box.onCellCreate(cell, box);
|
|
139
|
+
if (cell.refresh) cell.refresh(); // WHY: onCellCreate may change the width of the text (Ex: bold)
|
|
140
|
+
return cell;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// GROUP: One row. Its container must be set.
|
|
144
|
+
const createRow = function (data, rowIndex) {
|
|
145
|
+
|
|
146
|
+
const row = HGroup({
|
|
147
|
+
width: "100%",
|
|
148
|
+
height: "auto",
|
|
149
|
+
align: "left center",
|
|
150
|
+
gap: LINE_WIDTH,
|
|
151
|
+
color: "transparent",
|
|
152
|
+
clickable: 1,
|
|
153
|
+
cursor: "pointer",
|
|
154
|
+
role: "row",
|
|
155
|
+
});
|
|
156
|
+
row.rowIndex = rowIndex;
|
|
157
|
+
row.cells = [];
|
|
158
|
+
|
|
159
|
+
(Array.isArray(data) ? data : []).forEach(function (value, columnIndex) {
|
|
160
|
+
row.cells.push(createCell(value, rowIndex, columnIndex));
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
endGroup();
|
|
164
|
+
|
|
165
|
+
row.onHoverChange(function (self, isOver) {
|
|
166
|
+
paintRow(row, isOver);
|
|
167
|
+
});
|
|
168
|
+
row.on("click", function () {
|
|
169
|
+
box.onRowClick(box, rowIndex);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return row;
|
|
173
|
+
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// Under the mouse: a soft color and a thin line over and under the row (box-shadow: the rows do not move)
|
|
177
|
+
const paintRow = function (row, isOver) {
|
|
178
|
+
const line = _s.rowHover.lineColor;
|
|
179
|
+
row.color = isOver ? _s.rowHover.color : "transparent";
|
|
180
|
+
row.boxShadow = isOver ? "inset 0 " + LINE_WIDTH + "px 0 " + line + ", inset 0 -" + LINE_WIDTH + "px 0 " + line : "none";
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const createRows = function () {
|
|
184
|
+
box.rowList.forEach(function (row) { row.remove(); });
|
|
185
|
+
box.rowList = createIn(box.rowsGroup, function () {
|
|
186
|
+
return box.rows.map(createRow);
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// *** PUBLIC FUNCTIONS:
|
|
191
|
+
|
|
192
|
+
box.setRows = function (rows) {
|
|
193
|
+
if (box._isRemoved) return; // WHY: a removed table must not get new rows (their observers stay)
|
|
194
|
+
box.rows = Array.isArray(rows) ? rows.slice() : [];
|
|
195
|
+
createRows();
|
|
196
|
+
};
|
|
197
|
+
// USAGE: table.setRows([["1", "A"], ["2", "B"]])
|
|
198
|
+
|
|
199
|
+
// *** OBJECT VIEW:
|
|
200
|
+
|
|
201
|
+
box.props(_s.box);
|
|
202
|
+
box.role = "table";
|
|
203
|
+
|
|
204
|
+
// GROUP: Layout (the title row, the rows)
|
|
205
|
+
box.layout = VGroup({ width: "auto", height: "auto", align: "left top", gap: 0, position: "relative" });
|
|
206
|
+
|
|
207
|
+
// GROUP: Title row (the lines between the titles are its color seen through the gaps)
|
|
208
|
+
box.header = HGroup({ width: "auto", height: "auto", align: "left top", gap: LINE_WIDTH, color: _s.header.lineColor, role: "row" });
|
|
209
|
+
box.header.css = { width: "max-content" };
|
|
210
|
+
|
|
211
|
+
box.titleList = box.columns.map(function (column, i) {
|
|
212
|
+
// Title
|
|
213
|
+
const title = createTextItem(column.title, getColumnWidth(i), _s.header, "left");
|
|
214
|
+
title.role = "columnheader";
|
|
215
|
+
return title;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
endGroup();
|
|
219
|
+
|
|
220
|
+
// BOX: Rows (they scroll when bodyHeight is a number)
|
|
221
|
+
box.body = startBox({
|
|
222
|
+
width: "100%",
|
|
223
|
+
height: isScrolling ? box.bodyHeight : "auto",
|
|
224
|
+
color: _s.body.color,
|
|
225
|
+
scrollY: isScrolling ? 1 : 0,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// GROUP: Rows
|
|
229
|
+
box.rowsGroup = VGroup({
|
|
230
|
+
width: "100%",
|
|
231
|
+
height: "auto",
|
|
232
|
+
align: "left top",
|
|
233
|
+
gap: 0,
|
|
234
|
+
padding: [0, _s.body.paddingY],
|
|
235
|
+
position: "relative", // WHY: the body ("auto") grows with it
|
|
236
|
+
});
|
|
237
|
+
endGroup();
|
|
238
|
+
|
|
239
|
+
endBox();
|
|
240
|
+
if (!isScrolling) box.body.position = "relative";
|
|
241
|
+
|
|
242
|
+
endGroup();
|
|
243
|
+
|
|
244
|
+
if (isScrolling && typeof ScrollBar !== "undefined") {
|
|
245
|
+
box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.body }, _s.scrollBar));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// *** OBJECT INIT CODE:
|
|
249
|
+
|
|
250
|
+
createRows();
|
|
251
|
+
|
|
252
|
+
return endObject(box);
|
|
253
|
+
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// *** STYLE PACKAGES:
|
|
257
|
+
// USAGE: TinyTable({ styleName: "light" })
|
|
258
|
+
// USAGE: TinyTable({ style: { header: { color: "indianred" } } }) // Change only some keys.
|
|
259
|
+
// NOTE: A new package needs only the keys that differ from the classic style.
|
|
260
|
+
TinyTable.styles = {
|
|
261
|
+
|
|
262
|
+
// A black title row, a black frame.
|
|
263
|
+
classic: TinyTableDefaults.style,
|
|
264
|
+
|
|
265
|
+
// A soft gray title row and frame.
|
|
266
|
+
light: {
|
|
267
|
+
box: { color: "white", border: 1, borderColor: "rgba(0, 0, 0, 0.15)", round: 6 },
|
|
268
|
+
header: { color: "#F2F3F1", lineColor: "rgba(0, 0, 0, 0.08)", textColor: "rgba(0, 0, 0, 0.75)", fontSize: 16, padding: [10, 8] },
|
|
269
|
+
cell: { textColor: "rgba(0, 0, 0, 0.75)", fontSize: 15, padding: [10, 5] },
|
|
270
|
+
rowHover: { color: "#F7F8F6", lineColor: "rgba(0, 0, 0, 0.08)" },
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
// For a dark page.
|
|
274
|
+
dark: {
|
|
275
|
+
box: { color: "#232428", border: 1, borderColor: "rgba(255, 255, 255, 0.14)", round: 6 },
|
|
276
|
+
header: { color: "#2B2D31", lineColor: "rgba(255, 255, 255, 0.1)", textColor: "rgba(255, 255, 255, 0.85)", fontSize: 16, padding: [10, 8] },
|
|
277
|
+
body: { color: "#232428", paddingY: 10 },
|
|
278
|
+
cell: { textColor: "rgba(255, 255, 255, 0.78)", fontSize: 15, padding: [10, 5] },
|
|
279
|
+
rowHover: { color: "#2E3035", lineColor: "rgba(255, 255, 255, 0.08)" },
|
|
280
|
+
scrollBar: { neverHide: 0, showDots: 0, bar_color: "#A0A0A0", bar_mouseOverColor: "#D0D0D0" },
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
};
|