x4js 1.4.2
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.
- package/lib/application.d.ts +95 -0
- package/lib/application.js +137 -0
- package/lib/base64.d.ts +31 -0
- package/lib/base64.js +135 -0
- package/lib/base_component.d.ts +64 -0
- package/lib/base_component.js +77 -0
- package/lib/button.d.ts +145 -0
- package/lib/button.js +235 -0
- package/lib/calendar.d.ts +77 -0
- package/lib/calendar.js +236 -0
- package/lib/canvas.d.ts +88 -0
- package/lib/canvas.js +354 -0
- package/lib/cardview.d.ts +83 -0
- package/lib/cardview.js +152 -0
- package/lib/checkbox.d.ts +72 -0
- package/lib/checkbox.js +126 -0
- package/lib/color.d.ts +144 -0
- package/lib/color.js +584 -0
- package/lib/colorpicker.d.ts +98 -0
- package/lib/colorpicker.js +1457 -0
- package/lib/combobox.d.ts +97 -0
- package/lib/combobox.js +246 -0
- package/lib/component.d.ts +572 -0
- package/lib/component.js +1712 -0
- package/lib/datastore.d.ts +392 -0
- package/lib/datastore.js +986 -0
- package/lib/dialog.d.ts +171 -0
- package/lib/dialog.js +468 -0
- package/lib/dom_events.d.ts +284 -0
- package/lib/dom_events.js +13 -0
- package/lib/drag_manager.d.ts +26 -0
- package/lib/drag_manager.js +118 -0
- package/lib/drawtext.d.ts +43 -0
- package/lib/drawtext.js +261 -0
- package/lib/fileupload.d.ts +60 -0
- package/lib/fileupload.js +158 -0
- package/lib/form.d.ts +122 -0
- package/lib/form.js +293 -0
- package/lib/formatters.d.ts +31 -0
- package/lib/formatters.js +75 -0
- package/lib/gridview.d.ts +171 -0
- package/lib/gridview.js +786 -0
- package/lib/hosts/host.d.ts +44 -0
- package/lib/hosts/host.js +69 -0
- package/lib/i18n.d.ts +67 -0
- package/lib/i18n.js +169 -0
- package/lib/icon.d.ts +56 -0
- package/lib/icon.js +173 -0
- package/lib/image.d.ts +51 -0
- package/lib/image.js +149 -0
- package/lib/index.js +1 -0
- package/lib/input.d.ts +86 -0
- package/lib/input.js +172 -0
- package/lib/label.d.ts +54 -0
- package/lib/label.js +86 -0
- package/lib/layout.d.ts +77 -0
- package/lib/layout.js +261 -0
- package/lib/link.d.ts +46 -0
- package/lib/link.js +55 -0
- package/lib/listview.d.ts +173 -0
- package/lib/listview.js +532 -0
- package/lib/md5.d.ts +56 -0
- package/lib/md5.js +397 -0
- package/lib/menu.d.ts +122 -0
- package/lib/menu.js +276 -0
- package/lib/messagebox.d.ts +64 -0
- package/lib/messagebox.js +141 -0
- package/lib/panel.d.ts +42 -0
- package/lib/panel.js +61 -0
- package/lib/popup.d.ts +71 -0
- package/lib/popup.js +373 -0
- package/lib/property_editor.d.ts +67 -0
- package/lib/property_editor.js +247 -0
- package/lib/radiobtn.d.ts +68 -0
- package/lib/radiobtn.js +131 -0
- package/lib/rating.d.ts +49 -0
- package/lib/rating.js +93 -0
- package/lib/request.d.ts +48 -0
- package/lib/request.js +220 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +27 -0
- package/lib/settings.d.ts +33 -0
- package/lib/settings.js +63 -0
- package/lib/sidebarview.d.ts +44 -0
- package/lib/sidebarview.js +73 -0
- package/lib/smartedit.d.ts +103 -0
- package/lib/smartedit.js +381 -0
- package/lib/spreadsheet.d.ts +214 -0
- package/lib/spreadsheet.js +1073 -0
- package/lib/styles.d.ts +81 -0
- package/lib/styles.js +262 -0
- package/lib/svgcomponent.d.ts +165 -0
- package/lib/svgcomponent.js +350 -0
- package/lib/tabbar.d.ts +41 -0
- package/lib/tabbar.js +66 -0
- package/lib/tabview.d.ts +45 -0
- package/lib/tabview.js +79 -0
- package/lib/textarea.d.ts +59 -0
- package/lib/textarea.js +119 -0
- package/lib/textedit.d.ts +118 -0
- package/lib/textedit.js +406 -0
- package/lib/texthiliter.d.ts +56 -0
- package/lib/texthiliter.js +219 -0
- package/lib/toaster.d.ts +38 -0
- package/lib/toaster.js +58 -0
- package/lib/tools.d.ts +382 -0
- package/lib/tools.js +1096 -0
- package/lib/tooltips.d.ts +42 -0
- package/lib/tooltips.js +148 -0
- package/lib/treeview.d.ts +128 -0
- package/lib/treeview.js +490 -0
- package/lib/x4_events.d.ts +253 -0
- package/lib/x4_events.js +363 -0
- package/package.json +21 -0
- package/src/README.md +2 -0
- package/src/application.ts +191 -0
- package/src/base64.ts +162 -0
- package/src/base_component.ts +118 -0
- package/src/button.ts +327 -0
- package/src/calendar.ts +312 -0
- package/src/canvas.ts +501 -0
- package/src/cardview.ts +220 -0
- package/src/checkbox.ts +178 -0
- package/src/color.ts +748 -0
- package/src/colorpicker.ts +1618 -0
- package/src/combobox.ts +348 -0
- package/src/component.ts +2330 -0
- package/src/datastore.ts +1318 -0
- package/src/dialog.ts +631 -0
- package/src/dom_events.ts +297 -0
- package/src/drag_manager.ts +168 -0
- package/src/drawtext.ts +342 -0
- package/src/fileupload.ts +208 -0
- package/src/form.ts +362 -0
- package/src/formatters.ts +96 -0
- package/src/gridview.ts +1051 -0
- package/src/hosts/electron.ts +161 -0
- package/src/hosts/host.ts +100 -0
- package/src/hosts/nwjs.ts +141 -0
- package/src/hosts/nwjs_types.ts +339 -0
- package/src/i18n.ts +205 -0
- package/src/icon.ts +237 -0
- package/src/image.ts +198 -0
- package/src/input.ts +236 -0
- package/src/label.ts +124 -0
- package/src/layout.ts +366 -0
- package/src/link.ts +82 -0
- package/src/listview.ts +749 -0
- package/src/md5.ts +432 -0
- package/src/menu.ts +394 -0
- package/src/messagebox.ts +199 -0
- package/src/panel.ts +81 -0
- package/src/popup.ts +488 -0
- package/src/property_editor.ts +333 -0
- package/src/radiobtn.ts +190 -0
- package/src/rating.ts +131 -0
- package/src/request.ts +296 -0
- package/src/router.ts +43 -0
- package/src/settings.ts +75 -0
- package/src/sidebarview.ts +97 -0
- package/src/smartedit.ts +532 -0
- package/src/spreadsheet.ts +1423 -0
- package/src/styles.ts +332 -0
- package/src/svgcomponent.ts +440 -0
- package/src/tabbar.ts +105 -0
- package/src/tabview.ts +106 -0
- package/src/textarea.ts +183 -0
- package/src/textedit.ts +535 -0
- package/src/texthiliter.ts +284 -0
- package/src/toaster.ts +76 -0
- package/src/tools.ts +1391 -0
- package/src/tooltips.ts +185 -0
- package/src/treeview.ts +670 -0
- package/src/x4.less +1940 -0
- package/src/x4_events.ts +558 -0
- package/tsconfig.json +14 -0
package/lib/listview.js
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file listview.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
import { Container, Component, EvDblClick } from './component';
|
|
26
|
+
import { HLayout, VLayout } from './layout';
|
|
27
|
+
import { Popup } from './popup';
|
|
28
|
+
import { isFunction } from './tools';
|
|
29
|
+
import { MenuItem } from "./menu";
|
|
30
|
+
import { EvContextMenu, EvSelectionChange, EvClick, BasicEvent } from "./x4_events";
|
|
31
|
+
/**
|
|
32
|
+
* item definition
|
|
33
|
+
*/
|
|
34
|
+
export class ListViewItem {
|
|
35
|
+
id;
|
|
36
|
+
text; // if you need pure text
|
|
37
|
+
html; // if text is html
|
|
38
|
+
icon;
|
|
39
|
+
data;
|
|
40
|
+
}
|
|
41
|
+
;
|
|
42
|
+
/**
|
|
43
|
+
* Standard listview class
|
|
44
|
+
*/
|
|
45
|
+
export class ListView extends VLayout {
|
|
46
|
+
m_selection;
|
|
47
|
+
m_defer_sel;
|
|
48
|
+
m_container;
|
|
49
|
+
m_view;
|
|
50
|
+
m_topIndex;
|
|
51
|
+
m_itemHeight;
|
|
52
|
+
m_cache; // recycling elements
|
|
53
|
+
constructor(props) {
|
|
54
|
+
super(props);
|
|
55
|
+
this.setDomEvent('keydown', (e) => this._handleKey(e));
|
|
56
|
+
this.setDomEvent('click', (e) => this._handleClick(e));
|
|
57
|
+
this.setDomEvent('dblclick', (e) => this._handleClick(e));
|
|
58
|
+
this.setDomEvent('contextmenu', (e) => this._handleCtxMenu(e));
|
|
59
|
+
this._setTabIndex(props.tabIndex, 0);
|
|
60
|
+
this.mapPropEvents(props, 'click', 'dblClick', 'contextMenu', 'selectionChange', 'cancel');
|
|
61
|
+
}
|
|
62
|
+
componentCreated() {
|
|
63
|
+
if (this.m_props.virtual) {
|
|
64
|
+
this._buildItems();
|
|
65
|
+
}
|
|
66
|
+
else if (this.m_props.populate) {
|
|
67
|
+
this.items = this.m_props.populate();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
render(props) {
|
|
71
|
+
props.items = props.items || [];
|
|
72
|
+
props.gadgets = props.gadgets;
|
|
73
|
+
props.renderItem = props.renderItem;
|
|
74
|
+
props.virtual = props.virtual ?? false;
|
|
75
|
+
this.m_topIndex = 0;
|
|
76
|
+
if (props.virtual) {
|
|
77
|
+
console.assert(props.itemHeight !== undefined);
|
|
78
|
+
this.m_itemHeight = props.itemHeight;
|
|
79
|
+
this.m_cache = new Map();
|
|
80
|
+
this.addClass('virtual');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.m_itemHeight = undefined;
|
|
84
|
+
this.m_cache = undefined;
|
|
85
|
+
}
|
|
86
|
+
this._buildContent();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* change the list of item displayed
|
|
90
|
+
* @param items - new array of items
|
|
91
|
+
* @deprecated
|
|
92
|
+
*/
|
|
93
|
+
set items(items) {
|
|
94
|
+
this.setItems(items);
|
|
95
|
+
}
|
|
96
|
+
get items() {
|
|
97
|
+
return this.m_props.items;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* change the list of item displayed
|
|
101
|
+
* @param items - new array of items
|
|
102
|
+
*/
|
|
103
|
+
setItems(items, keepSel = true) {
|
|
104
|
+
this.m_props.items = items;
|
|
105
|
+
if (!keepSel) {
|
|
106
|
+
this.m_selection = null;
|
|
107
|
+
}
|
|
108
|
+
if (!this.m_container) {
|
|
109
|
+
this._buildContent();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this._buildItems();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
_handleKey(ev) {
|
|
116
|
+
let moveSel = (sens) => {
|
|
117
|
+
let items;
|
|
118
|
+
if (isFunction(this.m_props.items)) {
|
|
119
|
+
items = this.m_props.items();
|
|
120
|
+
this.m_props.items = items;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
items = this.m_props.items;
|
|
124
|
+
}
|
|
125
|
+
let newsel;
|
|
126
|
+
if (!this.m_selection) {
|
|
127
|
+
if (items) {
|
|
128
|
+
newsel = items[0];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
let index = items.findIndex((item) => item === this.m_selection.item);
|
|
133
|
+
if (sens > 0 && index < (items.length - 1)) {
|
|
134
|
+
newsel = items[index + 1];
|
|
135
|
+
}
|
|
136
|
+
else if (sens < 0 && index > 0) {
|
|
137
|
+
newsel = items[index - 1];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
newsel = this.selection;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
let citem = this._findItemWithId(newsel?.id);
|
|
144
|
+
this._selectItem(newsel, citem, true);
|
|
145
|
+
};
|
|
146
|
+
switch (ev.key) {
|
|
147
|
+
case 'ArrowDown': {
|
|
148
|
+
moveSel(1);
|
|
149
|
+
ev.stopPropagation();
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case 'ArrowUp': {
|
|
153
|
+
moveSel(-1);
|
|
154
|
+
ev.stopPropagation();
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** @ignore */
|
|
160
|
+
_buildContent() {
|
|
161
|
+
let props = this.m_props;
|
|
162
|
+
if (props.virtual) {
|
|
163
|
+
this.m_container = new Container({
|
|
164
|
+
cls: '@scroll-container',
|
|
165
|
+
content: []
|
|
166
|
+
});
|
|
167
|
+
this.m_view = new Container({
|
|
168
|
+
cls: '@scroll-view',
|
|
169
|
+
flex: 1,
|
|
170
|
+
content: this.m_container,
|
|
171
|
+
dom_events: {
|
|
172
|
+
sizechange: () => this._updateScroll(true),
|
|
173
|
+
scroll: () => this._updateScroll(false),
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
this.setContent([
|
|
177
|
+
this.m_view,
|
|
178
|
+
props.gadgets ? new HLayout({
|
|
179
|
+
cls: 'gadgets',
|
|
180
|
+
content: props.gadgets
|
|
181
|
+
}) : null,
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
this.m_view = undefined;
|
|
186
|
+
this.m_container = new VLayout({
|
|
187
|
+
cls: '@scroll-container',
|
|
188
|
+
content: []
|
|
189
|
+
});
|
|
190
|
+
this.addClass('@scroll-view');
|
|
191
|
+
this.setContent(this.m_container, false);
|
|
192
|
+
}
|
|
193
|
+
if (props.virtual) {
|
|
194
|
+
this.m_container.setStyleValue('height', props.items.length * this.m_itemHeight);
|
|
195
|
+
}
|
|
196
|
+
if (this.dom || !props.virtual) {
|
|
197
|
+
this._buildItems();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
*
|
|
202
|
+
*/
|
|
203
|
+
_updateScroll(forceUpdate) {
|
|
204
|
+
const update = () => {
|
|
205
|
+
let newTop = Math.floor(this.m_view.dom.scrollTop / this.m_itemHeight);
|
|
206
|
+
if (newTop != this.m_topIndex || forceUpdate) {
|
|
207
|
+
this.m_topIndex = newTop;
|
|
208
|
+
this._buildItems();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
if (forceUpdate) {
|
|
212
|
+
this.startTimer('scroll', 10, false, update);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
update();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async _buildItems() {
|
|
219
|
+
let props = this.m_props;
|
|
220
|
+
let items = [];
|
|
221
|
+
let list_items = props.items;
|
|
222
|
+
if (isFunction(list_items)) {
|
|
223
|
+
list_items = list_items();
|
|
224
|
+
}
|
|
225
|
+
let selId = this.m_selection?.item.id;
|
|
226
|
+
let selFnd = false;
|
|
227
|
+
if (props.virtual) {
|
|
228
|
+
let rc = this.getBoundingRect();
|
|
229
|
+
let limit = 100;
|
|
230
|
+
let y = 0;
|
|
231
|
+
let top = this.m_topIndex * this.m_itemHeight;
|
|
232
|
+
let index = this.m_topIndex;
|
|
233
|
+
let height = rc.height;
|
|
234
|
+
let count = props.items.length;
|
|
235
|
+
let newels = [];
|
|
236
|
+
let cache = this.m_cache;
|
|
237
|
+
this.m_cache = new Map();
|
|
238
|
+
while (y < height && index < count && --limit > 0) {
|
|
239
|
+
let it = props.items[index];
|
|
240
|
+
let itm;
|
|
241
|
+
if (cache.has(it.id)) {
|
|
242
|
+
itm = cache.get(it.id); // reuse it
|
|
243
|
+
cache.delete(it.id); // cache will contain only elements to remove
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
itm = this._renderItem(it);
|
|
247
|
+
newels.push(itm);
|
|
248
|
+
}
|
|
249
|
+
if (selId == it.id) {
|
|
250
|
+
itm.addClass('@selected');
|
|
251
|
+
selFnd = true;
|
|
252
|
+
}
|
|
253
|
+
itm.setStyleValue('top', top + y);
|
|
254
|
+
items.push(itm);
|
|
255
|
+
this.m_cache.set(it.id, itm); // keep it for next time
|
|
256
|
+
y += this.m_itemHeight;
|
|
257
|
+
index++;
|
|
258
|
+
}
|
|
259
|
+
// all element remaining here are to remove
|
|
260
|
+
cache.forEach((c) => {
|
|
261
|
+
c.dispose();
|
|
262
|
+
});
|
|
263
|
+
// append new elements
|
|
264
|
+
this.m_container.appendChild(newels);
|
|
265
|
+
this.m_container.setStyleValue('height', count * this.m_itemHeight);
|
|
266
|
+
// check that it's still existing
|
|
267
|
+
if (!selFnd) {
|
|
268
|
+
if (!list_items.some(it => selId == it.id)) {
|
|
269
|
+
this.m_selection = null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
list_items.forEach((it) => {
|
|
275
|
+
let itm = this._renderItem(it);
|
|
276
|
+
if (selId == it.id) {
|
|
277
|
+
itm.addClass('@selected');
|
|
278
|
+
selFnd = true;
|
|
279
|
+
}
|
|
280
|
+
items.push(itm);
|
|
281
|
+
});
|
|
282
|
+
this.m_container.setContent(items, false);
|
|
283
|
+
if (!selFnd) {
|
|
284
|
+
this.m_selection = null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (this.m_defer_sel) {
|
|
288
|
+
let t = this.m_defer_sel;
|
|
289
|
+
this.m_defer_sel = undefined;
|
|
290
|
+
this.selection = t;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/** @ignore
|
|
294
|
+
* default rendering of an item
|
|
295
|
+
*/
|
|
296
|
+
_renderItem(item) {
|
|
297
|
+
const newItem = this.onRenderItem(item);
|
|
298
|
+
newItem.setAttribute('data-id', item.id);
|
|
299
|
+
newItem.addClass('@list-item');
|
|
300
|
+
newItem.setData('item-id', item.id);
|
|
301
|
+
return newItem;
|
|
302
|
+
}
|
|
303
|
+
onRenderItem(item) {
|
|
304
|
+
if (this.m_props.renderItem) {
|
|
305
|
+
return this.m_props.renderItem(item);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
return new HLayout({ content: item.text });
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/** @ignore */
|
|
312
|
+
_handleClick(e) {
|
|
313
|
+
let dom = e.target, self = this.dom, list_items = this.m_props.items; // already created by build
|
|
314
|
+
// go up until we find something interesting
|
|
315
|
+
while (dom && dom != self) {
|
|
316
|
+
let itm = Component.getElement(dom), id = itm?.getData('item-id');
|
|
317
|
+
if (id !== undefined) {
|
|
318
|
+
// find the element
|
|
319
|
+
let item = list_items.find((item) => item.id == id);
|
|
320
|
+
if (item) {
|
|
321
|
+
let event;
|
|
322
|
+
if (e.type == 'click') {
|
|
323
|
+
event = EvClick(item);
|
|
324
|
+
this.emit('click', event);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
event = EvDblClick(item);
|
|
328
|
+
this.emit('dblClick', event);
|
|
329
|
+
}
|
|
330
|
+
if (!event.defaultPrevented) {
|
|
331
|
+
this._selectItem(item, itm);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
this._selectItem(null, null);
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
dom = dom.parentElement;
|
|
340
|
+
}
|
|
341
|
+
this._selectItem(null, null);
|
|
342
|
+
}
|
|
343
|
+
/** @ignore */
|
|
344
|
+
_handleCtxMenu(e) {
|
|
345
|
+
e.preventDefault();
|
|
346
|
+
let dom = e.target, self = this.dom, list_items = this.m_props.items; // already created by build;
|
|
347
|
+
while (dom && dom != self) {
|
|
348
|
+
let itm = Component.getElement(dom), id = itm?.getData('item-id');
|
|
349
|
+
if (id) {
|
|
350
|
+
// find the element
|
|
351
|
+
let item = list_items.find((item) => item.id == id);
|
|
352
|
+
if (item) {
|
|
353
|
+
this._selectItem(item, itm);
|
|
354
|
+
this.emit('contextMenu', EvContextMenu(e, item));
|
|
355
|
+
}
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
dom = dom.parentElement;
|
|
359
|
+
}
|
|
360
|
+
this.emit('contextMenu', EvContextMenu(e, null));
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* @ignore
|
|
364
|
+
* called when an item is selected by mouse
|
|
365
|
+
*/
|
|
366
|
+
_selectItem(item, citem, notify = true) {
|
|
367
|
+
if (this.m_selection && this.m_selection.citem) {
|
|
368
|
+
this.m_selection.citem.removeClass('@selected');
|
|
369
|
+
}
|
|
370
|
+
this.m_selection = item ? {
|
|
371
|
+
item: item,
|
|
372
|
+
citem: citem
|
|
373
|
+
} : null;
|
|
374
|
+
if (this.m_selection && this.m_selection.citem) {
|
|
375
|
+
this.m_selection.citem.addClass('@selected');
|
|
376
|
+
}
|
|
377
|
+
if (notify) {
|
|
378
|
+
this.emit('selectionChange', EvSelectionChange(item));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* return the current selection or null
|
|
383
|
+
*/
|
|
384
|
+
get selection() {
|
|
385
|
+
return this.m_selection ? this.m_selection.item : null;
|
|
386
|
+
}
|
|
387
|
+
set selection(id) {
|
|
388
|
+
if (id === null || id === undefined) {
|
|
389
|
+
this._selectItem(null, null);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
if (isFunction(this.m_props.items)) {
|
|
393
|
+
this.m_defer_sel = id;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
let item = this.m_props.items.find((item) => item.id == id);
|
|
397
|
+
let citem = this._findItemWithId(item.id);
|
|
398
|
+
this._selectItem(item, citem, false);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
_findItemWithId(id) {
|
|
403
|
+
let citem = null;
|
|
404
|
+
if (this.dom) {
|
|
405
|
+
// make the element visible to user
|
|
406
|
+
// todo: problem with virtual listview
|
|
407
|
+
this.m_container.enumChilds((c) => {
|
|
408
|
+
if (c.getData('item-id') == id) {
|
|
409
|
+
c.scrollIntoView();
|
|
410
|
+
citem = c;
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
return citem;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* append or prepend a new item
|
|
419
|
+
* @param item
|
|
420
|
+
* @param prepend
|
|
421
|
+
* @param select
|
|
422
|
+
*/
|
|
423
|
+
appendItem(item, prepend = false, select = true) {
|
|
424
|
+
if (prepend) {
|
|
425
|
+
this.m_props.items.unshift(item);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
this.m_props.items.push(item);
|
|
429
|
+
}
|
|
430
|
+
if (select) {
|
|
431
|
+
this.selection = null;
|
|
432
|
+
}
|
|
433
|
+
if (!this.m_container) {
|
|
434
|
+
this._buildContent();
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
this._buildItems();
|
|
438
|
+
}
|
|
439
|
+
if (select) {
|
|
440
|
+
this.selection = item.id;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* update an item
|
|
445
|
+
*/
|
|
446
|
+
updateItem(id, item) {
|
|
447
|
+
// find item
|
|
448
|
+
const idx = this.m_props.items.findIndex(itm => itm.id === id);
|
|
449
|
+
if (idx < 0) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
// take care of selection
|
|
453
|
+
let was_sel = false;
|
|
454
|
+
if (this.m_selection && this.m_selection.item === this.m_props.items[idx]) {
|
|
455
|
+
was_sel = true;
|
|
456
|
+
}
|
|
457
|
+
// replace it in the list
|
|
458
|
+
this.m_props.items[idx] = item;
|
|
459
|
+
// rebuild & replace it's line
|
|
460
|
+
const oldDOM = this.queryItem(`[data-id="${item.id}"]`)?.dom;
|
|
461
|
+
if (oldDOM) {
|
|
462
|
+
const _new = this._renderItem(item);
|
|
463
|
+
if (was_sel) {
|
|
464
|
+
_new.addClass('@selected');
|
|
465
|
+
this.m_selection.citem = _new;
|
|
466
|
+
this.m_selection.item = item;
|
|
467
|
+
}
|
|
468
|
+
const newDOM = _new._build();
|
|
469
|
+
this.m_container.dom.replaceChild(newDOM, oldDOM);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
export function EvCancel(context = null) {
|
|
474
|
+
return BasicEvent({ context });
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
*
|
|
478
|
+
*/
|
|
479
|
+
export class PopupListView extends Popup {
|
|
480
|
+
m_list;
|
|
481
|
+
constructor(props) {
|
|
482
|
+
super({ tabIndex: false });
|
|
483
|
+
this.enableMask(false);
|
|
484
|
+
props.tabIndex = false;
|
|
485
|
+
this.m_list = new ListView(props);
|
|
486
|
+
//this.m_list.addClass( '@fit' );
|
|
487
|
+
this.setContent(this.m_list);
|
|
488
|
+
this.mapPropEvents(props, 'cancel');
|
|
489
|
+
}
|
|
490
|
+
set items(items) {
|
|
491
|
+
this.m_list.items = items;
|
|
492
|
+
}
|
|
493
|
+
// @override
|
|
494
|
+
// todo: move into popup
|
|
495
|
+
_handleClick = (e) => {
|
|
496
|
+
if (!this.dom) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
let newfocus = e.target;
|
|
500
|
+
// child of this: ok
|
|
501
|
+
if (this.dom.contains(newfocus)) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
// menu: ok
|
|
505
|
+
let dest = Component.getElement(newfocus, MenuItem);
|
|
506
|
+
if (dest) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
this.signal('cancel', EvCancel());
|
|
510
|
+
this.close();
|
|
511
|
+
};
|
|
512
|
+
// todo: move into popup
|
|
513
|
+
show(modal) {
|
|
514
|
+
document.addEventListener('mousedown', this._handleClick);
|
|
515
|
+
super.show(modal);
|
|
516
|
+
}
|
|
517
|
+
hide() {
|
|
518
|
+
document.removeEventListener('mousedown', this._handleClick);
|
|
519
|
+
super.hide();
|
|
520
|
+
}
|
|
521
|
+
// todo: move into popup
|
|
522
|
+
close() {
|
|
523
|
+
document.removeEventListener('mousedown', this._handleClick);
|
|
524
|
+
super.close();
|
|
525
|
+
}
|
|
526
|
+
get selection() {
|
|
527
|
+
return this.m_list.selection;
|
|
528
|
+
}
|
|
529
|
+
set selection(itemId) {
|
|
530
|
+
this.m_list.selection = itemId;
|
|
531
|
+
}
|
|
532
|
+
}
|
package/lib/md5.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file md5.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
* @license
|
|
11
|
+
* Copyright (c) 2019-2021 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* This program is free software; you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation; either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* This program is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
**/
|
|
25
|
+
export declare class Md5 {
|
|
26
|
+
static hashStr(str: string, raw?: false): string;
|
|
27
|
+
static hashStr(str: string, raw?: true): Int32Array;
|
|
28
|
+
static hashAsciiStr(str: string, raw?: false): string;
|
|
29
|
+
static hashAsciiStr(str: string, raw?: true): Int32Array;
|
|
30
|
+
private static stateIdentity;
|
|
31
|
+
private static buffer32Identity;
|
|
32
|
+
private static hexChars;
|
|
33
|
+
private static hexOut;
|
|
34
|
+
private static onePassHasher;
|
|
35
|
+
private static _hex;
|
|
36
|
+
private static _md5cycle;
|
|
37
|
+
private _dataLength;
|
|
38
|
+
private _bufferLength;
|
|
39
|
+
private _state;
|
|
40
|
+
private _buffer;
|
|
41
|
+
private _buffer8;
|
|
42
|
+
private _buffer32;
|
|
43
|
+
constructor();
|
|
44
|
+
start(): this;
|
|
45
|
+
appendStr(str: string): this;
|
|
46
|
+
appendAsciiStr(str: string): this;
|
|
47
|
+
appendByteArray(input: Uint8Array): this;
|
|
48
|
+
getState(): {
|
|
49
|
+
buffer: any;
|
|
50
|
+
buflen: number;
|
|
51
|
+
length: number;
|
|
52
|
+
state: number[];
|
|
53
|
+
};
|
|
54
|
+
setState(state: any): void;
|
|
55
|
+
end(raw?: boolean): string | Int32Array;
|
|
56
|
+
}
|