@adhese/sdk-react 0.9.11 → 0.9.13

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,20 @@
1
1
  # @adhese/sdk-react
2
2
 
3
+ ## 0.9.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 10a2c67: Update entry file(s)
8
+ - Updated dependencies [10a2c67]
9
+ - Updated dependencies [de15eab]
10
+ - @adhese/sdk-shared@0.10.0
11
+
12
+ ## 0.9.12
13
+
14
+ ### Patch Changes
15
+
16
+ - 2dda12f: Update peerDependencies to match nearest compatible version
17
+
3
18
  ## 0.9.11
4
19
 
5
20
  ### Patch Changes
@@ -0,0 +1,18 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useRef, useEffect } from "react";
3
+ import { useAdheseSlot } from "./useAdheseSlot.js";
4
+ function AdheseSlot({
5
+ onChange,
6
+ ...options
7
+ }) {
8
+ const element = useRef(null);
9
+ const slot = useAdheseSlot(element, options);
10
+ useEffect(() => {
11
+ onChange == null ? void 0 : onChange(slot);
12
+ }, [onChange, slot]);
13
+ return /* @__PURE__ */ jsx("div", { ref: element });
14
+ }
15
+ export {
16
+ AdheseSlot
17
+ };
18
+ //# sourceMappingURL=AdheseSlot.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,28 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useState, useEffect, useContext } from "react";
3
+ const adheseContext = createContext(void 0);
4
+ function AdheseProvider({ children, options }) {
5
+ const [adhese, setAdhese] = useState(void 0);
6
+ useEffect(() => {
7
+ let instance;
8
+ import("@adhese/sdk").then(({ createAdhese }) => {
9
+ instance = createAdhese(options);
10
+ setAdhese((current) => {
11
+ current == null ? void 0 : current.dispose();
12
+ return instance;
13
+ });
14
+ }).catch(console.error);
15
+ return () => {
16
+ instance == null ? void 0 : instance.dispose();
17
+ };
18
+ }, [options]);
19
+ return /* @__PURE__ */ jsx(adheseContext.Provider, { value: adhese, children });
20
+ }
21
+ function useAdhese() {
22
+ return useContext(adheseContext);
23
+ }
24
+ export {
25
+ AdheseProvider,
26
+ useAdhese
27
+ };
28
+ //# sourceMappingURL=adheseContext.js.map
@@ -0,0 +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;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const react = require("react");
5
+ const useAdheseSlot = require("./useAdheseSlot.cjs");
6
+ function AdheseSlot({
7
+ onChange,
8
+ ...options
9
+ }) {
10
+ 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]);
15
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: element });
16
+ }
17
+ exports.AdheseSlot = AdheseSlot;
18
+ //# sourceMappingURL=AdheseSlot.cjs.map
@@ -0,0 +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;;"}
@@ -24,8 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
25
  const jsxRuntime = require("react/jsx-runtime");
26
26
  const react = require("react");
27
- const useDeepCompareEffect = require("use-deep-compare-effect");
28
- const sdkShared = require("@adhese/sdk-shared");
29
27
  const adheseContext = react.createContext(void 0);
