@finsweet/webflow-apps-utils 1.0.3 → 1.0.4

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 (95) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/router/Router.mdx +958 -0
  4. package/dist/router/Router.stories.d.ts +6 -0
  5. package/dist/router/Router.stories.js +47 -0
  6. package/dist/router/examples/RouterExample.svelte +271 -0
  7. package/dist/router/examples/RouterExample.svelte.d.ts +18 -0
  8. package/dist/router/examples/index.d.ts +4 -0
  9. package/dist/router/examples/index.js +4 -0
  10. package/dist/router/examples/pages/AboutPage.svelte +568 -0
  11. package/dist/router/examples/pages/AboutPage.svelte.d.ts +13 -0
  12. package/dist/router/examples/pages/HomePage.svelte +200 -0
  13. package/dist/router/examples/pages/HomePage.svelte.d.ts +14 -0
  14. package/dist/router/examples/pages/NotFoundPage.svelte +307 -0
  15. package/dist/router/examples/pages/NotFoundPage.svelte.d.ts +17 -0
  16. package/dist/router/hooks.svelte.d.ts +2 -2
  17. package/dist/router/index.d.ts +3 -0
  18. package/dist/router/index.js +3 -0
  19. package/dist/router/{Link.svelte → providers/Link.svelte} +1 -1
  20. package/dist/router/{Route.svelte → providers/Route.svelte} +1 -1
  21. package/dist/router/{Route.svelte.d.ts → providers/Route.svelte.d.ts} +1 -1
  22. package/dist/router/{Router.svelte → providers/RouterProvider.svelte} +22 -5
  23. package/dist/router/{Router.svelte.d.ts → providers/RouterProvider.svelte.d.ts} +8 -4
  24. package/dist/router/providers/index.d.ts +3 -0
  25. package/dist/router/providers/index.js +3 -0
  26. package/dist/router/{index.svelte.d.ts → router.svelte.d.ts} +1 -3
  27. package/dist/router/{index.svelte.js → router.svelte.js} +1 -4
  28. package/dist/stores/docs/Form.mdx +542 -0
  29. package/dist/stores/forms.d.ts +41 -4
  30. package/dist/stores/forms.js +86 -32
  31. package/dist/types/customCode.d.ts +1 -1
  32. package/dist/types/window.d.ts +1 -0
  33. package/dist/ui/components/copy-text/CopyText.stories.d.ts +70 -0
  34. package/dist/ui/components/copy-text/CopyText.stories.js +241 -0
  35. package/dist/ui/components/copy-text/CopyText.svelte +249 -0
  36. package/dist/ui/components/copy-text/CopyText.svelte.d.ts +4 -0
  37. package/dist/ui/components/copy-text/index.d.ts +2 -0
  38. package/dist/ui/components/copy-text/index.js +1 -0
  39. package/dist/ui/components/copy-text/types.d.ts +52 -0
  40. package/dist/ui/components/copy-text/types.js +1 -0
  41. package/dist/ui/components/index.d.ts +1 -0
  42. package/dist/ui/components/index.js +1 -0
  43. package/dist/ui/components/input/Input.stories.d.ts +9 -0
  44. package/dist/ui/components/input/Input.stories.js +78 -0
  45. package/dist/ui/components/input/Input.svelte +39 -3
  46. package/dist/ui/components/input/types.d.ts +6 -0
  47. package/dist/ui/components/layout/Layout.svelte +7 -59
  48. package/dist/ui/components/layout/Layout.svelte.d.ts +2 -2
  49. package/dist/ui/components/layout/examples/ExampleLayout.svelte +22 -17
  50. package/dist/ui/components/layout/index.d.ts +1 -1
  51. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte +20 -0
  52. package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte.d.ts +7 -0
  53. package/dist/ui/components/layout/types.d.ts +1 -10
  54. package/dist/ui/components/notification/Notification.stories.svelte +12 -1
  55. package/dist/ui/components/notification/Notification.svelte +10 -5
  56. package/dist/ui/components/notification/Notification.svelte.d.ts +1 -1
  57. package/dist/ui/components/notification/types.d.ts +1 -1
  58. package/dist/ui/components/section/Section.svelte +4 -2
  59. package/dist/ui/components/section/types.d.ts +8 -0
  60. package/dist/ui/components/text/Text.stories.svelte +67 -1
  61. package/dist/ui/components/text/Text.svelte +209 -8
  62. package/dist/ui/components/text/types.d.ts +4 -0
  63. package/dist/utils/animations/factory.d.ts +7 -0
  64. package/dist/utils/animations/factory.js +101 -0
  65. package/dist/utils/animations/index.d.ts +7 -0
  66. package/dist/utils/animations/index.js +62 -0
  67. package/dist/utils/animations/types.d.ts +39 -0
  68. package/dist/utils/animations/types.js +1 -0
  69. package/dist/utils/custom-code/configs.d.ts +22 -0
  70. package/dist/utils/custom-code/configs.js +40 -0
  71. package/dist/utils/custom-code/index.d.ts +1 -0
  72. package/dist/utils/custom-code/index.js +1 -0
  73. package/dist/utils/helpers/capitalizeFirstLetter.d.ts +4 -0
  74. package/dist/utils/helpers/capitalizeFirstLetter.js +9 -0
  75. package/dist/utils/helpers/getTimeNow.d.ts +4 -0
  76. package/dist/utils/helpers/getTimeNow.js +8 -0
  77. package/dist/utils/helpers/index.d.ts +4 -0
  78. package/dist/utils/helpers/index.js +4 -0
  79. package/dist/utils/helpers/minifyCode.d.ts +10 -0
  80. package/dist/utils/helpers/minifyCode.js +73 -0
  81. package/dist/utils/helpers/objectsToModuleExports.d.ts +1 -1
  82. package/dist/utils/helpers/objectsToModuleExports.js +1 -0
  83. package/dist/utils/helpers/toHumanReadableList.d.ts +4 -0
  84. package/dist/utils/helpers/toHumanReadableList.js +11 -0
  85. package/dist/utils/index.d.ts +1 -0
  86. package/dist/utils/index.js +1 -0
  87. package/dist/utils/webflow-canvas/getAllChildren.d.ts +16 -0
  88. package/dist/utils/webflow-canvas/getAllChildren.js +65 -0
  89. package/dist/utils/webflow-canvas/getElementClassList.d.ts +9 -0
  90. package/dist/utils/webflow-canvas/getElementClassList.js +19 -0
  91. package/dist/utils/webflow-canvas/index.d.ts +2 -0
  92. package/dist/utils/webflow-canvas/index.js +2 -0
  93. package/package.json +6 -1
  94. package/dist/router/README.md +0 -397
  95. /package/dist/router/{Link.svelte.d.ts → providers/Link.svelte.d.ts} +0 -0
