web-extend-plugin-vue2 0.3.3 → 0.3.5

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
@@ -75,7 +75,7 @@ function getEnvObject() {
75
75
  return raw.__WEP_ENV__;
76
76
  }
77
77
  }
78
- catch {
78
+ catch (_a) {
79
79
  /* ignore */
80
80
  }
81
81
  return null;
@@ -111,7 +111,7 @@ function readProcessEnv(key) {
111
111
  }
112
112
  }
113
113
  }
114
- catch {
114
+ catch (_a) {
115
115
  /* ignore */
116
116
  }
117
117
  return undefined;
@@ -137,7 +137,7 @@ function resolveBundledIsDev() {
137
137
  return true;
138
138
  }
139
139
  }
140
- catch {
140
+ catch (_a) {
141
141
  /* ignore */
142
142
  }
143
143
  try {
@@ -145,7 +145,7 @@ function resolveBundledIsDev() {
145
145
  return true;
146
146
  }
147
147
  }
148
- catch {
148
+ catch (_b) {
149
149
  /* ignore */
150
150
  }
151
151
  return false;
@@ -220,7 +220,7 @@ function isScriptHostAllowed(url, hostSet) {
220
220
  const h = normalizeHost(u.hostname);
221
221
  return hostSet.has(h);
222
222
  }
223
- catch {
223
+ catch (_a) {
224
224
  return false;
225
225
  }
226
226
  }
@@ -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
  : {}),
@@ -3426,7 +3432,7 @@ function parseWebPluginDevMapExplicit(opts) {
3426
3432
  const map = JSON.parse(String(raw));
3427
3433
  return map && typeof map === 'object' ? map : null;
3428
3434
  }
3429
- catch {
3435
+ catch (_a) {
3430
3436
  console.warn('[wep] invalid webPluginDevMapJson / VITE_WEB_PLUGIN_DEV_MAP');
3431
3437
  return null;
3432
3438
  }
@@ -3478,7 +3484,7 @@ async function buildImplicitWebPluginDevMap(opts, hostSet) {
3478
3484
  return {};
3479
3485
  }
3480
3486
  }
3481
- catch {
3487
+ catch (_a) {
3482
3488
  return {};
3483
3489
  }
3484
3490
  const pathPart = opts.webPluginDevEntryPath;
@@ -3502,7 +3508,7 @@ function closeAllPluginDevEventSources() {
3502
3508
  try {
3503
3509
  es.close();
3504
3510
  }
3505
- catch {
3511
+ catch (_a) {
3506
3512
  /* ignore */
3507
3513
  }
3508
3514
  }
@@ -3520,7 +3526,7 @@ function isDevOriginAllowedForSse(origin, hostSet) {
3520
3526
  const u = new URL(origin);
3521
3527
  return hostSet.has(normalizeHost(u.hostname));
3522
3528
  }
3523
- catch {
3529
+ catch (_a) {
3524
3530
  return false;
3525
3531
  }
3526
3532
  }
@@ -3564,7 +3570,7 @@ function startPluginDevSseForMap(devMap, isDev, hostSet, ssePath) {
3564
3570
  try {
3565
3571
  origins.add(new URL(t, window.location.href).origin);
3566
3572
  }
3567
- catch {
3573
+ catch (_a) {
3568
3574
  /* skip */
3569
3575
  }
3570
3576
  }
@@ -3686,15 +3692,254 @@ 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 resolveVueGlobalComponentSource(VueRuntime) {
3769
+ if (!VueRuntime || typeof VueRuntime !== 'object' || Array.isArray(VueRuntime)) {
3770
+ return undefined;
3771
+ }
3772
+ const maybeOptions = VueRuntime.options;
3773
+ if (!maybeOptions || typeof maybeOptions !== 'object' || Array.isArray(maybeOptions)) {
3774
+ return undefined;
3775
+ }
3776
+ const maybeComponents = maybeOptions.components;
3777
+ return maybeComponents && typeof maybeComponents === 'object' && !Array.isArray(maybeComponents)
3778
+ ? maybeComponents
3779
+ : undefined;
3780
+ }
3781
+ function resolveHostComponentMeta(metaInput, name, component) {
3782
+ const raw = typeof metaInput === 'function' ? metaInput(name, component) : metaInput;
3783
+ return raw && typeof raw === 'object' && !Array.isArray(raw)
3784
+ ? normalizeExposeMeta(raw)
3785
+ : {};
3786
+ }
3787
+ function registerHostComponents(input) {
3788
+ const entries = normalizeNamedEntries(input, normalizeHostComponentEntry);
3789
+ for (const { name, entry } of entries) {
3790
+ hostComponentsRegistry[name] = {
3791
+ value: entry.component,
3792
+ meta: normalizeExposeMeta(entry)
3793
+ };
3794
+ }
3795
+ return getAllHostComponentMeta();
3796
+ }
3797
+ function registerHostModules(input) {
3798
+ const entries = normalizeNamedEntries(input, normalizeHostModuleEntry);
3799
+ for (const { name, entry } of entries) {
3800
+ hostModulesRegistry[name] = {
3801
+ value: entry.module,
3802
+ meta: normalizeExposeMeta(entry)
3803
+ };
3804
+ }
3805
+ return getAllHostModuleMeta();
3806
+ }
3807
+ function registerVueGlobalComponents(VueRuntime, options = {}) {
3808
+ const source = options.source && typeof options.source === 'object' && !Array.isArray(options.source)
3809
+ ? options.source
3810
+ : resolveVueGlobalComponentSource(VueRuntime);
3811
+ if (!source) {
3812
+ return getAllHostComponentMeta();
3813
+ }
3814
+ const registry = {};
3815
+ for (const [rawName, component] of Object.entries(source)) {
3816
+ const sourceName = String(rawName).trim();
3817
+ if (!sourceName || component == null) {
3818
+ continue;
3819
+ }
3820
+ if (typeof options.include === 'function' && !options.include(sourceName, component)) {
3821
+ continue;
3822
+ }
3823
+ const mappedName = typeof options.mapName === 'function' ? options.mapName(sourceName, component) : sourceName;
3824
+ const exposeName = typeof mappedName === 'string' ? mappedName.trim() : '';
3825
+ if (!exposeName) {
3826
+ continue;
3827
+ }
3828
+ registry[exposeName] = {
3829
+ component,
3830
+ ...resolveHostComponentMeta(options.meta, sourceName, component)
3831
+ };
3832
+ }
3833
+ return registerHostComponents(registry);
3834
+ }
3835
+ function getHostComponent(name) {
3836
+ const key = typeof name === 'string' ? name.trim() : '';
3837
+ if (!key) {
3838
+ return undefined;
3839
+ }
3840
+ const record = hostComponentsRegistry[key];
3841
+ return record ? record.value : undefined;
3842
+ }
3843
+ function getHostModule(name) {
3844
+ const key = typeof name === 'string' ? name.trim() : '';
3845
+ if (!key) {
3846
+ return undefined;
3847
+ }
3848
+ const record = hostModulesRegistry[key];
3849
+ return record ? record.value : undefined;
3850
+ }
3851
+ function getHostComponentMeta(name) {
3852
+ const key = typeof name === 'string' ? name.trim() : '';
3853
+ const record = key ? hostComponentsRegistry[key] : undefined;
3854
+ const meta = record ? record.meta : undefined;
3855
+ return meta ? { ...meta } : undefined;
3856
+ }
3857
+ function getHostModuleMeta(name) {
3858
+ const key = typeof name === 'string' ? name.trim() : '';
3859
+ const record = key ? hostModulesRegistry[key] : undefined;
3860
+ const meta = record ? record.meta : undefined;
3861
+ return meta ? { ...meta } : undefined;
3862
+ }
3863
+ function getAllHostComponentMeta() {
3864
+ return cloneMetaMap(hostComponentsRegistry);
3865
+ }
3866
+ function getAllHostModuleMeta() {
3867
+ return cloneMetaMap(hostModulesRegistry);
3868
+ }
3869
+ function normalizeHostCapabilities(input) {
3870
+ const moduleMeta = getAllHostModuleMeta();
3871
+ const componentMeta = getAllHostComponentMeta();
3872
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
3873
+ const fallback = {};
3874
+ if (Object.keys(moduleMeta).length > 0) {
3875
+ fallback.modules = moduleMeta;
3876
+ }
3877
+ if (Object.keys(componentMeta).length > 0) {
3878
+ fallback.components = componentMeta;
3879
+ }
3880
+ return Object.keys(fallback).length > 0 ? Object.freeze(fallback) : undefined;
3881
+ }
3882
+ const raw = input;
3883
+ const normalized = { ...raw };
3884
+ if (raw.ui && typeof raw.ui === 'object' && !Array.isArray(raw.ui)) {
3885
+ const uiRaw = raw.ui;
3886
+ const ui = {};
3887
+ if (typeof uiRaw.framework === 'string' && uiRaw.framework.trim()) {
3888
+ ui.framework = uiRaw.framework.trim();
3889
+ }
3890
+ if (typeof uiRaw.componentLibrary === 'string' && uiRaw.componentLibrary.trim()) {
3891
+ ui.componentLibrary = uiRaw.componentLibrary.trim();
3892
+ }
3893
+ normalized.ui = ui;
3894
+ }
3895
+ const mergedModules = { ...moduleMeta };
3896
+ if (raw.modules && typeof raw.modules === 'object' && !Array.isArray(raw.modules)) {
3897
+ for (const [name, meta] of Object.entries(raw.modules)) {
3898
+ if (!name.trim()) {
3899
+ continue;
3900
+ }
3901
+ mergedModules[name.trim()] =
3902
+ meta && typeof meta === 'object' && !Array.isArray(meta)
3903
+ ? {
3904
+ ...(mergedModules[name.trim()] || {}),
3905
+ ...normalizeExposeMeta(meta)
3906
+ }
3907
+ : { ...(mergedModules[name.trim()] || {}) };
3908
+ }
3909
+ }
3910
+ const mergedComponents = { ...componentMeta };
3911
+ if (raw.components && typeof raw.components === 'object' && !Array.isArray(raw.components)) {
3912
+ for (const [name, meta] of Object.entries(raw.components)) {
3913
+ if (!name.trim()) {
3914
+ continue;
3915
+ }
3916
+ mergedComponents[name.trim()] =
3917
+ meta && typeof meta === 'object' && !Array.isArray(meta)
3918
+ ? {
3919
+ ...(mergedComponents[name.trim()] || {}),
3920
+ ...normalizeExposeMeta(meta)
3921
+ }
3922
+ : { ...(mergedComponents[name.trim()] || {}) };
3923
+ }
3924
+ }
3925
+ if (Object.keys(mergedModules).length > 0) {
3926
+ normalized.modules = mergedModules;
3927
+ }
3928
+ if (Object.keys(mergedComponents).length > 0) {
3929
+ normalized.components = mergedComponents;
3930
+ }
3931
+ return Object.freeze(normalized);
3932
+ }
3933
+
3934
+ function freezeShallowHostContext(input, explicitCapabilities) {
3935
+ const base = input != null && typeof input === 'object' && !Array.isArray(input)
3936
+ ? { ...input }
3937
+ : {};
3938
+ const mergedCapabilities = normalizeHostCapabilities(explicitCapabilities !== undefined ? explicitCapabilities : base.capabilities);
3939
+ if (mergedCapabilities) {
3940
+ base.capabilities = mergedCapabilities;
3696
3941
  }
3697
- return Object.freeze({ ...input });
3942
+ return Object.freeze(base);
3698
3943
  }
3699
3944
 
3700
3945
  /**
@@ -3716,7 +3961,7 @@ function resolveStaticManifestUrlForFetch(url, origin) {
3716
3961
  const pathPart = u.startsWith('/') ? u : `/${u}`;
3717
3962
  return new URL(pathPart, o).href;
3718
3963
  }
3719
- catch {
3964
+ catch (_a) {
3720
3965
  return u;
3721
3966
  }
3722
3967
  }
@@ -3902,7 +4147,7 @@ createHostApiFactory, runtimeOptions) {
3902
4147
  }
3903
4148
  const devMap = mergeDevMaps(implicit, explicit);
3904
4149
  startPluginDevSseForMap(devMap, opts.isDev, hostSet, opts.devReloadSsePath);
3905
- const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined);
4150
+ const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined, opts.hostCapabilities && typeof opts.hostCapabilities === 'object' ? opts.hostCapabilities : undefined);
3906
4151
  const hostKit = {
3907
4152
  hostContext: frozenHostContext,
3908
4153
  bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes,
@@ -4102,13 +4347,13 @@ function manifestFetchCacheMiddleware$1(options = {}) {
4102
4347
  return structuredClone(r);
4103
4348
  }
4104
4349
  }
4105
- catch {
4350
+ catch (_a) {
4106
4351
  /* ignore */
4107
4352
  }
4108
4353
  try {
4109
4354
  return JSON.parse(JSON.stringify(r));
4110
4355
  }
4111
- catch {
4356
+ catch (_b) {
4112
4357
  return { ...r, data: r.data };
4113
4358
  }
4114
4359
  }
@@ -4146,7 +4391,7 @@ function manifestFetchCacheMiddleware$1(options = {}) {
4146
4391
  }
4147
4392
  return res;
4148
4393
  }
4149
- catch {
4394
+ catch (_a) {
4150
4395
  return null;
4151
4396
  }
4152
4397
  }
@@ -4154,7 +4399,7 @@ function manifestFetchCacheMiddleware$1(options = {}) {
4154
4399
  try {
4155
4400
  store.setItem(key, JSON.stringify({ expiresAt, result }));
4156
4401
  }
4157
- catch {
4402
+ catch (_a) {
4158
4403
  /* Quota / 不可序列化 */
4159
4404
  }
4160
4405
  }
@@ -4247,7 +4492,7 @@ function normalizeBridgePath(input) {
4247
4492
  try {
4248
4493
  return decodeURIComponent(normalized);
4249
4494
  }
4250
- catch {
4495
+ catch (_a) {
4251
4496
  return normalized;
4252
4497
  }
4253
4498
  })();
@@ -4574,6 +4819,10 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
4574
4819
  throw new Error('registerSanitizedHtmlSnippet is not enabled');
4575
4820
  },
4576
4821
  getContributedRoutes: () => getContributedRoutesForPlugin(pluginId),
4822
+ getHostModule,
4823
+ getHostModuleMeta,
4824
+ getHostComponent,
4825
+ getHostComponentMeta,
4577
4826
  getBridge: () => bridge,
4578
4827
  onTeardown(_pluginId, fn) {
4579
4828
  if (typeof fn === 'function') {
@@ -4729,5 +4978,5 @@ function createVueCliAxiosInstallOptions(deps, extra = {}) {
4729
4978
  const { bootstrapPlugins, defaultFetchWebPluginManifest, resolveRuntimeOptions, ensurePluginHostRoute, getActivatedPluginIds } = pluginRuntime;
4730
4979
  const { composeManifestFetch, manifestFetchCacheMiddleware, wrapManifestFetchWithCache } = manifestComposer;
4731
4980
 
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 };
4981
+ 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, registerVueGlobalComponents, registries, resolveRuntimeOptions, routeSynthNamePrefix, setWebExtendPluginEnv, webExtendPluginEnvKeys, wrapManifestFetchWithCache };
4733
4982
  //# sourceMappingURL=index.mjs.map