@next-core/brick-utils 2.45.14 → 2.45.16

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.esm.js CHANGED
@@ -18152,10 +18152,14 @@ function getDllAndDepsOfStoryboard(storyboard, brickPackages, options) {
18152
18152
  usedTemplates
18153
18153
  } = scanStoryboard(storyboard, options);
18154
18154
  var customTemplates = (_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.customTemplates;
18155
+ var processors = scanProcessorsInAny([storyboard.routes, options !== null && options !== void 0 && options.ignoreBricksInUnusedCustomTemplates ? customTemplates === null || customTemplates === void 0 ? void 0 : customTemplates.filter(tpl => usedTemplates.includes(tpl.name)) : customTemplates]);
18155
18156
  return _objectSpread(_objectSpread({}, getDllAndDepsByResource({
18156
18157
  bricks,
18157
- processors: scanProcessorsInAny([storyboard.routes, options !== null && options !== void 0 && options.ignoreBricksInUnusedCustomTemplates ? customTemplates === null || customTemplates === void 0 ? void 0 : customTemplates.filter(tpl => usedTemplates.includes(tpl.name)) : customTemplates])
18158
+ processors
18158
18159
  }, brickPackages)), {}, {
18160
+ byProcessors: getDllAndDepsByResource({
18161
+ processors
18162
+ }, brickPackages),
18159
18163
  bricks
18160
18164
  });
18161
18165
  }
@@ -19452,7 +19456,178 @@ var {
19452
19456
  convertUnitValueByPrecision: convertValueByPrecision
19453
19457
  } = utils;
19454
19458
 
