@finsweet/webflow-apps-utils 1.0.3 → 1.0.5

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 (116) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/providers/GlobalProvider.stories.d.ts +5 -0
  4. package/dist/providers/GlobalProvider.stories.js +419 -0
  5. package/dist/providers/GlobalProviderDemo.svelte +266 -0
  6. package/dist/providers/GlobalProviderDemo.svelte.d.ts +3 -0
  7. package/dist/providers/configuratorUtils.d.ts +11 -14
  8. package/dist/providers/configuratorUtils.js +68 -115
  9. package/dist/providers/index.d.ts +1 -1
  10. package/dist/providers/index.js +1 -1
  11. package/dist/router/Router.stories.d.ts +6 -0
  12. package/dist/router/Router.stories.js +564 -0
  13. package/dist/router/examples/RouterExample.svelte +271 -0
  14. package/dist/router/examples/RouterExample.svelte.d.ts +18 -0
  15. package/dist/router/examples/index.d.ts +4 -0
  16. package/dist/router/examples/index.js +4 -0
  17. package/dist/router/examples/pages/AboutPage.svelte +568 -0
  18. package/dist/router/examples/pages/AboutPage.svelte.d.ts +13 -0
  19. package/dist/router/examples/pages/HomePage.svelte +200 -0
  20. package/dist/router/examples/pages/HomePage.svelte.d.ts +14 -0
  21. package/dist/router/examples/pages/NotFoundPage.svelte +307 -0
  22. package/dist/router/examples/pages/NotFoundPage.svelte.d.ts +17 -0
  23. package/dist/router/hooks.svelte.d.ts +2 -2
  24. package/dist/router/index.d.ts +3 -0
  25. package/dist/router/index.js +3 -0
  26. package/dist/router/{Link.svelte → providers/Link.svelte} +1 -1
  27. package/dist/router/{Route.svelte → providers/Route.svelte} +1 -1
  28. package/dist/router/{Route.svelte.d.ts → providers/Route.svelte.d.ts} +1 -1
  29. package/dist/router/{Router.svelte → providers/RouterProvider.svelte} +22 -5
  30. package/dist/router/{Router.svelte.d.ts → providers/RouterProvider.svelte.d.ts} +8 -4
  31. package/dist/router/providers/index.d.ts +3 -0
  32. package/dist/router/providers/index.js +3 -0
  33. package/dist/router/{index.svelte.d.ts → router.svelte.d.ts} +1 -3
  34. package/dist/router/{index.svelte.js → router.svelte.js} +1 -4
  35. package/dist/stores/forms/Form.stories.d.ts +5 -0
  36. package/dist/stores/forms/Form.stories.js +342 -0
  37. package/dist/stores/forms/FormDemo.svelte +545 -0
  38. package/dist/stores/forms/FormDemo.svelte.d.ts +18 -0
  39. package/dist/stores/forms.d.ts +41 -4
  40. package/dist/stores/forms.js +86 -32
  41. package/dist/types/customCode.d.ts +1 -1
  42. package/dist/types/window.d.ts +1 -0
  43. package/dist/ui/components/button/Button.svelte +1 -1
  44. package/dist/ui/components/copy-text/CopyText.stories.d.ts +70 -0
  45. package/dist/ui/components/copy-text/CopyText.stories.js +241 -0
  46. package/dist/ui/components/copy-text/CopyText.svelte +247 -0
  47. package/dist/ui/components/copy-text/CopyText.svelte.d.ts +4 -0
  48. package/dist/ui/components/copy-text/index.d.ts +2 -0
  49. package/dist/ui/components/copy-text/index.js +1 -0
  50. package/dist/ui/components/copy-text/types.d.ts +52 -0
  51. package/dist/ui/components/copy-text/types.js +1 -0
  52. package/dist/ui/components/index.d.ts +1 -0
  53. package/dist/ui/components/index.js +1 -0
  54. package/dist/ui/components/input/Input.stories.d.ts +9 -0
  55. package/dist/ui/components/input/Input.stories.js +78 -0
  56. package/dist/ui/components/input/Input.svelte +39 -3
  57. package/dist/ui/components/input/types.d.ts +6 -0
  58. package/dist/ui/components/layout/Layout.svelte +45 -64
  59. package/dist/ui/components/layout/Layout.svelte.d.ts +26 -3
  60. package/dist/ui/components/layout/examples/ExampleLayout.svelte +32 -27
  61. package/dist/ui/components/layout/index.d.ts +1 -1
  62. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte +20 -0
  63. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte.d.ts +7 -0
  64. package/dist/ui/components/layout/types.d.ts +1 -10
  65. package/dist/ui/components/notification/Notification.stories.svelte +12 -1
  66. package/dist/ui/components/notification/Notification.svelte +10 -5
  67. package/dist/ui/components/notification/Notification.svelte.d.ts +1 -1
  68. package/dist/ui/components/notification/types.d.ts +1 -1
  69. package/dist/ui/components/section/Section.svelte +8 -4
  70. package/dist/ui/components/section/types.d.ts +8 -0
  71. package/dist/ui/components/text/Text.stories.svelte +67 -1
  72. package/dist/ui/components/text/Text.svelte +209 -8
  73. package/dist/ui/components/text/types.d.ts +4 -0
  74. package/dist/ui/index.css +6 -2
  75. package/dist/utils/animations/factory.d.ts +7 -0
  76. package/dist/utils/animations/factory.js +101 -0
  77. package/dist/utils/animations/index.d.ts +7 -0
  78. package/dist/utils/animations/index.js +62 -0
  79. package/dist/utils/animations/types.d.ts +39 -0
  80. package/dist/utils/animations/types.js +1 -0
  81. package/dist/utils/custom-code/configs.d.ts +22 -0
  82. package/dist/utils/custom-code/configs.js +40 -0
  83. package/dist/utils/custom-code/index.d.ts +1 -0
  84. package/dist/utils/custom-code/index.js +1 -0
  85. package/dist/utils/diff-mapper/DiffMapper.stories.d.ts +5 -0
  86. package/dist/utils/diff-mapper/DiffMapper.stories.js +185 -0
  87. package/dist/utils/diff-mapper/DiffMapperDemo.svelte +351 -0
  88. package/dist/utils/diff-mapper/DiffMapperDemo.svelte.d.ts +18 -0
  89. package/dist/utils/diff-mapper/deepDiffMapper.d.ts +31 -0
  90. package/dist/utils/diff-mapper/deepDiffMapper.js +264 -0
  91. package/dist/utils/diff-mapper/index.d.ts +1 -0
  92. package/dist/utils/diff-mapper/index.js +1 -0
  93. package/dist/utils/helpers/capitalizeFirstLetter.d.ts +4 -0
  94. package/dist/utils/helpers/capitalizeFirstLetter.js +9 -0
  95. package/dist/utils/helpers/getTimeNow.d.ts +4 -0
  96. package/dist/utils/helpers/getTimeNow.js +8 -0
  97. package/dist/utils/helpers/index.d.ts +4 -0
  98. package/dist/utils/helpers/index.js +4 -0
  99. package/dist/utils/helpers/minifyCode.d.ts +10 -0
  100. package/dist/utils/helpers/minifyCode.js +73 -0
  101. package/dist/utils/helpers/objectsToModuleExports.d.ts +1 -1
  102. package/dist/utils/helpers/objectsToModuleExports.js +1 -0
  103. package/dist/utils/helpers/toHumanReadableList.d.ts +4 -0
  104. package/dist/utils/helpers/toHumanReadableList.js +11 -0
  105. package/dist/utils/index.d.ts +2 -0
  106. package/dist/utils/index.js +2 -0
  107. package/dist/utils/webflow-canvas/getAllChildren.d.ts +16 -0
  108. package/dist/utils/webflow-canvas/getAllChildren.js +65 -0
  109. package/dist/utils/webflow-canvas/getElementClassList.d.ts +9 -0
  110. package/dist/utils/webflow-canvas/getElementClassList.js +19 -0
  111. package/dist/utils/webflow-canvas/index.d.ts +2 -0
  112. package/dist/utils/webflow-canvas/index.js +2 -0
  113. package/package.json +6 -1
  114. package/dist/providers/GlobalProvider.mdx +0 -322
  115. package/dist/router/README.md +0 -397
  116. /package/dist/router/{Link.svelte.d.ts → providers/Link.svelte.d.ts} +0 -0
