@next-core/brick-kit 2.70.1 → 2.71.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,13 +4,15 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import _defineProperty$2 from '@babel/runtime/helpers/defineProperty';
5
5
  import _asyncToGenerator$4 from '@babel/runtime/helpers/asyncToGenerator';
6
6
  import { Modal, message, Empty, ConfigProvider } from 'antd';
7
- import { isObject, isEvaluable, transformAndInject, transform, trackContext, hasOwnProperty, preevaluate, toPath, computeRealRoutePath, scanPermissionActionsInStoryboard, precookFunction, cook, supply, shouldAllowRecursiveEvaluations, inject, deepFreeze, createProviderClass, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, resolveContextConcurrently, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
7
+ import { isObject, isEvaluable, transformAndInject, transform, trackContext, hasOwnProperty, preevaluate, toPath, computeRealRoutePath, scanPermissionActionsInStoryboard, precookFunction, cook, shouldAllowRecursiveEvaluations, inject, deepFreeze, createProviderClass, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, resolveContextConcurrently, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
8
8
  import * as React from 'react';
9
9
  import React__default, { useState, useEffect, forwardRef, useRef, useImperativeHandle, useMemo, useContext, createContext } from 'react';
10
10
  import { HttpResponseError, HttpFetchError, http } from '@next-core/brick-http';
11
11
  import { ExclamationCircleOutlined } from '@ant-design/icons';
12
12
  import i18next from 'i18next';
13
- import { set, get, sortBy, isEmpty, difference, cloneDeep, merge, clamp, uniqueId, orderBy, omit } from 'lodash';
13
+ import lodash, { set, get, sortBy, isEmpty, difference, cloneDeep, merge, clamp, uniqueId, orderBy, omit } from 'lodash';
14
+ import moment from 'moment';
15
+ import { pipes } from '@next-core/pipes';
14
16
  import yaml from 'js-yaml';
15
17
  import { apiAnalyzer } from '@next-core/easyops-analytics';
16
18
  import require$$0 from 'path';
@@ -402,6 +404,120 @@ function LoginTimeoutMessage() {
402
404
  return /*#__PURE__*/React__default.createElement("div", null, i18next.t("".concat(NS_BRICK_KIT, ":").concat(K.LOGIN_TIMEOUT_MESSAGE)));
403
405
  }
404
406
 
407
+ function supply(attemptToVisitGlobals, providedGlobalVariables) {
408
+ var globalVariables = _objectSpread({}, providedGlobalVariables); // Allow limited browser builtin values.
409
+
410
+
411
+ globalVariables["undefined"] = undefined;
412
+
413
+ for (var variableName of attemptToVisitGlobals) {
414
+ if (!Object.prototype.hasOwnProperty.call(globalVariables, variableName)) {
415
+ var variable = supplyIndividual(variableName);
416
+
417
+ if (variable !== undefined) {
418
+ globalVariables[variableName] = variable;
419
+ }
420
+ }
421
+ }
422
+
423
+ return globalVariables;
424
+ }
425
+ var shouldOmitInLodash = new Set([// Omit all mutable methods from lodash.
426
+ // But allow sequence methods like `_.chain`.
427
+ "fill", "pull", "pullAll", "pullAllBy", "pullAllWith", "pullAt", "remove", "reverse", "assign", "assignIn", "assignInWith", "assignWith", "defaults", "defaultsDeep", "merge", "mergeWith", "set", "setWith", "unset", "update", "updateWith",
428
+ /**
429
+ * Ignore `Function` methods from lodash, too.
430
+ * There are chances to invoke `Object.assign`, etc.
431
+ *
432
+ * E.g.:
433
+ *
434
+ * ```
435
+ * _.wrap(_.method('constructor.assign',{b:2},{b:3}),(func,...a) => func(...a))({})
436
+ * ```
437
+ */
438
+ "after", "ary", "before", "bind", "bindKey", "curry", "curryRight", "debounce", "defer", "delay", "flip", "memoize", "negate", "once", "overArgs", "partial", "partialRight", "rearg", "rest", "spread", "throttle", "unary", "wrap"]); // Omit all mutable methods from moment.
439
+
440
+ var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
441
+ var allowedGlobalObjects = new Set(["Array", "Boolean", "Date", "Infinity", "JSON", "Math", "NaN", "Number", "String", "decodeURI", "decodeURIComponent", "encodeURI", "encodeURIComponent", "isFinite", "isNaN", "parseFloat", "parseInt", "Map", "Set", "URLSearchParams", "WeakMap", "WeakSet", "atob", "btoa"]);
442
+
443
+ function supplyIndividual(variableName) {
444
+ switch (variableName) {
445
+ case "Object":
446
+ // Do not allow mutable methods like `Object.assign`.
447
+ return delegateMethods(Object, ["entries", "fromEntries", "keys", "values"]);
448
+
449
+ case "_":
450
+ return Object.fromEntries(Object.entries(lodash).filter(entry => !shouldOmitInLodash.has(entry[0])));
451
+
452
+ case "moment":
453
+ return Object.assign((...args) => moment(...args), Object.fromEntries(Object.entries(moment).filter(entry => !shouldOmitInMoment.has(entry[0]))));
454
+
455
+ case "PIPES":
456
+ return pipes;
457
+
458
+ case "location":
459
+ return {
460
+ href: location.href,
461
+ origin: location.origin
462
+ };
463
+
464
+ case "TAG_URL":
465
+ return tagUrlFactory(true);
466
+
467
+ case "SAFE_TAG_URL":
468
+ return tagUrlFactory();
469
+
470
+ default:
471
+ if (allowedGlobalObjects.has(variableName)) {
472
+ return window[variableName];
473
+ }
474
+
475
+ }
476
+ }
477
+
478
+ function delegateMethods(target, methods) {
479
+ return Object.fromEntries(methods.map(method => [method, (...args) => target[method].apply(target, args)]));
480
+ }
481
+ /**
482
+ * Pass `ignoreSlashes` as `true` to encode all tagged expressions
483
+ * as URL components, except for `/` which maybe used in `APP.homepage`.
484
+ *
485
+ * Otherwise encode all tagged expressions as URL components.
486
+ * This will encode `/` as `%2F`. So do not use it directly
487
+ * with `APP.homepage` as in template expressions.
488
+ *
489
+ * @example
490
+ *
491
+ * ```js
492
+ * TAG_URL`${APP.homepage}/list?q=${q}&redirect=${redirect}`
493
+ * ```
494
+ *
495
+ * ```js
496
+ * SAFE_TAG_URL`file/${path}?q=${q}`
497
+ * // `path` will be fully transformed by `encodeURIComponent`.
498
+ * ```
499
+ *
500
+ * ```js
501
+ * // Wrap `APP.homepage` outside of `SAFE_TAG_URL`.
502
+ * `${APP.homepage}/${SAFE_TAG_URL`file/${path}?q=${q}`}`
503
+ * ```
504
+ */
505
+
506
+
507
+ function tagUrlFactory(ignoreSlashes) {
508
+ return function (strings, ...partials) {
509
+ var result = [];
510
+ strings.forEach((str, index) => {
511
+ result.push(str);
512
+
513
+ if (index < partials.length) {
514
+ result.push(ignoreSlashes ? String(partials[index]).replace(/[^/]+/g, p => encodeURIComponent(p)) : encodeURIComponent(String(partials[index])));
515
+ }
516
+ });
517
+ return result.join("");
518
+ };
519
+ }
520
+
405
521
  var brickTemplateRegistry = new Map();
406
522
  function registerBrickTemplate(name, factory) {
407
523
  if (brickTemplateRegistry.has(name)) {
@@ -643,9 +759,13 @@ function recursiveMarkAsInjected(value) {
643
759
 
644
760
  if (Array.isArray(value)) {
645
761
  value.forEach(recursiveMarkAsInjected);
646
- } else if (value.constructor === Object) {
762
+ } else {
647
763
  // Only mark pure objects.
648
- Object.values(value).forEach(recursiveMarkAsInjected);
764
+ var proto = Object.getPrototypeOf(value);
765
+
766
+ if (!proto || proto.constructor === Object) {
767
+ Object.values(value).forEach(recursiveMarkAsInjected);
768
+ }
649
769
  }
650
770
  }
651
771
  }
@@ -7754,7 +7874,10 @@ class LocationContext {
7754
7874
  }
7755
7875
 
7756
7876
  handlePageLoad() {
7757
- this.dispatchLifeCycleEvent(new CustomEvent("page.load"), this.pageLoadHandlers);
7877
+ var event = new CustomEvent("page.load");
7878
+ this.dispatchLifeCycleEvent(event, this.pageLoadHandlers); // Currently only for e2e testing
7879
+
7880
+ window.dispatchEvent(event);
7758
7881
  }
7759
7882
 
7760
7883
  handleBeforePageLeave(detail) {