19455
- function resolveContextConcurrently(_x, _x2) {
19459
+ /**
19460
+ * Get tracking CTX for an evaluable expression in `track context` mode.
19461
+ *
19462
+ * A `track context` mode is an evaluable expression which is a sequence expression
19463
+ * starting with the exact literal string expression of "track context".
19464
+ *
19465
+ * @param raw - A raw string, which must be checked by `isEvaluable` first.
19466
+ *
19467
+ * @returns
19468
+ *
19469
+ * Returns used CTXs if `track context` mode is enabled, or returns false if not enabled or
19470
+ * no CTX found.
19471
+ *
19472
+ * @example
19473
+ *
19474
+ * ```js
19475
+ * trackContext('<% "track context", [CTX.hello, CTX.world] %>');
19476
+ * // => ["hello", "world"]
19477
+ *
19478
+ * trackContext('<% [CTX.hello, CTX.world] %>');
19479
+ * // => false
19480
+ *
19481
+ * trackContext('<% "track context", DATA.any %>');
19482
+ * // => false
19483
+ * ```
19484
+ */
19485
+ function trackContext(raw) {
19486
+ return track(raw, "track context", "CTX");
19487
+ }
19488
+ function trackState(raw) {
19489
+ return track(raw, "track state", "STATE");
19490
+ }
19491
+ function trackFormState(raw) {
19492
+ return track(raw, "track formstate", "FORM_STATE");
19493
+ }
19494
+ function trackUsedContext(data) {
19495
+ return collectContextUsage(data, "CTX").usedContexts;
19496
+ }
19497
+ function trackUsedState(data) {
19498
+ return collectContextUsage(data, "STATE").usedContexts;
19499
+ }
19500
+ function track(raw, trackText, variableName) {
19501
+ if (raw.includes(trackText)) {
19502
+ // const contexts = new Set<string>();
19503
+ var usage = {
19504
+ usedContexts: [],
19505
+ includesComputed: false
19506
+ };
19507
+ var {
19508
+ expression
19509
+ } = preevaluate(raw, {
19510
+ withParent: true,
19511
+ hooks: {
19512
+ beforeVisitGlobal: beforeVisitContextFactory(usage, variableName)
19513
+ }
19514
+ });
19515
+ // const contexts = usage
19516
+ var trackCtxExp;
19517
+ if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
19518
+ if (usage.usedContexts.length > 0) {
19519
+ return usage.usedContexts;
19520
+ } else {
19521
+ // eslint-disable-next-line no-console
19522
+ console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
19523
+ }
19524
+ }
19525
+ }
19526
+ return false;
19527
+ }
19528
+ function beforeVisitContextFactory(usage, variableName) {
19529
+ return function beforeVisitContext(node, parent) {
19530
+ if (node.name === variableName) {
19531
+ var memberParent = parent[parent.length - 1];
19532
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
19533
+ var memberNode = memberParent.node;
19534
+ var used;
19535
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
19536
+ used = memberNode.property.name;
19537
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
19538
+ used = memberNode.property.value;
19539
+ } else {
19540
+ usage.includesComputed = true;
19541
+ }
19542
+ if (used !== undefined && !usage.usedContexts.includes(used)) {
19543
+ usage.usedContexts.push(used);
19544
+ }
19545
+ }
19546
+ }
19547
+ };
19548
+ }
19549
+ function collectContextUsage(data, variableName) {
19550
+ var usage = {
19551
+ usedContexts: [],
19552
+ includesComputed: false
19553
+ };
19554
+ visitStoryboardExpressions(data, beforeVisitContextFactory(usage, variableName), variableName);
19555
+ return usage;
19556
+ }
19557
+
19558
+ function deferResolveContextConcurrently(contextConfs, resolveContext) {
19559
+ var keyword = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "CTX";
19560
+ var dependencyMap = getDependencyMapOfContext(contextConfs, keyword);
19561
+ var pendingDeps = new Set(Array.from(dependencyMap.keys()).map(contextConf => contextConf.name));
19562
+ var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
19563
+ var processed = new WeakSet();
19564
+ var deferredContexts = new Map();
19565
+ var pendingContexts = new Map([...new Set(contextConfs.map(contextConf => contextConf.name))].map(contextName => [contextName, new Promise((resolve, reject) => {
19566
+ deferredContexts.set(contextName, {
19567
+ resolve,
19568
+ reject
19569
+ });
19570
+ })]));
19571
+ var wrapResolve = /*#__PURE__*/function () {
19572
+ var _ref = _asyncToGenerator(function* (contextConf) {
19573
+ processed.add(contextConf);
19574
+ var resolved = yield resolveContext(contextConf);
19575
+ dependencyMap.delete(contextConf);
19576
+ if (resolved) {
19577
+ deferredContexts.get(contextConf.name).resolve();
19578
+ if (!pendingDeps.delete(contextConf.name)) {
19579
+ throw new Error("Duplicated context defined: ".concat(contextConf.name));
19580
+ }
19581
+ }
19582
+ yield scheduleNext();
19583
+ });
19584
+ return function wrapResolve(_x) {
19585
+ return _ref.apply(this, arguments);
19586
+ };
19587
+ }();
19588
+ var scheduleAsSerial = includesComputed;
19589
+ function scheduleNext() {
19590
+ return _scheduleNext.apply(this, arguments);
19591
+ }
19592
+ function _scheduleNext() {
19593
+ _scheduleNext = _asyncToGenerator(function* () {
19594
+ var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
19595
+ yield Promise.all(readyContexts.map(wrapResolve));
19596
+ });
19597
+ return _scheduleNext.apply(this, arguments);
19598
+ }
19599
+ var pendingResult = scheduleNext().then( /*#__PURE__*/_asyncToGenerator(function* () {
19600
+ // If there are still contexts left, it implies one of these situations:
19601
+ // - Circular contexts.
19602
+ // Such as: a depends on b, while b depends on a.
19603
+ // - Related contexts are all ignored.
19604
+ // Such as: a depends on b,
19605
+ // while both them are ignore by a falsy result of `if`.
19606
+ if (dependencyMap.size > 0) {
19607
+ // This will throw if circular contexts detected.
19608
+ detectCircularContexts(dependencyMap, keyword);
19609
+ scheduleAsSerial = true;
19610
+ yield scheduleNext();
19611
+ }
19612
+ // There maybe ignored contexts which are still not fulfilled.
19613
+ // We treat them as RESOLVED.
19614
+ for (var deferred of deferredContexts.values()) {
19615
+ deferred.resolve();
19616
+ }
19617
+ })).catch(error => {
19618
+ // There maybe contexts left not fulfilled, when an error occurred.
19619
+ // We treat them as REJECTED.
19620
+ for (var deferred of deferredContexts.values()) {
19621
+ deferred.reject(error);
19622
+ }
19623
+ throw error;
19624
+ });
19625
+ return {
19626
+ pendingResult,
19627
+ pendingContexts
19628
+ };
19629
+ }
19630
+ function resolveContextConcurrently(_x2, _x3) {
19456
19631
  return _resolveContextConcurrently.apply(this, arguments);
19457
19632
  }
