@getmicdrop/svelte-components 5.7.2 → 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.
Files changed (44) hide show
  1. package/dist/primitives/Checkbox/Checkbox.svelte +3 -3
  2. package/dist/stores/auth.svelte.d.ts +39 -0
  3. package/dist/stores/auth.svelte.d.ts.map +1 -0
  4. package/dist/stores/auth.svelte.js +60 -0
  5. package/dist/stores/formDataStore.svelte.d.ts +47 -0
  6. package/dist/stores/formDataStore.svelte.d.ts.map +1 -0
  7. package/dist/stores/formDataStore.svelte.js +84 -0
  8. package/dist/stores/formSave.svelte.d.ts +33 -0
  9. package/dist/stores/formSave.svelte.d.ts.map +1 -0
  10. package/dist/stores/formSave.svelte.js +113 -0
  11. package/dist/stores/index.d.ts +4 -4
  12. package/dist/stores/index.js +6 -7
  13. package/dist/stores/navigation.svelte.d.ts +35 -0
  14. package/dist/stores/navigation.svelte.d.ts.map +1 -0
  15. package/dist/stores/navigation.svelte.js +69 -0
  16. package/package.json +8 -9
  17. package/dist/stores/auth.js +0 -36
  18. package/dist/stores/auth.spec.d.ts +0 -2
  19. package/dist/stores/auth.spec.d.ts.map +0 -1
  20. package/dist/stores/auth.spec.js +0 -139
  21. package/dist/stores/createFormStore.d.ts +0 -77
  22. package/dist/stores/createFormStore.d.ts.map +0 -1
  23. package/dist/stores/createFormStore.js +0 -410
  24. package/dist/stores/createFormStore.spec.d.ts +0 -2
  25. package/dist/stores/createFormStore.spec.d.ts.map +0 -1
  26. package/dist/stores/createFormStore.spec.js +0 -540
  27. package/dist/stores/formDataStore.d.ts +0 -17
  28. package/dist/stores/formDataStore.d.ts.map +0 -1
  29. package/dist/stores/formDataStore.js +0 -25
  30. package/dist/stores/formDataStore.spec.d.ts +0 -2
  31. package/dist/stores/formDataStore.spec.d.ts.map +0 -1
  32. package/dist/stores/formDataStore.spec.js +0 -257
  33. package/dist/stores/formSave.d.ts +0 -24
  34. package/dist/stores/formSave.d.ts.map +0 -1
  35. package/dist/stores/formSave.js +0 -132
  36. package/dist/stores/formSave.spec.d.ts +0 -2
  37. package/dist/stores/formSave.spec.d.ts.map +0 -1
  38. package/dist/stores/formSave.spec.js +0 -296
  39. package/dist/stores/navigation.d.ts +0 -5
  40. package/dist/stores/navigation.d.ts.map +0 -1
  41. package/dist/stores/navigation.js +0 -12
  42. package/dist/stores/navigation.spec.d.ts +0 -2
  43. package/dist/stores/navigation.spec.d.ts.map +0 -1
  44. package/dist/stores/navigation.spec.js +0 -136