@@ -1,18 +1,23 @@
1
+ import { type DiffMap, type DiffResult } from '../utils/diff-mapper';
1
2
  import type { ConfiguratorState, ConfiguratorWatchOptions } from './types';
2
3
  /**
3
4
  * Create default configurator state
4
5
  */
5
6
  export declare function createDefaultConfiguratorState<T = Record<string, any>>(): ConfiguratorState<T>;
6
7
  /**
7
- * Deep compare two objects with performance optimizations
8
+ * Use deepDiffMapper to compare objects and determine if there are any changes
8
9
  */
9
- export declare function deepCompare<T>(obj1: T, obj2: T): boolean;
10
+ export declare function hasChangesViaDiff<T>(current: T, updated: T): boolean;
10
11
  /**
11
- * Compare specific keys of two objects with optimization
12
+ * Get detailed diff information using deepDiffMapper
12
13
  */
13
- export declare function compareKeys<T extends Record<string, any>>(obj1: T | null, obj2: T | null, keys: string[]): boolean;
14
+ export declare function getDetailedDiff<T>(current: T, updated: T): DiffResult | DiffMap;
14
15
  /**
15
- * Determine if configurator has changed with performance optimization
16
+ * Compare specific keys of two objects with optimization using deepDiffMapper
17
+ */
18
+ export declare function compareKeys<T extends Record<string, any>>(current: T | null, updated: T | null, keys: string[]): boolean;
19
+ /**
20
+ * Determine if configurator has changed with performance optimization using deepDiffMapper
16
21
  */
