@svgrid/grid 2.1.22 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/DockNodeView.svelte +306 -0
- package/dist/DockNodeView.svelte.d.ts +7 -0
- package/dist/DockPopoutHost.svelte +17 -0
- package/dist/DockPopoutHost.svelte.d.ts +14 -0
- package/dist/FlexRender.svelte +96 -96
- package/dist/GridFooter.svelte +178 -178
- package/dist/GridMenus.svelte +83 -3
- package/dist/SvAutoComplete.svelte +5 -3
- package/dist/SvCarousel.svelte +141 -163
- package/dist/SvColorInput.svelte +187 -186
- package/dist/SvColorInput.svelte.d.ts +1 -1
- package/dist/SvComboBox.svelte +7 -3
- package/dist/SvCommand.svelte +28 -85
- package/dist/SvContextMenu.svelte +116 -116
- package/dist/SvCountryInput.svelte +1 -1
- package/dist/SvDateRangeInput.svelte +1 -1
- package/dist/SvDateTimePicker.svelte +9 -3
- package/dist/SvDateTimePicker.svelte.d.ts +3 -0
- package/dist/SvDockLayout.svelte +244 -0
- package/dist/SvDockLayout.svelte.d.ts +77 -0
- package/dist/SvDockManager.svelte +922 -0
- package/dist/SvDockManager.svelte.d.ts +106 -0
- package/dist/SvDrawer.svelte +250 -228
- package/dist/SvDrawer.svelte.d.ts +4 -0
- package/dist/SvDropDownList.svelte +85 -13
- package/dist/SvDropDownList.svelte.d.ts +3 -0
- package/dist/SvField.svelte +21 -4
- package/dist/SvField.svelte.d.ts +1 -0
- package/dist/SvForm.svelte +201 -91
- package/dist/SvForm.svelte.d.ts +15 -22
- package/dist/SvGrid.controller.svelte.d.ts +32 -1
- package/dist/SvGrid.controller.svelte.js +156 -27
- package/dist/SvGrid.css +193 -5
- package/dist/SvGrid.svelte +3131 -2786
- package/dist/SvGrid.types.d.ts +452 -1
- package/dist/SvGridBoard.svelte +2339 -2339
- package/dist/SvGridChart.svelte +1724 -1724
- package/dist/SvGridChartPanel.svelte +485 -485
- package/dist/SvGridDropdown.svelte +689 -682
- package/dist/SvGridSelect.svelte +1 -0
- package/dist/SvGroupCell.svelte +109 -109
- package/dist/SvListBox.svelte +36 -14
- package/dist/SvMaskedInput.svelte +4 -3
- package/dist/SvMaskedInput.svelte.d.ts +1 -1
- package/dist/SvMenu.svelte +124 -124
- package/dist/SvMenuList.svelte +117 -165
- package/dist/SvMenuList.svelte.d.ts +2 -13
- package/dist/SvModal.svelte +12 -29
- package/dist/SvMultiSelect.svelte +1 -0
- package/dist/SvNumberInput.svelte +131 -130
- package/dist/SvNumberInput.svelte.d.ts +1 -1
- package/dist/SvOtpInput.svelte +158 -158
- package/dist/SvPagination.svelte +18 -18
- package/dist/SvPasswordInput.svelte +3 -2
- package/dist/SvPasswordInput.svelte.d.ts +1 -1
- package/dist/SvPhoneInput.svelte +3 -2
- package/dist/SvPhoneInput.svelte.d.ts +1 -1
- package/dist/SvPopover.svelte +139 -139
- package/dist/SvRowGroupPanel.svelte +170 -170
- package/dist/SvScrollArea.svelte +61 -61
- package/dist/SvStepper.svelte +6 -9
- package/dist/SvTagsInput.svelte +3 -2
- package/dist/SvTagsInput.svelte.d.ts +1 -1
- package/dist/SvTooltip.svelte +127 -138
- package/dist/SvTour.svelte +204 -176
- package/dist/SvTree.svelte +377 -377
- package/dist/SvTreeSelect.svelte +230 -229
- package/dist/build-api.js +76 -54
- package/dist/cdn/svgrid.js +10913 -6450
- package/dist/cdn/svgrid.svelte-external.js +9628 -5481
- package/dist/chart-export.js +8 -8
- package/dist/columns.js +6 -0
- package/dist/conditional-formatting.d.ts +67 -3
- package/dist/conditional-formatting.js +124 -17
- package/dist/createCarousel.svelte.d.ts +72 -0
- package/dist/createCarousel.svelte.js +80 -0
- package/dist/createCommand.svelte.d.ts +62 -0
- package/dist/createCommand.svelte.js +109 -0
- package/dist/createForm.svelte.d.ts +62 -0
- package/dist/createForm.svelte.js +374 -0
- package/dist/createMenu.svelte.d.ts +88 -0
- package/dist/createMenu.svelte.js +153 -0
- package/dist/createOverlay.svelte.d.ts +38 -0
- package/dist/createOverlay.svelte.js +68 -0
- package/dist/createPagination.d.ts +74 -0
- package/dist/createPagination.js +71 -0
- package/dist/createPopoverSelect.svelte.js +6 -12
- package/dist/createStepper.d.ts +44 -0
- package/dist/createStepper.js +26 -0
- package/dist/createTooltip.svelte.d.ts +32 -0
- package/dist/createTooltip.svelte.js +61 -0
- package/dist/datetime/timezone.d.ts +36 -0
- package/dist/datetime/timezone.js +110 -0
- package/dist/dock-context.d.ts +52 -0
- package/dist/dock-context.js +1 -0
- package/dist/dock-manager-model.d.ts +136 -0
- package/dist/dock-manager-model.js +514 -0
- package/dist/dock-model.d.ts +105 -0
- package/dist/dock-model.js +288 -0
- package/dist/dock-popout.d.ts +30 -0
- package/dist/dock-popout.js +81 -0
- package/dist/editor-contract.d.ts +2 -0
- package/dist/filter-operators.d.ts +6 -0
- package/dist/filter-operators.js +35 -2
- package/dist/filtering/excel-filters.d.ts +18 -1
- package/dist/filtering/excel-filters.js +56 -0
- package/dist/form-field.d.ts +73 -0
- package/dist/form-field.js +15 -0
- package/dist/index.d.ts +25 -5
- package/dist/index.js +40 -4
- package/dist/list-nav.d.ts +18 -0
- package/dist/list-nav.js +30 -0
- package/dist/list-option.d.ts +2 -0
- package/dist/menu-item.d.ts +20 -0
- package/dist/menu-item.js +1 -0
- package/dist/menus.d.ts +5 -0
- package/dist/menus.js +68 -16
- package/dist/panel-resize.d.ts +25 -0
- package/dist/panel-resize.js +40 -0
- package/dist/popover.d.ts +29 -3
- package/dist/popover.js +22 -6
- package/dist/recurrence.d.ts +33 -7
- package/dist/recurrence.js +151 -13
- package/dist/row-drag.d.ts +8 -0
- package/dist/row-drag.js +11 -0
- package/dist/scheduler-ical.d.ts +30 -0
- package/dist/scheduler-ical.js +180 -0
- package/dist/scheduler-model.d.ts +269 -0
- package/dist/scheduler-model.js +602 -0
- package/dist/scheduler-view.svelte.d.ts +22 -0
- package/dist/scheduler-view.svelte.js +13 -0
- package/dist/spreadsheet.js +20 -12
- package/dist/ui-app.types.d.ts +3 -0
- package/package.json +14 -10
- package/src/DockNodeView.svelte +306 -0
- package/src/DockPopoutHost.svelte +17 -0
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +178 -178
- package/src/GridMenus.svelte +83 -3
- package/src/SvAutoComplete.svelte +5 -3
- package/src/SvCarousel.svelte +141 -163
- package/src/SvCarousel.test.ts +68 -0
- package/src/SvColorInput.svelte +187 -186
- package/src/SvComboBox.svelte +7 -3
- package/src/SvCommand.svelte +28 -85
- package/src/SvCommand.test.ts +78 -0
- package/src/SvContextMenu.svelte +116 -116
- package/src/SvCountryInput.svelte +1 -1
- package/src/SvDateRangeInput.svelte +1 -1
- package/src/SvDateTimePicker.svelte +9 -3
- package/src/SvDockLayout.svelte +244 -0
- package/src/SvDockManager.svelte +922 -0
- package/src/SvDrawer.svelte +250 -228
- package/src/SvDropDownList.svelte +85 -13
- package/src/SvField.svelte +21 -4
- package/src/SvForm.svelte +201 -91
- package/src/SvForm.test.ts +299 -0
- package/src/SvGrid.controller.svelte.ts +3158 -3034
- package/src/SvGrid.css +193 -5
- package/src/SvGrid.svelte +3131 -2786
- package/src/SvGrid.types.ts +1489 -1027
- package/src/SvGridBoard.svelte +2339 -2339
- package/src/SvGridChart.svelte +1724 -1724
- package/src/SvGridChartPanel.svelte +485 -485
- package/src/SvGridDropdown.svelte +689 -682
- package/src/SvGridSelect.svelte +1 -0
- package/src/SvGroupCell.svelte +109 -109
- package/src/SvListBox.svelte +36 -14
- package/src/SvMaskedInput.svelte +4 -3
- package/src/SvMenu.svelte +124 -124
- package/src/SvMenu.test.ts +97 -73
- package/src/SvMenuList.svelte +117 -165
- package/src/SvModal.svelte +12 -29
- package/src/SvModal.test.ts +82 -0
- package/src/SvMultiSelect.svelte +1 -0
- package/src/SvNumberInput.svelte +131 -130
- package/src/SvOtpInput.svelte +158 -158
- package/src/SvPagination.svelte +18 -18
- package/src/SvPasswordInput.svelte +3 -2
- package/src/SvPhoneInput.svelte +3 -2
- package/src/SvPopover.svelte +139 -139
- package/src/SvRowGroupPanel.svelte +170 -170
- package/src/SvScrollArea.svelte +61 -61
- package/src/SvStepper.svelte +6 -9
- package/src/SvTagsInput.svelte +3 -2
- package/src/SvTooltip.svelte +127 -138
- package/src/SvTooltip.test.ts +73 -0
- package/src/SvTour.svelte +204 -176
- package/src/SvTree.svelte +377 -377
- package/src/SvTreeSelect.svelte +230 -229
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +61 -61
- package/src/build-api.ts +870 -847
- package/src/cell-formatting.ts +169 -169
- package/src/cell-render.ts +469 -469
- package/src/chart-export.ts +201 -201
- package/src/chart.ts +2296 -2296
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/columns.ts +5 -0
- package/src/conditional-formatting.test.ts +104 -0
- package/src/conditional-formatting.ts +176 -19
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1111 -1111
- package/src/createAutocomplete.svelte.ts +132 -132
- package/src/createCarousel.svelte.ts +104 -0
- package/src/createCombobox.svelte.ts +179 -179
- package/src/createCommand.svelte.ts +125 -0
- package/src/createCountryInput.svelte.ts +157 -157
- package/src/createDropdownList.svelte.ts +162 -162
- package/src/createForm.svelte.ts +333 -0
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/createMenu.svelte.ts +202 -0
- package/src/createOverlay.svelte.ts +101 -0
- package/src/createPagination.test.ts +65 -0
- package/src/createPagination.ts +84 -0
- package/src/createPopoverSelect.svelte.ts +206 -210
- package/src/createStepper.test.ts +62 -0
- package/src/createStepper.ts +61 -0
- package/src/createTooltip.svelte.ts +86 -0
- package/src/createTree.svelte.ts +319 -319
- package/src/datetime/timezone.test.ts +69 -0
- package/src/datetime/timezone.ts +134 -0
- package/src/dock-context.ts +47 -0
- package/src/dock-manager-model.test.ts +275 -0
- package/src/dock-manager-model.ts +593 -0
- package/src/dock-model.test.ts +163 -0
- package/src/dock-model.ts +368 -0
- package/src/dock-popout.ts +94 -0
- package/src/editing.test.ts +859 -859
- package/src/editing.ts +675 -675
- package/src/editor-contract.ts +2 -0
- package/src/export-data-api.test.ts +126 -126
- package/src/export-format.test.ts +107 -107
- package/src/export-format.ts +598 -598
- package/src/filter-operators.test.ts +59 -0
- package/src/filter-operators.ts +35 -2
- package/src/filtering/excel-filters.test.ts +86 -1
- package/src/filtering/excel-filters.ts +65 -0
- package/src/flex-render.ts +3 -3
- package/src/form-field.ts +87 -0
- package/src/index.ts +623 -469
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/list-nav.test.ts +49 -0
- package/src/list-nav.ts +29 -0
- package/src/list-option.ts +2 -0
- package/src/menu-item.ts +21 -0
- package/src/menus.test.ts +48 -0
- package/src/menus.ts +639 -582
- package/src/merge-objects.ts +48 -48
- package/src/overlays.test.ts +90 -90
- package/src/panel-resize.ts +52 -0
- package/src/popover.bounds.test.ts +93 -0
- package/src/popover.ts +51 -7
- package/src/recurrence.test.ts +88 -1
- package/src/recurrence.ts +166 -15
- package/src/render-component.ts +28 -28
- package/src/row-drag.ts +10 -0
- package/src/scheduler-ical.test.ts +68 -0
- package/src/scheduler-ical.ts +180 -0
- package/src/scheduler-model.test.ts +546 -0
- package/src/scheduler-model.ts +853 -0
- package/src/scheduler-view.svelte.ts +33 -0
- package/src/selection.test.ts +754 -754
- package/src/selection.ts +600 -600
- package/src/server-data-source.test.ts +289 -289
- package/src/server-data-source.ts +413 -413
- package/src/sparkline.test.ts +68 -68
- package/src/sparkline.ts +169 -169
- package/src/spreadsheet.test.ts +489 -489
- package/src/spreadsheet.ts +312 -304
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/svgrid-wrapper.types.ts +501 -501
- package/src/svgrid.behavior.test.ts +706 -706
- package/src/svgrid.charting.test.ts +527 -527
- package/src/svgrid.effect-driven-filter.svelte.test.ts +116 -0
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/test-setup.ts +62 -62
- package/src/themes/index.ts +159 -159
- package/src/ui-app.types.ts +3 -0
- package/src/virtual.test.ts +6 -4
- package/src/virtualization/column-virtualizer.test.ts +27 -27
- package/src/virtualization/column-virtualizer.ts +30 -30
- package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
- package/src/virtualization/types.ts +30 -30
- package/src/virtualization/virtualizer.test.ts +47 -47
- package/src/virtualization/virtualizer.ts +296 -296
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* One styled renderer over the headless `createDropdownList` core (state +
|
|
8
8
|
* keyboard + ARIA); only portal/measure/scroll render concerns live here.
|
|
9
9
|
*/
|
|
10
|
-
import { flushSync } from 'svelte'
|
|
11
10
|
import { anchoredRect, portalToBody, popIn, type AnchoredRect } from './popover'
|
|
11
|
+
import { startPanelResize } from './panel-resize'
|
|
12
12
|
import { createDismissableLayer } from './a11y/dismissable'
|
|
13
13
|
import { groupOptions, hasGroups, type ListOption } from './list-option'
|
|
14
14
|
import { virtualRange, scrollToIndex } from './virtual'
|
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
virtual?: boolean
|
|
27
27
|
/** Fixed option height in px (must match the CSS). Default 34. */
|
|
28
28
|
rowHeight?: number
|
|
29
|
+
/** Show a bottom drag grip so the user can resize the open panel's height
|
|
30
|
+
* (only while it opens downward). Off by default. */
|
|
31
|
+
resizable?: boolean
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
let {
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
autoOpen = false,
|
|
48
51
|
virtual = false,
|
|
49
52
|
rowHeight = 34,
|
|
53
|
+
resizable = false,
|
|
50
54
|
}: Props = $props()
|
|
51
55
|
|
|
52
56
|
const autoId = nextEditorId('sv-ddl')
|
|
@@ -61,7 +65,15 @@
|
|
|
61
65
|
|
|
62
66
|
let triggerEl = $state<HTMLButtonElement | null>(null)
|
|
63
67
|
let panelEl = $state<HTMLDivElement | null>(null)
|
|
64
|
-
let rect = $state<AnchoredRect>({ top: 0, left: 0, width: 0, openUpward: false })
|
|
68
|
+
let rect = $state<AnchoredRect>({ top: 0, left: 0, width: 0, openUpward: false, maxHeight: 0, availHeight: 0 })
|
|
69
|
+
// User-chosen panel height (px) once they drag the resize grip; null = auto.
|
|
70
|
+
let userHeight = $state<number | null>(null)
|
|
71
|
+
// Effective height cap: the user's drag if any (clamped to the viewport
|
|
72
|
+
// ceiling), otherwise the comfortable bounds-aware height.
|
|
73
|
+
const panelMaxH = $derived(
|
|
74
|
+
resizable && userHeight != null ? Math.min(userHeight, rect.availHeight) : rect.maxHeight,
|
|
75
|
+
)
|
|
76
|
+
const showGrip = $derived(resizable && !rect.openUpward)
|
|
65
77
|
|
|
66
78
|
const ddl = createDropdownList({
|
|
67
79
|
options: () => options,
|
|
@@ -81,7 +93,24 @@
|
|
|
81
93
|
|
|
82
94
|
function updatePos() {
|
|
83
95
|
if (!triggerEl) return
|
|
84
|
-
|
|
96
|
+
// When the user has resized, anchor to THAT height so the flip decision and
|
|
97
|
+
// upward top stay correct; otherwise estimate from the option count.
|
|
98
|
+
const estimatedHeight =
|
|
99
|
+
resizable && userHeight != null ? userHeight : Math.min(options.length, 8) * 34 + 8
|
|
100
|
+
rect = anchoredRect(triggerEl.getBoundingClientRect(), { estimatedHeight })
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function startResize(e: PointerEvent) {
|
|
104
|
+
if (!panelEl) return
|
|
105
|
+
startPanelResize(e, {
|
|
106
|
+
startHeight: panelEl.clientHeight,
|
|
107
|
+
min: 96,
|
|
108
|
+
max: () => rect.availHeight,
|
|
109
|
+
onHeight: (h) => {
|
|
110
|
+
userHeight = h
|
|
111
|
+
updatePos()
|
|
112
|
+
},
|
|
113
|
+
})
|
|
85
114
|
}
|
|
86
115
|
|
|
87
116
|
$effect(() => {
|
|
@@ -126,19 +155,20 @@
|
|
|
126
155
|
{...ddl.triggerProps()}
|
|
127
156
|
use:focusOpen
|
|
128
157
|
>
|
|
129
|
-
<span class="sv-ddl__value" class:is-placeholder={!selected}>{selected?.label ?? placeholder}</span>
|
|
158
|
+
<span class="sv-ddl__value" class:is-placeholder={!selected}>{#if selected?.color}<span class="sv-ddl__swatch" style:background={selected.color}></span>{/if}{selected?.label ?? placeholder}</span>
|
|
130
159
|
<svg class="sv-ddl__chev" viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 9 6 6 6-6" /></svg>
|
|
131
160
|
</button>
|
|
132
161
|
</SvField>
|
|
133
162
|
|
|
134
163
|
{#if ddl.open}
|
|
135
|
-
<div bind:this={panelEl} class="sv-ddl__panel" class:is-virtual={useVirtual} use:portalToBody use:popIn={{ up: rect.openUpward }} style:position="fixed" style:top={`${rect.top}px`} style:left={`${rect.left}px`} style:min-width={`${rect.width}px`} onscroll={(e) =>
|
|
164
|
+
<div bind:this={panelEl} class="sv-ddl__panel" class:is-virtual={useVirtual} class:is-resizable={showGrip} use:portalToBody use:popIn={{ up: rect.openUpward }} style:--sv-row-h={`${rowHeight}px`} style:position="fixed" style:top={`${rect.top}px`} style:left={`${rect.left}px`} style:min-width={`${rect.width}px`} style:max-height={`${panelMaxH}px`} style:height={resizable && userHeight != null ? `${panelMaxH}px` : undefined} onscroll={(e) => (scrollTop = e.currentTarget.scrollTop)} bind:clientHeight={viewportH} {...ddl.listboxProps()}>
|
|
136
165
|
{#if useVirtual}
|
|
137
|
-
<div class="sv-
|
|
166
|
+
<div class="sv-ddl__spacer" aria-hidden="true" style:height={`${vr.padTop}px`}></div>
|
|
138
167
|
{#each windowed as opt (opt.value)}
|
|
139
168
|
<!-- svelte-ignore a11y_click_events_have_key_events a11y_interactive_supports_focus -->
|
|
140
|
-
<div class="sv-ddl__opt
|
|
169
|
+
<div class="sv-ddl__opt" style:height={`${rowHeight}px`} class:is-active={ddl.isActive(opt.index)} class:is-selected={ddl.isSelected(opt)} class:is-disabled={opt.disabled} {...ddl.optionProps(opt.index)}>{#if opt.color}<span class="sv-ddl__swatch" style:background={opt.color}></span>{/if}{opt.label}</div>
|
|
141
170
|
{/each}
|
|
171
|
+
<div class="sv-ddl__spacer" aria-hidden="true" style:height={`${vr.padBottom}px`}></div>
|
|
142
172
|
{:else}
|
|
143
173
|
{#each groupOptions(options) as g (g.group ?? '')}
|
|
144
174
|
{#if g.group != null}
|
|
@@ -146,17 +176,23 @@
|
|
|
146
176
|
<div class="sv-ddl__group-label" aria-hidden="true">{g.group}</div>
|
|
147
177
|
{#each g.options as opt (opt.value)}
|
|
148
178
|
<!-- svelte-ignore a11y_click_events_have_key_events a11y_interactive_supports_focus -->
|
|
149
|
-
<div class="sv-ddl__opt" class:is-active={ddl.isActive(opt.index)} class:is-selected={ddl.isSelected(opt)} class:is-disabled={opt.disabled} {...ddl.optionProps(opt.index)}>{opt.label}</div>
|
|
179
|
+
<div class="sv-ddl__opt" class:is-active={ddl.isActive(opt.index)} class:is-selected={ddl.isSelected(opt)} class:is-disabled={opt.disabled} {...ddl.optionProps(opt.index)}>{#if opt.color}<span class="sv-ddl__swatch" style:background={opt.color}></span>{/if}{opt.label}</div>
|
|
150
180
|
{/each}
|
|
151
181
|
</div>
|
|
152
182
|
{:else}
|
|
153
183
|
{#each g.options as opt (opt.value)}
|
|
154
184
|
<!-- svelte-ignore a11y_click_events_have_key_events a11y_interactive_supports_focus -->
|
|
155
|
-
<div class="sv-ddl__opt" class:is-active={ddl.isActive(opt.index)} class:is-selected={ddl.isSelected(opt)} class:is-disabled={opt.disabled} {...ddl.optionProps(opt.index)}>{opt.label}</div>
|
|
185
|
+
<div class="sv-ddl__opt" class:is-active={ddl.isActive(opt.index)} class:is-selected={ddl.isSelected(opt)} class:is-disabled={opt.disabled} {...ddl.optionProps(opt.index)}>{#if opt.color}<span class="sv-ddl__swatch" style:background={opt.color}></span>{/if}{opt.label}</div>
|
|
156
186
|
{/each}
|
|
157
187
|
{/if}
|
|
158
188
|
{/each}
|
|
159
189
|
{/if}
|
|
190
|
+
{#if showGrip}
|
|
191
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
192
|
+
<div class="sv-ddl__grip" onpointerdown={startResize} title="Drag to resize" aria-hidden="true">
|
|
193
|
+
<span class="sv-ddl__grip-dots"></span>
|
|
194
|
+
</div>
|
|
195
|
+
{/if}
|
|
160
196
|
</div>
|
|
161
197
|
{/if}
|
|
162
198
|
{#if name}<input type="hidden" {name} value={value ?? ''} />{/if}
|
|
@@ -181,14 +217,50 @@
|
|
|
181
217
|
.sv-ddl__chev { color: var(--sg-muted, #64748b); flex: none; }
|
|
182
218
|
|
|
183
219
|
:global(.sv-ddl__panel) {
|
|
184
|
-
z-index: 2147483647; max-height: 288px; overflow-y: auto; padding: 4px;
|
|
220
|
+
box-sizing: border-box; z-index: 2147483647; max-height: 288px; overflow-y: auto; padding: 4px;
|
|
185
221
|
background: var(--sg-bg, #fff); color: var(--sg-fg, #0f172a);
|
|
186
222
|
border: 1px solid var(--sg-border, #e2e8f0); border-radius: 10px; box-shadow: 0 16px 48px -12px rgba(15,23,42,0.35);
|
|
187
223
|
}
|
|
188
224
|
:global(.sv-ddl__opt) { box-sizing: border-box; display: flex; align-items: center; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
:global(.sv-
|
|
225
|
+
/* Color swatch shown before an option's label (option.color) - in both the
|
|
226
|
+
trigger value and the portalled panel options. */
|
|
227
|
+
:global(.sv-ddl__swatch) {
|
|
228
|
+
display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 3px;
|
|
229
|
+
margin-inline-end: 8px; vertical-align: middle;
|
|
230
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, #000 18%, transparent);
|
|
231
|
+
}
|
|
232
|
+
/* Bottom resize grip: a row of dots ("····") the user drags to resize the
|
|
233
|
+
panel. Sticky so it stays pinned at the panel's bottom while options scroll. */
|
|
234
|
+
:global(.sv-ddl__panel.is-resizable) { padding-bottom: 0; }
|
|
235
|
+
:global(.sv-ddl__grip) {
|
|
236
|
+
position: sticky; bottom: 0; z-index: 1; margin: 2px -4px -4px; height: 15px;
|
|
237
|
+
display: flex; align-items: center; justify-content: center; cursor: ns-resize;
|
|
238
|
+
background: var(--sg-bg, #fff); border-top: 1px solid var(--sg-border, #e2e8f0);
|
|
239
|
+
border-radius: 0 0 10px 10px; touch-action: none;
|
|
240
|
+
}
|
|
241
|
+
:global(.sv-ddl__grip-dots) {
|
|
242
|
+
width: 26px; height: 4px; color: var(--sg-muted, #94a3b8); opacity: 0.6;
|
|
243
|
+
background-image: radial-gradient(currentColor 1px, transparent 1.6px);
|
|
244
|
+
background-size: 6px 4px; background-position: center; background-repeat: repeat-x;
|
|
245
|
+
}
|
|
246
|
+
:global(.sv-ddl__grip:hover .sv-ddl__grip-dots) { opacity: 1; }
|
|
247
|
+
/* Faint per-row skeleton so a fast scrollbar-thumb drag reveals placeholder
|
|
248
|
+
rows in this off-screen padding instead of blank, until JS re-windows. */
|
|
249
|
+
:global(.sv-ddl__spacer) {
|
|
250
|
+
padding: 0; margin: 0; flex: none; pointer-events: none;
|
|
251
|
+
background-image: linear-gradient(
|
|
252
|
+
to bottom,
|
|
253
|
+
transparent 0,
|
|
254
|
+
transparent calc((var(--sv-row-h, 34px) - 10px) / 2),
|
|
255
|
+
var(--sg-skeleton, color-mix(in srgb, currentColor 9%, transparent)) calc((var(--sv-row-h, 34px) - 10px) / 2),
|
|
256
|
+
var(--sg-skeleton, color-mix(in srgb, currentColor 9%, transparent)) calc((var(--sv-row-h, 34px) + 10px) / 2),
|
|
257
|
+
transparent calc((var(--sv-row-h, 34px) + 10px) / 2),
|
|
258
|
+
transparent var(--sv-row-h, 34px)
|
|
259
|
+
);
|
|
260
|
+
background-size: 62% var(--sv-row-h, 34px);
|
|
261
|
+
background-repeat: repeat-y;
|
|
262
|
+
background-position: 12px 0;
|
|
263
|
+
}
|
|
192
264
|
:global(.sv-ddl__opt.is-active) { background: var(--sg-row-hover-bg, #f1f5f9); }
|
|
193
265
|
:global(.sv-ddl__opt.is-selected) { color: var(--sg-accent, #2563eb); font-weight: 600; }
|
|
194
266
|
:global(.sv-ddl__opt.is-disabled) { opacity: 0.4; cursor: not-allowed; }
|
package/src/SvField.svelte
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
dir,
|
|
27
27
|
/** Stretch the field (and its control) to the container width. */
|
|
28
28
|
block = false,
|
|
29
|
+
/** Busy state - shows a small spinner beside the label. */
|
|
30
|
+
loading = false,
|
|
29
31
|
children,
|
|
30
32
|
}: {
|
|
31
33
|
id?: string
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
required?: boolean
|
|
36
38
|
dir?: EditorDir
|
|
37
39
|
block?: boolean
|
|
40
|
+
loading?: boolean
|
|
38
41
|
children: Snippet
|
|
39
42
|
} = $props()
|
|
40
43
|
|
|
@@ -43,10 +46,15 @@
|
|
|
43
46
|
</script>
|
|
44
47
|
|
|
45
48
|
<div class="sv-field" class:sv-field--block={block} dir={resolvedDir}>
|
|
46
|
-
{#if label}
|
|
47
|
-
<
|
|
48
|
-
{
|
|
49
|
-
|
|
49
|
+
{#if label || loading}
|
|
50
|
+
<span class="sv-field__labelrow">
|
|
51
|
+
{#if label}
|
|
52
|
+
<label class="sv-field__label" for={id}>
|
|
53
|
+
{label}{#if required}<span class="sv-field__req" aria-hidden="true">*</span>{/if}
|
|
54
|
+
</label>
|
|
55
|
+
{/if}
|
|
56
|
+
{#if loading}<span class="sv-field__spinner" role="status" aria-label="Loading"></span>{/if}
|
|
57
|
+
</span>
|
|
50
58
|
{/if}
|
|
51
59
|
{@render children()}
|
|
52
60
|
{#if error}
|
|
@@ -64,12 +72,21 @@
|
|
|
64
72
|
text-align: start;
|
|
65
73
|
}
|
|
66
74
|
.sv-field--block { display: flex; width: 100%; }
|
|
75
|
+
.sv-field__labelrow { display: inline-flex; align-items: center; gap: 6px; }
|
|
67
76
|
.sv-field__label {
|
|
68
77
|
font-size: 12.5px;
|
|
69
78
|
font-weight: 550;
|
|
70
79
|
color: var(--sg-fg, #0f172a);
|
|
71
80
|
line-height: 1.3;
|
|
72
81
|
}
|
|
82
|
+
.sv-field__spinner {
|
|
83
|
+
width: 12px; height: 12px; flex: none; border-radius: 50%;
|
|
84
|
+
border: 2px solid color-mix(in srgb, var(--sg-accent, #2563eb) 30%, transparent);
|
|
85
|
+
border-top-color: var(--sg-accent, #2563eb);
|
|
86
|
+
animation: sv-field-spin 0.6s linear infinite;
|
|
87
|
+
}
|
|
88
|
+
@keyframes sv-field-spin { to { transform: rotate(360deg); } }
|
|
89
|
+
@media (prefers-reduced-motion: reduce) { .sv-field__spinner { animation: none; } }
|
|
73
90
|
.sv-field__req { color: var(--sg-danger, #dc2626); margin-inline-start: 2px; }
|
|
74
91
|
.sv-field__hint {
|
|
75
92
|
font-size: 11.5px;
|
package/src/SvForm.svelte
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
| 'select' | 'checkbox' | 'switch' | 'date' | 'color' | 'rating'
|
|
7
|
-
|
|
8
|
-
export type FormField = {
|
|
9
|
-
name: string
|
|
10
|
-
label: string
|
|
11
|
-
type?: FormFieldType
|
|
12
|
-
required?: boolean
|
|
13
|
-
placeholder?: string
|
|
14
|
-
options?: Array<{ value: string | number; label: string }>
|
|
15
|
-
/** Declarative validation rules (see `rules` - email/pattern/min/compare...). */
|
|
16
|
-
rules?: ReadonlyArray<Validator>
|
|
17
|
-
/** Return an error message, or null/undefined when valid. */
|
|
18
|
-
validate?: (value: any, values: Record<string, any>) => string | null | undefined
|
|
19
|
-
/** Span full width in the grid. */
|
|
20
|
-
full?: boolean
|
|
21
|
-
}
|
|
2
|
+
// FormField/FormFieldType live in a plain `.ts` (breaks a Vite dev import
|
|
3
|
+
// cycle); re-exported so `import { type FormField } from './SvForm.svelte'`
|
|
4
|
+
// sites keep working.
|
|
5
|
+
export type { FormField, FormFieldType, FormSection, FormEntry } from './form-field'
|
|
22
6
|
</script>
|
|
23
7
|
|
|
24
8
|
<script lang="ts">
|
|
25
9
|
/**
|
|
26
10
|
* SvForm - a schema-driven form that renders the SvGrid UI-kit controls with
|
|
27
|
-
* labels, required + custom validation, and a submit handler.
|
|
28
|
-
*
|
|
11
|
+
* labels, required + custom validation, and a submit handler. The schema may be
|
|
12
|
+
* a flat `FormField[]` or mix in titled `FormSection`s; with `stepper` the
|
|
13
|
+
* sections become a validated wizard. Emits `onSubmit(values)` only when valid.
|
|
29
14
|
*/
|
|
30
15
|
import SvNumberInput from './SvNumberInput.svelte'
|
|
31
16
|
import SvPasswordInput from './SvPasswordInput.svelte'
|
|
@@ -36,105 +21,211 @@
|
|
|
36
21
|
import SvColorInput from './SvColorInput.svelte'
|
|
37
22
|
import SvRating from './SvRating.svelte'
|
|
38
23
|
import SvButton from './SvButton.svelte'
|
|
39
|
-
import
|
|
24
|
+
import SvStepper from './SvStepper.svelte'
|
|
25
|
+
import { isFormSection, type FormField, type FormEntry, type FormSection } from './form-field'
|
|
26
|
+
import { createForm } from './createForm.svelte'
|
|
40
27
|
|
|
41
28
|
type Props = {
|
|
42
|
-
fields: ReadonlyArray<
|
|
29
|
+
fields: ReadonlyArray<FormEntry>
|
|
43
30
|
initial?: Record<string, any>
|
|
44
|
-
|
|
31
|
+
/** Called with the visible-field values on a valid submit. May be async -
|
|
32
|
+
* the Submit button shows a loading state until it settles. */
|
|
33
|
+
onSubmit?: (values: Record<string, any>) => void | Promise<void>
|
|
45
34
|
onChange?: (values: Record<string, any>) => void
|
|
35
|
+
/** When set, a secondary Cancel button renders next to Submit. */
|
|
36
|
+
onCancel?: () => void
|
|
46
37
|
submitLabel?: string
|
|
47
|
-
|
|
38
|
+
cancelLabel?: string
|
|
39
|
+
/** Show a Reset button that restores the initial values. */
|
|
40
|
+
showReset?: boolean
|
|
41
|
+
resetLabel?: string
|
|
42
|
+
/** Render titled sections as a validated multi-step wizard (requires sections). */
|
|
43
|
+
stepper?: boolean
|
|
44
|
+
/** Columns in the responsive field grid (a section can override its own). */
|
|
48
45
|
columns?: number
|
|
49
46
|
disabled?: boolean
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
let {
|
|
49
|
+
let {
|
|
50
|
+
fields, initial = {}, onSubmit, onChange, onCancel,
|
|
51
|
+
submitLabel = 'Submit', cancelLabel = 'Cancel', showReset = false, resetLabel = 'Reset',
|
|
52
|
+
stepper = false, columns = 1, disabled = false,
|
|
53
|
+
}: Props = $props()
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let seededForm = false
|
|
58
|
-
$effect(() => { if (!seededForm) { seededForm = true; values = { ...initial } } })
|
|
55
|
+
const form = createForm({ fields: () => fields, initial, onSubmit, onChange })
|
|
56
|
+
const submit = (e: Event) => { e.preventDefault(); form.submit() }
|
|
57
|
+
const dateVal = (v: any): Date | null => (v instanceof Date ? v : v ? new Date(v) : null)
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (touched[name]) validateField(name)
|
|
64
|
-
}
|
|
59
|
+
const sections = $derived(fields.filter(isFormSection) as FormSection[])
|
|
60
|
+
const wizard = $derived(stepper && sections.length > 0)
|
|
61
|
+
const stepItems = $derived(sections.map((s) => ({ label: s.section, description: s.description })))
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
if (!err && field.rules) err = runRules(v, field.rules, values)
|
|
73
|
-
if (!err && field.validate) err = field.validate(v, values)
|
|
74
|
-
const next = { ...errors }
|
|
75
|
-
if (err) next[name] = err
|
|
76
|
-
else delete next[name]
|
|
77
|
-
errors = next
|
|
78
|
-
return !err
|
|
63
|
+
let step = $state(0)
|
|
64
|
+
async function next() {
|
|
65
|
+
const s = sections[step]
|
|
66
|
+
if (!s) return
|
|
67
|
+
const ok = await form.validateFields(s.fields.map((f) => f.name))
|
|
68
|
+
if (ok && step < sections.length - 1) step += 1
|
|
79
69
|
}
|
|
70
|
+
const back = () => { if (step > 0) step -= 1 }
|
|
80
71
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
// Shared shape passed to the `control` snippet so top-level fields and array
|
|
73
|
+
// item fields render the same set of controls without duplication.
|
|
74
|
+
type ControlOpts = {
|
|
75
|
+
id: string
|
|
76
|
+
type: string
|
|
77
|
+
label: string
|
|
78
|
+
value: any
|
|
79
|
+
onChange: (v: any) => void
|
|
80
|
+
onBlur?: () => void
|
|
81
|
+
disabled: boolean
|
|
82
|
+
placeholder?: string
|
|
83
|
+
options?: ReadonlyArray<{ value: string | number; label: string; color?: string }>
|
|
88
84
|
}
|
|
89
|
-
|
|
90
|
-
const dateVal = (v: any): Date | null => (v instanceof Date ? v : v ? new Date(v) : null)
|
|
91
85
|
</script>
|
|
92
86
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
{#snippet control(o: ControlOpts)}
|
|
88
|
+
{#if o.type === 'textarea'}
|
|
89
|
+
<textarea id={o.id} class="sv-form__control sv-form__textarea" rows="3" disabled={o.disabled} placeholder={o.placeholder} value={o.value ?? ''} oninput={(e) => o.onChange(e.currentTarget.value)} onblur={o.onBlur}></textarea>
|
|
90
|
+
{:else if o.type === 'number'}
|
|
91
|
+
<SvNumberInput value={o.value ?? null} disabled={o.disabled} onChange={o.onChange} />
|
|
92
|
+
{:else if o.type === 'password'}
|
|
93
|
+
<SvPasswordInput value={o.value ?? ''} disabled={o.disabled} onChange={o.onChange} />
|
|
94
|
+
{:else if o.type === 'select'}
|
|
95
|
+
<SvDropDownList options={o.options ?? []} value={o.value ?? null} disabled={o.disabled} placeholder={o.placeholder} onChange={o.onChange} />
|
|
96
|
+
{:else if o.type === 'checkbox'}
|
|
97
|
+
<SvCheckBox checked={!!o.value} disabled={o.disabled} onChange={o.onChange}>{o.label}</SvCheckBox>
|
|
98
|
+
{:else if o.type === 'switch'}
|
|
99
|
+
<div class="sv-form__inline"><SvSwitchButton checked={!!o.value} disabled={o.disabled} onChange={o.onChange} ariaLabel={o.label} /><span>{o.label}</span></div>
|
|
100
|
+
{:else if o.type === 'date'}
|
|
101
|
+
<SvDateTimePicker value={dateVal(o.value)} dropDownDisplayMode="calendar" formatString="yyyy-MM-dd" disabled={o.disabled} onChange={o.onChange} />
|
|
102
|
+
{:else if o.type === 'color'}
|
|
103
|
+
<SvColorInput value={o.value ?? '#3b82f6'} disabled={o.disabled} onChange={o.onChange} />
|
|
104
|
+
{:else if o.type === 'rating'}
|
|
105
|
+
<SvRating value={o.value ?? 0} disabled={o.disabled} onChange={o.onChange} />
|
|
106
|
+
{:else}
|
|
107
|
+
<input id={o.id} class="sv-form__control" type={o.type} disabled={o.disabled} placeholder={o.placeholder} value={o.value ?? ''} oninput={(e) => o.onChange(e.currentTarget.value)} onblur={o.onBlur} />
|
|
108
|
+
{/if}
|
|
109
|
+
{/snippet}
|
|
110
|
+
|
|
111
|
+
{#snippet renderItemField(arrayName: string, i: number, itf: FormField)}
|
|
112
|
+
{@const type = itf.type ?? 'text'}
|
|
113
|
+
{@const id = `f-${arrayName}-${i}-${itf.name}`}
|
|
114
|
+
{@const err = form.itemError(arrayName, i, itf.name)}
|
|
115
|
+
<div class="sv-form__field" class:has-error={err}>
|
|
116
|
+
{#if type !== 'checkbox' && type !== 'switch'}
|
|
117
|
+
<label class="sv-form__label" for={id}>{itf.label}{#if itf.required}<span class="sv-form__req" aria-hidden="true"> *</span>{/if}</label>
|
|
118
|
+
{/if}
|
|
119
|
+
{@render control({ id, type, label: itf.label, value: form.itemValue(arrayName, i, itf.name), onChange: (v) => form.setItemValue(arrayName, i, itf.name, v), onBlur: () => form.handleItemBlur(arrayName, i, itf.name), disabled, placeholder: itf.placeholder, options: itf.options })}
|
|
120
|
+
{#if err}<span class="sv-form__error" role="alert">{err}</span>{/if}
|
|
121
|
+
</div>
|
|
122
|
+
{/snippet}
|
|
123
|
+
|
|
124
|
+
{#snippet renderArray(field: FormField)}
|
|
125
|
+
<div class="sv-form__field is-full sv-form__array" class:has-error={form.error(field.name)}>
|
|
126
|
+
<label class="sv-form__label">{field.label}{#if field.required}<span class="sv-form__req" aria-hidden="true"> *</span>{/if}</label>
|
|
127
|
+
{#each form.arrayItems(field.name) as _item, i (i)}
|
|
128
|
+
<div class="sv-form__arow">
|
|
129
|
+
<div class="sv-form__grid" style:--cols={field.itemFields?.length ?? 1}>
|
|
130
|
+
{#each field.itemFields ?? [] as itf (itf.name)}{@render renderItemField(field.name, i, itf)}{/each}
|
|
131
|
+
</div>
|
|
132
|
+
<button type="button" class="sv-form__aremove" disabled={disabled} onclick={() => form.removeItem(field.name, i)} aria-label="Remove item">×</button>
|
|
133
|
+
</div>
|
|
134
|
+
{/each}
|
|
135
|
+
<div><SvButton type="button" variant="outline" size="sm" disabled={disabled} onclick={() => form.addItem(field.name)}>{field.addLabel ?? '+ Add'}</SvButton></div>
|
|
136
|
+
{#if form.error(field.name)}<span class="sv-form__error" role="alert">{form.error(field.name)}</span>{/if}
|
|
137
|
+
</div>
|
|
138
|
+
{/snippet}
|
|
139
|
+
|
|
140
|
+
{#snippet renderField(field: FormField, cols: number)}
|
|
141
|
+
{#if form.isVisible(field.name)}
|
|
142
|
+
{@const type = field.type ?? 'text'}
|
|
143
|
+
{#if type === 'array'}
|
|
144
|
+
{@render renderArray(field)}
|
|
145
|
+
{:else}
|
|
146
|
+
{@const fieldDisabled = disabled || form.isDisabled(field.name)}
|
|
147
|
+
<div class="sv-form__field" class:is-full={field.full || cols === 1} class:has-error={form.error(field.name)}>
|
|
98
148
|
{#if type !== 'checkbox' && type !== 'switch'}
|
|
99
149
|
<label class="sv-form__label" for={`f-${field.name}`}>
|
|
100
150
|
{field.label}{#if field.required}<span class="sv-form__req" aria-hidden="true"> *</span>{/if}
|
|
101
151
|
</label>
|
|
102
152
|
{/if}
|
|
103
|
-
|
|
104
|
-
{#if
|
|
105
|
-
<
|
|
106
|
-
{:else if
|
|
107
|
-
<
|
|
108
|
-
{:else if type === 'password'}
|
|
109
|
-
<SvPasswordInput value={values[field.name] ?? ''} {disabled} onChange={(v) => setValue(field.name, v)} />
|
|
110
|
-
{:else if type === 'select'}
|
|
111
|
-
<SvDropDownList options={field.options ?? []} value={values[field.name] ?? null} {disabled} placeholder={field.placeholder} onChange={(v) => setValue(field.name, v)} />
|
|
112
|
-
{:else if type === 'checkbox'}
|
|
113
|
-
<SvCheckBox checked={!!values[field.name]} {disabled} onChange={(v) => setValue(field.name, v)}>{field.label}</SvCheckBox>
|
|
114
|
-
{:else if type === 'switch'}
|
|
115
|
-
<div class="sv-form__inline"><SvSwitchButton checked={!!values[field.name]} {disabled} onChange={(v) => setValue(field.name, v)} ariaLabel={field.label} /><span>{field.label}</span></div>
|
|
116
|
-
{:else if type === 'date'}
|
|
117
|
-
<SvDateTimePicker value={dateVal(values[field.name])} dropDownDisplayMode="calendar" formatString="yyyy-MM-dd" {disabled} onChange={(v) => setValue(field.name, v)} />
|
|
118
|
-
{:else if type === 'color'}
|
|
119
|
-
<SvColorInput value={values[field.name] ?? '#3b82f6'} {disabled} onChange={(v) => setValue(field.name, v)} />
|
|
120
|
-
{:else if type === 'rating'}
|
|
121
|
-
<SvRating value={values[field.name] ?? 0} {disabled} onChange={(v) => setValue(field.name, v)} />
|
|
122
|
-
{:else}
|
|
123
|
-
<input id={`f-${field.name}`} class="sv-form__control" type={type} {disabled} placeholder={field.placeholder} value={values[field.name] ?? ''} oninput={(e) => setValue(field.name, e.currentTarget.value)} onblur={() => { touched[field.name] = true; validateField(field.name) }} />
|
|
153
|
+
{@render control({ id: `f-${field.name}`, type, label: field.label, value: form.value(field.name), onChange: (v) => form.setValue(field.name, v), onBlur: () => form.handleBlur(field.name), disabled: fieldDisabled, placeholder: field.placeholder, options: field.options })}
|
|
154
|
+
{#if form.error(field.name)}
|
|
155
|
+
<span class="sv-form__error" role="alert">{form.error(field.name)}</span>
|
|
156
|
+
{:else if form.isValidating(field.name)}
|
|
157
|
+
<span class="sv-form__checking" role="status"><span class="sv-form__spinner" aria-hidden="true"></span>Checking…</span>
|
|
124
158
|
{/if}
|
|
125
|
-
|
|
126
|
-
{#if errors[field.name]}<span class="sv-form__error" role="alert">{errors[field.name]}</span>{/if}
|
|
127
159
|
</div>
|
|
128
|
-
{/
|
|
160
|
+
{/if}
|
|
161
|
+
{/if}
|
|
162
|
+
{/snippet}
|
|
163
|
+
|
|
164
|
+
{#snippet grid(flds: ReadonlyArray<FormField>, cols: number)}
|
|
165
|
+
<div class="sv-form__grid" style:--cols={cols}>
|
|
166
|
+
{#each flds as field (field.name)}{@render renderField(field, cols)}{/each}
|
|
129
167
|
</div>
|
|
168
|
+
{/snippet}
|
|
169
|
+
|
|
170
|
+
{#snippet actions()}
|
|
130
171
|
<div class="sv-form__actions">
|
|
131
|
-
|
|
172
|
+
{#if showReset}
|
|
173
|
+
<SvButton type="button" variant="ghost" disabled={disabled || form.submitting} onclick={() => form.reset()}>{resetLabel}</SvButton>
|
|
174
|
+
{/if}
|
|
175
|
+
{#if onCancel}
|
|
176
|
+
<SvButton type="button" variant="secondary" disabled={disabled || form.submitting} onclick={onCancel}>{cancelLabel}</SvButton>
|
|
177
|
+
{/if}
|
|
178
|
+
<SvButton type="submit" loading={form.submitting} disabled={disabled || form.submitting}>{submitLabel}</SvButton>
|
|
132
179
|
</div>
|
|
180
|
+
{/snippet}
|
|
181
|
+
|
|
182
|
+
<form class="sv-form" onsubmit={submit} novalidate>
|
|
183
|
+
{#if wizard}
|
|
184
|
+
{@const s = sections[Math.min(step, sections.length - 1)]!}
|
|
185
|
+
<SvStepper steps={stepItems} current={step} onChange={(n) => (step = n)} linear />
|
|
186
|
+
<fieldset class="sv-form__section">
|
|
187
|
+
{#if s.description}<p class="sv-form__section-desc">{s.description}</p>{/if}
|
|
188
|
+
{@render grid(s.fields, s.columns ?? columns)}
|
|
189
|
+
</fieldset>
|
|
190
|
+
<div class="sv-form__actions">
|
|
191
|
+
{#if step > 0}
|
|
192
|
+
<SvButton type="button" variant="secondary" disabled={form.submitting} onclick={back}>Back</SvButton>
|
|
193
|
+
{/if}
|
|
194
|
+
<span class="sv-form__spacer"></span>
|
|
195
|
+
{#if step < sections.length - 1}
|
|
196
|
+
<SvButton type="button" disabled={form.submitting} onclick={next}>Next</SvButton>
|
|
197
|
+
{:else}
|
|
198
|
+
{#if showReset}
|
|
199
|
+
<SvButton type="button" variant="ghost" disabled={disabled || form.submitting} onclick={() => { form.reset(); step = 0 }}>{resetLabel}</SvButton>
|
|
200
|
+
{/if}
|
|
201
|
+
<SvButton type="submit" loading={form.submitting} disabled={disabled || form.submitting}>{submitLabel}</SvButton>
|
|
202
|
+
{/if}
|
|
203
|
+
</div>
|
|
204
|
+
{:else if sections.length > 0}
|
|
205
|
+
{#each fields as entry (isFormSection(entry) ? entry.section : entry.name)}
|
|
206
|
+
{#if isFormSection(entry)}
|
|
207
|
+
<fieldset class="sv-form__section">
|
|
208
|
+
<legend class="sv-form__section-title">{entry.section}</legend>
|
|
209
|
+
{#if entry.description}<p class="sv-form__section-desc">{entry.description}</p>{/if}
|
|
210
|
+
{@render grid(entry.fields, entry.columns ?? columns)}
|
|
211
|
+
</fieldset>
|
|
212
|
+
{:else}
|
|
213
|
+
{@render grid([entry], columns)}
|
|
214
|
+
{/if}
|
|
215
|
+
{/each}
|
|
216
|
+
{@render actions()}
|
|
217
|
+
{:else}
|
|
218
|
+
{@render grid(fields as ReadonlyArray<FormField>, columns)}
|
|
219
|
+
{@render actions()}
|
|
220
|
+
{/if}
|
|
133
221
|
</form>
|
|
134
222
|
|
|
135
223
|
<style>
|
|
136
|
-
.sv-form { --_accent: var(--sg-accent, #2563eb); width: 100%; }
|
|
224
|
+
.sv-form { --_accent: var(--sg-accent, #2563eb); width: 100%; display: flex; flex-direction: column; gap: 16px; }
|
|
137
225
|
.sv-form__grid { display: grid; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); gap: 14px 18px; }
|
|
226
|
+
.sv-form__section { border: 1px solid var(--sg-border, #e2e8f0); border-radius: 10px; padding: 16px; margin: 0; min-inline-size: 0; }
|
|
227
|
+
.sv-form__section-title { font-size: 13px; font-weight: 700; color: var(--sg-fg, #0f172a); padding: 0 4px; }
|
|
228
|
+
.sv-form__section-desc { margin: 0 0 12px; font-size: 12px; color: var(--sg-muted, #64748b); }
|
|
138
229
|
.sv-form__field { display: flex; flex-direction: column; gap: 5px; }
|
|
139
230
|
.sv-form__field.is-full { grid-column: 1 / -1; }
|
|
140
231
|
.sv-form__label { font-size: 12.5px; font-weight: 600; color: var(--sg-fg, #0f172a); }
|
|
@@ -149,5 +240,24 @@
|
|
|
149
240
|
.sv-form__field.has-error .sv-form__control { border-color: var(--sg-danger, #dc2626); }
|
|
150
241
|
.sv-form__inline { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
151
242
|
.sv-form__error { font-size: 11.5px; color: var(--sg-danger, #dc2626); }
|
|
152
|
-
.sv-
|
|
243
|
+
.sv-form__checking { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--sg-muted, #64748b); }
|
|
244
|
+
.sv-form__spinner {
|
|
245
|
+
width: 11px; height: 11px; border-radius: 50%;
|
|
246
|
+
border: 2px solid color-mix(in srgb, var(--_accent) 30%, transparent);
|
|
247
|
+
border-top-color: var(--_accent); animation: sv-form-spin 0.6s linear infinite;
|
|
248
|
+
}
|
|
249
|
+
@keyframes sv-form-spin { to { transform: rotate(360deg); } }
|
|
250
|
+
@media (prefers-reduced-motion: reduce) { .sv-form__spinner { animation: none; } }
|
|
251
|
+
.sv-form__actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
|
|
252
|
+
.sv-form__spacer { flex: 1; }
|
|
253
|
+
.sv-form__array { gap: 8px; }
|
|
254
|
+
.sv-form__arow { display: flex; align-items: flex-start; gap: 8px; }
|
|
255
|
+
.sv-form__arow > .sv-form__grid { flex: 1; padding: 10px; border: 1px solid var(--sg-border, #e2e8f0); border-radius: 8px; }
|
|
256
|
+
.sv-form__aremove {
|
|
257
|
+
flex: none; width: 28px; height: 28px; margin-top: 10px; border-radius: 6px; cursor: pointer;
|
|
258
|
+
border: 1px solid var(--sg-border, #cbd5e1); background: var(--sg-input-bg, #fff);
|
|
259
|
+
color: var(--sg-muted, #64748b); font-size: 16px; line-height: 1;
|
|
260
|
+
}
|
|
261
|
+
.sv-form__aremove:hover:not(:disabled) { color: var(--sg-danger, #dc2626); border-color: var(--sg-danger, #dc2626); }
|
|
262
|
+
.sv-form__aremove:disabled { opacity: 0.5; cursor: default; }
|
|
153
263
|
</style>
|