@getmicdrop/svelte-components 5.8.0 → 5.8.1

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.
@@ -1,7 +1,7 @@
1
1
  export { createFormStore, createFieldTracker } from "../forms/index";
2
- export { createFormSave, createDirtyTracker } from "./formSave";
3
- export { profileFormData, initialFormData, hasChanges } from "./formDataStore";
4
- export { isSubPage, hideHeaderBackButton, selectedVenueData, isAnimatedNavigation } from "./navigation";
2
+ export { createFormSave, createDirtyTracker } from "./formSave.svelte";
3
+ export { profileFormData, initialFormData, hasChanges } from "./formDataStore.svelte";
4
+ export { isSubPage, hideHeaderBackButton, selectedVenueData, isAnimatedNavigation } from "./navigation.svelte";
5
5
  export { toast, showToast } from "./toaster";
6
- export { auth, setAuthState, clearAuthState, initializeAuthState } from "./auth";
6
+ export { auth, setAuthState, clearAuthState, initializeAuthState } from "./auth.svelte";
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,10 +1,9 @@
1
- // Re-export form utilities from the new location
2
- // These are Svelte 5 runes-based implementations
1
+ // Form utilities (Svelte 5 runes-based)
3
2
  export { createFormStore, createFieldTracker } from '../forms/index';
4
3
 
5
- // Legacy store exports (for backward compatibility)
6
- export { createFormSave, createDirtyTracker } from './formSave';
7
- export { profileFormData, initialFormData, hasChanges } from './formDataStore';
8
- export { isSubPage, hideHeaderBackButton, selectedVenueData, isAnimatedNavigation } from './navigation';
4
+ // Store exports (Svelte 5 runes-based)
5
+ export { createFormSave, createDirtyTracker } from './formSave.svelte';
6
+ export { profileFormData, initialFormData, hasChanges } from './formDataStore.svelte';
7
+ export { isSubPage, hideHeaderBackButton, selectedVenueData, isAnimatedNavigation } from './navigation.svelte';
9
8
  export { toast, showToast } from './toaster';
10
- export { auth, setAuthState, clearAuthState, initializeAuthState, isPerformer } from './auth';
9
+ export { auth, setAuthState, clearAuthState, initializeAuthState } from './auth.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getmicdrop/svelte-components",
3
- "version": "5.8.0",
3
+ "version": "5.8.1",
4
4
  "description": "Shared component library for Micdrop applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -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"}
