@empjs/bridge-vue3 0.0.3 → 4.0.0-alpha.1

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/README.md CHANGED
@@ -1,13 +1,14 @@
1
- # EMP Bridge React
1
+ # EMP Bridge Vue3
2
2
 
3
- EMP Bridge React 是一个用于跨 React 版本组件通信的桥接工具,它解决了不同 React 版本之间组件共享和通信的问题。
3
+ EMP Bridge Vue 是一个用于在 React 应用中集成 Vue3 组件的桥接工具,它解决了 React 与 Vue 之间组件共享和通信的问题。
4
4
 
5
5
  ## 功能特点
6
6
 
7
- - 支持不同 React 版本(16/17/18/19)之间的组件共享
7
+ - 支持在 React 应用中使用 Vue 组件
8
8
  - 提供简单的 API 用于生产者和消费者之间的通信
9
- - 自动处理 React 不同版本的渲染和卸载方法差异
10
- - 支持异步加载组件
9
+ - 自动处理 React 与 Vue 之间的渲染和卸载方法差异
10
+ - 支持插件系统扩展 Vue 功能
11
+
11
12
 
12
13
  ## 安装
13
14
 
package/dist/index.cjs CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -13,7 +17,7 @@ var __webpack_require__ = {};
13
17
  })();
14
18
  (()=>{
15
19
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
21
  value: 'Module'
18
22
  });
