@finsweet/webflow-apps-utils 1.0.4 → 1.0.6

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 (36) hide show
  1. package/dist/providers/GlobalProvider.stories.d.ts +5 -0
  2. package/dist/providers/GlobalProvider.stories.js +419 -0
  3. package/dist/providers/GlobalProviderDemo.svelte +266 -0
  4. package/dist/providers/GlobalProviderDemo.svelte.d.ts +3 -0
  5. package/dist/providers/configuratorUtils.d.ts +11 -14
  6. package/dist/providers/configuratorUtils.js +68 -115
  7. package/dist/providers/index.d.ts +1 -1
  8. package/dist/providers/index.js +1 -1
  9. package/dist/router/Router.stories.js +519 -2
  10. package/dist/stores/forms/Form.stories.d.ts +5 -0
  11. package/dist/stores/forms/Form.stories.js +342 -0
  12. package/dist/stores/forms/FormDemo.svelte +545 -0
  13. package/dist/stores/forms/FormDemo.svelte.d.ts +18 -0
  14. package/dist/ui/components/button/Button.svelte +1 -1
  15. package/dist/ui/components/copy-text/CopyText.stories.js +1 -1
  16. package/dist/ui/components/copy-text/CopyText.svelte +17 -19
  17. package/dist/ui/components/input/Input.svelte +18 -22
  18. package/dist/ui/components/layout/Layout.svelte +38 -5
  19. package/dist/ui/components/layout/Layout.svelte.d.ts +24 -1
  20. package/dist/ui/components/layout/examples/ExampleLayout.svelte +12 -12
  21. package/dist/ui/components/section/Section.svelte +4 -2
  22. package/dist/ui/index.css +6 -2
  23. package/dist/utils/diff-mapper/DiffMapper.stories.d.ts +5 -0
  24. package/dist/utils/diff-mapper/DiffMapper.stories.js +185 -0
  25. package/dist/utils/diff-mapper/DiffMapperDemo.svelte +351 -0
  26. package/dist/utils/diff-mapper/DiffMapperDemo.svelte.d.ts +18 -0
  27. package/dist/utils/diff-mapper/deepDiffMapper.d.ts +31 -0
  28. package/dist/utils/diff-mapper/deepDiffMapper.js +264 -0
  29. package/dist/utils/diff-mapper/index.d.ts +1 -0
  30. package/dist/utils/diff-mapper/index.js +1 -0
  31. package/dist/utils/index.d.ts +1 -0
  32. package/dist/utils/index.js +1 -0
  33. package/package.json +1 -1
  34. package/dist/providers/GlobalProvider.mdx +0 -322
  35. package/dist/router/Router.mdx +0 -958
  36. package/dist/stores/docs/Form.mdx +0 -542
