native-document 1.0.166 → 1.0.168

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.
Files changed (108) hide show
  1. package/.vitepress/config.js +166 -0
  2. package/CHANGELOG.md +153 -0
  3. package/components.js +2 -1
  4. package/dist/native-document.components.min.js +495 -228
  5. package/dist/native-document.dev.js +7 -0
  6. package/dist/native-document.dev.js.map +1 -1
  7. package/dist/native-document.min.js +1 -1
  8. package/docs/advanced-components.md +213 -608
  9. package/docs/anchor.md +173 -312
  10. package/docs/cache.md +95 -803
  11. package/docs/cli.md +179 -0
  12. package/docs/components/accordion.md +172 -0
  13. package/docs/components/alert.md +99 -0
  14. package/docs/components/avatar.md +160 -0
  15. package/docs/components/badge.md +102 -0
  16. package/docs/components/breadcrumb.md +89 -0
  17. package/docs/components/button.md +183 -0
  18. package/docs/components/card.md +69 -0
  19. package/docs/components/context-menu.md +118 -0
  20. package/docs/components/data-table.md +345 -0
  21. package/docs/components/dropdown.md +214 -0
  22. package/docs/components/form/autocomplete-field.md +81 -0
  23. package/docs/components/form/checkbox-field.md +41 -0
  24. package/docs/components/form/checkbox-group-field.md +54 -0
  25. package/docs/components/form/color-field.md +64 -0
  26. package/docs/components/form/date-field.md +92 -0
  27. package/docs/components/form/field-collection.md +63 -0
  28. package/docs/components/form/file-field.md +203 -0
  29. package/docs/components/form/form-control.md +87 -0
  30. package/docs/components/form/image-field.md +90 -0
  31. package/docs/components/form/index.md +115 -0
  32. package/docs/components/form/number-field.md +65 -0
  33. package/docs/components/form/radio-field.md +51 -0
  34. package/docs/components/form/select-field.md +123 -0
  35. package/docs/components/form/slider.md +136 -0
  36. package/docs/components/form/string-field.md +134 -0
  37. package/docs/components/form/textarea-field.md +65 -0
  38. package/docs/components/form-fields.md +372 -0
  39. package/docs/components/getting-started.md +264 -0
  40. package/docs/components/index.md +337 -0
  41. package/docs/components/layout.md +279 -0
  42. package/docs/components/list.md +73 -0
  43. package/docs/components/menu.md +215 -0
  44. package/docs/components/modal.md +156 -0
  45. package/docs/components/pagination.md +95 -0
  46. package/docs/components/popover.md +131 -0
  47. package/docs/components/progress.md +111 -0
  48. package/docs/components/shortcut-manager.md +221 -0
  49. package/docs/components/simple-table.md +107 -0
  50. package/docs/components/skeleton.md +155 -0
  51. package/docs/components/spinner.md +100 -0
  52. package/docs/components/splitter.md +133 -0
  53. package/docs/components/stepper.md +163 -0
  54. package/docs/components/switch.md +113 -0
  55. package/docs/components/tabs.md +153 -0
  56. package/docs/components/toast.md +119 -0
  57. package/docs/components/tooltip.md +151 -0
  58. package/docs/components/traits.md +261 -0
  59. package/docs/conditional-rendering.md +170 -588
  60. package/docs/contributing.md +300 -25
  61. package/docs/core-concepts.md +205 -374
  62. package/docs/elements.md +251 -367
  63. package/docs/extending-native-document-element.md +192 -207
  64. package/docs/filters.md +153 -1122
  65. package/docs/getting-started.md +193 -267
  66. package/docs/i18n.md +241 -0
  67. package/docs/index.md +76 -0
  68. package/docs/lifecycle-events.md +143 -75
  69. package/docs/list-rendering.md +227 -852
  70. package/docs/memory-management.md +134 -47
  71. package/docs/native-document-element.md +337 -186
  72. package/docs/native-fetch.md +99 -630
  73. package/docs/observable-resource.md +364 -0
  74. package/docs/observables.md +592 -526
  75. package/docs/routing.md +244 -653
  76. package/docs/state-management.md +134 -241
  77. package/docs/svg-elements.md +231 -0
  78. package/docs/theming.md +409 -0
  79. package/docs/tutorials/.gitkeep +0 -0
  80. package/docs/validation.md +95 -97
  81. package/docs/vitepress-conventions.md +219 -0
  82. package/package.json +34 -13
  83. package/readme.md +269 -89
  84. package/src/components/card/Card.js +93 -39
  85. package/src/components/card/index.js +1 -1
  86. package/src/components/list/HasListItem.js +171 -0
  87. package/src/components/list/List.js +41 -107
  88. package/src/components/list/ListDivider.js +39 -0
  89. package/src/components/list/ListGroup.js +76 -59
  90. package/src/components/list/ListItem.js +117 -69
  91. package/src/components/list/index.js +3 -1
  92. package/src/components/list/types/ListItem.d.ts +45 -34
  93. package/src/components/spacer/Spacer.js +1 -1
  94. package/src/core/data/ObservableResource.js +5 -0
  95. package/src/core/data/observable-helpers/observable.prototypes.js +2 -0
  96. package/src/ui/components/card/CardRender.js +133 -0
  97. package/src/ui/components/card/card.css +169 -0
  98. package/src/ui/components/contextmenu/ContextmenuRender.js +1 -1
  99. package/src/ui/components/list/ListRender.js +18 -0
  100. package/src/ui/components/list/divider/ListDividerRender.js +10 -0
  101. package/src/ui/components/list/divider/list-divider.css +12 -0
  102. package/src/ui/components/list/group/ListGroupRender.js +61 -0
  103. package/src/ui/components/list/group/list-group.css +62 -0
  104. package/src/ui/components/list/item/ListItemRender.js +238 -0
  105. package/src/ui/components/list/item/list-item.css +191 -0
  106. package/src/ui/components/list/list.css +24 -0
  107. package/src/ui/components/spacer/SpacerRender.js +10 -0
  108. package/src/ui/index.js +8 -0
