@adhese/sdk-react 1.4.0 → 1.4.1-nightly-20241119103417
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,16 @@
|
|
|
1
1
|
# @adhese/sdk-react
|
|
2
2
|
|
|
3
|
+
## 1.4.1-nightly-20241119103417
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f7ea508: Optimise React rendering by using `useLayoutEffect` to prevent layout jumping during slot creation
|
|
8
|
+
- Updated dependencies [718bbab]
|
|
9
|
+
- Updated dependencies [718bbab]
|
|
10
|
+
- Updated dependencies [718bbab]
|
|
11
|
+
- @adhese/sdk@1.4.1-nightly-20241119103417
|
|
12
|
+
- @adhese/sdk-shared@1.3.1-nightly-20241119103417
|
|
13
|
+
|
|
3
14
|
## 1.4.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -12,7 +12,7 @@ function useAdheseSlot(elementRef, options) {
|
|
|
12
12
|
slot: options.slot
|
|
13
13
|
}), [adhese == null ? void 0 : adhese.location, options.format, options.slot]);
|
|
14
14
|
const [slot, setSlot] = react.useState(null);
|
|
15
|
-
react.
|
|
15
|
+
react.useLayoutEffect(() => {
|
|
16
16
|
const element = typeof elementRef === "string" ? elementRef : elementRef.current;
|
|
17
17
|
if (adhese && element) {
|
|
18
18
|
setSlot(adhese == null ? void 0 : adhese.addSlot({
|
|
@@ -28,7 +28,7 @@ function useAdheseSlot(elementRef, options) {
|
|
|
28
28
|
}
|
|
29
29
|
function useWatch(value, options) {
|
|
30
30
|
const [state, setState] = react.useState(typeof value === "function" ? value() : value);
|
|
31
|
-
react.
|
|
31
|
+
react.useLayoutEffect(() => {
|
|
32
32
|
let handle;
|
|
33
33
|
if (value) {
|
|
34
34
|
handle = sdkShared.watch(value, (newValue) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { generateSlotSignature, watch, type WatchHandle, type WatchOptions } from '@adhese/sdk-shared';\nimport {\n type RefObject,\n
|
|
1
|
+
{"version":3,"file":"useAdheseSlot.cjs","sources":["../../src/useAdheseSlot.ts"],"sourcesContent":["import type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { generateSlotSignature, watch, type WatchHandle, type WatchOptions } from '@adhese/sdk-shared';\nimport {\n type RefObject,\n useLayoutEffect,\n useMemo,\n useState,\n} from 'react';\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> | string, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const adhese = useAdhese();\n\n const slotSignature = useMemo(() => (adhese?.location) && generateSlotSignature({\n location: adhese.location,\n format: options.format,\n parameters: options.parameters,\n slot: options.slot,\n }), [adhese?.location, options.format, options.slot]);\n\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n\n useLayoutEffect(() => {\n const element = typeof elementRef === 'string' ? elementRef : elementRef.current;\n\n if (adhese && element) {\n setSlot(adhese?.addSlot({\n ...options,\n containingElement: element,\n }));\n }\n\n return (): void => {\n setSlot(null);\n };\n }, [adhese, ...Object.values(options), slotSignature]);\n\n return slot;\n}\n\n/**\n * Hook that will observe a value on a reactive object and convert to React state\n */\nexport function useWatch<\n Input,\n Output = Input extends () => unknown ? ReturnType<Input> | undefined : Input | undefined,\n>(value?: Input, options?: Omit<WatchOptions, 'immediate'>): Output {\n const [state, setState] = useState<Output>(typeof value === 'function' ? value() : value);\n\n useLayoutEffect(() => {\n let handle: WatchHandle | undefined;\n\n if (value) {\n handle = watch(value, (newValue) => {\n setState(newValue as Output);\n }, { immediate: true, ...options });\n }\n\n return (): void => {\n handle?.stop();\n };\n }, [value]);\n\n return state;\n}\n"],"names":["useAdhese","useMemo","generateSlotSignature","useState","useLayoutEffect","watch"],"mappings":";;;;;AAmBgB,SAAA,cAAc,YAA6C,SAAsF;AAC/J,QAAM,SAASA,cAAAA;AAEf,QAAM,gBAAgBC,MAAA,QAAQ,OAAO,iCAAQ,aAAaC,UAAAA,sBAAsB;AAAA,IAC9E,UAAU,OAAO;AAAA,IACjB,QAAQ,QAAQ;AAAA,IAChB,YAAY,QAAQ;AAAA,IACpB,MAAM,QAAQ;AAAA,EAAA,CACf,GAAG,CAAC,iCAAQ,UAAU,QAAQ,QAAQ,QAAQ,IAAI,CAAC;AAEpD,QAAM,CAAC,MAAM,OAAO,IAAIC,eAA4B,IAAI;AAExDC,QAAAA,gBAAgB,MAAM;AACpB,UAAM,UAAU,OAAO,eAAe,WAAW,aAAa,WAAW;AAEzE,QAAI,UAAU,SAAS;AACrB,cAAQ,iCAAQ,QAAQ;AAAA,QACtB,GAAG;AAAA,QACH,mBAAmB;AAAA,MACpB,EAAC;AAAA,IACJ;AAEA,WAAO,MAAY;AACjB,cAAQ,IAAI;AAAA,IAAA;AAAA,EACd,GACC,CAAC,QAAQ,GAAG,OAAO,OAAO,OAAO,GAAG,aAAa,CAAC;AAE9C,SAAA;AACT;AAKgB,SAAA,SAGd,OAAe,SAAmD;AAC5D,QAAA,CAAC,OAAO,QAAQ,IAAID,MAAA,SAAiB,OAAO,UAAU,aAAa,UAAU,KAAK;AAExFC,QAAAA,gBAAgB,MAAM;AAChB,QAAA;AAEJ,QAAI,OAAO;AACA,eAAAC,UAAA,MAAM,OAAO,CAAC,aAAa;AAClC,iBAAS,QAAkB;AAAA,SAC1B,EAAE,WAAW,MAAM,GAAG,QAAS,CAAA;AAAA,IACpC;AAEA,WAAO,MAAY;AACjB,uCAAQ;AAAA,IAAK;AAAA,EACf,GACC,CAAC,KAAK,CAAC;AAEH,SAAA;AACT;;;"}
|
package/dist/useAdheseSlot.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { generateSlotSignature, watch } from "@adhese/sdk-shared";
|
|
2
|
-
import { useMemo, useState,
|
|
2
|
+
import { useMemo, useState, useLayoutEffect } from "react";
|
|
3
3
|
import { useAdhese } from "./adheseContext.js";
|
|
4
4
|
function useAdheseSlot(elementRef, options) {
|
|
5
5
|
const adhese = useAdhese();
|
|
@@ -10,7 +10,7 @@ function useAdheseSlot(elementRef, options) {
|
|
|
10
10
|
slot: options.slot
|
|
11
11
|
}), [adhese == null ? void 0 : adhese.location, options.format, options.slot]);
|
|
12
12
|
const [slot, setSlot] = useState(null);
|
|
13
|
-
|
|
13
|
+
useLayoutEffect(() => {
|
|
14
14
|
const element = typeof elementRef === "string" ? elementRef : elementRef.current;
|
|
15
15
|
if (adhese && element) {
|
|
16
16
|
setSlot(adhese == null ? void 0 : adhese.addSlot({
|
|
@@ -26,7 +26,7 @@ function useAdheseSlot(elementRef, options) {
|
|
|
26
26
|
}
|
|
27
27
|
function useWatch(value, options) {
|
|
28
28
|
const [state, setState] = useState(typeof value === "function" ? value() : value);
|
|
29
|
-
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
30
|
let handle;
|
|
31
31
|
if (value) {
|
|
32
32
|
handle = watch(value, (newValue) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { generateSlotSignature, watch, type WatchHandle, type WatchOptions } from '@adhese/sdk-shared';\nimport {\n type RefObject,\n
|
|
1
|
+
{"version":3,"file":"useAdheseSlot.js","sources":["../src/useAdheseSlot.ts"],"sourcesContent":["import type { AdheseSlot, AdheseSlotOptions } from '@adhese/sdk';\nimport { generateSlotSignature, watch, type WatchHandle, type WatchOptions } from '@adhese/sdk-shared';\nimport {\n type RefObject,\n useLayoutEffect,\n useMemo,\n useState,\n} from 'react';\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> | string, options: Omit<AdheseSlotOptions, 'containingElement' | 'context'>): AdheseSlot | null {\n const adhese = useAdhese();\n\n const slotSignature = useMemo(() => (adhese?.location) && generateSlotSignature({\n location: adhese.location,\n format: options.format,\n parameters: options.parameters,\n slot: options.slot,\n }), [adhese?.location, options.format, options.slot]);\n\n const [slot, setSlot] = useState<AdheseSlot | null>(null);\n\n useLayoutEffect(() => {\n const element = typeof elementRef === 'string' ? elementRef : elementRef.current;\n\n if (adhese && element) {\n setSlot(adhese?.addSlot({\n ...options,\n containingElement: element,\n }));\n }\n\n return (): void => {\n setSlot(null);\n };\n }, [adhese, ...Object.values(options), slotSignature]);\n\n return slot;\n}\n\n/**\n * Hook that will observe a value on a reactive object and convert to React state\n */\nexport function useWatch<\n Input,\n Output = Input extends () => unknown ? ReturnType<Input> | undefined : Input | undefined,\n>(value?: Input, options?: Omit<WatchOptions, 'immediate'>): Output {\n const [state, setState] = useState<Output>(typeof value === 'function' ? value() : value);\n\n useLayoutEffect(() => {\n let handle: WatchHandle | undefined;\n\n if (value) {\n handle = watch(value, (newValue) => {\n setState(newValue as Output);\n }, { immediate: true, ...options });\n }\n\n return (): void => {\n handle?.stop();\n };\n }, [value]);\n\n return state;\n}\n"],"names":[],"mappings":";;;AAmBgB,SAAA,cAAc,YAA6C,SAAsF;AAC/J,QAAM,SAAS;AAEf,QAAM,gBAAgB,QAAQ,OAAO,iCAAQ,aAAa,sBAAsB;AAAA,IAC9E,UAAU,OAAO;AAAA,IACjB,QAAQ,QAAQ;AAAA,IAChB,YAAY,QAAQ;AAAA,IACpB,MAAM,QAAQ;AAAA,EAAA,CACf,GAAG,CAAC,iCAAQ,UAAU,QAAQ,QAAQ,QAAQ,IAAI,CAAC;AAEpD,QAAM,CAAC,MAAM,OAAO,IAAI,SAA4B,IAAI;AAExD,kBAAgB,MAAM;AACpB,UAAM,UAAU,OAAO,eAAe,WAAW,aAAa,WAAW;AAEzE,QAAI,UAAU,SAAS;AACrB,cAAQ,iCAAQ,QAAQ;AAAA,QACtB,GAAG;AAAA,QACH,mBAAmB;AAAA,MACpB,EAAC;AAAA,IACJ;AAEA,WAAO,MAAY;AACjB,cAAQ,IAAI;AAAA,IAAA;AAAA,EACd,GACC,CAAC,QAAQ,GAAG,OAAO,OAAO,OAAO,GAAG,aAAa,CAAC;AAE9C,SAAA;AACT;AAKgB,SAAA,SAGd,OAAe,SAAmD;AAC5D,QAAA,CAAC,OAAO,QAAQ,IAAI,SAAiB,OAAO,UAAU,aAAa,UAAU,KAAK;AAExF,kBAAgB,MAAM;AAChB,QAAA;AAEJ,QAAI,OAAO;AACA,eAAA,MAAM,OAAO,CAAC,aAAa;AAClC,iBAAS,QAAkB;AAAA,SAC1B,EAAE,WAAW,MAAM,GAAG,QAAS,CAAA;AAAA,IACpC;AAEA,WAAO,MAAY;AACjB,uCAAQ;AAAA,IAAK;AAAA,EACf,GACC,CAAC,KAAK,CAAC;AAEH,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.4.
|
|
4
|
+
"version": "1.4.1-nightly-20241119103417",
|
|
5
5
|
"description": "Adhese SDK",
|
|
6
6
|
"license": "GPL-3.0",
|
|
7
7
|
"repository": {
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"react-dom": ">=16.13"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@adhese/sdk": "1.4.
|
|
55
|
-
"@adhese/sdk-shared": "1.3.
|
|
54
|
+
"@adhese/sdk": "1.4.1-nightly-20241119103417",
|
|
55
|
+
"@adhese/sdk-shared": "1.3.1-nightly-20241119103417"
|
|
56
56
|
}
|
|
57
57
|
}
|