@redneckz/wildless-cms-uni-blocks 0.5.6 → 0.5.7
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/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +76 -105
- package/bundle/bundle.umd.min.js +1 -1
- package/cosmos-static/icons/AirPlaneIcon.svg +1 -1
- package/cosmos-static/icons/CarIcon.svg +1 -1
- package/cosmos-static/icons/CinemaIcon.svg +1 -1
- package/cosmos-static/icons/DocsIcon.svg +1 -1
- package/cosmos-static/icons/PackA4Icon.svg +1 -1
- package/cosmos-static/icons/PowerIcon.svg +1 -1
- package/cosmos-static/icons/PumpkinIcon.svg +1 -1
- package/cosmos-static/icons/SoundIcon.svg +1 -1
- package/cosmos-static/icons/WateringCanIcon.svg +1 -1
- package/dist/components/BonusBenefitsBlock/BonusBenefitsBlockContent.d.ts +1 -1
- package/dist/components/Calculator/CalculatorContent.d.ts +1 -1
- package/dist/components/ComparisonTable/ComparisonTableContent.d.ts +1 -1
- package/dist/components/ComparisonTable/TableColumn.d.ts +1 -1
- package/dist/components/Footer/FooterContent.d.ts +1 -1
- package/dist/components/Header/HeaderContent.d.ts +1 -1
- package/dist/components/OfficeServicesBlock/OfficeServicesBlockContent.d.ts +1 -1
- package/dist/components/ProductTile/ProductTileContent.d.ts +1 -1
- package/dist/components/SafeDepositRental/SafeDepositRental.js +1 -6
- package/dist/components/SafeDepositRental/SafeDepositRental.js.map +1 -1
- package/dist/components/SafeDepositRental/YandexMap.js +13 -6
- package/dist/components/SafeDepositRental/YandexMap.js.map +1 -1
- package/dist/components/SafeDepositRental/renderClusterer.d.ts +2 -1
- package/dist/components/SafeDepositRental/renderClusterer.js +16 -18
- package/dist/components/SafeDepositRental/renderClusterer.js.map +1 -1
- package/dist/components/SafeDepositRental/useYandexMaps.d.ts +2 -0
- package/dist/components/SafeDepositRental/useYandexMaps.js +12 -0
- package/dist/components/SafeDepositRental/useYandexMaps.js.map +1 -0
- package/dist/components/TariffsTable/TariffsTableContent.d.ts +1 -1
- package/dist/hooks/useExternalNS.d.ts +2 -0
- package/dist/hooks/useExternalNS.js +39 -0
- package/dist/hooks/useExternalNS.js.map +1 -0
- package/dist/icons/IconName.d.ts +4 -4
- package/dist/icons/IconName.js +3 -3
- package/dist/icons/IconName.js.map +1 -1
- package/dist/ui-kit/BenefitItem/BenefitItemProps.d.ts +1 -1
- package/dist/ui-kit/SelectCustom/SelectCustom.js +3 -3
- package/dist/ui-kit/SelectCustom/SelectCustom.js.map +1 -1
- package/lib/components/BonusBenefitsBlock/BonusBenefitsBlockContent.d.ts +1 -1
- package/lib/components/Calculator/CalculatorContent.d.ts +1 -1
- package/lib/components/ComparisonTable/ComparisonTableContent.d.ts +1 -1
- package/lib/components/ComparisonTable/TableColumn.d.ts +1 -1
- package/lib/components/ContentPage/computeAPIFallback.js +1 -1
- package/lib/components/Footer/FooterContent.d.ts +1 -1
- package/lib/components/Header/HeaderContent.d.ts +1 -1
- package/lib/components/OfficeServicesBlock/OfficeServicesBlockContent.d.ts +1 -1
- package/lib/components/ProductTile/ProductTileContent.d.ts +1 -1
- package/lib/components/SafeDepositRental/SafeDepositRental.js +1 -6
- package/lib/components/SafeDepositRental/SafeDepositRental.js.map +1 -1
- package/lib/components/SafeDepositRental/YandexMap.js +13 -6
- package/lib/components/SafeDepositRental/YandexMap.js.map +1 -1
- package/lib/components/SafeDepositRental/renderClusterer.d.ts +2 -1
- package/lib/components/SafeDepositRental/renderClusterer.js +16 -18
- package/lib/components/SafeDepositRental/renderClusterer.js.map +1 -1
- package/lib/components/SafeDepositRental/useYandexMaps.d.ts +2 -0
- package/lib/components/SafeDepositRental/useYandexMaps.js +9 -0
- package/lib/components/SafeDepositRental/useYandexMaps.js.map +1 -0
- package/lib/components/TariffsTable/TariffsTableContent.d.ts +1 -1
- package/lib/hooks/useExternalNS.d.ts +2 -0
- package/lib/hooks/useExternalNS.js +35 -0
- package/lib/hooks/useExternalNS.js.map +1 -0
- package/lib/icons/IconName.d.ts +4 -4
- package/lib/icons/IconName.js +3 -3
- package/lib/icons/IconName.js.map +1 -1
- package/lib/ui-kit/BenefitItem/BenefitItemProps.d.ts +1 -1
- package/lib/ui-kit/SelectCustom/SelectCustom.js +3 -3
- package/lib/ui-kit/SelectCustom/SelectCustom.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +6 -6
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/dist/components/BonusBenefitsBlock/BonusBenefitsBlockContent.d.ts +1 -1
- package/mobile/dist/components/Calculator/CalculatorContent.d.ts +1 -1
- package/mobile/dist/components/ComparisonTable/ComparisonTableContent.d.ts +1 -1
- package/mobile/dist/components/ComparisonTable/TableColumn.d.ts +1 -1
- package/mobile/dist/components/Footer/FooterContent.d.ts +1 -1
- package/mobile/dist/components/Header/HeaderContent.d.ts +1 -1
- package/mobile/dist/components/OfficeServicesBlock/OfficeServicesBlockContent.d.ts +1 -1
- package/mobile/dist/components/ProductTile/ProductTileContent.d.ts +1 -1
- package/mobile/dist/components/SafeDepositRental/SafeDepositRental.js +1 -6
- package/mobile/dist/components/SafeDepositRental/SafeDepositRental.js.map +1 -1
- package/mobile/dist/components/SafeDepositRental/YandexMap.js +13 -6
- package/mobile/dist/components/SafeDepositRental/YandexMap.js.map +1 -1
- package/mobile/dist/components/SafeDepositRental/renderClusterer.d.ts +2 -1
- package/mobile/dist/components/SafeDepositRental/renderClusterer.js +16 -18
- package/mobile/dist/components/SafeDepositRental/renderClusterer.js.map +1 -1
- package/mobile/dist/components/SafeDepositRental/useYandexMaps.d.ts +2 -0
- package/mobile/dist/components/SafeDepositRental/useYandexMaps.js +12 -0
- package/mobile/dist/components/SafeDepositRental/useYandexMaps.js.map +1 -0
- package/mobile/dist/components/TariffsTable/TariffsTableContent.d.ts +1 -1
- package/mobile/dist/hooks/useExternalNS.d.ts +2 -0
- package/mobile/dist/hooks/useExternalNS.js +39 -0
- package/mobile/dist/hooks/useExternalNS.js.map +1 -0
- package/mobile/dist/icons/IconName.d.ts +4 -4
- package/mobile/dist/icons/IconName.js +3 -3
- package/mobile/dist/icons/IconName.js.map +1 -1
- package/mobile/dist/ui-kit/BenefitItem/BenefitItemProps.d.ts +1 -1
- package/mobile/dist/ui-kit/SelectCustom/SelectCustom.js +3 -3
- package/mobile/dist/ui-kit/SelectCustom/SelectCustom.js.map +1 -1
- package/mobile/lib/components/BonusBenefitsBlock/BonusBenefitsBlockContent.d.ts +1 -1
- package/mobile/lib/components/Calculator/CalculatorContent.d.ts +1 -1
- package/mobile/lib/components/ComparisonTable/ComparisonTableContent.d.ts +1 -1
- package/mobile/lib/components/ComparisonTable/TableColumn.d.ts +1 -1
- package/mobile/lib/components/ContentPage/computeAPIFallback.js +1 -1
- package/mobile/lib/components/Footer/FooterContent.d.ts +1 -1
- package/mobile/lib/components/Header/HeaderContent.d.ts +1 -1
- package/mobile/lib/components/OfficeServicesBlock/OfficeServicesBlockContent.d.ts +1 -1
- package/mobile/lib/components/ProductTile/ProductTileContent.d.ts +1 -1
- package/mobile/lib/components/SafeDepositRental/SafeDepositRental.js +1 -6
- package/mobile/lib/components/SafeDepositRental/SafeDepositRental.js.map +1 -1
- package/mobile/lib/components/SafeDepositRental/YandexMap.js +13 -6
- package/mobile/lib/components/SafeDepositRental/YandexMap.js.map +1 -1
- package/mobile/lib/components/SafeDepositRental/renderClusterer.d.ts +2 -1
- package/mobile/lib/components/SafeDepositRental/renderClusterer.js +16 -18
- package/mobile/lib/components/SafeDepositRental/renderClusterer.js.map +1 -1
- package/mobile/lib/components/SafeDepositRental/useYandexMaps.d.ts +2 -0
- package/mobile/lib/components/SafeDepositRental/useYandexMaps.js +9 -0
- package/mobile/lib/components/SafeDepositRental/useYandexMaps.js.map +1 -0
- package/mobile/lib/components/TariffsTable/TariffsTableContent.d.ts +1 -1
- package/mobile/lib/hooks/useExternalNS.d.ts +2 -0
- package/mobile/lib/hooks/useExternalNS.js +35 -0
- package/mobile/lib/hooks/useExternalNS.js.map +1 -0
- package/mobile/lib/icons/IconName.d.ts +4 -4
- package/mobile/lib/icons/IconName.js +3 -3
- package/mobile/lib/icons/IconName.js.map +1 -1
- package/mobile/lib/ui-kit/BenefitItem/BenefitItemProps.d.ts +1 -1
- package/mobile/lib/ui-kit/SelectCustom/SelectCustom.js +3 -3
- package/mobile/lib/ui-kit/SelectCustom/SelectCustom.js.map +1 -1
- package/mobile/src/components/BonusBenefitsBlock/BonusBenefitsBlockContent.ts +2 -2
- package/mobile/src/components/Calculator/CalculatorContent.ts +2 -2
- package/mobile/src/components/ComparisonTable/ComparisonTableContent.ts +1 -1
- package/mobile/src/components/ComparisonTable/TableColumn.tsx +2 -2
- package/mobile/src/components/Footer/FooterContent.ts +2 -2
- package/mobile/src/components/GracePeriod/GracePeriodContent.ts +1 -1
- package/mobile/src/components/Header/HeaderContent.ts +1 -1
- package/mobile/src/components/InsuranceAmountBlock/InsuranceAmountBlockContent.ts +1 -1
- package/mobile/src/components/OfficeServicesBlock/OfficeServicesBlockContent.ts +2 -2
- package/mobile/src/components/ProductTile/ProductTileContent.ts +1 -1
- package/mobile/src/components/SafeDepositRental/SafeDepositRental.tsx +1 -12
- package/mobile/src/components/SafeDepositRental/YandexMap.tsx +17 -10
- package/mobile/src/components/SafeDepositRental/renderClusterer.ts +29 -23
- package/mobile/src/components/SafeDepositRental/useYandexMaps.ts +13 -0
- package/mobile/src/components/StepsBlock/StepsBlockContent.ts +1 -1
- package/mobile/src/components/TariffsTable/TariffsTableContent.ts +1 -1
- package/mobile/src/components/__snapshots__/Blocks.spec.tsx.snap +2 -2
- package/mobile/src/hooks/useExternalNS.ts +44 -0
- package/mobile/src/icons/AirPlaneIcon.svg +1 -98
- package/mobile/src/icons/CarIcon.svg +1 -466
- package/mobile/src/icons/CinemaIcon.svg +1 -274
- package/mobile/src/icons/DocsIcon.svg +1 -238
- package/mobile/src/icons/IconName.ts +2 -2
- package/mobile/src/icons/PackA4Icon.svg +1 -1
- package/mobile/src/icons/PowerIcon.svg +1 -135
- package/mobile/src/icons/PumpkinIcon.svg +1 -236
- package/mobile/src/icons/SoundIcon.svg +1 -113
- package/mobile/src/icons/WateringCanIcon.svg +1 -497
- package/mobile/src/ui-kit/BenefitItem/BenefitItemProps.ts +2 -2
- package/mobile/src/ui-kit/SelectCustom/SelectCustom.tsx +9 -2
- package/package.json +2 -1
- package/src/components/BonusBenefitsBlock/BonusBenefitsBlockContent.ts +2 -2
- package/src/components/Calculator/CalculatorContent.ts +2 -2
- package/src/components/ComparisonTable/ComparisonTableContent.ts +1 -1
- package/src/components/ComparisonTable/TableColumn.tsx +2 -2
- package/src/components/Footer/FooterContent.ts +2 -2
- package/src/components/GracePeriod/GracePeriodContent.ts +1 -1
- package/src/components/Header/HeaderContent.ts +1 -1
- package/src/components/InsuranceAmountBlock/InsuranceAmountBlockContent.ts +1 -1
- package/src/components/OfficeServicesBlock/OfficeServicesBlockContent.ts +2 -2
- package/src/components/ProductTile/ProductTileContent.ts +1 -1
- package/src/components/SafeDepositRental/SafeDepositRental.tsx +1 -12
- package/src/components/SafeDepositRental/YandexMap.tsx +17 -10
- package/src/components/SafeDepositRental/renderClusterer.ts +29 -23
- package/src/components/SafeDepositRental/useYandexMaps.ts +13 -0
- package/src/components/StepsBlock/StepsBlockContent.ts +1 -1
- package/src/components/TariffsTable/TariffsTableContent.ts +1 -1
- package/src/components/__snapshots__/Blocks.spec.tsx.snap +2 -2
- package/src/hooks/useExternalNS.ts +44 -0
- package/src/icons/AirPlaneIcon.svg +1 -98
- package/src/icons/CarIcon.svg +1 -466
- package/src/icons/CinemaIcon.svg +1 -274
- package/src/icons/DocsIcon.svg +1 -238
- package/src/icons/IconName.ts +4 -4
- package/src/icons/PackA4Icon.svg +1 -1
- package/src/icons/PowerIcon.svg +1 -135
- package/src/icons/PumpkinIcon.svg +1 -236
- package/src/icons/SoundIcon.svg +1 -113
- package/src/icons/WateringCanIcon.svg +1 -497
- package/src/ui-kit/BenefitItem/BenefitItemProps.ts +2 -2
- package/src/ui-kit/SelectCustom/SelectCustom.tsx +9 -2
- package/dist/hooks/useScript.d.ts +0 -6
- package/dist/hooks/useScript.js +0 -75
- package/dist/hooks/useScript.js.map +0 -1
- package/lib/hooks/useScript.d.ts +0 -6
- package/lib/hooks/useScript.js +0 -72
- package/lib/hooks/useScript.js.map +0 -1
- package/mobile/dist/hooks/useScript.d.ts +0 -6
- package/mobile/dist/hooks/useScript.js +0 -75
- package/mobile/dist/hooks/useScript.js.map +0 -1
- package/mobile/lib/hooks/useScript.d.ts +0 -6
- package/mobile/lib/hooks/useScript.js +0 -72
- package/mobile/lib/hooks/useScript.js.map +0 -1
- package/mobile/src/hooks/useScript.ts +0 -97
- package/src/hooks/useScript.ts +0 -97
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IconProps
|
|
1
|
+
import type { IconProps } from '../../model/Picture';
|
|
2
2
|
import type { BlockVersion } from '../../model/BlockVersion';
|
|
3
3
|
import type { IconVersion } from '../../model/IconVersion';
|
|
4
4
|
import type { DescriptionProps, LabelProps } from '../../model/HeadlineType';
|
|
@@ -11,7 +11,7 @@ export interface BenefitItemCommonProps {
|
|
|
11
11
|
className?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export type BenefitItemProps = DescriptionProps & LabelProps & IconProps
|
|
14
|
+
export type BenefitItemProps = DescriptionProps & LabelProps & IconProps;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @title Преимущество
|
|
@@ -38,12 +38,17 @@ export const SelectCustom = JSX<SelectCustomProps>(
|
|
|
38
38
|
{label ? <span className="mb-2">{label}</span> : null}
|
|
39
39
|
<div className={`relative w-fit`}>
|
|
40
40
|
<div
|
|
41
|
-
className={`text-m-light flex justify-between min-h-[56px] mb-0.5 p-4 pr-8 text-primary-text cursor-pointer
|
|
41
|
+
className={`text-m-light flex justify-between items-center min-h-[56px] mb-0.5 p-4 pr-8 text-primary-text cursor-pointer
|
|
42
42
|
${getBorderStyle(isBorder)}`}
|
|
43
43
|
onClick={() => setIsOpen(!isOpen)}
|
|
44
44
|
>
|
|
45
45
|
{selectedItem.text}
|
|
46
|
-
<Icon
|
|
46
|
+
<Icon
|
|
47
|
+
name="ArrowUpIcon"
|
|
48
|
+
width="16"
|
|
49
|
+
height="16"
|
|
50
|
+
className={`absolute right-3 ${isOpen ? '' : 'rotate-180'}`}
|
|
51
|
+
/>
|
|
47
52
|
</div>
|
|
48
53
|
{options.length > 0 ? (
|
|
49
54
|
<div className={`h-0 ${isOpen ? '' : 'overflow-hidden'}`}>
|
|
@@ -71,6 +76,8 @@ const renderOption =
|
|
|
71
76
|
<span>{option.text}</span>
|
|
72
77
|
<Icon
|
|
73
78
|
name="DoneSimpleIcon"
|
|
79
|
+
width="16"
|
|
80
|
+
height="16"
|
|
74
81
|
className={['absolute right-4 pt-0.5', isSelected(option) && isOpen ? '' : 'hidden'].join(
|
|
75
82
|
' ',
|
|
76
83
|
)}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
2
|
-
export interface UseScriptOptions {
|
|
3
|
-
shouldPreventLoad?: boolean;
|
|
4
|
-
removeOnUnmount?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus;
|
package/dist/hooks/useScript.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.useScript = void 0;
|
|
3
|
-
const hooks_1 = require("@redneckz/uni-jsx/lib/hooks");
|
|
4
|
-
const cachedScriptStatuses = {};
|
|
5
|
-
function getScriptNode(src) {
|
|
6
|
-
const node = document.querySelector(`script[src="${src}"]`);
|
|
7
|
-
const status = node?.getAttribute('data-status');
|
|
8
|
-
return {
|
|
9
|
-
node,
|
|
10
|
-
status,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function getScriptStatus(type) {
|
|
14
|
-
return type === 'load' ? 'ready' : 'error';
|
|
15
|
-
}
|
|
16
|
-
function getInitialValueStatus(src, options) {
|
|
17
|
-
if (!src || options?.shouldPreventLoad) {
|
|
18
|
-
return 'idle';
|
|
19
|
-
}
|
|
20
|
-
if (typeof window === 'undefined') {
|
|
21
|
-
return 'loading';
|
|
22
|
-
}
|
|
23
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
24
|
-
}
|
|
25
|
-
function useScript(src, options) {
|
|
26
|
-
const [status, setStatus] = (0, hooks_1.useState)(getInitialValueStatus(src, options));
|
|
27
|
-
// eslint-disable-next-line complexity
|
|
28
|
-
(0, hooks_1.useEffect)(() => {
|
|
29
|
-
if (!src || options?.shouldPreventLoad) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
33
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
34
|
-
setStatus(cachedScriptStatus);
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
const script = getScriptNode(src);
|
|
38
|
-
let scriptNode = script.node;
|
|
39
|
-
if (!scriptNode) {
|
|
40
|
-
scriptNode = document.createElement('script');
|
|
41
|
-
scriptNode.src = src;
|
|
42
|
-
scriptNode.async = true;
|
|
43
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
44
|
-
document.body.appendChild(scriptNode);
|
|
45
|
-
const setAttributeFromEvent = (event) => {
|
|
46
|
-
const scriptStatus = getScriptStatus(event.type);
|
|
47
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
48
|
-
};
|
|
49
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
50
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
54
|
-
}
|
|
55
|
-
const setStateFromEvent = (event) => {
|
|
56
|
-
const newStatus = getScriptStatus(event.type);
|
|
57
|
-
setStatus(newStatus);
|
|
58
|
-
cachedScriptStatuses[src] = newStatus;
|
|
59
|
-
};
|
|
60
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
61
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
62
|
-
return () => {
|
|
63
|
-
if (scriptNode) {
|
|
64
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
65
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
66
|
-
}
|
|
67
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
68
|
-
scriptNode.remove();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
72
|
-
return status;
|
|
73
|
-
}
|
|
74
|
-
exports.useScript = useScript;
|
|
75
|
-
//# sourceMappingURL=useScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.js","sourceRoot":"","sources":["../../src/hooks/useScript.ts"],"names":[],"mappings":";;AAAA,uDAAkE;AAQlE,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAE1E,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,IAAI,GAA6B,QAAQ,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,aAAa,CAA6B,CAAC;IAE7E,OAAO;QACL,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAI;IAC3B,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAkB,EAAE,OAA0B;IAC3E,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,iBAAiB,EAAE;QACtC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,MAAM,KAAK,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CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;YAC3D,UAAU,CAAC,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;SAC7D;aAAM;YACL,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,kBAAkB,IAAI,SAAS,CAAC,CAAC;SAC7D;QAED,MAAM,iBAAiB,GAAG,CAAC,KAAY,EAAE,EAAE;YACzC,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC9C,SAAS,CAAC,SAAS,CAAC,CAAC;YACrB,oBAAoB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;QACxC,CAAC,CAAC;QAEF,UAAU,CAAC,gBAAgB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QACvD,UAAU,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAExD,OAAO,GAAG,EAAE;YACV,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;gBAC1D,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;aAC5D;YAED,IAAI,UAAU,IAAI,OAAO,EAAE,eAAe,EAAE;gBAC1C,UAAU,CAAC,MAAM,EAAE,CAAC;aACrB;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC;AA5DD,8BA4DC"}
|
package/lib/hooks/useScript.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
2
|
-
export interface UseScriptOptions {
|
|
3
|
-
shouldPreventLoad?: boolean;
|
|
4
|
-
removeOnUnmount?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus;
|
package/lib/hooks/useScript.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
-
const cachedScriptStatuses = {};
|
|
3
|
-
function getScriptNode(src) {
|
|
4
|
-
const node = document.querySelector(`script[src="${src}"]`);
|
|
5
|
-
const status = node?.getAttribute('data-status');
|
|
6
|
-
return {
|
|
7
|
-
node,
|
|
8
|
-
status,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function getScriptStatus(type) {
|
|
12
|
-
return type === 'load' ? 'ready' : 'error';
|
|
13
|
-
}
|
|
14
|
-
function getInitialValueStatus(src, options) {
|
|
15
|
-
if (!src || options?.shouldPreventLoad) {
|
|
16
|
-
return 'idle';
|
|
17
|
-
}
|
|
18
|
-
if (typeof window === 'undefined') {
|
|
19
|
-
return 'loading';
|
|
20
|
-
}
|
|
21
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
22
|
-
}
|
|
23
|
-
export function useScript(src, options) {
|
|
24
|
-
const [status, setStatus] = useState(getInitialValueStatus(src, options));
|
|
25
|
-
// eslint-disable-next-line complexity
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (!src || options?.shouldPreventLoad) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
31
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
32
|
-
setStatus(cachedScriptStatus);
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
const script = getScriptNode(src);
|
|
36
|
-
let scriptNode = script.node;
|
|
37
|
-
if (!scriptNode) {
|
|
38
|
-
scriptNode = document.createElement('script');
|
|
39
|
-
scriptNode.src = src;
|
|
40
|
-
scriptNode.async = true;
|
|
41
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
42
|
-
document.body.appendChild(scriptNode);
|
|
43
|
-
const setAttributeFromEvent = (event) => {
|
|
44
|
-
const scriptStatus = getScriptStatus(event.type);
|
|
45
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
46
|
-
};
|
|
47
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
48
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
52
|
-
}
|
|
53
|
-
const setStateFromEvent = (event) => {
|
|
54
|
-
const newStatus = getScriptStatus(event.type);
|
|
55
|
-
setStatus(newStatus);
|
|
56
|
-
cachedScriptStatuses[src] = newStatus;
|
|
57
|
-
};
|
|
58
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
59
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
60
|
-
return () => {
|
|
61
|
-
if (scriptNode) {
|
|
62
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
63
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
64
|
-
}
|
|
65
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
66
|
-
scriptNode.remove();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
70
|
-
return status;
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=useScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.js","sourceRoot":"","sources":["../../src/hooks/useScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAQlE,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAE1E,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,IAAI,GAA6B,QAAQ,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,IAAI,EAAE,YAAY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,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
2
|
-
export interface UseScriptOptions {
|
|
3
|
-
shouldPreventLoad?: boolean;
|
|
4
|
-
removeOnUnmount?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.useScript = void 0;
|
|
3
|
-
const hooks_1 = require("@redneckz/uni-jsx/lib/hooks");
|
|
4
|
-
const cachedScriptStatuses = {};
|
|
5
|
-
function getScriptNode(src) {
|
|
6
|
-
const node = document.querySelector(`script[src="${src}"]`);
|
|
7
|
-
const status = node?.getAttribute('data-status');
|
|
8
|
-
return {
|
|
9
|
-
node,
|
|
10
|
-
status,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function getScriptStatus(type) {
|
|
14
|
-
return type === 'load' ? 'ready' : 'error';
|
|
15
|
-
}
|
|
16
|
-
function getInitialValueStatus(src, options) {
|
|
17
|
-
if (!src || options?.shouldPreventLoad) {
|
|
18
|
-
return 'idle';
|
|
19
|
-
}
|
|
20
|
-
if (typeof window === 'undefined') {
|
|
21
|
-
return 'loading';
|
|
22
|
-
}
|
|
23
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
24
|
-
}
|
|
25
|
-
function useScript(src, options) {
|
|
26
|
-
const [status, setStatus] = (0, hooks_1.useState)(getInitialValueStatus(src, options));
|
|
27
|
-
// eslint-disable-next-line complexity
|
|
28
|
-
(0, hooks_1.useEffect)(() => {
|
|
29
|
-
if (!src || options?.shouldPreventLoad) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
33
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
34
|
-
setStatus(cachedScriptStatus);
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
const script = getScriptNode(src);
|
|
38
|
-
let scriptNode = script.node;
|
|
39
|
-
if (!scriptNode) {
|
|
40
|
-
scriptNode = document.createElement('script');
|
|
41
|
-
scriptNode.src = src;
|
|
42
|
-
scriptNode.async = true;
|
|
43
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
44
|
-
document.body.appendChild(scriptNode);
|
|
45
|
-
const setAttributeFromEvent = (event) => {
|
|
46
|
-
const scriptStatus = getScriptStatus(event.type);
|
|
47
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
48
|
-
};
|
|
49
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
50
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
54
|
-
}
|
|
55
|
-
const setStateFromEvent = (event) => {
|
|
56
|
-
const newStatus = getScriptStatus(event.type);
|
|
57
|
-
setStatus(newStatus);
|
|
58
|
-
cachedScriptStatuses[src] = newStatus;
|
|
59
|
-
};
|
|
60
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
61
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
62
|
-
return () => {
|
|
63
|
-
if (scriptNode) {
|
|
64
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
65
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
66
|
-
}
|
|
67
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
68
|
-
scriptNode.remove();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
72
|
-
return status;
|
|
73
|
-
}
|
|
74
|
-
exports.useScript = useScript;
|
|
75
|
-
//# sourceMappingURL=useScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.js","sourceRoot":"","sources":["../../src/hooks/useScript.ts"],"names":[],"mappings":";;AAAA,uDAAkE;AAQlE,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAE1E,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,IAAI,GAA6B,QAAQ,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,aAAa,CAA6B,CAAC;IAE7E,OAAO;QACL,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAI;IAC3B,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAkB,EAAE,OAA0B;IAC3E,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,iBAAiB,EAAE;QACtC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,oBAAoB,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;AAChD,CAAC;AAED,SAAgB,SAAS,CAAC,GAAkB,EAAE,OAA0B;IACtE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAe,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAExF,sCAAsC;IACtC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,iBAAiB,EAAE;YACtC,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,kBAAkB,KAAK,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U,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAExD,OAAO,GAAG,EAAE;YACV,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;gBAC1D,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;aAC5D;YAED,IAAI,UAAU,IAAI,OAAO,EAAE,eAAe,EAAE;gBAC1C,UAAU,CAAC,MAAM,EAAE,CAAC;aACrB;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC;AA5DD,8BA4DC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
2
|
-
export interface UseScriptOptions {
|
|
3
|
-
shouldPreventLoad?: boolean;
|
|
4
|
-
removeOnUnmount?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
-
const cachedScriptStatuses = {};
|
|
3
|
-
function getScriptNode(src) {
|
|
4
|
-
const node = document.querySelector(`script[src="${src}"]`);
|
|
5
|
-
const status = node?.getAttribute('data-status');
|
|
6
|
-
return {
|
|
7
|
-
node,
|
|
8
|
-
status,
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function getScriptStatus(type) {
|
|
12
|
-
return type === 'load' ? 'ready' : 'error';
|
|
13
|
-
}
|
|
14
|
-
function getInitialValueStatus(src, options) {
|
|
15
|
-
if (!src || options?.shouldPreventLoad) {
|
|
16
|
-
return 'idle';
|
|
17
|
-
}
|
|
18
|
-
if (typeof window === 'undefined') {
|
|
19
|
-
return 'loading';
|
|
20
|
-
}
|
|
21
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
22
|
-
}
|
|
23
|
-
export function useScript(src, options) {
|
|
24
|
-
const [status, setStatus] = useState(getInitialValueStatus(src, options));
|
|
25
|
-
// eslint-disable-next-line complexity
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (!src || options?.shouldPreventLoad) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
31
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
32
|
-
setStatus(cachedScriptStatus);
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
const script = getScriptNode(src);
|
|
36
|
-
let scriptNode = script.node;
|
|
37
|
-
if (!scriptNode) {
|
|
38
|
-
scriptNode = document.createElement('script');
|
|
39
|
-
scriptNode.src = src;
|
|
40
|
-
scriptNode.async = true;
|
|
41
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
42
|
-
document.body.appendChild(scriptNode);
|
|
43
|
-
const setAttributeFromEvent = (event) => {
|
|
44
|
-
const scriptStatus = getScriptStatus(event.type);
|
|
45
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
46
|
-
};
|
|
47
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
48
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
52
|
-
}
|
|
53
|
-
const setStateFromEvent = (event) => {
|
|
54
|
-
const newStatus = getScriptStatus(event.type);
|
|
55
|
-
setStatus(newStatus);
|
|
56
|
-
cachedScriptStatuses[src] = newStatus;
|
|
57
|
-
};
|
|
58
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
59
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
60
|
-
return () => {
|
|
61
|
-
if (scriptNode) {
|
|
62
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
63
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
64
|
-
}
|
|
65
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
66
|
-
scriptNode.remove();
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
70
|
-
return status;
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=useScript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.js","sourceRoot":"","sources":["../../src/hooks/useScript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAQlE,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAE1E,SAAS,aAAa,CAAC,GAAW;IAChC,MAAM,IAAI,GAA6B,QAAQ,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,aAAa,CAA6B,CAAC;IAE7E,OAAO;QACL,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAI;IAC3B,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7C,CAAC;AAED,SAAS,qBAAqB,CAAC,GAAkB,EAAE,OAA0B;IAC3E,IAAI,CAAC,GAAG,IAAI,OAAO,EAAE,iBAAiB,EAAE;QACtC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,oBAAoB,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAkB,EAAE,OAA0B;IACtE,MAAM,C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AC,CAAC;SAC7D;QAED,MAAM,iBAAiB,GAAG,CAAC,KAAY,EAAE,EAAE;YACzC,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC9C,SAAS,CAAC,SAAS,CAAC,CAAC;YACrB,oBAAoB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;QACxC,CAAC,CAAC;QAEF,UAAU,CAAC,gBAAgB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;QACvD,UAAU,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QAExD,OAAO,GAAG,EAAE;YACV,IAAI,UAAU,EAAE;gBACd,UAAU,CAAC,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;gBAC1D,UAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;aAC5D;YAED,IAAI,UAAU,IAAI,OAAO,EAAE,eAAe,EAAE;gBAC1C,UAAU,CAAC,MAAM,EAAE,CAAC;aACrB;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
-
|
|
3
|
-
export type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
4
|
-
export interface UseScriptOptions {
|
|
5
|
-
shouldPreventLoad?: boolean;
|
|
6
|
-
removeOnUnmount?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const cachedScriptStatuses: Record<string, ScriptStatus | undefined> = {};
|
|
10
|
-
|
|
11
|
-
function getScriptNode(src: string) {
|
|
12
|
-
const node: HTMLScriptElement | null = document.querySelector(`script[src="${src}"]`);
|
|
13
|
-
const status = node?.getAttribute('data-status') as ScriptStatus | undefined;
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
node,
|
|
17
|
-
status,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getScriptStatus(type) {
|
|
22
|
-
return type === 'load' ? 'ready' : 'error';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getInitialValueStatus(src: string | null, options?: UseScriptOptions) {
|
|
26
|
-
if (!src || options?.shouldPreventLoad) {
|
|
27
|
-
return 'idle';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof window === 'undefined') {
|
|
31
|
-
return 'loading';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus {
|
|
38
|
-
const [status, setStatus] = useState<ScriptStatus>(getInitialValueStatus(src, options));
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line complexity
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!src || options?.shouldPreventLoad) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
47
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
48
|
-
setStatus(cachedScriptStatus);
|
|
49
|
-
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const script = getScriptNode(src);
|
|
54
|
-
let scriptNode = script.node;
|
|
55
|
-
|
|
56
|
-
if (!scriptNode) {
|
|
57
|
-
scriptNode = document.createElement('script');
|
|
58
|
-
scriptNode.src = src;
|
|
59
|
-
scriptNode.async = true;
|
|
60
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
61
|
-
document.body.appendChild(scriptNode);
|
|
62
|
-
|
|
63
|
-
const setAttributeFromEvent = (event: Event) => {
|
|
64
|
-
const scriptStatus: ScriptStatus = getScriptStatus(event.type);
|
|
65
|
-
|
|
66
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
70
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
71
|
-
} else {
|
|
72
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const setStateFromEvent = (event: Event) => {
|
|
76
|
-
const newStatus = getScriptStatus(event.type);
|
|
77
|
-
setStatus(newStatus);
|
|
78
|
-
cachedScriptStatuses[src] = newStatus;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
82
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
83
|
-
|
|
84
|
-
return () => {
|
|
85
|
-
if (scriptNode) {
|
|
86
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
87
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
91
|
-
scriptNode.remove();
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
95
|
-
|
|
96
|
-
return status;
|
|
97
|
-
}
|
package/src/hooks/useScript.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
|
-
|
|
3
|
-
export type ScriptStatus = 'idle' | 'loading' | 'ready' | 'error';
|
|
4
|
-
export interface UseScriptOptions {
|
|
5
|
-
shouldPreventLoad?: boolean;
|
|
6
|
-
removeOnUnmount?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const cachedScriptStatuses: Record<string, ScriptStatus | undefined> = {};
|
|
10
|
-
|
|
11
|
-
function getScriptNode(src: string) {
|
|
12
|
-
const node: HTMLScriptElement | null = document.querySelector(`script[src="${src}"]`);
|
|
13
|
-
const status = node?.getAttribute('data-status') as ScriptStatus | undefined;
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
node,
|
|
17
|
-
status,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getScriptStatus(type) {
|
|
22
|
-
return type === 'load' ? 'ready' : 'error';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getInitialValueStatus(src: string | null, options?: UseScriptOptions) {
|
|
26
|
-
if (!src || options?.shouldPreventLoad) {
|
|
27
|
-
return 'idle';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof window === 'undefined') {
|
|
31
|
-
return 'loading';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return cachedScriptStatuses[src] ?? 'loading';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function useScript(src: string | null, options?: UseScriptOptions): ScriptStatus {
|
|
38
|
-
const [status, setStatus] = useState<ScriptStatus>(getInitialValueStatus(src, options));
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line complexity
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!src || options?.shouldPreventLoad) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const cachedScriptStatus = cachedScriptStatuses[src];
|
|
47
|
-
if (cachedScriptStatus === 'ready' || cachedScriptStatus === 'error') {
|
|
48
|
-
setStatus(cachedScriptStatus);
|
|
49
|
-
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const script = getScriptNode(src);
|
|
54
|
-
let scriptNode = script.node;
|
|
55
|
-
|
|
56
|
-
if (!scriptNode) {
|
|
57
|
-
scriptNode = document.createElement('script');
|
|
58
|
-
scriptNode.src = src;
|
|
59
|
-
scriptNode.async = true;
|
|
60
|
-
scriptNode.setAttribute('data-status', 'loading');
|
|
61
|
-
document.body.appendChild(scriptNode);
|
|
62
|
-
|
|
63
|
-
const setAttributeFromEvent = (event: Event) => {
|
|
64
|
-
const scriptStatus: ScriptStatus = getScriptStatus(event.type);
|
|
65
|
-
|
|
66
|
-
scriptNode?.setAttribute('data-status', scriptStatus);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
scriptNode.addEventListener('load', setAttributeFromEvent);
|
|
70
|
-
scriptNode.addEventListener('error', setAttributeFromEvent);
|
|
71
|
-
} else {
|
|
72
|
-
setStatus(script.status ?? cachedScriptStatus ?? 'loading');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const setStateFromEvent = (event: Event) => {
|
|
76
|
-
const newStatus = getScriptStatus(event.type);
|
|
77
|
-
setStatus(newStatus);
|
|
78
|
-
cachedScriptStatuses[src] = newStatus;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
scriptNode.addEventListener('load', setStateFromEvent);
|
|
82
|
-
scriptNode.addEventListener('error', setStateFromEvent);
|
|
83
|
-
|
|
84
|
-
return () => {
|
|
85
|
-
if (scriptNode) {
|
|
86
|
-
scriptNode.removeEventListener('load', setStateFromEvent);
|
|
87
|
-
scriptNode.removeEventListener('error', setStateFromEvent);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (scriptNode && options?.removeOnUnmount) {
|
|
91
|
-
scriptNode.remove();
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
}, [src, options?.shouldPreventLoad, options?.removeOnUnmount]);
|
|
95
|
-
|
|
96
|
-
return status;
|
|
97
|
-
}
|