@adhese/sdk-react 1.1.1 → 1.1.2-nightly-20240617154422

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,15 @@
1
1
  # @adhese/sdk-react
2
2
 
3
+ ## 1.1.2-nightly-20240617154422
4
+
5
+ ### Patch Changes
6
+
7
+ - 6dd76ff: Make AdheseSlot a lazy component
8
+ - 6dd76ff: Wrap watch from @adhese/sdk-shared in dynamic import to enable more chunk splitting
9
+ - 6dd76ff: Make passing of options optional to `AdheseProvider`, this will not initialize the SDK but will create the context
10
+ provider. You can, for example, use this to dynamically import plugins first before creating the SDK. See
11
+ `apps/react-example` for an example.
12
+
3
13
  ## 1.1.1
4
14
 
5
15
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useRef, useCallback } from "react";
3
3
  import { watch } from "@adhese/sdk-shared";
4
- import { useAdheseSlot } from "./useAdheseSlot.js";
4
+ import { useAdheseSlot } from "../useAdheseSlot.js";
5
5
  function AdheseSlot({
6
6
  onChange,
7
7
  ...options
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdheseSlot.js","sources":["../../src/AdheseSlot/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;"}
@@ -0,0 +1,6 @@
1
+ import { lazy } from "react";
2
+ const AdheseSlot = lazy(() => import("./AdheseSlot.js").then((module) => ({ default: module.AdheseSlot })));
3
+ export {
4
+ AdheseSlot
5
+ };
6
+ //# sourceMappingURL=AdheseSlot.lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdheseSlot.lazy.js","sources":["../../src/AdheseSlot/AdheseSlot.lazy.ts"],"sourcesContent":["import { lazy } from 'react';\n\n// eslint-disable-next-line ts/naming-convention\nexport const AdheseSlot = lazy(() => import('./AdheseSlot').then(module => ({ default: module.AdheseSlot })));\n"],"names":[],"mappings":";AAGO,MAAM,aAAa,KAAK,MAAM,OAAO,iBAAc,EAAE,KAAK,CAAA,YAAW,EAAE,SAAS,OAAO,aAAa,CAAC;"}
@@ -5,6 +5,8 @@ function AdheseProvider({ children, options }) {
5
5
  const [adhese, setAdhese] = useState(void 0);
6
6
  useEffect(() => {
7
7
  let instance;
8
+ if (!options)
9
+ return;
8
10
  import("@adhese/sdk").then(({ createAdhese }) => {
9
11
  instance = createAdhese(options);
10
12
  setAdhese((current) => {
@@ -1 +1 @@
1
- {"version":3,"file":"adheseContext.js","sources":["../src/adheseContext.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"],"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;"}
1
+ {"version":3,"file":"adheseContext.js","sources":["../src/adheseContext.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 if (!options)\n return;\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"],"names":[],"mappings":";;AAYA,MAAM,gBAAgB,cAAkC,MAAS;AAQ1D,SAAS,eAAe,EAAE,UAAU,WAAyE;AAClH,QAAM,CAAC,QAAQ,SAAS,IAAI,SAA6B,MAAS;AAElE,YAAU,MAAM;AACV,QAAA;AAEJ,QAAI,CAAC;AACH;AAEF,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;"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const react = require("react");
5
5
  const sdkShared = require("@adhese/sdk-shared");
6
- const useAdheseSlot = require("./useAdheseSlot.cjs");
6
+ const useAdheseSlot = require("../useAdheseSlot.cjs");
7
7
  function AdheseSlot({
8
8
  onChange,
9
9
  ...options
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdheseSlot.cjs","sources":["../../../src/AdheseSlot/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;;"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const AdheseSlot = react.lazy(() => Promise.resolve().then(() => require("./AdheseSlot.cjs")).then((module2) => ({ default: module2.AdheseSlot })));
5
+ exports.AdheseSlot = AdheseSlot;
6
+ //# sourceMappingURL=AdheseSlot.lazy.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AdheseSlot.lazy.cjs","sources":["../../../src/AdheseSlot/AdheseSlot.lazy.ts"],"sourcesContent":["import { lazy } from 'react';\n\n// eslint-disable-next-line ts/naming-convention\nexport const AdheseSlot = lazy(() => import('./AdheseSlot').then(module => ({ default: module.AdheseSlot })));\n"],"names":["lazy","module"],"mappings":";;;AAGO,MAAM,aAAaA,MAAA,KAAK,MAAM,QAAO,QAAA,EAAA,KAAA,MAAA,QAAA,kBAAc,CAAA,EAAE,KAAK,CAAAC,aAAW,EAAE,SAASA,QAAO,aAAa,CAAC;;"}
@@ -29,6 +29,8 @@ function AdheseProvider({ children, options }) {
29
29
  const [adhese, setAdhese] = react.useState(void 0);
30
30
  react.useEffect(() => {
31
31
  let instance;
32
+ if (!options)
33
+ return;
32
34
  import("@adhese/sdk").then(({ createAdhese }) => {
33
35
  instance = createAdhese(options);
34
36
  setAdhese((current) => {
@@ -1 +1 @@
1
- {"version":3,"file":"adheseContext.cjs","sources":["../../src/adheseContext.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"],"names":["createContext","useState","useEffect","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgBA,MAAAA,cAAkC,MAAS;AAQ1D,SAAS,eAAe,EAAE,UAAU,WAAwE;AACjH,QAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAA6B,MAAS;AAElEC,QAAAA,UAAU,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,wCACG,cAAc,UAAd,EAAuB,OAAO,QAC5B,SACH,CAAA;AAEJ;AAKO,SAAS,YAAgC;AAC9C,SAAOC,MAAAA,WAAW,aAAa;AACjC;;;"}
1
+ {"version":3,"file":"adheseContext.cjs","sources":["../../src/adheseContext.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 if (!options)\n return;\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"],"names":["createContext","useState","useEffect","useContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,gBAAgBA,MAAAA,cAAkC,MAAS;AAQ1D,SAAS,eAAe,EAAE,UAAU,WAAyE;AAClH,QAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAA6B,MAAS;AAElEC,QAAAA,UAAU,MAAM;AACV,QAAA;AAEJ,QAAI,CAAC;AACH;AAEF,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,wCACG,cAAc,UAAd,EAAuB,OAAO,QAC5B,SACH,CAAA;AAEJ;AAKO,SAAS,YAAgC;AAC9C,SAAOC,MAAAA,WAAW,aAAa;AACjC;;;"}
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const adheseContext = require("./adheseContext.cjs");
4
4
  const useAdheseSlot = require("./useAdheseSlot.cjs");
5
- const AdheseSlot = require("./AdheseSlot.cjs");
5
+ const AdheseSlot_lazy = require("./AdheseSlot/AdheseSlot.lazy.cjs");
6
6
  exports.AdheseProvider = adheseContext.AdheseProvider;
7
7
  exports.useAdhese = adheseContext.useAdhese;
8
8
  exports.useAdheseSlot = useAdheseSlot.useAdheseSlot;
9
- exports.AdheseSlot = AdheseSlot.AdheseSlot;
9
+ exports.AdheseSlot = AdheseSlot_lazy.AdheseSlot;
10
10
  //# sourceMappingURL=sdkReact.cjs.map
@@ -1,26 +1,49 @@
1
1
  "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
2
24
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
25
  const react = require("react");
4
- const sdkShared = require("@adhese/sdk-shared");
5
26
  const adheseContext = require("./adheseContext.cjs");
6
27
  function useAdheseSlot(elementRef, options) {
7
28
  const adhese = adheseContext.useAdhese();
8
29
  const [slot, setSlot] = react.useState(null);
9
30
  react.useEffect(() => {
10
31
  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
- }
32
+ import("@adhese/sdk-shared").then(({ watch }) => {
33
+ if (adhese && elementRef.current) {
34
+ intermediate = adhese == null ? void 0 : adhese.addSlot({
35
+ ...options,
36
+ containingElement: elementRef.current,
37
+ setup(context, hooks) {
38
+ var _a;
39
+ (_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
40
+ watch(context, (newSlot) => {
41
+ setSlot(newSlot);
42
+ }, { deep: true, immediate: true });
43
+ }
44
+ });
45
+ }
46
+ }).catch(console.error);
24
47
  return () => {
25
48
  intermediate == null ? void 0 : intermediate.dispose();
26
49
  setSlot(null);
@@ -1 +1 @@
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;;"}
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 { 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 import('@adhese/sdk-shared').then(({ watch }) => {\n if (adhese && elementRef.current) {\n intermediate = 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 }).catch(console.error);\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiBgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,SAASA,cAAAA;AAEf,QAAM,CAAC,MAAM,OAAO,IAAIC,eAA4B,IAAI;AACxDC,QAAAA,UAAU,MAAM;AACd,QAAI,eAAkC;AAEtC,WAAO,oBAAoB,EAAE,KAAK,CAAC,EAAE,YAAY;AAC3C,UAAA,UAAU,WAAW,SAAS;AAChC,uBAAe,iCAAQ,QAAQ;AAAA,UAC7B,GAAG;AAAA,UACH,mBAAmB,WAAW;AAAA,UAC9B,MAAM,SAAS,OAAO;;AACZ,0BAAA,UAAA,iCAAQ,SAAS;AAEnB,kBAAA,SAAS,CAAC,YAAY;AAC1B,sBAAQ,OAAO;AAAA,eACd,EAAE,MAAM,MAAM,WAAW,KAAM,CAAA;AAAA,UACpC;AAAA,QAAA;AAAA,MAEJ;AAAA,IACD,CAAA,EAAE,MAAM,QAAQ,KAAK;AAEtB,WAAO,MAAY;AACjB,mDAAc;AAEd,cAAQ,IAAI;AAAA,IAAA;AAAA,EACd,GACC,CAAC,QAAQ,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC;AAE/B,SAAA;AACT;;"}
@@ -1,5 +1,6 @@
1
+ import * as react from 'react';
1
2
  import { PropsWithChildren, ReactElement, RefObject } from 'react';
2
- import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$1 } from '@adhese/sdk';
3
+ import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$2 } from '@adhese/sdk';
3
4
 
4
5
  /**
5
6
  * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be
@@ -7,7 +8,7 @@ import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$1 }
7
8
  * @constructor
8
9
  */
9
10
  declare function AdheseProvider({ children, options }: PropsWithChildren<{
10
- options: AdheseOptions;
11
+ options?: AdheseOptions;
11
12
  }>): ReactElement;
12
13
  /**
13
14
  * Hook to get the Adhese instance from the nearest `AdheseProvider`. When the Adhese instance is not available yet, `null`
@@ -23,13 +24,13 @@ declare function useAdhese(): Adhese | undefined;
23
24
  * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
24
25
  * memoized.
25
26
  */
26
- declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null;
27
+ declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$2 | null;
27
28
 
28
29
  type AdheseSlotProps = {
29
30
  /**
30
31
  * Callback to be called when the slot is created or disposed
31
32
  */
32
- onChange?(slot: AdheseSlot$1 | null): void;
33
+ onChange?(slot: AdheseSlot$2 | null): void;
33
34
  } & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;
34
35
  /**
35
36
  * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be
@@ -38,6 +39,8 @@ type AdheseSlotProps = {
38
39
  * @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
39
40
  * memoized.
40
41
  */
41
- declare function AdheseSlot({ onChange, ...options }: AdheseSlotProps): ReactElement;
42
+ declare function AdheseSlot$1({ onChange, ...options }: AdheseSlotProps): ReactElement;
43
+
44
+ declare const AdheseSlot: react.LazyExoticComponent<typeof AdheseSlot$1>;
42
45
 
43
46
  export { AdheseProvider, AdheseSlot, useAdhese, useAdheseSlot };
package/dist/sdkReact.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AdheseProvider, useAdhese } from "./adheseContext.js";
2
2
  import { useAdheseSlot } from "./useAdheseSlot.js";
3
- import { AdheseSlot } from "./AdheseSlot.js";
3
+ import { AdheseSlot } from "./AdheseSlot/AdheseSlot.lazy.js";
4
4
  export {
5
5
  AdheseProvider,
6
6
  AdheseSlot,
@@ -1,24 +1,25 @@
1
1
  import { useState, useEffect } from "react";
2
- import { toRaw, watch } from "@adhese/sdk-shared";
3
2
  import { useAdhese } from "./adheseContext.js";
4
3
  function useAdheseSlot(elementRef, options) {
5
4
  const adhese = useAdhese();
6
5
  const [slot, setSlot] = useState(null);
7
6
  useEffect(() => {
8
7
  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
- }
8
+ import("@adhese/sdk-shared").then(({ watch }) => {
9
+ if (adhese && elementRef.current) {
10
+ intermediate = 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
+ }
22
+ }).catch(console.error);
22
23
  return () => {
23
24
  intermediate == null ? void 0 : intermediate.dispose();
24
25
  setSlot(null);
@@ -1 +1 @@
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;"}
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 { 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 import('@adhese/sdk-shared').then(({ watch }) => {\n if (adhese && elementRef.current) {\n intermediate = 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 }).catch(console.error);\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":";;AAiBgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,SAAS;AAEf,QAAM,CAAC,MAAM,OAAO,IAAI,SAA4B,IAAI;AACxD,YAAU,MAAM;AACd,QAAI,eAAkC;AAEtC,WAAO,oBAAoB,EAAE,KAAK,CAAC,EAAE,YAAY;AAC3C,UAAA,UAAU,WAAW,SAAS;AAChC,uBAAe,iCAAQ,QAAQ;AAAA,UAC7B,GAAG;AAAA,UACH,mBAAmB,WAAW;AAAA,UAC9B,MAAM,SAAS,OAAO;;AACZ,0BAAA,UAAA,iCAAQ,SAAS;AAEnB,kBAAA,SAAS,CAAC,YAAY;AAC1B,sBAAQ,OAAO;AAAA,eACd,EAAE,MAAM,MAAM,WAAW,KAAM,CAAA;AAAA,UACpC;AAAA,QAAA;AAAA,MAEJ;AAAA,IACD,CAAA,EAAE,MAAM,QAAQ,KAAK;AAEtB,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.1.1",
4
+ "version": "1.1.2-nightly-20240617154422",
5
5
  "description": "Adhese SDK",
6
6
  "repository": {
7
7
  "type": "git",
@@ -44,7 +44,7 @@
44
44
  "react-dom": ">=16.13"
45
45
  },
46
46
  "dependencies": {
47
- "@adhese/sdk": "^1.1.0",
47
+ "@adhese/sdk": "^1.1.1",
48
48
  "@adhese/sdk-shared": "^1.1.0"
49
49
  }
50
50
  }
@@ -1 +0,0 @@
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;"}
@@ -1 +0,0 @@
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;;"}