@@ -1,397 +0,0 @@
1
- # Custom Svelte 5 Router
2
-
3
- A lightweight, type-safe client-side router built specifically for Svelte 5 using runes. Designed to replace svelte-routing with modern reactivity patterns and support for persistent app version hashes.
4
-
5
- ## Features
6
-
7
- - 🚀 **Svelte 5 Native**: Built with runes for optimal reactivity
8
- - 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
9
- - 📦 **Lightweight**: Minimal bundle size with no external dependencies
10
- - 🔄 **Reactive**: All router state is reactive using Svelte 5 runes
11
- - 🛣️ **Parameter Support**: URL parameters like `/users/:id`
12
- - 🔍 **Query Params**: Built-in query parameter handling
13
- - 🏠 **App Version Support**: Persistent app version hashes across navigation
14
- - 📱 **Hash Mode**: Optional hash-based routing
15
- - 🎣 **Rich Hooks**: Comprehensive set of utility hooks
16
- - ♿ **Accessible**: Built-in accessibility features for navigation
17
-
18
- ## Installation
19
-
20
- The router is included in your project. Import from:
21
-
22
- ```typescript
23
- import { Router, RouterComponent, Route, Link } from './router';
24
- ```
25
-
26
- ## Quick Start
27
-
28
- ### 1. Create and Configure Router
29
-
30
- ```typescript
31
- // router.ts
32
- import { createRouter } from './lib/router';
33
-
34
- export const appRouter = createRouter({
35
- autoInit: true
36
- });
37
-
38
- // Export the router instance for use throughout the app
39
- export default appRouter;
40
- ```
41
-
42
- ### 2. Initialize with App Version
43
-
44
- ```typescript
45
- // In your app initialization
46
- const awaitRouter = async () => {
47
- const current = new URL(window.location.href);
48
- const appVersionID = current.pathname.split('/')[1] || 'dev-mode';
49
-
50
- // Initialize app version - this persists across all navigation
51
- appRouter.initAppVersion(`/${appVersionID}`);
52
-
53
- // Define routes without app version prefix
54
- appRouter.addRoutes([
55
- { path: '/', component: MyComponentsLinks },
56
- { path: '/finsweetbuilder', component: BuilderLinks },
57
- { path: '/finsweetlibrary', component: LibraryLinks },
58
- { path: '/finsweetlibrary-admin', component: LibraryAdminLinks }
59
- ]);
60
-
61
- // Update your existing router store
62
- routerStore.set({
63
- hash: appVersionID,
64
- url: current
65
- });
66
- };
67
- ```
68
-
69
- ### 3. Setup Router in Your App
70
-
71
- ```svelte
72
- <!-- App.svelte -->
73
- <script lang="ts">
74
- import { RouterComponent, Route } from './lib/router';
75
- import appRouter from './router.ts';
76
- import { routerStore } from '@finsweet/components-utils';
77
-
78
- const awaitRouter = async () => {
79
- const current = new URL(window.location.href);
80
- const appVersionID = current.pathname.split('/')[1] || 'dev-mode';
81
-
82
- // Initialize app version - this persists across all navigation
83
- appRouter.initAppVersion(`/${appVersionID}`);
84
-
85
- // Update your existing router store
86
- routerStore.set({
87
- hash: appVersionID,
88
- url: current
89
- });
90
-
91
- // Update configurator if needed
92
- configurator.update((state) => ({
93
- ...state,
94
- pathname: current.pathname,
95
- appVersionID: appVersionID
96
- }));
97
-
98
- await delay(50);
99
- };
100
-
101
- // ... rest of your init logic
102
- </script>
103
-
104
- <!-- Replace your existing Router with RouterComponent -->
105
- <RouterComponent router={appRouter}>
106
- <!-- Define routes without app version prefix -->
107
- <Route path="/" component={MyComponentsLinks} />
108
- <Route path="/finsweetbuilder" component={BuilderLinks} />
109
- <Route path="/finsweetlibrary" component={LibraryLinks} />
110
- <Route path="/finsweetlibrary-admin" component={LibraryAdminLinks} />
111
-
112
- <!-- Dynamic component routes -->
113
- {#each $finsweetComponentsList as { solution, live, key }}
114
- {#if live}
115
- <Route path="/finsweetbuilder/{key}" component={solution} />
116
- {/if}
117
- {/each}
118
- </RouterComponent>
119
- ```
120
-
121
- ### 4. Navigate with Links
122
-
123
- ```svelte
124
- <!-- LeftNavBarLinks.svelte -->
125
- <script lang="ts">
126
- import { Link, useAppVersion, useLocation } from '../lib/router';
127
-
128
- const appVersionPath = useAppVersion();
129
- const location = useLocation();
130
-
131
- // Routes are now clean without app version prefix
132
- const navLinks = [
133
- { path: '/', label: 'My Components', icon: ComponentsIcon },
134
- { path: '/finsweetbuilder', label: 'Builder', icon: BuilderIcon },
135
- { path: '/finsweetlibrary', label: 'Library', icon: FinsweetLibraryIcon }
136
- ];
137
- </script>
138
-
139
- <div class="nav-container">
140
- {#each navLinks as link}
141
- <Link to={link.path} activeClass="active" class="nav-links parent-link">
142
- <svelte:component this={link.icon} />
143
- <Text label={link.label} fontSize="normal" />
144
- </Link>
145
- {/each}
146
- </div>
147
-
148
- <style>
149
- .active {
150
- font-weight: bold;
151
- color: blue;
152
- }
153
- </style>
154
- ```
155
-
156
- ### 5. Use Router Hooks for Navigation
157
-
158
- ```svelte
159
- <!-- BackNavLink.svelte -->
160
- <script lang="ts">
161
- import { useNavigate, useAppVersion } from '../lib/router';
162
-
163
- export let fsComponent: string;
164
-
165
- const navigate = useNavigate();
166
- const appVersionPath = useAppVersion();
167
-
168
- const goBack = () => {
169
- // Navigate to builder page - app version is automatically included
170
- navigate('/finsweetbuilder');
171
-
172
- // Update your existing store if needed
173
- const appVersionID = appVersionPath.slice(1); // Remove leading slash
174
- routerStore.set({
175
- hash: appVersionID,
176
- url: new URL(`${appVersionPath}/finsweetbuilder`, window.location.origin)
177
- });
178
- };
179
- </script>
180
-
181
- <div class="nav-links-wrapper">
182
- <Section clickable onclick={goBack}>
183
- <!-- ... rest of your template -->
184
- </Section>
185
- </div>
186
- ```
187
-
188
- ## Core Concepts
189
-
190
- ### App Version Hash Support
191
-
192
- The router's key feature is maintaining app version hashes across all navigation:
193
-
194
- ```typescript
195
- // Once initialized, all routes automatically include the app version
196
- appRouter.initAppVersion('/test-app-hash');
197
-
198
- // These routes work automatically with app version:
199
- navigate('/'); // Goes to /test-app-hash/
200
- navigate('/finsweetbuilder'); // Goes to /test-app-hash/finsweetbuilder
201
- ```
202
-
203
- ### Links with App Version
204
-
205
- Links automatically include the app version prefix:
206
-
207
- ```svelte
208
- <!-- These automatically include the app version prefix -->
209
- <Link to="/">Home</Link>
210
- <!-- Renders as href="/test-app-hash/" -->
211
-
212
- <Link to="/finsweetbuilder">Builder</Link>
213
- <!-- Renders as href="/test-app-hash/finsweetbuilder" -->
214
- ```
215
-
216
- ### App Version Utility Hooks
217
-
218
- ```svelte
219
- <script lang="ts">
220
- import { useAppVersion, useFullPathname, useLocation } from './router';
221
-
222
- const appVersionPath = useAppVersion(); // Returns '/test-app-hash'
223
- const fullPathname = useFullPathname(); // Returns '/test-app-hash/users/123'
224
- const location = useLocation(); // location.pathname is clean: '/users/123'
225
- </script>
226
-
227
- <p>App Version: {appVersionPath}</p>
228
- <p>Full Path: {fullPathname}</p>
229
- <p>Clean Path: {location.pathname}</p>
230
- ```
231
-
232
- ### Working with Route Parameters
233
-
234
- ```svelte
235
- <!-- UserDetail.svelte -->
236
- <script lang="ts">
237
- import { useParams, useNavigate, useLocation } from './router';
238
-
239
- const params = useParams();
240
- const navigate = useNavigate();
241
- const location = useLocation();
242
-
243
- // Reactive access to route parameters
244
- $: userId = params.id;
245
-
246
- function goBack() {
247
- navigate('/users');
248
- }
249
- </script>
250
-
251
- <h1>User {userId}</h1>
252
- <button onclick={goBack}>Back to Users</button>
253
- <p>Current path: {location.pathname}</p>
254
- ```
255
-
256
- ### Component Modal Updates
257
-
258
- ```svelte
259
- <!-- NewComponent.svelte -->
260
- <script lang="ts">
261
- import { useNavigate } from '../lib/router';
262
-
263
- const navigate = useNavigate();
264
-
265
- const handleBuilderClick = () => {
266
- // Navigate to builder - app version automatically included
267
- navigate('/finsweetbuilder');
268
- };
269
-
270
- const handleLibraryClick = () => {
271
- // Navigate to library - app version automatically included
272
- navigate('/finsweetlibrary');
273
- };
274
- </script>
275
-
276
- <!-- Navigation calls with new navigate function -->
277
- <WebflowTooltip>
278
- <div slot="tooltip">
279
- <Section clickable on:click={handleBuilderClick}>
280
- <!-- Builder option -->
281
- </Section>
282
- <Section clickable on:click={handleLibraryClick}>
283
- <!-- Library option -->
284
- </Section>
285
- </div>
286
- </WebflowTooltip>
287
- ```
288
-
289
- ## API Reference
290
-
291
- ### Router Class
292
-
293
- ```typescript
294
- const router = createRouter({
295
- basePath: '/app', // Optional base path
296
- hashMode: false, // Use hash-based routing
297
- fallbackRoute: '/404', // Fallback for unmatched routes
298
- autoInit: true // Auto-initialize in browser
299
- });
300
-
301
- // Methods
302
- router.navigate('/path', { replace: false, state: {} });
303
- router.addRoute({ path: '/users/:id', component: UserComponent });
304
- router.addRoutes([...routes]);
305
- router.initAppVersion('/app-version'); // Set persistent app version
306
- router.isActive('/path', (exact = false));
307
- router.getParams();
308
- router.getQuery();
309
- router.back();
310
- router.forward();
311
- ```
312
-
313
- ### Hooks
314
-
315
- ```typescript
316
- // Get router instance
317
- const router = useRouter();
318
-
319
- // Reactive location information
320
- const location = useLocation();
321
-
322
- // Current route information
323
- const route = useRoute();
324
-
325
- // Route parameters
326
- const params = useParams();
327
-
328
- // Query parameters
329
- const query = useQuery();
330
-
331
- // Navigation function
332
- const navigate = useNavigate();
333
-
334
- // Check if path is active
335
- const isActive = useIsActiveRoute();
336
-
337
- // App version utilities
338
- const appVersionPath = useAppVersion();
339
- const fullPathname = useFullPathname();
340
-
341
- // Navigation state
342
- const isNavigating = useNavigating();
343
-
344
- // History tracking
345
- const history = useHistory();
346
-
347
- // Search params helper
348
- const search = useSearchParams();
349
- search.set('page', '2');
350
- search.get('page');
351
- search.delete('page');
352
- ```
353
-
354
- ### Components
355
-
356
- #### RouterComponent
357
-
358
- ```svelte
359
- <RouterComponent {router} autoInit={true}>
360
- <!-- Route components go here -->
361
- </RouterComponent>
362
- ```
363
-
364
- #### Route
365
-
366
- ```svelte
367
- <Route path="/users/:id" component={UserComponent} exact={true} meta={{ requiresAuth: true }} />
368
-
369
- <!-- Or with slot content -->
370
- <Route path="/about">
371
- <AboutPage />
372
- </Route>
373
- ```
374
-
375
- #### Link
376
-
377
- ```svelte
378
- <Link
379
- to="/users/123"
380
- activeClass="active"
381
- exact={false}
382
- replace={false}
383
- disabled={false}
384
- element="a">View User</Link
385
- >
386
- ```
387
-
388
- ## Key Benefits
389
-
390
- 1. **Persistent App Version**: Once `initAppVersion` is called, the app version hash persists across all navigation
391
- 2. **Clean Route Definitions**: Define routes without app version prefixes (`/finsweetbuilder` instead of `/{appVersionID}/finsweetbuilder`)
392
- 3. **Automatic URL Generation**: Links and navigation automatically include the app version prefix
393
- 4. **Backward Compatibility**: Works with your existing `routerStore` and other components
394
- 5. **Type Safety**: Full TypeScript support with proper typing
395
- 6. **Modern Reactivity**: Built on Svelte 5 runes for optimal performance
396
-
397
- The router handles all the app version complexity automatically while maintaining compatibility with your existing application structure and providing a modern, type-safe routing solution for Svelte 5.