@next-core/brick-kit 2.191.1 → 2.193.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
@@ -3,16 +3,16 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
4
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
5
5
  import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
6
- import _, { escapeRegExp, set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, isEmpty, merge, sortBy, orderBy, pick, isObject as isObject$1, uniq, omit, findLastIndex, noop, isString as isString$1 } from 'lodash';
7
- import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, isTrackAll, trackAll, trackContext, trackState, trackFormState, transformAndInject, transform, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedFormState, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, scanPermissionActionsInAny, deepFreeze, scanProcessorsInAny, matchPath, asyncProcessBrick, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, snippetEvaluate, scanCustomApisInStoryboard, prefetchScript, scanBricksInBrickConf, loadScript, scanAppGetMenuInAny, scanInstalledAppsInStoryboard, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
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, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
+ import moment from 'moment';
9
+ import { pipes } from '@next-core/pipes';
10
+ import i18next, { getFixedT } from 'i18next';
8
11
  import React, { useState, useEffect, useMemo, useContext, createContext, useRef, useReducer, useCallback } from 'react';
9
12
  import { http, HttpResponseError, HttpAbortError, HttpFetchError } from '@next-core/brick-http';
13
+ import { userAnalytics, apiAnalyzer } from '@next-core/easyops-analytics';
10
14
  import { Modal, message, Empty, ConfigProvider } from 'antd';
11
15
  import { ExclamationCircleOutlined } from '@ant-design/icons';
12
- import i18next, { getFixedT } from 'i18next';
13
- import moment from 'moment';
14
- import { pipes } from '@next-core/pipes';
15
- import { userAnalytics, apiAnalyzer } from '@next-core/easyops-analytics';
16
16
  import yaml from 'js-yaml';
17
17
  import { loadBricksImperatively, loadProcessorsImperatively } from '@next-core/loader';
18
18
  import { withTranslation } from 'react-i18next';
@@ -291,999 +291,885 @@ var assertValidOperator = op => {
291
291
  }
292
292
  };
293
293
 
