@finsweet/webflow-apps-utils 1.0.2 → 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.
- package/README.md +162 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/providers/GlobalProvider.mdx +322 -0
- package/dist/providers/GlobalProvider.svelte +58 -0
- package/dist/providers/GlobalProvider.svelte.d.ts +4 -0
- package/dist/providers/configuratorUtils.d.ts +37 -0
- package/dist/providers/configuratorUtils.js +219 -0
- package/dist/providers/globalContext.svelte.d.ts +18 -0
- package/dist/providers/globalContext.svelte.js +439 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers/types.d.ts +103 -0
- package/dist/providers/types.js +6 -0
- package/dist/router/Router.mdx +958 -0
- package/dist/router/Router.stories.d.ts +6 -0
- package/dist/router/Router.stories.js +47 -0
- package/dist/router/examples/RouterExample.svelte +271 -0
- package/dist/{ui/components/NoSettingsNeeded.svelte.d.ts → router/examples/RouterExample.svelte.d.ts} +3 -3
- package/dist/router/examples/index.d.ts +4 -0
- package/dist/router/examples/index.js +4 -0
- package/dist/router/examples/pages/AboutPage.svelte +568 -0
- package/dist/router/examples/pages/AboutPage.svelte.d.ts +13 -0
- package/dist/router/examples/pages/HomePage.svelte +200 -0
- package/dist/router/examples/pages/HomePage.svelte.d.ts +14 -0
- package/dist/router/examples/pages/NotFoundPage.svelte +307 -0
- package/dist/router/examples/pages/NotFoundPage.svelte.d.ts +17 -0
- package/dist/router/hooks.svelte.d.ts +2 -2
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.js +3 -0
- package/dist/router/{Link.svelte → providers/Link.svelte} +1 -1
- package/dist/router/{Route.svelte → providers/Route.svelte} +1 -1
- package/dist/router/{Route.svelte.d.ts → providers/Route.svelte.d.ts} +1 -1
- package/dist/router/{Router.svelte → providers/RouterProvider.svelte} +22 -5
- package/dist/router/{Router.svelte.d.ts → providers/RouterProvider.svelte.d.ts} +8 -4
- package/dist/router/providers/index.d.ts +3 -0
- package/dist/router/providers/index.js +3 -0
- package/dist/router/{index.svelte.d.ts → router.svelte.d.ts} +1 -3
- package/dist/router/{index.svelte.js → router.svelte.js} +1 -4
- package/dist/stores/docs/Form.mdx +542 -0
- package/dist/stores/forms.d.ts +41 -4
- package/dist/stores/forms.js +86 -32
- package/dist/stores/index.d.ts +0 -1
- package/dist/stores/index.js +0 -1
- package/dist/types/customCode.d.ts +1 -1
- package/dist/types/webflow.d.ts +31 -47
- package/dist/types/window.d.ts +1 -0
- package/dist/ui/components/LoadingScreen.svelte +2 -1
- package/dist/ui/components/button/Button.svelte +1 -1
- package/dist/ui/components/button-group/ButtonGroup.stories.js +112 -0
- package/dist/ui/components/{ButtonGroup.svelte → button-group/ButtonGroup.svelte} +20 -33
- package/dist/ui/components/button-group/ButtonGroup.svelte.d.ts +13 -0
- package/dist/ui/components/button-group/index.d.ts +2 -0
- package/dist/ui/components/button-group/index.js +1 -0
- package/dist/ui/components/button-group/types.d.ts +32 -0
- package/dist/ui/components/checkbox/Checkbox.stories.d.ts +55 -0
- package/dist/ui/components/checkbox/Checkbox.stories.js +162 -0
- package/dist/ui/components/checkbox/Checkbox.svelte +141 -0
- package/dist/ui/components/checkbox/Checkbox.svelte.d.ts +4 -0
- package/dist/ui/components/checkbox/index.d.ts +2 -0
- package/dist/ui/components/checkbox/index.js +1 -0
- package/dist/ui/components/checkbox/types.d.ts +32 -0
- package/dist/ui/components/controlled-buttons/ControlledButtons.stories.d.ts +32 -0
- package/dist/ui/components/controlled-buttons/ControlledButtons.stories.js +152 -0
- package/dist/ui/components/{buttons/FooterButton.svelte → controlled-buttons/ControlledButtons.svelte} +18 -67
- package/dist/ui/components/controlled-buttons/ControlledButtons.svelte.d.ts +4 -0
- package/dist/ui/components/controlled-buttons/index.d.ts +2 -0
- package/dist/ui/components/controlled-buttons/index.js +1 -0
- package/dist/ui/components/{buttons → controlled-buttons}/types.d.ts +11 -4
- package/dist/ui/components/copy-text/CopyText.stories.d.ts +70 -0
- package/dist/ui/components/copy-text/CopyText.stories.js +241 -0
- package/dist/ui/components/copy-text/CopyText.svelte +249 -0
- package/dist/ui/components/copy-text/CopyText.svelte.d.ts +4 -0
- package/dist/ui/components/copy-text/index.d.ts +2 -0
- package/dist/ui/components/copy-text/index.js +1 -0
- package/dist/ui/components/copy-text/types.d.ts +52 -0
- package/dist/ui/components/copy-text/types.js +1 -0
- package/dist/ui/components/divider/Divider.stories.svelte +134 -0
- package/dist/ui/components/{clickable/Clickable.stories.svelte.d.ts → divider/Divider.stories.svelte.d.ts} +4 -4
- package/dist/ui/components/divider/Divider.svelte +30 -0
- package/dist/ui/components/divider/Divider.svelte.d.ts +4 -0
- package/dist/ui/components/divider/index.d.ts +2 -0
- package/dist/ui/components/divider/index.js +1 -0
- package/dist/ui/components/divider/types.d.ts +23 -0
- package/dist/ui/components/divider/types.js +1 -0
- package/dist/ui/components/iframe/Iframe.stories.svelte +122 -0
- package/dist/ui/components/{ToggleItem.svelte.d.ts → iframe/Iframe.stories.svelte.d.ts} +7 -8
- package/dist/ui/components/iframe/Iframe.svelte +75 -0
- package/dist/ui/components/iframe/Iframe.svelte.d.ts +4 -0
- package/dist/ui/components/iframe/index.d.ts +2 -0
- package/dist/ui/components/iframe/index.js +1 -0
- package/dist/ui/components/iframe/types.d.ts +38 -0
- package/dist/ui/components/iframe/types.js +1 -0
- package/dist/ui/components/index.d.ts +13 -39
- package/dist/ui/components/index.js +13 -39
- package/dist/ui/components/input/Input.stories.d.ts +33 -0
- package/dist/ui/components/input/Input.stories.js +176 -0
- package/dist/ui/components/input/Input.svelte +358 -81
- package/dist/ui/components/input/types.d.ts +33 -1
- package/dist/ui/components/layout/Layout.stories.svelte +3 -3
- package/dist/ui/components/layout/Layout.svelte +10 -64
- package/dist/ui/components/layout/Layout.svelte.d.ts +2 -2
- package/dist/ui/components/layout/common/EditModeMessage.svelte +24 -12
- package/dist/ui/components/layout/{ExampleLayout.svelte → examples/ExampleLayout.svelte} +56 -39
- package/dist/ui/components/layout/examples/Wrapper.svelte +9 -0
- package/dist/ui/components/{Header.svelte.d.ts → layout/examples/Wrapper.svelte.d.ts} +4 -6
- package/dist/ui/components/layout/examples/index.d.ts +2 -0
- package/dist/ui/components/layout/examples/index.js +2 -0
- package/dist/ui/components/layout/index.d.ts +3 -2
- package/dist/ui/components/layout/index.js +2 -1
- package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte +20 -0
- package/dist/ui/components/layout/test-helpers/TestLayoutWithFooter.svelte.d.ts +7 -0
- package/dist/ui/components/layout/types.d.ts +1 -10
- package/dist/ui/components/modal/Example.svelte +320 -0
- package/dist/ui/components/modal/Example.svelte.d.ts +3 -0
- package/dist/ui/components/modal/Modal.stories.svelte +18 -0
- package/dist/ui/components/modal/Modal.stories.svelte.d.ts +26 -0
- package/dist/ui/components/modal/Modal.svelte +490 -0
- package/dist/ui/components/modal/Modal.svelte.d.ts +130 -0
- package/dist/ui/components/modal/index.d.ts +2 -0
- package/dist/ui/components/modal/index.js +1 -0
- package/dist/ui/components/modal/types.d.ts +75 -0
- package/dist/ui/components/modal/types.js +1 -0
- package/dist/ui/components/notification/Notification.stories.svelte +239 -0
- package/dist/ui/components/{ToggleList.svelte.d.ts → notification/Notification.stories.svelte.d.ts} +9 -21
- package/dist/ui/components/notification/Notification.svelte +294 -0
- package/dist/ui/components/notification/Notification.svelte.d.ts +67 -0
- package/dist/ui/components/notification/index.d.ts +2 -0
- package/dist/ui/components/notification/index.js +1 -0
- package/dist/ui/components/notification/types.d.ts +68 -0
- package/dist/ui/components/notification/types.js +1 -0
- package/dist/ui/components/section/Section.stories.svelte +263 -0
- package/dist/ui/components/section/Section.stories.svelte.d.ts +27 -0
- package/dist/ui/components/section/Section.svelte +326 -0
- package/dist/ui/components/section/Section.svelte.d.ts +5 -0
- package/dist/ui/components/section/index.d.ts +2 -0
- package/dist/ui/components/section/index.js +1 -0
- package/dist/ui/components/section/types.d.ts +114 -0
- package/dist/ui/components/section/types.js +1 -0
- package/dist/ui/components/{ImageUpload.svelte → shared/ImageUpload.svelte} +3 -3
- package/dist/ui/components/{SelectBodyOrDivBlock.svelte → shared/SelectBodyOrDivBlock.svelte} +1 -1
- package/dist/ui/components/shared/index.d.ts +2 -0
- package/dist/ui/components/shared/index.js +2 -0
- package/dist/ui/components/text/Text.stories.svelte +67 -1
- package/dist/ui/components/text/Text.svelte +209 -8
- package/dist/ui/components/text/types.d.ts +4 -0
- package/dist/ui/index.css +33 -5
- package/dist/utils/animations/factory.d.ts +7 -0
- package/dist/utils/animations/factory.js +101 -0
- package/dist/utils/animations/index.d.ts +7 -0
- package/dist/utils/animations/index.js +62 -0
- package/dist/utils/animations/types.d.ts +39 -0
- package/dist/utils/animations/types.js +1 -0
- package/dist/utils/api/checkIfAppModeIsDesign.d.ts +1 -2
- package/dist/utils/api/checkIfAppModeIsDesign.js +1 -2
- package/dist/utils/api/clipboard/handlePaste.d.ts +6 -37
- package/dist/utils/api/clipboard/handlePaste.js +2 -6
- package/dist/utils/api/getAllAssets.d.ts +1 -2
- package/dist/utils/api/getAllAssets.js +1 -2
- package/dist/utils/api/getFinsweetComponentsEnvironment.d.ts +1 -2
- package/dist/utils/api/getFinsweetComponentsEnvironment.js +3 -6
- package/dist/utils/api/index.d.ts +0 -1
- package/dist/utils/api/index.js +0 -1
- package/dist/utils/api/insertWithXSCP.d.ts +1 -2
- package/dist/utils/api/insertWithXSCP.js +1 -2
- package/dist/utils/auth/crossWindowLogin.d.ts +3 -0
- package/dist/utils/auth/crossWindowLogin.js +3 -0
- package/dist/utils/auth/index.d.ts +9 -25
- package/dist/utils/auth/index.js +9 -25
- package/dist/utils/browser-storage/localStorage.d.ts +4 -12
- package/dist/utils/browser-storage/localStorage.js +4 -12
- package/dist/utils/browser-storage/sessionStorage.d.ts +4 -12
- package/dist/utils/browser-storage/sessionStorage.js +4 -12
- package/dist/utils/custom-code/api.d.ts +3 -7
- package/dist/utils/custom-code/api.js +3 -7
- package/dist/utils/custom-code/configs.d.ts +22 -0
- package/dist/utils/custom-code/configs.js +40 -0
- package/dist/utils/custom-code/index.d.ts +1 -0
- package/dist/utils/custom-code/index.js +1 -0
- package/dist/utils/helpers/capitalizeFirstLetter.d.ts +4 -0
- package/dist/utils/helpers/capitalizeFirstLetter.js +9 -0
- package/dist/utils/helpers/cleanupTooltipMessage.d.ts +1 -2
- package/dist/utils/helpers/cleanupTooltipMessage.js +1 -2
- package/dist/utils/helpers/getTimeNow.d.ts +4 -0
- package/dist/utils/helpers/getTimeNow.js +8 -0
- package/dist/utils/helpers/goto.d.ts +1 -4
- package/dist/utils/helpers/goto.js +2 -7
- package/dist/utils/helpers/index.d.ts +5 -0
- package/dist/utils/helpers/index.js +5 -0
- package/dist/utils/helpers/minifyCode.d.ts +10 -0
- package/dist/utils/helpers/minifyCode.js +73 -0
- package/dist/utils/helpers/noop.d.ts +1 -1
- package/dist/utils/helpers/noop.js +1 -1
- package/dist/utils/helpers/numbers.d.ts +4 -14
- package/dist/utils/helpers/numbers.js +4 -14
- package/dist/utils/helpers/objectsToModuleExports.d.ts +2 -4
- package/dist/utils/helpers/objectsToModuleExports.js +2 -3
- package/dist/utils/helpers/toHumanReadableList.d.ts +4 -0
- package/dist/utils/helpers/toHumanReadableList.js +11 -0
- package/dist/utils/helpers/trimText.d.ts +1 -8
- package/dist/utils/helpers/trimText.js +1 -8
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/logger/index.d.ts +0 -2
- package/dist/utils/logger/index.js +0 -2
- package/dist/utils/webflow-canvas/attributes/getAllWebflowElementAttributes.d.ts +1 -3
- package/dist/utils/webflow-canvas/attributes/getAllWebflowElementAttributes.js +1 -3
- package/dist/utils/webflow-canvas/attributes/getInstanceNamesFromObject.d.ts +1 -5
- package/dist/utils/webflow-canvas/attributes/getInstanceNamesFromObject.js +1 -5
- package/dist/utils/webflow-canvas/attributes/getWebflowElementAttribute.d.ts +1 -4
- package/dist/utils/webflow-canvas/attributes/getWebflowElementAttribute.js +1 -4
- package/dist/utils/webflow-canvas/attributes/getWebflowElementTextContent.d.ts +1 -3
- package/dist/utils/webflow-canvas/attributes/getWebflowElementTextContent.js +1 -3
- package/dist/utils/webflow-canvas/attributes/removeWebflowElementAttribute.d.ts +1 -4
- package/dist/utils/webflow-canvas/attributes/removeWebflowElementAttribute.js +1 -4
- package/dist/utils/webflow-canvas/attributes/setStyles.d.ts +1 -3
- package/dist/utils/webflow-canvas/attributes/setStyles.js +1 -3
- package/dist/utils/webflow-canvas/attributes/setWebflowElementAttribute.d.ts +1 -8
- package/dist/utils/webflow-canvas/attributes/setWebflowElementAttribute.js +1 -13
- package/dist/utils/webflow-canvas/findInstanceElement.d.ts +0 -6
- package/dist/utils/webflow-canvas/findInstanceElement.js +1 -7
- package/dist/utils/webflow-canvas/getAllChildren.d.ts +16 -0
- package/dist/utils/webflow-canvas/getAllChildren.js +65 -0
- package/dist/utils/webflow-canvas/getAllPages.d.ts +3 -10
- package/dist/utils/webflow-canvas/getAllPages.js +3 -10
- package/dist/utils/webflow-canvas/getElementClassList.d.ts +9 -0
- package/dist/utils/webflow-canvas/getElementClassList.js +19 -0
- package/dist/utils/webflow-canvas/getSiteStagingUrl.d.ts +1 -4
- package/dist/utils/webflow-canvas/getSiteStagingUrl.js +1 -4
- package/dist/utils/webflow-canvas/index.d.ts +3 -0
- package/dist/utils/webflow-canvas/index.js +3 -0
- package/package.json +14 -2
- package/dist/router/README.md +0 -397
- package/dist/stores/globalStore.d.ts +0 -10
- package/dist/stores/globalStore.js +0 -10
- package/dist/ui/components/ButtonGroup.svelte.d.ts +0 -28
- package/dist/ui/components/Checkbox.svelte +0 -94
- package/dist/ui/components/Checkbox.svelte.d.ts +0 -36
- package/dist/ui/components/Copy.svelte +0 -329
- package/dist/ui/components/Copy.svelte.d.ts +0 -35
- package/dist/ui/components/CustomModal.svelte +0 -192
- package/dist/ui/components/CustomModal.svelte.d.ts +0 -45
- package/dist/ui/components/DisableInEditMode.svelte +0 -66
- package/dist/ui/components/DisableInEditMode.svelte.d.ts +0 -33
- package/dist/ui/components/Divider.svelte +0 -31
- package/dist/ui/components/Divider.svelte.d.ts +0 -31
- package/dist/ui/components/Header.svelte +0 -30
- package/dist/ui/components/Iframe.svelte +0 -89
- package/dist/ui/components/Iframe.svelte.d.ts +0 -40
- package/dist/ui/components/InjectComponent.svelte +0 -297
- package/dist/ui/components/InjectComponent.svelte.d.ts +0 -27
- package/dist/ui/components/Modal.svelte +0 -139
- package/dist/ui/components/Modal.svelte.d.ts +0 -42
- package/dist/ui/components/Navbar.svelte +0 -132
- package/dist/ui/components/Navbar.svelte.d.ts +0 -29
- package/dist/ui/components/NoSettingsNeeded.svelte +0 -31
- package/dist/ui/components/Notification.svelte +0 -193
- package/dist/ui/components/Notification.svelte.d.ts +0 -64
- package/dist/ui/components/PlusMinusButton.svelte +0 -91
- package/dist/ui/components/PlusMinusButton.svelte.d.ts +0 -22
- package/dist/ui/components/PreviewBar.svelte +0 -40
- package/dist/ui/components/PreviewBar.svelte.d.ts +0 -20
- package/dist/ui/components/ScrollableContent.svelte +0 -18
- package/dist/ui/components/ScrollableContent.svelte.d.ts +0 -31
- package/dist/ui/components/Section.svelte +0 -97
- package/dist/ui/components/Section.svelte.d.ts +0 -50
- package/dist/ui/components/Spacer.svelte +0 -9
- package/dist/ui/components/Spacer.svelte.d.ts +0 -22
- package/dist/ui/components/SpinnerPlusMinus.svelte +0 -75
- package/dist/ui/components/SpinnerPlusMinus.svelte.d.ts +0 -23
- package/dist/ui/components/SpinnerUpDown.svelte +0 -194
- package/dist/ui/components/SpinnerUpDown.svelte.d.ts +0 -31
- package/dist/ui/components/Tabs.svelte +0 -71
- package/dist/ui/components/Tabs.svelte.d.ts +0 -26
- package/dist/ui/components/ToggleItem.svelte +0 -29
- package/dist/ui/components/ToggleList.svelte +0 -57
- package/dist/ui/components/buttons/FooterButton.svelte.d.ts +0 -10
- package/dist/ui/components/buttons/index.d.ts +0 -5
- package/dist/ui/components/buttons/index.js +0 -5
- package/dist/ui/components/clickable/Clickable.stories.svelte +0 -213
- package/dist/ui/components/clickable/Clickable.svelte +0 -93
- package/dist/ui/components/clickable/Clickable.svelte.d.ts +0 -4
- package/dist/ui/components/clickable/index.d.ts +0 -2
- package/dist/ui/components/clickable/index.js +0 -1
- package/dist/ui/components/clickable/types.d.ts +0 -17
- package/dist/utils/api/copyPaste/index.d.ts +0 -18
- /package/dist/router/{Link.svelte.d.ts → providers/Link.svelte.d.ts} +0 -0
- /package/dist/ui/components/{buttons → button-group}/types.js +0 -0
- /package/dist/ui/components/{clickable → checkbox}/types.js +0 -0
- /package/dist/{utils/api/copyPaste/index.js → ui/components/controlled-buttons/types.js} +0 -0
- /package/dist/ui/components/layout/{ExampleLayout.svelte.d.ts → examples/ExampleLayout.svelte.d.ts} +0 -0
- /package/dist/ui/components/{ImageUpload.svelte.d.ts → shared/ImageUpload.svelte.d.ts} +0 -0
- /package/dist/ui/components/{SelectBodyOrDivBlock.svelte.d.ts → shared/SelectBodyOrDivBlock.svelte.d.ts} +0 -0
|
@@ -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;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import RouterExample from './examples/RouterExample.svelte';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Containers/Router',
|
|
4
|
+
component: RouterExample,
|
|
5
|
+
parameters: {
|
|
6
|
+
layout: 'fullscreen'
|
|
7
|
+
},
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
argTypes: {}
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
export const CompleteExample = {
|
|
13
|
+
args: {},
|
|
14
|
+
parameters: {
|
|
15
|
+
docs: {
|
|
16
|
+
description: {
|
|
17
|
+
story: `
|
|
18
|
+
## Complete Router Example
|
|
19
|
+
|
|
20
|
+
This is a full-featured router implementation demonstrating:
|
|
21
|
+
|
|
22
|
+
### Routes Implemented:
|
|
23
|
+
- **Home Route** (\`/\`) - Landing page with feature overview
|
|
24
|
+
- **About Route** (\`/about\`) - Main about page with navigation cards
|
|
25
|
+
- **About Sections** (\`/about/:section\`) - Dynamic sections (team, history, mission)
|
|
26
|
+
- **404 Route** - Custom not found page with helpful navigation
|
|
27
|
+
|
|
28
|
+
### Features Demonstrated:
|
|
29
|
+
- **Link Components** - Active state management and navigation
|
|
30
|
+
- **Programmatic Navigation** - Using \`useNavigate()\` hook
|
|
31
|
+
- **Route Parameters** - Dynamic \`:section\` parameter handling
|
|
32
|
+
- **App Version Support** - Persistent version hash across all navigation
|
|
33
|
+
- **Debug Information** - Real-time route and parameter display
|
|
34
|
+
- **History Management** - Back/forward navigation support
|
|
35
|
+
|
|
36
|
+
### Navigation Examples:
|
|
37
|
+
- Click navigation links to see active states
|
|
38
|
+
- Use back/forward buttons to test history
|
|
39
|
+
- Try direct URL changes to test route matching
|
|
40
|
+
- Visit invalid routes to see 404 handling
|
|
41
|
+
|
|
42
|
+
The example shows how the router maintains app version hashes automatically while providing clean route definitions and reactive state management.
|
|
43
|
+
`
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import { Link, Route, RouterProvider } from '../providers';
|
|
5
|
+
import { createRouter } from '../router.svelte';
|
|
6
|
+
import AboutPage from './pages/AboutPage.svelte';
|
|
7
|
+
// Page Components
|
|
8
|
+
import HomePage from './pages/HomePage.svelte';
|
|
9
|
+
import NotFoundPage from './pages/NotFoundPage.svelte';
|
|
10
|
+
|
|
11
|
+
// Create router instance with configuration
|
|
12
|
+
const router = createRouter({
|
|
13
|
+
basePath: '',
|
|
14
|
+
hashMode: false,
|
|
15
|
+
fallbackRoute: '/',
|
|
16
|
+
autoInit: false
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Add routes
|
|
20
|
+
router.addRoutes([
|
|
21
|
+
{ path: '/', component: HomePage, meta: { title: 'Home' } },
|
|
22
|
+
{ path: '/about', component: AboutPage, meta: { title: 'About' } },
|
|
23
|
+
{ path: '/about/:section', component: AboutPage, meta: { title: 'About Section' } },
|
|
24
|
+
{ path: '*', component: NotFoundPage, meta: { title: 'Not Found' } }
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
onMount(() => {
|
|
28
|
+
router.init();
|
|
29
|
+
});
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<div class="router-example">
|
|
33
|
+
<h2>Router Example</h2>
|
|
34
|
+
<p>This example demonstrates the Router component with navigation between pages.</p>
|
|
35
|
+
|
|
36
|
+
<RouterProvider {router}>
|
|
37
|
+
{#snippet children({ router, currentRoute, currentLocation, isNavigating })}
|
|
38
|
+
<div class="app-layout">
|
|
39
|
+
<!-- Navigation -->
|
|
40
|
+
<nav class="navigation">
|
|
41
|
+
<div class="nav-brand">
|
|
42
|
+
<h3>My App</h3>
|
|
43
|
+
</div>
|
|
44
|
+
<ul class="nav-links">
|
|
45
|
+
<li>
|
|
46
|
+
<Link to="/" exact activeClass="active">Home</Link>
|
|
47
|
+
</li>
|
|
48
|
+
<li>
|
|
49
|
+
<Link to="/about" activeClass="active">About</Link>
|
|
50
|
+
</li>
|
|
51
|
+
<li>
|
|
52
|
+
<Link to="/about/team" activeClass="active">About Team</Link>
|
|
53
|
+
</li>
|
|
54
|
+
<li>
|
|
55
|
+
<Link to="/contact" activeClass="active">Contact (404)</Link>
|
|
56
|
+
</li>
|
|
57
|
+
</ul>
|
|
58
|
+
</nav>
|
|
59
|
+
|
|
60
|
+
<!-- Loading indicator -->
|
|
61
|
+
{#if isNavigating}
|
|
62
|
+
<div class="loading-indicator">
|
|
63
|
+
<div class="spinner"></div>
|
|
64
|
+
Navigating...
|
|
65
|
+
</div>
|
|
66
|
+
{/if}
|
|
67
|
+
|
|
68
|
+
<!-- Route information display -->
|
|
69
|
+
<div class="route-info">
|
|
70
|
+
<strong>Current Route:</strong>
|
|
71
|
+
{currentLocation?.pathname || 'None'}<br />
|
|
72
|
+
<strong>Route Title:</strong>
|
|
73
|
+
{currentRoute?.meta?.title || 'Unknown'}<br />
|
|
74
|
+
<strong>Parameters:</strong>
|
|
75
|
+
{JSON.stringify(currentLocation?.params || {})}<br />
|
|
76
|
+
<strong>Query:</strong>
|
|
77
|
+
{currentLocation?.search || 'None'}
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
<!-- Main content area -->
|
|
81
|
+
<main class="main-content">
|
|
82
|
+
<!-- Home Route -->
|
|
83
|
+
<Route path="/">
|
|
84
|
+
{#snippet children({ params, location, router, isActive })}
|
|
85
|
+
{#if isActive}
|
|
86
|
+
<HomePage {params} {location} {router} />
|
|
87
|
+
{/if}
|
|
88
|
+
{/snippet}
|
|
89
|
+
</Route>
|
|
90
|
+
|
|
91
|
+
<!-- About Route (with optional section parameter) -->
|
|
92
|
+
<Route path="/about">
|
|
93
|
+
{#snippet children({ params, location, router, isActive })}
|
|
94
|
+
{#if isActive}
|
|
95
|
+
<AboutPage {params} {location} {router} />
|
|
96
|
+
{/if}
|
|
97
|
+
{/snippet}
|
|
98
|
+
</Route>
|
|
99
|
+
|
|
100
|
+
<!-- About with section parameter -->
|
|
101
|
+
<Route path="/about/:section">
|
|
102
|
+
{#snippet children({ params, location, router, isActive })}
|
|
103
|
+
{#if isActive}
|
|
104
|
+
<AboutPage {params} {location} {router} />
|
|
105
|
+
{/if}
|
|
106
|
+
{/snippet}
|
|
107
|
+
</Route>
|
|
108
|
+
|
|
109
|
+
<!-- Fallback route (404) -->
|
|
110
|
+
<Route path="*" exact={false}>
|
|
111
|
+
{#snippet children({ params, location, router, isActive })}
|
|
112
|
+
{#if isActive && !router.isActive('/') && !router.isActive('/about')}
|
|
113
|
+
<NotFoundPage {params} {location} {router} />
|
|
114
|
+
{/if}
|
|
115
|
+
{/snippet}
|
|
116
|
+
</Route>
|
|
117
|
+
</main>
|
|
118
|
+
|
|
119
|
+
<!-- Router controls -->
|
|
120
|
+
<div class="router-controls">
|
|
121
|
+
<h4>Router Controls</h4>
|
|
122
|
+
<div class="controls-grid">
|
|
123
|
+
<button onclick={() => router.navigate('/')}> Go Home </button>
|
|
124
|
+
<button onclick={() => router.navigate('/about')}> Go to About </button>
|
|
125
|
+
<button onclick={() => router.navigate('/about/team')}> Go to Team </button>
|
|
126
|
+
<button onclick={() => router.back()}> ← Back </button>
|
|
127
|
+
<button onclick={() => router.forward()}> Forward → </button>
|
|
128
|
+
<button onclick={() => router.navigate('/random-page')}> 404 Page </button>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
{/snippet}
|
|
133
|
+
</RouterProvider>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<style>
|
|
137
|
+
.router-example {
|
|
138
|
+
width: 100%;
|
|
139
|
+
max-width: 800px;
|
|
140
|
+
margin: 0 auto;
|
|
141
|
+
padding: 1rem;
|
|
142
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.app-layout {
|
|
146
|
+
border: 1px solid #e1e5e9;
|
|
147
|
+
border-radius: 8px;
|
|
148
|
+
overflow: hidden;
|
|
149
|
+
background: white;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.navigation {
|
|
153
|
+
display: flex;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: space-between;
|
|
156
|
+
padding: 1rem 1.5rem;
|
|
157
|
+
background: #f8f9fa;
|
|
158
|
+
border-bottom: 1px solid #e1e5e9;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.nav-brand h3 {
|
|
162
|
+
margin: 0;
|
|
163
|
+
color: #2c3e50;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.nav-links {
|
|
167
|
+
display: flex;
|
|
168
|
+
list-style: none;
|
|
169
|
+
margin: 0;
|
|
170
|
+
padding: 0;
|
|
171
|
+
gap: 1rem;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.nav-links :global(a) {
|
|
175
|
+
padding: 0.5rem 1rem;
|
|
176
|
+
text-decoration: none;
|
|
177
|
+
color: #6c757d;
|
|
178
|
+
border-radius: 4px;
|
|
179
|
+
transition: all 0.2s ease;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.nav-links :global(a:hover) {
|
|
183
|
+
background: #e9ecef;
|
|
184
|
+
color: #495057;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.nav-links :global(a.active) {
|
|
188
|
+
background: #007bff;
|
|
189
|
+
color: white;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.loading-indicator {
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: center;
|
|
195
|
+
gap: 0.5rem;
|
|
196
|
+
padding: 0.75rem 1.5rem;
|
|
197
|
+
background: #fff3cd;
|
|
198
|
+
border-bottom: 1px solid #ffeaa7;
|
|
199
|
+
color: #856404;
|
|
200
|
+
font-size: 0.875rem;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.spinner {
|
|
204
|
+
width: 16px;
|
|
205
|
+
height: 16px;
|
|
206
|
+
border: 2px solid #ffeaa7;
|
|
207
|
+
border-top: 2px solid #856404;
|
|
208
|
+
border-radius: 50%;
|
|
209
|
+
animation: spin 1s linear infinite;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@keyframes spin {
|
|
213
|
+
0% {
|
|
214
|
+
transform: rotate(0deg);
|
|
215
|
+
}
|
|
216
|
+
100% {
|
|
217
|
+
transform: rotate(360deg);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.route-info {
|
|
222
|
+
padding: 1rem 1.5rem;
|
|
223
|
+
background: #f8f9fa;
|
|
224
|
+
border-bottom: 1px solid #e1e5e9;
|
|
225
|
+
font-size: 0.875rem;
|
|
226
|
+
color: #6c757d;
|
|
227
|
+
line-height: 1.5;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.main-content {
|
|
231
|
+
min-height: 300px;
|
|
232
|
+
padding: 2rem 1.5rem;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.router-controls {
|
|
236
|
+
padding: 1.5rem;
|
|
237
|
+
background: #f8f9fa;
|
|
238
|
+
border-top: 1px solid #e1e5e9;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.router-controls h4 {
|
|
242
|
+
margin: 0 0 1rem 0;
|
|
243
|
+
color: #2c3e50;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.controls-grid {
|
|
247
|
+
display: grid;
|
|
248
|
+
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
|
249
|
+
gap: 0.5rem;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.controls-grid button {
|
|
253
|
+
padding: 0.5rem 1rem;
|
|
254
|
+
border: 1px solid #ddd;
|
|
255
|
+
border-radius: 4px;
|
|
256
|
+
background: white;
|
|
257
|
+
color: #495057;
|
|
258
|
+
cursor: pointer;
|
|
259
|
+
font-size: 0.875rem;
|
|
260
|
+
transition: all 0.2s ease;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.controls-grid button:hover {
|
|
264
|
+
background: #f8f9fa;
|
|
265
|
+
border-color: #adb5bd;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.controls-grid button:active {
|
|
269
|
+
background: #e9ecef;
|
|
270
|
+
}
|
|
271
|
+
</style>
|
|
@@ -11,8 +11,8 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
|
|
|
11
11
|
};
|
|
12
12
|
z_$$bindings?: Bindings;
|
|
13
13
|
}
|
|
14
|
-
declare const
|
|
14
|
+
declare const RouterExample: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
15
|
[evt: string]: CustomEvent<any>;
|
|
16
16
|
}, {}, {}, string>;
|
|
17
|
-
type
|
|
18
|
-
export default
|
|
17
|
+
type RouterExample = InstanceType<typeof RouterExample>;
|
|
18
|
+
export default RouterExample;
|