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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/NOTICE +5 -0
  4. data/README.md +242 -0
  5. data/exe/ozdenui +17 -0
  6. data/lib/ozdenui/AGENTS.md +210 -0
  7. data/lib/ozdenui/COMPONENTS.md +3017 -0
  8. data/lib/ozdenui/app.rb +749 -0
  9. data/lib/ozdenui/command.rb +107 -0
  10. data/lib/ozdenui/components.rb +368 -0
  11. data/lib/ozdenui/dialogs.rb +212 -0
  12. data/lib/ozdenui/files.rb +124 -0
  13. data/lib/ozdenui/icon.png +0 -0
  14. data/lib/ozdenui/kit.json +1 -0
  15. data/lib/ozdenui/kit.rb +115 -0
  16. data/lib/ozdenui/look.rb +229 -0
  17. data/lib/ozdenui/objects.rb +652 -0
  18. data/lib/ozdenui/server.rb +270 -0
  19. data/lib/ozdenui/values.rb +273 -0
  20. data/lib/ozdenui/version.rb +15 -0
  21. data/lib/ozdenui/web/basic/LICENSE +14 -0
  22. data/lib/ozdenui/web/basic/basic.min.css +1 -0
  23. data/lib/ozdenui/web/basic/basic.min.js +78 -0
  24. data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
  25. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  26. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  27. data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
  28. data/lib/ozdenui/web/bridge.js +584 -0
  29. data/lib/ozdenui/web/comp/accordion.js +659 -0
  30. data/lib/ozdenui/web/comp/action-button/add.png +0 -0
  31. data/lib/ozdenui/web/comp/action-button.js +521 -0
  32. data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
  33. data/lib/ozdenui/web/comp/app-bar.js +237 -0
  34. data/lib/ozdenui/web/comp/badge.js +292 -0
  35. data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
  36. data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
  37. data/lib/ozdenui/web/comp/canvas.js +652 -0
  38. data/lib/ozdenui/web/comp/chat-view.js +827 -0
  39. data/lib/ozdenui/web/comp/check-box.js +490 -0
  40. data/lib/ozdenui/web/comp/code-editor.js +965 -0
  41. data/lib/ozdenui/web/comp/color-picker.js +636 -0
  42. data/lib/ozdenui/web/comp/context-menu.js +951 -0
  43. data/lib/ozdenui/web/comp/currency-field.js +209 -0
  44. data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
  45. data/lib/ozdenui/web/comp/data-table.js +937 -0
  46. data/lib/ozdenui/web/comp/date-picker.js +1055 -0
  47. data/lib/ozdenui/web/comp/dialog.js +992 -0
  48. data/lib/ozdenui/web/comp/email-field.js +65 -0
  49. data/lib/ozdenui/web/comp/file-picker.js +920 -0
  50. data/lib/ozdenui/web/comp/filters.js +807 -0
  51. data/lib/ozdenui/web/comp/form.js +602 -0
  52. data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
  53. data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
  54. data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
  55. data/lib/ozdenui/web/comp/gauge.js +439 -0
  56. data/lib/ozdenui/web/comp/graph-box.js +3911 -0
  57. data/lib/ozdenui/web/comp/grid-group.js +185 -0
  58. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
  59. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
  60. data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
  61. data/lib/ozdenui/web/comp/image-view.js +598 -0
  62. data/lib/ozdenui/web/comp/item-list.js +1740 -0
  63. data/lib/ozdenui/web/comp/json-editor.js +3221 -0
  64. data/lib/ozdenui/web/comp/json-view.js +597 -0
  65. data/lib/ozdenui/web/comp/label-editor.js +1140 -0
  66. data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
  67. data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
  68. data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
  69. data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
  70. data/lib/ozdenui/web/comp/left-menu.js +548 -0
  71. data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
  72. data/lib/ozdenui/web/comp/loading-screen.js +413 -0
  73. data/lib/ozdenui/web/comp/log-view.js +530 -0
  74. data/lib/ozdenui/web/comp/login-page.js +685 -0
  75. data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
  76. data/lib/ozdenui/web/comp/menu-bar.js +624 -0
  77. data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
  78. data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
  79. data/lib/ozdenui/web/comp/notice.js +229 -0
  80. data/lib/ozdenui/web/comp/number-field.js +128 -0
  81. data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
  82. data/lib/ozdenui/web/comp/page-control.js +762 -0
  83. data/lib/ozdenui/web/comp/page-header.js +191 -0
  84. data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
  85. data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
  86. data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
  87. data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
  88. data/lib/ozdenui/web/comp/password-field.js +192 -0
  89. data/lib/ozdenui/web/comp/period-bar.js +436 -0
  90. data/lib/ozdenui/web/comp/phone-field.js +322 -0
  91. data/lib/ozdenui/web/comp/progress-bar.js +992 -0
  92. data/lib/ozdenui/web/comp/property-panel.js +3639 -0
  93. data/lib/ozdenui/web/comp/radio-button.js +527 -0
  94. data/lib/ozdenui/web/comp/range-slider.js +569 -0
  95. data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
  96. data/lib/ozdenui/web/comp/scroll-area.js +308 -0
  97. data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
  98. data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
  99. data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
  100. data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
  101. data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
  102. data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
  103. data/lib/ozdenui/web/comp/search-input.js +725 -0
  104. data/lib/ozdenui/web/comp/search-results.js +596 -0
  105. data/lib/ozdenui/web/comp/select-box.js +1862 -0
  106. data/lib/ozdenui/web/comp/settings-row.js +299 -0
  107. data/lib/ozdenui/web/comp/side-panel.js +616 -0
  108. data/lib/ozdenui/web/comp/slider-field.js +952 -0
  109. data/lib/ozdenui/web/comp/slider.js +838 -0
  110. data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
  111. data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
  112. data/lib/ozdenui/web/comp/smart-button.js +981 -0
  113. data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
  114. data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
  115. data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
  116. data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
  117. data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
  118. data/lib/ozdenui/web/comp/smart-table.js +1883 -0
  119. data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
  120. data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
  121. data/lib/ozdenui/web/comp/splitter.js +411 -0
  122. data/lib/ozdenui/web/comp/status-bar.js +408 -0
  123. data/lib/ozdenui/web/comp/step-bar.js +345 -0
  124. data/lib/ozdenui/web/comp/stepper.js +753 -0
  125. data/lib/ozdenui/web/comp/tabs.js +1366 -0
  126. data/lib/ozdenui/web/comp/tag-input.js +1107 -0
  127. data/lib/ozdenui/web/comp/tap-effect.js +170 -0
  128. data/lib/ozdenui/web/comp/text-area-field.js +233 -0
  129. data/lib/ozdenui/web/comp/text-field.js +1006 -0
  130. data/lib/ozdenui/web/comp/time-line.js +398 -0
  131. data/lib/ozdenui/web/comp/time-picker.js +1032 -0
  132. data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
  133. data/lib/ozdenui/web/comp/tiny-select.js +322 -0
  134. data/lib/ozdenui/web/comp/tiny-table.js +283 -0
  135. data/lib/ozdenui/web/comp/toast.js +891 -0
  136. data/lib/ozdenui/web/comp/toggle.js +757 -0
  137. data/lib/ozdenui/web/comp/tool-bar.js +760 -0
  138. data/lib/ozdenui/web/comp/tooltip.js +534 -0
  139. data/lib/ozdenui/web/comp/tree-view.js +1179 -0
  140. data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
  141. data/lib/ozdenui/web/comp/ui-standards.js +403 -0
  142. data/lib/ozdenui/web/comp/url-field.js +190 -0
  143. data/lib/ozdenui/web/comp/web-view.js +588 -0
  144. data/lib/ozdenui/web/components.js +123 -0
  145. data/lib/ozdenui/web/index.html +39 -0
  146. data/lib/ozdenui/window.rb +188 -0
  147. data/lib/ozdenui/window_cocoa.rb +221 -0
  148. data/lib/ozdenui.rb +32 -0
  149. metadata +200 -0
