@svgrid/grid 1.2.33 → 2.0.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 +6 -5
- package/dist/FlexRender.svelte +96 -96
- package/dist/GridFooter.svelte +178 -178
- package/dist/SvAccordion.svelte +109 -0
- package/dist/SvAccordion.svelte.d.ts +28 -0
- package/dist/SvAlert.svelte +92 -0
- package/dist/SvAlert.svelte.d.ts +27 -0
- package/dist/SvAutoComplete.svelte +47 -18
- package/dist/SvAutoComplete.svelte.d.ts +2 -5
- package/dist/SvAvatar.svelte +75 -0
- package/dist/SvAvatar.svelte.d.ts +14 -0
- package/dist/SvAvatarGroup.svelte +48 -0
- package/dist/SvAvatarGroup.svelte.d.ts +16 -0
- package/dist/SvBadge.svelte +54 -0
- package/dist/SvBadge.svelte.d.ts +23 -0
- package/dist/SvBreadcrumb.svelte +88 -0
- package/dist/SvBreadcrumb.svelte.d.ts +23 -0
- package/dist/SvButtonGroup.svelte +121 -0
- package/dist/SvButtonGroup.svelte.d.ts +16 -0
- package/dist/SvCalendar.svelte +72 -9
- package/dist/SvCalendar.svelte.d.ts +34 -1
- package/dist/SvCard.svelte +71 -0
- package/dist/SvCard.svelte.d.ts +28 -0
- package/dist/SvCarousel.svelte +134 -0
- package/dist/SvCarousel.svelte.d.ts +28 -0
- package/dist/SvCheckBox.svelte +36 -21
- package/dist/SvCheckBox.svelte.d.ts +2 -5
- package/dist/SvChip.svelte +88 -0
- package/dist/SvChip.svelte.d.ts +31 -0
- package/dist/SvCircularProgress.svelte +109 -0
- package/dist/SvCircularProgress.svelte.d.ts +31 -0
- package/dist/SvColorInput.svelte +54 -27
- package/dist/SvColorInput.svelte.d.ts +10 -6
- package/dist/SvComboBox.svelte +119 -33
- package/dist/SvComboBox.svelte.d.ts +18 -6
- package/dist/SvCommand.svelte +197 -0
- package/dist/SvCommand.svelte.d.ts +26 -0
- package/dist/SvContextMenu.svelte +96 -0
- package/dist/SvContextMenu.svelte.d.ts +25 -0
- package/dist/SvCountryInput.svelte +56 -21
- package/dist/SvCountryInput.svelte.d.ts +9 -5
- package/dist/SvDateRangeInput.svelte +256 -0
- package/dist/SvDateRangeInput.svelte.d.ts +37 -0
- package/dist/SvDateTimePicker.svelte +57 -20
- package/dist/SvDateTimePicker.svelte.d.ts +12 -4
- package/dist/SvDivider.svelte +61 -0
- package/dist/SvDivider.svelte.d.ts +22 -0
- package/dist/SvDrawer.svelte +226 -0
- package/dist/SvDrawer.svelte.d.ts +43 -0
- package/dist/SvDropDownList.svelte +114 -35
- package/dist/SvDropDownList.svelte.d.ts +7 -6
- package/dist/SvDurationInput.svelte +108 -0
- package/dist/SvDurationInput.svelte.d.ts +15 -0
- package/dist/SvEmptyState.svelte +59 -0
- package/dist/SvEmptyState.svelte.d.ts +25 -0
- package/dist/SvField.svelte +85 -0
- package/dist/SvField.svelte.d.ts +30 -0
- package/dist/SvFileUpload.svelte +169 -0
- package/dist/SvFileUpload.svelte.d.ts +24 -0
- package/dist/SvForm.svelte +7 -1
- package/dist/SvForm.svelte.d.ts +3 -0
- package/dist/SvGauge.svelte +7 -1
- package/dist/SvGauge.svelte.d.ts +11 -0
- package/dist/SvGrid.controller.svelte.d.ts +6 -0
- package/dist/SvGrid.controller.svelte.js +64 -9
- package/dist/SvGrid.css +2376 -2343
- package/dist/SvGrid.svelte +2764 -2651
- package/dist/SvGrid.types.d.ts +366 -0
- package/dist/SvGridBoard.svelte +2281 -0
- package/dist/SvGridBoard.svelte.d.ts +31 -0
- package/dist/SvGridDropdown.svelte +666 -665
- package/dist/SvGridSelect.svelte +255 -0
- package/dist/SvGridSelect.svelte.d.ts +32 -0
- package/dist/SvGroupCell.svelte +109 -0
- package/dist/SvGroupCell.svelte.d.ts +41 -0
- package/dist/SvListBox.svelte +123 -36
- package/dist/SvListBox.svelte.d.ts +12 -8
- package/dist/SvMaskedInput.svelte +53 -13
- package/dist/SvMaskedInput.svelte.d.ts +16 -6
- package/dist/SvMenu.svelte +101 -0
- package/dist/SvMenu.svelte.d.ts +26 -0
- package/dist/SvMenuList.svelte +143 -0
- package/dist/SvMenuList.svelte.d.ts +24 -0
- package/dist/SvModal.svelte +220 -0
- package/dist/SvModal.svelte.d.ts +31 -0
- package/dist/SvMultiSelect.svelte +277 -0
- package/dist/SvMultiSelect.svelte.d.ts +31 -0
- package/dist/SvNavPane.svelte +314 -0
- package/dist/SvNavPane.svelte.d.ts +59 -0
- package/dist/SvNumberInput.svelte +23 -9
- package/dist/SvNumberInput.svelte.d.ts +2 -0
- package/dist/SvOtpInput.svelte +157 -0
- package/dist/SvOtpInput.svelte.d.ts +16 -0
- package/dist/SvPagination.svelte +100 -0
- package/dist/SvPagination.svelte.d.ts +16 -0
- package/dist/SvPasswordInput.svelte +42 -12
- package/dist/SvPasswordInput.svelte.d.ts +13 -6
- package/dist/SvPhoneInput.svelte +43 -11
- package/dist/SvPhoneInput.svelte.d.ts +10 -11
- package/dist/SvPopover.svelte +127 -0
- package/dist/SvPopover.svelte.d.ts +35 -0
- package/dist/SvProgress.svelte +116 -0
- package/dist/SvProgress.svelte.d.ts +32 -0
- package/dist/SvRadioGroup.svelte +40 -22
- package/dist/SvRadioGroup.svelte.d.ts +2 -10
- package/dist/SvRating.svelte +51 -30
- package/dist/SvRating.svelte.d.ts +10 -7
- package/dist/SvRichText.svelte +192 -0
- package/dist/SvRichText.svelte.d.ts +16 -0
- package/dist/SvRowGroupPanel.svelte +147 -0
- package/dist/SvRowGroupPanel.svelte.d.ts +17 -0
- package/dist/SvScrollArea.svelte +50 -0
- package/dist/SvScrollArea.svelte.d.ts +22 -0
- package/dist/SvSkeleton.svelte +76 -0
- package/dist/SvSkeleton.svelte.d.ts +25 -0
- package/dist/SvSlider.svelte +41 -9
- package/dist/SvSlider.svelte.d.ts +4 -4
- package/dist/SvSparkline.svelte +77 -0
- package/dist/SvSparkline.svelte.d.ts +28 -0
- package/dist/SvSplitter.svelte +138 -0
- package/dist/SvSplitter.svelte.d.ts +32 -0
- package/dist/SvStat.svelte +86 -0
- package/dist/SvStat.svelte.d.ts +30 -0
- package/dist/SvStepper.svelte +91 -0
- package/dist/SvStepper.svelte.d.ts +24 -0
- package/dist/SvSwitchButton.svelte +39 -24
- package/dist/SvSwitchButton.svelte.d.ts +2 -5
- package/dist/SvTabs.svelte +147 -28
- package/dist/SvTabs.svelte.d.ts +16 -4
- package/dist/SvTagsInput.svelte +59 -22
- package/dist/SvTagsInput.svelte.d.ts +9 -4
- package/dist/SvTextArea.svelte +113 -0
- package/dist/SvTextArea.svelte.d.ts +18 -0
- package/dist/SvTextInput.svelte +115 -0
- package/dist/SvTextInput.svelte.d.ts +20 -0
- package/dist/SvTimePicker.svelte +19 -5
- package/dist/SvTimePicker.svelte.d.ts +12 -0
- package/dist/SvTimeline.svelte +75 -0
- package/dist/SvTimeline.svelte.d.ts +24 -0
- package/dist/SvToaster.svelte +124 -0
- package/dist/SvToaster.svelte.d.ts +10 -0
- package/dist/SvToggleButton.svelte +37 -12
- package/dist/SvToggleButton.svelte.d.ts +2 -4
- package/dist/SvTooltip.svelte +113 -0
- package/dist/SvTooltip.svelte.d.ts +22 -0
- package/dist/SvTour.svelte +151 -0
- package/dist/SvTour.svelte.d.ts +25 -0
- package/dist/SvTree.svelte +286 -44
- package/dist/SvTree.svelte.d.ts +26 -9
- package/dist/SvTreeSelect.svelte +222 -0
- package/dist/SvTreeSelect.svelte.d.ts +24 -0
- package/dist/a11y/dismissable.d.ts +32 -0
- package/dist/a11y/dismissable.js +54 -0
- package/dist/a11y/focus-trap.d.ts +39 -0
- package/dist/a11y/focus-trap.js +142 -0
- package/dist/a11y/live-region.d.ts +8 -0
- package/dist/a11y/live-region.js +60 -0
- package/dist/a11y/scroll-lock.d.ts +4 -0
- package/dist/a11y/scroll-lock.js +41 -0
- package/dist/a11y.d.ts +3 -1
- package/dist/a11y.js +1 -1
- package/dist/avatar.d.ts +10 -0
- package/dist/avatar.js +22 -0
- package/dist/builtin-editors.d.ts +5 -0
- package/dist/builtin-editors.js +55 -0
- package/dist/cdn/svgrid.js +16022 -8235
- package/dist/cdn/svgrid.svelte-external.js +14543 -6765
- package/dist/columns.js +3 -2
- package/dist/core.d.ts +7 -1
- package/dist/countries.d.ts +12 -0
- package/dist/countries.js +24 -0
- package/dist/createAccordion.svelte.d.ts +71 -0
- package/dist/createAccordion.svelte.js +99 -0
- package/dist/createAutocomplete.svelte.d.ts +13 -4
- package/dist/createAutocomplete.svelte.js +11 -1
- package/dist/createButtonGroup.svelte.d.ts +62 -0
- package/dist/createButtonGroup.svelte.js +154 -0
- package/dist/createCalendar.svelte.d.ts +5 -0
- package/dist/createCalendar.svelte.js +2 -0
- package/dist/createCheckbox.svelte.d.ts +9 -17
- package/dist/createCheckbox.svelte.js +28 -1
- package/dist/createColorInput.svelte.d.ts +12 -22
- package/dist/createColorInput.svelte.js +13 -0
- package/dist/createCombobox.svelte.d.ts +16 -5
- package/dist/createCombobox.svelte.js +13 -2
- package/dist/createCountryInput.svelte.d.ts +14 -3
- package/dist/createCountryInput.svelte.js +12 -2
- package/dist/createDateTimePicker.svelte.d.ts +17 -2
- package/dist/createDateTimePicker.svelte.js +12 -2
- package/dist/createDropdownList.svelte.d.ts +14 -5
- package/dist/createDropdownList.svelte.js +50 -1
- package/dist/createFileUpload.svelte.d.ts +68 -0
- package/dist/createFileUpload.svelte.js +122 -0
- package/dist/createListbox.svelte.d.ts +10 -1
- package/dist/createListbox.svelte.js +48 -1
- package/dist/createMaskedInput.svelte.d.ts +11 -2
- package/dist/createMaskedInput.svelte.js +11 -1
- package/dist/createNumberInput.svelte.d.ts +1 -0
- package/dist/createNumberInput.svelte.js +1 -0
- package/dist/createPasswordInput.svelte.d.ts +19 -21
- package/dist/createPasswordInput.svelte.js +16 -4
- package/dist/createPhoneInput.svelte.d.ts +26 -7
- package/dist/createPhoneInput.svelte.js +24 -3
- package/dist/createPopoverSelect.svelte.d.ts +86 -0
- package/dist/createPopoverSelect.svelte.js +196 -0
- package/dist/createRadioGroup.svelte.d.ts +9 -0
- package/dist/createRadioGroup.svelte.js +11 -1
- package/dist/createRating.svelte.d.ts +11 -0
- package/dist/createRating.svelte.js +12 -1
- package/dist/createSlider.svelte.d.ts +2 -0
- package/dist/createSlider.svelte.js +16 -5
- package/dist/createSplitter.svelte.d.ts +67 -0
- package/dist/createSplitter.svelte.js +99 -0
- package/dist/createSwitch.svelte.d.ts +9 -16
- package/dist/createSwitch.svelte.js +28 -1
- package/dist/createTabs.svelte.d.ts +7 -0
- package/dist/createTabs.svelte.js +17 -2
- package/dist/createTagsInput.svelte.d.ts +13 -1
- package/dist/createTagsInput.svelte.js +12 -3
- package/dist/createToggle.svelte.d.ts +9 -0
- package/dist/createToggle.svelte.js +12 -1
- package/dist/createTree.svelte.d.ts +19 -0
- package/dist/createTree.svelte.js +108 -15
- package/dist/debounce.d.ts +11 -0
- package/dist/debounce.js +30 -0
- package/dist/duration.d.ts +15 -0
- package/dist/duration.js +51 -0
- package/dist/editor-contract.d.ts +62 -7
- package/dist/editor-contract.js +45 -5
- package/dist/editor-registry.d.ts +67 -0
- package/dist/editor-registry.js +38 -0
- package/dist/editors/cell-editors.d.ts +1 -1
- package/dist/editors/cell-editors.js +5 -0
- package/dist/fuzzy.d.ts +3 -0
- package/dist/fuzzy.js +41 -0
- package/dist/grid-select.d.ts +9 -0
- package/dist/grid-select.js +8 -0
- package/dist/index.d.ts +79 -6
- package/dist/index.js +78 -4
- package/dist/keyboard-handlers.js +19 -0
- package/dist/list-option.d.ts +36 -0
- package/dist/list-option.js +68 -0
- package/dist/otp.d.ts +16 -0
- package/dist/otp.js +26 -0
- package/dist/paginate.d.ts +20 -0
- package/dist/paginate.js +40 -0
- package/dist/popover.d.ts +15 -1
- package/dist/popover.js +29 -3
- package/dist/recurrence.d.ts +36 -0
- package/dist/recurrence.js +90 -0
- package/dist/server-data-source.d.ts +89 -0
- package/dist/server-data-source.js +4 -0
- package/dist/server-group-model.d.ts +98 -0
- package/dist/server-group-model.js +263 -0
- package/dist/toast-store.svelte.d.ts +41 -0
- package/dist/toast-store.svelte.js +113 -0
- package/dist/tree-select.d.ts +19 -0
- package/dist/tree-select.js +40 -0
- package/dist/ui-app.types.d.ts +80 -0
- package/dist/ui-app.types.js +7 -0
- package/dist/validators.d.ts +43 -0
- package/dist/validators.js +53 -0
- package/dist/virtual.d.ts +35 -0
- package/dist/virtual.js +34 -0
- package/package.json +85 -85
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +178 -178
- package/src/SvAccordion.svelte +109 -0
- package/src/SvAccordion.test.ts +66 -0
- package/src/SvAlert.svelte +92 -0
- package/src/SvAutoComplete.svelte +47 -18
- package/src/SvAvatar.svelte +75 -0
- package/src/SvAvatarGroup.svelte +48 -0
- package/src/SvBadge.svelte +54 -0
- package/src/SvBreadcrumb.svelte +88 -0
- package/src/SvButtonGroup.svelte +121 -0
- package/src/SvButtonGroup.test.ts +72 -0
- package/src/SvCalendar.svelte +72 -9
- package/src/SvCard.svelte +71 -0
- package/src/SvCarousel.svelte +134 -0
- package/src/SvCheckBox.svelte +36 -21
- package/src/SvChip.svelte +88 -0
- package/src/SvCircularProgress.svelte +109 -0
- package/src/SvColorInput.svelte +54 -27
- package/src/SvComboBox.svelte +119 -33
- package/src/SvCommand.svelte +197 -0
- package/src/SvContextMenu.svelte +96 -0
- package/src/SvCountryInput.svelte +56 -21
- package/src/SvDateRangeInput.svelte +256 -0
- package/src/SvDateRangeInput.test.ts +80 -0
- package/src/SvDateTimePicker.svelte +57 -20
- package/src/SvDivider.svelte +61 -0
- package/src/SvDrawer.svelte +226 -0
- package/src/SvDrawer.test.ts +125 -0
- package/src/SvDropDownList.svelte +114 -35
- package/src/SvDurationInput.svelte +108 -0
- package/src/SvEmptyState.svelte +59 -0
- package/src/SvField.svelte +85 -0
- package/src/SvFileUpload.svelte +169 -0
- package/src/SvFileUpload.test.ts +59 -0
- package/src/SvForm.svelte +7 -1
- package/src/SvGauge.svelte +7 -1
- package/src/SvGrid.controller.svelte.ts +2553 -2494
- package/src/SvGrid.css +2376 -2343
- package/src/SvGrid.svelte +2764 -2651
- package/src/SvGrid.types.ts +944 -570
- package/src/SvGridBoard.svelte +2281 -0
- package/src/SvGridDropdown.svelte +666 -665
- package/src/SvGridSelect.svelte +255 -0
- package/src/SvGridSelect.test.ts +100 -0
- package/src/SvGroupCell.svelte +109 -0
- package/src/SvListBox.svelte +123 -36
- package/src/SvMaskedInput.svelte +53 -13
- package/src/SvMenu.svelte +101 -0
- package/src/SvMenu.test.ts +73 -0
- package/src/SvMenuList.svelte +143 -0
- package/src/SvModal.svelte +220 -0
- package/src/SvMultiSelect.svelte +277 -0
- package/src/SvMultiSelect.test.ts +167 -0
- package/src/SvNavPane.svelte +314 -0
- package/src/SvNavPane.test.ts +70 -0
- package/src/SvNumberInput.svelte +23 -9
- package/src/SvOtpInput.svelte +157 -0
- package/src/SvPagination.svelte +100 -0
- package/src/SvPasswordInput.svelte +42 -12
- package/src/SvPhoneInput.svelte +43 -11
- package/src/SvPopover.svelte +127 -0
- package/src/SvProgress.svelte +116 -0
- package/src/SvRadioGroup.svelte +40 -22
- package/src/SvRating.svelte +51 -30
- package/src/SvRichText.svelte +192 -0
- package/src/SvRowGroupPanel.svelte +147 -0
- package/src/SvScrollArea.svelte +50 -0
- package/src/SvSkeleton.svelte +76 -0
- package/src/SvSlider.svelte +41 -9
- package/src/SvSparkline.svelte +77 -0
- package/src/SvSplitter.svelte +138 -0
- package/src/SvSplitter.test.ts +55 -0
- package/src/SvStat.svelte +86 -0
- package/src/SvStepper.svelte +91 -0
- package/src/SvSwitchButton.svelte +39 -24
- package/src/SvTabs.svelte +147 -28
- package/src/SvTagsInput.svelte +59 -22
- package/src/SvTextArea.svelte +113 -0
- package/src/SvTextInput.svelte +115 -0
- package/src/SvTimePicker.svelte +19 -5
- package/src/SvTimeline.svelte +75 -0
- package/src/SvToaster.svelte +124 -0
- package/src/SvToaster.test.ts +63 -0
- package/src/SvToggleButton.svelte +37 -12
- package/src/SvTooltip.svelte +113 -0
- package/src/SvTour.svelte +151 -0
- package/src/SvTree.svelte +286 -44
- package/src/SvTreeSelect.svelte +222 -0
- package/src/SvTreeSelect.test.ts +87 -0
- package/src/a11y/dismissable.test.ts +95 -0
- package/src/a11y/dismissable.ts +94 -0
- package/src/a11y/focus-trap.test.ts +110 -0
- package/src/a11y/focus-trap.ts +134 -0
- package/src/a11y/live-region.test.ts +40 -0
- package/src/a11y/live-region.ts +65 -0
- package/src/a11y/scroll-lock.test.ts +38 -0
- package/src/a11y/scroll-lock.ts +41 -0
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +61 -59
- package/src/avatar.test.ts +32 -0
- package/src/avatar.ts +21 -0
- package/src/board.test.ts +927 -0
- package/src/build-api.ts +798 -798
- package/src/builtin-editors.grid.test.ts +85 -0
- package/src/builtin-editors.test.ts +58 -0
- package/src/builtin-editors.ts +56 -0
- package/src/cell-formatting.ts +169 -169
- package/src/cell-render.ts +469 -469
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/columns.ts +3 -2
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1111 -1101
- package/src/countries.ts +25 -0
- package/src/createAccordion.svelte.ts +126 -0
- package/src/createAutocomplete.svelte.ts +18 -1
- package/src/createButtonGroup.svelte.ts +166 -0
- package/src/createCalendar.svelte.ts +6 -0
- package/src/createCheckbox.svelte.ts +23 -1
- package/src/createColorInput.svelte.ts +20 -0
- package/src/createCombobox.svelte.ts +22 -2
- package/src/createCountryInput.svelte.ts +21 -2
- package/src/createDateTimePicker.svelte.ts +23 -2
- package/src/createDropdownList.svelte.ts +31 -2
- package/src/createFileUpload.svelte.ts +144 -0
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/createListbox.svelte.ts +35 -3
- package/src/createMaskedInput.svelte.ts +18 -1
- package/src/createNumberInput.svelte.ts +2 -0
- package/src/createPasswordInput.svelte.ts +31 -5
- package/src/createPhoneInput.svelte.ts +38 -4
- package/src/createPopoverSelect.svelte.ts +208 -0
- package/src/createRadioGroup.svelte.ts +23 -1
- package/src/createRating.svelte.ts +26 -1
- package/src/createSlider.svelte.ts +14 -3
- package/src/createSplitter.svelte.ts +119 -0
- package/src/createSwitch.svelte.ts +26 -3
- package/src/createTabs.svelte.ts +20 -3
- package/src/createTagsInput.svelte.ts +24 -3
- package/src/createToggle.svelte.ts +25 -2
- package/src/createTree.svelte.ts +104 -14
- package/src/debounce.test.ts +50 -0
- package/src/debounce.ts +41 -0
- package/src/duration.test.ts +41 -0
- package/src/duration.ts +51 -0
- package/src/editing.test.ts +859 -859
- package/src/editing.ts +675 -675
- package/src/editor-contract.ts +87 -8
- package/src/editor-registry.grid.test.ts +98 -0
- package/src/editor-registry.test.ts +86 -0
- package/src/editor-registry.ts +106 -0
- package/src/editors/cell-editors.ts +10 -1
- 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/flex-render.ts +3 -3
- package/src/fuzzy.test.ts +40 -0
- package/src/fuzzy.ts +39 -0
- package/src/grid-select.test.ts +28 -0
- package/src/grid-select.ts +20 -0
- package/src/index.ts +463 -318
- package/src/keyboard-handlers.ts +20 -0
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/list-option.ts +74 -0
- package/src/list-power.test.ts +71 -0
- package/src/menus.ts +582 -582
- package/src/merge-objects.ts +48 -48
- package/src/otp.test.ts +28 -0
- package/src/otp.ts +28 -0
- package/src/overlays.test.ts +85 -0
- package/src/paginate.test.ts +41 -0
- package/src/paginate.ts +61 -0
- package/src/phone-valid.test.ts +26 -0
- package/src/popover.ts +31 -3
- package/src/progress.test.ts +55 -0
- package/src/recurrence.test.ts +91 -0
- package/src/recurrence.ts +111 -0
- package/src/render-component.ts +28 -28
- 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 -311
- package/src/server-group-model.test.ts +294 -0
- package/src/server-group-model.ts +370 -0
- package/src/sparkline.test.ts +68 -68
- package/src/sparkline.ts +169 -169
- package/src/spreadsheet.test.ts +489 -489
- package/src/spreadsheet.ts +304 -304
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/svgrid-wrapper.types.ts +439 -439
- package/src/svgrid.behavior.test.ts +706 -706
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.responsive.test.ts +72 -0
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/toast-store.svelte.ts +148 -0
- package/src/toast-store.test.ts +86 -0
- package/src/tree-edit.test.ts +49 -0
- package/src/tree-filter.test.ts +56 -0
- package/src/tree-select.test.ts +48 -0
- package/src/tree-select.ts +62 -0
- package/src/ui-app.test.ts +130 -0
- package/src/ui-app.types.ts +88 -0
- package/src/ui-display.test.ts +79 -0
- package/src/ui-inputs.test.ts +1 -1
- package/src/ui-status.test.ts +141 -0
- package/src/ui-tier1.test.ts +142 -0
- package/src/ui-tier2.test.ts +124 -0
- package/src/ui-tier3.test.ts +139 -0
- package/src/validators.test.ts +58 -0
- package/src/validators.ts +105 -0
- package/src/virtual.test.ts +72 -0
- package/src/virtual.ts +67 -0
- 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
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The free CSV / TSV / JSON export + copy-to-clipboard now on the grid API.
|
|
3
|
-
* Mounts a real <SvGrid /> and drives api.exportCsv/exportTsv/exportJson/
|
|
4
|
-
* copyToClipboard with download:false so nothing hits the DOM download path.
|
|
5
|
-
*/
|
|
6
|
-
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
-
import { mount, unmount } from 'svelte'
|
|
8
|
-
import SvGrid from './SvGrid.svelte'
|
|
9
|
-
import {
|
|
10
|
-
columnFilteringFeature,
|
|
11
|
-
rowSelectionFeature,
|
|
12
|
-
rowSortingFeature,
|
|
13
|
-
tableFeatures,
|
|
14
|
-
} from './index'
|
|
15
|
-
import type { ColumnDef, SvGridApi } from './index'
|
|
16
|
-
|
|
17
|
-
type Row = { id: number; name: string; price: number; when: string }
|
|
18
|
-
const rows: Row[] = [
|
|
19
|
-
{ id: 1, name: 'ACME, Inc', price: 1234.5, when: '2026-03-04' },
|
|
20
|
-
{ id: 2, name: 'Globex', price: 20, when: '2026-06-01' },
|
|
21
|
-
]
|
|
22
|
-
const columns: ColumnDef<any, Row>[] = [
|
|
23
|
-
{ field: 'name', header: 'Company', width: 180 },
|
|
24
|
-
{ field: 'price', header: 'Price', width: 120, align: 'right', format: { type: 'currency', currency: 'USD' } },
|
|
25
|
-
{ field: 'when', header: 'Date', width: 120 }, // plain string, no format (deterministic)
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
const features = tableFeatures({ columnFilteringFeature, rowSortingFeature, rowSelectionFeature })
|
|
29
|
-
|
|
30
|
-
function mountGrid(): Promise<{ api: SvGridApi<any, Row>; destroy: () => void }> {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const target = document.createElement('div')
|
|
33
|
-
document.body.appendChild(target)
|
|
34
|
-
let done = false
|
|
35
|
-
const app = mount(SvGrid, {
|
|
36
|
-
target,
|
|
37
|
-
props: {
|
|
38
|
-
data: rows.map((r) => ({ ...r })),
|
|
39
|
-
columns: columns.map((c) => ({ ...c })),
|
|
40
|
-
features,
|
|
41
|
-
getRowId: (r: Row) => String(r.id),
|
|
42
|
-
rowHeight: 34,
|
|
43
|
-
containerHeight: 400,
|
|
44
|
-
virtualization: false,
|
|
45
|
-
onApiReady(api: SvGridApi<any, Row>) {
|
|
46
|
-
done = true
|
|
47
|
-
resolve({ api, destroy: () => { unmount(app); target.remove() } })
|
|
48
|
-
},
|
|
49
|
-
} as any,
|
|
50
|
-
})
|
|
51
|
-
queueMicrotask(() => { if (!done) reject(new Error('onApiReady never fired')) })
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
let cleanup: (() => void) | null = null
|
|
56
|
-
afterEach(() => { cleanup?.(); cleanup = null; vi.restoreAllMocks() })
|
|
57
|
-
|
|
58
|
-
describe('free grid export: exportCsv', () => {
|
|
59
|
-
it('serializes visible rows with faithful formatted values + a BOM header', async () => {
|
|
60
|
-
const { api, destroy } = await mountGrid()
|
|
61
|
-
cleanup = destroy
|
|
62
|
-
const csv = await api.exportCsv({ download: false })
|
|
63
|
-
const lines = csv.replace(/^/, '').split('\r\n')
|
|
64
|
-
expect(lines[0]).toBe('Company,Price,Date')
|
|
65
|
-
// Formatted as on screen; the comma in "ACME, Inc" AND in "$1,234.50" both
|
|
66
|
-
// force RFC-4180 quoting.
|
|
67
|
-
expect(lines[1]).toBe('"ACME, Inc","$1,234.50",2026-03-04')
|
|
68
|
-
expect(csv.startsWith('')).toBe(true)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('rawValues:true writes the underlying numbers/strings', async () => {
|
|
72
|
-
const { api, destroy } = await mountGrid()
|
|
73
|
-
cleanup = destroy
|
|
74
|
-
const csv = await api.exportCsv({ download: false, rawValues: true, bom: false })
|
|
75
|
-
const lines = csv.split('\r\n')
|
|
76
|
-
expect(lines[1]).toBe('"ACME, Inc",1234.5,2026-03-04')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('honors a column subset in the given order', async () => {
|
|
80
|
-
const { api, destroy } = await mountGrid()
|
|
81
|
-
cleanup = destroy
|
|
82
|
-
const csv = await api.exportCsv({ download: false, bom: false, columns: ['when', 'name'] })
|
|
83
|
-
expect(csv.split('\r\n')[0]).toBe('Date,Company')
|
|
84
|
-
})
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
describe('free grid export: exportTsv / exportJson', () => {
|
|
88
|
-
it('exportTsv is tab-delimited', async () => {
|
|
89
|
-
const { api, destroy } = await mountGrid()
|
|
90
|
-
cleanup = destroy
|
|
91
|
-
const tsv = await api.exportTsv({ download: false, bom: false })
|
|
92
|
-
expect(tsv.split('\r\n')[0]).toBe('Company\tPrice\tDate')
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('exportJson emits an array of formatted records', async () => {
|
|
96
|
-
const { api, destroy } = await mountGrid()
|
|
97
|
-
cleanup = destroy
|
|
98
|
-
const json = JSON.parse(await api.exportJson({ download: false }))
|
|
99
|
-
expect(json).toHaveLength(2)
|
|
100
|
-
expect(json[0]).toEqual({ name: 'ACME, Inc', price: '$1,234.50', when: '2026-03-04' })
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
describe('free grid export: copyToClipboard', () => {
|
|
105
|
-
it('writes TSV to the clipboard by default', async () => {
|
|
106
|
-
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
107
|
-
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
108
|
-
const { api, destroy } = await mountGrid()
|
|
109
|
-
cleanup = destroy
|
|
110
|
-
const text = await api.copyToClipboard()
|
|
111
|
-
expect(writeText).toHaveBeenCalledOnce()
|
|
112
|
-
expect(text.split('\r\n')[0]).toBe('Company\tPrice\tDate')
|
|
113
|
-
expect(text.startsWith('')).toBe(false) // no BOM on clipboard
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('can copy a Markdown table', async () => {
|
|
117
|
-
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
118
|
-
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
119
|
-
const { api, destroy } = await mountGrid()
|
|
120
|
-
cleanup = destroy
|
|
121
|
-
const md = await api.copyToClipboard({ format: 'markdown' })
|
|
122
|
-
const lines = md.split('\n')
|
|
123
|
-
expect(lines[0]).toBe('| Company | Price | Date |')
|
|
124
|
-
expect(lines[1]).toBe('| --- | ---: | --- |') // Price is right-aligned
|
|
125
|
-
})
|
|
126
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* The free CSV / TSV / JSON export + copy-to-clipboard now on the grid API.
|
|
3
|
+
* Mounts a real <SvGrid /> and drives api.exportCsv/exportTsv/exportJson/
|
|
4
|
+
* copyToClipboard with download:false so nothing hits the DOM download path.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
7
|
+
import { mount, unmount } from 'svelte'
|
|
8
|
+
import SvGrid from './SvGrid.svelte'
|
|
9
|
+
import {
|
|
10
|
+
columnFilteringFeature,
|
|
11
|
+
rowSelectionFeature,
|
|
12
|
+
rowSortingFeature,
|
|
13
|
+
tableFeatures,
|
|
14
|
+
} from './index'
|
|
15
|
+
import type { ColumnDef, SvGridApi } from './index'
|
|
16
|
+
|
|
17
|
+
type Row = { id: number; name: string; price: number; when: string }
|
|
18
|
+
const rows: Row[] = [
|
|
19
|
+
{ id: 1, name: 'ACME, Inc', price: 1234.5, when: '2026-03-04' },
|
|
20
|
+
{ id: 2, name: 'Globex', price: 20, when: '2026-06-01' },
|
|
21
|
+
]
|
|
22
|
+
const columns: ColumnDef<any, Row>[] = [
|
|
23
|
+
{ field: 'name', header: 'Company', width: 180 },
|
|
24
|
+
{ field: 'price', header: 'Price', width: 120, align: 'right', format: { type: 'currency', currency: 'USD' } },
|
|
25
|
+
{ field: 'when', header: 'Date', width: 120 }, // plain string, no format (deterministic)
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
const features = tableFeatures({ columnFilteringFeature, rowSortingFeature, rowSelectionFeature })
|
|
29
|
+
|
|
30
|
+
function mountGrid(): Promise<{ api: SvGridApi<any, Row>; destroy: () => void }> {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const target = document.createElement('div')
|
|
33
|
+
document.body.appendChild(target)
|
|
34
|
+
let done = false
|
|
35
|
+
const app = mount(SvGrid, {
|
|
36
|
+
target,
|
|
37
|
+
props: {
|
|
38
|
+
data: rows.map((r) => ({ ...r })),
|
|
39
|
+
columns: columns.map((c) => ({ ...c })),
|
|
40
|
+
features,
|
|
41
|
+
getRowId: (r: Row) => String(r.id),
|
|
42
|
+
rowHeight: 34,
|
|
43
|
+
containerHeight: 400,
|
|
44
|
+
virtualization: false,
|
|
45
|
+
onApiReady(api: SvGridApi<any, Row>) {
|
|
46
|
+
done = true
|
|
47
|
+
resolve({ api, destroy: () => { unmount(app); target.remove() } })
|
|
48
|
+
},
|
|
49
|
+
} as any,
|
|
50
|
+
})
|
|
51
|
+
queueMicrotask(() => { if (!done) reject(new Error('onApiReady never fired')) })
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let cleanup: (() => void) | null = null
|
|
56
|
+
afterEach(() => { cleanup?.(); cleanup = null; vi.restoreAllMocks() })
|
|
57
|
+
|
|
58
|
+
describe('free grid export: exportCsv', () => {
|
|
59
|
+
it('serializes visible rows with faithful formatted values + a BOM header', async () => {
|
|
60
|
+
const { api, destroy } = await mountGrid()
|
|
61
|
+
cleanup = destroy
|
|
62
|
+
const csv = await api.exportCsv({ download: false })
|
|
63
|
+
const lines = csv.replace(/^/, '').split('\r\n')
|
|
64
|
+
expect(lines[0]).toBe('Company,Price,Date')
|
|
65
|
+
// Formatted as on screen; the comma in "ACME, Inc" AND in "$1,234.50" both
|
|
66
|
+
// force RFC-4180 quoting.
|
|
67
|
+
expect(lines[1]).toBe('"ACME, Inc","$1,234.50",2026-03-04')
|
|
68
|
+
expect(csv.startsWith('')).toBe(true)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('rawValues:true writes the underlying numbers/strings', async () => {
|
|
72
|
+
const { api, destroy } = await mountGrid()
|
|
73
|
+
cleanup = destroy
|
|
74
|
+
const csv = await api.exportCsv({ download: false, rawValues: true, bom: false })
|
|
75
|
+
const lines = csv.split('\r\n')
|
|
76
|
+
expect(lines[1]).toBe('"ACME, Inc",1234.5,2026-03-04')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('honors a column subset in the given order', async () => {
|
|
80
|
+
const { api, destroy } = await mountGrid()
|
|
81
|
+
cleanup = destroy
|
|
82
|
+
const csv = await api.exportCsv({ download: false, bom: false, columns: ['when', 'name'] })
|
|
83
|
+
expect(csv.split('\r\n')[0]).toBe('Date,Company')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('free grid export: exportTsv / exportJson', () => {
|
|
88
|
+
it('exportTsv is tab-delimited', async () => {
|
|
89
|
+
const { api, destroy } = await mountGrid()
|
|
90
|
+
cleanup = destroy
|
|
91
|
+
const tsv = await api.exportTsv({ download: false, bom: false })
|
|
92
|
+
expect(tsv.split('\r\n')[0]).toBe('Company\tPrice\tDate')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('exportJson emits an array of formatted records', async () => {
|
|
96
|
+
const { api, destroy } = await mountGrid()
|
|
97
|
+
cleanup = destroy
|
|
98
|
+
const json = JSON.parse(await api.exportJson({ download: false }))
|
|
99
|
+
expect(json).toHaveLength(2)
|
|
100
|
+
expect(json[0]).toEqual({ name: 'ACME, Inc', price: '$1,234.50', when: '2026-03-04' })
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
describe('free grid export: copyToClipboard', () => {
|
|
105
|
+
it('writes TSV to the clipboard by default', async () => {
|
|
106
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
107
|
+
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
108
|
+
const { api, destroy } = await mountGrid()
|
|
109
|
+
cleanup = destroy
|
|
110
|
+
const text = await api.copyToClipboard()
|
|
111
|
+
expect(writeText).toHaveBeenCalledOnce()
|
|
112
|
+
expect(text.split('\r\n')[0]).toBe('Company\tPrice\tDate')
|
|
113
|
+
expect(text.startsWith('')).toBe(false) // no BOM on clipboard
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('can copy a Markdown table', async () => {
|
|
117
|
+
const writeText = vi.fn().mockResolvedValue(undefined)
|
|
118
|
+
vi.stubGlobal('navigator', { clipboard: { writeText } })
|
|
119
|
+
const { api, destroy } = await mountGrid()
|
|
120
|
+
cleanup = destroy
|
|
121
|
+
const md = await api.copyToClipboard({ format: 'markdown' })
|
|
122
|
+
const lines = md.split('\n')
|
|
123
|
+
expect(lines[0]).toBe('| Company | Price | Date |')
|
|
124
|
+
expect(lines[1]).toBe('| --- | ---: | --- |') // Price is right-aligned
|
|
125
|
+
})
|
|
126
|
+
})
|
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
coerceExportDate,
|
|
4
|
-
formatValueForExport,
|
|
5
|
-
toExcelNumFmt,
|
|
6
|
-
valueForExcel,
|
|
7
|
-
} from './export-format'
|
|
8
|
-
import type { CellFormatConfig } from './core'
|
|
9
|
-
|
|
10
|
-
describe('formatValueForExport', () => {
|
|
11
|
-
it('returns "" for null / undefined', () => {
|
|
12
|
-
expect(formatValueForExport(null, undefined)).toBe('')
|
|
13
|
-
expect(formatValueForExport(undefined, { type: 'number' })).toBe('')
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('stringifies when there is no format', () => {
|
|
17
|
-
expect(formatValueForExport(42, undefined)).toBe('42')
|
|
18
|
-
expect(formatValueForExport('hi', undefined)).toBe('hi')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('formats currency like the grid does', () => {
|
|
22
|
-
const f: CellFormatConfig = { type: 'currency', currency: 'USD', locales: 'en-US' }
|
|
23
|
-
expect(formatValueForExport(19.95, f)).toBe('$19.95')
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('formats a percent from 0..100 points', () => {
|
|
27
|
-
const f: CellFormatConfig = { type: 'percent', valueIsPercentPoints: true, locales: 'en-US' }
|
|
28
|
-
expect(formatValueForExport(42, f)).toBe('42%')
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it('formats a number with grouping', () => {
|
|
32
|
-
const f: CellFormatConfig = {
|
|
33
|
-
type: 'number',
|
|
34
|
-
locales: 'en-US',
|
|
35
|
-
options: { minimumFractionDigits: 2 },
|
|
36
|
-
}
|
|
37
|
-
expect(formatValueForExport(1234567, f)).toBe('1,234,567.00')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('formats a date with the y-m-d pattern', () => {
|
|
41
|
-
const f: CellFormatConfig = { type: 'date', pattern: 'y-m-d', locales: 'en-US' }
|
|
42
|
-
expect(formatValueForExport(new Date('2026-03-04T00:00:00Z'), f)).toMatch(/2026/)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('falls back to String() when a date value is not parseable', () => {
|
|
46
|
-
const f: CellFormatConfig = { type: 'date' }
|
|
47
|
-
expect(formatValueForExport('not-a-date', f)).toBe('not-a-date')
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
describe('coerceExportDate', () => {
|
|
52
|
-
it('accepts Date, epoch ms, and ISO strings; rejects junk', () => {
|
|
53
|
-
expect(coerceExportDate(new Date('2020-01-01')) instanceof Date).toBe(true)
|
|
54
|
-
expect(coerceExportDate(1_600_000_000_000) instanceof Date).toBe(true)
|
|
55
|
-
expect(coerceExportDate('2021-06-15') instanceof Date).toBe(true)
|
|
56
|
-
expect(coerceExportDate('nope')).toBeNull()
|
|
57
|
-
expect(coerceExportDate(new Date('bad'))).toBeNull()
|
|
58
|
-
expect(coerceExportDate(null)).toBeNull()
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
describe('toExcelNumFmt', () => {
|
|
63
|
-
it('maps number/currency/percent/date to Excel codes', () => {
|
|
64
|
-
expect(toExcelNumFmt({ type: 'number' })).toBe('#,##0')
|
|
65
|
-
expect(toExcelNumFmt({ type: 'number', options: { maximumFractionDigits: 2 } })).toBe('#,##0.00')
|
|
66
|
-
expect(toExcelNumFmt({ type: 'currency', currency: 'USD' })).toBe('"$"#,##0.00')
|
|
67
|
-
expect(toExcelNumFmt({ type: 'currency', currency: 'EUR' })).toBe('"€"#,##0.00')
|
|
68
|
-
expect(toExcelNumFmt({ type: 'percent' })).toBe('0.00%')
|
|
69
|
-
expect(toExcelNumFmt({ type: 'date' })).toBe('yyyy-mm-dd')
|
|
70
|
-
expect(toExcelNumFmt({ type: 'datetime' })).toBe('yyyy-mm-dd hh:mm')
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it('falls back to the ISO code for currencies without a glyph', () => {
|
|
74
|
-
expect(toExcelNumFmt({ type: 'currency', currency: 'CHF' })).toBe('"CHF"#,##0.00')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('returns undefined without a format', () => {
|
|
78
|
-
expect(toExcelNumFmt(undefined)).toBeUndefined()
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
describe('valueForExcel', () => {
|
|
83
|
-
it('keeps numbers/currency numeric', () => {
|
|
84
|
-
expect(valueForExcel(19.95, { type: 'currency' })).toEqual({ ok: true, value: 19.95 })
|
|
85
|
-
expect(valueForExcel(1234, { type: 'number' })).toEqual({ ok: true, value: 1234 })
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('divides percent points to a fraction', () => {
|
|
89
|
-
expect(valueForExcel(42, { type: 'percent', valueIsPercentPoints: true })).toEqual({
|
|
90
|
-
ok: true,
|
|
91
|
-
value: 0.42,
|
|
92
|
-
})
|
|
93
|
-
expect(valueForExcel(0.42, { type: 'percent' })).toEqual({ ok: true, value: 0.42 })
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('returns real Dates for date formats', () => {
|
|
97
|
-
const r = valueForExcel('2026-03-04', { type: 'date' })
|
|
98
|
-
expect(r.ok).toBe(true)
|
|
99
|
-
if (r.ok) expect(r.value).toBeInstanceOf(Date)
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('reports not-ok for non-representable values', () => {
|
|
103
|
-
expect(valueForExcel('abc', { type: 'number' })).toEqual({ ok: false })
|
|
104
|
-
expect(valueForExcel(5, undefined)).toEqual({ ok: false })
|
|
105
|
-
expect(valueForExcel(null, { type: 'number' })).toEqual({ ok: false })
|
|
106
|
-
})
|
|
107
|
-
})
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
coerceExportDate,
|
|
4
|
+
formatValueForExport,
|
|
5
|
+
toExcelNumFmt,
|
|
6
|
+
valueForExcel,
|
|
7
|
+
} from './export-format'
|
|
8
|
+
import type { CellFormatConfig } from './core'
|
|
9
|
+
|
|
10
|
+
describe('formatValueForExport', () => {
|
|
11
|
+
it('returns "" for null / undefined', () => {
|
|
12
|
+
expect(formatValueForExport(null, undefined)).toBe('')
|
|
13
|
+
expect(formatValueForExport(undefined, { type: 'number' })).toBe('')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('stringifies when there is no format', () => {
|
|
17
|
+
expect(formatValueForExport(42, undefined)).toBe('42')
|
|
18
|
+
expect(formatValueForExport('hi', undefined)).toBe('hi')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('formats currency like the grid does', () => {
|
|
22
|
+
const f: CellFormatConfig = { type: 'currency', currency: 'USD', locales: 'en-US' }
|
|
23
|
+
expect(formatValueForExport(19.95, f)).toBe('$19.95')
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('formats a percent from 0..100 points', () => {
|
|
27
|
+
const f: CellFormatConfig = { type: 'percent', valueIsPercentPoints: true, locales: 'en-US' }
|
|
28
|
+
expect(formatValueForExport(42, f)).toBe('42%')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('formats a number with grouping', () => {
|
|
32
|
+
const f: CellFormatConfig = {
|
|
33
|
+
type: 'number',
|
|
34
|
+
locales: 'en-US',
|
|
35
|
+
options: { minimumFractionDigits: 2 },
|
|
36
|
+
}
|
|
37
|
+
expect(formatValueForExport(1234567, f)).toBe('1,234,567.00')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('formats a date with the y-m-d pattern', () => {
|
|
41
|
+
const f: CellFormatConfig = { type: 'date', pattern: 'y-m-d', locales: 'en-US' }
|
|
42
|
+
expect(formatValueForExport(new Date('2026-03-04T00:00:00Z'), f)).toMatch(/2026/)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('falls back to String() when a date value is not parseable', () => {
|
|
46
|
+
const f: CellFormatConfig = { type: 'date' }
|
|
47
|
+
expect(formatValueForExport('not-a-date', f)).toBe('not-a-date')
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('coerceExportDate', () => {
|
|
52
|
+
it('accepts Date, epoch ms, and ISO strings; rejects junk', () => {
|
|
53
|
+
expect(coerceExportDate(new Date('2020-01-01')) instanceof Date).toBe(true)
|
|
54
|
+
expect(coerceExportDate(1_600_000_000_000) instanceof Date).toBe(true)
|
|
55
|
+
expect(coerceExportDate('2021-06-15') instanceof Date).toBe(true)
|
|
56
|
+
expect(coerceExportDate('nope')).toBeNull()
|
|
57
|
+
expect(coerceExportDate(new Date('bad'))).toBeNull()
|
|
58
|
+
expect(coerceExportDate(null)).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('toExcelNumFmt', () => {
|
|
63
|
+
it('maps number/currency/percent/date to Excel codes', () => {
|
|
64
|
+
expect(toExcelNumFmt({ type: 'number' })).toBe('#,##0')
|
|
65
|
+
expect(toExcelNumFmt({ type: 'number', options: { maximumFractionDigits: 2 } })).toBe('#,##0.00')
|
|
66
|
+
expect(toExcelNumFmt({ type: 'currency', currency: 'USD' })).toBe('"$"#,##0.00')
|
|
67
|
+
expect(toExcelNumFmt({ type: 'currency', currency: 'EUR' })).toBe('"€"#,##0.00')
|
|
68
|
+
expect(toExcelNumFmt({ type: 'percent' })).toBe('0.00%')
|
|
69
|
+
expect(toExcelNumFmt({ type: 'date' })).toBe('yyyy-mm-dd')
|
|
70
|
+
expect(toExcelNumFmt({ type: 'datetime' })).toBe('yyyy-mm-dd hh:mm')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('falls back to the ISO code for currencies without a glyph', () => {
|
|
74
|
+
expect(toExcelNumFmt({ type: 'currency', currency: 'CHF' })).toBe('"CHF"#,##0.00')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('returns undefined without a format', () => {
|
|
78
|
+
expect(toExcelNumFmt(undefined)).toBeUndefined()
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('valueForExcel', () => {
|
|
83
|
+
it('keeps numbers/currency numeric', () => {
|
|
84
|
+
expect(valueForExcel(19.95, { type: 'currency' })).toEqual({ ok: true, value: 19.95 })
|
|
85
|
+
expect(valueForExcel(1234, { type: 'number' })).toEqual({ ok: true, value: 1234 })
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('divides percent points to a fraction', () => {
|
|
89
|
+
expect(valueForExcel(42, { type: 'percent', valueIsPercentPoints: true })).toEqual({
|
|
90
|
+
ok: true,
|
|
91
|
+
value: 0.42,
|
|
92
|
+
})
|
|
93
|
+
expect(valueForExcel(0.42, { type: 'percent' })).toEqual({ ok: true, value: 0.42 })
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('returns real Dates for date formats', () => {
|
|
97
|
+
const r = valueForExcel('2026-03-04', { type: 'date' })
|
|
98
|
+
expect(r.ok).toBe(true)
|
|
99
|
+
if (r.ok) expect(r.value).toBeInstanceOf(Date)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('reports not-ok for non-representable values', () => {
|
|
103
|
+
expect(valueForExcel('abc', { type: 'number' })).toEqual({ ok: false })
|
|
104
|
+
expect(valueForExcel(5, undefined)).toEqual({ ok: false })
|
|
105
|
+
expect(valueForExcel(null, { type: 'number' })).toEqual({ ok: false })
|
|
106
|
+
})
|
|
107
|
+
})
|