@next-core/brick-utils 2.48.1 → 2.49.0
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.bundle.js +220 -7
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +216 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/snippetEvaluate.d.ts +17 -0
- package/dist/types/snippetEvaluate.spec.d.ts +1 -0
- package/dist/types/visitStoryboard.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
2
|
-
import { uniq, get, cloneDeep, set, isEmpty, escapeRegExp, remove } from 'lodash';
|
|
2
|
+
import lodash, { uniq, get, cloneDeep, set, isEmpty, escapeRegExp, remove } from 'lodash';
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
5
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
6
|
import _taggedTemplateLiteral from '@babel/runtime/helpers/taggedTemplateLiteral';
|
|
7
|
-
import { processPipes, utils } from '@next-core/pipes';
|
|
7
|
+
import { processPipes, utils, pipes } from '@next-core/pipes';
|
|
8
8
|
export { pipes } from '@next-core/pipes';
|
|
9
|
+
import moment from 'moment';
|
|
9
10
|
import yaml from 'js-yaml';
|
|
10
11
|
|
|
11
12
|
var cache$1 = new Map();
|
|
@@ -17477,7 +17478,7 @@ function precookFunction(source) {
|
|
|
17477
17478
|
// `raw` should always be asserted by `isEvaluable`.
|
|
17478
17479
|
function preevaluate(raw, options) {
|
|
17479
17480
|
var fixes = [];
|
|
17480
|
-
var source = raw.replace(/^\s*<%[
|
|
17481
|
+
var source = raw.replace(/^\s*<%[~=!]?\s|\s%>\s*$/g, m => {
|
|
17481
17482
|
fixes.push(m);
|
|
17482
17483
|
return "";
|
|
17483
17484
|
});
|
|
@@ -17499,6 +17500,9 @@ function isEvaluable(raw) {
|
|
|
17499
17500
|
function shouldAllowRecursiveEvaluations(raw) {
|
|
17500
17501
|
return /^\s*<%~\s/.test(raw);
|
|
17501
17502
|
}
|
|
17503
|
+
function isSnippetEvaluation(raw) {
|
|
17504
|
+
return /^\s*<%[!@]\s/.test(raw) && /\s%>\s*$/.test(raw);
|
|
17505
|
+
}
|
|
17502
17506
|
function isTrackAll(raw) {
|
|
17503
17507
|
return /^\s*<%=\s/.test(raw) && /\s%>\s*$/.test(raw);
|
|
17504
17508
|
}
|
|
@@ -17553,13 +17557,14 @@ options) {
|
|
|
17553
17557
|
var {
|
|
17554
17558
|
matchExpressionString,
|
|
17555
17559
|
visitNonExpressionString,
|
|
17556
|
-
visitObject
|
|
17560
|
+
visitObject,
|
|
17561
|
+
customIsEvaluable = isEvaluable
|
|
17557
17562
|
} = typeof options === "string" ? {
|
|
17558
17563
|
matchExpressionString: v => v.includes(options)
|
|
17559
17564
|
} : options;
|
|
17560
17565
|
function visit(value) {
|
|
17561
17566
|
if (typeof value === "string") {
|
|
17562
|
-
if (matchExpressionString(value) &&
|
|
17567
|
+
if (matchExpressionString(value) && customIsEvaluable(value)) {
|
|
17563
17568
|
try {
|
|
17564
17569
|
preevaluate(value, {
|
|
17565
17570
|
withParent: true,
|
|
@@ -20399,5 +20404,210 @@ function isConstantLogical(node, expect, options) {
|
|
|
20399
20404
|
return node.type === "LogicalExpression" ? node.operator === (expect ? "||" : "&&") && [node.left, node.right].some(item => isConstantLogical(item, expect, options)) : node.type === "UnaryExpression" ? node.operator === "!" && isConstantLogical(node.argument, !expect, options) : node.type === "Literal" ? !!node.value === expect : node.type === "Identifier" ? node.name === "undefined" ? !expect : false : constantFeatureFlags && node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "FLAGS" && (node.computed ? node.property.type === "Literal" && typeof node.property.value === "string" && !!featureFlags[node.property.value] === expect : node.property.type === "Identifier" && !!featureFlags[node.property.name] === expect);
|
|
20400
20405
|
}
|
|
20401
20406
|
|
|
20402
|
-
|
|
20407
|
+
function supply(attemptToVisitGlobals, providedGlobalVariables, mock) {
|
|
20408
|
+
var globalVariables = _objectSpread({}, providedGlobalVariables);
|
|
20409
|
+
// Allow limited browser builtin values.
|
|
20410
|
+
globalVariables["undefined"] = undefined;
|
|
20411
|
+
for (var variableName of attemptToVisitGlobals) {
|
|
20412
|
+
if (!Object.prototype.hasOwnProperty.call(globalVariables, variableName)) {
|
|
20413
|
+
var variable = supplyIndividual(variableName, mock);
|
|
20414
|
+
if (variable !== undefined) {
|
|
20415
|
+
globalVariables[variableName] = variable;
|
|
20416
|
+
}
|
|
20417
|
+
}
|
|
20418
|
+
}
|
|
20419
|
+
return globalVariables;
|
|
20420
|
+
}
|
|
20421
|
+
var shouldOmitInLodash = new Set([
|
|
20422
|
+
// Omit all mutable methods from lodash.
|
|
20423
|
+
// But allow sequence methods like `_.chain`.
|
|
20424
|
+
"fill", "pull", "pullAll", "pullAllBy", "pullAllWith", "pullAt", "remove", "reverse", "assign", "assignIn", "assignInWith", "assignWith", "defaults", "defaultsDeep", "merge", "mergeWith", "set", "setWith", "unset", "update", "updateWith",
|
|
20425
|
+
/**
|
|
20426
|
+
* Ignore `Function` methods from lodash, too.
|
|
20427
|
+
* There are chances to invoke `Object.assign`, etc.
|
|
20428
|
+
*
|
|
20429
|
+
* E.g.:
|
|
20430
|
+
*
|
|
20431
|
+
* ```
|
|
20432
|
+
* _.wrap(_.method('constructor.assign',{b:2},{b:3}),(func,...a) => func(...a))({})
|
|
20433
|
+
* ```
|
|
20434
|
+
*/
|
|
20435
|
+
"after", "ary", "before", "bind", "bindKey", "curry", "curryRight", "debounce", "defer", "delay", "flip", "memoize", "negate", "once", "overArgs", "partial", "partialRight", "rearg", "rest", "spread", "throttle", "unary", "wrap"]);
|
|
20436
|
+
|
|
20437
|
+
// Omit all mutable methods from moment.
|
|
20438
|
+
var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
|
|
20439
|
+
var allowedGlobalObjects = new Set(["Array", "Boolean", "Date", "Infinity", "JSON", "Math", "NaN", "Number", "String", "RegExp", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isFinite", "isNaN", "parseFloat", "parseInt", "Map", "Set", "URLSearchParams", "WeakMap", "WeakSet", "atob", "btoa"]);
|
|
20440
|
+
function supplyIndividual(variableName, mock) {
|
|
20441
|
+
switch (variableName) {
|
|
20442
|
+
case "Object":
|
|
20443
|
+
// Do not allow mutable methods like `Object.assign`.
|
|
20444
|
+
return delegateMethods(Object, ["entries", "fromEntries", "keys", "values"]);
|
|
20445
|
+
case "_":
|
|
20446
|
+
return Object.fromEntries(Object.entries(lodash).filter(entry => !shouldOmitInLodash.has(entry[0])).concat(mock ? [["uniqueId", prefix => "".concat(prefix !== null && prefix !== void 0 ? prefix : "", "42")]] : []));
|
|
20447
|
+
case "moment":
|
|
20448
|
+
return Object.assign(function () {
|
|
20449
|
+
return moment(...arguments);
|
|
20450
|
+
}, Object.fromEntries(Object.entries(moment).filter(entry => !shouldOmitInMoment.has(entry[0]))));
|
|
20451
|
+
case "PIPES":
|
|
20452
|
+
return pipes;
|
|
20453
|
+
case "TAG_URL":
|
|
20454
|
+
return tagUrlFactory(true);
|
|
20455
|
+
case "SAFE_TAG_URL":
|
|
20456
|
+
return tagUrlFactory();
|
|
20457
|
+
default:
|
|
20458
|
+
if (allowedGlobalObjects.has(variableName)) {
|
|
20459
|
+
return window[variableName];
|
|
20460
|
+
}
|
|
20461
|
+
}
|
|
20462
|
+
}
|
|
20463
|
+
function delegateMethods(target, methods) {
|
|
20464
|
+
return Object.fromEntries(methods.map(method => [method, function () {
|
|
20465
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
20466
|
+
args[_key] = arguments[_key];
|
|
20467
|
+
}
|
|
20468
|
+
return target[method].apply(target, args);
|
|
20469
|
+
}]));
|
|
20470
|
+
}
|
|
20471
|
+
/**
|
|
20472
|
+
* Pass `ignoreSlashes` as `true` to encode all tagged expressions
|
|
20473
|
+
* as URL components, except for `/` which maybe used in `APP.homepage`.
|
|
20474
|
+
*
|
|
20475
|
+
* Otherwise encode all tagged expressions as URL components.
|
|
20476
|
+
* This will encode `/` as `%2F`. So do not use it directly
|
|
20477
|
+
* with `APP.homepage` as in template expressions.
|
|
20478
|
+
*
|
|
20479
|
+
* @example
|
|
20480
|
+
*
|
|
20481
|
+
* ```js
|
|
20482
|
+
* TAG_URL`${APP.homepage}/list?q=${q}&redirect=${redirect}`
|
|
20483
|
+
* ```
|
|
20484
|
+
*
|
|
20485
|
+
* ```js
|
|
20486
|
+
* SAFE_TAG_URL`file/${path}?q=${q}`
|
|
20487
|
+
* // `path` will be fully transformed by `encodeURIComponent`.
|
|
20488
|
+
* ```
|
|
20489
|
+
*
|
|
20490
|
+
* ```js
|
|
20491
|
+
* // Wrap `APP.homepage` outside of `SAFE_TAG_URL`.
|
|
20492
|
+
* `${APP.homepage}/${SAFE_TAG_URL`file/${path}?q=${q}`}`
|
|
20493
|
+
* ```
|
|
20494
|
+
*/
|
|
20495
|
+
function tagUrlFactory(ignoreSlashes) {
|
|
20496
|
+
return function (strings) {
|
|
20497
|
+
for (var _len2 = arguments.length, partials = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
20498
|
+
partials[_key2 - 1] = arguments[_key2];
|
|
20499
|
+
}
|
|
20500
|
+
var result = [];
|
|
20501
|
+
strings.forEach((str, index) => {
|
|
20502
|
+
result.push(str);
|
|
20503
|
+
if (index < partials.length) {
|
|
20504
|
+
result.push(ignoreSlashes ? String(partials[index]).replace(/[^/]+/g, p => encodeURIComponent(p)) : encodeURIComponent(String(partials[index])));
|
|
20505
|
+
}
|
|
20506
|
+
});
|
|
20507
|
+
return result.join("");
|
|
20508
|
+
};
|
|
20509
|
+
}
|
|
20510
|
+
|
|
20511
|
+
function beforeVisitSnippetParamsFactory(collection) {
|
|
20512
|
+
return function beforeVisitParams(node, parent) {
|
|
20513
|
+
if (node.name === "SNIPPET_PARAMS") {
|
|
20514
|
+
var memberParent = parent[parent.length - 1];
|
|
20515
|
+
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
20516
|
+
if (!memberParent.node.computed && memberParent.node.property.type === "Identifier") {
|
|
20517
|
+
collection.add(memberParent.node.property.name);
|
|
20518
|
+
} else if (memberParent.node.computed && memberParent.node.property.type === "Literal") {
|
|
20519
|
+
collection.add(memberParent.node.property.value);
|
|
20520
|
+
}
|
|
20521
|
+
}
|
|
20522
|
+
}
|
|
20523
|
+
};
|
|
20524
|
+
}
|
|
20525
|
+
function checkParamsValid(nameList, context) {
|
|
20526
|
+
var {
|
|
20527
|
+
declareParams = {},
|
|
20528
|
+
inputParams = {}
|
|
20529
|
+
} = context;
|
|
20530
|
+
return nameList.forEach(name => {
|
|
20531
|
+
var _declareParams$name;
|
|
20532
|
+
var type = (_declareParams$name = declareParams[name]) === null || _declareParams$name === void 0 ? void 0 : _declareParams$name.type;
|
|
20533
|
+
if (!type) {
|
|
20534
|
+
throw new Error("Missing type of ".concat(name, " in snippet params"));
|
|
20535
|
+
}
|
|
20536
|
+
var valid = ["string", "number", "boolean"].includes(type);
|
|
20537
|
+
if (!valid) {
|
|
20538
|
+
throw new Error("The ".concat(type, " type is not supported of ").concat(name, " in snippet params"));
|
|
20539
|
+
}
|
|
20540
|
+
var actualType = inputParams[name];
|
|
20541
|
+
if (actualType !== undefined && typeof actualType !== type) {
|
|
20542
|
+
throw new Error("The ".concat(name, " is declared as type ").concat(type, ", but it is receiving a value of type ").concat(typeof actualType));
|
|
20543
|
+
}
|
|
20544
|
+
});
|
|
20545
|
+
}
|
|
20546
|
+
function scanSnippetInStoryboard(data) {
|
|
20547
|
+
var collection = new Set();
|
|
20548
|
+
var beforeVisitGlobal = beforeVisitSnippetParamsFactory(collection);
|
|
20549
|
+
visitStoryboardExpressions(data, beforeVisitGlobal, {
|
|
20550
|
+
matchExpressionString: v => v.includes("SNIPPET_PARAMS"),
|
|
20551
|
+
customIsEvaluable: isSnippetEvaluation
|
|
20552
|
+
});
|
|
20553
|
+
return Array.from(collection);
|
|
20554
|
+
}
|
|
20555
|
+
function computeRealSnippetConf(value, context) {
|
|
20556
|
+
if (typeof value === "string" && isSnippetEvaluation(value)) {
|
|
20557
|
+
try {
|
|
20558
|
+
var raw = value;
|
|
20559
|
+
var ctxOrState = context.rootType === "template" ? "STATE" : "CTX";
|
|
20560
|
+
if (/^\s*<%@\s/.test(value)) {
|
|
20561
|
+
var replacements = [{
|
|
20562
|
+
search: "<%@",
|
|
20563
|
+
replace: "<%"
|
|
20564
|
+
}, {
|
|
20565
|
+
search: /\bCTX_OR_STATE\b/g,
|
|
20566
|
+
replace: ctxOrState
|
|
20567
|
+
}];
|
|
20568
|
+
var _result = value;
|
|
20569
|
+
replacements.forEach(replacement => {
|
|
20570
|
+
_result = _result.replace(replacement.search, replacement.replace);
|
|
20571
|
+
});
|
|
20572
|
+
return _result;
|
|
20573
|
+
}
|
|
20574
|
+
var globalVariables = {};
|
|
20575
|
+
var {
|
|
20576
|
+
expression,
|
|
20577
|
+
attemptToVisitGlobals,
|
|
20578
|
+
source
|
|
20579
|
+
} = preevaluate(raw);
|
|
20580
|
+
var attemptVisitSnippetParams = attemptToVisitGlobals.has("SNIPPET_PARAMS");
|
|
20581
|
+
if (attemptVisitSnippetParams) {
|
|
20582
|
+
globalVariables.SNIPPET_PARAMS = context.inputParams;
|
|
20583
|
+
}
|
|
20584
|
+
var result = cook(expression, source, {
|
|
20585
|
+
globalVariables: supply(attemptToVisitGlobals, globalVariables)
|
|
20586
|
+
});
|
|
20587
|
+
return result;
|
|
20588
|
+
} catch (error) {
|
|
20589
|
+
/* istanbul ignore next */
|
|
20590
|
+
// eslint-disable-next-line no-console
|
|
20591
|
+
console.error("Parse storyboard expression failed:", error);
|
|
20592
|
+
}
|
|
20593
|
+
}
|
|
20594
|
+
if (!isObject$1(value)) {
|
|
20595
|
+
return value;
|
|
20596
|
+
}
|
|
20597
|
+
if (Array.isArray(value)) {
|
|
20598
|
+
return value.map(v => computeRealSnippetConf(v, context));
|
|
20599
|
+
}
|
|
20600
|
+
return Object.fromEntries(Object.entries(value).map(_ref => {
|
|
20601
|
+
var [k, v] = _ref;
|
|
20602
|
+
return [computeRealSnippetConf(k, context), computeRealSnippetConf(v, context)];
|
|
20603
|
+
}));
|
|
20604
|
+
}
|
|
20605
|
+
function snippetEvaluate(brickConf, context) {
|
|
20606
|
+
var collection = scanSnippetInStoryboard(brickConf);
|
|
20607
|
+
checkParamsValid(collection, context);
|
|
20608
|
+
var result = computeRealSnippetConf(brickConf, context);
|
|
20609
|
+
return result;
|
|
20610
|
+
}
|
|
20611
|
+
|
|
20612
|
+
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, collectContextUsage, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, deferResolveContextConcurrently, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject$1 as isObject, isRouteNode, isSnippetEvaluation, isSnippetNode, isTrackAll, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseBrick, parseForAnalysis, parseRoutes, parseStoryboard, parseTemplate, parseTemplates, precook, precookFunction, preevaluate, prefetchScript, removeDeadConditions, removeDeadConditionsInTpl, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanStoryboardAst, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, snippetEvaluate, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackAll, trackContext, trackFormState, trackState, trackUsedContext, trackUsedFormState, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
20403
20613
|
//# sourceMappingURL=index.esm.js.map
|