@adhese/sdk-react 1.0.2 → 1.1.0

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,27 @@
1
1
  # @adhese/sdk-react
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 112e224: Add `width` and `height` option to overwrite slot sizing
8
+
9
+ **NOTE**: Only applies when `renderMode` is `iframe` or `undefined`
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [112e224]
14
+ - @adhese/sdk-shared@1.1.0
15
+ - @adhese/sdk@1.1.0
16
+
17
+ ## 1.0.3
18
+
19
+ ### Patch Changes
20
+
21
+ - 32e1ca5: Remove src/legacy.d.ts from included files
22
+ - 98121c3: Fix slot state sync not working properly
23
+ - 5e953f8: Add 'use client' directive to AdheseSlot component for RSC environments
24
+
3
25
  ## 1.0.2
4
26
 
5
27
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useRef } from "react";
2
+ import { useRef, useCallback } from "react";
3
3
  import { watch } from "@adhese/sdk-shared";
4
4
  import { useAdheseSlot } from "./useAdheseSlot.js";
5
5
  function AdheseSlot({
@@ -9,13 +9,13 @@ function AdheseSlot({
9
9
  const element = useRef(null);
10
10
  useAdheseSlot(element, {
11
11
  ...options,
12
- setup(context, hooks) {
12
+ setup: useCallback((context, hooks) => {
13
13
  var _a;
14
14
  (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
15
15
  watch(context, (newSlot) => {
16
16
  onChange == null ? void 0 : onChange(newSlot);
17
17
  }, { immediate: true, deep: true });
18
- }
18
+ }, [options.setup, onChange])
19
19
  });
20
20
  return /* @__PURE__ */ jsx("div", { ref: element });
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AdheseSlot.js","sources":["../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement, useRef } from 'react';\nimport type { AdheseSlotContext, AdheseSlotHooks, AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { type Ref, 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// 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(context: Ref<AdheseSlotContext | null>, hooks: AdheseSlotHooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n },\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":[],"mappings":";;;;AAiBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAU,OAA8B,IAAI;AAElD,gBAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,SAAwC,OAAwB;;AAC5D,oBAAA,UAAA,iCAAQ,SAAS;AAEnB,YAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACpC;AAAA,EAAA,CACD;AAGC,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;"}
@@ -11,13 +11,13 @@ function AdheseSlot({
11
11
  const element = react.useRef(null);
12
12
  useAdheseSlot.useAdheseSlot(element, {
13
13
  ...options,
14
- setup(context, hooks) {
14
+ setup: react.useCallback((context, hooks) => {
15
15
  var _a;
16
16
  (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
17
17
  sdkShared.watch(context, (newSlot) => {
18
18
  onChange == null ? void 0 : onChange(newSlot);
19
19
  }, { immediate: true, deep: true });
20
- }
20
+ }, [options.setup, onChange])
21
21
  });
22
22
  return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: element });
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AdheseSlot.cjs","sources":["../../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement, useRef } from 'react';\nimport type { AdheseSlotContext, AdheseSlotHooks, AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { type Ref, 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// 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(context: Ref<AdheseSlotContext | null>, hooks: AdheseSlotHooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n },\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":["useRef","useAdheseSlot","watch","jsx"],"mappings":";;;;;;AAiBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAUA,aAA8B,IAAI;AAElDC,gBAAAA,cAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,SAAwC,OAAwB;;AAC5D,oBAAA,UAAA,iCAAQ,SAAS;AAEnBC,sBAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACpC;AAAA,EAAA,CACD;AAGC,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,22 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("react");
4
+ const sdkShared = require("@adhese/sdk-shared");
4
5
  const adheseContext = require("./adheseContext.cjs");
5
6
  function useAdheseSlot(elementRef, options) {
6
- const slot = react.useRef(null);
7
7
  const adhese = adheseContext.useAdhese();
8
+ const [slot, setSlot] = react.useState(null);
8
9
  react.useEffect(() => {
9
- if (!adhese || !elementRef.current)
10
- return;
11
- slot.current = adhese == null ? void 0 : adhese.addSlot({
12
- ...options,
13
- containingElement: elementRef.current
14
- });
10
+ let intermediate = null;
11
+ if (adhese && 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 });
21
+ }
22
+ }));
23
+ }
15
24
  return () => {
16
- var _a;
17
- (_a = slot.current) == null ? void 0 : _a.dispose();
25
+ intermediate == null ? void 0 : intermediate.dispose();
26
+ setSlot(null);
18
27
  };
19
- }, [adhese == null ? void 0 : adhese.addSlot, options, elementRef.current]);
28
+ }, [adhese, ...Object.values(options)]);
20
29
  return slot;
21
30
  }