17
22
  export declare function hasConfiguratorChanged<T extends Record<string, any>>(configurator: T | null, configuratorCache: T | null, watchOptions: ConfiguratorWatchOptions): boolean;
18
23
  /**
@@ -22,16 +27,8 @@ export declare function createDebouncedUpdate<T extends (...args: any[]) => void
22
27
  /**
23
28
  * Extract specific keys from an object
24
29
  */
25
- export declare function extractKeys<T extends Record<string, any>>(obj: T | null, keys: string[]): Partial<T> | null;
26
- /**
27
- * Get all keys from an object (for watchAll mode)
28
- */
29
- export declare function getAllKeys<T extends Record<string, any>>(obj: T | null): string[];
30
+ export declare function extractKeys<T extends Record<string, any>>(current: T | null, keys: string[]): Partial<T> | null;
30
31
  /**
31
32
  * Validate watch options
32
33
  */
33
34
  export declare function validateWatchOptions(options: ConfiguratorWatchOptions): ConfiguratorWatchOptions;
34
- /**
35
- * Create a snapshot of configurator state for comparison
36
- */
37
- export declare function createConfiguratorSnapshot<T extends Record<string, any>>(configurator: T | null, watchOptions: ConfiguratorWatchOptions): T | Partial<T> | null;
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { deepDiffMapper, DiffType } from '../utils/diff-mapper';
1
3
  /**
2
4
  * Create default configurator state
3
5
  */
@@ -13,118 +15,88 @@ export function createDefaultConfiguratorState() {
13
15
  }
14
16
  };
15
17
  }
16
- // Cache for deep comparison results to avoid repeated expensive operations
17
- const comparisonCache = new Map();
18
+ // Cache for diff comparison results to avoid repeated expensive operations
19
+ const diffCache = new Map();
18
20
  const CACHE_TTL = 1000;
19
21
  /**
20
- * Optimized deep compare with caching and early returns
22
+ * Use deepDiffMapper to compare objects and determine if there are any changes
21
23
  */