294
- var brickTemplateRegistry = new Map();
295
- function registerBrickTemplate(name, factory) {
296
- if (brickTemplateRegistry.has(name)) {
297
- // eslint-disable-next-line no-console
298
- console.error("Brick template of \"".concat(name, "\" already registered."));
299
- return;
294
+ function supply(attemptToVisitGlobals, providedGlobalVariables, mock) {
295
+ var globalVariables = _objectSpread({}, providedGlobalVariables);
296
+ // Allow limited browser builtin values.
297
+ globalVariables["undefined"] = undefined;
298
+ for (var variableName of attemptToVisitGlobals) {
299
+ if (!Object.prototype.hasOwnProperty.call(globalVariables, variableName)) {
300
+ var variable = supplyIndividual(variableName, mock);
301
+ if (variable !== undefined) {
302
+ globalVariables[variableName] = variable;
303
+ }
304
+ }
300
305
  }
301
- brickTemplateRegistry.set(name, factory);
306
+ return globalVariables;
302
307
  }
308
+ var shouldOmitInLodash = new Set([
309
+ // Omit all mutable methods from lodash.
310
+ // But allow sequence methods like `_.chain`.
311
+ "fill", "pull", "pullAll", "pullAllBy", "pullAllWith", "pullAt", "remove", "reverse", "assign", "assignIn", "assignInWith", "assignWith", "defaults", "defaultsDeep", "merge", "mergeWith", "set", "setWith", "unset", "update", "updateWith",
312
+ /**
313
+ * Ignore `Function` methods from lodash, too.
314
+ * There are chances to invoke `Object.assign`, etc.
315
+ *
316
+ * E.g.:
317
+ *
318
+ * ```
319
+ * _.wrap(_.method('constructor.assign',{b:2},{b:3}),(func,...a) => func(...a))({})
320
+ * ```
321
+ */
322
+ "after", "ary", "before", "bind", "bindKey", "curry", "curryRight", "debounce", "defer", "delay", "flip", "memoize", "negate", "once", "overArgs", "partial", "partialRight", "rearg", "rest", "spread", "throttle", "unary", "wrap"]);
303
323
 
304
- // Themes.
305
- var DEFAULT_THEME = "light";
306
- var theme = DEFAULT_THEME;
307
- var storage = new JsonStorage(localStorage);
308
- var LOCAL_STORAGE_APPS_THEME_KEY = "apps-theme";
309
- function setTheme(value) {
310
- if (value !== "dark" && value !== "light" && value !== "dark-v2") {
311
- throw new Error("Unsupported theme: ".concat(value));
324
+ // Omit all mutable methods from moment.
325
+ var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
326
+ 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"]);
327
+ function supplyIndividual(variableName, mock) {
328
+ switch (variableName) {
329
+ case "Object":
330
+ // Do not allow mutable methods like `Object.assign`.
331
+ return delegateMethods(Object, ["entries", "fromEntries", "keys", "values"]);
332
+ case "_":
333
+ return Object.fromEntries(Object.entries(_).filter(entry => !shouldOmitInLodash.has(entry[0])).concat(mock ? [["uniqueId", prefix => "".concat(prefix !== null && prefix !== void 0 ? prefix : "", "42")]] : []));
334
+ case "moment":
335
+ return Object.assign(function () {
336
+ return moment(...arguments);
337
+ }, Object.fromEntries(Object.entries(moment).filter(entry => !shouldOmitInMoment.has(entry[0]))));
338
+ case "PIPES":
339
+ return pipes;
340
+ case "TAG_URL":
341
+ return tagUrlFactory(true);
342
+ case "SAFE_TAG_URL":
343
+ return tagUrlFactory();
344
+ default:
345
+ if (allowedGlobalObjects.has(variableName)) {
346
+ return window[variableName];
347
+ }
312
348
  }
313
- theme = value;
314
349
  }
315
- function getTheme() {
316
- return theme;
350
+ function delegateMethods(target, methods) {
351
+ return Object.fromEntries(methods.map(method => [method, function () {
352
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
353
+ args[_key] = arguments[_key];
354
+ }
355
+ return target[method].apply(target, args);
356
+ }]));
317
357
  }
318
- function getCurrentTheme() {
319
- return document.documentElement.dataset.theme;
358
+ /**
359
+ * Pass `ignoreSlashes` as `true` to encode all tagged expressions
360
+ * as URL components, except for `/` which maybe used in `APP.homepage`.
361
+ *
362
+ * Otherwise encode all tagged expressions as URL components.
363
+ * This will encode `/` as `%2F`. So do not use it directly
364
+ * with `APP.homepage` as in template expressions.
365
+ *
366
+ * @example
367
+ *
368
+ * ```js
369
+ * TAG_URL`${APP.homepage}/list?q=${q}&redirect=${redirect}`
370
+ * ```
371
+ *
372
+ * ```js
373
+ * SAFE_TAG_URL`file/${path}?q=${q}`
374
+ * // `path` will be fully transformed by `encodeURIComponent`.
375
+ * ```
376
+ *
377
+ * ```js
378
+ * // Wrap `APP.homepage` outside of `SAFE_TAG_URL`.
379
+ * `${APP.homepage}/${SAFE_TAG_URL`file/${path}?q=${q}`}`
380
+ * ```
381
+ */
382
+ function tagUrlFactory(ignoreSlashes) {
383
+ return function (strings) {
384
+ for (var _len2 = arguments.length, partials = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
385
+ partials[_key2 - 1] = arguments[_key2];
386
+ }
387
+ var result = [];
388
+ strings.forEach((str, index) => {
389
+ result.push(str);
390
+ if (index < partials.length) {
391
+ result.push(ignoreSlashes ? String(partials[index]).replace(/[^/]+/g, p => encodeURIComponent(p)) : encodeURIComponent(String(partials[index])));
392
+ }
393
+ });
394
+ return result.join("");
395
+ };
320
396
  }
321
- function applyTheme(value) {
322
- if (value) {
323
- setTheme(value);
324
- } else {
325
- value = getTheme();
326
- }
327
- if (value !== getCurrentTheme()) {
328
- document.documentElement.dataset.theme = value;
329
- window.dispatchEvent(new CustomEvent("theme.change", {
330
- detail: value
331
- }));
332
- }
397
+
398
+ function getUrlByAliasFactory(app) {
399
+ return function getUrlByAlias(alias, pathParams, query) {
400
+ if (!(app !== null && app !== void 0 && app.$$routeAliasMap.has(alias))) {
401
+ // eslint-disable-next-line no-console
402
+ throw new Error("Route alias not found: ".concat(alias));
403
+ }
404
+ var routeConf = app.$$routeAliasMap.get(alias);
405
+ var url = toPath(computeRealRoutePath(routeConf.path, app), pathParams);
406
+ if (query) {
407
+ var urlSearchParams = new URLSearchParams();
408
+ for (var [key, value] of Object.entries(query)) {
409
+ if (Array.isArray(value)) {
410
+ for (var item of value) {
411
+ urlSearchParams.append(key, item);
412
+ }
413
+ } else if (value !== undefined && value !== null && value !== "") {
414
+ urlSearchParams.set(key, value);
415
+ }
416
+ }
417
+ var queryString = urlSearchParams.toString();
418
+ if (queryString.length > 0) {
419
+ url += "?".concat(queryString);
420
+ }
421
+ }
422
+ return url;
423
+ };
333
424
  }
334
- function useCurrentTheme() {
335
- var [currentTheme, setCurrentTheme] = useState(getCurrentTheme());
336
- useEffect(() => {
337
- var listenToThemeChange = event => {
338
- setCurrentTheme(event.detail);
339
- };
340
- window.addEventListener("theme.change", listenToThemeChange);
341
- return () => {
342
- window.removeEventListener("theme.change", listenToThemeChange);
343
- };
344
- }, []);
345
- return currentTheme;
425
+
426
+ function getUrlBySegueFactory(app, segues) {
427
+ return function getUrlBySegue(segueId, pathParams, query) {
428
+ if (!hasOwnProperty(segues, segueId)) {
429
+ // eslint-disable-next-line no-console
430
+ throw new Error("Segue not found: ".concat(segueId));
431
+ }
432
+ var segue = segues[segueId];
433
+ return getUrlByAliasFactory(app)(segue.target, pathParams, query);
434
+ };
346
435
  }
347
- function batchSetAppsLocalTheme(appsTheme) {
348
- storage.setItem(LOCAL_STORAGE_APPS_THEME_KEY, _objectSpread(_objectSpread({}, getLocalAppsTheme()), appsTheme));
436
+
437
+ function imagesFactory(appId, isBuildPush, version) {
438
+ return {
439
+ get(name) {
440
+ var getSuffix = () => {
441
+ var suffix = window.APP_ROOT ? "".concat(window.APP_ROOT).concat(window.BOOTSTRAP_UNION_FILE && window.PUBLIC_DEPS ? "" : "-/") : "";
442
+ if (!suffix.startsWith("/")) {
443
+ suffix = getBasePath() + suffix;
444
+ }
445
+ if (window.APP_ID && window.APP_ID !== appId) {
446
+ return suffix.replace(new RegExp("(^|/)".concat(escapeRegExp(window.APP_ID), "/")), "$1".concat(appId, "/")).replace(/\/\d+\.\d+\.\d+\//, "/".concat(version, "/"));
447
+ }
448
+ return suffix;
449
+ };
450
+ return isBuildPush ? "".concat(getBasePath(), "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/").concat(name) : window.BOOTSTRAP_UNION_FILE && window.PUBLIC_DEPS ? "".concat(getSuffix(), "images/").concat(name) : "".concat(getSuffix(), "micro-apps/").concat(appId, "/images/").concat(name);
451
+ }
452
+ };
349
453
  }
350
- function getLocalAppsTheme() {
351
- var result;
352
- try {
353
- result = storage.getItem(LOCAL_STORAGE_APPS_THEME_KEY);
354
- } catch (_unused) {
355
- // eslint-disable-next-line no-console
356
- console.error("JSON parse error inside `getLocalAppsTheme()`");
357
- }
358
- return result || {};
454
+ function widgetImagesFactory(widgetId, widgetVersion) {
455
+ return {
456
+ get(name) {
457
+ var _window$PUBLIC_ROOT;
458
+ return "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "bricks/").concat(widgetId, "/").concat(window.PUBLIC_ROOT_WITH_VERSION && widgetVersion ? "".concat(widgetVersion, "/") : "", "dist/assets/").concat(name);
459
+ }
460
+ };
359
461
  }
360
462
 
361
- // Modes.
362
- var DEFAULT_MODE = "default";
363
- var mode = DEFAULT_MODE;
364
- function setMode(value) {
365
- if (value !== "dashboard" && value !== "default") {
366
- throw new Error("Unsupported mode: ".concat(value));
463
+ var injected = new WeakSet();
464
+
465
+ // The injected (or transformed) result should never be *injected* again.
466
+ // So does the fetched data from a remote api.
467
+ function recursiveMarkAsInjected(value) {
468
+ if (isObject(value)) {
469
+ if (!haveBeenInjected(value)) {
470
+ injected.add(value);
471
+ if (Array.isArray(value)) {
472
+ value.forEach(recursiveMarkAsInjected);
473
+ } else {
474
+ // Only mark pure objects.
475
+ var proto = Object.getPrototypeOf(value);
476
+ if (!proto || proto.constructor === Object) {
477
+ Object.values(value).forEach(recursiveMarkAsInjected);
478
+ }
479
+ }
480
+ }
367
481
  }
368
- mode = value;
369
482
  }
370
- function getMode() {
371
- return mode;
483
+ function haveBeenInjected(object) {
484
+ return injected.has(object);
372
485
  }
373
- function getCurrentMode() {
374
- return document.documentElement.dataset.mode;
486
+ function resetAllInjected() {
487
+ injected = new WeakSet();
375
488
  }
376
- function applyMode(value) {
377
- if (value) {
378
- setMode(value);
379
- } else {
380
- value = getMode();
381
- }
382
- if (value !== getCurrentMode()) {
383
- document.documentElement.dataset.mode = value;
384
- window.dispatchEvent(new CustomEvent("mode.change", {
385
- detail: value
386
- }));
489
+ function cloneDeepWithInjectedMark(value) {
490
+ if (isObject(value) && !isPreEvaluated(value)) {
491
+ var clone = Array.isArray(value) ? value.map(item => cloneDeepWithInjectedMark(item)) : Object.fromEntries(
492
+ // Get both string and symbol keys.
493
+ Object.entries(value).map(_ref => {
494
+ var [k, v] = _ref;
495
+ return [k, cloneDeepWithInjectedMark(v)];
496
+ }).concat(Object.getOwnPropertySymbols(value).map(k => [k, value[k]])));
497
+ if (haveBeenInjected(value)) {
498
+ injected.add(clone);
499
+ }
500
+ return clone;
387
501
  }
388
- }
389
- function useCurrentMode() {
390
- var [currentMode, setCurrentMode] = useState(getCurrentMode());
391
- useEffect(() => {
392
- var listenToModeChange = event => {
393
- setCurrentMode(event.detail);
394
- };
395
- window.addEventListener("mode.change", listenToModeChange);
396
- return () => {
397
- window.removeEventListener("mode.change", listenToModeChange);
398
- };
399
- }, []);
400
- return currentMode;
401
- }
402
- function getCssPropertyValue(name) {
403
- var _window$getComputedSt;
404
- var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.documentElement;
405
- if (!el) return "";
406
- return ((_window$getComputedSt = window.getComputedStyle(el)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue(name)) || "";
502
+ return value;
407
503
  }
408
504
 
409
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
410
- try {
411
- var info = gen[key](arg);
412
- var value = info.value;
413
- } catch (error) {
414
- reject(error);
415
- return;
505
+ var StateOfUseBrick;
506
+ (function (StateOfUseBrick) {
507
+ StateOfUseBrick[StateOfUseBrick["INITIAL"] = 0] = "INITIAL";
508
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK"] = 1] = "USE_BRICK";
509
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_ITEM"] = 2] = "USE_BRICK_ITEM";
510
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_PROPERTIES"] = 3] = "USE_BRICK_PROPERTIES";
511
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_TRANSFORM"] = 4] = "USE_BRICK_TRANSFORM";
512
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_EVENTS"] = 5] = "USE_BRICK_EVENTS";
513
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_IF"] = 6] = "USE_BRICK_IF";
514
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS"] = 7] = "USE_BRICK_SLOTS";
515
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM"] = 8] = "USE_BRICK_SLOTS_ITEM";
516
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM_BRICKS"] = 9] = "USE_BRICK_SLOTS_ITEM_BRICKS";
517
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM_BRICKS_ITEM"] = 10] = "USE_BRICK_SLOTS_ITEM_BRICKS_ITEM";
518
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE"] = 11] = "USE_BRICK_LIFECYCLE";
519
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES"] = 12] = "USE_BRICK_LIFECYCLE_USERESOLVES";
520
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM"] = 13] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM";
521
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM"] = 14] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM";
522
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT"] = 15] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT";
523
+ StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM"] = 16] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM";
524
+ })(StateOfUseBrick || (StateOfUseBrick = {}));
525
+ function isLazyContentInUseBrick(state) {
526
+ switch (state) {
527
+ case StateOfUseBrick.USE_BRICK_PROPERTIES:
528
+ case StateOfUseBrick.USE_BRICK_TRANSFORM:
529
+ case StateOfUseBrick.USE_BRICK_EVENTS:
530
+ case StateOfUseBrick.USE_BRICK_IF:
531
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM:
532
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM:
533
+ return true;
416
534
  }
417
- if (info.done) {
418
- resolve(value);
535
+ return false;
536
+ }
537
+ function getNextStateOfUseBrick(state, isArray, key) {
538
+ if (isLazyContentInUseBrick(state)) {
539
+ return state;
540
+ }
541
+ if (isArray) {
542
+ switch (state) {
543
+ case StateOfUseBrick.USE_BRICK:
544
+ return StateOfUseBrick.USE_BRICK_ITEM;
545
+ case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS:
546
+ return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM;
547
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES:
548
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM;
549
+ }
419
550
  } else {
420
- Promise.resolve(value).then(_next, _throw);
551
+ switch (state) {
552
+ case StateOfUseBrick.INITIAL:
553
+ if (key === "useBrick") {
554
+ return StateOfUseBrick.USE_BRICK;
555
+ }
556
+ break;
557
+ case StateOfUseBrick.USE_BRICK:
558
+ case StateOfUseBrick.USE_BRICK_ITEM:
559
+ case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM:
560
+ {
561
+ switch (key) {
562
+ case "properties":
563
+ return StateOfUseBrick.USE_BRICK_PROPERTIES;
564
+ case "transform":
565
+ return StateOfUseBrick.USE_BRICK_TRANSFORM;
566
+ case "events":
567
+ return StateOfUseBrick.USE_BRICK_EVENTS;
568
+ case "slots":
569
+ return StateOfUseBrick.USE_BRICK_SLOTS;
570
+ case "if":
571
+ return StateOfUseBrick.USE_BRICK_IF;
572
+ case "lifeCycle":
573
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE;
574
+ }
575
+ break;
576
+ }
577
+ case StateOfUseBrick.USE_BRICK_SLOTS:
578
+ return StateOfUseBrick.USE_BRICK_SLOTS_ITEM;
579
+ case StateOfUseBrick.USE_BRICK_SLOTS_ITEM:
580
+ if (key === "bricks") {
581
+ return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS;
582
+ }
583
+ break;
584
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE:
585
+ if (key === "useResolves") {
586
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES;
587
+ }
588
+ break;
589
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM:
590
+ {
591
+ switch (key) {
592
+ case "transform":
593
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM;
594
+ case "onReject":
595
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT;
596
+ }
597
+ break;
598
+ }
599
+ case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT:
600
+ if (key === "transform") {
601
+ return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM;
602
+ }
603
+ break;
604
+ }
421
605
  }
606
+ return StateOfUseBrick.INITIAL;
422
607
  }
423
- function _asyncToGenerator$2(fn) {
424
- return function () {
425
- var self = this,
426
- args = arguments;
427
- return new Promise(function (resolve, reject) {
428
- var gen = fn.apply(self, args);
429
- function _next(value) {
430
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
431
- }
432
- function _throw(err) {
433
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
608
+
609
+ function getTracks(value) {
610
+ var contextNames = false;
611
+ var stateNames = false;
612
+ var formStateNames = false;
613
+ if (typeof value === "string" ? isEvaluable(value) : isPreEvaluated(value)) {
614
+ var raw = typeof value === "string" ? value : getPreEvaluatedRaw(value);
615
+ if (isTrackAll(raw)) {
616
+ var result = trackAll(raw);
617
+ if (result) {
618
+ contextNames = result.context;
619
+ stateNames = result.state;
620
+ formStateNames = result.formState;
434
621
  }
435
- _next(undefined);
436
- });
622
+ } else {
623
+ contextNames = trackContext(raw);
624
+ stateNames = trackState(raw);
625
+ formStateNames = trackFormState(raw);
626
+ }
627
+ }
628
+ return {
629
+ contextNames,
630
+ stateNames,
631
+ formStateNames
437
632
  };
438
633
  }
439
- function _defineProperty(obj, key, value) {
440
- if (key in obj) {
441
- Object.defineProperty(obj, key, {
442
- value: value,
443
- enumerable: true,
444
- configurable: true,
445
- writable: true
446
- });
447
- } else {
448
- obj[key] = value;
449
- }
450
- return obj;
634
+
635
+ /** @internal */
636
+ function transformElementProperties(element, data, to, from, mapArray) {
637
+ var result = preprocessTransformProperties(data, to, from, mapArray);
638
+ setRealProperties(element, result, true);
451
639
  }
452
- function ownKeys(object, enumerableOnly) {
453
- var keys = Object.keys(object);
454
- if (Object.getOwnPropertySymbols) {
455
- var symbols = Object.getOwnPropertySymbols(object);
456
- if (enumerableOnly) symbols = symbols.filter(function (sym) {
457
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
458
- });
459
- keys.push.apply(keys, symbols);
640
+
641
+ /** @internal */
642
+ function transformProperties(props, data, to, from, mapArray, options) {
643
+ var result = preprocessTransformProperties(data, to, from, mapArray, options);
644
+ for (var [propName, propValue] of Object.entries(result)) {
645
+ set(props, propName, propValue);
460
646
  }
461
- return keys;
647
+ return props;
462
648
  }
463
- function _objectSpread2(target) {
464
- for (var i = 1; i < arguments.length; i++) {
465
- var source = arguments[i] != null ? arguments[i] : {};
466
- if (i % 2) {
467
- ownKeys(Object(source), true).forEach(function (key) {
468
- _defineProperty(target, key, source[key]);
469
- });
470
- } else if (Object.getOwnPropertyDescriptors) {
471
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
649
+
650
+ /** @internal */
651
+ function doTransform(data, to, options) {
652
+ var preEvaluated = isPreEvaluated(to);
653
+ if (preEvaluated || typeof to === "string") {
654
+ // For `useBrick`, some fields such as `properties`/`transform`/`events`,
655
+ // are kept and to be transformed later.
656
+ var lazy = (options === null || options === void 0 ? void 0 : options.$$lazyForUseBrick) && isLazyContentInUseBrick(options.$$stateOfUseBrick);
657
+ if (lazy) {
658
+ // The current data context is not memoized, since a new data context
659
+ // should always be provided before later transformations.
660
+ return to;
661
+ }
662
+ var result;
663
+ var dismissRecursiveMarkingInjected = false;
664
+ if (preEvaluated || isEvaluable(to)) {
665
+ var runtimeContext = {
666
+ data
667
+ };
668
+ if (options !== null && options !== void 0 && options.tplContextId) runtimeContext.tplContextId = options.tplContextId;
669
+ if (options !== null && options !== void 0 && options.formContextId) runtimeContext.formContextId = options.formContextId;
670
+ result = evaluate(to, runtimeContext, options === null || options === void 0 ? void 0 : options.evaluateOptions);
671
+ dismissRecursiveMarkingInjected = shouldDismissRecursiveMarkingInjected(to);
472
672
  } else {
473
- ownKeys(Object(source)).forEach(function (key) {
474
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
475
- });
673
+ result = options !== null && options !== void 0 && options.allowInject ? transformAndInject(to, data, _internalApiGetCurrentContext()) : transform(to, data);
476
674
  }
477
- }
478
- return target;
675
+ if (!dismissRecursiveMarkingInjected) {
676
+ recursiveMarkAsInjected(result);
677
+ }
678
+ return result;
679
+ }
680
+ if (!isObject(to) || haveBeenInjected(to)) {
681
+ return to;
682
+ }
683
+ if (Array.isArray(to)) {
684
+ var nextOptions = getNextDoTransformOptions(options, true);
685
+ return to.map(item => doTransform(data, item, nextOptions));
686
+ }
687
+ return Object.fromEntries(
688
+ // Get both string and symbol keys.
689
+ Object.entries(to).map(_ref => {
690
+ var [k, v] = _ref;
691
+ if (Array.isArray(options === null || options === void 0 ? void 0 : options.trackingContextList) && (typeof v === "string" ? isEvaluable(v) : isPreEvaluated(v))) {
692
+ var raw;
693
+ if (typeof v === "string") {
694
+ raw = v;
695
+ } else {
696
+ raw = getPreEvaluatedRaw(v);
697
+ addDataToPreEvaluated(v, data);
698
+ }
699
+ var {
700
+ contextNames,
701
+ stateNames,
702
+ formStateNames
703
+ } = getTracks(raw);
704
+ if (contextNames || stateNames || formStateNames) {
705
+ options.trackingContextList.push({
706
+ contextNames,
707
+ stateNames,
708
+ formStateNames,
709
+ propName: k,
710
+ propValue: v
711
+ });
712
+ }
713
+ }
714
+ return [k, doTransform(data, v, getNextDoTransformOptions(options, false, k))];
715
+ }).concat(Object.getOwnPropertySymbols(to).map(k => [k, to[k]])));
479
716
  }
480
717
 
481
- /**
482
- * @description 获取实例详情
483
- * @endpoint GET /object/:objectId/instance/:instanceId
484
- */
485
- var InstanceApi_getDetail = /*#__PURE__*/function () {
486
- var _ref = _asyncToGenerator$2(function* (objectId, instanceId, params, options) {
487
- return (/**! @contract easyops.api.cmdb.instance.GetDetail */
488
- (yield http.get("api/gateway/cmdb.instance.GetDetail/object/".concat(objectId, "/instance/").concat(instanceId), _objectSpread2(_objectSpread2({}, options), {}, {
489
- params
490
- }))).data
491
- );
492
- });
493
- return function InstanceApi_getDetail(_x, _x2, _x3, _x4) {
494
- return _ref.apply(this, arguments);
495
- };
496
- }();
718
+ /** @internal */
719
+ function reTransformForDevtools(transformationId, data, to, from, mapArray, allowInject) {
720
+ try {
721
+ preprocessTransformProperties(data, to, from, mapArray, {
722
+ isReTransformation: true,
723
+ transformationId,
724
+ allowInject
725
+ });
726
+ } catch (error) {
727
+ devtoolsHookEmit("re-transformation", {
728
+ id: transformationId,
729
+ error: error.message,
730
+ detail: {
731
+ transform: to,
732
+ data,
733
+ options: {
734
+ from,
735
+ mapArray,
736
+ allowInject
737
+ }
738
+ }
739
+ });
740
+ }
741
+ }
497
742
 
498
- /**
499
- * @description 搜索实例
500
- * @endpoint POST /object/:objectId/instance/_search
501
- */
502
- var InstanceApi_postSearch = /*#__PURE__*/function () {
503
- var _ref = _asyncToGenerator$2(function* (objectId, data, options) {
504
- return (/**! @contract easyops.api.cmdb.instance.PostSearch */
505
- (yield http.post("api/gateway/cmdb.instance.PostSearch/object/".concat(objectId, "/instance/_search"), data, options)).data
506
- );
507
- });
508
- return function InstanceApi_postSearch(_x, _x2, _x3) {
509
- return _ref.apply(this, arguments);
743
+ /** @internal */
744
+ function preprocessTransformProperties(data, to, from, mapArray, options) {
745
+ var props = {};
746
+ var processedData = from ? get(data, from) : data;
747
+ if (Array.isArray(to)) {
748
+ for (var item of to) {
749
+ pipeableTransform(props, processedData, item.to, item.from, item.mapArray, {
750
+ allowInject: options === null || options === void 0 ? void 0 : options.allowInject
751
+ });
752
+ }
753
+ } else {
754
+ pipeableTransform(props, processedData, to, undefined, mapArray, {
755
+ allowInject: options === null || options === void 0 ? void 0 : options.allowInject
756
+ });
757
+ }
758
+ var detail = {
759
+ transform: to,
760
+ data,
761
+ options: {
762
+ from,
763
+ mapArray,
764
+ allowInject: options === null || options === void 0 ? void 0 : options.allowInject
765
+ },
766
+ result: props
510
767
  };
511
- }();
512
-
513
- /**
514
- * @description 获取菜单信息
515
- * @endpoint GET /api/v1/micro-app/menus/:menuId
516
- */
517
- var InstalledMicroAppApi_getMenusInfo = /*#__PURE__*/function () {
518
- var _ref = _asyncToGenerator$3(function* (menuId, params, options) {
519
- return (/**! @contract easyops.api.micro_app.installed_micro_app.GetMenusInfo@1.0.0 */(yield http.get("api/gateway/micro_app.installed_micro_app.GetMenusInfo/api/v1/micro-app/menus/".concat(menuId), _objectSpread(_objectSpread({}, options), {}, {
520
- params
521
- }))).data
522
- );
523
- });
524
- return function InstalledMicroAppApi_getMenusInfo(_x, _x2, _x3) {
525
- return _ref.apply(this, arguments);
768
+ if (options !== null && options !== void 0 && options.isReTransformation) {
769
+ devtoolsHookEmit("re-transformation", {
770
+ id: options.transformationId,
771
+ detail
772
+ });
773
+ } else {
774
+ devtoolsHookEmit("transformation", detail);
775
+ }
776
+ return props;
777
+ }
778
+ function pipeableTransform(props, data, to, from, mapArray, options) {
779
+ if (!to) {
780
+ // Do nothing if `to` is falsy.
781
+ return;
782
+ }
783
+ var fromData = from ? get(data, from) : data;
784
+ var isArray = Array.isArray(fromData);
785
+ if (!isArray && mapArray === true) {
786
+ isArray = true;
787
+ fromData = [fromData];
788
+ } else if (isArray && mapArray === false) {
789
+ isArray = false;
790
+ }
791
+ if (typeof to === "string") {
792
+ props[to] = fromData;
793
+ return;
794
+ }
795
+ var _loop = function (transformedPropName, transformTo) {
796
+ // If `fromData` is an array, mapping it's items.
797
+ props[transformedPropName] = isArray ? fromData.map(item => doTransform(item, transformTo, options)) : doTransform(fromData, transformTo, options);
526
798
  };
527
- }();
799
+ for (var [transformedPropName, transformTo] of Object.entries(to)) {
800
+ _loop(transformedPropName, transformTo);
801
+ }
802
+ }
528
803
 
529
- /** 微应用的i18n信息 */
804
+ /** @internal */
805
+ function transformIntermediateData(data, to, from, mapArray) {
806
+ var intermediateData = from ? get(data, from) : data;
807
+ if (!to) {
808
+ return intermediateData;
809
+ }
810
+ return transformProperties({}, intermediateData, to, undefined, mapArray);
811
+ }
812
+ function getNextDoTransformOptions(options, isArray, key) {
813
+ var _options$$$stateOfUse;
814
+ return options ? _objectSpread(_objectSpread({}, options), {}, {
815
+ // Collect tracking context in first level only.
816
+ trackingContextList: undefined,
817
+ $$stateOfUseBrick: options.$$lazyForUseBrick ? getNextStateOfUseBrick((_options$$$stateOfUse = options.$$stateOfUseBrick) !== null && _options$$$stateOfUse !== void 0 ? _options$$$stateOfUse : StateOfUseBrick.INITIAL, isArray, key) : undefined
818
+ }) : options;
819
+ }
530
820
 
531
- /**
532
- * @description 获取微应用的i18n数据
533
- * @endpoint GET /api/v1/micro-app/i18n
534
- */
535
- var InstalledMicroAppApi_getI18NData = /*#__PURE__*/function () {
536
- var _ref = _asyncToGenerator$3(function* (params, options) {
537
- return (/**! @contract easyops.api.micro_app.installed_micro_app.GetI18NData@1.0.0 */(yield http.get("api/gateway/micro_app.installed_micro_app.GetI18NData/api/v1/micro-app/i18n", _objectSpread(_objectSpread({}, options), {}, {
538
- params
539
- }))).data
540
- );
541
- });
542
- return function InstalledMicroAppApi_getI18NData(_x, _x2) {
543
- return _ref.apply(this, arguments);
544
- };
545
- }();
821
+ var MESSAGE_SOURCE_PANEL = "brick-next-devtools-panel";
822
+ var EVALUATION_EDIT = "devtools-evaluation-edit";
823
+ var TRANSFORMATION_EDIT = "devtools-transformation-edit";
824
+ var FRAME_ACTIVE_CHANGE = "devtools-frame-active-change";
825
+ var PANEL_CHANGE = "devtools-panel-change";
826
+ var frameIsActive = true;
827
+ var selectedPanel;
546
828
 
547
- /**
548
- * @description 校验系统权限
549
- * @endpoint POST /api/micro_app/v1/permission/validate
550
- */
551
- var PermissionApi_validatePermissions = /*#__PURE__*/function () {
552
- var _ref = _asyncToGenerator$3(function* (data, options) {
553
- return (/**! @contract easyops.api.micro_app.permission.ValidatePermissions@1.0.0 */(yield http.post("api/gateway/micro_app.permission.ValidatePermissions/api/micro_app/v1/permission/validate", data, options)).data
554
- );
555
- });
556
- return function PermissionApi_validatePermissions(_x, _x2) {
557
- return _ref.apply(this, arguments);
829
+ /* istanbul ignore next */
830
+ function devtoolsHookEmit(type, payload) {
831
+ var devtools = getDevHook();
832
+ if (!devtools || !(type === "evaluation" ? frameIsActive && (!selectedPanel || selectedPanel === "Evaluations") : type === "transformation" ? frameIsActive && (!selectedPanel || selectedPanel === "Transformations") : true)) {
833
+ // Ignore messages if current devtools panel is not relevant.
834
+ return;
835
+ }
836
+ var emit = () => {
837
+ var _devtools$emit;
838
+ (_devtools$emit = devtools.emit) === null || _devtools$emit === void 0 ? void 0 : _devtools$emit.call(devtools, {
839
+ type,
840
+ payload
841
+ });
558
842
  };
559
- }();
560
843
 
561
- function supply(attemptToVisitGlobals, providedGlobalVariables, mock) {
562
- var globalVariables = _objectSpread({}, providedGlobalVariables);
563
- // Allow limited browser builtin values.
564
- globalVariables["undefined"] = undefined;
565
- for (var variableName of attemptToVisitGlobals) {
566
- if (!Object.prototype.hasOwnProperty.call(globalVariables, variableName)) {
567
- var variable = supplyIndividual(variableName, mock);
568
- if (variable !== undefined) {
569
- globalVariables[variableName] = variable;
570
- }
571
- }
844
+ // Try to emit only in idle time.
845
+ if (typeof window.requestIdleCallback === "function") {
846
+ window.requestIdleCallback(emit);
847
+ } else {
848
+ setTimeout(emit, 0);
572
849
  }
573
- return globalVariables;
574
850
  }
575
- var shouldOmitInLodash = new Set([
576
- // Omit all mutable methods from lodash.
577
- // But allow sequence methods like `_.chain`.
578
- "fill", "pull", "pullAll", "pullAllBy", "pullAllWith", "pullAt", "remove", "reverse", "assign", "assignIn", "assignInWith", "assignWith", "defaults", "defaultsDeep", "merge", "mergeWith", "set", "setWith", "unset", "update", "updateWith",
579
- /**
580
- * Ignore `Function` methods from lodash, too.
581
- * There are chances to invoke `Object.assign`, etc.
582
- *
583
- * E.g.:
584
- *
585
- * ```
586
- * _.wrap(_.method('constructor.assign',{b:2},{b:3}),(func,...a) => func(...a))({})
587
- * ```
588
- */
589
- "after", "ary", "before", "bind", "bindKey", "curry", "curryRight", "debounce", "defer", "delay", "flip", "memoize", "negate", "once", "overArgs", "partial", "partialRight", "rearg", "rest", "spread", "throttle", "unary", "wrap"]);
590
-
591
- // Omit all mutable methods from moment.
592
- var shouldOmitInMoment = new Set(["lang", "langData", "locale", "localeData", "defineLocale", "updateLocale", "updateOffset"]);
593
- 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"]);
594
- function supplyIndividual(variableName, mock) {
595
- switch (variableName) {
596
- case "Object":
597
- // Do not allow mutable methods like `Object.assign`.
598
- return delegateMethods(Object, ["entries", "fromEntries", "keys", "values"]);
599
- case "_":
600
- return Object.fromEntries(Object.entries(_).filter(entry => !shouldOmitInLodash.has(entry[0])).concat(mock ? [["uniqueId", prefix => "".concat(prefix !== null && prefix !== void 0 ? prefix : "", "42")]] : []));
601
- case "moment":
602
- return Object.assign(function () {
603
- return moment(...arguments);
604
- }, Object.fromEntries(Object.entries(moment).filter(entry => !shouldOmitInMoment.has(entry[0]))));
605
- case "PIPES":
606
- return pipes;
607
- case "TAG_URL":
608
- return tagUrlFactory(true);
609
- case "SAFE_TAG_URL":
610
- return tagUrlFactory();
611
- default:
612
- if (allowedGlobalObjects.has(variableName)) {
613
- return window[variableName];
614
- }
615
- }
616
- }
617
- function delegateMethods(target, methods) {
618
- return Object.fromEntries(methods.map(method => [method, function () {
619
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
620
- args[_key] = arguments[_key];
621
- }
622
- return target[method].apply(target, args);
623
- }]));
624
- }
625
- /**
626
- * Pass `ignoreSlashes` as `true` to encode all tagged expressions
627
- * as URL components, except for `/` which maybe used in `APP.homepage`.
628
- *
629
- * Otherwise encode all tagged expressions as URL components.
630
- * This will encode `/` as `%2F`. So do not use it directly
631
- * with `APP.homepage` as in template expressions.
632
- *
633
- * @example
634
- *
635
- * ```js
636
- * TAG_URL`${APP.homepage}/list?q=${q}&redirect=${redirect}`
637
- * ```
638
- *
639
- * ```js
640
- * SAFE_TAG_URL`file/${path}?q=${q}`
641
- * // `path` will be fully transformed by `encodeURIComponent`.
642
- * ```
643
- *
644
- * ```js
645
- * // Wrap `APP.homepage` outside of `SAFE_TAG_URL`.
646
- * `${APP.homepage}/${SAFE_TAG_URL`file/${path}?q=${q}`}`
647
- * ```
648
- */
649
- function tagUrlFactory(ignoreSlashes) {
650
- return function (strings) {
651
- for (var _len2 = arguments.length, partials = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
652
- partials[_key2 - 1] = arguments[_key2];
653
- }
654
- var result = [];
655
- strings.forEach((str, index) => {
656
- result.push(str);
657
- if (index < partials.length) {
658
- result.push(ignoreSlashes ? String(partials[index]).replace(/[^/]+/g, p => encodeURIComponent(p)) : encodeURIComponent(String(partials[index])));
659
- }
660
- });
661
- return result.join("");
662
- };
663
- }
664
-
665
- function getUrlByAliasFactory(app) {
666
- return function getUrlByAlias(alias, pathParams, query) {
667
- if (!(app !== null && app !== void 0 && app.$$routeAliasMap.has(alias))) {
668
- // eslint-disable-next-line no-console
669
- throw new Error("Route alias not found: ".concat(alias));
670
- }
671
- var routeConf = app.$$routeAliasMap.get(alias);
672
- var url = toPath(computeRealRoutePath(routeConf.path, app), pathParams);
673
- if (query) {
674
- var urlSearchParams = new URLSearchParams();
675
- for (var [key, value] of Object.entries(query)) {
676
- if (Array.isArray(value)) {
677
- for (var item of value) {
678
- urlSearchParams.append(key, item);
679
- }
680
- } else if (value !== undefined && value !== null && value !== "") {
681
- urlSearchParams.set(key, value);
682
- }
683
- }
684
- var queryString = urlSearchParams.toString();
685
- if (queryString.length > 0) {
686
- url += "?".concat(queryString);
687
- }
688
- }
689
- return url;
690
- };
691
- }
692
-
693
- function getUrlBySegueFactory(app, segues) {
694
- return function getUrlBySegue(segueId, pathParams, query) {
695
- if (!hasOwnProperty(segues, segueId)) {
696
- // eslint-disable-next-line no-console
697
- throw new Error("Segue not found: ".concat(segueId));
851
+ function listenDevtoolsEagerly() {
852
+ window.addEventListener("message", _ref => {
853
+ var {
854
+ data
855
+ } = _ref;
856
+ if ((data === null || data === void 0 ? void 0 : data.source) !== MESSAGE_SOURCE_PANEL) {
857
+ return;
698
858
  }
699
- var segue = segues[segueId];
700
- return getUrlByAliasFactory(app)(segue.target, pathParams, query);
701
- };
702
- }
703
-
704
- function imagesFactory(appId, isBuildPush, version) {
705
- return {
706
- get(name) {
707
- var getSuffix = () => {
708
- var suffix = window.APP_ROOT ? "".concat(window.APP_ROOT).concat(window.BOOTSTRAP_UNION_FILE && window.PUBLIC_DEPS ? "" : "-/") : "";
709
- if (!suffix.startsWith("/")) {
710
- suffix = getBasePath() + suffix;
859
+ var payload = data.payload;
860
+ switch (payload === null || payload === void 0 ? void 0 : payload.type) {
861
+ case FRAME_ACTIVE_CHANGE:
862
+ {
863
+ frameIsActive = payload.active;
864
+ break;
711
865
  }
712
- if (window.APP_ID && window.APP_ID !== appId) {
713
- return suffix.replace(new RegExp("(^|/)".concat(escapeRegExp(window.APP_ID), "/")), "$1".concat(appId, "/")).replace(/\/\d+\.\d+\.\d+\//, "/".concat(version, "/"));
866
+ case PANEL_CHANGE:
867
+ {
868
+ selectedPanel = payload.panel;
869
+ break;
714
870
  }
715
- return suffix;
716
- };
717
- return isBuildPush ? "".concat(getBasePath(), "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/").concat(name) : window.BOOTSTRAP_UNION_FILE && window.PUBLIC_DEPS ? "".concat(getSuffix(), "images/").concat(name) : "".concat(getSuffix(), "micro-apps/").concat(appId, "/images/").concat(name);
718
871
  }
719
- };
872
+ });
720
873
  }
721
- function widgetImagesFactory(widgetId, widgetVersion) {
722
- return {
723
- get(name) {
724
- var _window$PUBLIC_ROOT;
725
- return "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "bricks/").concat(widgetId, "/").concat(window.PUBLIC_ROOT_WITH_VERSION && widgetVersion ? "".concat(widgetVersion, "/") : "", "dist/assets/").concat(name);
874
+ function listenDevtools() {
875
+ window.addEventListener("message", _ref2 => {
876
+ var {
877
+ data
878
+ } = _ref2;
879
+ if ((data === null || data === void 0 ? void 0 : data.source) !== MESSAGE_SOURCE_PANEL) {
880
+ return;
726
881
  }
727
- };
728
- }
729
-
730
- var injected = new WeakSet();
731
-
732
- // The injected (or transformed) result should never be *injected* again.
733
- // So does the fetched data from a remote api.
734
- function recursiveMarkAsInjected(value) {
735
- if (isObject(value)) {
736
- if (!haveBeenInjected(value)) {
737
- injected.add(value);
738
- if (Array.isArray(value)) {
739
- value.forEach(recursiveMarkAsInjected);
740
- } else {
741
- // Only mark pure objects.
742
- var proto = Object.getPrototypeOf(value);
743
- if (!proto || proto.constructor === Object) {
744
- Object.values(value).forEach(recursiveMarkAsInjected);
882
+ var payload = data.payload;
883
+ switch (payload === null || payload === void 0 ? void 0 : payload.type) {
884
+ case EVALUATION_EDIT:
885
+ {
886
+ var {
887
+ raw,
888
+ context,
889
+ id
890
+ } = payload;
891
+ evaluate(raw, {
892
+ data: context.data,
893
+ event: restoreDehydrated(context.event)
894
+ }, {
895
+ isReEvaluation: true,
896
+ evaluationId: id
897
+ });
898
+ break;
899
+ }
900
+ case TRANSFORMATION_EDIT:
901
+ {
902
+ var {
903
+ data: _data,
904
+ transform,
905
+ id: _id,
906
+ options: {
907
+ from,
908
+ mapArray,
909
+ allowInject
910
+ }
911
+ } = payload;
912
+ reTransformForDevtools(_id, _data, transform, from, mapArray, allowInject);
913
+ break;
745
914
  }
746
- }
747
915
  }
748
- }
916
+ });
749
917
  }
750
- function haveBeenInjected(object) {
751
- return injected.has(object);
918
+ function getDevHook() {
919
+ return window.__BRICK_NEXT_DEVTOOLS_HOOK__;
752
920
  }
753
- function resetAllInjected() {
754
- injected = new WeakSet();
921
+ function restoreDehydrated(value) {
922
+ var _getDevHook$restoreDe, _getDevHook;
923
+ return (_getDevHook$restoreDe = (_getDevHook = getDevHook()) === null || _getDevHook === void 0 ? void 0 : _getDevHook.restoreDehydrated(value)) !== null && _getDevHook$restoreDe !== void 0 ? _getDevHook$restoreDe : value;
755
924
  }
756
- function cloneDeepWithInjectedMark(value) {
757
- if (isObject(value) && !isPreEvaluated(value)) {
758
- var clone = Array.isArray(value) ? value.map(item => cloneDeepWithInjectedMark(item)) : Object.fromEntries(
759
- // Get both string and symbol keys.
760
- Object.entries(value).map(_ref => {
761
- var [k, v] = _ref;
762
- return [k, cloneDeepWithInjectedMark(v)];
763
- }).concat(Object.getOwnPropertySymbols(value).map(k => [k, value[k]])));
764
- if (haveBeenInjected(value)) {
765
- injected.add(clone);
766
- }
767
- return clone;
768
- }
769
- return value;
925
+
926
+ function getItemFactory(storageType) {
927
+ return function (name) {
928
+ var storage = storageType === "local" ? localStorage : sessionStorage;
929
+ return JSON.parse(storage.getItem(name));
930
+ };
770
931
  }
771
932
 
772
- var StateOfUseBrick;
773
- (function (StateOfUseBrick) {
774
- StateOfUseBrick[StateOfUseBrick["INITIAL"] = 0] = "INITIAL";
775
- StateOfUseBrick[StateOfUseBrick["USE_BRICK"] = 1] = "USE_BRICK";
776
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_ITEM"] = 2] = "USE_BRICK_ITEM";
777
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_PROPERTIES"] = 3] = "USE_BRICK_PROPERTIES";
778
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_TRANSFORM"] = 4] = "USE_BRICK_TRANSFORM";
779
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_EVENTS"] = 5] = "USE_BRICK_EVENTS";
780
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_IF"] = 6] = "USE_BRICK_IF";
781
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS"] = 7] = "USE_BRICK_SLOTS";
782
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM"] = 8] = "USE_BRICK_SLOTS_ITEM";
783
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM_BRICKS"] = 9] = "USE_BRICK_SLOTS_ITEM_BRICKS";
784
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_SLOTS_ITEM_BRICKS_ITEM"] = 10] = "USE_BRICK_SLOTS_ITEM_BRICKS_ITEM";
785
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE"] = 11] = "USE_BRICK_LIFECYCLE";
786
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES"] = 12] = "USE_BRICK_LIFECYCLE_USERESOLVES";
787
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM"] = 13] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM";
788
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM"] = 14] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM";
789
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT"] = 15] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT";
790
- StateOfUseBrick[StateOfUseBrick["USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM"] = 16] = "USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM";
791
- })(StateOfUseBrick || (StateOfUseBrick = {}));
792
- function isLazyContentInUseBrick(state) {
793
- switch (state) {
794
- case StateOfUseBrick.USE_BRICK_PROPERTIES:
795
- case StateOfUseBrick.USE_BRICK_TRANSFORM:
796
- case StateOfUseBrick.USE_BRICK_EVENTS:
797
- case StateOfUseBrick.USE_BRICK_IF:
798
- case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM:
799
- case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM:
800
- return true;
801
- }
802
- return false;
933
+ var locale$7 = {
934
+ [K.REQUEST_FAILED]: "Request Failed",
935
+ [K.MODAL_OK]: "Ok",
936
+ [K.MODAL_CANCEL]: "Cancel",
937
+ [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
938
+ [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
939
+ [K.NETWORK_ERROR]: "Network error, please check your network.",
940
+ [K.PAGE_NOT_FOUND]: "Page not found, please check the URL",
941
+ [K.APP_NOT_FOUND]: "App not found, maybe the URL is wrong or you don't have permission to access",
942
+ [K.LICENSE_EXPIRED]: "The license authorization has expired, please contact the platform administrator",
943
+ [K.NO_PERMISSION]: "Unauthorized access, unable to retrieve the required resources for this page",
944
+ [K.OTHER_ERROR]: "Oops! Something went wrong",
945
+ [K.GO_BACK_PREVIOUS_PAGE]: "Go back to previous page",
946
+ [K.GO_BACK_HOME_PAGE]: "Back to home page",
947
+ [K.LOGIN_CHANGED]: "You have logged in as another account, click OK to refresh the page.",
948
+ [K.LOGOUT_APPLIED]: "Your account has been logged out, click OK to refresh the page."
949
+ };
950
+ var en = locale$7;
951
+
952
+ var locale$6 = {
953
+ [K.REQUEST_FAILED]: "请求失败",
954
+ [K.MODAL_OK]: "确认",
955
+ [K.MODAL_CANCEL]: "取消",
956
+ [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
957
+ [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
958
+ [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。",
959
+ [K.PAGE_NOT_FOUND]: "请求的页面未找到,请确认 URL 是否正确",
960
+ [K.APP_NOT_FOUND]: "请求的微应用无法找到, 可能是 URL 错误或者无权限访问",
961
+ [K.LICENSE_EXPIRED]: "License 授权失效,请联系平台管理员",
962
+ [K.NO_PERMISSION]: "没有权限,无法获取页面所需要的资源",
963
+ [K.OTHER_ERROR]: "糟糕!页面出现了一些问题",
964
+ [K.GO_BACK_PREVIOUS_PAGE]: "回到上一页",
965
+ [K.GO_BACK_HOME_PAGE]: "回到首页",
966
+ [K.LOGIN_CHANGED]: "您已经登录另一个账号,点击确定刷新页面。",
967
+ [K.LOGOUT_APPLIED]: "您的账号已经登出,点击确定刷新页面。"
968
+ };
969
+ var zh = locale$6;
970
+
971
+ /** @internal */
972
+ var initI18n = () => {
973
+ i18next.addResourceBundle("en", NS_BRICK_KIT, en);
974
+ i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
975
+ };
976
+
977
+ /** @internal */
978
+ function getI18nNamespace(type, id) {
979
+ return "$".concat(type, "-").concat(id);
803
980
  }
804
- function getNextStateOfUseBrick(state, isArray, key) {
805
- if (isLazyContentInUseBrick(state)) {
806
- return state;
981
+
982
+ function registerWidgetI18n(widgetId, i18n) {
983
+ var ns = getI18nNamespace("widget", widgetId);
984
+ Object.entries(i18n).forEach(_ref => {
985
+ var [lang, resources] = _ref;
986
+ i18next.addResourceBundle(lang, ns, resources);
987
+ });
988
+ }
989
+ function widgetI18nFactory(widgetId) {
990
+ return getFixedT(null, getI18nNamespace("widget", widgetId));
991
+ }
992
+
993
+ function i18nText(data) {
994
+ var _i18next$language;
995
+ if (!data) {
996
+ return;
807
997
  }
808
- if (isArray) {
809
- switch (state) {
810
- case StateOfUseBrick.USE_BRICK:
811
- return StateOfUseBrick.USE_BRICK_ITEM;
812
- case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS:
813
- return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM;
814
- case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES:
815
- return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM;
816
- }
817
- } else {
818
- switch (state) {
819
- case StateOfUseBrick.INITIAL:
820
- if (key === "useBrick") {
821
- return StateOfUseBrick.USE_BRICK;
822
- }
823
- break;
824
- case StateOfUseBrick.USE_BRICK:
825
- case StateOfUseBrick.USE_BRICK_ITEM:
826
- case StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS_ITEM:
827
- {
828
- switch (key) {
829
- case "properties":
830
- return StateOfUseBrick.USE_BRICK_PROPERTIES;
831
- case "transform":
832
- return StateOfUseBrick.USE_BRICK_TRANSFORM;
833
- case "events":
834
- return StateOfUseBrick.USE_BRICK_EVENTS;
835
- case "slots":
836
- return StateOfUseBrick.USE_BRICK_SLOTS;
837
- case "if":
838
- return StateOfUseBrick.USE_BRICK_IF;
839
- case "lifeCycle":
840
- return StateOfUseBrick.USE_BRICK_LIFECYCLE;
841
- }
842
- break;
843
- }
844
- case StateOfUseBrick.USE_BRICK_SLOTS:
845
- return StateOfUseBrick.USE_BRICK_SLOTS_ITEM;
846
- case StateOfUseBrick.USE_BRICK_SLOTS_ITEM:
847
- if (key === "bricks") {
848
- return StateOfUseBrick.USE_BRICK_SLOTS_ITEM_BRICKS;
849
- }
850
- break;
851
- case StateOfUseBrick.USE_BRICK_LIFECYCLE:
852
- if (key === "useResolves") {
853
- return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES;
854
- }
855
- break;
856
- case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM:
857
- {
858
- switch (key) {
859
- case "transform":
860
- return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_TRANSFORM;
861
- case "onReject":
862
- return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT;
863
- }
864
- break;
865
- }
866
- case StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT:
867
- if (key === "transform") {
868
- return StateOfUseBrick.USE_BRICK_LIFECYCLE_USERESOLVES_ITEM_ONREJECT_TRANSFORM;
869
- }
870
- break;
998
+ var language = (_i18next$language = i18next.language) !== null && _i18next$language !== void 0 ? _i18next$language : "zh-CN";
999
+ // First, make a perfect match.
1000
+ if (hasOwnProperty(data, language)) {
1001
+ return data[language];
1002
+ }
1003
+ // https://en.wikipedia.org/wiki/IETF_language_tag
1004
+ var primaryLanguage = language.split("-")[0];
1005
+ if (primaryLanguage !== language) {
1006
+ // Then, match the primary language (which omits other subtags).
1007
+ // E.g., match `zh` if the current language is `zh-CN`.
1008
+ return hasOwnProperty(data, primaryLanguage) ? data[primaryLanguage] : undefined;
1009
+ }
1010
+ // At last, match the first key which starts with the primary language,
1011
+ // if the current language contains primary subtag only.
1012
+ // E.g., match `zh-CN` if the current language is `zh`.
1013
+ var prefix = "".concat(primaryLanguage, "-");
1014
+ for (var key of Object.keys(data)) {
1015
+ if (key.startsWith(prefix)) {
1016
+ return data[key];
871
1017
  }
872
1018
  }
873
- return StateOfUseBrick.INITIAL;
874
1019
  }
875
1020
 
876
- function getTracks(value) {
877
- var contextNames = false;
878
- var stateNames = false;
879
- var formStateNames = false;
880
- if (typeof value === "string" ? isEvaluable(value) : isPreEvaluated(value)) {
881
- var raw = typeof value === "string" ? value : getPreEvaluatedRaw(value);
882
- if (isTrackAll(raw)) {
883
- var result = trackAll(raw);
884
- if (result) {
885
- contextNames = result.context;
886
- stateNames = result.state;
887
- formStateNames = result.formState;
888
- }
889
- } else {
890
- contextNames = trackContext(raw);
891
- stateNames = trackState(raw);
892
- formStateNames = trackFormState(raw);
893
- }
1021
+ // Themes.
1022
+ var DEFAULT_THEME = "light";
1023
+ var theme = DEFAULT_THEME;
1024
+ var storage = new JsonStorage(localStorage);
1025
+ var LOCAL_STORAGE_APPS_THEME_KEY = "apps-theme";
1026
+ function setTheme(value) {
1027
+ if (value !== "dark" && value !== "light" && value !== "dark-v2") {
1028
+ throw new Error("Unsupported theme: ".concat(value));
894
1029
  }
895
- return {
896
- contextNames,
897
- stateNames,
898
- formStateNames
899
- };
1030
+ theme = value;
900
1031
  }
901
-
902
- /** @internal */
903
- function transformElementProperties(element, data, to, from, mapArray) {
904
- var result = preprocessTransformProperties(data, to, from, mapArray);
905
- setRealProperties(element, result, true);
1032
+ function getTheme() {
1033
+ return theme;
906
1034
  }
907
-
908
- /** @internal */
909
- function transformProperties(props, data, to, from, mapArray, options) {
910
- var result = preprocessTransformProperties(data, to, from, mapArray, options);
911
- for (var [propName, propValue] of Object.entries(result)) {
912
- set(props, propName, propValue);
1035
+ function getCurrentTheme() {
1036
+ return document.documentElement.dataset.theme;
1037
+ }
1038
+ function applyTheme(value) {
1039
+ if (value) {
1040
+ setTheme(value);
1041
+ } else {
1042
+ value = getTheme();
913
1043
  }
914
- return props;
1044
+ if (value !== getCurrentTheme()) {
1045
+ document.documentElement.dataset.theme = value;
1046
+ window.dispatchEvent(new CustomEvent("theme.change", {
1047
+ detail: value
1048
+ }));
1049
+ }
1050
+ }
1051
+ function useCurrentTheme() {
1052
+ var [currentTheme, setCurrentTheme] = useState(getCurrentTheme());
1053
+ useEffect(() => {
1054
+ var listenToThemeChange = event => {
1055
+ setCurrentTheme(event.detail);
1056
+ };
1057
+ window.addEventListener("theme.change", listenToThemeChange);
1058
+ return () => {
1059
+ window.removeEventListener("theme.change", listenToThemeChange);
1060
+ };
1061
+ }, []);
1062
+ return currentTheme;
1063
+ }
1064
+ function batchSetAppsLocalTheme(appsTheme) {
1065
+ storage.setItem(LOCAL_STORAGE_APPS_THEME_KEY, _objectSpread(_objectSpread({}, getLocalAppsTheme()), appsTheme));
1066
+ }
1067
+ function getLocalAppsTheme() {
1068
+ var result;
1069
+ try {
1070
+ result = storage.getItem(LOCAL_STORAGE_APPS_THEME_KEY);
1071
+ } catch (_unused) {
1072
+ // eslint-disable-next-line no-console
1073
+ console.error("JSON parse error inside `getLocalAppsTheme()`");
1074
+ }
1075
+ return result || {};
915
1076
  }
916
1077
 
917
- /** @internal */
918
- function doTransform(data, to, options) {
919
- var preEvaluated = isPreEvaluated(to);
920
- if (preEvaluated || typeof to === "string") {
921
- // For `useBrick`, some fields such as `properties`/`transform`/`events`,
922
- // are kept and to be transformed later.
923
- var lazy = (options === null || options === void 0 ? void 0 : options.$$lazyForUseBrick) && isLazyContentInUseBrick(options.$$stateOfUseBrick);
924
- if (lazy) {
925
- // The current data context is not memoized, since a new data context
926
- // should always be provided before later transformations.
927
- return to;
928
- }
929
- var result;
930
- var dismissRecursiveMarkingInjected = false;
931
- if (preEvaluated || isEvaluable(to)) {
932
- var runtimeContext = {
933
- data
934
- };
935
- if (options !== null && options !== void 0 && options.tplContextId) runtimeContext.tplContextId = options.tplContextId;
936
- if (options !== null && options !== void 0 && options.formContextId) runtimeContext.formContextId = options.formContextId;
937
- result = evaluate(to, runtimeContext, options === null || options === void 0 ? void 0 : options.evaluateOptions);
938
- dismissRecursiveMarkingInjected = shouldDismissRecursiveMarkingInjected(to);
939
- } else {
940
- result = options !== null && options !== void 0 && options.allowInject ? transformAndInject(to, data, _internalApiGetCurrentContext()) : transform(to, data);
941
- }
942
- if (!dismissRecursiveMarkingInjected) {
943
- recursiveMarkAsInjected(result);
944
- }
945
- return result;
946
- }
947
- if (!isObject(to) || haveBeenInjected(to)) {
948
- return to;
949
- }
950
- if (Array.isArray(to)) {
951
- var nextOptions = getNextDoTransformOptions(options, true);
952
- return to.map(item => doTransform(data, item, nextOptions));
1078
+ // Modes.
1079
+ var DEFAULT_MODE = "default";
1080
+ var mode = DEFAULT_MODE;
1081
+ function setMode(value) {
1082
+ if (value !== "dashboard" && value !== "default") {
1083
+ throw new Error("Unsupported mode: ".concat(value));
953
1084
  }
954
- return Object.fromEntries(
955
- // Get both string and symbol keys.
956
- Object.entries(to).map(_ref => {
957
- var [k, v] = _ref;
958
- if (Array.isArray(options === null || options === void 0 ? void 0 : options.trackingContextList) && (typeof v === "string" ? isEvaluable(v) : isPreEvaluated(v))) {
959
- var raw;
960
- if (typeof v === "string") {
961
- raw = v;
962
- } else {
963
- raw = getPreEvaluatedRaw(v);
964
- addDataToPreEvaluated(v, data);
965
- }
966
- var {
967
- contextNames,
968
- stateNames,
969
- formStateNames
970
- } = getTracks(raw);
971
- if (contextNames || stateNames || formStateNames) {
972
- options.trackingContextList.push({
973
- contextNames,
974
- stateNames,
975
- formStateNames,
976
- propName: k,
977
- propValue: v
978
- });
979
- }
980
- }
981
- return [k, doTransform(data, v, getNextDoTransformOptions(options, false, k))];
982
- }).concat(Object.getOwnPropertySymbols(to).map(k => [k, to[k]])));
1085
+ mode = value;
983
1086
  }
984
-
985
- /** @internal */
986
- function reTransformForDevtools(transformationId, data, to, from, mapArray, allowInject) {
987
- try {
988
- preprocessTransformProperties(data, to, from, mapArray, {
989
- isReTransformation: true,
990
- transformationId,
991
- allowInject
992
- });
993
- } catch (error) {
994
- devtoolsHookEmit("re-transformation", {
995
- id: transformationId,
996
- error: error.message,
997
- detail: {
998
- transform: to,
999
- data,
1000
- options: {
1001
- from,
1002
- mapArray,
1003
- allowInject
1004
- }
1005
- }
1006
- });
1007
- }
1087
+ function getMode() {
1088
+ return mode;
1008
1089
  }
1009
-
1010
- /** @internal */
1011
- function preprocessTransformProperties(data, to, from, mapArray, options) {
1012
- var props = {};
1013
- var processedData = from ? get(data, from) : data;
1014
- if (Array.isArray(to)) {
1015
- for (var item of to) {
1016
- pipeableTransform(props, processedData, item.to, item.from, item.mapArray, {
1017
- allowInject: options === null || options === void 0 ? void 0 : options.allowInject
1018
- });
1019
- }
1020
- } else {
1021
- pipeableTransform(props, processedData, to, undefined, mapArray, {
1022
- allowInject: options === null || options === void 0 ? void 0 : options.allowInject
1023
- });
1024
- }
1025
- var detail = {
1026
- transform: to,
1027
- data,
1028
- options: {
1029
- from,
1030
- mapArray,
1031
- allowInject: options === null || options === void 0 ? void 0 : options.allowInject
1032
- },
1033
- result: props
1034
- };
1035
- if (options !== null && options !== void 0 && options.isReTransformation) {
1036
- devtoolsHookEmit("re-transformation", {
1037
- id: options.transformationId,
1038
- detail
1039
- });
1040
- } else {
1041
- devtoolsHookEmit("transformation", detail);
1042
- }
1043
- return props;
1090
+ function getCurrentMode() {
1091
+ return document.documentElement.dataset.mode;
1044
1092
  }
1045
- function pipeableTransform(props, data, to, from, mapArray, options) {
1046
- if (!to) {
1047
- // Do nothing if `to` is falsy.
1048
- return;
1049
- }
1050
- var fromData = from ? get(data, from) : data;
1051
- var isArray = Array.isArray(fromData);
1052
- if (!isArray && mapArray === true) {
1053
- isArray = true;
1054
- fromData = [fromData];
1055
- } else if (isArray && mapArray === false) {
1056
- isArray = false;
1057
- }
1058
- if (typeof to === "string") {
1059
- props[to] = fromData;
1060
- return;
1093
+ function applyMode(value) {
1094
+ if (value) {
1095
+ setMode(value);
1096
+ } else {
1097
+ value = getMode();
1061
1098
  }
1062
- var _loop = function (transformedPropName, transformTo) {
1063
- // If `fromData` is an array, mapping it's items.
1064
- props[transformedPropName] = isArray ? fromData.map(item => doTransform(item, transformTo, options)) : doTransform(fromData, transformTo, options);
1065
- };
1066
- for (var [transformedPropName, transformTo] of Object.entries(to)) {
1067
- _loop(transformedPropName, transformTo);
1099
+ if (value !== getCurrentMode()) {
1100
+ document.documentElement.dataset.mode = value;
1101
+ window.dispatchEvent(new CustomEvent("mode.change", {
1102
+ detail: value
1103
+ }));
1068
1104
  }
1069
1105
  }
1070
-
1071
- /** @internal */
1072
- function transformIntermediateData(data, to, from, mapArray) {
1073
- var intermediateData = from ? get(data, from) : data;
1074
- if (!to) {
1075
- return intermediateData;
1076
- }
1077
- return transformProperties({}, intermediateData, to, undefined, mapArray);
1106
+ function useCurrentMode() {
1107
+ var [currentMode, setCurrentMode] = useState(getCurrentMode());
1108
+ useEffect(() => {
1109
+ var listenToModeChange = event => {
1110
+ setCurrentMode(event.detail);
1111
+ };
1112
+ window.addEventListener("mode.change", listenToModeChange);
1113
+ return () => {
1114
+ window.removeEventListener("mode.change", listenToModeChange);
1115
+ };
1116
+ }, []);
1117
+ return currentMode;
1078
1118
  }
1079
- function getNextDoTransformOptions(options, isArray, key) {
1080
- var _options$$$stateOfUse;
1081
- return options ? _objectSpread(_objectSpread({}, options), {}, {
1082
- // Collect tracking context in first level only.
1083
- trackingContextList: undefined,
1084
- $$stateOfUseBrick: options.$$lazyForUseBrick ? getNextStateOfUseBrick((_options$$$stateOfUse = options.$$stateOfUseBrick) !== null && _options$$$stateOfUse !== void 0 ? _options$$$stateOfUse : StateOfUseBrick.INITIAL, isArray, key) : undefined
1085
- }) : options;
1119
+ function getCssPropertyValue(name) {
1120
+ var _window$getComputedSt;
1121
+ var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.documentElement;
1122
+ if (!el) return "";
1123
+ return ((_window$getComputedSt = window.getComputedStyle(el)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue(name)) || "";
1086
1124
  }
1087
1125
 
1088
- var MESSAGE_SOURCE_PANEL = "brick-next-devtools-panel";
1089
- var EVALUATION_EDIT = "devtools-evaluation-edit";
1090
- var TRANSFORMATION_EDIT = "devtools-transformation-edit";
1091
- var FRAME_ACTIVE_CHANGE = "devtools-frame-active-change";
1092
- var PANEL_CHANGE = "devtools-panel-change";
1093
- var frameIsActive = true;
1094
- var selectedPanel;
1126
+ /**
1127
+ * @description 获取菜单信息
1128
+ * @endpoint GET /api/v1/micro-app/menus/:menuId
1129
+ */
1130
+ var InstalledMicroAppApi_getMenusInfo = /*#__PURE__*/function () {
1131
+ var _ref = _asyncToGenerator$3(function* (menuId, params, options) {
1132
+ return (/**! @contract easyops.api.micro_app.installed_micro_app.GetMenusInfo@1.0.0 */(yield http.get("api/gateway/micro_app.installed_micro_app.GetMenusInfo/api/v1/micro-app/menus/".concat(menuId), _objectSpread(_objectSpread({}, options), {}, {
1133
+ params
1134
+ }))).data
1135
+ );
1136
+ });
1137
+ return function InstalledMicroAppApi_getMenusInfo(_x, _x2, _x3) {
1138
+ return _ref.apply(this, arguments);
1139
+ };
1140
+ }();
1095
1141
 
1096
- /* istanbul ignore next */
1097
- function devtoolsHookEmit(type, payload) {
1098
- var devtools = getDevHook();
1099
- if (!devtools || !(type === "evaluation" ? frameIsActive && (!selectedPanel || selectedPanel === "Evaluations") : type === "transformation" ? frameIsActive && (!selectedPanel || selectedPanel === "Transformations") : true)) {
1100
- // Ignore messages if current devtools panel is not relevant.
1101
- return;
1102
- }
1103
- var emit = () => {
1104
- var _devtools$emit;
1105
- (_devtools$emit = devtools.emit) === null || _devtools$emit === void 0 ? void 0 : _devtools$emit.call(devtools, {
1106
- type,
1107
- payload
1108
- });
1142
+ /** 微应用的i18n信息 */
1143
+
1144
+ /**
1145
+ * @description 获取微应用的i18n数据
1146
+ * @endpoint GET /api/v1/micro-app/i18n
1147
+ */
1148
+ var InstalledMicroAppApi_getI18NData = /*#__PURE__*/function () {
1149
+ var _ref = _asyncToGenerator$3(function* (params, options) {
1150
+ return (/**! @contract easyops.api.micro_app.installed_micro_app.GetI18NData@1.0.0 */(yield http.get("api/gateway/micro_app.installed_micro_app.GetI18NData/api/v1/micro-app/i18n", _objectSpread(_objectSpread({}, options), {}, {
1151
+ params
1152
+ }))).data
1153
+ );
1154
+ });
1155
+ return function InstalledMicroAppApi_getI18NData(_x, _x2) {
1156
+ return _ref.apply(this, arguments);
1109
1157
  };
1158
+ }();
1110
1159
 
1111
- // Try to emit only in idle time.
1112
- if (typeof window.requestIdleCallback === "function") {
1113
- window.requestIdleCallback(emit);
1114
- } else {
1115
- setTimeout(emit, 0);
1116
- }
1117
- }
1118
- function listenDevtoolsEagerly() {
1119
- window.addEventListener("message", _ref => {
1120
- var {
1121
- data
1122
- } = _ref;
1123
- if ((data === null || data === void 0 ? void 0 : data.source) !== MESSAGE_SOURCE_PANEL) {
1124
- return;
1125
- }
1126
- var payload = data.payload;
1127
- switch (payload === null || payload === void 0 ? void 0 : payload.type) {
1128
- case FRAME_ACTIVE_CHANGE:
1129
- {
1130
- frameIsActive = payload.active;
1131
- break;
1132
- }
1133
- case PANEL_CHANGE:
1134
- {
1135
- selectedPanel = payload.panel;
1136
- break;
1137
- }
1138
- }
1139
- });
1140
- }
1141
- function listenDevtools() {
1142
- window.addEventListener("message", _ref2 => {
1143
- var {
1144
- data
1145
- } = _ref2;
1146
- if ((data === null || data === void 0 ? void 0 : data.source) !== MESSAGE_SOURCE_PANEL) {
1147
- return;
1148
- }
1149
- var payload = data.payload;
1150
- switch (payload === null || payload === void 0 ? void 0 : payload.type) {
1151
- case EVALUATION_EDIT:
1152
- {
1153
- var {
1154
- raw,
1155
- context,
1156
- id
1157
- } = payload;
1158
- evaluate(raw, {
1159
- data: context.data,
1160
- event: restoreDehydrated(context.event)
1161
- }, {
1162
- isReEvaluation: true,
1163
- evaluationId: id
1164
- });
1165
- break;
1166
- }
1167
- case TRANSFORMATION_EDIT:
1168
- {
1169
- var {
1170
- data: _data,
1171
- transform,
1172
- id: _id,
1173
- options: {
1174
- from,
1175
- mapArray,
1176
- allowInject
1177
- }
1178
- } = payload;
1179
- reTransformForDevtools(_id, _data, transform, from, mapArray, allowInject);
1180
- break;
1181
- }
1182
- }
1160
+ /**
1161
+ * @description 校验系统权限
1162
+ * @endpoint POST /api/micro_app/v1/permission/validate
1163
+ */
1164
+ var PermissionApi_validatePermissions = /*#__PURE__*/function () {
1165
+ var _ref = _asyncToGenerator$3(function* (data, options) {
1166
+ return (/**! @contract easyops.api.micro_app.permission.ValidatePermissions@1.0.0 */(yield http.post("api/gateway/micro_app.permission.ValidatePermissions/api/micro_app/v1/permission/validate", data, options)).data
1167
+ );
1183
1168
  });
1184
- }
1185
- function getDevHook() {
1186
- return window.__BRICK_NEXT_DEVTOOLS_HOOK__;
1187
- }
1188
- function restoreDehydrated(value) {
1189
- var _getDevHook$restoreDe, _getDevHook;
1190
- return (_getDevHook$restoreDe = (_getDevHook = getDevHook()) === null || _getDevHook === void 0 ? void 0 : _getDevHook.restoreDehydrated(value)) !== null && _getDevHook$restoreDe !== void 0 ? _getDevHook$restoreDe : value;
1191
- }
1192
-
1193
- function getItemFactory(storageType) {
1194
- return function (name) {
1195
- var storage = storageType === "local" ? localStorage : sessionStorage;
1196
- return JSON.parse(storage.getItem(name));
1169
+ return function PermissionApi_validatePermissions(_x, _x2) {
1170
+ return _ref.apply(this, arguments);
1197
1171
  };
1198
- }
1199
-
1200
- var locale$7 = {
1201
- [K.REQUEST_FAILED]: "Request Failed",
1202
- [K.MODAL_OK]: "Ok",
1203
- [K.MODAL_CANCEL]: "Cancel",
1204
- [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
1205
- [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
1206
- [K.NETWORK_ERROR]: "Network error, please check your network.",
1207
- [K.PAGE_NOT_FOUND]: "Page not found, please check the URL",
1208
- [K.APP_NOT_FOUND]: "App not found, maybe the URL is wrong or you don't have permission to access",
1209
- [K.LICENSE_EXPIRED]: "The license authorization has expired, please contact the platform administrator",
1210
- [K.NO_PERMISSION]: "Unauthorized access, unable to retrieve the required resources for this page",
1211
- [K.OTHER_ERROR]: "Oops! Something went wrong",
1212
- [K.GO_BACK_PREVIOUS_PAGE]: "Go back to previous page",
1213
- [K.GO_BACK_HOME_PAGE]: "Back to home page",
1214
- [K.LOGIN_CHANGED]: "You have logged in as another account, click OK to refresh the page.",
1215
- [K.LOGOUT_APPLIED]: "Your account has been logged out, click OK to refresh the page."
1216
- };
1217
- var en = locale$7;
1218
-
1219
- var locale$6 = {
1220
- [K.REQUEST_FAILED]: "请求失败",
1221
- [K.MODAL_OK]: "确认",
1222
- [K.MODAL_CANCEL]: "取消",
1223
- [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
1224
- [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
1225
- [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。",
1226
- [K.PAGE_NOT_FOUND]: "请求的页面未找到,请确认 URL 是否正确",
1227
- [K.APP_NOT_FOUND]: "请求的微应用无法找到, 可能是 URL 错误或者无权限访问",
1228
- [K.LICENSE_EXPIRED]: "License 授权失效,请联系平台管理员",
1229
- [K.NO_PERMISSION]: "没有权限,无法获取页面所需要的资源",
1230
- [K.OTHER_ERROR]: "糟糕!页面出现了一些问题",
1231
- [K.GO_BACK_PREVIOUS_PAGE]: "回到上一页",
1232
- [K.GO_BACK_HOME_PAGE]: "回到首页",
1233
- [K.LOGIN_CHANGED]: "您已经登录另一个账号,点击确定刷新页面。",
1234
- [K.LOGOUT_APPLIED]: "您的账号已经登出,点击确定刷新页面。"
1235
- };
1236
- var zh = locale$6;
1237
-
1238
- /** @internal */
1239
- var initI18n = () => {
1240
- i18next.addResourceBundle("en", NS_BRICK_KIT, en);
1241
- i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
1242
- };
1243
-
1244
- /** @internal */
1245
- function getI18nNamespace(type, id) {
1246
- return "$".concat(type, "-").concat(id);
1247
- }
1248
-
1249
- function registerWidgetI18n(widgetId, i18n) {
1250
- var ns = getI18nNamespace("widget", widgetId);
1251
- Object.entries(i18n).forEach(_ref => {
1252
- var [lang, resources] = _ref;
1253
- i18next.addResourceBundle(lang, ns, resources);
1254
- });
1255
- }
1256
- function widgetI18nFactory(widgetId) {
1257
- return getFixedT(null, getI18nNamespace("widget", widgetId));
1258
- }
1259
-
1260
- function i18nText(data) {
1261
- var _i18next$language;
1262
- if (!data) {
1263
- return;
1264
- }
1265
- var language = (_i18next$language = i18next.language) !== null && _i18next$language !== void 0 ? _i18next$language : "zh-CN";
1266
- // First, make a perfect match.
1267
- if (hasOwnProperty(data, language)) {
1268
- return data[language];
1269
- }
1270
- // https://en.wikipedia.org/wiki/IETF_language_tag
1271
- var primaryLanguage = language.split("-")[0];
1272
- if (primaryLanguage !== language) {
1273
- // Then, match the primary language (which omits other subtags).
1274
- // E.g., match `zh` if the current language is `zh-CN`.
1275
- return hasOwnProperty(data, primaryLanguage) ? data[primaryLanguage] : undefined;
1276
- }
1277
- // At last, match the first key which starts with the primary language,
1278
- // if the current language contains primary subtag only.
1279
- // E.g., match `zh-CN` if the current language is `zh`.
1280
- var prefix = "".concat(primaryLanguage, "-");
1281
- for (var key of Object.keys(data)) {
1282
- if (key.startsWith(prefix)) {
1283
- return data[key];
1284
- }
1285
- }
1286
- }
1172
+ }();
1287
1173
 
1288
1174
  var auth = {};
1289
1175
 
@@ -1298,6 +1184,7 @@ function authenticate(newAuth) {
1298
1184
  isAdmin: newAuth.isAdmin,
1299
1185
  csrfToken: newAuth.csrfToken,
1300
1186
  license: newAuth.license,
1187
+ accessToken: newAuth.accessToken,
1301
1188
  userShowValue: newAuth.userShowValue
1302
1189
  });
1303
1190
 
@@ -2347,1122 +2234,1236 @@ function getCustomContextTriggerListByLifecycle(lifecycle) {
2347
2234
  return [...tplContextMap.values()].map(tplContext => tplContext.state.getContextTriggerSetByLifecycle(lifecycle)).filter(trigger => trigger.length > 0).flat(1);
2348
2235
  }
2349
2236
 
2350
- var MediaBreakpoint;
2351
- (function (MediaBreakpoint) {
2352
- MediaBreakpoint["xLarge"] = "xLarge";
2353
- MediaBreakpoint["large"] = "large";
2354
- MediaBreakpoint["medium"] = "medium";
2355
- MediaBreakpoint["small"] = "small";
2356
- MediaBreakpoint["xSmall"] = "xSmall";
2357
- })(MediaBreakpoint || (MediaBreakpoint = {}));
2358
- var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2359
- var mediaEventTarget = new EventTarget$1();
2360
- var breakpointMatchesMap = {};
2361
- var MEDIA = {};
2362
- function handleMatchesChange(data, breakpoint) {
2363
- var changed = false;
2364
- breakpointMatchesMap[breakpoint] = data.matches;
2365
- for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2366
- if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2367
- MEDIA.breakpoint = _breakpoint;
2368
- changed = true;
2369
- break;
2370
- }
2237
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
2238
+ try {
2239
+ var info = gen[key](arg);
2240
+ var value = info.value;
2241
+ } catch (error) {
2242
+ reject(error);
2243
+ return;
2371
2244
  }
2372
- if (changed) {
2373
- mediaEventTarget.dispatchEvent(new CustomEvent("change", {
2374
- detail: MEDIA
2375
- }));
2245
+ if (info.done) {
2246
+ resolve(value);
2247
+ } else {
2248
+ Promise.resolve(value).then(_next, _throw);
2376
2249
  }
2377
2250
  }
2378
- mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2379
- var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2380
- handleMatchesChange(mediaQueryList, breakpoint);
2381
- if (mediaQueryList.addEventListener) {
2382
- mediaQueryList.addEventListener("change", event => {
2383
- handleMatchesChange(event, breakpoint);
2251
+ function _asyncToGenerator$2(fn) {
2252
+ return function () {
2253
+ var self = this,
2254
+ args = arguments;
2255
+ return new Promise(function (resolve, reject) {
2256
+ var gen = fn.apply(self, args);
2257
+ function _next(value) {
2258
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
2259
+ }
2260
+ function _throw(err) {
2261
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
2262
+ }
2263
+ _next(undefined);
2264
+ });
2265
+ };
2266
+ }
2267
+ function _defineProperty(obj, key, value) {
2268
+ if (key in obj) {
2269
+ Object.defineProperty(obj, key, {
2270
+ value: value,
2271
+ enumerable: true,
2272
+ configurable: true,
2273
+ writable: true
2384
2274
  });
2385
2275
  } else {
2386
- mediaQueryList.addListener(event => {
2387
- handleMatchesChange(event, breakpoint);
2276
+ obj[key] = value;
2277
+ }
2278
+ return obj;
2279
+ }
2280
+ function ownKeys(object, enumerableOnly) {
2281
+ var keys = Object.keys(object);
2282
+ if (Object.getOwnPropertySymbols) {
2283
+ var symbols = Object.getOwnPropertySymbols(object);
2284
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
2285
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2388
2286
  });
2287
+ keys.push.apply(keys, symbols);
2389
2288
  }
2390
- });
2391
- var getMedia = () => MEDIA;
2392
-
2393
- var FormContextMap = new Map();
2394
- class CustomFormContext {
2395
- constructor(renderId) {
2396
- _defineProperty$1(this, "formState", void 0);
2397
- _defineProperty$1(this, "id", uniqueId("form-ctx-"));
2398
- FormContextMap.set(this.id, this);
2399
- this.formState = new StoryboardContextWrapper(undefined, this.id, renderId);
2400
- }
2289
+ return keys;
2401
2290
  }
2402
- function getCustomFormContext(formContextId) {
2403
- return FormContextMap.get(formContextId);
2291
+ function _objectSpread2(target) {
2292
+ for (var i = 1; i < arguments.length; i++) {
2293
+ var source = arguments[i] != null ? arguments[i] : {};
2294
+ if (i % 2) {
2295
+ ownKeys(Object(source), true).forEach(function (key) {
2296
+ _defineProperty(target, key, source[key]);
2297
+ });
2298
+ } else if (Object.getOwnPropertyDescriptors) {
2299
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
2300
+ } else {
2301
+ ownKeys(Object(source)).forEach(function (key) {
2302
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2303
+ });
2304
+ }
2305
+ }
2306
+ return target;
2404
2307
  }
2405
2308
 
2406
- var symbolForRaw = Symbol.for("pre.evaluated.raw");
2407
- var symbolForContext = Symbol.for("pre.evaluated.context");
2408
- function isPreEvaluated(raw) {
2409
- return !!(raw !== null && raw !== void 0 && raw[symbolForRaw]);
2309
+ /**
2310
+ * @description 获取实例详情
2311
+ * @endpoint GET /object/:objectId/instance/:instanceId
2312
+ */
2313
+ var InstanceApi_getDetail = /*#__PURE__*/function () {
2314
+ var _ref = _asyncToGenerator$2(function* (objectId, instanceId, params, options) {
2315
+ return (/**! @contract easyops.api.cmdb.instance.GetDetail */
2316
+ (yield http.get("api/gateway/cmdb.instance.GetDetail/object/".concat(objectId, "/instance/").concat(instanceId), _objectSpread2(_objectSpread2({}, options), {}, {
2317
+ params
2318
+ }))).data
2319
+ );
2320
+ });
2321
+ return function InstanceApi_getDetail(_x, _x2, _x3, _x4) {
2322
+ return _ref.apply(this, arguments);
2323
+ };
2324
+ }();
2325
+
2326
+ /**
2327
+ * @description 搜索实例
2328
+ * @endpoint POST /object/:objectId/instance/_search
2329
+ */
2330
+ var InstanceApi_postSearch = /*#__PURE__*/function () {
2331
+ var _ref = _asyncToGenerator$2(function* (objectId, data, options) {
2332
+ return (/**! @contract easyops.api.cmdb.instance.PostSearch */
2333
+ (yield http.post("api/gateway/cmdb.instance.PostSearch/object/".concat(objectId, "/instance/_search"), data, options)).data
2334
+ );
2335
+ });
2336
+ return function InstanceApi_postSearch(_x, _x2, _x3) {
2337
+ return _ref.apply(this, arguments);
2338
+ };
2339
+ }();
2340
+
2341
+ var _excluded$8 = ["children"],
2342
+ _excluded2$2 = ["children"],
2343
+ _excluded3 = ["items", "app"];
2344
+ var symbolAppId = Symbol("appId");
2345
+ var symbolMenuI18nNamespace = Symbol("menuI18nNamespace");
2346
+ var symbolOverrideApp = Symbol("overrideApp");
2347
+ var symbolShouldCache = Symbol("shouldCache");
2348
+ // Caching menu requests to avoid flicker.
2349
+ var menuCache = new Map();
2350
+ var menuTitleCache = new Map();
2351
+ var processMenuCache = new Map();
2352
+ function constructMenu(_x, _x2, _x3) {
2353
+ return _constructMenu.apply(this, arguments);
2410
2354
  }
2411
- function getPreEvaluatedRaw(pre) {
2412
- return pre[symbolForRaw];
2355
+ function _constructMenu() {
2356
+ _constructMenu = _asyncToGenerator$3(function* (menuBar, context, kernel) {
2357
+ var hasSubMenu = !!menuBar.subMenuId;
2358
+ yield Promise.all([_asyncToGenerator$3(function* () {
2359
+ if (menuBar.menuId) {
2360
+ var _menuBar$menu;
2361
+ var defaultCollapsed = (_menuBar$menu = menuBar.menu) === null || _menuBar$menu === void 0 ? void 0 : _menuBar$menu.defaultCollapsed;
2362
+ var menu = yield processMenu(menuBar.menuId, context, kernel, hasSubMenu);
2363
+ if (!isNil(defaultCollapsed)) {
2364
+ menu.defaultCollapsed = defaultCollapsed;
2365
+ }
2366
+ menuBar.menu = menu;
2367
+ }
2368
+ })(), _asyncToGenerator$3(function* () {
2369
+ if (hasSubMenu) {
2370
+ menuBar.subMenu = yield processMenu(menuBar.subMenuId, context, kernel);
2371
+ } else {
2372
+ menuBar.subMenu = null;
2373
+ }
2374
+ })()]);
2375
+ });
2376
+ return _constructMenu.apply(this, arguments);
2413
2377
  }
2414
- function addDataToPreEvaluated(pre, data) {
2415
- pre[symbolForContext].data = data;
2378
+ function preConstructMenus(_x4, _x5, _x6) {
2379
+ return _preConstructMenus.apply(this, arguments);
2416
2380
  }
2417
- function shouldDismissRecursiveMarkingInjected(raw) {
2418
- if (typeof raw === "string") {
2419
- return shouldAllowRecursiveEvaluations(raw);
2420
- }
2421
- return shouldAllowRecursiveEvaluations(raw[symbolForRaw]);
2381
+ function _preConstructMenus() {
2382
+ _preConstructMenus = _asyncToGenerator$3(function* (menus, context, kernel) {
2383
+ var data = yield Promise.all(menus.map(menuId => processMenu(menuId, context, kernel, undefined, true)));
2384
+ data.forEach((item, index) => processMenuCache.set(menus[index], item));
2385
+ });
2386
+ return _preConstructMenus.apply(this, arguments);
2422
2387
  }
2423
- var possibleErrorConstructs = new WeakSet([SyntaxError, TypeError, ReferenceError]);
2424
- function getCookErrorConstructor(error) {
2425
- return possibleErrorConstructs.has(error.constructor) ? error.constructor : TypeError;
2388
+ var getMenu = menuId => processMenuCache.get(menuId);
2389
+ function fetchMenuById(_x7, _x8, _x9) {
2390
+ return _fetchMenuById.apply(this, arguments);
2426
2391
  }
2427
-
2428
- // `raw` should always be asserted to `isEvaluable` or `isPreEvaluated`.
2429
- function evaluate(raw) {
2430
- var _runtimeContext$overr;
2431
- var runtimeContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2432
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2433
- if (options.isReEvaluation && !(typeof raw === "string" && isEvaluable(raw))) {
2434
- devtoolsHookEmit("re-evaluation", {
2435
- id: options.evaluationId,
2436
- detail: {
2437
- raw,
2438
- context: {}
2439
- },
2440
- error: "Invalid evaluation code"
2441
- });
2442
- return;
2443
- }
2444
- if (typeof raw !== "string") {
2445
- // If the `raw` is not a string, it must be a pre-evaluated object.
2446
- // Then fulfil the context, and restore the original `raw`.
2447
- runtimeContext = _objectSpread(_objectSpread({}, raw[symbolForContext]), runtimeContext);
2448
- raw = raw[symbolForRaw];
2449
- }
2450
-
2451
- // A `SyntaxError` maybe thrown.
2452
- var precooked;
2453
- try {
2454
- precooked = preevaluate(raw);
2455
- } catch (error) {
2456
- var message = "".concat(error.message, ", in \"").concat(raw, "\"");
2457
- if (options.isReEvaluation) {
2458
- devtoolsHookEmit("re-evaluation", {
2459
- id: options.evaluationId,
2460
- detail: {
2461
- raw,
2462
- context: {}
2463
- },
2464
- error: message
2465
- });
2466
- return;
2467
- } else {
2468
- var errorConstructor = getCookErrorConstructor(error);
2469
- throw new errorConstructor(message);
2470
- }
2471
- }
2472
- var globalVariables = {};
2473
- var attemptToVisitGlobals = precooked.attemptToVisitGlobals;
2474
- var attemptToVisitEvent = attemptToVisitGlobals.has("EVENT");
2475
- var attemptToVisitData = attemptToVisitGlobals.has("DATA");
2476
- var attemptToVisitTpl = attemptToVisitGlobals.has("TPL");
2477
- var attemptToVisitState = attemptToVisitGlobals.has("STATE");
2478
- var attemptToVisitFormState = attemptToVisitGlobals.has("FORM_STATE");
2479
- var attemptToVisitTplOrState = attemptToVisitTpl || attemptToVisitState;
2480
-
2481
- // Ignore evaluating if `event` is missing in context.
2482
- // Since it should be evaluated during events handling.
2483
- var missingEvent = options.lazy === true;
2484
- if (attemptToVisitEvent) {
2485
- if (hasOwnProperty(runtimeContext, "event")) {
2486
- globalVariables.EVENT = runtimeContext.event;
2487
- } else {
2488
- // Let's see if pre-evaluation is required (store the `data` in context).
2489
- missingEvent = true;
2490
- }
2491
- }
2492
- var missingTplOrState = attemptToVisitTplOrState && !hasOwnProperty(runtimeContext, "tplContextId");
2493
- var missingData = attemptToVisitData && !hasOwnProperty(runtimeContext, "data");
2494
- var rawWithContext = Object.keys(runtimeContext).length > 0 ? {
2495
- [symbolForRaw]: raw,
2496
- [symbolForContext]: runtimeContext
2497
- } : raw;
2498
-
2499
- // Since `EVENT`, `DATA`, `TPL` and `STATE` are provided in different context,
2500
- // whenever missing one of them, memorize the current context for later consuming.
2501
- if (missingEvent || missingData || missingTplOrState) {
2502
- return rawWithContext;
2503
- }
2504
- if (attemptToVisitData) {
2505
- globalVariables.DATA = runtimeContext.data;
2506
- }
2507
- if (attemptToVisitTplOrState && runtimeContext.tplContextId) {
2508
- var tplContext = getCustomTemplateContext(runtimeContext.tplContextId);
2509
- if (attemptToVisitTpl) {
2510
- globalVariables.TPL = tplContext.getVariables();
2392
+ function _fetchMenuById() {
2393
+ _fetchMenuById = _asyncToGenerator$3(function* (menuId, kernel, isPreFetch) {
2394
+ if (menuCache.has(menuId)) {
2395
+ return menuCache.get(menuId);
2511
2396
  }
2512
- if (attemptToVisitState) {
2513
- globalVariables.STATE = getDynamicReadOnlyProxy({
2514
- get(target, key) {
2515
- return tplContext.state.getValue(key);
2397
+ var menuList = window.STANDALONE_MICRO_APPS ? yield kernel.getStandaloneMenus(menuId, isPreFetch) : kernel.getFeatureFlags()["three-level-menu-layout"] ? (yield InstalledMicroAppApi_getMenusInfo(menuId, {
2398
+ menuObjectId: "EASYOPS_STORYBOARD_MENU"
2399
+ })).menus : (yield InstanceApi_postSearch("EASYOPS_STORYBOARD_MENU", {
2400
+ page: 1,
2401
+ page_size: 200,
2402
+ fields: {
2403
+ menuId: true,
2404
+ title: true,
2405
+ icon: true,
2406
+ link: true,
2407
+ titleDataSource: true,
2408
+ defaultCollapsed: true,
2409
+ defaultCollapsedBreakpoint: true,
2410
+ type: true,
2411
+ injectMenuGroupId: true,
2412
+ dynamicItems: true,
2413
+ itemsResolve: true,
2414
+ items: true,
2415
+ i18n: true,
2416
+ "items.children": true,
2417
+ "app.appId": true
2418
+ },
2419
+ query: {
2420
+ menuId: {
2421
+ $eq: menuId
2516
2422
  },
2517
- ownKeys() {
2518
- return Array.from(tplContext.state.get().keys());
2423
+ app: {
2424
+ $size: {
2425
+ $gt: 0
2426
+ }
2519
2427
  }
2520
- });
2428
+ }
2429
+ })).list;
2430
+ var menuData = yield mergeMenu(menuList, kernel);
2431
+ if (!menuData) {
2432
+ throw new Error("Menu not found: ".concat(menuId));
2521
2433
  }
2522
- }
2523
- if (attemptToVisitFormState && runtimeContext.formContextId) {
2524
- var formContext = getCustomFormContext(runtimeContext.formContextId);
2525
- globalVariables.FORM_STATE = getDynamicReadOnlyProxy({
2526
- get(target, key) {
2527
- return formContext.formState.getValue(key);
2528
- },
2529
- ownKeys() {
2530
- return Array.from(formContext.formState.get().keys());
2434
+ reorderMenu(menuData);
2435
+ menuData[symbolShouldCache] && menuCache.set(menuId, menuData);
2436
+ return menuData;
2437
+ });
2438
+ return _fetchMenuById.apply(this, arguments);
2439
+ }
2440
+ function mergeMenu(_x10, _x11) {
2441
+ return _mergeMenu.apply(this, arguments);
2442
+ }
2443
+ function _mergeMenu() {
2444
+ _mergeMenu = _asyncToGenerator$3(function* (menuList, kernel) {
2445
+ var mainMenu = menuList.find(menu => menu.type !== "inject");
2446
+ if (!mainMenu) {
2447
+ return undefined;
2448
+ }
2449
+ var validMenuList = [];
2450
+ var injectWithMenus = new Map();
2451
+ var menuWithI18n = new WeakMap();
2452
+ for (var menu of menuList) {
2453
+ if (menu.i18n) {
2454
+ (function () {
2455
+ var menuI18nNamespace = getI18nNamespace("menu", "".concat(menu.menuId, "~").concat(menu.app[0].appId, "+").concat(menu.instanceId));
2456
+ // Support any language in `meta.i18n`.
2457
+ Object.entries(menu.i18n).forEach(_ref6 => {
2458
+ var [lang, resources] = _ref6;
2459
+ i18next.addResourceBundle(lang, menuI18nNamespace, resources);
2460
+ });
2461
+ menuWithI18n.set(menu, menuI18nNamespace);
2462
+ })();
2463
+ }
2464
+ }
2465
+ var shouldCacheList = yield Promise.all(menuList.map(menu => loadDynamicMenuItems(menu, kernel, menuWithI18n)));
2466
+ for (var _menu of menuList) {
2467
+ var _menu$items;
2468
+ if (((_menu$items = _menu.items) === null || _menu$items === void 0 ? void 0 : _menu$items.length) > 0) {
2469
+ if (_menu.type === "inject" && _menu.injectMenuGroupId) {
2470
+ var injectingMenus = injectWithMenus.get(_menu.injectMenuGroupId);
2471
+ if (!injectingMenus) {
2472
+ injectingMenus = [];
2473
+ injectWithMenus.set(_menu.injectMenuGroupId, injectingMenus);
2474
+ }
2475
+ injectingMenus.push(_menu);
2476
+ } else {
2477
+ validMenuList.push(_menu);
2478
+ }
2479
+ }
2480
+ }
2481
+ return _objectSpread(_objectSpread({}, mainMenu), {}, {
2482
+ items: validMenuList.flatMap(menu => processGroupInject(menu.items, menu, injectWithMenus, menuWithI18n)),
2483
+ [symbolShouldCache]: shouldCacheList.every(Boolean),
2484
+ [symbolMenuI18nNamespace]: menuWithI18n.get(mainMenu),
2485
+ [symbolOverrideApp]: mainMenu.overrideApp
2486
+ });
2487
+ });
2488
+ return _mergeMenu.apply(this, arguments);
2489
+ }
2490
+ function processGroupInject(items, menu, injectWithMenus, menuWithI18n) {
2491
+ return items === null || items === void 0 ? void 0 : items.map(item => {
2492
+ var _processGroupInject;
2493
+ var foundInjectingMenus = item.groupId && injectWithMenus.get(item.groupId);
2494
+ if (foundInjectingMenus) {
2495
+ // Each menu to be injected with should be injected only once.
2496
+ injectWithMenus.delete(item.groupId);
2497
+ }
2498
+ return _objectSpread(_objectSpread({}, item), {}, {
2499
+ children: ((_processGroupInject = processGroupInject(item.children || item.items, menu, injectWithMenus, menuWithI18n)) !== null && _processGroupInject !== void 0 ? _processGroupInject : []).concat(foundInjectingMenus ? foundInjectingMenus.flatMap(injectingMenu => processGroupInject(injectingMenu.items, injectingMenu, injectWithMenus, menuWithI18n)) : []),
2500
+ [symbolAppId]: menu.app[0].appId,
2501
+ [symbolMenuI18nNamespace]: menuWithI18n.get(menu),
2502
+ [symbolOverrideApp]: menu.overrideApp
2503
+ });
2504
+ });
2505
+ }
2506
+ function loadDynamicMenuItems(_x12, _x13, _x14) {
2507
+ return _loadDynamicMenuItems.apply(this, arguments);
2508
+ }
2509
+ function _loadDynamicMenuItems() {
2510
+ _loadDynamicMenuItems = _asyncToGenerator$3(function* (menu, kernel, menuWithI18n) {
2511
+ if (menu.dynamicItems && menu.itemsResolve) {
2512
+ var _menu$itemsResolve;
2513
+ var itemsConf = {};
2514
+ var overrideAppId = menu.app[0].appId;
2515
+ var context = _internalApiGetCurrentContext();
2516
+ var newContext = context;
2517
+ if (overrideAppId !== context.app.id && attemptToVisit(menu.itemsResolve, ["APP", "I18N"])) {
2518
+ if (window.STANDALONE_MICRO_APPS) {
2519
+ if (menu.overrideApp) {
2520
+ menu.overrideApp.config = deepFreeze(merge({}, menu.overrideApp.defaultConfig, menu.overrideApp.userConfig));
2521
+ }
2522
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
2523
+ overrideApp: menu.overrideApp,
2524
+ appendI18nNamespace: menuWithI18n.get(menu)
2525
+ });
2526
+ } else {
2527
+ var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
2528
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
2529
+ overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
2530
+ appendI18nNamespace: menuWithI18n.get(menu)
2531
+ });
2532
+ }
2533
+ }
2534
+ var usedActions = scanPermissionActionsInAny(menu.itemsResolve);
2535
+ yield validatePermissions(usedActions);
2536
+ yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
2537
+ transform: "items",
2538
+ transformMapArray: false
2539
+ }, menu.itemsResolve), itemsConf, null, newContext);
2540
+ menu.items = itemsConf.items;
2541
+ if ((_menu$itemsResolve = menu.itemsResolve) !== null && _menu$itemsResolve !== void 0 && _menu$itemsResolve.args) {
2542
+ var _menu$itemsResolve2;
2543
+ return !attemptToVisit((_menu$itemsResolve2 = menu.itemsResolve) === null || _menu$itemsResolve2 === void 0 ? void 0 : _menu$itemsResolve2.args, ["QUERY", "PATH"]);
2544
+ }
2545
+ }
2546
+ return true;
2547
+ });
2548
+ return _loadDynamicMenuItems.apply(this, arguments);
2549
+ }
2550
+ function walkMenuItems(menuItems) {
2551
+ return menuItems === null || menuItems === void 0 ? void 0 : menuItems.filter(
2552
+ // `if` is already evaluated.
2553
+ looseCheckIfOfComputed).map(item => {
2554
+ var children = walkMenuItems(item.children || item.items);
2555
+ return item.type === "group" ? {
2556
+ type: "group",
2557
+ childLayout: item.childLayout,
2558
+ title: item.text || item.title,
2559
+ items: children,
2560
+ groupId: item.groupId,
2561
+ groupFrom: item.groupFrom
2562
+ } : children !== null && children !== void 0 && children.length ? {
2563
+ type: "subMenu",
2564
+ childLayout: item.childLayout,
2565
+ title: item.text || item.title,
2566
+ icon: item.icon,
2567
+ items: children,
2568
+ defaultExpanded: item.defaultExpanded
2569
+ } : item;
2570
+ });
2571
+ }
2572
+ function processMenu(_x15, _x16, _x17, _x18, _x19) {
2573
+ return _processMenu.apply(this, arguments);
2574
+ }
2575
+ function _processMenu() {
2576
+ _processMenu = _asyncToGenerator$3(function* (menuId, context, kernel, hasSubMenu, isPreFetch) {
2577
+ var _yield$fetchMenuById = yield fetchMenuById(menuId, kernel, isPreFetch),
2578
+ {
2579
+ items,
2580
+ app
2581
+ } = _yield$fetchMenuById,
2582
+ restMenuData = _objectWithoutProperties(_yield$fetchMenuById, _excluded3);
2583
+ var usedActions = scanPermissionActionsInAny([items, restMenuData]);
2584
+ yield validatePermissions(usedActions);
2585
+ var appsRequireI18nFulfilled = new Set();
2586
+ var rootAppId = app[0].appId;
2587
+ if (rootAppId !== context.app.id && !restMenuData[symbolMenuI18nNamespace]) {
2588
+ appsRequireI18nFulfilled.add(rootAppId);
2589
+ }
2590
+ collectAppsRequireI18nFulfilled(items, context.app.id, appsRequireI18nFulfilled);
2591
+ yield kernel.fulfilStoryboardI18n([...appsRequireI18nFulfilled]);
2592
+ var menuData = _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(restMenuData, rootAppId, context, kernel)), {}, {
2593
+ items: yield computeMenuItemsWithOverrideApp(items, context, kernel)
2594
+ });
2595
+ return {
2596
+ title: yield processMenuTitle(menuData),
2597
+ icon: menuData.icon,
2598
+ link: menuData.link,
2599
+ menuItems: walkMenuItems(menuData.items),
2600
+ defaultCollapsed: menuData.defaultCollapsed || hasSubMenu,
2601
+ defaultCollapsedBreakpoint: menuData.defaultCollapsedBreakpoint
2602
+ };
2603
+ });
2604
+ return _processMenu.apply(this, arguments);
2605
+ }
2606
+ function collectAppsRequireI18nFulfilled(items, contextAppId, appIds) {
2607
+ function collect(items) {
2608
+ for (var _ref of items) {
2609
+ var {
2610
+ children
2611
+ } = _ref,
2612
+ rest = _objectWithoutProperties(_ref, _excluded$8);
2613
+ var overrideAppId = rest[symbolAppId];
2614
+ if (!rest[symbolMenuI18nNamespace] && overrideAppId !== contextAppId && !appIds.has(overrideAppId) && attemptToVisit(rest, ["I18N"])) {
2615
+ appIds.add(overrideAppId);
2616
+ }
2617
+ children && collect(children);
2618
+ }
2619
+ }
2620
+ collect(items);
2621
+ }
2622
+ function computeMenuItemsWithOverrideApp(items, context, kernel) {
2623
+ return Promise.all(items.map( /*#__PURE__*/function () {
2624
+ var _ref3 = _asyncToGenerator$3(function* (_ref2) {
2625
+ var {
2626
+ children
2627
+ } = _ref2,
2628
+ rest = _objectWithoutProperties(_ref2, _excluded2$2);
2629
+ return _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
2630
+ children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
2631
+ });
2632
+ });
2633
+ return function (_x20) {
2634
+ return _ref3.apply(this, arguments);
2635
+ };
2636
+ }()));
2637
+ }
2638
+ function processMenuTitle(_x21) {
2639
+ return _processMenuTitle.apply(this, arguments);
2640
+ }
2641
+ function _processMenuTitle() {
2642
+ _processMenuTitle = _asyncToGenerator$3(function* (menuData) {
2643
+ if (menuData.title || isEmpty(menuData.titleDataSource)) {
2644
+ return menuData.title;
2645
+ }
2646
+ var cacheKey = JSON.stringify(menuData.titleDataSource);
2647
+ if (menuTitleCache.has(cacheKey)) {
2648
+ return menuTitleCache.get(cacheKey);
2649
+ }
2650
+ var {
2651
+ objectId,
2652
+ instanceId,
2653
+ attributeId
2654
+ } = menuData.titleDataSource;
2655
+ var attr = attributeId !== null && attributeId !== void 0 ? attributeId : "name";
2656
+ var instanceData = yield InstanceApi_getDetail(objectId, instanceId, {
2657
+ fields: attr
2658
+ });
2659
+ var title;
2660
+ if (attributeId === "#showKey" && Array.isArray(instanceData[attr])) {
2661
+ var [primary, ...rest] = instanceData[attr];
2662
+ title = rest.length > 0 ? "".concat(primary, "(").concat(rest.join(","), ")") : String(primary);
2663
+ } else {
2664
+ title = String(instanceData[attr]);
2665
+ }
2666
+ menuTitleCache.set(cacheKey, title);
2667
+ return title;
2668
+ });
2669
+ return _processMenuTitle.apply(this, arguments);
2670
+ }
2671
+ function clearMenuTitleCache() {
2672
+ menuTitleCache.clear();
2673
+ }
2674
+ function clearMenuCache() {
2675
+ menuCache.clear();
2676
+ }
2677
+ function reorderMenu(menuData) {
2678
+ menuData.items = reorderMenuItems(menuData.items);
2679
+ }
2680
+ function reorderMenuItems(list) {
2681
+ return sortMenuItems(list).map(item => _objectSpread(_objectSpread({}, item), {}, {
2682
+ children: reorderMenuItems(item.children)
2683
+ }));
2684
+ }
2685
+ function sortMenuItems(list) {
2686
+ return sortBy(list, item => {
2687
+ var _item$sort;
2688
+ return (_item$sort = item.sort) !== null && _item$sort !== void 0 ? _item$sort : -Infinity;
2689
+ });
2690
+ }
2691
+
2692
+ /**
2693
+ * If the menu contains evaluations which use `APP` or `I18N`,
2694
+ * we have to override app in context when computing real values.
2695
+ */
2696
+ function attemptToVisit(data, globals) {
2697
+ var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
2698
+ if (typeof data === "string") {
2699
+ if (isEvaluable(data)) {
2700
+ if (globals.some(key => data.includes(key))) {
2701
+ var {
2702
+ attemptToVisitGlobals
2703
+ } = preevaluate(data);
2704
+ return globals.some(key => attemptToVisitGlobals.has(key));
2705
+ }
2706
+ } else if (globals.includes("APP")) {
2707
+ return /\${\s*APP\s*\./.test(data);
2708
+ }
2709
+ } else if (isObject(data)) {
2710
+ // Avoid call stack overflow.
2711
+ // istanbul ignore next
2712
+ if (memo.has(data)) {
2713
+ return false;
2714
+ }
2715
+ memo.add(data);
2716
+ return (Array.isArray(data) ? data : Object.values(data)).some(item => attemptToVisit(item, globals, memo));
2717
+ }
2718
+ return false;
2719
+ }
2720
+ function computeRealValueWithOverrideApp(_x22, _x23, _x24, _x25) {
2721
+ return _computeRealValueWithOverrideApp.apply(this, arguments);
2722
+ }
2723
+ function _computeRealValueWithOverrideApp() {
2724
+ _computeRealValueWithOverrideApp = _asyncToGenerator$3(function* (data, overrideAppId, context, kernel) {
2725
+ if ("titleDataSource" in data && isObject(data.titleDataSource) && Object.entries(data.titleDataSource).every(_ref7 => {
2726
+ var [key, value] = _ref7;
2727
+ return value === null || value === "";
2728
+ })) {
2729
+ delete data.titleDataSource;
2730
+ }
2731
+ if ("if" in data && data.if === null) {
2732
+ delete data.if;
2733
+ }
2734
+ if ("to" in data && data.to && !isEvaluable(data.to)) {
2735
+ var yaml = pipes.yaml(data.to);
2736
+ if (isObject(yaml) && ["pathname", "search", "hash"].some(key => hasOwnProperty(yaml, key))) {
2737
+ data.to = yaml;
2738
+ }
2739
+ }
2740
+ var newContext = context;
2741
+ if (overrideAppId !== context.app.id && attemptToVisit(data, ["APP", "I18N", "IMG"])) {
2742
+ if (window.STANDALONE_MICRO_APPS) {
2743
+ if (data[symbolOverrideApp]) {
2744
+ data[symbolOverrideApp].config = deepFreeze(merge({}, data[symbolOverrideApp].defaultConfig, data[symbolOverrideApp].userConfig));
2745
+ }
2746
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
2747
+ overrideApp: data[symbolOverrideApp],
2748
+ appendI18nNamespace: data[symbolMenuI18nNamespace]
2749
+ });
2750
+ } else {
2751
+ var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
2752
+ newContext = _objectSpread(_objectSpread({}, context), {}, {
2753
+ overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
2754
+ appendI18nNamespace: data[symbolMenuI18nNamespace]
2755
+ });
2531
2756
  }
2757
+ }
2758
+ var processors = scanProcessorsInAny(data);
2759
+ yield kernel.loadDynamicBricks([], processors);
2760
+ yield kernel.router.waitForUsedContext(data);
2761
+ return computeRealValue(data, newContext, true, {
2762
+ ignoreSymbols: true
2763
+ });
2764
+ });
2765
+ return _computeRealValueWithOverrideApp.apply(this, arguments);
2766
+ }
2767
+
2768
+ var MediaBreakpoint;
2769
+ (function (MediaBreakpoint) {
2770
+ MediaBreakpoint["xLarge"] = "xLarge";
2771
+ MediaBreakpoint["large"] = "large";
2772
+ MediaBreakpoint["medium"] = "medium";
2773
+ MediaBreakpoint["small"] = "small";
2774
+ MediaBreakpoint["xSmall"] = "xSmall";
2775
+ })(MediaBreakpoint || (MediaBreakpoint = {}));
2776
+ var mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
2777
+ var mediaEventTarget = new EventTarget$1();
2778
+ var breakpointMatchesMap = {};
2779
+ var MEDIA = {};
2780
+ function handleMatchesChange(data, breakpoint) {
2781
+ var changed = false;
2782
+ breakpointMatchesMap[breakpoint] = data.matches;
2783
+ for (var [_breakpoint] of mediaBreakpointMinWidthMap) {
2784
+ if (breakpointMatchesMap[_breakpoint] && MEDIA.breakpoint !== _breakpoint) {
2785
+ MEDIA.breakpoint = _breakpoint;
2786
+ changed = true;
2787
+ break;
2788
+ }
2789
+ }
2790
+ if (changed) {
2791
+ mediaEventTarget.dispatchEvent(new CustomEvent("change", {
2792
+ detail: MEDIA
2793
+ }));
2794
+ }
2795
+ }
2796
+ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2797
+ var mediaQueryList = window.matchMedia("(min-width: ".concat(minWidth, ")"));
2798
+ handleMatchesChange(mediaQueryList, breakpoint);
2799
+ if (mediaQueryList.addEventListener) {
2800
+ mediaQueryList.addEventListener("change", event => {
2801
+ handleMatchesChange(event, breakpoint);
2802
+ });
2803
+ } else {
2804
+ mediaQueryList.addListener(event => {
2805
+ handleMatchesChange(event, breakpoint);
2532
2806
  });
2533
2807
  }
2534
- var internalContext = _internalApiGetCurrentContext();
2535
- var mergedContext = {};
2808
+ });
2809
+ var getMedia = () => MEDIA;
2536
2810
 
2537
- // Use runtime context over internal context.
2538
- // Internal context such as `match`, maybe change after `history.push`.
2539
- // So we prefer memoized runtime context.
2540
- for (var key of ["query", "match", "hash", "pathname", "app", "segues"]) {
2541
- mergedContext[key] = (hasOwnProperty(runtimeContext, key) ? runtimeContext : internalContext)[key];
2811
+ var FormContextMap = new Map();
2812
+ class CustomFormContext {
2813
+ constructor(renderId) {
2814
+ _defineProperty$1(this, "formState", void 0);
2815
+ _defineProperty$1(this, "id", uniqueId("form-ctx-"));
2816
+ FormContextMap.set(this.id, this);
2817
+ this.formState = new StoryboardContextWrapper(undefined, this.id, renderId);
2542
2818
  }
2543
- var {
2544
- app: currentApp,
2545
- query,
2546
- match,
2547
- hash,
2548
- pathname,
2549
- segues
2550
- } = mergedContext;
2551
- var {
2552
- sys,
2553
- flags,
2554
- storyboardContext
2555
- } = internalContext;
2556
- var app = (_runtimeContext$overr = runtimeContext.overrideApp) !== null && _runtimeContext$overr !== void 0 ? _runtimeContext$overr : currentApp;
2557
- function getIndividualGlobal(variableName) {
2558
- switch (variableName) {
2559
- case "ALIAS":
2560
- return {
2561
- getUrl: getUrlByAliasFactory(app)
2562
- };
2563
- case "ANCHOR":
2564
- return hash ? hash.substr(1) : null;
2565
- case "APP":
2566
- return _objectSpread(_objectSpread({}, cloneDeep(app)), {}, {
2567
- getMenu
2568
- });
2569
- case "CTX":
2570
- return getDynamicReadOnlyProxy({
2571
- get(target, key) {
2572
- var _item$brick$element;
2573
- var item = storyboardContext.get(key);
2574
- return !item ? item : item.type === "brick-property" ? (_item$brick$element = item.brick.element) === null || _item$brick$element === void 0 ? void 0 : _item$brick$element[item.prop] : item.value;
2575
- },
2576
- ownKeys() {
2577
- return Array.from(storyboardContext.keys());
2578
- }
2579
- });
2580
- case "FLAGS":
2581
- return getReadOnlyProxy(flags);
2582
- case "HASH":
2583
- return hash;
2584
- case "PATH_NAME":
2585
- return pathname;
2586
- case "INSTALLED_APPS":
2587
- return {
2588
- has: (appId, matchVersion) => getRuntime().hasInstalledApp(appId, matchVersion)
2589
- };
2590
- case "LOCAL_STORAGE":
2591
- return {
2592
- getItem: getItemFactory("local")
2593
- };
2594
- case "MISC":
2595
- return getRuntime().getMiscSettings();
2596
- case "PARAMS":
2597
- return new URLSearchParams(query);
2598
- case "PATH":
2599
- return getReadOnlyProxy(match.params);
2600
- case "PROCESSORS":
2601
- return getDynamicReadOnlyProxy({
2602
- get(target, key) {
2603
- var pkg = customProcessorRegistry.get(key);
2604
- if (!pkg) {
2605
- throw new Error("'PROCESSORS.".concat(key, "' is not registered! Have you installed the relevant brick package of '").concat(key.replace(/[A-Z]/g, m => "-".concat(m.toLowerCase())), "-NB'?"));
2606
- }
2607
- return getDynamicReadOnlyProxy({
2608
- get(t, k) {
2609
- return pkg.get(k);
2610
- },
2611
- ownKeys() {
2612
- return Array.from(pkg.keys());
2613
- }
2614
- });
2615
- },
2616
- ownKeys() {
2617
- return Array.from(customProcessorRegistry.keys());
2618
- }
2619
- });
2620
- case "QUERY":
2621
- return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.get(key)]));
2622
- case "QUERY_ARRAY":
2623
- return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.getAll(key)]));
2624
- case "SEGUE":
2625
- return {
2626
- getUrl: getUrlBySegueFactory(app, segues)
2627
- };
2628
- case "SESSION_STORAGE":
2629
- return {
2630
- getItem: getItemFactory("session")
2631
- };
2632
- case "SYS":
2633
- return getReadOnlyProxy(sys);
2634
- case "MEDIA":
2635
- return getReadOnlyProxy(getMedia());
2636
- case "__WIDGET_FN__":
2637
- return widgetFunctions;
2638
- case "__WIDGET_IMG__":
2639
- return widgetImagesFactory;
2640
- case "__WIDGET_I18N__":
2641
- return widgetI18nFactory;
2642
- }
2819
+ }
2820
+ function getCustomFormContext(formContextId) {
2821
+ return FormContextMap.get(formContextId);
2822
+ }
2823
+
2824
+ var symbolForRaw = Symbol.for("pre.evaluated.raw");
2825
+ var symbolForContext = Symbol.for("pre.evaluated.context");
2826
+ function isPreEvaluated(raw) {
2827
+ return !!(raw !== null && raw !== void 0 && raw[symbolForRaw]);
2828
+ }
2829
+ function getPreEvaluatedRaw(pre) {
2830
+ return pre[symbolForRaw];
2831
+ }
2832
+ function addDataToPreEvaluated(pre, data) {
2833
+ pre[symbolForContext].data = data;
2834
+ }
2835
+ function shouldDismissRecursiveMarkingInjected(raw) {
2836
+ if (typeof raw === "string") {
2837
+ return shouldAllowRecursiveEvaluations(raw);
2643
2838
  }
2644
- for (var variableName of attemptToVisitGlobals) {
2645
- var variable = getIndividualGlobal(variableName);
2646
- if (variable !== undefined) {
2647
- globalVariables[variableName] = variable;
2648
- }
2839
+ return shouldAllowRecursiveEvaluations(raw[symbolForRaw]);
2840
+ }
2841
+ var possibleErrorConstructs = new WeakSet([SyntaxError, TypeError, ReferenceError]);
2842
+ function getCookErrorConstructor(error) {
2843
+ return possibleErrorConstructs.has(error.constructor) ? error.constructor : TypeError;
2844
+ }
2845
+
2846
+ // `raw` should always be asserted to `isEvaluable` or `isPreEvaluated`.
2847
+ function evaluate(raw) {
2848
+ var _runtimeContext$overr;
2849
+ var runtimeContext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2850
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2851
+ if (options.isReEvaluation && !(typeof raw === "string" && isEvaluable(raw))) {
2852
+ devtoolsHookEmit("re-evaluation", {
2853
+ id: options.evaluationId,
2854
+ detail: {
2855
+ raw,
2856
+ context: {}
2857
+ },
2858
+ error: "Invalid evaluation code"
2859
+ });
2860
+ return;
2861
+ }
2862
+ if (typeof raw !== "string") {
2863
+ // If the `raw` is not a string, it must be a pre-evaluated object.
2864
+ // Then fulfil the context, and restore the original `raw`.
2865
+ runtimeContext = _objectSpread(_objectSpread({}, raw[symbolForContext]), runtimeContext);
2866
+ raw = raw[symbolForRaw];
2649
2867
  }
2650
- Object.assign(globalVariables, getGeneralGlobals(precooked.attemptToVisitGlobals, {
2651
- storyboardFunctions,
2652
- app,
2653
- appendI18nNamespace: runtimeContext.appendI18nNamespace
2654
- }));
2868
+
2869
+ // A `SyntaxError` maybe thrown.
2870
+ var precooked;
2655
2871
  try {
2656
- var result = cook(precooked.expression, precooked.source, {
2657
- globalVariables: supply(precooked.attemptToVisitGlobals, globalVariables)
2658
- });
2659
- var detail = {
2660
- raw,
2661
- context: globalVariables,
2662
- result
2663
- };
2664
- if (options.isReEvaluation) {
2665
- devtoolsHookEmit("re-evaluation", {
2666
- id: options.evaluationId,
2667
- detail
2668
- });
2669
- } else {
2670
- devtoolsHookEmit("evaluation", detail);
2671
- }
2672
- return result;
2872
+ precooked = preevaluate(raw);
2673
2873
  } catch (error) {
2674
- var _message = "".concat(error.message, ", in \"").concat(raw, "\"");
2874
+ var message = "".concat(error.message, ", in \"").concat(raw, "\"");
2675
2875
  if (options.isReEvaluation) {
2676
2876
  devtoolsHookEmit("re-evaluation", {
2677
2877
  id: options.evaluationId,
2678
2878
  detail: {
2679
2879
  raw,
2680
- context: globalVariables
2880
+ context: {}
2681
2881
  },
2682
- error: _message
2882
+ error: message
2683
2883
  });
2884
+ return;
2684
2885
  } else {
2685
- var _errorConstructor = getCookErrorConstructor(error);
2686
- throw new _errorConstructor(_message);
2886
+ var errorConstructor = getCookErrorConstructor(error);
2887
+ throw new errorConstructor(message);
2687
2888
  }
2688
2889
  }
2689
- }
2690
-
2691
- function isBasicProperty(propRef) {
2692
- return !!propRef.refProperty;
2693
- }
2694
- function isTransformableProperty(propRef) {
2695
- return !!propRef.refTransform;
2696
- }
2697
- function isMergeableProperty(propRef) {
2698
- return !!propRef.mergeProperty;
2699
- }
2700
- function isRefProperty(propRef) {
2701
- return !!propRef.ref;
2702
- }
2703
- function isVariableProperty(propRef) {
2704
- return !!propRef.asVariable;
2705
- }
2706
-
2707
- var customTemplateRegistry = new Map();
2708
- var appRegistered = new Set();
2709
- var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
2710
- var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
2711
- var symbolForTplContextId = Symbol.for("tpl.contextId");
2890
+ var globalVariables = {};
2891
+ var attemptToVisitGlobals = precooked.attemptToVisitGlobals;
2892
+ var attemptToVisitEvent = attemptToVisitGlobals.has("EVENT");
2893
+ var attemptToVisitData = attemptToVisitGlobals.has("DATA");
2894
+ var attemptToVisitTpl = attemptToVisitGlobals.has("TPL");
2895
+ var attemptToVisitState = attemptToVisitGlobals.has("STATE");
2896
+ var attemptToVisitFormState = attemptToVisitGlobals.has("FORM_STATE");
2897
+ var attemptToVisitTplOrState = attemptToVisitTpl || attemptToVisitState;
2712
2898
 
2713
- function propertyMerge(conf, value, object) {
2714
- return propertyMergeAll(conf.$$mergeBase, Object.fromEntries(conf.$$mergeBase.proxies.map(proxy => [proxy.$$reversedRef, proxy === conf ? value : object[proxy.$$reversedRef]])));
2715
- }
2716
- function propertyMergeAll(mergeBase, object) {
2717
- if (mergeBase.mergeType === "array") {
2718
- return propertyMergeAllOfArray(mergeBase, object);
2719
- }
2720
- if (mergeBase.mergeType === "object") {
2721
- return propertyMergeAllOfObject(mergeBase, object);
2722
- }
2723
- // istanbul ignore next: should never reach
2724
- throw new TypeError("unsupported mergeType: \"".concat(mergeBase.mergeType, "\""));
2725
- }
2726
- function propertyMergeAllOfArray(_ref, object) {
2727
- var _, _proxy$mergeArgs;
2728
- var {
2729
- baseValue,
2730
- context,
2731
- proxies
2732
- } = _ref;
2733
- // Use an approach like template-literal's quasis:
2734
- // `quasi0${0}quais1${1}quasi2...`
2735
- // Every quasi can be merged with multiple items.
2736
- var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true, {
2737
- $$lazyForUseBrick: true
2738
- }) : [];
2739
- var quasis = [];
2740
- var size = computedBaseValue.length + 1;
2741
- for (var i = 0; i < size; i += 1) {
2742
- quasis.push([]);
2743
- }
2744
- for (var proxy of proxies) {
2745
- var position = void 0;
2746
- switch (proxy.mergeMethod) {
2747
- case "append":
2748
- position = computedBaseValue.length;
2749
- break;
2750
- case "prepend":
2751
- position = 0;
2752
- break;
2753
- case "insertAt":
2754
- // Defaults to `-1`.
2755
- position = (_ = (_proxy$mergeArgs = proxy.mergeArgs) === null || _proxy$mergeArgs === void 0 ? void 0 : _proxy$mergeArgs[0]) !== null && _ !== void 0 ? _ : -1;
2756
- if (position < 0) {
2757
- // It's counted from the end if position is negative.
2758
- position += quasis.length;
2759
- }
2760
- position = clamp(position, 0, computedBaseValue.length);
2761
- break;
2762
- // istanbul ignore next: should never reach
2763
- default:
2764
- throw new TypeError("unsupported mergeMethod: \"".concat(proxy.mergeMethod, "\" for mergeType \"").concat(proxy.mergeType, "\""));
2765
- }
2766
- var patchValue = object[proxy.$$reversedRef];
2767
- if (!Array.isArray(patchValue)) {
2768
- patchValue = [];
2899
+ // Ignore evaluating if `event` is missing in context.
2900
+ // Since it should be evaluated during events handling.
2901
+ var missingEvent = options.lazy === true;
2902
+ if (attemptToVisitEvent) {
2903
+ if (hasOwnProperty(runtimeContext, "event")) {
2904
+ globalVariables.EVENT = runtimeContext.event;
2905
+ } else {
2906
+ // Let's see if pre-evaluation is required (store the `data` in context).
2907
+ missingEvent = true;
2769
2908
  }
2770
- quasis[position].push(...patchValue);
2771
2909
  }
2772
- return quasis.flatMap((item, index) => index < computedBaseValue.length ? item.concat(computedBaseValue[index]) : item);
2773
- }
2774
- function propertyMergeAllOfObject(_ref2, object) {
2775
- var {
2776
- baseValue,
2777
- proxies,
2778
- context
2779
- } = _ref2;
2780
- var computedBaseValue = isObject(baseValue) ? computeRealValue(baseValue, context, true) : {};
2781
- return proxies.reduce((acc, proxy) => {
2782
- switch (proxy.mergeMethod) {
2783
- case "extend":
2784
- return _objectSpread(_objectSpread({}, acc), object[proxy.$$reversedRef]);
2785
- // istanbul ignore next: should never reach
2786
- default:
2787
- throw new TypeError("unsupported mergeMethod: \"".concat(proxy.mergeMethod, "\" for mergeType \"").concat(proxy.mergeType, "\""));
2788
- }
2789
- }, computedBaseValue);
2790
- }
2791
-
2792
- function setupTemplateProxy(proxyContext, ref, slots) {
2793
- var computedPropsFromProxy = {};
2794
- var refForProxy;
2795
- var {
2796
- reversedProxies,
2797
- templateProperties,
2798
- externalSlots,
2799
- templateContextId,
2800
- proxyBrick
2801
- } = proxyContext;
2802
- if (ref && reversedProxies) {
2803
- refForProxy = {};
2804
- proxyBrick.proxyRefs.set(ref, refForProxy);
2805
-
2806
- // Reversed proxies are used for expand storyboard before rendering page.
2807
- if (reversedProxies.properties.has(ref)) {
2808
- Object.assign(computedPropsFromProxy, Object.fromEntries(reversedProxies.properties.get(ref).flatMap(propRef => {
2809
- // `propValue` is computed.
2810
- var propValue = templateProperties === null || templateProperties === void 0 ? void 0 : templateProperties[propRef.$$reversedRef];
2811
- if (isTransformableProperty(propRef)) {
2812
- return Object.entries(preprocessTransformProperties({
2813
- [propRef.$$reversedRef]: propValue
2814
- }, propRef.refTransform));
2815
- }
2816
- if (isBasicProperty(propRef)) {
2817
- return [[propRef.refProperty, propValue]];
2818
- }
2819
- // Ignore Variable properties.
2820
- // And mergeable properties are processed later.
2821
- return [];
2822
- }).filter(propRef => propRef[1] !== undefined)));
2823
-
2824
- // Brick properties can be merged multiple times.
2825
- if (reversedProxies.mergeBases.has(ref)) {
2826
- Object.assign(computedPropsFromProxy, Object.fromEntries(Array.from(reversedProxies.mergeBases.get(ref).entries()).map(_ref => {
2827
- var [mergeProperty, mergeBase] = _ref;
2828
- return [mergeProperty, propertyMergeAll(mergeBase, templateProperties !== null && templateProperties !== void 0 ? templateProperties : {})];
2829
- }).filter(item => item[1] !== undefined)));
2830
- }
2831
- }
2910
+ var missingTplOrState = attemptToVisitTplOrState && !hasOwnProperty(runtimeContext, "tplContextId");
2911
+ var missingData = attemptToVisitData && !hasOwnProperty(runtimeContext, "data");
2912
+ var rawWithContext = Object.keys(runtimeContext).length > 0 ? {
2913
+ [symbolForRaw]: raw,
2914
+ [symbolForContext]: runtimeContext
2915
+ } : raw;
2832
2916
 
2833
- // Use an approach like template-literal's quasis:
2834
- // `quasi0${0}quais1${1}quasi2...`
2835
- // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.
2836
- var quasisMap = new Map();
2837
- if (reversedProxies.slots.has(ref)) {
2838
- for (var item of reversedProxies.slots.get(ref)) {
2839
- var _item$refPosition, _externalSlots$item$$, _externalSlots$item$$2;
2840
- if (!quasisMap.has(item.refSlot)) {
2841
- var quasis = [];
2842
- // The size of quasis should be the existed slotted bricks' size plus one.
2843
- var size = hasOwnProperty(slots, item.refSlot) ? slots[item.refSlot].bricks.length + 1 : 1;
2844
- for (var i = 0; i < size; i += 1) {
2845
- quasis.push([]);
2846
- }
2847
- quasisMap.set(item.refSlot, quasis);
2848
- }
2849
- var expandableSlot = quasisMap.get(item.refSlot);
2850
- var refPosition = (_item$refPosition = item.refPosition) !== null && _item$refPosition !== void 0 ? _item$refPosition : -1;
2851
- expandableSlot[clamp(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((_externalSlots$item$$ = externalSlots === null || externalSlots === void 0 ? void 0 : (_externalSlots$item$$2 = externalSlots[item.$$reversedRef]) === null || _externalSlots$item$$2 === void 0 ? void 0 : _externalSlots$item$$2.bricks) !== null && _externalSlots$item$$ !== void 0 ? _externalSlots$item$$ : []));
2852
- }
2853
- }
2854
- var _loop = function (slotName, _quasis) {
2855
- if (!hasOwnProperty(slots, slotName)) {
2856
- slots[slotName] = {
2857
- type: "bricks",
2858
- bricks: []
2859
- };
2860
- }
2861
- var slotConf = slots[slotName];
2862
- slotConf.bricks = _quasis.flatMap((bricks, index) => index < slotConf.bricks.length ? bricks.concat(slotConf.bricks[index]) : bricks);
2863
- if (slotConf.bricks.length === 0) {
2864
- delete slots[slotName];
2865
- }
2866
- };
2867
- for (var [slotName, _quasis] of quasisMap.entries()) {
2868
- _loop(slotName, _quasis);
2869
- }
2917
+ // Since `EVENT`, `DATA`, `TPL` and `STATE` are provided in different context,
2918
+ // whenever missing one of them, memorize the current context for later consuming.
2919
+ if (missingEvent || missingData || missingTplOrState) {
2920
+ return rawWithContext;
2870
2921
  }
2871
- return {
2872
- [symbolForComputedPropsFromProxy]: computedPropsFromProxy,
2873
- [symbolForRefForProxy]: refForProxy,
2874
- [symbolForTplContextId]: templateContextId
2875
- };
2876
- }
2877
-
2878
- var _excluded$8 = ["properties", "slots"];
2879
- function setupUseBrickInTemplate(props, proxyContext) {
2880
- function walk(props) {
2881
- if (Array.isArray(props)) {
2882
- return props.map(walk);
2922
+ if (attemptToVisitData) {
2923
+ globalVariables.DATA = runtimeContext.data;
2924
+ }
2925
+ if (attemptToVisitTplOrState && runtimeContext.tplContextId) {
2926
+ var tplContext = getCustomTemplateContext(runtimeContext.tplContextId);
2927
+ if (attemptToVisitTpl) {
2928
+ globalVariables.TPL = tplContext.getVariables();
2883
2929
  }
2884
- if (!isObject(props) || !isPlainObject(props)) {
2885
- return props;
2930
+ if (attemptToVisitState) {
2931
+ globalVariables.STATE = getDynamicReadOnlyProxy({
2932
+ get(target, key) {
2933
+ return tplContext.state.getValue(key);
2934
+ },
2935
+ ownKeys() {
2936
+ return Array.from(tplContext.state.get().keys());
2937
+ }
2938
+ });
2886
2939
  }
2887
- return Object.fromEntries(Object.entries(props).map(_ref => {
2888
- var [key, value] = _ref;
2889
- return isObject(value) && key === "useBrick" ? Array.isArray(value) ? [key, value.map(setup)] : [key, setup(value)] : [key, walk(value)];
2890
- }).concat(Object.getOwnPropertySymbols(props).map(k => [k, props[k]])));
2891
2940
  }
2892
- function setup(item) {
2893
- var {
2894
- properties,
2895
- slots: originalSlots
2896
- } = item,
2897
- restConf = _objectWithoutProperties(item, _excluded$8);
2898
- var slots = Object.fromEntries(Object.entries(originalSlots !== null && originalSlots !== void 0 ? originalSlots : {}).map(_ref2 => {
2899
- var _slotConf$bricks;
2900
- var [slotName, slotConf] = _ref2;
2901
- return [slotName, {
2902
- type: "bricks",
2903
- bricks: ((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : []).map(setup)
2904
- }];
2905
- }));
2906
- return _objectSpread(_objectSpread({}, restConf), {}, {
2907
- properties: walk(properties),
2908
- slots
2909
- }, setupTemplateProxy(proxyContext, restConf.ref, slots));
2941
+ if (attemptToVisitFormState && runtimeContext.formContextId) {
2942
+ var formContext = getCustomFormContext(runtimeContext.formContextId);
2943
+ globalVariables.FORM_STATE = getDynamicReadOnlyProxy({
2944
+ get(target, key) {
2945
+ return formContext.formState.getValue(key);
2946
+ },
2947
+ ownKeys() {
2948
+ return Array.from(formContext.formState.get().keys());
2949
+ }
2950
+ });
2910
2951
  }
2911
- return walk(props);
2912
- }
2913
- function isPlainObject(object) {
2914
- return Object.prototype.toString.call(object) === "[object Object]";
2915
- }
2952
+ var internalContext = _internalApiGetCurrentContext();
2953
+ var mergedContext = {};
2916
2954
 
2917
- var computeRealValue = (value, context, injectDeep, internalOptions) => {
2918
- var preEvaluated = isPreEvaluated(value);
2919
- if (preEvaluated || typeof value === "string") {
2920
- // For `useBrick`, some fields such as `properties`/`transform`/`events`/`if`,
2921
- // are kept and to be evaluated later.
2922
- var lazy = (internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.$$lazyForUseBrick) && isLazyContentInUseBrick(internalOptions.$$stateOfUseBrick);
2923
- var result;
2924
- var dismissRecursiveMarkingInjected = lazy;
2925
- if (preEvaluated || isEvaluable(value)) {
2926
- var runtimeContext = {};
2927
- if (context) {
2928
- var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId", "query", "match", "app", "segues"];
2929
- for (var key of keys) {
2930
- if (context[key]) {
2931
- runtimeContext[key] = context[key];
2955
+ // Use runtime context over internal context.
2956
+ // Internal context such as `match`, maybe change after `history.push`.
2957
+ // So we prefer memoized runtime context.
2958
+ for (var key of ["query", "match", "hash", "pathname", "app", "segues"]) {
2959
+ mergedContext[key] = (hasOwnProperty(runtimeContext, key) ? runtimeContext : internalContext)[key];
2960
+ }
2961
+ var {
2962
+ app: currentApp,
2963
+ query,
2964
+ match,
2965
+ hash,
2966
+ pathname,
2967
+ segues
2968
+ } = mergedContext;
2969
+ var {
2970
+ sys,
2971
+ flags,
2972
+ storyboardContext
2973
+ } = internalContext;
2974
+ var app = (_runtimeContext$overr = runtimeContext.overrideApp) !== null && _runtimeContext$overr !== void 0 ? _runtimeContext$overr : currentApp;
2975
+ function getIndividualGlobal(variableName) {
2976
+ switch (variableName) {
2977
+ case "ALIAS":
2978
+ return {
2979
+ getUrl: getUrlByAliasFactory(app)
2980
+ };
2981
+ case "ANCHOR":
2982
+ return hash ? hash.substr(1) : null;
2983
+ case "APP":
2984
+ return _objectSpread(_objectSpread({}, cloneDeep(app)), {}, {
2985
+ getMenu
2986
+ });
2987
+ case "CTX":
2988
+ return getDynamicReadOnlyProxy({
2989
+ get(target, key) {
2990
+ var _item$brick$element;
2991
+ var item = storyboardContext.get(key);
2992
+ return !item ? item : item.type === "brick-property" ? (_item$brick$element = item.brick.element) === null || _item$brick$element === void 0 ? void 0 : _item$brick$element[item.prop] : item.value;
2993
+ },
2994
+ ownKeys() {
2995
+ return Array.from(storyboardContext.keys());
2932
2996
  }
2933
- }
2934
- var simpleKeys = ["hash", "pathname"];
2935
- for (var _key of simpleKeys) {
2936
- if (hasOwnProperty(context, _key)) {
2937
- runtimeContext[_key] = context[_key];
2997
+ });
2998
+ case "FLAGS":
2999
+ return getReadOnlyProxy(flags);
3000
+ case "HASH":
3001
+ return hash;
3002
+ case "PATH_NAME":
3003
+ return pathname;
3004
+ case "INSTALLED_APPS":
3005
+ return {
3006
+ has: (appId, matchVersion) => getRuntime().hasInstalledApp(appId, matchVersion)
3007
+ };
3008
+ case "LOCAL_STORAGE":
3009
+ return {
3010
+ getItem: getItemFactory("local")
3011
+ };
3012
+ case "MISC":
3013
+ return getRuntime().getMiscSettings();
3014
+ case "PARAMS":
3015
+ return new URLSearchParams(query);
3016
+ case "PATH":
3017
+ return getReadOnlyProxy(match.params);
3018
+ case "PROCESSORS":
3019
+ return getDynamicReadOnlyProxy({
3020
+ get(target, key) {
3021
+ var pkg = customProcessorRegistry.get(key);
3022
+ if (!pkg) {
3023
+ throw new Error("'PROCESSORS.".concat(key, "' is not registered! Have you installed the relevant brick package of '").concat(key.replace(/[A-Z]/g, m => "-".concat(m.toLowerCase())), "-NB'?"));
3024
+ }
3025
+ return getDynamicReadOnlyProxy({
3026
+ get(t, k) {
3027
+ return pkg.get(k);
3028
+ },
3029
+ ownKeys() {
3030
+ return Array.from(pkg.keys());
3031
+ }
3032
+ });
3033
+ },
3034
+ ownKeys() {
3035
+ return Array.from(customProcessorRegistry.keys());
2938
3036
  }
2939
- }
2940
- }
2941
- // The current runtime context is memoized even if the evaluation maybe lazy.
2942
- result = evaluate(value, runtimeContext, {
2943
- lazy
2944
- });
2945
- dismissRecursiveMarkingInjected = shouldDismissRecursiveMarkingInjected(value);
2946
- } else {
2947
- result = lazy ? value : inject(value, context);
2948
- }
2949
- if (!dismissRecursiveMarkingInjected) {
2950
- recursiveMarkAsInjected(result);
3037
+ });
3038
+ case "QUERY":
3039
+ return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.get(key)]));
3040
+ case "QUERY_ARRAY":
3041
+ return Object.fromEntries(Array.from(query.keys()).map(key => [key, query.getAll(key)]));
3042
+ case "SEGUE":
3043
+ return {
3044
+ getUrl: getUrlBySegueFactory(app, segues)
3045
+ };
3046
+ case "SESSION_STORAGE":
3047
+ return {
3048
+ getItem: getItemFactory("session")
3049
+ };
3050
+ case "SYS":
3051
+ return getReadOnlyProxy(sys);
3052
+ case "MEDIA":
3053
+ return getReadOnlyProxy(getMedia());
3054
+ case "__WIDGET_FN__":
3055
+ return widgetFunctions;
3056
+ case "__WIDGET_IMG__":
3057
+ return widgetImagesFactory;
3058
+ case "__WIDGET_I18N__":
3059
+ return widgetI18nFactory;
2951
3060
  }
2952
- return result;
2953
3061
  }
2954
- if (!(injectDeep && isObject(value)) || haveBeenInjected(value)) {
2955
- return value;
2956
- }
2957
- if (Array.isArray(value)) {
2958
- var nextOptions = getNextInternalOptions(internalOptions, true);
2959
- return value.map(v => computeRealValue(v, context, injectDeep, nextOptions));
3062
+ for (var variableName of attemptToVisitGlobals) {
3063
+ var variable = getIndividualGlobal(variableName);
3064
+ if (variable !== undefined) {
3065
+ globalVariables[variableName] = variable;
3066
+ }
2960
3067
  }
2961
- return Object.fromEntries(Object.entries(value).map(_ref => {
2962
- var [k, v] = _ref;
2963
- return [computeRealValue(k, context, false), computeRealValue(v, context, injectDeep, getNextInternalOptions(internalOptions, false, k))];
2964
- }).concat(internalOptions !== null && internalOptions !== void 0 && internalOptions.ignoreSymbols ? [] : Object.getOwnPropertySymbols(value).map(k => [k, value[k]])));
2965
- };
2966
- function setProperties(bricks, properties, context, injectDeep) {
2967
- var realProps = computeRealProperties(properties, context, injectDeep);
2968
- if (context.tplContextId) {
2969
- realProps = setupUseBrickInTemplate(realProps, {
2970
- templateContextId: context.tplContextId
3068
+ Object.assign(globalVariables, getGeneralGlobals(precooked.attemptToVisitGlobals, {
3069
+ storyboardFunctions,
3070
+ app,
3071
+ appendI18nNamespace: runtimeContext.appendI18nNamespace
3072
+ }));
3073
+ try {
3074
+ var result = cook(precooked.expression, precooked.source, {
3075
+ globalVariables: supply(precooked.attemptToVisitGlobals, globalVariables)
2971
3076
  });
2972
- }
2973
- if (!Array.isArray(bricks)) {
2974
- bricks = [bricks];
2975
- }
2976
- bricks.forEach(brick => {
2977
- setRealProperties(brick, realProps);
2978
- });
2979
- }
2980
- function setRealProperties(brick, realProps, extractProps) {
2981
- for (var [propName, propValue] of Object.entries(realProps)) {
2982
- if (propName === "style" || propName === "dataset") {
2983
- for (var [k, v] of Object.entries(propValue)) {
2984
- brick[propName][k] = v;
2985
- }
2986
- } else if (propName === "innerHTML") {
2987
- // `innerHTML` is dangerous, use `textContent` instead.
2988
- // eslint-disable-next-line no-console
2989
- console.error("Please use `textContent` instead of `innerHTML`.");
2990
- brick.textContent = propValue;
2991
- } else {
2992
- if (extractProps) {
2993
- set(brick, propName, propValue);
2994
- } else {
2995
- brick[propName] = propValue;
2996
- }
3077
+ var detail = {
3078
+ raw,
3079
+ context: globalVariables,
3080
+ result
3081
+ };
3082
+ if (options.isReEvaluation) {
3083
+ devtoolsHookEmit("re-evaluation", {
3084
+ id: options.evaluationId,
3085
+ detail
3086
+ });
3087
+ } else {
3088
+ devtoolsHookEmit("evaluation", detail);
2997
3089
  }
2998
- }
2999
- }
3000
- function computeRealProperties(properties, context, injectDeep, trackingContextList) {
3001
- var result = {};
3002
- if (isObject(properties)) {
3003
- for (var [propName, propValue] of Object.entries(properties)) {
3004
- // Related: https://github.com/facebook/react/issues/11347
3005
- var realValue = computeRealValue(propValue, context, injectDeep, {
3006
- $$lazyForUseBrick: true,
3007
- $$stateOfUseBrick: propName === "useBrick" ? StateOfUseBrick.USE_BRICK : StateOfUseBrick.INITIAL
3090
+ return result;
3091
+ } catch (error) {
3092
+ var _message = "".concat(error.message, ", in \"").concat(raw, "\"");
3093
+ if (options.isReEvaluation) {
3094
+ devtoolsHookEmit("re-evaluation", {
3095
+ id: options.evaluationId,
3096
+ detail: {
3097
+ raw,
3098
+ context: globalVariables
3099
+ },
3100
+ error: _message
3008
3101
  });
3009
- if (realValue !== undefined) {
3010
- // For `style` and `dataset`, only object is acceptable.
3011
- if (propName !== "style" && propName !== "dataset" || isObject(realValue)) {
3012
- result[propName] = realValue;
3013
- }
3014
- }
3015
- if (Array.isArray(trackingContextList)) {
3016
- var {
3017
- contextNames,
3018
- stateNames,
3019
- formStateNames
3020
- } = getTracks(propValue);
3021
- if (contextNames || stateNames || formStateNames) {
3022
- trackingContextList.push({
3023
- contextNames,
3024
- stateNames,
3025
- formStateNames,
3026
- propName,
3027
- propValue
3028
- });
3029
- }
3030
- }
3102
+ } else {
3103
+ var _errorConstructor = getCookErrorConstructor(error);
3104
+ throw new _errorConstructor(_message);
3031
3105
  }
3032
3106
  }
3033
- return result;
3034
- }
3035
- function getNextInternalOptions(internalOptions, isArray, key) {
3036
- return internalOptions !== null && internalOptions !== void 0 && internalOptions.$$lazyForUseBrick ? _objectSpread(_objectSpread({}, internalOptions), {}, {
3037
- $$stateOfUseBrick: getNextStateOfUseBrick(internalOptions.$$stateOfUseBrick, isArray, key)
3038
- }) : internalOptions;
3039
3107
  }
3040
3108
 
3041
- var _excluded$7 = ["children"],
3042
- _excluded2$2 = ["children"],
3043
- _excluded3 = ["items", "app"];
3044
- var symbolAppId = Symbol("appId");
3045
- var symbolMenuI18nNamespace = Symbol("menuI18nNamespace");
3046
- var symbolOverrideApp = Symbol("overrideApp");
3047
- var symbolShouldCache = Symbol("shouldCache");
3048
- // Caching menu requests to avoid flicker.
3049
- var menuCache = new Map();
3050
- var menuTitleCache = new Map();
3051
- var processMenuCache = new Map();
3052
- function constructMenu(_x, _x2, _x3) {
3053
- return _constructMenu.apply(this, arguments);
3109
+ function isBasicProperty(propRef) {
3110
+ return !!propRef.refProperty;
3054
3111
  }
3055
- function _constructMenu() {
3056
- _constructMenu = _asyncToGenerator$3(function* (menuBar, context, kernel) {
3057
- var hasSubMenu = !!menuBar.subMenuId;
3058
- yield Promise.all([_asyncToGenerator$3(function* () {
3059
- if (menuBar.menuId) {
3060
- var _menuBar$menu;
3061
- var defaultCollapsed = (_menuBar$menu = menuBar.menu) === null || _menuBar$menu === void 0 ? void 0 : _menuBar$menu.defaultCollapsed;
3062
- var menu = yield processMenu(menuBar.menuId, context, kernel, hasSubMenu);
3063
- if (!isNil(defaultCollapsed)) {
3064
- menu.defaultCollapsed = defaultCollapsed;
3065
- }
3066
- menuBar.menu = menu;
3067
- }
3068
- })(), _asyncToGenerator$3(function* () {
3069
- if (hasSubMenu) {
3070
- menuBar.subMenu = yield processMenu(menuBar.subMenuId, context, kernel);
3071
- } else {
3072
- menuBar.subMenu = null;
3073
- }
3074
- })()]);
3075
- });
3076
- return _constructMenu.apply(this, arguments);
3112
+ function isTransformableProperty(propRef) {
3113
+ return !!propRef.refTransform;
3077
3114
  }
3078
- function preConstructMenus(_x4, _x5, _x6) {
3079
- return _preConstructMenus.apply(this, arguments);
3115
+ function isMergeableProperty(propRef) {
3116
+ return !!propRef.mergeProperty;
3080
3117
  }
3081
- function _preConstructMenus() {
3082
- _preConstructMenus = _asyncToGenerator$3(function* (menus, context, kernel) {
3083
- var data = yield Promise.all(menus.map(menuId => processMenu(menuId, context, kernel, undefined, true)));
3084
- data.forEach((item, index) => processMenuCache.set(menus[index], item));
3085
- });
3086
- return _preConstructMenus.apply(this, arguments);
3118
+ function isRefProperty(propRef) {
3119
+ return !!propRef.ref;
3087
3120
  }
3088
- var getMenu = menuId => processMenuCache.get(menuId);
3089
- function fetchMenuById(_x7, _x8, _x9) {
3090
- return _fetchMenuById.apply(this, arguments);
3121
+ function isVariableProperty(propRef) {
3122
+ return !!propRef.asVariable;
3091
3123
  }
3092
- function _fetchMenuById() {
3093
- _fetchMenuById = _asyncToGenerator$3(function* (menuId, kernel, isPreFetch) {
3094
- if (menuCache.has(menuId)) {
3095
- return menuCache.get(menuId);
3096
- }
3097
- var menuList = window.STANDALONE_MICRO_APPS ? yield kernel.getStandaloneMenus(menuId, isPreFetch) : kernel.getFeatureFlags()["three-level-menu-layout"] ? (yield InstalledMicroAppApi_getMenusInfo(menuId, {
3098
- menuObjectId: "EASYOPS_STORYBOARD_MENU"
3099
- })).menus : (yield InstanceApi_postSearch("EASYOPS_STORYBOARD_MENU", {
3100
- page: 1,
3101
- page_size: 200,
3102
- fields: {
3103
- menuId: true,
3104
- title: true,
3105
- icon: true,
3106
- link: true,
3107
- titleDataSource: true,
3108
- defaultCollapsed: true,
3109
- defaultCollapsedBreakpoint: true,
3110
- type: true,
3111
- injectMenuGroupId: true,
3112
- dynamicItems: true,
3113
- itemsResolve: true,
3114
- items: true,
3115
- i18n: true,
3116
- "items.children": true,
3117
- "app.appId": true
3118
- },
3119
- query: {
3120
- menuId: {
3121
- $eq: menuId
3122
- },
3123
- app: {
3124
- $size: {
3125
- $gt: 0
3126
- }
3124
+
3125
+ var customTemplateRegistry = new Map();
3126
+ var appRegistered = new Set();
3127
+ var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
3128
+ var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
3129
+ var symbolForTplContextId = Symbol.for("tpl.contextId");
3130
+
3131
+ function propertyMerge(conf, value, object) {
3132
+ return propertyMergeAll(conf.$$mergeBase, Object.fromEntries(conf.$$mergeBase.proxies.map(proxy => [proxy.$$reversedRef, proxy === conf ? value : object[proxy.$$reversedRef]])));
3133
+ }
3134
+ function propertyMergeAll(mergeBase, object) {
3135
+ if (mergeBase.mergeType === "array") {
3136
+ return propertyMergeAllOfArray(mergeBase, object);
3137
+ }
3138
+ if (mergeBase.mergeType === "object") {
3139
+ return propertyMergeAllOfObject(mergeBase, object);
3140
+ }
3141
+ // istanbul ignore next: should never reach
3142
+ throw new TypeError("unsupported mergeType: \"".concat(mergeBase.mergeType, "\""));
3143
+ }
3144
+ function propertyMergeAllOfArray(_ref, object) {
3145
+ var _, _proxy$mergeArgs;
3146
+ var {
3147
+ baseValue,
3148
+ context,
3149
+ proxies
3150
+ } = _ref;
3151
+ // Use an approach like template-literal's quasis:
3152
+ // `quasi0${0}quais1${1}quasi2...`
3153
+ // Every quasi can be merged with multiple items.
3154
+ var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true, {
3155
+ $$lazyForUseBrick: true
3156
+ }) : [];
3157
+ var quasis = [];
3158
+ var size = computedBaseValue.length + 1;
3159
+ for (var i = 0; i < size; i += 1) {
3160
+ quasis.push([]);
3161
+ }
3162
+ for (var proxy of proxies) {
3163
+ var position = void 0;
3164
+ switch (proxy.mergeMethod) {
3165
+ case "append":
3166
+ position = computedBaseValue.length;
3167
+ break;
3168
+ case "prepend":
3169
+ position = 0;
3170
+ break;
3171
+ case "insertAt":
3172
+ // Defaults to `-1`.
3173
+ position = (_ = (_proxy$mergeArgs = proxy.mergeArgs) === null || _proxy$mergeArgs === void 0 ? void 0 : _proxy$mergeArgs[0]) !== null && _ !== void 0 ? _ : -1;
3174
+ if (position < 0) {
3175
+ // It's counted from the end if position is negative.
3176
+ position += quasis.length;
3127
3177
  }
3128
- }
3129
- })).list;
3130
- var menuData = yield mergeMenu(menuList, kernel);
3131
- if (!menuData) {
3132
- throw new Error("Menu not found: ".concat(menuId));
3178
+ position = clamp(position, 0, computedBaseValue.length);
3179
+ break;
3180
+ // istanbul ignore next: should never reach
3181
+ default:
3182
+ throw new TypeError("unsupported mergeMethod: \"".concat(proxy.mergeMethod, "\" for mergeType \"").concat(proxy.mergeType, "\""));
3133
3183
  }
3134
- reorderMenu(menuData);
3135
- menuData[symbolShouldCache] && menuCache.set(menuId, menuData);
3136
- return menuData;
3137
- });
3138
- return _fetchMenuById.apply(this, arguments);
3139
- }
3140
- function mergeMenu(_x10, _x11) {
3141
- return _mergeMenu.apply(this, arguments);
3184
+ var patchValue = object[proxy.$$reversedRef];
3185
+ if (!Array.isArray(patchValue)) {
3186
+ patchValue = [];
3187
+ }
3188
+ quasis[position].push(...patchValue);
3189
+ }
3190
+ return quasis.flatMap((item, index) => index < computedBaseValue.length ? item.concat(computedBaseValue[index]) : item);
3142
3191
  }
3143
- function _mergeMenu() {
3144
- _mergeMenu = _asyncToGenerator$3(function* (menuList, kernel) {
3145
- var mainMenu = menuList.find(menu => menu.type !== "inject");
3146
- if (!mainMenu) {
3147
- return undefined;
3192
+ function propertyMergeAllOfObject(_ref2, object) {
3193
+ var {
3194
+ baseValue,
3195
+ proxies,
3196
+ context
3197
+ } = _ref2;
3198
+ var computedBaseValue = isObject(baseValue) ? computeRealValue(baseValue, context, true) : {};
3199
+ return proxies.reduce((acc, proxy) => {
3200
+ switch (proxy.mergeMethod) {
3201
+ case "extend":
3202
+ return _objectSpread(_objectSpread({}, acc), object[proxy.$$reversedRef]);
3203
+ // istanbul ignore next: should never reach
3204
+ default:
3205
+ throw new TypeError("unsupported mergeMethod: \"".concat(proxy.mergeMethod, "\" for mergeType \"").concat(proxy.mergeType, "\""));
3148
3206
  }
3149
- var validMenuList = [];
3150
- var injectWithMenus = new Map();
3151
- var menuWithI18n = new WeakMap();
3152
- for (var menu of menuList) {
3153
- if (menu.i18n) {
3154
- (function () {
3155
- var menuI18nNamespace = getI18nNamespace("menu", "".concat(menu.menuId, "~").concat(menu.app[0].appId, "+").concat(menu.instanceId));
3156
- // Support any language in `meta.i18n`.
3157
- Object.entries(menu.i18n).forEach(_ref6 => {
3158
- var [lang, resources] = _ref6;
3159
- i18next.addResourceBundle(lang, menuI18nNamespace, resources);
3160
- });
3161
- menuWithI18n.set(menu, menuI18nNamespace);
3162
- })();
3207
+ }, computedBaseValue);
3208
+ }
3209
+
3210
+ function setupTemplateProxy(proxyContext, ref, slots) {
3211
+ var computedPropsFromProxy = {};
3212
+ var refForProxy;
3213
+ var {
3214
+ reversedProxies,
3215
+ templateProperties,
3216
+ externalSlots,
3217
+ templateContextId,
3218
+ proxyBrick
3219
+ } = proxyContext;
3220
+ if (ref && reversedProxies) {
3221
+ refForProxy = {};
3222
+ proxyBrick.proxyRefs.set(ref, refForProxy);
3223
+
3224
+ // Reversed proxies are used for expand storyboard before rendering page.
3225
+ if (reversedProxies.properties.has(ref)) {
3226
+ Object.assign(computedPropsFromProxy, Object.fromEntries(reversedProxies.properties.get(ref).flatMap(propRef => {
3227
+ // `propValue` is computed.
3228
+ var propValue = templateProperties === null || templateProperties === void 0 ? void 0 : templateProperties[propRef.$$reversedRef];
3229
+ if (isTransformableProperty(propRef)) {
3230
+ return Object.entries(preprocessTransformProperties({
3231
+ [propRef.$$reversedRef]: propValue
3232
+ }, propRef.refTransform));
3233
+ }
3234
+ if (isBasicProperty(propRef)) {
3235
+ return [[propRef.refProperty, propValue]];
3236
+ }
3237
+ // Ignore Variable properties.
3238
+ // And mergeable properties are processed later.
3239
+ return [];
3240
+ }).filter(propRef => propRef[1] !== undefined)));
3241
+
3242
+ // Brick properties can be merged multiple times.
3243
+ if (reversedProxies.mergeBases.has(ref)) {
3244
+ Object.assign(computedPropsFromProxy, Object.fromEntries(Array.from(reversedProxies.mergeBases.get(ref).entries()).map(_ref => {
3245
+ var [mergeProperty, mergeBase] = _ref;
3246
+ return [mergeProperty, propertyMergeAll(mergeBase, templateProperties !== null && templateProperties !== void 0 ? templateProperties : {})];
3247
+ }).filter(item => item[1] !== undefined)));
3163
3248
  }
3164
3249
  }
3165
- var shouldCacheList = yield Promise.all(menuList.map(menu => loadDynamicMenuItems(menu, kernel, menuWithI18n)));
3166
- for (var _menu of menuList) {
3167
- var _menu$items;
3168
- if (((_menu$items = _menu.items) === null || _menu$items === void 0 ? void 0 : _menu$items.length) > 0) {
3169
- if (_menu.type === "inject" && _menu.injectMenuGroupId) {
3170
- var injectingMenus = injectWithMenus.get(_menu.injectMenuGroupId);
3171
- if (!injectingMenus) {
3172
- injectingMenus = [];
3173
- injectWithMenus.set(_menu.injectMenuGroupId, injectingMenus);
3250
+
3251
+ // Use an approach like template-literal's quasis:
3252
+ // `quasi0${0}quais1${1}quasi2...`
3253
+ // Every quasi (indexed by `refPosition`) can be slotted with multiple bricks.
3254
+ var quasisMap = new Map();
3255
+ if (reversedProxies.slots.has(ref)) {
3256
+ for (var item of reversedProxies.slots.get(ref)) {
3257
+ var _item$refPosition, _externalSlots$item$$, _externalSlots$item$$2;
3258
+ if (!quasisMap.has(item.refSlot)) {
3259
+ var quasis = [];
3260
+ // The size of quasis should be the existed slotted bricks' size plus one.
3261
+ var size = hasOwnProperty(slots, item.refSlot) ? slots[item.refSlot].bricks.length + 1 : 1;
3262
+ for (var i = 0; i < size; i += 1) {
3263
+ quasis.push([]);
3174
3264
  }
3175
- injectingMenus.push(_menu);
3176
- } else {
3177
- validMenuList.push(_menu);
3265
+ quasisMap.set(item.refSlot, quasis);
3178
3266
  }
3267
+ var expandableSlot = quasisMap.get(item.refSlot);
3268
+ var refPosition = (_item$refPosition = item.refPosition) !== null && _item$refPosition !== void 0 ? _item$refPosition : -1;
3269
+ expandableSlot[clamp(refPosition < 0 ? expandableSlot.length + refPosition : refPosition, 0, expandableSlot.length - 1)].push(...((_externalSlots$item$$ = externalSlots === null || externalSlots === void 0 ? void 0 : (_externalSlots$item$$2 = externalSlots[item.$$reversedRef]) === null || _externalSlots$item$$2 === void 0 ? void 0 : _externalSlots$item$$2.bricks) !== null && _externalSlots$item$$ !== void 0 ? _externalSlots$item$$ : []));
3179
3270
  }
3180
3271
  }
3181
- return _objectSpread(_objectSpread({}, mainMenu), {}, {
3182
- items: validMenuList.flatMap(menu => processGroupInject(menu.items, menu, injectWithMenus, menuWithI18n)),
3183
- [symbolShouldCache]: shouldCacheList.every(Boolean),
3184
- [symbolMenuI18nNamespace]: menuWithI18n.get(mainMenu),
3185
- [symbolOverrideApp]: mainMenu.overrideApp
3186
- });
3187
- });
3188
- return _mergeMenu.apply(this, arguments);
3189
- }
3190
- function processGroupInject(items, menu, injectWithMenus, menuWithI18n) {
3191
- return items === null || items === void 0 ? void 0 : items.map(item => {
3192
- var _processGroupInject;
3193
- var foundInjectingMenus = item.groupId && injectWithMenus.get(item.groupId);
3194
- if (foundInjectingMenus) {
3195
- // Each menu to be injected with should be injected only once.
3196
- injectWithMenus.delete(item.groupId);
3197
- }
3198
- return _objectSpread(_objectSpread({}, item), {}, {
3199
- children: ((_processGroupInject = processGroupInject(item.children || item.items, menu, injectWithMenus, menuWithI18n)) !== null && _processGroupInject !== void 0 ? _processGroupInject : []).concat(foundInjectingMenus ? foundInjectingMenus.flatMap(injectingMenu => processGroupInject(injectingMenu.items, injectingMenu, injectWithMenus, menuWithI18n)) : []),
3200
- [symbolAppId]: menu.app[0].appId,
3201
- [symbolMenuI18nNamespace]: menuWithI18n.get(menu),
3202
- [symbolOverrideApp]: menu.overrideApp
3203
- });
3204
- });
3205
- }
3206
- function loadDynamicMenuItems(_x12, _x13, _x14) {
3207
- return _loadDynamicMenuItems.apply(this, arguments);
3208
- }
3209
- function _loadDynamicMenuItems() {
3210
- _loadDynamicMenuItems = _asyncToGenerator$3(function* (menu, kernel, menuWithI18n) {
3211
- if (menu.dynamicItems && menu.itemsResolve) {
3212
- var _menu$itemsResolve;
3213
- var itemsConf = {};
3214
- var overrideAppId = menu.app[0].appId;
3215
- var context = _internalApiGetCurrentContext();
3216
- var newContext = context;
3217
- if (overrideAppId !== context.app.id && attemptToVisit(menu.itemsResolve, ["APP", "I18N"])) {
3218
- if (window.STANDALONE_MICRO_APPS) {
3219
- if (menu.overrideApp) {
3220
- menu.overrideApp.config = deepFreeze(merge({}, menu.overrideApp.defaultConfig, menu.overrideApp.userConfig));
3221
- }
3222
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3223
- overrideApp: menu.overrideApp,
3224
- appendI18nNamespace: menuWithI18n.get(menu)
3225
- });
3226
- } else {
3227
- var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3228
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3229
- overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
3230
- appendI18nNamespace: menuWithI18n.get(menu)
3231
- });
3232
- }
3272
+ var _loop = function (slotName, _quasis) {
3273
+ if (!hasOwnProperty(slots, slotName)) {
3274
+ slots[slotName] = {
3275
+ type: "bricks",
3276
+ bricks: []
3277
+ };
3233
3278
  }
3234
- var usedActions = scanPermissionActionsInAny(menu.itemsResolve);
3235
- yield validatePermissions(usedActions);
3236
- yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
3237
- transform: "items",
3238
- transformMapArray: false
3239
- }, menu.itemsResolve), itemsConf, null, newContext);
3240
- menu.items = itemsConf.items;
3241
- if ((_menu$itemsResolve = menu.itemsResolve) !== null && _menu$itemsResolve !== void 0 && _menu$itemsResolve.args) {
3242
- var _menu$itemsResolve2;
3243
- return !attemptToVisit((_menu$itemsResolve2 = menu.itemsResolve) === null || _menu$itemsResolve2 === void 0 ? void 0 : _menu$itemsResolve2.args, ["QUERY", "PATH"]);
3279
+ var slotConf = slots[slotName];
3280
+ slotConf.bricks = _quasis.flatMap((bricks, index) => index < slotConf.bricks.length ? bricks.concat(slotConf.bricks[index]) : bricks);
3281
+ if (slotConf.bricks.length === 0) {
3282
+ delete slots[slotName];
3244
3283
  }
3284
+ };
3285
+ for (var [slotName, _quasis] of quasisMap.entries()) {
3286
+ _loop(slotName, _quasis);
3245
3287
  }
3246
- return true;
3247
- });
3248
- return _loadDynamicMenuItems.apply(this, arguments);
3249
- }
3250
- function walkMenuItems(menuItems) {
3251
- return menuItems === null || menuItems === void 0 ? void 0 : menuItems.filter(
3252
- // `if` is already evaluated.
3253
- looseCheckIfOfComputed).map(item => {
3254
- var children = walkMenuItems(item.children || item.items);
3255
- return item.type === "group" ? {
3256
- type: "group",
3257
- childLayout: item.childLayout,
3258
- title: item.text || item.title,
3259
- items: children,
3260
- groupId: item.groupId,
3261
- groupFrom: item.groupFrom
3262
- } : children !== null && children !== void 0 && children.length ? {
3263
- type: "subMenu",
3264
- childLayout: item.childLayout,
3265
- title: item.text || item.title,
3266
- icon: item.icon,
3267
- items: children,
3268
- defaultExpanded: item.defaultExpanded
3269
- } : item;
3270
- });
3271
- }
3272
- function processMenu(_x15, _x16, _x17, _x18, _x19) {
3273
- return _processMenu.apply(this, arguments);
3288
+ }
3289
+ return {
3290
+ [symbolForComputedPropsFromProxy]: computedPropsFromProxy,
3291
+ [symbolForRefForProxy]: refForProxy,
3292
+ [symbolForTplContextId]: templateContextId
3293
+ };
3274
3294
  }
3275
- function _processMenu() {
3276
- _processMenu = _asyncToGenerator$3(function* (menuId, context, kernel, hasSubMenu, isPreFetch) {
3277
- var _yield$fetchMenuById = yield fetchMenuById(menuId, kernel, isPreFetch),
3278
- {
3279
- items,
3280
- app
3281
- } = _yield$fetchMenuById,
3282
- restMenuData = _objectWithoutProperties(_yield$fetchMenuById, _excluded3);
3283
- var usedActions = scanPermissionActionsInAny([items, restMenuData]);
3284
- yield validatePermissions(usedActions);
3285
- var appsRequireI18nFulfilled = new Set();
3286
- var rootAppId = app[0].appId;
3287
- if (rootAppId !== context.app.id && !restMenuData[symbolMenuI18nNamespace]) {
3288
- appsRequireI18nFulfilled.add(rootAppId);
3295
+
3296
+ var _excluded$7 = ["properties", "slots"];
3297
+ function setupUseBrickInTemplate(props, proxyContext) {
3298
+ function walk(props) {
3299
+ if (Array.isArray(props)) {
3300
+ return props.map(walk);
3289
3301
  }
3290
- collectAppsRequireI18nFulfilled(items, context.app.id, appsRequireI18nFulfilled);
3291
- yield kernel.fulfilStoryboardI18n([...appsRequireI18nFulfilled]);
3292
- var menuData = _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(restMenuData, rootAppId, context, kernel)), {}, {
3293
- items: yield computeMenuItemsWithOverrideApp(items, context, kernel)
3294
- });
3295
- return {
3296
- title: yield processMenuTitle(menuData),
3297
- icon: menuData.icon,
3298
- link: menuData.link,
3299
- menuItems: walkMenuItems(menuData.items),
3300
- defaultCollapsed: menuData.defaultCollapsed || hasSubMenu,
3301
- defaultCollapsedBreakpoint: menuData.defaultCollapsedBreakpoint
3302
- };
3303
- });
3304
- return _processMenu.apply(this, arguments);
3305
- }
3306
- function collectAppsRequireI18nFulfilled(items, contextAppId, appIds) {
3307
- function collect(items) {
3308
- for (var _ref of items) {
3309
- var {
3310
- children
3311
- } = _ref,
3312
- rest = _objectWithoutProperties(_ref, _excluded$7);
3313
- var overrideAppId = rest[symbolAppId];
3314
- if (!rest[symbolMenuI18nNamespace] && overrideAppId !== contextAppId && !appIds.has(overrideAppId) && attemptToVisit(rest, ["I18N"])) {
3315
- appIds.add(overrideAppId);
3316
- }
3317
- children && collect(children);
3302
+ if (!isObject(props) || !isPlainObject(props)) {
3303
+ return props;
3318
3304
  }
3305
+ return Object.fromEntries(Object.entries(props).map(_ref => {
3306
+ var [key, value] = _ref;
3307
+ return isObject(value) && key === "useBrick" ? Array.isArray(value) ? [key, value.map(setup)] : [key, setup(value)] : [key, walk(value)];
3308
+ }).concat(Object.getOwnPropertySymbols(props).map(k => [k, props[k]])));
3319
3309
  }
3320
- collect(items);
3321
- }
3322
- function computeMenuItemsWithOverrideApp(items, context, kernel) {
3323
- return Promise.all(items.map( /*#__PURE__*/function () {
3324
- var _ref3 = _asyncToGenerator$3(function* (_ref2) {
3325
- var {
3326
- children
3327
- } = _ref2,
3328
- rest = _objectWithoutProperties(_ref2, _excluded2$2);
3329
- return _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
3330
- children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
3331
- });
3332
- });
3333
- return function (_x20) {
3334
- return _ref3.apply(this, arguments);
3335
- };
3336
- }()));
3310
+ function setup(item) {
3311
+ var {
3312
+ properties,
3313
+ slots: originalSlots
3314
+ } = item,
3315
+ restConf = _objectWithoutProperties(item, _excluded$7);
3316
+ var slots = Object.fromEntries(Object.entries(originalSlots !== null && originalSlots !== void 0 ? originalSlots : {}).map(_ref2 => {
3317
+ var _slotConf$bricks;
3318
+ var [slotName, slotConf] = _ref2;
3319
+ return [slotName, {
3320
+ type: "bricks",
3321
+ bricks: ((_slotConf$bricks = slotConf.bricks) !== null && _slotConf$bricks !== void 0 ? _slotConf$bricks : []).map(setup)
3322
+ }];
3323
+ }));
3324
+ return _objectSpread(_objectSpread({}, restConf), {}, {
3325
+ properties: walk(properties),
3326
+ slots
3327
+ }, setupTemplateProxy(proxyContext, restConf.ref, slots));
3328
+ }
3329
+ return walk(props);
3337
3330
  }
3338
- function processMenuTitle(_x21) {
3339
- return _processMenuTitle.apply(this, arguments);
3331
+ function isPlainObject(object) {
3332
+ return Object.prototype.toString.call(object) === "[object Object]";
3340
3333
  }
3341
- function _processMenuTitle() {
3342
- _processMenuTitle = _asyncToGenerator$3(function* (menuData) {
3343
- if (menuData.title || isEmpty(menuData.titleDataSource)) {
3344
- return menuData.title;
3334
+
3335
+ var computeRealValue = (value, context, injectDeep, internalOptions) => {
3336
+ var preEvaluated = isPreEvaluated(value);
3337
+ if (preEvaluated || typeof value === "string") {
3338
+ // For `useBrick`, some fields such as `properties`/`transform`/`events`/`if`,
3339
+ // are kept and to be evaluated later.
3340
+ var lazy = (internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.$$lazyForUseBrick) && isLazyContentInUseBrick(internalOptions.$$stateOfUseBrick);
3341
+ var result;
3342
+ var dismissRecursiveMarkingInjected = lazy;
3343
+ if (preEvaluated || isEvaluable(value)) {
3344
+ var runtimeContext = {};
3345
+ if (context) {
3346
+ var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId", "query", "match", "app", "segues"];
3347
+ for (var key of keys) {
3348
+ if (context[key]) {
3349
+ runtimeContext[key] = context[key];
3350
+ }
3351
+ }
3352
+ var simpleKeys = ["hash", "pathname"];
3353
+ for (var _key of simpleKeys) {
3354
+ if (hasOwnProperty(context, _key)) {
3355
+ runtimeContext[_key] = context[_key];
3356
+ }
3357
+ }
3358
+ }
3359
+ // The current runtime context is memoized even if the evaluation maybe lazy.
3360
+ result = evaluate(value, runtimeContext, {
3361
+ lazy
3362
+ });
3363
+ dismissRecursiveMarkingInjected = shouldDismissRecursiveMarkingInjected(value);
3364
+ } else {
3365
+ result = lazy ? value : inject(value, context);
3345
3366
  }
3346
- var cacheKey = JSON.stringify(menuData.titleDataSource);
3347
- if (menuTitleCache.has(cacheKey)) {
3348
- return menuTitleCache.get(cacheKey);
3367
+ if (!dismissRecursiveMarkingInjected) {
3368
+ recursiveMarkAsInjected(result);
3349
3369
  }
3350
- var {
3351
- objectId,
3352
- instanceId,
3353
- attributeId
3354
- } = menuData.titleDataSource;
3355
- var attr = attributeId !== null && attributeId !== void 0 ? attributeId : "name";
3356
- var instanceData = yield InstanceApi_getDetail(objectId, instanceId, {
3357
- fields: attr
3370
+ return result;
3371
+ }
3372
+ if (!(injectDeep && isObject(value)) || haveBeenInjected(value)) {
3373
+ return value;
3374
+ }
3375
+ if (Array.isArray(value)) {
3376
+ var nextOptions = getNextInternalOptions(internalOptions, true);
3377
+ return value.map(v => computeRealValue(v, context, injectDeep, nextOptions));
3378
+ }
3379
+ return Object.fromEntries(Object.entries(value).map(_ref => {
3380
+ var [k, v] = _ref;
3381
+ return [computeRealValue(k, context, false), computeRealValue(v, context, injectDeep, getNextInternalOptions(internalOptions, false, k))];
3382
+ }).concat(internalOptions !== null && internalOptions !== void 0 && internalOptions.ignoreSymbols ? [] : Object.getOwnPropertySymbols(value).map(k => [k, value[k]])));
3383
+ };
3384
+ function setProperties(bricks, properties, context, injectDeep) {
3385
+ var realProps = computeRealProperties(properties, context, injectDeep);
3386
+ if (context.tplContextId) {
3387
+ realProps = setupUseBrickInTemplate(realProps, {
3388
+ templateContextId: context.tplContextId
3358
3389
  });
3359
- var title;
3360
- if (attributeId === "#showKey" && Array.isArray(instanceData[attr])) {
3361
- var [primary, ...rest] = instanceData[attr];
3362
- title = rest.length > 0 ? "".concat(primary, "(").concat(rest.join(","), ")") : String(primary);
3363
- } else {
3364
- title = String(instanceData[attr]);
3365
- }
3366
- menuTitleCache.set(cacheKey, title);
3367
- return title;
3368
- });
3369
- return _processMenuTitle.apply(this, arguments);
3370
- }
3371
- function clearMenuTitleCache() {
3372
- menuTitleCache.clear();
3373
- }
3374
- function clearMenuCache() {
3375
- menuCache.clear();
3376
- }
3377
- function reorderMenu(menuData) {
3378
- menuData.items = reorderMenuItems(menuData.items);
3379
- }
3380
- function reorderMenuItems(list) {
3381
- return sortMenuItems(list).map(item => _objectSpread(_objectSpread({}, item), {}, {
3382
- children: reorderMenuItems(item.children)
3383
- }));
3384
- }
3385
- function sortMenuItems(list) {
3386
- return sortBy(list, item => {
3387
- var _item$sort;
3388
- return (_item$sort = item.sort) !== null && _item$sort !== void 0 ? _item$sort : -Infinity;
3390
+ }
3391
+ if (!Array.isArray(bricks)) {
3392
+ bricks = [bricks];
3393
+ }
3394
+ bricks.forEach(brick => {
3395
+ setRealProperties(brick, realProps);
3389
3396
  });
3390
3397
  }
3391
-
3392
- /**
3393
- * If the menu contains evaluations which use `APP` or `I18N`,
3394
- * we have to override app in context when computing real values.
3395
- */
3396
- function attemptToVisit(data, globals) {
3397
- var memo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakSet();
3398
- if (typeof data === "string") {
3399
- if (isEvaluable(data)) {
3400
- if (globals.some(key => data.includes(key))) {
3401
- var {
3402
- attemptToVisitGlobals
3403
- } = preevaluate(data);
3404
- return globals.some(key => attemptToVisitGlobals.has(key));
3398
+ function setRealProperties(brick, realProps, extractProps) {
3399
+ for (var [propName, propValue] of Object.entries(realProps)) {
3400
+ if (propName === "style" || propName === "dataset") {
3401
+ for (var [k, v] of Object.entries(propValue)) {
3402
+ brick[propName][k] = v;
3403
+ }
3404
+ } else if (propName === "innerHTML") {
3405
+ // `innerHTML` is dangerous, use `textContent` instead.
3406
+ // eslint-disable-next-line no-console
3407
+ console.error("Please use `textContent` instead of `innerHTML`.");
3408
+ brick.textContent = propValue;
3409
+ } else {
3410
+ if (extractProps) {
3411
+ set(brick, propName, propValue);
3412
+ } else {
3413
+ brick[propName] = propValue;
3405
3414
  }
3406
- } else if (globals.includes("APP")) {
3407
- return /\${\s*APP\s*\./.test(data);
3408
- }
3409
- } else if (isObject(data)) {
3410
- // Avoid call stack overflow.
3411
- // istanbul ignore next
3412
- if (memo.has(data)) {
3413
- return false;
3414
3415
  }
3415
- memo.add(data);
3416
- return (Array.isArray(data) ? data : Object.values(data)).some(item => attemptToVisit(item, globals, memo));
3417
3416
  }
3418
- return false;
3419
3417
  }
3420
- function computeRealValueWithOverrideApp(_x22, _x23, _x24, _x25) {
3421
- return _computeRealValueWithOverrideApp.apply(this, arguments);
3422
- }
3423
- function _computeRealValueWithOverrideApp() {
3424
- _computeRealValueWithOverrideApp = _asyncToGenerator$3(function* (data, overrideAppId, context, kernel) {
3425
- if ("titleDataSource" in data && isObject(data.titleDataSource) && Object.entries(data.titleDataSource).every(_ref7 => {
3426
- var [key, value] = _ref7;
3427
- return value === null || value === "";
3428
- })) {
3429
- delete data.titleDataSource;
3430
- }
3431
- if ("if" in data && data.if === null) {
3432
- delete data.if;
3433
- }
3434
- if ("to" in data && data.to && !isEvaluable(data.to)) {
3435
- var yaml = pipes.yaml(data.to);
3436
- if (isObject(yaml) && ["pathname", "search", "hash"].some(key => hasOwnProperty(yaml, key))) {
3437
- data.to = yaml;
3418
+ function computeRealProperties(properties, context, injectDeep, trackingContextList) {
3419
+ var result = {};
3420
+ if (isObject(properties)) {
3421
+ for (var [propName, propValue] of Object.entries(properties)) {
3422
+ // Related: https://github.com/facebook/react/issues/11347
3423
+ var realValue = computeRealValue(propValue, context, injectDeep, {
3424
+ $$lazyForUseBrick: true,
3425
+ $$stateOfUseBrick: propName === "useBrick" ? StateOfUseBrick.USE_BRICK : StateOfUseBrick.INITIAL
3426
+ });
3427
+ if (realValue !== undefined) {
3428
+ // For `style` and `dataset`, only object is acceptable.
3429
+ if (propName !== "style" && propName !== "dataset" || isObject(realValue)) {
3430
+ result[propName] = realValue;
3431
+ }
3438
3432
  }
3439
- }
3440
- var newContext = context;
3441
- if (overrideAppId !== context.app.id && attemptToVisit(data, ["APP", "I18N", "IMG"])) {
3442
- if (window.STANDALONE_MICRO_APPS) {
3443
- if (data[symbolOverrideApp]) {
3444
- data[symbolOverrideApp].config = deepFreeze(merge({}, data[symbolOverrideApp].defaultConfig, data[symbolOverrideApp].userConfig));
3433
+ if (Array.isArray(trackingContextList)) {
3434
+ var {
3435
+ contextNames,
3436
+ stateNames,
3437
+ formStateNames
3438
+ } = getTracks(propValue);
3439
+ if (contextNames || stateNames || formStateNames) {
3440
+ trackingContextList.push({
3441
+ contextNames,
3442
+ stateNames,
3443
+ formStateNames,
3444
+ propName,
3445
+ propValue
3446
+ });
3445
3447
  }
3446
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3447
- overrideApp: data[symbolOverrideApp],
3448
- appendI18nNamespace: data[symbolMenuI18nNamespace]
3449
- });
3450
- } else {
3451
- var storyboard = kernel.bootstrapData.storyboards.find(story => story.app.id === overrideAppId);
3452
- newContext = _objectSpread(_objectSpread({}, context), {}, {
3453
- overrideApp: storyboard === null || storyboard === void 0 ? void 0 : storyboard.app,
3454
- appendI18nNamespace: data[symbolMenuI18nNamespace]
3455
- });
3456
3448
  }
3457
3449
  }
3458
- var processors = scanProcessorsInAny(data);
3459
- yield kernel.loadDynamicBricks([], processors);
3460
- yield kernel.router.waitForUsedContext(data);
3461
- return computeRealValue(data, newContext, true, {
3462
- ignoreSymbols: true
3463
- });
3464
- });
3465
- return _computeRealValueWithOverrideApp.apply(this, arguments);
3450
+ }
3451
+ return result;
3452
+ }
3453
+ function getNextInternalOptions(internalOptions, isArray, key) {
3454
+ return internalOptions !== null && internalOptions !== void 0 && internalOptions.$$lazyForUseBrick ? _objectSpread(_objectSpread({}, internalOptions), {}, {
3455
+ $$stateOfUseBrick: getNextStateOfUseBrick(internalOptions.$$stateOfUseBrick, isArray, key)
3456
+ }) : internalOptions;
3457
+ }
3458
+
3459
+ var brickTemplateRegistry = new Map();
3460
+ function registerBrickTemplate(name, factory) {
3461
+ if (brickTemplateRegistry.has(name)) {
3462
+ // eslint-disable-next-line no-console
3463
+ console.error("Brick template of \"".concat(name, "\" already registered."));
3464
+ return;
3465
+ }
3466
+ brickTemplateRegistry.set(name, factory);
3466
3467
  }
3467
3468
 
3468
3469
  var lazyBrickRegistry = new Map();
@@ -3654,10 +3655,39 @@ function _dev_only_getAllContextValues(_ref2) {
3654
3655
  }
3655
3656
 
3656
3657
  /* istanbul ignore next */
3658
+ function _dev_only_debugDataValue(_x, _x2) {
3659
+ return _dev_only_debugDataValue2.apply(this, arguments);
3660
+ }
3661
+
3662
+ /* istanbul ignore next */
3663
+ function _dev_only_debugDataValue2() {
3664
+ _dev_only_debugDataValue2 = _asyncToGenerator$3(function* (debugData, _ref3) {
3665
+ var {
3666
+ tplContextId
3667
+ } = _ref3;
3668
+ var runtimeContext = _objectSpread(_objectSpread({}, _internalApiGetCurrentContext()), {}, {
3669
+ tplContextId
3670
+ });
3671
+ if (debugData.value) {
3672
+ return computeRealValue(debugData.value, runtimeContext, true);
3673
+ }
3674
+ var hasTransform = debugData.resolve.transform;
3675
+ var result = {};
3676
+ yield _internalApiGetResolver().resolveOne("reference", hasTransform ? debugData.resolve : _objectSpread(_objectSpread({}, debugData.resolve), {}, {
3677
+ transform: "value"
3678
+ }), result, null, runtimeContext, {
3679
+ cache: "reload"
3680
+ });
3681
+
3682
+ // 跟 v3 的数据结构保持一致,有 transform 时返回完整定义,无 transform 时直接返回数据
3683
+ return hasTransform ? result : result.value;
3684
+ });
3685
+ return _dev_only_debugDataValue2.apply(this, arguments);
3686
+ }
3657
3687
  function _dev_only_updateFormPreviewSettings(appId, formId, settings) {
3658
3688
  kernel._dev_only_updateFormPreviewSettings(appId, formId, settings);
3659
3689
  }
3660
- function _dev_only_render(_x, _x2) {
3690
+ function _dev_only_render(_x3, _x4) {
3661
3691
  return _dev_only_render2.apply(this, arguments);
3662
3692
  }
3663
3693
  function _dev_only_render2() {
@@ -14446,6 +14476,7 @@ var developHelper = {
14446
14476
  getAddedContracts: _dev_only_getAddedContracts,
14447
14477
  getContextValue: _dev_only_getContextValue,
14448
14478
  getAllContextValues: _dev_only_getAllContextValues,
14479
+ debugDataValue: _dev_only_debugDataValue,
14449
14480
  render: _dev_only_render,
14450
14481
  setRealTimeDataInspectRoot,
14451
14482
  addRealTimeDataInspectHook