@solapi/ui-kit 1.0.3 → 1.0.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.
@@ -1,8 +1,11 @@
1
1
  /**
2
2
  * 원격 hook을 안전하게 로드하는 wrapper 생성
3
3
  *
4
- * 전제: createSafeProviderLoader가 로딩 완료까지 children을 렌더하지 않음
5
- * useSafeHook() 호출 시 모듈은 이미 캐시에 있거나, 실패로 확정된 상태
6
- * 캐시에서 동기 조회 원격 hook 또는 fallback 반환
4
+ * 팩토리 호출 시점에 loadModuleSafely를 즉시 트리거하여 모듈 로드를 시작한다.
5
+ * createSafeProviderLoader가 children 렌더를 차단하므로,
6
+ * 실제 hook 호출 시점에는 모듈이 이미 캐시에 있거나 실패로 확정된 상태이다.
7
+ *
8
+ * 동일한 moduleImport 함수 참조를 Provider/Component 로더와 공유하면
9
+ * loadModuleSafely 내부 중복 방지(dedup)로 한 번만 로드된다.
7
10
  */
8
11
  export declare const createSafeHookLoader: <T>(moduleImport: () => Promise<any>, hookName: string, fallback: T) => (() => T);
@@ -2,3 +2,4 @@ export { loadModuleSafely, getModuleFromCache, clearModuleCache, isModuleEmpty,
2
2
  export { createSafeProviderLoader, type SafeProviderLoaderOptions } from './providerLoader';
3
3
  export { createSafeComponentLoader } from './componentLoader';
4
4
  export { createSafeHookLoader } from './hookLoader';
5
+ export { default as FederationErrorBoundary, type FederationErrorBoundaryProps, type FederationErrorInfo } from './FederationErrorBoundary';
@@ -1 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),l=require("react"),d=new Map,h=new Map,C=async e=>{const t=h.get(e);if(t)return t;const o=d.get(e);if(o)return o;const s=e().then(n=>{const c=n?.default||n;return d.set(e,c),c}).catch(n=>(console.error("모듈 로드 실패:",n),d.set(e,{}),{})).finally(()=>{h.delete(e)});return h.set(e,s),s},p=e=>d.get(e)??null,F=e=>{e?(d.delete(e),h.delete(e)):(d.clear(),h.clear())},M=e=>!e||Object.keys(e).length===0,y=(e,t,o)=>{if(!e)return;const n=(e?.default||e)?.[t]??e?.[t];return n||console.error(`[${t}] ${o}를 모듈에서 찾을 수 없습니다.`,"모듈 키:",Object.keys(e||{})),n},b=({message:e})=>r.jsxs("div",{style:{height:"43px",lineHeight:"41px",backgroundColor:"#feebec",color:"#cf3035",textAlign:"center",fontSize:"14px",fontWeight:500,borderBottom:"1px solid #cf3035",zIndex:1e4},children:["⚠️ ",e]}),k=(e,t,o={})=>{const{warningMessage:s}=o;return n=>{const[c,a]=l.useState(null),[S,g]=l.useState(!0),[x,i]=l.useState(!1),u=l.useRef(e);if(u.current=e,l.useEffect(()=>{C(u.current).then(f=>{if(M(f)){i(!0);return}const L=y(f,t,"모듈");L?a(()=>L):i(!0)}).finally(()=>g(!1))},[t]),S)return null;if(x){const f=n?.children;return r.jsxs(r.Fragment,{children:[s&&r.jsx(b,{message:s}),f&&r.jsx("div",{style:{paddingTop:"16px"},children:f})]})}if(c)return r.jsx(c,{...n});const j=n?.children;return j?r.jsx(r.Fragment,{children:j}):null}},v=({componentName:e,children:t})=>r.jsxs("div",{style:{padding:"16px",backgroundColor:"#fff3cd",border:"1px solid #ffc107",borderRadius:"4px"},children:[r.jsxs("p",{style:{fontWeight:500},children:["⚠️ ",e," 컴포넌트를 찾을 수 없습니다."]}),t]}),R=(e,t)=>o=>{const[s,n]=l.useState(null),[c,a]=l.useState(!0),[S,g]=l.useState(!1),x=l.useRef(e);if(x.current=e,l.useEffect(()=>{C(x.current).then(i=>{if(M(i)){g(!0);return}const u=y(i,t,"컴포넌트");u?n(()=>u):g(!0)}).finally(()=>a(!1))},[t]),c){const i=o?.children;return i?r.jsx(r.Fragment,{children:i}):null}if(S||!s){const i=o?.children;return r.jsx(v,{componentName:t,children:i})}return r.jsx(s,{...o})},E=(e,t,o)=>{let s=null,n=!1;return()=>{if(!n){const c=p(e);if(c&&(n=!0,!M(c))){const a=y(c,t,"hook");a&&typeof a=="function"&&(s=a)}}if(s)try{return s()}catch(c){return console.error(`[${t}] 원격 hook 호출 실패, fallback 사용:`,c),o}return o}};exports.clearModuleCache=F;exports.createSafeComponentLoader=R;exports.createSafeHookLoader=E;exports.createSafeProviderLoader=k;exports.findExportInModule=y;exports.getModuleFromCache=p;exports.isModuleEmpty=M;exports.loadModuleSafely=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),c=require("react"),d=new Map,h=new Map,y=async e=>{const r=h.get(e);if(r)return r;const o=d.get(e);if(o)return o;const s=e().then(n=>{const a=n?.default||n;return d.set(e,a),a}).catch(n=>(console.error("모듈 로드 실패:",n),d.set(e,{}),{})).finally(()=>{h.delete(e)});return h.set(e,s),s},k=e=>d.get(e)??null,M=e=>{e?(d.delete(e),h.delete(e)):(d.clear(),h.clear())},b=e=>!e||Object.keys(e).length===0,j=(e,r,o)=>{if(!e)return;const n=(e?.default||e)?.[r]??e?.[r];return n||console.error(`[${r}] ${o}를 모듈에서 찾을 수 없습니다.`,"모듈 키:",Object.keys(e||{})),n},R=({message:e})=>t.jsxs("div",{style:{height:"43px",lineHeight:"41px",backgroundColor:"#feebec",color:"#cf3035",textAlign:"center",fontSize:"14px",fontWeight:500,borderBottom:"1px solid #cf3035",zIndex:1e4},children:["⚠️ ",e]}),F=(e,r,o={})=>{const{warningMessage:s}=o;return n=>{const[a,l]=c.useState(null),[S,g]=c.useState(!0),[x,i]=c.useState(!1),u=c.useRef(e);if(u.current=e,c.useEffect(()=>{y(u.current).then(f=>{if(b(f)){i(!0);return}const C=j(f,r,"모듈");C?l(()=>C):i(!0)}).finally(()=>g(!1))},[r]),S)return null;if(x){const f=n?.children;return t.jsxs(t.Fragment,{children:[s&&t.jsx(R,{message:s}),f&&t.jsx("div",{style:{paddingTop:"16px"},children:f})]})}if(a)return t.jsx(a,{...n});const v=n?.children;return v?t.jsx(t.Fragment,{children:v}):null}},L=({componentName:e,children:r})=>t.jsxs("div",{style:{padding:"16px",backgroundColor:"#fff3cd",border:"1px solid #ffc107",borderRadius:"4px"},children:[t.jsxs("p",{style:{fontWeight:500},children:["⚠️ ",e," 컴포넌트를 찾을 수 없습니다."]}),r]}),_=(e,r)=>o=>{const[s,n]=c.useState(null),[a,l]=c.useState(!0),[S,g]=c.useState(!1),x=c.useRef(e);if(x.current=e,c.useEffect(()=>{y(x.current).then(i=>{if(b(i)){g(!0);return}const u=j(i,r,"컴포넌트");u?n(()=>u):g(!0)}).finally(()=>l(!1))},[r]),a){const i=o?.children;return i?t.jsx(t.Fragment,{children:i}):null}if(S||!s){const i=o?.children;return t.jsx(L,{componentName:r,children:i})}return t.jsx(s,{...o})},E=(e,r,o)=>{let s=null,n=!1;return y(e),()=>{if(!n){const a=k(e);if(a&&(n=!0,!b(a))){const l=j(a,r,"hook");l&&typeof l=="function"&&(s=l)}}if(s)try{return s()}catch(a){return console.error(`[${r}] 원격 hook 호출 실패, fallback 사용:`,a),o}return o}},m="_root_16oj8_1 _base_1tubv_6",D="_message_16oj8_14",w="_errorDetails_16oj8_22",z="_actions_16oj8_38",p={root:m,message:D,errorDetails:w,actions:z};class P extends c.Component{constructor(r){super(r),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,o){this.setState({errorInfo:o}),this.props.onError?.(r,o)}handleRetry=()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onRetry?.()};handleReload=()=>{window.location.reload()};render(){if(!this.state.hasError)return this.props.children;const{error:r,errorInfo:o}=this.state,{fallback:s,showDetails:n=!1,message:a}=this.props;return s?t.jsx(s,{error:r,onRetry:this.handleRetry,onReload:this.handleReload}):t.jsxs("div",{className:p.root,children:[t.jsx("div",{className:p.message,children:a||"모듈을 로드하는 중 오류가 발생했습니다."}),n&&r&&t.jsxs("div",{className:p.errorDetails,children:[r.toString(),o?.componentStack&&`
2
+ ${o.componentStack}`]}),t.jsxs("div",{className:p.actions,children:[t.jsx("button",{type:"button",onClick:this.handleRetry,style:{padding:"6px 16px",fontSize:"14px",fontWeight:500,border:"1px solid var(--color-border, #ddd)",borderRadius:"var(--border-radius-sm, 4px)",background:"var(--color-background, #fff)",color:"var(--color-text, #333)",cursor:"pointer"},children:"재시도"}),t.jsx("button",{type:"button",onClick:this.handleReload,style:{padding:"6px 16px",fontSize:"14px",fontWeight:500,border:"none",borderRadius:"var(--border-radius-sm, 4px)",background:"var(--color-primary, #5780ff)",color:"#fff",cursor:"pointer"},children:"새로고침"})]})]})}}exports.FederationErrorBoundary=P;exports.clearModuleCache=M;exports.createSafeComponentLoader=_;exports.createSafeHookLoader=E;exports.createSafeProviderLoader=F;exports.findExportInModule=j;exports.getModuleFromCache=k;exports.isModuleEmpty=b;exports.loadModuleSafely=y;
@@ -1,28 +1,28 @@
1
- import { jsxs as y, Fragment as M, jsx as l } from "react/jsx-runtime";
2
- import { useState as d, useRef as F, useEffect as v } from "react";
3
- const a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), S = async (e) => {
4
- const n = h.get(e);
5
- if (n) return n;
6
- const r = a.get(e);
1
+ import { jsxs as l, Fragment as k, jsx as i } from "react/jsx-runtime";
2
+ import { useState as d, useRef as M, useEffect as F, Component as L } from "react";
3
+ const u = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), v = async (e) => {
4
+ const r = p.get(e);
7
5
  if (r) return r;
8
- const o = e().then((t) => {
9
- const c = t?.default || t;
10
- return a.set(e, c), c;
11
- }).catch((t) => (console.error("모듈 로드 실패:", t), a.set(e, {}), {})).finally(() => {
12
- h.delete(e);
6
+ const t = u.get(e);
7
+ if (t) return t;
8
+ const n = e().then((o) => {
9
+ const s = o?.default || o;
10
+ return u.set(e, s), s;
11
+ }).catch((o) => (console.error("모듈 로드 실패:", o), u.set(e, {}), {})).finally(() => {
12
+ p.delete(e);
13
13
  });
14
- return h.set(e, o), o;
15
- }, j = (e) => a.get(e) ?? null, H = (e) => {
16
- e ? (a.delete(e), h.delete(e)) : (a.clear(), h.clear());
17
- }, L = (e) => !e || Object.keys(e).length === 0, p = (e, n, r) => {
14
+ return p.set(e, n), n;
15
+ }, E = (e) => u.get(e) ?? null, H = (e) => {
16
+ e ? (u.delete(e), p.delete(e)) : (u.clear(), p.clear());
17
+ }, C = (e) => !e || Object.keys(e).length === 0, R = (e, r, t) => {
18
18
  if (!e) return;
19
- const t = (e?.default || e)?.[n] ?? e?.[n];
20
- return t || console.error(
21
- `[${n}] ${r}를 모듈에서 찾을 수 없습니다.`,
19
+ const o = (e?.default || e)?.[r] ?? e?.[r];
20
+ return o || console.error(
21
+ `[${r}] ${t}를 모듈에서 찾을 수 없습니다.`,
22
22
  "모듈 키:",
23
23
  Object.keys(e || {})
24
- ), t;
25
- }, R = ({ message: e }) => /* @__PURE__ */ y(
24
+ ), o;
25
+ }, j = ({ message: e }) => /* @__PURE__ */ l(
26
26
  "div",
27
27
  {
28
28
  style: {
@@ -41,92 +41,177 @@ const a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), S = async (e
41
41
  e
42
42
  ]
43
43
  }
44
- ), P = (e, n, r = {}) => {
45
- const { warningMessage: o } = r;
46
- return (t) => {
47
- const [c, i] = d(null), [C, g] = d(!0), [x, s] = d(!1), f = F(e);
48
- if (f.current = e, v(() => {
49
- S(f.current).then((u) => {
50
- if (L(u)) {
51
- s(!0);
44
+ ), P = (e, r, t = {}) => {
45
+ const { warningMessage: n } = t;
46
+ return (o) => {
47
+ const [s, a] = d(null), [x, g] = d(!0), [b, c] = d(!1), f = M(e);
48
+ if (f.current = e, F(() => {
49
+ v(f.current).then((h) => {
50
+ if (C(h)) {
51
+ c(!0);
52
52
  return;
53
53
  }
54
- const k = p(u, n, "모듈");
55
- k ? i(() => k) : s(!0);
54
+ const S = R(h, r, "모듈");
55
+ S ? a(() => S) : c(!0);
56
56
  }).finally(() => g(!1));
57
- }, [n]), C) return null;
58
- if (x) {
59
- const u = t?.children;
60
- return /* @__PURE__ */ y(M, { children: [
61
- o && /* @__PURE__ */ l(R, { message: o }),
62
- u && /* @__PURE__ */ l("div", { style: { paddingTop: "16px" }, children: u })
57
+ }, [r]), x) return null;
58
+ if (b) {
59
+ const h = o?.children;
60
+ return /* @__PURE__ */ l(k, { children: [
61
+ n && /* @__PURE__ */ i(j, { message: n }),
62
+ h && /* @__PURE__ */ i("div", { style: { paddingTop: "16px" }, children: h })
63
63
  ] });
64
64
  }
65
- if (c) return /* @__PURE__ */ l(c, { ...t });
66
- const b = t?.children;
67
- return b ? /* @__PURE__ */ l(M, { children: b }) : null;
65
+ if (s) return /* @__PURE__ */ i(s, { ...o });
66
+ const _ = o?.children;
67
+ return _ ? /* @__PURE__ */ i(k, { children: _ }) : null;
68
68
  };
69
- }, w = ({
69
+ }, m = ({
70
70
  componentName: e,
71
- children: n
72
- }) => /* @__PURE__ */ y("div", { style: {
71
+ children: r
72
+ }) => /* @__PURE__ */ l("div", { style: {
73
73
  padding: "16px",
74
74
  backgroundColor: "#fff3cd",
75
75
  border: "1px solid #ffc107",
76
76
  borderRadius: "4px"
77
77
  }, children: [
78
- /* @__PURE__ */ y("p", { style: { fontWeight: 500 }, children: [
78
+ /* @__PURE__ */ l("p", { style: { fontWeight: 500 }, children: [
79
79
  "⚠️ ",
80
80
  e,
81
81
  " 컴포넌트를 찾을 수 없습니다."
82
82
  ] }),
83
- n
84
- ] }), T = (e, n) => (r) => {
85
- const [o, t] = d(null), [c, i] = d(!0), [C, g] = d(!1), x = F(e);
86
- if (x.current = e, v(() => {
87
- S(x.current).then((s) => {
88
- if (L(s)) {
83
+ r
84
+ ] }), T = (e, r) => (t) => {
85
+ const [n, o] = d(null), [s, a] = d(!0), [x, g] = d(!1), b = M(e);
86
+ if (b.current = e, F(() => {
87
+ v(b.current).then((c) => {
88
+ if (C(c)) {
89
89
  g(!0);
90
90
  return;
91
91
  }
92
- const f = p(s, n, "컴포넌트");
93
- f ? t(() => f) : g(!0);
94
- }).finally(() => i(!1));
95
- }, [n]), c) {
96
- const s = r?.children;
97
- return s ? /* @__PURE__ */ l(M, { children: s }) : null;
92
+ const f = R(c, r, "컴포넌트");
93
+ f ? o(() => f) : g(!0);
94
+ }).finally(() => a(!1));
95
+ }, [r]), s) {
96
+ const c = t?.children;
97
+ return c ? /* @__PURE__ */ i(k, { children: c }) : null;
98
98
  }
99
- if (C || !o) {
100
- const s = r?.children;
101
- return /* @__PURE__ */ l(w, { componentName: n, children: s });
99
+ if (x || !n) {
100
+ const c = t?.children;
101
+ return /* @__PURE__ */ i(m, { componentName: r, children: c });
102
102
  }
103
- return /* @__PURE__ */ l(o, { ...r });
104
- }, W = (e, n, r) => {
105
- let o = null, t = !1;
106
- return () => {
107
- if (!t) {
108
- const c = j(e);
109
- if (c && (t = !0, !L(c))) {
110
- const i = p(c, n, "hook");
111
- i && typeof i == "function" && (o = i);
103
+ return /* @__PURE__ */ i(n, { ...t });
104
+ }, K = (e, r, t) => {
105
+ let n = null, o = !1;
106
+ return v(e), () => {
107
+ if (!o) {
108
+ const s = E(e);
109
+ if (s && (o = !0, !C(s))) {
110
+ const a = R(s, r, "hook");
111
+ a && typeof a == "function" && (n = a);
112
112
  }
113
113
  }
114
- if (o)
114
+ if (n)
115
115
  try {
116
- return o();
117
- } catch (c) {
118
- return console.error(`[${n}] 원격 hook 호출 실패, fallback 사용:`, c), r;
116
+ return n();
117
+ } catch (s) {
118
+ return console.error(`[${r}] 원격 hook 호출 실패, fallback 사용:`, s), t;
119
119
  }
120
- return r;
120
+ return t;
121
121
  };
122
+ }, D = "_root_16oj8_1 _base_1tubv_6", w = "_message_16oj8_14", z = "_errorDetails_16oj8_22", W = "_actions_16oj8_38", y = {
123
+ root: D,
124
+ message: w,
125
+ errorDetails: z,
126
+ actions: W
122
127
  };
128
+ class O extends L {
129
+ constructor(r) {
130
+ super(r), this.state = { hasError: !1, error: null, errorInfo: null };
131
+ }
132
+ static getDerivedStateFromError(r) {
133
+ return { hasError: !0, error: r };
134
+ }
135
+ componentDidCatch(r, t) {
136
+ this.setState({ errorInfo: t }), this.props.onError?.(r, t);
137
+ }
138
+ handleRetry = () => {
139
+ this.setState({ hasError: !1, error: null, errorInfo: null }), this.props.onRetry?.();
140
+ };
141
+ handleReload = () => {
142
+ window.location.reload();
143
+ };
144
+ render() {
145
+ if (!this.state.hasError)
146
+ return this.props.children;
147
+ const { error: r, errorInfo: t } = this.state, {
148
+ fallback: n,
149
+ showDetails: o = !1,
150
+ message: s
151
+ } = this.props;
152
+ return n ? /* @__PURE__ */ i(
153
+ n,
154
+ {
155
+ error: r,
156
+ onRetry: this.handleRetry,
157
+ onReload: this.handleReload
158
+ }
159
+ ) : /* @__PURE__ */ l("div", { className: y.root, children: [
160
+ /* @__PURE__ */ i("div", { className: y.message, children: s || "모듈을 로드하는 중 오류가 발생했습니다." }),
161
+ o && r && /* @__PURE__ */ l("div", { className: y.errorDetails, children: [
162
+ r.toString(),
163
+ t?.componentStack && `
164
+ ${t.componentStack}`
165
+ ] }),
166
+ /* @__PURE__ */ l("div", { className: y.actions, children: [
167
+ /* @__PURE__ */ i(
168
+ "button",
169
+ {
170
+ type: "button",
171
+ onClick: this.handleRetry,
172
+ style: {
173
+ padding: "6px 16px",
174
+ fontSize: "14px",
175
+ fontWeight: 500,
176
+ border: "1px solid var(--color-border, #ddd)",
177
+ borderRadius: "var(--border-radius-sm, 4px)",
178
+ background: "var(--color-background, #fff)",
179
+ color: "var(--color-text, #333)",
180
+ cursor: "pointer"
181
+ },
182
+ children: "재시도"
183
+ }
184
+ ),
185
+ /* @__PURE__ */ i(
186
+ "button",
187
+ {
188
+ type: "button",
189
+ onClick: this.handleReload,
190
+ style: {
191
+ padding: "6px 16px",
192
+ fontSize: "14px",
193
+ fontWeight: 500,
194
+ border: "none",
195
+ borderRadius: "var(--border-radius-sm, 4px)",
196
+ background: "var(--color-primary, #5780ff)",
197
+ color: "#fff",
198
+ cursor: "pointer"
199
+ },
200
+ children: "새로고침"
201
+ }
202
+ )
203
+ ] })
204
+ ] });
205
+ }
206
+ }
123
207
  export {
208
+ O as FederationErrorBoundary,
124
209
  H as clearModuleCache,
125
210
  T as createSafeComponentLoader,
126
- W as createSafeHookLoader,
211
+ K as createSafeHookLoader,
127
212
  P as createSafeProviderLoader,
128
- p as findExportInModule,
129
- j as getModuleFromCache,
130
- L as isModuleEmpty,
131
- S as loadModuleSafely
213
+ R as findExportInModule,
214
+ E as getModuleFromCache,
215
+ C as isModuleEmpty,
216
+ v as loadModuleSafely
132
217
  };