@next-core/brick-utils 2.48.1 → 2.50.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 +2 -0
- package/dist/types/snippetEvaluate.spec.d.ts +1 -0
- package/dist/types/visitStoryboard.d.ts +1 -0
- package/package.json +5 -5
package/dist/index.bundle.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/asyncToGenerator'), require('lodash'), require('@babel/runtime/helpers/defineProperty'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/objectWithoutProperties'), require('@babel/runtime/helpers/taggedTemplateLiteral'), require('@next-core/pipes'), require('js-yaml')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/asyncToGenerator', 'lodash', '@babel/runtime/helpers/defineProperty', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/objectWithoutProperties', '@babel/runtime/helpers/taggedTemplateLiteral', '@next-core/pipes', 'js-yaml'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickUtils = {}, global._asyncToGenerator, global.lodash, global._defineProperty, global._objectSpread, global._objectWithoutProperties, global._taggedTemplateLiteral, global.pipes, global.yaml));
|
|
5
|
-
})(this, (function (exports, _asyncToGenerator, lodash, _defineProperty, _objectSpread, _objectWithoutProperties, _taggedTemplateLiteral, pipes, yaml) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/asyncToGenerator'), require('lodash'), require('@babel/runtime/helpers/defineProperty'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/objectWithoutProperties'), require('@babel/runtime/helpers/taggedTemplateLiteral'), require('@next-core/pipes'), require('moment'), require('js-yaml')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/asyncToGenerator', 'lodash', '@babel/runtime/helpers/defineProperty', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/objectWithoutProperties', '@babel/runtime/helpers/taggedTemplateLiteral', '@next-core/pipes', 'moment', 'js-yaml'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickUtils = {}, global._asyncToGenerator, global.lodash, global._defineProperty, global._objectSpread, global._objectWithoutProperties, global._taggedTemplateLiteral, global.pipes, global.moment, global.yaml));
|
|
5
|
+
})(this, (function (exports, _asyncToGenerator, lodash, _defineProperty, _objectSpread, _objectWithoutProperties, _taggedTemplateLiteral, pipes, moment, yaml) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
10
|
+
var lodash__default = /*#__PURE__*/_interopDefaultLegacy(lodash);
|
|
10
11
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
11
12
|
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
12
13
|
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
13
14
|
var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
|
|
15
|
+
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
14
16
|
var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
|
|
15
17
|
|
|
16
18
|
var cache$1 = new Map();
|
|
@@ -17482,7 +17484,7 @@
|
|
|
17482
17484
|
// `raw` should always be asserted by `isEvaluable`.
|
|
17483
17485
|
function preevaluate(raw, options) {
|
|
17484
17486
|
var fixes = [];
|
|
17485
|
-
var source = raw.replace(/^\s*<%[
|
|
17487
|
+
var source = raw.replace(/^\s*<%[~=!]?\s|\s%>\s*$/g, m => {
|
|
17486
17488
|
fixes.push(m);
|
|
17487
17489
|
return "";
|
|
17488
17490
|
});
|
|
@@ -17504,6 +17506,9 @@
|
|
|
17504
17506
|
function shouldAllowRecursiveEvaluations(raw) {
|
|
17505
17507
|
return /^\s*<%~\s/.test(raw);
|
|
17506
17508
|
}
|
|
17509
|
+
function isSnippetEvaluation(raw) {
|
|
17510
|
+
return /^\s*<%[!@]\s/.test(raw) && /\s%>\s*$/.test(raw);
|
|
17511
|
+
}
|
|
17507
17512
|
function isTrackAll(raw) {
|
|
17508
17513
|
return /^\s*<%=\s/.test(raw) && /\s%>\s*$/.test(raw);
|
|
17509
17514
|
}
|
|
@@ -17558,13 +17563,14 @@
|
|
|
17558
17563
|
var {
|
|
17559
17564
|
matchExpressionString,
|
|
17560
17565
|
visitNonExpressionString,
|
|
17561
|
-
visitObject
|
|
17566
|
+
visitObject,
|
|
17567
|
+
customIsEvaluable = isEvaluable
|
|
17562
17568
|
} = typeof options === "string" ? {
|
|
17563
17569
|
matchExpressionString: v => v.includes(options)
|
|
17564
17570
|
} : options;
|
|
17565
17571
|
function visit(value) {
|
|
17566
17572
|
if (typeof value === "string") {
|
|
17567
|
-
if (matchExpressionString(value) &&
|
|
17573
|
+
if (matchExpressionString(value) && customIsEvaluable(value)) {
|
|
17568
17574
|
try {
|
|
17569
17575
|
preevaluate(value, {
|
|
17570
17576
|
withParent: true,
|
|
@@ -20404,6 +20410,211 @@
|
|
|
20404
20410
|
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);
|
|
20405
20411
|
}
|
|
20406
20412
|
|
|
20413
|
+
function supply(attemptToVisitGlobals, providedGlobalVariables, mock) {
|
|
20414
|
+
var globalVariables = _objectSpread__default["default"]({}, providedGlobalVariables);
|
|
20415
|
+
// Allow limited browser builtin values.
|
|
20416
|
+
globalVariables["undefined"] = undefined;
|
|
20417
|
+
for (var variableName of attemptToVisitGlobals) {
|
|
20418
|
+
if (!Object.prototype.hasOwnProperty.call(globalVariables, variableName)) {
|
|
20419
|
+
var variable = supplyIndividual(variableName, mock);
|
|
20420
|
+
if (variable !== undefined) {
|
|
20421
|
+
globalVariables[variableName] = variable;
|
|
20422
|
+
}
|
|
20423
|
+
}
|
|
20424
|
+
}
|
|
20425
|
+
return globalVariables;
|
|
20426
|
+
}
|
|
20427
|
+
var shouldOmitInLodash = new Set([
|
|
20428
|
+
// Omit all mutable methods from lodash.
|
|
20429
|
+
// But allow sequence methods like `_.chain`.
|
|
20430
|
+
"fill", "pull", "pullAll", "pullAllBy", "pullAllWith", "pullAt", "remove", "reverse", "assign", "assignIn", "assignInWith", "assignWith", "defaults", "defaultsDeep", "merge", "mergeWith", "set", "setWith", "unset", "update", "updateWith",
|
|
20431
|
+
/**
|
|
20432
|
+
* Ignore `Function` methods from lodash, too.
|
|
20433
|
+
* There are chances to invoke `Object.assign`, etc.
|
|
20434
|
+
*
|
|
20435
|
+
* E.g.:
|
|
20436
|
+
*
|
|
20437
|
+
* ```
|
|
20438
|
+
* _.wrap(_.method('constructor.assign',{b:2},{b:3}),(func,...a) => func(...a))({})
|
|
20439
|
+
* ```
|
|
20440
|
+
*/
|
|
20441
|
+
"after", "ary", "before", "bind", "bindKey", "curry", "curryRight", "debounce", "defer", "delay", "flip", "memoize", "negate", "once", "overArgs", "partial", "partialRight", "rearg", "rest", "spread", "throttle", "unary", "wrap"]);
|
|
20442
|
+
|
|
20443
|
+
// Omit all mutable methods from moment.
|
|
20444
|
+
var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
|
|
20445
|
+
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"]);
|
|
20446
|
+
function supplyIndividual(variableName, mock) {
|
|
20447
|
+
switch (variableName) {
|
|
20448
|
+
case "Object":
|
|
20449
|
+
// Do not allow mutable methods like `Object.assign`.
|
|
20450
|
+
return delegateMethods(Object, ["entries", "fromEntries", "keys", "values"]);
|
|
20451
|
+
case "_":
|
|
20452
|
+
return Object.fromEntries(Object.entries(lodash__default["default"]).filter(entry => !shouldOmitInLodash.has(entry[0])).concat(mock ? [["uniqueId", prefix => "".concat(prefix !== null && prefix !== void 0 ? prefix : "", "42")]] : []));
|
|
20453
|
+
case "moment":
|
|
20454
|
+
return Object.assign(function () {
|
|
20455
|
+
return moment__default["default"](...arguments);
|
|
20456
|
+
}, Object.fromEntries(Object.entries(moment__default["default"]).filter(entry => !shouldOmitInMoment.has(entry[0]))));
|
|
20457
|
+
case "PIPES":
|
|
20458
|
+
return pipes.pipes;
|
|
20459
|
+
case "TAG_URL":
|
|
20460
|
+
return tagUrlFactory(true);
|
|
20461
|
+
case "SAFE_TAG_URL":
|
|
20462
|
+
return tagUrlFactory();
|
|
20463
|
+
default:
|
|
20464
|
+
if (allowedGlobalObjects.has(variableName)) {
|
|
20465
|
+
return window[variableName];
|
|
20466
|
+
}
|
|
20467
|
+
}
|
|
20468
|
+
}
|
|
20469
|
+
function delegateMethods(target, methods) {
|
|
20470
|
+
return Object.fromEntries(methods.map(method => [method, function () {
|
|
20471
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
20472
|
+
args[_key] = arguments[_key];
|
|
20473
|
+
}
|
|
20474
|
+
return target[method].apply(target, args);
|
|
20475
|
+
}]));
|
|
20476
|
+
}
|
|
20477
|
+
/**
|
|
20478
|
+
* Pass `ignoreSlashes` as `true` to encode all tagged expressions
|
|
20479
|
+
* as URL components, except for `/` which maybe used in `APP.homepage`.
|
|
20480
|
+
*
|
|
20481
|
+
* Otherwise encode all tagged expressions as URL components.
|
|
20482
|
+
* This will encode `/` as `%2F`. So do not use it directly
|
|
20483
|
+
* with `APP.homepage` as in template expressions.
|
|
20484
|
+
*
|
|
20485
|
+
* @example
|
|
20486
|
+
*
|
|
20487
|
+
* ```js
|
|
20488
|
+
* TAG_URL`${APP.homepage}/list?q=${q}&redirect=${redirect}`
|
|
20489
|
+
* ```
|
|
20490
|
+
*
|
|
20491
|
+
* ```js
|
|
20492
|
+
* SAFE_TAG_URL`file/${path}?q=${q}`
|
|
20493
|
+
* // `path` will be fully transformed by `encodeURIComponent`.
|
|
20494
|
+
* ```
|
|
20495
|
+
*
|
|
20496
|
+
* ```js
|
|
20497
|
+
* // Wrap `APP.homepage` outside of `SAFE_TAG_URL`.
|
|
20498
|
+
* `${APP.homepage}/${SAFE_TAG_URL`file/${path}?q=${q}`}`
|
|
20499
|
+
* ```
|
|
20500
|
+
*/
|
|
20501
|
+
function tagUrlFactory(ignoreSlashes) {
|
|
20502
|
+
return function (strings) {
|
|
20503
|
+
for (var _len2 = arguments.length, partials = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
20504
|
+
partials[_key2 - 1] = arguments[_key2];
|
|
20505
|
+
}
|
|
20506
|
+
var result = [];
|
|
20507
|
+
strings.forEach((str, index) => {
|
|
20508
|
+
result.push(str);
|
|
20509
|
+
if (index < partials.length) {
|
|
20510
|
+
result.push(ignoreSlashes ? String(partials[index]).replace(/[^/]+/g, p => encodeURIComponent(p)) : encodeURIComponent(String(partials[index])));
|
|
20511
|
+
}
|
|
20512
|
+
});
|
|
20513
|
+
return result.join("");
|
|
20514
|
+
};
|
|
20515
|
+
}
|
|
20516
|
+
|
|
20517
|
+
function beforeVisitSnippetParamsFactory(collection) {
|
|
20518
|
+
return function beforeVisitParams(node, parent) {
|
|
20519
|
+
if (node.name === "SNIPPET_PARAMS") {
|
|
20520
|
+
var memberParent = parent[parent.length - 1];
|
|
20521
|
+
if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
|
|
20522
|
+
if (!memberParent.node.computed && memberParent.node.property.type === "Identifier") {
|
|
20523
|
+
collection.add(memberParent.node.property.name);
|
|
20524
|
+
} else if (memberParent.node.computed && memberParent.node.property.type === "Literal") {
|
|
20525
|
+
collection.add(memberParent.node.property.value);
|
|
20526
|
+
}
|
|
20527
|
+
}
|
|
20528
|
+
}
|
|
20529
|
+
};
|
|
20530
|
+
}
|
|
20531
|
+
function checkParamsValid(nameList, context) {
|
|
20532
|
+
var {
|
|
20533
|
+
declareParams = {},
|
|
20534
|
+
inputParams = {}
|
|
20535
|
+
} = context;
|
|
20536
|
+
return nameList.forEach(name => {
|
|
20537
|
+
var _declareParams$name;
|
|
20538
|
+
var type = (_declareParams$name = declareParams[name]) === null || _declareParams$name === void 0 ? void 0 : _declareParams$name.type;
|
|
20539
|
+
if (!type) {
|
|
20540
|
+
throw new Error("Missing type of ".concat(name, " in snippet params"));
|
|
20541
|
+
}
|
|
20542
|
+
var valid = ["string", "number", "boolean"].includes(type);
|
|
20543
|
+
if (!valid) {
|
|
20544
|
+
throw new Error("The ".concat(type, " type is not supported of ").concat(name, " in snippet params"));
|
|
20545
|
+
}
|
|
20546
|
+
var actualType = inputParams[name];
|
|
20547
|
+
if (actualType !== undefined && typeof actualType !== type) {
|
|
20548
|
+
throw new Error("The ".concat(name, " is declared as type ").concat(type, ", but it is receiving a value of type ").concat(typeof actualType));
|
|
20549
|
+
}
|
|
20550
|
+
});
|
|
20551
|
+
}
|
|
20552
|
+
function scanSnippetInStoryboard(data) {
|
|
20553
|
+
var collection = new Set();
|
|
20554
|
+
var beforeVisitGlobal = beforeVisitSnippetParamsFactory(collection);
|
|
20555
|
+
visitStoryboardExpressions(data, beforeVisitGlobal, {
|
|
20556
|
+
matchExpressionString: v => v.includes("SNIPPET_PARAMS"),
|
|
20557
|
+
customIsEvaluable: isSnippetEvaluation
|
|
20558
|
+
});
|
|
20559
|
+
return Array.from(collection);
|
|
20560
|
+
}
|
|
20561
|
+
function computeRealSnippetConf(value, context) {
|
|
20562
|
+
if (typeof value === "string" && isSnippetEvaluation(value)) {
|
|
20563
|
+
try {
|
|
20564
|
+
var raw = value;
|
|
20565
|
+
var ctxOrState = context.rootType === "template" ? "STATE" : "CTX";
|
|
20566
|
+
if (/^\s*<%@\s/.test(value)) {
|
|
20567
|
+
var replacements = [{
|
|
20568
|
+
search: "<%@",
|
|
20569
|
+
replace: "<%"
|
|
20570
|
+
}, {
|
|
20571
|
+
search: /\bCTX_OR_STATE\b/g,
|
|
20572
|
+
replace: ctxOrState
|
|
20573
|
+
}];
|
|
20574
|
+
var _result = value;
|
|
20575
|
+
replacements.forEach(replacement => {
|
|
20576
|
+
_result = _result.replace(replacement.search, replacement.replace);
|
|
20577
|
+
});
|
|
20578
|
+
return _result;
|
|
20579
|
+
}
|
|
20580
|
+
var globalVariables = {};
|
|
20581
|
+
var {
|
|
20582
|
+
expression,
|
|
20583
|
+
attemptToVisitGlobals,
|
|
20584
|
+
source
|
|
20585
|
+
} = preevaluate(raw);
|
|
20586
|
+
var attemptVisitSnippetParams = attemptToVisitGlobals.has("SNIPPET_PARAMS");
|
|
20587
|
+
if (attemptVisitSnippetParams) {
|
|
20588
|
+
globalVariables.SNIPPET_PARAMS = context.inputParams;
|
|
20589
|
+
}
|
|
20590
|
+
var result = cook(expression, source, {
|
|
20591
|
+
globalVariables: supply(attemptToVisitGlobals, globalVariables)
|
|
20592
|
+
});
|
|
20593
|
+
return result;
|
|
20594
|
+
} catch (error) {
|
|
20595
|
+
/* istanbul ignore next */
|
|
20596
|
+
// eslint-disable-next-line no-console
|
|
20597
|
+
console.error("Parse storyboard expression failed:", error);
|
|
20598
|
+
}
|
|
20599
|
+
}
|
|
20600
|
+
if (!isObject$1(value)) {
|
|
20601
|
+
return value;
|
|
20602
|
+
}
|
|
20603
|
+
if (Array.isArray(value)) {
|
|
20604
|
+
return value.map(v => computeRealSnippetConf(v, context));
|
|
20605
|
+
}
|
|
20606
|
+
return Object.fromEntries(Object.entries(value).map(_ref => {
|
|
20607
|
+
var [k, v] = _ref;
|
|
20608
|
+
return [computeRealSnippetConf(k, context), computeRealSnippetConf(v, context)];
|
|
20609
|
+
}));
|
|
20610
|
+
}
|
|
20611
|
+
function snippetEvaluate(brickConf, context) {
|
|
20612
|
+
var collection = scanSnippetInStoryboard(brickConf);
|
|
20613
|
+
checkParamsValid(collection, context);
|
|
20614
|
+
var result = computeRealSnippetConf(brickConf, context);
|
|
20615
|
+
return result;
|
|
20616
|
+
}
|
|
20617
|
+
|
|
20407
20618
|
Object.defineProperty(exports, 'pipes', {
|
|
20408
20619
|
enumerable: true,
|
|
20409
20620
|
get: function () { return pipes.pipes; }
|
|
@@ -20437,6 +20648,7 @@
|
|
|
20437
20648
|
exports.isEvaluable = isEvaluable;
|
|
20438
20649
|
exports.isObject = isObject$1;
|
|
20439
20650
|
exports.isRouteNode = isRouteNode;
|
|
20651
|
+
exports.isSnippetEvaluation = isSnippetEvaluation;
|
|
20440
20652
|
exports.isSnippetNode = isSnippetNode;
|
|
20441
20653
|
exports.isTrackAll = isTrackAll;
|
|
20442
20654
|
exports.lint = lint;
|
|
@@ -20479,6 +20691,7 @@
|
|
|
20479
20691
|
exports.scanTemplatesInStoryboard = scanTemplatesInStoryboard;
|
|
20480
20692
|
exports.shouldAllowRecursiveEvaluations = shouldAllowRecursiveEvaluations;
|
|
20481
20693
|
exports.smartDisplayForEvaluableString = smartDisplayForEvaluableString;
|
|
20694
|
+
exports.snippetEvaluate = snippetEvaluate;
|
|
20482
20695
|
exports.syncResolveContextConcurrently = syncResolveContextConcurrently;
|
|
20483
20696
|
exports.toPath = toPath;
|
|
20484
20697
|
exports.tokTypes = tokTypes_1;
|