@dialstack/sdk-react 3.8.0 → 3.10.0

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.
Files changed (51) hide show
  1. package/dist/ai-agent.cjs +1 -1
  2. package/dist/ai-agent.cjs.map +1 -1
  3. package/dist/ai-agent.mjs +1 -1
  4. package/dist/ai-agent.mjs.map +1 -1
  5. package/dist/call-history.cjs +1 -1
  6. package/dist/call-history.cjs.map +1 -1
  7. package/dist/call-history.mjs +1 -1
  8. package/dist/call-history.mjs.map +1 -1
  9. package/dist/call-logs.cjs +1 -1
  10. package/dist/call-logs.cjs.map +1 -1
  11. package/dist/call-logs.d.cts +4 -0
  12. package/dist/call-logs.d.ts +4 -0
  13. package/dist/call-logs.mjs +1 -1
  14. package/dist/call-logs.mjs.map +1 -1
  15. package/dist/dial-plan.cjs +1 -1
  16. package/dist/dial-plan.cjs.map +1 -1
  17. package/dist/dial-plan.d.cts +1 -1
  18. package/dist/dial-plan.d.ts +1 -1
  19. package/dist/dial-plan.mjs +1 -1
  20. package/dist/dial-plan.mjs.map +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +21 -2
  24. package/dist/index.d.ts +21 -2
  25. package/dist/index.mjs +1 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/onboarding.cjs +1 -1
  28. package/dist/onboarding.cjs.map +1 -1
  29. package/dist/onboarding.mjs +1 -1
  30. package/dist/onboarding.mjs.map +1 -1
  31. package/dist/phone-number-ordering.cjs +1 -1
  32. package/dist/phone-number-ordering.cjs.map +1 -1
  33. package/dist/phone-number-ordering.mjs +1 -1
  34. package/dist/phone-number-ordering.mjs.map +1 -1
  35. package/dist/phone-numbers.cjs +1 -1
  36. package/dist/phone-numbers.cjs.map +1 -1
  37. package/dist/phone-numbers.mjs +1 -1
  38. package/dist/phone-numbers.mjs.map +1 -1
  39. package/dist/softphone.cjs +1 -1
  40. package/dist/softphone.cjs.map +1 -1
  41. package/dist/softphone.d.cts +86 -40
  42. package/dist/softphone.d.ts +86 -40
  43. package/dist/softphone.mjs +1 -1
  44. package/dist/softphone.mjs.map +1 -1
  45. package/dist/voicemails.cjs +1 -1
  46. package/dist/voicemails.cjs.map +1 -1
  47. package/dist/voicemails.d.cts +4 -0
  48. package/dist/voicemails.d.ts +4 -0
  49. package/dist/voicemails.mjs +1 -1
  50. package/dist/voicemails.mjs.map +1 -1
  51. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react");const t=e.createContext(null),n=()=>{const n=e.useContext(t);if(!n)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return n};exports.DialstackComponentsContext=t,exports.DialstackComponentsProvider=({dialstack:n,children:r})=>{var a;null===(a=null==n?void 0:n.registerClientPackage)||void 0===a||a.call(n,"sdk-react","3.8.0");const o={dialstack:n};return e.createElement(t.Provider,{value:o},r)},exports.useAppearance=function(t){const[n,r]=e.useState(()=>t.getAppearance());return e.useEffect(()=>{if("undefined"==typeof document)return;const e=document.createElement("div"),n=e=>{const t=e.detail;r(null==t?void 0:t.appearance)};return e.addEventListener("dialstack-appearance-update",n),t.addAppearanceTarget(e),()=>{t.removeAppearanceTarget(e),e.removeEventListener("dialstack-appearance-update",n)}},[t]),n},exports.useCreateComponent=function(t,n,r){const a=e.useRef(null),o=e.useRef(r);e.useLayoutEffect(()=>{o.current=r});const[s,i]=e.useState(null);return{containerRef:e.useCallback(e=>{var r;if(a.current&&a.current.parentNode&&(a.current.parentNode.removeChild(a.current),a.current=null,i(null)),!e)return;const s=t.create(n);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(s,n)}catch(e){throw t.removeAppearanceTarget(s),e}null===(r=o.current)||void 0===r||r.call(o,s),e.appendChild(s),a.current=s,i(s)},[t,n]),componentInstance:s}},exports.useDialstack=()=>{const{dialstack:e}=n();return e},exports.useDialstackComponents=n,exports.useReportComponent=function(n){var r,a,o;null===(o=null===(a=null===(r=e.useContext(t))||void 0===r?void 0:r.dialstack)||void 0===a?void 0:a.registerClientComponent)||void 0===o||o.call(a,"sdk-react",n)},exports.useUpdateWithSetter=function(t,n,r){e.useEffect(()=>{if(t&&void 0!==n)try{r(t,n)}catch(e){console.error("DialStack: Error calling setter:",e)}},[t,n,r])};
