native-document 1.0.166 → 1.0.169
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/.vitepress/config.js +166 -0
- package/CHANGELOG.md +187 -0
- package/components.js +4 -1
- package/dist/native-document.components.min.js +593 -300
- package/dist/native-document.dev.js +99 -75
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/advanced-components.md +213 -608
- package/docs/anchor.md +173 -312
- package/docs/cache.md +95 -803
- package/docs/cli.md +179 -0
- package/docs/components/accordion.md +172 -0
- package/docs/components/alert.md +99 -0
- package/docs/components/avatar.md +160 -0
- package/docs/components/badge.md +102 -0
- package/docs/components/breadcrumb.md +89 -0
- package/docs/components/button.md +183 -0
- package/docs/components/card.md +69 -0
- package/docs/components/context-menu.md +118 -0
- package/docs/components/data-table.md +345 -0
- package/docs/components/dropdown.md +214 -0
- package/docs/components/form/autocomplete-field.md +81 -0
- package/docs/components/form/checkbox-field.md +41 -0
- package/docs/components/form/checkbox-group-field.md +54 -0
- package/docs/components/form/color-field.md +64 -0
- package/docs/components/form/date-field.md +92 -0
- package/docs/components/form/field-collection.md +63 -0
- package/docs/components/form/file-field.md +203 -0
- package/docs/components/form/form-control.md +87 -0
- package/docs/components/form/image-field.md +90 -0
- package/docs/components/form/index.md +115 -0
- package/docs/components/form/number-field.md +65 -0
- package/docs/components/form/radio-field.md +51 -0
- package/docs/components/form/select-field.md +123 -0
- package/docs/components/form/slider.md +136 -0
- package/docs/components/form/string-field.md +134 -0
- package/docs/components/form/textarea-field.md +65 -0
- package/docs/components/form-fields.md +372 -0
- package/docs/components/getting-started.md +264 -0
- package/docs/components/icons.md +321 -0
- package/docs/components/index.md +337 -0
- package/docs/components/layout.md +279 -0
- package/docs/components/list.md +73 -0
- package/docs/components/menu.md +215 -0
- package/docs/components/modal.md +156 -0
- package/docs/components/pagination.md +95 -0
- package/docs/components/popover.md +131 -0
- package/docs/components/progress.md +111 -0
- package/docs/components/shortcut-manager.md +221 -0
- package/docs/components/simple-table.md +107 -0
- package/docs/components/skeleton.md +155 -0
- package/docs/components/spinner.md +100 -0
- package/docs/components/splitter.md +133 -0
- package/docs/components/stepper.md +163 -0
- package/docs/components/switch.md +113 -0
- package/docs/components/tabs.md +153 -0
- package/docs/components/toast.md +119 -0
- package/docs/components/tooltip.md +151 -0
- package/docs/components/traits.md +261 -0
- package/docs/conditional-rendering.md +170 -588
- package/docs/contributing.md +300 -25
- package/docs/core-concepts.md +205 -374
- package/docs/elements.md +251 -367
- package/docs/extending-native-document-element.md +192 -207
- package/docs/filters.md +153 -1122
- package/docs/getting-started.md +193 -267
- package/docs/i18n.md +241 -0
- package/docs/index.md +76 -0
- package/docs/lifecycle-events.md +143 -75
- package/docs/list-rendering.md +227 -852
- package/docs/memory-management.md +134 -47
- package/docs/native-document-element.md +337 -186
- package/docs/native-fetch.md +99 -630
- package/docs/observable-resource.md +364 -0
- package/docs/observables.md +592 -526
- package/docs/routing.md +244 -653
- package/docs/state-management.md +134 -241
- package/docs/svg-elements.md +231 -0
- package/docs/theming.md +409 -0
- package/docs/tutorials/.gitkeep +0 -0
- package/docs/validation.md +95 -97
- package/docs/vitepress-conventions.md +219 -0
- package/package.json +34 -13
- package/readme.md +269 -89
- package/src/components/card/Card.js +93 -39
- package/src/components/card/index.js +1 -1
- package/src/components/form/field/types/FileField.js +3 -3
- package/src/components/icon/Icon.js +107 -0
- package/src/components/icon/icon-getters.js +142 -0
- package/src/components/icon/icons.js +171 -0
- package/src/components/icon/index.js +17 -0
- package/src/components/icon/types/Icon.d.ts +191 -0
- package/src/components/index.d.ts +6 -1
- package/src/components/list/HasListItem.js +171 -0
- package/src/components/list/List.js +41 -107
- package/src/components/list/ListDivider.js +39 -0
- package/src/components/list/ListGroup.js +76 -59
- package/src/components/list/ListItem.js +117 -69
- package/src/components/list/index.js +3 -1
- package/src/components/list/types/List.d.ts +45 -32
- package/src/components/list/types/ListDivider.ts +16 -0
- package/src/components/list/types/ListGroup.d.ts +51 -29
- package/src/components/list/types/ListItem.d.ts +40 -30
- package/src/components/spacer/Spacer.js +1 -1
- package/src/core/data/ObservableResource.js +5 -0
- package/src/core/data/observable-helpers/observable.prototypes.js +2 -0
- package/src/core/elements/content-formatter.js +16 -2
- package/src/core/elements/form.js +1 -1
- package/src/core/elements/img.js +1 -1
- package/src/core/elements/medias.js +2 -2
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/wrappers/AttributesWrapper.js +37 -22
- package/src/core/wrappers/ElementCreator.js +9 -16
- package/src/core/wrappers/HtmlElementWrapper.js +26 -7
- package/src/core/wrappers/NDElement.js +12 -1
- package/src/core/wrappers/prototypes/attributes-extensions.js +24 -24
- package/src/core/wrappers/prototypes/nd-element-extensions.js +1 -8
- package/src/ui/components/card/CardRender.js +133 -0
- package/src/ui/components/card/card.css +169 -0
- package/src/ui/components/contextmenu/ContextmenuRender.js +1 -1
- package/src/ui/components/icon/material/MaterialIconRender.js +71 -0
- package/src/ui/components/icon/material/material.css +15 -0
- package/src/ui/components/icon/material/material.map.js +170 -0
- package/src/ui/components/icon/phosphor/PhosphorIconRender.js +71 -0
- package/src/ui/components/icon/phosphor/phosphor.css +17 -0
- package/src/ui/components/icon/phosphor/phosphor.map.js +165 -0
- package/src/ui/components/icon/tabler/TablerIconRender.js +59 -0
- package/src/ui/components/icon/tabler/tabler.css +14 -0
- package/src/ui/components/icon/tabler/tabler.map.js +165 -0
- package/src/ui/components/list/ListRender.js +18 -0
- package/src/ui/components/list/divider/ListDividerRender.js +10 -0
- package/src/ui/components/list/divider/list-divider.css +12 -0
- package/src/ui/components/list/group/ListGroupRender.js +61 -0
- package/src/ui/components/list/group/list-group.css +62 -0
- package/src/ui/components/list/item/ListItemRender.js +238 -0
- package/src/ui/components/list/item/list-item.css +191 -0
- package/src/ui/components/list/list.css +24 -0
- package/src/ui/components/spacer/SpacerRender.js +10 -0
- package/src/ui/index.js +13 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
// Navigation
|
|
3
|
+
arrowLeft: 'arrow-left',
|
|
4
|
+
arrowRight: 'arrow-right',
|
|
5
|
+
arrowUp: 'arrow-up',
|
|
6
|
+
arrowDown: 'arrow-down',
|
|
7
|
+
chevronLeft: 'chevron-left',
|
|
8
|
+
chevronRight: 'chevron-right',
|
|
9
|
+
chevronUp: 'chevron-up',
|
|
10
|
+
chevronDown: 'chevron-down',
|
|
11
|
+
home: 'home',
|
|
12
|
+
menu: 'menu-2',
|
|
13
|
+
close: 'x',
|
|
14
|
+
back: 'arrow-back',
|
|
15
|
+
forward: 'arrow-forward',
|
|
16
|
+
expand: 'arrows-maximize',
|
|
17
|
+
collapse: 'arrows-minimize',
|
|
18
|
+
fullscreen: 'maximize',
|
|
19
|
+
fullscreenExit: 'minimize',
|
|
20
|
+
|
|
21
|
+
// Actions
|
|
22
|
+
search: 'search',
|
|
23
|
+
filter: 'filter',
|
|
24
|
+
sort: 'arrows-sort',
|
|
25
|
+
edit: 'pencil',
|
|
26
|
+
delete: 'trash',
|
|
27
|
+
add: 'plus',
|
|
28
|
+
remove: 'minus',
|
|
29
|
+
save: 'device-floppy',
|
|
30
|
+
copy: 'copy',
|
|
31
|
+
download: 'download',
|
|
32
|
+
upload: 'upload',
|
|
33
|
+
share: 'share',
|
|
34
|
+
refresh: 'refresh',
|
|
35
|
+
more: 'dots',
|
|
36
|
+
settings: 'settings',
|
|
37
|
+
drag: 'grip-horizontal',
|
|
38
|
+
resize: 'resize',
|
|
39
|
+
undo: 'arrow-back-up',
|
|
40
|
+
redo: 'arrow-forward-up',
|
|
41
|
+
scan: 'scan',
|
|
42
|
+
print: 'printer',
|
|
43
|
+
import: 'file-import',
|
|
44
|
+
export: 'file-export',
|
|
45
|
+
|
|
46
|
+
// Feedback
|
|
47
|
+
check: 'check',
|
|
48
|
+
checkCircle: 'circle-check',
|
|
49
|
+
error: 'circle-x',
|
|
50
|
+
warning: 'alert-triangle',
|
|
51
|
+
info: 'info-circle',
|
|
52
|
+
help: 'help-circle',
|
|
53
|
+
loading: 'loader-2',
|
|
54
|
+
success: 'circle-check',
|
|
55
|
+
|
|
56
|
+
// User
|
|
57
|
+
user: 'user',
|
|
58
|
+
userCircle: 'user-circle',
|
|
59
|
+
users: 'users',
|
|
60
|
+
lock: 'lock',
|
|
61
|
+
unlock: 'lock-open',
|
|
62
|
+
eye: 'eye',
|
|
63
|
+
eyeOff: 'eye-off',
|
|
64
|
+
bell: 'bell',
|
|
65
|
+
notification: 'bell-ringing',
|
|
66
|
+
|
|
67
|
+
// Files & Media
|
|
68
|
+
file: 'file',
|
|
69
|
+
folder: 'folder',
|
|
70
|
+
image: 'photo',
|
|
71
|
+
document: 'file-text',
|
|
72
|
+
attachment: 'paperclip',
|
|
73
|
+
link: 'link',
|
|
74
|
+
externalLink: 'external-link',
|
|
75
|
+
play: 'player-play',
|
|
76
|
+
pause: 'player-pause',
|
|
77
|
+
stop: 'player-stop',
|
|
78
|
+
mute: 'volume-off',
|
|
79
|
+
sound: 'volume',
|
|
80
|
+
video: 'video',
|
|
81
|
+
camera: 'camera',
|
|
82
|
+
|
|
83
|
+
// Interface
|
|
84
|
+
grid: 'layout-grid',
|
|
85
|
+
list: 'list',
|
|
86
|
+
calendar: 'calendar',
|
|
87
|
+
clock: 'clock',
|
|
88
|
+
tag: 'tag',
|
|
89
|
+
tags: 'tags',
|
|
90
|
+
qrCode: 'qrcode',
|
|
91
|
+
barcode: 'barcode',
|
|
92
|
+
|
|
93
|
+
// Text editing
|
|
94
|
+
bold: 'bold',
|
|
95
|
+
italic: 'italic',
|
|
96
|
+
underline: 'underline',
|
|
97
|
+
strikethrough: 'strikethrough',
|
|
98
|
+
alignLeft: 'align-left',
|
|
99
|
+
alignCenter: 'align-center',
|
|
100
|
+
alignRight: 'align-right',
|
|
101
|
+
alignJustify: 'align-justified',
|
|
102
|
+
orderedList: 'list-numbers',
|
|
103
|
+
unorderedList: 'list',
|
|
104
|
+
indent: 'indent-increase',
|
|
105
|
+
outdent: 'indent-decrease',
|
|
106
|
+
scissors: 'scissors',
|
|
107
|
+
fontColor: 'letter-case',
|
|
108
|
+
highlight: 'highlight',
|
|
109
|
+
|
|
110
|
+
// Data & charts
|
|
111
|
+
barChart: 'chart-bar',
|
|
112
|
+
lineChart: 'chart-line',
|
|
113
|
+
pieChart: 'chart-pie',
|
|
114
|
+
areaChart: 'chart-area',
|
|
115
|
+
table: 'table',
|
|
116
|
+
database: 'database',
|
|
117
|
+
|
|
118
|
+
// Commerce & finance
|
|
119
|
+
shoppingCart: 'shopping-cart',
|
|
120
|
+
creditCard: 'credit-card',
|
|
121
|
+
wallet: 'wallet',
|
|
122
|
+
bank: 'building-bank',
|
|
123
|
+
gift: 'gift',
|
|
124
|
+
percentage: 'percentage',
|
|
125
|
+
dollar: 'currency-dollar',
|
|
126
|
+
euro: 'currency-euro',
|
|
127
|
+
|
|
128
|
+
// Communication
|
|
129
|
+
mail: 'mail',
|
|
130
|
+
message: 'message',
|
|
131
|
+
comment: 'message-circle',
|
|
132
|
+
phone: 'phone',
|
|
133
|
+
|
|
134
|
+
// System & dev
|
|
135
|
+
cloud: 'cloud',
|
|
136
|
+
cloudUpload: 'cloud-upload',
|
|
137
|
+
cloudDownload: 'cloud-download',
|
|
138
|
+
api: 'api',
|
|
139
|
+
code: 'code',
|
|
140
|
+
bug: 'bug',
|
|
141
|
+
tool: 'tool',
|
|
142
|
+
robot: 'robot',
|
|
143
|
+
|
|
144
|
+
// Location
|
|
145
|
+
map: 'map',
|
|
146
|
+
compass: 'compass',
|
|
147
|
+
global: 'world',
|
|
148
|
+
location: 'map-pin',
|
|
149
|
+
|
|
150
|
+
// Shapes & objects
|
|
151
|
+
star: 'star',
|
|
152
|
+
heart: 'heart',
|
|
153
|
+
flag: 'flag',
|
|
154
|
+
trophy: 'trophy',
|
|
155
|
+
medal: 'medal',
|
|
156
|
+
rocket: 'rocket',
|
|
157
|
+
fire: 'flame',
|
|
158
|
+
thunder: 'bolt',
|
|
159
|
+
smile: 'mood-smile',
|
|
160
|
+
frown: 'mood-sad',
|
|
161
|
+
like: 'thumb-up',
|
|
162
|
+
dislike: 'thumb-down',
|
|
163
|
+
safety: 'shield-check',
|
|
164
|
+
key: 'key',
|
|
165
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Ul, ForEachArray } from '../../../core/elements';
|
|
2
|
+
|
|
3
|
+
import './list.css';
|
|
4
|
+
|
|
5
|
+
export default function ListRender($desc, instance) {
|
|
6
|
+
const props = instance.getEditableProps();
|
|
7
|
+
|
|
8
|
+
props.class.add({ list: true, 'with-divider': $desc.divider });
|
|
9
|
+
|
|
10
|
+
if ($desc.inset) {
|
|
11
|
+
props.style.add(
|
|
12
|
+
'--list-inset-padding',
|
|
13
|
+
$desc.inset.transform((v) => v > 0 ? `${v}px` : null),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Ul(instance.resolveProps(), ForEachArray($desc.items, $desc.itemBuilder));
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Li } from '../../../../core/elements';
|
|
2
|
+
|
|
3
|
+
import './list-divider.css';
|
|
4
|
+
|
|
5
|
+
export default function ListDividerRender($desc, instance) {
|
|
6
|
+
const props = instance.getEditableProps();
|
|
7
|
+
props.class.add('list-divider');
|
|
8
|
+
|
|
9
|
+
return Li(instance.resolveProps());
|
|
10
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Li, Div, Span, ForEachArray, ShowIf, Switch } from '../../../../core/elements';
|
|
2
|
+
|
|
3
|
+
import './list-group.css';
|
|
4
|
+
|
|
5
|
+
export default function ListGroupRender($desc, instance) {
|
|
6
|
+
if ($desc.render) {
|
|
7
|
+
return $desc.render($desc, instance);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const props = instance.getEditableProps();
|
|
11
|
+
props.class.add('list-group');
|
|
12
|
+
|
|
13
|
+
if ($desc.collapsable) {
|
|
14
|
+
props.class.add('is-collapsable');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const content = [];
|
|
18
|
+
|
|
19
|
+
if ($desc.label || $desc.icon) {
|
|
20
|
+
content.push(buildGroupHeader($desc, instance));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ($desc.collapsable && $desc.collapsed) {
|
|
24
|
+
content.push(ShowIf($desc.collapsed, () => Div({ class: 'list-group-items' }, ForEachArray($desc.items))));
|
|
25
|
+
} else {
|
|
26
|
+
content.push(Div({ class: 'list-group-items' }, ForEachArray($desc.items)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return Li(instance.resolveProps(), content);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function buildGroupHeader($desc, instance) {
|
|
33
|
+
const content = [];
|
|
34
|
+
|
|
35
|
+
if ($desc.icon) {
|
|
36
|
+
content.push(Span({ class: 'list-group-icon' }, $desc.icon));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ($desc.label) {
|
|
40
|
+
content.push(Span({ class: 'list-group-label' }, $desc.label));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ($desc.collapsable && $desc.collapsed) {
|
|
44
|
+
const openedIcon = $desc.collapsableOpenedIcon || '▾';
|
|
45
|
+
const closedIcon = $desc.collapsableClosedIcon || '▸';
|
|
46
|
+
|
|
47
|
+
content.push(
|
|
48
|
+
Span({ class: $desc.collapsed.transform((c) => 'list-group-chevron' + (c ? '' : ' is-open')) },
|
|
49
|
+
Switch($desc.collapsed, closedIcon, openedIcon),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const header = Div({ class: 'list-group-header' }, content);
|
|
55
|
+
|
|
56
|
+
if ($desc.collapsable && $desc.collapsed) {
|
|
57
|
+
header.nd.onStopClick(() => $desc.collapsed.toggle());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return header;
|
|
61
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--list-group-header-padding: 6px 14px 4px;
|
|
3
|
+
--list-group-header-font-size: var(--note-size);
|
|
4
|
+
--list-group-header-weight: 500;
|
|
5
|
+
--list-group-header-color: var(--gray);
|
|
6
|
+
--list-group-header-color-hover: var(--text-color);
|
|
7
|
+
--list-group-header-letter-spacing: 0.05em;
|
|
8
|
+
--list-group-icon-size: 14px;
|
|
9
|
+
--list-group-icon-color: var(--gray);
|
|
10
|
+
--list-group-chevron-size: 11px;
|
|
11
|
+
--list-group-items-indent: 14px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.list-group {
|
|
15
|
+
list-style: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.list-group-header {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
gap: 8px;
|
|
22
|
+
padding: var(--list-group-header-padding);
|
|
23
|
+
font-size: var(--list-group-header-font-size);
|
|
24
|
+
font-weight: var(--list-group-header-weight);
|
|
25
|
+
color: var(--list-group-header-color);
|
|
26
|
+
letter-spacing: var(--list-group-header-letter-spacing);
|
|
27
|
+
user-select: none;
|
|
28
|
+
|
|
29
|
+
.is-collapsable & {
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
|
|
32
|
+
&:hover {
|
|
33
|
+
color: var(--list-group-header-color-hover);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.list-group-icon {
|
|
39
|
+
font-size: var(--list-group-icon-size);
|
|
40
|
+
color: var(--list-group-icon-color);
|
|
41
|
+
flex-shrink: 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.list-group-label {
|
|
45
|
+
flex: 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.list-group-chevron {
|
|
49
|
+
font-size: var(--list-group-chevron-size);
|
|
50
|
+
transition: transform 0.15s ease;
|
|
51
|
+
flex-shrink: 0;
|
|
52
|
+
|
|
53
|
+
&.is-open {
|
|
54
|
+
transform: rotate(90deg);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.list-group-items {
|
|
59
|
+
.list-item {
|
|
60
|
+
padding-left: calc(var(--list-group-items-indent) + 14px);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { Li, Div, Span, ShowIf } from '../../../../core/elements';
|
|
2
|
+
|
|
3
|
+
import './list-item.css';
|
|
4
|
+
|
|
5
|
+
export default function ListItemRender($desc, instance) {
|
|
6
|
+
if ($desc.render) {
|
|
7
|
+
return $desc.render($desc, instance);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const props = instance.getEditableProps();
|
|
11
|
+
|
|
12
|
+
props.class.add('list-item');
|
|
13
|
+
|
|
14
|
+
if ($desc.disabled) {
|
|
15
|
+
props.class.add('is-disabled', $desc.disabled);
|
|
16
|
+
}
|
|
17
|
+
if ($desc.selected) {
|
|
18
|
+
props.class.add('is-selected', $desc.selected);
|
|
19
|
+
}
|
|
20
|
+
if ($desc.visibility) {
|
|
21
|
+
props.class.add('is-hidden', $desc.visibility.isFalsy());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const backContent = [];
|
|
25
|
+
const frontContent = [];
|
|
26
|
+
|
|
27
|
+
const $list = instance.$parent;
|
|
28
|
+
|
|
29
|
+
// Checkbox — réactif via ShowIf
|
|
30
|
+
if ($list?.$description?.selectByCheckbox) {
|
|
31
|
+
const selectedValues = $list.$description.selectedValues;
|
|
32
|
+
const value = $desc.value ?? instance;
|
|
33
|
+
const isChecked = selectedValues ? selectedValues.isIncludes(value) : null;
|
|
34
|
+
|
|
35
|
+
const cls = isChecked
|
|
36
|
+
? isChecked.transform((c) => 'list-item-checkbox' + (c ? ' is-checked' : ''))
|
|
37
|
+
: 'list-item-checkbox';
|
|
38
|
+
|
|
39
|
+
frontContent.push(
|
|
40
|
+
ShowIf($list.$description.selectByCheckbox, () =>
|
|
41
|
+
Span({ class: cls, 'aria-hidden': 'true' })
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if ($desc.icon) {
|
|
47
|
+
frontContent.push(Span({ class: 'list-item-icon' }, $desc.icon));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
frontContent.push(buildBody($desc));
|
|
51
|
+
|
|
52
|
+
// Select indicator — réactif via isIncludes
|
|
53
|
+
if ($list?.$description?.selectByClick) {
|
|
54
|
+
const selectedValues = $list.$description.selectedValues;
|
|
55
|
+
const value = $desc.value ?? instance;
|
|
56
|
+
const isSelected = selectedValues ? selectedValues.isIncludes(value) : null;
|
|
57
|
+
|
|
58
|
+
if (isSelected) {
|
|
59
|
+
frontContent.push(
|
|
60
|
+
Span({
|
|
61
|
+
class: isSelected.transform((s) => 'list-item-indicator' + (s ? ' is-visible' : '')),
|
|
62
|
+
'aria-hidden': 'true',
|
|
63
|
+
}, $desc.isSelectedIcon)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ($desc.trailing) {
|
|
69
|
+
frontContent.push(Div({ class: 'list-item-trailing' }, $desc.trailing));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Swipe actions
|
|
73
|
+
const hasLeadingSwipe = Array.isArray($desc.swipeLeading) && $desc.swipeLeading.length > 0;
|
|
74
|
+
const hasTrailingSwipe = Array.isArray($desc.swipeTrailing) && $desc.swipeTrailing.length > 0;
|
|
75
|
+
|
|
76
|
+
if (hasLeadingSwipe || hasTrailingSwipe) {
|
|
77
|
+
props.class.add('is-swipeable');
|
|
78
|
+
|
|
79
|
+
if (hasLeadingSwipe) {
|
|
80
|
+
backContent.push(Div({ class: 'swipe-actions-container container-leading' }, $desc.swipeLeading));
|
|
81
|
+
}
|
|
82
|
+
if (hasTrailingSwipe) {
|
|
83
|
+
backContent.push(Div({ class: 'swipe-actions-container container-trailing' }, $desc.swipeTrailing));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const elFront = Div({ class: 'list-item-content' }, frontContent);
|
|
88
|
+
const elBack = backContent.length > 0
|
|
89
|
+
? Div({ class: 'list-item-swipe-background' }, backContent)
|
|
90
|
+
: null;
|
|
91
|
+
|
|
92
|
+
const el = Li(instance.resolveProps(), elBack ? [elBack, elFront] : [elFront]);
|
|
93
|
+
|
|
94
|
+
if (elBack) {
|
|
95
|
+
setupSwipeEvents(elFront, elBack, hasLeadingSwipe, hasTrailingSwipe);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
el.nd.onClick((e) => {
|
|
99
|
+
if ($desc.disabled) return;
|
|
100
|
+
|
|
101
|
+
const $list = instance.$parent;
|
|
102
|
+
if (!$list) {
|
|
103
|
+
instance.emit('click', instance, e);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const desc = $list.$description;
|
|
108
|
+
if (desc.selectable || desc.selectByClick || desc.selectByCheckbox) {
|
|
109
|
+
handleSelect($list, $desc, instance);
|
|
110
|
+
instance.emit('itemSelect', instance);
|
|
111
|
+
$list.emit('itemSelect', instance);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
instance.emit('click', instance, e);
|
|
115
|
+
$list.emit('itemClick', instance, e);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return el;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function buildBody($desc) {
|
|
122
|
+
const parts = [];
|
|
123
|
+
|
|
124
|
+
if ($desc.label) {
|
|
125
|
+
parts.push(Span({ class: 'list-item-label' }, $desc.label));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if ($desc.subtitle) {
|
|
129
|
+
parts.push(Span({ class: 'list-item-subtitle' }, $desc.subtitle));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return Div({ class: 'list-item-body' }, parts);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function handleSelect($list, $desc, instance) {
|
|
136
|
+
const $values = $list.$description.selectedValues;
|
|
137
|
+
if (!$values) return;
|
|
138
|
+
|
|
139
|
+
const value = $desc.value ?? instance;
|
|
140
|
+
|
|
141
|
+
if ($values.includes(value)) {
|
|
142
|
+
$values.removeItem(value);
|
|
143
|
+
} else {
|
|
144
|
+
if (!$list.$description.multiSelect.val()) {
|
|
145
|
+
$values.clear();
|
|
146
|
+
}
|
|
147
|
+
$values.push(value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function setupSwipeEvents(elFront, elBack, hasLeading, hasTrailing) {
|
|
152
|
+
let startX = 0;
|
|
153
|
+
let currentX = 0;
|
|
154
|
+
let isSwiping = false;
|
|
155
|
+
let isOpen = false;
|
|
156
|
+
|
|
157
|
+
const leadingContainer = elBack.querySelector('.container-leading');
|
|
158
|
+
const trailingContainer = elBack.querySelector('.container-trailing');
|
|
159
|
+
|
|
160
|
+
// Stop propagation on all swipe action clicks — must not bubble to list-item onClick
|
|
161
|
+
elBack.addEventListener('click', (e) => e.stopPropagation());
|
|
162
|
+
|
|
163
|
+
elFront.addEventListener('pointerdown', (e) => {
|
|
164
|
+
startX = e.clientX;
|
|
165
|
+
isSwiping = true;
|
|
166
|
+
elFront.style.transition = 'none';
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
elFront.addEventListener('pointermove', (e) => {
|
|
170
|
+
if (!isSwiping) return;
|
|
171
|
+
|
|
172
|
+
let diffX = e.clientX - startX;
|
|
173
|
+
|
|
174
|
+
if (diffX > 0 && !hasLeading) diffX = 0;
|
|
175
|
+
if (diffX < 0 && !hasTrailing) diffX = 0;
|
|
176
|
+
|
|
177
|
+
const threshold = diffX > 0
|
|
178
|
+
? (leadingContainer ? leadingContainer.offsetWidth : 100)
|
|
179
|
+
: (trailingContainer ? trailingContainer.offsetWidth : 100);
|
|
180
|
+
|
|
181
|
+
if (Math.abs(diffX) > threshold) {
|
|
182
|
+
diffX = diffX > 0
|
|
183
|
+
? threshold + (diffX - threshold) * 0.2
|
|
184
|
+
: -threshold + (diffX + threshold) * 0.2;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
currentX = diffX;
|
|
188
|
+
elFront.style.transform = `translate3d(${currentX}px, 0, 0)`;
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const resetSwipe = () => {
|
|
192
|
+
elFront.style.transition = 'transform 0.2s ease-out';
|
|
193
|
+
elFront.style.transform = 'translate3d(0, 0, 0)';
|
|
194
|
+
currentX = 0;
|
|
195
|
+
isOpen = false;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const closeSwipe = () => {
|
|
199
|
+
isSwiping = false;
|
|
200
|
+
elFront.style.transition = 'transform 0.2s ease-out';
|
|
201
|
+
|
|
202
|
+
const leadingThreshold = leadingContainer ? leadingContainer.offsetWidth : 100;
|
|
203
|
+
const trailingThreshold = trailingContainer ? trailingContainer.offsetWidth : 100;
|
|
204
|
+
|
|
205
|
+
if (currentX > leadingThreshold / 2 && hasLeading) {
|
|
206
|
+
elFront.style.transform = `translate3d(${leadingThreshold}px, 0, 0)`;
|
|
207
|
+
isOpen = true;
|
|
208
|
+
} else if (currentX < -trailingThreshold / 2 && hasTrailing) {
|
|
209
|
+
elFront.style.transform = `translate3d(-${trailingThreshold}px, 0, 0)`;
|
|
210
|
+
isOpen = true;
|
|
211
|
+
} else {
|
|
212
|
+
resetSwipe();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
elFront.addEventListener('pointerup', closeSwipe);
|
|
217
|
+
elFront.addEventListener('pointerleave', closeSwipe);
|
|
218
|
+
|
|
219
|
+
// Close swipe when clicking outside the item
|
|
220
|
+
const onDocumentClick = (e) => {
|
|
221
|
+
if (!isOpen) return;
|
|
222
|
+
if (!elFront.closest('.list-item')?.contains(e.target)) {
|
|
223
|
+
resetSwipe();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
document.addEventListener('click', onDocumentClick);
|
|
228
|
+
|
|
229
|
+
// Close swipe when clicking on a swipe action (after the action fires)
|
|
230
|
+
elBack.addEventListener('click', () => {
|
|
231
|
+
if (isOpen) resetSwipe();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Cleanup on unmount
|
|
235
|
+
elFront.nd?.unmounted(() => {
|
|
236
|
+
document.removeEventListener('click', onDocumentClick);
|
|
237
|
+
});
|
|
238
|
+
}
|