@adhese/sdk-react 1.0.1 → 1.0.3

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @adhese/sdk-react
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 32e1ca5: Remove src/legacy.d.ts from included files
8
+ - 98121c3: Fix slot state sync not working properly
9
+ - 5e953f8: Add 'use client' directive to AdheseSlot component for RSC environments
10
+
11
+ ## 1.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - e59b2d5: Replace use-deep-compare-effect in useAdheseSlot with useEffect and useRef
16
+
3
17
  ## 1.0.1
4
18
 
5
19
  ### Patch Changes
@@ -1,15 +1,22 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useRef, useEffect } from "react";
2
+ import { useRef, useCallback } from "react";
3
+ import { watch } from "@adhese/sdk-shared";
3
4
  import { useAdheseSlot } from "./useAdheseSlot.js";
4
5
  function AdheseSlot({
5
6
  onChange,
6
7
  ...options
7
8
  }) {
8
9
  const element = useRef(null);
9
- const slot = useAdheseSlot(element, options);
10
- useEffect(() => {
11
- onChange == null ? void 0 : onChange(slot);
12
- }, [onChange, slot]);
10
+ useAdheseSlot(element, {
11
+ ...options,
12
+ setup: useCallback((context, hooks) => {
13
+ var _a;
14
+ (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
15
+ watch(context, (newSlot) => {
16
+ onChange == null ? void 0 : onChange(newSlot);
17
+ }, { immediate: true, deep: true });
18
+ }, [options.setup, onChange])
19
+ });
13
20
  return /* @__PURE__ */ jsx("div", { ref: element });
14
21
  }
15
22
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"AdheseSlot.js","sources":["../src/AdheseSlot.tsx"],"sourcesContent":["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":";;;AAgBO,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;"}
1
+ {"version":3,"file":"AdheseSlot.js","sources":["../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport { type ReactElement, useCallback, useRef } from 'react';\nimport type { AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { watch } from '@adhese/sdk-shared';\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 * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not\n * memoized.\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 useAdheseSlot(element, {\n ...options,\n setup: useCallback(((context, hooks): void => {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n }) satisfies AdheseSlotOptions['setup'], [options.setup, onChange]),\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":[],"mappings":";;;;AAsBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAU,OAA8B,IAAI;AAElD,gBAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,OAAO,YAAa,CAAC,SAAS,UAAgB;;AACpC,oBAAA,UAAA,iCAAQ,SAAS;AAEnB,YAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACK,GAAA,CAAC,QAAQ,OAAO,QAAQ,CAAC;AAAA,EAAA,CACnE;AAGC,SAAA,oBAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;"}
@@ -2,16 +2,23 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const react = require("react");
5
+ const sdkShared = require("@adhese/sdk-shared");
5
6
  const useAdheseSlot = require("./useAdheseSlot.cjs");
6
7
  function AdheseSlot({
7
8
  onChange,
8
9
  ...options
9
10
  }) {
10
11
  const element = react.useRef(null);
11
- const slot = useAdheseSlot.useAdheseSlot(element, options);
12
- react.useEffect(() => {
13
- onChange == null ? void 0 : onChange(slot);
14
- }, [onChange, slot]);
12
+ useAdheseSlot.useAdheseSlot(element, {
13
+ ...options,
14
+ setup: react.useCallback((context, hooks) => {
15
+ var _a;
16
+ (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
17
+ sdkShared.watch(context, (newSlot) => {
18
+ onChange == null ? void 0 : onChange(newSlot);
19
+ }, { immediate: true, deep: true });
20
+ }, [options.setup, onChange])
21
+ });
15
22
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: element });
16
23
  }
17
24
  exports.AdheseSlot = AdheseSlot;
@@ -1 +1 @@
1
- {"version":3,"file":"AdheseSlot.cjs","sources":["../../src/AdheseSlot.tsx"],"sourcesContent":["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":["useRef","useAdheseSlot","useEffect","jsx"],"mappings":";;;;;AAgBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAUA,aAA8B,IAAI;AAE5C,QAAA,OAAOC,cAAAA,cAAc,SAAS,OAAO;AAE3CC,QAAAA,UAAU,MAAM;AACd,yCAAW;AAAA,EAAI,GACd,CAAC,UAAU,IAAI,CAAC;AAGjB,SAAAC,2BAAA,IAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;;"}
1
+ {"version":3,"file":"AdheseSlot.cjs","sources":["../../src/AdheseSlot.tsx"],"sourcesContent":["'use client';\n\nimport { type ReactElement, useCallback, useRef } from 'react';\nimport type { AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { watch } from '@adhese/sdk-shared';\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 * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not\n * memoized.\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 useAdheseSlot(element, {\n ...options,\n setup: useCallback(((context, hooks): void => {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n }) satisfies AdheseSlotOptions['setup'], [options.setup, onChange]),\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":["useRef","useAdheseSlot","useCallback","watch","jsx"],"mappings":";;;;;;AAsBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAUA,aAA8B,IAAI;AAElDC,gBAAAA,cAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,OAAOC,MAAA,YAAa,CAAC,SAAS,UAAgB;;AACpC,oBAAA,UAAA,iCAAQ,SAAS;AAEnBC,sBAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACK,GAAA,CAAC,QAAQ,OAAO,QAAQ,CAAC;AAAA,EAAA,CACnE;AAGC,SAAAC,2BAAA,IAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;;"}
@@ -1,27 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
- const useDeepCompareEffect = require("use-deep-compare-effect");
5
4
  const sdkShared = require("@adhese/sdk-shared");
6
5
  const adheseContext = require("./adheseContext.cjs");
7
6
  function useAdheseSlot(elementRef, options) {
8
- const [slot, setSlot] = react.useState(null);
9
7
  const adhese = adheseContext.useAdhese();
10
- useDeepCompareEffect(() => {
11
- let intermediate;
8
+ const [slot, setSlot] = react.useState(null);
9
+ react.useEffect(() => {
10
+ let intermediate = null;
12
11
  if (adhese && elementRef.current) {
13
- intermediate = adhese.addSlot(
14
- {
15
- ...options,
16
- containingElement: elementRef.current
12
+ intermediate = sdkShared.toRaw(adhese == null ? void 0 : adhese.addSlot({
13
+ ...options,
14
+ containingElement: elementRef.current,
15
+ setup(context, hooks) {
16
+ var _a;
17
+ (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
18
+ sdkShared.watch(context, (newSlot) => {
19
+ setSlot(newSlot);
20
+ }, { deep: true, immediate: true });
17
21
  }
18
- );
19
- setSlot(intermediate);
22
+ }));
20
23
  }
21
24
  return () => {
22
25
  intermediate == null ? void 0 : intermediate.dispose();
26
+ setSlot(null);
23
27
  };
24
- }, [adhese, sdkShared.omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
28
+ }, [adhese, ...Object.values(options)]);
25
29
  return slot;
26
30
  }
27
31
  exports.useAdheseSlot = useAdheseSlot;
@@ -1 +1 @@
1
- {"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useState } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport useDeepCompareEffect from 'use-deep-compare-effect';\nimport { omit } from '@adhese/sdk-shared';\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"],"names":["useState","useAdhese","omit"],"mappings":";;;;;;AAYgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,CAAC,MAAM,OAAO,IAAIA,eAA4B,IAAI;AACxD,QAAM,SAASC,cAAAA;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,QAAQC,eAAK,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;;"}
1
+ {"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import {\n type RefObject,\n useEffect,\n useState,\n} from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { toRaw, watch } from '@adhese/sdk-shared';\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 *\n * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not\n * memoized.\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const adhese = useAdhese();\n\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n useEffect(() => {\n let intermediate: AdheseSlot | null = null;\n\n if (adhese && elementRef.current) {\n intermediate = toRaw(adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n setup(context, hooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n setSlot(newSlot);\n }, { deep: true, immediate: true });\n },\n }));\n }\n\n return (): void => {\n intermediate?.dispose();\n\n setSlot(null);\n };\n }, [adhese, ...Object.values(options)]);\n\n return slot;\n}\n"],"names":["useAdhese","useState","useEffect","toRaw","watch"],"mappings":";;;;;AAkBgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,SAASA,cAAAA;AAEf,QAAM,CAAC,MAAM,OAAO,IAAIC,eAA4B,IAAI;AACxDC,QAAAA,UAAU,MAAM;AACd,QAAI,eAAkC;AAElC,QAAA,UAAU,WAAW,SAAS;AACjB,qBAAAC,UAAAA,MAAM,iCAAQ,QAAQ;AAAA,QACnC,GAAG;AAAA,QACH,mBAAmB,WAAW;AAAA,QAC9B,MAAM,SAAS,OAAO;;AACZ,wBAAA,UAAA,iCAAQ,SAAS;AAEnBC,0BAAA,SAAS,CAAC,YAAY;AAC1B,oBAAQ,OAAO;AAAA,aACd,EAAE,MAAM,MAAM,WAAW,KAAM,CAAA;AAAA,QACpC;AAAA,MACD,EAAC;AAAA,IACJ;AAEA,WAAO,MAAY;AACjB,mDAAc;AAEd,cAAQ,IAAI;AAAA,IAAA;AAAA,EACd,GACC,CAAC,QAAQ,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC;AAE/B,SAAA;AACT;;"}
@@ -19,6 +19,9 @@ declare function useAdhese(): Adhese | undefined;
19
19
  * when the containing element is available and the Adhese instance is available.
20
20
  * @param elementRef The ref to the containing element
21
21
  * @param options The options to create the slot
22
+ *
23
+ * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
24
+ * memoized.
22
25
  */
23
26
  declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null;
24
27
 
@@ -31,6 +34,9 @@ type AdheseSlotProps = {
31
34
  /**
32
35
  * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be
33
36
  * created when the containing element is available and the Adhese instance is available.
37
+ *
38
+ * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
39
+ * memoized.
34
40
  */
35
41
  declare function AdheseSlot({ onChange, ...options }: AdheseSlotProps): ReactElement;
36
42
 
@@ -1,25 +1,29 @@
1
- import { useState } from "react";
2
- import useDeepCompareEffect from "use-deep-compare-effect";
3
- import { omit } from "@adhese/sdk-shared";
1
+ import { useState, useEffect } from "react";
2
+ import { toRaw, watch } from "@adhese/sdk-shared";
4
3
  import { useAdhese } from "./adheseContext.js";
5
4
  function useAdheseSlot(elementRef, options) {
6
- const [slot, setSlot] = useState(null);
7
5
  const adhese = useAdhese();
8
- useDeepCompareEffect(() => {
9
- let intermediate;
6
+ const [slot, setSlot] = useState(null);
7
+ useEffect(() => {
8
+ let intermediate = null;
10
9
  if (adhese && elementRef.current) {
11
- intermediate = adhese.addSlot(
12
- {
13
- ...options,
14
- containingElement: elementRef.current
10
+ intermediate = toRaw(adhese == null ? void 0 : adhese.addSlot({
11
+ ...options,
12
+ containingElement: elementRef.current,
13
+ setup(context, hooks) {
14
+ var _a;
15
+ (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
16
+ watch(context, (newSlot) => {
17
+ setSlot(newSlot);
18
+ }, { deep: true, immediate: true });
15
19
  }
16
- );
17
- setSlot(intermediate);
20
+ }));
18
21
  }
19
22
  return () => {
20
23
  intermediate == null ? void 0 : intermediate.dispose();
24
+ setSlot(null);
21
25
  };
22
- }, [adhese, omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
26
+ }, [adhese, ...Object.values(options)]);
23
27
  return slot;
24
28
  }
25
29
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useState } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport useDeepCompareEffect from 'use-deep-compare-effect';\nimport { omit } from '@adhese/sdk-shared';\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"],"names":[],"mappings":";;;;AAYgB,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;"}
1
+ {"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import {\n type RefObject,\n useEffect,\n useState,\n} from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { toRaw, watch } from '@adhese/sdk-shared';\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 *\n * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not\n * memoized.\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const adhese = useAdhese();\n\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n useEffect(() => {\n let intermediate: AdheseSlot | null = null;\n\n if (adhese && elementRef.current) {\n intermediate = toRaw(adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n setup(context, hooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n setSlot(newSlot);\n }, { deep: true, immediate: true });\n },\n }));\n }\n\n return (): void => {\n intermediate?.dispose();\n\n setSlot(null);\n };\n }, [adhese, ...Object.values(options)]);\n\n return slot;\n}\n"],"names":[],"mappings":";;;AAkBgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,SAAS;AAEf,QAAM,CAAC,MAAM,OAAO,IAAI,SAA4B,IAAI;AACxD,YAAU,MAAM;AACd,QAAI,eAAkC;AAElC,QAAA,UAAU,WAAW,SAAS;AACjB,qBAAA,MAAM,iCAAQ,QAAQ;AAAA,QACnC,GAAG;AAAA,QACH,mBAAmB,WAAW;AAAA,QAC9B,MAAM,SAAS,OAAO;;AACZ,wBAAA,UAAA,iCAAQ,SAAS;AAEnB,gBAAA,SAAS,CAAC,YAAY;AAC1B,oBAAQ,OAAO;AAAA,aACd,EAAE,MAAM,MAAM,WAAW,KAAM,CAAA;AAAA,QACpC;AAAA,MACD,EAAC;AAAA,IACJ;AAEA,WAAO,MAAY;AACjB,mDAAc;AAEd,cAAQ,IAAI;AAAA,IAAA;AAAA,EACd,GACC,CAAC,QAAQ,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC;AAE/B,SAAA;AACT;"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@adhese/sdk-react",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.3",
5
5
  "description": "Adhese SDK",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/adhese/sdk_typescript.git"
9
9
  },
10
- "exports": [
11
- {
10
+ "exports": {
11
+ ".": {
12
12
  "types": "./dist/sdkReact.d.ts",
13
13
  "import": "./dist/sdkReact.js",
14
14
  "require": "./dist/cjs/sdkReact.cjs",
15
15
  "types@<5.1": "./dist/legacy.d.ts"
16
16
  }
17
- ],
17
+ },
18
18
  "main": "./dist/cjs/sdkReact.cjs",
19
19
  "module": "./dist/sdkReact.js",
20
20
  "types": "./dist/sdkReact.d.ts",
@@ -29,8 +29,7 @@
29
29
  "CHANGELOG.md",
30
30
  "LICENSE",
31
31
  "README.md",
32
- "dist",
33
- "src/legacy.d.ts"
32
+ "dist"
34
33
  ],
35
34
  "scripts": {
36
35
  "build": "vite build",
@@ -46,7 +45,6 @@
46
45
  },
47
46
  "dependencies": {
48
47
  "@adhese/sdk": "^1.0.2",
49
- "@adhese/sdk-shared": "^1.0.0",
50
- "use-deep-compare-effect": "^1.8.1"
48
+ "@adhese/sdk-shared": "^1.0.0"
51
49
  }
52
50
  }
package/src/legacy.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { PropsWithChildren, ReactElement, RefObject } from 'react';
2
-
3
- declare function AdheseProvider({ children, options }: PropsWithChildren<{
4
- options: any;
5
- }>): ReactElement;
6
-
7
- declare function useAdhese(): any | undefined;
8
-
9
- declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: any): any;
10
-
11
- declare function AdheseSlot({ onChange, ...options }: {
12
- onChange?(slot: any | null): void;
13
- } & any): ReactElement;