x4js 1.6.4 → 2.0.1

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 (282) hide show
  1. package/README.md +3 -14
  2. package/lib/README.txt +3 -14
  3. package/lib/src/assets/house-light.svg +1 -0
  4. package/lib/src/assets/radio.svg +4 -0
  5. package/lib/src/components/base.scss +26 -0
  6. package/lib/src/components/boxes/boxes.module.scss +37 -0
  7. package/lib/src/components/boxes/boxes.ts +125 -0
  8. package/lib/src/components/btngroup/btngroup.module.scss +29 -0
  9. package/lib/src/components/btngroup/btngroup.ts +106 -0
  10. package/lib/src/components/button/button.module.scss +154 -0
  11. package/lib/src/components/button/button.ts +117 -0
  12. package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  13. package/lib/src/components/calendar/calendar.module.scss +163 -0
  14. package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
  15. package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  16. package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  17. package/lib/src/components/checkbox/check.svg +4 -0
  18. package/lib/src/components/checkbox/checkbox.module.scss +142 -0
  19. package/lib/src/components/checkbox/checkbox.ts +125 -0
  20. package/lib/src/components/colorinput/colorinput.module.scss +65 -0
  21. package/lib/src/components/colorinput/colorinput.ts +88 -0
  22. package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  23. package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
  24. package/lib/src/components/colorpicker/colorpicker.ts +477 -0
  25. package/lib/src/components/combobox/combobox.module.scss +121 -0
  26. package/lib/src/components/combobox/combobox.ts +190 -0
  27. package/lib/src/components/combobox/updown.svg +4 -0
  28. package/lib/src/components/dialog/dialog.module.scss +71 -0
  29. package/lib/src/components/dialog/dialog.ts +91 -0
  30. package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
  31. package/lib/src/components/form/form.module.scss +34 -0
  32. package/lib/src/components/form/form.ts +36 -0
  33. package/lib/src/components/header/header.module.scss +40 -0
  34. package/lib/src/components/header/header.ts +124 -0
  35. package/lib/src/components/icon/icon.module.scss +30 -0
  36. package/lib/src/components/icon/icon.ts +134 -0
  37. package/lib/src/components/image/image.module.scss +21 -0
  38. package/lib/src/components/image/image.ts +67 -0
  39. package/lib/src/components/input/input.module.scss +69 -0
  40. package/lib/src/components/input/input.ts +274 -0
  41. package/lib/src/components/label/label.module.scss +52 -0
  42. package/lib/src/components/label/label.ts +55 -0
  43. package/lib/src/components/listbox/listbox.module.scss +103 -0
  44. package/lib/src/components/listbox/listbox.ts +427 -0
  45. package/lib/src/components/menu/caret-right-solid.svg +1 -0
  46. package/lib/src/components/menu/menu.module.scss +108 -0
  47. package/lib/src/components/menu/menu.ts +168 -0
  48. package/lib/src/components/messages/circle-exclamation.svg +1 -0
  49. package/lib/src/components/messages/messages.module.scss +47 -0
  50. package/lib/src/components/messages/messages.ts +64 -0
  51. package/lib/src/components/normalize.scss +386 -0
  52. package/lib/src/components/notification/circle-check-solid.svg +1 -0
  53. package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
  54. package/lib/src/components/notification/circle-notch-light.svg +1 -0
  55. package/lib/src/components/notification/notification.module.scss +82 -0
  56. package/lib/src/components/notification/notification.ts +108 -0
  57. package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
  58. package/lib/src/components/panel/panel.module.scss +48 -0
  59. package/lib/src/components/panel/panel.ts +57 -0
  60. package/lib/src/components/popup/popup.module.scss +43 -0
  61. package/lib/src/components/popup/popup.ts +395 -0
  62. package/lib/src/components/progress/progress.module.scss +57 -0
  63. package/lib/src/components/progress/progress.ts +43 -0
  64. package/lib/src/components/rating/rating.module.scss +23 -0
  65. package/lib/src/components/rating/rating.ts +125 -0
  66. package/lib/src/components/rating/star-sharp-light.svg +1 -0
  67. package/lib/src/components/rating/star-sharp-solid.svg +1 -0
  68. package/lib/src/components/shared.scss +76 -0
  69. package/lib/src/components/sizers/sizer.module.scss +90 -0
  70. package/lib/src/components/sizers/sizer.ts +120 -0
  71. package/lib/src/components/slider/slider.module.scss +71 -0
  72. package/lib/src/components/slider/slider.ts +143 -0
  73. package/lib/src/components/switch/switch.module.scss +127 -0
  74. package/lib/src/components/switch/switch.ts +56 -0
  75. package/lib/src/components/tabs/tabs.module.scss +46 -0
  76. package/lib/src/components/tabs/tabs.ts +157 -0
  77. package/lib/src/components/textarea/textarea.module.scss +59 -0
  78. package/lib/src/components/textarea/textarea.ts +54 -0
  79. package/lib/src/components/textedit/textedit.module.scss +114 -0
  80. package/lib/src/components/textedit/textedit.ts +82 -0
  81. package/lib/src/components/themes.scss +77 -0
  82. package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  83. package/lib/src/components/tooltips/tooltips.scss +51 -0
  84. package/lib/src/components/tooltips/tooltips.ts +103 -0
  85. package/lib/src/components/treeview/chevron-down-light.svg +1 -0
  86. package/lib/src/components/treeview/treeview.module.scss +116 -0
  87. package/lib/src/components/treeview/treeview.ts +403 -0
  88. package/lib/src/components/viewport/viewport.module.scss +25 -0
  89. package/lib/src/components/viewport/viewport.ts +38 -0
  90. package/lib/src/core/component.ts +979 -0
  91. package/lib/src/core/core_colors.ts +250 -0
  92. package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
  93. package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
  94. package/lib/src/core/core_element.ts +98 -0
  95. package/lib/src/core/core_events.ts +149 -0
  96. package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
  97. package/lib/src/{router.ts → core/core_router.ts} +27 -40
  98. package/lib/src/core/core_styles.ts +215 -0
  99. package/lib/src/core/core_svg.ts +550 -0
  100. package/lib/src/core/core_tools.ts +673 -0
  101. package/lib/src/main.scss +21 -0
  102. package/lib/src/main.tsx +323 -0
  103. package/lib/src/x4.scss +19 -0
  104. package/lib/types/x4.d.ts +2624 -0
  105. package/package.json +67 -59
  106. package/scripts/build.mjs +351 -0
  107. package/scripts/prepack.mjs +15 -0
  108. package/src/assets/house-light.svg +1 -0
  109. package/src/assets/radio.svg +4 -0
  110. package/src/components/base.scss +26 -0
  111. package/src/components/boxes/boxes.module.scss +37 -0
  112. package/src/components/boxes/boxes.ts +125 -0
  113. package/src/components/btngroup/btngroup.module.scss +29 -0
  114. package/src/components/btngroup/btngroup.ts +106 -0
  115. package/src/components/button/button.module.scss +154 -0
  116. package/src/components/button/button.ts +117 -0
  117. package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
  118. package/src/components/calendar/calendar.module.scss +163 -0
  119. package/src/components/calendar/calendar.ts +326 -0
  120. package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
  121. package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
  122. package/src/components/checkbox/check.svg +4 -0
  123. package/src/components/checkbox/checkbox.module.scss +142 -0
  124. package/src/components/checkbox/checkbox.ts +125 -0
  125. package/src/components/colorinput/colorinput.module.scss +65 -0
  126. package/src/components/colorinput/colorinput.ts +88 -0
  127. package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
  128. package/src/components/colorpicker/colorpicker.module.scss +133 -0
  129. package/src/components/colorpicker/colorpicker.ts +477 -0
  130. package/src/components/combobox/combobox.module.scss +121 -0
  131. package/src/components/combobox/combobox.ts +190 -0
  132. package/src/components/combobox/updown.svg +4 -0
  133. package/src/components/dialog/dialog.module.scss +71 -0
  134. package/src/components/dialog/dialog.ts +91 -0
  135. package/src/components/dialog/xmark-sharp-light.svg +1 -0
  136. package/src/components/form/form.module.scss +34 -0
  137. package/src/components/form/form.ts +36 -0
  138. package/src/components/header/header.module.scss +40 -0
  139. package/src/components/header/header.ts +124 -0
  140. package/src/components/icon/icon.module.scss +30 -0
  141. package/src/components/icon/icon.ts +134 -0
  142. package/src/components/image/image.module.scss +21 -0
  143. package/src/components/image/image.ts +67 -0
  144. package/src/components/input/input.module.scss +69 -0
  145. package/src/components/input/input.ts +274 -0
  146. package/src/components/label/label.module.scss +52 -0
  147. package/src/components/label/label.ts +55 -0
  148. package/src/components/listbox/listbox.module.scss +103 -0
  149. package/src/components/listbox/listbox.ts +427 -0
  150. package/src/components/menu/caret-right-solid.svg +1 -0
  151. package/src/components/menu/menu.module.scss +108 -0
  152. package/src/components/menu/menu.ts +168 -0
  153. package/src/components/messages/circle-exclamation.svg +1 -0
  154. package/src/components/messages/messages.module.scss +47 -0
  155. package/src/components/messages/messages.ts +64 -0
  156. package/src/components/normalize.scss +386 -0
  157. package/src/components/notification/circle-check-solid.svg +1 -0
  158. package/src/components/notification/circle-exclamation-solid.svg +1 -0
  159. package/src/components/notification/circle-notch-light.svg +1 -0
  160. package/src/components/notification/notification.module.scss +82 -0
  161. package/src/components/notification/notification.ts +108 -0
  162. package/src/components/notification/xmark-sharp-light.svg +1 -0
  163. package/src/components/panel/panel.module.scss +48 -0
  164. package/src/components/panel/panel.ts +57 -0
  165. package/src/components/popup/popup.module.scss +43 -0
  166. package/src/components/popup/popup.ts +395 -0
  167. package/src/components/progress/progress.module.scss +57 -0
  168. package/src/components/progress/progress.ts +43 -0
  169. package/src/components/rating/rating.module.scss +23 -0
  170. package/src/components/rating/rating.ts +125 -0
  171. package/src/components/rating/star-sharp-light.svg +1 -0
  172. package/src/components/rating/star-sharp-solid.svg +1 -0
  173. package/src/components/shared.scss +76 -0
  174. package/src/components/sizers/sizer.module.scss +90 -0
  175. package/src/components/sizers/sizer.ts +120 -0
  176. package/src/components/slider/slider.module.scss +71 -0
  177. package/src/components/slider/slider.ts +143 -0
  178. package/src/components/switch/switch.module.scss +127 -0
  179. package/src/components/switch/switch.ts +56 -0
  180. package/src/components/tabs/tabs.module.scss +46 -0
  181. package/src/components/tabs/tabs.ts +157 -0
  182. package/src/components/textarea/textarea.module.scss +59 -0
  183. package/src/components/textarea/textarea.ts +54 -0
  184. package/src/components/textedit/textedit.module.scss +114 -0
  185. package/src/components/textedit/textedit.ts +82 -0
  186. package/src/components/themes.scss +77 -0
  187. package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
  188. package/src/components/tooltips/tooltips.scss +51 -0
  189. package/src/components/tooltips/tooltips.ts +103 -0
  190. package/src/components/treeview/chevron-down-light.svg +1 -0
  191. package/src/components/treeview/treeview.module.scss +116 -0
  192. package/src/components/treeview/treeview.ts +403 -0
  193. package/src/components/viewport/viewport.module.scss +25 -0
  194. package/src/components/viewport/viewport.ts +38 -0
  195. package/src/core/component.ts +979 -0
  196. package/src/core/core_colors.ts +250 -0
  197. package/src/core/core_dom.ts +471 -0
  198. package/src/core/core_dragdrop.ts +201 -0
  199. package/src/core/core_element.ts +98 -0
  200. package/src/core/core_events.ts +149 -0
  201. package/src/core/core_i18n.ts +377 -0
  202. package/src/core/core_router.ts +221 -0
  203. package/src/core/core_styles.ts +215 -0
  204. package/src/core/core_svg.ts +550 -0
  205. package/src/core/core_tools.ts +673 -0
  206. package/src/main.scss +21 -0
  207. package/src/main.tsx +323 -0
  208. package/src/x4.scss +19 -0
  209. package/tsconfig.json +14 -0
  210. package/types/scss.d.ts +4 -0
  211. package/types/svg.d.ts +4 -0
  212. package/types/x4react.d.ts +9 -0
  213. package/lib/changelog.txt +0 -23
  214. package/lib/cjs/x4js.js +0 -39
  215. package/lib/cjs/x4js.js.map +0 -7
  216. package/lib/esm/x4js.mjs +0 -15972
  217. package/lib/esm/x4js.mjs.map +0 -7
  218. package/lib/licence.md +0 -21
  219. package/lib/src/MIT-license.md +0 -14
  220. package/lib/src/action.ts +0 -88
  221. package/lib/src/alpha.jpg +0 -0
  222. package/lib/src/app_sockets.ts +0 -81
  223. package/lib/src/application.ts +0 -262
  224. package/lib/src/autocomplete.ts +0 -232
  225. package/lib/src/base64.ts +0 -166
  226. package/lib/src/base_component.ts +0 -152
  227. package/lib/src/button.ts +0 -355
  228. package/lib/src/canvas.ts +0 -510
  229. package/lib/src/cardview.ts +0 -228
  230. package/lib/src/checkbox.ts +0 -188
  231. package/lib/src/color.ts +0 -752
  232. package/lib/src/colorpicker.ts +0 -1649
  233. package/lib/src/combobox.ts +0 -512
  234. package/lib/src/component.ts +0 -2367
  235. package/lib/src/copyright.txt +0 -27
  236. package/lib/src/datastore.ts +0 -1302
  237. package/lib/src/dialog.ts +0 -656
  238. package/lib/src/drawtext.ts +0 -355
  239. package/lib/src/fileupload.ts +0 -213
  240. package/lib/src/form.ts +0 -413
  241. package/lib/src/formatters.ts +0 -105
  242. package/lib/src/gridview.ts +0 -1185
  243. package/lib/src/icon.ts +0 -362
  244. package/lib/src/image.ts +0 -225
  245. package/lib/src/index.ts +0 -89
  246. package/lib/src/input.ts +0 -297
  247. package/lib/src/label.ts +0 -153
  248. package/lib/src/layout.ts +0 -442
  249. package/lib/src/link.ts +0 -86
  250. package/lib/src/listview.ts +0 -765
  251. package/lib/src/md5.ts +0 -438
  252. package/lib/src/menu.ts +0 -425
  253. package/lib/src/messagebox.ts +0 -224
  254. package/lib/src/panel.ts +0 -86
  255. package/lib/src/popup.ts +0 -494
  256. package/lib/src/property_editor.ts +0 -337
  257. package/lib/src/radiobtn.ts +0 -197
  258. package/lib/src/rating.ts +0 -135
  259. package/lib/src/request.ts +0 -300
  260. package/lib/src/settings.ts +0 -77
  261. package/lib/src/sidebarview.ts +0 -108
  262. package/lib/src/spreadsheet.ts +0 -1449
  263. package/lib/src/styles.ts +0 -343
  264. package/lib/src/svgcomponent.ts +0 -592
  265. package/lib/src/tabbar.ts +0 -151
  266. package/lib/src/tabview.ts +0 -110
  267. package/lib/src/textarea.ts +0 -235
  268. package/lib/src/textedit.ts +0 -533
  269. package/lib/src/toaster.ts +0 -80
  270. package/lib/src/tools.ts +0 -1473
  271. package/lib/src/tooltips.ts +0 -191
  272. package/lib/src/treeview.ts +0 -716
  273. package/lib/src/version.ts +0 -30
  274. package/lib/src/x4.less +0 -2242
  275. package/lib/src/x4dom.ts +0 -57
  276. package/lib/src/x4events.ts +0 -585
  277. package/lib/src/x4js.ts +0 -89
  278. package/lib/src/x4react.ts +0 -90
  279. package/lib/styles/x4.css +0 -1785
  280. package/lib/styles/x4.less +0 -2242
  281. package/lib/types/x4js.d.ts +0 -6728
  282. package/license.md +0 -21
