@adhese/sdk-react 0.9.3 → 0.9.4

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 ADDED
@@ -0,0 +1,238 @@
1
+ # @adhese/sdk-react
2
+
3
+ ## 0.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [242cfa3]
8
+ - @adhese/sdk-shared@0.3.0
9
+
10
+ ## 0.9.3
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [44130f4]
15
+ - @adhese/sdk-shared@0.2.0
16
+
17
+ ## 0.9.2
18
+
19
+ ### Patch Changes
20
+
21
+ - dbc1db3: Fix NPM files not pointing to dist folder
22
+
23
+ ## 0.9.1
24
+
25
+ ### Patch Changes
26
+
27
+ - eebcd88: Release @adhese/sdk-shared
28
+ - Updated dependencies [eebcd88]
29
+ - @adhese/sdk-shared@0.1.0
30
+
31
+ ## 0.9.0
32
+
33
+ ### Minor Changes
34
+
35
+ - 6294fd5: Add AdheseSlot component
36
+
37
+ ## 0.8.1
38
+
39
+ ### Patch Changes
40
+
41
+ - 59f07dd: Make packages peer dependant on @adhese/sdk to allow more flexibile dependency installations
42
+
43
+ ## 0.8.0
44
+
45
+ ### Minor Changes
46
+
47
+ - 10a18fd: Make addSlot function syncronous and remove add function
48
+
49
+ ### Patch Changes
50
+
51
+ - ee019fd: Update README files to match package specific instructions
52
+ - Updated dependencies [ee019fd]
53
+ - Updated dependencies [1cc8bff]
54
+ - Updated dependencies [76566dc]
55
+ - Updated dependencies [10a18fd]
56
+ - Updated dependencies [10a18fd]
57
+ - @adhese/sdk@0.8.0
58
+
59
+ ## 0.7.0
60
+
61
+ ### Minor Changes
62
+
63
+ - 3e0b574: Create plugin system for @adhese/sdk and move @adhese/sdk-devtools to it
64
+
65
+ ### Patch Changes
66
+
67
+ - fa24130: Replace lodash with remeda to offer a more modern solution to common utilities
68
+ - Updated dependencies [c8c37d9]
69
+ - Updated dependencies [3e0b574]
70
+ - Updated dependencies [80d943b]
71
+ - Updated dependencies [fa24130]
72
+ - @adhese/sdk@0.7.0
73
+
74
+ ## 0.6.4
75
+
76
+ ### Patch Changes
77
+
78
+ - 53683c6: Filter out all external dependencies from bundle
79
+ - Updated dependencies [53683c6]
80
+ - @adhese/sdk@0.6.4
81
+
82
+ ## 0.6.3
83
+
84
+ ### Patch Changes
85
+
86
+ - 99f728f: Replace lodash-es with lodash to prevent breaking CJS builds
87
+ - a27f499: Add 'use-client' directive to adheseContext
88
+ - 85ee707: Remove dynamicImportInCjs option
89
+ - Updated dependencies [99f728f]
90
+ - Updated dependencies [85ee707]
91
+ - @adhese/sdk@0.6.3
92
+
93
+ ## 0.6.2
94
+
95
+ ### Patch Changes
96
+
97
+ - e9fb6f3: Update build outputs to allow installation in CommonJS env
98
+ - Updated dependencies [e9fb6f3]
99
+ - @adhese/sdk@0.6.2
100
+
101
+ ## 0.6.1
102
+
103
+ ### Patch Changes
104
+
105
+ - a5846f2: Move React dependencies to peerDependencies to allow wider React support
106
+ - Updated dependencies [c435430]
107
+ - @adhese/sdk@0.6.1
108
+
109
+ ## 0.6.0
110
+
111
+ ### Patch Changes
112
+
113
+ - 9c80d57: Update dependencies
114
+ - Updated dependencies [9c80d57]
115
+ - Updated dependencies [41b0dd8]
116
+ - @adhese/sdk@0.6.0
117
+
118
+ ## 0.5.2
119
+
120
+ ### Patch Changes
121
+
122
+ - f594b82: Fix issue where useAdheseSlot would land in an infinite loop without the options being wrapped in a useMemo
123
+ - @adhese/sdk@0.5.2
124
+
125
+ ## 0.5.1
126
+
127
+ ### Patch Changes
128
+
129
+ - a211689: Fix issue where the transformed ad was sent again to the onBeforeRender callback making subsequent transforms not possible
130
+ - Updated dependencies [a211689]
131
+ - Updated dependencies [7fc299d]
132
+ - @adhese/sdk@0.5.1
133
+
134
+ ## 0.5.0
135
+
136
+ ### Minor Changes
137
+
138
+ - eac9754: Add Vue based reactivity to offer more flexible control flow
139
+ - eac9754: Make createAdhese and createSlot syncronous to simplify implementation
140
+ - eac9754: Allow having more than one Adhese instance in React applications
141
+
142
+ ### Patch Changes
143
+
144
+ - Updated dependencies [a666b90]
145
+ - Updated dependencies [eac9754]
146
+ - Updated dependencies [eac9754]
147
+ - Updated dependencies [a666b90]
148
+ - @adhese/sdk@0.5.0
149
+
150
+ ## 0.4.0
151
+
152
+ ### Minor Changes
153
+
154
+ - 52862a1: Add support for DALE gateway responses
155
+
156
+ ### Patch Changes
157
+
158
+ - a4da136: Fix GET request not working with some slots properly
159
+ - 7bbe1ff: Fix @adhese/sdk-devtools not outputting css to example
160
+ - Updated dependencies [52862a1]
161
+ - Updated dependencies [a4da136]
162
+ - @adhese/sdk@0.4.0
163
+
164
+ ## 0.3.0
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies [22c81ff]
169
+ - Updated dependencies [e88cce4]
170
+ - Updated dependencies [63cd49f]
171
+ - @adhese/sdk-devtools@0.3.0
172
+ - @adhese/sdk@0.3.0
173
+
174
+ ## 0.2.0
175
+
176
+ ### Minor Changes
177
+
178
+ - 82d823f: Create separate @adhese/sdk-devtool package to simplify dependencies in the @adhese/sdk package
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies [82d823f]
183
+ - @adhese/sdk-devtools@0.2.0
184
+ - @adhese/sdk@0.2.0
185
+
186
+ ## 0.1.5
187
+
188
+ ### Patch Changes
189
+
190
+ - 6725b17: Add repository field to package.json
191
+ - Updated dependencies [6725b17]
192
+ - @adhese/sdk@0.1.5
193
+
194
+ ## 0.1.4
195
+
196
+ ### Patch Changes
197
+
198
+ - @adhese/sdk@0.1.4
199
+
200
+ ## 0.1.3
201
+
202
+ ### Patch Changes
203
+
204
+ - @adhese/sdk@0.1.3
205
+
206
+ ## 0.1.2
207
+
208
+ ### Patch Changes
209
+
210
+ - 6c3b93e: Add license file
211
+ - Updated dependencies [6c3b93e]
212
+ - Updated dependencies [6c3b93e]
213
+ - @adhese/sdk@0.1.2
214
+
215
+ ## 0.1.1
216
+
217
+ ### Patch Changes
218
+
219
+ - d481a4e: Add license file
220
+ - Updated dependencies [d481a4e]
221
+ - @adhese/sdk@0.1.1
222
+
223
+ ## 0.1.0
224
+
225
+ ### Minor Changes
226
+
227
+ - 9df9809: Add comitizen
228
+ - 9df9809: Initial release
229
+
230
+ ### Patch Changes
231
+
232
+ - 9df9809: Update dependencies
233
+ - 9df9809: Fix eslint-config version number
234
+ - Updated dependencies [9df9809]
235
+ - Updated dependencies [9df9809]
236
+ - Updated dependencies [9df9809]
237
+ - Updated dependencies [9df9809]
238
+ - @adhese/sdk@0.1.0
package/dist/index.cjs CHANGED
@@ -1,18 +1,42 @@
1
1
  "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
