x4js 2.0.5 → 2.0.7
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/build/x4.css +1 -0
- package/build/x4.js +1 -0
- package/lib/README.txt +15 -0
- package/lib/cjs/x4.css +1 -0
- package/lib/cjs/x4.js +1 -0
- package/lib/esm/x4.css +1 -0
- package/lib/esm/x4.mjs +1 -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/components/calendar/calendar.ts +326 -0
- 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/core/core_dom.ts +471 -0
- package/lib/src/core/core_dragdrop.ts +201 -0
- package/lib/src/core/core_element.ts +98 -0
- package/lib/src/core/core_events.ts +149 -0
- package/lib/src/core/core_i18n.ts +377 -0
- package/lib/src/core/core_router.ts +221 -0
- 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/demo/assets/house-light.svg +1 -0
- package/lib/src/demo/assets/radio.svg +4 -0
- package/lib/src/demo/index.html +12 -0
- package/lib/src/demo/main.scss +21 -0
- package/lib/src/demo/main.tsx +323 -0
- package/lib/src/x4.scss +19 -0
- package/lib/src/x4.ts +60 -0
- package/lib/styles/x4.css +1 -0
- package/lib/types/x4.d.ts +51026 -0
- package/package.json +3 -12
- package/scripts/build.mjs +362 -0
- package/scripts/prepack.mjs +51 -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/demo/assets/house-light.svg +1 -0
- package/src/demo/assets/radio.svg +4 -0
- package/src/demo/index.html +12 -0
- package/src/demo/main.scss +21 -0
- package/src/demo/main.tsx +323 -0
- package/src/x4.scss +19 -0
- package/src/x4.ts +60 -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
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file treeview.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
|
+
:root {
|
|
18
|
+
--treeitem-backgound: var( );
|
|
19
|
+
--treeitem-color: var( );
|
|
20
|
+
|
|
21
|
+
--treeitem-backgound-hover: var( --background-secondary );
|
|
22
|
+
--treeitem-color-hover: var( );
|
|
23
|
+
|
|
24
|
+
--treeitem-background-sel: var( --accent-background );
|
|
25
|
+
--treeitem-color-sel: var( --accent-color );
|
|
26
|
+
|
|
27
|
+
--treeitem-backgound-active: var( --accent-background-active);
|
|
28
|
+
--treeitem-color-active: var( --accent-color-active );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.x4treeview {
|
|
32
|
+
overflow-y: auto;
|
|
33
|
+
height: 100%;
|
|
34
|
+
margin: 5px;
|
|
35
|
+
|
|
36
|
+
outline: none;
|
|
37
|
+
|
|
38
|
+
border: 1px solid var( --border );
|
|
39
|
+
|
|
40
|
+
&:focus {
|
|
41
|
+
border: 1px solid var( --border-focus );
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// child + subitems
|
|
45
|
+
.x4ctreeviewitem {
|
|
46
|
+
&>.label {
|
|
47
|
+
gap: 4px;
|
|
48
|
+
|
|
49
|
+
.x4label, .x4icon {
|
|
50
|
+
color: inherit;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.x4icon {
|
|
54
|
+
width: 16px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
padding: 4px;
|
|
58
|
+
|
|
59
|
+
&:hover {
|
|
60
|
+
background-color: var( --treeitem-backgound-hover );
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&.selected {
|
|
64
|
+
background-color: var( --treeitem-background-sel );
|
|
65
|
+
color: var( --treeitem-color-sel );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&:active{
|
|
69
|
+
background-color: var( --accent-background-active );
|
|
70
|
+
color: var( --accent-color-active );
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&>.body:not(:first-child) {
|
|
75
|
+
padding-left: 24px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&>.body {
|
|
79
|
+
transition: opacity 0.5s ease;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&.folder {
|
|
83
|
+
&> .label {
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: row;
|
|
86
|
+
align-items: center;
|
|
87
|
+
|
|
88
|
+
&>.x-icon {
|
|
89
|
+
transform: rotate( 0deg );
|
|
90
|
+
transition: transform 0.2s ease;
|
|
91
|
+
|
|
92
|
+
width: 16px;
|
|
93
|
+
height: 16px;
|
|
94
|
+
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&>.body {
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&:not(.open) {
|
|
104
|
+
&>.body {
|
|
105
|
+
//display: none;
|
|
106
|
+
height: 0;
|
|
107
|
+
opacity: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
&>.label>.x4icon {
|
|
111
|
+
transform: rotate( -90deg );
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file treeview.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, ComponentProps, componentFromDOM } from '@core/component';
|
|
18
|
+
|
|
19
|
+
import { Label } from '../label/label';
|
|
20
|
+
import { ListboxID, ListItem, kbNav } from '../listbox/listbox';
|
|
21
|
+
import { Box, BoxProps, HBox, VBox } from '../boxes/boxes';
|
|
22
|
+
import { Icon } from '../icon/icon.js';
|
|
23
|
+
|
|
24
|
+
import "./treeview.module.scss";
|
|
25
|
+
import folder_icon from "./chevron-down-light.svg"
|
|
26
|
+
|
|
27
|
+
//import folder_closed from "./folder-minus-light.svg"
|
|
28
|
+
|
|
29
|
+
export enum kbTreeNav {
|
|
30
|
+
first,
|
|
31
|
+
prev,
|
|
32
|
+
next,
|
|
33
|
+
last,
|
|
34
|
+
|
|
35
|
+
parent,
|
|
36
|
+
child,
|
|
37
|
+
|
|
38
|
+
expand,
|
|
39
|
+
collapse,
|
|
40
|
+
toggle,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export interface TreeItem extends ListItem {
|
|
45
|
+
children?: TreeItem[];
|
|
46
|
+
open?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface TreeviewProps extends Omit<ComponentProps,"content"> {
|
|
50
|
+
items: TreeItem[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
interface ChangeEvent extends ComponentEvent {
|
|
54
|
+
selection: TreeItem;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface TreeviewEvents extends ComponentEvents {
|
|
58
|
+
change: ChangeEvent;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class CTreeViewItem extends Box {
|
|
62
|
+
|
|
63
|
+
private _item: TreeItem;
|
|
64
|
+
private _label: Component;
|
|
65
|
+
private _icon: Icon;
|
|
66
|
+
private _childs: Component;
|
|
67
|
+
|
|
68
|
+
constructor( props: BoxProps, item: TreeItem ) {
|
|
69
|
+
super( { ...props } );
|
|
70
|
+
|
|
71
|
+
this._item = item;
|
|
72
|
+
|
|
73
|
+
if( item ) {
|
|
74
|
+
this._label = new HBox( {cls:"label item", content: [
|
|
75
|
+
this._icon = new Icon( { iconId: item.children? folder_icon : item.iconId } ),
|
|
76
|
+
new Label( { tag: "span", cls: "", text: item.text } ),
|
|
77
|
+
]});
|
|
78
|
+
|
|
79
|
+
this._label.setData( "id", item.id+"" );
|
|
80
|
+
|
|
81
|
+
if( item.children ) {
|
|
82
|
+
this. _childs = new VBox( { cls: "body" } );
|
|
83
|
+
|
|
84
|
+
if( item.open===undefined ) {
|
|
85
|
+
item.open = false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.addClass( "folder" )
|
|
89
|
+
this.setClass( "open", item.open );
|
|
90
|
+
this.setItems( item.children );
|
|
91
|
+
|
|
92
|
+
this._icon.addDOMEvent( "click", ( ev )=>this.toggle(ev) );
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
this. _childs = new VBox( { cls: "body" } );
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.setContent( [
|
|
100
|
+
this._label,
|
|
101
|
+
this._childs,
|
|
102
|
+
] );
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
toggle( ev?: UIEvent ) {
|
|
106
|
+
|
|
107
|
+
const isOpen = this.hasClass("open");
|
|
108
|
+
this.open( !isOpen );
|
|
109
|
+
|
|
110
|
+
if( ev ) {
|
|
111
|
+
ev.stopPropagation( );
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
open( open = true ) {
|
|
116
|
+
this.setClass( "open", open );
|
|
117
|
+
this._item.open = open;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setItems( items: TreeItem[ ] ) {
|
|
121
|
+
if( items ) {
|
|
122
|
+
const childs = items.map( itm => {
|
|
123
|
+
return new CTreeViewItem( {}, itm );
|
|
124
|
+
})
|
|
125
|
+
this._childs.setContent( childs );
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
this._childs.clearContent( );
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
export class Treeview extends Component<TreeviewProps,TreeviewEvents> {
|
|
138
|
+
private _selection: ListboxID;
|
|
139
|
+
private _selitem: Component;
|
|
140
|
+
private _items: TreeItem[];
|
|
141
|
+
|
|
142
|
+
constructor( props: TreeviewProps ) {
|
|
143
|
+
super( props );
|
|
144
|
+
|
|
145
|
+
if( props.items ) {
|
|
146
|
+
this.setItems( props.items );
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.setAttribute( "tabindex", 0 );
|
|
150
|
+
this.setDOMEvents( {
|
|
151
|
+
click: ( ev ) => this._onclick( ev ),
|
|
152
|
+
keydown: ( ev ) => this._onkey( ev ),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
*
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
setItems( items: TreeItem[ ] ) {
|
|
161
|
+
this._items = items;
|
|
162
|
+
|
|
163
|
+
const root = new CTreeViewItem( { cls: "root"}, null );
|
|
164
|
+
root.setItems( items );
|
|
165
|
+
this.setContent( root );
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private _onclick( ev: UIEvent ) {
|
|
169
|
+
let target = ev.target as HTMLElement;
|
|
170
|
+
while( target && target!=this.dom ) {
|
|
171
|
+
const c = componentFromDOM( target );
|
|
172
|
+
|
|
173
|
+
if( c && c.hasClass("item") ) {
|
|
174
|
+
const id = c.getData( "id" );
|
|
175
|
+
this._selectItem( id, c );
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
target = target.parentElement;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
this.clearSelection( );
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private _onkey( ev: KeyboardEvent ) {
|
|
186
|
+
switch( ev.key ) {
|
|
187
|
+
case "ArrowDown": {
|
|
188
|
+
this.navigate( kbTreeNav.next );
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
case "ArrowUp": {
|
|
193
|
+
this.navigate( kbTreeNav.prev );
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
case "Home": {
|
|
198
|
+
this.navigate( kbTreeNav.first );
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
case "End": {
|
|
203
|
+
this.navigate( kbTreeNav.last );
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
case "ArrowRight":{
|
|
208
|
+
this.navigate( kbTreeNav.child );
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
case "+": {
|
|
213
|
+
this.navigate( kbTreeNav.expand );
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
case "ArrowLeft": {
|
|
218
|
+
this.navigate( kbTreeNav.parent );
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
case "-": {
|
|
223
|
+
this.navigate( kbTreeNav.collapse );
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
case ' ': {
|
|
229
|
+
this.navigate( kbTreeNav.toggle );
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
default:
|
|
234
|
+
console.log( ev.key );
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
ev.preventDefault( );
|
|
239
|
+
ev.stopPropagation( );
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
navigate( sens: kbTreeNav ) {
|
|
247
|
+
|
|
248
|
+
if( !this._items || this._items.length==0 ) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if( !this._selitem ) {
|
|
253
|
+
if( sens==kbTreeNav.next || sens==kbTreeNav.parent ) sens = kbTreeNav.first;
|
|
254
|
+
else if( sens==kbTreeNav.prev ) sens = kbTreeNav.last;
|
|
255
|
+
else return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const p = this._selitem?.parentElement<CTreeViewItem>( );
|
|
259
|
+
const isFolder = p?.hasClass("folder");
|
|
260
|
+
|
|
261
|
+
if( p && sens==kbTreeNav.parent && isFolder && p.hasClass("open") ) {
|
|
262
|
+
sens = kbTreeNav.collapse;
|
|
263
|
+
}
|
|
264
|
+
else if( sens==kbTreeNav.child ) {
|
|
265
|
+
if( isFolder) {
|
|
266
|
+
if( !p.hasClass("open") ) {
|
|
267
|
+
sens = kbTreeNav.expand;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
sens = kbTreeNav.next;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
sens = kbTreeNav.next;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if( sens==kbTreeNav.expand || sens==kbTreeNav.collapse || sens==kbTreeNav.toggle ) {
|
|
279
|
+
if( isFolder ) {
|
|
280
|
+
if( sens==kbTreeNav.toggle ) {
|
|
281
|
+
p.toggle( );
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
p.open( sens==kbTreeNav.expand );
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
const all = this._flattenOpenItems( );
|
|
292
|
+
let cur = all.findIndex( x => this._selection==x.id );
|
|
293
|
+
|
|
294
|
+
let newSel: ListboxID;
|
|
295
|
+
|
|
296
|
+
if( sens==kbTreeNav.first ) {
|
|
297
|
+
newSel = all[0].id;
|
|
298
|
+
}
|
|
299
|
+
else if( sens==kbTreeNav.last ) {
|
|
300
|
+
newSel = all[all.length-1].id;
|
|
301
|
+
}
|
|
302
|
+
else if( cur>=0 ) {
|
|
303
|
+
if( sens==kbTreeNav.prev ) {
|
|
304
|
+
if( cur>0 ) {
|
|
305
|
+
newSel = all[cur-1].id;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else if( sens==kbTreeNav.next ) {
|
|
309
|
+
if( cur<all.length-1 ) {
|
|
310
|
+
newSel = all[cur+1].id;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if( sens==kbTreeNav.parent ) {
|
|
314
|
+
|
|
315
|
+
const clevel = all[cur].level;
|
|
316
|
+
while( cur>0 ) {
|
|
317
|
+
cur--;
|
|
318
|
+
if( all[cur].level<clevel ) {
|
|
319
|
+
newSel = all[cur].id;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if( newSel ) {
|
|
327
|
+
const nsel = this.query( `[data-id="${newSel}"]`)
|
|
328
|
+
this._selectItem( newSel, nsel );
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private _flattenOpenItems( ) {
|
|
337
|
+
let all: { id: ListboxID, level: number }[] = [];
|
|
338
|
+
|
|
339
|
+
const build = ( x: TreeItem, level: number ) => {
|
|
340
|
+
all.push( {id: x.id+"", level } );
|
|
341
|
+
if( x.children && x.open ) {
|
|
342
|
+
x.children.forEach( y => build( y, level+1 ) );
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
this._items.forEach( y => build( y, 0 ) );
|
|
347
|
+
return all;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private _flattenItems( ) {
|
|
351
|
+
let all: TreeItem[] = [];
|
|
352
|
+
|
|
353
|
+
const build = ( x: TreeItem ) => {
|
|
354
|
+
all.push( x );
|
|
355
|
+
if( x.children ) {
|
|
356
|
+
x.children.forEach( y => build(y) );
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
this._items.forEach( y => build( y ) );
|
|
361
|
+
return all;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private _selectItem( id: ListboxID, item: Component ) {
|
|
365
|
+
if( this._selitem ) {
|
|
366
|
+
this._selitem.removeClass( "selected" );
|
|
367
|
+
this._selitem = undefined;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
this._selitem = item;
|
|
371
|
+
this._selection = id;
|
|
372
|
+
|
|
373
|
+
if( item ) {
|
|
374
|
+
item.addClass( "selected" );
|
|
375
|
+
item.scrollIntoView( {
|
|
376
|
+
behavior: "smooth",
|
|
377
|
+
block: "nearest"
|
|
378
|
+
} );
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const itm = this._findItem( id );
|
|
382
|
+
this.fire( "change", { selection: itm } );
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private _findItem( id: ListboxID ) {
|
|
386
|
+
const all = this._flattenItems( );
|
|
387
|
+
return all.find( x => x.id==id );
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
*
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
clearSelection( ) {
|
|
395
|
+
if( this._selitem ) {
|
|
396
|
+
this._selitem.removeClass( "selected" );
|
|
397
|
+
this._selitem = undefined;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this._selection = undefined;
|
|
401
|
+
this.fire( "change", { selection: undefined } );
|
|
402
|
+
}
|
|
403
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file viewport.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
|
+
.x4scrollview {
|
|
20
|
+
@extend .flex;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.x4viewport {
|
|
24
|
+
width: 100%;
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ___ ___ __
|
|
3
|
+
* \ \/ / / _
|
|
4
|
+
* \ / /_| |_
|
|
5
|
+
* / \____ _|
|
|
6
|
+
* /__/\__\ |_|
|
|
7
|
+
*
|
|
8
|
+
* @file viewport.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, ComponentProps } from "@core/component"
|
|
18
|
+
|
|
19
|
+
import "./viewport.module.scss"
|
|
20
|
+
|
|
21
|
+
export class Viewport extends Component {
|
|
22
|
+
constructor( props: ComponentProps ) {
|
|
23
|
+
super( props );
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ScrollView extends Component {
|
|
28
|
+
constructor( props: ComponentProps ) {
|
|
29
|
+
super( props );
|
|
30
|
+
this.setContent( new Viewport( {} ) );
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getViewport( ) {
|
|
34
|
+
return this.firstChild<Viewport>( );
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|