x4js 2.0.13 → 2.0.14
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/.vscode/launch.json +14 -0
- package/README.md +5 -0
- package/{lib/src/demo → demo}/main.scss +3 -1
- package/{lib/src/demo/main.tsx → demo/main.ts} +37 -36
- package/demo/package.json +26 -0
- package/demo/scss.d.ts +4 -0
- package/demo/svg.d.ts +1 -0
- package/demo/tsconfig.json +14 -0
- package/lib/README.txt +5 -0
- package/lib/cjs/x4.css +1 -1
- package/lib/cjs/x4.js +2 -1
- package/lib/esm/x4.css +1 -1
- package/lib/esm/x4.mjs +2 -1
- package/lib/src/components/boxes/boxes.module.scss +17 -0
- package/lib/src/components/boxes/boxes.ts +162 -13
- package/lib/src/components/breadcrumb/breadcrumb.scss +56 -28
- package/lib/src/components/breadcrumb/breadcrumb.ts +93 -84
- package/lib/src/components/btngroup/btngroup.module.scss +12 -0
- package/lib/src/components/btngroup/btngroup.ts +41 -8
- package/lib/src/components/button/button.module.scss +23 -5
- package/lib/src/components/button/button.ts +72 -4
- package/lib/src/components/canvas/canvas.module.scss +25 -0
- package/lib/src/components/canvas/canvas.ts +189 -0
- package/lib/src/components/canvas/canvas_ex.ts +269 -0
- package/lib/src/components/checkbox/checkbox.ts +18 -4
- package/lib/src/components/combobox/combobox.module.scss +24 -15
- package/lib/src/components/combobox/combobox.ts +107 -24
- package/lib/src/components/components.ts +7 -0
- package/lib/src/components/dialog/dialog.module.scss +37 -3
- package/lib/src/components/dialog/dialog.ts +149 -31
- package/lib/src/components/filedrop/cloud-arrow-up.svg +1 -0
- package/lib/src/components/filedrop/filedrop.module.scss +70 -0
- package/lib/src/components/filedrop/filedrop.ts +131 -0
- package/lib/src/components/form/form.module.scss +4 -0
- package/lib/src/components/form/form.ts +137 -6
- package/lib/src/components/gridview/arrow-down-light.svg +1 -0
- package/lib/src/components/gridview/arrow-up-light.svg +1 -0
- package/lib/src/components/gridview/gridview.module.scss +324 -0
- package/lib/src/components/gridview/gridview.ts +1175 -0
- package/lib/src/components/icon/icon.module.scss +1 -1
- package/lib/src/components/icon/icon.ts +4 -1
- package/lib/src/components/image/image.module.scss +8 -1
- package/lib/src/components/image/image.ts +105 -6
- package/lib/src/components/input/input.module.scss +8 -3
- package/lib/src/components/input/input.ts +137 -14
- package/lib/src/components/keyboard/arrow-up.svg +1 -0
- package/lib/src/components/keyboard/delete-left.svg +1 -0
- package/lib/src/components/keyboard/eye-slash.svg +1 -0
- package/lib/src/components/keyboard/keyboard.module.scss +134 -0
- package/lib/src/components/keyboard/keyboard.ts +525 -0
- package/lib/src/components/label/label.module.scss +22 -4
- package/lib/src/components/label/label.ts +33 -0
- package/lib/src/components/link/link.ts +81 -78
- package/lib/src/components/listbox/listbox.module.scss +61 -3
- package/lib/src/components/listbox/listbox.ts +164 -56
- package/lib/src/components/menu/menu.module.scss +10 -1
- package/lib/src/components/menu/menu.ts +4 -1
- package/lib/src/components/messages/messages.module.scss +44 -0
- package/lib/src/components/messages/messages.ts +164 -18
- package/lib/src/components/messages/pen-field.svg +1 -0
- package/lib/src/components/normalize.scss +5 -0
- package/lib/src/components/notification/notification.module.scss +4 -2
- package/lib/src/components/notification/notification.ts +2 -4
- package/lib/src/components/panel/panel.module.scss +12 -0
- package/lib/src/components/popup/popup.module.scss +4 -2
- package/lib/src/components/popup/popup.ts +136 -92
- package/lib/src/components/propgrid/folder-closed.svg +1 -0
- package/lib/src/components/propgrid/folder-open.svg +1 -0
- package/lib/src/components/propgrid/progrid.module.scss +108 -0
- package/lib/src/components/propgrid/propgrid.ts +271 -0
- package/lib/src/components/propgrid/updown.svg +4 -0
- package/lib/src/components/radio/radio.module.scss +147 -0
- package/lib/src/components/radio/radio.svg +4 -0
- package/lib/src/components/radio/radio.ts +142 -0
- package/lib/src/components/select/select.module.scss +9 -0
- package/lib/src/components/select/select.ts +134 -0
- package/lib/src/components/shared.scss +47 -0
- package/lib/src/components/sizers/sizer.ts +9 -2
- package/lib/src/components/slider/slider.module.scss +77 -30
- package/lib/src/components/slider/slider.ts +72 -22
- package/lib/src/components/tabs/tabs.module.scss +1 -2
- package/lib/src/components/tabs/tabs.ts +43 -12
- package/lib/src/components/textarea/textarea.module.scss +6 -2
- package/lib/src/components/textarea/textarea.ts +73 -8
- package/lib/src/components/textedit/textedit.module.scss +3 -1
- package/lib/src/components/textedit/textedit.ts +31 -4
- package/lib/src/components/themes.scss +7 -0
- package/lib/src/components/tickline/tickline.module.scss +26 -0
- package/lib/src/components/tickline/tickline.ts +82 -0
- package/lib/src/components/tooltips/comments-question.svg +1 -0
- package/lib/src/components/tooltips/tooltips.scss +30 -9
- package/lib/src/components/tooltips/tooltips.ts +10 -5
- package/lib/src/components/treeview/treeview.module.scss +129 -60
- package/lib/src/components/treeview/treeview.ts +47 -12
- package/lib/src/components/viewport/viewport.module.scss +7 -0
- package/lib/src/core/component.ts +102 -32
- package/lib/src/core/core_application.ts +222 -2
- package/lib/src/core/core_colors.ts +2 -2
- package/lib/src/{components/grid/datastore.ts → core/core_data.ts} +261 -250
- package/lib/src/core/core_dragdrop.ts +3 -3
- package/lib/src/core/core_element.ts +13 -1
- package/lib/src/core/core_events.ts +28 -0
- package/lib/src/core/core_i18n.ts +18 -2
- package/lib/src/core/core_react.ts +79 -0
- package/lib/src/core/core_router.ts +23 -7
- package/lib/src/core/core_styles.ts +5 -5
- package/lib/src/core/core_svg.ts +173 -12
- package/lib/src/core/core_tools.ts +305 -87
- package/lib/src/x4tsx.d.ts +25 -0
- package/lib/styles/x4.css +1 -1
- package/lib/types/x4js.d.ts +767 -92
- package/package.json +4 -4
- package/scripts/build.mjs +378 -0
- package/scripts/prepack.mjs +346 -0
- package/src/components/base.scss +25 -0
- package/src/components/boxes/boxes.module.scss +54 -0
- package/src/components/boxes/boxes.ts +278 -0
- package/src/components/breadcrumb/breadcrumb.scss +56 -0
- package/src/components/breadcrumb/breadcrumb.ts +93 -0
- package/src/components/breadcrumb/chevron-right.svg +1 -0
- package/src/components/btngroup/btngroup.module.scss +41 -0
- package/src/components/btngroup/btngroup.ts +153 -0
- package/src/components/button/button.module.scss +173 -0
- package/src/components/button/button.ts +185 -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 +327 -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/canvas/canvas.module.scss +25 -0
- package/src/components/canvas/canvas.ts +189 -0
- package/src/components/canvas/canvas_ex.ts +269 -0
- package/src/components/checkbox/check.svg +4 -0
- package/src/components/checkbox/checkbox.module.scss +142 -0
- package/src/components/checkbox/checkbox.ts +140 -0
- package/src/components/colorinput/colorinput.module.scss +65 -0
- package/src/components/colorinput/colorinput.ts +91 -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 +482 -0
- package/src/components/combobox/combobox.module.scss +133 -0
- package/src/components/combobox/combobox.ts +275 -0
- package/src/components/combobox/updown.svg +4 -0
- package/src/components/components.ts +41 -0
- package/src/components/dialog/dialog.module.scss +105 -0
- package/src/components/dialog/dialog.ts +212 -0
- package/src/components/dialog/xmark-sharp-light.svg +1 -0
- package/src/components/filedrop/cloud-arrow-up.svg +1 -0
- package/src/components/filedrop/filedrop.module.scss +70 -0
- package/src/components/filedrop/filedrop.ts +131 -0
- package/src/components/form/form.module.scss +38 -0
- package/src/components/form/form.ts +172 -0
- package/src/components/gridview/arrow-down-light.svg +1 -0
- package/src/components/gridview/arrow-up-light.svg +1 -0
- package/src/components/gridview/gridview.module.scss +324 -0
- package/src/components/gridview/gridview.ts +1175 -0
- package/src/components/header/header.module.scss +40 -0
- package/src/components/header/header.ts +130 -0
- package/src/components/icon/icon.module.scss +30 -0
- package/src/components/icon/icon.ts +139 -0
- package/src/components/image/image.module.scss +28 -0
- package/src/components/image/image.ts +168 -0
- package/src/components/input/input.module.scss +74 -0
- package/src/components/input/input.ts +398 -0
- package/src/components/keyboard/arrow-up.svg +1 -0
- package/src/components/keyboard/delete-left.svg +1 -0
- package/src/components/keyboard/eye-slash.svg +1 -0
- package/src/components/keyboard/keyboard.module.scss +134 -0
- package/src/components/keyboard/keyboard.ts +525 -0
- package/src/components/label/label.module.scss +76 -0
- package/src/components/label/label.ts +97 -0
- package/src/components/link/link.ts +81 -0
- package/src/components/listbox/listbox.module.scss +161 -0
- package/src/components/listbox/listbox.ts +539 -0
- package/src/components/menu/caret-right-solid.svg +1 -0
- package/src/components/menu/menu.module.scss +117 -0
- package/src/components/menu/menu.ts +174 -0
- package/src/components/messages/circle-exclamation.svg +1 -0
- package/src/components/messages/messages.module.scss +92 -0
- package/src/components/messages/messages.ts +215 -0
- package/src/components/messages/pen-field.svg +1 -0
- package/src/components/normalize.scss +391 -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 +84 -0
- package/src/components/notification/notification.ts +107 -0
- package/src/components/notification/xmark-sharp-light.svg +1 -0
- package/src/components/panel/panel.module.scss +60 -0
- package/src/components/panel/panel.ts +58 -0
- package/src/components/popup/popup.module.scss +45 -0
- package/src/components/popup/popup.ts +440 -0
- package/src/components/progress/progress.module.scss +57 -0
- package/src/components/progress/progress.ts +44 -0
- package/src/components/propgrid/folder-closed.svg +1 -0
- package/src/components/propgrid/folder-open.svg +1 -0
- package/src/components/propgrid/progrid.module.scss +108 -0
- package/src/components/propgrid/propgrid.ts +271 -0
- package/src/components/propgrid/updown.svg +4 -0
- package/src/components/radio/radio.module.scss +147 -0
- package/src/components/radio/radio.svg +4 -0
- package/src/components/radio/radio.ts +142 -0
- package/src/components/rating/rating.module.scss +23 -0
- package/src/components/rating/rating.ts +131 -0
- package/src/components/rating/star-sharp-light.svg +1 -0
- package/src/components/rating/star-sharp-solid.svg +1 -0
- package/src/components/select/select.module.scss +9 -0
- package/src/components/select/select.ts +134 -0
- package/src/components/shared.scss +137 -0
- package/src/components/sizers/sizer.module.scss +90 -0
- package/src/components/sizers/sizer.ts +131 -0
- package/src/components/slider/slider.module.scss +118 -0
- package/src/components/slider/slider.ts +198 -0
- package/src/components/switch/switch.module.scss +127 -0
- package/src/components/switch/switch.ts +62 -0
- package/src/components/tabs/tabs.module.scss +45 -0
- package/src/components/tabs/tabs.ts +199 -0
- package/src/components/textarea/textarea.module.scss +63 -0
- package/src/components/textarea/textarea.ts +125 -0
- package/src/components/textedit/textedit.module.scss +116 -0
- package/src/components/textedit/textedit.ts +110 -0
- package/src/components/themes.scss +88 -0
- package/src/components/tickline/tickline.module.scss +26 -0
- package/src/components/tickline/tickline.ts +82 -0
- package/src/components/tooltips/circle-info-sharp-light.svg +1 -0
- package/src/components/tooltips/comments-question.svg +1 -0
- package/src/components/tooltips/tooltips.scss +72 -0
- package/src/components/tooltips/tooltips.ts +109 -0
- package/src/components/treeview/chevron-down-light.svg +1 -0
- package/src/components/treeview/treeview.module.scss +185 -0
- package/src/components/treeview/treeview.ts +445 -0
- package/src/components/viewport/viewport.module.scss +32 -0
- package/src/components/viewport/viewport.ts +41 -0
- package/src/core/component.ts +1072 -0
- package/src/core/core_application.ts +264 -0
- package/src/core/core_colors.ts +250 -0
- package/src/core/core_data.ts +1309 -0
- package/src/core/core_dom.ts +471 -0
- package/src/core/core_dragdrop.ts +201 -0
- package/src/core/core_element.ts +110 -0
- package/src/core/core_events.ts +177 -0
- package/src/core/core_i18n.ts +393 -0
- package/src/core/core_react.ts +79 -0
- package/src/core/core_router.ts +237 -0
- package/src/core/core_styles.ts +214 -0
- package/src/core/core_svg.ts +711 -0
- package/src/core/core_tools.ts +906 -0
- package/src/types/scss.d.ts +4 -0
- package/src/types/svg.d.ts +1 -0
- package/src/types/x4react.d.ts +9 -0
- package/src/x4.scss +19 -0
- package/src/x4tsx.d.ts +25 -0
- package/tsconfig.json +14 -0
- package/lib/src/components/grid/gridview.ts +0 -1108
- package/lib/src/components/grid/memdb.ts +0 -325
- /package/{lib/src/demo → demo}/assets/house-light.svg +0 -0
- /package/{lib/src/demo → demo}/assets/radio.svg +0 -0
- /package/{lib/src/demo → demo}/index.html +0 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file listbox.ts
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
import { Component, ComponentEvent, ComponentEvents, componentFromDOM, ComponentProps, EvChange, EvClick, EvContextMenu, EvDblClick, EvSelectionChange } from '../../core/component';
|
|
18
|
+
import { EventCallback } from '../../core/core_events.js';
|
|
19
|
+
import { kbNav, class_ns, isArray, UnsafeHtml } from '@core/core_tools.js';
|
|
20
|
+
|
|
21
|
+
import { ScrollView, Viewport } from '../viewport/viewport';
|
|
22
|
+
import { HBox } from '../boxes/boxes.js';
|
|
23
|
+
import { Label } from '../label/label.js';
|
|
24
|
+
|
|
25
|
+
import "./listbox.module.scss"
|
|
26
|
+
|
|
27
|
+
export type ListboxID = number | string;
|
|
28
|
+
|
|
29
|
+
export interface ListItem {
|
|
30
|
+
id: ListboxID;
|
|
31
|
+
text: string | UnsafeHtml;
|
|
32
|
+
|
|
33
|
+
iconId?: string;
|
|
34
|
+
data?: any;
|
|
35
|
+
cls?: string;
|
|
36
|
+
checked?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
interface ListboxEvents extends ComponentEvents {
|
|
44
|
+
//change: EvChange;
|
|
45
|
+
click?: EvClick;
|
|
46
|
+
dblClick?: EvDblClick;
|
|
47
|
+
contextMenu?: EvContextMenu;
|
|
48
|
+
selectionChange?: EvSelectionChange;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
interface ListboxProps extends Omit<ComponentProps,'content'> {
|
|
56
|
+
items?: ListItem[];
|
|
57
|
+
renderer?: ( item: ListItem ) => Component;
|
|
58
|
+
//header?: Header;
|
|
59
|
+
footer?: Component,
|
|
60
|
+
checkable?: true,
|
|
61
|
+
multisel?: true,
|
|
62
|
+
|
|
63
|
+
dblClick?: EventCallback<EvDblClick>;
|
|
64
|
+
selectionChange?: EventCallback<EvSelectionChange>;
|
|
65
|
+
contextMenu?: EventCallback<EvContextMenu>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
@class_ns( "x4" )
|
|
73
|
+
export class Listbox extends Component<ListboxProps,ListboxEvents> {
|
|
74
|
+
|
|
75
|
+
private _view: Viewport;
|
|
76
|
+
//private _selection: ListboxID;
|
|
77
|
+
//private _selitem: Component;
|
|
78
|
+
|
|
79
|
+
private _lastsel: ListboxID;
|
|
80
|
+
|
|
81
|
+
private _multisel: Set<ListboxID>;
|
|
82
|
+
private _items: ListItem[];
|
|
83
|
+
|
|
84
|
+
preventFocus = false;
|
|
85
|
+
|
|
86
|
+
constructor( props: ListboxProps ) {
|
|
87
|
+
super( { ...props } );
|
|
88
|
+
|
|
89
|
+
this.setAttribute( "tabindex", 0 );
|
|
90
|
+
this.mapPropEvents( props, "dblClick", "selectionChange", "contextMenu" );
|
|
91
|
+
|
|
92
|
+
const scroller = new ScrollView( { cls: "body" } );
|
|
93
|
+
this._view = scroller.getViewport( );
|
|
94
|
+
this._multisel = new Set( );
|
|
95
|
+
this._items = [];
|
|
96
|
+
|
|
97
|
+
if( props.footer ) {
|
|
98
|
+
props.footer.setAttribute( "id", "footer" );
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.setContent( [
|
|
102
|
+
//props.header ? props.header : null,
|
|
103
|
+
scroller,
|
|
104
|
+
props.footer,
|
|
105
|
+
] );
|
|
106
|
+
|
|
107
|
+
this.setDOMEvents( {
|
|
108
|
+
click: (ev) => this._on_click( ev ),
|
|
109
|
+
keydown: ( ev ) => this._on_key( ev ),
|
|
110
|
+
dblclick: (e) => this._on_click(e),
|
|
111
|
+
contextmenu: (e) => this._on_ctx_menu(e),
|
|
112
|
+
} );
|
|
113
|
+
|
|
114
|
+
if( props.items ) {
|
|
115
|
+
this.setItems( props.items );
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
private _on_key( ev: KeyboardEvent ) {
|
|
124
|
+
if( this.isDisabled() ) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
switch( ev.key ) {
|
|
129
|
+
case "ArrowDown": {
|
|
130
|
+
this.navigate( kbNav.next );
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
case "ArrowUp": {
|
|
135
|
+
this.navigate( kbNav.prev );
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
case "Home": {
|
|
140
|
+
this.navigate( kbNav.first );
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case "End": {
|
|
145
|
+
this.navigate( kbNav.last );
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
default:
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
ev.preventDefault( );
|
|
154
|
+
ev.stopPropagation( );
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
navigate( sens: kbNav ) {
|
|
162
|
+
|
|
163
|
+
if( !this._lastsel ) {
|
|
164
|
+
if( sens==kbNav.next ) sens = kbNav.first;
|
|
165
|
+
else sens = kbNav.last;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const next_visible = ( el: Component, down: boolean ) => {
|
|
169
|
+
|
|
170
|
+
while( el && !el.isVisible() ) {
|
|
171
|
+
el = down ? el.nextElement() : el.prevElement();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return el;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if( sens==kbNav.first || sens==kbNav.last ) {
|
|
178
|
+
let fel = sens==kbNav.first ? this._view.firstChild() : this._view.lastChild( );
|
|
179
|
+
fel = next_visible( fel, sens==kbNav.first );
|
|
180
|
+
|
|
181
|
+
if( fel ) {
|
|
182
|
+
const id = fel.getInternalData( "id" );
|
|
183
|
+
this._selectItem( id, fel, 'single' );
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const selitem = this._itemWithID( this._lastsel );
|
|
189
|
+
let nel = sens==kbNav.next ? selitem.nextElement() : selitem.prevElement();
|
|
190
|
+
nel = next_visible( nel, sens==kbNav.next );
|
|
191
|
+
|
|
192
|
+
if( nel ) {
|
|
193
|
+
const id = nel.getInternalData( "id" );
|
|
194
|
+
this._selectItem( id, nel, 'single' );
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
private _itemWithID( id: ListboxID ) {
|
|
207
|
+
//const itm = this.query( `[data-id="${id}"]` );
|
|
208
|
+
const all = this._view.enumChildComponents( false );
|
|
209
|
+
return all.find( x => x.getInternalData("id")===id )
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
*
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
private _on_click( ev: MouseEvent ) {
|
|
217
|
+
let target = ev.target as HTMLElement;
|
|
218
|
+
|
|
219
|
+
while( target && target!=this.dom ) {
|
|
220
|
+
const c = componentFromDOM( target );
|
|
221
|
+
|
|
222
|
+
// avoid trapping child ckick
|
|
223
|
+
if( c.dom.tagName==='INPUT' ) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if( c && c.hasClass("x4item") ) {
|
|
228
|
+
const id = c.getInternalData( "id" );
|
|
229
|
+
const fev: ComponentEvent = { context:id };
|
|
230
|
+
if (ev.type == 'click') {
|
|
231
|
+
this.fire('click', fev );
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.fire('dblClick', fev );
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!fev.defaultPrevented) {
|
|
238
|
+
this._selectItem( id, c, ev.ctrlKey ? 'toggle' : 'single' );
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
target = target.parentElement;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.clearSelection( );
|
|
248
|
+
|
|
249
|
+
ev.stopImmediatePropagation();
|
|
250
|
+
ev.preventDefault( );
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
private _on_ctx_menu(ev: MouseEvent) {
|
|
258
|
+
|
|
259
|
+
ev.preventDefault();
|
|
260
|
+
|
|
261
|
+
let target = ev.target as HTMLElement;
|
|
262
|
+
while( target && target!=this.dom ) {
|
|
263
|
+
const c = componentFromDOM( target );
|
|
264
|
+
if( c && c.hasClass("x4item") ) {
|
|
265
|
+
const id = c.getInternalData( "id" );
|
|
266
|
+
|
|
267
|
+
this._selectItem(id, c, 'single' );
|
|
268
|
+
this.fire('contextMenu', {uievent: ev, context: id } );
|
|
269
|
+
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
target = target.parentElement;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
this.fire('contextMenu', { uievent:ev, context: null } );
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
*
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
private _selectItem( id: ListboxID, item: Component, mode: "single" | "toggle" ) {
|
|
284
|
+
|
|
285
|
+
if( !this.props.multisel ) {
|
|
286
|
+
mode = 'single';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
this._lastsel = id;
|
|
290
|
+
|
|
291
|
+
if( mode=='single' ) {
|
|
292
|
+
if( this._multisel.has(id) ) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
this._clearSelection( );
|
|
297
|
+
if( item ) {
|
|
298
|
+
this._multisel.add( id );
|
|
299
|
+
item.addClass( "selected" );
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else { // toggle
|
|
303
|
+
if( item ) {
|
|
304
|
+
if( this._multisel.has(id) ) {
|
|
305
|
+
item.removeClass( "selected" );
|
|
306
|
+
this._multisel.delete( id );
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this._multisel.add( id );
|
|
310
|
+
item.addClass( "selected" );
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if( item ) {
|
|
316
|
+
item.scrollIntoView( {
|
|
317
|
+
behavior: "smooth",
|
|
318
|
+
block: "nearest"
|
|
319
|
+
} );
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
this.fire( "selectionChange", { selection: this.getSelection(), empty: this._multisel.size==0 } );
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
*
|
|
327
|
+
*/
|
|
328
|
+
|
|
329
|
+
getItem( id: ListboxID ): ListItem {
|
|
330
|
+
return this._items.find( x => x.id===id );
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* select an item by it's id
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
select( ids: ListboxID | ListboxID[], notify = true ) {
|
|
338
|
+
|
|
339
|
+
if( !isArray(ids) ) {
|
|
340
|
+
ids = [ids];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if( !ids.length ) {
|
|
344
|
+
if( this._multisel.size ) {
|
|
345
|
+
this.clearSelection( );
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// if one of new selection not in old selection...
|
|
352
|
+
if( ids.some( x => !this._multisel.has(x)) ) {
|
|
353
|
+
this._clearSelection( );
|
|
354
|
+
const all = this._view.enumChildComponents( false );
|
|
355
|
+
|
|
356
|
+
ids.forEach( id => {
|
|
357
|
+
const itm = all.find( x => x.getInternalData("id")===id ); //this.query( `[data-id="${id}"]` );
|
|
358
|
+
if( itm ) {
|
|
359
|
+
this._multisel.add( id );
|
|
360
|
+
itm.addClass( "selected" );
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
this.fire( "selectionChange", { selection: this.getSelection(), empty: this._multisel.size==0 } );
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
*
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
private _findItemIndex( id: ListboxID ) {
|
|
373
|
+
return this._items.findIndex( x => x.id==id );
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
*
|
|
378
|
+
*/
|
|
379
|
+
|
|
380
|
+
private _clearSelection( ) {
|
|
381
|
+
|
|
382
|
+
const all = this._view.enumChildComponents( false );
|
|
383
|
+
|
|
384
|
+
if( this._multisel.size ) {
|
|
385
|
+
const ids = Array.from( this._multisel );
|
|
386
|
+
ids.forEach( id => {
|
|
387
|
+
const itm = all.find( x => x.getInternalData("id")===id ); //this.query( `[data-id="${id}"]` );
|
|
388
|
+
if( itm ) {
|
|
389
|
+
itm.removeClass( "selected" );
|
|
390
|
+
}
|
|
391
|
+
} );
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
this._multisel.clear( );
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
clearSelection( ) {
|
|
398
|
+
if( this._multisel.size ) {
|
|
399
|
+
this._clearSelection( );
|
|
400
|
+
this.fire( "selectionChange", { selection: [], empty: true } );
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
*
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
setItems( items: ListItem[], keepSel = false ) {
|
|
409
|
+
|
|
410
|
+
const oldSel = this.getSelection( );
|
|
411
|
+
|
|
412
|
+
this.clearSelection( );
|
|
413
|
+
this._view.clearContent( );
|
|
414
|
+
this._items = items;
|
|
415
|
+
|
|
416
|
+
if( items ) {
|
|
417
|
+
const content = items.map( x => this.renderItem(x) );
|
|
418
|
+
this._view.setContent( content );
|
|
419
|
+
|
|
420
|
+
if( keepSel ) {
|
|
421
|
+
this.select( oldSel );
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
*
|
|
428
|
+
*/
|
|
429
|
+
|
|
430
|
+
renderItem( item: ListItem ) {
|
|
431
|
+
const renderer = this.props.renderer ?? this.defaultRenderer;
|
|
432
|
+
const line = renderer( item );
|
|
433
|
+
|
|
434
|
+
line.addClass( "x4item" );
|
|
435
|
+
line.setInternalData( "id", item.id );
|
|
436
|
+
|
|
437
|
+
return line;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
*
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
defaultRenderer( item: ListItem ): Component {
|
|
445
|
+
return new HBox( {
|
|
446
|
+
cls: item.cls,
|
|
447
|
+
content: new Label( { icon: item.iconId, text: item.text })
|
|
448
|
+
} )
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
*
|
|
453
|
+
*/
|
|
454
|
+
|
|
455
|
+
filter( filter: string ) {
|
|
456
|
+
const childs = this._view.enumChildComponents( false );
|
|
457
|
+
|
|
458
|
+
if( !filter ) {
|
|
459
|
+
childs.forEach( x => x.show( true ) );
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
// get list of visible items
|
|
463
|
+
const filtred = this._items
|
|
464
|
+
.filter( x => x.text.includes(filter) )
|
|
465
|
+
.map( x => x.id+'' );
|
|
466
|
+
|
|
467
|
+
// now hide all elements not in list
|
|
468
|
+
childs.forEach( x => {
|
|
469
|
+
x.show( filtred.includes( x.getInternalData( "id" ) ) );
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* append or prepend a new item
|
|
476
|
+
* @param item
|
|
477
|
+
* @param prepend
|
|
478
|
+
* @param select
|
|
479
|
+
*/
|
|
480
|
+
|
|
481
|
+
appendItem( item: ListItem, prepend = false, select = true ) {
|
|
482
|
+
|
|
483
|
+
if( select ) {
|
|
484
|
+
this._clearSelection( );
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
let el = this.renderItem( item );
|
|
488
|
+
|
|
489
|
+
if( prepend ) {
|
|
490
|
+
this._items.unshift( item );
|
|
491
|
+
this._view.prependContent( el );
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
this._items.push( item );
|
|
495
|
+
this._view.appendContent( el );
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if( select ) {
|
|
499
|
+
this._selectItem( item.id, el, 'single' );
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* update an item
|
|
505
|
+
*/
|
|
506
|
+
|
|
507
|
+
updateItem( id: any, item: ListItem ) {
|
|
508
|
+
|
|
509
|
+
// find item
|
|
510
|
+
const idx = this._findItemIndex( id );
|
|
511
|
+
if( idx<0 ) {
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// take care of selection
|
|
516
|
+
let was_sel = false;
|
|
517
|
+
if( this._multisel.has(id) ) {
|
|
518
|
+
was_sel = true;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// replace it in the list
|
|
522
|
+
this._items[idx] = item;
|
|
523
|
+
|
|
524
|
+
// rebuild & replace it's line
|
|
525
|
+
const old = this._itemWithID( item.id );
|
|
526
|
+
if( old?.dom ) {
|
|
527
|
+
const _new = this.renderItem( item );
|
|
528
|
+
if( was_sel ) {
|
|
529
|
+
_new.addClass( "selected" );
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
this._view.dom.replaceChild( _new.dom, old.dom );
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
getSelection( ) {
|
|
537
|
+
return Array.from( this._multisel );
|
|
538
|
+
}
|
|
539
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" fill="var(--color-gray-8)"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M246.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-128-128c-9.2-9.2-22.9-11.9-34.9-6.9s-19.8 16.6-19.8 29.6l0 256c0 12.9 7.8 24.6 19.8 29.6s25.7 2.2 34.9-6.9l128-128z"/></svg>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file menu.module.scss
|
|
9
|
+
* @author Etienne Cochard
|
|
10
|
+
*
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
|
+
*
|
|
13
|
+
* Use of this source code is governed by an MIT-style license
|
|
14
|
+
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
|
+
**/
|
|
16
|
+
|
|
17
|
+
@use "../shared.scss";
|
|
18
|
+
|
|
19
|
+
:root {
|
|
20
|
+
--menu-background: var( --background-primary );
|
|
21
|
+
--menu-border: var( --border-hover );
|
|
22
|
+
|
|
23
|
+
--menuitem-color: var( --text-ternary );;
|
|
24
|
+
--menuitem-background-active: var( --accent-background-active );
|
|
25
|
+
--menuitem-color-active: var( --accent-color-active );
|
|
26
|
+
--menuitem-background-hover: var( --accent-background-hover );
|
|
27
|
+
--menuitem-color-hover: var( --accent-color-hover );
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.x4menu {
|
|
31
|
+
@extend .shadow-lg;
|
|
32
|
+
|
|
33
|
+
position: absolute;
|
|
34
|
+
overflow-y: auto;
|
|
35
|
+
|
|
36
|
+
border-radius: var(--bradius);
|
|
37
|
+
padding: 8px 0;
|
|
38
|
+
min-width: 150px;
|
|
39
|
+
|
|
40
|
+
background-color: var(--menu-background);
|
|
41
|
+
border: 1px solid var(--menu-border);
|
|
42
|
+
|
|
43
|
+
max-height: calc( 100vh - 32px );
|
|
44
|
+
|
|
45
|
+
.x4cmenuitem {
|
|
46
|
+
@extend .hbox;
|
|
47
|
+
|
|
48
|
+
transition: background-color 0.3s, color 0.3s;
|
|
49
|
+
|
|
50
|
+
align-items: center;
|
|
51
|
+
color: var(--menuitem-color);
|
|
52
|
+
|
|
53
|
+
padding: 6px;
|
|
54
|
+
gap: 10px;
|
|
55
|
+
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
|
|
58
|
+
#icon {
|
|
59
|
+
width: 16px;
|
|
60
|
+
height: 16px;
|
|
61
|
+
|
|
62
|
+
.fa-primary {
|
|
63
|
+
fill: var( --color-primary-a50 );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.fa-secondary {
|
|
67
|
+
fill: var( --color-primary-a30 );
|
|
68
|
+
opacity: 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#text {
|
|
73
|
+
@extend .flex;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
&.title {
|
|
77
|
+
color: var( --text-primary );
|
|
78
|
+
cursor: auto;
|
|
79
|
+
margin-left: -16px;
|
|
80
|
+
margin-top: -6px;
|
|
81
|
+
font-weight: 600;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&.popup {
|
|
85
|
+
&:after {
|
|
86
|
+
content: url("./caret-right-solid.svg");
|
|
87
|
+
width: 6px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&:hover:not(.title),
|
|
92
|
+
&.opened {
|
|
93
|
+
background-color: var(--menuitem-background-hover);
|
|
94
|
+
color: var(--menuitem-color-hover);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:active:not(.title) {
|
|
98
|
+
background-color: var(--menuitem-background-active);
|
|
99
|
+
color: var(--menuitem-color-active);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&[disabled] {
|
|
103
|
+
&:hover {
|
|
104
|
+
background-color: var(--disabled-background) !important;
|
|
105
|
+
}
|
|
106
|
+
color: var( --disabled-color-dark ) !important;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
transition: background-color 0.1s;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.x4cmenusep {
|
|
113
|
+
padding-top: 4px;
|
|
114
|
+
border-bottom: 1px solid var(--border);
|
|
115
|
+
margin-bottom: 4px;
|
|
116
|
+
}
|
|
117
|
+
}
|