seer-dynamic-component
Advanced tools
Comparing version 1.6.1 to 1.6.2
253
lib/index.js
@@ -18,24 +18,16 @@ import "core-js/modules/es6.reflect.construct.js"; | ||
import "core-js/modules/es6.array.find-index.js"; | ||
import "core-js/modules/es6.string.starts-with.js"; | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
import React from "react"; | ||
import { getCompInfo, loadRealComponent } from "./utils"; | ||
import { getCompInfo, loadRealComponent, getLangData as _getLangData } from "./utils"; | ||
var lang = require('ac-lang-cn').default; | ||
var SeerDynamicComponent = /*#__PURE__*/function (_React$Component) { | ||
_inherits(SeerDynamicComponent, _React$Component); | ||
var _super = _createSuper(SeerDynamicComponent); | ||
function SeerDynamicComponent(props) { | ||
var _this; | ||
_classCallCheck(this, SeerDynamicComponent); | ||
_this = _super.call(this, props); | ||
_defineProperty(_assertThisInitialized(_this), "id", ""); | ||
_this.state = { | ||
@@ -45,10 +37,7 @@ ModuleComponent: null, | ||
}; | ||
if (!props.id) { | ||
console.error('[SeerDynamicComponent]: Component id is missing!'); | ||
} | ||
return _this; | ||
} | ||
_createClass(SeerDynamicComponent, [{ | ||
@@ -61,92 +50,78 @@ key: "loadComponent", | ||
function () { | ||
var _loadComponent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, relativePath) { | ||
var _loadComponent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(id, relativePath) { | ||
var _this2 = this; | ||
var targetComp, injectReducer; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return getCompInfo(id, relativePath); | ||
case 2: | ||
targetComp = _context2.sent; | ||
injectReducer = this.props.injectReducer; | ||
if (targetComp) { | ||
_context2.next = 8; | ||
break; | ||
} | ||
this.setState({ | ||
findComponent: false | ||
}); | ||
_context2.next = 9; | ||
var targetComp, injectReducer, _id, reducers, targetComponent, injectReducers, _loop, i; | ||
return _regeneratorRuntime.wrap(function _callee$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return getCompInfo(id, relativePath); | ||
case 2: | ||
targetComp = _context2.sent; | ||
injectReducer = this.props.injectReducer; | ||
if (targetComp) { | ||
_context2.next = 8; | ||
break; | ||
case 8: | ||
return _context2.delegateYield( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var id, reducers, targetComponent, injectReducers, _loop, i; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
id = targetComp.id, reducers = targetComp.reducers; | ||
_context.next = 3; | ||
return loadRealComponent(targetComp, id, "components_", "componentsIn", relativePath); | ||
case 3: | ||
targetComponent = _context.sent; | ||
if (!(injectReducer && Array.isArray(reducers) && reducers.length > 0)) { | ||
_context.next = 10; | ||
break; | ||
} | ||
injectReducers = []; | ||
_loop = function _loop(i) { | ||
var routers = window.seerConfig.routers || []; | ||
var targetRoute = routers.find(function (router) { | ||
return Array.isArray(router.reducer) ? router.reducer.findIndex(function (reducer) { | ||
return reducer === reducers[i]; | ||
}) > -1 : router.reducer === reducers[i]; | ||
}); | ||
targetRoute && injectReducers.push(_this2.injectReducer(targetRoute, reducers[i], injectReducer, relativePath)); | ||
}; | ||
for (i = 0; i < reducers.length; i++) { | ||
_loop(i); | ||
} | ||
_context.next = 10; | ||
return Promise.all(injectReducers); | ||
case 10: | ||
_this2.setState({ | ||
ModuleComponent: targetComponent | ||
}); | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})(), "t0", 9); | ||
case 9: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
this.setState({ | ||
findComponent: false | ||
}); | ||
_context2.next = 24; | ||
break; | ||
case 8: | ||
_id = targetComp.id, reducers = targetComp.reducers; | ||
_context2.next = 11; | ||
return loadRealComponent(targetComp, _id, "components_", "componentsIn", relativePath); | ||
case 11: | ||
targetComponent = _context2.sent; | ||
if (!(injectReducer && Array.isArray(reducers) && reducers.length > 0)) { | ||
_context2.next = 23; | ||
break; | ||
} | ||
injectReducers = []; | ||
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop(i) { | ||
var routers, targetRoute; | ||
return _regeneratorRuntime.wrap(function _loop$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
routers = window.seerConfig.routers || []; | ||
targetRoute = routers.find(function (router) { | ||
return Array.isArray(router.reducer) ? router.reducer.findIndex(function (reducer) { | ||
return reducer === reducers[i]; | ||
}) > -1 : router.reducer === reducers[i]; | ||
}); | ||
targetRoute && injectReducers.push(_this2.injectReducer(targetRoute, reducers[i], injectReducer, relativePath)); | ||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _loop); | ||
}); | ||
i = 0; | ||
case 16: | ||
if (!(i < reducers.length)) { | ||
_context2.next = 21; | ||
break; | ||
} | ||
return _context2.delegateYield(_loop(i), "t0", 18); | ||
case 18: | ||
i++; | ||
_context2.next = 16; | ||
break; | ||
case 21: | ||
_context2.next = 23; | ||
return Promise.all(injectReducers); | ||
case 23: | ||
this.setState({ | ||
ModuleComponent: targetComponent | ||
}); | ||
case 24: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
}, _callee, this); | ||
})); | ||
function loadComponent(_x, _x2) { | ||
return _loadComponent.apply(this, arguments); | ||
} | ||
return loadComponent; | ||
@@ -159,34 +134,26 @@ }() | ||
*/ | ||
}, { | ||
key: "injectReducer", | ||
value: function () { | ||
var _injectReducer2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(targetRoute, reducerId, _injectReducer, relativePath) { | ||
var _injectReducer2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(targetRoute, reducerId, _injectReducer, relativePath) { | ||
var reducerComp; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return loadRealComponent(targetRoute, reducerId, "reducer_", "moduleIns", relativePath); | ||
case 2: | ||
reducerComp = _context3.sent; | ||
if (reducerComp) { | ||
_injectReducer(reducerId, reducerComp); | ||
} | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
return _regeneratorRuntime.wrap(function _callee2$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return loadRealComponent(targetRoute, reducerId, "reducer_", "moduleIns", relativePath); | ||
case 2: | ||
reducerComp = _context3.sent; | ||
if (reducerComp) { | ||
_injectReducer(reducerId, reducerComp); | ||
} | ||
case 4: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
}, _callee3); | ||
}, _callee2); | ||
})); | ||
function injectReducer(_x3, _x4, _x5, _x6) { | ||
return _injectReducer2.apply(this, arguments); | ||
} | ||
return injectReducer; | ||
@@ -198,14 +165,45 @@ }() | ||
var _this$props = this.props, | ||
id = _this$props.id, | ||
_this$props$relativeP = _this$props.relativePath, | ||
relativePath = _this$props$relativeP === void 0 ? "/" : _this$props$relativeP; | ||
id = _this$props.id, | ||
groupCode = _this$props.groupCode, | ||
_this$props$relativeP = _this$props.relativePath, | ||
relativePath = _this$props$relativeP === void 0 ? "/" : _this$props$relativeP; | ||
this.getLangData(id, groupCode); | ||
if (id) this.loadComponent(id, relativePath); | ||
} | ||
//加載多語資源 | ||
}, { | ||
key: "getLangData", | ||
value: function getLangData(id, groupCode) { | ||
if (!id) { | ||
return; | ||
} | ||
var includeFw = true; | ||
if (!groupCode) { | ||
if (id.startsWith('datamodel.') || id.startsWith('dimension.') || id.startsWith('semantic.')) { | ||
groupCode = 'YS_PF_DATAMODEL-FE'; | ||
includeFw = false; | ||
} else { | ||
groupCode = 'YS_PF_ANALYTIC-FE'; | ||
} | ||
} | ||
if (window.lang) { | ||
_getLangData({ | ||
groupCode: groupCode, | ||
includeFw: includeFw | ||
}); | ||
} else { | ||
_getLangData({ | ||
groupCode: groupCode, | ||
includeFw: includeFw, | ||
lang: lang | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var _this$state = this.state, | ||
ModuleComponent = _this$state.ModuleComponent, | ||
findComponent = _this$state.findComponent; | ||
ModuleComponent = _this$state.ModuleComponent, | ||
findComponent = _this$state.findComponent; | ||
if (!findComponent) { | ||
@@ -215,3 +213,2 @@ console.error('未找到组件'); | ||
} | ||
if (!ModuleComponent) return null; | ||
@@ -221,6 +218,4 @@ return /*#__PURE__*/React.createElement(ModuleComponent, this.props); | ||
}]); | ||
return SeerDynamicComponent; | ||
}(React.Component); | ||
export { SeerDynamicComponent as default }; |
167
lib/utils.js
@@ -9,7 +9,4 @@ import "core-js/modules/es6.object.keys.js"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
import "core-js/modules/es6.object.to-string.js"; | ||
@@ -22,3 +19,5 @@ import "core-js/modules/es6.promise.js"; | ||
import "core-js/modules/es6.regexp.replace.js"; | ||
import "core-js/modules/es6.regexp.to-string.js"; | ||
import "core-js/modules/es6.string.includes.js"; | ||
import "core-js/modules/es7.array.includes.js"; | ||
/** | ||
@@ -35,3 +34,2 @@ * 获取组件配置信息 | ||
}); | ||
if (targetComp) { | ||
@@ -44,3 +42,2 @@ resolve(targetComp); | ||
delete window.default; | ||
if (res.default) { | ||
@@ -60,3 +57,4 @@ var config = res.default; | ||
console.warn(e); | ||
resolve(); // reject(); | ||
resolve(); | ||
// reject(); | ||
}); | ||
@@ -80,2 +78,3 @@ }); | ||
}; | ||
/* | ||
@@ -89,3 +88,2 @@ * 动态获取组件 | ||
*/ | ||
export var loadRealComponent = function loadRealComponent(targetComp, compId, fp) { | ||
@@ -97,11 +95,10 @@ var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "componentsIn"; | ||
var module = targetComp.module, | ||
_targetComp$packageNa = targetComp.packageName, | ||
packageName = _targetComp$packageNa === void 0 ? "index" : _targetComp$packageNa, | ||
_targetComp$packageHa = targetComp.packageHash, | ||
packageHash = _targetComp$packageHa === void 0 ? "" : _targetComp$packageHa, | ||
_targetComp$splitChun = targetComp.splitChunkName, | ||
splitChunkName = _targetComp$splitChun === void 0 ? '' : _targetComp$splitChun; | ||
_targetComp$packageNa = targetComp.packageName, | ||
packageName = _targetComp$packageNa === void 0 ? "index" : _targetComp$packageNa, | ||
_targetComp$packageHa = targetComp.packageHash, | ||
packageHash = _targetComp$packageHa === void 0 ? "" : _targetComp$packageHa, | ||
_targetComp$splitChun = targetComp.splitChunkName, | ||
splitChunkName = _targetComp$splitChun === void 0 ? '' : _targetComp$splitChun; | ||
var jsName = "".concat(packageName).concat(packageHash ? "." + packageHash : "", ".js"); | ||
window.seerConfig[key] = window.seerConfig[key] || {}; | ||
if (window.seerConfig[key][module]) { | ||
@@ -116,50 +113,38 @@ var comp = window.seerConfig[key][module][tranCompId]; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
delete window.default; | ||
if (!(res && res.default)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
if (!res.default.default) { | ||
_context.next = 6; | ||
break; | ||
} | ||
window.seerConfig[key][module] = res.default.default; | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
delete window.default; | ||
if (!(res && res.default)) { | ||
_context.next = 13; | ||
break; | ||
case 6: | ||
if (!res.default.init) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 9; | ||
return res.default.init(); | ||
case 9: | ||
window.seerConfig[key][module] = _context.sent; | ||
_context.next = 13; | ||
} | ||
if (!res.default.default) { | ||
_context.next = 6; | ||
break; | ||
case 12: | ||
window.seerConfig[key][module] = res.default; | ||
case 13: | ||
comp = window.seerConfig[key][module][tranCompId]; | ||
resolve(comp); | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
window.seerConfig[key][module] = res.default.default; | ||
_context.next = 13; | ||
break; | ||
case 6: | ||
if (!res.default.init) { | ||
_context.next = 12; | ||
break; | ||
} | ||
_context.next = 9; | ||
return res.default.init(); | ||
case 9: | ||
window.seerConfig[key][module] = _context.sent; | ||
_context.next = 13; | ||
break; | ||
case 12: | ||
window.seerConfig[key][module] = res.default; | ||
case 13: | ||
comp = window.seerConfig[key][module][tranCompId]; | ||
resolve(comp); | ||
case 15: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
@@ -174,5 +159,3 @@ return _ref.apply(this, arguments); | ||
}; | ||
window.loadedSplitChunk = window.loadedSplitChunk || {}; | ||
if (splitChunkName && !window.loadedSplitChunk[splitChunkName]) { | ||
@@ -189,2 +172,68 @@ var chunkUrl = "".concat(relativePath + module, "/js/").concat(splitChunkName, ".chunk.js"); | ||
}); | ||
}; | ||
var xssFilter = function xssFilter(v) { | ||
var val = v; | ||
if (val) { | ||
val = val.toString(); | ||
val = val.replace(">", ">"); | ||
val = val.replace("<", "<"); | ||
val = val.replace('"', """); | ||
val = val.replace("'", "'"); | ||
val = val.replace("\r", ""); | ||
val = val.replace("\n", ""); | ||
val = val.replace("\r\n", ""); | ||
} | ||
return val; | ||
}; | ||
//获取当前平台的多语资源 | ||
export var getLangData = function getLangData(_ref2) { | ||
var groupCode = _ref2.groupCode, | ||
tenantid = _ref2.tenantid, | ||
langApi = _ref2.langApi, | ||
lang = _ref2.lang, | ||
packJs = _ref2.packJs, | ||
callback = _ref2.callback, | ||
includeFw = _ref2.includeFw; | ||
//已经加载过的则不需要再次加载 | ||
if (window.seerConfig && window.seerConfig.groupCodeList && window.seerConfig.groupCodeList.includes(groupCode)) { | ||
callback && callback(data); | ||
return true; | ||
} | ||
lang = lang || window.lang; | ||
if (!lang) { | ||
return false; | ||
} | ||
if (typeof includeFw === 'undefined') { | ||
includeFw = true; | ||
} | ||
var diworkContext = window.diworkContext ? window.diworkContext() : null; | ||
if (diworkContext) { | ||
if (!diworkContext.ext.multilingualFlag) { | ||
return false; | ||
} | ||
if (!tenantid) { | ||
tenantid = diworkContext.tenantid; | ||
} | ||
} else if (seerConfig && seerConfig.userInfo) { | ||
var userInfo = seerConfig.userInfo || {}; | ||
if (!userInfo.enableMultilingual) { | ||
return false; | ||
} | ||
if (!tenantid) { | ||
tenantid = userInfo.tenantPk || '0'; //可以直接从url中取 | ||
} | ||
} | ||
langApi = langApi || (window._YMSHOST_ ? window._YMSHOST_ : xssFilter(window.location.origin)) + "/iuap-apcom-i18n"; | ||
lang.init(packJs || {}); | ||
lang.jsonpUuid(tenantid, groupCode, langApi, function (data) { | ||
callback && callback(data); | ||
}, 'YS', includeFw); | ||
//把已经加载过的多语模块存入全局变量中 | ||
window.seerConfig = window.seerConfig || {}; | ||
window.seerConfig.groupCodeList = window.seerConfig.groupCodeList || []; | ||
if (!window.seerConfig.groupCodeList.includes(groupCode)) { | ||
window.seerConfig.groupCodeList.push(groupCode); | ||
} | ||
return true; | ||
}; |
{ | ||
"name": "seer-dynamic-component", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
18977
440
2