1
+ "use strict";var e=require("react");const t=e.createContext(null),n=()=>{const n=e.useContext(t);if(!n)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return n};function r(e,t,n,r,o=!1){if(!t)return;const a=e.current,s=null!==a&&a.component===t;if(void 0===n){if(!o||!s||void 0===a.value)return}else if(s&&Object.is(a.value,n))return;e.current={component:t,value:n};try{r(t,n)}catch(e){console.error("DialStack: Error calling setter:",e)}}exports.DialstackComponentsContext=t,exports.DialstackComponentsProvider=({dialstack:n,children:r})=>{var o;null===(o=null==n?void 0:n.registerClientPackage)||void 0===o||o.call(n,"sdk-react","3.10.0");const a={dialstack:n};return e.createElement(t.Provider,{value:a},r)},exports.useAppearance=function(t){const[n,r]=e.useState(()=>t.getAppearance());return e.useEffect(()=>{if("undefined"==typeof document)return;const e=document.createElement("div"),n=e=>{const t=e.detail;r(null==t?void 0:t.appearance)};return e.addEventListener("dialstack-appearance-update",n),t.addAppearanceTarget(e),()=>{t.removeAppearanceTarget(e),e.removeEventListener("dialstack-appearance-update",n)}},[t]),n},exports.useCreateComponent=function(t,n,r){const o=e.useRef(null),a=e.useRef(r);e.useLayoutEffect(()=>{a.current=r});const[s,c]=e.useState(null);return{containerRef:e.useCallback(e=>{var r;if(o.current&&o.current.parentNode&&(o.current.parentNode.removeChild(o.current),o.current=null,c(null)),!e)return;const s=t.create(n);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(s,n)}catch(e){throw t.removeAppearanceTarget(s),e}null===(r=a.current)||void 0===r||r.call(a,s),e.appendChild(s),o.current=s,c(s)},[t,n]),componentInstance:s}},exports.useDialstack=()=>{const{dialstack:e}=n();return e},exports.useDialstackComponents=n,exports.useReportComponent=function(n){var r,o,a;null===(a=null===(o=null===(r=e.useContext(t))||void 0===r?void 0:r.dialstack)||void 0===o?void 0:o.registerClientComponent)||void 0===a||a.call(o,"sdk-react",n)},exports.useUpdateHandlerWithSetter=function(t,n,o){const a=e.useRef(null);e.useEffect(()=>r(a,t,n,o,!0))},exports.useUpdateWithSetter=function(t,n,o){const a=e.useRef(null);e.useEffect(()=>r(a,t,n,o))};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useAppearance.ts","../src/react/useCreateComponent.tsx","../src/react/useUpdateWithSetter.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","useDialstackComponents","context","useContext","Error","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","value","React","createElement","Provider","appearance","setAppearance","useState","getAppearance","useEffect","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeAppearanceTarget","removeEventListener","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","current","componentInstance","setComponentInstance","containerRef","useCallback","container","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","appendChild","useDialstack","name","_c","_b","registerCl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,IAAIgB,GAAyE,mBAAtDA,EAAsCC,YAG7D,MAAM,IAAI1C,MACR,cAAcyB,sZAOlB,CA0DQkB,CAAeJ,EAAWd,EAC5B,CAAE,MAAOmB,GAMP,MADA1C,EAAUqB,uBAAuBgB,GAC3BK,CACR,CAEuB,QAAvBxC,EAAAyB,EAAgBE,mBAAO3B,GAAAA,EAAAE,KAAAuB,EAAGU,GAG1BH,EAAUS,YAAYN,GACtBZ,EAAaI,QAAUQ,EACvBN,EAAqBM,IAEvB,CAACrC,EAAWuB,IAKZO,oBAEJ,uBF9B4Bc,KAC1B,MAAM5C,UAAEA,GAAcL,IACtB,OAAOK,+DAUH,SAA6B6C,aACyC,QAA1EC,EAAiD,QAAjDC,EAAsC,QAAtC7C,EAAAL,EAAAA,WAAWJ,UAA2B,IAAAS,OAAA,EAAAA,EAAEF,iBAAS,IAAA+C,OAAA,EAAAA,EAAEC,mCAAuBF,GAAAA,EAAA1C,KAAA2C,EAAG,YAAaF,EAC5F,uCGzEER,EACAhC,EACA4C,GAEApC,EAAAA,UAAU,KACR,GAAKwB,QAAuBa,IAAV7C,EAElB,IACE4C,EAAUZ,EAAWhC,EACvB,CAAE,MAAO8C,GACPC,QAAQD,MAAM,mCAAoCA,EACpD,GACC,CAACd,EAAWhC,EAAO4C,GACxB"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts","../src/react/useCreateComponent.tsx"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","useDialstackComponents","context","useContext","Error","applyIfChanged","applied","component","value","onUpdated","clearOnRemove","last","current","sameComponent","undefined","Object","is","error","console","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","React","createElement","Provider","appearance","setAppearance","useState","getAppearance","useEffect","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeAppearanceTarget","removeEventListener","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","componentInstance","setComponentInstance","containerRef","useCallback","container","parentNode","removeChild","create","element","setInstance","assertUpgraded","err","appendChild","useDialstack","name","_c","_b","registerClientComponent"],"mappings":"oCAEO,MCkBDA,EAA6BC,EAAAA,cAAsD,MA6D5EC,EAAyBA,KACpC,MAAMC,EAAUC,EAAAA,WAAWJ,GAC3B,IAAKG,EACH,MAAM,IAAIE,MACR,6KAIJ,OAAOF,GCgBT,SAASG,EACPC,EACAC,EACAC,EACAC,EACAC,GAAgB,GAEhB,IAAKH,EAAW,OAChB,MAAMI,EAAOL,EAAQM,QACfC,EAAyB,OAATF,GAAiBA,EAAKJ,YAAcA,EAC1D,QAAcO,IAAVN,GAEF,IAAKE,IAAkBG,QAAgCC,IAAfH,EAAKH,MAAqB,YAC7D,GAAIK,GAAiBE,OAAOC,GAAGL,EAAKH,MAAOA,GAChD,OAKFF,EAAQM,QAAU,CAAEL,YAAWC,SAC/B,IACEC,EAAUF,EAAWC,EACvB,CAAE,MAAOS,GACPC,QAAQD,MAAM,mCAAoCA,EACpD,CACF,0ED5EuFE,EACrFC,YACAC,qBAOgC,QAAhCC,EAAAF,aAAS,EAATA,EAAWG,6BAAqB,IAAAD,GAAAA,EAAAE,KAAAJ,EAAG,YD7DN,UC+D7B,MAAMZ,EAAyC,CAC7CY,aAGF,OACEK,EAAAC,cAAC3B,EAA2B4B,SAAQ,CAACnB,MAAOA,GACzCa,0BEtDD,SAAwBD,GAC5B,MAAOQ,EAAYC,GAAiBC,EAAAA,SAAwC,IAC1EV,EAAUW,iBAqBZ,OAlBAC,EAAAA,UAAU,KACR,GAAwB,oBAAbC,SAA0B,OAErC,MAAMC,EAASD,SAASP,cAAc,OAChCS,EAAWC,IACf,MAAMC,EAAUD,EAAqEC,OACrFR,EAAcQ,eAAAA,EAAQT,aAMxB,OAJAM,EAAOI,iBAAiB,8BAA+BH,GAEvDf,EAAUmB,oBAAoBL,GAEvB,KACLd,EAAUoB,uBAAuBN,GACjCA,EAAOO,o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S1B,GAAW,GACzE,uCAtCEF,EACAC,EACAC,GAEA,MAAMH,EAAUuC,EAAAA,OAA0B,MAG1Cb,EAAAA,UAAU,IAAM3B,EAAeC,EAASC,EAAWC,EAAOC,GAC5D"}
package/dist/index.d.cts CHANGED
@@ -120,6 +120,17 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
120
120
  * This enables declarative React patterns (props) to control imperative
