@getmicdrop/svelte-components 5.8.0 → 5.8.2
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/dist/calendar/AboutShow/AboutShow.svelte +172 -172
- package/dist/calendar/Calendar/MiniMonthCalendar.svelte +782 -782
- package/dist/calendar/FAQs/FAQs.svelte +75 -75
- package/dist/calendar/MonthSwitcher/MonthSwitcher.svelte +126 -126
- package/dist/calendar/OrderSummary/OrderSummary.svelte +367 -367
- package/dist/calendar/PublicCard/PublicCard.svelte +134 -134
- package/dist/calendar/ShowCard/ShowCard.svelte +157 -157
- package/dist/calendar/ShowTimeCard/ShowTimeCard.svelte +61 -61
- package/dist/components/Heading.svelte +60 -58
- package/dist/components/Heading.svelte.d.ts +1 -0
- package/dist/components/Heading.svelte.d.ts.map +1 -1
- package/dist/components/Layout/AppShell.svelte +104 -104
- package/dist/components/Layout/ContentSection.svelte +80 -80
- package/dist/components/Layout/Grid.svelte +4 -4
- package/dist/components/Layout/Heading.svelte +81 -81
- package/dist/components/Layout/PageContainer.svelte +69 -69
- package/dist/components/Layout/Responsive.svelte +75 -75
- package/dist/components/Layout/Section.svelte +80 -80
- package/dist/components/Layout/ShowOnDesktop.svelte +37 -37
- package/dist/components/Layout/ShowOnMobile.svelte +37 -37
- package/dist/components/Layout/Sidebar.svelte +108 -108
- package/dist/components/Layout/Stack.spec.js +1 -1
- package/dist/components/Layout/Stack.svelte +6 -6
- package/dist/components/Layout/Text.svelte +87 -87
- package/dist/components/Layout/TwoColumn.svelte +108 -108
- package/dist/components/Text.svelte +53 -53
- package/dist/constants/validation.js +91 -91
- package/dist/constants/validation.spec.js +64 -64
- package/dist/datetime/__tests__/format.test.js +1 -1
- package/dist/datetime/__tests__/parse.test.js +1 -1
- package/dist/datetime/__tests__/timezone.test.js +1 -1
- package/dist/datetime/parse.js +1 -1
- package/dist/forms/createFormStore.svelte.js +1 -0
- package/dist/index.js +50 -50
- package/dist/patterns/data/DataGrid.svelte +45 -45
- package/dist/patterns/data/DataList.svelte +24 -24
- package/dist/patterns/data/DataTable.svelte +36 -36
- package/dist/patterns/forms/FormActions.spec.js +95 -95
- package/dist/patterns/forms/FormActions.stories.svelte +97 -97
- package/dist/patterns/forms/FormActions.svelte +46 -46
- package/dist/patterns/forms/FormGrid.svelte +33 -33
- package/dist/patterns/forms/FormSection.svelte +32 -32
- package/dist/patterns/forms/FormValidationSummary.stories.svelte +83 -83
- package/dist/patterns/forms/FormValidationSummary.svelte +74 -74
- package/dist/patterns/layout/Sidebar.svelte +39 -39
- package/dist/patterns/layout/index.js +29 -29
- package/dist/patterns/navigation/BottomNav.stories.svelte +117 -117
- package/dist/patterns/navigation/BottomNav.svelte +74 -74
- package/dist/patterns/navigation/Header.stories.svelte +77 -77
- package/dist/patterns/navigation/Header.svelte +193 -193
- package/dist/patterns/page/PageHeader.svelte +18 -18
- package/dist/patterns/page/PageLayout.svelte +40 -40
- package/dist/patterns/page/PageLoader.spec.js +57 -57
- package/dist/patterns/page/PageLoader.stories.svelte +137 -137
- package/dist/patterns/page/PageLoader.svelte +24 -24
- package/dist/patterns/page/SectionHeader.svelte +29 -29
- package/dist/presets/badges.js +112 -112
- package/dist/presets/buttons.js +76 -76
- package/dist/presets/index.js +9 -9
- package/dist/primitives/Accordion/Accordion.stories.svelte +75 -75
- package/dist/primitives/Accordion/Accordion.svelte +42 -42
- package/dist/primitives/Accordion/AccordionItem.svelte +95 -95
- package/dist/primitives/Alert/Alert.spec.js +173 -173
- package/dist/primitives/Alert/Alert.stories.svelte +88 -88
- package/dist/primitives/Alert/Alert.svelte +27 -27
- package/dist/primitives/Avatar/Avatar.stories.svelte +94 -94
- package/dist/primitives/Avatar/Avatar.svelte +66 -66
- package/dist/primitives/Badges/Badge.spec.js +144 -144
- package/dist/primitives/Badges/Badge.stories.svelte +86 -86
- package/dist/primitives/Badges/Badge.svelte +79 -79
- package/dist/primitives/BottomSheet/BottomSheet.spec.js +136 -136
- package/dist/primitives/BottomSheet/BottomSheet.stories.svelte +83 -83
- package/dist/primitives/BottomSheet/BottomSheet.svelte +100 -100
- package/dist/primitives/Breadcrumb/Breadcrumb.spec.js +122 -122
- package/dist/primitives/Breadcrumb/Breadcrumb.stories.svelte +23 -23
- package/dist/primitives/Breadcrumb/Breadcrumb.svelte +89 -89
- package/dist/primitives/Button/Button.spec.js +223 -223
- package/dist/primitives/Button/Button.stories.svelte +76 -76
- package/dist/primitives/Button/Button.svelte +270 -270
- package/dist/primitives/Button/ButtonSaveDemo.spec.js +146 -146
- package/dist/primitives/Button/ButtonSaveDemo.svelte +25 -25
- package/dist/primitives/Button/ButtonVariantShowcase.svelte +129 -129
- package/dist/primitives/Card.spec.js +49 -49
- package/dist/primitives/Card.stories.svelte +22 -22
- package/dist/primitives/Card.svelte +28 -28
- package/dist/primitives/Checkbox/Checkbox.stories.svelte +84 -84
- package/dist/primitives/Checkbox/Checkbox.svelte +88 -88
- package/dist/primitives/DarkModeToggle.spec.js +390 -390
- package/dist/primitives/DarkModeToggle.stories.svelte +57 -57
- package/dist/primitives/DarkModeToggle.svelte +136 -136
- package/dist/primitives/Drawer/Drawer.stories.svelte +80 -80
- package/dist/primitives/Drawer/Drawer.svelte +120 -120
- package/dist/primitives/Dropdown/Dropdown.stories.svelte +137 -137
- package/dist/primitives/Dropdown/Dropdown.svelte +14 -14
- package/dist/primitives/Dropdown/DropdownDivider.svelte +9 -9
- package/dist/primitives/Dropdown/DropdownItem.svelte +80 -80
- package/dist/primitives/Helper/Helper.svelte +33 -33
- package/dist/primitives/Icons/ArrowLeft.svelte +8 -8
- package/dist/primitives/Icons/ArrowRight.svelte +8 -8
- package/dist/primitives/Icons/Availability.svelte +14 -14
- package/dist/primitives/Icons/Back.svelte +14 -14
- package/dist/primitives/Icons/CheckCircle.svelte +6 -6
- package/dist/primitives/Icons/CheckCircleOutline.svelte +15 -15
- package/dist/primitives/Icons/ChevronLeft.svelte +4 -4
- package/dist/primitives/Icons/ChevronRight.svelte +4 -4
- package/dist/primitives/Icons/Copy.svelte +15 -15
- package/dist/primitives/Icons/Cross.svelte +5 -5
- package/dist/primitives/Icons/DownArrow.svelte +8 -8
- package/dist/primitives/Icons/ErrorCircle.svelte +6 -6
- package/dist/primitives/Icons/FacebookIcon.svelte +2 -2
- package/dist/primitives/Icons/Home.svelte +15 -15
- package/dist/primitives/Icons/Icon.spec.js +169 -169
- package/dist/primitives/Icons/Icon.stories.svelte +100 -100
- package/dist/primitives/Icons/Icon.svelte +52 -52
- package/dist/primitives/Icons/IconGallery.stories.svelte +235 -235
- package/dist/primitives/Icons/Info.svelte +7 -7
- package/dist/primitives/Icons/InstagramIcon.svelte +4 -4
- package/dist/primitives/Icons/LogoInstagram.svelte +2 -2
- package/dist/primitives/Icons/Message.svelte +15 -15
- package/dist/primitives/Icons/MoonIcon.svelte +5 -5
- package/dist/primitives/Icons/More.svelte +21 -21
- package/dist/primitives/Icons/MoreHori.spec.js +61 -61
- package/dist/primitives/Icons/MoreHori.svelte +22 -22
- package/dist/primitives/Icons/Notification.svelte +14 -14
- package/dist/primitives/Icons/Payment.svelte +14 -14
- package/dist/primitives/Icons/Profile.svelte +21 -21
- package/dist/primitives/Icons/Reload.svelte +29 -29
- package/dist/primitives/Icons/Shows.svelte +21 -21
- package/dist/primitives/Icons/Signout.svelte +21 -21
- package/dist/primitives/Icons/SunIcon.svelte +8 -8
- package/dist/primitives/Icons/TiktokIcon.svelte +2 -2
- package/dist/primitives/Icons/TwitterIcon.svelte +2 -2
- package/dist/primitives/Icons/WarningIcon.spec.js +18 -18
- package/dist/primitives/Icons/WarningIcon.svelte +5 -5
- package/dist/primitives/Input/Input.spec.js +573 -573
- package/dist/primitives/Input/Input.stories.svelte +139 -139
- package/dist/primitives/Input/Select.spec.js +212 -212
- package/dist/primitives/Input/Select.stories.svelte +112 -112
- package/dist/primitives/Input/Select.svelte +128 -128
- package/dist/primitives/Input/Textarea.stories.svelte +137 -137
- package/dist/primitives/Input/Textarea.svelte +35 -35
- package/dist/primitives/Label/Label.svelte +37 -37
- package/dist/primitives/Modal/Modal.spec.js +99 -99
- package/dist/primitives/Modal/Modal.stories.svelte +86 -86
- package/dist/primitives/Pagination/Pagination.stories.svelte +76 -76
- package/dist/primitives/Pagination/Pagination.svelte +261 -261
- package/dist/primitives/Radio/Radio.stories.svelte +80 -80
- package/dist/primitives/Radio/Radio.svelte +67 -67
- package/dist/primitives/Skeleton/CardPlaceholder.svelte +87 -87
- package/dist/primitives/Skeleton/ImagePlaceholder.svelte +59 -59
- package/dist/primitives/Skeleton/ListPlaceholder.svelte +76 -76
- package/dist/primitives/Skeleton/Skeleton.stories.svelte +151 -151
- package/dist/primitives/Skeleton/Skeleton.svelte +26 -26
- package/dist/primitives/Spinner/Spinner.spec.js +71 -71
- package/dist/primitives/Spinner/Spinner.stories.svelte +29 -29
- package/dist/primitives/Spinner/Spinner.svelte +20 -20
- package/dist/primitives/Tabs/TabItem.svelte +49 -49
- package/dist/primitives/Tabs/Tabs.stories.svelte +112 -112
- package/dist/primitives/Tabs/Tabs.svelte +123 -123
- package/dist/primitives/Toggle.spec.js +143 -143
- package/dist/primitives/Toggle.stories.svelte +92 -92
- package/dist/primitives/Tooltip/Tooltip.svelte +83 -83
- package/dist/primitives/Typography/Typography.svelte +53 -53
- package/dist/primitives/ValidationError.spec.js +103 -103
- package/dist/primitives/ValidationError.stories.svelte +69 -69
- package/dist/primitives/ValidationError.svelte +29 -29
- package/dist/primitives/index.js +91 -91
- package/dist/recipes/CropImage/CropImage.spec.js +208 -208
- package/dist/recipes/CropImage/CropImage.stories.svelte +104 -104
- package/dist/recipes/CropImage/CropImage.svelte +238 -238
- package/dist/recipes/ImageUploader/ImageUploader.stories.svelte +125 -125
- package/dist/recipes/ImageUploader/ImageUploader.svelte +804 -804
- package/dist/recipes/Toaster/Toaster.stories.svelte +62 -62
- package/dist/recipes/feedback/EmptyState/EmptyState.svelte +1 -1
- package/dist/recipes/feedback/ErrorDisplay.spec.js +69 -69
- package/dist/recipes/feedback/ErrorDisplay.stories.svelte +101 -101
- package/dist/recipes/feedback/ErrorDisplay.svelte +1 -1
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.spec.js +133 -133
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.svelte +157 -157
- package/dist/recipes/fields/CheckboxField.svelte +85 -85
- package/dist/recipes/fields/FormField.svelte +58 -58
- package/dist/recipes/fields/RadioGroup.svelte +95 -95
- package/dist/recipes/fields/SelectField.svelte +80 -80
- package/dist/recipes/fields/TextareaField.svelte +97 -97
- package/dist/recipes/fields/ToggleField.svelte +60 -60
- package/dist/recipes/fields/index.js +7 -7
- package/dist/recipes/inputs/MultiSelect.spec.js +258 -258
- package/dist/recipes/inputs/MultiSelect.stories.svelte +133 -133
- package/dist/recipes/inputs/OTPInput.spec.js +251 -251
- package/dist/recipes/inputs/OTPInput.stories.svelte +162 -162
- package/dist/recipes/inputs/OTPInput.svelte +29 -29
- package/dist/recipes/inputs/PasswordInput.svelte +22 -22
- package/dist/recipes/inputs/PasswordStrengthIndicator/PasswordStrengthIndicator.svelte +117 -117
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.stories.svelte +123 -123
- package/dist/recipes/inputs/Search.svelte +37 -37
- package/dist/recipes/inputs/SelectDropdown.svelte +57 -57
- package/dist/recipes/modals/AlertModal.svelte +130 -130
- package/dist/recipes/modals/ConfirmationModal.spec.js +206 -206
- package/dist/recipes/modals/ConfirmationModal.stories.svelte +119 -119
- package/dist/recipes/modals/ConfirmationModal.svelte +152 -152
- package/dist/recipes/modals/InputModal.svelte +182 -182
- package/dist/recipes/modals/ModalStateManager.spec.js +100 -100
- package/dist/recipes/modals/ModalStateManager.svelte +77 -77
- package/dist/recipes/modals/ModalTestWrapper.svelte +65 -65
- package/dist/recipes/modals/StatusModal.svelte +206 -206
- package/dist/services/EventService.js +75 -75
- package/dist/services/EventService.spec.js +217 -217
- package/dist/services/ShowService.spec.js +345 -345
- package/dist/stores/index.d.ts +4 -4
- package/dist/stores/index.js +6 -7
- package/dist/stores/toaster.js +13 -13
- package/dist/stories/ButtonAuditReview.stories.svelte +14 -14
- package/dist/stories/ButtonAuditReview.svelte +427 -427
- package/dist/stories/PatternsGallery.stories.svelte +19 -19
- package/dist/stories/PatternsGallery.svelte +206 -206
- package/dist/stories/PrimitivesGallery.stories.svelte +19 -19
- package/dist/stories/PrimitivesGallery.svelte +725 -725
- package/dist/stories/RecipesGallery.stories.svelte +19 -19
- package/dist/stories/RecipesGallery.svelte +271 -271
- package/dist/stories/button-audit-manifest.json +11186 -11186
- package/dist/tailwind/preset.cjs +82 -82
- package/dist/telemetry.js +405 -405
- package/dist/telemetry.spec.js +1169 -1169
- package/dist/tokens/tokens.css +87 -87
- package/dist/tokens/typography-base.css +163 -163
- package/dist/tokens/utilities.css +353 -0
- package/dist/utils/apiConfig.spec.js +219 -219
- package/dist/utils/transitions.js +62 -62
- package/dist/utils/utils.js +354 -354
- package/package.json +296 -295
- package/dist/stores/auth.js +0 -44
- package/dist/stores/createFormStore.d.ts +0 -77
- package/dist/stores/createFormStore.d.ts.map +0 -1
- package/dist/stores/createFormStore.js +0 -410
- package/dist/stores/formDataStore.d.ts +0 -17
- package/dist/stores/formDataStore.d.ts.map +0 -1
- package/dist/stores/formDataStore.js +0 -33
- package/dist/stores/formSave.d.ts +0 -24
- package/dist/stores/formSave.d.ts.map +0 -1
- package/dist/stores/formSave.js +0 -140
- package/dist/stores/navigation.d.ts +0 -5
- package/dist/stores/navigation.d.ts.map +0 -1
- package/dist/stores/navigation.js +0 -20
package/dist/stores/auth.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use the Svelte 5 runes version from './auth.svelte.ts' instead.
|
|
3
|
-
* This file is maintained for backwards compatibility with Svelte 4 components.
|
|
4
|
-
*/
|
|
5
|
-
import { writable } from "svelte/store";
|
|
6
|
-
|
|
7
|
-
console.warn(
|
|
8
|
-
"[DEPRECATED] auth.js is deprecated. Use auth.svelte.ts for Svelte 5 runes."
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
// Store to manage authentication state
|
|
12
|
-
export const auth = writable({
|
|
13
|
-
isAuthenticated: false,
|
|
14
|
-
token: null,
|
|
15
|
-
userDetails: null, // To store email and first name
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// Function to set authentication state
|
|
19
|
-
export const setAuthState = (state) => {
|
|
20
|
-
auth.set(state);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// Function to clear the authentication state
|
|
24
|
-
export const clearAuthState = () => {
|
|
25
|
-
auth.set({ isAuthenticated: false, token: null, userDetails: null });
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// Initialize the store from cookies
|
|
29
|
-
export const initializeAuthState = () => {
|
|
30
|
-
const cookies = Object.fromEntries(
|
|
31
|
-
document.cookie
|
|
32
|
-
.split("; ")
|
|
33
|
-
.map((c) => c.split("="))
|
|
34
|
-
.map(([k, v]) => [k, decodeURIComponent(v)])
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
if (cookies.performer_token) {
|
|
38
|
-
setAuthState({
|
|
39
|
-
isAuthenticated: true,
|
|
40
|
-
token: cookies.performer_token,
|
|
41
|
-
userDetails: cookies.userDetails ? JSON.parse(cookies.userDetails) : null,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use createFormStore from '@getmicdrop/svelte-components/forms' instead.
|
|
3
|
-
* @typedef {Object} FormStoreOptions
|
|
4
|
-
* @property {Object} initialData - Initial form data
|
|
5
|
-
* @property {string} [endpoint] - API endpoint for saving
|
|
6
|
-
* @property {string} [successMessage] - Message to show on success
|
|
7
|
-
* @property {string} [errorMessage] - Message to show on error
|
|
8
|
-
* @property {Function} [validate] - Validation function returning { isValid, errors }
|
|
9
|
-
* @property {Function} [transformData] - Transform data before saving
|
|
10
|
-
* @property {Function} [onSuccess] - Callback after successful save
|
|
11
|
-
* @property {Function} [onError] - Callback after error
|
|
12
|
-
* @property {boolean} [showToasts=true] - Show toast notifications
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated Use createFormStore from '@getmicdrop/svelte-components/forms' instead.
|
|
16
|
-
*
|
|
17
|
-
* Creates a comprehensive form store with state management, dirty tracking,
|
|
18
|
-
* validation, and save handling.
|
|
19
|
-
*
|
|
20
|
-
* @param {FormStoreOptions} options - Configuration options
|
|
21
|
-
* @returns {Object} Form store with all state and handlers
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const form = createFormStore({
|
|
25
|
-
* initialData: { name: '', email: '' },
|
|
26
|
-
* endpoint: '/api/profile',
|
|
27
|
-
* validate: (data) => {
|
|
28
|
-
* const errors = {};
|
|
29
|
-
* if (!data.name) errors.name = 'Name is required';
|
|
30
|
-
* return { isValid: Object.keys(errors).length === 0, errors };
|
|
31
|
-
* }
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* // In Svelte component:
|
|
35
|
-
* <input bind:value={$form.data.name} on:input={form.checkDirty} />
|
|
36
|
-
* <button on:click={form.submit} disabled={$form.isLoading}>Save</button>
|
|
37
|
-
*/
|
|
38
|
-
export function createFormStore(options?: FormStoreOptions): Object;
|
|
39
|
-
export type FormStoreOptions = {
|
|
40
|
-
/**
|
|
41
|
-
* - Initial form data
|
|
42
|
-
*/
|
|
43
|
-
initialData: Object;
|
|
44
|
-
/**
|
|
45
|
-
* - API endpoint for saving
|
|
46
|
-
*/
|
|
47
|
-
endpoint?: string | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* - Message to show on success
|
|
50
|
-
*/
|
|
51
|
-
successMessage?: string | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* - Message to show on error
|
|
54
|
-
*/
|
|
55
|
-
errorMessage?: string | undefined;
|
|
56
|
-
/**
|
|
57
|
-
* - Validation function returning { isValid, errors }
|
|
58
|
-
*/
|
|
59
|
-
validate?: Function | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* - Transform data before saving
|
|
62
|
-
*/
|
|
63
|
-
transformData?: Function | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* - Callback after successful save
|
|
66
|
-
*/
|
|
67
|
-
onSuccess?: Function | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* - Callback after error
|
|
70
|
-
*/
|
|
71
|
-
onError?: Function | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* - Show toast notifications
|
|
74
|
-
*/
|
|
75
|
-
showToasts?: boolean | undefined;
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=createFormStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createFormStore.d.ts","sourceRoot":"","sources":["../../src/lib/stores/createFormStore.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,0CAlBW,gBAAgB,GACd,MAAM,CAgXlB;;;;;iBAlYa,MAAM"}
|
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use `@getmicdrop/svelte-components/forms` instead.
|
|
3
|
-
* This Svelte 4 store-based implementation will be removed in the next major version.
|
|
4
|
-
*
|
|
5
|
-
* Migration:
|
|
6
|
-
* ```typescript
|
|
7
|
-
* // Old (Svelte 4 stores):
|
|
8
|
-
* import { createFormStore } from '@getmicdrop/svelte-components/stores/createFormStore';
|
|
9
|
-
* const form = createFormStore({ initialData: {...}, endpoint: '...' });
|
|
10
|
-
*
|
|
11
|
-
* // New (Svelte 5 runes):
|
|
12
|
-
* import { createFormStore } from '@getmicdrop/svelte-components/forms';
|
|
13
|
-
* import { z } from 'zod';
|
|
14
|
-
* const schema = z.object({ name: z.string(), email: z.string().email() });
|
|
15
|
-
* const form = createFormStore(schema, { name: '', email: '' });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
import { writable, derived, get } from "svelte/store";
|
|
19
|
-
import { showToast } from "./toaster";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use createFormStore from '@getmicdrop/svelte-components/forms' instead.
|
|
23
|
-
* @typedef {Object} FormStoreOptions
|
|
24
|
-
* @property {Object} initialData - Initial form data
|
|
25
|
-
* @property {string} [endpoint] - API endpoint for saving
|
|
26
|
-
* @property {string} [successMessage] - Message to show on success
|
|
27
|
-
* @property {string} [errorMessage] - Message to show on error
|
|
28
|
-
* @property {Function} [validate] - Validation function returning { isValid, errors }
|
|
29
|
-
* @property {Function} [transformData] - Transform data before saving
|
|
30
|
-
* @property {Function} [onSuccess] - Callback after successful save
|
|
31
|
-
* @property {Function} [onError] - Callback after error
|
|
32
|
-
* @property {boolean} [showToasts=true] - Show toast notifications
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @deprecated Use createFormStore from '@getmicdrop/svelte-components/forms' instead.
|
|
37
|
-
*
|
|
38
|
-
* Creates a comprehensive form store with state management, dirty tracking,
|
|
39
|
-
* validation, and save handling.
|
|
40
|
-
*
|
|
41
|
-
* @param {FormStoreOptions} options - Configuration options
|
|
42
|
-
* @returns {Object} Form store with all state and handlers
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* const form = createFormStore({
|
|
46
|
-
* initialData: { name: '', email: '' },
|
|
47
|
-
* endpoint: '/api/profile',
|
|
48
|
-
* validate: (data) => {
|
|
49
|
-
* const errors = {};
|
|
50
|
-
* if (!data.name) errors.name = 'Name is required';
|
|
51
|
-
* return { isValid: Object.keys(errors).length === 0, errors };
|
|
52
|
-
* }
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* // In Svelte component:
|
|
56
|
-
* <input bind:value={$form.data.name} on:input={form.checkDirty} />
|
|
57
|
-
* <button on:click={form.submit} disabled={$form.isLoading}>Save</button>
|
|
58
|
-
*/
|
|
59
|
-
export function createFormStore(options = {}) {
|
|
60
|
-
console.warn(
|
|
61
|
-
'[DEPRECATED] createFormStore from stores/createFormStore is deprecated. ' +
|
|
62
|
-
'Use createFormStore from @getmicdrop/svelte-components/forms instead.'
|
|
63
|
-
);
|
|
64
|
-
const {
|
|
65
|
-
initialData = {},
|
|
66
|
-
endpoint = "",
|
|
67
|
-
successMessage = "Changes saved successfully",
|
|
68
|
-
errorMessage = "Failed to save changes",
|
|
69
|
-
validate,
|
|
70
|
-
transformData,
|
|
71
|
-
onSuccess,
|
|
72
|
-
onError,
|
|
73
|
-
showToasts = true,
|
|
74
|
-
} = options;
|
|
75
|
-
|
|
76
|
-
// Deep clone initial data to prevent mutations
|
|
77
|
-
const cloneData = (data) => JSON.parse(JSON.stringify(data));
|
|
78
|
-
|
|
79
|
-
// Core state stores
|
|
80
|
-
const data = writable(cloneData(initialData));
|
|
81
|
-
const initial = writable(cloneData(initialData));
|
|
82
|
-
const errors = writable({});
|
|
83
|
-
const isLoading = writable(false);
|
|
84
|
-
const isSuccess = writable(false);
|
|
85
|
-
const saveError = writable(null);
|
|
86
|
-
const showErrors = writable(false);
|
|
87
|
-
|
|
88
|
-
// Derived states
|
|
89
|
-
const isDirty = derived(
|
|
90
|
-
[data, initial],
|
|
91
|
-
([$data, $initial]) => JSON.stringify($data) !== JSON.stringify($initial)
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const isValid = derived(
|
|
95
|
-
errors,
|
|
96
|
-
($errors) => countErrors($errors) === 0
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const errorCount = derived(
|
|
100
|
-
errors,
|
|
101
|
-
($errors) => countErrors($errors)
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const errorList = derived(
|
|
105
|
-
errors,
|
|
106
|
-
($errors) => flattenErrors($errors)
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Count total errors in a nested error object
|
|
111
|
-
*/
|
|
112
|
-
function countErrors(errorObj) {
|
|
113
|
-
let count = 0;
|
|
114
|
-
const traverse = (obj) => {
|
|
115
|
-
if (!obj || typeof obj !== 'object') return;
|
|
116
|
-
Object.values(obj).forEach(value => {
|
|
117
|
-
if (typeof value === 'string' && value) {
|
|
118
|
-
count++;
|
|
119
|
-
} else if (typeof value === 'object') {
|
|
120
|
-
traverse(value);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
traverse(errorObj);
|
|
125
|
-
return count;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Flatten nested errors into array of { field, message, section }
|
|
130
|
-
*/
|
|
131
|
-
function flattenErrors(errorObj) {
|
|
132
|
-
const list = [];
|
|
133
|
-
const traverse = (obj, section = '') => {
|
|
134
|
-
if (!obj || typeof obj !== 'object') return;
|
|
135
|
-
Object.entries(obj).forEach(([key, value]) => {
|
|
136
|
-
if (typeof value === 'string' && value) {
|
|
137
|
-
list.push({ field: key, message: value, section });
|
|
138
|
-
} else if (typeof value === 'object') {
|
|
139
|
-
traverse(value, key);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
traverse(errorObj);
|
|
144
|
-
return list;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Update form data (partial update)
|
|
149
|
-
*/
|
|
150
|
-
function updateData(updates) {
|
|
151
|
-
data.update(current => ({ ...current, ...updates }));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Update a specific section of form data
|
|
156
|
-
*/
|
|
157
|
-
function updateSection(section, updates) {
|
|
158
|
-
data.update(current => ({
|
|
159
|
-
...current,
|
|
160
|
-
[section]: { ...current[section], ...updates }
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Update a specific field
|
|
166
|
-
*/
|
|
167
|
-
function updateField(section, field, value) {
|
|
168
|
-
data.update(current => ({
|
|
169
|
-
...current,
|
|
170
|
-
[section]: { ...current[section], [field]: value }
|
|
171
|
-
}));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Check if form is dirty (call after data changes)
|
|
176
|
-
*/
|
|
177
|
-
function checkDirty() {
|
|
178
|
-
// Dirty state is computed automatically via derived store
|
|
179
|
-
// Reset success state when dirty
|
|
180
|
-
const dirty = get(isDirty);
|
|
181
|
-
if (dirty) {
|
|
182
|
-
isSuccess.set(false);
|
|
183
|
-
}
|
|
184
|
-
return dirty;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Run validation and update errors
|
|
189
|
-
* @returns {boolean} Whether form is valid
|
|
190
|
-
*/
|
|
191
|
-
function runValidation() {
|
|
192
|
-
if (!validate) {
|
|
193
|
-
errors.set({});
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const currentData = get(data);
|
|
198
|
-
const result = validate(currentData);
|
|
199
|
-
|
|
200
|
-
if (typeof result === 'boolean') {
|
|
201
|
-
// Simple boolean validation
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Object-based validation { isValid, errors }
|
|
206
|
-
errors.set(result.errors || {});
|
|
207
|
-
return result.isValid;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Clear all errors
|
|
212
|
-
*/
|
|
213
|
-
function clearErrors() {
|
|
214
|
-
errors.set({});
|
|
215
|
-
showErrors.set(false);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Clear error for specific field
|
|
220
|
-
*/
|
|
221
|
-
function clearFieldError(section, field) {
|
|
222
|
-
errors.update(current => {
|
|
223
|
-
if (current[section]) {
|
|
224
|
-
const updated = { ...current };
|
|
225
|
-
updated[section] = { ...current[section] };
|
|
226
|
-
delete updated[section][field];
|
|
227
|
-
return updated;
|
|
228
|
-
}
|
|
229
|
-
return current;
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Set error for specific field
|
|
235
|
-
*/
|
|
236
|
-
function setFieldError(section, field, message) {
|
|
237
|
-
errors.update(current => ({
|
|
238
|
-
...current,
|
|
239
|
-
[section]: { ...current[section], [field]: message }
|
|
240
|
-
}));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Submit the form
|
|
245
|
-
* @param {string} [customEndpoint] - Override default endpoint
|
|
246
|
-
* @returns {Promise<boolean>} Success status
|
|
247
|
-
*/
|
|
248
|
-
async function submit(customEndpoint = null) {
|
|
249
|
-
showErrors.set(true);
|
|
250
|
-
|
|
251
|
-
// Run validation
|
|
252
|
-
const valid = runValidation();
|
|
253
|
-
if (!valid) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const targetEndpoint = customEndpoint || endpoint;
|
|
258
|
-
if (!targetEndpoint) {
|
|
259
|
-
console.error("No endpoint specified for form save");
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
isLoading.set(true);
|
|
264
|
-
isSuccess.set(false);
|
|
265
|
-
saveError.set(null);
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
let submitData = get(data);
|
|
269
|
-
|
|
270
|
-
// Transform data if transformer provided
|
|
271
|
-
if (transformData) {
|
|
272
|
-
submitData = transformData(submitData);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const res = await fetch(targetEndpoint, {
|
|
276
|
-
method: "POST",
|
|
277
|
-
headers: { "Content-Type": "application/json" },
|
|
278
|
-
body: JSON.stringify(submitData),
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
if (res.ok) {
|
|
282
|
-
isSuccess.set(true);
|
|
283
|
-
// Update initial data to current (form is now clean)
|
|
284
|
-
initial.set(cloneData(get(data)));
|
|
285
|
-
|
|
286
|
-
if (showToasts && successMessage) {
|
|
287
|
-
showToast(successMessage, "success");
|
|
288
|
-
}
|
|
289
|
-
onSuccess?.();
|
|
290
|
-
return true;
|
|
291
|
-
} else {
|
|
292
|
-
const errorData = await res.json().catch(() => ({}));
|
|
293
|
-
const errorMsg = errorData.message || errorMessage;
|
|
294
|
-
saveError.set(errorMsg);
|
|
295
|
-
|
|
296
|
-
if (showToasts) {
|
|
297
|
-
showToast(errorMsg, "error");
|
|
298
|
-
}
|
|
299
|
-
onError?.(errorMsg);
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
} catch (err) {
|
|
303
|
-
const errorMsg = err.message || "Something went wrong";
|
|
304
|
-
saveError.set(errorMsg);
|
|
305
|
-
|
|
306
|
-
if (showToasts) {
|
|
307
|
-
showToast(errorMsg, "error");
|
|
308
|
-
}
|
|
309
|
-
onError?.(errorMsg);
|
|
310
|
-
return false;
|
|
311
|
-
} finally {
|
|
312
|
-
isLoading.set(false);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Reset form to initial data
|
|
318
|
-
*/
|
|
319
|
-
function reset() {
|
|
320
|
-
data.set(cloneData(get(initial)));
|
|
321
|
-
errors.set({});
|
|
322
|
-
showErrors.set(false);
|
|
323
|
-
isSuccess.set(false);
|
|
324
|
-
saveError.set(null);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Reset form to new initial data
|
|
329
|
-
*/
|
|
330
|
-
function resetTo(newInitialData) {
|
|
331
|
-
const cloned = cloneData(newInitialData);
|
|
332
|
-
initial.set(cloned);
|
|
333
|
-
data.set(cloned);
|
|
334
|
-
errors.set({});
|
|
335
|
-
showErrors.set(false);
|
|
336
|
-
isSuccess.set(false);
|
|
337
|
-
saveError.set(null);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Reset only the success state
|
|
342
|
-
*/
|
|
343
|
-
function resetSuccess() {
|
|
344
|
-
isSuccess.set(false);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Mark form as saved (update initial to match current)
|
|
349
|
-
*/
|
|
350
|
-
function markSaved() {
|
|
351
|
-
initial.set(cloneData(get(data)));
|
|
352
|
-
isSuccess.set(true);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Create a subscribable store that combines all state
|
|
356
|
-
const combinedStore = derived(
|
|
357
|
-
[data, errors, isLoading, isSuccess, saveError, isDirty, isValid, errorCount, showErrors],
|
|
358
|
-
([$data, $errors, $isLoading, $isSuccess, $saveError, $isDirty, $isValid, $errorCount, $showErrors]) => ({
|
|
359
|
-
data: $data,
|
|
360
|
-
errors: $errors,
|
|
361
|
-
isLoading: $isLoading,
|
|
362
|
-
isSuccess: $isSuccess,
|
|
363
|
-
saveError: $saveError,
|
|
364
|
-
isDirty: $isDirty,
|
|
365
|
-
isValid: $isValid,
|
|
366
|
-
errorCount: $errorCount,
|
|
367
|
-
showErrors: $showErrors,
|
|
368
|
-
})
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
return {
|
|
372
|
-
// Subscribable combined store
|
|
373
|
-
subscribe: combinedStore.subscribe,
|
|
374
|
-
|
|
375
|
-
// Individual stores (for direct subscription)
|
|
376
|
-
data,
|
|
377
|
-
errors,
|
|
378
|
-
isLoading,
|
|
379
|
-
isSuccess,
|
|
380
|
-
saveError,
|
|
381
|
-
isDirty,
|
|
382
|
-
isValid,
|
|
383
|
-
errorCount,
|
|
384
|
-
errorList,
|
|
385
|
-
showErrors,
|
|
386
|
-
|
|
387
|
-
// Actions
|
|
388
|
-
updateData,
|
|
389
|
-
updateSection,
|
|
390
|
-
updateField,
|
|
391
|
-
checkDirty,
|
|
392
|
-
runValidation,
|
|
393
|
-
clearErrors,
|
|
394
|
-
clearFieldError,
|
|
395
|
-
setFieldError,
|
|
396
|
-
submit,
|
|
397
|
-
reset,
|
|
398
|
-
resetTo,
|
|
399
|
-
resetSuccess,
|
|
400
|
-
markSaved,
|
|
401
|
-
|
|
402
|
-
// Convenience getters
|
|
403
|
-
get currentData() { return get(data); },
|
|
404
|
-
get currentErrors() { return get(errors); },
|
|
405
|
-
get loading() { return get(isLoading); },
|
|
406
|
-
get success() { return get(isSuccess); },
|
|
407
|
-
get dirty() { return get(isDirty); },
|
|
408
|
-
get valid() { return get(isValid); },
|
|
409
|
-
};
|
|
410
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const profileFormData: import("svelte/store").Writable<{
|
|
2
|
-
basicInfo: {
|
|
3
|
-
firstName: string;
|
|
4
|
-
lastName: string;
|
|
5
|
-
email: string;
|
|
6
|
-
phone: string;
|
|
7
|
-
stageName: string;
|
|
8
|
-
location: string;
|
|
9
|
-
};
|
|
10
|
-
socialMedia: {
|
|
11
|
-
videoLink: string;
|
|
12
|
-
};
|
|
13
|
-
extraDetails: {};
|
|
14
|
-
}>;
|
|
15
|
-
export const initialFormData: import("svelte/store").Writable<null>;
|
|
16
|
-
export const hasChanges: import("svelte/store").Readable<boolean>;
|
|
17
|
-
//# sourceMappingURL=formDataStore.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formDataStore.d.ts","sourceRoot":"","sources":["../../src/lib/stores/formDataStore.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;GAaG;AAEH,oEAA8C;AAE9C,kEAKE"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use the Svelte 5 runes version from './formDataStore.svelte.ts' instead.
|
|
3
|
-
* This file is maintained for backwards compatibility with Svelte 4 components.
|
|
4
|
-
*/
|
|
5
|
-
import { writable, derived } from "svelte/store";
|
|
6
|
-
|
|
7
|
-
console.warn(
|
|
8
|
-
"[DEPRECATED] formDataStore.js is deprecated. Use formDataStore.svelte.ts for Svelte 5 runes."
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
export const profileFormData = writable({
|
|
12
|
-
basicInfo: {
|
|
13
|
-
firstName: "",
|
|
14
|
-
lastName: "",
|
|
15
|
-
email: "",
|
|
16
|
-
phone: "",
|
|
17
|
-
stageName: "",
|
|
18
|
-
location: "",
|
|
19
|
-
},
|
|
20
|
-
socialMedia: {
|
|
21
|
-
videoLink: "",
|
|
22
|
-
},
|
|
23
|
-
extraDetails: {},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const initialFormData = writable(null);
|
|
27
|
-
|
|
28
|
-
export const hasChanges = derived(
|
|
29
|
-
[profileFormData, initialFormData],
|
|
30
|
-
([$profileFormData, $initialFormData]) => {
|
|
31
|
-
return JSON.stringify($profileFormData) !== JSON.stringify($initialFormData);
|
|
32
|
-
}
|
|
33
|
-
);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a form save handler with loading and success states
|
|
3
|
-
* @param {Object} options - Configuration options
|
|
4
|
-
* @param {string} options.endpoint - API endpoint for saving
|
|
5
|
-
* @param {string} options.successMessage - Message to show on success
|
|
6
|
-
* @param {string} options.errorMessage - Message to show on error
|
|
7
|
-
* @param {Function} options.onSuccess - Callback after successful save
|
|
8
|
-
* @param {Function} options.onError - Callback after error
|
|
9
|
-
* @returns {Object} Form save store and handlers
|
|
10
|
-
*/
|
|
11
|
-
export function createFormSave(options?: {
|
|
12
|
-
endpoint: string;
|
|
13
|
-
successMessage: string;
|
|
14
|
-
errorMessage: string;
|
|
15
|
-
onSuccess: Function;
|
|
16
|
-
onError: Function;
|
|
17
|
-
}): Object;
|
|
18
|
-
/**
|
|
19
|
-
* Creates a simple dirty state tracker for forms
|
|
20
|
-
* @param {Object} initialData - Initial form data
|
|
21
|
-
* @returns {Object} Dirty state tracker
|
|
22
|
-
*/
|
|
23
|
-
export function createDirtyTracker(initialData: Object): Object;
|
|
24
|
-
//# sourceMappingURL=formSave.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formSave.d.ts","sourceRoot":"","sources":["../../src/lib/stores/formSave.js"],"names":[],"mappings":"AAWA;;;;;;;;;GASG;AACH,yCAPG;IAAwB,QAAQ,EAAxB,MAAM;IACU,cAAc,EAA9B,MAAM;IACU,YAAY,EAA5B,MAAM;IACY,SAAS;IACT,OAAO;CACjC,GAAU,MAAM,CA6FlB;AAED;;;;GAIG;AACH,gDAHW,MAAM,GACJ,MAAM,CAsBlB"}
|