@@ -1,257 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { get } from 'svelte/store';
3
- import { profileFormData, initialFormData, hasChanges } from './formDataStore';
4
-
5
- describe('formDataStore', () => {
6
- beforeEach(() => {
7
- // Reset stores to initial state
8
- profileFormData.set({
9
- basicInfo: {
10
- firstName: '',
11
- lastName: '',
12
- email: '',
13
- phone: '',
14
- stageName: '',
15
- location: '',
16
- },
17
- socialMedia: {
18
- videoLink: '',
19
- },
20
- extraDetails: {},
21
- });
22
- initialFormData.set(null);
23
- });
24
-
25
- describe('profileFormData', () => {
26
- it('has initial structure with basicInfo', () => {
27
- const data = get(profileFormData);
28
- expect(data.basicInfo).toBeDefined();
29
- expect(data.basicInfo.firstName).toBe('');
30
- expect(data.basicInfo.lastName).toBe('');
31
- expect(data.basicInfo.email).toBe('');
32
- });
33
-
34
- it('has initial structure with socialMedia', () => {
35
- const data = get(profileFormData);
36
- expect(data.socialMedia).toBeDefined();
37
- expect(data.socialMedia.videoLink).toBe('');
38
- });
39
-
40
- it('has initial structure with extraDetails', () => {
41
- const data = get(profileFormData);
42
- expect(data.extraDetails).toBeDefined();
43
- });
44
-
45
- it('can be updated', () => {
46
- profileFormData.update((data) => ({
47
- ...data,
48
- basicInfo: {
49
- ...data.basicInfo,
50
- firstName: 'John',
51
- lastName: 'Doe',
52
- },
53
- }));
54
-
55
- const data = get(profileFormData);
56
- expect(data.basicInfo.firstName).toBe('John');
57
- expect(data.basicInfo.lastName).toBe('Doe');
58
- });
59
-
60
- it('can be set completely', () => {
61
- profileFormData.set({
62
- basicInfo: {
63
- firstName: 'Jane',
64
- lastName: 'Smith',
65
- email: 'jane@example.com',
66
- phone: '555-1234',
67
- stageName: 'JSmith',
68
- location: 'LA',
69
- },
70
- socialMedia: {
71
- videoLink: 'https://youtube.com/watch',
72
- },
73
- extraDetails: { bio: 'Test bio' },
74
- });
75
-
76
- const data = get(profileFormData);
77
- expect(data.basicInfo.firstName).toBe('Jane');
78
- expect(data.socialMedia.videoLink).toBe('https://youtube.com/watch');
79
- expect(data.extraDetails.bio).toBe('Test bio');
80
- });
81
- });
82
-
83
- describe('initialFormData', () => {
84
- it('starts as null', () => {
85
- expect(get(initialFormData)).toBe(null);
86
- });
87
-
88
- it('can store form data snapshot', () => {
89
- const snapshot = {
90
- basicInfo: {
91
- firstName: 'Original',
92
- lastName: 'Name',
93
- email: '',
94
- phone: '',
95
- stageName: '',
96
- location: '',
97
- },
98
- socialMedia: { videoLink: '' },
99
- extraDetails: {},
100
- };
101
- initialFormData.set(snapshot);
102
-
103
- expect(get(initialFormData)).toEqual(snapshot);
104
- });
105
- });
106
-
107
- describe('hasChanges (derived store)', () => {
108
- it('is false when both are null/empty', () => {
109
- profileFormData.set({
110
- basicInfo: {
111
- firstName: '',
112
- lastName: '',
113
- email: '',
114
- phone: '',
115
- stageName: '',
116
- location: '',
117
- },
118
- socialMedia: { videoLink: '' },
119
- extraDetails: {},
120
- });
121
- initialFormData.set(null);
122
-
123
- // The comparison will be false because null !== stringified object
124
- expect(get(hasChanges)).toBe(true);
125
- });
126
-
127
- it('is false when form data matches initial', () => {
128
- const data = {
129
- basicInfo: {
130
- firstName: 'John',
131
- lastName: 'Doe',
132
- email: 'john@example.com',
133
- phone: '',
134
- stageName: '',
135
- location: '',
136
- },
137
- socialMedia: { videoLink: '' },
138
- extraDetails: {},
139
- };
140
-
141
- profileFormData.set(data);
142
- initialFormData.set(data);
143
-
144
- expect(get(hasChanges)).toBe(false);
145
- });
146
-
147
- it('is true when form data differs from initial', () => {
148
- const initial = {
149
- basicInfo: {
150
- firstName: 'John',
151
- lastName: 'Doe',
152
- email: 'john@example.com',
153
- phone: '',
154
- stageName: '',
155
- location: '',
156
- },
157
- socialMedia: { videoLink: '' },
158
- extraDetails: {},
159
- };
160
-
161
- const changed = {
162
- ...initial,
163
- basicInfo: { ...initial.basicInfo, firstName: 'Jane' },
164
- };
165
-
166
- initialFormData.set(initial);
167
- profileFormData.set(changed);
168
-
169
- expect(get(hasChanges)).toBe(true);
170
- });
171
-
172
- it('detects changes in socialMedia', () => {
173
- const initial = {
174
- basicInfo: {
175
- firstName: '',
176
- lastName: '',
177
- email: '',
178
- phone: '',
179
- stageName: '',
180
- location: '',
181
- },
182
- socialMedia: { videoLink: '' },
183
- extraDetails: {},
184
- };
185
-
186
- initialFormData.set(initial);
187
- profileFormData.set({
188
- ...initial,
189
- socialMedia: { videoLink: 'https://youtube.com/new' },
190
- });
191
-
192
- expect(get(hasChanges)).toBe(true);
193
- });
194
-
195
- it('detects changes in extraDetails', () => {
196
- const initial = {
197
- basicInfo: {
198
- firstName: '',
199
- lastName: '',
200
- email: '',
201
- phone: '',
202
- stageName: '',
203
- location: '',
204
- },
205
- socialMedia: { videoLink: '' },
206
- extraDetails: {},
207
- };
208
-
209
- initialFormData.set(initial);
210
- profileFormData.set({
211
- ...initial,
212
- extraDetails: { bio: 'New bio' },
213
- });
214
-
215
- expect(get(hasChanges)).toBe(true);
216
- });
217
-
218
- it('updates reactively when form changes', () => {
219
- const initial = {
220
- basicInfo: {
221
- firstName: 'John',
222
- lastName: 'Doe',
223
- email: '',
224
- phone: '',
225
- stageName: '',
226
- location: '',
227
- },
228
- socialMedia: { videoLink: '' },
229
- extraDetails: {},
230
- };
231
-
232
- profileFormData.set(initial);
233
- initialFormData.set(initial);
234
-
235
- // No changes initially
236
- expect(get(hasChanges)).toBe(false);
237
-
238
- // Make a change
239
- profileFormData.update((data) => ({
240
- ...data,
241
- basicInfo: { ...data.basicInfo, firstName: 'Jane' },
242
- }));
243
-
244
- // Now has changes
245
- expect(get(hasChanges)).toBe(true);
246
-
247
- // Revert the change
248
- profileFormData.update((data) => ({
249
- ...data,
250
- basicInfo: { ...data.basicInfo, firstName: 'John' },
251
- }));
252
-
253
- // Back to no changes
254
- expect(get(hasChanges)).toBe(false);
255
- });
256
- });
257
- });
@@ -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":"AAGA;;;;;;;;;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,132 +0,0 @@
1
- import { writable, get } from "svelte/store";
2
- import { showToast } from "./toaster";
3
-
4
- /**
5
- * Creates a form save handler with loading and success states
6
- * @param {Object} options - Configuration options
7
- * @param {string} options.endpoint - API endpoint for saving
8
- * @param {string} options.successMessage - Message to show on success
9
- * @param {string} options.errorMessage - Message to show on error
10
- * @param {Function} options.onSuccess - Callback after successful save
11
- * @param {Function} options.onError - Callback after error
12
- * @returns {Object} Form save store and handlers
13
- */
14
- export function createFormSave(options = {}) {
15
- const {
16
- endpoint = "",
17
- successMessage = "Changes saved successfully",
18
- errorMessage = "Failed to save changes",
19
- onSuccess,
20
- onError,
21
- } = options;
22
-
23
- const isLoading = writable(false);
24
- const isSuccess = writable(false);
25
- const error = writable(null);
26
-
27
- /**
28
- * Reset success state (call when form becomes dirty)
29
- */
30
- function resetSuccess() {
31
- isSuccess.set(false);
32
- }
33
-
34
- /**
35
- * Save form data to the endpoint
36
- * @param {Object} data - Data to save
37
- * @param {string} customEndpoint - Override the default endpoint
38
- * @returns {Promise<boolean>} Success status
39
- */
40
- async function save(data, customEndpoint = null) {
41
- const targetEndpoint = customEndpoint || endpoint;
42
-
43
- if (!targetEndpoint) {
44
- console.error("No endpoint specified for form save");
45
- return false;
46
- }
47
-
48
- isLoading.set(true);
49
- isSuccess.set(false);
50
- error.set(null);
51
-
52
- try {
53
- const res = await fetch(targetEndpoint, {
54
- method: "POST",
55
- headers: { "Content-Type": "application/json" },
56
- body: JSON.stringify(data),
57
- });
58
-
59
- if (res.ok) {
60
- isSuccess.set(true);
61
- if (successMessage) {
62
- showToast(successMessage, "success");
63
- }
64
- onSuccess?.();
65
- return true;
66
- } else {
67
- const errorData = await res.json().catch(() => ({}));
68
- const errorMsg = errorData.message || errorMessage;
69
- error.set(errorMsg);
70
- showToast(errorMsg, "error");
71
- onError?.(errorMsg);
72
- return false;
73
- }
74
- } catch (err) {
75
- const errorMsg = err.message || "Something went wrong";
76
- error.set(errorMsg);
77
- showToast(errorMsg, "error");
78
- onError?.(errorMsg);
79
- return false;
80
- } finally {
81
- isLoading.set(false);
82
- }
83
- }
84
-
85
- /**
86
- * Reset all states
87
- */
88
- function reset() {
89
- isLoading.set(false);
90
- isSuccess.set(false);
91
- error.set(null);
92
- }
93
-
94
- return {
95
- isLoading,
96
- isSuccess,
97
- error,
98
- save,
99
- resetSuccess,
100
- reset,
101
- // Convenience getters
102
- get loading() { return get(isLoading); },
103
- get success() { return get(isSuccess); },
104
- };
105
- }
106
-
107
- /**
108
- * Creates a simple dirty state tracker for forms
109
- * @param {Object} initialData - Initial form data
110
- * @returns {Object} Dirty state tracker
111
- */
112
- export function createDirtyTracker(initialData) {
113
- const isDirty = writable(false);
114
- let initial = JSON.stringify(initialData);
115
-
116
- function check(currentData) {
117
- const dirty = JSON.stringify(currentData) !== initial;
118
- isDirty.set(dirty);
119
- return dirty;
120
- }
121
-
122
- function reset(newInitialData) {
123
- initial = JSON.stringify(newInitialData);
124
- isDirty.set(false);
125
- }
126
-
127
- return {
128
- isDirty,
129
- check,
130
- reset,
131
- };
132
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=formSave.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formSave.spec.d.ts","sourceRoot":"","sources":["../../src/lib/stores/formSave.spec.js"],"names":[],"mappings":""}