@@ -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
+ }
@@ -0,0 +1,191 @@
1
+ :root {
2
+ --list-item-padding-v: 9px;
3
+ --list-item-padding-h: 14px;
4
+ --list-item-gap: 10px;
5
+ --list-item-font-size: var(--description-size);
6
+ --list-item-color: var(--text-color);
7
+ --list-item-bg-hover: var(--gray-lite-5);
8
+ --list-item-bg-selected: color-mix(in srgb, var(--blue) 8%, transparent);
9
+ --list-item-color-selected: var(--blue);
10
+ --list-item-weight-selected: 500;
11
+ --list-item-disabled-opacity: 0.45;
12
+ --list-item-transition: background 0.1s ease;
13
+
14
+ --list-item-subtitle-size: var(--note-size);
15
+ --list-item-subtitle-color: var(--gray);
16
+
17
+ --list-item-trailing-size: var(--note-size);
18
+ --list-item-trailing-color: var(--gray);
19
+
20
+ --list-item-icon-size: 16px;
21
+ --list-item-icon-color: var(--gray);
22
+
23
+ --list-item-checkbox-size: 15px;
24
+ --list-item-checkbox-radius: 4px;
25
+ --list-item-checkbox-border: var(--gray-lite-2);
26
+ --list-item-checkbox-bg: var(--blue);
27
+
28
+ --list-item-indicator-size: 12px;
29
+
30
+ --list-item-swipe-transition: transform 0.2s ease-out;
31
+ --list-item-swipe-leading-bg: var(--color-success);
32
+ --list-item-swipe-trailing-bg: var(--color-danger);
33
+ --list-item-swipe-actions-min-width: 80px;
34
+ }
35
+
36
+ /* ── Base ───────────────────────────────────────────────────── */
37
+
38
+ .list-item {
39
+ position: relative;
40
+ list-style: none;
41
+ font-size: var(--list-item-font-size);
42
+ color: var(--list-item-color);
43
+ overflow: hidden;
44
+
45
+ &.is-disabled {
46
+ opacity: var(--list-item-disabled-opacity);
47
+ cursor: not-allowed;
48
+ pointer-events: none;
49
+ }
50
+
51
+ &.is-hidden {
52
+ display: none;
53
+ }
54
+ }
55
+
56
+ /* ── Content (front layer) ──────────────────────────────────── */
57
+
58
+ .list-item-content {
59
+ position: relative;
60
+ z-index: 1;
61
+ display: flex;
62
+ align-items: center;
63
+ gap: var(--list-item-gap);
64
+ padding: var(--list-item-padding-v) var(--list-item-padding-h);
65
+ cursor: pointer;
66
+ background: var(--list-bg);
67
+ transition: var(--list-item-transition);
68
+
69
+ .list-item:hover & {
70
+ background: var(--list-item-bg-hover);
71
+ }
72
+
73
+ .list-item.is-selected & {
74
+ background: var(--list-item-bg-selected);
75
+ color: var(--list-item-color-selected);
76
+
77
+ .list-item-label {
78
+ font-weight: var(--list-item-weight-selected);
79
+ }
80
+ }
81
+
82
+ .list-item.is-swipeable & {
83
+ transition: transform 0.05s linear, background var(--fast);
84
+ }
85
+ }
86
+
87
+ /* ── Slots ──────────────────────────────────────────────────── */
88
+
89
+ .list-item-icon {
90
+ font-size: var(--list-item-icon-size);
91
+ color: var(--list-item-icon-color);
92
+ flex-shrink: 0;
93
+ display: flex;
94
+ align-items: center;
95
+ }
96
+
97
+ .list-item-body {
98
+ flex: 1;
99
+ min-width: 0;
100
+ display: flex;
101
+ flex-direction: column;
102
+ gap: 2px;
103
+ }
104
+
105
+ .list-item-label {
106
+ white-space: nowrap;
107
+ overflow: hidden;
108
+ text-overflow: ellipsis;
109
+ }
110
+
111
+ .list-item-subtitle {
112
+ font-size: var(--list-item-subtitle-size);
113
+ color: var(--list-item-subtitle-color);
114
+ white-space: nowrap;
115
+ overflow: hidden;
116
+ text-overflow: ellipsis;
117
+ }
118
+
119
+ .list-item-trailing {
120
+ flex-shrink: 0;
121
+ font-size: var(--list-item-trailing-size);
122
+ color: var(--list-item-trailing-color);
123
+ }
124
+
125
+ /* ── Checkbox ───────────────────────────────────────────────── */
126
+
127
+ .list-item-checkbox {
128
+ flex-shrink: 0;
129
+ width: var(--list-item-checkbox-size);
130
+ height: var(--list-item-checkbox-size);
131
+ border-radius: var(--list-item-checkbox-radius);
132
+ border: 1.5px solid var(--list-item-checkbox-border);
133
+ background: transparent;
134
+ display: flex;
135
+ align-items: center;
136
+ justify-content: center;
137
+ font-size: 10px;
138
+ transition: background 0.1s ease, border-color 0.1s ease;
139
+
140
+ &.is-checked {
141
+ background: var(--list-item-checkbox-bg);
142
+ border-color: var(--list-item-checkbox-bg);
143
+ color: white;
144
+ }
145
+ }
146
+
147
+ /* ── Select indicator (selectByClick) ───────────────────────── */
148
+
149
+ .list-item-indicator {
150
+ opacity: 0;
151
+ flex-shrink: 0;
152
+ font-size: var(--list-item-indicator-size);
153
+ color: var(--list-item-color-selected);
154
+ transition: opacity 0.1s ease;
155
+
156
+ &.is-visible {
157
+ opacity: 1;
158
+ }
159
+ }
160
+
161
+ /* ── Swipe ──────────────────────────────────────────────────── */
162
+
163
+ .list-item-swipe-background {
164
+ position: absolute;
165
+ inset: 0;
166
+ display: flex;
167
+ z-index: 0;
168
+ }
169
+
170
+ .swipe-actions-container {
171
+ display: flex;
172
+ align-items: center;
173
+ min-width: var(--list-item-swipe-actions-min-width);
174
+
175
+ &.container-leading {
176
+ justify-content: flex-start;
177
+ }
178
+
179
+ &.container-trailing {
180
+ justify-content: flex-end;
181
+ margin-left: auto;
182
+ }
183
+
184
+ &.container-trailing,
185
+ &.container-leading {
186
+ > * {
187
+ height: 100%;
188
+ border-radius: 0;
189
+ }
190
+ }
191
+ }
@@ -0,0 +1,24 @@
1
+ :root {
2
+ --list-bg: var(--background);
3
+ --list-border: var(--gray-lite-3);
4
+ --list-radius: var(--radius-card);
5
+ --list-padding: 0;
6
+ --list-inset-padding: 0px;
7
+ }
8
+
9
+ .list {
10
+ background: var(--list-bg);
11
+ border: 1px solid var(--list-border);
12
+ border-radius: var(--list-radius);
13
+ padding: var(--list-padding);
14
+ overflow: hidden;
15
+ list-style: none;
16
+ &.with-divider {
17
+ li {
18
+ border-bottom: solid 1px var(--list-border, #e0e0e0);
19
+ &:last-child {
20
+ border-bottom: none;
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,10 @@
1
+ import { Div } from '../../../core/elements';
2
+
3
+ export default function SpacerRender($desc, instance) {
4
+ const props = instance.getEditableProps();
5
+
6
+ props.class.add('spacer');
7
+ props.style.add('flex', '1');
8
+
9
+ return Div(instance.resolveProps());
10
+ }
package/src/ui/index.js CHANGED
@@ -34,6 +34,14 @@ export { default as AccordionRender } from './components/accordion/AccordionRend
34
34
  export { default as SimpleTableRender } from './components/table/simple-table/SimpleTableRender';
35
35
  export { default as DataTableRender } from './components/table/data-table/DataTableRender';
36
36
  export { default as SwitchRender } from './components/switch/SwitchRender';
37
+ export { default as SpacerRender } from './components/spacer/SpacerRender';
38
+
39
+ export { default as ListRender } from './components/list/ListRender';
40
+ export { default as ListGroupRender } from './components/list/group/ListGroupRender';
41
+ export { default as ListItemRender } from './components/list/item/ListItemRender';
42
+ export { default as ListDividerRender } from './components/list/divider/ListDividerRender';
43
+
44
+ export { default as CardRender } from './components/card/CardRender';
37
45
 
38
46
  export * from './components/stacks';
39
47
  export * from './components/form';