@adhese/sdk-react 1.0.0 → 1.0.2
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 +13 -0
- package/dist/AdheseSlot.js +12 -5
- package/dist/AdheseSlot.js.map +1 -1
- package/dist/cjs/AdheseSlot.cjs +11 -4
- package/dist/cjs/AdheseSlot.cjs.map +1 -1
- package/dist/cjs/useAdheseSlot.cjs +11 -16
- package/dist/cjs/useAdheseSlot.cjs.map +1 -1
- package/dist/legacy.d.ts +13 -0
- package/dist/sdkReact.d.ts +1 -1
- package/dist/useAdheseSlot.js +12 -17
- package/dist/useAdheseSlot.js.map +1 -1
- package/package.json +20 -9
- package/src/legacy.d.ts +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @adhese/sdk-react
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e59b2d5: Replace use-deep-compare-effect in useAdheseSlot with useEffect and useRef
|
|
8
|
+
|
|
9
|
+
## 1.0.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5393373: Add fallback legacy d.ts file for older ts version with very limited types
|
|
14
|
+
- 5393373: Mode @adhese/sdk as a dependency instead of peer dependency
|
|
15
|
+
|
|
3
16
|
## 1.0.0
|
|
4
17
|
|
|
5
18
|
### Major Changes
|
package/dist/AdheseSlot.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useRef
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { watch } from "@adhese/sdk-shared";
|
|
3
4
|
import { useAdheseSlot } from "./useAdheseSlot.js";
|
|
4
5
|
function AdheseSlot({
|
|
5
6
|
onChange,
|
|
6
7
|
...options
|
|
7
8
|
}) {
|
|
8
9
|
const element = useRef(null);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
useAdheseSlot(element, {
|
|
11
|
+
...options,
|
|
12
|
+
setup(context, hooks) {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
|
|
15
|
+
watch(context, (newSlot) => {
|
|
16
|
+
onChange == null ? void 0 : onChange(newSlot);
|
|
17
|
+
}, { immediate: true, deep: true });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
13
20
|
return /* @__PURE__ */ jsx("div", { ref: element });
|
|
14
21
|
}
|
|
15
22
|
export {
|
package/dist/AdheseSlot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdheseSlot.js","sources":["../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement,
|
|
1
|
+
{"version":3,"file":"AdheseSlot.js","sources":["../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement, useRef } from 'react';\nimport type { AdheseSlotContext, AdheseSlotHooks, AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { type Ref, watch } from '@adhese/sdk-shared';\nimport { useAdheseSlot } from './useAdheseSlot';\n\nexport type AdheseSlotProps = {\n /**\n * Callback to be called when the slot is created or disposed\n */\n onChange?(slot: Slot | null): void;\n} & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;\n\n/**\n * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be\n * created when the containing element is available and the Adhese instance is available.\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseSlot({\n onChange,\n ...options\n}: AdheseSlotProps): ReactElement {\n const element = useRef<HTMLDivElement | null>(null);\n\n useAdheseSlot(element, {\n ...options,\n setup(context: Ref<AdheseSlotContext | null>, hooks: AdheseSlotHooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n },\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":[],"mappings":";;;;AAiBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAU,OAA8B,IAAI;AAElD,gBAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,SAAwC,OAAwB;;AAC5D,oBAAA,UAAA,iCAAQ,SAAS;AAEnB,YAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACpC;AAAA,EAAA,CACD;AAGC,SAAA,oBAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;"}
|
package/dist/cjs/AdheseSlot.cjs
CHANGED
|
@@ -2,16 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const react = require("react");
|
|
5
|
+
const sdkShared = require("@adhese/sdk-shared");
|
|
5
6
|
const useAdheseSlot = require("./useAdheseSlot.cjs");
|
|
6
7
|
function AdheseSlot({
|
|
7
8
|
onChange,
|
|
8
9
|
...options
|
|
9
10
|
}) {
|
|
10
11
|
const element = react.useRef(null);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
useAdheseSlot.useAdheseSlot(element, {
|
|
13
|
+
...options,
|
|
14
|
+
setup(context, hooks) {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = options.setup) == null ? void 0 : _a.call(options, context, hooks);
|
|
17
|
+
sdkShared.watch(context, (newSlot) => {
|
|
18
|
+
onChange == null ? void 0 : onChange(newSlot);
|
|
19
|
+
}, { immediate: true, deep: true });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
15
22
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: element });
|
|
16
23
|
}
|
|
17
24
|
exports.AdheseSlot = AdheseSlot;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdheseSlot.cjs","sources":["../../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement,
|
|
1
|
+
{"version":3,"file":"AdheseSlot.cjs","sources":["../../src/AdheseSlot.tsx"],"sourcesContent":["import { type ReactElement, useRef } from 'react';\nimport type { AdheseSlotContext, AdheseSlotHooks, AdheseSlotOptions, AdheseSlot as Slot } from '@adhese/sdk';\nimport { type Ref, watch } from '@adhese/sdk-shared';\nimport { useAdheseSlot } from './useAdheseSlot';\n\nexport type AdheseSlotProps = {\n /**\n * Callback to be called when the slot is created or disposed\n */\n onChange?(slot: Slot | null): void;\n} & Omit<AdheseSlotOptions, 'containingElement' | 'context'>;\n\n/**\n * Component to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be\n * created when the containing element is available and the Adhese instance is available.\n */\n// eslint-disable-next-line ts/naming-convention\nexport function AdheseSlot({\n onChange,\n ...options\n}: AdheseSlotProps): ReactElement {\n const element = useRef<HTMLDivElement | null>(null);\n\n useAdheseSlot(element, {\n ...options,\n setup(context: Ref<AdheseSlotContext | null>, hooks: AdheseSlotHooks) {\n options.setup?.(context, hooks);\n\n watch(context, (newSlot) => {\n onChange?.(newSlot);\n }, { immediate: true, deep: true });\n },\n });\n\n return (\n <div ref={element} />\n );\n}\n"],"names":["useRef","useAdheseSlot","watch","jsx"],"mappings":";;;;;;AAiBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA,GAAG;AACL,GAAkC;AAC1B,QAAA,UAAUA,aAA8B,IAAI;AAElDC,gBAAAA,cAAc,SAAS;AAAA,IACrB,GAAG;AAAA,IACH,MAAM,SAAwC,OAAwB;;AAC5D,oBAAA,UAAA,iCAAQ,SAAS;AAEnBC,sBAAA,SAAS,CAAC,YAAY;AAC1B,6CAAW;AAAA,SACV,EAAE,WAAW,MAAM,MAAM,KAAM,CAAA;AAAA,IACpC;AAAA,EAAA,CACD;AAGC,SAAAC,2BAAA,IAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;;"}
|
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const react = require("react");
|
|
4
|
-
const useDeepCompareEffect = require("use-deep-compare-effect");
|
|
5
|
-
const sdkShared = require("@adhese/sdk-shared");
|
|
6
4
|
const adheseContext = require("./adheseContext.cjs");
|
|
7
5
|
function useAdheseSlot(elementRef, options) {
|
|
8
|
-
const
|
|
6
|
+
const slot = react.useRef(null);
|
|
9
7
|
const adhese = adheseContext.useAdhese();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
);
|
|
19
|
-
setSlot(intermediate);
|
|
20
|
-
}
|
|
8
|
+
react.useEffect(() => {
|
|
9
|
+
if (!adhese || !elementRef.current)
|
|
10
|
+
return;
|
|
11
|
+
slot.current = adhese == null ? void 0 : adhese.addSlot({
|
|
12
|
+
...options,
|
|
13
|
+
containingElement: elementRef.current
|
|
14
|
+
});
|
|
21
15
|
return () => {
|
|
22
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = slot.current) == null ? void 0 : _a.dispose();
|
|
23
18
|
};
|
|
24
|
-
}, [adhese
|
|
19
|
+
}, [adhese == null ? void 0 : adhese.addSlot, options, elementRef.current]);
|
|
25
20
|
return slot;
|
|
26
21
|
}
|
|
27
22
|
exports.useAdheseSlot = useAdheseSlot;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject,
|
|
1
|
+
{"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { useAdhese } from './adheseContext';\n\n/**\n * Hook to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be created\n * when the containing element is available and the Adhese instance is available.\n * @param elementRef The ref to the containing element\n * @param options The options to create the slot\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): RefObject<AdheseSlot | null> {\n const slot = useRef<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useEffect(() => {\n if (!adhese || !elementRef.current)\n return;\n\n slot.current = adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n });\n return (): void => {\n slot.current?.dispose();\n };\n }, [adhese?.addSlot, options, elementRef.current]);\n\n return slot;\n}\n"],"names":["useRef","useAdhese","useEffect"],"mappings":";;;;AAUgB,SAAA,cAAc,YAAoC,SAAiG;AAC3J,QAAA,OAAOA,aAA0B,IAAI;AAC3C,QAAM,SAASC,cAAAA;AAEfC,QAAAA,UAAU,MAAM;AACV,QAAA,CAAC,UAAU,CAAC,WAAW;AACzB;AAEG,SAAA,UAAU,iCAAQ,QAAQ;AAAA,MAC7B,GAAG;AAAA,MACH,mBAAmB,WAAW;AAAA,IAAA;AAEhC,WAAO,MAAY;;AACjB,iBAAK,YAAL,mBAAc;AAAA,IAAQ;AAAA,EACxB,GACC,CAAC,iCAAQ,SAAS,SAAS,WAAW,OAAO,CAAC;AAE1C,SAAA;AACT;;"}
|
package/dist/legacy.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PropsWithChildren, ReactElement, RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function AdheseProvider({ children, options }: PropsWithChildren<{
|
|
4
|
+
options: any;
|
|
5
|
+
}>): ReactElement;
|
|
6
|
+
|
|
7
|
+
declare function useAdhese(): any | undefined;
|
|
8
|
+
|
|
9
|
+
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: any): any;
|
|
10
|
+
|
|
11
|
+
declare function AdheseSlot({ onChange, ...options }: {
|
|
12
|
+
onChange?(slot: any | null): void;
|
|
13
|
+
} & any): ReactElement;
|
package/dist/sdkReact.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare function useAdhese(): Adhese | undefined;
|
|
|
20
20
|
* @param elementRef The ref to the containing element
|
|
21
21
|
* @param options The options to create the slot
|
|
22
22
|
*/
|
|
23
|
-
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot$1 | null
|
|
23
|
+
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): RefObject<AdheseSlot$1 | null>;
|
|
24
24
|
|
|
25
25
|
type AdheseSlotProps = {
|
|
26
26
|
/**
|
package/dist/useAdheseSlot.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import useDeepCompareEffect from "use-deep-compare-effect";
|
|
3
|
-
import { omit } from "@adhese/sdk-shared";
|
|
1
|
+
import { useRef, useEffect } from "react";
|
|
4
2
|
import { useAdhese } from "./adheseContext.js";
|
|
5
3
|
function useAdheseSlot(elementRef, options) {
|
|
6
|
-
const
|
|
4
|
+
const slot = useRef(null);
|
|
7
5
|
const adhese = useAdhese();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
);
|
|
17
|
-
setSlot(intermediate);
|
|
18
|
-
}
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!adhese || !elementRef.current)
|
|
8
|
+
return;
|
|
9
|
+
slot.current = adhese == null ? void 0 : adhese.addSlot({
|
|
10
|
+
...options,
|
|
11
|
+
containingElement: elementRef.current
|
|
12
|
+
});
|
|
19
13
|
return () => {
|
|
20
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = slot.current) == null ? void 0 : _a.dispose();
|
|
21
16
|
};
|
|
22
|
-
}, [adhese
|
|
17
|
+
}, [adhese == null ? void 0 : adhese.addSlot, options, elementRef.current]);
|
|
23
18
|
return slot;
|
|
24
19
|
}
|
|
25
20
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject,
|
|
1
|
+
{"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef } from 'react';\nimport type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { useAdhese } from './adheseContext';\n\n/**\n * Hook to create an Adhese slot. The slot will be disposed when the component is unmounted. The slot will be created\n * when the containing element is available and the Adhese instance is available.\n * @param elementRef The ref to the containing element\n * @param options The options to create the slot\n */\nexport function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): RefObject<AdheseSlot | null> {\n const slot = useRef<AdheseSlot | null>(null);\n const adhese = useAdhese();\n\n useEffect(() => {\n if (!adhese || !elementRef.current)\n return;\n\n slot.current = adhese?.addSlot({\n ...options,\n containingElement: elementRef.current,\n });\n return (): void => {\n slot.current?.dispose();\n };\n }, [adhese?.addSlot, options, elementRef.current]);\n\n return slot;\n}\n"],"names":[],"mappings":";;AAUgB,SAAA,cAAc,YAAoC,SAAiG;AAC3J,QAAA,OAAO,OAA0B,IAAI;AAC3C,QAAM,SAAS;AAEf,YAAU,MAAM;AACV,QAAA,CAAC,UAAU,CAAC,WAAW;AACzB;AAEG,SAAA,UAAU,iCAAQ,QAAQ;AAAA,MAC7B,GAAG;AAAA,MACH,mBAAmB,WAAW;AAAA,IAAA;AAEhC,WAAO,MAAY;;AACjB,iBAAK,YAAL,mBAAc;AAAA,IAAQ;AAAA,EACxB,GACC,CAAC,iCAAQ,SAAS,SAAS,WAAW,OAAO,CAAC;AAE1C,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adhese/sdk-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Adhese SDK",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/adhese/sdk_typescript.git"
|
|
9
9
|
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/sdkReact.d.ts",
|
|
13
|
+
"import": "./dist/sdkReact.js",
|
|
14
|
+
"require": "./dist/cjs/sdkReact.cjs",
|
|
15
|
+
"types@<5.1": "./dist/legacy.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
10
18
|
"main": "./dist/cjs/sdkReact.cjs",
|
|
11
19
|
"module": "./dist/sdkReact.js",
|
|
12
20
|
"types": "./dist/sdkReact.d.ts",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
"<5.1": {
|
|
23
|
+
"*": [
|
|
24
|
+
"./dist/legacy.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
13
28
|
"files": [
|
|
14
29
|
"CHANGELOG.md",
|
|
15
30
|
"LICENSE",
|
|
16
31
|
"README.md",
|
|
17
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"src/legacy.d.ts"
|
|
18
34
|
],
|
|
19
35
|
"scripts": {
|
|
20
36
|
"build": "vite build",
|
|
@@ -25,16 +41,11 @@
|
|
|
25
41
|
"prepareRelease": "npm run build"
|
|
26
42
|
},
|
|
27
43
|
"peerDependencies": {
|
|
28
|
-
"@adhese/sdk": ">=1.0.0",
|
|
29
44
|
"react": ">=16.13",
|
|
30
45
|
"react-dom": ">=16.13"
|
|
31
46
|
},
|
|
32
47
|
"dependencies": {
|
|
33
|
-
"@adhese/sdk
|
|
34
|
-
"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"react": "^18.3.1",
|
|
38
|
-
"react-dom": "^18.3.1"
|
|
48
|
+
"@adhese/sdk": "^1.0.2",
|
|
49
|
+
"@adhese/sdk-shared": "^1.0.0"
|
|
39
50
|
}
|
|
40
51
|
}
|
package/src/legacy.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PropsWithChildren, ReactElement, RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function AdheseProvider({ children, options }: PropsWithChildren<{
|
|
4
|
+
options: any;
|
|
5
|
+
}>): ReactElement;
|
|
6
|
+
|
|
7
|
+
declare function useAdhese(): any | undefined;
|
|
8
|
+
|
|
9
|
+
declare function useAdheseSlot(elementRef: RefObject<HTMLElement>, options: any): any;
|
|
10
|
+
|
|
11
|
+
declare function AdheseSlot({ onChange, ...options }: {
|
|
12
|
+
onChange?(slot: any | null): void;
|
|
13
|
+
} & any): ReactElement;
|