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/combobox.ts
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file combobox.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
|
+
/**
|
|
27
|
+
* TODO: replace custom combo list by listview or gridview
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { Component, CProps, ContainerEventMap } from './component'
|
|
31
|
+
import { EvChange, EvSelectionChange, EventCallback } from './x4_events'
|
|
32
|
+
|
|
33
|
+
import { Input } from './input'
|
|
34
|
+
import { Label } from './label'
|
|
35
|
+
import { Button } from './button'
|
|
36
|
+
import { HLayout } from './layout'
|
|
37
|
+
import { PopupListView, ListViewItem, PopulateItems, EvCancel } from './listview';
|
|
38
|
+
import { DataStore, DataView, Record } from './datastore'
|
|
39
|
+
import { isFunction, HtmlString } from './tools'
|
|
40
|
+
|
|
41
|
+
export interface ComboStoreProxyProps {
|
|
42
|
+
store: DataView | DataStore;
|
|
43
|
+
display: ( rec: Record ) => string | HtmlString;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// [COMBOBOX]
|
|
48
|
+
// ============================================================================
|
|
49
|
+
|
|
50
|
+
export interface ComboItemRender {
|
|
51
|
+
( itm: ListViewItem ) : Component;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface ComboBoxEventMap extends ContainerEventMap {
|
|
55
|
+
readonly change: EvChange; // value change (event.value = new value as id)
|
|
56
|
+
readonly selectionChange?: EvSelectionChange; // ( event.value = new value as ListItem)
|
|
57
|
+
readonly cancel?: EvCancel;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ComboBoxProps extends CProps<ComboBoxEventMap> {
|
|
61
|
+
tabIndex?: number | boolean;
|
|
62
|
+
name?: string;
|
|
63
|
+
readOnly?: boolean;
|
|
64
|
+
|
|
65
|
+
label?: string;
|
|
66
|
+
labelWidth?: number; // < 0 for flex
|
|
67
|
+
// =0 to adjust label width
|
|
68
|
+
// > 0 to specify a width
|
|
69
|
+
|
|
70
|
+
labelAlign?: 'left' | 'right';
|
|
71
|
+
|
|
72
|
+
items?: ListViewItem[];
|
|
73
|
+
populate?: PopulateItems; // if not specified, fire 'populate' event
|
|
74
|
+
value?: any; // shown value at init
|
|
75
|
+
|
|
76
|
+
renderer?: ComboItemRender;
|
|
77
|
+
selectionChange?: EventCallback<EvSelectionChange>;// shortcut to events: { selectionChange: ... }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @review use textedit
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
export class ComboBox extends HLayout<ComboBoxProps,ComboBoxEventMap> {
|
|
85
|
+
|
|
86
|
+
private m_ui_input: Component;
|
|
87
|
+
private m_ui_button: Button;
|
|
88
|
+
private m_popup: PopupListView;
|
|
89
|
+
|
|
90
|
+
private m_selection: ListViewItem;
|
|
91
|
+
private m_defer_sel: any;
|
|
92
|
+
|
|
93
|
+
constructor(props: ComboBoxProps) {
|
|
94
|
+
super(props);
|
|
95
|
+
|
|
96
|
+
this.setDomEvent( 'keypress', () => this.showPopup() );
|
|
97
|
+
this.setDomEvent( 'click', () => this.showPopup() );
|
|
98
|
+
|
|
99
|
+
this.mapPropEvents(props, 'selectionChange' );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set items( items: ListViewItem[] ) {
|
|
103
|
+
this.m_props.items = items;
|
|
104
|
+
if( this.m_popup ) {
|
|
105
|
+
this.m_popup.items = items;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** @ignore */
|
|
110
|
+
render( props: ComboBoxProps ) {
|
|
111
|
+
|
|
112
|
+
if( !props.renderer ) {
|
|
113
|
+
this.m_ui_input = new Input( {
|
|
114
|
+
flex : 1,
|
|
115
|
+
readOnly : true,
|
|
116
|
+
tabIndex : 0,
|
|
117
|
+
name: props.name,
|
|
118
|
+
value_hook: {
|
|
119
|
+
get: (): string => { return this.value; },
|
|
120
|
+
set: (v: string) => { this.value = v; }
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.m_ui_input = new Component( {
|
|
126
|
+
flex: 1,
|
|
127
|
+
cls: '@fake-input @hlayout',
|
|
128
|
+
tabIndex: 1
|
|
129
|
+
} );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let width = undefined,
|
|
133
|
+
flex = undefined;
|
|
134
|
+
|
|
135
|
+
let labelWidth = props.labelWidth ?? 0;
|
|
136
|
+
|
|
137
|
+
if( labelWidth>0 ) {
|
|
138
|
+
width = labelWidth;
|
|
139
|
+
}
|
|
140
|
+
else if( labelWidth<0 ) {
|
|
141
|
+
flex = -labelWidth;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
this.setContent([
|
|
145
|
+
// todo: why 'label1' class name
|
|
146
|
+
new Label({
|
|
147
|
+
cls: 'label1' + (props.label ? '' : ' @hidden'),
|
|
148
|
+
text: props.label,
|
|
149
|
+
width,
|
|
150
|
+
flex,
|
|
151
|
+
align: props.labelAlign
|
|
152
|
+
}),
|
|
153
|
+
new HLayout({
|
|
154
|
+
flex: 1,
|
|
155
|
+
content: [
|
|
156
|
+
this.m_ui_input,
|
|
157
|
+
this.m_ui_button = new Button({
|
|
158
|
+
cls: 'gadget',
|
|
159
|
+
icon: 'cls(far fa-angle-down)',
|
|
160
|
+
tabIndex: false,
|
|
161
|
+
click: () => this.showPopup(),
|
|
162
|
+
dom_events: {
|
|
163
|
+
focus: () => { this.dom.focus(); },
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
]
|
|
167
|
+
}),
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
if (props.value !== undefined) {
|
|
171
|
+
this.value = props.value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
componentDisposed( ) {
|
|
176
|
+
if( this.m_popup ) {
|
|
177
|
+
this.m_popup.close( );
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
super.componentDisposed( );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* display the popup
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
showPopup() {
|
|
188
|
+
|
|
189
|
+
let props = this.m_props;
|
|
190
|
+
if (props.readOnly) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// need creation ?
|
|
195
|
+
|
|
196
|
+
if( !this.m_popup ) {
|
|
197
|
+
let cstyle = this.getComputedStyle( );
|
|
198
|
+
let fontFamily = cstyle.value( 'fontFamily' );
|
|
199
|
+
let fontSize = cstyle.value( 'fontSize' );
|
|
200
|
+
|
|
201
|
+
// prepare the combo listview
|
|
202
|
+
this.m_popup = new PopupListView({
|
|
203
|
+
cls: '@combo-popup',
|
|
204
|
+
items: props.items,
|
|
205
|
+
populate: props.populate,
|
|
206
|
+
renderItem: this.m_props.renderer,
|
|
207
|
+
selectionChange: (e) => this._selectItem(e),
|
|
208
|
+
cancel: ( e ) => this.signal( 'cancel', e ),
|
|
209
|
+
style: {
|
|
210
|
+
fontFamily,
|
|
211
|
+
fontSize
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let r1 = this.m_ui_button.getBoundingRect(),
|
|
217
|
+
r2 = this.m_ui_input.getBoundingRect();
|
|
218
|
+
|
|
219
|
+
this.m_popup.setStyle({
|
|
220
|
+
minWidth: r1.right - r2.left,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
this.m_popup.displayAt(r2.left, r2.bottom);
|
|
224
|
+
|
|
225
|
+
if( this.value!==undefined ) {
|
|
226
|
+
this.m_popup.selection = this.value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** @ignore
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
private _selectItem( ev: EvSelectionChange ) {
|
|
234
|
+
|
|
235
|
+
let item: ListViewItem = ev.selection as ListViewItem;
|
|
236
|
+
if( !item ) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
this._setInput( item, true );
|
|
241
|
+
|
|
242
|
+
this.m_selection = {
|
|
243
|
+
id: item.id,
|
|
244
|
+
text: item.text
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
this.emit( 'selectionChange', EvSelectionChange( item ) );
|
|
248
|
+
this.emit( 'change', EvChange(item.id) );
|
|
249
|
+
this.m_ui_input.focus( );
|
|
250
|
+
|
|
251
|
+
this.m_popup.hide( );
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
257
|
+
|
|
258
|
+
private _setInput( item, fireEv = false ) {
|
|
259
|
+
|
|
260
|
+
if( item ) {
|
|
261
|
+
if( this.m_ui_input ) {
|
|
262
|
+
if( this.m_ui_input instanceof Input ) {
|
|
263
|
+
this.m_ui_input.value = item.text;
|
|
264
|
+
// fires a change event
|
|
265
|
+
if( fireEv ) {
|
|
266
|
+
this.m_ui_input.dom.dispatchEvent( new Event('input') );
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.m_ui_input.setContent( this.m_props.renderer( item ) );
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
this.m_props.value = item.id;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
*
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
public get value() {
|
|
284
|
+
return this.m_selection ? this.m_selection.id : undefined;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public get valueText( ) {
|
|
288
|
+
return this.m_selection ? this.m_selection.text : undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
*
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
public set value(id) {
|
|
296
|
+
let items = this.m_props.items;
|
|
297
|
+
|
|
298
|
+
if( isFunction(items) ) {
|
|
299
|
+
items = items( );
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
items.some( (v) => {
|
|
303
|
+
if (v.id === id) {
|
|
304
|
+
this._setInput( v );
|
|
305
|
+
this.m_selection = v;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
get input( ) : Input {
|
|
312
|
+
return this.m_ui_input instanceof Input ? this.m_ui_input : null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static storeProxy( props: ComboStoreProxyProps ): PopulateItems {
|
|
316
|
+
|
|
317
|
+
let view: DataView = props.store instanceof DataStore ? props.store.createView() : props.store;
|
|
318
|
+
|
|
319
|
+
return ( ) => {
|
|
320
|
+
let result: ListViewItem[] = new Array( props.store.count );
|
|
321
|
+
|
|
322
|
+
props.store.forEach( ( rec, index ) => {
|
|
323
|
+
result[index] = {
|
|
324
|
+
id: rec.getID( ),
|
|
325
|
+
text: props.display( rec )
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
return result;
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
/*
|
|
337
|
+
export type CBComboBoxRenderer = ( rec: Record ) => string;
|
|
338
|
+
export interface ComboBoxStore {
|
|
339
|
+
store: DataStore;
|
|
340
|
+
display: string | CBComboBoxRenderer; // if string, the field name to display
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|