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/src/smartedit.ts
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file smartedit.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
|
+
|
|
26
|
+
import { InputProps } from './input'
|
|
27
|
+
import { TextEdit, TextEditProps } from './textedit'
|
|
28
|
+
import { DataStore, DataView, Record } from './datastore'
|
|
29
|
+
import { Popup, PopupProps, PopupEventMap } from './popup';
|
|
30
|
+
import { Component, CProps, EvFocus } from './component';
|
|
31
|
+
import { EvChange, EvClick } from './x4_events';
|
|
32
|
+
|
|
33
|
+
type Renderer = (rec: Record) => CellData[];
|
|
34
|
+
|
|
35
|
+
export interface ToolItem {
|
|
36
|
+
text: string;
|
|
37
|
+
callback: (target: TextEdit) => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SmartEditProps extends TextEditProps {
|
|
41
|
+
store: DataStore;
|
|
42
|
+
field: string;
|
|
43
|
+
minDisplay?: number; // min char number before displaying items
|
|
44
|
+
maxCount?: number; // max count elements to display
|
|
45
|
+
autoFill?: boolean; // force selected element into edit (cannot select empty)
|
|
46
|
+
renderer: Renderer;
|
|
47
|
+
tools?: ToolItem[]; // elements to add at end
|
|
48
|
+
searchCallback?: (value: string, view: DataView) => boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class SmartEdit extends TextEdit<SmartEditProps> {
|
|
52
|
+
|
|
53
|
+
m_popup: PopupTable;
|
|
54
|
+
m_dataview: DataView;
|
|
55
|
+
m_field: string;
|
|
56
|
+
m_minDisplay: number;
|
|
57
|
+
m_maxCount: number;
|
|
58
|
+
m_autoFill: boolean;
|
|
59
|
+
m_renderer: Renderer;
|
|
60
|
+
m_tools: ToolItem[];
|
|
61
|
+
m_searchCallback: (value: string, view: DataView) => boolean;
|
|
62
|
+
|
|
63
|
+
constructor(props: SmartEditProps) {
|
|
64
|
+
super(props);
|
|
65
|
+
|
|
66
|
+
this.m_dataview = props.store.createView();
|
|
67
|
+
this.m_field = props.field;
|
|
68
|
+
this.m_renderer = props.renderer;
|
|
69
|
+
this.m_minDisplay = props.minDisplay ?? 0;
|
|
70
|
+
this.m_maxCount = props.maxCount ?? 10;
|
|
71
|
+
this.m_autoFill = props.autoFill === undefined ? true : props.autoFill;
|
|
72
|
+
this.m_popup = null;
|
|
73
|
+
this.m_tools = props.tools ?? [];
|
|
74
|
+
this.m_searchCallback = props.searchCallback;
|
|
75
|
+
|
|
76
|
+
this.on('change', (e) => this._onChange(e));
|
|
77
|
+
this.on('focus', (e) => this._onFocus(e));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
render(props: SmartEditProps) {
|
|
81
|
+
super.render(props);
|
|
82
|
+
|
|
83
|
+
this.m_ui_input.setDomEvent('keydown', (e) => this._onKey(e));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private _onChange(ev: EvChange) {
|
|
87
|
+
this._showPopup(ev.value as string);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private _onFocus(ev: EvFocus) {
|
|
91
|
+
if (ev.focus) {
|
|
92
|
+
this._showPopup(this.value);
|
|
93
|
+
}
|
|
94
|
+
else if (this.m_popup) {
|
|
95
|
+
this.m_popup.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private _onKey(e) {
|
|
100
|
+
|
|
101
|
+
console.log(e.key);
|
|
102
|
+
|
|
103
|
+
switch (e.key) {
|
|
104
|
+
case 'Backspace': {
|
|
105
|
+
|
|
106
|
+
// remove selection
|
|
107
|
+
let start = e.target.selectionStart;
|
|
108
|
+
let end = e.target.selectionEnd;
|
|
109
|
+
|
|
110
|
+
if (start > end) {
|
|
111
|
+
let t = start;
|
|
112
|
+
start = end;
|
|
113
|
+
end = t;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let v = this.value;
|
|
117
|
+
let a = v.substr(0, start);
|
|
118
|
+
let b = v.substr(end);
|
|
119
|
+
|
|
120
|
+
this.value = a + b;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
case 'ArrowUp':
|
|
125
|
+
case 'Up': {
|
|
126
|
+
if (this.m_popup) {
|
|
127
|
+
this._moveNext(false);
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
case 'ArrowDown':
|
|
135
|
+
case 'Down': {
|
|
136
|
+
if (this.m_popup) {
|
|
137
|
+
this._moveNext(true);
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case 'Enter': {
|
|
145
|
+
if (this.m_popup) {
|
|
146
|
+
this._checkTool(e);
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private _showSugg(text) {
|
|
154
|
+
let sel = this.getSelection();
|
|
155
|
+
this.value = text;
|
|
156
|
+
this.select(sel.start, sel.length);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
isOpen() {
|
|
160
|
+
return this.m_popup !== null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
componentDisposed() {
|
|
165
|
+
if (this.m_popup) {
|
|
166
|
+
this.m_popup.close();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
super.componentDisposed();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// enter pressed on an element
|
|
173
|
+
private _checkTool(e: KeyboardEvent) {
|
|
174
|
+
|
|
175
|
+
let sel = this.m_popup.selection;
|
|
176
|
+
if (this._callTool(sel)) {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private _callTool(sel: number): boolean {
|
|
182
|
+
let data = this.m_popup.getRowData(sel) as ToolItem;
|
|
183
|
+
if (data) {
|
|
184
|
+
if (this.m_popup) {
|
|
185
|
+
this.m_popup.close();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
data.callback(this);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private _moveNext(next: boolean) {
|
|
197
|
+
let sel = this.m_popup.selNext(next);
|
|
198
|
+
console.log('movenext: ', sel);
|
|
199
|
+
|
|
200
|
+
let data = this.m_popup.getRowData(sel);
|
|
201
|
+
|
|
202
|
+
if (!data) {
|
|
203
|
+
let text = this.m_popup.getCell(sel, 0).text;
|
|
204
|
+
this._showSugg(text);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//_onKey( e: KeyboardEvent ) {
|
|
209
|
+
// if( e.key==' ' ) {
|
|
210
|
+
// this._showPopup( this.value )
|
|
211
|
+
// }
|
|
212
|
+
//}
|
|
213
|
+
|
|
214
|
+
private _showPopup(v: string) {
|
|
215
|
+
|
|
216
|
+
if (this.m_popup) {
|
|
217
|
+
this.m_popup.close();
|
|
218
|
+
this.m_popup = null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let cnt: number;
|
|
222
|
+
|
|
223
|
+
let sel = this.getSelection();
|
|
224
|
+
let search = sel.length ? v.substr(0, sel.start) : v;
|
|
225
|
+
|
|
226
|
+
if (search.length < this.m_minDisplay) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let autoFill = this.m_autoFill;
|
|
231
|
+
|
|
232
|
+
if (search.length == 0) {
|
|
233
|
+
cnt = this.m_dataview.filter(null);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
if (this.m_searchCallback) {
|
|
237
|
+
autoFill = this.m_searchCallback(search, this.m_dataview);
|
|
238
|
+
cnt = this.m_dataview.count;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
cnt = this.m_dataview.filter({
|
|
242
|
+
op: '=',
|
|
243
|
+
field: this.m_field,
|
|
244
|
+
value: new RegExp('^' + search.trim() + '.*', 'mi')
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (cnt > 0) {
|
|
250
|
+
let rec = this.m_dataview.getByIndex(0);
|
|
251
|
+
|
|
252
|
+
if (autoFill) {
|
|
253
|
+
this.value = rec.getField(this.m_field);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.select(v.length);
|
|
257
|
+
|
|
258
|
+
let count = Math.min(this.m_dataview.count, this.m_maxCount);
|
|
259
|
+
let r2 = this.m_ui_input.getBoundingRect();
|
|
260
|
+
|
|
261
|
+
this.m_popup = new PopupTable({
|
|
262
|
+
cls: '@editor-popup',
|
|
263
|
+
minWidth: r2.width
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
this.m_popup.on('click', (ev: EvClick) => {
|
|
267
|
+
|
|
268
|
+
let { row, text } = ev.context;
|
|
269
|
+
|
|
270
|
+
if (!this._callTool(row)) {
|
|
271
|
+
this.value = text;
|
|
272
|
+
this.emit('click', EvClick());
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
let i;
|
|
277
|
+
for (i = 0; i < count; i++) {
|
|
278
|
+
|
|
279
|
+
let rec = this.m_dataview.getByIndex(i);
|
|
280
|
+
let texts = this.m_renderer(rec);
|
|
281
|
+
|
|
282
|
+
this.m_popup.setCell(i, 0, texts[0].text, texts[0].cls);
|
|
283
|
+
this.m_popup.setCell(i, 1, texts[1].text, texts[1].cls);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
for (let j = 0; j < this.m_tools.length; j++, i++) {
|
|
287
|
+
this.m_popup.setCell(i, 0, this.m_tools[j].text);
|
|
288
|
+
this.m_popup.setCell(i, 1, '');
|
|
289
|
+
this.m_popup.setRowData(i, this.m_tools[j]);
|
|
290
|
+
console.log('fill: ', i);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
this.m_popup.displayAt(r2.left, r2.bottom);
|
|
294
|
+
}
|
|
295
|
+
else if (this.m_tools.length) {
|
|
296
|
+
let r2 = this.m_ui_input.getBoundingRect();
|
|
297
|
+
|
|
298
|
+
this.m_popup = new PopupTable({
|
|
299
|
+
cls: '@editor-popup',
|
|
300
|
+
minWidth: r2.width
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
this.m_popup.on('click', (ev: EvClick) => {
|
|
304
|
+
|
|
305
|
+
let { row, text } = ev.context;
|
|
306
|
+
if (!this._callTool(row)) {
|
|
307
|
+
this.value = text;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
for (let j = 0, i = 0; j < this.m_tools.length; j++, i++) {
|
|
312
|
+
this.m_popup.setCell(i, 0, this.m_tools[j].text);
|
|
313
|
+
this.m_popup.setCell(i, 1, '');
|
|
314
|
+
this.m_popup.setRowData(i, this.m_tools[j]);
|
|
315
|
+
console.log('fill: ', i);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
this.m_popup.displayAt(r2.left, r2.bottom);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface CellData {
|
|
324
|
+
text: string;
|
|
325
|
+
cls?: string;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
type CellMap = Map<number, CellData>;
|
|
329
|
+
|
|
330
|
+
interface PopupTableEventMap extends PopupEventMap {
|
|
331
|
+
click: EvClick;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
interface PopupTableProps extends PopupProps<PopupTableEventMap> {
|
|
335
|
+
rows?: number;
|
|
336
|
+
cols?: number;
|
|
337
|
+
minWidth?: number;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
export class PopupTable extends Popup<PopupTableProps, PopupTableEventMap> {
|
|
343
|
+
|
|
344
|
+
private m_rows: number;
|
|
345
|
+
private m_cols: number;
|
|
346
|
+
private m_cells: CellMap;
|
|
347
|
+
private m_data: Map<number, any>;
|
|
348
|
+
private m_minw: number;
|
|
349
|
+
private m_defcell: CellData;
|
|
350
|
+
private m_sel: number;
|
|
351
|
+
|
|
352
|
+
constructor(props: PopupTableProps) {
|
|
353
|
+
super(props);
|
|
354
|
+
|
|
355
|
+
this.m_rows = props.rows ?? 0;
|
|
356
|
+
this.m_cols = props.cols ?? 0;
|
|
357
|
+
this.m_minw = props.minWidth;
|
|
358
|
+
this.m_cells = new Map<number, CellData>();
|
|
359
|
+
this.m_data = new Map<number, any>();
|
|
360
|
+
this.m_defcell = { text: '', cls: undefined };
|
|
361
|
+
this.m_sel = 0;
|
|
362
|
+
this.enableMask(false);
|
|
363
|
+
|
|
364
|
+
this.setDomEvent('create', () => {
|
|
365
|
+
(<HTMLTableElement>this.dom).cellPadding = '0px';
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
this.setDomEvent('mousedown', (e: MouseEvent) => {
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
|
|
371
|
+
let el = Component.getElement(<HTMLElement>e.target);
|
|
372
|
+
let row = el.getData('row');
|
|
373
|
+
|
|
374
|
+
this.m_sel = row;
|
|
375
|
+
this.update();
|
|
376
|
+
|
|
377
|
+
this.emit('click', EvClick({ row, text: this.getCell(row, 0).text }));
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
setRowData(row: number, data: any) {
|
|
382
|
+
this.m_data.set(row, data);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
getRowData(row: number): any {
|
|
386
|
+
return this.m_data.get(row);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
setCell(row: number, col: number, text: string, cls?: string) {
|
|
390
|
+
this.m_cells.set(_cid(row, col), { text, cls });
|
|
391
|
+
|
|
392
|
+
if (this.m_rows < (row + 1)) {
|
|
393
|
+
this.m_rows = (row + 1);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (this.m_cols < (col + 1)) {
|
|
397
|
+
this.m_cols = (col + 1);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
getCell(row, col): CellData {
|
|
402
|
+
|
|
403
|
+
let cd = this.m_cells.get(_cid(row, col));
|
|
404
|
+
if (cd == null) {
|
|
405
|
+
return this.m_defcell;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return cd;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** @ignore */
|
|
412
|
+
render() {
|
|
413
|
+
this.setProp('tag', 'table');
|
|
414
|
+
|
|
415
|
+
if (this.m_minw) {
|
|
416
|
+
this.setStyleValue('minWidth', this.m_minw);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let rows = [];
|
|
420
|
+
|
|
421
|
+
for (let r = 0; r < this.m_rows; r++) {
|
|
422
|
+
|
|
423
|
+
let cols = [];
|
|
424
|
+
let data = { row: r };
|
|
425
|
+
|
|
426
|
+
for (let c = 0; c < this.m_cols; c++) {
|
|
427
|
+
|
|
428
|
+
let cell = this.getCell(r, c);
|
|
429
|
+
|
|
430
|
+
let col = new Component({
|
|
431
|
+
tag: 'td',
|
|
432
|
+
content: cell.text,
|
|
433
|
+
cls: cell.cls,
|
|
434
|
+
data
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
cols.push(col);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let cls = undefined;
|
|
441
|
+
if (r === this.m_sel) {
|
|
442
|
+
cls = '@selected';
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
let row = new Component({
|
|
446
|
+
tag: 'tr',
|
|
447
|
+
cls,
|
|
448
|
+
content: cols,
|
|
449
|
+
data
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
rows.push(row);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
this.setContent(rows);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* display the popup at a specific position
|
|
460
|
+
* @param x
|
|
461
|
+
* @param y
|
|
462
|
+
*/
|
|
463
|
+
|
|
464
|
+
public displayAt(x: number, y: number, align: string = 'top left') {
|
|
465
|
+
|
|
466
|
+
this.show();
|
|
467
|
+
|
|
468
|
+
let halign = 'l',
|
|
469
|
+
valign = 't';
|
|
470
|
+
|
|
471
|
+
if (align.indexOf('right') >= 0) {
|
|
472
|
+
halign = 'r';
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (align.indexOf('bottom') >= 0) {
|
|
476
|
+
valign = 'b';
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// @TODO: this is a minimal overflow problem solution
|
|
480
|
+
let rc = document.body.getBoundingClientRect(),
|
|
481
|
+
rm = this.getBoundingRect();
|
|
482
|
+
|
|
483
|
+
if (halign == 'r') {
|
|
484
|
+
x -= rm.width;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (valign == 'b') {
|
|
488
|
+
y -= rm.height;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (x < 4) {
|
|
492
|
+
x = 4;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if ((x + rm.width) > rc.right - 4) {
|
|
496
|
+
x = rc.right - 4 - rm.width;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (y < 4) {
|
|
500
|
+
y = 4;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if ((y + rm.height) > rc.bottom - 4) {
|
|
504
|
+
y = rc.bottom - 4 - rm.height;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
this.setStyle({ left: x, top: y });
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
selNext(next: boolean): number {
|
|
511
|
+
|
|
512
|
+
this.m_sel += next ? 1 : -1;
|
|
513
|
+
if (this.m_sel >= this.m_rows) {
|
|
514
|
+
this.m_sel = 0;
|
|
515
|
+
}
|
|
516
|
+
else if (this.m_sel < 0) {
|
|
517
|
+
this.m_sel = this.m_rows - 1;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
this.update();
|
|
521
|
+
return this.m_sel;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
get selection() {
|
|
525
|
+
return this.m_sel;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
function _cid(row: number, col: number) {
|
|
531
|
+
return row * 1000 + col;
|
|
532
|
+
}
|