@adhese/sdk-react 1.1.2 → 1.1.3-nightly-20240617192245
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 +6 -0
- package/dist/{AdheseSlot/AdheseSlot.js → AdheseSlot.js} +1 -1
- package/dist/AdheseSlot.js.map +1 -0
- package/dist/adheseContext.js +5 -6
- package/dist/adheseContext.js.map +1 -1
- package/dist/cjs/{AdheseSlot/AdheseSlot.cjs → AdheseSlot.cjs} +1 -1
- package/dist/cjs/AdheseSlot.cjs.map +1 -0
- package/dist/cjs/adheseContext.cjs +6 -29
- package/dist/cjs/adheseContext.cjs.map +1 -1
- package/dist/cjs/sdkReact.cjs +2 -2
- package/dist/cjs/useAdheseSlot.cjs +14 -37
- package/dist/cjs/useAdheseSlot.cjs.map +1 -1
- package/dist/sdkReact.d.ts +4 -7
- package/dist/sdkReact.js +1 -1
- package/dist/useAdheseSlot.js +14 -15
- package/dist/useAdheseSlot.js.map +1 -1
- package/package.json +1 -1
- package/dist/AdheseSlot/AdheseSlot.js.map +0 -1
- package/dist/AdheseSlot/AdheseSlot.lazy.js +0 -6
- package/dist/AdheseSlot/AdheseSlot.lazy.js.map +0 -1
- package/dist/cjs/AdheseSlot/AdheseSlot.cjs.map +0 -1
- package/dist/cjs/AdheseSlot/AdheseSlot.lazy.cjs +0 -6
- package/dist/cjs/AdheseSlot/AdheseSlot.lazy.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -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 "
|
|
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.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;"}
|
package/dist/adheseContext.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useState, useEffect, useContext } from "react";
|
|
3
|
+
import { createAdhese } from "@adhese/sdk";
|
|
3
4
|
const adheseContext = createContext(void 0);
|
|
4
5
|
function AdheseProvider({ children, options }) {
|
|
5
6
|
const [adhese, setAdhese] = useState(void 0);
|
|
@@ -7,13 +8,11 @@ function AdheseProvider({ children, options }) {
|
|
|
7
8
|
let instance;
|
|
8
9
|
if (!options)
|
|
9
10
|
return;
|
|
10
|
-
|
|
11
|
+
setAdhese((current) => {
|
|
11
12
|
instance = createAdhese(options);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
}).catch(console.error);
|
|
13
|
+
current == null ? void 0 : current.dispose();
|
|
14
|
+
return instance;
|
|
15
|
+
});
|
|
17
16
|
return () => {
|
|
18
17
|
instance == null ? void 0 : instance.dispose();
|
|
19
18
|
};
|
|
@@ -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
|
|
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, type AdheseOptions, createAdhese } 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 setAdhese((current) => {\n instance = createAdhese(options);\n current?.dispose();\n\n return instance;\n });\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,cAAU,CAAC,YAAY;AACrB,iBAAW,aAAa,OAAO;AAC/B,yCAAS;AAEF,aAAA;AAAA,IAAA,CACR;AAED,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("
|
|
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.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,29 +1,8 @@
|
|
|
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
|
-
));
|
|
24
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
26
4
|
const react = require("react");
|
|
5
|
+
const sdk = require("@adhese/sdk");
|
|
27
6
|
const adheseContext = react.createContext(void 0);
|
|
28
7
|
function AdheseProvider({ children, options }) {
|
|
29
8
|
const [adhese, setAdhese] = react.useState(void 0);
|
|
@@ -31,13 +10,11 @@ function AdheseProvider({ children, options }) {
|
|
|
31
10
|
let instance;
|
|
32
11
|
if (!options)
|
|
33
12
|
return;
|
|
34
|
-
|
|
35
|
-
instance = createAdhese(options);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
}).catch(console.error);
|
|
13
|
+
setAdhese((current) => {
|
|
14
|
+
instance = sdk.createAdhese(options);
|
|
15
|
+
current == null ? void 0 : current.dispose();
|
|
16
|
+
return instance;
|
|
17
|
+
});
|
|
41
18
|
return () => {
|
|
42
19
|
instance == null ? void 0 : instance.dispose();
|
|
43
20
|
};
|
|
@@ -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
|
|
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, type AdheseOptions, createAdhese } 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 setAdhese((current) => {\n instance = createAdhese(options);\n current?.dispose();\n\n return instance;\n });\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","createAdhese","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,cAAU,CAAC,YAAY;AACrB,iBAAWC,IAAAA,aAAa,OAAO;AAC/B,yCAAS;AAEF,aAAA;AAAA,IAAA,CACR;AAED,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;;;"}
|
package/dist/cjs/sdkReact.cjs
CHANGED
|
@@ -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
|
|
5
|
+
const AdheseSlot = require("./AdheseSlot.cjs");
|
|
6
6
|
exports.AdheseProvider = adheseContext.AdheseProvider;
|
|
7
7
|
exports.useAdhese = adheseContext.useAdhese;
|
|
8
8
|
exports.useAdheseSlot = useAdheseSlot.useAdheseSlot;
|
|
9
|
-
exports.AdheseSlot =
|
|
9
|
+
exports.AdheseSlot = AdheseSlot.AdheseSlot;
|
|
10
10
|
//# sourceMappingURL=sdkReact.cjs.map
|
|
@@ -1,49 +1,26 @@
|
|
|
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
|
-
));
|
|
24
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
3
|
const react = require("react");
|
|
4
|
+
const sdkShared = require("@adhese/sdk-shared");
|
|
26
5
|
const adheseContext = require("./adheseContext.cjs");
|
|
27
6
|
function useAdheseSlot(elementRef, options) {
|
|
28
7
|
const adhese = adheseContext.useAdhese();
|
|
29
8
|
const [slot, setSlot] = react.useState(null);
|
|
30
9
|
react.useEffect(() => {
|
|
31
10
|
let intermediate = null;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
}).catch(console.error);
|
|
11
|
+
if (adhese && elementRef.current) {
|
|
12
|
+
intermediate = 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
|
+
}
|
|
47
24
|
return () => {
|
|
48
25
|
intermediate == null ? void 0 : intermediate.dispose();
|
|
49
26
|
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 { 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
|
|
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 { 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 = 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","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;AAChC,qBAAe,iCAAQ,QAAQ;AAAA,QAC7B,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,MAAA;AAAA,IAEJ;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/dist/sdkReact.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
1
|
import { PropsWithChildren, ReactElement, RefObject } from 'react';
|
|
3
|
-
import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$
|
|
2
|
+
import { AdheseOptions, Adhese, AdheseSlotOptions, AdheseSlot as AdheseSlot$1 } from '@adhese/sdk';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Provider to create an Adhese instance with the given options. Via the `useAdhese` hook, the Adhese instance can be
|
|
@@ -24,13 +23,13 @@ declare function useAdhese(): Adhese | undefined;
|
|
|
24
23
|
* @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
|
|
25
24
|
* memoized.
|
|
26
25
|
*/
|
|
27
|
-
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$
|
|
26
|
+
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null;
|
|
28
27
|
|
|
29
28
|
type AdheseSlotProps = {
|
|
30
29
|
/**
|
|
31
30
|
* Callback to be called when the slot is created or disposed
|
|
32
31
|
*/
|
|
33
|
-
onChange?(slot: AdheseSlot$
|
|
32
|
+
onChange?(slot: AdheseSlot$1 | null): void;
|
|
34
33
|
} & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;
|
|
35
34
|
/**
|
|
36
35
|
* Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be
|
|
@@ -39,8 +38,6 @@ type AdheseSlotProps = {
|
|
|
39
38
|
* @warning Make sure to wrap your `setup` function in a `useCallback` as it can trigger an infinite loop if it's not
|
|
40
39
|
* memoized.
|
|
41
40
|
*/
|
|
42
|
-
declare function AdheseSlot
|
|
43
|
-
|
|
44
|
-
declare const AdheseSlot: react.LazyExoticComponent<typeof AdheseSlot$1>;
|
|
41
|
+
declare function AdheseSlot({ onChange, ...options }: AdheseSlotProps): ReactElement;
|
|
45
42
|
|
|
46
43
|
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
|
|
3
|
+
import { AdheseSlot } from "./AdheseSlot.js";
|
|
4
4
|
export {
|
|
5
5
|
AdheseProvider,
|
|
6
6
|
AdheseSlot,
|
package/dist/useAdheseSlot.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
|
+
import { watch } from "@adhese/sdk-shared";
|
|
2
3
|
import { useAdhese } from "./adheseContext.js";
|
|
3
4
|
function useAdheseSlot(elementRef, options) {
|
|
4
5
|
const adhese = useAdhese();
|
|
5
6
|
const [slot, setSlot] = useState(null);
|
|
6
7
|
useEffect(() => {
|
|
7
8
|
let intermediate = null;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}).catch(console.error);
|
|
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
|
+
}
|
|
23
22
|
return () => {
|
|
24
23
|
intermediate == null ? void 0 : intermediate.dispose();
|
|
25
24
|
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 { 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
|
|
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 { 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 = 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;AAChC,qBAAe,iCAAQ,QAAQ;AAAA,QAC7B,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,MAAA;AAAA,IAEJ;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 +0,0 @@
|
|
|
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;"}
|
|
@@ -1 +0,0 @@
|
|
|
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;"}
|
|
@@ -1 +0,0 @@
|
|
|
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;;"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;;"}
|