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/settings.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file local_storage.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 { host } from './hosts/host';
|
|
26
|
+
export class Settings {
|
|
27
|
+
m_data;
|
|
28
|
+
m_name;
|
|
29
|
+
constructor(name) {
|
|
30
|
+
this.m_data = null;
|
|
31
|
+
this.m_name = name ?? 'settings';
|
|
32
|
+
}
|
|
33
|
+
set(name, value) {
|
|
34
|
+
this._load();
|
|
35
|
+
this.m_data[name] = value;
|
|
36
|
+
this._save();
|
|
37
|
+
}
|
|
38
|
+
get(name, defValue) {
|
|
39
|
+
this._load();
|
|
40
|
+
return this.m_data[name] ?? defValue;
|
|
41
|
+
}
|
|
42
|
+
_save() {
|
|
43
|
+
let data = JSON.stringify(this.m_data);
|
|
44
|
+
host.writeLocalStorage(this.m_name, data);
|
|
45
|
+
}
|
|
46
|
+
_load() {
|
|
47
|
+
if (this.m_data) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.m_data = {};
|
|
51
|
+
let data = host.readLocalStorage(this.m_name);
|
|
52
|
+
if (data !== null) {
|
|
53
|
+
data = JSON.parse(data);
|
|
54
|
+
if (data) {
|
|
55
|
+
this.m_data = data;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.info('There was an error attempting to read your settings.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// console.info('There was an error attempting to read your settings.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file sidebarview.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 { Component } from './component';
|
|
26
|
+
import { VLayout } from './layout';
|
|
27
|
+
import { CardView, CardViewProps, ICardViewItem } from './cardview';
|
|
28
|
+
export interface SideBarItem extends ICardViewItem {
|
|
29
|
+
}
|
|
30
|
+
export interface SideBarProps extends CardViewProps {
|
|
31
|
+
bar_sizable?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare class SideBarView extends CardView {
|
|
37
|
+
m_sidebar: VLayout;
|
|
38
|
+
m_content: Component;
|
|
39
|
+
constructor(props: SideBarProps);
|
|
40
|
+
/** @ignore */
|
|
41
|
+
render(): void;
|
|
42
|
+
protected _prepareSelector(card: ICardViewItem): Component;
|
|
43
|
+
protected _preparePage(page: Component): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \_/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / _ \____ _|
|
|
6
|
+
* /__/ \__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file sidebarview.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 { HLayout, VLayout } from './layout';
|
|
26
|
+
import { Button } from './button';
|
|
27
|
+
import { CardView } from './cardview';
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
export class SideBarView extends CardView {
|
|
32
|
+
m_sidebar;
|
|
33
|
+
m_content;
|
|
34
|
+
constructor(props) {
|
|
35
|
+
super(props);
|
|
36
|
+
this.addClass('@hlayout');
|
|
37
|
+
this.m_sidebar = new VLayout({
|
|
38
|
+
cls: '@side-bar',
|
|
39
|
+
sizable: props.bar_sizable ? 'right' : undefined,
|
|
40
|
+
});
|
|
41
|
+
this.m_content = new HLayout({ flex: 1, cls: '@tab-container' });
|
|
42
|
+
}
|
|
43
|
+
/** @ignore */
|
|
44
|
+
render() {
|
|
45
|
+
let tabs = [];
|
|
46
|
+
this.m_cards.forEach((p) => {
|
|
47
|
+
tabs.push(p.selector);
|
|
48
|
+
});
|
|
49
|
+
this.m_sidebar.setContent(new VLayout({
|
|
50
|
+
flex: 1,
|
|
51
|
+
cls: 'content',
|
|
52
|
+
content: tabs
|
|
53
|
+
}));
|
|
54
|
+
this.setContent([
|
|
55
|
+
this.m_sidebar,
|
|
56
|
+
this.m_content
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
_prepareSelector(card) {
|
|
60
|
+
return new Button({
|
|
61
|
+
text: card.title,
|
|
62
|
+
icon: card.icon,
|
|
63
|
+
tooltip: card.title,
|
|
64
|
+
click: () => { this.switchTo(card.name); }
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
_preparePage(page) {
|
|
68
|
+
super._preparePage(page);
|
|
69
|
+
if (!page.dom) {
|
|
70
|
+
this.m_content.appendChild(page);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
import { TextEdit, TextEditProps } from './textedit';
|
|
26
|
+
import { DataStore, DataView, Record } from './datastore';
|
|
27
|
+
import { Popup, PopupProps, PopupEventMap } from './popup';
|
|
28
|
+
import { EvClick } from './x4_events';
|
|
29
|
+
declare type Renderer = (rec: Record) => CellData[];
|
|
30
|
+
export interface ToolItem {
|
|
31
|
+
text: string;
|
|
32
|
+
callback: (target: TextEdit) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface SmartEditProps extends TextEditProps {
|
|
35
|
+
store: DataStore;
|
|
36
|
+
field: string;
|
|
37
|
+
minDisplay?: number;
|
|
38
|
+
maxCount?: number;
|
|
39
|
+
autoFill?: boolean;
|
|
40
|
+
renderer: Renderer;
|
|
41
|
+
tools?: ToolItem[];
|
|
42
|
+
searchCallback?: (value: string, view: DataView) => boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare class SmartEdit extends TextEdit<SmartEditProps> {
|
|
45
|
+
m_popup: PopupTable;
|
|
46
|
+
m_dataview: DataView;
|
|
47
|
+
m_field: string;
|
|
48
|
+
m_minDisplay: number;
|
|
49
|
+
m_maxCount: number;
|
|
50
|
+
m_autoFill: boolean;
|
|
51
|
+
m_renderer: Renderer;
|
|
52
|
+
m_tools: ToolItem[];
|
|
53
|
+
m_searchCallback: (value: string, view: DataView) => boolean;
|
|
54
|
+
constructor(props: SmartEditProps);
|
|
55
|
+
render(props: SmartEditProps): void;
|
|
56
|
+
private _onChange;
|
|
57
|
+
private _onFocus;
|
|
58
|
+
private _onKey;
|
|
59
|
+
private _showSugg;
|
|
60
|
+
isOpen(): boolean;
|
|
61
|
+
componentDisposed(): void;
|
|
62
|
+
private _checkTool;
|
|
63
|
+
private _callTool;
|
|
64
|
+
private _moveNext;
|
|
65
|
+
private _showPopup;
|
|
66
|
+
}
|
|
67
|
+
interface CellData {
|
|
68
|
+
text: string;
|
|
69
|
+
cls?: string;
|
|
70
|
+
}
|
|
71
|
+
interface PopupTableEventMap extends PopupEventMap {
|
|
72
|
+
click: EvClick;
|
|
73
|
+
}
|
|
74
|
+
interface PopupTableProps extends PopupProps<PopupTableEventMap> {
|
|
75
|
+
rows?: number;
|
|
76
|
+
cols?: number;
|
|
77
|
+
minWidth?: number;
|
|
78
|
+
}
|
|
79
|
+
export declare class PopupTable extends Popup<PopupTableProps, PopupTableEventMap> {
|
|
80
|
+
private m_rows;
|
|
81
|
+
private m_cols;
|
|
82
|
+
private m_cells;
|
|
83
|
+
private m_data;
|
|
84
|
+
private m_minw;
|
|
85
|
+
private m_defcell;
|
|
86
|
+
private m_sel;
|
|
87
|
+
constructor(props: PopupTableProps);
|
|
88
|
+
setRowData(row: number, data: any): void;
|
|
89
|
+
getRowData(row: number): any;
|
|
90
|
+
setCell(row: number, col: number, text: string, cls?: string): void;
|
|
91
|
+
getCell(row: any, col: any): CellData;
|
|
92
|
+
/** @ignore */
|
|
93
|
+
render(): void;
|
|
94
|
+
/**
|
|
95
|
+
* display the popup at a specific position
|
|
96
|
+
* @param x
|
|
97
|
+
* @param y
|
|
98
|
+
*/
|
|
99
|
+
displayAt(x: number, y: number, align?: string): void;
|
|
100
|
+
selNext(next: boolean): number;
|
|
101
|
+
get selection(): number;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
package/lib/smartedit.js
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
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
|
+
import { TextEdit } from './textedit';
|
|
26
|
+
import { Popup } from './popup';
|
|
27
|
+
import { Component } from './component';
|
|
28
|
+
import { EvClick } from './x4_events';
|
|
29
|
+
export class SmartEdit extends TextEdit {
|
|
30
|
+
m_popup;
|
|
31
|
+
m_dataview;
|
|
32
|
+
m_field;
|
|
33
|
+
m_minDisplay;
|
|
34
|
+
m_maxCount;
|
|
35
|
+
m_autoFill;
|
|
36
|
+
m_renderer;
|
|
37
|
+
m_tools;
|
|
38
|
+
m_searchCallback;
|
|
39
|
+
constructor(props) {
|
|
40
|
+
super(props);
|
|
41
|
+
this.m_dataview = props.store.createView();
|
|
42
|
+
this.m_field = props.field;
|
|
43
|
+
this.m_renderer = props.renderer;
|
|
44
|
+
this.m_minDisplay = props.minDisplay ?? 0;
|
|
45
|
+
this.m_maxCount = props.maxCount ?? 10;
|
|
46
|
+
this.m_autoFill = props.autoFill === undefined ? true : props.autoFill;
|
|
47
|
+
this.m_popup = null;
|
|
48
|
+
this.m_tools = props.tools ?? [];
|
|
49
|
+
this.m_searchCallback = props.searchCallback;
|
|
50
|
+
this.on('change', (e) => this._onChange(e));
|
|
51
|
+
this.on('focus', (e) => this._onFocus(e));
|
|
52
|
+
}
|
|
53
|
+
render(props) {
|
|
54
|
+
super.render(props);
|
|
55
|
+
this.m_ui_input.setDomEvent('keydown', (e) => this._onKey(e));
|
|
56
|
+
}
|
|
57
|
+
_onChange(ev) {
|
|
58
|
+
this._showPopup(ev.value);
|
|
59
|
+
}
|
|
60
|
+
_onFocus(ev) {
|
|
61
|
+
if (ev.focus) {
|
|
62
|
+
this._showPopup(this.value);
|
|
63
|
+
}
|
|
64
|
+
else if (this.m_popup) {
|
|
65
|
+
this.m_popup.close();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_onKey(e) {
|
|
69
|
+
console.log(e.key);
|
|
70
|
+
switch (e.key) {
|
|
71
|
+
case 'Backspace': {
|
|
72
|
+
// remove selection
|
|
73
|
+
let start = e.target.selectionStart;
|
|
74
|
+
let end = e.target.selectionEnd;
|
|
75
|
+
if (start > end) {
|
|
76
|
+
let t = start;
|
|
77
|
+
start = end;
|
|
78
|
+
end = t;
|
|
79
|
+
}
|
|
80
|
+
let v = this.value;
|
|
81
|
+
let a = v.substr(0, start);
|
|
82
|
+
let b = v.substr(end);
|
|
83
|
+
this.value = a + b;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'ArrowUp':
|
|
87
|
+
case 'Up': {
|
|
88
|
+
if (this.m_popup) {
|
|
89
|
+
this._moveNext(false);
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'ArrowDown':
|
|
95
|
+
case 'Down': {
|
|
96
|
+
if (this.m_popup) {
|
|
97
|
+
this._moveNext(true);
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case 'Enter': {
|
|
103
|
+
if (this.m_popup) {
|
|
104
|
+
this._checkTool(e);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
_showSugg(text) {
|
|
111
|
+
let sel = this.getSelection();
|
|
112
|
+
this.value = text;
|
|
113
|
+
this.select(sel.start, sel.length);
|
|
114
|
+
}
|
|
115
|
+
isOpen() {
|
|
116
|
+
return this.m_popup !== null;
|
|
117
|
+
}
|
|
118
|
+
componentDisposed() {
|
|
119
|
+
if (this.m_popup) {
|
|
120
|
+
this.m_popup.close();
|
|
121
|
+
}
|
|
122
|
+
super.componentDisposed();
|
|
123
|
+
}
|
|
124
|
+
// enter pressed on an element
|
|
125
|
+
_checkTool(e) {
|
|
126
|
+
let sel = this.m_popup.selection;
|
|
127
|
+
if (this._callTool(sel)) {
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
_callTool(sel) {
|
|
132
|
+
let data = this.m_popup.getRowData(sel);
|
|
133
|
+
if (data) {
|
|
134
|
+
if (this.m_popup) {
|
|
135
|
+
this.m_popup.close();
|
|
136
|
+
}
|
|
137
|
+
data.callback(this);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
_moveNext(next) {
|
|
145
|
+
let sel = this.m_popup.selNext(next);
|
|
146
|
+
console.log('movenext: ', sel);
|
|
147
|
+
let data = this.m_popup.getRowData(sel);
|
|
148
|
+
if (!data) {
|
|
149
|
+
let text = this.m_popup.getCell(sel, 0).text;
|
|
150
|
+
this._showSugg(text);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//_onKey( e: KeyboardEvent ) {
|
|
154
|
+
// if( e.key==' ' ) {
|
|
155
|
+
// this._showPopup( this.value )
|
|
156
|
+
// }
|
|
157
|
+
//}
|
|
158
|
+
_showPopup(v) {
|
|
159
|
+
if (this.m_popup) {
|
|
160
|
+
this.m_popup.close();
|
|
161
|
+
this.m_popup = null;
|
|
162
|
+
}
|
|
163
|
+
let cnt;
|
|
164
|
+
let sel = this.getSelection();
|
|
165
|
+
let search = sel.length ? v.substr(0, sel.start) : v;
|
|
166
|
+
if (search.length < this.m_minDisplay) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
let autoFill = this.m_autoFill;
|
|
170
|
+
if (search.length == 0) {
|
|
171
|
+
cnt = this.m_dataview.filter(null);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
if (this.m_searchCallback) {
|
|
175
|
+
autoFill = this.m_searchCallback(search, this.m_dataview);
|
|
176
|
+
cnt = this.m_dataview.count;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
cnt = this.m_dataview.filter({
|
|
180
|
+
op: '=',
|
|
181
|
+
field: this.m_field,
|
|
182
|
+
value: new RegExp('^' + search.trim() + '.*', 'mi')
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (cnt > 0) {
|
|
187
|
+
let rec = this.m_dataview.getByIndex(0);
|
|
188
|
+
if (autoFill) {
|
|
189
|
+
this.value = rec.getField(this.m_field);
|
|
190
|
+
}
|
|
191
|
+
this.select(v.length);
|
|
192
|
+
let count = Math.min(this.m_dataview.count, this.m_maxCount);
|
|
193
|
+
let r2 = this.m_ui_input.getBoundingRect();
|
|
194
|
+
this.m_popup = new PopupTable({
|
|
195
|
+
cls: '@editor-popup',
|
|
196
|
+
minWidth: r2.width
|
|
197
|
+
});
|
|
198
|
+
this.m_popup.on('click', (ev) => {
|
|
199
|
+
let { row, text } = ev.context;
|
|
200
|
+
if (!this._callTool(row)) {
|
|
201
|
+
this.value = text;
|
|
202
|
+
this.emit('click', EvClick());
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
let i;
|
|
206
|
+
for (i = 0; i < count; i++) {
|
|
207
|
+
let rec = this.m_dataview.getByIndex(i);
|
|
208
|
+
let texts = this.m_renderer(rec);
|
|
209
|
+
this.m_popup.setCell(i, 0, texts[0].text, texts[0].cls);
|
|
210
|
+
this.m_popup.setCell(i, 1, texts[1].text, texts[1].cls);
|
|
211
|
+
}
|
|
212
|
+
for (let j = 0; j < this.m_tools.length; j++, i++) {
|
|
213
|
+
this.m_popup.setCell(i, 0, this.m_tools[j].text);
|
|
214
|
+
this.m_popup.setCell(i, 1, '');
|
|
215
|
+
this.m_popup.setRowData(i, this.m_tools[j]);
|
|
216
|
+
console.log('fill: ', i);
|
|
217
|
+
}
|
|
218
|
+
this.m_popup.displayAt(r2.left, r2.bottom);
|
|
219
|
+
}
|
|
220
|
+
else if (this.m_tools.length) {
|
|
221
|
+
let r2 = this.m_ui_input.getBoundingRect();
|
|
222
|
+
this.m_popup = new PopupTable({
|
|
223
|
+
cls: '@editor-popup',
|
|
224
|
+
minWidth: r2.width
|
|
225
|
+
});
|
|
226
|
+
this.m_popup.on('click', (ev) => {
|
|
227
|
+
let { row, text } = ev.context;
|
|
228
|
+
if (!this._callTool(row)) {
|
|
229
|
+
this.value = text;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
for (let j = 0, i = 0; j < this.m_tools.length; j++, i++) {
|
|
233
|
+
this.m_popup.setCell(i, 0, this.m_tools[j].text);
|
|
234
|
+
this.m_popup.setCell(i, 1, '');
|
|
235
|
+
this.m_popup.setRowData(i, this.m_tools[j]);
|
|
236
|
+
console.log('fill: ', i);
|
|
237
|
+
}
|
|
238
|
+
this.m_popup.displayAt(r2.left, r2.bottom);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
export class PopupTable extends Popup {
|
|
243
|
+
m_rows;
|
|
244
|
+
m_cols;
|
|
245
|
+
m_cells;
|
|
246
|
+
m_data;
|
|
247
|
+
m_minw;
|
|
248
|
+
m_defcell;
|
|
249
|
+
m_sel;
|
|
250
|
+
constructor(props) {
|
|
251
|
+
super(props);
|
|
252
|
+
this.m_rows = props.rows ?? 0;
|
|
253
|
+
this.m_cols = props.cols ?? 0;
|
|
254
|
+
this.m_minw = props.minWidth;
|
|
255
|
+
this.m_cells = new Map();
|
|
256
|
+
this.m_data = new Map();
|
|
257
|
+
this.m_defcell = { text: '', cls: undefined };
|
|
258
|
+
this.m_sel = 0;
|
|
259
|
+
this.enableMask(false);
|
|
260
|
+
this.setDomEvent('create', () => {
|
|
261
|
+
this.dom.cellPadding = '0px';
|
|
262
|
+
});
|
|
263
|
+
this.setDomEvent('mousedown', (e) => {
|
|
264
|
+
e.preventDefault();
|
|
265
|
+
let el = Component.getElement(e.target);
|
|
266
|
+
let row = el.getData('row');
|
|
267
|
+
this.m_sel = row;
|
|
268
|
+
this.update();
|
|
269
|
+
this.emit('click', EvClick({ row, text: this.getCell(row, 0).text }));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
setRowData(row, data) {
|
|
273
|
+
this.m_data.set(row, data);
|
|
274
|
+
}
|
|
275
|
+
getRowData(row) {
|
|
276
|
+
return this.m_data.get(row);
|
|
277
|
+
}
|
|
278
|
+
setCell(row, col, text, cls) {
|
|
279
|
+
this.m_cells.set(_cid(row, col), { text, cls });
|
|
280
|
+
if (this.m_rows < (row + 1)) {
|
|
281
|
+
this.m_rows = (row + 1);
|
|
282
|
+
}
|
|
283
|
+
if (this.m_cols < (col + 1)) {
|
|
284
|
+
this.m_cols = (col + 1);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
getCell(row, col) {
|
|
288
|
+
let cd = this.m_cells.get(_cid(row, col));
|
|
289
|
+
if (cd == null) {
|
|
290
|
+
return this.m_defcell;
|
|
291
|
+
}
|
|
292
|
+
return cd;
|
|
293
|
+
}
|
|
294
|
+
/** @ignore */
|
|
295
|
+
render() {
|
|
296
|
+
this.setProp('tag', 'table');
|
|
297
|
+
if (this.m_minw) {
|
|
298
|
+
this.setStyleValue('minWidth', this.m_minw);
|
|
299
|
+
}
|
|
300
|
+
let rows = [];
|
|
301
|
+
for (let r = 0; r < this.m_rows; r++) {
|
|
302
|
+
let cols = [];
|
|
303
|
+
let data = { row: r };
|
|
304
|
+
for (let c = 0; c < this.m_cols; c++) {
|
|
305
|
+
let cell = this.getCell(r, c);
|
|
306
|
+
let col = new Component({
|
|
307
|
+
tag: 'td',
|
|
308
|
+
content: cell.text,
|
|
309
|
+
cls: cell.cls,
|
|
310
|
+
data
|
|
311
|
+
});
|
|
312
|
+
cols.push(col);
|
|
313
|
+
}
|
|
314
|
+
let cls = undefined;
|
|
315
|
+
if (r === this.m_sel) {
|
|
316
|
+
cls = '@selected';
|
|
317
|
+
}
|
|
318
|
+
let row = new Component({
|
|
319
|
+
tag: 'tr',
|
|
320
|
+
cls,
|
|
321
|
+
content: cols,
|
|
322
|
+
data
|
|
323
|
+
});
|
|
324
|
+
rows.push(row);
|
|
325
|
+
}
|
|
326
|
+
this.setContent(rows);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* display the popup at a specific position
|
|
330
|
+
* @param x
|
|
331
|
+
* @param y
|
|
332
|
+
*/
|
|
333
|
+
displayAt(x, y, align = 'top left') {
|
|
334
|
+
this.show();
|
|
335
|
+
let halign = 'l', valign = 't';
|
|
336
|
+
if (align.indexOf('right') >= 0) {
|
|
337
|
+
halign = 'r';
|
|
338
|
+
}
|
|
339
|
+
if (align.indexOf('bottom') >= 0) {
|
|
340
|
+
valign = 'b';
|
|
341
|
+
}
|
|
342
|
+
// @TODO: this is a minimal overflow problem solution
|
|
343
|
+
let rc = document.body.getBoundingClientRect(), rm = this.getBoundingRect();
|
|
344
|
+
if (halign == 'r') {
|
|
345
|
+
x -= rm.width;
|
|
346
|
+
}
|
|
347
|
+
if (valign == 'b') {
|
|
348
|
+
y -= rm.height;
|
|
349
|
+
}
|
|
350
|
+
if (x < 4) {
|
|
351
|
+
x = 4;
|
|
352
|
+
}
|
|
353
|
+
if ((x + rm.width) > rc.right - 4) {
|
|
354
|
+
x = rc.right - 4 - rm.width;
|
|
355
|
+
}
|
|
356
|
+
if (y < 4) {
|
|
357
|
+
y = 4;
|
|
358
|
+
}
|
|
359
|
+
if ((y + rm.height) > rc.bottom - 4) {
|
|
360
|
+
y = rc.bottom - 4 - rm.height;
|
|
361
|
+
}
|
|
362
|
+
this.setStyle({ left: x, top: y });
|
|
363
|
+
}
|
|
364
|
+
selNext(next) {
|
|
365
|
+
this.m_sel += next ? 1 : -1;
|
|
366
|
+
if (this.m_sel >= this.m_rows) {
|
|
367
|
+
this.m_sel = 0;
|
|
368
|
+
}
|
|
369
|
+
else if (this.m_sel < 0) {
|
|
370
|
+
this.m_sel = this.m_rows - 1;
|
|
371
|
+
}
|
|
372
|
+
this.update();
|
|
373
|
+
return this.m_sel;
|
|
374
|
+
}
|
|
375
|
+
get selection() {
|
|
376
|
+
return this.m_sel;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function _cid(row, col) {
|
|
380
|
+
return row * 1000 + col;
|
|
381
|
+
}
|