19458
19633
  function _resolveContextConcurrently() {
@@ -19463,7 +19638,7 @@ function _resolveContextConcurrently() {
19463
19638
  var includesComputed = Array.from(dependencyMap.values()).some(stats => stats.includesComputed);
19464
19639
  var processed = new WeakSet();
19465
19640
  var wrapResolve = /*#__PURE__*/function () {
19466
- var _ref = _asyncToGenerator(function* (contextConf) {
19641
+ var _ref3 = _asyncToGenerator(function* (contextConf) {
19467
19642
  processed.add(contextConf);
19468
19643
  var resolved = yield resolveContext(contextConf);
19469
19644
  dependencyMap.delete(contextConf);
@@ -19474,20 +19649,20 @@ function _resolveContextConcurrently() {
19474
19649
  }
19475
19650
  yield scheduleNext();
19476
19651
  });
19477
- return function wrapResolve(_x3) {
19478
- return _ref.apply(this, arguments);
19652
+ return function wrapResolve(_x4) {
19653
+ return _ref3.apply(this, arguments);
19479
19654
  };
19480
19655
  }();
19481
19656
  var scheduleAsSerial = includesComputed;
19482
19657
  function scheduleNext() {
19483
- return _scheduleNext.apply(this, arguments);
19658
+ return _scheduleNext2.apply(this, arguments);
19484
19659
  }
19485
- function _scheduleNext() {
19486
- _scheduleNext = _asyncToGenerator(function* () {
19660
+ function _scheduleNext2() {
19661
+ _scheduleNext2 = _asyncToGenerator(function* () {
19487
19662
  var readyContexts = Array.from(dependencyMap.entries()).filter(predicateNextResolveFactory(pendingDeps, scheduleAsSerial)).map(entry => entry[0]).filter(contextConf => !processed.has(contextConf));
19488
19663
  yield Promise.all(readyContexts.map(wrapResolve));
19489
19664
  });
19490
- return _scheduleNext.apply(this, arguments);
19665
+ return _scheduleNext2.apply(this, arguments);
19491
19666
  }
19492
19667
  yield scheduleNext();
19493
19668
 
@@ -19547,51 +19722,24 @@ function predicateNextResolveFactory(pendingDeps, scheduleAsSerial) {
19547
19722
  // So make them process sequentially, keep the same behavior as before.
19548
19723
  scheduleAsSerial ? index === 0 :
19549
19724
  // A context is ready when it has no pending dependencies.
19550
- !entry[1].dependencies.some(dep => pendingDeps.has(dep));
19725
+ !entry[1].usedContexts.some(dep => pendingDeps.has(dep));
19551
19726
  }
19552
19727
  function getDependencyMapOfContext(contextConfs) {
19553
19728
  var keyword = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "CTX";
19554
19729
  var depsMap = new Map();
19555
19730
  for (var _contextConf2 of contextConfs) {
19556
- var stats = {
19557
- dependencies: [],
19558
- includesComputed: false
19559
- };
19560
- if (!_contextConf2.property) {
19561
- visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory$1(stats, keyword), keyword);
19562
- }
19731
+ var stats = collectContextUsage(_contextConf2.property ? null : [_contextConf2.if, _contextConf2.value, _contextConf2.resolve], keyword);
19563
19732
  depsMap.set(_contextConf2, stats);
19564
19733
  }
19565
19734
  return depsMap;
19566
19735
  }
19567
- function beforeVisitContextFactory$1(stats, keyword) {
19568
- return function beforeVisitContext(node, parent) {
19569
- if (node.name === keyword) {
19570
- var memberParent = parent[parent.length - 1];
19571
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
19572
- var memberNode = memberParent.node;
19573
- var dep;
19574
- if (!memberNode.computed && memberNode.property.type === "Identifier") {
19575
- dep = memberNode.property.name;
19576
- } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
19577
- dep = memberNode.property.value;
19578
- } else {
19579
- stats.includesComputed = true;
19580
- }
19581
- if (dep !== undefined && !stats.dependencies.includes(dep)) {
19582
- stats.dependencies.push(dep);
19583
- }
19584
- }
19585
- }
19586
- };
19587
- }
19588
19736
  function detectCircularContexts(dependencyMap, keyword) {
19589
19737
  var duplicatedMap = new Map(dependencyMap);
19590
19738
  var pendingDeps = new Set(Array.from(duplicatedMap.keys()).map(contextConf => contextConf.name));
19591
19739
  var next = () => {
19592
19740
  var processedAtLeastOne = false;
19593
19741
  for (var [_contextConf3, stats] of duplicatedMap.entries()) {
19594
- if (!stats.dependencies.some(dep => pendingDeps.has(dep))) {
19742
+ if (!stats.usedContexts.some(dep => pendingDeps.has(dep))) {
19595
19743
  duplicatedMap.delete(_contextConf3);
19596
19744
  pendingDeps.delete(_contextConf3.name);
19597
19745
  processedAtLeastOne = true;
@@ -19834,91 +19982,6 @@ function deepFreeze(object) {
19834
19982
  return Object.freeze(object);
19835
19983
  }
19836
19984
 
19837
- /**
19838
- * Get tracking CTX for an evaluable expression in `track context` mode.
19839
- *
19840
- * A `track context` mode is an evaluable expression which is a sequence expression
19841
- * starting with the exact literal string expression of "track context".
19842
- *
19843
- * @param raw - A raw string, which must be checked by `isEvaluable` first.
19844
- *
19845
- * @returns
19846
- *
19847
- * Returns used CTXs if `track context` mode is enabled, or returns false if not enabled or
19848
- * no CTX found.
19849
- *
19850
- * @example
19851
- *
19852
- * ```js
19853
- * trackContext('<% "track context", [CTX.hello, CTX.world] %>');
19854
- * // => ["hello", "world"]
19855
- *
19856
- * trackContext('<% [CTX.hello, CTX.world] %>');
19857
- * // => false
19858
- *
19859
- * trackContext('<% "track context", DATA.any %>');
19860
- * // => false
19861
- * ```
19862
- */
19863
- function trackContext(raw) {
19864
- return track(raw, "track context", "CTX");
19865
- }
19866
- function trackState(raw) {
19867
- return track(raw, "track state", "STATE");
19868
- }
19869
- function trackFormState(raw) {
19870
- return track(raw, "track formstate", "FORM_STATE");
19871
- }
19872
- function trackUsedContext(data) {
19873
- return trackUsed(data, "CTX");
19874
- }
19875
- function trackUsedState(data) {
19876
- return trackUsed(data, "STATE");
19877
- }
19878
- function track(raw, trackText, variableName) {
19879
- if (raw.includes(trackText)) {
19880
- var contexts = new Set();
19881
- var {
19882
- expression
19883
- } = preevaluate(raw, {
19884
- withParent: true,
19885
- hooks: {
19886
- beforeVisitGlobal: beforeVisitContextFactory(contexts, variableName)
19887
- }
19888
- });
19889
- var trackCtxExp;
19890
- if (expression.type === "SequenceExpression" && (trackCtxExp = expression.expressions[0]) && trackCtxExp.type === "Literal" && trackCtxExp.value === trackText) {
19891
- if (contexts.size > 0) {
19892
- return Array.from(contexts);
19893
- } else {
19894
- // eslint-disable-next-line no-console
19895
- console.warn("You are using \"".concat(trackText, "\" but no `").concat(variableName, "` usage found in your expression: ").concat(JSON.stringify(raw)));
19896
- }
19897
- }
19898
- }
19899
- return false;
19900
- }
19901
- function trackUsed(data, variableName) {
19902
- var contexts = new Set();
19903
- visitStoryboardExpressions(data, beforeVisitContextFactory(contexts, variableName), variableName);
19904
- return Array.from(contexts);
19905
- }
19906
- function beforeVisitContextFactory(contexts, variableName) {
19907
- return function beforeVisitContext(node, parent) {
19908
- if (node.name === variableName) {
19909
- var memberParent = parent[parent.length - 1];
19910
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
19911
- var memberNode = memberParent.node;
19912
- if (!memberNode.computed && memberNode.property.type === "Identifier") {
19913
- contexts.add(memberNode.property.name);
19914
- } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
19915
- contexts.add(memberNode.property.value);
19916
- }
19917
- }
19918
- }
19919
- };
19920
- }
19921
-
19922
19985
  // The debounce function receives our function as a parameter
19923
19986
  function debounceByAnimationFrame(fn) {
19924
19987
  // This holds the requestAnimationFrame reference, so we can cancel it if we wish
@@ -20223,5 +20286,5 @@ function isConstantLogical(node, expect, options) {
20223
20286
  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);
20224
20287
  }
20225
20288
 
20226
- export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject$1 as isObject, isRouteNode, isSnippetNode, 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, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackFormState, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
20289
+ 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, isSnippetNode, 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, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackFormState, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
20227
20290
  //# sourceMappingURL=index.esm.js.map