UNPKG

@lcap/nasl

Version:

NetEase Application Specific Language

149 lines 6.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadCustomUIDeclaration = exports.loadCustomDetail = exports.getVersion = void 0; const format_1 = require("./format"); const LOAD_ASSETS_URL = '/api/v1/asset-center/component/'; const LOAD_ASSETS_PARAMS = { platformVersion: '1.0.0', type: 'extend', offset: 0, limit: 1000, }; function getVersion(version) { if (!version) return { majorVersion: null, minorVersion: null }; const versionList = version.split('.'); const majorVersion = versionList[0]; const minorVersion = versionList.length > 2 ? `${versionList[1]}.${versionList[2]}` : `${versionList[1]}`; return { majorVersion, minorVersion }; } exports.getVersion = getVersion; ; // 官方扩展组件从官方获取详情 async function loadCustomDetail(originCustomItem, query, { appInfo, axios }, { officialCustomMap, componentApi }) { const { name } = originCustomItem; if (officialCustomMap[name]) { query = { ...query, tenantId: appInfo.tenantID, }; } const version = `${query.majorVersion}.${query.minorVersion}`; const response = await axios.get(`/api/v1/asset-center/component/${query.symbol}/version/${version}`, { params: query }); if (!response.data || !response.data.result || !response.data.result.symbol) { return; } const { jsonSchema, depDescription, dsl } = response.data.result; try { componentApi[name] = JSON.parse(jsonSchema || '{}'); componentApi[name].props = componentApi[name].props || componentApi[name].attrs || []; componentApi[name].props.forEach((prop) => { prop.name = (0, format_1.attrKebab2Camel)(prop.name); if (prop['designer-value']) { prop.designerValue = prop['designer-value']; delete prop['designer-value']; } (0, format_1.formatCustomSetter)(prop); }); const { blocks, screenShot, drawings } = componentApi[name]; // 根据 jsonSchema 补充原始组件选项数据 Object.assign(originCustomItem, { blocks: Array.isArray(blocks) ? blocks : JSON.parse(blocks), screenshots: screenShot ? screenShot.split(',') : [], drawings: drawings ? drawings.split(',') : [], props: componentApi[name].props, }); } catch (error) { componentApi[name] = {}; } Object.assign(componentApi[name], { depDescription, dsl, }); const { children } = componentApi[name]; if (Array.isArray(children)) { children.forEach((child) => { (0, format_1.formatSub)(child, componentApi); }); } } exports.loadCustomDetail = loadCustomDetail; ; async function loadCustomComponentAPI(hasComponentList = [], context, { originCustomList, officialCustomMap, componentApi }) { const { app } = context; //console.log('-----------getCustomComponentAPI start----------') const resultList = (originCustomList || []).filter((item) => hasComponentList.includes(item.name)); if (!Array.isArray(resultList) || resultList.length === 0) { return; } await Promise.all(resultList.map((originCustomItem) => { const { name, curMajorVersion, curMinorVersion } = originCustomItem; const query = { symbol: name, majorVersion: curMajorVersion, minorVersion: curMinorVersion, }; // 应用内置版本跟最新版本不一致时,以实际版本为准 const componentDependenciesForType = app.genAllCustomComponents(); const componentDependencies = [...componentDependenciesForType.pc, ...componentDependenciesForType.h5]; if (componentDependencies) { const diffCustom = componentDependencies.find((item) => item.name === name && item.version !== `${curMajorVersion}.${curMinorVersion}`); if (diffCustom) { const { minorVersion, majorVersion } = getVersion(diffCustom.version); query.minorVersion = minorVersion; query.majorVersion = majorVersion; } } return loadCustomDetail(originCustomItem, query, context, { officialCustomMap, componentApi }); })); } ; async function loadCustomUIDeclaration(context) { const { axios, app, appInfo } = context; const [response1, response2] = await Promise.all([ axios.get(LOAD_ASSETS_URL, { params: { ...LOAD_ASSETS_PARAMS, tenantId: appInfo.tenantID }, }), axios.get(LOAD_ASSETS_URL, { params: { ...LOAD_ASSETS_PARAMS, }, }), ]); const { result: officialResult } = response1.data; const { result } = response2.data; const rows = {}; const officialCustomMapTemp = {}; // 默认以官方租户内容为准 if (Array.isArray(officialResult.rows)) { officialResult.rows.forEach((item) => { officialCustomMapTemp[item.symbol] = true; (0, format_1.formatItem)(item, rows); }); } // symbol 不包含在官方租户内,再添加进来 if (Array.isArray(result.rows)) { result.rows.forEach((item) => { if (!officialCustomMapTemp[item.symbol]) { (0, format_1.formatItem)(item, rows); } }); } const officialCustomMap = officialCustomMapTemp; const originCustomList = Object.values(rows); const hasComponentList = app.frontendTypes.map((frontendType) => frontendType?.componentDependencies?.map((t) => t?.name) || []).flat(2); const componentApi = {}; await loadCustomComponentAPI(hasComponentList, context, { officialCustomMap, originCustomList, componentApi }); return { allNodesAPI: componentApi, componentList: originCustomList, officialCustomMap, }; } exports.loadCustomUIDeclaration = loadCustomUIDeclaration; //# sourceMappingURL=custom.js.map