@@ -1,322 +0,0 @@
1
- # GlobalProvider
2
-
3
- The `GlobalProvider` is a context management system built on Svelte 5 that manages multiple application contexts in a type-safe and reactive way.
4
-
5
- ## Features
6
-
7
- - **Multiple Contexts**: Manage different types of state (form, app, data, etc.) in separate contexts
8
- - **Type Safety**: Full TypeScript support with branded types and generics
9
- - **Reactive**: Built on Svelte 5 runes for optimal reactivity
10
- - **Event System**: Subscribe to context changes and global events (batched for performance)
11
-
12
- ## Basic Usage
13
-
14
- ### Wrap Your App
15
-
16
- ```svelte
17
- <script lang="ts">
18
- import { GlobalProvider } from '$lib/providers';
19
-
20
- const initialContexts = {
21
- app: {
22
- editMode: false,
23
- repairMode: false,
24
- title: 'My App'
25
- },
26
- form: {
27
- formKey: null,
28
- formUpdateKey: null
29
- }
30
- };
31
- </script>
32
-
33
- <GlobalProvider {initialContexts} debug={true}>
34
- <App />
35
- </GlobalProvider>
36
- ```
37
-
38
- ### Default Contexts
39
-
40
- The `GlobalProvider` automatically creates these default contexts:
41
-
42
- - **`app`**: Application state (editMode, repairMode, title, configurator)
43
- - **`form`**: Form state (formKey, formUpdateKey)
44
- - **`data`**: General data state
45
-
46
- ### Use Contexts in Components
47
-
48
- ```svelte
49
- <script lang="ts">
50
- import { useAppContext, useFormContext, useDataContext } from '$lib/providers';
51
-
52
- const appContext = useAppContext();
53
- const formContext = useFormContext();
54
- const dataContext = useDataContext();
55
-
56
- let appData = $derived(appContext.get());
57
- let formData = $derived(formContext.get());
58
-
59
- function toggleEditMode() {
60
- appContext.update((current) => ({
61
- ...current,
62
- editMode: !current?.editMode
63
- }));
64
- }
65
- </script>
66
-
67
- <div>
68
- <p>Edit Mode: {appData?.editMode}</p>
69
- <p>Form Key: {formData?.formKey}</p>
70
- <button onclick={toggleEditMode}>Toggle Edit Mode</button>
71
- </div>
72
- ```
73
-
74
- ## API Reference
75
-
76
- ### Context Operations
77
-
78
- #### `get(): T | null`
79
-
80
- Returns the current context data. Returns `undefined` if the context has been reset (completely removed).
81
-
82
- #### `set(data: Partial<T>): void`
83
-
84
- Sets context data (merges with existing data).
85
-
86
- #### `update(updater: (current: T | null) => T): void`
87
-
88
- Updates context data using an updater function.
89
-
90
- #### `clear(): void`
91
-
92
- Clears context data (sets to null). The context remains active but with null data.
93
-
94
- #### `reset(): void`
95
-
96
- Completely removes the context. After reset, `hasContext()` returns false and `get()` returns `undefined`.
97
-
98
- #### `subscribe(callback: (data: T | null) => void): () => void`
99
-
100
- Subscribes to context changes. Returns unsubscribe function. **Note**: Events are batched and emitted asynchronously for performance.
101
-
102
- ### Global Operations
103
-
104
- - `getContext<T>(key: string): ContextOperations<T>` - Get context operations for a key
105
- - `hasContext(key: string): boolean` - Check if context exists
106
- - `removeContext(key: string): void` - Remove a specific context
107
- - `clearAll(): void` - Clear all context data (set to null)
108
- - `resetAll(): void` - Reset all contexts (completely remove them)
109
- - `resetByKey(key: string): void` - Reset a specific context by key
110
- - `getActiveContexts(): string[]` - Get list of active context keys
111
- - `getAllContexts(): Record<string, unknown>` - Get all context data
112
- - `getContextMetadata(key: string)` - Get metadata (version, updatedAt, isActive) for a context
113
- - `subscribe(callback): () => void` - Subscribe to global context events
114
-
115
- ## Examples
116
-
117
- ### App State Management
118
-
119
- ```svelte
120
- <script lang="ts">
121
- import { useAppContext } from '$lib/providers';
122
-
123
- const appContext = useAppContext();
124
- let appData = $derived(appContext.get());
125
-
126
- function handleSubmit() {
127
- appContext.set({ editMode: true });
128
- }
129
- </script>
130
-
131
- <form onsubmit={handleSubmit}>
132
- <p>Edit Mode: {appData?.editMode}</p>
133
- <button type="submit">Submit</button>
134
- </form>
135
- ```
136
-
137
- ### Custom Context
138
-
139
- ```svelte
140
- <script lang="ts">
141
- import { useContext } from '$lib/providers';
142
-
143
- type UserContext = {
144
- id: string;
145
- name: string;
146
- preferences: { theme: 'light' | 'dark' };
147
- };
148
-
149
- const userContext = useContext<UserContext>('user');
150
- let userData = $derived(userContext.get());
151
-
152
- function updateTheme(theme: 'light' | 'dark') {
153
- userContext.update((current) => ({
154
- ...current!,
155
- preferences: { ...current!.preferences, theme }
156
- }));
157
- }
158
- </script>
159
- ```
160
-
161
- ### Typed Data Context
162
-
163
- ```svelte
164
- <script lang="ts">
165
- import { useDataContext } from '$lib/providers';
166
-
167
- type AppDataType = {
168
- users: Array<{ id: string; name: string; email: string }>;
169
- products: Array<{ id: string; title: string; price: number }>;
170
- currentPage: number;
171
- totalPages: number;
172
- };
173
-
174
- const dataContext = useDataContext<AppDataType>();
175
- let appData = $derived(dataContext.get());
176
-
177
- function loadUsers(users: AppDataType['users']) {
178
- dataContext.set({
179
- state: {
180
- ...appData?.state,
181
- users,
182
- currentPage: 1
183
- }
184
- });
185
- }
186
-
187
- function nextPage() {
188
- if (appData?.state && appData.state.currentPage < appData.state.totalPages) {
189
- dataContext.update((current) => ({
190
- state: {
191
- ...current!.state!,
192
- currentPage: current!.state!.currentPage + 1
193
- }
194
- }));
195
- }
196
- }
197
- </script>
198
-
199
- <div>
200
- <p>Users: {appData?.state?.users?.length || 0}</p>
201
- <p>Page: {appData?.state?.currentPage || 1} of {appData?.state?.totalPages || 1}</p>
202
- <button onclick={nextPage}>Next Page</button>
203
- </div>
204
- ```
205
-
206
- ## Configurator Support
207
-
208
- The `GlobalProvider` includes built-in support for configurator state management with automatic change detection.
209
-
210
- ### Using the Configurator Context
211
-
212
- ```svelte
213
- <script lang="ts">
214
- import { useConfiguratorContext, useAppContext } from '$lib/providers';
215
-
216
- // Define your configurator type
217
- type MyConfiguratorType = {
218
- theme: 'light' | 'dark';
219
- layout: 'grid' | 'list';
220
- itemsPerPage: number;
221
- };
222
-
223
- // Use typed configurator context
224
- const configurator = useConfiguratorContext<MyConfiguratorType>();
225
-
226
- // Or use typed app context
227
- const appContext = useAppContext<MyConfiguratorType>();
228
-
229
- // Set configurator data with watch options (fully typed)
230
- configurator.setConfigurator(
231
- { theme: 'dark', layout: 'grid', itemsPerPage: 10 },
232
- { watchKeys: ['theme'], debounceMs: 100 }
233
- );
234
-
235
- // Check if configurator has changed
236
- let hasChanged = $derived(configurator.hasChanged);
237
- let currentConfig = $derived(configurator.configurator); // Type: MyConfiguratorType | null
238
- let cachedConfig = $derived(configurator.configuratorCache); // Type: MyConfiguratorType | null
239
-
240
- // Save current state to cache
241
- function saveToCache() {
242
- configurator.saveToCache();
243
- }
244
- </script>
245
-
246
- <div>
247
- <p>Has Changed: {hasChanged}</p>
248
- <p>Current Theme: {currentConfig?.theme}</p>
249
- <p>Cached Theme: {cachedConfig?.theme}</p>
250
- <button onclick={saveToCache}>Save to Cache</button>
251
- </div>
252
- ```
253
-
254
- ### Configurator API
255
-
256
- - `configurator` - Current configurator data
257
- - `configuratorCache` - Cached configurator data
258
- - `hasChanged` - Boolean indicating if configurator differs from cache
259
- - `watchOptions` - Current watch configuration
260
- - `setConfigurator(data, watchOptions?)` - Set configurator data
261
- - `setConfiguratorCache(data)` - Set cache data
262
- - `saveToCache()` - Save current configurator to cache
263
- - `updateWatchOptions(options)` - Update watch configuration
264
-
265
- ### Watch Options
266
-
267
- ```typescript
268
- interface ConfiguratorWatchOptions {
269
- watchAll?: boolean; // Watch all keys (default: true)
270
- watchKeys?: string[]; // Specific keys to watch
271
- debounceMs?: number; // Debounce delay (default: 50ms)
272
- }
273
- ```
274
-
275
- ## TypeScript Support
276
-
277
- ### Generic Context Usage
278
-
279
- ```typescript
280
- import type { ContextOperations, AppContextData, DataContextData } from '$lib/providers';
281
-
282
- // For custom contexts
283
- const userContext: ContextOperations<UserType> = useContext<UserType>('user');
284
-
285
- // For typed app context with configurator
286
- type MyConfiguratorType = {
287
- theme: 'light' | 'dark';
288
- layout: 'grid' | 'list';
289
- };
290
-
291
- const appContext = useAppContext<MyConfiguratorType>();
292
- const configurator = useConfiguratorContext<MyConfiguratorType>();
293
-
294
- // For typed data context
295
- type MyDataType = {
296
- users: User[];
297
- products: Product[];
298
- currentPage: number;
299
- };
300
-
301
- const dataContext = useDataContext<MyDataType>();
302
-
303
- // The configurator and configuratorCache will both be typed as MyConfiguratorType | null
304
- // The data context state will be typed as MyDataType | null
305
- ```
306
-
307
- ### Type Definitions
308
-
309
- ```typescript
310
- // Your configurator type
311
- type MyConfiguratorType = {
312
- theme: 'light' | 'dark';
313
- layout: 'grid' | 'list';
314
- itemsPerPage: number;
315
- };
316
-
317
- // App context will be typed as AppContextData<MyConfiguratorType>
318
- type MyAppContextType = AppContextData<MyConfiguratorType>;
319
-
320
- // Data context will be typed as DataContextData<MyDataType>
321
- type MyDataContextType = DataContextData<MyDataType>;
322
- ```