19
23
  Object.defineProperty(exports1, '__esModule', {
@@ -23,11 +27,6 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- createBridgeComponent: ()=>createBridgeComponent,
28
- createRemoteAppComponent: ()=>createRemoteAppComponent,
29
- default: ()=>__WEBPACK_DEFAULT_EXPORT__
30
- });
31
30
  function createBridgeComponent(Component, options) {
32
31
  const { createApp } = options.Vue;
33
32
  return function() {
@@ -70,7 +69,7 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
70
69
  if (!component) throw new Error('createRemoteAppComponent: component parameter cannot be empty');
71
70
  const { Vue } = vueOptions;
72
71
  return defineComponent({
73
- name: 'RemoteAppComponent',
72
+ name: 'Vue3RemoteAppComponent',
74
73
  props: {},
75
74
  setup () {
76
75
  const provider = ref(null);
@@ -119,7 +118,7 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
119
118
  onBeforeUnmount(()=>{
120
119
  isMounted.value = false;
121
120
  const cleanup = ()=>unmountComponent();
122
- if ('undefined' != typeof window && window.requestAnimationFrame) window.requestAnimationFrame(cleanup);
121
+ if ("u" > typeof window && window.requestAnimationFrame) window.requestAnimationFrame(cleanup);
123
122
  else setTimeout(cleanup, 0);
124
123
  });
125
124
  loadComponent();
@@ -148,18 +147,24 @@ function onBeforeUnmount(fn) {}
148
147
  function getCurrentInstance() {
149
148
  return null;
150
149
  }
151
- const __WEBPACK_DEFAULT_EXPORT__ = {
150
+ const __rspack_default_export = {
152
151
  createBridgeComponent,
153
152
  createRemoteAppComponent
154
153
  };
154
+ __webpack_require__.d(__webpack_exports__, {
155
+ createBridgeComponent: ()=>createBridgeComponent,
156
+ createRemoteAppComponent: ()=>createRemoteAppComponent
157
+ }, {
158
+ default: __rspack_default_export
159
+ });
155
160
  exports.createBridgeComponent = __webpack_exports__.createBridgeComponent;
156
161
  exports.createRemoteAppComponent = __webpack_exports__.createRemoteAppComponent;
157
162
  exports["default"] = __webpack_exports__["default"];
158
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
163
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
159
164
  "createBridgeComponent",
160
165
  "createRemoteAppComponent",
161
166
  "default"
162
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
167
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
163
168
  Object.defineProperty(exports, '__esModule', {
164
169
  value: true
165
170
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["webpack://@empjs/bridge-vue3/webpack/runtime/define_property_getters","webpack://@empjs/bridge-vue3/webpack/runtime/has_own_property","webpack://@empjs/bridge-vue3/webpack/runtime/make_namespace_object","webpack://@empjs/bridge-vue3/./src/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// Type definitions\nexport interface BridgeProviderReturn {\n render: (dom: HTMLElement, props?: Record<string, any>) => void\n destroy: (dom: HTMLElement) => void\n}\n\nexport type BridgeProvider = () => BridgeProviderReturn\nexport type AsyncBridgeProvider = () => Promise<{default: BridgeProvider}>\nexport type ComponentProvider = BridgeProvider | AsyncBridgeProvider\n\ninterface Vue3Options {\n Vue?: any\n plugin?: (app: any) => void\n}\n\n/**\n * Create bridge component - for producer to wrap application-level export modules\n */\nexport function createBridgeComponent(Component: any, options: Vue3Options): BridgeProvider {\n const {createApp} = options.Vue\n\n return function (): BridgeProviderReturn {\n const appMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n try {\n const existingApp = appMap.get(dom)\n\n if (existingApp) {\n // Update props for existing app\n if (props) {\n Object.keys(props).forEach(key => {\n existingApp._instance.props[key] = props[key]\n })\n }\n } else {\n // Create new app instance\n const app = createApp(Component, props || {})\n\n // 使用自定义插件(如果提供)\n if (options.plugin) {\n options.plugin(app)\n }\n\n app.mount(dom)\n appMap.set(dom, app)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render/update Vue component', error)\n throw error\n }\n }\n\n const destroy = (dom: HTMLElement): void => {\n const app = appMap.get(dom)\n if (!app) return\n\n try {\n app.unmount()\n appMap.delete(dom)\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\n/**\n * Create remote app component - for consumer to load application-level modules\n */\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue3Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n const {Vue} = vueOptions\n\n return defineComponent({\n name: 'RemoteAppComponent',\n props: {},\n setup() {\n const provider = ref<BridgeProviderReturn | null>(null)\n const providerInfo = ref<BridgeProvider | null>(null)\n const isMounted = ref(false)\n const containerRef = ref<HTMLElement | null>(null)\n\n const loadComponent = async () => {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n providerInfo.value = module.default\n } else {\n providerInfo.value = component as BridgeProvider\n }\n }\n\n if (isMounted.value && containerRef.value) {\n renderComponent()\n }\n } catch (error) {\n if (options.onError) options.onError(error as Error)\n console.error('[EMP-ERROR] Failed to load component', error)\n }\n }\n\n const renderComponent = () => {\n if (!providerInfo.value || !containerRef.value) return\n\n try {\n if (!provider.value) {\n provider.value = providerInfo.value()\n }\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n }\n }\n\n const unmountComponent = () => {\n if (provider.value && containerRef.value) {\n try {\n provider.value.destroy(containerRef.value)\n provider.value = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n }\n\n onMounted(() => {\n isMounted.value = true\n if (providerInfo.value) renderComponent()\n })\n\n onUpdated(() => {\n if (provider.value && containerRef.value) {\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n }\n })\n\n onBeforeUnmount(() => {\n isMounted.value = false\n const cleanup = () => unmountComponent()\n\n if (typeof window !== 'undefined' && window.requestAnimationFrame) {\n window.requestAnimationFrame(cleanup)\n } else {\n setTimeout(cleanup, 0)\n }\n })\n\n // 立即加载组件\n loadComponent()\n\n return {\n containerRef,\n }\n },\n render() {\n return Vue.h('div', {ref: 'containerRef'})\n },\n })\n}\n\n// 添加必要的导入声明\nfunction defineComponent(options: any): any {\n return options\n}\n\nfunction ref<T>(initialValue?: T): {value: T | null} {\n return {value: initialValue || null}\n}\n\nfunction onMounted(fn: () => void): void {}\nfunction onUpdated(fn: () => void): void {}\nfunction onBeforeUnmount(fn: () => void): void {}\nfunction getCurrentInstance(): {props: Record<string, any>} | null {\n return null\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","createBridgeComponent","Component","options","createApp","appMap","Map","render","dom","props","existingApp","app","error","console","destroy","createRemoteAppComponent","component","vueOptions","Error","Vue","defineComponent","provider","ref","providerInfo","isMounted","containerRef","loadComponent","result","Promise","module","renderComponent","getCurrentInstance","unmountComponent","onMounted","onUpdated","onBeforeUnmount","cleanup","window","setTimeout","initialValue","fn"],"mappings":";;;IAAAA,oBAAoB,CAAC,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BACdC,QAAQ,KAAK,CAAC,0CAA0CD;gBAC1D;YACF;YAEA,MAAMoB,mBAAmB;gBACvB,IAAIX,SAAS,KAAK,IAAII,aAAa,KAAK,EACtC,IAAI;oBACFJ,SAAS,KAAK,CAAC,OAAO,CAACI,aAAa,KAAK;oBACzCJ,SAAS,KAAK,GAAG;gBACnB,EAAE,OAAOT,OAAO;oBACdC,QAAQ,KAAK,CAAC,2CAA2CD;gBAC3D;YAEJ;YAEAqB,UAAU;gBACRT,UAAU,KAAK,GAAG;gBAClB,IAAID,aAAa,KAAK,EAAEO;YAC1B;YAEAI,UAAU;gBACR,IAAIb,SAAS,KAAK,IAAII,aAAa,KAAK,EACtCJ,SAAS,KAAK,CAAC,MAAM,CAACI,aAAa,KAAK,EAAEM,sBAAsB,SAAS,CAAC;YAE9E;YAEAI,gBAAgB;gBACdX,UAAU,KAAK,GAAG;gBAClB,MAAMY,UAAU,IAAMJ;gBAEtB,IAAI,AAAkB,eAAlB,OAAOK,UAA0BA,OAAO,qBAAqB,EAC/DA,OAAO,qBAAqB,CAACD;qBAE7BE,WAAWF,SAAS;YAExB;YAGAV;YAEA,OAAO;gBACLD;YACF;QACF;QACA;YACE,OAAON,IAAI,CAAC,CAAC,OAAO;gBAAC,KAAK;YAAc;QAC1C;IACF;AACF;AAGA,SAASC,gBAAgBjB,OAAY;IACnC,OAAOA;AACT;AAEA,SAASmB,IAAOiB,YAAgB;IAC9B,OAAO;QAAC,OAAOA,gBAAgB;IAAI;AACrC;AAEA,SAASN,UAAUO,EAAc,GAAS;AAC1C,SAASN,UAAUM,EAAc,GAAS;AAC1C,SAASL,gBAAgBK,EAAc,GAAS;AAChD,SAAST;IACP,OAAO;AACT;AAEA,mCAAe;IACb9B;IACAc;AACF"}
1
+ {"version":3,"file":"index.cjs","sources":["webpack://webpack/runtime/define_property_getters","webpack://webpack/runtime/has_own_property","webpack://webpack/runtime/make_namespace_object","../src/index.ts"],"sourcesContent":["__webpack_require__.d = (exports, getters, values) => {\n\tvar define = (defs, kind) => {\n\t\tfor(var key in defs) {\n\t\t\tif(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {\n\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });\n\t\t\t}\n\t\t}\n\t};\n\tdefine(getters, \"get\");\n\tdefine(values, \"value\");\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// Type definitions\nexport interface BridgeProviderReturn {\n render: (dom: HTMLElement, props?: Record<string, any>) => void\n destroy: (dom: HTMLElement) => void\n}\n\nexport type BridgeProvider = () => BridgeProviderReturn\nexport type AsyncBridgeProvider = () => Promise<{default: BridgeProvider}>\nexport type ComponentProvider = BridgeProvider | AsyncBridgeProvider\n\ninterface Vue3Options {\n Vue?: any\n plugin?: (app: any) => void\n}\n\n/**\n * Create bridge component - for producer to wrap application-level export modules\n */\nexport function createBridgeComponent(Component: any, options: Vue3Options): BridgeProvider {\n const {createApp} = options.Vue\n\n return function (): BridgeProviderReturn {\n const appMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n try {\n const existingApp = appMap.get(dom)\n\n if (existingApp) {\n // Update props for existing app\n if (props) {\n Object.keys(props).forEach(key => {\n existingApp._instance.props[key] = props[key]\n })\n }\n } else {\n // Create new app instance\n const app = createApp(Component, props || {})\n\n // 使用自定义插件(如果提供)\n if (options.plugin) {\n options.plugin(app)\n }\n\n app.mount(dom)\n appMap.set(dom, app)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render/update Vue component', error)\n throw error\n }\n }\n\n const destroy = (dom: HTMLElement): void => {\n const app = appMap.get(dom)\n if (!app) return\n\n try {\n app.unmount()\n appMap.delete(dom)\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\n/**\n * Create remote app component - for consumer to load application-level modules\n */\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue3Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n const {Vue} = vueOptions\n\n return defineComponent({\n name: 'Vue3RemoteAppComponent',\n props: {},\n setup() {\n const provider = ref<BridgeProviderReturn | null>(null)\n const providerInfo = ref<BridgeProvider | null>(null)\n const isMounted = ref(false)\n const containerRef = ref<HTMLElement | null>(null)\n\n const loadComponent = async () => {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n providerInfo.value = module.default\n } else {\n providerInfo.value = component as BridgeProvider\n }\n }\n\n if (isMounted.value && containerRef.value) {\n renderComponent()\n }\n } catch (error) {\n if (options.onError) options.onError(error as Error)\n console.error('[EMP-ERROR] Failed to load component', error)\n }\n }\n\n const renderComponent = () => {\n if (!providerInfo.value || !containerRef.value) return\n\n try {\n if (!provider.value) {\n provider.value = providerInfo.value()\n }\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n }\n }\n\n const unmountComponent = () => {\n if (provider.value && containerRef.value) {\n try {\n provider.value.destroy(containerRef.value)\n provider.value = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n }\n\n onMounted(() => {\n isMounted.value = true\n if (providerInfo.value) renderComponent()\n })\n\n onUpdated(() => {\n if (provider.value && containerRef.value) {\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n }\n })\n\n onBeforeUnmount(() => {\n isMounted.value = false\n const cleanup = () => unmountComponent()\n\n if (typeof window !== 'undefined' && window.requestAnimationFrame) {\n window.requestAnimationFrame(cleanup)\n } else {\n setTimeout(cleanup, 0)\n }\n })\n\n // 立即加载组件\n loadComponent()\n\n return {\n containerRef,\n }\n },\n render() {\n return Vue.h('div', {ref: 'containerRef'})\n },\n })\n}\n\n// 添加必要的导入声明\nfunction defineComponent(options: any): any {\n return options\n}\n\nfunction ref<T>(initialValue?: T): {value: T | null} {\n return {value: initialValue || null}\n}\n\nfunction onMounted(fn: () => void): void {}\nfunction onUpdated(fn: () => void): void {}\nfunction onBeforeUnmount(fn: () => void): void {}\nfunction getCurrentInstance(): {props: Record<string, any>} | null {\n return null\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["__webpack_require__","getters","values","define","defs","kind","key","Object","obj","prop","Symbol","createBridgeComponent","Component","options","createApp","appMap","Map","render","dom","props","existingApp","app","error","console","destroy","createRemoteAppComponent","component","vueOptions","Error","Vue","defineComponent","provider","ref","providerInfo","isMounted","containerRef","loadComponent","result","Promise","module","renderComponent","getCurrentInstance","unmountComponent","onMounted","onUpdated","onBeforeUnmount","cleanup","window","setTimeout","initialValue","fn"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC,SAASC;QAC1C,IAAIC,SAAS,CAACC,MAAMC;YACnB,IAAI,IAAIC,OAAOF,KACd,IAAGJ,oBAAoB,CAAC,CAACI,MAAME,QAAQ,CAACN,oBAAoB,CAAC,CAAC,UAASM,MACtEC,OAAO,cAAc,CAAC,UAASD,KAAK;gBAAE,YAAY;gBAAM,CAACD,KAAK,EAAED,IAAI,CAACE,IAAI;YAAC;QAG7E;QACAH,OAAOF,SAAS;QAChBE,OAAOD,QAAQ;IAChB;;;ICVAF,oBAAoB,CAAC,GAAG,CAACQ,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFT,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,MAAlB,OAAOU,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE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K,EAAEM,sBAAsB,SAAS,CAAC;YAE9E;YAEAI,gBAAgB;gBACdX,UAAU,KAAK,GAAG;gBAClB,MAAMY,UAAU,IAAMJ;gBAEtB,IAAI,AAAkB,MAAlB,OAAOK,UAA0BA,OAAO,qBAAqB,EAC/DA,OAAO,qBAAqB,CAACD;qBAE7BE,WAAWF,SAAS;YAExB;YAGAV;YAEA,OAAO;gBACLD;YACF;QACF;QACA;YACE,OAAON,IAAI,CAAC,CAAC,OAAO;gBAAC,KAAK;YAAc;QAC1C;IACF;AACF;AAGA,SAASC,gBAAgBjB,OAAY;IACnC,OAAOA;AACT;AAEA,SAASmB,IAAOiB,YAAgB;IAC9B,OAAO;QAAC,OAAOA,gBAAgB;IAAI;AACrC;AAEA,SAASN,UAAUO,EAAc,GAAS;AAC1C,SAASN,UAAUM,EAAc,GAAS;AAC1C,SAASL,gBAAgBK,EAAc,GAAS;AAChD,SAAST;IACP,OAAO;AACT;AAEA,gCAAe;IACb9B;IACAc;AACF"}
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
40
40
  if (!component) throw new Error('createRemoteAppComponent: component parameter cannot be empty');
41
41
  const { Vue } = vueOptions;
42
42
  return defineComponent({
43
- name: 'RemoteAppComponent',
43
+ name: 'Vue3RemoteAppComponent',
44
44
  props: {},
45
45
  setup () {
46
46
  const provider = ref(null);
@@ -89,7 +89,7 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
89
89
  onBeforeUnmount(()=>{
90
90
  isMounted.value = false;
91
91
  const cleanup = ()=>unmountComponent();
92
- if ('undefined' != typeof window && window.requestAnimationFrame) window.requestAnimationFrame(cleanup);
92
+ if ("u" > typeof window && window.requestAnimationFrame) window.requestAnimationFrame(cleanup);
93
93
  else setTimeout(cleanup, 0);
94
94
  });
95
95
  loadComponent();
@@ -119,9 +119,10 @@ function getCurrentInstance() {
119
119
  return null;
120
120
  }
121
121
  const src = {
122
- createBridgeComponent,
123
- createRemoteAppComponent
122
+ createBridgeComponent: createBridgeComponent,
123
+ createRemoteAppComponent: createRemoteAppComponent
124
124
  };
125
- export { createBridgeComponent, createRemoteAppComponent, src as default };
125
+ export default src;
126
+ export { createBridgeComponent, createRemoteAppComponent };
126
127
 
127
128
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["webpack://@empjs/bridge-vue3/./src/index.ts"],"sourcesContent":["// Type definitions\nexport interface BridgeProviderReturn {\n render: (dom: HTMLElement, props?: Record<string, any>) => void\n destroy: (dom: HTMLElement) => void\n}\n\nexport type BridgeProvider = () => BridgeProviderReturn\nexport type AsyncBridgeProvider = () => Promise<{default: BridgeProvider}>\nexport type ComponentProvider = BridgeProvider | AsyncBridgeProvider\n\ninterface Vue3Options {\n Vue?: any\n plugin?: (app: any) => void\n}\n\n/**\n * Create bridge component - for producer to wrap application-level export modules\n */\nexport function createBridgeComponent(Component: any, options: Vue3Options): BridgeProvider {\n const {createApp} = options.Vue\n\n return function (): BridgeProviderReturn {\n const appMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n try {\n const existingApp = appMap.get(dom)\n\n if (existingApp) {\n // Update props for existing app\n if (props) {\n Object.keys(props).forEach(key => {\n existingApp._instance.props[key] = props[key]\n })\n }\n } else {\n // Create new app instance\n const app = createApp(Component, props || {})\n\n // 使用自定义插件(如果提供)\n if (options.plugin) {\n options.plugin(app)\n }\n\n app.mount(dom)\n appMap.set(dom, app)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render/update Vue component', error)\n throw error\n }\n }\n\n const destroy = (dom: HTMLElement): void => {\n const app = appMap.get(dom)\n if (!app) return\n\n try {\n app.unmount()\n appMap.delete(dom)\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\n/**\n * Create remote app component - for consumer to load application-level modules\n */\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue3Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n const {Vue} = vueOptions\n\n return defineComponent({\n name: 'RemoteAppComponent',\n props: {},\n setup() {\n const provider = ref<BridgeProviderReturn | null>(null)\n const providerInfo = ref<BridgeProvider | null>(null)\n const isMounted = ref(false)\n const containerRef = ref<HTMLElement | null>(null)\n\n const loadComponent = async () => {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n providerInfo.value = module.default\n } else {\n providerInfo.value = component as BridgeProvider\n }\n }\n\n if (isMounted.value && containerRef.value) {\n renderComponent()\n }\n } catch (error) {\n if (options.onError) options.onError(error as Error)\n console.error('[EMP-ERROR] Failed to load component', error)\n }\n }\n\n const renderComponent = () => {\n if (!providerInfo.value || !containerRef.value) return\n\n try {\n if (!provider.value) {\n provider.value = providerInfo.value()\n }\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n }\n }\n\n const unmountComponent = () => {\n if (provider.value && containerRef.value) {\n try {\n provider.value.destroy(containerRef.value)\n provider.value = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n }\n\n onMounted(() => {\n isMounted.value = true\n if (providerInfo.value) renderComponent()\n })\n\n onUpdated(() => {\n if (provider.value && containerRef.value) {\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n }\n })\n\n onBeforeUnmount(() => {\n isMounted.value = false\n const cleanup = () => unmountComponent()\n\n if (typeof window !== 'undefined' && window.requestAnimationFrame) {\n window.requestAnimationFrame(cleanup)\n } else {\n setTimeout(cleanup, 0)\n }\n })\n\n // 立即加载组件\n loadComponent()\n\n return {\n containerRef,\n }\n },\n render() {\n return Vue.h('div', {ref: 'containerRef'})\n },\n })\n}\n\n// 添加必要的导入声明\nfunction defineComponent(options: any): any {\n return options\n}\n\nfunction ref<T>(initialValue?: T): {value: T | null} {\n return {value: initialValue || null}\n}\n\nfunction onMounted(fn: () => void): void {}\nfunction onUpdated(fn: () => void): void {}\nfunction onBeforeUnmount(fn: () => void): void {}\nfunction getCurrentInstance(): {props: Record<string, any>} | null {\n return null\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["createBridgeComponent","Component","options","createApp","appMap","Map","render","dom","props","existingApp","Object","key","app","error","console","destroy","createRemoteAppComponent","component","vueOptions","Error","Vue","defineComponent","provider","ref","providerInfo","isMounted","containerRef","loadComponent","result","Promise","module","renderComponent","getCurrentInstance","unmountComponent","onMounted","onUpdated","onBeforeUnmount","cleanup","window","setTimeout","initialValue","fn"],"mappings":"AAkBO,SAASA,sBAAsBC,SAAc,EAAEC,OAAoB;IACxE,MAAM,EAACC,SAAS,EAAC,GAAGD,QAAQ,GAAG;IAE/B,OAAO;QACL,MAAME,SAAS,IAAIC;QAEnB,MAAMC,SAAS,CAACC,KAAkBC;YAChC,IAAI;gBACF,MAAMC,cAAcL,OAAO,GAAG,CAACG;gBAE/B,IAAIE,aAEF;oBAAA,IAAID,OACFE,OAAO,IAAI,CAACF,OAAO,OAAO,CAACG,CAAAA;wBACzBF,YAAY,SAAS,CAAC,KAAK,CAACE,IAAI,GAAGH,KAAK,CAACG,IAAI;oBAC/C;gBACF,OACK;oBAEL,MAAMC,MAAMT,UAAUF,WAAWO,SAAS,CAAC;oBAG3C,IAAIN,QAAQ,MAAM,EAChBA,QAAQ,MAAM,CAACU;oBAGjBA,IAAI,KAAK,CAACL;oBACVH,OAAO,GAAG,CAACG,KAAKK;gBAClB;YACF,EAAE,OAAOC,OAAO;gBACdC,QAAQ,KAAK,CAAC,qDAAqDD;gBACnE,MAAMA;YACR;QACF;QAEA,MAAME,UAAU,CAACR;YACf,MAAMK,MAAMR,OAAO,GAAG,CAACG;YACvB,IAAI,CAACK,KAAK;YAEV,IAAI;gBACFA,IAAI,OAAO;gBACX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X,SAAS,KAAK,IAAII,aAAa,KAAK,EACtC,IAAI;oBACFJ,SAAS,KAAK,CAAC,OAAO,CAACI,aAAa,KAAK;oBACzCJ,SAAS,KAAK,GAAG;gBACnB,EAAE,OAAOT,OAAO;oBACdC,QAAQ,KAAK,CAAC,2CAA2CD;gBAC3D;YAEJ;YAEAqB,UAAU;gBACRT,UAAU,KAAK,GAAG;gBAClB,IAAID,aAAa,KAAK,EAAEO;YAC1B;YAEAI,UAAU;gBACR,IAAIb,SAAS,KAAK,IAAII,aAAa,KAAK,EACtCJ,SAAS,KAAK,CAAC,MAAM,CAACI,aAAa,KAAK,EAAEM,sBAAsB,SAAS,CAAC;YAE9E;YAEAI,gBAAgB;gBACdX,UAAU,KAAK,GAAG;gBAClB,MAAMY,UAAU,IAAMJ;gBAEtB,IAAI,AAAkB,eAAlB,OAAOK,UAA0BA,OAAO,qBAAqB,EAC/DA,OAAO,qBAAqB,CAACD;qBAE7BE,WAAWF,SAAS;YAExB;YAGAV;YAEA,OAAO;gBACLD;YACF;QACF;QACA;YACE,OAAON,IAAI,CAAC,CAAC,OAAO;gBAAC,KAAK;YAAc;QAC1C;IACF;AACF;AAGA,SAASC,gBAAgBnB,OAAY;IACnC,OAAOA;AACT;AAEA,SAASqB,IAAOiB,YAAgB;IAC9B,OAAO;QAAC,OAAOA,gBAAgB;IAAI;AACrC;AAEA,SAASN,UAAUO,EAAc,GAAS;AAC1C,SAASN,UAAUM,EAAc,GAAS;AAC1C,SAASL,gBAAgBK,EAAc,GAAS;AAChD,SAAST;IACP,OAAO;AACT;AAEA,YAAe;IACbhC;IACAgB;AACF"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["// Type definitions\nexport interface BridgeProviderReturn {\n render: (dom: HTMLElement, props?: Record<string, any>) => void\n destroy: (dom: HTMLElement) => void\n}\n\nexport type BridgeProvider = () => BridgeProviderReturn\nexport type AsyncBridgeProvider = () => Promise<{default: BridgeProvider}>\nexport type ComponentProvider = BridgeProvider | AsyncBridgeProvider\n\ninterface Vue3Options {\n Vue?: any\n plugin?: (app: any) => void\n}\n\n/**\n * Create bridge component - for producer to wrap application-level export modules\n */\nexport function createBridgeComponent(Component: any, options: Vue3Options): BridgeProvider {\n const {createApp} = options.Vue\n\n return function (): BridgeProviderReturn {\n const appMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n try {\n const existingApp = appMap.get(dom)\n\n if (existingApp) {\n // Update props for existing app\n if (props) {\n Object.keys(props).forEach(key => {\n existingApp._instance.props[key] = props[key]\n })\n }\n } else {\n // Create new app instance\n const app = createApp(Component, props || {})\n\n // 使用自定义插件(如果提供)\n if (options.plugin) {\n options.plugin(app)\n }\n\n app.mount(dom)\n appMap.set(dom, app)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render/update Vue component', error)\n throw error\n }\n }\n\n const destroy = (dom: HTMLElement): void => {\n const app = appMap.get(dom)\n if (!app) return\n\n try {\n app.unmount()\n appMap.delete(dom)\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\n/**\n * Create remote app component - for consumer to load application-level modules\n */\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue3Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n const {Vue} = vueOptions\n\n return defineComponent({\n name: 'Vue3RemoteAppComponent',\n props: {},\n setup() {\n const provider = ref<BridgeProviderReturn | null>(null)\n const providerInfo = ref<BridgeProvider | null>(null)\n const isMounted = ref(false)\n const containerRef = ref<HTMLElement | null>(null)\n\n const loadComponent = async () => {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n providerInfo.value = module.default\n } else {\n providerInfo.value = component as BridgeProvider\n }\n }\n\n if (isMounted.value && containerRef.value) {\n renderComponent()\n }\n } catch (error) {\n if (options.onError) options.onError(error as Error)\n console.error('[EMP-ERROR] Failed to load component', error)\n }\n }\n\n const renderComponent = () => {\n if (!providerInfo.value || !containerRef.value) return\n\n try {\n if (!provider.value) {\n provider.value = providerInfo.value()\n }\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n }\n }\n\n const unmountComponent = () => {\n if (provider.value && containerRef.value) {\n try {\n provider.value.destroy(containerRef.value)\n provider.value = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n }\n\n onMounted(() => {\n isMounted.value = true\n if (providerInfo.value) renderComponent()\n })\n\n onUpdated(() => {\n if (provider.value && containerRef.value) {\n provider.value.render(containerRef.value, getCurrentInstance()?.props || {})\n }\n })\n\n onBeforeUnmount(() => {\n isMounted.value = false\n const cleanup = () => unmountComponent()\n\n if (typeof window !== 'undefined' && window.requestAnimationFrame) {\n window.requestAnimationFrame(cleanup)\n } else {\n setTimeout(cleanup, 0)\n }\n })\n\n // 立即加载组件\n loadComponent()\n\n return {\n containerRef,\n }\n },\n render() {\n return Vue.h('div', {ref: 'containerRef'})\n },\n })\n}\n\n// 添加必要的导入声明\nfunction defineComponent(options: any): any {\n return options\n}\n\nfunction ref<T>(initialValue?: T): {value: T | null} {\n return {value: initialValue || null}\n}\n\nfunction onMounted(fn: () => void): void {}\nfunction onUpdated(fn: () => void): void {}\nfunction onBeforeUnmount(fn: () => void): void {}\nfunction getCurrentInstance(): {props: Record<string, any>} | null {\n return null\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["createBridgeComponent","Component","options","createApp","appMap","Map","render","dom","props","existingApp","Object","key","app","error","console","destroy","createRemoteAppComponent","component","vueOptions","Error","Vue","defineComponent","provider","ref","providerInfo","isMounted","containerRef","loadComponent","result","Promise","module","renderComponent","getCurrentInstance","unmountComponent","onMounted","onUpdated","onBeforeUnmount","cleanup","window","setTimeout","initialValue","fn"],"mappings":"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AClB,MAAMY,UAAU,IAAMJ;gBAEtB,IAAI,AAAkB,MAAlB,OAAOK,UAA0BA,OAAO,qBAAqB,EAC/DA,OAAO,qBAAqB,CAACD;qBAE7BE,WAAWF,SAAS;YAExB;YAGAV;YAEA,OAAO;gBACLD;YACF;QACF;QACA;YACE,OAAON,IAAI,CAAC,CAAC,OAAO;gBAAC,KAAK;YAAc;QAC1C;IACF;AACF;AAGA,SAASC,gBAAgBnB,OAAY;IACnC,OAAOA;AACT;AAEA,SAASqB,IAAOiB,YAAgB;IAC9B,OAAO;QAAC,OAAOA,gBAAgB;IAAI;AACrC;AAEA,SAASN,UAAUO,EAAc,GAAS;AAC1C,SAASN,UAAUM,EAAc,GAAS;AAC1C,SAASL,gBAAgBK,EAAc,GAAS;AAChD,SAAST;IACP,OAAO;AACT;AAEA,YAAe;IACbhC,uBAAAA;IACAgB,0BAAAA;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empjs/bridge-vue3",
3
- "version": "0.0.3",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Emp Bridge Vue v3",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  }
37
37
  },
38
38
  "engines": {
39
- "node": ">=16.0.0"
39
+ "node": "^20.19.0 || >=22.12.0"
40
40
  },
41
41
  "author": "Ken",
42
42
  "dependencies": {},