@dialstack/sdk-react 3.7.0 → 3.8.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.d.cts +4 -4
  4. package/dist/ai-agent.d.ts +4 -4
  5. package/dist/ai-agent.mjs +1 -1
  6. package/dist/ai-agent.mjs.map +1 -1
  7. package/dist/call-history.cjs +1 -1
  8. package/dist/call-history.cjs.map +1 -1
  9. package/dist/call-history.mjs +1 -1
  10. package/dist/call-history.mjs.map +1 -1
  11. package/dist/call-logs.cjs +1 -1
  12. package/dist/call-logs.cjs.map +1 -1
  13. package/dist/call-logs.d.cts +11 -1
  14. package/dist/call-logs.d.ts +11 -1
  15. package/dist/call-logs.mjs +1 -1
  16. package/dist/call-logs.mjs.map +1 -1
  17. package/dist/dial-plan.cjs +1 -1
  18. package/dist/dial-plan.cjs.map +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 +17 -2
  24. package/dist/index.d.ts +17 -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.d.cts +11 -5
  34. package/dist/phone-number-ordering.d.ts +11 -5
  35. package/dist/phone-number-ordering.mjs +1 -1
  36. package/dist/phone-number-ordering.mjs.map +1 -1
  37. package/dist/phone-numbers.cjs +1 -1
  38. package/dist/phone-numbers.cjs.map +1 -1
  39. package/dist/phone-numbers.mjs +1 -1
  40. package/dist/phone-numbers.mjs.map +1 -1
  41. package/dist/softphone.cjs +1 -1
  42. package/dist/softphone.cjs.map +1 -1
  43. package/dist/softphone.d.cts +49 -2
  44. package/dist/softphone.d.ts +49 -2
  45. package/dist/softphone.mjs +1 -1
  46. package/dist/softphone.mjs.map +1 -1
  47. package/dist/voicemails.cjs +1 -1
  48. package/dist/voicemails.cjs.map +1 -1
  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),r=()=>{const r=e.useContext(t);if(!r)throw new Error("Could not find DialStack context; You need to wrap your app in a <DialstackComponentsProvider> provider. See https://docs.dialstack.ai/sdk/react for setup instructions.");return r};exports.DialstackComponentsContext=t,exports.DialstackComponentsProvider=({dialstack:r,children:n})=>{const a={dialstack:r};return e.createElement(t.Provider,{value:a},n)},exports.useAppearance=function(t){const[r,n]=e.useState(()=>t.getAppearance());return e.useEffect(()=>{if("undefined"==typeof document)return;const e=document.createElement("div"),r=e=>{const t=e.detail;n(null==t?void 0:t.appearance)};return e.addEventListener("dialstack-appearance-update",r),t.addAppearanceTarget(e),()=>{t.removeAppearanceTarget(e),e.removeEventListener("dialstack-appearance-update",r)}},[t]),r},exports.useCreateComponent=function(t,r){const n=e.useRef(null),[a,o]=e.useState(null);return{containerRef:e.useCallback(e=>{if(n.current&&n.current.parentNode&&(n.current.parentNode.removeChild(n.current),n.current=null,o(null)),!e)return;const a=t.create(r);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,r)}catch(e){throw t.removeAppearanceTarget(a),e}try{a.setAttribute("data-dialstack-sdk-version","3.7.0")}catch(e){console.log("Error setting SDK version attribute:",e)}e.appendChild(a),n.current=a,o(a)},[t,r]),componentInstance:a}},exports.useDialstack=()=>{const{dialstack:e}=r();return e},exports.useDialstackComponents=r,exports.useUpdateWithSetter=function(t,r,n){e.useEffect(()=>{if(t&&void 0!==r)try{n(t,r)}catch(e){console.error("DialStack: Error calling setter:",e)}},[t,r,n])};
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])};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/react/DialstackComponentsProvider.tsx","../src/react/useAppearance.ts","../src/react/useCreateComponent.tsx","../src/react/version.ts","../src/react/useUpdateWithSetter.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","useDialstackComponents","context","useContext","Error","DialstackComponentsProvider","dialstack","children","value","React","createElement","Provider","appearance","setAppearance","useState","getAppearance","useEffect","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeAppearanceTarget","removeEventListener","tagName","componentRef","useRef","componentInstance","setComponentInstance","containerRef","useCallback","container","current","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","setAttribute","e","console","log","appendChild","useDialstack","onUpdated","undefined","error"],"mappings":"oCAmBA,MAAMA,EAA6BC,EAAAA,cAAsD,MAsD5EC,EAAyBA,KACpC,MAAMC,EAAUC,EAAAA,WAAWJ,GAC3B,IAAKG,EACH,MAAM,IAAIE,MACR,4KAIJ,OAAOF,4EA5B8EG,EACrFC,YACAC,eAEA,MAAMC,EAAyC,CAC7CF,aAGF,OACEG,EAAAC,cAACX,EAA2BY,SAAQ,CAACH,MAAOA,GACzCD,0BC9CD,SAAwBD,GAC5B,MAAOM,EAAYC,GAAiBC,EAAAA,SAAwC,IAC1ER,EAAUS,iBAqBZ,OAlBAC,EAAAA,UAAU,KACR,GAAwB,oBAAbC,SAA0B,OAErC,MAAM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js","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","registerClientComponent","onUpdated","undefined","error","console"],"mappings":"oCAEO,MCkBDA,EAA6BC,EAAAA,cAAsD,MA6D5EC,EAAyBA,KACpC,MAAMC,EAAUC,EAAAA,WAAWJ,GAC3B,IAAKG,EACH,MAAM,IAAIE,MACR,6KAIJ,OAAOF,4EAnC8EG,EACrFC,YACAC,qBAOgC,QAAhCC,EAAAF,aAAS,EAATA,EAAWG,6BAAqB,IAAAD,GAAAA,EAAAE,KAAAJ,EAAG,YD7DN,SC+D7B,MAAMK,EAAyC,CAC7CL,aAGF,OACEM,EAAAC,cAACd,EAA2Be,SAAQ,CAACH,MAAOA,GACzCJ,0BCtDD,SAAwBD,GAC5B,MAAOS,EAAYC,GAAiBC,EAAAA,SAAwC,IAC1EX,EAAUY,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,GAEvDhB,EAAUoB,oBAAoBL,GAEvB,KACLf,EAAUqB,uBAAuBN,GACjCA,EAAOO,oBAAoB,8BAA+BN,KAE3D,CAAChB,IA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AACd,EAAWhC,EAAO4C,GACxB"}
package/dist/index.d.cts CHANGED
@@ -60,6 +60,14 @@ declare const useDialstackComponents: () => DialstackComponentsContextValue;
60
60
  * @throws {Error} If used outside of DialstackComponentsProvider