@@ -1,140 +0,0 @@
1
- /**
2
- * @deprecated Use the Svelte 5 runes version from './formSave.svelte.ts' instead.
3
- * This file is maintained for backwards compatibility with Svelte 4 components.
4
- */
5
- import { writable, get } from "svelte/store";
6
- import { showToast } from "./toaster";
7
-
8
- console.warn(
9
- "[DEPRECATED] formSave.js is deprecated. Use formSave.svelte.ts for Svelte 5 runes."
10
- );
11
-
12
- /**
13
- * Creates a form save handler with loading and success states
14
- * @param {Object} options - Configuration options
15
- * @param {string} options.endpoint - API endpoint for saving
16
- * @param {string} options.successMessage - Message to show on success
17
- * @param {string} options.errorMessage - Message to show on error
18
- * @param {Function} options.onSuccess - Callback after successful save
19
- * @param {Function} options.onError - Callback after error
20
- * @returns {Object} Form save store and handlers
21
- */
22
- export function createFormSave(options = {}) {
23
- const {
24
- endpoint = "",
25
- successMessage = "Changes saved successfully",
26
- errorMessage = "Failed to save changes",
27
- onSuccess,
28
- onError,
29
- } = options;
30
-
31
- const isLoading = writable(false);
32
- const isSuccess = writable(false);
33
- const error = writable(null);
34
-
35
- /**
36
- * Reset success state (call when form becomes dirty)
37
- */
38
- function resetSuccess() {
39
- isSuccess.set(false);
40
- }
41
-
42
- /**
43
- * Save form data to the endpoint
44
- * @param {Object} data - Data to save
45
- * @param {string} customEndpoint - Override the default endpoint
46
- * @returns {Promise<boolean>} Success status
47
- */
48
- async function save(data, customEndpoint = null) {
49
- const targetEndpoint = customEndpoint || endpoint;
50
-
51
- if (!targetEndpoint) {
52
- console.error("No endpoint specified for form save");
53
- return false;
54
- }
55
-
56
- isLoading.set(true);
57
- isSuccess.set(false);
58
- error.set(null);
59
-
60
- try {
61
- const res = await fetch(targetEndpoint, {
62
- method: "POST",
63
- headers: { "Content-Type": "application/json" },
64
- body: JSON.stringify(data),
65
- });
66
-
67
- if (res.ok) {
68
- isSuccess.set(true);
69
- if (successMessage) {
70
- showToast(successMessage, "success");
71
- }
72
- onSuccess?.();
73
- return true;
74
- } else {
75
- const errorData = await res.json().catch(() => ({}));
76
- const errorMsg = errorData.message || errorMessage;
77
- error.set(errorMsg);
78
- showToast(errorMsg, "error");
79
- onError?.(errorMsg);
80
- return false;
81
- }
82
- } catch (err) {
83
- const errorMsg = err.message || "Something went wrong";
84
- error.set(errorMsg);
85
- showToast(errorMsg, "error");
86
- onError?.(errorMsg);
87
- return false;
88
- } finally {
89
- isLoading.set(false);
90
- }
91
- }
92
-
93
- /**
94
- * Reset all states
95
- */
96
- function reset() {
97
- isLoading.set(false);
98
- isSuccess.set(false);
99
- error.set(null);
100
- }
101
-
102
- return {
103
- isLoading,
104
- isSuccess,
105
- error,
106
- save,
107
- resetSuccess,
108
- reset,
109
- // Convenience getters
110
- get loading() { return get(isLoading); },
111
- get success() { return get(isSuccess); },
112
- };
113
- }
114
-
115
- /**
116
- * Creates a simple dirty state tracker for forms
117
- * @param {Object} initialData - Initial form data
118
- * @returns {Object} Dirty state tracker
119
- */
120
- export function createDirtyTracker(initialData) {
121
- const isDirty = writable(false);
122
- let initial = JSON.stringify(initialData);
123
-
124
- function check(currentData) {
125
- const dirty = JSON.stringify(currentData) !== initial;
126
- isDirty.set(dirty);
127
- return dirty;
128
- }
129
-
130
- function reset(newInitialData) {
131
- initial = JSON.stringify(newInitialData);
132
- isDirty.set(false);
133
- }
134
-
135
- return {
136
- isDirty,
137
- check,
138
- reset,
139
- };
140
- }
@@ -1,5 +0,0 @@
1
- export const isSubPage: import("svelte/store").Writable<boolean>;
2
- export const hideHeaderBackButton: import("svelte/store").Writable<boolean>;
3
- export const selectedVenueData: import("svelte/store").Writable<null>;
4
- export const isAnimatedNavigation: import("svelte/store").Writable<boolean>;
5
- //# sourceMappingURL=navigation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../src/lib/stores/navigation.js"],"names":[],"mappings":"AAUA,iEAAyC;AAGzC,4EAAoD;AAGpD,sEAAgD;AAGhD,4EAAoD"}
@@ -1,20 +0,0 @@
1
- /**
2
- * @deprecated Use the Svelte 5 runes version from './navigation.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] navigation.js is deprecated. Use navigation.svelte.ts for Svelte 5 runes."
9
- );
10
-
11
- export const isSubPage = writable(false);
12
-
13
- // Pages can set this to true to hide the header back button (e.g., when they have their own)
14
- export const hideHeaderBackButton = writable(false);
15
-
16
- // Store venue data when navigating to calendar to avoid re-fetching
17
- export const selectedVenueData = writable(null);
18
-
19
- // Flag to indicate we're doing an animated navigation (not a refresh/direct load)
20
- export const isAnimatedNavigation = writable(false);