@adhese/sdk-react 0.9.5 → 0.9.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/CHANGELOG.md +13 -0
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @adhese/sdk-react
|
|
2
2
|
|
|
3
|
+
## 0.9.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [4cb01f8]
|
|
8
|
+
- @adhese/sdk-shared@0.5.0
|
|
9
|
+
|
|
10
|
+
## 0.9.6
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 1819375: Fix Adhese not being properly disposed in React instances
|
|
15
|
+
|
|
3
16
|
## 0.9.5
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -30,10 +30,13 @@ const adheseContext = react.createContext(void 0);
|
|
|
30
30
|
function AdheseProvider({ children, options }) {
|
|
31
31
|
const [adhese, setAdhese] = react.useState(void 0);
|
|
32
32
|
react.useEffect(() => {
|
|
33
|
-
let instance
|
|
33
|
+
let instance;
|
|
34
34
|
import("@adhese/sdk").then(({ createAdhese }) => {
|
|
35
35
|
instance = createAdhese(options);
|
|
36
|
-
setAdhese(
|
|
36
|
+
setAdhese((current) => {
|
|
37
|
+
current == null ? void 0 : current.dispose();
|
|
38
|
+
return instance;
|
|
39
|
+
});
|
|
37
40
|
}).catch(console.error);
|
|
38
41
|
return () => {
|
|
39
42
|
instance == null ? void 0 : instance.dispose();
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/adheseContext.tsx","../src/useAdheseSlot.ts","../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport {\n type PropsWithChildren,\n type ReactElement,\n createContext,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport type { Adhese, AdheseOptions } from '@adhese/sdk';\n\nconst adheseContext = createContext<Adhese | undefined>(undefined);\n\n/**\n * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be\n * used in all child components.\n * @constructor\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseProvider({ children, options }: PropsWithChildren<{ options: AdheseOptions }>): ReactElement {\n const [adhese, setAdhese] = useState<Adhese | undefined>(undefined);\n\n useEffect(() => {\n let instance: Adhese |
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/adheseContext.tsx","../src/useAdheseSlot.ts","../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport {\n type PropsWithChildren,\n type ReactElement,\n createContext,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport type { Adhese, AdheseOptions } from '@adhese/sdk';\n\nconst adheseContext = createContext<Adhese | undefined>(undefined);\n\n/**\n * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be\n * used in all child components.\n * @constructor\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseProvider({ children, options }: PropsWithChildren<{ options: AdheseOptions }>): ReactElement {\n const [adhese, setAdhese] = useState<Adhese | undefined>(undefined);\n\n useEffect(() => {\n let instance: Adhese | undefined;\n\n import('@adhese/sdk').then(({ createAdhese }) => {\n instance = createAdhese(options);\n\n setAdhese((current) => {\n current?.dispose();\n\n return instance;\n });\n }).catch(console.error);\n\n return (): void => {\n instance?.dispose();\n };\n }, [options]);\n\n return (\n <adheseContext.Provider value={adhese}>\n {children}\n </adheseContext.Provider>\n );\n}\n\n/**\n * Hook to get the Adhese instance from the nearest `AdheseProvider`. When the Adhese instance is not available yet, `null`\n */\nexport function useAdhese(): Adhese | undefined {\n return useContext(adheseContext);\n}\n","import { type RefObject, useState } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport useDeepCompareEffect from 'use-deep-compare-effect';\nimport { omit } from 'remeda';\nimport { useAdhese } from './adheseContext';\n\n/**\n * Hook to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be created\n * when the containing element is available and the Adhese instance is available.\n * @param elementRef The ref to the containing element\n * @param options The options to create the slot\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useDeepCompareEffect(() => {\n let intermediate: AdheseSlot | undefined;\n\n if (adhese && elementRef.current) {\n intermediate = adhese.addSlot(\n {\n ...options,\n containingElement: elementRef.current,\n },\n );\n\n setSlot(intermediate);\n }\n\n return (): void => {\n intermediate?.dispose();\n };\n }, [adhese, omit(options, Object.entries(options).filter(([, value]) => typeof value === 'function').map(([key]) => key as keyof typeof options)), elementRef.current]);\n\n return slot;\n}\n","import { type ReactElement, useEffect, useRef } from 'react';\nimport type { AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { useAdheseSlot } from './useAdheseSlot';\n\nexport type AdheseSlotProps = {\n /**\n * Callback to be called when the slot is created or disposed\n */\n onChange?(slot: Slot | null): void;\n} & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;\n\n/**\n * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be\n * created when the containing element is available and the Adhese instance is available.\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseSlot({\n onChange,\n ...options\n}: AdheseSlotProps): ReactElement {\n const element = useRef<HTMLDivElement | null>(null);\n\n const slot = useAdheseSlot(element, options);\n\n useEffect(() => {\n onChange?.(slot);\n }, [onChange, slot]);\n\n return (\n <div ref={element} />\n );\n}\n"],"names":["createContext","useState","useEffect","useContext","omit","useRef","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgBA,MAAAA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E3CH,QAAAA,UAAU,MAAM;AACd,yCAAW;AAAA,EAAI,GACd,CAAC,UAAU,IAAI,CAAC;AAGjB,SAAAI,2BAAA,IAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,13 @@ const adheseContext = createContext(void 0);
|
|
|
6
6
|
function AdheseProvider({ children, options }) {
|
|
7
7
|
const [adhese, setAdhese] = useState(void 0);
|
|
8
8
|
useEffect(() => {
|
|
9
|
-
let instance
|
|
9
|
+
let instance;
|
|
10
10
|
import("@adhese/sdk").then(({ createAdhese }) => {
|
|
11
11
|
instance = createAdhese(options);
|
|
12
|
-
setAdhese(
|
|
12
|
+
setAdhese((current) => {
|
|
13
|
+
current == null ? void 0 : current.dispose();
|
|
14
|
+
return instance;
|
|
15
|
+
});
|
|
13
16
|
}).catch(console.error);
|
|
14
17
|
return () => {
|
|
15
18
|
instance == null ? void 0 : instance.dispose();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/adheseContext.tsx","../src/useAdheseSlot.ts","../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport {\n type PropsWithChildren,\n type ReactElement,\n createContext,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport type { Adhese, AdheseOptions } from '@adhese/sdk';\n\nconst adheseContext = createContext<Adhese | undefined>(undefined);\n\n/**\n * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be\n * used in all child components.\n * @constructor\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseProvider({ children, options }: PropsWithChildren<{ options: AdheseOptions }>): ReactElement {\n const [adhese, setAdhese] = useState<Adhese | undefined>(undefined);\n\n useEffect(() => {\n let instance: Adhese |
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/adheseContext.tsx","../src/useAdheseSlot.ts","../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport {\n type PropsWithChildren,\n type ReactElement,\n createContext,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport type { Adhese, AdheseOptions } from '@adhese/sdk';\n\nconst adheseContext = createContext<Adhese | undefined>(undefined);\n\n/**\n * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be\n * used in all child components.\n * @constructor\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseProvider({ children, options }: PropsWithChildren<{ options: AdheseOptions }>): ReactElement {\n const [adhese, setAdhese] = useState<Adhese | undefined>(undefined);\n\n useEffect(() => {\n let instance: Adhese | undefined;\n\n import('@adhese/sdk').then(({ createAdhese }) => {\n instance = createAdhese(options);\n\n setAdhese((current) => {\n current?.dispose();\n\n return instance;\n });\n }).catch(console.error);\n\n return (): void => {\n instance?.dispose();\n };\n }, [options]);\n\n return (\n <adheseContext.Provider value={adhese}>\n {children}\n </adheseContext.Provider>\n );\n}\n\n/**\n * Hook to get the Adhese instance from the nearest `AdheseProvider`. When the Adhese instance is not available yet, `null`\n */\nexport function useAdhese(): Adhese | undefined {\n return useContext(adheseContext);\n}\n","import { type RefObject, useState } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport useDeepCompareEffect from 'use-deep-compare-effect';\nimport { omit } from 'remeda';\nimport { useAdhese } from './adheseContext';\n\n/**\n * Hook to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be created\n * when the containing element is available and the Adhese instance is available.\n * @param elementRef The ref to the containing element\n * @param options The options to create the slot\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useDeepCompareEffect(() => {\n let intermediate: AdheseSlot | undefined;\n\n if (adhese && elementRef.current) {\n intermediate = adhese.addSlot(\n {\n ...options,\n containingElement: elementRef.current,\n },\n );\n\n setSlot(intermediate);\n }\n\n return (): void => {\n intermediate?.dispose();\n };\n }, [adhese, omit(options, Object.entries(options).filter(([, value]) => typeof value === 'function').map(([key]) => key as keyof typeof options)), elementRef.current]);\n\n return slot;\n}\n","import { type ReactElement, useEffect, useRef } from 'react';\nimport type { AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { useAdheseSlot } from './useAdheseSlot';\n\nexport type AdheseSlotProps = {\n /**\n * Callback to be called when the slot is created or disposed\n */\n onChange?(slot: Slot | null): void;\n} & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;\n\n/**\n * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be\n * created when the containing element is available and the Adhese instance is available.\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseSlot({\n onChange,\n ...options\n}: AdheseSlotProps): ReactElement {\n const element = useRef<HTMLDivElement | null>(null);\n\n const slot = useAdheseSlot(element, options);\n\n useEffect(() => {\n onChange?.(slot);\n }, [onChange, slot]);\n\n return (\n <div ref={element} />\n );\n}\n"],"names":[],"mappings":";;;;AAYA,MAAM,gBAAgB,cAAkC,MAAS;AAQ1D,SAAS,eAAe,EAAE,UAAU,WAAwE;AACjH,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA6B,MAAS;AAElE,YAAU,MAAM;AACV,QAAA;AAEJ,WAAO,aAAa,EAAE,KAAK,CAAC,EAAE,mBAAmB;AAC/C,iBAAW,aAAa,OAAO;AAE/B,gBAAU,CAAC,YAAY;AACrB,2CAAS;AAEF,eAAA;AAAA,MAAA,CACR;AAAA,IACF,CAAA,EAAE,MAAM,QAAQ,KAAK;AAEtB,WAAO,MAAY;AACjB,2CAAU;AAAA,IAAQ;AAAA,EACpB,GACC,CAAC,OAAO,CAAC;AAEZ,6BACG,cAAc,UAAd,EAAuB,OAAO,QAC5B,SACH,CAAA;AAEJ;AAKO,SAAS,YAAgC;AAC9C,SAAO,WAAW,aAAa;AACjC;ACzCgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,CAAC,MAAM,OAAO,IAAI,SAA4B,IAAI;AACxD,QAAM,SAAS;AAEf,uBAAqB,MAAM;AACrB,QAAA;AAEA,QAAA,UAAU,WAAW,SAAS;AAChC,qBAAe,OAAO;AAAA,QACpB;AAAA,UACE,GAAG;AAAA,UACH,mBAAmB,WAAW;AAAA,QAChC;AAAA,MAAA;AAGF,cAAQ,YAAY;AAAA,IACtB;AAEA,WAAO,MAAY;AACjB,mDAAc;AAAA,IAAQ;AAAA,EAEvB,GAAA,CAAC,QAAQ,KAAK,SAAS,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAA,EAAG,KAAK,MAAM,OAAO,UAAU,UAAU,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,GAA2B,CAAC,GAAG,WAAW,OAAO,CAAC;AAE/J,SAAA;AACT;ACpBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAU,OAA8B,IAAI;AAE5C,QAAA,OAAO,cAAc,SAAS,OAAO;AAE3C,YAAU,MAAM;AACd,yCAAW;AAAA,EAAI,GACd,CAAC,UAAU,IAAI,CAAC;AAGjB,SAAA,oBAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhese/sdk-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.7",
|
|
5
5
|
"description": "Adhese SDK",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"react-dom": ">=16.13"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@adhese/sdk-shared": "^0.
|
|
33
|
+
"@adhese/sdk-shared": "^0.5.0",
|
|
34
34
|
"remeda": "^1.61.0",
|
|
35
35
|
"use-deep-compare-effect": "^1.8.1"
|
|
36
36
|
},
|