121
121
  * Web Component APIs (setter methods) in a type-safe way.
122
122
  *
123
+ * The setter runs only when the component or the value changes, compared by
124
+ * identity like React's own effect deps, so a host that re-renders often
125
+ * doesn't make the element re-render or reload.
126
+ * That makes two things part of the contract:
127
+ * - `onUpdated` must depend only on `component` and `value`. A setter closing
128
+ * over other state isn't re-run when only that state changes; pass it in
129
+ * `value` instead.
130
+ * - Keep object props stable (a constant, `useMemo`, state) and replace rather
131
+ * than mutate them: an inline `{…}` is a new value on every render, and a
132
+ * value mutated in place is the same one.
133
+ *
123
134
  * @param component - The Web Component instance (or null if not mounted)
124
135
  * @param value - The prop value to sync
125
136
  * @param onUpdated - Callback that receives the component and value, should call the setter
@@ -134,7 +145,8 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
134
145
  * comp.setUserId(val);
135
146
  * });
136
147
  *
137
- * useUpdateWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
148
+ * // A callback: removing the prop clears it on the element.
149
+ * useUpdateHandlerWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
138
150
  * comp.setOnVoicemailSelect(val);
139
151
  * });
140
152
  *
@@ -143,6 +155,13 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
143
155
  * ```
144
156
  */
145
157
  declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | null, value: V | undefined, onUpdated: (component: T, value: V) => void): void;
158
+ /**
159
+ * `useUpdateWithSetter` for a callback prop: when the host stops passing it,
160
+ * the setter is called once with `undefined`, so the element stops calling a
161
+ * handler the host has let go of. Other props keep their last value instead,
162
+ * since clearing them would need a per-setter reset to defaults.
163
+ */
164
+ declare function useUpdateHandlerWithSetter<T extends HTMLElement, H>(component: T | null, handler: H | undefined, onUpdated: (component: T, handler: H | undefined) => void): void;
146
165
 
147
166
  /**
148
167
  * useAppearance — subscribe to live appearance updates from a DialStack instance.
@@ -159,5 +178,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
159
178
  */
160
179
  declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
161
180
 
162
- export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateWithSetter };
181
+ export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateHandlerWithSetter, useUpdateWithSetter };
163
182
  export type { DialstackComponentsProviderProps };
package/dist/index.d.ts CHANGED
@@ -120,6 +120,17 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
120
120
  * This enables declarative React patterns (props) to control imperative
121
121
  * Web Component APIs (setter methods) in a type-safe way.
122
122
  *
123
+ * The setter runs only when the component or the value changes, compared by
124
+ * identity like React's own effect deps, so a host that re-renders often
125
+ * doesn't make the element re-render or reload.
126
+ * That makes two things part of the contract:
127
+ * - `onUpdated` must depend only on `component` and `value`. A setter closing
128
+ * over other state isn't re-run when only that state changes; pass it in
129
+ * `value` instead.
130
+ * - Keep object props stable (a constant, `useMemo`, state) and replace rather
131
+ * than mutate them: an inline `{…}` is a new value on every render, and a
132
+ * value mutated in place is the same one.
133
+ *
123
134
  * @param component - The Web Component instance (or null if not mounted)
124
135
  * @param value - The prop value to sync
125
136
  * @param onUpdated - Callback that receives the component and value, should call the setter
@@ -134,7 +145,8 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
134
145
  * comp.setUserId(val);
135
146
  * });
136
147
  *
137
- * useUpdateWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
148
+ * // A callback: removing the prop clears it on the element.
149
+ * useUpdateHandlerWithSetter(componentInstance, onVoicemailSelect, (comp, val) => {
138
150
  * comp.setOnVoicemailSelect(val);
139
151
  * });
140
152
  *
@@ -143,6 +155,13 @@ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResu
143
155
  * ```