61
61
  */
62
62
  declare const useDialstack: () => DialStackInstance;
63
+ /**
64
+ * Report a React-only component (one that is not a web component, which
65
+ * reports itself) in the `DialStack-Client` header. No-op outside a provider.
66
+ * Runs during render, like the provider's own registration, so requests from
67
+ * the component's children's mount effects already carry it.
68
+ * @internal
69
+ */
70
+ declare function useReportComponent(name: string): void;
63
71
 
64
72
  /**
65
73
  * React hook for creating and managing Web Components
@@ -91,7 +99,14 @@ interface UseCreateComponentResult<T extends ComponentTagName> {
91
99
  * // TypeScript knows about setUserId, setOnVoicemailPlay, etc.
92
100
  * ```
93
101
  */
94
- declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T): UseCreateComponentResult<T>;
102
+ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T,
103
+ /**
104
+ * Applies props to the element before it is attached. Attaching is what
105
+ * starts its first load, and the prop effects only run after that, so a
106
+ * setting that shapes the first request belongs here or it costs a second
107
+ * one. Read at creation time; it does not re-run.
108
+ */
109
+ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResult<T>;
95
110
 
96
111
  /**
97
112
  * React hook for synchronizing React props to Web Component setter methods
@@ -144,5 +159,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
144
159
  */
145
160
  declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
146
161
 
147
- export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useUpdateWithSetter };
162
+ export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateWithSetter };
148
163
  export type { DialstackComponentsProviderProps };
package/dist/index.d.ts CHANGED
@@ -60,6 +60,14 @@ declare const useDialstackComponents: () => DialstackComponentsContextValue;
60
60
  * @throws {Error} If used outside of DialstackComponentsProvider
61
61
  */
62
62
  declare const useDialstack: () => DialStackInstance;
63
+ /**
64
+ * Report a React-only component (one that is not a web component, which
65
+ * reports itself) in the `DialStack-Client` header. No-op outside a provider.
66
+ * Runs during render, like the provider's own registration, so requests from
67
+ * the component's children's mount effects already carry it.
68
+ * @internal
69
+ */
70
+ declare function useReportComponent(name: string): void;
63
71
 
