web-extend-plugin-vue2 0.3.2 → 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.cjs +209 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +202 -10
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +74 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -401,6 +401,12 @@ function resolveRuntimeOptions$1(user = {}) {
|
|
|
401
401
|
!Array.isArray(user.hostContext)
|
|
402
402
|
? { hostContext: user.hostContext }
|
|
403
403
|
: {}),
|
|
404
|
+
...(user.hostCapabilities !== undefined &&
|
|
405
|
+
user.hostCapabilities !== null &&
|
|
406
|
+
typeof user.hostCapabilities === 'object' &&
|
|
407
|
+
!Array.isArray(user.hostCapabilities)
|
|
408
|
+
? { hostCapabilities: user.hostCapabilities }
|
|
409
|
+
: {}),
|
|
404
410
|
...(typeof user.onBeforePluginActivate === 'function'
|
|
405
411
|
? { onBeforePluginActivate: user.onBeforePluginActivate }
|
|
406
412
|
: {}),
|
|
@@ -3692,15 +3698,197 @@ function ensurePluginHostRoute$1(router, opts) {
|
|
|
3692
3698
|
});
|
|
3693
3699
|
}
|
|
3694
3700
|
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3701
|
+
const hostComponentsRegistry = Object.create(null);
|
|
3702
|
+
const hostModulesRegistry = Object.create(null);
|
|
3703
|
+
function normalizeExposeMeta(raw) {
|
|
3704
|
+
const meta = {};
|
|
3705
|
+
if (typeof raw.title === 'string' && raw.title.trim()) {
|
|
3706
|
+
meta.title = raw.title.trim();
|
|
3707
|
+
}
|
|
3708
|
+
if (typeof raw.description === 'string' && raw.description.trim()) {
|
|
3709
|
+
meta.description = raw.description.trim();
|
|
3710
|
+
}
|
|
3711
|
+
return meta;
|
|
3712
|
+
}
|
|
3713
|
+
function normalizeHostComponentEntry(entry) {
|
|
3714
|
+
if (!entry) {
|
|
3715
|
+
return null;
|
|
3716
|
+
}
|
|
3717
|
+
if (typeof entry === 'object' && !Array.isArray(entry)) {
|
|
3718
|
+
const record = entry;
|
|
3719
|
+
if ('component' in record) {
|
|
3720
|
+
return {
|
|
3721
|
+
component: record.component,
|
|
3722
|
+
...normalizeExposeMeta(record)
|
|
3723
|
+
};
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
return { component: entry };
|
|
3727
|
+
}
|
|
3728
|
+
function normalizeHostModuleEntry(entry) {
|
|
3729
|
+
if (!entry) {
|
|
3730
|
+
return null;
|
|
3731
|
+
}
|
|
3732
|
+
if (typeof entry === 'object' && !Array.isArray(entry)) {
|
|
3733
|
+
const record = entry;
|
|
3734
|
+
if ('module' in record) {
|
|
3735
|
+
return {
|
|
3736
|
+
module: record.module,
|
|
3737
|
+
...normalizeExposeMeta(record)
|
|
3738
|
+
};
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
return { module: entry };
|
|
3742
|
+
}
|
|
3743
|
+
function normalizeNamedEntries(input, normalizeEntry) {
|
|
3744
|
+
if (Array.isArray(input)) {
|
|
3745
|
+
return input
|
|
3746
|
+
.map((item) => {
|
|
3747
|
+
const name = typeof item.name === 'string' ? item.name.trim() : '';
|
|
3748
|
+
const entry = normalizeEntry(item);
|
|
3749
|
+
if (!name || !entry) {
|
|
3750
|
+
return null;
|
|
3751
|
+
}
|
|
3752
|
+
return { name, entry };
|
|
3753
|
+
})
|
|
3754
|
+
.filter(Boolean);
|
|
3755
|
+
}
|
|
3756
|
+
return Object.entries(input || {})
|
|
3757
|
+
.map(([rawName, rawEntry]) => {
|
|
3758
|
+
const name = String(rawName).trim();
|
|
3759
|
+
const entry = normalizeEntry(rawEntry);
|
|
3760
|
+
if (!name || !entry) {
|
|
3761
|
+
return null;
|
|
3762
|
+
}
|
|
3763
|
+
return { name, entry };
|
|
3764
|
+
})
|
|
3765
|
+
.filter(Boolean);
|
|
3766
|
+
}
|
|
3767
|
+
function cloneMetaMap(registry) {
|
|
3768
|
+
const out = {};
|
|
3769
|
+
for (const [name, entry] of Object.entries(registry)) {
|
|
3770
|
+
out[name] = { ...entry.meta };
|
|
3771
|
+
}
|
|
3772
|
+
return out;
|
|
3773
|
+
}
|
|
3774
|
+
function registerHostComponents(input) {
|
|
3775
|
+
const entries = normalizeNamedEntries(input, normalizeHostComponentEntry);
|
|
3776
|
+
for (const { name, entry } of entries) {
|
|
3777
|
+
hostComponentsRegistry[name] = {
|
|
3778
|
+
value: entry.component,
|
|
3779
|
+
meta: normalizeExposeMeta(entry)
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
return getAllHostComponentMeta();
|
|
3783
|
+
}
|
|
3784
|
+
function registerHostModules(input) {
|
|
3785
|
+
const entries = normalizeNamedEntries(input, normalizeHostModuleEntry);
|
|
3786
|
+
for (const { name, entry } of entries) {
|
|
3787
|
+
hostModulesRegistry[name] = {
|
|
3788
|
+
value: entry.module,
|
|
3789
|
+
meta: normalizeExposeMeta(entry)
|
|
3790
|
+
};
|
|
3791
|
+
}
|
|
3792
|
+
return getAllHostModuleMeta();
|
|
3793
|
+
}
|
|
3794
|
+
function getHostComponent(name) {
|
|
3795
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
3796
|
+
return key ? hostComponentsRegistry[key]?.value : undefined;
|
|
3797
|
+
}
|
|
3798
|
+
function getHostModule(name) {
|
|
3799
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
3800
|
+
return key ? hostModulesRegistry[key]?.value : undefined;
|
|
3801
|
+
}
|
|
3802
|
+
function getHostComponentMeta(name) {
|
|
3803
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
3804
|
+
const meta = key ? hostComponentsRegistry[key]?.meta : undefined;
|
|
3805
|
+
return meta ? { ...meta } : undefined;
|
|
3806
|
+
}
|
|
3807
|
+
function getHostModuleMeta(name) {
|
|
3808
|
+
const key = typeof name === 'string' ? name.trim() : '';
|
|
3809
|
+
const meta = key ? hostModulesRegistry[key]?.meta : undefined;
|
|
3810
|
+
return meta ? { ...meta } : undefined;
|
|
3811
|
+
}
|
|
3812
|
+
function getAllHostComponentMeta() {
|
|
3813
|
+
return cloneMetaMap(hostComponentsRegistry);
|
|
3814
|
+
}
|
|
3815
|
+
function getAllHostModuleMeta() {
|
|
3816
|
+
return cloneMetaMap(hostModulesRegistry);
|
|
3817
|
+
}
|
|
3818
|
+
function normalizeHostCapabilities(input) {
|
|
3819
|
+
const moduleMeta = getAllHostModuleMeta();
|
|
3820
|
+
const componentMeta = getAllHostComponentMeta();
|
|
3821
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
3822
|
+
const fallback = {};
|
|
3823
|
+
if (Object.keys(moduleMeta).length > 0) {
|
|
3824
|
+
fallback.modules = moduleMeta;
|
|
3825
|
+
}
|
|
3826
|
+
if (Object.keys(componentMeta).length > 0) {
|
|
3827
|
+
fallback.components = componentMeta;
|
|
3828
|
+
}
|
|
3829
|
+
return Object.keys(fallback).length > 0 ? Object.freeze(fallback) : undefined;
|
|
3830
|
+
}
|
|
3831
|
+
const raw = input;
|
|
3832
|
+
const normalized = { ...raw };
|
|
3833
|
+
if (raw.ui && typeof raw.ui === 'object' && !Array.isArray(raw.ui)) {
|
|
3834
|
+
const uiRaw = raw.ui;
|
|
3835
|
+
const ui = {};
|
|
3836
|
+
if (typeof uiRaw.framework === 'string' && uiRaw.framework.trim()) {
|
|
3837
|
+
ui.framework = uiRaw.framework.trim();
|
|
3838
|
+
}
|
|
3839
|
+
if (typeof uiRaw.componentLibrary === 'string' && uiRaw.componentLibrary.trim()) {
|
|
3840
|
+
ui.componentLibrary = uiRaw.componentLibrary.trim();
|
|
3841
|
+
}
|
|
3842
|
+
normalized.ui = ui;
|
|
3843
|
+
}
|
|
3844
|
+
const mergedModules = { ...moduleMeta };
|
|
3845
|
+
if (raw.modules && typeof raw.modules === 'object' && !Array.isArray(raw.modules)) {
|
|
3846
|
+
for (const [name, meta] of Object.entries(raw.modules)) {
|
|
3847
|
+
if (!name.trim()) {
|
|
3848
|
+
continue;
|
|
3849
|
+
}
|
|
3850
|
+
mergedModules[name.trim()] =
|
|
3851
|
+
meta && typeof meta === 'object' && !Array.isArray(meta)
|
|
3852
|
+
? {
|
|
3853
|
+
...(mergedModules[name.trim()] || {}),
|
|
3854
|
+
...normalizeExposeMeta(meta)
|
|
3855
|
+
}
|
|
3856
|
+
: { ...(mergedModules[name.trim()] || {}) };
|
|
3857
|
+
}
|
|
3858
|
+
}
|
|
3859
|
+
const mergedComponents = { ...componentMeta };
|
|
3860
|
+
if (raw.components && typeof raw.components === 'object' && !Array.isArray(raw.components)) {
|
|
3861
|
+
for (const [name, meta] of Object.entries(raw.components)) {
|
|
3862
|
+
if (!name.trim()) {
|
|
3863
|
+
continue;
|
|
3864
|
+
}
|
|
3865
|
+
mergedComponents[name.trim()] =
|
|
3866
|
+
meta && typeof meta === 'object' && !Array.isArray(meta)
|
|
3867
|
+
? {
|
|
3868
|
+
...(mergedComponents[name.trim()] || {}),
|
|
3869
|
+
...normalizeExposeMeta(meta)
|
|
3870
|
+
}
|
|
3871
|
+
: { ...(mergedComponents[name.trim()] || {}) };
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
if (Object.keys(mergedModules).length > 0) {
|
|
3875
|
+
normalized.modules = mergedModules;
|
|
3876
|
+
}
|
|
3877
|
+
if (Object.keys(mergedComponents).length > 0) {
|
|
3878
|
+
normalized.components = mergedComponents;
|
|
3879
|
+
}
|
|
3880
|
+
return Object.freeze(normalized);
|
|
3881
|
+
}
|
|
3882
|
+
|
|
3883
|
+
function freezeShallowHostContext(input, explicitCapabilities) {
|
|
3884
|
+
const base = input != null && typeof input === 'object' && !Array.isArray(input)
|
|
3885
|
+
? { ...input }
|
|
3886
|
+
: {};
|
|
3887
|
+
const mergedCapabilities = normalizeHostCapabilities(explicitCapabilities !== undefined ? explicitCapabilities : base.capabilities);
|
|
3888
|
+
if (mergedCapabilities) {
|
|
3889
|
+
base.capabilities = mergedCapabilities;
|
|
3702
3890
|
}
|
|
3703
|
-
return Object.freeze(
|
|
3891
|
+
return Object.freeze(base);
|
|
3704
3892
|
}
|
|
3705
3893
|
|
|
3706
3894
|
/**
|
|
@@ -3908,7 +4096,7 @@ createHostApiFactory, runtimeOptions) {
|
|
|
3908
4096
|
}
|
|
3909
4097
|
const devMap = mergeDevMaps(implicit, explicit);
|
|
3910
4098
|
startPluginDevSseForMap(devMap, opts.isDev, hostSet, opts.devReloadSsePath);
|
|
3911
|
-
const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined);
|
|
4099
|
+
const frozenHostContext = freezeShallowHostContext(opts.hostContext !== undefined ? opts.hostContext : undefined, opts.hostCapabilities && typeof opts.hostCapabilities === 'object' ? opts.hostCapabilities : undefined);
|
|
3912
4100
|
const hostKit = {
|
|
3913
4101
|
hostContext: frozenHostContext,
|
|
3914
4102
|
bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes,
|
|
@@ -4580,6 +4768,10 @@ function createHostApi(pluginId, router, hostKitOptions = {}) {
|
|
|
4580
4768
|
throw new Error('registerSanitizedHtmlSnippet is not enabled');
|
|
4581
4769
|
},
|
|
4582
4770
|
getContributedRoutes: () => getContributedRoutesForPlugin(pluginId),
|
|
4771
|
+
getHostModule,
|
|
4772
|
+
getHostModuleMeta,
|
|
4773
|
+
getHostComponent,
|
|
4774
|
+
getHostComponentMeta,
|
|
4583
4775
|
getBridge: () => bridge,
|
|
4584
4776
|
onTeardown(_pluginId, fn) {
|
|
4585
4777
|
if (typeof fn === 'function') {
|
|
@@ -4750,11 +4942,19 @@ exports.defaultWebExtendPluginRuntime = defaultWebExtendPluginRuntime;
|
|
|
4750
4942
|
exports.disposeWebPlugin = disposeWebPlugin;
|
|
4751
4943
|
exports.ensurePluginHostRoute = ensurePluginHostRoute;
|
|
4752
4944
|
exports.getActivatedPluginIds = getActivatedPluginIds;
|
|
4945
|
+
exports.getAllHostComponentMeta = getAllHostComponentMeta;
|
|
4946
|
+
exports.getAllHostModuleMeta = getAllHostModuleMeta;
|
|
4753
4947
|
exports.getContributedRoutesForPlugin = getContributedRoutesForPlugin;
|
|
4948
|
+
exports.getHostComponent = getHostComponent;
|
|
4949
|
+
exports.getHostComponentMeta = getHostComponentMeta;
|
|
4950
|
+
exports.getHostModule = getHostModule;
|
|
4951
|
+
exports.getHostModuleMeta = getHostModuleMeta;
|
|
4754
4952
|
exports.getRegisteredTopRouteNamesForPlugin = getRegisteredTopRouteNamesForPlugin;
|
|
4755
4953
|
exports.installWebExtendPluginVue2 = installWebExtendPluginVue2;
|
|
4756
4954
|
exports.manifestFetchCacheMiddleware = manifestFetchCacheMiddleware;
|
|
4757
4955
|
exports.peerMinimumVersions = peerMinimumVersions;
|
|
4956
|
+
exports.registerHostComponents = registerHostComponents;
|
|
4957
|
+
exports.registerHostModules = registerHostModules;
|
|
4758
4958
|
exports.registries = registries;
|
|
4759
4959
|
exports.resolveRuntimeOptions = resolveRuntimeOptions;
|
|
4760
4960
|
exports.routeSynthNamePrefix = routeSynthNamePrefix;
|