@next-core/brick-kit 2.201.0 → 2.203.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.esm.js CHANGED
@@ -4,7 +4,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
5
5
  import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
6
6
  import _, { escapeRegExp, set, get, difference, identity, uniqueId, isNil, isEmpty, merge, sortBy, cloneDeep, clamp, orderBy, pick, isObject as isObject$1, uniq, omit, findLastIndex, noop, isString as isString$1 } from 'lodash';
7
- import { toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, isTrackAll, trackAll, trackContext, trackState, trackFormState, transformAndInject, transform, JsonStorage, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedFormState, trackUsedState, trackUsedContext, scanPermissionActionsInAny, deepFreeze, scanProcessorsInAny, preevaluate, shouldAllowRecursiveEvaluations, inject, matchPath, asyncProcessBrick, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, snippetEvaluate, scanCustomApisInStoryboard, prefetchScript, scanBricksInBrickConf, loadScript, scanAppGetMenuInAny, scanInstalledAppsInStoryboard, clearExpressionASTCache, clearFunctionASTCache, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
7
+ import { toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable as isEvaluable$1, isTrackAll, trackAll, trackContext, trackState, trackFormState, transformAndInject, transform, JsonStorage, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedFormState, trackUsedState, trackUsedContext, scanPermissionActionsInAny, deepFreeze, scanProcessorsInAny, preevaluate, shouldAllowRecursiveEvaluations, inject, matchPath, asyncProcessBrick, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, snippetEvaluate, scanCustomApisInStoryboard, prefetchScript, scanBricksInBrickConf, loadScript, scanAppGetMenuInAny, scanInstalledAppsInStoryboard, clearExpressionASTCache, clearFunctionASTCache, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
8
  import moment from 'moment';
9
9
  import { pipes } from '@next-core/pipes';
10
10
  import i18next, { getFixedT } from 'i18next';
@@ -612,7 +612,7 @@ function getTracks(value) {
612
612
  var contextNames = false;
613
613
  var stateNames = false;
614
614
  var formStateNames = false;
615
- if (typeof value === "string" ? isEvaluable(value) : isPreEvaluated(value)) {
615
+ if (typeof value === "string" ? isEvaluable$1(value) : isPreEvaluated(value)) {
616
616
  var raw = typeof value === "string" ? value : getPreEvaluatedRaw(value);
617
617
  if (isTrackAll(raw)) {
618
618
  var result = trackAll(raw);
@@ -663,7 +663,7 @@ function doTransform(data, to, options) {
663
663
  }
664
664
  var result;
665
665
  var dismissRecursiveMarkingInjected = false;
666
- if (preEvaluated || isEvaluable(to)) {
666
+ if (preEvaluated || isEvaluable$1(to)) {
667
667
  var runtimeContext = {
668
668
  data
669
669
  };
@@ -690,7 +690,7 @@ function doTransform(data, to, options) {
690
690
  // Get both string and symbol keys.
691
691
  Object.entries(to).map(_ref => {
692
692
  var [k, v] = _ref;
693
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.trackingContextList) && (typeof v === "string" ? isEvaluable(v) : isPreEvaluated(v))) {
693
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.trackingContextList) && (typeof v === "string" ? isEvaluable$1(v) : isPreEvaluated(v))) {
694
694
  var raw;
695
695
  if (typeof v === "string") {
696
696
  raw = v;
@@ -1448,11 +1448,22 @@ function StoryboardFunctionRegistryFactory() {
1448
1448
  for (var fn of functions) {
1449
1449
  registeredFunctions.set(fn.name, {
1450
1450
  source: fn.source,
1451
- typescript: fn.typescript
1451
+ typescript: fn.typescript,
1452
+ transformed: fn.transformed
1452
1453
  });
1453
1454
  }
1454
1455
  }
1455
1456
  }
1457
+ function getGlobalVariables(globals) {
1458
+ return supply(globals, getGeneralGlobals(globals, {
1459
+ collectCoverage,
1460
+ widgetId,
1461
+ widgetVersion,
1462
+ app: currentApp,
1463
+ storyboardFunctions,
1464
+ isStoryboardFunction: true
1465
+ }), !!collectCoverage);
1466
+ }
1456
1467
  function getStoryboardFunction(name) {
1457
1468
  var fn = registeredFunctions.get(name);
1458
1469
  if (!fn) {
@@ -1465,35 +1476,39 @@ function StoryboardFunctionRegistryFactory() {
1465
1476
  if (collectCoverage) {
1466
1477
  collector = collectCoverage.createCollector(name);
1467
1478
  }
1468
- var precooked = precookFunction(fn.source, {
1469
- cacheKey: fn,
1470
- typescript: fn.typescript,
1471
- hooks: collector && {
1472
- beforeVisit: collector.beforeVisit
1473
- }
1474
- });
1475
- fn.cooked = cook(precooked.function, fn.source, {
1476
- rules: {
1477
- noVar: true
1478
- },
1479
- globalVariables: supply(precooked.attemptToVisitGlobals, getGeneralGlobals(precooked.attemptToVisitGlobals, {
1480
- collectCoverage,
1481
- widgetId,
1482
- widgetVersion,
1483
- app: currentApp,
1484
- storyboardFunctions,
1485
- isStoryboardFunction: true
1486
- }), !!collectCoverage),
1487
- hooks: _objectSpread({
1488
- perfCall: needPerf ? duration => {
1489
- perf(name, fn.source, duration);
1490
- } : undefined
1491
- }, collector ? {
1492
- beforeEvaluate: collector.beforeEvaluate,
1493
- beforeCall: collector.beforeCall,
1494
- beforeBranch: collector.beforeBranch
1495
- } : null)
1496
- });
1479
+
1480
+ // Do not use transformed functions when collecting coverage.
1481
+ var transformed = !collector && fn.transformed;
1482
+ if (transformed) {
1483
+ var globalVariables = getGlobalVariables(transformed.globals);
1484
+ // Spread globals as params to prevent accessing forbidden globals.
1485
+ // NOTE: in native mode, forbidden globals are declared as `undefined`,
1486
+ // thus accessing them will not throw a ReferenceError.
1487
+ fn.cooked = new Function(...transformed.globals, "\"use strict\";return (".concat(transformed.source, ")"))(...transformed.globals.map(key => hasOwnProperty(globalVariables, key) ? globalVariables[key] : undefined));
1488
+ } else {
1489
+ var precooked = precookFunction(fn.source, {
1490
+ cacheKey: fn,
1491
+ typescript: fn.typescript,
1492
+ hooks: collector && {
1493
+ beforeVisit: collector.beforeVisit
1494
+ }
1495
+ });
1496
+ fn.cooked = cook(precooked.function, fn.source, {
1497
+ rules: {
1498
+ noVar: true
1499
+ },
1500
+ globalVariables: getGlobalVariables(precooked.attemptToVisitGlobals),
1501
+ hooks: _objectSpread({
1502
+ perfCall: needPerf ? duration => {
1503
+ perf(name, fn.source, duration);
1504
+ } : undefined
1505
+ }, collector ? {
1506
+ beforeEvaluate: collector.beforeEvaluate,
1507
+ beforeCall: collector.beforeCall,
1508
+ beforeBranch: collector.beforeBranch
1509
+ } : null)
1510
+ });
1511
+ }
1497
1512
  fn.processed = true;
1498
1513
  return fn.cooked;
1499
1514
  }
@@ -1503,7 +1518,8 @@ function StoryboardFunctionRegistryFactory() {
1503
1518
  updateStoryboardFunction(name, data) {
1504
1519
  registeredFunctions.set(name, {
1505
1520
  source: data.source,
1506
- typescript: data.typescript
1521
+ typescript: data.typescript,
1522
+ transformed: data.transformed
1507
1523
  });
1508
1524
  }
1509
1525
  };
@@ -2725,7 +2741,7 @@ function sortMenuItems(list) {
2725
2741
  function attemptToVisit(data, globals) {
2726
2742
  var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
2727
2743
  if (typeof data === "string") {
2728
- if (isEvaluable(data)) {
2744
+ if (isEvaluable$1(data)) {
2729
2745
  if (globals.some(key => data.includes(key))) {
2730
2746
  var {
2731
2747
  attemptToVisitGlobals
@@ -2762,7 +2778,7 @@ function _computeRealValueWithOverrideApp() {
2762
2778
  if ("if" in data && data.if === null) {
2763
2779
  delete data.if;
2764
2780
  }
2765
- if ("to" in data && data.to && !isEvaluable(data.to)) {
2781
+ if ("to" in data && data.to && !isEvaluable$1(data.to)) {
2766
2782
  var yaml = pipes.yaml(data.to);
2767
2783
  if (isObject(yaml) && ["pathname", "search", "hash"].some(key => hasOwnProperty(yaml, key))) {
2768
2784
  data.to = yaml;
@@ -2879,7 +2895,7 @@ function evaluate(raw) {
2879
2895
  var _runtimeContext$overr;
2880
2896
  var runtimeContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2881
2897
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2882
- if (options.isReEvaluation && !(typeof raw === "string" && isEvaluable(raw))) {
2898
+ if (options.isReEvaluation && !(typeof raw === "string" && isEvaluable$1(raw))) {
2883
2899
  devtoolsHookEmit("re-evaluation", {
2884
2900
  id: options.evaluationId,
2885
2901
  detail: {
@@ -3240,7 +3256,7 @@ function propertyMergeAllOfObject(_ref2, object) {
3240
3256
  }, computedBaseValue);
3241
3257
  }
3242
3258
 
3243
- function setupTemplateProxy(proxyContext, ref, slots) {
3259
+ function setupTemplateProxy(proxyContext, ref, slots, slotted) {
3244
3260
  var computedPropsFromProxy = {};
3245
3261
  var refForProxy;
3246
3262
  var {
@@ -3286,6 +3302,9 @@ function setupTemplateProxy(proxyContext, ref, slots) {
3286
3302
  // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.
3287
3303
  var quasisMap = new Map();
3288
3304
  if (reversedProxies.slots.has(ref)) {
3305
+ if (slotted) {
3306
+ throw new Error("Can not have proxied slot ref when the ref target has a slot element child, check your template \"".concat(proxyBrick.type, "\" and ref \"").concat(ref, "\""));
3307
+ }
3289
3308
  for (var item of reversedProxies.slots.get(ref)) {
3290
3309
  var _item$refPosition, _externalSlots$item$$, _externalSlots$item$$2;
3291
3310
  if (!quasisMap.has(item.refSlot)) {
@@ -3373,7 +3392,7 @@ var computeRealValue = (value, context, injectDeep, internalOptions) => {
3373
3392
  var lazy = (internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.$$lazyForUseBrick) && isLazyContentInUseBrick(internalOptions.$$stateOfUseBrick);
3374
3393
  var result;
3375
3394
  var dismissRecursiveMarkingInjected = lazy;
3376
- if (preEvaluated || isEvaluable(value)) {
3395
+ if (preEvaluated || isEvaluable$1(value)) {
3377
3396
  var runtimeContext = {};
3378
3397
  if (context) {
3379
3398
  var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId", "query", "match", "app", "segues"];
@@ -6733,7 +6752,7 @@ function customListenerFactory(handler, ifContainer, context, runtimeBrick) {
6733
6752
  var rawTargetRef = handler.targetRef;
6734
6753
  var computedTarget = rawTarget;
6735
6754
  // Allow `target` to be set as evaluable string.
6736
- if (typeof rawTarget === "string" ? isEvaluable(rawTarget) : isPreEvaluated(rawTarget)) {
6755
+ if (typeof rawTarget === "string" ? isEvaluable$1(rawTarget) : isPreEvaluated(rawTarget)) {
6737
6756
  computedTarget = computeRealValue(rawTarget, _objectSpread(_objectSpread({}, context), {}, {
6738
6757
  event
6739
6758
  }));
@@ -6759,7 +6778,7 @@ function customListenerFactory(handler, ifContainer, context, runtimeBrick) {
6759
6778
  } else if (rawTargetRef) {
6760
6779
  var computedTargetRef = rawTargetRef;
6761
6780
  // Allow `targetRef` to be set as evaluable string.
6762
- if (typeof rawTargetRef === "string" ? isEvaluable(rawTargetRef) : isPreEvaluated(rawTargetRef)) {
6781
+ if (typeof rawTargetRef === "string" ? isEvaluable$1(rawTargetRef) : isPreEvaluated(rawTargetRef)) {
6763
6782
  computedTargetRef = computeRealValue(rawTargetRef, _objectSpread(_objectSpread({}, context), {}, {
6764
6783
  event
6765
6784
  }), true);
@@ -8437,6 +8456,38 @@ function collectMergeBases(conf, mergeBases, contextInTemplate, refToBrickConf)
8437
8456
  }
8438
8457
  }
8439
8458
 
8459
+ function isEvaluable(raw) {
8460
+ return /^\s*<%[~=]?\s/.test(raw) && /\s%>\s*$/.test(raw);
8461
+ }
8462
+
8463
+ function replaceSlotWithSlottedBricks(brickConf, proxyContext, expand) {
8464
+ var _brickConf$properties, _brickConf$properties2, _slots$$bricks, _slots, _slots$;
8465
+ // Currently, no support for `if` in a slot.
8466
+ if (brickConf.if != null && !brickConf.if || typeof brickConf.if === "string") {
8467
+ throw new Error("Can not use \"if\" in a slot currently, check your template \"".concat(proxyContext.proxyBrick.type, "\""));
8468
+ }
8469
+ var slot = String((_brickConf$properties = (_brickConf$properties2 = brickConf.properties) === null || _brickConf$properties2 === void 0 ? void 0 : _brickConf$properties2.name) !== null && _brickConf$properties !== void 0 ? _brickConf$properties : "");
8470
+
8471
+ // Currently, no support for expression as slot name.
8472
+ if (isEvaluable(slot)) {
8473
+ throw new Error("Can not use an expression as slot name \"".concat(slot, "\" currently, check your template \"").concat(proxyContext.proxyBrick.type, "\""));
8474
+ }
8475
+
8476
+ // Do not repeat the same slot name in a template.
8477
+ if (proxyContext.usedSlots.has(slot)) {
8478
+ throw new Error("Can not have multiple slots with the same name \"".concat(slot, "\", check your template \"").concat(proxyContext.proxyBrick.type, "\""));
8479
+ }
8480
+ proxyContext.usedSlots.add(slot);
8481
+ if (proxyContext.externalSlots && hasOwnProperty(proxyContext.externalSlots, slot)) {
8482
+ var _proxyContext$externa;
8483
+ var insertBricks = (_proxyContext$externa = proxyContext.externalSlots[slot].bricks) !== null && _proxyContext$externa !== void 0 ? _proxyContext$externa : [];
8484
+ if (insertBricks.length > 0) {
8485
+ return insertBricks;
8486
+ }
8487
+ }
8488
+ return ((_slots$$bricks = (_slots = brickConf.slots) === null || _slots === void 0 ? void 0 : (_slots$ = _slots[""]) === null || _slots$ === void 0 ? void 0 : _slots$.bricks) !== null && _slots$$bricks !== void 0 ? _slots$$bricks : []).flatMap(item => expand(item, proxyContext));
8489
+ }
8490
+
8440
8491
  var _excluded$4 = ["properties", "slots"],
8441
8492
  _excluded2 = ["ref", "slots"];
8442
8493
  function expandCustomTemplate(brickConf, proxyBrick, context) {
@@ -8565,38 +8616,48 @@ function lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context,
8565
8616
  templateProperties,
8566
8617
  externalSlots: externalSlots,
8567
8618
  templateContextId: tplContext.id,
8568
- proxyBrick
8619
+ proxyBrick,
8620
+ usedSlots: new Set()
8569
8621
  };
8570
8622
  newBrickConf.slots = {
8571
8623
  "": {
8572
8624
  type: "bricks",
8573
- bricks: bricks.map(item => expandBrickInTemplate(item, proxyContext))
8625
+ bricks: bricks.flatMap(item => expandBrickInTemplate(item, proxyContext))
8574
8626
  }
8575
8627
  };
8576
8628
  return newBrickConf;
8577
8629
  }
8578
- function expandBrickInTemplate(brickConfInTemplate, proxyContext) {
8630
+ function expandBrickInTemplate(brickConfInTemplate, proxyContext, markSlotted) {
8579
8631
  // Ignore `if: null` to make `looseCheckIf` working.
8580
8632
  if (brickConfInTemplate.if === null) {
8581
8633
  delete brickConfInTemplate.if;
8582
8634
  }
8583
- var {
8635
+ if (brickConfInTemplate.brick === "slot") {
8636
+ markSlotted === null || markSlotted === void 0 ? void 0 : markSlotted();
8637
+ return replaceSlotWithSlottedBricks(brickConfInTemplate, proxyContext, expandBrickInTemplate);
8638
+ }
8639
+ var _ref = brickConfInTemplate,
8640
+ {
8584
8641
  ref,
8585
8642
  slots: slotsInTemplate
8586
- } = brickConfInTemplate,
8587
- restBrickConfInTemplate = _objectWithoutProperties(brickConfInTemplate, _excluded2);
8588
- var slots = Object.fromEntries(Object.entries(slotsInTemplate !== null && slotsInTemplate !== void 0 ? slotsInTemplate : {}).map(_ref => {
8643
+ } = _ref,
8644
+ restBrickConfInTemplate = _objectWithoutProperties(_ref, _excluded2);
8645
+ var slotted = false;
8646
+ var markChild = () => {
8647
+ slotted = true;
8648
+ };
8649
+ var slots = Object.fromEntries(Object.entries(slotsInTemplate !== null && slotsInTemplate !== void 0 ? slotsInTemplate : {}).map(_ref2 => {
8589
8650
  var _slotConf$bricks;
8590
- var [slotName, slotConf] = _ref;
8651
+ var [slotName, slotConf] = _ref2;
8591
8652
  return [slotName, {
8592
8653
  type: "bricks",
8593
- bricks: ((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : []).map(item => expandBrickInTemplate(item, proxyContext))
8654
+ bricks: ((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : []).flatMap(item => expandBrickInTemplate(item, proxyContext, markChild))
8594
8655
  }];
8595
8656
  }));
8596
8657
  return _objectSpread(_objectSpread({}, restBrickConfInTemplate), {}, {
8597
8658
  properties: setupUseBrickInTemplate(brickConfInTemplate.properties, proxyContext),
8598
8659
  slots
8599
- }, setupTemplateProxy(proxyContext, ref, slots));
8660
+ }, setupTemplateProxy(proxyContext, ref, slots, slotted));
8600
8661
  }
8601
8662
 
8602
8663
  // If it's a custom template, return the tag name of the template.
@@ -15209,7 +15270,7 @@ function getRealValue(value) {
15209
15270
  }
15210
15271
  var compute = data => {
15211
15272
  if (typeof data === "string") {
15212
- if (isEvaluable(data)) {
15273
+ if (isEvaluable$1(data)) {
15213
15274
  var result = evaluate(data, ctx);
15214
15275
  recursiveMarkAsInjected(result);
15215
15276
  return result;