@moldable-ai/ui 0.2.14 → 0.2.15

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.
@@ -1,17 +1,20 @@
1
1
  import { Component, type ErrorInfo, type ReactNode } from 'react';
2
- type ErrorSource = 'react' | 'window' | 'promise';
2
+ export type AppErrorSource = 'react' | 'window' | 'promise' | 'bootstrap';
3
3
  interface AppErrorBoundaryProps {
4
4
  appName: string;
5
5
  children: ReactNode;
6
+ initialError?: Error | null;
7
+ initialSource?: AppErrorSource;
6
8
  }
7
9
  interface AppErrorBoundaryState {
8
10
  error: Error | null;
9
- source: ErrorSource;
11
+ source: AppErrorSource;
10
12
  componentStack: string | null;
11
13
  }
12
14
  export declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
13
15
  state: AppErrorBoundaryState;
14
16
  static getDerivedStateFromError(error: Error): Partial<AppErrorBoundaryState>;
17
+ constructor(props: AppErrorBoundaryProps);
15
18
  componentDidMount(): void;
16
19
  componentWillUnmount(): void;
17
20
  componentDidCatch(error: Error, info: ErrorInfo): void;
@@ -1 +1 @@
1
- {"version":3,"file":"app-error-boundary.d.ts","sourceRoot":"","sources":["../../src/components/app-error-boundary.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjE,KAAK,WAAW,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;AAWjD,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,WAAW,CAAA;IACnB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAqDD,qBAAa,gBAAiB,SAAQ,SAAS,CAC7C,qBAAqB,EACrB,qBAA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I,IAAI;IAU5B,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAWtD,OAAO,CAAC,iBAAiB,CAMxB;IAED,OAAO,CAAC,wBAAwB,CAK/B;IAED,OAAO,CAAC,MAAM,CAEb;IAED,OAAO,CAAC,WAAW,CAYlB;IAED,MAAM;CA8CP"}
@@ -40,19 +40,26 @@ function reportClientErrorToMoldable(appName, error, source, componentStack) {
40
40
  window.parent.postMessage(message, '*');
41
41
  }
42
42
  export class AppErrorBoundary extends Component {
43
- state = {
44
- error: null,
45
- source: 'react',
46
- componentStack: null,
47
- };
43
+ state;
48
44
  static getDerivedStateFromError(error) {
49
45
  return { error, source: 'react' };
50
46
  }
47
+ constructor(props) {
48
+ super(props);
49
+ this.state = {
50
+ error: props.initialError ?? null,
51
+ source: props.initialSource ?? 'react',
52
+ componentStack: null,
53
+ };
54
+ }
51
55
  componentDidMount() {
52
56
  if (typeof window === 'undefined')
53
57
  return;
54
58
  window.addEventListener('error', this.handleWindowError);
55
59
  window.addEventListener('unhandledrejection', this.handleUnhandledRejection);
60
+ if (this.state.error) {
61
+ reportClientErrorToMoldable(this.props.appName, this.state.error, this.state.source, this.state.componentStack);
62
+ }
56
63
  }
57
64
  componentWillUnmount() {
58
65
  if (typeof window === 'undefined')
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export { useIsMobile } from './hooks/use-mobile';
8
8
  export { Markdown } from './components/markdown';
9
9
  export { RichMediaPlayer, type RichMediaPlayerProps, } from './components/rich-media-player';
10
10
  export { CodeBlock } from './components/code-block';
11
- export { AppErrorBoundary } from './components/app-error-boundary';
11
+ export { AppErrorBoundary, type AppErrorSource, } from './components/app-error-boundary';
12
+ export { installMoldableFrameLifecycle } from './lib/frame-lifecycle';
12
13
  export * from './components/chat';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"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,CAAA;AAGhC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AAG9E,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,GACjB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,EACZ,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EACnC,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAA;AAGvB,cAAc,iBAAiB,CAAA;AAG/B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAA;AAGpB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EACL,eAAe,EACf,KAAK,oBAAoB,GAC1B,MAAM,gCAAgC,CAAA;AAGvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGnD,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,iCAAiC,CAAA;AAGxC,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAA;AAGrE,cAAc,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -18,6 +18,8 @@ export { RichMediaPlayer, } from './components/rich-media-player';
18
18
  // Export CodeBlock
19
19
  export { CodeBlock } from './components/code-block';
20
20
  // Export app error boundary
21
- export { AppErrorBoundary } from './components/app-error-boundary';
21
+ export { AppErrorBoundary, } from './components/app-error-boundary';
22
+ // Export Moldable frame lifecycle
23
+ export { installMoldableFrameLifecycle } from './lib/frame-lifecycle';
22
24
  // Export chat components
23
25
  export * from './components/chat';
@@ -0,0 +1,2 @@
1
+ export declare function installMoldableFrameLifecycle(): void;
2
+ //# sourceMappingURL=frame-lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-lifecycle.d.ts","sourceRoot":"","sources":["../../src/lib/frame-lifecycle.ts"],"names":[],"mappings":"AAgEA,wBAAgB,6BAA6B,IAAI,IAAI,CAapD"}
@@ -0,0 +1,47 @@
1
+ let frameLifecycleInstalled = false;
2
+ function postMoldableFrameMessage(message) {
3
+ if (typeof window === 'undefined' || window.parent === window)
4
+ return;
5
+ window.parent.postMessage(message, '*');
6
+ }
7
+ function reportAppReady(reason) {
8
+ postMoldableFrameMessage({ type: 'moldable:app-ready', reason });
9
+ }
10
+ function scheduleRenderReady() {
11
+ requestAnimationFrame(() => {
12
+ requestAnimationFrame(() => reportAppReady('render'));
13
+ });
14
+ }
15
+ function installViteHmrLifecycle() {
16
+ const hot = import.meta.hot;
17
+ if (!hot)
18
+ return;
19
+ hot.on('vite:beforeUpdate', () => {
20
+ postMoldableFrameMessage({ type: 'moldable:app-hmr-before-update' });
21
+ });
22
+ hot.on('vite:afterUpdate', () => {
23
+ reportAppReady('hmr');
24
+ postMoldableFrameMessage({ type: 'moldable:app-hmr-after-update' });
25
+ });
26
+ hot.on('vite:error', (payload) => {
27
+ postMoldableFrameMessage({
28
+ type: 'moldable:app-hmr-error',
29
+ message: payload.err?.message ??
30
+ payload.message ??
31
+ 'Vite hot reload failed while updating the app.',
32
+ stack: payload.err?.stack,
33
+ });
34
+ });
35
+ }
36
+ export function installMoldableFrameLifecycle() {
37
+ if (typeof window === 'undefined' || frameLifecycleInstalled)
38
+ return;
39
+ frameLifecycleInstalled = true;
40
+ installViteHmrLifecycle();
41
+ scheduleRenderReady();
42
+ if (document.readyState === 'complete') {
43
+ reportAppReady('load');
44
+ return;
45
+ }
46
+ window.addEventListener('load', () => reportAppReady('load'), { once: true });
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moldable-ai/ui",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Shared UI components for Moldable applications",
5
5
  "author": "Desiderata LLC",
6
6
  "license": "SEE LICENSE IN LICENSE",