64
72
  /**
65
73
  * React hook for creating and managing Web Components
@@ -91,7 +99,14 @@ interface UseCreateComponentResult<T extends ComponentTagName> {
91
99
  * // TypeScript knows about setUserId, setOnVoicemailPlay, etc.
92
100
  * ```
93
101
  */
94
- declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T): UseCreateComponentResult<T>;
102
+ declare function useCreateComponent<T extends ComponentTagName>(dialstack: DialStackInstance, tagName: T,
103
+ /**
104
+ * Applies props to the element before it is attached. Attaching is what
105
+ * starts its first load, and the prop effects only run after that, so a
106
+ * setting that shapes the first request belongs here or it costs a second
107
+ * one. Read at creation time; it does not re-run.
108
+ */
109
+ beforeAttach?: (component: ComponentElement[T]) => void): UseCreateComponentResult<T>;
95
110
 
96
111
  /**
97
112
  * React hook for synchronizing React props to Web Component setter methods
@@ -144,5 +159,5 @@ declare function useUpdateWithSetter<T extends HTMLElement, V>(component: T | nu
144
159
  */
145
160
  declare function useAppearance(dialstack: DialStackInstance): AppearanceOptions | undefined;
146
161
 
147
- export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useUpdateWithSetter };
162
+ export { DialstackComponentsContext, DialstackComponentsProvider, useAppearance, useCreateComponent, useDialstack, useDialstackComponents, useReportComponent, useUpdateWithSetter };
148
163
  export type { DialstackComponentsProviderProps };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import e,{createContext as t,useContext as r,useRef as n,useState as a,useCallback as o,useEffect as i}from"react";const c=t(null),s=({dialstack:t,children:r})=>{const n={dialstack:t};return e.createElement(c.Provider,{value:n},r)},d=()=>{const e=r(c);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/sdk/react for setup instructions.");return e},l=()=>{const{dialstack:e}=d();return e};function u(e,t){const r=n(null),[i,c]=a(null);return{containerRef:o(n=>{if(r.current&&r.current.parentNode&&(r.current.parentNode.removeChild(r.current),r.current=null,c(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}try{a.setAttribute("data-dialstack-sdk-version","3.7.0")}catch(e){console.log("Error setting SDK version attribute:",e)}n.appendChild(a),r.current=a,c(a)},[e,t]),componentInstance:i}}function p(e,t,r){i(()=>{if(e&&void 0!==t)try{r(e,t)}catch(e){console.error("DialStack: Error calling setter:",e)}},[e,t,r])}function f(e){const[t,r]=a(()=>e.getAppearance());return i(()=>{if("undefined"==typeof document)return;const t=document.createElement("div"),n=e=>{const t=e.detail;r(null==t?void 0:t.appearance)};return t.addEventListener("dialstack-appearance-update",n),e.addAppearanceTarget(t),()=>{e.removeAppearanceTarget(t),t.removeEventListener("dialstack-appearance-update",n)}},[e]),t}export{c as DialstackComponentsContext,s as DialstackComponentsProvider,f as useAppearance,u as useCreateComponent,l as useDialstack,d as useDialstackComponents,p 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 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};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/react/DialstackComponentsProvider.tsx","../src/react/useCreateComponent.tsx","../src/react/version.ts","../src/react/useUpdateWithSetter.ts","../src/react/useAppearance.ts"],"sourcesContent":[null,null,null,null,null],"names":["DialstackComponentsContext","createContext","DialstackComponentsProvider","dialstack","children","value","React","createElement","Provider","useDialstackComponents","context","useContext","Error","useDialstack","useCreateComponent","tagName","componentRef","useRef","componentInstance","setComponentInstance","useState","containerRef","useCallback","container","current","parentNode","removeChild","component","create","element","setInstance","assertUpgraded","err","removeAppearanceTarget","setAttribute","e","console","log","appendChild","useUpdateWithSetter","onUpdated","useEffect","undefined","error","useAppearance","appearance","setAppearance","getAppearance","document","target","handler","event","detail","addEventListener","addAppearanceTarget","removeEventListener"],"mappings":"mHAmBA,MAAMA,EAA6BC,EAAsD,MAkC5EC,EAA0EA,EACrFC,YACAC,eAEA,MAAMC,EAAyC,CAC7CF,aAGF,OACEG,EAAAC,cAACP,EAA2BQ,SAAQ,CAACH,MAAOA,GACzCD,IAUMK,EAAyBA,KACpC,MAAMC,EAAUC,EAAWX,GAC3B,IAAKU,EACH,MAAM,IAAIE,MACR,4KAIJ,OAAOF,GAQIG,EAAeA,KAC1B,MAAMV,UAAEA,GAAcM,IACtB,OAAON,GCvBH,SAAUW,EACdX,EACAY,GAEA,MAAMC,EAAeC,EAAmC,OAEjDC,EAAmBC,GAAwBC,EAAqC,MA0CvF,MAAO,CACLC,aAxCmBC,EAClBC,IAQC,GANIP,EAAaQ,SAAWR,EAAaQ,QAAQC,aAC/CT,EAAaQ,QAAQC,WAAWC,YAAYV,EAAaQ,SACzDR,EAAaQ,QAAU,KACvBL,EAAqB,QAGlBI,EAAW,OAGhB,MAAMI,EAAYxB,EAAUyB,OAAOb,GACnC,KAvDN,SAAwBc,EAAkBd,GACxC,IAAIc,GAAyE,mBAAtDA,EAAsCC,YAG7D,MAAM,IAAIlB,MACR,cAAcG,sZAOlB,CA4CQgB,CAAeJ,EAAWZ,EAC5B,CAAE,MAAOiB,GAMP,MADA7B,EAAU8B,uBAAuBN,GAC3BK,CACR,CAGA,IACEL,EAAUO,aAAa,6BCrGA,QDsGzB,CAAE,MAAOC,GACPC,QAAQC,IAAI,uCAAwCF,EACtD,CAGAZ,EAAUe,YAAYX,GACtBX,EAAaQ,QAAUG,EACvBR,EAAqBQ,IAEvB,CAACxB,EAAWY,IAKZG,oBAEJ,UEnFgBqB,EACdZ,EACAtB,EACAmC,GAEAC,EAAU,KACR,GAAKd,QAAuBe,IAAVrC,EAElB,IACEmC,EAAUb,EAAWtB,EACvB,CAAE,MAAOsC,GACPP,QAAQO,MAAM,mCAAoCA,EACpD,GACC,CAAChB,EAAWtB,EAAOmC,GACxB,CClCM,SAAUI,EAAczC,GAC5B,MAAO0C,EAAYC,GAAiB1B,EAAwC,IAC1EjB,EAAU4C,iBAqBZ,OAlBAN,EAAU,KACR,GAAwB,oBAAbO,SAA0B,OAErC,MAAMC,EAASD,SAASzC,cAAc,OAChC2C,EAAWC,IACf,MAAMC,EAAUD,EAAqEC,OACrFN,EAAcM,eAAAA,EAAQP,aAMxB,OAJAI,EAAOI,iBAAiB,8BAA+BH,GAEvD/C,EAAUmD,oBAAoBL,GAEvB,KACL9C,EAAU8B,uBAAuBgB,GACjCA,EAAOM,oBAAoB,8BAA+BL,KAE3D,CAAC/C,IAEG0C,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","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,mCAAuBF,GAAAA,EAAAZ,KAAAa,EAAG,YAAaF,EAC5F,CC7CM,SAAUI,EACdnB,EACAoB,EAOAC,GAEA,MAAMC,EAAeC,EAAmC,MAIlDC,EAAkBD,EAAOF,GAC/BI,EAAgB,KACdD,EAAgBE,QAAUL,IAG5B,MAAOM,EAAmBC,GAAwBC,EAAqC,MAqCvF,MAAO,CACLC,aAnCmBC,EAClBC,UAQC,GANIV,EAAaI,SAAWJ,EAAaI,QAAQO,aAC/CX,EAAaI,QAAQO,WAAWC,YAAYZ,EAAaI,SACzDJ,EAAaI,QAAU,KACvBE,EAAqB,QAGlBI,EAAW,OAGhB,MAAMG,EAAYnC,EAAUoC,OAAOhB,GACnC,KArEN,SAAwBiB,EAAkBjB,GACxC,IAAIiB,GAAyE,mBAAtDA,EAAsCC,YAG7D,MAAM,IAAI1B,MACR,cAAcQ,sZAOlB,CA0DQmB,CAAeJ,EAAW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