30
28
  function AdheseProvider({ children, options }) {
31
29
  const [adhese, setAdhese] = react.useState(void 0);
@@ -47,39 +45,6 @@ function AdheseProvider({ children, options }) {
47
45
  function useAdhese() {
48
46
  return react.useContext(adheseContext);
49
47
  }
50
- function useAdheseSlot(elementRef, options) {
51
- const [slot, setSlot] = react.useState(null);
52
- const adhese = useAdhese();
53
- useDeepCompareEffect(() => {
54
- let intermediate;
55
- if (adhese && elementRef.current) {
56
- intermediate = adhese.addSlot(
57
- {
58
- ...options,
59
- containingElement: elementRef.current
60
- }
61
- );
62
- setSlot(intermediate);
63
- }
64
- return () => {
65
- intermediate == null ? void 0 : intermediate.dispose();
66
- };
67
- }, [adhese, sdkShared.omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
68
- return slot;
69
- }
70
- function AdheseSlot({
71
- onChange,
72
- ...options
73
- }) {
74
- const element = react.useRef(null);
75
- const slot = useAdheseSlot(element, options);
76
- react.useEffect(() => {
77
- onChange == null ? void 0 : onChange(slot);
78
- }, [onChange, slot]);
79
- return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: element });
80
- }
81
48
  exports.AdheseProvider = AdheseProvider;
82
- exports.AdheseSlot = AdheseSlot;
83
49
  exports.useAdhese = useAdhese;
84
- exports.useAdheseSlot = useAdheseSlot;
85
- //# sourceMappingURL=index.cjs.map
50
+ //# sourceMappingURL=adheseContext.cjs.map
@@ -0,0 +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;;;"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const adheseContext = require("./adheseContext.cjs");
4
+ const useAdheseSlot = require("./useAdheseSlot.cjs");
5
+ const AdheseSlot = require("./AdheseSlot.cjs");
6
+ exports.AdheseProvider = adheseContext.AdheseProvider;
7
+ exports.useAdhese = adheseContext.useAdhese;
8
+ exports.useAdheseSlot = useAdheseSlot.useAdheseSlot;
9
+ exports.AdheseSlot = AdheseSlot.AdheseSlot;
10
+ //# sourceMappingURL=sdkReact.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdkReact.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const useDeepCompareEffect = require("use-deep-compare-effect");
5
+ const sdkShared = require("@adhese/sdk-shared");
6
+ const adheseContext = require("./adheseContext.cjs");
7
+ function useAdheseSlot(elementRef, options) {
8
+ const [slot, setSlot] = react.useState(null);
9
+ const adhese = adheseContext.useAdhese();
10
+ useDeepCompareEffect(() => {
11
+ let intermediate;
12
+ if (adhese && elementRef.current) {
13
+ intermediate = adhese.addSlot(
14
+ {
15
+ ...options,
16
+ containingElement: elementRef.current
17
+ }
18
+ );
19
+ setSlot(intermediate);
20
+ }
21
+ return () => {
22
+ intermediate == null ? void 0 : intermediate.dispose();
23
+ };
24
+ }, [adhese, sdkShared.omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
25
+ return slot;
26
+ }
27
+ exports.useAdheseSlot = useAdheseSlot;
28
+ //# sourceMappingURL=useAdheseSlot.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,10 @@
1
+ import { AdheseProvider, useAdhese } from "./adheseContext.js";
2
+ import { useAdheseSlot } from "./useAdheseSlot.js";
3
+ import { AdheseSlot } from "./AdheseSlot.js";
4
+ export {
5
+ AdheseProvider,
6
+ AdheseSlot,
7
+ useAdhese,
8
+ useAdheseSlot
9
+ };
10
+ //# sourceMappingURL=sdkReact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdkReact.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,28 @@
1
+ import { useState } from "react";
2
+ import useDeepCompareEffect from "use-deep-compare-effect";
3
+ import { omit } from "@adhese/sdk-shared";
4
+ import { useAdhese } from "./adheseContext.js";
5
+ function useAdheseSlot(elementRef, options) {
6
+ const [slot, setSlot] = useState(null);
7
+ const adhese = useAdhese();
8
+ useDeepCompareEffect(() => {
9
+ let intermediate;
10
+ if (adhese && elementRef.current) {
11
+ intermediate = adhese.addSlot(
12
+ {
13
+ ...options,
14
+ containingElement: elementRef.current
15
+ }
16
+ );
17
+ setSlot(intermediate);
18
+ }
19
+ return () => {
20
+ intermediate == null ? void 0 : intermediate.dispose();
21
+ };
22
+ }, [adhese, omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
23
+ return slot;
24
+ }
25
+ export {
26
+ useAdheseSlot
27
+ };
28
+ //# sourceMappingURL=useAdheseSlot.js.map
@@ -0,0 +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;"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@adhese/sdk-react",
3
3
  "type": "module",
4
- "version": "0.9.11",
4
+ "version": "0.9.13",
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
- "main": "./dist/index.cjs",
11
- "module": "./dist/index.js",
12
- "types": "./dist/index.d.ts",
10
+ "main": "./dist/cjs/sdkReact.cjs",
11
+ "module": "./dist/sdkReact.js",
12
+ "types": "./dist/sdkReact.d.ts",
13
13
  "files": [
14
14
  "CHANGELOG.md",
15
15
  "LICENSE",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "scripts": {
20
- "build": "vite build && tsup src/index.ts --dts-only --minify --format esm",
20
+ "build": "vite build",
21
21
  "lint": "eslint . --ignore-pattern **/*.md/**/*",
22
22
  "lint:fix": "eslint --fix . --ignore-pattern **/*.md/**/*",
23
23
  "clean": "rm -rf dist",
@@ -25,12 +25,12 @@
25
25
  "prepareRelease": "npm run build"
26
26
  },
27
27
  "peerDependencies": {
28
- "@adhese/sdk": "^0",
28
+ "@adhese/sdk": ">= 0.16 < 1",
29
29
  "react": ">=16.13",
30
30
  "react-dom": ">=16.13"
31
31
  },
32
32
  "dependencies": {
33
- "@adhese/sdk-shared": "^0.9.0",
33
+ "@adhese/sdk-shared": "^0.10.0",
34
34
  "use-deep-compare-effect": "^1.8.1"
35
35
  },
36
36
  "devDependencies": {
@@ -1 +0,0 @@
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 '@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","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,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;ACzCgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,CAAC,MAAM,OAAO,IAAIF,eAA4B,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,QAAQG,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;ACpBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAUC,aAA8B,IAAI;AAE5C,QAAA,OAAO,cAAc,SAAS,OAAO;AAE3CH,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.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { PropsWithChildren, ReactElement, RefObject } from 'react';
2
- import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$1 } from '@adhese/sdk';
3
-
4
- /**
5
- * Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be
6
- * used in all child components.
7
- * @constructor
8
- */
9
- declare function AdheseProvider({ children, options }: PropsWithChildren<{
10
- options: AdheseOptions;
11
- }>): ReactElement;
12
- /**
13
- * Hook to get the Adhese instance from the nearest `AdheseProvider`. When the Adhese instance is not available yet, `null`
14
- */
15
- declare function useAdhese(): Adhese | undefined;
16
-
17
- /**
18
- * Hook to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be created
19
- * when the containing element is available and the Adhese instance is available.
20
- * @param elementRef The ref to the containing element
21
- * @param options The options to create the slot
22
- */
23
- declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null;
24
-
25
- type AdheseSlotProps = {
26
- /**
27
- * Callback to be called when the slot is created or disposed
28
- */
29
- onChange?(slot: AdheseSlot$1 | null): void;
30
- } & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;
31
- /**
32
- * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be
33
- * created when the containing element is available and the Adhese instance is available.
34
- */
35
- declare function AdheseSlot({ onChange, ...options }: AdheseSlotProps): ReactElement;
36
-
37
- export { AdheseProvider, AdheseSlot, useAdhese, useAdheseSlot };
package/dist/index.js DELETED
@@ -1,63 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { createContext, useState, useEffect, useContext, useRef } from "react";
3
- import useDeepCompareEffect from "use-deep-compare-effect";
4
- import { omit } from "@adhese/sdk-shared";
5
- const adheseContext = createContext(void 0);
6
- function AdheseProvider({ children, options }) {
7
- const [adhese, setAdhese] = useState(void 0);
8
- useEffect(() => {
9
- let instance;
10
- import("@adhese/sdk").then(({ createAdhese }) => {
11
- instance = createAdhese(options);
12
- setAdhese((current) => {
13
- current == null ? void 0 : current.dispose();
14
- return instance;
15
- });
16
- }).catch(console.error);
17
- return () => {
18
- instance == null ? void 0 : instance.dispose();
19
- };
20
- }, [options]);
21
- return /* @__PURE__ */ jsx(adheseContext.Provider, { value: adhese, children });
22
- }
23
- function useAdhese() {
24
- return useContext(adheseContext);
25
- }
26
- function useAdheseSlot(elementRef, options) {
27
- const [slot, setSlot] = useState(null);
28
- const adhese = useAdhese();
29
- useDeepCompareEffect(() => {
30
- let intermediate;
31
- if (adhese && elementRef.current) {
32
- intermediate = adhese.addSlot(
33
- {
34
- ...options,
35
- containingElement: elementRef.current
36
- }
37
- );
38
- setSlot(intermediate);
39
- }
40
- return () => {
41
- intermediate == null ? void 0 : intermediate.dispose();
42
- };
43
- }, [adhese, omit(options, Object.entries(options).filter(([, value]) => typeof value === "function").map(([key]) => key)), elementRef.current]);
44
- return slot;
45
- }
46
- function AdheseSlot({
47
- onChange,
48
- ...options
49
- }) {
50
- const element = useRef(null);
51
- const slot = useAdheseSlot(element, options);
52
- useEffect(() => {
53
- onChange == null ? void 0 : onChange(slot);
54
- }, [onChange, slot]);
55
- return /* @__PURE__ */ jsx("div", { ref: element });
56
- }
57
- export {
58
- AdheseProvider,
59
- AdheseSlot,
60
- useAdhese,
61
- useAdheseSlot
62
- };
63
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
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 '@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","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;"}