22
31
  exports.useAdheseSlot = useAdheseSlot;
@@ -1 +1 @@
1
- {"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\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'>): RefObject<AdheseSlot | null> {\n const slot = useRef<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useEffect(() => {\n if (!adhese || !elementRef.current)\n return;\n\n slot.current = adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n });\n return (): void => {\n slot.current?.dispose();\n };\n }, [adhese?.addSlot, options, elementRef.current]);\n\n return slot;\n}\n"],"names":["useRef","useAdhese","useEffect"],"mappings":";;;;AAUgB,SAAA,cAAc,YAAoC,SAAiG;AAC3J,QAAA,OAAOA,aAA0B,IAAI;AAC3C,QAAM,SAASC,cAAAA;AAEfC,QAAAA,UAAU,MAAM;AACV,QAAA,CAAC,UAAU,CAAC,WAAW;AACzB;AAEG,SAAA,UAAU,iCAAQ,QAAQ;AAAA,MAC7B,GAAG;AAAA,MACH,mBAAmB,WAAW;AAAA,IAAA;AAEhC,WAAO,MAAY;;AACjB,iBAAK,YAAL,mBAAc;AAAA,IAAQ;AAAA,EACxB,GACC,CAAC,iCAAQ,SAAS,SAAS,WAAW,OAAO,CAAC;AAE1C,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,8 +19,11 @@ 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
- declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): RefObject<AdheseSlot$1 | null>;
26
+ declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null;
24
27
 
25
28
  type AdheseSlotProps = {
26
29
  /**
@@ -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,20 +1,29 @@
1
- import { useRef, useEffect } from "react";
1
+ import { useState, useEffect } from "react";
2
+ import { toRaw, watch } from "@adhese/sdk-shared";
2
3
  import { useAdhese } from "./adheseContext.js";
3
4
  function useAdheseSlot(elementRef, options) {
4
- const slot = useRef(null);
5
5
  const adhese = useAdhese();
6
+ const [slot, setSlot] = useState(null);
6
7
  useEffect(() => {
7
- if (!adhese || !elementRef.current)
8
- return;
9
- slot.current = adhese == null ? void 0 : adhese.addSlot({
10
- ...options,
11
- containingElement: elementRef.current
12
- });
8
+ let intermediate = null;
9
+ if (adhese && 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 });
19
+ }
20
+ }));
21
+ }
13
22
  return () => {
14
- var _a;
15
- (_a = slot.current) == null ? void 0 : _a.dispose();
23
+ intermediate == null ? void 0 : intermediate.dispose();
24
+ setSlot(null);
16
25
  };
17
- }, [adhese == null ? void 0 : adhese.addSlot, options, elementRef.current]);
26
+ }, [adhese, ...Object.values(options)]);
18
27
  return slot;
19
28
  }
20
29
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\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'>): RefObject<AdheseSlot | null> {\n const slot = useRef<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useEffect(() => {\n if (!adhese || !elementRef.current)\n return;\n\n slot.current = adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n });\n return (): void => {\n slot.current?.dispose();\n };\n }, [adhese?.addSlot, options, elementRef.current]);\n\n return slot;\n}\n"],"names":[],"mappings":";;AAUgB,SAAA,cAAc,YAAoC,SAAiG;AAC3J,QAAA,OAAO,OAA0B,IAAI;AAC3C,QAAM,SAAS;AAEf,YAAU,MAAM;AACV,QAAA,CAAC,UAAU,CAAC,WAAW;AACzB;AAEG,SAAA,UAAU,iCAAQ,QAAQ;AAAA,MAC7B,GAAG;AAAA,MACH,mBAAmB,WAAW;AAAA,IAAA;AAEhC,WAAO,MAAY;;AACjB,iBAAK,YAAL,mBAAc;AAAA,IAAQ;AAAA,EACxB,GACC,CAAC,iCAAQ,SAAS,SAAS,WAAW,OAAO,CAAC;AAE1C,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,7 +1,7 @@
1
1
  {
2
2
  "name": "@adhese/sdk-react",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.1.0",
5
5
  "description": "Adhese SDK",
6
6
  "repository": {
7
7
  "type": "git",
@@ -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",
@@ -45,7 +44,7 @@
45
44
  "react-dom": ">=16.13"
46
45
  },
47
46
  "dependencies": {
48
- "@adhese/sdk": "^1.0.2",
49
- "@adhese/sdk-shared": "^1.0.0"
47
+ "@adhese/sdk": "^1.1.0",
48
+ "@adhese/sdk-shared": "^1.1.0"
50
49
  }
51
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;