22
- function deepEqual(obj1, obj2, maxDepth = 10) {
23
- if (obj1 === obj2)
24
- return true;
25
- if (maxDepth <= 0)
26
- return obj1 === obj2;
27
- if (obj1 == null || obj2 == null)
28
- return obj1 === obj2;
29
- const type1 = typeof obj1;
30
- const type2 = typeof obj2;
31
- if (type1 !== type2)
32
- return false;
33
- if (type1 !== 'object')
34
- return obj1 === obj2;
35
- const isArray1 = Array.isArray(obj1);
36
- const isArray2 = Array.isArray(obj2);
37
- if (isArray1 !== isArray2)
38
- return false;
39
- if (isArray1) {
40
- if (obj1.length !== obj2.length)
41
- return false;
42
- for (let i = 0; i < obj1.length; i++) {
43
- if (!deepEqual(obj1[i], obj2[i], maxDepth - 1))
44
- return false;
45
- }
46
- return true;
47
- }
48
- const keys1 = Object.keys(obj1);
49
- const keys2 = Object.keys(obj2);
50
- if (keys1.length !== keys2.length)
24
+ export function hasChangesViaDiff(current, updated) {
25
+ if (current === updated)
51
26
  return false;
52
- keys1.sort();
53
- keys2.sort();
54
- for (let i = 0; i < keys1.length; i++) {
55
- if (keys1[i] !== keys2[i])
56
- return false;
27
+ const cacheKey = JSON.stringify([current, updated]);
28
+ const cached = diffCache.get(cacheKey);
29
+ let diff;
30
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
31
+ diff = cached.result;
57
32
  }
58
- for (const key of keys1) {
59
- if (!deepEqual(obj1[key], obj2[key], maxDepth - 1))
60
- return false;
33
+ else {
34
+ diff = deepDiffMapper.compare(current, updated);
35
+ diffCache.set(cacheKey, { result: diff, timestamp: Date.now() });
36
+ // Clean old cache entries periodically
37
+ if (diffCache.size > 100) {
38
+ const now = Date.now();
39
+ for (const [key, value] of diffCache.entries()) {
40
+ if (now - value.timestamp > CACHE_TTL) {
41
+ diffCache.delete(key);
42
+ }
43
+ }
44
+ }
61
45
  }
62
- return true;
46
+ // Check if there are any meaningful changes
47
+ return hasAnyChanges(diff);
63
48
  }
64
49
  /**
65
- * Fast shallow comparison for primitive values and first-level objects
50
+ * Recursively check if a diff result contains any actual changes
66
51
  */
67
- function shallowCompare(obj1, obj2) {
68
- if (obj1 === obj2)
69
- return true;
70
- if (obj1 == null || obj2 == null)
71
- return obj1 === obj2;
72
- if (typeof obj1 !== 'object' || typeof obj2 !== 'object')
73
- return obj1 === obj2;
74
- const keys1 = Object.keys(obj1);
75
- const keys2 = Object.keys(obj2);
76
- if (keys1.length !== keys2.length)
77
- return false;
78
- for (const key of keys1) {
79
- if (obj1[key] !== obj2[key])
80
- return false;
52
+ function hasAnyChanges(diff) {
53
+ // If it's a DiffResult, check if it's not UNCHANGED
54
+ if (diff && typeof diff === 'object' && 'type' in diff && 'data' in diff) {
55
+ return diff.type !== DiffType.UNCHANGED;
81
56
  }
82
- return true;
57
+ // If it's a DiffMap, check all properties recursively
58
+ if (diff && typeof diff === 'object') {
59
+ for (const key in diff) {
60
+ if (hasAnyChanges(diff[key])) {
61
+ return true;
62
+ }
63
+ }
64
+ }
65
+ return false;
83
66
  }
84
67
  /**
85
- * Deep compare two objects with performance optimizations
68
+ * Get detailed diff information using deepDiffMapper
86
69
  */
87
- export function deepCompare(obj1, obj2) {
88
- if (shallowCompare(obj1, obj2))
89
- return true;
90
- const cacheKey = JSON.stringify([obj1, obj2]);
91
- const cached = comparisonCache.get(cacheKey);
70
+ export function getDetailedDiff(current, updated) {
71
+ const cacheKey = JSON.stringify([current, updated]);
72
+ const cached = diffCache.get(cacheKey);
92
73
  if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
93
74
  return cached.result;
94
75
  }
95
- const result = deepEqual(obj1, obj2, 5);
96
- comparisonCache.set(cacheKey, { result, timestamp: Date.now() });
97
- // Clean old cache entries periodically
98
- if (comparisonCache.size > 100) {
99
- const now = Date.now();
100
- for (const [key, value] of comparisonCache.entries()) {
101
- if (now - value.timestamp > CACHE_TTL) {
102
- comparisonCache.delete(key);
103
- }
104
- }
105
- }
106
- return result;
76
+ const diff = deepDiffMapper.compare(current, updated);
77
+ diffCache.set(cacheKey, { result: diff, timestamp: Date.now() });
78
+ return diff;
107
79
  }
108
80
  /**
109
- * Compare specific keys of two objects with optimization
81
+ * Compare specific keys of two objects with optimization using deepDiffMapper
110
82
  */
111
- export function compareKeys(obj1, obj2, keys) {
112
- if (!obj1 && !obj2)
83
+ export function compareKeys(current, updated, keys) {
84
+ if (!current && !updated)
113
85
  return true;
114
- if (!obj1 || !obj2)
86
+ if (!current || !updated)
115
87
  return false;
116
88
  if (keys.length === 0)
117
89
  return true;
118
90
  if (keys.length === 1) {
119
91
  const key = keys[0];
120
- return obj1[key] === obj2[key] || deepCompare(obj1[key], obj2[key]);
92
+ return !hasChangesViaDiff(current[key], updated[key]);
121
93
  }
122
94
  for (const key of keys) {
123
- const val1 = obj1[key];
124
- const val2 = obj2[key];
95
+ const val1 = current[key];
96
+ const val2 = updated[key];
125
97
  if (val1 === val2)
126
98
  continue;
127
- if (!deepCompare(val1, val2)) {
99
+ if (hasChangesViaDiff(val1, val2)) {
128
100
  return false;
129
101
  }
130
102
  }
@@ -133,7 +105,7 @@ export function compareKeys(obj1, obj2, keys) {
133
105
  // Debounce storage
134
106
  const debounceTimers = new Map();
135
107
  /**
136
- * Determine if configurator has changed with performance optimization
108
+ * Determine if configurator has changed with performance optimization using deepDiffMapper
137
109
  */
138
110
  export function hasConfiguratorChanged(configurator, configuratorCache, watchOptions) {
139
111
  if (!configurator && !configuratorCache)
@@ -141,14 +113,17 @@ export function hasConfiguratorChanged(configurator, configuratorCache, watchOpt
141
113
  if (!configurator || !configuratorCache)
142
114
  return true;
143
115
  if (watchOptions.watchAll) {
144
- if (shallowCompare(configurator, configuratorCache))
145
- return false;
146
- return !deepCompare(configurator, configuratorCache);
116
+ // Use deepDiffMapper for comprehensive comparison with type coercion and better edge case handling
117
+ return hasChangesViaDiff(configurator, configuratorCache);
147
118
  }
148
119
  if (watchOptions.watchKeys && watchOptions.watchKeys.length > 0) {
149
- return !compareKeys(configurator, configuratorCache, watchOptions.watchKeys);
120
+ // Extract only the watched keys and compare them
121
+ const extracted1 = extractKeys(configurator, watchOptions.watchKeys);
122
+ const extracted2 = extractKeys(configuratorCache, watchOptions.watchKeys);
123
+ return hasChangesViaDiff(extracted1, extracted2);
150
124
  }
151
- return !shallowCompare(configurator, configuratorCache);
125
+ // For minimal watch (no specific keys), fallback to full comparison with diff mapper
126
+ return hasChangesViaDiff(configurator, configuratorCache);
152
127
  }
153
128
  /**
154
129
  * Create a debounced function for configurator updates
@@ -170,25 +145,17 @@ export function createDebouncedUpdate(fn, delay) {
170
145
  /**
171
146
  * Extract specific keys from an object
172
147
  */
173
- export function extractKeys(obj, keys) {
174
- if (!obj || keys.length === 0)
148
+ export function extractKeys(current, keys) {
149
+ if (!current || keys.length === 0)
175
150
  return null;
176
151
  const result = {};
177
152
  for (const key of keys) {
178
- if (key in obj) {
179
- result[key] = obj[key];
153
+ if (key in current) {
154
+ result[key] = current[key];
180
155
  }
181
156
  }
182
157
  return result;
183
158
  }
184
- /**
185
- * Get all keys from an object (for watchAll mode)
186
- */
187
- export function getAllKeys(obj) {
188
- if (!obj)
189
- return [];
190
- return Object.keys(obj);
191
- }
192
159
  /**
193
160
  * Validate watch options
194
161
  */
@@ -203,17 +170,3 @@ export function validateWatchOptions(options) {
203
170
  }
204
171
  return validated;
205
172
  }
206
- /**
207
- * Create a snapshot of configurator state for comparison
208
- */
209
- export function createConfiguratorSnapshot(configurator, watchOptions) {
210
- if (!configurator)
211
- return null;
212
- if (watchOptions.watchAll) {
213
- return { ...configurator };
214
- }
215
- if (watchOptions.watchKeys && watchOptions.watchKeys.length > 0) {
216
- return extractKeys(configurator, watchOptions.watchKeys);
217
- }
218
- return { ...configurator };
219
- }
@@ -2,4 +2,4 @@ export { default as GlobalProvider } from './GlobalProvider.svelte';
2
2
  export { createGlobalContext, setGlobalContext, getGlobalContext, useContext, useFormContext, useAppContext, useDataContext, useConfiguratorContext } from './globalContext.svelte.js';
3
3
  export type { FormContextState, AppContextState, DataContextState, ContextState, GlobalContextState, ContextOperations, GlobalContextOperations, GlobalProviderProps, ContextEvent, GlobalContextEvent, ContextKey, ContextId, ConfiguratorWatchOptions, ConfiguratorState, AppContextData, FormContextData, DataContextData } from './types.js';
4
4
  export { CONTEXT_KEYS } from './types.js';
5
- export { deepCompare, compareKeys, hasConfiguratorChanged, createDebouncedUpdate, extractKeys, getAllKeys, validateWatchOptions, createConfiguratorSnapshot, createDefaultConfiguratorState } from './configuratorUtils';
5
+ export { hasChangesViaDiff, getDetailedDiff, compareKeys, hasConfiguratorChanged, createDebouncedUpdate, extractKeys, validateWatchOptions, createDefaultConfiguratorState } from './configuratorUtils';
@@ -4,4 +4,4 @@ export { default as GlobalProvider } from './GlobalProvider.svelte';
4
4
  export { createGlobalContext, setGlobalContext, getGlobalContext, useContext, useFormContext, useAppContext, useDataContext, useConfiguratorContext } from './globalContext.svelte.js';
5
5
  export { CONTEXT_KEYS } from './types.js';
6
6
  // Configurator utilities
7
- export { deepCompare, compareKeys, hasConfiguratorChanged, createDebouncedUpdate, extractKeys, getAllKeys, validateWatchOptions, createConfiguratorSnapshot, createDefaultConfiguratorState } from './configuratorUtils';
7
+ export { hasChangesViaDiff, getDetailedDiff, compareKeys, hasConfiguratorChanged, createDebouncedUpdate, extractKeys, validateWatchOptions, createDefaultConfiguratorState } from './configuratorUtils';
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from '@storybook/sveltekit';
2
+ import RouterExample from './examples/RouterExample.svelte';
3
+ declare const meta: Meta<typeof RouterExample>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof meta>;
6
+ export declare const CompleteExample: Story;