2
24
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
25
  const jsxRuntime = require("react/jsx-runtime");
4
26
  const react = require("react");
5
- const sdk = require("@adhese/sdk");
6
27
  const useDeepCompareEffect = require("use-deep-compare-effect");
7
28
  const remeda = require("remeda");
8
29
  const adheseContext = react.createContext(void 0);
9
30
  function AdheseProvider({ children, options }) {
10
31
  const [adhese, setAdhese] = react.useState(void 0);
11
32
  react.useEffect(() => {
12
- const instance = sdk.createAdhese(options);
13
- setAdhese(instance);
33
+ let instance = null;
34
+ import("@adhese/sdk").then(({ createAdhese }) => {
35
+ instance = createAdhese(options);
36
+ setAdhese(instance);
37
+ }).catch(console.error);
14
38
  return () => {
15
- instance.dispose();
39
+ instance == null ? void 0 : instance.dispose();
16
40
  };
17
41
  }, [options]);
18
42
  return /* @__PURE__ */ jsxRuntime.jsx(adheseContext.Provider, { value: adhese, children });
@@ -1 +1 @@
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, 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 const instance = createAdhese(options);\n setAdhese(instance);\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 'remeda';\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","createAdhese","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;AACR,UAAA,WAAWC,iBAAa,OAAO;AACrC,cAAU,QAAQ;AAElB,WAAO,MAAY;AACjB,eAAS,QAAQ;AAAA,IAAA;AAAA,EACnB,GACC,CAAC,OAAO,CAAC;AAEZ,wCACG,cAAc,UAAd,EAAuB,OAAO,QAC5B,SACH,CAAA;AAEJ;AAKO,SAAS,YAAgC;AAC9C,SAAOC,MAAAA,WAAW,aAAa;AACjC;AChCgB,SAAA,cAAc,YAAoC,SAAsF;AACtJ,QAAM,CAAC,MAAM,OAAO,IAAIH,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,QAAQI,YAAK,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;AAE3CJ,QAAAA,UAAU,MAAM;AACd,yCAAW;AAAA,EAAI,GACd,CAAC,UAAU,IAAI,CAAC;AAGjB,SAAAK,2BAAA,IAAC,OAAI,EAAA,KAAK,QAAS,CAAA;AAEvB;;;;;"}
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 | null = null;\n\n import('@adhese/sdk').then(({ createAdhese }) => {\n instance = createAdhese(options);\n\n setAdhese(instance);\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 'remeda';\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;AACd,QAAI,WAA0B;AAE9B,WAAO,aAAa,EAAE,KAAK,CAAC,EAAE,mBAAmB;AAC/C,iBAAW,aAAa,OAAO;AAE/B,gBAAU,QAAQ;AAAA,IACnB,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;ACrCgB,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,YAAK,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.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { createContext, useState, useEffect, useContext, useRef } from "react";
3
- import { createAdhese } from "@adhese/sdk";
4
3
  import useDeepCompareEffect from "use-deep-compare-effect";
5
4
  import { omit } from "remeda";
6
5
  const adheseContext = createContext(void 0);
7
6
  function AdheseProvider({ children, options }) {
8
7
  const [adhese, setAdhese] = useState(void 0);
9
8
  useEffect(() => {
10
- const instance = createAdhese(options);
11
- setAdhese(instance);
9
+ let instance = null;
10
+ import("@adhese/sdk").then(({ createAdhese }) => {
11
+ instance = createAdhese(options);
12
+ setAdhese(instance);
13
+ }).catch(console.error);
12
14
  return () => {
13
- instance.dispose();
15
+ instance == null ? void 0 : instance.dispose();
14
16
  };
15
17
  }, [options]);
16
18
  return /* @__PURE__ */ jsx(adheseContext.Provider, { value: adhese, children });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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, 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 const instance = createAdhese(options);\n setAdhese(instance);\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 'remeda';\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;AACR,UAAA,WAAW,aAAa,OAAO;AACrC,cAAU,QAAQ;AAElB,WAAO,MAAY;AACjB,eAAS,QAAQ;AAAA,IAAA;AAAA,EACnB,GACC,CAAC,OAAO,CAAC;AAEZ,6BACG,cAAc,UAAd,EAAuB,OAAO,QAC5B,SACH,CAAA;AAEJ;AAKO,SAAS,YAAgC;AAC9C,SAAO,WAAW,aAAa;AACjC;AChCgB,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;"}
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 | null = null;\n\n import('@adhese/sdk').then(({ createAdhese }) => {\n instance = createAdhese(options);\n\n setAdhese(instance);\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 'remeda';\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;AACd,QAAI,WAA0B;AAE9B,WAAO,aAAa,EAAE,KAAK,CAAC,EAAE,mBAAmB;AAC/C,iBAAW,aAAa,OAAO;AAE/B,gBAAU,QAAQ;AAAA,IACnB,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;ACrCgB,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;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adhese/sdk-react",
3
3
  "type": "module",
4
- "version": "0.9.3",
4
+ "version": "0.9.4",
5
5
  "description": "Adhese SDK",
6
6
  "repository": {
7
7
  "type": "git",
@@ -11,6 +11,7 @@
11
11
  "module": "./dist/index.js",
12
12
  "types": "./dist/index.d.ts",
13
13
  "files": [
14
+ "CHANGELOG.md",
14
15
  "LICENSE",
15
16
  "README.md",
16
17
  "dist"
@@ -29,7 +30,7 @@
29
30
  "react-dom": ">=16.13"
30
31
  },
31
32
  "dependencies": {
32
- "@adhese/sdk-shared": "^0.2.0",
33
+ "@adhese/sdk-shared": "^0.3.0",
33
34
  "remeda": "^1.61.0",
34
35
  "use-deep-compare-effect": "^1.8.1"
35
36
  },