@@ -1,765 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \_/ / / _
4
- * \ / /_| |_
5
- * / _ \____ _|
6
- * /__/ \__\ |_|
7
- *
8
- * @file listview.ts
9
- * @author Etienne Cochard
10
- *
11
- * Copyright (c) 2019-2023 R-libre ingenierie
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
- * of the Software, and to permit persons to whom the Software is furnished to do so,
18
- * subject to the following conditions:
19
- * The above copyright notice and this permission notice shall be included in all copies
20
- * or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- **/
29
-
30
- import { x4document } from './x4dom'
31
-
32
- import { Container, Component, ContainerProps, ContainerEventMap, EvDblClick } from './component'
33
- import { IconID } from './icon';
34
- import { HLayout, VLayout } from './layout'
35
- import { Popup, PopupEventMap, PopupProps } from './popup';
36
- import { HtmlString, isFunction } from './tools';
37
- import { Menu, MenuItem } from "./menu";
38
-
39
- import { EvContextMenu, EvSelectionChange, EvClick, EventCallback, BasicEvent, EvChange } from "./x4events";
40
-
41
- /**
42
- * item definition
43
- */
44
-
45
- export interface ListViewItem {
46
- id: any;
47
- text?: string | HtmlString; // if you need pure text
48
- html?: boolean; // if text is html
49
- icon?: IconID;
50
- data?: any;
51
- };
52
-
53
- /**
54
- * callback to render item
55
- */
56
-
57
- export interface RenderListItem {
58
- (item: ListViewItem): any;
59
- }
60
-
61
- /**
62
- * callback to fill the list
63
- */
64
- export interface PopulateItems {
65
- ( filter: string ): ListViewItem[];
66
- }
67
-
68
- /**
69
- * listview can generate these events
70
- */
71
-
72
- export interface ListViewEventMap extends ContainerEventMap {
73
- click?: EvClick;
74
- dblClick?: EvDblClick;
75
- contextMenu?: EvContextMenu;
76
- selectionChange?: EvSelectionChange;
77
- cancel?: EvCancel;
78
- }
79
-
80
-
81
- /**
82
- * listview properties
83
- */
84
- export interface ListViewProps<E extends ListViewEventMap = ListViewEventMap> extends ContainerProps<E> {
85
- items?: ListViewItem[];
86
- populate?: PopulateItems;
87
- gadgets?: Component[]; // gadgets to instert at bottom
88
-
89
- virtual?: boolean; // if true, items will be rendered on demand
90
- itemHeight?: number; // in case of a virtual list, item height
91
-
92
- renderItem?: RenderListItem;
93
-
94
- click?: EventCallback<EvClick>; // shortcut to events: { click: ... }
95
- dblClick?: EventCallback<EvDblClick>;// shortcut to events: { dblClick: ... }
96
- contextMenu?: EventCallback<EvContextMenu>;// shortcut to events: { contentMenu: ... }
97
- selectionChange?: EventCallback<EvSelectionChange>;// shortcut to events: { selectionChange: ... }
98
- cancel?: EventCallback<EvCancel>; // shortcut to events: { cancel: ... }
99
- }
100
-
101
- /**
102
- * Standard listview class
103
- */
104
-
105
- export class ListView extends VLayout<ListViewProps,ListViewEventMap> {
106
-
107
- protected m_selection: {
108
- item: ListViewItem;
109
- citem: Component;
110
- }
111
-
112
- protected m_defer_sel: any;
113
-
114
- protected m_container: Container;
115
- protected m_view: Container;
116
-
117
- protected m_topIndex: number;
118
- protected m_itemHeight: number;
119
-
120
- protected m_cache: Map<number, Component>; // recycling elements
121
-
122
- constructor(props: ListViewProps) {
123
- super(props);
124
-
125
- this.setDomEvent('keydown', (e) => this.handleKey(e));
126
- this.setDomEvent('click', (e) => this._handleClick(e));
127
- this.setDomEvent('dblclick', (e) => this._handleClick(e));
128
- this.setDomEvent('contextmenu', (e) => this._handleCtxMenu(e));
129
-
130
- this._setTabIndex(props.tabIndex, 0);
131
- this.mapPropEvents(props, 'click', 'dblClick', 'contextMenu', 'selectionChange', 'cancel' );
132
- }
133
-
134
- componentCreated() {
135
-
136
- if (this.m_props.virtual) {
137
- this._buildItems();
138
- }
139
- else if( this.m_props.populate ) {
140
- this.items = this.m_props.populate( null );
141
- }
142
- }
143
-
144
- render(props: ListViewProps) {
145
-
146
- props.items = props.items || [];
147
- props.gadgets = props.gadgets;
148
- props.renderItem = props.renderItem;
149
- props.virtual = props.virtual ?? false;
150
-
151
- this.m_topIndex = 0;
152
-
153
- if (props.virtual) {
154
- console.assert(props.itemHeight !== undefined);
155
- this.m_itemHeight = props.itemHeight;
156
- this.m_cache = new Map<number, Component>();
157
- this.addClass('virtual');
158
- }
159
- else {
160
- this.m_itemHeight = undefined;
161
- this.m_cache = undefined;
162
- }
163
-
164
- this._buildContent();
165
- }
166
-
167
- /**
168
- * change the list of item displayed
169
- * @param items - new array of items
170
- * @deprecated
171
- */
172
-
173
- public set items(items: ListViewItem[]) {
174
- this.setItems( items );
175
- }
176
-
177
- public get items( ) {
178
- return this.m_props.items;
179
- }
180
-
181
- /**
182
- * change the list of item displayed
183
- * @param items - new array of items
184
- */
185
-
186
- public setItems( items: ListViewItem[], keepSel = true ) {
187
- this.m_props.items = items;
188
-
189
- if( !keepSel ) {
190
- this.m_selection = null;
191
- }
192
-
193
- if( !this.m_container ) {
194
- this._buildContent( );
195
- }
196
- else {
197
- this._buildItems( );
198
- }
199
- }
200
-
201
- public handleKey(ev: KeyboardEvent) {
202
-
203
- let moveSel = (sens) => {
204
-
205
- let items: ListViewItem[];
206
- if (isFunction(this.m_props.items)) {
207
- items = this.m_props.items();
208
- this.m_props.items = items;
209
- }
210
- else {
211
- items = this.m_props.items;
212
- }
213
-
214
- let newsel: ListViewItem;
215
- if (!this.m_selection) {
216
- if (items) {
217
- newsel = items[0];
218
- }
219
- }
220
- else {
221
- let index = items.findIndex((item) => item === this.m_selection.item);
222
- if (sens > 0 && index < (items.length - 1)) {
223
- newsel = items[index + 1];
224
- }
225
- else if (sens < 0 && index > 0) {
226
- newsel = items[index - 1];
227
- }
228
- else {
229
- newsel = this.selection
230
- }
231
- }
232
-
233
- let citem = this._findItemWithId(newsel?.id);
234
- this._selectItem(newsel, citem, true);
235
- }
236
-
237
- switch (ev.key) {
238
- case 'ArrowDown': {
239
- moveSel(1);
240
- ev.preventDefault( );
241
- ev.stopPropagation();
242
- break;
243
- }
244
-
245
- case 'ArrowUp': {
246
- moveSel(-1);
247
- ev.preventDefault( );
248
- ev.stopPropagation();
249
- break;
250
- }
251
- }
252
- }
253
-
254
- /** @ignore */
255
- private _buildContent() {
256
-
257
- let props = this.m_props;
258
-
259
- if (props.virtual) {
260
- this.m_container = new Container({
261
- cls: '@scroll-container',
262
- content: []
263
- });
264
-
265
- this.m_view = new Container({
266
- cls: '@scroll-view',
267
- flex: 1,
268
- content: this.m_container,
269
- dom_events: {
270
- sizechange: () => this._updateScroll(true),
271
- scroll: () => this._updateScroll(false),
272
- }
273
- });
274
-
275
- this.setContent(
276
- [
277
- this.m_view,
278
- props.gadgets ? new HLayout({
279
- cls: 'gadgets',
280
- content: props.gadgets
281
- }) : null,
282
- ]
283
- );
284
- }
285
- else {
286
- this.m_view = undefined;
287
- this.m_container = new VLayout({
288
- cls: '@scroll-container',
289
- content: []
290
- });
291
-
292
- this.addClass('@scroll-view');
293
- this.setContent(this.m_container, false);
294
- }
295
-
296
- if (props.virtual) {
297
- this.m_container.setStyleValue('height', props.items.length * this.m_itemHeight);
298
- }
299
-
300
- if (this.dom || !props.virtual ) {
301
- this._buildItems();
302
- }
303
- }
304
-
305
- /**
306
- *
307
- */
308
-
309
- private _updateScroll(forceUpdate: boolean) {
310
-
311
- const update = () => {
312
- let newTop = Math.floor(this.m_view.dom.scrollTop / this.m_itemHeight);
313
-
314
- if (newTop != this.m_topIndex || forceUpdate) {
315
- this.m_topIndex = newTop;
316
- this._buildItems();
317
- }
318
- }
319
-
320
- if (forceUpdate) {
321
- this.startTimer('scroll', 10, false, update);
322
- }
323
- else {
324
- update();
325
- }
326
- }
327
-
328
- private async _buildItems() {
329
- let props = this.m_props;
330
- let items: Component[] = [];
331
-
332
- let list_items = props.items;
333
- if (isFunction(list_items)) {
334
- list_items = list_items();
335
- }
336
-
337
- let selId = this.m_selection?.item.id;
338
- let selFnd = false;
339
-
340
- if (props.virtual) {
341
- let rc = this.getBoundingRect();
342
- let limit = 100;
343
-
344
- let y = 0;
345
- let top = this.m_topIndex * this.m_itemHeight;
346
- let index = this.m_topIndex;
347
- let height = rc.height;
348
- let count = props.items.length;
349
-
350
- let newels = [];
351
-
352
- let cache = this.m_cache;
353
- this.m_cache = new Map<number, Component>();
354
-
355
- while (y < height && index < count && --limit > 0) {
356
-
357
- let it = props.items[index];
358
- let itm: Component;
359
-
360
- if (cache.has(it.id)) {
361
- itm = cache.get(it.id); // reuse it
362
- cache.delete(it.id); // cache will contain only elements to remove
363
- }
364
- else {
365
- itm = this._renderItem(it);
366
- newels.push(itm);
367
- }
368
-
369
- if (selId == it.id) {
370
- itm.addClass('@selected');
371
- selFnd = true;
372
- }
373
-
374
- itm.setStyleValue('top', top + y);
375
- items.push(itm);
376
-
377
- this.m_cache.set(it.id, itm); // keep it for next time
378
-
379
- y += this.m_itemHeight;
380
- index++;
381
- }
382
-
383
- // all element remaining here are to remove
384
- cache.forEach((c) => {
385
- c.dispose();
386
- });
387
-
388
- // append new elements
389
- this.m_container.appendChild(newels);
390
- this.m_container.setStyleValue( 'height', count*this.m_itemHeight );
391
-
392
- // check that it's still existing
393
- if( !selFnd ) {
394
- if( !list_items.some( it => selId == it.id ) ) {
395
- this.m_selection = null;
396
- }
397
- }
398
-
399
- }
400
- else {
401
- list_items.forEach((it) => {
402
- let itm = this._renderItem(it);
403
- if (selId == it.id) {
404
- itm.addClass('@selected');
405
- selFnd = true;
406
- }
407
-
408
- items.push(itm);
409
- });
410
-
411
- this.m_container.setContent(items, false);
412
-
413
- if( !selFnd ) {
414
- this.m_selection = null;
415
- }
416
- }
417
-
418
- if (this.m_defer_sel) {
419
- let t = this.m_defer_sel;
420
- this.m_defer_sel = undefined;
421
- this.selection = t;
422
- }
423
- }
424
-
425
- /** @ignore
426
- * default rendering of an item
427
- */
428
-
429
- private _renderItem(item: ListViewItem): Component {
430
-
431
- const newItem = this.onRenderItem( item );
432
-
433
- newItem.setAttribute( 'data-id', item.id );
434
- newItem.addClass('@list-item');
435
- newItem.setData('item-id', item.id);
436
-
437
- return newItem;
438
- }
439
-
440
- onRenderItem( item: ListViewItem): Component {
441
- if (this.m_props.renderItem) {
442
- return this.m_props.renderItem(item);
443
- }
444
- else {
445
- return new HLayout({ content: item.text });
446
- }
447
- }
448
-
449
- /** @ignore */
450
- private _handleClick(e: MouseEvent) {
451
-
452
- e.stopImmediatePropagation();
453
- e.preventDefault( );
454
-
455
- let dom = e.target as HTMLElement,
456
- self = this.dom,
457
- list_items = this.m_props.items as ListViewItem[]; // already created by build
458
-
459
- // go up until we find something interesting
460
- while (dom && dom != self) {
461
- let itm = Component.getElement(dom),
462
- id = itm?.getData('item-id');
463
-
464
- if (id!==undefined) {
465
- // find the element
466
- let item = list_items.find((item) => item.id == id);
467
- if (item) {
468
- let event: BasicEvent;
469
- if (e.type == 'click') {
470
- event = EvClick(item);
471
- this.emit('click', event);
472
- }
473
- else {
474
- event = EvDblClick(item);
475
- this.emit('dblClick', event);
476
- }
477
-
478
- if (!event.defaultPrevented) {
479
- this._selectItem(item, itm);
480
- }
481
- }
482
- else {
483
- this._selectItem(null, null);
484
- }
485
-
486
- return;
487
- }
488
-
489
- dom = dom.parentElement;
490
- }
491
-
492
- this._selectItem(null, null);
493
- }
494
-
495
- /** @ignore */
496
- private _handleCtxMenu(e: MouseEvent) {
497
-
498
- e.preventDefault();
499
-
500
- let dom = e.target as HTMLElement,
501
- self = this.dom,
502
- list_items = this.m_props.items as ListViewItem[]; // already created by build;
503
-
504
- while (dom && dom != self) {
505
- let itm = Component.getElement(dom),
506
- id = itm?.getData('item-id');
507
-
508
- if (id) {
509
-
510
- // find the element
511
- let item = list_items.find((item) => item.id == id);
512
- if (item) {
513
- this._selectItem(item, itm);
514
- this.emit('contextMenu', EvContextMenu(e, item));
515
- }
516
-
517
- return;
518
- }
519
-
520
- dom = dom.parentElement;
521
- }
522
-
523
- this.emit('contextMenu', EvContextMenu(e, null));
524
- }
525
-
526
- /**
527
- * @ignore
528
- * called when an item is selected by mouse
529
- */
530
-
531
- protected _selectItem(item: ListViewItem, citem: Component, notify = true) {
532
-
533
- if (this.m_selection && this.m_selection.citem) {
534
- this.m_selection.citem.removeClass('@selected');
535
- }
536
-
537
- this.m_selection = item ? {
538
- item: item,
539
- citem: citem
540
- } : null;
541
-
542
- if (this.m_selection && this.m_selection.citem) {
543
- this.m_selection.citem.addClass('@selected');
544
- }
545
-
546
- if (notify) {
547
- this.emit('selectionChange', EvSelectionChange(item));
548
- }
549
- }
550
-
551
- /**
552
- * return the current selection or null
553
- */
554
-
555
- public get selection() {
556
- return this.m_selection ? this.m_selection.item : null;
557
- }
558
-
559
- public set selection(id: any) {
560
- if (id === null || id === undefined) {
561
- this._selectItem(null, null);
562
- }
563
- else {
564
- if (isFunction(this.m_props.items)) {
565
- this.m_defer_sel = id;
566
- }
567
- else {
568
- let item = this.m_props.items.find((item) => item.id == id);
569
- let citem = this._findItemWithId(item.id);
570
- this._selectItem(item, citem, false);
571
- }
572
- }
573
- }
574
-
575
- private _findItemWithId(id: any) {
576
- let citem: Component = null;
577
-
578
- if (this.dom) {
579
- // make the element visible to user
580
- // todo: problem with virtual listview
581
- this.m_container.enumChilds((c: Component) => {
582
- if (c.getData('item-id') == id) {
583
- c.scrollIntoView();
584
- citem = c;
585
- return true;
586
- }
587
- })
588
- }
589
-
590
- return citem;
591
- }
592
-
593
- /**
594
- * append or prepend a new item
595
- * @param item
596
- * @param prepend
597
- * @param select
598
- */
599
-
600
- appendItem( item: ListViewItem, prepend = false, select = true ) {
601
-
602
- if( prepend ) {
603
- this.m_props.items.unshift( item );
604
- }
605
- else {
606
- this.m_props.items.push( item );
607
- }
608
-
609
- if( select ) {
610
- this.selection = null;
611
- }
612
-
613
- if( !this.m_container ) {
614
- this._buildContent();
615
- }
616
- else {
617
- this._buildItems();
618
- }
619
-
620
- if( select ) {
621
- this.selection = item.id;
622
- }
623
- }
624
-
625
- /**
626
- * update an item
627
- */
628
-
629
- updateItem( id: any, item: ListViewItem ) {
630
-
631
- // find item
632
- const idx = this.m_props.items.findIndex( itm => itm.id === id );
633
- if( idx<0 ) {
634
- return;
635
- }
636
-
637
- // take care of selection
638
- let was_sel = false;
639
- if( this.m_selection && this.m_selection.item===this.m_props.items[idx] ) {
640
- was_sel = true;
641
- }
642
-
643
- // replace it in the list
644
- this.m_props.items[idx] = item;
645
-
646
- // rebuild & replace it's line
647
- const oldDOM = this.queryItem( `[data-id="${item.id}"]` )?.dom;
648
- if( oldDOM ) {
649
- const _new = this._renderItem( item );
650
-
651
- if( was_sel ) {
652
- _new.addClass( '@selected' );
653
- this.m_selection.citem = _new;
654
- this.m_selection.item = item;
655
- }
656
-
657
- const newDOM = _new._build( );
658
- this.m_container.dom.replaceChild( newDOM, oldDOM );
659
- }
660
- }
661
-
662
-
663
- }
664
-
665
-
666
-
667
- /**
668
- * Cancel Event
669
- */
670
-
671
- export interface EvCancel extends BasicEvent {
672
- }
673
-
674
- export function EvCancel( context = null ) {
675
- return BasicEvent<EvCancel>({ context });
676
- }
677
-
678
- interface PopupListViewEventMap extends PopupEventMap {
679
- cancel: EvCancel;
680
- }
681
-
682
- interface PopupListViewProps extends PopupProps<PopupListViewEventMap> {
683
-
684
- }
685
-
686
-
687
- /**
688
- *
689
- */
690
-
691
- export class PopupListView extends Popup<PopupListViewProps,PopupListViewEventMap> {
692
-
693
- m_list: ListView;
694
-
695
- constructor(props: ListViewProps) {
696
- super({ tabIndex: false });
697
-
698
- this.enableMask(false);
699
- this.addClass( "@non-maskable" );
700
-
701
- props.tabIndex = false;
702
- this.m_list = new ListView(props);
703
- //this.m_list.addClass( '@fit' );
704
-
705
- this.setContent(this.m_list);
706
- this.mapPropEvents( props, 'cancel' );
707
- }
708
-
709
- set items( items: ListViewItem[] ) {
710
- this.m_list.items = items;
711
- }
712
-
713
- public handleKey( ev: KeyboardEvent ) {
714
- this.m_list.handleKey( ev );
715
- }
716
-
717
-
718
- // todo: move into popup
719
- private _handleClick = (e: MouseEvent) => {
720
- if (!this.dom) {
721
- return;
722
- }
723
-
724
- let newfocus = <HTMLElement>e.target;
725
-
726
- // child of this: ok
727
- if (this.dom.contains(newfocus)) {
728
- return;
729
- }
730
-
731
- // menu: ok
732
- let dest = Component.getElement(newfocus, MenuItem);
733
- if (dest) {
734
- return;
735
- }
736
-
737
- this.signal( 'cancel', EvCancel() );
738
- this.close();
739
- }
740
-
741
- // todo: move into popup
742
- show(modal?: boolean) {
743
- x4document.addEventListener('mousedown', this._handleClick);
744
- super.show(modal);
745
- }
746
-
747
- hide( ) {
748
- x4document.removeEventListener('mousedown', this._handleClick);
749
- super.hide( );
750
- }
751
-
752
- // todo: move into popup
753
- close() {
754
- x4document.removeEventListener('mousedown', this._handleClick);
755
- super.close();
756
- }
757
-
758
- get selection(): any {
759
- return this.m_list.selection;
760
- }
761
-
762
- set selection(itemId: any) {
763
- this.m_list.selection = itemId;
764
- }
765
- }