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,548 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ LeftMenu - v26.09
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - You can customize, this template code as you need:
9
+
10
+ - The menu opens when the mouse is over it. On a touch device there is no hover, so it opens with a tap:
11
+ the first tap opens the menu (it does not select an item, because the texts are not visible when it is closed),
12
+ the second tap selects the item and closes the menu. A tap outside the menu also closes it.
13
+ -- openOnClick: "auto" (touch device: tap, mouse: hover), 1: always tap, 0: always hover, "direct": a tap selects at
14
+ once and the menu stays closed (for a short menu with clear icons).
15
+ -- itemHeight: the height of a button item. A page fitted with page.fit() is zoomed: for a finger give Ex: 44 / page.zoom.
16
+ -- leftMenu.setOpenOnClick(1) changes it later.
17
+ - Style packages: "dark" (default: a dark menu with a red selection) and "light" (for a light
18
+ page: a light menu with a line at its right side, a soft shadow while it is open over the page, the cyan of
19
+ SmartButton in light tones, dark icons and a dark scroll bar). A package is a package of params (LeftMenu.styles):
20
+ LeftMenu({ styleName: "light" }), LeftMenu({ styleName: "light", selectedColor: "#DCEBEC" }) (a param wins).
21
+ Samples: 02-comp-examples/left-menu.htm (dark), left-menu-2.htm (light).
22
+ - An item: { key, type: "button", text, iconFile, dontSelect } (dontSelect: 1: a click opens it, the selection stays)
23
+ or a title { key, type: "header", text }. addItemToTop(item) / addItemToBottom(item) add one later.
24
+
25
+ Started Date: December 2024
26
+ Webpage: https://bug7a.github.io/js-components/
27
+
28
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
29
+ Licensed under the Apache License, Version 2.0
30
+ SPDX-License-Identifier: Apache-2.0
31
+
32
+ */
33
+
34
+ "use strict";
35
+
36
+ // Default values:
37
+ const LeftMenuDefaults = {
38
+ key: "0",
39
+ expandedWidth: 250, // Expanded width on hover
40
+ itemHeight: 40, // The height of a button item
41
+ topBarHeight: 40, // Height of top bar to account for
42
+ backgroundColor: "#141414", // Menu background color
43
+ hoverColor: "rgba(255, 255, 255, 0.05)", // Hover color for buttons
44
+ selectedColor: "#583432", // Selected button color
45
+ titleColor: "#8E342F",
46
+ textColor: "rgba(255, 255, 255, 0.6)", // Text color
47
+ selectedTextColor: "rgba(255, 255, 255, 0.95)",
48
+ allowHtml: 0, // 1: the texts of the items are HTML (only for your own texts)
49
+ invertIconColor: 1,
50
+ lineColor: "", // A line at the right side of the menu ("": none)
51
+ expandedShadow: "", // The shadow of the open menu over the page ("": none). Ex: "6px 0 18px rgba(0, 0, 0, 0.08)"
52
+ scrollBarColor: "#FFFFFF", // The bar of the scroll of the items (a dark one on a light menu)
53
+ openOnClick: "auto", // "auto": Tap on a touch device, hover with a mouse. 1: Always tap, 0: Always hover.
54
+ items: [], // [{ key, type: "button", text, iconFile }, { key, type: "header", text }]
55
+ onItemClick: function(self, item) {}, // Callback when item is clicked
56
+ onMenuToggle: function(self, isExpanded) {}, // Callback when menu expands/collapses
57
+ styleName: "dark", // "dark", "light" or a name added to LeftMenu.styles
58
+ style: {}, // WHY: the look is in the flat params above; the packages are packages of params (LeftMenu.styles)
59
+ };
60
+
61
+ const LeftMenu = function(params = {}) {
62
+
63
+ // Merge style package: your params > LeftMenu.styles[styleName] (a package of params) > LeftMenuDefaults (dark)
64
+ basic.applyStylePackage(params, LeftMenu.styles, LeftMenuDefaults);
65
+
66
+ // Merge params:
67
+ mergeIntoIfMissing(params, LeftMenuDefaults);
68
+
69
+ // BOX: Component container
70
+ let box = startObject(params);
71
+
72
+ // *** PRIVATE VARIABLES:
73
+ let isExpanded = 0; // Menu expansion state
74
+ let selectedItemKey = null; // Currently selected item
75
+ let useTapMode = 0; // 1: The menu opens with a tap (touch device), not with hover.
76
+ const itemList = []; // Array to store menu items
77
+ const itemElements = []; // Array to store item UI elements
78
+ const WIDTH = 40; // Collapsed width (only the icons)
79
+ const ICON_OPACITY = 0.6; // The icon of an item that is not hovered or selected
80
+
81
+ // *** PUBLIC VARIABLES:
82
+ box.publicVar = 1;
83
+ box.state = "collapsed"; // "collapsed", "expanded"
84
+
85
+ // *** PRIVATE FUNCTIONS:
86
+
87
+ const setText = function (label, text) {
88
+ const value = (text === undefined || text === null) ? "" : String(text);
89
+ if (box.allowHtml == 1) label.text = value;
90
+ else label.plainText = value;
91
+ };
92
+
93
+ // The look of a button item: "normal", "hover" or "selected" (a gradient from the left)
94
+ const paintButtonItem = function(buttonBox, look) {
95
+ if (look === "normal") {
96
+ buttonBox.css.background = "transparent";
97
+ buttonBox.icon.opacity = ICON_OPACITY;
98
+ buttonBox.textLabel.textColor = box.textColor;
99
+ return;
100
+ }
101
+ const backColor = (look === "selected") ? box.selectedColor : box.hoverColor;
102
+ buttonBox.css.background = `linear-gradient(to right, ${backColor} 0%, rgba(0,0,0,0) 100%)`;
103
+ buttonBox.icon.opacity = 1;
104
+ buttonBox.textLabel.textColor = box.selectedTextColor;
105
+ };
106
+
107
+ // Create a menu button item
108
+ const createButtonItem = function(item) {
109
+
110
+ const buttonBox = startBox({
111
+ width: "100%",
112
+ height: box.itemHeight,
113
+ color: "transparent",
114
+ clickable: 1,
115
+ position: "relative",
116
+ });
117
+ buttonBox.setMotion("background-color 0.2s");
118
+ buttonBox.cursor = "pointer";
119
+ buttonBox.data = item;
120
+
121
+ HGroup({
122
+ align: "left center",
123
+ gap: 20,
124
+ padding: [8, 0],
125
+ });
126
+
127
+ // Icon
128
+ buttonBox.icon = Icon({
129
+ width: 24,
130
+ height: 24,
131
+ color: "transparent",
132
+ opacity: ICON_OPACITY,
133
+ });
134
+ buttonBox.icon.load(item.iconFile);
135
+
136
+ if (box.invertIconColor == 1) {
137
+ that.css.filter = "invert(100%)";
138
+ }
139
+
140
+ // Text label (hidden when collapsed)
141
+ buttonBox.textLabel = Label({
142
+ textColor: box.textColor,
143
+ fontSize: 18,
144
+ color: "transparent",
145
+ });
146
+ setText(buttonBox.textLabel, item.text);
147
+
148
+ endGroup();
149
+
150
+ endBox();
151
+
152
+ // Click handler
153
+ buttonBox.on("click", function(self, event) {
154
+
155
+ // WHY: The menu box also listens for the tap (to open itself). Without this, closing after a selection would open it again.
156
+ if (event) event.stopPropagation();
157
+
158
+ // WHY: Touch device, closed menu: only the icons are visible. The first tap opens the menu, it does not select.
159
+ if (useTapMode && !isExpanded && box.openOnClick !== "direct") {
160
+ expandMenu();
161
+ return;
162
+ }
163
+
164
+ if (selectedItemKey != item.key) {
165
+ if (!item.dontSelect) {
166
+ selectItem(item.key);
167
+ }
168
+ box.onItemClick(box, item);
169
+ }
170
+
171
+ // Touch device: the open menu must not stay over the page.
172
+ if (useTapMode) collapseMenu();
173
+
174
+ });
175
+
176
+ // Hover effects
177
+ buttonBox.on("mouseover", function() {
178
+ if (useTapMode) return; // WHY: A touch also fires mouseover; the color would stay on the item.
179
+ if (selectedItemKey != item.key) paintButtonItem(buttonBox, "hover");
180
+ });
181
+
182
+ buttonBox.on("mouseout", function() {
183
+ if (useTapMode) return;
184
+ if (selectedItemKey != item.key) paintButtonItem(buttonBox, "normal");
185
+ });
186
+
187
+ return buttonBox;
188
+ };
189
+
190
+ // Create a header item
191
+ const createHeaderItem = function(item) {
192
+
193
+ const headerBox = startBox({
194
+ width: "100%",
195
+ height: 29,
196
+ color: "transparent",
197
+ clickable: 1,
198
+ position: "relative",
199
+ });
200
+ headerBox.data = item;
201
+
202
+ // BOX: Line
203
+ Box(0, 0, 100, 1, {
204
+ color: box.titleColor,
205
+ });
206
+ that.top = 14;
207
+ that.opacity = 0.50;
208
+
209
+ AutoLayout({
210
+ align: "left center",
211
+ padding: [40, 0],
212
+ });
213
+
214
+ // Header text
215
+ const headerText = Label({
216
+ textColor: box.titleColor,
217
+ fontSize: 12,
218
+ color: box.backgroundColor,
219
+ padding: [12, 0],
220
+ });
221
+ setText(headerText, item.text);
222
+ headerText.css = { fontWeight: "bold", textTransform: "uppercase" };
223
+
224
+ endAutoLayout();
225
+
226
+ endBox();
227
+
228
+ return headerBox;
229
+
230
+ };
231
+
232
+ box.clearSelection = function() {
233
+
234
+ // The item selected before is not selected any more
235
+ if (selectedItemKey) {
236
+ const prev = itemElements.find(el => el.data.key === selectedItemKey);
237
+ if (prev && prev.data.type === "button") {
238
+ paintButtonItem(prev, "normal");
239
+ prev.cursor = "pointer";
240
+ }
241
+
242
+ selectedItemKey = null;
243
+ }
244
+
245
+ }
246
+
247
+ // Select an item (its look)
248
+ const selectItem = function(itemKey) {
249
+
250
+ // The item selected before is not selected any more
251
+ box.clearSelection();
252
+
253
+ // Select the new item
254
+ const current = itemElements.find(el => el.data.key === itemKey);
255
+ if (current && current.data.type === "button") {
256
+ paintButtonItem(current, "selected");
257
+ current.cursor = "default";
258
+
259
+ selectedItemKey = itemKey;
260
+ }
261
+
262
+ };
263
+
264
+ // Expand menu
265
+ const expandMenu = function() {
266
+ if (isExpanded) return;
267
+
268
+ isExpanded = 1;
269
+ box.state = "expanded";
270
+ box.width = box.expandedWidth;
271
+ paintShadow();
272
+
273
+ box.onMenuToggle(box, 1);
274
+ };
275
+
276
+ // Collapse menu
277
+ const collapseMenu = function() {
278
+ if (!isExpanded) return;
279
+
280
+ isExpanded = 0;
281
+ box.state = "collapsed";
282
+ box.width = WIDTH;
283
+ paintShadow();
284
+
285
+ box.onMenuToggle(box, 0);
286
+ };
287
+
288
+ // The shadow of the open menu over the page (expandedShadow)
289
+ const paintShadow = function() {
290
+ box.boxShadow = (isExpanded && box.expandedShadow) ? box.expandedShadow : "";
291
+ };
292
+
293
+ // Is this a touch device? (No mouse hover.)
294
+ const isTouchDevice = function() {
295
+ // WHY: "hover: none" is the real question (a tablet, a phone). basic.isMobile() is the fallback for old browsers.
296
+ if (window.matchMedia && window.matchMedia("(hover: none)").matches) return 1;
297
+ if (window.matchMedia && window.matchMedia("(pointer: coarse)").matches) return 1;
298
+ return basic.isMobile();
299
+ };
300
+
301
+ // Tap outside the menu: close it. (Only in tap mode)
302
+ const onDocumentPointerDown = function(self, event) {
303
+ if (!box || !useTapMode || !isExpanded) return;
304
+ if (box.elem.contains(event.target)) return;
305
+ collapseMenu();
306
+ };
307
+
308
+ // *** PUBLIC FUNCTIONS:
309
+
310
+ // "auto": Tap on a touch device, hover with a mouse. 1: Always tap, 0: Always hover.
311
+ box.setOpenOnClick = function(openOnClick) {
312
+ box.openOnClick = openOnClick;
313
+ if (openOnClick === "auto") {
314
+ useTapMode = isTouchDevice();
315
+ } else if (openOnClick === "direct") {
316
+ useTapMode = 1;
317
+ } else {
318
+ useTapMode = basic.isOn(openOnClick) ? 1 : 0;
319
+ }
320
+ if (!useTapMode) collapseMenu(); // WHY: Hover mode starts closed; the mouse decides.
321
+ return useTapMode;
322
+ };
323
+ // USAGE: leftMenu.setOpenOnClick(1) // Returns 1 if the menu opens with a tap.
324
+
325
+ box.isTapMode = function() {
326
+ return useTapMode;
327
+ };
328
+
329
+ // WHY: box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
330
+ const superRemove = box.remove;
331
+ box.superRemove = superRemove;
332
+ box.remove = function () {
333
+
334
+ if (!box) return; // WHY: remove() can be called twice (also by the parent's remove()).
335
+ // WHY: page.onResize() is not cleaned by box.remove(). (box.onPageResize() is a window resize: not the same time.)
336
+ page.remove_onResize(resizeScrollableBox);
337
+
338
+ superRemove.call(box); // NOTE: basic.js remove(). It cleans all the events and the objects inside.
339
+ box = null;
340
+
341
+ };
342
+
343
+ // Add item to top of menu
344
+ box.addItemToTop = function(item) {
345
+
346
+ itemList.push(item);
347
+ const element = item.type === "button" ? createButtonItem(item) : createHeaderItem(item);
348
+ itemElements.push(element);
349
+
350
+ // Add to UI at top using topBox
351
+ box.topBox.add(element);
352
+
353
+ return element;
354
+ };
355
+
356
+ // Add item to bottom of menu
357
+ box.addItemToBottom = function(item) {
358
+
359
+ itemList.push(item);
360
+ const element = item.type === "button" ? createButtonItem(item) : createHeaderItem(item);
361
+ itemElements.push(element);
362
+
363
+ // Added at the bottom of the menu
364
+ box.bottomBox.add(element);
365
+
366
+ return element;
367
+
368
+ };
369
+
370
+ // Remove item by key
371
+ box.removeItem = function(itemKey) {
372
+
373
+ if (itemKey === selectedItemKey) box.clearSelection(); // The selected item is removed: the selection is cleared first.
374
+
375
+ const index = itemList.findIndex(item => item.key === itemKey);
376
+ if (index !== -1) {
377
+ const element = itemElements[index];
378
+ element.remove();
379
+ itemList.splice(index, 1);
380
+ itemElements.splice(index, 1);
381
+ }
382
+
383
+ };
384
+
385
+ // Get selected item
386
+ box.getSelectedItem = function() {
387
+ return itemList.find(item => item.key === selectedItemKey);
388
+ };
389
+
390
+ // Set selected item
391
+ box.setSelectedItem = function(itemKey) {
392
+ selectItem(itemKey);
393
+ };
394
+
395
+ // Expand menu programmatically
396
+ box.expand = function() {
397
+ expandMenu();
398
+ };
399
+
400
+ // Collapse menu programmatically
401
+ box.collapse = function() {
402
+ collapseMenu();
403
+ };
404
+
405
+ // Toggle menu state
406
+ box.toggle = function() {
407
+ if (isExpanded) {
408
+ collapseMenu();
409
+ } else {
410
+ expandMenu();
411
+ }
412
+ };
413
+
414
+ // *** OBJECT VIEW:
415
+ box.cursor = "default";
416
+ box.color = box.backgroundColor;
417
+ box.height = `calc(100% - ${box.topBarHeight}px)`;
418
+ box.width = WIDTH;
419
+ box.bottom = 0;
420
+ box.left = 0;
421
+ box.round = 0;
422
+
423
+ const SPACE_BETWEEN = 30;
424
+
425
+ box.scrollableBox = startBox(0, SPACE_BETWEEN, box.expandedWidth, 0);
426
+ that.color = "transparent";
427
+ that.scrollY = 1;
428
+
429
+ box.topBox = VGroup({
430
+ align: "top left",
431
+ gap: 0,
432
+ padding: 0,
433
+ height: "auto",
434
+ width: "100%",
435
+ });
436
+ that.position = "relative";
437
+
438
+ // Add initial items
439
+ box.items.forEach(item => {
440
+ box.addItemToTop(item);
441
+ });
442
+
443
+ endGroup();
444
+
445
+ endBox();
446
+
447
+ // SCROLL BAR:
448
+ box.scrollBar = ScrollBar({
449
+ scrollableBox: box.scrollableBox,
450
+ bar_border: 0,
451
+ bar_round: 3,
452
+ bar_borderColor: "rgba(0, 0, 0, 1)",
453
+ bar_width: 4,
454
+ bar_mouseOverWidth: 4,
455
+ bar_mouseOverColor: box.scrollBarColor,
456
+ bar_opacity: 0.4,
457
+ bar_mouseOverOpacity: 0.9,
458
+ bar_padding: 2,
459
+ bar_color: box.scrollBarColor,
460
+ neverHide: 0,
461
+ showDots: 1,
462
+ });
463
+
464
+ const resizeScrollableBox = function() {
465
+ box.scrollableBox.height = box.height - (SPACE_BETWEEN * 2) - box.bottomBox.height - SPACE_BETWEEN;
466
+ };
467
+
468
+ // Menu container
469
+ box.bottomBox = VGroup({
470
+ align: "bottom left",
471
+ gap: 0,
472
+ padding: 0,
473
+ height: "auto",
474
+ width: box.expandedWidth,
475
+ });
476
+ that.bottom = SPACE_BETWEEN;
477
+ that.left = 0;
478
+ that.color = "transparent";
479
+ box.bottomBox.onResize(function(self) {
480
+ resizeScrollableBox();
481
+ });
482
+
483
+ page.onResize(resizeScrollableBox);
484
+
485
+ endGroup();
486
+
487
+ // BOX: The line at the right side (lineColor)
488
+ // WHY a box made last (not a border of the menu): the colors of the selected item covered a line under them, and a
489
+ // border takes a px of the 40 px of the icons
490
+ if (box.lineColor) {
491
+ box.line = Box({ right: 0, top: 0, width: 1, height: "100%", color: box.lineColor });
492
+ }
493
+
494
+ // *** OBJECT INIT CODE:
495
+
496
+ box.setOpenOnClick(box.openOnClick);
497
+
498
+ // Hover events for expansion (mouse)
499
+ box.on("mouseenter", function() {
500
+ if (useTapMode) return;
501
+ expandMenu();
502
+ });
503
+
504
+ box.on("mouseleave", function() {
505
+ if (useTapMode) return;
506
+ collapseMenu();
507
+ });
508
+
509
+ // Tap on the menu (also on an empty place of it): open it. (Touch device)
510
+ box.on("click", function() {
511
+ if (useTapMode && !isExpanded && box.openOnClick !== "direct") expandMenu();
512
+ });
513
+
514
+ // WHY: Capture, so it also works when the tap is stopped by another object. (Ex: a page that closes its own menu)
515
+ box.listenTo(document, "pointerdown", onDocumentPointerDown, true); // NOTE: Removed by remove().
516
+
517
+ return endObject(box);
518
+
519
+ };
520
+
521
+ // *** STYLE PACKAGES:
522
+ // USAGE: LeftMenu({ styleName: "light" })
523
+ // USAGE: LeftMenu({ styleName: "light", selectedColor: "#DCEBEC" }) // A param you give wins over the package.
524
+ // NOTE: Every package has "style: {}": the mark of a package of params (basic.js v26.10.27). A package needs only
525
+ // the params that differ from LeftMenuDefaults (dark).
526
+ LeftMenu.styles = {
527
+
528
+ // The look of LeftMenuDefaults: a dark menu with a red selection.
529
+ dark: { style: {} },
530
+
531
+ // For a light page: a light menu with a line at its right side and a soft shadow while it is
532
+ // open over the page; the cyan of SmartButton (#5BBAC1) in light tones;
533
+ // dark icons and a dark scroll bar.
534
+ light: {
535
+ style: {},
536
+ backgroundColor: "#F7F7F5",
537
+ hoverColor: Black(0.05),
538
+ selectedColor: "#D1ECEE", // (#5BBAC1, 28 % on white)
539
+ titleColor: "#3D8F96", // (a darker #5BBAC1: it reads on the light menu)
540
+ textColor: Black(0.6),
541
+ selectedTextColor: Black(0.88),
542
+ invertIconColor: 0,
543
+ lineColor: Black(0.08),
544
+ expandedShadow: "6px 0 18px " + Black(0.08),
545
+ scrollBarColor: "#373836",
546
+ },
547
+
548
+ };