web-extend-plugin-vue2 0.3.1 → 0.3.3
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 +77 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +77 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3255,13 +3255,30 @@ function getRegisteredTopRouteNamesForPlugin(pluginId) {
|
|
|
3255
3255
|
}
|
|
3256
3256
|
|
|
3257
3257
|
/**
|
|
3258
|
-
*
|
|
3259
|
-
*
|
|
3258
|
+
* Host-side reactive registries for extension-point slot components.
|
|
3259
|
+
* Menus/sidebar mapping stays on the host and is not duplicated here.
|
|
3260
3260
|
*/
|
|
3261
|
-
const registries =
|
|
3261
|
+
const registries = {
|
|
3262
3262
|
slots: {},
|
|
3263
3263
|
slotRevision: 0
|
|
3264
|
-
}
|
|
3264
|
+
};
|
|
3265
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3266
|
+
function ensureRegistriesReactive(VueLike) {
|
|
3267
|
+
if (!VueLike || typeof VueLike.observable !== 'function') {
|
|
3268
|
+
return registries;
|
|
3269
|
+
}
|
|
3270
|
+
if (registries.__wepObservedBy__ === VueLike) {
|
|
3271
|
+
return registries;
|
|
3272
|
+
}
|
|
3273
|
+
VueLike.observable(registries);
|
|
3274
|
+
Object.defineProperty(registries, '__wepObservedBy__', {
|
|
3275
|
+
value: VueLike,
|
|
3276
|
+
configurable: true,
|
|
3277
|
+
enumerable: false,
|
|
3278
|
+
writable: true
|
|
3279
|
+
});
|
|
3280
|
+
return registries;
|
|
3281
|
+
}
|
|
3265
3282
|
|
|
3266
3283
|
/**
|
|
3267
3284
|
* 按插件 id 收集 `onTeardown` 回调,供 `disposeWebPlugin` 统一执行。
|
|
@@ -4470,6 +4487,9 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
|
|
|
4470
4487
|
const hostContext = hostKitOptions.hostContext != null && typeof hostKitOptions.hostContext === 'object'
|
|
4471
4488
|
? hostKitOptions.hostContext
|
|
4472
4489
|
: Object.freeze({});
|
|
4490
|
+
const hostVue = hostContext && hostContext.Vue;
|
|
4491
|
+
const VueRuntime = hostVue || Vue;
|
|
4492
|
+
ensureRegistriesReactive(VueRuntime);
|
|
4473
4493
|
registerPluginTeardown(pluginId, () => {
|
|
4474
4494
|
clearContributedRoutesForPlugin(pluginId);
|
|
4475
4495
|
});
|
|
@@ -4525,7 +4545,7 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
|
|
|
4525
4545
|
return;
|
|
4526
4546
|
}
|
|
4527
4547
|
if (!registries.slots[pointId]) {
|
|
4528
|
-
|
|
4548
|
+
VueRuntime.set(registries.slots, pointId, []);
|
|
4529
4549
|
}
|
|
4530
4550
|
const list = registries.slots[pointId];
|
|
4531
4551
|
for (const c of components) {
|
|
@@ -4563,62 +4583,64 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
|
|
|
4563
4583
|
};
|
|
4564
4584
|
}
|
|
4565
4585
|
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4586
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4587
|
+
function createExtensionPointComponent(VueLike = Vue) {
|
|
4588
|
+
ensureRegistriesReactive(VueLike);
|
|
4589
|
+
const SlotErrorBoundary = VueLike.extend({
|
|
4590
|
+
name: 'SlotErrorBoundary',
|
|
4591
|
+
props: { label: String },
|
|
4592
|
+
data() {
|
|
4593
|
+
return { error: null };
|
|
4594
|
+
},
|
|
4595
|
+
errorCaptured(err) {
|
|
4596
|
+
this.error = err instanceof Error && err.message ? err.message : String(err);
|
|
4597
|
+
console.error('[wep:ExtensionPoint]', this.label, err);
|
|
4598
|
+
return false;
|
|
4599
|
+
},
|
|
4600
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4601
|
+
render(h) {
|
|
4602
|
+
if (this.error) {
|
|
4603
|
+
return h('div', { class: 'plugin-point-error' }, `[插件 ${this.label}] 渲染失败`);
|
|
4604
|
+
}
|
|
4605
|
+
const d = this.$slots.default;
|
|
4606
|
+
return d && d[0] ? d[0] : h('span');
|
|
4585
4607
|
}
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
}
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
props: {
|
|
4594
|
-
pointId: { type: String, required: true },
|
|
4595
|
-
slotProps: { type: Object, default: () => ({}) }
|
|
4596
|
-
},
|
|
4597
|
-
computed: {
|
|
4598
|
-
items() {
|
|
4599
|
-
void registries.slotRevision;
|
|
4600
|
-
return registries.slots[this.pointId] || [];
|
|
4608
|
+
});
|
|
4609
|
+
return VueLike.extend({
|
|
4610
|
+
name: 'ExtensionPoint',
|
|
4611
|
+
components: { SlotErrorBoundary },
|
|
4612
|
+
props: {
|
|
4613
|
+
pointId: { type: String, required: true },
|
|
4614
|
+
slotProps: { type: Object, default: () => ({}) }
|
|
4601
4615
|
},
|
|
4602
|
-
|
|
4603
|
-
|
|
4616
|
+
computed: {
|
|
4617
|
+
items() {
|
|
4618
|
+
void registries.slotRevision;
|
|
4619
|
+
return registries.slots[this.pointId] || [];
|
|
4620
|
+
},
|
|
4621
|
+
forwardProps() {
|
|
4622
|
+
return this.slotProps || {};
|
|
4623
|
+
}
|
|
4624
|
+
},
|
|
4625
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4626
|
+
render(h) {
|
|
4627
|
+
return h('div', {
|
|
4628
|
+
class: 'extension-point',
|
|
4629
|
+
attrs: { 'data-point-id': this.pointId }
|
|
4630
|
+
}, this.items.map((item) => h(SlotErrorBoundary, {
|
|
4631
|
+
key: item.key,
|
|
4632
|
+
props: { label: item.pluginId }
|
|
4633
|
+
}, [h(item.component, { props: this.forwardProps })])));
|
|
4604
4634
|
}
|
|
4605
|
-
}
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
return h('div', {
|
|
4609
|
-
class: 'extension-point',
|
|
4610
|
-
attrs: { 'data-point-id': this.pointId }
|
|
4611
|
-
}, this.items.map((item) => h(SlotErrorBoundary, {
|
|
4612
|
-
key: item.key,
|
|
4613
|
-
props: { label: item.pluginId }
|
|
4614
|
-
}, [h(item.component, { props: this.forwardProps })])));
|
|
4615
|
-
}
|
|
4616
|
-
});
|
|
4635
|
+
});
|
|
4636
|
+
}
|
|
4637
|
+
var ExtensionPoint = createExtensionPointComponent();
|
|
4617
4638
|
|
|
4618
4639
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4619
4640
|
function installWebExtendPluginVue2(Vue, router, options) {
|
|
4620
|
-
if (Vue
|
|
4621
|
-
Vue
|
|
4641
|
+
if (Vue) {
|
|
4642
|
+
ensureRegistriesReactive(Vue);
|
|
4643
|
+
Vue.component('ExtensionPoint', createExtensionPointComponent(Vue));
|
|
4622
4644
|
}
|
|
4623
4645
|
const runtime = resolveRuntimeOptions$1(options || {});
|
|
4624
4646
|
return bootstrapPlugins$1(router, (id, r, kit) => createHostApi(id, r, kit || {}), runtime);
|