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,1862 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ Select Box - v26.09
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - A dropdown select: a field that opens a list (popup) under or above it.
9
+ - Single or multiple selection (multiple: 1). "Select all" and "Clear" for multiple.
10
+ - Search in the list (searchable: "auto" -> when there are more than 8 options). Matches are highlighted.
11
+ - The search box is a SearchInput (comp/search-input.js, with its clear button) when that file is loaded
12
+ before this one (useSearchInput: 1). Its look: style.searchInput (the params of SearchInput). Without it the
13
+ search box is an own input (its look: style.search).
14
+ - The list at the full height of the page (fullHeightList: 1): as wide as the field, at its left, from the top
15
+ of the page to its bottom, and it stays that high when a search leaves a few rows.
16
+ A resize of the page places it again (the normal list closes).
17
+ - Options can have a description, an icon, a group title and can be disabled.
18
+ - style.optionSelected.canSelectAgain: 0 (ozden, ozdenDark): the selected row (single) can not be chosen again:
19
+ no look under the mouse or the keys, the keys skip it, a click on it does nothing.
20
+ - An edge around the rows (style.option.border, borderColor; optionActive.borderColor, optionSelected.borderColor) and
21
+ space between them (style.option.space): the minimal packages frame the row under the mouse and the selected one.
22
+ optionSelected.tickSize: the tick of the selected row (16).
23
+ - Clear button in the field (clearable: 1).
24
+ - Keyboard: Enter / Space / ArrowDown opens. ArrowUp / ArrowDown / Home / End move, Enter selects,
25
+ Escape closes, Tab closes. Typing on the closed field opens the search with the typed letter.
26
+ - Accessibility: combobox + listbox roles, aria-expanded, aria-selected, aria-activedescendant.
27
+ - onChange is NOT called when the component is created or when the value is set with silent: 1.
28
+ - Big lists: Only the first "maxRenderCount" matches are drawn. (Search shows the others.)
29
+ - The list scrolls with basic/scroll-bar.js (useScrollBar: 1, style.scrollBar) when it is loaded before.
30
+ - Your own rows: createItemView(option, row, self) draws an option with your objects. The list is then a
31
+ ItemList (load comp/item-list.js before this file; without it: a warning and the normal rows).
32
+ The search box, the keyboard, single / multiple, disabled options and onChange work the same.
33
+ (Not in this mode: the group titles, the highlight of the search and maxRenderCount.) The list: box.itemList.
34
+ The search finds the label, the description, the group and option.searchText (Turkish letters without marks).
35
+ - Your own field: createValueView(option, field, self) draws the selected option in the field with your
36
+ objects (single selection; the placeholder and the multiple text stay as they are).
37
+ - Style packages: "light" (default; the old name "classic" works too), "dark", "ozden" (a package of params: 350 x 50, a search box, the list goes down to the bottom of the page),
38
+ "ozdenDark" (the same on a dark page). Select with styleName. (SelectBox.styles)
39
+ NEW PROJECTS: use "light" (the default) on a light page and "dark" on a dark page, the
40
+ looks of 02-comp-examples/select-box.htm, unless the user asks for another look ("ozden" / "ozdenDark" only when
41
+ asked).
42
+ - scale: multiplies every size (the style, width / height / panelMinWidth / panelMaxHeight, the spaces in the
43
+ code, the search box, the rows, the checks). Its default is basic.uiScale: on a page fitted with page.fit()
44
+ (basic.uiScale = 1 / page.zoom) the field and its list keep their size on the screen. The objects of
45
+ createItemView / createValueView are yours: multiply their sizes with self.scale (Ex: fontSize: 16 * self.scale).
46
+ (Needs basic.js v26.11.01 for a scale other than 1.)
47
+
48
+ OPTION: { value, label, description, iconFile, group, disabled }
49
+ - A string or a number is also accepted: "Apple" -> { value: "Apple", label: "Apple" }
50
+
51
+ USAGE:
52
+ const fruit = SelectBox({
53
+ width: 260,
54
+ options: ["Apple", "Banana", { value: "cherry", label: "Cherry", description: "Red and sweet" }],
55
+ value: "Banana",
56
+ clearable: 1,
57
+ onChange: (self) => println(self.value),
58
+ });
59
+ fruit.setValue("cherry"); // onChange is called
60
+ fruit.setValue("Apple", 1); // silent: onChange is not called
61
+ const skills = SelectBox({ multiple: 1, options: ["JS", "CSS", "SQL"], value: ["JS"] });
62
+ skills.getSelectedOptions(); // [{ value: "JS", label: "JS", ... }]
63
+
64
+ // Your own rows and field (load comp/item-list.js first). The other keys of an option stay on it.
65
+ const country = SelectBox({
66
+ styleName: "ozden",
67
+ options: [{ value: "TR", label: "Türkiye", code: "+90", searchText: "Turkey" }, { value: "DE", label: "Germany", code: "+49" }],
68
+ value: "TR",
69
+ createItemView: function (option, row, self) { // Objects created here go into the row (an HGroup).
70
+ Label({ plainText: option.code, fontSize: 16 });
71
+ Label({ plainText: option.label, fontSize: 20 });
72
+ },
73
+ createValueView: function (option, field, self) { // Objects created here go into the field (an HGroup).
74
+ Label({ plainText: option.code + " " + option.label, fontSize: 20 });
75
+ },
76
+ });
77
+
78
+ Started Date: September 2026
79
+ Webpage: https://bug7a.github.io/js-components/
80
+
81
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
82
+ Licensed under the Apache License, Version 2.0
83
+ SPDX-License-Identifier: Apache-2.0
84
+
85
+ */
86
+
87
+ "use strict";
88
+
89
+ // Default values:
90
+ const SelectBoxDefaults = {
91
+ key: "0",
92
+ width: 240,
93
+ height: 44,
94
+ options: [], // [{ value, label, description, iconFile, group, disabled }] or ["A", "B"]
95
+ value: null, // Single: a value or null. Multiple: [values]
96
+ multiple: 0,
97
+ searchable: "auto", // 1, 0, "auto" (more than autoSearchCount options)
98
+ autoSearchCount: 8,
99
+ clearable: 0, // 1: Clear button in the field
100
+ closeOnSelect: null, // null: 1 for single, 0 for multiple
101
+ showSelectAll: 1, // Multiple: "Select all" and "Clear" buttons
102
+ placeholder: "Select...",
103
+ searchPlaceholder: "Search...",
104
+ emptyText: "No results",
105
+ selectAllText: "Select all",
106
+ clearText: "Clear",
107
+ moreText: "+{count}", // Multiple: field text when many are selected. Ex: "Apple, Banana +3"
108
+ fieldLabelCount: 2, // Multiple: how many labels are written in the field
109
+ panelMinWidth: 220,
110
+ panelMaxHeight: 320,
111
+ maxRenderCount: 300,
112
+ enabled: 1,
113
+ useScrollBar: 1, // basic/scroll-bar.js on the list (load it first). 0: the scrollbar of the browser (hidden by basic.css in Chrome).
114
+ useSearchInput: 1, // 1: the search box is a SearchInput when comp/search-input.js is loaded first (style.searchInput). 0: the own input (style.search)
115
+ fullHeightList: 0, // 1: the list opens from the top of the page to its bottom, as wide as the field, at its left. (box.setFullHeightList())
116
+ scale: null, // Multiplies every size. null: basic.uiScale (1, or 1 / page.zoom on a fitted page). (Only at create time)
117
+ ariaLabel: "",
118
+ createItemView: null, // function (option, row, self) { ... } Your own rows: the list is an ItemList (load comp/item-list.js first). Its look: style.itemList
119
+ createValueView: null, // function (option, field, self) { ... } Your own view of the selected option in the field (single selection)
120
+ onChange: function (self) { }, // self.value, self.getSelectedOptions()
121
+ onOpen: function (self) { },
122
+ onClose: function (self) { },
123
+ styleName: "light", // "light" ("classic": its old name), "dark", "ozden", "ozdenDark", "minimal", "minimalDark" or a name added to SelectBox.styles
124
+ style: { // Light style package (default)
125
+ field: {
126
+ color: White(1),
127
+ border: 1,
128
+ borderColor: Black(0.2),
129
+ round: 6,
130
+ padding: [12, 0],
131
+ },
132
+ fieldHover: {
133
+ borderColor: Black(0.5),
134
+ },
135
+ fieldFocus: {
136
+ borderColor: "#141414",
137
+ },
138
+ fieldText: {
139
+ fontSize: 16,
140
+ textColor: Black(0.85),
141
+ },
142
+ // The icon and the description of the selected option in the field (single selection)
143
+ fieldOption: {
144
+ iconSize: 0, // 0: no icon in the field
145
+ iconRound: 0,
146
+ iconMarginLeft: 0,
147
+ gap: 8,
148
+ showDescription: 0,
149
+ emptyIconColor: "", // A box in the place of the icon when nothing is selected. "": no box
150
+ },
151
+ placeholder: {
152
+ textColor: Black(0.4),
153
+ },
154
+ arrow: {
155
+ color: Black(0.55),
156
+ icon: "chevron", // "chevron" (rotates when open), "unfold" (up and down)
157
+ size: 16,
158
+ opacity: 1,
159
+ marginRight: 0, // A negative value moves it into the padding of the field
160
+ },
161
+ panel: {
162
+ color: White(1),
163
+ border: 1,
164
+ borderColor: Black(0.12),
165
+ round: 10,
166
+ padding: 6,
167
+ shadow: "0 8px 24px rgba(0, 0, 0, 0.12)",
168
+ gap: 6,
169
+ coverField: 0, // 1: the panel opens over the field (at its top, as wide as it)
170
+ motion: "", // Ex: "opacity 0.2s, transform 0.2s": the panel fades and grows in (and out)
171
+ motionDuration: 200, // ms of the motion (the close waits for it)
172
+ startScale: 0.9,
173
+ },
174
+ // The search box when it is a SearchInput: its params (a styleName of SearchInput.styles and its look params).
175
+ // Its icons are the ones of SearchInput (searchIconFile, clearIconFile: your own pictures).
176
+ searchInput: {
177
+ styleName: "original", // the first look of SearchInput
178
+ height: 38,
179
+ searchIconLeft: 10, // WHY: the icon and the text at the place of the own search input (icon 18, text 42)
180
+ color: Black(0.04),
181
+ border: 1,
182
+ borderColor: Black(0.1),
183
+ borderBottomStyle: "1px solid rgba(0, 0, 0, 0.1)", // WHY: the bottom line of SearchInput takes the place of the border there.
184
+ round: 6,
185
+ fontSize: 14,
186
+ textColor: Black(0.85),
187
+ placeholderColor: "",
188
+ searchIconSize: 16,
189
+ searchIconGap: 8, // Between the icon and the text (the default of SearchInput: here, so that scale changes it)
190
+ searchIconOpacity: 0.55,
191
+ clearIconOpacity: 0.45,
192
+ invertIconColor: 0,
193
+ },
194
+ // The own search box (when SearchInput is not loaded)
195
+ search: {
196
+ color: Black(0.04),
197
+ border: 1,
198
+ borderColor: Black(0.1),
199
+ round: 6,
200
+ fontSize: 14,
201
+ textColor: Black(0.85),
202
+ height: 38,
203
+ padding: [10, 0],
204
+ iconSize: 16,
205
+ borderBottom: "", // Ex: "2px solid rgba(0, 0, 0, 0.06)"
206
+ },
207
+ option: {
208
+ fontSize: 15,
209
+ textColor: Black(0.85),
210
+ round: 6,
211
+ padding: [10, 8],
212
+ gap: 10,
213
+ minHeight: 0,
214
+ iconSize: 22,
215
+ iconRound: 0,
216
+ iconMargin: [0, 0], // [left, top and bottom]
217
+ border: 0, // px: an edge around every row (its color: borderColor, optionActive / optionSelected.borderColor)
218
+ borderColor: "transparent",
219
+ space: 0, // px between two rows (Ex: 2: the edges of two rows do not meet)
220
+ },
221
+ optionActive: {
222
+ color: Black(0.06),
223
+ lineColor: "", // A line above and under the active row (1 px, inside it: no row moves). "": none
224
+ borderColor: "", // The edge of the active row (option.border). "": the edge of the row
225
+ showAtOpen: 1, // 0: no row is marked when the list opens (only under the mouse / the keyboard)
226
+ },
227
+ optionSelected: {
228
+ textColor: "#141414",
229
+ checkColor: "#141414",
230
+ checkTickColor: White(1),
231
+ fontFamily: "opensans-bold", // Single selection. "": the font does not change
232
+ showTick: 1, // Single selection: a tick on the right
233
+ tickSize: 16, // px of the tick
234
+ borderColor: "", // The edge of the selected row (option.border). "": the edge of the row
235
+ opacity: 1,
236
+ canSelectAgain: 1, // 0 (single): the selected row can not be chosen again: no look under the mouse or the keys, the keys skip it, a click on it does nothing
237
+ },
238
+ optionDisabled: {
239
+ opacity: 0.4,
240
+ },
241
+ description: {
242
+ fontSize: 12,
243
+ textColor: Black(0.5),
244
+ marginTop: 0,
245
+ },
246
+ group: {
247
+ fontSize: 11,
248
+ textColor: Black(0.45),
249
+ },
250
+ highlight: {
251
+ color: "rgba(255, 196, 0, 0.35)",
252
+ },
253
+ empty: {
254
+ fontSize: 14,
255
+ textColor: Black(0.45),
256
+ },
257
+ footerButton: {
258
+ fontSize: 13,
259
+ textColor: "#3871E0",
260
+ },
261
+ divider: {
262
+ color: Black(0.08),
263
+ },
264
+ disabled: {
265
+ opacity: 0.4,
266
+ },
267
+ // The package of the ItemList of createItemView (ItemList.styles)
268
+ itemListStyleName: "ozden",
269
+ // The style of the ItemList of createItemView (the keys of ItemList.styles.ozden: row, hover, selected,
270
+ // disabled, check...). Its empty text takes style.empty. The check mark is shown only for multiple.
271
+ itemList: {
272
+ box: { color: "transparent", border: 0, round: 0, padding: 0 },
273
+ list: { gap: 0 },
274
+ row: { height: "auto", padding: [8, 8], gap: 10, color: "transparent", round: 6, motion: "" },
275
+ hover: { color: Black(0.06), lineColor: "" }, // WHY: "": no lines above and under the row (ItemList ozden has them).
276
+ selected: { color: Black(0.04), opacity: 1 },
277
+ disabled: { opacity: 0.4 },
278
+ focus: { ringColor: "transparent" }, // WHY: The keyboard stays in the field / search box (the active row is painted).
279
+ check: { size: 18, color: "#141414", iconColor: White(1), borderColor: Black(0.3) },
280
+ },
281
+ scrollBar: { // The params of ScrollBar (basic/scroll-bar.js)
282
+ bar_color: "#9A9A98",
283
+ bar_mouseOverColor: "#6A6A68",
284
+ bar_width: 4,
285
+ bar_mouseOverWidth: 4, // (the default of ScrollBar: here, so that scale changes it)
286
+ bar_round: 3,
287
+ bar_opacity: 0.4,
288
+ bar_mouseOverOpacity: 0.9,
289
+ bar_padding: 2,
290
+ neverHide: 0,
291
+ showDots: 0,
292
+ },
293
+ }
294
+ };
295
+
296
+ const SelectBox = function (params = {}) {
297
+
298
+ // Merge style package: params.style > SelectBox.styles[styleName] > SelectBoxDefaults.style (light)
299
+ basic.applyStylePackage(params, SelectBox.styles, SelectBoxDefaults);
300
+ SelectBox.fillSearchInputPackage(params.style);
301
+
302
+ // Merge params:
303
+ mergeIntoIfMissing(params, SelectBoxDefaults);
304
+
305
+ // Scale: the sizes of the style and of the params are multiplied. (A page fitted with page.fit() sets basic.uiScale.)
306
+ SelectBox.applyScale(params);
307
+
308
+ // WHY: startObject() copies params (only 4 levels) and keeps arrays by reference. Options and value are kept out of it.
309
+ const startOptions = params.options;
310
+ const startValue = params.value;
311
+ delete params.options;
312
+ delete params.value;
313
+
314
+ // BOX: Component container
315
+ let box = startObject(params);
316
+
317
+ // *** PRIVATE VARIABLES:
318
+ const _s = box.style;
319
+ const id = "selectbox-" + (SelectBox._counter++);
320
+ let isOpen = 0;
321
+ let isMouseOver = 0;
322
+ let isFocused = 0;
323
+ let searchText = "";
324
+ let rows = []; // Drawn option rows: [{ row, option }]
325
+ let activeIndex = -1; // Index in rows
326
+ const scale = box.scale; // The px of the code below are multiplied by it, like the style.
327
+ const PANEL_GAP = 6 * scale; // px between the field and the panel
328
+ const SCREEN_MARGIN = 8 * scale; // px: the panel stays this far from the edges of the page
329
+ const MIN_LIST_HEIGHT = 80 * scale; // px: the list is not made shorter than this when the space is small
330
+ const CHECK_SIZE = 18 * scale; // The check box of a row (multiple)
331
+ const TICK_SIZE = _s.optionSelected.tickSize; // The tick of the selected row (single; the style is scaled already)
332
+ const CLEAR_BUTTON_SIZE = 20 * scale; // The clear button of the field
333
+ const CLEAR_ICON_SIZE = 14 * scale;
334
+ const BUTTON_ROUND = 4 * scale; // The clear button and the footer buttons
335
+ const MARK_ROUND = 3 * scale; // The highlight of the search
336
+ const MESSAGE_PADDING = [8 * scale, 14 * scale]; // [x, y] "No results"
337
+ const MORE_MESSAGE_PADDING = [8 * scale, 8 * scale]; // "Showing 300 of 900. Type to search."
338
+ const GROUP_PADDING = [8 * scale, 4 * scale]; // The title of a group of options
339
+ const GROUP_LETTER_SPACING = 1 * scale;
340
+ const GROUP_SPACE_TOP = 6 * scale; // Above a group title that is not the first row
341
+ const SEARCH_GAP = 8 * scale; // The own search box: between its icon and its input
342
+ const SEARCH_INPUT_SPACE = 4 * scale; // The own search box: its input is this much shorter than the box
343
+ const FOOTER_PADDING = [4 * scale, 6 * scale];
344
+ const FOOTER_BUTTON_PADDING = [6 * scale, 2 * scale];
345
+ const DIVIDER_WIDTH = 1 * scale; // The line above the footer
346
+ const OVERLAY_Z_INDEX = 1000;
347
+ const PANEL_Z_INDEX = 1001;
348
+ // createItemView: the list is an ItemList (box.itemList), made at the first open.
349
+ const usesItemList = (typeof box.createItemView === "function") && SelectBox.canUseItemList();
350
+ let fieldViewOption = null; // The option that createValueView has drawn in the field
351
+ // The search box is a SearchInput (box.searchGroup) when comp/search-input.js is loaded. box.searchInput: its input.
352
+ const usesSearchInput = (box.useSearchInput == 1) && SelectBox.canUseSearchInput();
353
+
354
+ // *** PUBLIC VARIABLES:
355
+ // [var] Normalized options
356
+ box.options = [];
357
+ // [var] Single: value or null. Multiple: array
358
+ box.value = null;
359
+
360
+ // *** PRIVATE FUNCTIONS:
361
+
362
+ const isMultiple = function () {
363
+ return box.multiple == 1;
364
+ };
365
+
366
+ const isSearchable = function () {
367
+ if (box.searchable === "auto") return box.options.length > box.autoSearchCount;
368
+ return box.searchable == 1;
369
+ };
370
+
371
+ const sameValue = function (a, b) {
372
+ return a !== null && a !== undefined && b !== null && b !== undefined && String(a) === String(b);
373
+ };
374
+
375
+ const isSelected = function (option) {
376
+ if (isMultiple()) return box.value.some(function (v) { return sameValue(v, option.value); });
377
+ return sameValue(box.value, option.value);
378
+ };
379
+
380
+ // single, style.optionSelected.canSelectAgain: 0 (ozden): the selected row can not be chosen again.
381
+ const isLockedOption = function (option) {
382
+ return _s.optionSelected.canSelectAgain == 0 && !isMultiple() && isSelected(option);
383
+ };
384
+
385
+ // A row the mouse and the keys can make active (and choose): not disabled, not the locked selected one.
386
+ const isActivatable = function (option) {
387
+ return !option.disabled && !isLockedOption(option);
388
+ };
389
+
390
+ const findOption = function (value) {
391
+ return box.options.find(function (option) { return sameValue(option.value, value); });
392
+ };
393
+
394
+ // Multiple: a value, an array or nothing -> an array
395
+ const toValueList = function (value) {
396
+ if (Array.isArray(value)) return value;
397
+ if (value === null || value === undefined || value === "") return [];
398
+ return [value];
399
+ };
400
+
401
+ const normalizeValue = function (value) {
402
+ if (isMultiple()) {
403
+ const list = toValueList(value);
404
+ // WHY: Only values that are in the options. The order of the options is used.
405
+ const selectedOptions = box.options.filter(function (option) {
406
+ return list.some(function (v) { return sameValue(v, option.value); });
407
+ });
408
+ return selectedOptions.map(function (option) { return option.value; });
409
+ }
410
+ const option = findOption(value);
411
+ return (option) ? option.value : null;
412
+ };
413
+
414
+ const getFilteredOptions = function () {
415
+ const text = searchText.trim().toLocaleLowerCase();
416
+ if (!text) return box.options;
417
+ return box.options.filter(function (option) {
418
+ return (option.label + " " + option.description + " " + option.group).toLocaleLowerCase().includes(text);
419
+ });
420
+ };
421
+
422
+ // Label with the search match highlighted (safe HTML)
423
+ const highlight = function (label) {
424
+ const text = searchText.trim();
425
+ const escaped = SelectBox.escapeHtml(label);
426
+ if (!text) return escaped;
427
+ const index = label.toLocaleLowerCase().indexOf(text.toLocaleLowerCase());
428
+ if (index < 0) return escaped;
429
+ const before = SelectBox.escapeHtml(label.slice(0, index));
430
+ const match = SelectBox.escapeHtml(label.slice(index, index + text.length));
431
+ const after = SelectBox.escapeHtml(label.slice(index + text.length));
432
+ const markStyle = "background:" + _s.highlight.color + "; color: inherit; border-radius: " + MARK_ROUND + "px";
433
+ return before + "<mark style='" + markStyle + "'>" + match + "</mark>" + after;
434
+ };
435
+
436
+ // Creates the objects of a container again, in one group (container.wrapper).
437
+ const renderInto = function (container, buildContent, gap = 0) {
438
+ if (container.wrapper) container.wrapper.remove();
439
+ createIn(container, function () {
440
+ container.wrapper = VGroup({ width: "100%", height: "auto", align: "left top", gap: gap, position: "relative" });
441
+ container.wrapper.css.alignItems = "stretch";
442
+ buildContent();
443
+ endGroup();
444
+ });
445
+ };
446
+
447
+ const getFieldBorderColor = function () {
448
+ if (isOpen || isFocused) return _s.fieldFocus.borderColor;
449
+ if (isMouseOver) return _s.fieldHover.borderColor;
450
+ return _s.field.borderColor;
451
+ };
452
+
453
+ // A small SVG picture in a Label that does not shrink in a group.
454
+ const createSvgLabel = function (svg, size) {
455
+ const label = Label({ text: svg, width: size, height: size });
456
+ label.shrink = 0;
457
+ label.lineHeight = "0";
458
+ return label;
459
+ };
460
+
461
+ // The icon and the description of the selected option in the field (style.fieldOption).
462
+ const updateFieldOption = function (option) {
463
+ const hasIcon = _s.fieldOption.iconSize > 0 && option && option.iconFile;
464
+ // WHY: An empty box keeps the place of the icon: the placeholder text starts where a selected label starts.
465
+ const hasIconOptions = box.options.some(function (o) { return o.iconFile; }); // WHY: Text options have no icon place.
466
+ const hasEmptyIcon = _s.fieldOption.iconSize > 0 && !option && _s.fieldOption.emptyIconColor && hasIconOptions;
467
+ box.fieldIcon.visible = (hasIcon || hasEmptyIcon) ? 1 : 0;
468
+ box.fieldIcon.color = hasEmptyIcon ? _s.fieldOption.emptyIconColor : "transparent";
469
+ box.fieldIcon.imageElement.style.visibility = hasEmptyIcon ? "hidden" : "visible";
470
+ // WHY: Loaded again only when it changed, so the icon does not flicker.
471
+ if (hasIcon && box.fieldIcon.imageElement.getAttribute("src") != option.iconFile) box.fieldIcon.load(option.iconFile);
472
+
473
+ const hasDescription = basic.isOn(_s.fieldOption.showDescription) && option && option.description;
474
+ box.fieldDescription.visible = hasDescription ? 1 : 0;
475
+ box.fieldDescription.text = hasDescription ? SelectBox.escapeHtml(option.description) : "";
476
+ };
477
+
478
+ // createValueView: the selected option drawn by the page in the field, in the place of the text.
479
+ const updateFieldView = function (option) {
480
+ if (typeof box.createValueView !== "function") return;
481
+ const isShown = !!option;
482
+ box.fieldTexts.visible = isShown ? 0 : 1; // WHY: The placeholder is still the text of the field.
483
+ if (isShown) box.fieldIcon.visible = 0;
484
+ if (!isShown) {
485
+ removeFieldView();
486
+ return;
487
+ }
488
+ // WHY: Drawn again only when the option changed (setOptions() makes new option objects).
489
+ if (option !== fieldViewOption) drawFieldView(option);
490
+ };
491
+
492
+ const removeFieldView = function () {
493
+ if (box.fieldView) box.fieldView.remove();
494
+ box.fieldView = null;
495
+ fieldViewOption = null;
496
+ };
497
+
498
+ const drawFieldView = function (option) {
499
+ removeFieldView();
500
+ createIn(box.field, function () {
501
+ // GROUP: The view of the page
502
+ box.fieldView = HGroup({ width: "auto", height: "100%", align: "left center", gap: _s.fieldOption.gap });
503
+ box.fieldView.css = { flex: "1 1 auto", minWidth: "0" };
504
+ box.createValueView(option, box.fieldView, box);
505
+ endGroup();
506
+ });
507
+ // WHY: In the place of the text: before the clear button and the arrow.
508
+ box.field.elem.insertBefore(box.fieldView.elem, box.clearButton.elem);
509
+ fieldViewOption = option;
510
+ };
511
+
512
+ const updateField = function () {
513
+
514
+ const selected = box.getSelectedOptions();
515
+ let text = "";
516
+
517
+ if (isMultiple()) {
518
+ const names = selected.slice(0, box.fieldLabelCount).map(function (option) { return SelectBox.escapeHtml(option.label); });
519
+ text = names.join(", ");
520
+ if (selected.length > box.fieldLabelCount) text += " " + box.moreText.replace("{count}", selected.length - box.fieldLabelCount);
521
+ } else if (selected[0]) {
522
+ text = SelectBox.escapeHtml(selected[0].label);
523
+ }
524
+
525
+ box.fieldText.text = text || SelectBox.escapeHtml(box.placeholder);
526
+ box.fieldText.textColor = (text) ? _s.fieldText.textColor : _s.placeholder.textColor;
527
+ updateFieldOption(isMultiple() ? null : selected[0]);
528
+ updateFieldView(isMultiple() ? null : selected[0]);
529
+
530
+ box.clearButton.visible = (box.clearable == 1 && selected.length > 0 && box.enabled == 1) ? 1 : 0;
531
+
532
+ box.field.borderColor = getFieldBorderColor();
533
+ if (_s.arrow.icon === "chevron") box.arrow.css.transform = (isOpen) ? "rotate(180deg)" : "rotate(0deg)";
534
+
535
+ box.opacity = (box.enabled == 1) ? 1 : _s.disabled.opacity;
536
+ box.tabIndex = (box.enabled == 1) ? 0 : -1;
537
+ box.aria = {
538
+ expanded: (isOpen) ? "true" : "false",
539
+ disabled: (box.enabled == 1) ? "false" : "true",
540
+ };
541
+
542
+ };
543
+
544
+ // Draws the option rows. (Filtered by the search)
545
+ const renderList = function () {
546
+
547
+ if (usesItemList) {
548
+ renderItemList();
549
+ return;
550
+ }
551
+
552
+ const list = getFilteredOptions();
553
+ const shown = list.slice(0, box.maxRenderCount);
554
+ rows = [];
555
+
556
+ renderInto(box.list, function () {
557
+
558
+ if (list.length == 0) {
559
+ Label({ text: SelectBox.escapeHtml(box.emptyText), width: "100%", textAlign: "center", padding: MESSAGE_PADDING, ..._s.empty });
560
+ return;
561
+ }
562
+
563
+ let lastGroup = "";
564
+
565
+ shown.forEach(function (option) {
566
+
567
+ if (option.group && option.group != lastGroup) {
568
+ lastGroup = option.group;
569
+ Label({ text: SelectBox.escapeHtml(option.group.toUpperCase()), padding: GROUP_PADDING, ..._s.group });
570
+ that.css = {
571
+ letterSpacing: GROUP_LETTER_SPACING + "px",
572
+ marginTop: (rows.length) ? GROUP_SPACE_TOP + "px" : "0px",
573
+ };
574
+ }
575
+
576
+ rows.push({ row: createOptionRow(option, rows.length), option: option });
577
+
578
+ });
579
+
580
+ if (list.length > shown.length) {
581
+ const moreText = "Showing " + shown.length + " of " + list.length + ". Type to search.";
582
+ Label({ text: moreText, width: "100%", textAlign: "center", padding: MORE_MESSAGE_PADDING, ..._s.empty });
583
+ }
584
+
585
+ }, _s.option.space);
586
+
587
+ setActive(getStartActiveIndex(), 0);
588
+
589
+ box.list.aria = { multiselectable: (isMultiple()) ? "true" : "false" };
590
+ refreshScrollBar();
591
+
592
+ };
593
+
594
+ const refreshScrollBar = function () {
595
+ if (box.scrollBar) box.scrollBar.refreshScroll();
596
+ };
597
+
598
+ // *** THE ITEMLIST OF createItemView
599
+ // WHY: The keyboard of the ItemList moves the focus into the rows; here the focus stays in the field or
600
+ // the search box (a combobox), so the active row is painted by SelectBox (aria-activedescendant).
601
+
602
+ // An option as an item of the ItemList. The key is its index in box.options.
603
+ const toListItem = function (option, index) {
604
+ return {
605
+ key: String(index),
606
+ text: option.label,
607
+ description: option.description,
608
+ searchText: [option.group, option.searchText || ""].join(" "),
609
+ enabled: basic.isOn(option.disabled) ? 0 : 1,
610
+ option: option,
611
+ };
612
+ };
613
+
614
+ const getListKey = function (option) {
615
+ return String(box.options.indexOf(option));
616
+ };
617
+
618
+ const getItemListStyle = function () {
619
+ const check = Object.assign({}, _s.itemList.check, { visible: isMultiple() ? 1 : 0 });
620
+ // WHY: The rows of the ItemList follow optionSelected.canSelectAgain: one setting for both kinds of rows (the
621
+ // ozden package of ItemList has 0, so a classic SelectBox must give its 1).
622
+ const selected = Object.assign({}, _s.itemList.selected, { canSelectAgain: _s.optionSelected.canSelectAgain });
623
+ return Object.assign({}, _s.itemList, { empty: _s.itemList.empty || _s.empty, check: check, selected: selected });
624
+ };
625
+
626
+ const createListItemView = function (item, row) {
627
+ if (_s.option.minHeight) row.css.minHeight = _s.option.minHeight + "px";
628
+ box.createItemView(item.option, row, box);
629
+ };
630
+
631
+ const createItemList = function () {
632
+ createIn(box.list, function () {
633
+ box.itemList = ItemList({
634
+ width: "100%",
635
+ height: "auto",
636
+ position: "relative",
637
+ items: [],
638
+ selection: isMultiple() ? "multiple" : "single",
639
+ scrollToSelected: 0,
640
+ useScrollBar: 0,
641
+ createItemView: createListItemView,
642
+ emptyText: box.emptyText,
643
+ noResultText: box.emptyText,
644
+ ariaLabel: box.ariaLabel || "List",
645
+ onItemClick: onListItemClick,
646
+ onChange: onListChange,
647
+ styleName: _s.itemListStyleName,
648
+ style: getItemListStyle(),
649
+ scale: 1, // WHY: style.itemList is scaled already (with the style of SelectBox).
650
+ });
651
+ });
652
+ fillItemList();
653
+ };
654
+
655
+ // The rows of the options, made again (at the first open and by setOptions).
656
+ const fillItemList = function () {
657
+ box.itemList.setItems(box.options.map(toListItem));
658
+ // WHY: box.list is the listbox of the combobox: the group of the ItemList is not one more listbox.
659
+ box.itemList.wrapper.role = "none";
660
+ box.itemList.wrapper.aria = { label: null, multiselectable: null };
661
+ box.itemList.forEach(prepareListRow);
662
+ };
663
+
664
+ const prepareListRow = function (item, row, index) {
665
+ row.elem.id = id + "-option-" + index;
666
+ row.on("mousemove", function () {
667
+ const rowIndex = rows.findIndex(function (shown) { return shown.row === row; });
668
+ onRowMouseMove(rowIndex, item.option);
669
+ });
670
+ };
671
+
672
+ // The mouse on a row makes it active. WHY: On the locked selected row no row is active (the last one is not
673
+ // left white): the row under the mouse can not be chosen.
674
+ const onRowMouseMove = function (index, option) {
675
+ if (index < 0 || index == activeIndex || option.disabled) return;
676
+ setActive(isLockedOption(option) ? -1 : index, 0);
677
+ };
678
+
679
+
680
+ // The search, the selection and the active row of the ItemList (its rows are made only once).
681
+ const renderItemList = function () {
682
+ if (!box.itemList) createItemList();
683
+ syncListSelection(); // WHY: Also the cursors: the ItemList gives a hand only to a row that can be chosen.
684
+ box.itemList.search(searchText);
685
+ rows = [];
686
+ box.itemList.forEach(function (item, row) {
687
+ if (row.visible == 1) rows.push({ row: row, option: item.option });
688
+ });
689
+ setActive(getStartActiveIndex(), 0);
690
+ box.list.aria = { multiselectable: (isMultiple()) ? "true" : "false" };
691
+ refreshScrollBar();
692
+ };
693
+
694
+ const syncListSelection = function () {
695
+ if (!box.itemList) return;
696
+ const keys = box.getSelectedOptions().map(getListKey);
697
+ box.itemList.setSelected(keys, 1);
698
+ };
699
+
700
+ // A click on a row: the ItemList changes its selection (onListChange). The selected row clicked again
701
+ // (single) is not a change, but the list closes like the normal rows (not the locked one: nothing happens).
702
+ const onListItemClick = function (list, item) {
703
+ if (isLockedOption(item.option)) return;
704
+ if (!isMultiple() && isSelected(item.option)) afterSelect(JSON.stringify(box.value));
705
+ };
706
+
707
+ const onListChange = function () {
708
+ const oldValue = JSON.stringify(box.value);
709
+ const values = box.itemList.getSelected().map(function (item) { return item.option.value; });
710
+ box.value = (isMultiple()) ? normalizeValue(values) : normalizeValue(values[0]);
711
+ afterSelect(oldValue);
712
+ };
713
+
714
+ // Enter / Space on the active row: through the ItemList, like a click.
715
+ const selectInItemList = function (option) {
716
+ const key = getListKey(option);
717
+ if (isMultiple() && isSelected(option)) {
718
+ box.itemList.unselect(key);
719
+ return;
720
+ }
721
+ if (isSelected(option)) {
722
+ afterSelect(JSON.stringify(box.value));
723
+ return;
724
+ }
725
+ box.itemList.select(key);
726
+ };
727
+
728
+ // The options of the rows that are shown now (the search)
729
+ const getShownOptions = function () {
730
+ if (usesItemList) return rows.map(function (item) { return item.option; });
731
+ return getFilteredOptions();
732
+ };
733
+
734
+ // The edge of an own row (option.border): selected, active, or its own
735
+ const getOptionBorderColor = function (row, isActive) {
736
+ if (row.isSelectedOption && _s.optionSelected.borderColor) return _s.optionSelected.borderColor;
737
+ if (isActive && _s.optionActive.borderColor) return _s.optionActive.borderColor;
738
+ return _s.option.borderColor;
739
+ };
740
+
741
+ // The look of an own row (not of an ItemList), active (under the mouse or the arrow keys) or not: style.optionActive.
742
+ const paintOptionRow = function (row, isActive) {
743
+ row.color = isActive ? _s.optionActive.color : "transparent";
744
+ if (_s.option.border) row.borderColor = getOptionBorderColor(row, isActive);
745
+ const lineColor = _s.optionActive.lineColor;
746
+ // WHY: Only with lines: a package without them never touches the shadow of a row.
747
+ if (lineColor) row.boxShadow = isActive ? "inset 0 1px 0 " + lineColor + ", inset 0 -1px 0 " + lineColor : "";
748
+ };
749
+
750
+ // Scrolls the list to show a row.
751
+ const scrollToRow = function (row) {
752
+ if (!usesItemList) {
753
+ row.elem.scrollIntoView({ block: "nearest" });
754
+ return;
755
+ }
756
+ // WHY: Only the list, by its own scrollTop: scrollIntoView() also scrolled the boxes around it.
757
+ const area = box.list.elem;
758
+ let top = 0;
759
+ for (let elem = row.elem; elem && elem !== area; elem = elem.offsetParent) top += elem.offsetTop;
760
+ const bottom = top + row.elem.offsetHeight;
761
+ if (top < area.scrollTop) area.scrollTop = top;
762
+ else if (bottom > area.scrollTop + area.clientHeight) area.scrollTop = bottom - area.clientHeight;
763
+ };
764
+
765
+ // Active row after the list is drawn: the first selected one, or the first one that can be chosen
766
+ const getStartActiveIndex = function () {
767
+ if (_s.optionActive.showAtOpen == 0) return -1;
768
+ const selectedIndex = rows.findIndex(function (item) { return isSelected(item.option) && isActivatable(item.option); });
769
+ if (selectedIndex >= 0) return selectedIndex;
770
+ return rows.findIndex(function (item) { return isActivatable(item.option); });
771
+ };
772
+
773
+ const createDescription = function (html) {
774
+ const label = Label({ text: html, width: "100%", fontSize: _s.description.fontSize, textColor: _s.description.textColor });
775
+ if (_s.description.marginTop) label.css.marginTop = _s.description.marginTop + "px";
776
+ return label;
777
+ };
778
+
779
+ const createOptionRow = function (option, index) {
780
+
781
+ const selected = isSelected(option);
782
+
783
+ const row = HGroup({
784
+ width: "100%",
785
+ height: "auto",
786
+ align: "left center",
787
+ gap: _s.option.gap,
788
+ padding: _s.option.padding,
789
+ round: _s.option.round,
790
+ color: "transparent",
791
+ clickable: 1,
792
+ });
793
+ if (_s.option.minHeight) row.css.minHeight = _s.option.minHeight + "px";
794
+ row.isSelectedOption = selected;
795
+ if (_s.option.border) row.props({ border: _s.option.border, borderColor: getOptionBorderColor(row, 0) });
796
+ if (selected && _s.optionSelected.opacity != 1) row.opacity = _s.optionSelected.opacity;
797
+ row.elem.id = id + "-option-" + index;
798
+ row.role = "option";
799
+ row.aria = { selected: (selected) ? "true" : "false" };
800
+ row.cursor = isActivatable(option) ? "pointer" : "default";
801
+ if (option.disabled) {
802
+ row.aria = { disabled: "true" };
803
+ row.opacity = _s.optionDisabled.opacity;
804
+ }
805
+
806
+ // Multiple: check box
807
+ if (isMultiple()) {
808
+ createSvgLabel(SelectBox.getCheckSvg(selected, _s, CHECK_SIZE), CHECK_SIZE);
809
+ }
810
+
811
+ if (option.iconFile) {
812
+ const iconMargin = _s.option.iconMargin;
813
+ Icon({ width: _s.option.iconSize, height: _s.option.iconSize, round: _s.option.iconRound });
814
+ that.load(option.iconFile);
815
+ that.shrink = 0;
816
+ that.elem.alt = "";
817
+ that.css.margin = iconMargin[1] + "px 0px " + iconMargin[1] + "px " + iconMargin[0] + "px";
818
+ }
819
+
820
+ VGroup({ width: "auto", height: "auto", align: "left top", gap: 0 });
821
+ that.css = { flex: "1 1 auto", minWidth: "0" };
822
+
823
+ const labelColor = (selected) ? _s.optionSelected.textColor : _s.option.textColor;
824
+ Label({ text: highlight(option.label), fontSize: _s.option.fontSize, textColor: labelColor, width: "100%" });
825
+ if (selected && !isMultiple() && _s.optionSelected.fontFamily) that.css.fontFamily = _s.optionSelected.fontFamily;
826
+ that.css.overflowWrap = "anywhere";
827
+
828
+ if (option.description) {
829
+ createDescription(highlight(option.description));
830
+ }
831
+
832
+ endGroup();
833
+
834
+ // Single: tick on the right
835
+ if (!isMultiple() && selected && _s.optionSelected.showTick == 1) {
836
+ createSvgLabel(SelectBox.getTickSvg(_s.optionSelected.checkColor, TICK_SIZE), TICK_SIZE);
837
+ }
838
+
839
+ endGroup();
840
+
841
+ row.on("mousemove", function () {
842
+ onRowMouseMove(index, option);
843
+ });
844
+
845
+ row.on("click", function () {
846
+ if (isActivatable(option)) selectOption(option);
847
+ });
848
+
849
+ return row;
850
+
851
+ };
852
+
853
+ // scroll: 1 -> Move the list to show the active row.
854
+ const setActive = function (index, scroll = 1) {
855
+
856
+ if (rows[activeIndex] && !usesItemList) paintOptionRow(rows[activeIndex].row, 0);
857
+ activeIndex = index;
858
+
859
+ const item = rows[activeIndex];
860
+ // WHY: The ItemList paints its own rows: it knows their look (selected, under the mouse).
861
+ if (usesItemList && box.itemList) box.itemList.setActiveKey(item ? getListKey(item.option) : null);
862
+ if (!item) {
863
+ box.panel.aria = { activedescendant: null };
864
+ box.aria = { activedescendant: null };
865
+ return;
866
+ }
867
+
868
+ if (!usesItemList) paintOptionRow(item.row, 1);
869
+ box.aria = { activedescendant: item.row.elem.id };
870
+ if (box.searchInput) box.searchInput.inputElement.setAttribute("aria-activedescendant", item.row.elem.id);
871
+ if (scroll) scrollToRow(item.row);
872
+
873
+ };
874
+
875
+ // step: +1 or -1. Skips the rows that can not be chosen (disabled, the locked selected one).
876
+ const moveActive = function (step) {
877
+ if (rows.length == 0) return;
878
+ // WHY: With no active row (-1), ArrowUp starts from the end: (-1 - 1) % length was the row before the last one.
879
+ let index = (activeIndex < 0 && step < 0) ? rows.length : activeIndex;
880
+ for (let i = 0; i < rows.length; i++) {
881
+ index = (index + step + rows.length) % rows.length;
882
+ if (isActivatable(rows[index].option)) return setActive(index);
883
+ }
884
+ };
885
+
886
+ // closeOnSelect: null -> close for single, stay open for multiple
887
+ const shouldCloseOnSelect = function () {
888
+ if (box.closeOnSelect === null) return !isMultiple();
889
+ return box.closeOnSelect == 1;
890
+ };
891
+
892
+ const toggleInValue = function (option) {
893
+ if (isSelected(option)) {
894
+ box.value = box.value.filter(function (v) { return !sameValue(v, option.value); });
895
+ return;
896
+ }
897
+ box.value = normalizeValue(box.value.concat([option.value]));
898
+ };
899
+
900
+ const selectOption = function (option) {
901
+
902
+ if (usesItemList) {
903
+ selectInItemList(option);
904
+ return;
905
+ }
906
+
907
+ const oldValue = JSON.stringify(box.value);
908
+ if (isMultiple()) {
909
+ toggleInValue(option);
910
+ } else {
911
+ box.value = option.value;
912
+ }
913
+ afterSelect(oldValue);
914
+
915
+ };
916
+
917
+ // After a choice: the field, the list (closed or drawn again) and onChange.
918
+ const afterSelect = function (oldValue) {
919
+
920
+ const isChanged = (JSON.stringify(box.value) !== oldValue);
921
+
922
+ const keepActive = activeIndex;
923
+ updateField();
924
+
925
+ if (shouldCloseOnSelect()) {
926
+ box.close();
927
+ box.elem.focus();
928
+ } else {
929
+ const scrollTop = box.list.elem.scrollTop;
930
+ renderList();
931
+ box.list.elem.scrollTop = scrollTop; // WHY: The list must not jump after a click.
932
+ // WHY: The row just chosen may be the locked selected one now (canSelectAgain: 0): no active row then.
933
+ const keptRow = rows[keepActive];
934
+ setActive((keptRow && isActivatable(keptRow.option)) ? keepActive : -1, 0);
935
+ }
936
+
937
+ // WHY: The selected option clicked again is not a change.
938
+ if (isChanged) box.onChange(box);
939
+
940
+ };
941
+
942
+ // Position the popup panel under (or above) the field.
943
+ // Makes the list shorter by "extra" px. (Not shorter than MIN_LIST_HEIGHT.)
944
+ // WHY: From the height of the list now, not from panelMaxHeight: a list shorter than panelMaxHeight was not made shorter.
945
+ const shortenList = function (extra) {
946
+ box.list.css.maxHeight = Math.max(MIN_LIST_HEIGHT, box.list.elem.offsetHeight - extra) + "px";
947
+ };
948
+
949
+ const positionPanel = function () {
950
+
951
+ const rect = box.elem.getBoundingClientRect();
952
+ const width = Math.max(withPageZoom(rect.width), box.panelMinWidth);
953
+
954
+ box.panel.width = width;
955
+
956
+ if (box.fullHeightList == 1) {
957
+ placePanelFullHeight(rect, width);
958
+ return;
959
+ }
960
+
961
+ box.list.css.maxHeight = box.panelMaxHeight + "px";
962
+
963
+ if (_s.panel.coverField == 1) {
964
+ placePanelOverField(rect, width);
965
+ return;
966
+ }
967
+
968
+ const panelHeight = box.panel.elem.offsetHeight;
969
+ const below = page.height - withPageZoom(rect.bottom) - PANEL_GAP - SCREEN_MARGIN;
970
+ const above = withPageZoom(rect.top) - PANEL_GAP - SCREEN_MARGIN;
971
+
972
+ let top = withPageZoom(rect.bottom) + PANEL_GAP;
973
+ if (panelHeight > below && above > below) {
974
+ // Open above. Make the list shorter if there is not enough space.
975
+ const extra = panelHeight - above;
976
+ if (extra > 0) shortenList(extra);
977
+ top = withPageZoom(rect.top) - box.panel.elem.offsetHeight - PANEL_GAP;
978
+ } else if (panelHeight > below) {
979
+ shortenList(panelHeight - below);
980
+ }
981
+
982
+ let left = withPageZoom(rect.left);
983
+ left = Math.max(SCREEN_MARGIN, Math.min(left, page.width - width - SCREEN_MARGIN));
984
+
985
+ box.panel.left = left;
986
+ box.panel.top = Math.max(SCREEN_MARGIN, top);
987
+
988
+ };
989
+
990
+ // style.panel.coverField: the panel opens over the field: from its top down to the bottom of the page, or
991
+ // (when there is more space above) from its bottom up to the top of the page.
992
+ const placePanelOverField = function (rect, width) {
993
+ // WHY: A panel shorter than the field (a search with few results) showed the bottom of the field under it.
994
+ box.panel.css.minHeight = withPageZoom(rect.height) + "px";
995
+ const fieldTop = withPageZoom(rect.top);
996
+ const fieldBottom = withPageZoom(rect.bottom);
997
+ const spaceDown = page.height - fieldTop - SCREEN_MARGIN;
998
+ const spaceUp = fieldBottom - SCREEN_MARGIN;
999
+ const panelHeight = box.panel.elem.offsetHeight;
1000
+ const isUp = (panelHeight > spaceDown && spaceUp > spaceDown);
1001
+ const space = isUp ? spaceUp : spaceDown;
1002
+ if (panelHeight > space) shortenList(panelHeight - space);
1003
+
1004
+ let left = withPageZoom(rect.left);
1005
+ left = Math.max(SCREEN_MARGIN, Math.min(left, page.width - width - SCREEN_MARGIN));
1006
+ box.panel.left = left;
1007
+ box.panel.top = isUp ? fieldBottom - box.panel.elem.offsetHeight : fieldTop;
1008
+ };
1009
+
1010
+ // fullHeightList: the panel from the top of the page to its bottom, at the left of the field. The list fills
1011
+ // the panel, so the panel stays that high after a search that leaves a few rows.
1012
+ const placePanelFullHeight = function (rect, width) {
1013
+ let left = withPageZoom(rect.left);
1014
+ left = Math.max(0, Math.min(left, page.width - width));
1015
+ box.panel.left = left;
1016
+ box.panel.top = 0;
1017
+ box.panel.height = page.height;
1018
+ };
1019
+
1020
+ // The height of the panel and the list for fullHeightList (1) or the normal list (0).
1021
+ const applyListHeightMode = function () {
1022
+ const isFullHeight = (box.fullHeightList == 1);
1023
+ // WHY: a full height list touches the top and the bottom of the page: square corners.
1024
+ box.panel.round = isFullHeight ? 0 : _s.panel.round;
1025
+ box.panel.height = "auto";
1026
+ box.panel.css.minHeight = "";
1027
+ box.list.css = {
1028
+ flex: isFullHeight ? "1 1 auto" : "",
1029
+ minHeight: isFullHeight ? "0px" : "",
1030
+ maxHeight: isFullHeight ? "none" : box.panelMaxHeight + "px",
1031
+ };
1032
+ };
1033
+
1034
+ // style.panel.motion: the panel fades and grows in.
1035
+ const showPanelWithMotion = function () {
1036
+ if (!_s.panel.motion) return;
1037
+ box.panel.clickable = 1;
1038
+ box.panel.css.transition = "none";
1039
+ box.panel.css.opacity = "0";
1040
+ box.panel.css.transform = "scale(" + _s.panel.startScale + ")";
1041
+ // WHY: Read a size, so the browser draws the start state before the transition is turned on.
1042
+ void box.panel.elem.offsetHeight;
1043
+ box.panel.css.transition = _s.panel.motion;
1044
+ box.panel.css.opacity = "1";
1045
+ box.panel.css.transform = "scale(1)";
1046
+ };
1047
+
1048
+ // Returns 1 when the panel is hidden later (after its motion).
1049
+ const hidePanelWithMotion = function () {
1050
+ if (!_s.panel.motion) return 0;
1051
+ box.panel.clickable = 0; // WHY: A fading panel must not take a click.
1052
+ box.panel.css.opacity = "0";
1053
+ box.panel.css.transform = "scale(" + _s.panel.startScale + ")";
1054
+ box.after(_s.panel.motionDuration, function () {
1055
+ if (!isOpen) box.panel.visible = 0;
1056
+ });
1057
+ return 1;
1058
+ };
1059
+
1060
+ const selectActiveRow = function () {
1061
+ const item = rows[activeIndex];
1062
+ if (item && isActivatable(item.option)) selectOption(item.option);
1063
+ };
1064
+
1065
+ // A letter typed without Ctrl / Cmd / Alt
1066
+ const isTypedLetter = function (event) {
1067
+ if (event.key.length != 1) return false;
1068
+ return !event.ctrlKey && !event.metaKey && !event.altKey;
1069
+ };
1070
+
1071
+ const onKeyDown = function (self, event) {
1072
+
1073
+ if (box.enabled != 1) return;
1074
+ const key = event.key;
1075
+ const inSearch = box.searchInput && event.target === box.searchInput.inputElement;
1076
+
1077
+ if (!isOpen) {
1078
+ if (key == "Enter" || key == " " || key == "ArrowDown" || key == "ArrowUp") {
1079
+ event.preventDefault();
1080
+ box.open();
1081
+ } else if (isTypedLetter(event) && isSearchable()) {
1082
+ // Typing on the field starts a search.
1083
+ event.preventDefault();
1084
+ box.open(key);
1085
+ }
1086
+ return;
1087
+ }
1088
+
1089
+ switch (key) {
1090
+ case "ArrowDown":
1091
+ event.preventDefault();
1092
+ moveActive(1);
1093
+ break;
1094
+ case "ArrowUp":
1095
+ event.preventDefault();
1096
+ moveActive(-1);
1097
+ break;
1098
+ case "Home":
1099
+ if (inSearch) return;
1100
+ event.preventDefault();
1101
+ setActive(-1, 0);
1102
+ moveActive(1);
1103
+ break;
1104
+ case "End":
1105
+ if (inSearch) return;
1106
+ event.preventDefault();
1107
+ setActive(rows.length, 0);
1108
+ moveActive(-1);
1109
+ break;
1110
+ case "Enter":
1111
+ event.preventDefault();
1112
+ selectActiveRow();
1113
+ break;
1114
+ case " ":
1115
+ if (inSearch) return; // WHY: Space is a letter in the search.
1116
+ event.preventDefault();
1117
+ selectActiveRow();
1118
+ break;
1119
+ case "Escape":
1120
+ event.preventDefault();
1121
+ box.close();
1122
+ box.elem.focus();
1123
+ break;
1124
+ case "Tab":
1125
+ box.close();
1126
+ break;
1127
+ }
1128
+
1129
+ };
1130
+
1131
+ // WHY: The full height list is placed again (on a phone the keyboard of the search box resizes the page).
1132
+ const onPageResize = function () {
1133
+ if (!isOpen) return;
1134
+ if (box.fullHeightList != 1) {
1135
+ box.close();
1136
+ return;
1137
+ }
1138
+ positionPanel();
1139
+ refreshScrollBar();
1140
+ };
1141
+
1142
+ // *** THE SEARCH BOX
1143
+
1144
+ const createSearchBox = function () {
1145
+ if (usesSearchInput) createSearchInput();
1146
+ else createOwnSearch();
1147
+ box.searchGroup.shrink = 0;
1148
+ const input = box.searchInput.inputElement;
1149
+ input.setAttribute("aria-label", box.searchPlaceholder);
1150
+ input.setAttribute("aria-controls", id + "-list");
1151
+ input.setAttribute("autocomplete", "off");
1152
+ };
1153
+
1154
+ // A SearchInput of comp/search-input.js (style.searchInput), with its clear button.
1155
+ const createSearchInput = function () {
1156
+ const params = Object.assign({}, _s.searchInput);
1157
+ params.width = "100%";
1158
+ params.scale = 1; // WHY: style.searchInput is scaled already (with the style of SelectBox).
1159
+ params.placeholder = box.searchPlaceholder;
1160
+ params.onChange = onSearchTextChange; // WHY: also after its clear button (that is not an "input" event).
1161
+ box.searchGroup = SearchInput(params);
1162
+ box.searchInput = box.searchGroup.txtSearch;
1163
+ };
1164
+
1165
+ // The own search box: an icon and an input in a group (style.search).
1166
+ const createOwnSearch = function () {
1167
+ // GROUP: Search
1168
+ box.searchGroup = HGroup({
1169
+ width: "100%",
1170
+ height: _s.search.height,
1171
+ align: "left center",
1172
+ gap: SEARCH_GAP,
1173
+ padding: _s.search.padding,
1174
+ color: _s.search.color,
1175
+ border: _s.search.border,
1176
+ borderColor: _s.search.borderColor,
1177
+ round: _s.search.round,
1178
+ });
1179
+ if (_s.search.borderBottom) box.searchGroup.css.borderBottom = _s.search.borderBottom;
1180
+
1181
+ createSvgLabel(SelectBox.getSearchSvg(_s.arrow.color, _s.search.iconSize), _s.search.iconSize);
1182
+
1183
+ box.searchInput = Input({ width: "100%", height: _s.search.height - SEARCH_INPUT_SPACE, minimal: 1, color: "transparent", fontSize: _s.search.fontSize, textColor: _s.search.textColor });
1184
+ box.searchInput.inputElement.style.padding = "0px";
1185
+ box.searchInput.inputElement.placeholder = box.searchPlaceholder;
1186
+ box.searchInput.css = { flex: "1 1 auto", minWidth: "0" };
1187
+
1188
+ endGroup();
1189
+ };
1190
+
1191
+ const setSearchBoxText = function (text) {
1192
+ if (usesSearchInput) box.searchGroup.setValue(text, 1);
1193
+ else box.searchInput.text = text;
1194
+ };
1195
+
1196
+ // The list of the typed text. (Only when the text changed: SearchInput and the input event both call it.)
1197
+ const onSearchTextChange = function () {
1198
+ if (box.searchInput.text === searchText) return;
1199
+ searchText = box.searchInput.text;
1200
+ renderList();
1201
+ box.list.elem.scrollTop = 0;
1202
+ };
1203
+
1204
+ // *** PUBLIC FUNCTIONS:
1205
+
1206
+ // startText: The first letters of the search (typed on the closed field)
1207
+ box.open = function (startText = "") {
1208
+
1209
+ if (isOpen || box.enabled != 1) return;
1210
+ isOpen = 1;
1211
+
1212
+ searchText = (isSearchable()) ? startText : "";
1213
+ box.searchGroup.visible = (isSearchable()) ? 1 : 0;
1214
+ setSearchBoxText(searchText);
1215
+ box.footer.visible = (isMultiple() && box.showSelectAll == 1) ? 1 : 0;
1216
+
1217
+ // WHY at open: a field in a Dialog or a SidePanel (their layer is over 1001) opens its list over them
1218
+ const layerZIndex = basic.zIndexAbove(box, OVERLAY_Z_INDEX);
1219
+ box.overlay.zIndex = layerZIndex;
1220
+ box.panel.zIndex = layerZIndex + 1;
1221
+ box.overlay.visible = 1;
1222
+ box.panel.visible = 1;
1223
+ applyListHeightMode();
1224
+ renderList();
1225
+ positionPanel();
1226
+ refreshScrollBar(); // WHY: positionPanel may make the list shorter.
1227
+ showPanelWithMotion();
1228
+ if (rows[activeIndex]) scrollToRow(rows[activeIndex].row);
1229
+
1230
+ if (isSearchable()) {
1231
+ box.searchInput.inputElement.focus({ preventScroll: true });
1232
+ const length = searchText.length;
1233
+ box.searchInput.inputElement.setSelectionRange(length, length);
1234
+ } else {
1235
+ box.panel.elem.focus({ preventScroll: true });
1236
+ }
1237
+
1238
+ updateField();
1239
+ box.onOpen(box);
1240
+
1241
+ };
1242
+
1243
+ box.close = function () {
1244
+
1245
+ if (!isOpen) return;
1246
+ isOpen = 0;
1247
+
1248
+ box.overlay.visible = 0;
1249
+ if (!hidePanelWithMotion()) box.panel.visible = 0;
1250
+
1251
+ updateField();
1252
+ box.onClose(box);
1253
+
1254
+ };
1255
+
1256
+ box.toggle = function () {
1257
+ (isOpen) ? box.close() : box.open();
1258
+ };
1259
+
1260
+ box.isOpen = function () {
1261
+ return isOpen;
1262
+ };
1263
+
1264
+ // silent: 1 -> onChange is not called.
1265
+ box.setValue = function (value, silent = 0) {
1266
+ const next = normalizeValue(value);
1267
+ // WHY JSON: a multiple selection is a list (setOptions compares the same way)
1268
+ if (JSON.stringify(next) === JSON.stringify(box.value)) return;
1269
+ box.value = next;
1270
+ updateField();
1271
+ if (isOpen) renderList();
1272
+ if (!silent) box.onChange(box);
1273
+ };
1274
+ // USAGE: select.setValue("apple") or select.setValue(["a", "b"]) (multiple)
1275
+
1276
+ box.getValue = function () {
1277
+ return (isMultiple()) ? box.value.slice() : box.value;
1278
+ };
1279
+
1280
+ box.getSelectedOptions = function () {
1281
+ return box.options.filter(isSelected);
1282
+ };
1283
+
1284
+ // Changes the options. The value is kept if it is still in the options.
1285
+ box.setOptions = function (options, silent = 1) {
1286
+ box.options = SelectBox.normalizeOptions(options);
1287
+ const oldValue = JSON.stringify(box.value);
1288
+ box.value = normalizeValue(box.value);
1289
+ if (box.itemList) fillItemList();
1290
+ updateField();
1291
+ if (isOpen) renderList();
1292
+ if (!silent && JSON.stringify(box.value) != oldValue) box.onChange(box);
1293
+ };
1294
+
1295
+ box.clear = function (silent = 0) {
1296
+ box.setValue((isMultiple()) ? [] : null, silent);
1297
+ };
1298
+
1299
+ box.setEnabled = function (enabled) {
1300
+ box.enabled = basic.isOn(enabled) ? 1 : 0;
1301
+ if (box.enabled != 1) box.close();
1302
+ updateField();
1303
+ };
1304
+
1305
+ box.setPlaceholder = function (text) {
1306
+ box.placeholder = text;
1307
+ updateField();
1308
+ };
1309
+
1310
+ box.focus = function () {
1311
+ box.elem.focus();
1312
+ };
1313
+
1314
+ // 1: the list from the top of the page to its bottom. 0: under (or above) the field.
1315
+ box.setFullHeightList = function (value) {
1316
+ box.fullHeightList = basic.isOn(value) ? 1 : 0;
1317
+ if (!isOpen) return;
1318
+ applyListHeightMode();
1319
+ positionPanel();
1320
+ refreshScrollBar();
1321
+ };
1322
+ // USAGE: select.setFullHeightList(1)
1323
+
1324
+
1325
+ // *** OBJECT VIEW:
1326
+
1327
+ box.color = "transparent";
1328
+ box.clickable = 1;
1329
+ box.css = { outline: "none", userSelect: "none" };
1330
+ box.role = "combobox";
1331
+ box.aria = { haspopup: "listbox", controls: id + "-list" };
1332
+ if (box.ariaLabel) box.aria = { label: box.ariaLabel };
1333
+
1334
+ // GROUP: Field
1335
+ box.field = HGroup({
1336
+ width: "100%",
1337
+ height: "100%",
1338
+ align: "left center",
1339
+ gap: _s.fieldOption.gap,
1340
+ ..._s.field,
1341
+ });
1342
+ box.field.setMotion("border-color 0.15s");
1343
+
1344
+ // ICON: The icon of the selected option (style.fieldOption.iconSize)
1345
+ box.fieldIcon = Icon({ width: _s.fieldOption.iconSize, height: _s.fieldOption.iconSize, round: _s.fieldOption.iconRound });
1346
+ box.fieldIcon.shrink = 0;
1347
+ box.fieldIcon.elem.alt = "";
1348
+ box.fieldIcon.css.marginLeft = _s.fieldOption.iconMarginLeft + "px";
1349
+
1350
+ // GROUP: Selected text and its description
1351
+ box.fieldTexts = VGroup({ width: "auto", height: "auto", align: "left center", gap: 0 });
1352
+ box.fieldTexts.css = { flex: "1 1 auto", minWidth: "0", alignItems: "stretch" };
1353
+
1354
+ // LABEL: Selected text
1355
+ box.fieldText = Label({
1356
+ text: "",
1357
+ width: "100%",
1358
+ fontSize: _s.fieldText.fontSize,
1359
+ textColor: _s.fieldText.textColor,
1360
+ });
1361
+ box.fieldText.ellipsis = 1;
1362
+
1363
+ // LABEL: Description of the selected option
1364
+ box.fieldDescription = createDescription("");
1365
+ box.fieldDescription.ellipsis = 1;
1366
+
1367
+ endGroup();
1368
+ // WHY: Hidden after they are created: children created in a hidden group are not flex items.
1369
+ box.fieldIcon.visible = 0;
1370
+ box.fieldDescription.visible = 0;
1371
+
1372
+ // LABEL: Clear button
1373
+ box.clearButton = Label({
1374
+ text: SelectBox.getClearSvg(_s.arrow.color, CLEAR_ICON_SIZE),
1375
+ width: CLEAR_BUTTON_SIZE,
1376
+ height: CLEAR_BUTTON_SIZE,
1377
+ round: BUTTON_ROUND,
1378
+ clickable: 1,
1379
+ });
1380
+ box.clearButton.shrink = 0;
1381
+ box.clearButton.lineHeight = "0";
1382
+ box.clearButton.elem.style.display = "flex";
1383
+ box.clearButton.css = { alignItems: "center", justifyContent: "center" };
1384
+ box.clearButton.cursor = "pointer";
1385
+ box.clearButton.aria = { label: "Clear" };
1386
+
1387
+ // LABEL: Arrow
1388
+ const arrowSvg = (_s.arrow.icon === "unfold") ? SelectBox.getUnfoldSvg(_s.arrow.color, _s.arrow.size) : SelectBox.getArrowSvg(_s.arrow.color, _s.arrow.size);
1389
+ box.arrow = createSvgLabel(arrowSvg, _s.arrow.size);
1390
+ box.arrow.css.transition = "transform 0.15s";
1391
+ box.arrow.opacity = _s.arrow.opacity;
1392
+ if (_s.arrow.marginRight) box.arrow.css.marginRight = _s.arrow.marginRight + "px";
1393
+
1394
+ endGroup();
1395
+
1396
+ // POPUP: Create the overlay and the panel on the page, over everything.
1397
+ setDefaultContainerBox(page);
1398
+ // NOTE: endGroup() of the panel below returns the default container to the component box.
1399
+
1400
+ // BOX: Transparent overlay (click outside: close)
1401
+ // WHY a very big box and not 100% x 100%: with position "fixed" the "100%" is taken from the nearest parent that
1402
+ // has a zoom or a transform (page.autoFit, a scaled preview); there the overlay had no height (0 px) and a click
1403
+ // outside the list did not close it. A box that starts far before the screen and ends far after it covers the
1404
+ // screen in every case.
1405
+ const OVERLAY_SIZE = 20000; // px
1406
+ box.overlay = Box(-OVERLAY_SIZE, -OVERLAY_SIZE, OVERLAY_SIZE * 2, OVERLAY_SIZE * 2, { color: "transparent", clickable: 1 });
1407
+ box.overlay.css.position = "fixed";
1408
+ box.overlay.zIndex = OVERLAY_Z_INDEX;
1409
+
1410
+ // GROUP: Panel
1411
+ box.panel = VGroup({
1412
+ width: box.panelMinWidth,
1413
+ height: "auto",
1414
+ align: "left top",
1415
+ gap: _s.panel.gap,
1416
+ color: _s.panel.color,
1417
+ border: _s.panel.border,
1418
+ borderColor: _s.panel.borderColor,
1419
+ round: _s.panel.round,
1420
+ padding: _s.panel.padding,
1421
+ clickable: 1,
1422
+ });
1423
+ box.panel.css = { alignItems: "stretch", outline: "none" };
1424
+ box.panel.boxShadow = _s.panel.shadow;
1425
+ box.panel.zIndex = PANEL_Z_INDEX;
1426
+ box.panel.tabIndex = -1;
1427
+
1428
+ // SEARCH: a SearchInput, or the own search box
1429
+ createSearchBox();
1430
+
1431
+ // BOX: List
1432
+ box.list = Box({ width: "100%", height: "auto", color: "transparent", scrollY: 1, position: "relative" });
1433
+ box.list.elem.id = id + "-list";
1434
+ box.list.role = "listbox";
1435
+ box.list.css.overscrollBehavior = "contain";
1436
+
1437
+ // GROUP: Footer (multiple)
1438
+ box.footer = HGroup({ width: "100%", height: "auto", align: "left center", padding: FOOTER_PADDING });
1439
+ box.footer.css = {
1440
+ justifyContent: "space-between",
1441
+ borderTop: DIVIDER_WIDTH + "px solid " + _s.divider.color,
1442
+ };
1443
+ box.footer.shrink = 0;
1444
+
1445
+ box.selectAllButton = Label({ text: SelectBox.escapeHtml(box.selectAllText), padding: FOOTER_BUTTON_PADDING, round: BUTTON_ROUND, clickable: 1, ..._s.footerButton });
1446
+ box.selectAllButton.cursor = "pointer";
1447
+
1448
+ box.clearAllButton = Label({ text: SelectBox.escapeHtml(box.clearText), padding: FOOTER_BUTTON_PADDING, round: BUTTON_ROUND, clickable: 1, ..._s.footerButton });
1449
+ box.clearAllButton.cursor = "pointer";
1450
+
1451
+ endGroup();
1452
+
1453
+ endGroup();
1454
+
1455
+ box.overlay.visible = 0;
1456
+ box.panel.visible = 0;
1457
+
1458
+ // SCROLL BAR: on the list. It moves itself into the panel (the parent of the list) and sits over the list.
1459
+ // WHY: Created here, not in the panel: an object created in the panel (a group) would be a part of its layout.
1460
+ if (box.useScrollBar == 1 && typeof ScrollBar !== "undefined") {
1461
+ // WHY scale 1: style.scrollBar is scaled already (with the style of SelectBox).
1462
+ box.scrollBar = ScrollBar(Object.assign({ scrollableBox: box.list, scale: 1 }, _s.scrollBar));
1463
+ }
1464
+
1465
+ // *** OBJECT INIT CODE:
1466
+
1467
+ box.on("click", function (self, event) {
1468
+ if (box.enabled != 1) return;
1469
+ if (box.clearButton.elem.contains(event.target)) return;
1470
+ box.toggle();
1471
+ });
1472
+ box.on("keydown", onKeyDown);
1473
+ box.on("focus", function () {
1474
+ isFocused = 1;
1475
+ updateField();
1476
+ });
1477
+ box.on("blur", function () {
1478
+ isFocused = 0;
1479
+ updateField();
1480
+ });
1481
+ box.on("mouseover", function () {
1482
+ isMouseOver = 1;
1483
+ updateField();
1484
+ });
1485
+ box.on("mouseout", function () {
1486
+ isMouseOver = 0;
1487
+ updateField();
1488
+ });
1489
+
1490
+ box.clearButton.on("click", function () {
1491
+ box.clear();
1492
+ box.elem.focus();
1493
+ });
1494
+
1495
+ box.overlay.on("click", function () { box.close(); });
1496
+
1497
+ box.panel.on("keydown", onKeyDown);
1498
+ // style.optionActive.showAtOpen: 0 -> the active row is only the row under the mouse (or of the keyboard).
1499
+ box.list.on("mouseleave", function () {
1500
+ if (_s.optionActive.showAtOpen == 0) setActive(-1, 0);
1501
+ });
1502
+ // WHY: Keep the keyboard focus (field or search) when a row is pressed.
1503
+ box.panel.on("mousedown", function (self, event) {
1504
+ if (event.target !== box.searchInput.inputElement) event.preventDefault();
1505
+ });
1506
+
1507
+ box.searchInput.inputElement.addEventListener("input", onSearchTextChange);
1508
+
1509
+ box.selectAllButton.on("click", function () {
1510
+ // Only the options in the search result
1511
+ const enabledOptions = getShownOptions().filter(function (option) { return !option.disabled; });
1512
+ const valuesToAdd = enabledOptions.map(function (option) { return option.value; });
1513
+ box.setValue(box.value.concat(valuesToAdd));
1514
+ });
1515
+
1516
+ box.clearAllButton.on("click", function () {
1517
+ box.clear();
1518
+ });
1519
+
1520
+ // (onPageResize / own: the overlay and the panel are on the page, they are removed with the box)
1521
+ box.onPageResize(onPageResize);
1522
+ box.own(box.overlay);
1523
+ box.own(box.panel);
1524
+
1525
+ box.enabled = basic.isOn(box.enabled) ? 1 : 0;
1526
+ box.options = SelectBox.normalizeOptions(startOptions);
1527
+ box.value = normalizeValue(startValue);
1528
+
1529
+ updateField();
1530
+
1531
+ return endObject(box);
1532
+
1533
+ };
1534
+
1535
+ // *** STATIC VARIABLES AND FUNCTIONS:
1536
+
1537
+ SelectBox._counter = 1;
1538
+
1539
+ // scale: every size of the style and of the size params is multiplied (params is changed). Scale 1 changes nothing.
1540
+ // WHY: The default (null) is read when a select box is made, not when this file is loaded: the page sets
1541
+ // basic.uiScale later (page.fit(600, 800); basic.uiScale = 1 / page.zoom).
1542
+ SelectBox.applyScale = function (params) {
1543
+ const givenScale = Number(params.scale);
1544
+ params.scale = (givenScale > 0) ? givenScale : (basic.uiScale || 1);
1545
+ if (params.scale === 1) return;
1546
+ const scale = params.scale;
1547
+ const style = basic.scaleStyle(params.style, scale);
1548
+ // WHY: Texts with px in them: basic.scaleStyle changes only the numbers.
1549
+ style.panel.shadow = basic.scaleCssText(style.panel.shadow, scale);
1550
+ style.search.borderBottom = basic.scaleCssText(style.search.borderBottom, scale);
1551
+ style.searchInput.borderBottomStyle = basic.scaleCssText(style.searchInput.borderBottomStyle, scale);
1552
+ params.style = style;
1553
+ ["width", "height", "panelMinWidth", "panelMaxHeight"].forEach(function (name) {
1554
+ params[name] = basic.scaleSize(params[name], scale);
1555
+ });
1556
+ };
1557
+
1558
+ // createItemView needs comp/item-list.js. Without it: one warning, and the normal rows.
1559
+ SelectBox.canUseItemList = function () {
1560
+ if (typeof ItemList !== "undefined") return true;
1561
+ if (!SelectBox._hasWarnedItemList) {
1562
+ console.warn("SelectBox: createItemView needs comp/item-list.js (ItemList), loaded before select-box.js. The normal rows are used.");
1563
+ SelectBox._hasWarnedItemList = 1;
1564
+ }
1565
+ return false;
1566
+ };
1567
+
1568
+ // The search box is a SearchInput when comp/search-input.js is loaded (no warning without it: the own box).
1569
+ // WHY SearchInput.styles: an older SearchInput had the same global name and not the same params.
1570
+ SelectBox.canUseSearchInput = function () {
1571
+ return (typeof SearchInput === "function") && !!SearchInput.styles;
1572
+ };
1573
+
1574
+ // A search box in a package of SearchInput (style.searchInput.styleName): the params of that package fill
1575
+ // style.searchInput before SelectBoxDefaults does. The keys of the SelectBox package still win.
1576
+ // WHY: The look keys of the classic search box of SelectBoxDefaults filled every missing key, so a search box with
1577
+ // styleName "ozden" kept the classic icons, sizes and colors (the search box of SelectBox ozden looked old).
1578
+ SelectBox.fillSearchInputPackage = function (style) {
1579
+ const searchInput = style.searchInput;
1580
+ if (!searchInput || !SelectBox.canUseSearchInput()) return;
1581
+ const searchPackage = SearchInput.styles[searchInput.styleName];
1582
+ if (!searchPackage) return;
1583
+ const packageParams = Object.assign({}, searchPackage);
1584
+ delete packageParams.style;
1585
+ mergeIntoIfMissing(searchInput, packageParams);
1586
+ };
1587
+
1588
+ // "Apple" -> { value: "Apple", label: "Apple", description: "", iconFile: "", group: "", disabled: 0 }
1589
+ SelectBox.normalizeOptions = function (options) {
1590
+ return (options || []).map(function (option) {
1591
+ if (option === null || typeof option !== "object") {
1592
+ return { value: option, label: String(option), description: "", iconFile: "", group: "", disabled: 0 };
1593
+ }
1594
+ return {
1595
+ ...option,
1596
+ value: option.value,
1597
+ label: String(option.label ?? option.value),
1598
+ description: option.description || "",
1599
+ iconFile: option.iconFile || "",
1600
+ group: option.group || "",
1601
+ disabled: basic.isOn(option.disabled) ? 1 : 0,
1602
+ };
1603
+ });
1604
+ };
1605
+
1606
+ // WHY: Label.text uses innerHTML. Texts must not be read as HTML.
1607
+ SelectBox.escapeHtml = basic.escapeHtml; // (the name is kept: other code may use it)
1608
+
1609
+ SelectBox.getArrowSvg = function (color, size = 16) {
1610
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>';
1611
+ };
1612
+
1613
+ // Up and down arrows (the "unfold more" icon)
1614
+ SelectBox.getUnfoldSvg = function (color, size = 20) {
1615
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 -960 960 960" fill="' + color + '"><path d="M480-80 240-320l57-57 183 183 183-183 57 57L480-80ZM298-584l-58-56 240-240 240 240-58 56-182-182-182 182Z"/></svg>';
1616
+ };
1617
+
1618
+ SelectBox.getClearSvg = function (color, size = 14) {
1619
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.2" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg>';
1620
+ };
1621
+
1622
+ SelectBox.getSearchSvg = function (color, size = 16) {
1623
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>';
1624
+ };
1625
+
1626
+ SelectBox.getTickSvg = function (color, size = 16) {
1627
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="' + color + '" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12.5 4.5 4.5L19 7.5"/></svg>';
1628
+ };
1629
+
1630
+ // Check box of the multiple mode
1631
+ SelectBox.getCheckSvg = function (checked, style, size = 18) {
1632
+ const s = style.optionSelected;
1633
+ const svgStart = '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 18 18">';
1634
+ if (!checked) {
1635
+ return svgStart + '<rect x="1" y="1" width="16" height="16" rx="4" fill="none" stroke="' + style.arrow.color + '" stroke-width="1.5"/></svg>';
1636
+ }
1637
+ return svgStart + '<rect x="0.5" y="0.5" width="17" height="17" rx="4" fill="' + s.checkColor + '"/>' +
1638
+ '<path d="m4.5 9.3 3 3 6-6.3" fill="none" stroke="' + s.checkTickColor + '" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
1639
+ };
1640
+
1641
+ // *** STYLE PACKAGES:
1642
+ // USAGE: SelectBox({ styleName: "dark" })
1643
+ // USAGE: SelectBox({ styleName: "dark", style: { field: { round: 4 } } }) // Change only some keys.
1644
+ // USAGE: SelectBox({ style: SelectBox.styles.dark }) // The same as styleName: "dark". (The package is copied, never changed.)
1645
+ // NOTE: A new package needs only the keys that differ from the default (classic) style.
1646
+ // USAGE: SelectBox.styles.myStyle = { field: { color: "ivory" } };
1647
+ SelectBox.styles = {
1648
+
1649
+ // White field, dark text, a soft line.
1650
+ light: SelectBoxDefaults.style,
1651
+
1652
+ // Dark theme. (The other dark packages use these colors.)
1653
+ dark: {
1654
+ field: { color: "#232322", border: 1, borderColor: "rgba(255, 255, 255, 0.10)", round: 8, padding: [12, 0] },
1655
+ fieldHover: { borderColor: "rgba(255, 255, 255, 0.30)" },
1656
+ fieldFocus: { borderColor: "#65A293" },
1657
+ fieldText: { fontSize: 15, textColor: "rgba(255, 255, 255, 0.90)" },
1658
+ placeholder: { textColor: "rgba(255, 255, 255, 0.40)" },
1659
+ arrow: { color: "rgba(255, 255, 255, 0.55)" },
1660
+ panel: { color: "#232322", border: 1, borderColor: "rgba(255, 255, 255, 0.12)", round: 10, padding: 6, shadow: "0 8px 24px rgba(0, 0, 0, 0.5)" },
1661
+ searchInput: {
1662
+ styleName: "original", // the first look of SearchInput
1663
+ height: 38,
1664
+ searchIconLeft: 10, // WHY: the icon and the text at the place of the own search input (icon 18, text 42)
1665
+ color: "rgba(255, 255, 255, 0.05)",
1666
+ border: 1,
1667
+ borderColor: "rgba(255, 255, 255, 0.10)",
1668
+ borderBottomStyle: "1px solid rgba(255, 255, 255, 0.10)",
1669
+ round: 6,
1670
+ fontSize: 14,
1671
+ textColor: "rgba(255, 255, 255, 0.90)",
1672
+ placeholderColor: "",
1673
+ searchIconSize: 16,
1674
+ searchIconOpacity: 0.55,
1675
+ clearIconOpacity: 0.45,
1676
+ invertIconColor: 1, // WHY: the icon files are black.
1677
+ },
1678
+ search: { color: "rgba(255, 255, 255, 0.05)", border: 1, borderColor: "rgba(255, 255, 255, 0.10)", round: 6, fontSize: 14, textColor: "rgba(255, 255, 255, 0.90)" },
1679
+ option: { fontSize: 14, textColor: "rgba(255, 255, 255, 0.85)", round: 6, padding: [10, 8] },
1680
+ optionActive: { color: "rgba(255, 255, 255, 0.08)" },
1681
+ optionSelected: { textColor: "#FFFFFF", checkColor: "#3D7A6B", checkTickColor: "#FFFFFF" },
1682
+ optionDisabled: { opacity: 0.4 },
1683
+ description: { fontSize: 12, textColor: "rgba(255, 255, 255, 0.45)" },
1684
+ group: { fontSize: 11, textColor: "rgba(255, 255, 255, 0.45)" },
1685
+ highlight: { color: "rgba(101, 162, 147, 0.45)" },
1686
+ empty: { fontSize: 14, textColor: "rgba(255, 255, 255, 0.45)" },
1687
+ footerButton: { fontSize: 13, textColor: "#65A293" },
1688
+ divider: { color: "rgba(255, 255, 255, 0.08)" },
1689
+ disabled: { opacity: 0.4 },
1690
+ itemList: {
1691
+ hover: { color: "rgba(255, 255, 255, 0.08)" },
1692
+ selected: { color: "rgba(255, 255, 255, 0.05)", opacity: 1 },
1693
+ check: { color: "#3D7A6B", iconColor: "#FFFFFF", borderColor: "rgba(255, 255, 255, 0.3)" },
1694
+ },
1695
+ scrollBar: { bar_color: "#8A8A88", bar_mouseOverColor: "#BFBFBD" },
1696
+ },
1697
+
1698
+ };
1699
+ SelectBox.styles.classic = SelectBox.styles.light; // the old name of light: the pages made with it keep their look
1700
+
1701
+
1702
+ // A whitesmoke box with a thin border, the list opens over the field with a fade, a white search box (SearchInput),
1703
+ // rows that get white with a thin line above and under them under the mouse, the selected one half transparent.
1704
+ // A package of params: a 350 x 50 field, a search box, the list down to the
1705
+ // bottom of the page. Text rows; your own rows and field: createItemView / createValueView
1706
+ // (02-comp-examples/select-box-ozden-item.htm). The params of the package are used when the page does not give them.
1707
+ SelectBox.styles.ozden = {
1708
+ width: 350,
1709
+ height: 50,
1710
+ searchable: 1,
1711
+ searchPlaceholder: "Search",
1712
+ panelMaxHeight: 2000, // WHY: The old list went down to the bottom of the page (the panel stays on the page).
1713
+ style: {
1714
+ // WHY: padding 19 (not 20): the border is inside the box. The old border was drawn over the content.
1715
+ field: { color: "whitesmoke", border: 1, borderColor: "rgba(0, 0, 0, 0.3)", round: 4, padding: [19, 0] },
1716
+ fieldHover: { borderColor: "rgba(0, 0, 0, 0.3)" },
1717
+ fieldFocus: { borderColor: "rgba(0, 0, 0, 0.3)" },
1718
+ fieldText: { fontSize: 20, textColor: "rgba(0, 0, 0, 0.8)" },
1719
+ fieldOption: { iconSize: 0, iconRound: 0, iconMarginLeft: 0, gap: 12, showDescription: 0, emptyIconColor: "" }, // text in the field: your own field with createValueView
1720
+ placeholder: { textColor: Black(0.4) },
1721
+ arrow: { color: "black", icon: "unfold", size: 20, opacity: 0.8, marginRight: -16 },
1722
+ panel: {
1723
+ color: "whitesmoke",
1724
+ border: 1,
1725
+ borderColor: "rgba(0, 0, 0, 0.3)",
1726
+ round: 4,
1727
+ padding: 0,
1728
+ shadow: "none",
1729
+ gap: 0,
1730
+ coverField: 1,
1731
+ motion: "opacity 0.2s, transform 0.2s",
1732
+ motionDuration: 200,
1733
+ startScale: 0.9,
1734
+ },
1735
+ // The search bar: the ozden SearchInput (its icons, its font and icon sizes, its bottom line) in white, nearly
1736
+ // square and without a border: the search box of ItemList ozden.
1737
+ searchInput: {
1738
+ styleName: "ozden",
1739
+ height: 44, // as ItemList ozden; ozdenDark takes it too
1740
+ searchIconLeft: 16, // WHY: the default of SearchInput, as ItemList ozden (SelectBoxDefaults has 10)
1741
+ color: "white",
1742
+ border: 0,
1743
+ round: 2,
1744
+ },
1745
+ search: {
1746
+ color: "white", // (as searchInput)
1747
+ border: 0,
1748
+ borderColor: "transparent",
1749
+ round: 2,
1750
+ fontSize: 18,
1751
+ textColor: "rgba(0, 0, 0, 0.8)",
1752
+ height: 44, // as searchInput (this own search box: a page without comp/search-input.js)
1753
+ padding: [16, 0],
1754
+ iconSize: 22,
1755
+ borderBottom: "2px solid rgba(0, 0, 0, 0.06)",
1756
+ },
1757
+ option: {
1758
+ fontSize: 20,
1759
+ textColor: "rgba(0, 0, 0, 0.8)",
1760
+ round: 0,
1761
+ padding: [19, 0], // WHY: 19: the border of the panel is inside it (see field)
1762
+ gap: 20,
1763
+ minHeight: 50,
1764
+ iconSize: 30,
1765
+ iconRound: 4,
1766
+ iconMargin: [0, 0],
1767
+ },
1768
+ optionActive: { color: "white", lineColor: Black(0.2), showAtOpen: 0 }, // as ItemList ozden
1769
+ // WHY canSelectAgain 0: the selected item is half transparent and not clickable: it does not get the white under
1770
+ // the mouse and a click on it does nothing.
1771
+ optionSelected: { textColor: "rgba(0, 0, 0, 0.8)", checkColor: "#373836", checkTickColor: "white", fontFamily: "", showTick: 0, opacity: 0.5, canSelectAgain: 0 },
1772
+ description: { fontSize: 14, textColor: "gray", marginTop: -4 }, // WHY -4: the title and the description overlap a little.
1773
+ highlight: { color: "transparent" },
1774
+ empty: { fontSize: 16, textColor: Black(0.45) },
1775
+ // createItemView: rows that are white with a thin line above and under them under the mouse, the selected one
1776
+ // half transparent, as ItemList ozden.
1777
+ itemList: {
1778
+ row: { padding: [19, 0], gap: 20, round: 0, motion: "background-color 0.2s, box-shadow 0.2s" }, // WHY: 19: see option.padding
1779
+ hover: { color: "white", lineColor: Black(0.2) },
1780
+ selected: { color: "transparent", opacity: 0.5 }, // WHY: transparent: no look of its own (it can not be chosen again).
1781
+ check: { size: 22, color: "#373836", iconColor: "white", borderColor: Black(0.25) },
1782
+ },
1783
+ // The scroll bar: always shown, with the dots at its ends.
1784
+ scrollBar: { bar_color: "#373836", bar_mouseOverColor: "#373836", bar_opacity: 0.4, bar_mouseOverOpacity: 0.9, neverHide: 1, showDots: 1 },
1785
+ },
1786
+ };
1787
+
1788
+ // The dark theme of ozden: the shapes of ozden in the dark tones of the kit, as ItemList
1789
+ // ozdenDark: a field and a list of #1A1A19 (on a darker page, Ex: #141414), the active row #262624 with a thin light
1790
+ // line above and under it, the selected one half transparent, the ozdenDark search box (02-comp-examples/
1791
+ // select-box-ozden-dark-text.htm). Only the colors are here: the sizes and the params come from ozden (below).
1792
+ SelectBox.styles.ozdenDark = {
1793
+ style: {
1794
+ field: { color: "#1A1A19", borderColor: White(0.22) },
1795
+ fieldHover: { borderColor: White(0.22) },
1796
+ fieldFocus: { borderColor: White(0.22) },
1797
+ fieldText: { textColor: White(0.88) },
1798
+ placeholder: { textColor: White(0.4) },
1799
+ arrow: { color: "white" },
1800
+ panel: { color: "#1A1A19", borderColor: White(0.22) },
1801
+ searchInput: { styleName: "ozdenDark", color: "#262624" },
1802
+ search: { color: "#262624", textColor: White(0.88), borderBottom: "2px solid " + White(0.06) },
1803
+ option: { textColor: White(0.88) },
1804
+ optionActive: { color: "#262624", lineColor: White(0.14) },
1805
+ optionSelected: { textColor: White(0.88), checkColor: "#E6E6E4", checkTickColor: "#1A1A19" },
1806
+ description: { textColor: White(0.45) },
1807
+ group: { textColor: White(0.45) },
1808
+ empty: { textColor: White(0.45) },
1809
+ footerButton: { textColor: White(0.8) },
1810
+ divider: { color: White(0.08) },
1811
+ itemListStyleName: "ozdenDark",
1812
+ itemList: {
1813
+ hover: { color: "#262624", lineColor: White(0.14) },
1814
+ check: { color: "#E6E6E4", iconColor: "#1A1A19", borderColor: White(0.3) },
1815
+ },
1816
+ scrollBar: { bar_color: "#CFCFCD", bar_mouseOverColor: "#CFCFCD" },
1817
+ },
1818
+ };
1819
+ // WHY: The shapes, the sizes and the params of ozden (350 x 50, the search box, the list to the bottom of the page).
1820
+ mergeIntoIfMissing(SelectBox.styles.ozdenDark, SelectBox.styles.ozden);
1821
+
1822
+ // The old name of the dark package. (Kept: pages may use it.)
1823
+ SelectBox.DARK_STYLE = SelectBox.styles.dark;
1824
+
1825
+ // The minimal theme (_designs/minimal-theme.htm): a 28 px field of a line (darker under the mouse, ink while open),
1826
+ // a 13 px text, a 14 px chevron; the list on the ground of the window with a line and no shadow, a line around the row
1827
+ // under the mouse, the selected row in ink with a check. minimalDark: the same on a dark window.
1828
+ SelectBox.createMinimalStyle = function (colors) {
1829
+ return {
1830
+ height: 28,
1831
+ style: {
1832
+ field: { color: "transparent", border: 1, borderColor: colors.edge, round: 4, padding: [10, 0] }, // WHY edge: 3:1 at least (a control)
1833
+ fieldHover: { borderColor: colors.edgeHover },
1834
+ fieldFocus: { borderColor: colors.ink },
1835
+ fieldText: { fontSize: 13, textColor: colors.text },
1836
+ placeholder: { textColor: colors.faintText },
1837
+ arrow: { color: colors.softText, icon: "chevron", size: 14, opacity: 1, marginRight: 0 },
1838
+ panel: { color: colors.ground, border: 1, borderColor: colors.line, round: 4, padding: 4, shadow: "none", gap: 4 },
1839
+ searchInput: { styleName: colors.searchStyleName, height: 28, fontSize: 13, searchIconSize: 14, searchIconLeft: 10, searchIconGap: 6, round: 14 },
1840
+ search: { color: "transparent", border: 1, borderColor: colors.edge, round: 4, fontSize: 13, textColor: colors.text, height: 28, padding: [10, 0], iconSize: 14 },
1841
+ option: { fontSize: 13, textColor: colors.text, round: 3, padding: [8, 4], gap: 8, iconSize: 14, border: 1, borderColor: "transparent", space: 2 },
1842
+ optionActive: { color: "transparent", lineColor: "", borderColor: colors.lineHover },
1843
+ optionSelected: { textColor: colors.ink, checkColor: colors.ink, checkTickColor: colors.onInk, fontFamily: "", showTick: 1, tickSize: 12, borderColor: colors.ink },
1844
+ description: { fontSize: 12, textColor: colors.softText },
1845
+ group: { fontSize: 11, textColor: colors.faintText },
1846
+ empty: { fontSize: 12, textColor: colors.softText },
1847
+ footerButton: { fontSize: 12, textColor: colors.ink },
1848
+ divider: { color: colors.line },
1849
+ itemListStyleName: colors.itemListStyleName,
1850
+ },
1851
+ };
1852
+ };
1853
+ SelectBox.MINIMAL_COLORS = {
1854
+ ground: "#FFFFFF", text: Black(0.85), softText: Black(0.55), faintText: Black(0.54),
1855
+ line: Black(0.2), lineHover: Black(0.45), edge: Black(0.45), edgeHover: Black(0.65), ink: "#1F1F1F", onInk: "#FFFFFF", searchStyleName: "minimal", itemListStyleName: "minimal",
1856
+ };
1857
+ SelectBox.styles.minimal = SelectBox.createMinimalStyle(SelectBox.MINIMAL_COLORS);
1858
+ SelectBox.MINIMAL_DARK_COLORS = {
1859
+ ground: "#1A1A19", text: White(0.88), softText: White(0.55), faintText: White(0.48),
1860
+ line: White(0.18), lineHover: White(0.42), edge: White(0.42), edgeHover: White(0.62), ink: "#EDEDEB", onInk: "#1A1A19", searchStyleName: "minimalDark", itemListStyleName: "minimalDark",
1861
+ };
1862
+ SelectBox.styles.minimalDark = SelectBox.createMinimalStyle(SelectBox.MINIMAL_DARK_COLORS);