144
156
  */
145
157
  declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | null, value: V | undefined, onUpdated: (component: T, value: V) => void): void;
158
+ /**
159
+ * `useUpdateWithSetter` for a callback prop: when the host stops passing it,
160
+ * the setter is called once with `undefined`, so the element stops calling a
161
+ * handler the host has let go of. Other props keep their last value instead,
162
+ * since clearing them would need a per-setter reset to defaults.
163
+ */
164
+ declare function useUpdateHandlerWithSetter<T extends HTMLElement, H>(component: T | null, handler: H | undefined, onUpdated: (component: T, handler: H | undefined) => void): void;
146
165
 
147
166
  /**
148
167
  * useAppearance — subscribe to live appearance updates from a DialStack instance.
@@ -159,5 +178,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
159
178
  */
160
179
  declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
161
180
 
162
- export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateWithSetter };
181
+ export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateHandlerWithSetter, useUpdateWithSetter };
163
182
  export type { DialstackComponentsProviderProps };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import e,{createContext as t,useContext as n,useRef as r,useLayoutEffect as a,useState as o,useCallback as i,useEffect as c}from"react";const s=t(null),l=({dialstack:t,children:n})=>{var r;null===(r=null==t?void 0:t.registerClientPackage)||void 0===r||r.call(t,"sdk-react","3.8.0");const a={dialstack:t};return e.createElement(s.Provider,{value:a},n)},d=()=>{const e=n(s);if(!e)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return e},u=()=>{const{dialstack:e}=d();return e};function p(e){var t,r,a;null===(a=null===(r=null===(t=n(s))||void 0===t?void 0:t.dialstack)||void 0===r?void 0:r.registerClientComponent)||void 0===a||a.call(r,"sdk-react",e)}function v(e,t,n){const c=r(null),s=r(n);a(()=>{s.current=n});const[l,d]=o(null);return{containerRef:i(n=>{var r;if(c.current&&c.current.parentNode&&(c.current.parentNode.removeChild(c.current),c.current=null,d(null)),!n)return;const a=e.create(t);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(a,t)}catch(t){throw e.removeAppearanceTarget(a),t}null===(r=s.current)||void 0===r||r.call(s,a),n.appendChild(a),c.current=a,d(a)},[e,t]),componentInstance:l}}function f(e,t,n){c(()=>{if(e&&void 0!==t)try{n(e,t)}catch(e){console.error("DialStack: Error calling setter:",e)}},[e,t,n])}function k(e){const[t,n]=o(()=>e.getAppearance());return c(()=>{if("undefined"==typeof document)return;const t=document.createElement("div"),r=e=>{const t=e.detail;n(null==t?void 0:t.appearance)};return t.addEventListener("dialstack-appearance-update",r),e.addAppearanceTarget(t),()=>{e.removeAppearanceTarget(t),t.removeEventListener("dialstack-appearance-update",r)}},[e]),t}export{s as DialstackComponentsContext,l as DialstackComponentsProvider,k as useAppearance,v as useCreateComponent,u as useDialstack,d as useDialstackComponents,p as useReportComponent,f as useUpdateWithSetter};
