x4js 1.6.5 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -14
- package/lib/README.txt +3 -14
- package/lib/src/assets/house-light.svg +1 -0
- package/lib/src/assets/radio.svg +4 -0
- package/lib/src/components/base.scss +26 -0
- package/lib/src/components/boxes/boxes.module.scss +37 -0
- package/lib/src/components/boxes/boxes.ts +125 -0
- package/lib/src/components/btngroup/btngroup.module.scss +29 -0
- package/lib/src/components/btngroup/btngroup.ts +106 -0
- package/lib/src/components/button/button.module.scss +154 -0
- package/lib/src/components/button/button.ts +117 -0
- package/lib/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/lib/src/components/calendar/calendar.module.scss +163 -0
- package/lib/src/{calendar.ts → components/calendar/calendar.ts} +81 -83
- package/lib/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/lib/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/lib/src/components/checkbox/check.svg +4 -0
- package/lib/src/components/checkbox/checkbox.module.scss +142 -0
- package/lib/src/components/checkbox/checkbox.ts +125 -0
- package/lib/src/components/colorinput/colorinput.module.scss +65 -0
- package/lib/src/components/colorinput/colorinput.ts +88 -0
- package/lib/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/lib/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/lib/src/components/colorpicker/colorpicker.ts +477 -0
- package/lib/src/components/combobox/combobox.module.scss +121 -0
- package/lib/src/components/combobox/combobox.ts +190 -0
- package/lib/src/components/combobox/updown.svg +4 -0
- package/lib/src/components/dialog/dialog.module.scss +71 -0
- package/lib/src/components/dialog/dialog.ts +91 -0
- package/lib/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/lib/src/components/form/form.module.scss +34 -0
- package/lib/src/components/form/form.ts +36 -0
- package/lib/src/components/header/header.module.scss +40 -0
- package/lib/src/components/header/header.ts +124 -0
- package/lib/src/components/icon/icon.module.scss +30 -0
- package/lib/src/components/icon/icon.ts +134 -0
- package/lib/src/components/image/image.module.scss +21 -0
- package/lib/src/components/image/image.ts +67 -0
- package/lib/src/components/input/input.module.scss +69 -0
- package/lib/src/components/input/input.ts +274 -0
- package/lib/src/components/label/label.module.scss +52 -0
- package/lib/src/components/label/label.ts +55 -0
- package/lib/src/components/listbox/listbox.module.scss +103 -0
- package/lib/src/components/listbox/listbox.ts +427 -0
- package/lib/src/components/menu/caret-right-solid.svg +1 -0
- package/lib/src/components/menu/menu.module.scss +108 -0
- package/lib/src/components/menu/menu.ts +168 -0
- package/lib/src/components/messages/circle-exclamation.svg +1 -0
- package/lib/src/components/messages/messages.module.scss +47 -0
- package/lib/src/components/messages/messages.ts +64 -0
- package/lib/src/components/normalize.scss +386 -0
- package/lib/src/components/notification/circle-check-solid.svg +1 -0
- package/lib/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/lib/src/components/notification/circle-notch-light.svg +1 -0
- package/lib/src/components/notification/notification.module.scss +82 -0
- package/lib/src/components/notification/notification.ts +108 -0
- package/lib/src/components/notification/xmark-sharp-light.svg +1 -0
- package/lib/src/components/panel/panel.module.scss +48 -0
- package/lib/src/components/panel/panel.ts +57 -0
- package/lib/src/components/popup/popup.module.scss +43 -0
- package/lib/src/components/popup/popup.ts +395 -0
- package/lib/src/components/progress/progress.module.scss +57 -0
- package/lib/src/components/progress/progress.ts +43 -0
- package/lib/src/components/rating/rating.module.scss +23 -0
- package/lib/src/components/rating/rating.ts +125 -0
- package/lib/src/components/rating/star-sharp-light.svg +1 -0
- package/lib/src/components/rating/star-sharp-solid.svg +1 -0
- package/lib/src/components/shared.scss +76 -0
- package/lib/src/components/sizers/sizer.module.scss +90 -0
- package/lib/src/components/sizers/sizer.ts +120 -0
- package/lib/src/components/slider/slider.module.scss +71 -0
- package/lib/src/components/slider/slider.ts +143 -0
- package/lib/src/components/switch/switch.module.scss +127 -0
- package/lib/src/components/switch/switch.ts +56 -0
- package/lib/src/components/tabs/tabs.module.scss +46 -0
- package/lib/src/components/tabs/tabs.ts +157 -0
- package/lib/src/components/textarea/textarea.module.scss +59 -0
- package/lib/src/components/textarea/textarea.ts +54 -0
- package/lib/src/components/textedit/textedit.module.scss +114 -0
- package/lib/src/components/textedit/textedit.ts +82 -0
- package/lib/src/components/themes.scss +77 -0
- package/lib/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +51 -0
- package/lib/src/components/tooltips/tooltips.ts +103 -0
- package/lib/src/components/treeview/chevron-down-light.svg +1 -0
- package/lib/src/components/treeview/treeview.module.scss +116 -0
- package/lib/src/components/treeview/treeview.ts +403 -0
- package/lib/src/components/viewport/viewport.module.scss +25 -0
- package/lib/src/components/viewport/viewport.ts +38 -0
- package/lib/src/core/component.ts +979 -0
- package/lib/src/core/core_colors.ts +250 -0
- package/lib/src/{dom_events.ts → core/core_dom.ts} +195 -39
- package/lib/src/{drag_manager.ts → core/core_dragdrop.ts} +29 -44
- package/lib/src/core/core_element.ts +98 -0
- package/lib/src/core/core_events.ts +149 -0
- package/lib/src/{i18n.ts → core/core_i18n.ts} +43 -42
- package/lib/src/{router.ts → core/core_router.ts} +27 -40
- package/lib/src/core/core_styles.ts +215 -0
- package/lib/src/core/core_svg.ts +550 -0
- package/lib/src/core/core_tools.ts +673 -0
- package/lib/src/main.scss +21 -0
- package/lib/src/main.tsx +323 -0
- package/lib/src/x4.scss +19 -0
- package/lib/types/x4.d.ts +2624 -0
- package/package.json +67 -59
- package/scripts/build.mjs +351 -0
- package/scripts/prepack.mjs +15 -0
- package/src/assets/house-light.svg +1 -0
- package/src/assets/radio.svg +4 -0
- package/src/components/base.scss +26 -0
- package/src/components/boxes/boxes.module.scss +37 -0
- package/src/components/boxes/boxes.ts +125 -0
- package/src/components/btngroup/btngroup.module.scss +29 -0
- package/src/components/btngroup/btngroup.ts +106 -0
- package/src/components/button/button.module.scss +154 -0
- package/src/components/button/button.ts +117 -0
- package/src/components/calendar/calendar-check-sharp-light.svg +1 -0
- package/src/components/calendar/calendar.module.scss +163 -0
- package/src/components/calendar/calendar.ts +326 -0
- package/src/components/calendar/chevron-left-sharp-light.svg +1 -0
- package/src/components/calendar/chevron-right-sharp-light.svg +1 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +125 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +88 -0
- package/src/components/colorinput/crosshairs-simple-sharp-light.svg +1 -0
- package/src/components/colorpicker/colorpicker.module.scss +133 -0
- package/src/components/colorpicker/colorpicker.ts +477 -0
- package/src/components/combobox/combobox.module.scss +121 -0
- package/src/components/combobox/combobox.ts +190 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/dialog/dialog.module.scss +71 -0
- package/src/components/dialog/dialog.ts +91 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/form/form.module.scss +34 -0
- package/src/components/form/form.ts +36 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +124 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +134 -0
- package/src/components/image/image.module.scss +21 -0
- package/src/components/image/image.ts +67 -0
- package/src/components/input/input.module.scss +69 -0
- package/src/components/input/input.ts +274 -0
- package/src/components/label/label.module.scss +52 -0
- package/src/components/label/label.ts +55 -0
- package/src/components/listbox/listbox.module.scss +103 -0
- package/src/components/listbox/listbox.ts +427 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +108 -0
- package/src/components/menu/menu.ts +168 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +47 -0
- package/src/components/messages/messages.ts +64 -0
- package/src/components/normalize.scss +386 -0
- package/src/components/notification/circle-check-solid.svg +1 -0
- package/src/components/notification/circle-exclamation-solid.svg +1 -0
- package/src/components/notification/circle-notch-light.svg +1 -0
- package/src/components/notification/notification.module.scss +82 -0
- package/src/components/notification/notification.ts +108 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +48 -0
- package/src/components/panel/panel.ts +57 -0
- package/src/components/popup/popup.module.scss +43 -0
- package/src/components/popup/popup.ts +395 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +43 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +125 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/shared.scss +76 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +120 -0
- package/src/components/slider/slider.module.scss +71 -0
- package/src/components/slider/slider.ts +143 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +56 -0
- package/src/components/tabs/tabs.module.scss +46 -0
- package/src/components/tabs/tabs.ts +157 -0
- package/src/components/textarea/textarea.module.scss +59 -0
- package/src/components/textarea/textarea.ts +54 -0
- package/src/components/textedit/textedit.module.scss +114 -0
- package/src/components/textedit/textedit.ts +82 -0
- package/src/components/themes.scss +77 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/tooltips.scss +51 -0
- package/src/components/tooltips/tooltips.ts +103 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +116 -0
- package/src/components/treeview/treeview.ts +403 -0
- package/src/components/viewport/viewport.module.scss +25 -0
- package/src/components/viewport/viewport.ts +38 -0
- package/src/core/component.ts +979 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +98 -0
- package/src/core/core_events.ts +149 -0
- package/src/core/core_i18n.ts +377 -0
- package/src/core/core_router.ts +221 -0
- package/src/core/core_styles.ts +215 -0
- package/src/core/core_svg.ts +550 -0
- package/src/core/core_tools.ts +673 -0
- package/src/main.scss +21 -0
- package/src/main.tsx +323 -0
- package/src/x4.scss +19 -0
- package/tsconfig.json +14 -0
- package/types/scss.d.ts +4 -0
- package/types/svg.d.ts +4 -0
- package/types/x4react.d.ts +9 -0
- package/lib/changelog.txt +0 -23
- package/lib/cjs/x4js.js +0 -39
- package/lib/cjs/x4js.js.map +0 -7
- package/lib/esm/x4js.mjs +0 -15972
- package/lib/esm/x4js.mjs.map +0 -7
- package/lib/licence.md +0 -21
- package/lib/src/MIT-license.md +0 -14
- package/lib/src/action.ts +0 -88
- package/lib/src/alpha.jpg +0 -0
- package/lib/src/app_sockets.ts +0 -81
- package/lib/src/application.ts +0 -262
- package/lib/src/autocomplete.ts +0 -232
- package/lib/src/base64.ts +0 -166
- package/lib/src/base_component.ts +0 -152
- package/lib/src/button.ts +0 -355
- package/lib/src/canvas.ts +0 -510
- package/lib/src/cardview.ts +0 -228
- package/lib/src/checkbox.ts +0 -188
- package/lib/src/color.ts +0 -752
- package/lib/src/colorpicker.ts +0 -1649
- package/lib/src/combobox.ts +0 -512
- package/lib/src/component.ts +0 -2367
- package/lib/src/copyright.txt +0 -27
- package/lib/src/datastore.ts +0 -1302
- package/lib/src/dialog.ts +0 -656
- package/lib/src/drawtext.ts +0 -355
- package/lib/src/fileupload.ts +0 -213
- package/lib/src/form.ts +0 -413
- package/lib/src/formatters.ts +0 -105
- package/lib/src/gridview.ts +0 -1185
- package/lib/src/icon.ts +0 -362
- package/lib/src/image.ts +0 -225
- package/lib/src/index.ts +0 -89
- package/lib/src/input.ts +0 -297
- package/lib/src/label.ts +0 -153
- package/lib/src/layout.ts +0 -442
- package/lib/src/link.ts +0 -86
- package/lib/src/listview.ts +0 -765
- package/lib/src/md5.ts +0 -438
- package/lib/src/menu.ts +0 -425
- package/lib/src/messagebox.ts +0 -224
- package/lib/src/panel.ts +0 -86
- package/lib/src/popup.ts +0 -494
- package/lib/src/property_editor.ts +0 -337
- package/lib/src/radiobtn.ts +0 -197
- package/lib/src/rating.ts +0 -135
- package/lib/src/request.ts +0 -300
- package/lib/src/settings.ts +0 -77
- package/lib/src/sidebarview.ts +0 -108
- package/lib/src/spreadsheet.ts +0 -1449
- package/lib/src/styles.ts +0 -343
- package/lib/src/svgcomponent.ts +0 -592
- package/lib/src/tabbar.ts +0 -151
- package/lib/src/tabview.ts +0 -110
- package/lib/src/textarea.ts +0 -235
- package/lib/src/textedit.ts +0 -533
- package/lib/src/toaster.ts +0 -80
- package/lib/src/tools.ts +0 -1473
- package/lib/src/tooltips.ts +0 -191
- package/lib/src/treeview.ts +0 -716
- package/lib/src/version.ts +0 -30
- package/lib/src/x4.less +0 -2242
- package/lib/src/x4dom.ts +0 -57
- package/lib/src/x4events.ts +0 -585
- package/lib/src/x4js.ts +0 -89
- package/lib/src/x4react.ts +0 -90
- package/lib/styles/x4.css +0 -1785
- package/lib/styles/x4.less +0 -2242
- package/lib/types/x4js.d.ts +0 -6728
- package/license.md +0 -21
package/lib/src/spreadsheet.ts
DELETED
|
@@ -1,1449 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ___ ___ __
|
|
3
|
-
* \ \_/ / / _
|
|
4
|
-
* \ / /_| |_
|
|
5
|
-
* / _ \____ _|
|
|
6
|
-
* /__/ \__\ |_|
|
|
7
|
-
*
|
|
8
|
-
* @file spreadsheet.ts
|
|
9
|
-
* @author Etienne Cochard
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2019-2023 R-libre ingenierie
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
17
|
-
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
-
* subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all copies
|
|
20
|
-
* or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
23
|
-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
24
|
-
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
-
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
26
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
27
|
-
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
import { x4document } from './x4dom'
|
|
31
|
-
|
|
32
|
-
import { Component, SizerOverlay, EvDblClick, EvSize, ContainerEventMap, ContainerProps } from './component'
|
|
33
|
-
import { Input, InputProps } from './input';
|
|
34
|
-
import { HLayout, VLayout } from './layout';
|
|
35
|
-
import { TextEditProps, TextEdit } from './textedit';
|
|
36
|
-
import { FormatFunc } from './formatters'
|
|
37
|
-
import { asap, parseIntlFloat } from './tools';
|
|
38
|
-
import { deferCall } from './tools';
|
|
39
|
-
import { EvContextMenu, EvChange, EvSelectionChange, EventCallback } from './x4events'
|
|
40
|
-
import { ComboBox } from './combobox';
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export interface EditorFactory {
|
|
44
|
-
(props: InputProps, row: number, col: number) : Component;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
export interface ColProp {
|
|
53
|
-
title: string;
|
|
54
|
-
width: number;
|
|
55
|
-
formatter?: string;
|
|
56
|
-
align?: string;
|
|
57
|
-
cls?: string;
|
|
58
|
-
min_width?: number;
|
|
59
|
-
renderer?: FormatFunc;
|
|
60
|
-
createEditor?: EditorFactory; // null => disable edition
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
class CellData {
|
|
64
|
-
text: string;
|
|
65
|
-
cls?: string;
|
|
66
|
-
|
|
67
|
-
static empty_cell: CellData = {
|
|
68
|
-
text: ''
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
export interface SpreadsheetEventSet extends ContainerEventMap {
|
|
77
|
-
change?: EvChange;
|
|
78
|
-
dblClick?: EvDblClick;
|
|
79
|
-
selectionChange?: EvSelectionChange;
|
|
80
|
-
contextMenu?: EvContextMenu;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
export interface SpreadsheetProps extends ContainerProps {
|
|
89
|
-
columns: ColProp[];
|
|
90
|
-
maxrows?: number;
|
|
91
|
-
autoedit?: boolean;
|
|
92
|
-
|
|
93
|
-
change?: EventCallback<EvChange>; // shortcut to event { change: ... }
|
|
94
|
-
dblClick?: EventCallback<EvDblClick>;// shortcut to event { dblclick: ... }
|
|
95
|
-
selectionChange?: EventCallback<EvSelectionChange>;// shortcut to event { selectionChange: ... }
|
|
96
|
-
contextMenu?: EventCallback<EvContextMenu>;// shortcut to event { contextMenu: ... }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
export class Spreadsheet extends VLayout<SpreadsheetProps, SpreadsheetEventSet> {
|
|
105
|
-
|
|
106
|
-
private m_columns: ColProp[];
|
|
107
|
-
private m_row_limit: number;
|
|
108
|
-
private m_cells_data: Map<number, CellData>;
|
|
109
|
-
private m_rows_data: Map<number, string>;
|
|
110
|
-
|
|
111
|
-
protected m_view: Component;
|
|
112
|
-
protected m_container: Component;
|
|
113
|
-
protected m_header: Component;
|
|
114
|
-
|
|
115
|
-
private m_itemHeight: number;
|
|
116
|
-
private m_topIndex: number;
|
|
117
|
-
|
|
118
|
-
private m_visible_cells: Map<number, Component>;
|
|
119
|
-
private m_row_count: number; // visible row count
|
|
120
|
-
|
|
121
|
-
private m_selection: { row: number, col: number };
|
|
122
|
-
private m_editor: Component;
|
|
123
|
-
private m_autoedit: boolean;
|
|
124
|
-
private m_lockupdate: number;
|
|
125
|
-
private m_auto_row_count: boolean;
|
|
126
|
-
|
|
127
|
-
private m_recycler: Component[];
|
|
128
|
-
private m_used_cells: Component[];
|
|
129
|
-
|
|
130
|
-
constructor(props: SpreadsheetProps) {
|
|
131
|
-
super(props);
|
|
132
|
-
|
|
133
|
-
this.m_columns = props.columns;
|
|
134
|
-
this.m_autoedit = props.autoedit;
|
|
135
|
-
this.m_lockupdate = 0;
|
|
136
|
-
|
|
137
|
-
this.m_cells_data = new Map<number, CellData>();
|
|
138
|
-
this.m_rows_data = new Map<number, string>();
|
|
139
|
-
this.m_itemHeight = 0;
|
|
140
|
-
this.m_selection = { row: 0, col: 0 };
|
|
141
|
-
this.m_row_count = 0;
|
|
142
|
-
this.m_auto_row_count = false;
|
|
143
|
-
this.m_recycler = [];
|
|
144
|
-
this.m_used_cells = [];
|
|
145
|
-
|
|
146
|
-
if (props.maxrows === undefined) {
|
|
147
|
-
this.m_row_limit = 0;
|
|
148
|
-
this.m_auto_row_count = true;
|
|
149
|
-
}
|
|
150
|
-
else if (props.maxrows < 0) {
|
|
151
|
-
this.m_row_limit = 0;
|
|
152
|
-
this.m_auto_row_count = true;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.m_row_limit = props.maxrows;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.setAttribute('tabindex', 0);
|
|
159
|
-
|
|
160
|
-
this.setDomEvent('click', (e) => this._itemClick(e) );
|
|
161
|
-
this.setDomEvent('dblclick', (e) => this._itemDblClick(e) );
|
|
162
|
-
this.setDomEvent('keydown', (e) => this._handleKey(e) );
|
|
163
|
-
this.setDomEvent('keypress', (e) => this._keyPress(e) );
|
|
164
|
-
this.setDomEvent('focus', () => this._focus(true));
|
|
165
|
-
this.setDomEvent('focusout', () => this._focus(false));
|
|
166
|
-
this.setDomEvent('contextmenu', (e) => this._ctxMenu(e));
|
|
167
|
-
|
|
168
|
-
this.mapPropEvents( props, 'dblClick', 'selectionChange', 'contextMenu', 'change' );
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
componentCreated() {
|
|
172
|
-
super.componentCreated( );
|
|
173
|
-
this._updateScroll(true);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
setColWidth(col: number, width: number) {
|
|
177
|
-
this._on_col_resize(col, width);
|
|
178
|
-
this.update(10);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
getColWidth(col: number): number {
|
|
182
|
-
if (!this.m_columns[col]) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return this.m_columns[col].width;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
setColTitle(col: number, title: string) {
|
|
190
|
-
console.assert(this.m_columns[col] !== undefined); // what ?
|
|
191
|
-
this.m_columns[col].title = title;
|
|
192
|
-
this.update(10);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* reset the spreadsheet
|
|
197
|
-
* @param columns
|
|
198
|
-
*/
|
|
199
|
-
reset(columns?: ColProp[]) {
|
|
200
|
-
if( columns ) {
|
|
201
|
-
this.m_columns = columns;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
this.m_cells_data = new Map<number, CellData>();
|
|
205
|
-
this.m_rows_data = new Map<number, string>();
|
|
206
|
-
this.update(10);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* insert a row
|
|
211
|
-
* @param before row number before wich insert the new row
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
public insertRow(before: number) {
|
|
215
|
-
|
|
216
|
-
let new_cells_data = new Map<number, CellData>();
|
|
217
|
-
this.m_cells_data.forEach((celldata, key) => {
|
|
218
|
-
|
|
219
|
-
let { row, col } = _getid(key);
|
|
220
|
-
|
|
221
|
-
if (row >= before) {
|
|
222
|
-
new_cells_data.set(_mkid(row + 1, col), celldata);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
new_cells_data.set(key, celldata);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
let new_rows_data = new Map<number, string>();
|
|
230
|
-
this.m_rows_data.forEach((rowdata, row) => {
|
|
231
|
-
|
|
232
|
-
if (row >= before) {
|
|
233
|
-
new_rows_data.set(row + 1, rowdata);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
new_rows_data.set(row, rowdata);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
this.m_cells_data = new_cells_data;
|
|
241
|
-
this.m_rows_data = new_rows_data;
|
|
242
|
-
|
|
243
|
-
this._buildItems();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* remove a row
|
|
248
|
-
* @param rowtodel row number to remove
|
|
249
|
-
*/
|
|
250
|
-
|
|
251
|
-
public deleteRow(rowtodel: number) {
|
|
252
|
-
let new_cells_data = new Map<number, CellData>();
|
|
253
|
-
let new_rows_data = new Map<number, string>();
|
|
254
|
-
|
|
255
|
-
this.m_cells_data.forEach((celldata, key) => {
|
|
256
|
-
|
|
257
|
-
let { row, col } = _getid(key);
|
|
258
|
-
|
|
259
|
-
if (row > rowtodel) {
|
|
260
|
-
new_cells_data.set(_mkid(row - 1, col), celldata);
|
|
261
|
-
}
|
|
262
|
-
else if (row < rowtodel) {
|
|
263
|
-
new_cells_data.set(key, celldata);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
this.m_rows_data.forEach((rowdata, row) => {
|
|
268
|
-
|
|
269
|
-
if (row > rowtodel) {
|
|
270
|
-
new_rows_data.set(row - 1, rowdata);
|
|
271
|
-
}
|
|
272
|
-
else if (row < rowtodel) {
|
|
273
|
-
new_rows_data.set(row, rowdata);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
this.m_cells_data = new_cells_data;
|
|
278
|
-
this.m_rows_data = new_rows_data;
|
|
279
|
-
|
|
280
|
-
this._buildItems();
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* insert a new column
|
|
285
|
-
* @param before column index before to insert the new column or <0 to append
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
public insertCol(before: number, column: ColProp) {
|
|
289
|
-
|
|
290
|
-
let inspos = before;
|
|
291
|
-
if (inspos < 0) {
|
|
292
|
-
inspos = this.m_columns.length + 1;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// insert the col at the right place
|
|
296
|
-
this.m_columns.splice(inspos, 0, column);
|
|
297
|
-
|
|
298
|
-
if (before >= 0) {
|
|
299
|
-
let new_cells_data = new Map<number, CellData>();
|
|
300
|
-
|
|
301
|
-
this.m_cells_data.forEach((celldata, key) => {
|
|
302
|
-
|
|
303
|
-
let { row, col } = _getid(key);
|
|
304
|
-
|
|
305
|
-
if (col >= before) {
|
|
306
|
-
new_cells_data.set(_mkid(row, col + 1), celldata);
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
new_cells_data.set(key, celldata);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
this.m_cells_data = new_cells_data;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
this.update();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* remove a column
|
|
321
|
-
* @param coltodel
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
public deleteCol(coltodel: number) {
|
|
325
|
-
|
|
326
|
-
// insert the col at the right place
|
|
327
|
-
this.m_columns.splice(coltodel, 1);
|
|
328
|
-
|
|
329
|
-
let new_cells_data = new Map<number, CellData>();
|
|
330
|
-
this.m_cells_data.forEach((celldata, key) => {
|
|
331
|
-
|
|
332
|
-
let { row, col } = _getid(key);
|
|
333
|
-
|
|
334
|
-
if (col > coltodel) {
|
|
335
|
-
new_cells_data.set(_mkid(row, col - 1), celldata);
|
|
336
|
-
}
|
|
337
|
-
else if (col < coltodel) {
|
|
338
|
-
new_cells_data.set(key, celldata);
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
this.m_cells_data = new_cells_data;
|
|
343
|
-
this.update();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
*
|
|
348
|
-
* @param row
|
|
349
|
-
* @param col
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
private _getCellData(row: number, col: number, raw: boolean = false): CellData {
|
|
353
|
-
let value = this.m_cells_data.get(_mkid(row, col));
|
|
354
|
-
if (value === undefined) {
|
|
355
|
-
return raw ? null : CellData.empty_cell;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return value;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
private _focus(focus: boolean) {
|
|
362
|
-
this.setClass('@focus', focus);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
private _ctxMenu(e) {
|
|
366
|
-
|
|
367
|
-
let dom = e.target,
|
|
368
|
-
self = this.dom;
|
|
369
|
-
|
|
370
|
-
while (dom && dom != self) {
|
|
371
|
-
let itm = Component.getElement(dom),
|
|
372
|
-
row = itm.getData('row-id'),
|
|
373
|
-
col = itm.getData('col-id');
|
|
374
|
-
|
|
375
|
-
if (row !== undefined) {
|
|
376
|
-
this._selectItem(row, col);
|
|
377
|
-
this.emit( 'contextMenu', EvContextMenu(e, { row, col, item: itm }));
|
|
378
|
-
e.preventDefault();
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
dom = dom.parentElement;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/** @ignore */
|
|
387
|
-
|
|
388
|
-
render() {
|
|
389
|
-
|
|
390
|
-
this.m_recycler = [];
|
|
391
|
-
this.m_container = new Component({
|
|
392
|
-
cls: 'content',
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
this.m_view = new Component({
|
|
396
|
-
cls: '@scroll-view',
|
|
397
|
-
flex: 1,
|
|
398
|
-
dom_events: {
|
|
399
|
-
sizechange: ( ) => this._updateScroll(true),
|
|
400
|
-
scroll: ( ) => this._updateScroll(false)
|
|
401
|
-
},
|
|
402
|
-
content: this.m_container
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
let cols = this.m_columns.map((col, index) => {
|
|
406
|
-
|
|
407
|
-
let comp = new Component({
|
|
408
|
-
cls: '@cell c'+index,
|
|
409
|
-
content: col.title ? col.title : ' ',
|
|
410
|
-
flex: col.width < 0 ? -col.width : undefined,
|
|
411
|
-
attrs: {
|
|
412
|
-
title: col.title
|
|
413
|
-
},
|
|
414
|
-
style: {
|
|
415
|
-
width: col.width >= 0 ? col.width : undefined,
|
|
416
|
-
minWidth: col.min_width
|
|
417
|
-
},
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
new SizerOverlay({
|
|
421
|
-
target: comp,
|
|
422
|
-
sens: 'right',
|
|
423
|
-
resize: (ev: EvSize) => {
|
|
424
|
-
this._on_col_resize(index, ev.size.width);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
(<any>col).$col = comp;
|
|
429
|
-
return comp;
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
this.m_header = new HLayout({
|
|
433
|
-
cls: '@header',
|
|
434
|
-
content: <any>cols,
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
this.setContent([
|
|
438
|
-
this.m_header,
|
|
439
|
-
this.m_view
|
|
440
|
-
]);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
*
|
|
445
|
-
*/
|
|
446
|
-
|
|
447
|
-
private _on_col_resize(col, width) {
|
|
448
|
-
|
|
449
|
-
if (!this.m_columns[col]) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// -> flex
|
|
454
|
-
if (width <= 0) {
|
|
455
|
-
this.m_columns[col].width = -1; // flex default
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
this.m_columns[col].width = width;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
this._updateScroll(true);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* compute misc dimensions
|
|
466
|
-
* - item height
|
|
467
|
-
* - scroll width
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
|
-
private _computeItemHeight() {
|
|
471
|
-
let g1 = x4document.createElement('div');
|
|
472
|
-
g1.classList.add('x-spreadsheet');
|
|
473
|
-
|
|
474
|
-
let g2 = x4document.createElement('div');
|
|
475
|
-
g2.classList.add('content');
|
|
476
|
-
|
|
477
|
-
let g3 = x4document.createElement('div');
|
|
478
|
-
g3.classList.add('x-cell');
|
|
479
|
-
g3.append( ' ' )
|
|
480
|
-
|
|
481
|
-
g2.appendChild(g3);
|
|
482
|
-
g1.appendChild(g2);
|
|
483
|
-
|
|
484
|
-
this.dom.appendChild(g1);
|
|
485
|
-
let rc = g3.getBoundingClientRect();
|
|
486
|
-
this.dom.removeChild(g1);
|
|
487
|
-
|
|
488
|
-
this.m_itemHeight = rc.height;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* compute columns widths
|
|
493
|
-
* use col.width for fixed size columns
|
|
494
|
-
* if col.width < 0 that mean that this is a proportion of the remaining space
|
|
495
|
-
*/
|
|
496
|
-
|
|
497
|
-
private _calcColWidths(width: number) {
|
|
498
|
-
|
|
499
|
-
let fullw = 0;
|
|
500
|
-
let nwide = 0;
|
|
501
|
-
|
|
502
|
-
let calcw = new Int32Array(this.m_columns.length);
|
|
503
|
-
let calcz = new Int32Array(this.m_columns.length);
|
|
504
|
-
let calcm = new Int32Array(this.m_columns.length);
|
|
505
|
-
|
|
506
|
-
this.m_columns.forEach((col, colIdx) => {
|
|
507
|
-
|
|
508
|
-
let minw = Math.max(10, col.min_width ?? 0);
|
|
509
|
-
|
|
510
|
-
if (col.width > 0) {
|
|
511
|
-
let cw = Math.max(col.width, minw);
|
|
512
|
-
fullw += cw;
|
|
513
|
-
calcw[colIdx] = cw;
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
let z = -col.width;
|
|
517
|
-
calcz[colIdx] = z;
|
|
518
|
-
nwide += z;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
calcm[colIdx] = minw;
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
if (nwide) {
|
|
525
|
-
let restw = width - fullw;
|
|
526
|
-
|
|
527
|
-
for (let i = 0; i < this.m_columns.length && nwide; i++) {
|
|
528
|
-
|
|
529
|
-
if (!calcw[i]) {
|
|
530
|
-
let rest = Math.round(restw / nwide) * calcz[i];
|
|
531
|
-
if (rest < calcm[i]) {
|
|
532
|
-
rest = calcm[i];
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
calcw[i] = rest;
|
|
536
|
-
restw -= rest;
|
|
537
|
-
nwide -= calcz[i];
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return calcw;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* create a cell (component)
|
|
547
|
-
* and append it to the parent view
|
|
548
|
-
* if a cell was reviously recyled, use it
|
|
549
|
-
*/
|
|
550
|
-
private _createCell(): Component {
|
|
551
|
-
|
|
552
|
-
let cell;
|
|
553
|
-
if (this.m_recycler.length) {
|
|
554
|
-
cell = this.m_recycler.pop();
|
|
555
|
-
cell.clearClasses();
|
|
556
|
-
cell.addClass( '@comp' ); // todo: find better to reset to default
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
cell = new Component({
|
|
560
|
-
cls: '@cell'
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (!cell.dom) {
|
|
565
|
-
this.m_container.appendChild(cell);
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return cell;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* build cells of the spreadsheet
|
|
573
|
-
* cells are recycled when scrolling,
|
|
574
|
-
* only visibles cells exists
|
|
575
|
-
*/
|
|
576
|
-
|
|
577
|
-
private _buildItems() {
|
|
578
|
-
|
|
579
|
-
let rc = this.getBoundingRect();
|
|
580
|
-
let rh = this.m_header.getBoundingRect();
|
|
581
|
-
let height = rc.height - rh.height;
|
|
582
|
-
|
|
583
|
-
if (this.m_itemHeight == 0) {
|
|
584
|
-
this._computeItemHeight();
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
let top = this.m_topIndex * this.m_itemHeight;
|
|
588
|
-
let y = 0;
|
|
589
|
-
let cidx = 0;
|
|
590
|
-
let rowIdx = this.m_topIndex;
|
|
591
|
-
let count = this.m_row_limit;
|
|
592
|
-
|
|
593
|
-
if (this.m_auto_row_count) {
|
|
594
|
-
//@review should be evaluated only when row count change
|
|
595
|
-
this.m_row_limit = count = this.getMaxRowCount();
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
let right_pos = 0;
|
|
599
|
-
if ((count * this.m_itemHeight) > height) {
|
|
600
|
-
let w = Component.getScrollbarSize();
|
|
601
|
-
rc.width -= w;
|
|
602
|
-
right_pos = w;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
let even = this.m_topIndex & 1 ? true : false;
|
|
606
|
-
this.m_visible_cells = new Map<number, Component>();
|
|
607
|
-
|
|
608
|
-
// passe 0 - all created cells are moved to the recycler
|
|
609
|
-
this.m_used_cells.forEach((c) => {
|
|
610
|
-
this.m_recycler.push(c);
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
this.m_used_cells = [];
|
|
614
|
-
|
|
615
|
-
// pass 1 - compute column widths
|
|
616
|
-
let calcw = this._calcColWidths(rc.width);
|
|
617
|
-
|
|
618
|
-
//
|
|
619
|
-
let full_width = 0;
|
|
620
|
-
for (let i = 0; i < calcw.length; i++) {
|
|
621
|
-
full_width += calcw[i];
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (full_width <= rc.width) {
|
|
625
|
-
|
|
626
|
-
this.m_view.setStyleValue('overflow-x', 'hidden');
|
|
627
|
-
this.m_header.setStyleValue('width', rc.width);
|
|
628
|
-
this.m_container.setStyleValue('width', rc.width);
|
|
629
|
-
|
|
630
|
-
this.m_container.setStyle({
|
|
631
|
-
height: count * this.m_itemHeight,
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
else {
|
|
635
|
-
this.m_header.setStyleValue('width', full_width);
|
|
636
|
-
this.m_container.setStyleValue('width', full_width);
|
|
637
|
-
this.m_view.setStyleValue('overflow-x', 'visible');
|
|
638
|
-
|
|
639
|
-
this.m_container.setStyle({
|
|
640
|
-
height: count * this.m_itemHeight,
|
|
641
|
-
width: full_width
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
this.m_view.addClass('@hidden');
|
|
646
|
-
|
|
647
|
-
// pass 2 - build cells
|
|
648
|
-
let limit = 100;
|
|
649
|
-
while (y < height && rowIdx < count && --limit > 0) {
|
|
650
|
-
|
|
651
|
-
let rowdata = this.m_rows_data.get(rowIdx);
|
|
652
|
-
let x = 0;
|
|
653
|
-
|
|
654
|
-
let cols = this.m_columns.map((col, colIdx) => {
|
|
655
|
-
|
|
656
|
-
let cls = '@cell c'+colIdx ;
|
|
657
|
-
if (col.align) {
|
|
658
|
-
cls += ' ' + col.align;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (col.cls) {
|
|
662
|
-
cls += ' ' + col.cls;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
let cell: Component;
|
|
666
|
-
let celldata = this._getCellData(rowIdx, colIdx);
|
|
667
|
-
|
|
668
|
-
let text: string = celldata.text;
|
|
669
|
-
|
|
670
|
-
if (col.renderer && text.length) {
|
|
671
|
-
text = col.renderer(text, { row: rowIdx, col: colIdx });
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
//if( text.length==0 ) {
|
|
675
|
-
// text = ' '
|
|
676
|
-
//}
|
|
677
|
-
|
|
678
|
-
cls += (even ? ' even' : ' odd');
|
|
679
|
-
if (rowdata) {
|
|
680
|
-
cls += ' ' + rowdata;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
cell = this._createCell();
|
|
684
|
-
this.m_used_cells.push(cell);
|
|
685
|
-
|
|
686
|
-
cell.setContent(text); // always because cell reuse
|
|
687
|
-
|
|
688
|
-
cell.addClass(cls);
|
|
689
|
-
cell.setStyle({
|
|
690
|
-
left: x,
|
|
691
|
-
top: top + y,
|
|
692
|
-
width: calcw[colIdx],
|
|
693
|
-
height: this.m_itemHeight
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
if (this.m_selection.row == rowIdx && this.m_selection.col == colIdx) {
|
|
697
|
-
cell.addClass('@selected');
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
cell.setData('row-id', rowIdx);
|
|
701
|
-
cell.setData('col-id', colIdx);
|
|
702
|
-
|
|
703
|
-
if (celldata.cls) {
|
|
704
|
-
cell.addClass(celldata.cls);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
this.m_visible_cells.set(_mkid(rowIdx, colIdx), cell);
|
|
708
|
-
|
|
709
|
-
x += calcw[colIdx];
|
|
710
|
-
return cell;
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
even = !even;
|
|
714
|
-
|
|
715
|
-
y += this.m_itemHeight;
|
|
716
|
-
|
|
717
|
-
rowIdx++;
|
|
718
|
-
cidx++;
|
|
719
|
-
|
|
720
|
-
//rows.splice( rows.length, 0, ...cols );
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// if some cells are still in cache, hide them
|
|
724
|
-
this.m_recycler.forEach((c) => {
|
|
725
|
-
c.addClass('@hidden');
|
|
726
|
-
})
|
|
727
|
-
|
|
728
|
-
this.m_row_count = cidx;
|
|
729
|
-
//this.m_container.setContent( <ComponentContent>rows);
|
|
730
|
-
|
|
731
|
-
this.m_view.removeClass('@hidden');
|
|
732
|
-
this.setClass('empty', count == 0);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/** @ignore */
|
|
736
|
-
private _itemClick(e: MouseEvent) {
|
|
737
|
-
let dom = e.target as HTMLElement;
|
|
738
|
-
if (this.m_editor && this.m_editor.dom.contains(dom)) {
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
let itm = Component.getElement(dom, Component);
|
|
743
|
-
|
|
744
|
-
if (!itm) {
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
let rowIdx = itm.getData('row-id'),
|
|
749
|
-
colIdx = itm.getData('col-id');
|
|
750
|
-
|
|
751
|
-
if (rowIdx === undefined || colIdx === undefined) {
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
this._selectItem(rowIdx, colIdx);
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
private _itemDblClick(e: MouseEvent) {
|
|
759
|
-
let dom = e.target as HTMLElement;
|
|
760
|
-
if (this.m_editor && this.m_editor.dom.contains(dom)) {
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
let itm = Component.getElement(dom),
|
|
765
|
-
rowIdx = itm.getData('row-id'),
|
|
766
|
-
colIdx = itm.getData('col-id');
|
|
767
|
-
|
|
768
|
-
if (rowIdx === undefined || colIdx === undefined) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
this.emit( 'dblClick', EvDblClick({ row: rowIdx, col: colIdx }));
|
|
773
|
-
this.editCell(rowIdx, colIdx);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
/**
|
|
777
|
-
*
|
|
778
|
-
* @param rowIdx
|
|
779
|
-
* @param colIdx
|
|
780
|
-
* @param scrollIntoView
|
|
781
|
-
*/
|
|
782
|
-
|
|
783
|
-
protected _selectItem(rowIdx: number, colIdx: number, scrollIntoView?: boolean) {
|
|
784
|
-
|
|
785
|
-
if (rowIdx < 0) {
|
|
786
|
-
rowIdx = 0;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
if (rowIdx > this.m_row_limit - 1) {
|
|
790
|
-
rowIdx = this.m_row_limit - 1;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
if (colIdx < 0) {
|
|
794
|
-
colIdx = 0;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
let lastcol = this.m_columns.length - 1;
|
|
798
|
-
if (colIdx > lastcol) {
|
|
799
|
-
colIdx = lastcol;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
if (this.m_selection.row == rowIdx && this.m_selection.col == colIdx) {
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
this.select(rowIdx, colIdx, scrollIntoView);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
private _scrollIntoView(row: number, col: number) {
|
|
810
|
-
|
|
811
|
-
let doscroll = (itm: Component, mode: string = 'nearest') => {
|
|
812
|
-
itm.scrollIntoView({
|
|
813
|
-
block: <ScrollLogicalPosition>mode //<ScrollLogicalPosition>sens ?? 'nearest'
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
let last = this.m_topIndex + this.m_row_count - 1;
|
|
818
|
-
|
|
819
|
-
if (row < this.m_topIndex) {
|
|
820
|
-
this.m_topIndex = row;
|
|
821
|
-
this.m_view.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
|
|
822
|
-
this._buildItems();
|
|
823
|
-
doscroll(this._findItem(row, col), 'start');
|
|
824
|
-
}
|
|
825
|
-
else if (row > last) {
|
|
826
|
-
this.m_topIndex = row - this.m_row_count + 1;
|
|
827
|
-
this.m_view.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
|
|
828
|
-
this._buildItems();
|
|
829
|
-
doscroll(this._findItem(row, col), 'end');
|
|
830
|
-
}
|
|
831
|
-
else {
|
|
832
|
-
doscroll(this._findItem(row, col));
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
/**
|
|
837
|
-
*
|
|
838
|
-
* @param row
|
|
839
|
-
* @param col
|
|
840
|
-
*/
|
|
841
|
-
|
|
842
|
-
private _findItem(row, col): Component {
|
|
843
|
-
if (!this.m_visible_cells) {
|
|
844
|
-
return null;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
return this.m_visible_cells.get(_mkid(row, col));
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
*
|
|
852
|
-
*/
|
|
853
|
-
|
|
854
|
-
private _updateScroll(forceUpdate) {
|
|
855
|
-
if (!this?.m_view?.dom) {
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
let newTop = Math.floor(this.m_view.dom.scrollTop / (this.m_itemHeight || 1));
|
|
860
|
-
|
|
861
|
-
if (newTop != this.m_topIndex || forceUpdate) {
|
|
862
|
-
this.m_topIndex = newTop;
|
|
863
|
-
this._buildItems();
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
let newLeft = this.m_view.dom.scrollLeft;
|
|
867
|
-
this.m_header.setStyleValue('left', -newLeft);
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
*
|
|
872
|
-
* @param event
|
|
873
|
-
* @param t
|
|
874
|
-
*/
|
|
875
|
-
|
|
876
|
-
private _moveSel(sensy: number, sensx: number) {
|
|
877
|
-
|
|
878
|
-
let sel = this.m_selection;
|
|
879
|
-
|
|
880
|
-
let newRow = sel.row ?? 0;
|
|
881
|
-
let newCol = sel.col ?? 0;
|
|
882
|
-
|
|
883
|
-
if (sensy == 1) {
|
|
884
|
-
newRow++;
|
|
885
|
-
}
|
|
886
|
-
else if (sensy == -1) {
|
|
887
|
-
newRow--;
|
|
888
|
-
}
|
|
889
|
-
else if (sensy == 2) {
|
|
890
|
-
newRow += this.m_row_count - 1;
|
|
891
|
-
}
|
|
892
|
-
else if (sensy == -2) {
|
|
893
|
-
newRow -= this.m_row_count - 1;
|
|
894
|
-
}
|
|
895
|
-
else if (sensy == 3) {
|
|
896
|
-
newRow = this.m_row_limit - 1;
|
|
897
|
-
}
|
|
898
|
-
else if (sensy == -3) {
|
|
899
|
-
newRow = 0;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
if (sensx == 1) {
|
|
903
|
-
newCol++;
|
|
904
|
-
}
|
|
905
|
-
else if (sensx == -1) {
|
|
906
|
-
newCol--;
|
|
907
|
-
}
|
|
908
|
-
else if (sensx == 2) {
|
|
909
|
-
newCol = this.m_columns.length - 1;
|
|
910
|
-
}
|
|
911
|
-
else if (sensx == -2) {
|
|
912
|
-
newCol = 0;
|
|
913
|
-
}
|
|
914
|
-
else if (sensx == 3) { // new editable cell skip line if needed
|
|
915
|
-
newCol++;
|
|
916
|
-
|
|
917
|
-
let lastcol = this.m_columns.length - 1;
|
|
918
|
-
|
|
919
|
-
l1: for (let trys = 0; trys < 2; trys++) {
|
|
920
|
-
while (newCol < lastcol) {
|
|
921
|
-
if (this.m_columns[newCol].createEditor !== null) {
|
|
922
|
-
break l1;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
newCol++;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
if (newCol > lastcol) {
|
|
929
|
-
newRow++;
|
|
930
|
-
newCol = 0;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
else if (sensx == -3) {
|
|
937
|
-
newCol--;
|
|
938
|
-
|
|
939
|
-
let lastcol = this.m_columns.length - 1;
|
|
940
|
-
|
|
941
|
-
l2: for (let trys = 0; trys < 2; trys++) {
|
|
942
|
-
while (newCol >= 0) {
|
|
943
|
-
if (this.m_columns[newCol].createEditor !== null) {
|
|
944
|
-
break l2;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
newCol--;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
if (newCol < 0) {
|
|
951
|
-
newRow--;
|
|
952
|
-
newCol = lastcol;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
this._selectItem(newRow, newCol, true);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
private _handleKey(event: KeyboardEvent) {
|
|
961
|
-
let dom = <Node>event.target;
|
|
962
|
-
if (this.m_editor && this.m_editor.dom.contains(dom)) {
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
switch (event.key) {
|
|
967
|
-
case 'ArrowDown':
|
|
968
|
-
case 'Down': {
|
|
969
|
-
this._moveSel(1, 0);
|
|
970
|
-
break;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
case 'ArrowUp':
|
|
974
|
-
case 'Up': {
|
|
975
|
-
this._moveSel(-1, 0);
|
|
976
|
-
break;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
case 'PageUp': {
|
|
980
|
-
this._moveSel(-2, 0);
|
|
981
|
-
break;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
case 'PageDown': {
|
|
985
|
-
this._moveSel(2, 0);
|
|
986
|
-
break;
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
case 'ArrowLeft':
|
|
990
|
-
case 'Left': {
|
|
991
|
-
this._moveSel(0, -1);
|
|
992
|
-
break;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
case 'ArrowRight':
|
|
996
|
-
case 'Right': {
|
|
997
|
-
this._moveSel(0, 1);
|
|
998
|
-
break;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
case 'Home': {
|
|
1002
|
-
if (event.ctrlKey) {
|
|
1003
|
-
this._moveSel(-3, 0);
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
this._moveSel(0, -2);
|
|
1007
|
-
}
|
|
1008
|
-
break;
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
case 'End': {
|
|
1012
|
-
if (event.ctrlKey) {
|
|
1013
|
-
this._moveSel(3, 0);
|
|
1014
|
-
}
|
|
1015
|
-
else {
|
|
1016
|
-
this._moveSel(0, 2);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
break;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
case 'Enter': {
|
|
1023
|
-
this.editCurCell();
|
|
1024
|
-
event.stopPropagation( );
|
|
1025
|
-
event.preventDefault( );
|
|
1026
|
-
break;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
case 'Delete': {
|
|
1030
|
-
this.clearCell(this.m_selection.row, this.m_selection.col);
|
|
1031
|
-
break;
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
default: {
|
|
1035
|
-
//console.log( "unknown key: ", event.key);
|
|
1036
|
-
break;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
private _keyPress(event: KeyboardEvent) {
|
|
1042
|
-
let dom = <Node>event.target;
|
|
1043
|
-
if (this.m_editor && this.m_editor.dom.contains(dom)) {
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
if (event.ctrlKey || event.altKey) {
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
this.editCurCell(event.key);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
/**
|
|
1055
|
-
* return the selection
|
|
1056
|
-
* { row, col }
|
|
1057
|
-
*/
|
|
1058
|
-
|
|
1059
|
-
getSelection() {
|
|
1060
|
-
return this.m_selection;
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
select(row: number, col: number, scrollIntoView: boolean = true) {
|
|
1064
|
-
|
|
1065
|
-
if (this.m_selection.row == row && this.m_selection.col == col) {
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
let oldSel = this._findItem(this.m_selection.row, this.m_selection.col);
|
|
1070
|
-
if (oldSel) {
|
|
1071
|
-
oldSel.removeClass('@selected');
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
this.m_selection = { row, col };
|
|
1075
|
-
|
|
1076
|
-
if (scrollIntoView) {
|
|
1077
|
-
this._scrollIntoView(row, col);
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
let newSel = this._findItem(row, col);
|
|
1081
|
-
if (newSel) {
|
|
1082
|
-
newSel.addClass('@selected');
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
this.emit( 'selectionChange', EvSelectionChange({ row, col }));
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
/**
|
|
1089
|
-
* return the row count
|
|
1090
|
-
*/
|
|
1091
|
-
|
|
1092
|
-
rowCount() {
|
|
1093
|
-
return this.m_row_limit;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* return the maximum row index filled with something
|
|
1098
|
-
*/
|
|
1099
|
-
|
|
1100
|
-
getMaxRowCount() {
|
|
1101
|
-
|
|
1102
|
-
let max_row = 0;
|
|
1103
|
-
|
|
1104
|
-
this.m_cells_data.forEach((c, uid) => {
|
|
1105
|
-
let row = Math.round(uid / 1000) + 1;
|
|
1106
|
-
if (max_row < row) {
|
|
1107
|
-
max_row = row;
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
|
|
1111
|
-
return max_row;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
getColCount() {
|
|
1115
|
-
return this.m_columns.length;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
setRowStyle(row: number, cls: string) {
|
|
1119
|
-
this.m_rows_data.set(row, cls);
|
|
1120
|
-
|
|
1121
|
-
if (this.m_lockupdate == 0) {
|
|
1122
|
-
this._buildItems();
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
|
|
1126
|
-
getRowStyle(row: number) {
|
|
1127
|
-
return this.m_rows_data.get(row);
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
setCellStyle(row: number, col: number, cls: string) {
|
|
1131
|
-
let cell = this._getCellData(row, col, true);
|
|
1132
|
-
if (!cell) {
|
|
1133
|
-
cell = { text: '' };
|
|
1134
|
-
this.m_cells_data.set(_mkid(row, col), cell);
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
cell.cls = cls;
|
|
1138
|
-
|
|
1139
|
-
if (this.m_lockupdate == 0 && this.m_visible_cells) {
|
|
1140
|
-
let itm = this._findItem(row, col);
|
|
1141
|
-
if (itm) {
|
|
1142
|
-
itm.setClass(cls, true); //todo: pb when changing classes
|
|
1143
|
-
}
|
|
1144
|
-
else {
|
|
1145
|
-
this._buildItems();
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
getCellText(row: number, col: number): string {
|
|
1151
|
-
return this._getCellData(row, col).text;
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
getCellNumber(row: number, col: number): number {
|
|
1155
|
-
let text = this._getCellData(row, col).text;
|
|
1156
|
-
return parseIntlFloat(text);
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
clearRow(row: number) {
|
|
1160
|
-
for (let c = 0; c < this.m_columns.length; c++) {
|
|
1161
|
-
this.clearCell(row, c);
|
|
1162
|
-
}
|
|
1163
|
-
this.update(10);
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
clearCell(row: number, col: number) {
|
|
1167
|
-
this.setCellText(row, col, null);
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
editCurCell(forceText?: string) {
|
|
1171
|
-
this.editCell(this.m_selection.row, this.m_selection.col, forceText);
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
editCell(row: number, col: number, forcedText?: string) {
|
|
1175
|
-
|
|
1176
|
-
if (!this.m_autoedit) {
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
// disable edition
|
|
1181
|
-
if (this.m_columns[col].createEditor === null) {
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
this._scrollIntoView(row, col);
|
|
1186
|
-
|
|
1187
|
-
let item = this._findItem(row, col);
|
|
1188
|
-
let place = item.dom;
|
|
1189
|
-
let parent = place.parentElement;
|
|
1190
|
-
|
|
1191
|
-
let rc = place.getBoundingClientRect();
|
|
1192
|
-
let prc = parent.getBoundingClientRect();
|
|
1193
|
-
|
|
1194
|
-
let cell = this._getCellData(row, col, true);
|
|
1195
|
-
|
|
1196
|
-
let edtBuilder = (props: TextEditProps, col, row): Component => {
|
|
1197
|
-
return new TextEdit(props);
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
if (this.m_columns[col].createEditor) {
|
|
1201
|
-
edtBuilder = this.m_columns[col].createEditor;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
let cellvalue = forcedText ? forcedText : (cell ? cell.text : '');
|
|
1205
|
-
|
|
1206
|
-
this.m_editor = edtBuilder({
|
|
1207
|
-
cls: '@editor',
|
|
1208
|
-
style: {
|
|
1209
|
-
left: rc.left - prc.left,
|
|
1210
|
-
top: rc.top - prc.top,
|
|
1211
|
-
width: rc.width - 1,
|
|
1212
|
-
height: rc.height - 1
|
|
1213
|
-
},
|
|
1214
|
-
tabIndex: false,
|
|
1215
|
-
value: cellvalue,
|
|
1216
|
-
data: {
|
|
1217
|
-
row,
|
|
1218
|
-
col
|
|
1219
|
-
},
|
|
1220
|
-
}, row, col);
|
|
1221
|
-
|
|
1222
|
-
if( !this.m_editor ) {
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
parent.appendChild(this.m_editor._build());
|
|
1227
|
-
|
|
1228
|
-
this._setupEditor( );
|
|
1229
|
-
|
|
1230
|
-
this.m_editor.setData('old-value', cellvalue);
|
|
1231
|
-
this.m_editor.focus();
|
|
1232
|
-
|
|
1233
|
-
if (this.m_editor instanceof TextEdit) {
|
|
1234
|
-
this.m_editor.selectAll();
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
_setupEditor( ) {
|
|
1239
|
-
|
|
1240
|
-
let movesel = (sensy, sensx) => {
|
|
1241
|
-
deferCall(() => {
|
|
1242
|
-
this.killEditor(true);
|
|
1243
|
-
this._moveSel(sensy, sensx);
|
|
1244
|
-
this.editCurCell();
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
// todo: better
|
|
1249
|
-
if( this.m_editor instanceof TextEdit ) {
|
|
1250
|
-
let editor = this.m_editor as TextEdit;
|
|
1251
|
-
let input: Input = editor.input;
|
|
1252
|
-
|
|
1253
|
-
input.setDomEvent( 'blur', () => {
|
|
1254
|
-
this.killEditor(true);
|
|
1255
|
-
} );
|
|
1256
|
-
|
|
1257
|
-
input.setDomEvent( 'keydown', (e: KeyboardEvent) => {
|
|
1258
|
-
// prevented by edit...
|
|
1259
|
-
if( e.defaultPrevented ) {
|
|
1260
|
-
return;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
switch (e.key) {
|
|
1264
|
-
case 'Escape': {
|
|
1265
|
-
this.killEditor(false);
|
|
1266
|
-
e.stopPropagation();
|
|
1267
|
-
e.preventDefault( );
|
|
1268
|
-
break;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
case 'Enter':
|
|
1272
|
-
case 'Tab': {
|
|
1273
|
-
let sens = 3;
|
|
1274
|
-
if (e.shiftKey) {
|
|
1275
|
-
sens = -3;
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
movesel(0, sens);
|
|
1279
|
-
e.stopPropagation();
|
|
1280
|
-
e.preventDefault( );
|
|
1281
|
-
break;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
case 'ArrowUp':
|
|
1285
|
-
case 'Up': {
|
|
1286
|
-
movesel(-1, 0);
|
|
1287
|
-
e.stopPropagation();
|
|
1288
|
-
e.preventDefault( );
|
|
1289
|
-
break;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
case 'ArrowDown':
|
|
1293
|
-
case 'Down': {
|
|
1294
|
-
movesel(1, 0);
|
|
1295
|
-
e.stopPropagation();
|
|
1296
|
-
e.preventDefault( );
|
|
1297
|
-
break;
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
else if( this.m_editor instanceof ComboBox ) {
|
|
1303
|
-
|
|
1304
|
-
let input: Input = (this.m_editor as ComboBox).input;
|
|
1305
|
-
input.setDomEvent( 'blur', () => {
|
|
1306
|
-
this.killEditor(true);
|
|
1307
|
-
} );
|
|
1308
|
-
|
|
1309
|
-
input.setDomEvent( 'keydown', (e: KeyboardEvent) => {
|
|
1310
|
-
|
|
1311
|
-
switch (e.key) {
|
|
1312
|
-
case 'Escape': {
|
|
1313
|
-
this.killEditor(false);
|
|
1314
|
-
e.stopPropagation();
|
|
1315
|
-
e.preventDefault( );
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
case 'Enter':
|
|
1320
|
-
case 'Tab': {
|
|
1321
|
-
let sens = 3;
|
|
1322
|
-
if (e.shiftKey) {
|
|
1323
|
-
sens = -3;
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
movesel(0, sens);
|
|
1327
|
-
e.stopPropagation();
|
|
1328
|
-
e.preventDefault( );
|
|
1329
|
-
break;
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
|
|
1334
|
-
this.m_editor.showPopup( );
|
|
1335
|
-
this.m_editor.on( 'change', ( ev ) => {
|
|
1336
|
-
this.killEditor(true);
|
|
1337
|
-
});
|
|
1338
|
-
|
|
1339
|
-
this.m_editor.on( 'cancel', ( ev ) => {
|
|
1340
|
-
this.killEditor(false);
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
killEditor(save: boolean) {
|
|
1346
|
-
if (this.m_editor) {
|
|
1347
|
-
if (save) {
|
|
1348
|
-
|
|
1349
|
-
let text, id;
|
|
1350
|
-
|
|
1351
|
-
if( this.m_editor instanceof TextEdit ) {
|
|
1352
|
-
text = (this.m_editor as TextEdit).value;
|
|
1353
|
-
}
|
|
1354
|
-
else if( this.m_editor instanceof ComboBox ) {
|
|
1355
|
-
id = (this.m_editor as ComboBox).value;
|
|
1356
|
-
text = (this.m_editor as ComboBox).valueText;
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
let row = this.m_editor.getData('row');
|
|
1360
|
-
let col = this.m_editor.getData('col');
|
|
1361
|
-
let old = this.m_editor.getData('old-value');
|
|
1362
|
-
|
|
1363
|
-
this.setCellText(row, col, text);
|
|
1364
|
-
const ev = EvChange(text, { row, col, oldValue: old, id });
|
|
1365
|
-
this.emit('change', ev );
|
|
1366
|
-
|
|
1367
|
-
if( ev.defaultPrevented ) {
|
|
1368
|
-
this.setCellText(row, col, old);
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
// cannot dipose while handling blur event, so we defer...
|
|
1373
|
-
let t = this.m_editor;
|
|
1374
|
-
asap( ( ) => {
|
|
1375
|
-
t.dispose();
|
|
1376
|
-
})
|
|
1377
|
-
|
|
1378
|
-
this.m_editor = null;
|
|
1379
|
-
this.focus();
|
|
1380
|
-
}
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
clearData() {
|
|
1384
|
-
this.m_cells_data = new Map<number, CellData>();
|
|
1385
|
-
this.m_rows_data = new Map<number, string>();
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
setCellText(row: number, col: number, value: string) {
|
|
1389
|
-
|
|
1390
|
-
if (value == null || value.length == 0) {
|
|
1391
|
-
this.m_cells_data.delete(_mkid(row, col));
|
|
1392
|
-
value = ''; //' ';
|
|
1393
|
-
}
|
|
1394
|
-
else {
|
|
1395
|
-
let cell: any = this._getCellData(row, col, true);
|
|
1396
|
-
if (!cell) {
|
|
1397
|
-
cell = {};
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
cell.text = value;
|
|
1401
|
-
this.m_cells_data.set(_mkid(row, col), cell);
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
if (this.m_lockupdate == 0 && this.m_visible_cells) {
|
|
1405
|
-
let itm = this._findItem(row, col);
|
|
1406
|
-
if (itm) {
|
|
1407
|
-
|
|
1408
|
-
if (this.m_columns[col].renderer) {
|
|
1409
|
-
value = this.m_columns[col].renderer(value, { row, col });
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
itm.setContent(value);
|
|
1413
|
-
}
|
|
1414
|
-
else {
|
|
1415
|
-
this._buildItems();
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
lockUpdate(start: boolean) {
|
|
1421
|
-
if (start) {
|
|
1422
|
-
this.m_lockupdate++;
|
|
1423
|
-
}
|
|
1424
|
-
else {
|
|
1425
|
-
if (--this.m_lockupdate == 0) {
|
|
1426
|
-
this._updateScroll(true);
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
/**
|
|
1433
|
-
* @ignore
|
|
1434
|
-
*/
|
|
1435
|
-
|
|
1436
|
-
function _mkid(row: number, col: number): number {
|
|
1437
|
-
return row * 1000 + col;
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
/**
|
|
1441
|
-
* @ignore
|
|
1442
|
-
*/
|
|
1443
|
-
|
|
1444
|
-
function _getid(key: number) {
|
|
1445
|
-
return {
|
|
1446
|
-
row: Math.floor(key / 1000) | 0,
|
|
1447
|
-
col: (key % 1000) | 0
|
|
1448
|
-
}
|
|
1449
|
-
}
|