@empjs/bridge-vue2 0.2.2 → 4.0.0-alpha.2
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/dist/index.cjs +19 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 (
|
|
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 Vue = options.Vue;
|
|
33
32
|
const instanceOptions = options.instanceOptions || {};
|
|
@@ -195,18 +194,24 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
|
|
|
195
194
|
}
|
|
196
195
|
};
|
|
197
196
|
}
|
|
198
|
-
const
|
|
197
|
+
const __rspack_default_export = {
|
|
199
198
|
createBridgeComponent,
|
|
200
199
|
createRemoteAppComponent
|
|
201
200
|
};
|
|
201
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
202
|
+
createBridgeComponent: ()=>createBridgeComponent,
|
|
203
|
+
createRemoteAppComponent: ()=>createRemoteAppComponent
|
|
204
|
+
}, {
|
|
205
|
+
default: __rspack_default_export
|
|
206
|
+
});
|
|
202
207
|
exports.createBridgeComponent = __webpack_exports__.createBridgeComponent;
|
|
203
208
|
exports.createRemoteAppComponent = __webpack_exports__.createRemoteAppComponent;
|
|
204
209
|
exports["default"] = __webpack_exports__["default"];
|
|
205
|
-
for(var
|
|
210
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
206
211
|
"createBridgeComponent",
|
|
207
212
|
"createRemoteAppComponent",
|
|
208
213
|
"default"
|
|
209
|
-
].indexOf(
|
|
214
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
210
215
|
Object.defineProperty(exports, '__esModule', {
|
|
211
216
|
value: true
|
|
212
217
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["webpack://@empjs/bridge-vue2/webpack/runtime/define_property_getters","webpack://@empjs/bridge-vue2/webpack/runtime/has_own_property","webpack://@empjs/bridge-vue2/webpack/runtime/make_namespace_object","webpack://@empjs/bridge-vue2/./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};","export 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 Vue2Options {\n Vue?: any\n plugin?: (vue: any) => void\n instanceOptions?: Record<string, any>\n}\n\nexport function createBridgeComponent(Component: any, options: Vue2Options): BridgeProvider {\n const Vue = options.Vue\n const instanceOptions = options.instanceOptions || {}\n\n return function (): BridgeProviderReturn {\n const instanceMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to render')\n return\n }\n\n try {\n const existingInstance = instanceMap.get(dom)\n\n if (existingInstance) {\n if (props) {\n try {\n existingInstance.$options.render = (h: any) => h(Component, {props: props || {}})\n existingInstance.$options.propsData = props || {}\n existingInstance.$forceUpdate()\n } catch (error) {\n console.warn('[EMP-WARN] Failed to update props:', error)\n }\n }\n } else {\n const vueContainer = document.createElement('div')\n vueContainer.className = 'vue2-container'\n dom.appendChild(vueContainer)\n if (options.plugin) {\n options.plugin(Vue)\n }\n const instance = new Vue({\n propsData: props || {},\n render: (h: any) => h(Component, {props: props || {}}),\n el: vueContainer,\n beforeDestroy() {\n if (vueContainer && vueContainer.parentNode) {\n while (vueContainer.firstChild) {\n vueContainer.removeChild(vueContainer.firstChild)\n }\n try {\n dom.removeChild(vueContainer)\n } catch (e) {\n console.warn('[EMP-WARN] Failed to remove Vue container:', e)\n }\n }\n },\n ...instanceOptions,\n })\n\n instanceMap.set(dom, instance)\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 if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to destroy')\n return\n }\n\n const instance = instanceMap.get(dom)\n\n if (!instance) return\n\n try {\n const vmToDestroy = instance\n instanceMap.delete(dom)\n\n try {\n if (dom) {\n try {\n if (typeof dom.replaceChildren === 'function') {\n dom.replaceChildren()\n }\n } catch (replaceError) {\n console.warn('[EMP-WARN] destroy - replaceChildren failed:', replaceError)\n }\n\n try {\n while (dom.firstChild) {\n dom.removeChild(dom.firstChild)\n }\n } catch (removeError) {\n console.warn('[EMP-WARN] destroy - removeChild failed:', removeError)\n }\n }\n } catch (domError) {\n console.warn('[EMP-WARN] Error clearing DOM before destroy:', domError)\n }\n\n try {\n vmToDestroy.$destroy()\n } catch (destroyError) {\n console.error('[EMP-ERROR] Error during Vue instance destroy:', destroyError)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue2Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n return {\n name: 'Vue2RemoteAppComponent',\n props: {\n name: String,\n [Symbol.toPrimitive]: Function,\n },\n data() {\n return {\n provider: null,\n providerInfo: null,\n isMounted: false,\n }\n },\n methods: {\n async loadComponent() {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n this.providerInfo = module.default\n } else {\n this.providerInfo = component as BridgeProvider\n }\n }\n\n if (this.isMounted && this.$el) {\n this.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 renderComponent() {\n if (!this.providerInfo || !this.$el) return\n\n try {\n if (!this.provider && this.providerInfo) {\n this.provider = this.providerInfo()\n }\n\n if (!this.provider) {\n console.warn('[EMP-WARN] Provider not available yet')\n return\n }\n\n const props = this.$props || this.$options.propsData || {}\n\n if (props && typeof props === 'object') {\n this.provider.render(this.$el, props)\n } else {\n this.provider.render(this.$el, {})\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n if (options.onError) options.onError(error as Error)\n }\n },\n unmountComponent() {\n if (this.provider && this.$el) {\n try {\n try {\n while (this.$el.firstChild) {\n this.$el.removeChild(this.$el.firstChild)\n }\n } catch (clearError) {\n console.error('[EMP-ERROR] unmountComponent - Error during DOM clearing:', clearError)\n }\n\n this.provider.destroy(this.$el)\n this.provider = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n },\n },\n mounted() {\n this.isMounted = true\n if (this.providerInfo) this.renderComponent()\n },\n updated() {\n if (this.provider && this.$el) {\n const props = this.$props || this.$options.propsData || {}\n this.provider.render(this.$el, props)\n }\n },\n beforeDestroy() {\n this.isMounted = false\n this.unmountComponent()\n },\n created() {\n this.loadComponent()\n },\n render(h: any) {\n return h('div')\n },\n }\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","createBridgeComponent","Component","options","Vue","instanceOptions","instanceMap","Map","render","dom","props","HTMLElement","console","existingInstance","h","error","vueContainer","document","instance","e","destroy","vmToDestroy","replaceError","removeError","domError","destroyError","createRemoteAppComponent","component","vueOptions","Error","String","Function","result","Promise","module","clearError"],"mappings":";;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,I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,CAAC,gBAAgB;QACvB;QACA;YACE,IAAI,CAAC,aAAa;QACpB;QACA,QAAOI,CAAM;YACX,OAAOA,EAAE;QACX;IACF;AACF;AAEA,mCAAe;IACbb;IACAyB;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};","export 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 Vue2Options {\n Vue?: any\n plugin?: (vue: any) => void\n instanceOptions?: Record<string, any>\n}\n\nexport function createBridgeComponent(Component: any, options: Vue2Options): BridgeProvider {\n const Vue = options.Vue\n const instanceOptions = options.instanceOptions || {}\n\n return function (): BridgeProviderReturn {\n const instanceMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to render')\n return\n }\n\n try {\n const existingInstance = instanceMap.get(dom)\n\n if (existingInstance) {\n if (props) {\n try {\n existingInstance.$options.render = (h: any) => h(Component, {props: props || {}})\n existingInstance.$options.propsData = props || {}\n existingInstance.$forceUpdate()\n } catch (error) {\n console.warn('[EMP-WARN] Failed to update props:', error)\n }\n }\n } else {\n const vueContainer = document.createElement('div')\n vueContainer.className = 'vue2-container'\n dom.appendChild(vueContainer)\n if (options.plugin) {\n options.plugin(Vue)\n }\n const instance = new Vue({\n propsData: props || {},\n render: (h: any) => h(Component, {props: props || {}}),\n el: vueContainer,\n beforeDestroy() {\n if (vueContainer && vueContainer.parentNode) {\n while (vueContainer.firstChild) {\n vueContainer.removeChild(vueContainer.firstChild)\n }\n try {\n dom.removeChild(vueContainer)\n } catch (e) {\n console.warn('[EMP-WARN] Failed to remove Vue container:', e)\n }\n }\n },\n ...instanceOptions,\n })\n\n instanceMap.set(dom, instance)\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 if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to destroy')\n return\n }\n\n const instance = instanceMap.get(dom)\n\n if (!instance) return\n\n try {\n const vmToDestroy = instance\n instanceMap.delete(dom)\n\n try {\n if (dom) {\n try {\n if (typeof dom.replaceChildren === 'function') {\n dom.replaceChildren()\n }\n } catch (replaceError) {\n console.warn('[EMP-WARN] destroy - replaceChildren failed:', replaceError)\n }\n\n try {\n while (dom.firstChild) {\n dom.removeChild(dom.firstChild)\n }\n } catch (removeError) {\n console.warn('[EMP-WARN] destroy - removeChild failed:', removeError)\n }\n }\n } catch (domError) {\n console.warn('[EMP-WARN] Error clearing DOM before destroy:', domError)\n }\n\n try {\n vmToDestroy.$destroy()\n } catch (destroyError) {\n console.error('[EMP-ERROR] Error during Vue instance destroy:', destroyError)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue2Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n return {\n name: 'Vue2RemoteAppComponent',\n props: {\n name: String,\n [Symbol.toPrimitive]: Function,\n },\n data() {\n return {\n provider: null,\n providerInfo: null,\n isMounted: false,\n }\n },\n methods: {\n async loadComponent() {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n this.providerInfo = module.default\n } else {\n this.providerInfo = component as BridgeProvider\n }\n }\n\n if (this.isMounted && this.$el) {\n this.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 renderComponent() {\n if (!this.providerInfo || !this.$el) return\n\n try {\n if (!this.provider && this.providerInfo) {\n this.provider = this.providerInfo()\n }\n\n if (!this.provider) {\n console.warn('[EMP-WARN] Provider not available yet')\n return\n }\n\n const props = this.$props || this.$options.propsData || {}\n\n if (props && typeof props === 'object') {\n this.provider.render(this.$el, props)\n } else {\n this.provider.render(this.$el, {})\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n if (options.onError) options.onError(error as Error)\n }\n },\n unmountComponent() {\n if (this.provider && this.$el) {\n try {\n try {\n while (this.$el.firstChild) {\n this.$el.removeChild(this.$el.firstChild)\n }\n } catch (clearError) {\n console.error('[EMP-ERROR] unmountComponent - Error during DOM clearing:', clearError)\n }\n\n this.provider.destroy(this.$el)\n this.provider = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n },\n },\n mounted() {\n this.isMounted = true\n if (this.providerInfo) this.renderComponent()\n },\n updated() {\n if (this.provider && this.$el) {\n const props = this.$props || this.$options.propsData || {}\n this.provider.render(this.$el, props)\n }\n },\n beforeDestroy() {\n this.isMounted = false\n this.unmountComponent()\n },\n created() {\n this.loadComponent()\n },\n render(h: any) {\n return h('div')\n },\n }\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","Vue","instanceOptions","instanceMap","Map","render","dom","props","HTMLElement","console","existingInstance","h","error","vueContainer","document","instance","e","destroy","vmToDestroy","replaceError","removeError","domError","destroyError","createRemoteAppComponent","component","vueOptions","Error","String","Function","result","Promise","module","clearError"],"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,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;ACSO,SAASI,sBAAsBC,SAAc,EAAEC,OAAoB;IACxE,MAAMC,MAAMD,QAAQ,GAAG;IACvB,MAAME,kBAAkBF,QAAQ,eAAe,IAAI,CAAC;IAEpD,OAAO;QACL,MAAMG,cAAc,IAAIC;QAExB,MAAMC,SAAS,CAACC,KAAkBC;YAChC,IAAI,CAACD,OAAO,CAAEA,CAAAA,eAAeE,WAAU,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9B,IAAI,CAAC,QAAQ,GAAG;gBAClB,EAAE,OAAOpB,OAAO;oBACdH,QAAQ,KAAK,CAAC,2CAA2CG;gBAC3D;YAEJ;QACF;QACA;YACE,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,eAAe;QAC7C;QACA;YACE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE;gBAC7B,MAAML,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC;gBACzD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAEA;YACjC;QACF;QACA;YACE,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,gBAAgB;QACvB;QACA;YACE,IAAI,CAAC,aAAa;QACpB;QACA,QAAOI,CAAM;YACX,OAAOA,EAAE;QACX;IACF;AACF;AAEA,gCAAe;IACbb;IACAyB;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -166,9 +166,10 @@ function createRemoteAppComponent(component, vueOptions, options = {}) {
|
|
|
166
166
|
};
|
|
167
167
|
}
|
|
168
168
|
const src = {
|
|
169
|
-
createBridgeComponent,
|
|
170
|
-
createRemoteAppComponent
|
|
169
|
+
createBridgeComponent: createBridgeComponent,
|
|
170
|
+
createRemoteAppComponent: createRemoteAppComponent
|
|
171
171
|
};
|
|
172
|
-
export
|
|
172
|
+
export default src;
|
|
173
|
+
export { createBridgeComponent, createRemoteAppComponent };
|
|
173
174
|
|
|
174
175
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["webpack://@empjs/bridge-vue2/./src/index.ts"],"sourcesContent":["export 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 Vue2Options {\n Vue?: any\n plugin?: (vue: any) => void\n instanceOptions?: Record<string, any>\n}\n\nexport function createBridgeComponent(Component: any, options: Vue2Options): BridgeProvider {\n const Vue = options.Vue\n const instanceOptions = options.instanceOptions || {}\n\n return function (): BridgeProviderReturn {\n const instanceMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to render')\n return\n }\n\n try {\n const existingInstance = instanceMap.get(dom)\n\n if (existingInstance) {\n if (props) {\n try {\n existingInstance.$options.render = (h: any) => h(Component, {props: props || {}})\n existingInstance.$options.propsData = props || {}\n existingInstance.$forceUpdate()\n } catch (error) {\n console.warn('[EMP-WARN] Failed to update props:', error)\n }\n }\n } else {\n const vueContainer = document.createElement('div')\n vueContainer.className = 'vue2-container'\n dom.appendChild(vueContainer)\n if (options.plugin) {\n options.plugin(Vue)\n }\n const instance = new Vue({\n propsData: props || {},\n render: (h: any) => h(Component, {props: props || {}}),\n el: vueContainer,\n beforeDestroy() {\n if (vueContainer && vueContainer.parentNode) {\n while (vueContainer.firstChild) {\n vueContainer.removeChild(vueContainer.firstChild)\n }\n try {\n dom.removeChild(vueContainer)\n } catch (e) {\n console.warn('[EMP-WARN] Failed to remove Vue container:', e)\n }\n }\n },\n ...instanceOptions,\n })\n\n instanceMap.set(dom, instance)\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 if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to destroy')\n return\n }\n\n const instance = instanceMap.get(dom)\n\n if (!instance) return\n\n try {\n const vmToDestroy = instance\n instanceMap.delete(dom)\n\n try {\n if (dom) {\n try {\n if (typeof dom.replaceChildren === 'function') {\n dom.replaceChildren()\n }\n } catch (replaceError) {\n console.warn('[EMP-WARN] destroy - replaceChildren failed:', replaceError)\n }\n\n try {\n while (dom.firstChild) {\n dom.removeChild(dom.firstChild)\n }\n } catch (removeError) {\n console.warn('[EMP-WARN] destroy - removeChild failed:', removeError)\n }\n }\n } catch (domError) {\n console.warn('[EMP-WARN] Error clearing DOM before destroy:', domError)\n }\n\n try {\n vmToDestroy.$destroy()\n } catch (destroyError) {\n console.error('[EMP-ERROR] Error during Vue instance destroy:', destroyError)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue2Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n return {\n name: 'Vue2RemoteAppComponent',\n props: {\n name: String,\n [Symbol.toPrimitive]: Function,\n },\n data() {\n return {\n provider: null,\n providerInfo: null,\n isMounted: false,\n }\n },\n methods: {\n async loadComponent() {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n this.providerInfo = module.default\n } else {\n this.providerInfo = component as BridgeProvider\n }\n }\n\n if (this.isMounted && this.$el) {\n this.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 renderComponent() {\n if (!this.providerInfo || !this.$el) return\n\n try {\n if (!this.provider && this.providerInfo) {\n this.provider = this.providerInfo()\n }\n\n if (!this.provider) {\n console.warn('[EMP-WARN] Provider not available yet')\n return\n }\n\n const props = this.$props || this.$options.propsData || {}\n\n if (props && typeof props === 'object') {\n this.provider.render(this.$el, props)\n } else {\n this.provider.render(this.$el, {})\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n if (options.onError) options.onError(error as Error)\n }\n },\n unmountComponent() {\n if (this.provider && this.$el) {\n try {\n try {\n while (this.$el.firstChild) {\n this.$el.removeChild(this.$el.firstChild)\n }\n } catch (clearError) {\n console.error('[EMP-ERROR] unmountComponent - Error during DOM clearing:', clearError)\n }\n\n this.provider.destroy(this.$el)\n this.provider = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n },\n },\n mounted() {\n this.isMounted = true\n if (this.providerInfo) this.renderComponent()\n },\n updated() {\n if (this.provider && this.$el) {\n const props = this.$props || this.$options.propsData || {}\n this.provider.render(this.$el, props)\n }\n },\n beforeDestroy() {\n this.isMounted = false\n this.unmountComponent()\n },\n created() {\n this.loadComponent()\n },\n render(h: any) {\n return h('div')\n },\n }\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["createBridgeComponent","Component","options","Vue","instanceOptions","instanceMap","Map","render","dom","props","HTMLElement","console","existingInstance","h","error","vueContainer","document","instance","e","destroy","vmToDestroy","replaceError","removeError","domError","destroyError","createRemoteAppComponent","component","vueOptions","Error","String","Symbol","Function","result","Promise","module","clearError"],"mappings":"AAeO,SAASA,sBAAsBC,SAAc,EAAEC,OAAoB;IACxE,MAAMC,MAAMD,QAAQ,GAAG;IACvB,MAAME,kBAAkBF,QAAQ,eAAe,IAAI,CAAC;IAEpD,OAAO;QACL,MAAMG,cAAc,IAAIC;QAExB,MAAMC,SAAS,CAACC,KAAkBC;YAChC,IAAI,CAACD,OAAO,CAAEA,CAAAA,eAAeE,WAAU,GAAI,YACzCC,QAAQ,KAAK,CAAC;YAIhB,IAAI;gBACF,MAAMC,mBAAmBP,YAAY,GAAG,CAACG;gBAEzC,IAAII,kBACF;oBAAA,IAAIH,OACF,IAAI;wBACFG,iBAAiB,QAAQ,CAAC,MAAM,GAAG,CAACC,IAAWA,EAAEZ,WAAW;gCAAC,OAAOQ,SAAS,CAAC;4BAAC;wBAC/EG,iBAAiB,QAAQ,CAAC,SAAS,GAAGH,SAAS,CAAC;wBAChDG,i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MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC;gBACzD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAEA;YACjC;QACF;QACA;YACE,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,gBAAgB;QACvB;QACA;YACE,IAAI,CAAC,aAAa;QACpB;QACA,QAAOI,CAAM;YACX,OAAOA,EAAE;QACX;IACF;AACF;AAEA,YAAe;IACbb;IACAyB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export 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 Vue2Options {\n Vue?: any\n plugin?: (vue: any) => void\n instanceOptions?: Record<string, any>\n}\n\nexport function createBridgeComponent(Component: any, options: Vue2Options): BridgeProvider {\n const Vue = options.Vue\n const instanceOptions = options.instanceOptions || {}\n\n return function (): BridgeProviderReturn {\n const instanceMap = new Map<HTMLElement, any>()\n\n const render = (dom: HTMLElement, props?: Record<string, any>): void => {\n if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to render')\n return\n }\n\n try {\n const existingInstance = instanceMap.get(dom)\n\n if (existingInstance) {\n if (props) {\n try {\n existingInstance.$options.render = (h: any) => h(Component, {props: props || {}})\n existingInstance.$options.propsData = props || {}\n existingInstance.$forceUpdate()\n } catch (error) {\n console.warn('[EMP-WARN] Failed to update props:', error)\n }\n }\n } else {\n const vueContainer = document.createElement('div')\n vueContainer.className = 'vue2-container'\n dom.appendChild(vueContainer)\n if (options.plugin) {\n options.plugin(Vue)\n }\n const instance = new Vue({\n propsData: props || {},\n render: (h: any) => h(Component, {props: props || {}}),\n el: vueContainer,\n beforeDestroy() {\n if (vueContainer && vueContainer.parentNode) {\n while (vueContainer.firstChild) {\n vueContainer.removeChild(vueContainer.firstChild)\n }\n try {\n dom.removeChild(vueContainer)\n } catch (e) {\n console.warn('[EMP-WARN] Failed to remove Vue container:', e)\n }\n }\n },\n ...instanceOptions,\n })\n\n instanceMap.set(dom, instance)\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 if (!dom || !(dom instanceof HTMLElement)) {\n console.error('[EMP-ERROR] Invalid DOM element provided to destroy')\n return\n }\n\n const instance = instanceMap.get(dom)\n\n if (!instance) return\n\n try {\n const vmToDestroy = instance\n instanceMap.delete(dom)\n\n try {\n if (dom) {\n try {\n if (typeof dom.replaceChildren === 'function') {\n dom.replaceChildren()\n }\n } catch (replaceError) {\n console.warn('[EMP-WARN] destroy - replaceChildren failed:', replaceError)\n }\n\n try {\n while (dom.firstChild) {\n dom.removeChild(dom.firstChild)\n }\n } catch (removeError) {\n console.warn('[EMP-WARN] destroy - removeChild failed:', removeError)\n }\n }\n } catch (domError) {\n console.warn('[EMP-WARN] Error clearing DOM before destroy:', domError)\n }\n\n try {\n vmToDestroy.$destroy()\n } catch (destroyError) {\n console.error('[EMP-ERROR] Error during Vue instance destroy:', destroyError)\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount Vue component', error)\n }\n }\n\n return {render, destroy}\n }\n}\n\nexport function createRemoteAppComponent(\n component: ComponentProvider,\n vueOptions: Vue2Options,\n options: {onError?: (error: Error) => void} = {},\n): any {\n if (!component) {\n throw new Error('createRemoteAppComponent: component parameter cannot be empty')\n }\n\n return {\n name: 'Vue2RemoteAppComponent',\n props: {\n name: String,\n [Symbol.toPrimitive]: Function,\n },\n data() {\n return {\n provider: null,\n providerInfo: null,\n isMounted: false,\n }\n },\n methods: {\n async loadComponent() {\n try {\n if (typeof component === 'function') {\n const result = component()\n\n if (result instanceof Promise) {\n const module = await result\n this.providerInfo = module.default\n } else {\n this.providerInfo = component as BridgeProvider\n }\n }\n\n if (this.isMounted && this.$el) {\n this.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 renderComponent() {\n if (!this.providerInfo || !this.$el) return\n\n try {\n if (!this.provider && this.providerInfo) {\n this.provider = this.providerInfo()\n }\n\n if (!this.provider) {\n console.warn('[EMP-WARN] Provider not available yet')\n return\n }\n\n const props = this.$props || this.$options.propsData || {}\n\n if (props && typeof props === 'object') {\n this.provider.render(this.$el, props)\n } else {\n this.provider.render(this.$el, {})\n }\n } catch (error) {\n console.error('[EMP-ERROR] Failed to render component', error)\n if (options.onError) options.onError(error as Error)\n }\n },\n unmountComponent() {\n if (this.provider && this.$el) {\n try {\n try {\n while (this.$el.firstChild) {\n this.$el.removeChild(this.$el.firstChild)\n }\n } catch (clearError) {\n console.error('[EMP-ERROR] unmountComponent - Error during DOM clearing:', clearError)\n }\n\n this.provider.destroy(this.$el)\n this.provider = null\n } catch (error) {\n console.error('[EMP-ERROR] Failed to unmount component', error)\n }\n }\n },\n },\n mounted() {\n this.isMounted = true\n if (this.providerInfo) this.renderComponent()\n },\n updated() {\n if (this.provider && this.$el) {\n const props = this.$props || this.$options.propsData || {}\n this.provider.render(this.$el, props)\n }\n },\n beforeDestroy() {\n this.isMounted = false\n this.unmountComponent()\n },\n created() {\n this.loadComponent()\n },\n render(h: any) {\n return h('div')\n },\n }\n}\n\nexport default {\n createBridgeComponent,\n createRemoteAppComponent,\n}\n"],"names":["createBridgeComponent","Component","options","Vue","instanceOptions","instanceMap","Map","render","dom","props","HTMLElement","console","existingInstance","h","error","vueContainer","document","instance","e","destroy","vmToDestroy","replaceError","removeError","domError","destroyError","createRemoteAppComponent","component","vueOptions","Error","String","Symbol","Function","result","Promise","module","clearError"],"mappings":"AAeO,SAASA,sBAAsBC,SAAc,EAAEC,OAAoB;IACxE,MAAMC,MAAMD,QA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C,IAAI,CAAC,GAAG,CAAC,UAAU;oBAE5C,EAAE,OAAOqB,YAAY;wBACnBxB,QAAQ,KAAK,CAAC,6DAA6DwB;oBAC7E;oBAEA,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;oBAC9B,IAAI,CAAC,QAAQ,GAAG;gBAClB,EAAE,OAAOrB,OAAO;oBACdH,QAAQ,KAAK,CAAC,2CAA2CG;gBAC3D;YAEJ;QACF;QACA;YACE,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,eAAe;QAC7C;QACA;YACE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE;gBAC7B,MAAML,QAAQ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC;gBACzD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAEA;YACjC;QACF;QACA;YACE,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,gBAAgB;QACvB;QACA;YACE,IAAI,CAAC,aAAa;QACpB;QACA,QAAOI,CAAM;YACX,OAAOA,EAAE;QACX;IACF;AACF;AAEA,YAAe;IACbb,uBAAAA;IACAyB,0BAAAA;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empjs/bridge-vue2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "4.0.0-alpha.2",
|
|
4
4
|
"description": "Emp Bridge Vue v2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": "
|
|
39
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
40
40
|
},
|
|
41
41
|
"author": "Ken",
|
|
42
42
|
"dependencies": {},
|