1
+ import e,{createContext as t,useContext as n,useRef as r,useLayoutEffect as a,useState as o,useCallback as i,useEffect as c}from"react";const l=t(null),s=({dialstack:t,children:n})=>{var r;null===(r=null==t?void 0:t.registerClientPackage)||void 0===r||r.call(t,"sdk-react","3.10.0");const a={dialstack:t};return e.createElement(l.Provider,{value:a},n)},u=()=>{const e=n(l);if(!e)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdks/setup for setup instructions.");return e},d=()=>{const{dialstack:e}=u();return e};function p(e){var t,r,a;null===(a=null===(r=null===(t=n(l))||void 0===t?void 0:t.dialstack)||void 0===r?void 0:r.registerClientComponent)||void 0===a||a.call(r,"sdk-react",e)}function v(e,t,n){const c=r(null),l=r(n);a(()=>{l.current=n});const[s,u]=o(null);return{containerRef:i(n=>{var r;if(c.current&&c.current.parentNode&&(c.current.parentNode.removeChild(c.current),c.current=null,u(null)),!n)return;const a=e.create(t);try{!function(e,t){if(!e||"function"!=typeof e.setInstance)throw new Error(`<dialstack-${t}> was created but is not a registered custom element, so it would render nothing. Install @dialstack/sdk-js alongside @dialstack/sdk-react and import it once at your entry point — importing it is what registers the elements. On @dialstack/sdk-js/pure nothing registers on import: await registerComponents() before rendering. If it is installed, check that your bundler is not dropping its side effects.`)}(a,t)}catch(t){throw e.removeAppearanceTarget(a),t}null===(r=l.current)||void 0===r||r.call(l,a),n.appendChild(a),c.current=a,u(a)},[e,t]),componentInstance:s}}function f(e,t,n){const a=r(null);c(()=>m(a,e,t,n))}function k(e,t,n){const a=r(null);c(()=>m(a,e,t,n,!0))}function m(e,t,n,r,a=!1){if(!t)return;const o=e.current,i=null!==o&&o.component===t;if(void 0===n){if(!a||!i||void 0===o.value)return}else if(i&&Object.is(o.value,n))return;e.current={component:t,value:n};try{r(t,n)}catch(e){console.error("DialStack: Error calling setter:",e)}}function g(e){const[t,n]=o(()=>e.getAppearance());return c(()=>{if("undefined"==typeof document)return;const t=document.createElement("div"),r=e=>{const t=e.detail;n(null==t?void 0:t.appearance)};return t.addEventListener("dialstack-appearance-update",r),e.addAppearanceTarget(t),()=>{e.removeAppearanceTarget(t),t.removeEventListener("dialstack-appearance-update",r)}},[e]),t}export{l as DialstackComponentsContext,s as DialstackComponentsProvider,g as useAppearance,v as useCreateComponent,d as useDialstack,u as useDialstackComponents,p as useReportComponent,k as useUpdateHandlerWithSetter,f as useUpdateWithSetter};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useCreateComponent.tsx","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","value","React","createElement","Provider","useDialstackComponents","context","useContext","Error","useDialstack","useReportComponent","name","_c","_b","registerClientComponent","useCreateComponent","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","current","componentInstance","setComponentInstance","useState","containerRef","useCallback","container","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","removeAppearanceTarget","appendChild","useUpdateWithSetter","onUpdated","useEffect","undefined","error","console","useAppearance","appearance","setAppearance","getAppearance","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeEventListener"],"mappings":"wIAEO,MCkBDA,EAA6BC,EAAsD,MAkC5EC,EAA0EA,EACrFC,YACAC,qBAOgC,QAAhCC,EAAAF,aAAS,EAATA,EAAWG,6BAAqB,IAAAD,GAAAA,EAAAE,KAAAJ,EAAG,YD7DN,SC+D7B,MAAMK,EAAyC,CAC7CL,aAGF,OACEM,EAAAC,cAACV,EAA2BW,SAAQ,CAACH,MAAOA,GACzCJ,IAUMQ,EAAyBA,KACpC,MAAMC,EAAUC,EAAWd,GAC3B,IAAKa,EACH,MAAM,IAAIE,MACR,6KAIJ,OAAOF,GAQIG,EAAeA,KAC1B,MAAMb,UAAEA,GAAcS,IACtB,OAAOT,GAUH,SAAUc,EAAmBC,aACyC,QAA1EC,EAAiD,QAAjDC,EAAsC,QAAtCf,EAAAS,EAAWd,UAA2B,IAAAK,OAAA,EAAAA,EAAEF,iBAAS,IAAAiB,OAAA,EAAAA,EAAEC,mCAA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QP,aAMxB,OAJAI,EAAOI,iBAAiB,8BAA+BH,GAEvDvD,EAAU2D,oBAAoBL,GAEvB,KACLtD,EAAUyC,uBAAuBa,GACjCA,EAAOM,oBAAoB,8BAA+BL,KAE3D,CAACvD,IAEGkD,CACT"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/react/version.ts","../src/react/DialstackComponentsProvider.tsx","../src/react/useCreateComponent.tsx","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","DialstackComponentsProvider","dialstack","children","_a","registerClientPackage","call","value","React","createElement","Provider","useDialstackComponents","context","useContext","Error","useDialstack","useReportComponent","name","_c","_b","registerClientComponent","useCreateComponent","tagName","beforeAttach","componentRef","useRef","beforeAttachRef","useLayoutEffect","current","componentInstance","setComponentInstance","useState","containerRef","useCallback","container","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","removeAppearanceTarget","appendChild","useUpdateWithSetter","onUpdated","applied","useEffect","applyIfChanged","useUpdateHandlerWithSetter","handler","clearOnRemove","last","sameComponent","undefined","Object","is","error","console","useAppearance","appearance","setAppearance","getAppearance","document","target","event","detail","addEventListener","addAppearanceTarget","removeEventListener"],"mappings":"wIAEO,MCkBDA,EAA6BC,EAAsD,MAkC5EC,EAA0EA,EACrFC,YACAC,qBAOgC,QAAhCC,EAAAF,aAAS,EAATA,EAAWG,6BAAqB,IAAAD,GAAAA,EAAAE,KAAAJ,EAAG,YD7DN,UC+D7B,MAAMK,EAAyC,CAC7CL,aAGF,OACEM,EAAAC,cAACV,EAA2BW,SAAQ,CAACH,MAAOA,GACzCJ,IAUMQ,EAAyBA,KACpC,MAAMC,EAAUC,EAAWd,GAC3B,IAAKa,EACH,MAAM,IAAIE,MACR,6KAIJ,OAAOF,GAQIG,EAAeA,KAC1B,MAAMb,UAAEA,GAAcS,IACtB,OAAOT,GAUH,SAAUc,EAAmBC,aACyC,QAA1EC,EAAiD,QAAjDC,EAAsC,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