@@ -0,0 +1,596 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Search Results - v26.09
6
+
7
+ UI COMPONENT
8
+ - The result list that opens under a search input. (Command palette / autocomplete.)
9
+ - The items are plain objects: { text, description, group }. Anything else you put in them comes back
10
+ to you in onSelect, so the page decides what "opening a result" means.
11
+ - Group headers: the items are shown in the order they are given, and a new "group" value starts
12
+ a new header. (Ex: "Pages", "Users", "Orders")
13
+ - It is always created on the page and placed with fixed position, so it is never clipped by the
14
+ bar or the group it is called from, and it stays on the screen on a small screen.
15
+ - The width: maxWidth (default 380) whatever the width of the anchor; matchAnchorWidth: 1
16
+ makes the list as wide as the anchor, so both edges meet on a phone and on a wide screen (maxWidth is not used
17
+ then). Never wider than the screen. setMatchAnchorWidth(). Sample: 02-comp-examples/search-results.htm
18
+ - The list scrolls with basic/scroll-bar.js (ScrollBar), not with the scrollbar of the browser.
19
+ - attachTo(inputElement) does the whole keyboard work: ArrowUp / ArrowDown move, Enter opens,
20
+ Escape closes, focus reopens the last results and blur closes them.
21
+ - The texts are written with plainText (textContent), so a name with < or & is shown as it is.
22
+ - Style packages: "light" (default; the old name "classic" works too), "dark", "modern". Select with styleName. (SearchResults.styles)
23
+
24
+ USAGE:
25
+ const results = SearchResults({
26
+ anchor: searchInput, // The object the list opens under
27
+ styleName: "dark",
28
+ onSelect: function (self, item) { item.open(); },
29
+ });
30
+ searchInput.onChange = function (self) { results.setItems(findResults(self.getSearchText()), self.getSearchText()); };
31
+ results.attachTo(searchInput.txtSearch.inputElement);
32
+ results.remove(); // Also removes its window events and its ScrollBar.
33
+
34
+ Started Date: September 2026
35
+ Webpage: https://bug7a.github.io/js-components/
36
+
37
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
38
+ Licensed under the Apache License, Version 2.0
39
+ SPDX-License-Identifier: Apache-2.0
40
+
41
+ */
42
+
43
+ "use strict";
44
+
45
+ // Default values:
46
+ const SearchResultsDefaults = {
47
+ key: "0",
48
+ anchor: null, // The basic.js object the list opens under. (Ex: a SearchInput)
49
+ anchorAlign: "right", // "right": the right edges meet, "left": the left edges meet.
50
+ matchAnchorWidth: 0, // 1: the list is as wide as the anchor (both edges meet; maxWidth is not used). setMatchAnchorWidth()
51
+ maxWidth: 380,
52
+ maxHeightRatio: 0.7, // Of the screen height.
53
+ offsetY: 6, // Space between the anchor and the list.
54
+ screenMargin: 8, // The list never comes closer than this to the edge of the screen.
55
+ emptyText: "No results for \"{query}\"", // {query} is replaced by the text that was searched.
56
+ showEmpty: 1, // 0: The list is not opened at all when there is no result.
57
+ hintText: "↑ ↓ to move · Enter to open · Esc to close",
58
+ showHint: 1,
59
+ showGroups: 1,
60
+ openOnFocus: 1, // Focus on the input opens the last results again.
61
+ closeOnBlur: 1,
62
+ useScrollBar: 1, // basic/scroll-bar.js. 0: the scrollbar of the browser.
63
+ zIndexValue: 1000, // WHY: "zIndex" is a basic.js property of every box, the name is taken.
64
+ ariaLabel: "Search results",
65
+ createItemView: null, // function (item, index, self) {} -> Your own row. (Optional)
66
+ onSelect: function (self, item, index) { },
67
+ onOpen: function (self) { },
68
+ onClose: function (self) { },
69
+ onActiveChange: function (self, item, index) { },
70
+ styleName: "light", // "light" ("classic": its old name), "dark", "modern" or a name added to SearchResults.styles
71
+ style: { // Light style package (default)
72
+ box: {
73
+ color: White(1),
74
+ border: 1,
75
+ borderColor: Black(0.12),
76
+ round: 10,
77
+ padding: 6,
78
+ boxShadow: "0px 12px 32px rgba(0, 0, 0, 0.18)",
79
+ },
80
+ group: {
81
+ fontSize: 10,
82
+ textColor: Black(0.4),
83
+ padding: [12, 6],
84
+ letterSpacing: "1px",
85
+ },
86
+ item: {
87
+ padding: [12, 6],
88
+ round: 6,
89
+ color: "transparent",
90
+ activeColor: Black(0.06),
91
+ },
92
+ itemText: {
93
+ fontSize: 14,
94
+ textColor: Black(0.85),
95
+ },
96
+ itemDesc: {
97
+ fontSize: 12,
98
+ textColor: Black(0.45),
99
+ },
100
+ empty: {
101
+ fontSize: 13,
102
+ textColor: Black(0.5),
103
+ padding: [14, 12],
104
+ },
105
+ hint: {
106
+ fontSize: 11,
107
+ textColor: Black(0.35),
108
+ padding: [12, 8],
109
+ dividerColor: Black(0.08),
110
+ },
111
+ scrollBar: {
112
+ bar_color: "#9A9A98",
113
+ bar_mouseOverColor: "#6A6A68",
114
+ bar_width: 4,
115
+ bar_round: 3,
116
+ bar_opacity: 0.4,
117
+ bar_mouseOverOpacity: 0.9,
118
+ bar_padding: 2,
119
+ },
120
+ },
121
+ };
122
+
123
+ const SearchResults = function (params = {}) {
124
+
125
+ // Merge style package: params.style > SearchResults.styles[styleName] > SearchResultsDefaults.style (light)
126
+ basic.applyStylePackage(params, SearchResults.styles, SearchResultsDefaults);
127
+
128
+ // Merge params:
129
+ mergeIntoIfMissing(params, SearchResultsDefaults);
130
+
131
+ // WHY: A dropdown has to be over everything and must not be clipped by the bar or the group it
132
+ // is called from, so it is created on the page. createIn() can NOT be used here: it puts
133
+ // the container back when its function ends, and startObject() would be inside it while
134
+ // endObject() is outside. The container is put back by hand after endObject().
135
+ const previousContainer = getDefaultContainerBox();
136
+ setDefaultContainerBox(page);
137
+
138
+ // BOX: Component container
139
+ let box = startObject(params);
140
+
141
+ const _s = box.style;
142
+
143
+ // *** PRIVATE VARIABLES:
144
+
145
+ let items = []; // The items that are shown now.
146
+ let query = ""; // The text they were found with.
147
+ let activeIndex = -1;
148
+ let isClosedByUser = 0; // 1: Escape closed the list (it stays closed for the same text)
149
+ let rows = []; // The row objects, in the order of items.
150
+ let inputElem = null; // attachTo()
151
+ let inputRemovers = []; // The removers of the events of that input.
152
+ const SECTION_SPACE = "4px"; // Above a group header and the hint
153
+ const MIN_LIST_HEIGHT = 60; // px: the list is not made shorter than this to fit the screen (it scrolls)
154
+
155
+ // *** PRIVATE FUNCTIONS:
156
+
157
+ // Creates the content of the list again.
158
+ const render = function () {
159
+
160
+ rows = [];
161
+
162
+ if (box.wrapper) box.wrapper.remove();
163
+
164
+ createIn(box.scrollBox, function () {
165
+
166
+ box.wrapper = VGroup({ width: "100%", height: "auto", align: "left top", gap: 0 });
167
+ box.wrapper.css.alignItems = "stretch";
168
+ // WHY: A box grows with its content only when the content is in the flow.
169
+ box.wrapper.position = "relative";
170
+
171
+ if (items.length == 0) {
172
+ Label({
173
+ plainText: box.emptyText.replace("{query}", query.trim()),
174
+ fontSize: _s.empty.fontSize,
175
+ textColor: _s.empty.textColor,
176
+ padding: _s.empty.padding,
177
+ });
178
+ } else {
179
+ renderItems();
180
+ renderHint();
181
+ }
182
+
183
+ endGroup();
184
+
185
+ });
186
+
187
+ };
188
+
189
+ const renderItems = function () {
190
+
191
+ let lastGroup = "";
192
+
193
+ items.forEach(function (item, index) {
194
+
195
+ // LABEL: Group header
196
+ if (box.showGroups == 1 && item.group && item.group != lastGroup) {
197
+ lastGroup = item.group;
198
+ Label({
199
+ plainText: String(item.group).toUpperCase(),
200
+ fontSize: _s.group.fontSize,
201
+ textColor: _s.group.textColor,
202
+ padding: _s.group.padding,
203
+ });
204
+ that.css = {
205
+ letterSpacing: _s.group.letterSpacing,
206
+ marginTop: (index > 0) ? SECTION_SPACE : "0px",
207
+ };
208
+ }
209
+
210
+ // GROUP: One row
211
+ const row = VGroup({
212
+ width: "100%",
213
+ height: "auto",
214
+ align: "left top",
215
+ gap: 0,
216
+ padding: _s.item.padding,
217
+ round: _s.item.round,
218
+ color: _s.item.color,
219
+ });
220
+ row.cursor = "pointer";
221
+
222
+ // WHY: mousedown, not click. The input loses the focus on mousedown and the list would
223
+ // already be closed before the click arrives.
224
+ row.elem.addEventListener("mousedown", function (event) {
225
+ event.preventDefault();
226
+ box.selectIndex(index);
227
+ });
228
+ row.on("mouseover", function () { box.setActiveIndex(index); });
229
+
230
+ if (typeof box.createItemView === "function") {
231
+ box.createItemView(item, index, box);
232
+ } else {
233
+
234
+ Label({
235
+ plainText: item.text,
236
+ fontSize: _s.itemText.fontSize,
237
+ textColor: _s.itemText.textColor,
238
+ ellipsis: 1,
239
+ });
240
+
241
+ if (item.description) {
242
+ Label({
243
+ plainText: item.description,
244
+ fontSize: _s.itemDesc.fontSize,
245
+ textColor: _s.itemDesc.textColor,
246
+ ellipsis: 1,
247
+ });
248
+ }
249
+
250
+ }
251
+
252
+ endGroup();
253
+
254
+ rows.push(row);
255
+
256
+ });
257
+
258
+ };
259
+
260
+ const renderHint = function () {
261
+
262
+ if (box.showHint != 1 || !box.hintText) return;
263
+
264
+ Label({
265
+ plainText: box.hintText,
266
+ width: "100%",
267
+ fontSize: _s.hint.fontSize,
268
+ textColor: _s.hint.textColor,
269
+ padding: _s.hint.padding,
270
+ });
271
+ that.css = {
272
+ borderTop: "1px solid " + _s.hint.dividerColor,
273
+ marginTop: SECTION_SPACE,
274
+ };
275
+
276
+ };
277
+
278
+ // The width of the list: maxWidth, or the width of the anchor (matchAnchorWidth). Never wider than the screen.
279
+ const getListWidth = function () {
280
+ const screenWidth = page.width - (box.screenMargin * 2);
281
+ const hasAnchor = (box.anchor && box.anchor.elem);
282
+ if (box.matchAnchorWidth != 1 || !hasAnchor) return Math.min(box.maxWidth, screenWidth);
283
+ const anchorWidth = withPageZoom(box.anchor.elem.getBoundingClientRect().width);
284
+ return Math.min(anchorWidth, screenWidth);
285
+ };
286
+
287
+ // Under the anchor (over it when there is more room there), on the screen, as tall as its content up to the
288
+ // maximum and to the room on the screen.
289
+ const layout = function () {
290
+
291
+ const padding = _s.box.padding || 0;
292
+ const width = getListWidth(); // (as wide as the anchor: both values of anchorAlign give its left edge)
293
+ box.width = width;
294
+
295
+ // WHY: The height has to be a number, not "auto": the content is in a scrolling box and a
296
+ // box does not grow with it. It is also what the ScrollBar needs.
297
+ // WHY: The border is in the height too. A basic.js box is border-box, so the scrolling box
298
+ // inside it was 2 px shorter than its content and the bar was shown for those 2 px,
299
+ // even when there was nothing to scroll.
300
+ const border = _s.box.border || 0;
301
+ const contentHeight = (box.wrapper) ? box.wrapper.elem.offsetHeight : 0;
302
+ const fullHeight = contentHeight + (padding * 2) + (border * 2);
303
+ const maxHeight = Math.round(window.innerHeight * box.maxHeightRatio);
304
+ let height = Math.min(fullHeight, maxHeight);
305
+
306
+ if (box.anchor && box.anchor.elem) {
307
+ const rect = box.anchor.elem.getBoundingClientRect();
308
+ const left = (box.anchorAlign === "left") ? withPageZoom(rect.left) : withPageZoom(rect.right) - width;
309
+ box.left = Math.max(box.screenMargin, Math.min(left, page.width - width - box.screenMargin));
310
+ // WHY the room: the list was always under the anchor, so under a field low on the screen its rows were
311
+ // below the window (the box itself out of the screen: they could not be scrolled up)
312
+ const anchorTop = withPageZoom(rect.top);
313
+ const anchorBottom = withPageZoom(rect.bottom);
314
+ const roomBelow = page.height - anchorBottom - box.offsetY - box.screenMargin;
315
+ const roomAbove = anchorTop - box.offsetY - box.screenMargin;
316
+ const isAbove = (height > roomBelow && roomAbove > roomBelow);
317
+ height = Math.min(height, Math.max(MIN_LIST_HEIGHT, isAbove ? roomAbove : roomBelow));
318
+ box.top = isAbove ? anchorTop - box.offsetY - height : anchorBottom + box.offsetY;
319
+ }
320
+
321
+ box.height = height;
322
+
323
+ if (box.scrollBar) box.scrollBar.refreshScroll();
324
+
325
+ };
326
+
327
+ // *** PUBLIC VARIABLES:
328
+
329
+ // 1 while the list is open. [var]
330
+ box.isOpened = 0;
331
+
332
+ // *** PUBLIC FUNCTIONS:
333
+
334
+ // items: [{ text, description, group, ... }]. The list opens by itself when there is something to show.
335
+ box.setItems = function (newItems, searchedText = "") {
336
+
337
+ // WHY: the same text again keeps the active row (it went back to the first one), and a list closed with Escape
338
+ // stays closed (it opened again)
339
+ const isSameQuery = (String(searchedText) === String(query));
340
+ const keptIndex = (isSameQuery && box.isOpened === 1) ? activeIndex : 0;
341
+ if (!isSameQuery) isClosedByUser = 0;
342
+
343
+ items = newItems || [];
344
+ query = searchedText;
345
+
346
+ const hasNothingToShow = (items.length == 0 && box.showEmpty != 1);
347
+ if (!String(query).trim() || hasNothingToShow) {
348
+ box.close();
349
+ return;
350
+ }
351
+
352
+ if (isClosedByUser) return; // (Escape closed it: the same text keeps it closed, the focus opens it again)
353
+
354
+ render();
355
+ box.open();
356
+ box.setActiveIndex((items.length) ? Math.min(Math.max(keptIndex, 0), items.length - 1) : -1);
357
+
358
+ };
359
+
360
+ box.getItems = function () {
361
+ return items;
362
+ };
363
+
364
+ box.open = function () {
365
+
366
+ if (!box.wrapper) render();
367
+
368
+ box.zIndex = basic.zIndexAbove(box.anchor, box.zIndexValue); // WHY: a search field in a Dialog or a SidePanel opens its list over them
369
+ box.visible = 1;
370
+ layout();
371
+
372
+ if (box.isOpened === 1) return;
373
+ box.isOpened = 1;
374
+ box.onOpen(box);
375
+
376
+ };
377
+
378
+ box.close = function () {
379
+ box.visible = 0;
380
+ activeIndex = -1;
381
+ if (box.isOpened === 0) return;
382
+ box.isOpened = 0;
383
+ box.onClose(box);
384
+ };
385
+
386
+ box.setActiveIndex = function (index) {
387
+
388
+ activeIndex = index;
389
+
390
+ rows.forEach(function (row, i) {
391
+ row.color = (i == index) ? _s.item.activeColor : _s.item.color;
392
+ });
393
+
394
+ const row = rows[index];
395
+ if (row) row.elem.scrollIntoView({ block: "nearest" });
396
+
397
+ box.onActiveChange(box, items[index] || null, index);
398
+
399
+ };
400
+
401
+ box.getActiveIndex = function () {
402
+ return activeIndex;
403
+ };
404
+
405
+ // Moves the selection. It does not go around the ends.
406
+ box.moveActive = function (delta) {
407
+ if (items.length == 0) return;
408
+ const index = Math.max(0, Math.min(activeIndex + delta, items.length - 1));
409
+ box.setActiveIndex(index);
410
+ };
411
+
412
+ box.selectIndex = function (index) {
413
+ const item = items[index];
414
+ if (!item) return;
415
+ box.close();
416
+ box.onSelect(box, item, index);
417
+ };
418
+
419
+ box.selectActive = function () {
420
+ box.selectIndex(Math.max(activeIndex, 0));
421
+ };
422
+
423
+ // Does the whole keyboard work of a search input. Returns the function that undoes it.
424
+ box.attachTo = function (element) {
425
+
426
+ if (!element) {
427
+ console.error("SearchResults: attachTo() needs the input element.");
428
+ return function () { };
429
+ }
430
+
431
+ box.detach();
432
+ inputElem = element;
433
+
434
+ const onKeyDown = function (event) {
435
+
436
+ if (box.isOpened === 0) {
437
+ if (event.key === "Escape") element.blur();
438
+ return;
439
+ }
440
+
441
+ if (event.key === "ArrowDown") {
442
+ event.preventDefault();
443
+ box.moveActive(1);
444
+ } else if (event.key === "ArrowUp") {
445
+ event.preventDefault();
446
+ box.moveActive(-1);
447
+ } else if (event.key === "Enter") {
448
+ event.preventDefault();
449
+ box.selectActive();
450
+ } else if (event.key === "Escape") {
451
+ event.preventDefault();
452
+ box.close();
453
+ isClosedByUser = 1;
454
+ }
455
+
456
+ };
457
+
458
+ const onFocus = function () {
459
+ isClosedByUser = 0;
460
+ if (box.openOnFocus == 1 && String(query).trim() && items.length) box.open();
461
+ };
462
+
463
+ const onBlur = function () {
464
+ if (box.closeOnBlur == 1) box.close();
465
+ };
466
+
467
+ element.addEventListener("keydown", onKeyDown);
468
+ element.addEventListener("focus", onFocus);
469
+ element.addEventListener("blur", onBlur);
470
+
471
+ inputRemovers = [
472
+ function () { element.removeEventListener("keydown", onKeyDown); },
473
+ function () { element.removeEventListener("focus", onFocus); },
474
+ function () { element.removeEventListener("blur", onBlur); },
475
+ ];
476
+
477
+ return box.detach;
478
+
479
+ };
480
+
481
+ box.detach = function () {
482
+ inputRemovers.forEach(function (remove) { remove(); });
483
+ inputRemovers = [];
484
+ inputElem = null;
485
+ };
486
+
487
+ // Place it again. (After the anchor moved, ex: the bar got narrower.)
488
+ box.refresh = function () {
489
+ if (box.isOpened === 1) layout();
490
+ };
491
+
492
+ // 1: the list is as wide as the anchor, 0: as wide as maxWidth.
493
+ box.setMatchAnchorWidth = function (value) {
494
+ box.matchAnchorWidth = value;
495
+ box.refresh();
496
+ };
497
+
498
+ // WHY: box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
499
+ const superRemove = box.remove;
500
+ box.superRemove = superRemove;
501
+ box.remove = function () {
502
+
503
+ if (!box) return; // WHY: remove() can be called twice (also by the parent's remove()).
504
+ box.detach();
505
+
506
+ superRemove.call(box); // NOTE: basic.js remove(). It cleans all the events and the objects inside.
507
+ box = null;
508
+
509
+ };
510
+
511
+ // *** OBJECT VIEW:
512
+
513
+ box.props({
514
+ left: 0,
515
+ top: 0,
516
+ width: box.maxWidth,
517
+ height: 0,
518
+ color: _s.box.color,
519
+ border: _s.box.border,
520
+ borderColor: _s.box.borderColor,
521
+ round: _s.box.round,
522
+ boxShadow: _s.box.boxShadow,
523
+ clipContent: 1,
524
+ visible: 0,
525
+ });
526
+ box.css.position = "fixed";
527
+ box.zIndex = box.zIndexValue;
528
+ box.role = "listbox";
529
+ box.aria = { label: box.ariaLabel };
530
+
531
+ // BOX: The part that scrolls. The content is created in it.
532
+ box.scrollBox = Box(_s.box.padding, _s.box.padding, "100%", "100%", {
533
+ color: "transparent",
534
+ scrollY: 1,
535
+ });
536
+ box.scrollBox.css = {
537
+ width: "calc(100% - " + (_s.box.padding * 2) + "px)",
538
+ height: "calc(100% - " + (_s.box.padding * 2) + "px)",
539
+ };
540
+
541
+ // SCROLL BAR: basic/scroll-bar.js instead of the scrollbar of the browser.
542
+ if (box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
543
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.scrollBox, neverHide: 0, showDots: 0 }, _s.scrollBar));
544
+ }
545
+
546
+ // *** OBJECT INIT CODE:
547
+
548
+ box.onPageResize(function () { box.refresh(); }); // (removed with the box)
549
+
550
+ const results = endObject(box);
551
+
552
+ // WHY: The container was moved to the page above. The caller goes on with its own container.
553
+ setDefaultContainerBox(previousContainer);
554
+
555
+ return results;
556
+
557
+ };
558
+
559
+ // *** STYLE PACKAGES:
560
+ // USAGE: SearchResults({ styleName: "dark" })
561
+ // USAGE: SearchResults({ styleName: "dark", style: { box: { color: "tomato" } } }) // Change only some keys.
562
+ // USAGE: SearchResults({ style: SearchResults.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
563
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
564
+ // USAGE: SearchResults.styles.myStyle = { box: { color: "red" } };
565
+
566
+ SearchResults.styles = {
567
+
568
+ // White list, gray text.
569
+ light: SearchResultsDefaults.style,
570
+
571
+ // Dark list. The same colors as the "dark" Tabs, Stepper and SidePanel.
572
+ dark: {
573
+ box: { color: "#1A1A19", border: 1, borderColor: "rgba(255, 255, 255, 0.14)", round: 10, padding: 6, boxShadow: "0px 12px 32px rgba(0, 0, 0, 0.5)" },
574
+ group: { fontSize: 10, textColor: "rgba(255, 255, 255, 0.4)", padding: [12, 6], letterSpacing: "1px" },
575
+ item: { padding: [12, 6], round: 6, color: "transparent", activeColor: "rgba(255, 255, 255, 0.08)" },
576
+ itemText: { fontSize: 14, textColor: "rgba(255, 255, 255, 0.92)" },
577
+ itemDesc: { fontSize: 12, textColor: "rgba(255, 255, 255, 0.45)" },
578
+ empty: { fontSize: 13, textColor: "rgba(255, 255, 255, 0.5)", padding: [14, 12] },
579
+ hint: { fontSize: 11, textColor: "rgba(255, 255, 255, 0.35)", padding: [12, 8], dividerColor: "rgba(255, 255, 255, 0.08)" },
580
+ scrollBar: { bar_color: "#8A8A88", bar_mouseOverColor: "#BFBFBD", bar_width: 4, bar_round: 3, bar_opacity: 0.4, bar_mouseOverOpacity: 0.9, bar_padding: 2 },
581
+ },
582
+
583
+ // Round corners, cadetblue. The same colors as the modern Tabs and Stepper.
584
+ modern: {
585
+ box: { color: White(1), border: 0, borderColor: "transparent", round: 14, padding: 8, boxShadow: "0px 14px 40px rgba(47, 95, 97, 0.22)" },
586
+ group: { fontSize: 10, textColor: "#6E9A9B", padding: [12, 6], letterSpacing: "1px" },
587
+ item: { padding: [12, 8], round: 10, color: "transparent", activeColor: "#EEF5F5" },
588
+ itemText: { fontSize: 14, textColor: "#2F5F61" },
589
+ itemDesc: { fontSize: 12, textColor: "#6E9A9B" },
590
+ empty: { fontSize: 13, textColor: "#6E9A9B", padding: [14, 12] },
591
+ hint: { fontSize: 11, textColor: "#6E9A9B", padding: [12, 8], dividerColor: "#E3ECEC" },
592
+ scrollBar: { bar_color: "#CFE2E2", bar_mouseOverColor: "cadetblue", bar_width: 4, bar_round: 3, bar_opacity: 0.6, bar_mouseOverOpacity: 1, bar_padding: 2 },
593
+ },
594
+
595
+ };
596
+ SearchResults.styles.classic = SearchResults.styles.light; // the old name of light: the pages made with it keep their look