@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,101 @@
|
|
|
1
|
+
import { animate, stagger as staggerDelay } from 'motion';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Animation.
|
|
4
|
+
* @param props The animaiton props.
|
|
5
|
+
* @returns A new `in` and `out` Animation functions.
|
|
6
|
+
*/
|
|
7
|
+
export const createAnimation = ({ initialStyles, keyframes }) => {
|
|
8
|
+
const isBrowser = typeof window !== 'undefined';
|
|
9
|
+
/**
|
|
10
|
+
* Prepares the {@link animateIn} elements by setting the initial styles and rendering them to the DOM.
|
|
11
|
+
* @param elements The elements to prepare.
|
|
12
|
+
* @param options.target If defined, the element will be appended to the target.
|
|
13
|
+
* @param options.insertAfter A child of the target. If defined, the element will be appended right after this anchor element.
|
|
14
|
+
*/
|
|
15
|
+
const prepareIn = (elements, options = {}) => {
|
|
16
|
+
const { target, insertAfter, display = '' } = options;
|
|
17
|
+
if (!Array.isArray(elements))
|
|
18
|
+
elements = [elements];
|
|
19
|
+
for (const element of elements) {
|
|
20
|
+
element.style.display = display;
|
|
21
|
+
Object.assign(element.style, initialStyles);
|
|
22
|
+
if (target && insertAfter !== undefined) {
|
|
23
|
+
if (insertAfter)
|
|
24
|
+
target.insertBefore(element, insertAfter.nextSibling);
|
|
25
|
+
else {
|
|
26
|
+
if (isBrowser && target instanceof HTMLElement) {
|
|
27
|
+
target.insertBefore(element, target.firstChild);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (target)
|
|
32
|
+
target.appendChild(element);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* In animation.
|
|
37
|
+
* @param elements The elements to animate.
|
|
38
|
+
* @param options.target If defined, the element will be appended to the target.
|
|
39
|
+
* @param options.insertAfter A child of the target. If defined, the element will be appended right after this anchor element.
|
|
40
|
+
* @param options.prepared Defines if the animation has been prepared beforehand, useful to avoid performing double preparation.
|
|
41
|
+
* @param options.stagger If defined, the animation will be staggered using this time value.
|
|
42
|
+
* @param options.animationOptions The main options of the animation. Reference: {@link [Motion One](https://motion.dev/dom/animate#options)}.
|
|
43
|
+
* @returns An awaitable promise.
|
|
44
|
+
*/
|
|
45
|
+
const animateIn = async (elements, options = {}) => {
|
|
46
|
+
//TODO: probably display can be used also?
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
48
|
+
const { prepared, stagger, display, duration, ...animationOptions } = options;
|
|
49
|
+
const durationInSeconds = duration ? duration / 1000 : undefined;
|
|
50
|
+
if (!prepared)
|
|
51
|
+
prepareIn(elements, options);
|
|
52
|
+
const { finished } = animate(elements, keyframes, {
|
|
53
|
+
...animationOptions,
|
|
54
|
+
delay: stagger ? staggerDelay(stagger / 1000) : undefined,
|
|
55
|
+
duration: durationInSeconds
|
|
56
|
+
});
|
|
57
|
+
return await finished;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Out animation.
|
|
61
|
+
* @param elements The elements to animate.
|
|
62
|
+
* @param options.remove If defined, the element will be removed from the DOM after the animation ends.
|
|
63
|
+
* @param options.stagger If defined, the animation will be staggered using this time value.
|
|
64
|
+
* @param options.animationOptions The main options of the animation. Reference: {@link [Motion One](https://motion.dev/dom/animate#options)}.
|
|
65
|
+
* @returns An awaitable promise.
|
|
66
|
+
*/
|
|
67
|
+
const animateOut = async (elements, options = {}) => {
|
|
68
|
+
const { remove, stagger, target, insertAfter, display = 'none', duration, ...animationOptions } = options;
|
|
69
|
+
const durationInSeconds = duration ? duration / 1000 : undefined;
|
|
70
|
+
if (!Array.isArray(elements))
|
|
71
|
+
elements = [elements];
|
|
72
|
+
elements = elements.filter((element) => document.body.contains(element));
|
|
73
|
+
if (!elements.length)
|
|
74
|
+
return;
|
|
75
|
+
const { finished } = animate(elements, keyframes, {
|
|
76
|
+
...animationOptions,
|
|
77
|
+
duration: durationInSeconds,
|
|
78
|
+
delay: stagger ? staggerDelay(stagger / 1000) : undefined,
|
|
79
|
+
direction: 'reverse'
|
|
80
|
+
});
|
|
81
|
+
await finished;
|
|
82
|
+
for (const element of elements) {
|
|
83
|
+
if (target && insertAfter !== undefined) {
|
|
84
|
+
if (insertAfter)
|
|
85
|
+
target.insertBefore(element, insertAfter.nextSibling);
|
|
86
|
+
else {
|
|
87
|
+
if (isBrowser && target instanceof HTMLElement) {
|
|
88
|
+
target.insertBefore(element, target.firstChild);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (target)
|
|
93
|
+
target.appendChild(element);
|
|
94
|
+
if (remove)
|
|
95
|
+
element.remove();
|
|
96
|
+
else
|
|
97
|
+
element.style.display = display;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return { prepareIn, animateIn, animateOut };
|
|
101
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnimationsObject } from './types';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export declare const easings: readonly ["linear", "ease", "ease-in", "ease-out", "ease-in-out"];
|
|
4
|
+
/**
|
|
5
|
+
* Contains all animation functions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const animations: AnimationsObject;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createAnimation } from './factory';
|
|
2
|
+
export * from './types';
|
|
3
|
+
// Constants
|
|
4
|
+
export const easings = ['linear', 'ease', 'ease-in', 'ease-out', 'ease-in-out'];
|
|
5
|
+
/**
|
|
6
|
+
* Contains all animation functions.
|
|
7
|
+
*/
|
|
8
|
+
export const animations = {
|
|
9
|
+
/**
|
|
10
|
+
* Fade
|
|
11
|
+
*/
|
|
12
|
+
fade: createAnimation({ keyframes: { opacity: [0, 1] }, initialStyles: { opacity: '0' } }),
|
|
13
|
+
/**
|
|
14
|
+
* Slide Up
|
|
15
|
+
*/
|
|
16
|
+
'slide-up': createAnimation({
|
|
17
|
+
keyframes: { y: [100, 0], opacity: [0, 1] },
|
|
18
|
+
initialStyles: { transform: 'translateY(100px)', opacity: '0' }
|
|
19
|
+
}),
|
|
20
|
+
/**
|
|
21
|
+
* Slide Down
|
|
22
|
+
*/
|
|
23
|
+
'slide-down': createAnimation({
|
|
24
|
+
keyframes: { y: [-100, 0], opacity: [0, 1] },
|
|
25
|
+
initialStyles: { transform: 'translateY(-100px)', opacity: '0' }
|
|
26
|
+
}),
|
|
27
|
+
/**
|
|
28
|
+
* Slide Right
|
|
29
|
+
*/
|
|
30
|
+
'slide-right': createAnimation({
|
|
31
|
+
keyframes: { x: [-100, 0], opacity: [0, 1] },
|
|
32
|
+
initialStyles: { transform: 'translateX(-100px)', opacity: '0' }
|
|
33
|
+
}),
|
|
34
|
+
/**
|
|
35
|
+
* Slide Left
|
|
36
|
+
*/
|
|
37
|
+
'slide-left': createAnimation({
|
|
38
|
+
keyframes: { x: [100, 0], opacity: [0, 1] },
|
|
39
|
+
initialStyles: { transform: 'translateX(100px)', opacity: '0' }
|
|
40
|
+
}),
|
|
41
|
+
/**
|
|
42
|
+
* Grow
|
|
43
|
+
*/
|
|
44
|
+
grow: createAnimation({
|
|
45
|
+
keyframes: { scale: [0, 1], opacity: [0, 1] },
|
|
46
|
+
initialStyles: { transform: 'scale(0)', opacity: '0' }
|
|
47
|
+
}),
|
|
48
|
+
/**
|
|
49
|
+
* Shrink
|
|
50
|
+
*/
|
|
51
|
+
shrink: createAnimation({
|
|
52
|
+
keyframes: { scale: [1.25, 1], opacity: [0, 1] },
|
|
53
|
+
initialStyles: { transform: 'scale(1.25)', opacity: '0' }
|
|
54
|
+
}),
|
|
55
|
+
/**
|
|
56
|
+
* Spin
|
|
57
|
+
*/
|
|
58
|
+
spin: createAnimation({
|
|
59
|
+
keyframes: { rotate: [900, 0], opacity: [0, 1] },
|
|
60
|
+
initialStyles: { transform: 'rotate(900deg)', opacity: '0' }
|
|
61
|
+
})
|
|
62
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AnimationOptions, MotionKeyframesDefinition } from 'motion';
|
|
2
|
+
import type { easings } from '.';
|
|
3
|
+
export interface AnimationProps {
|
|
4
|
+
keyframes: MotionKeyframesDefinition;
|
|
5
|
+
initialStyles: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
type FilteredAnimationOptions = Pick<AnimationOptions, 'duration' | 'easing'> & {
|
|
10
|
+
stagger?: number;
|
|
11
|
+
};
|
|
12
|
+
type AnimationPrepare<T> = (element: HTMLElement | HTMLElement[], options?: T) => void;
|
|
13
|
+
type AnimationBase<T> = (element: HTMLElement | HTMLElement[], options?: T & FilteredAnimationOptions) => Promise<void>;
|
|
14
|
+
type PrepareProps = {
|
|
15
|
+
target?: Element;
|
|
16
|
+
insertAfter?: Node | null;
|
|
17
|
+
display?: string;
|
|
18
|
+
};
|
|
19
|
+
type AnimationInProps = PrepareProps & {
|
|
20
|
+
prepared?: true;
|
|
21
|
+
};
|
|
22
|
+
type AnimationOutProps = PrepareProps & {
|
|
23
|
+
remove?: boolean;
|
|
24
|
+
};
|
|
25
|
+
type PrepareIn = AnimationPrepare<PrepareProps>;
|
|
26
|
+
type AnimationIn = AnimationBase<AnimationInProps>;
|
|
27
|
+
type AnimationOut = AnimationBase<AnimationOutProps>;
|
|
28
|
+
export type AnimationFunctions = {
|
|
29
|
+
prepareIn: PrepareIn;
|
|
30
|
+
animateIn: AnimationIn;
|
|
31
|
+
animateOut: AnimationOut;
|
|
32
|
+
};
|
|
33
|
+
export type Animation = AnimationFunctions & {
|
|
34
|
+
options?: FilteredAnimationOptions;
|
|
35
|
+
};
|
|
36
|
+
export type AnimationsObject = Readonly<Record<'fade' | 'slide-up' | 'slide-down' | 'slide-right' | 'slide-left' | 'grow' | 'shrink' | 'spin', AnimationFunctions>>;
|
|
37
|
+
export type Easings = typeof easings;
|
|
38
|
+
export type AnimationOptionsCustom = Readonly<Record<'fade' | 'slide-up' | 'slide-down' | 'slide-right' | 'slide-left' | 'grow' | 'shrink' | 'spin', string>>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
meta: {
|
|
3
|
-
droppedLinks: number;
|
|
4
|
-
dynBindRemovedCount: number;
|
|
5
|
-
dynListBindRemovedCount: number;
|
|
6
|
-
paginationRemovedCount: number;
|
|
7
|
-
universalBindingsRemovedCount: number;
|
|
8
|
-
unlinkedSymbolCount: number;
|
|
9
|
-
};
|
|
10
|
-
type: string;
|
|
11
|
-
payload: {
|
|
12
|
-
nodes: PastedNodes[];
|
|
13
|
-
styles: {
|
|
14
|
-
name: string;
|
|
15
|
-
type: string | 'class';
|
|
16
|
-
}[];
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
type PastedNodes = {
|
|
20
|
-
children: string[];
|
|
21
|
-
classes: string[];
|
|
22
|
-
tag: string;
|
|
23
|
-
type: string;
|
|
24
|
-
data: {
|
|
25
|
-
xattr: Attr[];
|
|
26
|
-
};
|
|
27
|
-
};
|
|
1
|
+
import type { XSCPMetadata } from '../../../types';
|
|
28
2
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param component
|
|
31
|
-
* @param strict - if true, check for exact match, else check for any child
|
|
3
|
+
* Processes pasted component data to validate Finsweet components.
|
|
32
4
|
*/
|
|
33
|
-
export declare const processPastedComponent: (pasteData:
|
|
34
|
-
data:
|
|
5
|
+
export declare const processPastedComponent: (pasteData: XSCPMetadata, component: string) => {
|
|
6
|
+
data: XSCPMetadata;
|
|
35
7
|
key: string;
|
|
36
8
|
} | undefined;
|
|
37
9
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param e
|
|
40
|
-
* @param strict - if true, check for exact match, else check for any child
|
|
10
|
+
* Handles pasting of Webflow components from clipboard.
|
|
41
11
|
*/
|
|
42
12
|
export declare const handlePasteXSCP: (e: ClipboardEvent, component: string) => {
|
|
43
|
-
data:
|
|
13
|
+
data: XSCPMetadata;
|
|
44
14
|
key: string;
|
|
45
15
|
} | undefined;
|
|
46
|
-
export {};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { getLogger } from '../../logger';
|
|
2
2
|
const logger = getLogger('webflow-apps-ui-utils');
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param component
|
|
6
|
-
* @param strict - if true, check for exact match, else check for any child
|
|
4
|
+
* Processes pasted component data to validate Finsweet components.
|
|
7
5
|
*/
|
|
8
6
|
export const processPastedComponent = (pasteData, component) => {
|
|
9
7
|
const valid = pasteData?.payload?.nodes?.some((node) => node?.data?.xattr?.some((attr) => {
|
|
@@ -20,9 +18,7 @@ export const processPastedComponent = (pasteData, component) => {
|
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
20
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param e
|
|
25
|
-
* @param strict - if true, check for exact match, else check for any child
|
|
21
|
+
* Handles pasting of Webflow components from clipboard.
|
|
26
22
|
*/
|
|
27
23
|
export const handlePasteXSCP = (e, component) => {
|
|
28
24
|
if (!e.clipboardData?.types.includes('application/json'))
|
|
@@ -9,9 +9,7 @@ const URL_DEV_MODE_API_KEY = 'api';
|
|
|
9
9
|
let lastLogTime = 0;
|
|
10
10
|
const LOG_THROTTLE_MS = 3000;
|
|
11
11
|
/**
|
|
12
|
-
* Gets a parameter value from the URL search params
|
|
13
|
-
* @param key The key to search for in URL parameters
|
|
14
|
-
* @returns The value of the parameter or null if not found
|
|
12
|
+
* Gets a parameter value from the URL search params.
|
|
15
13
|
*/
|
|
16
14
|
const getUrlParam = (key) => {
|
|
17
15
|
if (typeof window === 'undefined')
|
|
@@ -26,7 +24,7 @@ const getUrlParam = (key) => {
|
|
|
26
24
|
}
|
|
27
25
|
};
|
|
28
26
|
/**
|
|
29
|
-
*
|
|
27
|
+
* Throttled console log that only logs once within the throttle interval.
|
|
30
28
|
*/
|
|
31
29
|
const throttledLog = (message, data) => {
|
|
32
30
|
const now = Date.now();
|
|
@@ -36,8 +34,7 @@ const throttledLog = (message, data) => {
|
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
36
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @returns
|
|
37
|
+
* Gets the Finsweet components environment configuration.
|
|
41
38
|
*/
|
|
42
39
|
export const getFinsweetComponentsEnvironment = () => {
|
|
43
40
|
const devFromUrl = getUrlParam(URL_DEV_MODE_KEY);
|
package/dist/utils/api/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param template - the template to insert, should be a string
|
|
2
|
+
* Inserts a template into the Designer Canvas using XSCP APIs.
|
|
4
3
|
*/
|
|
5
4
|
export declare const insertWithXSCP: (template: string) => Promise<void>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AUTH0_AUDIENCE, AUTH0_CLIENT_ID, AUTH0_LOGIN_URL, AUTH0_REDIRECT_URL, AUTH0_SCOPE, PROD_FINSWEEET_ACCOUNTS_ORIGIN } from '../constants';
|
|
2
|
+
/**
|
|
3
|
+
* Opens a popup window for cross-window authentication with Auth0.
|
|
4
|
+
*/
|
|
2
5
|
export const crossWindowLogin = () => {
|
|
3
6
|
return new Promise((resolve, reject) => {
|
|
4
7
|
const timeout = setTimeout(() => {
|
|
@@ -5,55 +5,39 @@ import type { FinsweetAuth } from '../../types';
|
|
|
5
5
|
export declare const finsweetUser: import("svelte/store").Writable<FinsweetAuth | null>;
|
|
6
6
|
export declare const isLoggingIn: import("svelte/store").Writable<boolean>;
|
|
7
7
|
/**
|
|
8
|
-
* Fetches subscriptions from the server.
|
|
9
|
-
* @param token
|
|
10
|
-
* @returns
|
|
8
|
+
* Fetches user subscriptions from the server.
|
|
11
9
|
*/
|
|
12
10
|
export declare const getSubscriptions: (token: string) => Promise<any>;
|
|
13
11
|
/**
|
|
14
|
-
* Fetches user data from the server.
|
|
15
|
-
* @param token
|
|
16
|
-
* @returns
|
|
12
|
+
* Fetches user data from the authentication server.
|
|
17
13
|
*/
|
|
18
14
|
export declare const getUser: (token: string) => Promise<FinsweetAuth["user"]>;
|
|
19
15
|
/**
|
|
20
|
-
* Handles login
|
|
21
|
-
* @returns void
|
|
16
|
+
* Handles user login authentication flow.
|
|
22
17
|
*/
|
|
23
18
|
export declare const handleLogin: () => Promise<void>;
|
|
24
19
|
/**
|
|
25
|
-
* Handles logout
|
|
20
|
+
* Handles user logout and cleanup.
|
|
26
21
|
*/
|
|
27
22
|
export declare const handleLogout: () => Promise<void>;
|
|
28
23
|
/**
|
|
29
|
-
* Checks if the user is logged in by
|
|
24
|
+
* Checks if the user is logged in by validating stored session.
|
|
30
25
|
*/
|
|
31
26
|
export declare const checkInitialLoginState: () => Promise<void>;
|
|
32
27
|
/**
|
|
33
|
-
* Sets a cookie
|
|
34
|
-
* @param {string} name - Name of the cookie
|
|
35
|
-
* @param {string} value - Value of the cookie
|
|
36
|
-
* @param {Object} options - Options for the cookie (expires, path, etc.)
|
|
28
|
+
* Sets a cookie with security options.
|
|
37
29
|
*/
|
|
38
30
|
export declare const setCookie: (name: string, value: string, options?: {}) => void;
|
|
39
31
|
/**
|
|
40
|
-
* Gets a cookie
|
|
41
|
-
* @param {string} name - Name of the cookie to retrieve
|
|
42
|
-
* @returns {string | undefined} - Value of the cookie, if found
|
|
32
|
+
* Gets a cookie value by name.
|
|
43
33
|
*/
|
|
44
34
|
export declare const getCookie: (name: string) => string | undefined;
|
|
45
35
|
/**
|
|
46
|
-
* Deletes a cookie
|
|
47
|
-
* @param {string} name - Name of the cookie to delete
|
|
48
|
-
* @param {Object} options - Options for the cookie (path, etc.)
|
|
36
|
+
* Deletes a cookie by name.
|
|
49
37
|
*/
|
|
50
38
|
export declare const deleteCookie: (name: string, options?: {}) => void;
|
|
51
39
|
/**
|
|
52
|
-
* Checks if the user has access to a feature
|
|
53
|
-
* @param loggedIn
|
|
54
|
-
* @param access
|
|
55
|
-
* @param required
|
|
56
|
-
* @returns
|
|
40
|
+
* Checks if the user has access to a specific feature.
|
|
57
41
|
*/
|
|
58
42
|
export declare const canAccessFeature: (loggedIn: boolean, access: FinsweetAuth["user"]["libraryAccess"] | null | undefined, required: FinsweetAuth["user"]["libraryAccess"]) => {
|
|
59
43
|
granted: boolean;
|
package/dist/utils/auth/index.js
CHANGED
|
@@ -34,9 +34,7 @@ const checkLibraryAccess = (user, subscriptions) => {
|
|
|
34
34
|
return ['canFavourite'];
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
|
-
* Fetches subscriptions from the server.
|
|
38
|
-
* @param token
|
|
39
|
-
* @returns
|
|
37
|
+
* Fetches user subscriptions from the server.
|
|
40
38
|
*/
|
|
41
39
|
export const getSubscriptions = async (token) => {
|
|
42
40
|
try {
|
|
@@ -58,9 +56,7 @@ export const getSubscriptions = async (token) => {
|
|
|
58
56
|
}
|
|
59
57
|
};
|
|
60
58
|
/**
|
|
61
|
-
* Fetches user data from the server.
|
|
62
|
-
* @param token
|
|
63
|
-
* @returns
|
|
59
|
+
* Fetches user data from the authentication server.
|
|
64
60
|
*/
|
|
65
61
|
export const getUser = async (token) => {
|
|
66
62
|
const response = await fetch('/auth0/verify', {
|
|
@@ -73,8 +69,7 @@ export const getUser = async (token) => {
|
|
|
73
69
|
return data;
|
|
74
70
|
};
|
|
75
71
|
/**
|
|
76
|
-
* Handles login
|
|
77
|
-
* @returns void
|
|
72
|
+
* Handles user login authentication flow.
|
|
78
73
|
*/
|
|
79
74
|
export const handleLogin = async () => {
|
|
80
75
|
if (get(isLoggingIn))
|
|
@@ -112,7 +107,7 @@ export const handleLogin = async () => {
|
|
|
112
107
|
}
|
|
113
108
|
};
|
|
114
109
|
/**
|
|
115
|
-
* Handles logout
|
|
110
|
+
* Handles user logout and cleanup.
|
|
116
111
|
*/
|
|
117
112
|
export const handleLogout = async () => {
|
|
118
113
|
removeLocalStorage('finsweetComponentsAuth');
|
|
@@ -124,7 +119,7 @@ export const handleLogout = async () => {
|
|
|
124
119
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
125
120
|
};
|
|
126
121
|
/**
|
|
127
|
-
* Checks if the user is logged in by
|
|
122
|
+
* Checks if the user is logged in by validating stored session.
|
|
128
123
|
*/
|
|
129
124
|
export const checkInitialLoginState = async () => {
|
|
130
125
|
const session = getLocalStorage('finsweetComponentsAuth');
|
|
@@ -150,36 +145,25 @@ export const checkInitialLoginState = async () => {
|
|
|
150
145
|
await handleLogout();
|
|
151
146
|
};
|
|
152
147
|
/**
|
|
153
|
-
* Sets a cookie
|
|
154
|
-
* @param {string} name - Name of the cookie
|
|
155
|
-
* @param {string} value - Value of the cookie
|
|
156
|
-
* @param {Object} options - Options for the cookie (expires, path, etc.)
|
|
148
|
+
* Sets a cookie with security options.
|
|
157
149
|
*/
|
|
158
150
|
export const setCookie = (name, value, options = {}) => {
|
|
159
151
|
Cookies.set(name, value, { sameSite: 'None', secure: true, ...options });
|
|
160
152
|
};
|
|
161
153
|
/**
|
|
162
|
-
* Gets a cookie
|
|
163
|
-
* @param {string} name - Name of the cookie to retrieve
|
|
164
|
-
* @returns {string | undefined} - Value of the cookie, if found
|
|
154
|
+
* Gets a cookie value by name.
|
|
165
155
|
*/
|
|
166
156
|
export const getCookie = (name) => {
|
|
167
157
|
return Cookies.get(name);
|
|
168
158
|
};
|
|
169
159
|
/**
|
|
170
|
-
* Deletes a cookie
|
|
171
|
-
* @param {string} name - Name of the cookie to delete
|
|
172
|
-
* @param {Object} options - Options for the cookie (path, etc.)
|
|
160
|
+
* Deletes a cookie by name.
|
|
173
161
|
*/
|
|
174
162
|
export const deleteCookie = (name, options = {}) => {
|
|
175
163
|
Cookies.remove(name, options);
|
|
176
164
|
};
|
|
177
165
|
/**
|
|
178
|
-
* Checks if the user has access to a feature
|
|
179
|
-
* @param loggedIn
|
|
180
|
-
* @param access
|
|
181
|
-
* @param required
|
|
182
|
-
* @returns
|
|
166
|
+
* Checks if the user has access to a specific feature.
|
|
183
167
|
*/
|
|
184
168
|
export const canAccessFeature = (loggedIn, access, required) => {
|
|
185
169
|
if (!loggedIn) {
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @returns {boolean} True if localStorage is accessible, false otherwise.
|
|
2
|
+
* Checks if localStorage is available in the current environment.
|
|
4
3
|
*/
|
|
5
4
|
export declare const isLocalStorageAvailable: () => boolean;
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {string} key - The key to retrieve the value for.
|
|
9
|
-
* @returns {string | null} The value associated with the key, or null if not found or localStorage is not available.
|
|
6
|
+
* Gets a value from localStorage.
|
|
10
7
|
*/
|
|
11
8
|
export declare const getLocalStorage: (key: string) => string | null;
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {string} key - The key to set the value for.
|
|
15
|
-
* @param {string} value - The value to be stored.
|
|
16
|
-
* @returns {boolean} True if the operation succeeded, false otherwise (or if localStorage is not available).
|
|
10
|
+
* Sets a value in localStorage.
|
|
17
11
|
*/
|
|
18
12
|
export declare const setLocalStorage: (key: string, value: string) => boolean;
|
|
19
13
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param key - The key to remove the value for.
|
|
22
|
-
* @returns {boolean} True if the operation succeeded, false otherwise (or if localStorage is not available).
|
|
14
|
+
* Removes a value from localStorage.
|
|
23
15
|
*/
|
|
24
16
|
export declare const removeLocalStorage: (key: string) => boolean;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @returns {boolean} True if localStorage is accessible, false otherwise.
|
|
2
|
+
* Checks if localStorage is available in the current environment.
|
|
4
3
|
*/
|
|
5
4
|
export const isLocalStorageAvailable = () => {
|
|
6
5
|
if (typeof window === 'undefined')
|
|
@@ -18,9 +17,7 @@ export const isLocalStorageAvailable = () => {
|
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @param {string} key - The key to retrieve the value for.
|
|
23
|
-
* @returns {string | null} The value associated with the key, or null if not found or localStorage is not available.
|
|
20
|
+
* Gets a value from localStorage.
|
|
24
21
|
*/
|
|
25
22
|
export const getLocalStorage = (key) => {
|
|
26
23
|
if (isLocalStorageAvailable()) {
|
|
@@ -30,10 +27,7 @@ export const getLocalStorage = (key) => {
|
|
|
30
27
|
return null;
|
|
31
28
|
};
|
|
32
29
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param {string} key - The key to set the value for.
|
|
35
|
-
* @param {string} value - The value to be stored.
|
|
36
|
-
* @returns {boolean} True if the operation succeeded, false otherwise (or if localStorage is not available).
|
|
30
|
+
* Sets a value in localStorage.
|
|
37
31
|
*/
|
|
38
32
|
export const setLocalStorage = (key, value) => {
|
|
39
33
|
if (isLocalStorageAvailable()) {
|
|
@@ -43,9 +37,7 @@ export const setLocalStorage = (key, value) => {
|
|
|
43
37
|
return false;
|
|
44
38
|
};
|
|
45
39
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @param key - The key to remove the value for.
|
|
48
|
-
* @returns {boolean} True if the operation succeeded, false otherwise (or if localStorage is not available).
|
|
40
|
+
* Removes a value from localStorage.
|
|
49
41
|
*/
|
|
50
42
|
export const removeLocalStorage = (key) => {
|
|
51
43
|
if (isLocalStorageAvailable()) {
|