web-extend-plugin-vue2 0.3.1 → 0.3.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 CHANGED
@@ -3261,13 +3261,30 @@ function getRegisteredTopRouteNamesForPlugin(pluginId) {
3261
3261
  }
3262
3262
 
3263
3263
  /**
3264
- * 宿主侧响应式注册表:扩展点槽位(供布局与 `ExtensionPoint` 消费)。
3265
- * 菜单/侧栏树完全由宿主基于路由快照自行映射,框架不维护平行菜单列表。
3264
+ * Host-side reactive registries for extension-point slot components.
3265
+ * Menus/sidebar mapping stays on the host and is not duplicated here.
3266
3266
  */
3267
- const registries = Vue__default.default.observable({
3267
+ const registries = {
3268
3268
  slots: {},
3269
3269
  slotRevision: 0
3270
- });
3270
+ };
3271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3272
+ function ensureRegistriesReactive(VueLike) {
3273
+ if (!VueLike || typeof VueLike.observable !== 'function') {
3274
+ return registries;
3275
+ }
3276
+ if (registries.__wepObservedBy__ === VueLike) {
3277
+ return registries;
3278
+ }
3279
+ VueLike.observable(registries);
3280
+ Object.defineProperty(registries, '__wepObservedBy__', {
3281
+ value: VueLike,
3282
+ configurable: true,
3283
+ enumerable: false,
3284
+ writable: true
3285
+ });
3286
+ return registries;
3287
+ }
3271
3288
 
3272
3289
  /**
3273
3290
  * 按插件 id 收集 `onTeardown` 回调,供 `disposeWebPlugin` 统一执行。
@@ -4476,6 +4493,9 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4476
4493
  const hostContext = hostKitOptions.hostContext != null && typeof hostKitOptions.hostContext === 'object'
4477
4494
  ? hostKitOptions.hostContext
4478
4495
  : Object.freeze({});
4496
+ const hostVue = hostContext && hostContext.Vue;
4497
+ const VueRuntime = hostVue || Vue__default.default;
4498
+ ensureRegistriesReactive(VueRuntime);
4479
4499
  registerPluginTeardown(pluginId, () => {
4480
4500
  clearContributedRoutesForPlugin(pluginId);
4481
4501
  });
@@ -4531,7 +4551,7 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4531
4551
  return;
4532
4552
  }
4533
4553
  if (!registries.slots[pointId]) {
4534
- Vue__default.default.set(registries.slots, pointId, []);
4554
+ VueRuntime.set(registries.slots, pointId, []);
4535
4555
  }
4536
4556
  const list = registries.slots[pointId];
4537
4557
  for (const c of components) {
@@ -4569,62 +4589,64 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4569
4589
  };
4570
4590
  }
4571
4591
 
4572
- /**
4573
- * 布局中的扩展点占位;插件通过 `hostApi.registerSlotComponents(pointId, ...)` 注入组件。
4574
- * 样式由宿主全局 CSS 覆盖 `.extension-point` / `.plugin-point-error`。
4575
- */
4576
- const SlotErrorBoundary = Vue__default.default.extend({
4577
- name: 'SlotErrorBoundary',
4578
- props: { label: String },
4579
- data() {
4580
- return { error: null };
4581
- },
4582
- errorCaptured(err) {
4583
- this.error = err instanceof Error && err.message ? err.message : String(err);
4584
- console.error('[wep:ExtensionPoint]', this.label, err);
4585
- return false;
4586
- },
4587
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4588
- render(h) {
4589
- if (this.error) {
4590
- return h('div', { class: 'plugin-point-error' }, `[插件 ${this.label}] 渲染失败`);
4592
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4593
+ function createExtensionPointComponent(VueLike = Vue__default.default) {
4594
+ ensureRegistriesReactive(VueLike);
4595
+ const SlotErrorBoundary = VueLike.extend({
4596
+ name: 'SlotErrorBoundary',
4597
+ props: { label: String },
4598
+ data() {
4599
+ return { error: null };
4600
+ },
4601
+ errorCaptured(err) {
4602
+ this.error = err instanceof Error && err.message ? err.message : String(err);
4603
+ console.error('[wep:ExtensionPoint]', this.label, err);
4604
+ return false;
4605
+ },
4606
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4607
+ render(h) {
4608
+ if (this.error) {
4609
+ return h('div', { class: 'plugin-point-error' }, `[插件 ${this.label}] 渲染失败`);
4610
+ }
4611
+ const d = this.$slots.default;
4612
+ return d && d[0] ? d[0] : h('span');
4591
4613
  }
4592
- const d = this.$slots.default;
4593
- return d && d[0] ? d[0] : h('span');
4594
- }
4595
- });
4596
- var ExtensionPoint = Vue__default.default.extend({
4597
- name: 'ExtensionPoint',
4598
- components: { SlotErrorBoundary },
4599
- props: {
4600
- pointId: { type: String, required: true },
4601
- slotProps: { type: Object, default: () => ({}) }
4602
- },
4603
- computed: {
4604
- items() {
4605
- void registries.slotRevision;
4606
- return registries.slots[this.pointId] || [];
4614
+ });
4615
+ return VueLike.extend({
4616
+ name: 'ExtensionPoint',
4617
+ components: { SlotErrorBoundary },
4618
+ props: {
4619
+ pointId: { type: String, required: true },
4620
+ slotProps: { type: Object, default: () => ({}) }
4607
4621
  },
4608
- forwardProps() {
4609
- return this.slotProps || {};
4622
+ computed: {
4623
+ items() {
4624
+ void registries.slotRevision;
4625
+ return registries.slots[this.pointId] || [];
4626
+ },
4627
+ forwardProps() {
4628
+ return this.slotProps || {};
4629
+ }
4630
+ },
4631
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4632
+ render(h) {
4633
+ return h('div', {
4634
+ class: 'extension-point',
4635
+ attrs: { 'data-point-id': this.pointId }
4636
+ }, this.items.map((item) => h(SlotErrorBoundary, {
4637
+ key: item.key,
4638
+ props: { label: item.pluginId }
4639
+ }, [h(item.component, { props: this.forwardProps })])));
4610
4640
  }
4611
- },
4612
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4613
- render(h) {
4614
- return h('div', {
4615
- class: 'extension-point',
4616
- attrs: { 'data-point-id': this.pointId }
4617
- }, this.items.map((item) => h(SlotErrorBoundary, {
4618
- key: item.key,
4619
- props: { label: item.pluginId }
4620
- }, [h(item.component, { props: this.forwardProps })])));
4621
- }
4622
- });
4641
+ });
4642
+ }
4643
+ var ExtensionPoint = createExtensionPointComponent();
4623
4644
 
4624
4645
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4625
4646
  function installWebExtendPluginVue2(Vue, router, options) {
4626
- if (Vue && ExtensionPoint) {
4627
- Vue.component('ExtensionPoint', ExtensionPoint);
4647
+ if (Vue) {
4648
+ ensureRegistriesReactive(Vue);
4649
+ Vue.component('ExtensionPoint', createExtensionPointComponent(Vue));
4628
4650
  }
4629
4651
  const runtime = resolveRuntimeOptions$1(options || {});
4630
4652
  return bootstrapPlugins$1(router, (id, r, kit) => createHostApi(id, r, kit || {}), runtime);