@leaflink/stash 51.9.2 → 51.10.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/assets/icons/cloud-share.svg +1 -0
- package/assets/spritesheet.svg +1 -1
- package/dist/Accordion.js.map +1 -1
- package/dist/Accordion.vue.d.ts +7 -38
- package/dist/ActionsDropdown.js +2 -2
- package/dist/ActionsDropdown.js.map +1 -1
- package/dist/ActionsDropdown.vue.d.ts +0 -74
- package/dist/AddressSelect.js +56 -60
- package/dist/AddressSelect.js.map +1 -1
- package/dist/AddressSelect.vue.d.ts +8 -65
- package/dist/Alert.js.map +1 -1
- package/dist/Alert.vue.d.ts +4 -41
- package/dist/AppNavigationItem.js.map +1 -1
- package/dist/AppNavigationItem.vue.d.ts +5 -32
- package/dist/AppSidebar.js.map +1 -1
- package/dist/AppSidebar.vue.d.ts +8 -35
- package/dist/AppTopbar.js +1 -1
- package/dist/AppTopbar.js.map +1 -1
- package/dist/AppTopbar.vue.d.ts +4 -33
- package/dist/Avatar.js.map +1 -1
- package/dist/Avatar.vue.d.ts +5 -44
- package/dist/Backdrop.js.map +1 -1
- package/dist/Backdrop.vue.d.ts +1 -1
- package/dist/Badge.js.map +1 -1
- package/dist/Badge.vue.d.ts +6 -55
- package/dist/Box.vue.d.ts +3 -36
- package/dist/Box.vue_vue_type_script_setup_true_lang-rFnvwLVY.js.map +1 -1
- package/dist/Button.js.map +1 -1
- package/dist/Button.vue.d.ts +5 -50
- package/dist/ButtonGroup.js +33 -37
- package/dist/ButtonGroup.js.map +1 -1
- package/dist/ButtonGroup.vue.d.ts +6 -39
- package/dist/Card.js.map +1 -1
- package/dist/Card.vue.d.ts +5 -32
- package/dist/CardContent.js.map +1 -1
- package/dist/CardContent.vue.d.ts +1 -1
- package/dist/CardFooter.js.map +1 -1
- package/dist/CardFooter.vue.d.ts +1 -1
- package/dist/CardHeader.js.map +1 -1
- package/dist/CardHeader.vue.d.ts +2 -15
- package/dist/CardMedia.js.map +1 -1
- package/dist/CardMedia.vue.d.ts +2 -15
- package/dist/Carousel.js +66 -72
- package/dist/Carousel.js.map +1 -1
- package/dist/Carousel.vue.d.ts +10 -10
- package/dist/Checkbox.js.map +1 -1
- package/dist/Checkbox.vue.d.ts +8 -53
- package/dist/ChevronToggle.vue.d.ts +7 -34
- package/dist/ChevronToggle.vue_vue_type_script_setup_true_lang-Ce_qOXfR.js.map +1 -1
- package/dist/Chip.js.map +1 -1
- package/dist/Chip.vue.d.ts +10 -52
- package/dist/ConfirmationCodeInput.js +40 -44
- package/dist/ConfirmationCodeInput.js.map +1 -1
- package/dist/ConfirmationCodeInput.vue.d.ts +8 -43
- package/dist/ContextSwitcher.js.map +1 -1
- package/dist/ContextSwitcher.vue.d.ts +6 -41
- package/dist/Copy.js.map +1 -1
- package/dist/Copy.vue.d.ts +3 -34
- package/dist/CurrencyInput.js +20 -21
- package/dist/CurrencyInput.js.map +1 -1
- package/dist/CurrencyInput.vue.d.ts +125 -46
- package/dist/CustomRender.js.map +1 -1
- package/dist/DataView.js +94 -96
- package/dist/DataView.js.map +1 -1
- package/dist/DataView.keys-aSOnA4AD.js.map +1 -1
- package/dist/DataView.vue.d.ts +15 -57
- package/dist/DataViewFilters.js +127 -139
- package/dist/DataViewFilters.js.map +1 -1
- package/dist/DataViewFilters.keys-BLu07FiP.js.map +1 -1
- package/dist/DataViewFilters.vue.d.ts +9 -54
- package/dist/DataViewSortButton.js +2 -2
- package/dist/DataViewSortButton.js.map +1 -1
- package/dist/DataViewSortButton.vue.d.ts +3 -30
- package/dist/DataViewToolbar.js +70 -62
- package/dist/DataViewToolbar.js.map +1 -1
- package/dist/DataViewToolbar.vue.d.ts +5 -40
- package/dist/DatePicker.js +4524 -4636
- package/dist/DatePicker.js.map +1 -1
- package/dist/DatePicker.vue.d.ts +32 -81
- package/dist/DescriptionList.js.map +1 -1
- package/dist/DescriptionList.vue.d.ts +3 -32
- package/dist/DescriptionListDetail.js.map +1 -1
- package/dist/DescriptionListDetail.vue.d.ts +1 -1
- package/dist/DescriptionListGroup.js.map +1 -1
- package/dist/DescriptionListGroup.vue.d.ts +1 -1
- package/dist/DescriptionListTerm.js.map +1 -1
- package/dist/DescriptionListTerm.vue.d.ts +1 -1
- package/dist/Dialog.js.map +1 -1
- package/dist/Dialog.vue.d.ts +10 -53
- package/dist/Divider.js.map +1 -1
- package/dist/Dropdown.js +89 -95
- package/dist/Dropdown.js.map +1 -1
- package/dist/Dropdown.vue.d.ts +12 -48
- package/dist/EmptyState.js +1 -1
- package/dist/EmptyState.js.map +1 -1
- package/dist/EmptyState.vue.d.ts +5 -62
- package/dist/Expand.vue.d.ts +10 -40
- package/dist/Expand.vue_vue_type_script_setup_true_lang-CiONJfAp.js.map +1 -1
- package/dist/Field.vue.d.ts +4 -53
- package/dist/Field.vue_vue_type_script_setup_true_lang-DI6z3AE9.js.map +1 -1
- package/dist/FileUpload.js +72 -74
- package/dist/FileUpload.js.map +1 -1
- package/dist/FileUpload.vue.d.ts +10 -44
- package/dist/FilterChip.js.map +1 -1
- package/dist/FilterChip.vue.d.ts +6 -41
- package/dist/FilterDrawerItem.js +21 -21
- package/dist/FilterDrawerItem.js.map +1 -1
- package/dist/FilterDrawerItem.vue.d.ts +6 -23
- package/dist/FilterDropdown.js +63 -69
- package/dist/FilterDropdown.js.map +1 -1
- package/dist/FilterDropdown.vue.d.ts +122 -35
- package/dist/FilterSelect.js.map +1 -1
- package/dist/FilterSelect.vue.d.ts +4 -31
- package/dist/Filters.js +157 -164
- package/dist/Filters.js.map +1 -1
- package/dist/Filters.vue.d.ts +0 -2190
- package/dist/HttpError.js +7 -7
- package/dist/HttpError.js.map +1 -1
- package/dist/HttpError.vue.d.ts +4 -41
- package/dist/Icon.js +16 -15
- package/dist/Icon.js.map +1 -1
- package/dist/Icon.vue.d.ts +4 -37
- package/dist/IconLabel.js.map +1 -1
- package/dist/IconLabel.vue.d.ts +6 -41
- package/dist/Illustration.js +2 -2
- package/dist/Illustration.vue.d.ts +3 -42
- package/dist/{Illustration.vue_vue_type_script_setup_true_lang-BrqEF8xe.js → Illustration.vue_vue_type_script_setup_true_lang-BVzzNsRt.js} +11 -11
- package/dist/{Illustration.vue_vue_type_script_setup_true_lang-BrqEF8xe.js.map → Illustration.vue_vue_type_script_setup_true_lang-BVzzNsRt.js.map} +1 -1
- package/dist/Image.js +2 -2
- package/dist/Image.vue.d.ts +5 -40
- package/dist/{Image.vue_vue_type_script_setup_true_lang-D5u4av0_.js → Image.vue_vue_type_script_setup_true_lang-Dg2Zk2r2.js} +37 -41
- package/dist/{Image.vue_vue_type_script_setup_true_lang-D5u4av0_.js.map → Image.vue_vue_type_script_setup_true_lang-Dg2Zk2r2.js.map} +1 -1
- package/dist/InlineEdit.js.map +1 -1
- package/dist/InlineEdit.vue.d.ts +126 -47
- package/dist/Input.js.map +1 -1
- package/dist/Input.vue.d.ts +12 -45
- package/dist/InputOptions.js +66 -69
- package/dist/InputOptions.js.map +1 -1
- package/dist/InputOptions.vue.d.ts +10 -55
- package/dist/IntegrationIcon.js +7 -7
- package/dist/IntegrationIcon.js.map +1 -1
- package/dist/IntegrationIcon.vue.d.ts +3 -36
- package/dist/Label.vue.d.ts +3 -42
- package/dist/Label.vue_vue_type_script_setup_true_lang-CNquF3AP.js.map +1 -1
- package/dist/LicenseChip.js.map +1 -1
- package/dist/LicenseChip.vue.d.ts +3 -30
- package/dist/ListItem.js.map +1 -1
- package/dist/ListItem.vue.d.ts +0 -294
- package/dist/ListItemCell.js.map +1 -1
- package/dist/ListItemCell.vue.d.ts +0 -21
- package/dist/ListView.js +122 -132
- package/dist/ListView.js.map +1 -1
- package/dist/ListView.types.d.ts +0 -29
- package/dist/ListView.vue.d.ts +0 -5496
- package/dist/Loading.js +2 -2
- package/dist/Loading.js.map +1 -1
- package/dist/Loading.vue.d.ts +1 -1
- package/dist/Logo.js +1 -1
- package/dist/Logo.vue.d.ts +6 -41
- package/dist/{Logo.vue_vue_type_script_setup_true_lang-Dz8c98sc.js → Logo.vue_vue_type_script_setup_true_lang-Y3iE9utm.js} +17 -17
- package/dist/Logo.vue_vue_type_script_setup_true_lang-Y3iE9utm.js.map +1 -0
- package/dist/Menu.js.map +1 -1
- package/dist/Menu.vue.d.ts +1 -1
- package/dist/MenuItem.js.map +1 -1
- package/dist/MenuItem.vue.d.ts +1 -1
- package/dist/MenusPlugin-B4jpNe7x.js +12 -0
- package/dist/{MenusPlugin-Bk6UW6o9.js.map → MenusPlugin-B4jpNe7x.js.map} +1 -1
- package/dist/Metric.js.map +1 -1
- package/dist/Metric.vue.d.ts +3 -34
- package/dist/Modal.js +62 -64
- package/dist/Modal.js.map +1 -1
- package/dist/Modal.vue.d.ts +13 -60
- package/dist/Modals.js +17 -18
- package/dist/Modals.js.map +1 -1
- package/dist/ModalsPlugin.js +11 -11
- package/dist/ModalsPlugin.js.map +1 -1
- package/dist/Module.js.map +1 -1
- package/dist/Module.keys-CEsrW2f0.js.map +1 -1
- package/dist/Module.types-B1FfGGac.js.map +1 -1
- package/dist/Module.vue.d.ts +2 -29
- package/dist/ModuleContent.js.map +1 -1
- package/dist/ModuleContent.vue.d.ts +3 -3
- package/dist/ModuleFooter.js.map +1 -1
- package/dist/ModuleFooter.vue.d.ts +1 -1
- package/dist/ModuleHeader.js.map +1 -1
- package/dist/ModuleHeader.vue.d.ts +5 -39
- package/dist/ObfuscateText.js.map +1 -1
- package/dist/ObfuscateText.vue.d.ts +3 -40
- package/dist/PageContent.js.map +1 -1
- package/dist/PageContent.vue.d.ts +3 -30
- package/dist/PageHeader.js.map +1 -1
- package/dist/PageHeader.vue.d.ts +6 -35
- package/dist/PageNavigation.js +50 -50
- package/dist/PageNavigation.js.map +1 -1
- package/dist/PageNavigation.vue.d.ts +7 -36
- package/dist/Paginate.js.map +1 -1
- package/dist/Paginate.vue.d.ts +5 -40
- package/dist/PlaidLink.js.map +1 -1
- package/dist/PlaidLink.vue.d.ts +12 -49
- package/dist/QuickAction.js.map +1 -1
- package/dist/QuickAction.vue.d.ts +3 -16
- package/dist/Radio.js.map +1 -1
- package/dist/Radio.vue.d.ts +0 -93
- package/dist/RadioGroup.js +94 -101
- package/dist/RadioGroup.js.map +1 -1
- package/dist/RadioGroup.vue.d.ts +116 -42
- package/dist/RadioNew.js +96 -99
- package/dist/RadioNew.js.map +1 -1
- package/dist/RadioNew.vue.d.ts +7 -48
- package/dist/RangeInput.js.map +1 -1
- package/dist/RangeInput.vue.d.ts +1 -1
- package/dist/SearchBar.js +38 -39
- package/dist/SearchBar.js.map +1 -1
- package/dist/SearchBar.vue.d.ts +127 -44
- package/dist/SectionHeader.js.map +1 -1
- package/dist/SectionHeader.vue.d.ts +6 -37
- package/dist/Select.js +171 -183
- package/dist/Select.js.map +1 -1
- package/dist/Select.vue.d.ts +23 -102
- package/dist/SelectStatus.js +38 -38
- package/dist/SelectStatus.js.map +1 -1
- package/dist/SelectStatus.vue.d.ts +227 -47
- package/dist/Skeleton.js.map +1 -1
- package/dist/Skeleton.vue.d.ts +3 -34
- package/dist/Step.js +44 -44
- package/dist/Step.js.map +1 -1
- package/dist/Step.vue.d.ts +4 -43
- package/dist/Stepper.js.map +1 -1
- package/dist/Stepper.vue.d.ts +9 -44
- package/dist/Switch.js.map +1 -1
- package/dist/Switch.vue.d.ts +8 -47
- package/dist/Tab.js +1 -1
- package/dist/Tab.js.map +1 -1
- package/dist/Tab.vue.d.ts +2 -15
- package/dist/TabPanel.js.map +1 -1
- package/dist/TabPanel.vue.d.ts +3 -30
- package/dist/Table.js +53 -59
- package/dist/Table.js.map +1 -1
- package/dist/Table.keys-LHQf6FEH.js.map +1 -1
- package/dist/Table.vue.d.ts +3 -50
- package/dist/TableCell.js +1 -1
- package/dist/TableCell.js.map +1 -1
- package/dist/TableCell.vue.d.ts +3 -32
- package/dist/TableHeaderCell.js +1 -1
- package/dist/TableHeaderCell.js.map +1 -1
- package/dist/TableHeaderCell.vue.d.ts +3 -30
- package/dist/TableHeaderRow.js +47 -45
- package/dist/TableHeaderRow.js.map +1 -1
- package/dist/TableHeaderRow.vue.d.ts +5 -34
- package/dist/TableRow.js +60 -61
- package/dist/TableRow.js.map +1 -1
- package/dist/TableRow.vue.d.ts +7 -48
- package/dist/Tabs.js +2 -2
- package/dist/Tabs.vue.d.ts +122 -31
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-Dprx064Y.js +156 -0
- package/dist/{Tabs.vue_vue_type_script_setup_true_lang-CmnBP4i1.js.map → Tabs.vue_vue_type_script_setup_true_lang-Dprx064Y.js.map} +1 -1
- package/dist/TextEditor.js +2414 -2420
- package/dist/TextEditor.js.map +1 -1
- package/dist/TextEditor.vue.d.ts +9 -40
- package/dist/Textarea.js +69 -69
- package/dist/Textarea.js.map +1 -1
- package/dist/Textarea.vue.d.ts +9 -44
- package/dist/Thumbnail.js +1 -1
- package/dist/Thumbnail.js.map +1 -1
- package/dist/Thumbnail.vue.d.ts +4 -4
- package/dist/ThumbnailEmpty.js.map +1 -1
- package/dist/ThumbnailEmpty.vue.d.ts +1 -1
- package/dist/ThumbnailGroup.js.map +1 -1
- package/dist/ThumbnailGroup.keys-EJ4qFNhx.js.map +1 -1
- package/dist/ThumbnailGroup.vue.d.ts +26 -22
- package/dist/Timeline.js.map +1 -1
- package/dist/Timeline.vue.d.ts +3 -32
- package/dist/TimelineItem.js.map +1 -1
- package/dist/TimelineItem.vue.d.ts +1 -1
- package/dist/Toast.js.map +1 -1
- package/dist/Toast.vue.d.ts +3 -30
- package/dist/Toasts.js.map +1 -1
- package/dist/ToastsPlugin.js +11 -11
- package/dist/ToastsPlugin.js.map +1 -1
- package/dist/Tooltip.js +29 -30
- package/dist/Tooltip.js.map +1 -1
- package/dist/Tooltip.vue.d.ts +11 -43
- package/dist/colors-DDDVvqfQ.js.map +1 -1
- package/dist/components.css +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/directives/autofocus.js.map +1 -1
- package/dist/directives/clickoutside.js.map +1 -1
- package/dist/directives/observe.js.map +1 -1
- package/dist/directives/sticky.js.map +1 -1
- package/dist/directives/tooltip.js +3 -3
- package/dist/directives/tooltip.js.map +1 -1
- package/dist/directives/viewable.js +39 -44
- package/dist/directives/viewable.js.map +1 -1
- package/dist/{floating-ui.vue-pzUuloyX.js → floating-ui.vue-CL01Y9ER.js} +2 -2
- package/dist/{floating-ui.vue-pzUuloyX.js.map → floating-ui.vue-CL01Y9ER.js.map} +1 -1
- package/dist/formatDateTime-DG7kBc2T.js +1414 -0
- package/dist/{formatDateTime-Dz8bXV0R.js.map → formatDateTime-DG7kBc2T.js.map} +1 -1
- package/dist/index-D6bxWkZ1.js.map +1 -1
- package/dist/{index-ConQ3o31.js → index-GUu9zvbg.js} +3 -3
- package/dist/{index-ConQ3o31.js.map → index-GUu9zvbg.js.map} +1 -1
- package/dist/index.js +99 -104
- package/dist/index.js.map +1 -1
- package/dist/isDefined-DzVx0B6k.js.map +1 -1
- package/dist/keys-BEdEsanp.js.map +1 -1
- package/dist/keys-C8Zfr_By.js.map +1 -1
- package/dist/locale.js.map +1 -1
- package/dist/misc-CHQs-G03.js.map +1 -1
- package/dist/obfuscateText.d.ts +1 -1
- package/dist/parseISO-wlfIB_QJ.js.map +1 -1
- package/dist/searchFuzzy-DBDE6jkd.js +408 -0
- package/dist/{searchFuzzy-DRasJ33G.js.map → searchFuzzy-DBDE6jkd.js.map} +1 -1
- package/dist/statusLevels-D8EgtE_L.js.map +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/tailwind-base.js +4 -4
- package/dist/tailwind-base.js.map +1 -1
- package/dist/toTimeZone-Coq1oPTt.js.map +1 -1
- package/dist/useConfirmBeforeClosing.js.map +1 -1
- package/dist/useDialog.d.ts +2 -2
- package/dist/useDialog.js +21 -25
- package/dist/useDialog.js.map +1 -1
- package/dist/useGoogleMaps.js +108 -110
- package/dist/useGoogleMaps.js.map +1 -1
- package/dist/useMediaQuery.d.ts +0 -6
- package/dist/useMediaQuery.js +11 -15
- package/dist/useMediaQuery.js.map +1 -1
- package/dist/useModals.d.ts +1 -1
- package/dist/useModals.js.map +1 -1
- package/dist/usePaginationStats-d_q39naC.js.map +1 -1
- package/dist/usePlaidLink.js +20 -27
- package/dist/usePlaidLink.js.map +1 -1
- package/dist/useScriptTag.js.map +1 -1
- package/dist/useSearch.js +13 -13
- package/dist/useSearch.js.map +1 -1
- package/dist/useSelection.js +56 -56
- package/dist/useSelection.js.map +1 -1
- package/dist/useSortable.js +54 -63
- package/dist/useSortable.js.map +1 -1
- package/dist/useStepper.d.ts +2 -2
- package/dist/useStepper.js +36 -40
- package/dist/useStepper.js.map +1 -1
- package/dist/useToasts.js +23 -23
- package/dist/useToasts.js.map +1 -1
- package/dist/useValidation.js +96 -100
- package/dist/useValidation.js.map +1 -1
- package/dist/utils/calculateElementOverflow.js +4 -4
- package/dist/utils/calculateElementOverflow.js.map +1 -1
- package/dist/utils/colorScheme.js +2 -2
- package/dist/utils/colorScheme.js.map +1 -1
- package/dist/utils/createQueryString.js.map +1 -1
- package/dist/utils/createValidDate.js.map +1 -1
- package/dist/utils/formatDateTime.js +1 -1
- package/dist/utils/getContrastingTextColor.js.map +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/i18n.js.map +1 -1
- package/dist/utils/normalizeDate.js.map +1 -1
- package/dist/utils/obfuscateText.js +6 -6
- package/dist/utils/obfuscateText.js.map +1 -1
- package/dist/utils/searchFuzzy.js +1 -1
- package/dist/utils/storage.js +23 -23
- package/dist/utils/storage.js.map +1 -1
- package/package.json +13 -14
- package/tailwind-base.ts +4 -4
- package/types/vite.d.ts +7 -0
- package/types/vitest.d.ts +7 -0
- package/dist/Logo.vue_vue_type_script_setup_true_lang-Dz8c98sc.js.map +0 -1
- package/dist/MenusPlugin-Bk6UW6o9.js +0 -12
- package/dist/Tabs.vue_vue_type_script_setup_true_lang-CmnBP4i1.js +0 -159
- package/dist/formatDateTime-Dz8bXV0R.js +0 -1418
- package/dist/searchFuzzy-DRasJ33G.js +0 -409
package/dist/useSortable.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { u as
|
|
3
|
-
import { isRef as
|
|
4
|
-
function
|
|
5
|
-
if (
|
|
6
|
-
const r =
|
|
1
|
+
import d from "@leaflink/snitch";
|
|
2
|
+
import { u as C } from "./index-GUu9zvbg.js";
|
|
3
|
+
import { isRef as I, toValue as D, nextTick as w, computed as i, ref as y, watch as A, onMounted as S, onBeforeUnmount as $ } from "vue";
|
|
4
|
+
function G({ list: o, from: l, to: e }) {
|
|
5
|
+
if (l === e) return;
|
|
6
|
+
const r = I(o), a = r ? [...D(o)] : D(o);
|
|
7
7
|
if (e >= 0 && e < a.length) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
a.splice(e, 0,
|
|
8
|
+
const s = a.splice(l, 1)[0];
|
|
9
|
+
w(() => {
|
|
10
|
+
a.splice(e, 0, s), r && (o.value = a);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
e.classList.add(...s), e.style.position = "absolute", e.style.top = "-9999px", e.style.listStyle = "none", e.setAttribute("data-test", `${e.dataset.test}|ghost`), e.removeAttribute("draggable"), document.body.appendChild(e), (a = n.dataTransfer) == null || a.setDragImage(e, e.offsetWidth / 2, e.offsetHeight / 2);
|
|
14
|
+
function O(o, l) {
|
|
15
|
+
const e = v(o.target).cloneNode(!0);
|
|
16
|
+
e.classList.add(...l), e.style.position = "absolute", e.style.top = "-9999px", e.style.listStyle = "none", e.setAttribute("data-test", `${e.dataset.test}|ghost`), e.removeAttribute("draggable"), document.body.appendChild(e), o.dataTransfer?.setDragImage(e, e.offsetWidth / 2, e.offsetHeight / 2);
|
|
18
17
|
function r() {
|
|
19
18
|
requestAnimationFrame(() => {
|
|
20
19
|
document.body.removeChild(e);
|
|
@@ -25,45 +24,38 @@ function B(n, s) {
|
|
|
25
24
|
cleanupGhostElement: r
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
31
|
-
return
|
|
27
|
+
function v(o) {
|
|
28
|
+
const l = o?.closest("[draggable=true]");
|
|
29
|
+
if (!l) throw new Error("Draggable element not found");
|
|
30
|
+
return l;
|
|
32
31
|
}
|
|
33
|
-
function
|
|
34
|
-
isEnabled:
|
|
35
|
-
sortInPlace:
|
|
32
|
+
function k({
|
|
33
|
+
isEnabled: o = !0,
|
|
34
|
+
sortInPlace: l = !0,
|
|
36
35
|
...e
|
|
37
36
|
}) {
|
|
38
|
-
const r = i(() =>
|
|
39
|
-
var t;
|
|
40
|
-
return ((t = e.ghostClass) == null ? void 0 : t.split(" ")) || [];
|
|
41
|
-
}), f = i(() => {
|
|
42
|
-
var t;
|
|
43
|
-
return ((t = e.chosenClass) == null ? void 0 : t.split(" ")) || [];
|
|
44
|
-
}), g = (t) => {
|
|
45
|
-
var l;
|
|
37
|
+
const r = i(() => C(e.ref)), a = y(-1), s = y(-1), b = i(() => a.value !== -1), T = i(() => e.ghostClass?.split(" ") || []), f = i(() => e.chosenClass?.split(" ") || []), g = (t) => {
|
|
46
38
|
if (!(!t.dataTransfer || !r.value)) {
|
|
47
39
|
t.dataTransfer.setData("text/plain", ""), t.dataTransfer.effectAllowed = "move";
|
|
48
40
|
try {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
const { cleanupGhostElement:
|
|
52
|
-
|
|
53
|
-
} catch (
|
|
54
|
-
|
|
41
|
+
const n = v(t.target), u = Array.from(r.value.children).indexOf(n);
|
|
42
|
+
if (u === -1) return;
|
|
43
|
+
const { cleanupGhostElement: c } = O(t, T.value);
|
|
44
|
+
s.value = a.value = u, n.classList.add(...f.value), c(), e.onDragStart?.({ ...t, oldIndex: u });
|
|
45
|
+
} catch (n) {
|
|
46
|
+
d.error(`Error in drag start: ${n}`);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
}, m = (t) => {
|
|
58
50
|
if (!(!t.dataTransfer || !r.value)) {
|
|
59
51
|
t.dataTransfer.dropEffect = "move";
|
|
60
52
|
try {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
64
|
-
r.value.insertBefore(
|
|
65
|
-
} catch (
|
|
66
|
-
|
|
53
|
+
const n = v(t.target), u = Array.from(r.value.children).indexOf(n);
|
|
54
|
+
if (u === -1 || u === a.value) return;
|
|
55
|
+
const c = r.value.children[a.value];
|
|
56
|
+
r.value.insertBefore(c, u < a.value ? n : n.nextSibling), a.value = u;
|
|
57
|
+
} catch (n) {
|
|
58
|
+
d.error(`Error in drag enter: ${n}`);
|
|
67
59
|
}
|
|
68
60
|
}
|
|
69
61
|
};
|
|
@@ -73,44 +65,43 @@ function q({
|
|
|
73
65
|
function E(t) {
|
|
74
66
|
if (t.preventDefault(), !!r.value)
|
|
75
67
|
try {
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
} catch (
|
|
79
|
-
|
|
68
|
+
if (s.value === a.value || !l) return;
|
|
69
|
+
G({ list: e.list, from: s.value, to: a.value });
|
|
70
|
+
} catch (n) {
|
|
71
|
+
d.error(`Error in drag drop: ${n}`);
|
|
80
72
|
}
|
|
81
73
|
}
|
|
82
|
-
function
|
|
83
|
-
var l;
|
|
74
|
+
function p(t) {
|
|
84
75
|
try {
|
|
85
|
-
|
|
76
|
+
v(t.target).classList.remove(...f.value), e.onDragEnd?.({
|
|
86
77
|
...t,
|
|
87
|
-
oldIndex:
|
|
78
|
+
oldIndex: s.value,
|
|
88
79
|
newIndex: a.value
|
|
89
|
-
}),
|
|
90
|
-
} catch (
|
|
91
|
-
|
|
80
|
+
}), s.value = a.value = -1;
|
|
81
|
+
} catch (n) {
|
|
82
|
+
d.error(`Error in drag end: ${n}`);
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
|
-
|
|
95
|
-
() =>
|
|
96
|
-
() =>
|
|
85
|
+
A(
|
|
86
|
+
() => o,
|
|
87
|
+
() => o ? L() : x()
|
|
97
88
|
);
|
|
98
|
-
function
|
|
99
|
-
r.value && (r.value.addEventListener("dragstart", g), r.value.addEventListener("dragend",
|
|
89
|
+
function L() {
|
|
90
|
+
r.value && (r.value.addEventListener("dragstart", g), r.value.addEventListener("dragend", p), r.value.addEventListener("dragenter", m), r.value.addEventListener("dragover", h), r.value.addEventListener("drop", E));
|
|
100
91
|
}
|
|
101
92
|
function x() {
|
|
102
|
-
r.value && (r.value.removeEventListener("dragstart", g), r.value.removeEventListener("dragend",
|
|
93
|
+
r.value && (r.value.removeEventListener("dragstart", g), r.value.removeEventListener("dragend", p), r.value.removeEventListener("dragenter", m), r.value.removeEventListener("dragover", h), r.value.removeEventListener("drop", E));
|
|
103
94
|
}
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
}),
|
|
95
|
+
return S(() => {
|
|
96
|
+
o && L();
|
|
97
|
+
}), $(x), {
|
|
107
98
|
isDragging: b,
|
|
108
|
-
oldIndex:
|
|
99
|
+
oldIndex: s,
|
|
109
100
|
newIndex: a
|
|
110
101
|
};
|
|
111
102
|
}
|
|
112
103
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
k as default,
|
|
105
|
+
G as moveSortableElements
|
|
115
106
|
};
|
|
116
107
|
//# sourceMappingURL=useSortable.js.map
|
package/dist/useSortable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortable.js","sources":["../src/composables/useSortable/useSortable.utils.ts","../src/composables/useSortable/useSortable.ts"],"sourcesContent":["import { isRef, nextTick, Ref, toValue } from 'vue';\n\nimport { MoveSortableElementsOptions } from './useSortable.types';\n\n/**\n * Move sortable elements in the list\n * @param list List of sortable elements\n * @param from Original element position\n * @param to New element position\n */\nexport function moveSortableElements<ListItem>({ list, from, to }: MoveSortableElementsOptions<ListItem>): void {\n if (from === to) return;\n\n const _listIsRef = isRef(list);\n // When the list is a ref, make a shallow copy of it to avoid repeatedly triggering side effects when moving elements\n const listCopy = _listIsRef ? [...toValue(list)] : toValue(list);\n\n if (to >= 0 && to < listCopy.length) {\n const element = listCopy.splice(from, 1)[0];\n nextTick(() => {\n listCopy.splice(to, 0, element);\n // When list is ref, assign listCopy to list.value\n if (_listIsRef) (list as Ref).value = listCopy;\n });\n }\n}\n\n/**\n * Create a ghost element for dragging, which is the element that follows the cursor while dragging\n * @param e Drag event\n * @param ghostClass Custom classes to be added to the ghost element\n * @returns Ghost element and cleanup function\n */\nexport function createGhostElement(e: DragEvent, ghostClass: string[]) {\n const ghost = getValidDragTarget(e.target as HTMLElement).cloneNode(true) as HTMLElement;\n\n ghost.classList.add(...ghostClass);\n\n ghost.style.position = 'absolute';\n ghost.style.top = '-9999px';\n ghost.style.listStyle = 'none';\n ghost.setAttribute('data-test', `${ghost.dataset.test}|ghost`);\n ghost.removeAttribute('draggable');\n\n document.body.appendChild(ghost);\n\n e.dataTransfer?.setDragImage(ghost, ghost.offsetWidth / 2, ghost.offsetHeight / 2);\n\n function cleanupGhostElement() {\n requestAnimationFrame(() => {\n document.body.removeChild(ghost);\n });\n }\n\n return {\n ghost,\n cleanupGhostElement,\n };\n}\n\n/**\n * Get the valid draggable target element\n * @param element\n * @returns Draggable element\n */\nexport function getValidDragTarget(element: HTMLElement | null) {\n const dragElement = element?.closest<HTMLElement>('[draggable=true]');\n if (!dragElement) throw new Error('Draggable element not found');\n return dragElement;\n}\n","import logger from '@leaflink/snitch';\nimport { unrefElement } from '@vueuse/core';\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n\nimport type { UseSortableOptions, UseSortableReturn } from './useSortable.types';\nimport { createGhostElement, getValidDragTarget, moveSortableElements } from './useSortable.utils';\n\nexport * from './useSortable.types';\nexport { moveSortableElements } from './useSortable.utils';\n\nexport default function useSortable<SortableItem>({\n isEnabled = true,\n sortInPlace = true,\n ...options\n}: UseSortableOptions<SortableItem>): UseSortableReturn {\n const parentEl = computed(() => unrefElement(options.ref));\n\n const newIndex = ref(-1);\n const oldIndex = ref(-1);\n\n const isDragging = computed(() => newIndex.value !== -1);\n\n const ghostClasses = computed(() => options.ghostClass?.split(' ') || []);\n const chosenClasses = computed(() => options.chosenClass?.split(' ') || []);\n\n const handleDragStart = (e: DragEvent) => {\n if (!e.dataTransfer || !parentEl.value) return;\n e.dataTransfer.setData('text/plain', ''); // Required for Firefox\n e.dataTransfer.effectAllowed = 'move';\n\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n const index = Array.from(parentEl.value.children).indexOf(target);\n if (index === -1) return;\n\n const { cleanupGhostElement } = createGhostElement(e, ghostClasses.value);\n\n oldIndex.value = newIndex.value = index;\n\n target.classList.add(...chosenClasses.value);\n\n cleanupGhostElement();\n\n options.onDragStart?.({ ...e, oldIndex: index });\n } catch (error) {\n logger.error(`Error in drag start: ${error}`);\n }\n };\n\n const handleDragEnter = (e: DragEvent) => {\n if (!e.dataTransfer || !parentEl.value) return;\n e.dataTransfer.dropEffect = 'move';\n\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n const index = Array.from(parentEl.value.children).indexOf(target);\n if (index === -1 || index === newIndex.value) return;\n\n const draggedEl = parentEl.value.children[newIndex.value];\n parentEl.value.insertBefore(draggedEl, index < newIndex.value ? target : target.nextSibling);\n\n newIndex.value = index;\n } catch (error) {\n logger.error(`Error in drag enter: ${error}`);\n }\n };\n\n function handleDragOver(e: DragEvent) {\n e.preventDefault(); // Required to allow dropping\n }\n\n function handleDrop(e: DragEvent) {\n e.preventDefault();\n\n if (!parentEl.value) return;\n\n try {\n if (oldIndex.value === newIndex.value || !sortInPlace) return;\n moveSortableElements({ list: options.list, from: oldIndex.value, to: newIndex.value });\n } catch (error) {\n logger.error(`Error in drag drop: ${error}`);\n }\n }\n\n function handleDragEnd(e: DragEvent) {\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n target.classList.remove(...chosenClasses.value);\n\n options.onDragEnd?.({\n ...e,\n oldIndex: oldIndex.value,\n newIndex: newIndex.value,\n });\n\n oldIndex.value = newIndex.value = -1;\n } catch (error) {\n logger.error(`Error in drag end: ${error}`);\n }\n }\n\n watch(\n () => isEnabled,\n () => (isEnabled ? setupListeners() : removeListeners()),\n );\n\n function setupListeners() {\n if (!parentEl.value) return;\n\n parentEl.value.addEventListener('dragstart', handleDragStart);\n parentEl.value.addEventListener('dragend', handleDragEnd);\n parentEl.value.addEventListener('dragenter', handleDragEnter);\n parentEl.value.addEventListener('dragover', handleDragOver);\n parentEl.value.addEventListener('drop', handleDrop);\n }\n\n function removeListeners() {\n if (!parentEl.value) return;\n\n parentEl.value.removeEventListener('dragstart', handleDragStart);\n parentEl.value.removeEventListener('dragend', handleDragEnd);\n parentEl.value.removeEventListener('dragenter', handleDragEnter);\n parentEl.value.removeEventListener('dragover', handleDragOver);\n parentEl.value.removeEventListener('drop', handleDrop);\n }\n\n onMounted(() => {\n if (!isEnabled) return;\n setupListeners();\n });\n\n onBeforeUnmount(removeListeners);\n\n return {\n isDragging,\n oldIndex,\n newIndex,\n };\n}\n"],"names":["moveSortableElements","list","from","to","_listIsRef","isRef","listCopy","toValue","element","nextTick","createGhostElement","e","ghostClass","ghost","getValidDragTarget","_a","cleanupGhostElement","dragElement","useSortable","isEnabled","sortInPlace","options","parentEl","computed","unrefElement","newIndex","ref","oldIndex","isDragging","ghostClasses","chosenClasses","handleDragStart","target","index","error","logger","handleDragEnter","draggedEl","handleDragOver","handleDrop","handleDragEnd","watch","setupListeners","removeListeners","onMounted","onBeforeUnmount"],"mappings":";;;AAUO,SAASA,EAA+B,EAAE,MAAAC,GAAM,MAAAC,GAAM,IAAAC,KAAmD;AAC9G,MAAID,MAASC,EAAI;AAEX,QAAAC,IAAaC,EAAMJ,CAAI,GAEvBK,IAAWF,IAAa,CAAC,GAAGG,EAAQN,CAAI,CAAC,IAAIM,EAAQN,CAAI;AAE/D,MAAIE,KAAM,KAAKA,IAAKG,EAAS,QAAQ;AACnC,UAAME,IAAUF,EAAS,OAAOJ,GAAM,CAAC,EAAE,CAAC;AAC1C,IAAAO,EAAS,MAAM;AACJ,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WAAWkB,CAAa,GAClDlB,EAAA,MAAM,oBAAoB,aAAac,CAAe,GACtDd,EAAA,MAAM,oBAAoB,YAAYgB,CAAc,GACpDhB,EAAA,MAAM,oBAAoB,QAAQiB,CAAU;AAAA,EAAA;AAGvD,SAAAK,EAAU,MAAM;AACd,IAAKzB,KACUuB,EAAA;AAAA,EAAA,CAChB,GAEDG,EAAgBF,CAAe,GAExB;AAAA,IACL,YAAAf;AAAA,IACA,UAAAD;AAAA,IACA,UAAAF;AAAA,EACF;AACF;"}
|
|
1
|
+
{"version":3,"file":"useSortable.js","sources":["../src/composables/useSortable/useSortable.utils.ts","../src/composables/useSortable/useSortable.ts"],"sourcesContent":["import { isRef, nextTick, Ref, toValue } from 'vue';\n\nimport { MoveSortableElementsOptions } from './useSortable.types';\n\n/**\n * Move sortable elements in the list\n * @param list List of sortable elements\n * @param from Original element position\n * @param to New element position\n */\nexport function moveSortableElements<ListItem>({ list, from, to }: MoveSortableElementsOptions<ListItem>): void {\n if (from === to) return;\n\n const _listIsRef = isRef(list);\n // When the list is a ref, make a shallow copy of it to avoid repeatedly triggering side effects when moving elements\n const listCopy = _listIsRef ? [...toValue(list)] : toValue(list);\n\n if (to >= 0 && to < listCopy.length) {\n const element = listCopy.splice(from, 1)[0];\n nextTick(() => {\n listCopy.splice(to, 0, element);\n // When list is ref, assign listCopy to list.value\n if (_listIsRef) (list as Ref).value = listCopy;\n });\n }\n}\n\n/**\n * Create a ghost element for dragging, which is the element that follows the cursor while dragging\n * @param e Drag event\n * @param ghostClass Custom classes to be added to the ghost element\n * @returns Ghost element and cleanup function\n */\nexport function createGhostElement(e: DragEvent, ghostClass: string[]) {\n const ghost = getValidDragTarget(e.target as HTMLElement).cloneNode(true) as HTMLElement;\n\n ghost.classList.add(...ghostClass);\n\n ghost.style.position = 'absolute';\n ghost.style.top = '-9999px';\n ghost.style.listStyle = 'none';\n ghost.setAttribute('data-test', `${ghost.dataset.test}|ghost`);\n ghost.removeAttribute('draggable');\n\n document.body.appendChild(ghost);\n\n e.dataTransfer?.setDragImage(ghost, ghost.offsetWidth / 2, ghost.offsetHeight / 2);\n\n function cleanupGhostElement() {\n requestAnimationFrame(() => {\n document.body.removeChild(ghost);\n });\n }\n\n return {\n ghost,\n cleanupGhostElement,\n };\n}\n\n/**\n * Get the valid draggable target element\n * @param element\n * @returns Draggable element\n */\nexport function getValidDragTarget(element: HTMLElement | null) {\n const dragElement = element?.closest<HTMLElement>('[draggable=true]');\n if (!dragElement) throw new Error('Draggable element not found');\n return dragElement;\n}\n","import logger from '@leaflink/snitch';\nimport { unrefElement } from '@vueuse/core';\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';\n\nimport type { UseSortableOptions, UseSortableReturn } from './useSortable.types';\nimport { createGhostElement, getValidDragTarget, moveSortableElements } from './useSortable.utils';\n\nexport * from './useSortable.types';\nexport { moveSortableElements } from './useSortable.utils';\n\nexport default function useSortable<SortableItem>({\n isEnabled = true,\n sortInPlace = true,\n ...options\n}: UseSortableOptions<SortableItem>): UseSortableReturn {\n const parentEl = computed(() => unrefElement(options.ref));\n\n const newIndex = ref(-1);\n const oldIndex = ref(-1);\n\n const isDragging = computed(() => newIndex.value !== -1);\n\n const ghostClasses = computed(() => options.ghostClass?.split(' ') || []);\n const chosenClasses = computed(() => options.chosenClass?.split(' ') || []);\n\n const handleDragStart = (e: DragEvent) => {\n if (!e.dataTransfer || !parentEl.value) return;\n e.dataTransfer.setData('text/plain', ''); // Required for Firefox\n e.dataTransfer.effectAllowed = 'move';\n\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n const index = Array.from(parentEl.value.children).indexOf(target);\n if (index === -1) return;\n\n const { cleanupGhostElement } = createGhostElement(e, ghostClasses.value);\n\n oldIndex.value = newIndex.value = index;\n\n target.classList.add(...chosenClasses.value);\n\n cleanupGhostElement();\n\n options.onDragStart?.({ ...e, oldIndex: index });\n } catch (error) {\n logger.error(`Error in drag start: ${error}`);\n }\n };\n\n const handleDragEnter = (e: DragEvent) => {\n if (!e.dataTransfer || !parentEl.value) return;\n e.dataTransfer.dropEffect = 'move';\n\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n const index = Array.from(parentEl.value.children).indexOf(target);\n if (index === -1 || index === newIndex.value) return;\n\n const draggedEl = parentEl.value.children[newIndex.value];\n parentEl.value.insertBefore(draggedEl, index < newIndex.value ? target : target.nextSibling);\n\n newIndex.value = index;\n } catch (error) {\n logger.error(`Error in drag enter: ${error}`);\n }\n };\n\n function handleDragOver(e: DragEvent) {\n e.preventDefault(); // Required to allow dropping\n }\n\n function handleDrop(e: DragEvent) {\n e.preventDefault();\n\n if (!parentEl.value) return;\n\n try {\n if (oldIndex.value === newIndex.value || !sortInPlace) return;\n moveSortableElements({ list: options.list, from: oldIndex.value, to: newIndex.value });\n } catch (error) {\n logger.error(`Error in drag drop: ${error}`);\n }\n }\n\n function handleDragEnd(e: DragEvent) {\n try {\n const target = getValidDragTarget(e.target as HTMLElement);\n\n target.classList.remove(...chosenClasses.value);\n\n options.onDragEnd?.({\n ...e,\n oldIndex: oldIndex.value,\n newIndex: newIndex.value,\n });\n\n oldIndex.value = newIndex.value = -1;\n } catch (error) {\n logger.error(`Error in drag end: ${error}`);\n }\n }\n\n watch(\n () => isEnabled,\n () => (isEnabled ? setupListeners() : removeListeners()),\n );\n\n function setupListeners() {\n if (!parentEl.value) return;\n\n parentEl.value.addEventListener('dragstart', handleDragStart);\n parentEl.value.addEventListener('dragend', handleDragEnd);\n parentEl.value.addEventListener('dragenter', handleDragEnter);\n parentEl.value.addEventListener('dragover', handleDragOver);\n parentEl.value.addEventListener('drop', handleDrop);\n }\n\n function removeListeners() {\n if (!parentEl.value) return;\n\n parentEl.value.removeEventListener('dragstart', handleDragStart);\n parentEl.value.removeEventListener('dragend', handleDragEnd);\n parentEl.value.removeEventListener('dragenter', handleDragEnter);\n parentEl.value.removeEventListener('dragover', handleDragOver);\n parentEl.value.removeEventListener('drop', handleDrop);\n }\n\n onMounted(() => {\n if (!isEnabled) return;\n setupListeners();\n });\n\n onBeforeUnmount(removeListeners);\n\n return {\n isDragging,\n oldIndex,\n newIndex,\n };\n}\n"],"names":["moveSortableElements","list","from","to","_listIsRef","isRef","listCopy","toValue","element","nextTick","createGhostElement","e","ghostClass","ghost","getValidDragTarget","cleanupGhostElement","dragElement","useSortable","isEnabled","sortInPlace","options","parentEl","computed","unrefElement","newIndex","ref","oldIndex","isDragging","ghostClasses","chosenClasses","handleDragStart","target","index","error","logger","handleDragEnter","draggedEl","handleDragOver","handleDrop","handleDragEnd","watch","setupListeners","removeListeners","onMounted","onBeforeUnmount"],"mappings":";;;AAUO,SAASA,EAA+B,EAAE,MAAAC,GAAM,MAAAC,GAAM,IAAAC,KAAmD;AAC9G,MAAID,MAASC,EAAI;AAEjB,QAAMC,IAAaC,EAAMJ,CAAI,GAEvBK,IAAWF,IAAa,CAAC,GAAGG,EAAQN,CAAI,CAAC,IAAIM,EAAQN,CAAI;AAE/D,MAAIE,KAAM,KAAKA,IAAKG,EAAS,QAAQ;AACnC,UAAME,IAAUF,EAAS,OAAOJ,GAAM,CAAC,EAAE,CAAC;AAC1C,IAAAO,EAAS,MAAM;AACb,MAAAH,EAAS,OAAOH,GAAI,GAAGK,CAAO,GAE1BJ,MAAaH,EAAa,QAAQK;AAAA,IACxC,CAAC;AAAA,EACH;AACF;AAQO,SAASI,EAAmBC,GAAcC,GAAsB;AACrE,QAAMC,IAAQC,EAAmBH,EAAE,MAAqB,EAAE,UAAU,EAAI;AAExE,EAAAE,EAAM,UAAU,IAAI,GAAGD,CAAU,GAEjCC,EAAM,MAAM,WAAW,YACvBA,EAAM,MAAM,MAAM,WAClBA,EAAM,MAAM,YAAY,QACxBA,EAAM,aAAa,aAAa,GAAGA,EAAM,QAAQ,IAAI,QAAQ,GAC7DA,EAAM,gBAAgB,WAAW,GAEjC,SAAS,KAAK,YAAYA,CAAK,GAE/BF,EAAE,cAAc,aAAaE,GAAOA,EAAM,cAAc,GAAGA,EAAM,e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AAS;AAAA,MAAA,CACpB,GAEDE,EAAS,QAAQF,EAAS,QAAQ;AAAA,IACpC,SAASS,GAAO;AACd,MAAAC,EAAO,MAAM,sBAAsBD,CAAK,EAAE;AAAA,IAC5C;AAAA,EACF;AAEA,EAAAO;AAAA,IACE,MAAMtB;AAAA,IACN,MAAOA,IAAYuB,EAAA,IAAmBC,EAAA;AAAA,EAAgB;AAGxD,WAASD,IAAiB;AACxB,IAAKpB,EAAS,UAEdA,EAAS,MAAM,iBAAiB,aAAaS,CAAe,GAC5DT,EAAS,MAAM,iBAAiB,WAAWkB,CAAa,GACxDlB,EAAS,MAAM,iBAAiB,aAAac,CAAe,GAC5Dd,EAAS,MAAM,iBAAiB,YAAYgB,CAAc,GAC1DhB,EAAS,MAAM,iBAAiB,QAAQiB,CAAU;AAAA,EACpD;AAEA,WAASI,IAAkB;AACzB,IAAKrB,EAAS,UAEdA,EAAS,MAAM,oBAAoB,aAAaS,CAAe,GAC/DT,EAAS,MAAM,oBAAoB,WAAWkB,CAAa,GAC3DlB,EAAS,MAAM,oBAAoB,aAAac,CAAe,GAC/Dd,EAAS,MAAM,oBAAoB,YAAYgB,CAAc,GAC7DhB,EAAS,MAAM,oBAAoB,QAAQiB,CAAU;AAAA,EACvD;AAEA,SAAAK,EAAU,MAAM;AACd,IAAKzB,KACLuB,EAAA;AAAA,EACF,CAAC,GAEDG,EAAgBF,CAAe,GAExB;AAAA,IACL,YAAAf;AAAA,IACA,UAAAD;AAAA,IACA,UAAAF;AAAA,EAAA;AAEJ;"}
|
package/dist/useStepper.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
2
|
import { Ref } from 'vue';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
declare interface StepDefinition {
|
|
5
5
|
completed: boolean;
|
|
6
6
|
substeps: Array<Omit<StepDefinition, 'substeps'>>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
declare interface StepperOptions {
|
|
10
10
|
/**
|
|
11
11
|
* If true, the stepper will prevent skipping steps
|
|
12
12
|
*/
|
package/dist/useStepper.js
CHANGED
|
@@ -1,70 +1,66 @@
|
|
|
1
|
-
import { ref as f, computed as p, readonly as
|
|
2
|
-
function
|
|
1
|
+
import { ref as f, computed as p, readonly as A } from "vue";
|
|
2
|
+
function C(v = {
|
|
3
3
|
linear: !1,
|
|
4
4
|
activeStep: -1,
|
|
5
5
|
activeSubstep: -1,
|
|
6
6
|
steps: []
|
|
7
7
|
}) {
|
|
8
|
-
const
|
|
8
|
+
const u = f(v.steps ? v.steps : []), n = p(() => u.value.length), e = f(
|
|
9
9
|
v.activeStep !== null && v.activeStep !== void 0 ? v.activeStep : -1
|
|
10
10
|
), l = f(
|
|
11
11
|
v.activeSubstep !== null && v.activeSubstep !== void 0 ? v.activeSubstep : -1
|
|
12
|
-
), S = p(() =>
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}), m = p(() => S.value[e.value]);
|
|
16
|
-
function s(u) {
|
|
17
|
-
return !!a.value[u].substeps.length;
|
|
12
|
+
), o = p(() => Array.from(v.ref?.value?.children || [])), S = p(() => o.value[e.value]);
|
|
13
|
+
function s(a) {
|
|
14
|
+
return !!u.value[a].substeps.length;
|
|
18
15
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
16
|
+
function m() {
|
|
17
|
+
const a = e.value === -1, t = e.value === u.value.length - 1;
|
|
18
|
+
if (a)
|
|
22
19
|
e.value++, s(e.value) && l.value++;
|
|
23
20
|
else if (t)
|
|
24
21
|
if (s(e.value)) {
|
|
25
|
-
const
|
|
26
|
-
|
|
22
|
+
const c = l.value === -1, r = l.value === u.value[e.value].substeps.length - 1;
|
|
23
|
+
c ? l.value++ : r ? (u.value[e.value].substeps[l.value].completed = !0, l.value = -1, u.value[e.value].completed = !0, e.value = -1) : (u.value[e.value].substeps[l.value].completed = !0, l.value++);
|
|
27
24
|
} else
|
|
28
|
-
|
|
25
|
+
u.value[e.value].completed = !0, e.value = -1;
|
|
29
26
|
else if (s(e.value)) {
|
|
30
|
-
const
|
|
31
|
-
|
|
27
|
+
const c = l.value === -1, r = l.value === u.value[e.value].substeps.length - 1;
|
|
28
|
+
c ? l.value++ : r ? (u.value[e.value].substeps[l.value].completed = !0, l.value = -1, u.value[e.value].completed = !0, e.value++, s(e.value) && l.value === -1 && l.value++) : (u.value[e.value].substeps[l.value].completed = !0, l.value++);
|
|
32
29
|
} else
|
|
33
|
-
|
|
30
|
+
u.value[e.value].completed = !0, e.value++, s(e.value) && l.value === -1 && l.value++;
|
|
34
31
|
}
|
|
35
|
-
function
|
|
36
|
-
e.value !== -1 && (s(e.value) ? l.value === 0 ? (e.value--, l.value--, e.value >= 0 && s(e.value) && (l.value =
|
|
32
|
+
function b() {
|
|
33
|
+
e.value !== -1 && (s(e.value) ? l.value === 0 ? (e.value--, l.value--, e.value >= 0 && s(e.value) && (l.value = u.value[e.value].substeps.length - 1)) : l.value-- : (e.value--, e.value >= 0 && s(e.value) && (l.value = u.value[e.value].substeps.length - 1)));
|
|
37
34
|
}
|
|
38
|
-
function
|
|
39
|
-
v.linear ? (
|
|
35
|
+
function h(a, t = -1) {
|
|
36
|
+
v.linear ? (i(a - 1) || a === 0) && (s(a) && (t <= 0 ? l.value = 0 : i(a, t - 1) && (l.value = t)), e.value = a) : (e.value = a, s(a) && (t < 0 ? l.value = 0 : l.value = t));
|
|
40
37
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
return t >= 0 ? (c = (i = a.value[u]) == null ? void 0 : i.substeps[t]) == null ? void 0 : c.completed : (n = a.value[u]) == null ? void 0 : n.completed;
|
|
38
|
+
function i(a, t = -1) {
|
|
39
|
+
return t >= 0 ? u.value[a]?.substeps[t]?.completed : u.value[a]?.completed;
|
|
44
40
|
}
|
|
45
|
-
function
|
|
46
|
-
return t >= 0 ? e.value ===
|
|
41
|
+
function g(a, t = -1) {
|
|
42
|
+
return t >= 0 ? e.value === a && l.value === t : e.value === a;
|
|
47
43
|
}
|
|
48
|
-
function
|
|
49
|
-
if (
|
|
44
|
+
function d(a = !1) {
|
|
45
|
+
if (a && !u.value.length)
|
|
50
46
|
throw new Error("Cannot register a substep without a parent step.");
|
|
51
|
-
|
|
47
|
+
a ? u.value[u.value.length - 1].substeps.push({ completed: !1 }) : u.value.push({ completed: !1, substeps: [] });
|
|
52
48
|
}
|
|
53
49
|
return {
|
|
54
|
-
steps:
|
|
55
|
-
stepCount:
|
|
56
|
-
activeStepElement:
|
|
50
|
+
steps: A(u),
|
|
51
|
+
stepCount: n,
|
|
52
|
+
activeStepElement: S,
|
|
57
53
|
activeStepIndex: e,
|
|
58
54
|
activeSubstepIndex: l,
|
|
59
|
-
registerStep:
|
|
60
|
-
next:
|
|
61
|
-
back:
|
|
62
|
-
goTo:
|
|
63
|
-
isStepActive:
|
|
64
|
-
isStepCompleted:
|
|
55
|
+
registerStep: d,
|
|
56
|
+
next: m,
|
|
57
|
+
back: b,
|
|
58
|
+
goTo: h,
|
|
59
|
+
isStepActive: g,
|
|
60
|
+
isStepCompleted: i
|
|
65
61
|
};
|
|
66
62
|
}
|
|
67
63
|
export {
|
|
68
|
-
|
|
64
|
+
C as default
|
|
69
65
|
};
|
|
70
66
|
//# sourceMappingURL=useStepper.js.map
|
package/dist/useStepper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStepper.js","sources":["../src/composables/useStepper/useStepper.ts"],"sourcesContent":["import { computed, readonly, Ref, ref } from 'vue';\n\nexport interface StepDefinition {\n completed: boolean;\n substeps: Array<Omit<StepDefinition, 'substeps'>>;\n}\n\nexport interface StepperOptions {\n /**\n * If true, the stepper will prevent skipping steps\n */\n linear?: boolean;\n /**\n * The index of the active step\n */\n activeStep?: number;\n /**\n * The index of the active substep\n */\n activeSubstep?: number;\n /**\n * The stepper representation as an array of steps and substeps\n */\n steps?: Array<StepDefinition>;\n /**\n * A ref to the stepper element\n */\n ref?: Ref<HTMLUListElement | null>;\n}\n\nexport default function useStepper(\n options: StepperOptions = {\n linear: false,\n activeStep: -1,\n activeSubstep: -1,\n steps: [],\n },\n) {\n /**\n * The steps and substeps of the stepper, so we can keep track of their state.\n * Can be populated with the `steps` option, or via the `registerStep` function.\n */\n const steps = ref<Array<StepDefinition>>(options.steps ? options.steps : []);\n\n const stepCount = computed(() => steps.value.length);\n\n const activeStepIndex = ref(\n options.activeStep !== null && options.activeStep !== undefined ? options.activeStep : -1,\n );\n const activeSubstepIndex = ref(\n options.activeSubstep !== null && options.activeSubstep !== undefined ? options.activeSubstep : -1,\n );\n\n const stepElements = computed(() => {\n return Array.from((options.ref?.value?.children || []) as HTMLCollectionOf<HTMLLIElement>);\n });\n\n const activeStepElement = computed(() => stepElements.value[activeStepIndex.value]);\n\n /**\n * Returns true if the step at the given index has substeps\n * @param stepIndex The index of the step to check\n */\n function stepHasSubsteps(stepIndex: number): boolean {\n return !!steps.value[stepIndex].substeps.length;\n }\n\n /**\n * Goes to the next step or substep, while flagging the current one as completed.\n * If the current step has substeps, it will go to the next substep if there are any, or to the next substep.\n * And if the next step has substeps, automatically goes to the first substep\n */\n function next(): void {\n const hasNoActiveStep = activeStepIndex.value === -1;\n const isLastStep = activeStepIndex.value === steps.value.length - 1;\n\n // If there is no active step, we want to activate the first step\n if (hasNoActiveStep) {\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep\n if (stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value++;\n }\n } else if (isLastStep) {\n if (stepHasSubsteps(activeStepIndex.value)) {\n const hasNoActiveSubstep = activeSubstepIndex.value === -1;\n const isLastSubstep = activeSubstepIndex.value === steps.value[activeStepIndex.value].substeps.length - 1;\n\n // if there are no active substeps, we want to activate the first substep\n if (hasNoActiveSubstep) {\n activeSubstepIndex.value++;\n // if the active substep is the last one, we want to reset the step and substep to -1\n } else if (isLastSubstep) {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value = -1;\n\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value = -1;\n // if there are more substeps, we want to complete the current one and proceed to the next substep\n } else {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value++;\n }\n // If there are no substeps, we want to complete the current step and reset the step to -1\n } else {\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value = -1;\n }\n } else {\n if (stepHasSubsteps(activeStepIndex.value)) {\n const hasNoActiveSubstep = activeSubstepIndex.value === -1;\n const isLastSubstep = activeSubstepIndex.value === steps.value[activeStepIndex.value].substeps.length - 1;\n\n // if there are no active substeps, we want to activate the first substep\n if (hasNoActiveSubstep) {\n activeSubstepIndex.value++;\n // if the active substep is the last one, we want to go to the next step\n } else if (isLastSubstep) {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value = -1;\n\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep right away\n if (stepHasSubsteps(activeStepIndex.value) && activeSubstepIndex.value === -1) {\n activeSubstepIndex.value++;\n }\n // if there are more substeps, we want to complete the current one and proceed to the next substep\n } else {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value++;\n }\n } else {\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep right away\n if (stepHasSubsteps(activeStepIndex.value) && activeSubstepIndex.value === -1) {\n activeSubstepIndex.value++;\n }\n }\n }\n }\n\n function back(): void {\n // We don't want to go back if there is no active step\n if (activeStepIndex.value === -1) {\n return;\n }\n\n if (stepHasSubsteps(activeStepIndex.value)) {\n // If the active substep is the first one, we want to go back to the previous step\n if (activeSubstepIndex.value === 0) {\n activeStepIndex.value--;\n activeSubstepIndex.value--;\n\n // If the step that we just navigated to has substeps, we want to navigate to the last substep\n if (activeStepIndex.value >= 0 && stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value = steps.value[activeStepIndex.value].substeps.length - 1;\n }\n } else {\n activeSubstepIndex.value--;\n }\n } else {\n activeStepIndex.value--;\n\n // If the step that we just navigated to has substeps, we want to navigate to the last substep\n if (activeStepIndex.value >= 0 && stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value = steps.value[activeStepIndex.value].substeps.length - 1;\n }\n }\n }\n\n /**\n * Navigates to a specific step and substep.\n */\n function goTo(stepIndex: number, substepIndex = -1): void {\n // A linear stepper prevents navigation to incomplete steps\n if (options.linear) {\n if (isStepCompleted(stepIndex - 1) || stepIndex === 0) {\n if (stepHasSubsteps(stepIndex)) {\n if (substepIndex <= 0) {\n activeSubstepIndex.value = 0;\n } else if (isStepCompleted(stepIndex, substepIndex - 1)) {\n activeSubstepIndex.value = substepIndex;\n }\n }\n activeStepIndex.value = stepIndex;\n }\n } else {\n activeStepIndex.value = stepIndex;\n\n if (stepHasSubsteps(stepIndex)) {\n if (substepIndex < 0) {\n activeSubstepIndex.value = 0;\n } else {\n activeSubstepIndex.value = substepIndex;\n }\n }\n }\n }\n\n /**\n * Returns true if the step is completed.\n * if the substep index is provided, check if the substep is completed.\n */\n function isStepCompleted(stepIndex: number, substepIndex = -1): boolean {\n if (substepIndex >= 0) {\n return steps.value[stepIndex]?.substeps[substepIndex]?.completed;\n } else {\n return steps.value[stepIndex]?.completed;\n }\n }\n\n /**\n * Returns true if the step is active.\n * if the substep index is provided, check both if the step and the substep are active.\n */\n function isStepActive(stepIndex: number, substepIndex = -1): boolean {\n if (substepIndex >= 0) {\n return activeStepIndex.value === stepIndex && activeSubstepIndex.value === substepIndex;\n } else {\n return activeStepIndex.value === stepIndex;\n }\n }\n\n /**\n * Registers a new step or substep into the steps array\n */\n function registerStep(nested = false): void {\n if (nested && !steps.value.length) {\n throw new Error('Cannot register a substep without a parent step.');\n }\n\n if (nested) {\n steps.value[steps.value.length - 1].substeps.push({ completed: false });\n } else {\n steps.value.push({ completed: false, substeps: [] });\n }\n }\n\n return {\n steps: readonly(steps),\n stepCount,\n activeStepElement,\n activeStepIndex,\n activeSubstepIndex,\n registerStep,\n next,\n back,\n goTo,\n isStepActive,\n isStepCompleted,\n };\n}\n"],"names":["useStepper","options","steps","ref","stepCount","computed","activeStepIndex","activeSubstepIndex","stepElements","_b","_a","activeStepElement","stepHasSubsteps","stepIndex","next","hasNoActiveStep","isLastStep","hasNoActiveSubstep","isLastSubstep","back","goTo","substepIndex","isStepCompleted","_c","isStepActive","registerStep","nested","readonly"],"mappings":";AA8BA,SAAwBA,EACtBC,IAA0B;AAAA,EACxB,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,eAAe;AAAA,EACf,OAAO,CAAA;AACT,GACA;AAKA,QAAMC,IAAQC,EAA2BF,EAAQ,QAAQA,EAAQ,QAAQ,EAAE,GAErEG,IAAYC,EAAS,MAAMH,EAAM,MAAM,MAAM,GAE7CI,IAAkBH;AAAA,IACtBF,EAAQ,eAAe,QAAQA,EAAQ,eAAe,SAAYA,EAAQ,aAAa;AAAA,EACzF,GACMM,IAAqBJ;AAAA,IACzBF,EAAQ,kBAAkB,QAAQA,EAAQ,kBAAkB,SAAYA,EAAQ,gBAAgB;AAAA,EAClG,GAEMO,IAAeH,EAAS,MAAM;;AAClC,WAAO,MAAM,OAAMI,KAAAC,IAAAT,EAAQ,QAAR,gBAAAS,EAAa,UAAb,gBAAAD,EAAoB,aAAY,EAAsC;AAAA,EAAA,CAC1F,GAEKE,IAAoBN,EAAS,MAAMG,EAAa,MAAMF,EAAgB,KAAK,CAAC;AAMlF,WAASM,EAAgBC,GAA4B;AACnD,WAAO,CAAC,CAACX,EAAM,MAAMW,CAAS,EAAE,SAAS;AAAA,EAAA;AAQ3C,WAASC,IAAa;AACd,UAAAC,IAAkBT,EAAgB,UAAU,IAC5CU,IAAaV,EAAgB,UAAUJ,EAAM,MAAM,SAAS;AAGlE,QAAIa;AACc,MAAAT,EA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wB,IACIxB,EAAA,MAAMA,EAAM,MAAM,SAAS,CAAC,EAAE,SAAS,KAAK,EAAE,WAAW,GAAA,CAAO,IAEhEA,EAAA,MAAM,KAAK,EAAE,WAAW,IAAO,UAAU,CAAA,GAAI;AAAA,EACrD;AAGK,SAAA;AAAA,IACL,OAAOyB,EAASzB,CAAK;AAAA,IACrB,WAAAE;AAAA,IACA,mBAAAO;AAAA,IACA,iBAAAL;AAAA,IACA,oBAAAC;AAAA,IACA,cAAAkB;AAAA,IACA,MAAAX;AAAA,IACA,MAAAK;AAAA,IACA,MAAAC;AAAA,IACA,cAAAI;AAAA,IACA,iBAAAF;AAAA,EACF;AACF;"}
|
|
1
|
+
{"version":3,"file":"useStepper.js","sources":["../src/composables/useStepper/useStepper.ts"],"sourcesContent":["import { computed, readonly, Ref, ref } from 'vue';\n\nexport interface StepDefinition {\n completed: boolean;\n substeps: Array<Omit<StepDefinition, 'substeps'>>;\n}\n\nexport interface StepperOptions {\n /**\n * If true, the stepper will prevent skipping steps\n */\n linear?: boolean;\n /**\n * The index of the active step\n */\n activeStep?: number;\n /**\n * The index of the active substep\n */\n activeSubstep?: number;\n /**\n * The stepper representation as an array of steps and substeps\n */\n steps?: Array<StepDefinition>;\n /**\n * A ref to the stepper element\n */\n ref?: Ref<HTMLUListElement | null>;\n}\n\nexport default function useStepper(\n options: StepperOptions = {\n linear: false,\n activeStep: -1,\n activeSubstep: -1,\n steps: [],\n },\n) {\n /**\n * The steps and substeps of the stepper, so we can keep track of their state.\n * Can be populated with the `steps` option, or via the `registerStep` function.\n */\n const steps = ref<Array<StepDefinition>>(options.steps ? options.steps : []);\n\n const stepCount = computed(() => steps.value.length);\n\n const activeStepIndex = ref(\n options.activeStep !== null && options.activeStep !== undefined ? options.activeStep : -1,\n );\n const activeSubstepIndex = ref(\n options.activeSubstep !== null && options.activeSubstep !== undefined ? options.activeSubstep : -1,\n );\n\n const stepElements = computed(() => {\n return Array.from((options.ref?.value?.children || []) as HTMLCollectionOf<HTMLLIElement>);\n });\n\n const activeStepElement = computed(() => stepElements.value[activeStepIndex.value]);\n\n /**\n * Returns true if the step at the given index has substeps\n * @param stepIndex The index of the step to check\n */\n function stepHasSubsteps(stepIndex: number): boolean {\n return !!steps.value[stepIndex].substeps.length;\n }\n\n /**\n * Goes to the next step or substep, while flagging the current one as completed.\n * If the current step has substeps, it will go to the next substep if there are any, or to the next substep.\n * And if the next step has substeps, automatically goes to the first substep\n */\n function next(): void {\n const hasNoActiveStep = activeStepIndex.value === -1;\n const isLastStep = activeStepIndex.value === steps.value.length - 1;\n\n // If there is no active step, we want to activate the first step\n if (hasNoActiveStep) {\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep\n if (stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value++;\n }\n } else if (isLastStep) {\n if (stepHasSubsteps(activeStepIndex.value)) {\n const hasNoActiveSubstep = activeSubstepIndex.value === -1;\n const isLastSubstep = activeSubstepIndex.value === steps.value[activeStepIndex.value].substeps.length - 1;\n\n // if there are no active substeps, we want to activate the first substep\n if (hasNoActiveSubstep) {\n activeSubstepIndex.value++;\n // if the active substep is the last one, we want to reset the step and substep to -1\n } else if (isLastSubstep) {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value = -1;\n\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value = -1;\n // if there are more substeps, we want to complete the current one and proceed to the next substep\n } else {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value++;\n }\n // If there are no substeps, we want to complete the current step and reset the step to -1\n } else {\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value = -1;\n }\n } else {\n if (stepHasSubsteps(activeStepIndex.value)) {\n const hasNoActiveSubstep = activeSubstepIndex.value === -1;\n const isLastSubstep = activeSubstepIndex.value === steps.value[activeStepIndex.value].substeps.length - 1;\n\n // if there are no active substeps, we want to activate the first substep\n if (hasNoActiveSubstep) {\n activeSubstepIndex.value++;\n // if the active substep is the last one, we want to go to the next step\n } else if (isLastSubstep) {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value = -1;\n\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep right away\n if (stepHasSubsteps(activeStepIndex.value) && activeSubstepIndex.value === -1) {\n activeSubstepIndex.value++;\n }\n // if there are more substeps, we want to complete the current one and proceed to the next substep\n } else {\n steps.value[activeStepIndex.value].substeps[activeSubstepIndex.value].completed = true;\n activeSubstepIndex.value++;\n }\n } else {\n steps.value[activeStepIndex.value].completed = true;\n activeStepIndex.value++;\n\n // If the step we just navigated to has substeps, we want to activate the first substep right away\n if (stepHasSubsteps(activeStepIndex.value) && activeSubstepIndex.value === -1) {\n activeSubstepIndex.value++;\n }\n }\n }\n }\n\n function back(): void {\n // We don't want to go back if there is no active step\n if (activeStepIndex.value === -1) {\n return;\n }\n\n if (stepHasSubsteps(activeStepIndex.value)) {\n // If the active substep is the first one, we want to go back to the previous step\n if (activeSubstepIndex.value === 0) {\n activeStepIndex.value--;\n activeSubstepIndex.value--;\n\n // If the step that we just navigated to has substeps, we want to navigate to the last substep\n if (activeStepIndex.value >= 0 && stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value = steps.value[activeStepIndex.value].substeps.length - 1;\n }\n } else {\n activeSubstepIndex.value--;\n }\n } else {\n activeStepIndex.value--;\n\n // If the step that we just navigated to has substeps, we want to navigate to the last substep\n if (activeStepIndex.value >= 0 && stepHasSubsteps(activeStepIndex.value)) {\n activeSubstepIndex.value = steps.value[activeStepIndex.value].substeps.length - 1;\n }\n }\n }\n\n /**\n * Navigates to a specific step and substep.\n */\n function goTo(stepIndex: number, substepIndex = -1): void {\n // A linear stepper prevents navigation to incomplete steps\n if (options.linear) {\n if (isStepCompleted(stepIndex - 1) || stepIndex === 0) {\n if (stepHasSubsteps(stepIndex)) {\n if (substepIndex <= 0) {\n activeSubstepIndex.value = 0;\n } else if (isStepCompleted(stepIndex, substepIndex - 1)) {\n activeSubstepIndex.value = substepIndex;\n }\n }\n activeStepIndex.value = stepIndex;\n }\n } else {\n activeStepIndex.value = stepIndex;\n\n if (stepHasSubsteps(stepIndex)) {\n if (substepIndex < 0) {\n activeSubstepIndex.value = 0;\n } else {\n activeSubstepIndex.value = substepIndex;\n }\n }\n }\n }\n\n /**\n * Returns true if the step is completed.\n * if the substep index is provided, check if the substep is completed.\n */\n function isStepCompleted(stepIndex: number, substepIndex = -1): boolean {\n if (substepIndex >= 0) {\n return steps.value[stepIndex]?.substeps[substepIndex]?.completed;\n } else {\n return steps.value[stepIndex]?.completed;\n }\n }\n\n /**\n * Returns true if the step is active.\n * if the substep index is provided, check both if the step and the substep are active.\n */\n function isStepActive(stepIndex: number, substepIndex = -1): boolean {\n if (substepIndex >= 0) {\n return activeStepIndex.value === stepIndex && activeSubstepIndex.value === substepIndex;\n } else {\n return activeStepIndex.value === stepIndex;\n }\n }\n\n /**\n * Registers a new step or substep into the steps array\n */\n function registerStep(nested = false): void {\n if (nested && !steps.value.length) {\n throw new Error('Cannot register a substep without a parent step.');\n }\n\n if (nested) {\n steps.value[steps.value.length - 1].substeps.push({ completed: false });\n } else {\n steps.value.push({ completed: false, substeps: [] });\n }\n }\n\n return {\n steps: readonly(steps),\n stepCount,\n activeStepElement,\n activeStepIndex,\n activeSubstepIndex,\n registerStep,\n next,\n back,\n goTo,\n isStepActive,\n isStepCompleted,\n };\n}\n"],"names":["useStepper","options","steps","ref","stepCount","computed","activeStepIndex","activeSubstepIndex","stepElements","activeStepElement","stepHasSubsteps","stepIndex","next","hasNoActiveStep","isLastStep","hasNoActiveSubstep","isLastSubstep","back","goTo","substepIndex","isStepCompleted","isStepActive","registerStep","nested","readonly"],"mappings":";AA8BA,SAAwBA,EACtBC,IAA0B;AAAA,EACxB,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,eAAe;AAAA,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9CD,EAAgBC,CAAS,MACvBQ,KAAgB,IAClBZ,EAAmB,QAAQ,IAClBa,EAAgBT,GAAWQ,IAAe,CAAC,MACpDZ,EAAmB,QAAQY,KAG/Bb,EAAgB,QAAQK,MAG1BL,EAAgB,QAAQK,GAEpBD,EAAgBC,CAAS,MACvBQ,IAAe,IACjBZ,EAAmB,QAAQ,IAE3BA,EAAmB,QAAQY;AAAA,EAInC;AAMA,WAASC,EAAgBT,GAAmBQ,IAAe,IAAa;AACtE,WAAIA,KAAgB,IACXjB,EAAM,MAAMS,CAAS,GAAG,SAASQ,CAAY,GAAG,YAEhDjB,EAAM,MAAMS,CAAS,GAAG;AAAA,EAEnC;AAMA,WAASU,EAAaV,GAAmBQ,IAAe,IAAa;AACnE,WAAIA,KAAgB,IACXb,EAAgB,UAAUK,KAAaJ,EAAmB,UAAUY,IAEpEb,EAAgB,UAAUK;AAAA,EAErC;AAKA,WAASW,EAAaC,IAAS,IAAa;AAC1C,QAAIA,KAAU,CAACrB,EAAM,MAAM;AACzB,YAAM,IAAI,MAAM,kDAAkD;AAGpE,IAAIqB,IACFrB,EAAM,MAAMA,EAAM,MAAM,SAAS,CAAC,EAAE,SAAS,KAAK,EAAE,WAAW,GAAA,CAAO,IAEtEA,EAAM,MAAM,KAAK,EAAE,WAAW,IAAO,UAAU,CAAA,GAAI;AAAA,EAEvD;AAEA,SAAO;AAAA,IACL,OAAOsB,EAAStB,CAAK;AAAA,IACrB,WAAAE;AAAA,IACA,mBAAAK;AAAA,IACA,iBAAAH;AAAA,IACA,oBAAAC;AAAA,IACA,cAAAe;AAAA,IACA,MAAAV;AAAA,IACA,MAAAK;AAAA,IACA,MAAAC;AAAA,IACA,cAAAG;AAAA,IACA,iBAAAD;AAAA,EAAA;AAEJ;"}
|
package/dist/useToasts.js
CHANGED
|
@@ -2,38 +2,38 @@ import l from "lodash-es/merge";
|
|
|
2
2
|
import T from "lodash-es/uniqueId";
|
|
3
3
|
import { ref as h, reactive as y, readonly as b } from "vue";
|
|
4
4
|
const w = 5e3, n = h([]);
|
|
5
|
-
function M(
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
5
|
+
function M(c = { timeout: w }) {
|
|
6
|
+
function s(o) {
|
|
7
|
+
const e = typeof o == "string" ? o : void 0, { group: i = void 0, status: t = void 0 } = typeof o == "object" ? o : {};
|
|
8
|
+
if (!e && (!i || !t))
|
|
9
9
|
throw new Error("Must provide either a toast ID or both group and type");
|
|
10
|
-
const r = i && t ? `toast-${t}-${i}` : String(
|
|
10
|
+
const r = i && t ? `toast-${t}-${i}` : String(e), f = n.value.findIndex(({ id: g }) => g === r);
|
|
11
11
|
f !== -1 && n.value.splice(f, 1);
|
|
12
12
|
}
|
|
13
|
-
function u(
|
|
14
|
-
const t = l({},
|
|
15
|
-
if (!(t
|
|
13
|
+
function u(o, e, i) {
|
|
14
|
+
const t = l({}, c, i), r = t?.group ? `toast-${e}-${t.group}` : T("toast-");
|
|
15
|
+
if (!(t?.group && n.value.some(({ id: f }) => f === r)))
|
|
16
16
|
return n.value.push({
|
|
17
|
-
text:
|
|
17
|
+
text: o,
|
|
18
18
|
id: r,
|
|
19
|
-
status:
|
|
19
|
+
status: e,
|
|
20
20
|
offsetTop: t.offsetTop
|
|
21
|
-
}), typeof t.timeout == "number" && setTimeout(() =>
|
|
21
|
+
}), typeof t.timeout == "number" && setTimeout(() => s(r), Math.abs(t.timeout)), r;
|
|
22
22
|
}
|
|
23
23
|
function a() {
|
|
24
24
|
n.value = [];
|
|
25
25
|
}
|
|
26
|
-
function m(
|
|
27
|
-
return u(
|
|
26
|
+
function m(o, e) {
|
|
27
|
+
return u(o, "error", e);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
return u(
|
|
29
|
+
function p(o, e) {
|
|
30
|
+
return u(o, "info", e);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return u(
|
|
32
|
+
function v(o, e) {
|
|
33
|
+
return u(o, "success", e);
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
return u(
|
|
35
|
+
function d(o, e) {
|
|
36
|
+
return u(o, "warning", e);
|
|
37
37
|
}
|
|
38
38
|
return y({
|
|
39
39
|
/**
|
|
@@ -43,7 +43,7 @@ function M(s = { timeout: w }) {
|
|
|
43
43
|
/**
|
|
44
44
|
* Removes an active/visible toast by id or by group and type.
|
|
45
45
|
*/
|
|
46
|
-
remove:
|
|
46
|
+
remove: s,
|
|
47
47
|
/**
|
|
48
48
|
* Creates a new toast and makes it active/visible.
|
|
49
49
|
*/
|
|
@@ -59,15 +59,15 @@ function M(s = { timeout: w }) {
|
|
|
59
59
|
/**
|
|
60
60
|
* Creates a new "info" toast.
|
|
61
61
|
*/
|
|
62
|
-
info:
|
|
62
|
+
info: p,
|
|
63
63
|
/**
|
|
64
64
|
* Creates a new "success" toast.
|
|
65
65
|
*/
|
|
66
|
-
success:
|
|
66
|
+
success: v,
|
|
67
67
|
/**
|
|
68
68
|
* Creates a new "warning" toast.
|
|
69
69
|
*/
|
|
70
|
-
warning:
|
|
70
|
+
warning: d
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
export {
|
package/dist/useToasts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToasts.js","sources":["../src/composables/useToasts/useToasts.ts"],"sourcesContent":["import merge from 'lodash-es/merge';\nimport uniqueId from 'lodash-es/uniqueId';\nimport { reactive, readonly, ref, RenderFunction } from 'vue';\n\nimport { StatusSeverity } from '../../../types/statusLevels';\n\nexport const DEFAULT_TIMEOUT = 5000;\n\nexport type Toast = {\n id: string;\n text: string | RenderFunction;\n status: StatusSeverity;\n offsetTop?: string;\n};\n\nexport interface ToastOptions {\n /**\n * The timeout in milliseconds before the toast is automatically dismissed. If set to `false`, the toast will persist until the user clicks on it.\n * @default DEFAULT_TIMEOUT\n */\n timeout?: number | boolean;\n /**\n * A group name ensures only one toast with the same group and status is visible at any given time.\n * Toasts with the same group but different statuses will be treated as separate and will display concurrently.\n */\n group?: string;\n /**\n * The container distance from the top of the viewport.\n */\n offsetTop?: string;\n}\n\ntype ToastIdOrUndefined<O extends ToastOptions | undefined> = O extends { id: string }\n ? Toast['id'] | undefined\n : Toast['id'];\n\nconst active = ref<Toast[]>([]);\n\nexport default function useToasts(globalOptions: Omit<ToastOptions, 'group'> = { timeout: DEFAULT_TIMEOUT }) {\n // method overloads\n function remove(toastId: Toast['id']): void;\n function remove(options: { group: string; status: StatusSeverity }): void;\n function remove(toastIdOrOptions: Toast['id'] | { group: string; status: StatusSeverity }) {\n const toastId = typeof toastIdOrOptions === 'string' ? toastIdOrOptions : undefined;\n const { group = undefined, status = undefined } = typeof toastIdOrOptions === 'object' ? toastIdOrOptions : {};\n\n if (!toastId && (!group || !status)) {\n throw new Error('Must provide either a toast ID or both group and type');\n }\n\n const idToRemove = group && status ? `toast-${status}-${group}` : String(toastId);\n const index = active.value.findIndex(({ id }) => id === idToRemove);\n if (index === -1) {\n return;\n }\n\n active.value.splice(index, 1);\n }\n\n // method overloads\n function create(text: Toast['text'], status: StatusSeverity, options?: Omit<ToastOptions, 'group'>): Toast['id'];\n function create(\n text: Toast['text'],\n status: StatusSeverity,\n options: ToastOptions & { id: string },\n ): Toast['id'] | undefined;\n function create(text: Toast['text'], status: StatusSeverity, localOptions?: ToastOptions): Toast['id'] | undefined {\n const options = merge({}, globalOptions, localOptions);\n\n const id = options?.group ? `toast-${status}-${options.group}` : uniqueId('toast-');\n if (options?.group && active.value.some(({ id: existingId }) => existingId === id)) {\n return;\n }\n\n active.value.push({\n text,\n id,\n status,\n offsetTop: options.offsetTop,\n });\n\n if (typeof options.timeout === 'number') {\n setTimeout(() => remove(id), Math.abs(options.timeout));\n }\n\n return id;\n }\n\n function removeAll() {\n active.value = [];\n }\n\n function error<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'error', options);\n }\n\n function info<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'info', options);\n }\n\n function success<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'success', options);\n }\n\n function warning<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'warning', options);\n }\n\n return reactive({\n /**\n * The list of toasts that are currently visible.\n */\n active: readonly(active),\n\n /**\n * Removes an active/visible toast by id or by group and type.\n */\n remove,\n\n /**\n * Creates a new toast and makes it active/visible.\n */\n create,\n\n /**\n * Removes all active/visible toasts.\n */\n removeAll,\n\n /**\n * Creates a new \"error\" toast.\n */\n error,\n\n /**\n * Creates a new \"info\" toast.\n */\n info,\n\n /**\n * Creates a new \"success\" toast.\n */\n success,\n\n /**\n * Creates a new \"warning\" toast.\n */\n warning,\n });\n}\n"],"names":["DEFAULT_TIMEOUT","active","ref","useToasts","globalOptions","remove","toastIdOrOptions","toastId","group","status","idToRemove","index","id","create","text","localOptions","options","merge","uniqueId","existingId","removeAll","error","info","success","warning","reactive","readonly"],"mappings":";;;AAMO,MAAMA,IAAkB,KA8BzBC,IAASC,EAAa,EAAE;AAE9B,SAAwBC,EAAUC,IAA6C,EAAE,SAASJ,KAAmB;AAI3G,WAASK,EAAOC,GAA2E;AACzF,UAAMC,IAAU,OAAOD,KAAqB,WAAWA,IAAmB,QACpE,EAAE,OAAAE,IAAQ,QAAW,QAAAC,IAAS,
|
|
1
|
+
{"version":3,"file":"useToasts.js","sources":["../src/composables/useToasts/useToasts.ts"],"sourcesContent":["import merge from 'lodash-es/merge';\nimport uniqueId from 'lodash-es/uniqueId';\nimport { reactive, readonly, ref, RenderFunction } from 'vue';\n\nimport { StatusSeverity } from '../../../types/statusLevels';\n\nexport const DEFAULT_TIMEOUT = 5000;\n\nexport type Toast = {\n id: string;\n text: string | RenderFunction;\n status: StatusSeverity;\n offsetTop?: string;\n};\n\nexport interface ToastOptions {\n /**\n * The timeout in milliseconds before the toast is automatically dismissed. If set to `false`, the toast will persist until the user clicks on it.\n * @default DEFAULT_TIMEOUT\n */\n timeout?: number | boolean;\n /**\n * A group name ensures only one toast with the same group and status is visible at any given time.\n * Toasts with the same group but different statuses will be treated as separate and will display concurrently.\n */\n group?: string;\n /**\n * The container distance from the top of the viewport.\n */\n offsetTop?: string;\n}\n\ntype ToastIdOrUndefined<O extends ToastOptions | undefined> = O extends { id: string }\n ? Toast['id'] | undefined\n : Toast['id'];\n\nconst active = ref<Toast[]>([]);\n\nexport default function useToasts(globalOptions: Omit<ToastOptions, 'group'> = { timeout: DEFAULT_TIMEOUT }) {\n // method overloads\n function remove(toastId: Toast['id']): void;\n function remove(options: { group: string; status: StatusSeverity }): void;\n function remove(toastIdOrOptions: Toast['id'] | { group: string; status: StatusSeverity }) {\n const toastId = typeof toastIdOrOptions === 'string' ? toastIdOrOptions : undefined;\n const { group = undefined, status = undefined } = typeof toastIdOrOptions === 'object' ? toastIdOrOptions : {};\n\n if (!toastId && (!group || !status)) {\n throw new Error('Must provide either a toast ID or both group and type');\n }\n\n const idToRemove = group && status ? `toast-${status}-${group}` : String(toastId);\n const index = active.value.findIndex(({ id }) => id === idToRemove);\n if (index === -1) {\n return;\n }\n\n active.value.splice(index, 1);\n }\n\n // method overloads\n function create(text: Toast['text'], status: StatusSeverity, options?: Omit<ToastOptions, 'group'>): Toast['id'];\n function create(\n text: Toast['text'],\n status: StatusSeverity,\n options: ToastOptions & { id: string },\n ): Toast['id'] | undefined;\n function create(text: Toast['text'], status: StatusSeverity, localOptions?: ToastOptions): Toast['id'] | undefined {\n const options = merge({}, globalOptions, localOptions);\n\n const id = options?.group ? `toast-${status}-${options.group}` : uniqueId('toast-');\n if (options?.group && active.value.some(({ id: existingId }) => existingId === id)) {\n return;\n }\n\n active.value.push({\n text,\n id,\n status,\n offsetTop: options.offsetTop,\n });\n\n if (typeof options.timeout === 'number') {\n setTimeout(() => remove(id), Math.abs(options.timeout));\n }\n\n return id;\n }\n\n function removeAll() {\n active.value = [];\n }\n\n function error<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'error', options);\n }\n\n function info<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'info', options);\n }\n\n function success<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'success', options);\n }\n\n function warning<O extends ToastOptions>(text: Toast['text'], options?: O): ToastIdOrUndefined<O> {\n return create(text, 'warning', options);\n }\n\n return reactive({\n /**\n * The list of toasts that are currently visible.\n */\n active: readonly(active),\n\n /**\n * Removes an active/visible toast by id or by group and type.\n */\n remove,\n\n /**\n * Creates a new toast and makes it active/visible.\n */\n create,\n\n /**\n * Removes all active/visible toasts.\n */\n removeAll,\n\n /**\n * Creates a new \"error\" toast.\n */\n error,\n\n /**\n * Creates a new \"info\" toast.\n */\n info,\n\n /**\n * Creates a new \"success\" toast.\n */\n success,\n\n /**\n * Creates a new \"warning\" toast.\n */\n warning,\n });\n}\n"],"names":["DEFAULT_TIMEOUT","active","ref","useToasts","globalOptions","remove","toastIdOrOptions","toastId","group","status","idToRemove","index","id","create","text","localOptions","options","merge","uniqueId","existingId","removeAll","error","info","success","warning","reactive","readonly"],"mappings":";;;AAMO,MAAMA,IAAkB,KA8BzBC,IAASC,EAAa,EAAE;AAE9B,SAAwBC,EAAUC,IAA6C,EAAE,SAASJ,KAAmB;AAI3G,WAASK,EAAOC,GAA2E;AACzF,UAAMC,IAAU,OAAOD,KAAqB,WAAWA,IAAmB,QACpE,EAAE,OAAAE,IAAQ,QAAW,QAAAC,IAAS,OAAA,IAAc,OAAOH,KAAqB,WAAWA,IAAmB,CAAA;AAE5G,QAAI,CAACC,MAAY,CAACC,KAAS,CAACC;AAC1B,YAAM,IAAI,MAAM,uDAAuD;AAGzE,UAAMC,IAAaF,KAASC,IAAS,SAASA,CAAM,IAAID,CAAK,KAAK,OAAOD,CAAO,GAC1EI,IAAQV,EAAO,MAAM,UAAU,CAAC,EAAE,IAAAW,E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