web-extend-plugin-vue2 0.3.3 → 0.3.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.
package/dist/index.mjs CHANGED
@@ -395,6 +395,12 @@ function resolveRuntimeOptions$1(user = {}) {
395
395
  !Array.isArray(user.hostContext)
396
396
  ? { hostContext: user.hostContext }
397
397
  : {}),
398
+ ...(user.hostCapabilities !== undefined &&
399
+ user.hostCapabilities !== null &&
400
+ typeof user.hostCapabilities === 'object' &&
401
+ !Array.isArray(user.hostCapabilities)
402
+ ? { hostCapabilities: user.hostCapabilities }
403
+ : {}),
398
404
  ...(typeof user.onBeforePluginActivate === 'function'
399
405
  ? { onBeforePluginActivate: user.onBeforePluginActivate }
400
406
  : {}),
@@ -3686,15 +3692,197 @@ function ensurePluginHostRoute$1(router, opts) {
3686
3692
  });
3687
3693
  }
3688
3694
 
3689
- /**
3690
- * 宿主通过 `resolveRuntimeOptions({ hostContext })` 注入的只读上下文,
3691
- * 经浅拷贝 + 浅冻结后挂到 `hostApi.hostContext`,供插件访问 store/i18n 等而不污染 HostApi 顶层命名。
3692
- */
3693
- function freezeShallowHostContext(input) {
3694
- if (input == null || typeof input !== 'object' || Array.isArray(input)) {
3695
- return Object.freeze({});
3695
+ const hostComponentsRegistry = Object.create(null);
3696
+ const hostModulesRegistry = Object.create(null);
3697
+ function normalizeExposeMeta(raw) {
3698
+ const meta = {};
3699
+ if (typeof raw.title === 'string' && raw.title.trim()) {
3700
+ meta.title = raw.title.trim();
3701
+ }
3702
+ if (typeof raw.description === 'string' && raw.description.trim()) {
3703
+ meta.description = raw.description.trim();
3704
+ }
3705
+ return meta;
3706
+ }
3707
+ function normalizeHostComponentEntry(entry) {
3708
+ if (!entry) {
3709
+ return null;
3710
+ }
3711
+ if (typeof entry === 'object' && !Array.isArray(entry)) {
3712
+ const record = entry;
3713
+ if ('component' in record) {
3714
+ return {
3715
+ component: record.component,
3716
+ ...normalizeExposeMeta(record)
3717
+ };
3718
+ }
3719
+ }
3720
+ return { component: entry };
3721
+ }
3722
+ function normalizeHostModuleEntry(entry) {
3723
+ if (!entry) {
3724
+ return null;
3725
+ }
3726
+ if (typeof entry === 'object' && !Array.isArray(entry)) {
3727
+ const record = entry;
3728
+ if ('module' in record) {
3729
+ return {
3730
+ module: record.module,
3731
+ ...normalizeExposeMeta(record)
3732
+ };
3733
+ }
3734
+ }
3735
+ return { module: entry };
3736
+ }
3737
+ function normalizeNamedEntries(input, normalizeEntry) {
3738
+ if (Array.isArray(input)) {
3739
+ return input
3740
+ .map((item) => {
3741
+ const name = typeof item.name === 'string' ? item.name.trim() : '';
3742
+ const entry = normalizeEntry(item);
3743
+ if (!name || !entry) {
3744
+ return null;
3745
+ }
3746
+ return { name, entry };
3747
+ })
3748
+ .filter(Boolean);
3749
+ }
3750
+ return Object.entries(input || {})
3751
+ .map(([rawName, rawEntry]) => {
3752
+ const name = String(rawName).trim();
3753
+ const entry = normalizeEntry(rawEntry);
3754
+ if (!name || !entry) {
3755
+ return null;
3756
+ }
3757
+ return { name, entry };
3758
+ })
3759
+ .filter(Boolean);
3760
+ }
3761
+ function cloneMetaMap(registry) {
3762
+ const out = {};
3763
+ for (const [name, entry] of Object.entries(registry)) {
3764
+ out[name] = { ...entry.meta };
3765
+ }
3766
+ return out;
3767
+ }
3768
+ function registerHostComponents(input) {
3769
+ const entries = normalizeNamedEntries(input, normalizeHostComponentEntry);
3770
+ for (const { name, entry } of entries) {
3771
+ hostComponentsRegistry[name] = {
3772
+ value: entry.component,
3773
+ meta: normalizeExposeMeta(entry)
3774
+ };
3775
+ }
3776
+ return getAllHostComponentMeta();
3777
+ }
3778
+ function registerHostModules(input) {
3779
+ const entries = normalizeNamedEntries(input, normalizeHostModuleEntry);
3780
+ for (const { name, entry } of entries) {
3781
+ hostModulesRegistry[name] = {
3782
+ value: entry.module,
3783
+ meta: normalizeExposeMeta(entry)
3784
+ };
3785
+ }
3786
+ return getAllHostModuleMeta();
3787
+ }
3788
+ function getHostComponent(name) {
3789
+ const key = typeof name === 'string' ? name.trim() : '';
3790
+ return key ? hostComponentsRegistry[key]?.value : undefined;
3791
+ }
3792
+ function getHostModule(name) {
3793
+ const key = typeof name === 'string' ? name.trim() : '';
3794
+ return key ? hostModulesRegistry[key]?.value : undefined;
3795
+ }
3796
+ function getHostComponentMeta(name) {
3797
+ const key = typeof name === 'string' ? name.trim() : '';
3798
+ const meta = key ? hostComponentsRegistry[key]?.meta : undefined;
3799
+ return meta ? { ...meta } : undefined;
3800
+ }
3801
+ function getHostModuleMeta(name) {
3802
+ const key = typeof name === 'string' ? name.trim() : '';
3803
+ const meta = key ? hostModulesRegistry[key]?.meta : undefined;
3804
+ return meta ? { ...meta } : undefined;
3805
+ }
3806
+ function getAllHostComponentMeta() {
3807
+ return cloneMetaMap(hostComponentsRegistry);
3808
+ }
3809
+ function getAllHostModuleMeta() {
3810
+ return cloneMetaMap(hostModulesRegistry);
3811
+ }
3812
+ function normalizeHostCapabilities(input) {
3813
+ const moduleMeta = getAllHostModuleMeta();
3814
+ const componentMeta = getAllHostComponentMeta();
3815
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
3816
+ const fallback = {};
3817
+ if (Object.keys(moduleMeta).length > 0) {
3818
+ fallback.modules = moduleMeta;
3819
+ }
3820
+ if (Object.keys(componentMeta).length > 0) {
3821
+ fallback.components = componentMeta;
3822
+ }
3823
+ return Object.keys(fallback).length > 0 ? Object.freeze(fallback) : undefined;
3824
+ }
3825
+ const raw = input;
3826
+ const normalized = { ...raw };
3827
+ if (raw.ui && typeof raw.ui === 'object' && !Array.isArray(raw.ui)) {
3828
+ const uiRaw = raw.ui;
3829
+ const ui = {};
3830
+ if (typeof uiRaw.framework === 'string' && uiRaw.framework.trim()) {
3831
+ ui.framework = uiRaw.framework.trim();
3832
+ }
3833
+ if (typeof uiRaw.componentLibrary === 'string' && uiRaw.componentLibrary.trim()) {
3834
+ ui.componentLibrary = uiRaw.componentLibrary.trim();
3835
+ }
3836
+ normalized.ui = ui;
3837
+ }
3838
+ const mergedModules = { ...moduleMeta };
3839
+ if (raw.modules && typeof raw.modules === 'object' && !Array.isArray(raw.modules)) {
3840
+ for (const [name, meta] of Object.entries(raw.modules)) {
3841
+ if (!name.trim()) {
3842
+ continue;
3843
+ }
3844
+ mergedModules[name.trim()] =
3845
+ meta && typeof meta === 'object' && !Array.isArray(meta)
3846
+ ? {
3847
+ ...(mergedModules[name.trim()] || {}),
3848
+ ...normalizeExposeMeta(meta)
3849
+ }
3850
+ : { ...(mergedModules[name.trim()] || {}) };
3851
+ }
3852
+ }
3853
+ const mergedComponents = { ...componentMeta };
3854
+ if (raw.components && typeof raw.components === 'object' && !Array.isArray(raw.components)) {
3855
+ for (const [name, meta] of Object.entries(raw.components)) {
3856
+ if (!name.trim()) {
3857
+ continue;
3858
+ }
3859
+ mergedComponents[name.trim()] =
3860
+ meta && typeof meta === 'object' && !Array.isArray(meta)
3861
+ ? {
3862
+ ...(mergedComponents[name.trim()] || {}),
3863
+ ...normalizeExposeMeta(meta)
3864
+ }
3865
+ : { ...(mergedComponents[name.trim()] || {}) };
3866
+ }
3867
+ }
3868
+ if (Object.keys(mergedModules).length > 0) {
3869
+ normalized.modules = mergedModules;
3870
+ }
3871
+ if (Object.keys(mergedComponents).length > 0) {
3872
+ normalized.components = mergedComponents;
3873
+ }
3874
+ return Object.freeze(normalized);
3875
+ }
3876
+
3877
+ function freezeShallowHostContext(input, explicitCapabilities) {
3878
+ const base = input != null && typeof input === 'object' && !Array.isArray(input)
3879
+ ? { ...input }
3880
+ : {};
3881
+ const mergedCapabilities = normalizeHostCapabilities(explicitCapabilities !== undefined ? explicitCapabilities : base.capabilities);
3882
+ if (mergedCapabilities) {
3883
+ base.capabilities = mergedCapabilities;
3696
3884
  }
3697
- return Object.freeze({ ...input });
3885
+ return Object.freeze(base);
3698
3886
  }
3699
3887
 
3700
3888
  /**
@@ -3902,7 +4090,7 @@ createHostApiFactory, runtimeOptions) {
3902
4090
  }
3903
4091
  const devMap = mergeDevMaps(implicit, explicit);
3904
4092
  startPluginDevSseForMap(devMap, opts.isDev, hostSet, opts.devReloadSsePath);
3905
- const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined);
4093
+ const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined, opts.hostCapabilities && typeof opts.hostCapabilities === 'object' ? opts.hostCapabilities : undefined);
3906
4094
  const hostKit = {
3907
4095
  hostContext: frozenHostContext,
3908
4096
  bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes,
@@ -4574,6 +4762,10 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4574
4762
  throw new Error('registerSanitizedHtmlSnippet is not enabled');
4575
4763
  },
4576
4764
  getContributedRoutes: () => getContributedRoutesForPlugin(pluginId),
4765
+ getHostModule,
4766
+ getHostModuleMeta,
4767
+ getHostComponent,
4768
+ getHostComponentMeta,
4577
4769
  getBridge: () => bridge,
4578
4770
  onTeardown(_pluginId, fn) {
4579
4771
  if (typeof fn === 'function') {
@@ -4729,5 +4921,5 @@ function createVueCliAxiosInstallOptions(deps, extra = {}) {
4729
4921
  const { bootstrapPlugins, defaultFetchWebPluginManifest, resolveRuntimeOptions, ensurePluginHostRoute, getActivatedPluginIds } = pluginRuntime;
4730
4922
  const { composeManifestFetch, manifestFetchCacheMiddleware, wrapManifestFetchWithCache } = manifestComposer;
4731
4923
 
4732
- export { ExtensionPoint, HOST_PLUGIN_API_VERSION, RUNTIME_CONSOLE_LABEL, bootstrapPlugins, composeManifestFetch, createHostApi, createRequestBridge, createVueCliAxiosInstallOptions, defaultFetchWebPluginManifest, defaultManifestFetchCache, defaultManifestMode, defaultWebExtendPluginRuntime, disposeWebPlugin, ensurePluginHostRoute, getActivatedPluginIds, getContributedRoutesForPlugin, getRegisteredTopRouteNamesForPlugin, installWebExtendPluginVue2, manifestFetchCacheMiddleware, peerMinimumVersions, registries, resolveRuntimeOptions, routeSynthNamePrefix, setWebExtendPluginEnv, webExtendPluginEnvKeys, wrapManifestFetchWithCache };
4924
+ export { ExtensionPoint, HOST_PLUGIN_API_VERSION, RUNTIME_CONSOLE_LABEL, bootstrapPlugins, composeManifestFetch, createHostApi, createRequestBridge, createVueCliAxiosInstallOptions, defaultFetchWebPluginManifest, defaultManifestFetchCache, defaultManifestMode, defaultWebExtendPluginRuntime, disposeWebPlugin, ensurePluginHostRoute, getActivatedPluginIds, getAllHostComponentMeta, getAllHostModuleMeta, getContributedRoutesForPlugin, getHostComponent, getHostComponentMeta, getHostModule, getHostModuleMeta, getRegisteredTopRouteNamesForPlugin, installWebExtendPluginVue2, manifestFetchCacheMiddleware, peerMinimumVersions, registerHostComponents, registerHostModules, registries, resolveRuntimeOptions, routeSynthNamePrefix, setWebExtendPluginEnv, webExtendPluginEnvKeys, wrapManifestFetchWithCache };
4733
4925
  //# sourceMappingURL=index.mjs.map