@next-core/runtime 1.2.1 → 1.3.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.
Files changed (87) hide show
  1. package/dist/cjs/Dialog.js +49 -0
  2. package/dist/cjs/Dialog.js.map +1 -0
  3. package/dist/cjs/Notification.js +30 -0
  4. package/dist/cjs/Notification.js.map +1 -0
  5. package/dist/cjs/StoryboardFunctionRegistry.js +14 -0
  6. package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
  7. package/dist/cjs/handleHttpError.js +33 -18
  8. package/dist/cjs/handleHttpError.js.map +1 -1
  9. package/dist/cjs/index.js +19 -3
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/internal/CustomTemplates/utils.js +1 -1
  12. package/dist/cjs/internal/CustomTemplates/utils.js.map +1 -1
  13. package/dist/cjs/internal/Renderer.js +2 -3
  14. package/dist/cjs/internal/Renderer.js.map +1 -1
  15. package/dist/cjs/internal/Runtime.js +21 -11
  16. package/dist/cjs/internal/Runtime.js.map +1 -1
  17. package/dist/cjs/internal/bindListeners.js +7 -2
  18. package/dist/cjs/internal/bindListeners.js.map +1 -1
  19. package/dist/cjs/internal/compute/checkIf.js +4 -0
  20. package/dist/cjs/internal/compute/checkIf.js.map +1 -1
  21. package/dist/cjs/internal/compute/getNextStateOfUseBrick.js +4 -4
  22. package/dist/cjs/internal/compute/getNextStateOfUseBrick.js.map +1 -1
  23. package/dist/cjs/internal/enums.js +4 -4
  24. package/dist/cjs/internal/enums.js.map +1 -1
  25. package/dist/cjs/internal/historyExtended.js +21 -0
  26. package/dist/cjs/internal/historyExtended.js.map +1 -1
  27. package/dist/cjs/internal/i18n.js +31 -0
  28. package/dist/cjs/internal/i18n.js.map +1 -0
  29. package/dist/cjs/internal/mediaQuery.js +4 -4
  30. package/dist/cjs/internal/mediaQuery.js.map +1 -1
  31. package/dist/cjs/internal/secret_internals.js +5 -0
  32. package/dist/cjs/internal/secret_internals.js.map +1 -1
  33. package/dist/esm/CustomTemplates.js.map +1 -1
  34. package/dist/esm/Dialog.js +40 -0
  35. package/dist/esm/Dialog.js.map +1 -0
  36. package/dist/esm/Notification.js +21 -0
  37. package/dist/esm/Notification.js.map +1 -0
  38. package/dist/esm/StoryboardFunctionRegistry.js +12 -0
  39. package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
  40. package/dist/esm/handleHttpError.js +32 -17
  41. package/dist/esm/handleHttpError.js.map +1 -1
  42. package/dist/esm/index.js +4 -2
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js +2 -2
  45. package/dist/esm/internal/CustomTemplates/bindTemplateProxy.js.map +1 -1
  46. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js +2 -2
  47. package/dist/esm/internal/CustomTemplates/setupTemplateProxy.js.map +1 -1
  48. package/dist/esm/internal/CustomTemplates/utils.js +1 -1
  49. package/dist/esm/internal/CustomTemplates/utils.js.map +1 -1
  50. package/dist/esm/internal/Renderer.js +2 -3
  51. package/dist/esm/internal/Renderer.js.map +1 -1
  52. package/dist/esm/internal/Runtime.js +21 -11
  53. package/dist/esm/internal/Runtime.js.map +1 -1
  54. package/dist/esm/internal/bindListeners.js +7 -2
  55. package/dist/esm/internal/bindListeners.js.map +1 -1
  56. package/dist/esm/internal/checkInstalledApps.js.map +1 -1
  57. package/dist/esm/internal/compute/checkIf.js +5 -0
  58. package/dist/esm/internal/compute/checkIf.js.map +1 -1
  59. package/dist/esm/internal/compute/getNextStateOfUseBrick.js +3 -3
  60. package/dist/esm/internal/compute/getNextStateOfUseBrick.js.map +1 -1
  61. package/dist/esm/internal/compute/listenOnTrackingContext.js.map +1 -1
  62. package/dist/esm/internal/data/DataStore.js.map +1 -1
  63. package/dist/esm/internal/data/FlowApiProvider.js +6 -6
  64. package/dist/esm/internal/data/FlowApiProvider.js.map +1 -1
  65. package/dist/esm/internal/enums.js +3 -3
  66. package/dist/esm/internal/enums.js.map +1 -1
  67. package/dist/esm/internal/historyExtended.js +21 -0
  68. package/dist/esm/internal/historyExtended.js.map +1 -1
  69. package/dist/esm/internal/i18n.js +22 -0
  70. package/dist/esm/internal/i18n.js.map +1 -0
  71. package/dist/esm/internal/loadBootstrapData.js +19 -18
  72. package/dist/esm/internal/loadBootstrapData.js.map +1 -1
  73. package/dist/esm/internal/mediaQuery.js +3 -3
  74. package/dist/esm/internal/mediaQuery.js.map +1 -1
  75. package/dist/esm/internal/menu/interfaces.js +4 -0
  76. package/dist/esm/internal/menu/interfaces.js.map +1 -1
  77. package/dist/esm/internal/menu/mergeMenu.js +11 -10
  78. package/dist/esm/internal/menu/mergeMenu.js.map +1 -1
  79. package/dist/esm/internal/secret_internals.js +5 -0
  80. package/dist/esm/internal/secret_internals.js.map +1 -1
  81. package/dist/types/Dialog.d.ts +14 -0
  82. package/dist/types/Notification.d.ts +10 -0
  83. package/dist/types/index.d.ts +4 -1
  84. package/dist/types/internal/Runtime.d.ts +1 -4
  85. package/dist/types/internal/i18n.d.ts +14 -0
  86. package/dist/types/tsdoc-metadata.json +11 -0
  87. package/package.json +16 -12
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.mediaEventTarget = exports.mediaBreakpointMinWidthMap = exports.getMedia = exports.MediaBreakpoint = void 0;
8
8
  var _eventTarget = _interopRequireDefault(require("@ungap/event-target"));
9
- let MediaBreakpoint;
10
- exports.MediaBreakpoint = MediaBreakpoint;
11
- (function (MediaBreakpoint) {
9
+ let MediaBreakpoint = /*#__PURE__*/function (MediaBreakpoint) {
12
10
  MediaBreakpoint["xLarge"] = "xLarge";
13
11
  MediaBreakpoint["large"] = "large";
14
12
  MediaBreakpoint["medium"] = "medium";
15
13
  MediaBreakpoint["small"] = "small";
16
14
  MediaBreakpoint["xSmall"] = "xSmall";
17
- })(MediaBreakpoint || (exports.MediaBreakpoint = MediaBreakpoint = {}));
15
+ return MediaBreakpoint;
16
+ }({});
17
+ exports.MediaBreakpoint = MediaBreakpoint;
18
18
  const mediaBreakpointMinWidthMap = new Map([[MediaBreakpoint.xLarge, "1920px"], [MediaBreakpoint.large, "1600px"], [MediaBreakpoint.medium, "1280px"], [MediaBreakpoint.small, "1024px"], [MediaBreakpoint.xSmall, 0]]);
19
19
  exports.mediaBreakpointMinWidthMap = mediaBreakpointMinWidthMap;
20
20
  const mediaEventTarget = new _eventTarget.default();
@@ -1 +1 @@
1
- {"version":3,"file":"mediaQuery.js","names":["_eventTarget","_interopRequireDefault","require","MediaBreakpoint","exports","mediaBreakpointMinWidthMap","Map","xLarge","large","medium","small","xSmall","mediaEventTarget","EventTarget","breakpointMatchesMap","MEDIA","handleMatchesChange","data","breakpoint","changed","matches","dispatchEvent","CustomEvent","detail","forEach","minWidth","mediaQueryList","window","matchMedia","addEventListener","event","addListener","getMedia"],"sources":["../../../src/internal/mediaQuery.ts"],"sourcesContent":["import EventTarget from \"@ungap/event-target\";\n\nexport interface Media {\n breakpoint?: MediaBreakpoint;\n}\n\nexport enum MediaBreakpoint {\n xLarge = \"xLarge\",\n large = \"large\",\n medium = \"medium\",\n small = \"small\",\n xSmall = \"xSmall\",\n}\n\nexport const mediaBreakpointMinWidthMap = new Map<\n MediaBreakpoint,\n string | number\n>([\n [MediaBreakpoint.xLarge, \"1920px\"],\n [MediaBreakpoint.large, \"1600px\"],\n [MediaBreakpoint.medium, \"1280px\"],\n [MediaBreakpoint.small, \"1024px\"],\n [MediaBreakpoint.xSmall, 0],\n]);\nexport const mediaEventTarget = new EventTarget();\n\nconst breakpointMatchesMap: Partial<Record<MediaBreakpoint, boolean>> = {};\nconst MEDIA: Media = {};\n\nfunction handleMatchesChange(\n data: { readonly matches: boolean; readonly media: string },\n breakpoint: MediaBreakpoint\n): void {\n let changed = false;\n breakpointMatchesMap[breakpoint] = data.matches;\n\n for (const [breakpoint] of mediaBreakpointMinWidthMap) {\n if (breakpointMatchesMap[breakpoint] && MEDIA.breakpoint !== breakpoint) {\n MEDIA.breakpoint = breakpoint;\n changed = true;\n break;\n }\n }\n\n if (changed) {\n mediaEventTarget.dispatchEvent(\n new CustomEvent(\"change\", { detail: MEDIA })\n );\n }\n}\n\nmediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {\n const mediaQueryList = window.matchMedia(`(min-width: ${minWidth})`);\n\n handleMatchesChange(mediaQueryList, breakpoint);\n\n if (mediaQueryList.addEventListener) {\n mediaQueryList.addEventListener(\"change\", (event) => {\n handleMatchesChange(event, breakpoint);\n });\n } else {\n mediaQueryList.addListener((event) => {\n handleMatchesChange(event, breakpoint);\n });\n }\n});\n\nexport const getMedia = (): Media => MEDIA;\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8C,IAMlCC,eAAe;AAAAC,OAAA,CAAAD,eAAA,GAAAA,eAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,KAAAC,OAAA,CAAAD,eAAA,GAAfA,eAAe;AAQpB,MAAME,0BAA0B,GAAG,IAAIC,GAAG,CAG/C,CACA,CAACH,eAAe,CAACI,MAAM,EAAE,QAAQ,CAAC,EAClC,CAACJ,eAAe,CAACK,KAAK,EAAE,QAAQ,CAAC,EACjC,CAACL,eAAe,CAACM,MAAM,EAAE,QAAQ,CAAC,EAClC,CAACN,eAAe,CAACO,KAAK,EAAE,QAAQ,CAAC,EACjC,CAACP,eAAe,CAACQ,MAAM,EAAE,CAAC,CAAC,CAC5B,CAAC;AAACP,OAAA,CAAAC,0BAAA,GAAAA,0BAAA;AACI,MAAMO,gBAAgB,GAAG,IAAIC,oBAAW,EAAE;AAACT,OAAA,CAAAQ,gBAAA,GAAAA,gBAAA;AAElD,MAAME,oBAA+D,GAAG,CAAC,CAAC;AAC1E,MAAMC,KAAY,GAAG,CAAC,CAAC;AAEvB,SAASC,mBAAmBA,CAC1BC,IAA2D,EAC3DC,UAA2B,EACrB;EACN,IAAIC,OAAO,GAAG,KAAK;EACnBL,oBAAoB,CAACI,UAAU,CAAC,GAAGD,IAAI,CAACG,OAAO;EAE/C,KAAK,MAAM,CAACF,UAAU,CAAC,IAAIb,0BAA0B,EAAE;IACrD,IAAIS,oBAAoB,CAACI,UAAU,CAAC,IAAIH,KAAK,CAACG,UAAU,KAAKA,UAAU,EAAE;MACvEH,KAAK,CAACG,UAAU,GAAGA,UAAU;MAC7BC,OAAO,GAAG,IAAI;MACd;IACF;EACF;EAEA,IAAIA,OAAO,EAAE;IACXP,gBAAgB,CAACS,aAAa,CAC5B,IAAIC,WAAW,CAAC,QAAQ,EAAE;MAAEC,MAAM,EAAER;IAAM,CAAC,CAAC,CAC7C;EACH;AACF;AAEAV,0BAA0B,CAACmB,OAAO,CAAC,CAACC,QAAQ,EAAEP,UAAU,KAAK;EAC3D,MAAMQ,cAAc,GAAGC,MAAM,CAACC,UAAU,CAAE,eAAcH,QAAS,GAAE,CAAC;EAEpET,mBAAmB,CAACU,cAAc,EAAER,UAAU,CAAC;EAE/C,IAAIQ,cAAc,CAACG,gBAAgB,EAAE;IACnCH,cAAc,CAACG,gBAAgB,CAAC,QAAQ,EAAGC,KAAK,IAAK;MACnDd,mBAAmB,CAACc,KAAK,EAAEZ,UAAU,CAAC;IACxC,CAAC,CAAC;EACJ,CAAC,MAAM;IACLQ,cAAc,CAACK,WAAW,CAAED,KAAK,IAAK;MACpCd,mBAAmB,CAACc,KAAK,EAAEZ,UAAU,CAAC;IACxC,CAAC,CAAC;EACJ;AACF,CAAC,CAAC;AAEK,MAAMc,QAAQ,GAAGA,CAAA,KAAajB,KAAK;AAACX,OAAA,CAAA4B,QAAA,GAAAA,QAAA"}
1
+ {"version":3,"file":"mediaQuery.js","names":["_eventTarget","_interopRequireDefault","require","MediaBreakpoint","exports","mediaBreakpointMinWidthMap","Map","xLarge","large","medium","small","xSmall","mediaEventTarget","EventTarget","breakpointMatchesMap","MEDIA","handleMatchesChange","data","breakpoint","changed","matches","dispatchEvent","CustomEvent","detail","forEach","minWidth","mediaQueryList","window","matchMedia","addEventListener","event","addListener","getMedia"],"sources":["../../../src/internal/mediaQuery.ts"],"sourcesContent":["import EventTarget from \"@ungap/event-target\";\n\nexport interface Media {\n breakpoint?: MediaBreakpoint;\n}\n\nexport enum MediaBreakpoint {\n xLarge = \"xLarge\",\n large = \"large\",\n medium = \"medium\",\n small = \"small\",\n xSmall = \"xSmall\",\n}\n\nexport const mediaBreakpointMinWidthMap = new Map<\n MediaBreakpoint,\n string | number\n>([\n [MediaBreakpoint.xLarge, \"1920px\"],\n [MediaBreakpoint.large, \"1600px\"],\n [MediaBreakpoint.medium, \"1280px\"],\n [MediaBreakpoint.small, \"1024px\"],\n [MediaBreakpoint.xSmall, 0],\n]);\nexport const mediaEventTarget = new EventTarget();\n\nconst breakpointMatchesMap: Partial<Record<MediaBreakpoint, boolean>> = {};\nconst MEDIA: Media = {};\n\nfunction handleMatchesChange(\n data: { readonly matches: boolean; readonly media: string },\n breakpoint: MediaBreakpoint\n): void {\n let changed = false;\n breakpointMatchesMap[breakpoint] = data.matches;\n\n for (const [breakpoint] of mediaBreakpointMinWidthMap) {\n if (breakpointMatchesMap[breakpoint] && MEDIA.breakpoint !== breakpoint) {\n MEDIA.breakpoint = breakpoint;\n changed = true;\n break;\n }\n }\n\n if (changed) {\n mediaEventTarget.dispatchEvent(\n new CustomEvent(\"change\", { detail: MEDIA })\n );\n }\n}\n\nmediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {\n const mediaQueryList = window.matchMedia(`(min-width: ${minWidth})`);\n\n handleMatchesChange(mediaQueryList, breakpoint);\n\n if (mediaQueryList.addEventListener) {\n mediaQueryList.addEventListener(\"change\", (event) => {\n handleMatchesChange(event, breakpoint);\n });\n } else {\n mediaQueryList.addListener((event) => {\n handleMatchesChange(event, breakpoint);\n });\n }\n});\n\nexport const getMedia = (): Media => MEDIA;\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA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AV,0BAA0B,CAACmB,OAAO,CAAC,CAACC,QAAQ,EAAEP,UAAU,KAAK;EAC3D,MAAMQ,cAAc,GAAGC,MAAM,CAACC,UAAU,CAAE,eAAcH,QAAS,GAAE,CAAC;EAEpET,mBAAmB,CAACU,cAAc,EAAER,UAAU,CAAC;EAE/C,IAAIQ,cAAc,CAACG,gBAAgB,EAAE;IACnCH,cAAc,CAACG,gBAAgB,CAAC,QAAQ,EAAGC,KAAK,IAAK;MACnDd,mBAAmB,CAACc,KAAK,EAAEZ,UAAU,CAAC;IACxC,CAAC,CAAC;EACJ,CAAC,MAAM;IACLQ,cAAc,CAACK,WAAW,CAAED,KAAK,IAAK;MACpCd,mBAAmB,CAACc,KAAK,EAAEZ,UAAU,CAAC;IACxC,CAAC,CAAC;EACJ;AACF,CAAC,CAAC;AAEK,MAAMc,QAAQ,GAAGA,CAAA,KAAajB,KAAK;AAACX,OAAA,CAAA4B,QAAA,GAAAA,QAAA"}
@@ -29,6 +29,8 @@ var _computeRealValue = require("./compute/computeRealValue.js");
29
29
  var _isStrictMode = require("../isStrictMode.js");
30
30
  var _CustomTemplates = require("../CustomTemplates.js");
31
31
  var _registerAppI18n = require("./registerAppI18n.js");
32
+ var _Notification = require("../Notification.js");
33
+ var _Dialog = require("../Dialog.js");
32
34
  async function renderUseBrick(useBrick, data) {
33
35
  var _runtimeContext$tplSt, _output$node;
34
36
  const tplStateStoreScope = [];
@@ -107,6 +109,9 @@ function unmountUseBrick({
107
109
  let _rendererContext;
108
110
  function initializePreviewBootstrap(bootstrapData) {
109
111
  (0, _Runtime._internalApiSetBootstrapData)(bootstrapData);
112
+ // Todo: allow configuration of notification bricks.
113
+ (0, _Notification.loadNotificationService)("shoelace.show-notification");
114
+ (0, _Dialog.loadDialogService)("shoelace.show-dialog");
110
115
  }
111
116
  async function renderPreviewBricks(bricks, mountPoints, options = {}) {
112
117
  const runtimeContext = {
@@ -1 +1 @@
1
- {"version":3,"file":"secret_internals.js","names":["_loader","require","_lodash","_Runtime","_Renderer","_RendererContext","_mount","_handleHttpError","_themeAndMode","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","renderUseBrick","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","flushStableLoadBricks","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","_rendererContext","initializePreviewBootstrap","bootstrapData","_internalApiSetBootstrapData","renderPreviewBricks","bricks","mountPoints","options","previousRendererContext","container","main","failed","renderBricks","push","values","error","BRICK","textContent","httpErrorToString","return","menuRequests","sandbox","_options$theme","setTheme","theme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","window","scrollTo","dispatchPageLoad","legacyDoTransform","to","computeRealValue","noInject","loadBricks","loadBricksImperatively","getBrickPackages","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","exports","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BootstrapData,\n BrickConf,\n CustomTemplate,\n RouteConf,\n SiteTheme,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport {\n flushStableLoadBricks,\n loadBricksImperatively,\n} from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n _internalApiSetBootstrapData,\n getBrickPackages,\n} from \"./Runtime.js\";\nimport { RenderOutput, renderBrick, renderBricks } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { httpErrorToString } from \"../handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"../themeAndMode.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"useBrick\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...tplStateStoreScope.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\nlet _rendererContext: RendererContext;\n\nexport function initializePreviewBootstrap(\n bootstrapData: Partial<BootstrapData>\n) {\n _internalApiSetBootstrapData(bootstrapData);\n}\n\nexport async function renderPreviewBricks(\n bricks: BrickConf[],\n mountPoints: {\n main: HTMLElement;\n portal: HTMLElement;\n },\n options: {\n sandbox?: boolean;\n theme?: SiteTheme;\n } = {}\n) {\n const runtimeContext = {\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = _rendererContext;\n const rendererContext = (_rendererContext = new RendererContext(\"router\"));\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container: mountPoints.main,\n createPortal: mountPoints.portal,\n };\n\n let failed = false;\n let output: RenderOutput;\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n output.blockingList.push(\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck\n );\n\n flushStableLoadBricks();\n\n await Promise.all(output.blockingList);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispose();\n unmountTree(mountPoints.main);\n unmountTree(mountPoints.portal);\n\n if (options.sandbox) {\n setTheme(options.theme ?? \"light\");\n setMode(\"default\");\n\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (options.sandbox) {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n}\n\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\n// istanbul ignore next\nexport function loadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAMA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,iBAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,gBAAA,GAAAX,OAAA;AACA,IAAAY,gBAAA,GAAAZ,OAAA;AAQO,eAAea,cAAcA,CAClCC,QAA4B,EAC5BC,IAAa,EACkB;EAAA,IAAAC,qBAAA,EAAAC,YAAA;EAC/B,MAAMC,kBAAwC,GAAG,EAAE;EACnD,MAAMC,cAA8B,GAAG;IACrC,GAAG,IAAAC,sCAA6B,GAAG;IACnCL,IAAI;IACJM,0BAA0B,EAAE,EAAE;IAC9BH;EACF,CAAC;EAED,CAAAF,qBAAA,GAAAG,cAAc,CAACG,gBAAgB,cAAAN,qBAAA,cAAAA,qBAAA,GAA/BG,cAAc,CAACG,gBAAgB,GAAK,IAAIC,GAAG,EAAE;EAE7C,MAAMC,eAAe,GAAG,IAAIC,gCAAe,CAAC,UAAU,CAAC;EAEvD,MAAMC,UAAsB,GAAG;IAC7BC,GAAG,EAAEC,gBAAS,CAACC,IAAI;IACnB;IACAC,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B,MAAM,CAACG,OAAO,CAACwB,eAAe,CAAC;EACjC,CAAC,MAAM;IACL3B,MAAM,CAAC6B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
1
+ {"version":3,"file":"secret_internals.js","names":["_loader","require","_lodash","_Runtime","_Renderer","_RendererContext","_mount","_handleHttpError","_themeAndMode","_enums","_computeRealValue","_isStrictMode","_CustomTemplates","_registerAppI18n","_Notification","_Dialog","renderUseBrick","useBrick","data","_runtimeContext$tplSt","_output$node","tplStateStoreScope","runtimeContext","_internalApiGetRuntimeContext","pendingPermissionsPreCheck","tplStateStoreMap","Map","rendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","createPortal","transform","strict","isStrictMode","warnAboutStrictMode","output","renderBrick","properties","flushStableLoadBricks","Promise","all","blockingList","map","store","waitForAll","node","portal","Error","child","tagName","type","mountUseBrick","element","portalRoot","document","querySelector","createElement","appendChild","mountTree","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmountUseBrick","mountResult","unmountTree","remove","dispatchOnUnmount","dispose","_rendererContext","initializePreviewBootstrap","bootstrapData","_internalApiSetBootstrapData","loadNotificationService","loadDialogService","renderPreviewBricks","bricks","mountPoints","options","previousRendererContext","container","main","failed","renderBricks","push","values","error","BRICK","textContent","httpErrorToString","return","menuRequests","sandbox","_options$theme","setTheme","theme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","window","scrollTo","dispatchPageLoad","legacyDoTransform","to","computeRealValue","noInject","loadBricks","loadBricksImperatively","getBrickPackages","updateStoryboard","appId","storyboardPatch","storyboard","_internalApiGetStoryboardInBootstrapData","Object","assign","$$fulfilling","$$fulfilled","$$registerCustomTemplateProcessed","registerAppI18n","updateStoryboardByRoute","newRoute","match","getKey","route","path","exact","replaceRoute","routes","key","routeKey","unshift","updateStoryboardByTemplate","newTemplate","settings","tplName","name","customTemplates","define","proxy","state","updateTemplatePreviewSettings","templateId","_updatePreviewSettings","brick","pick","updateStoryboardBySnippet","snippetData","_snippetData$bricks","snippetId","length","updateSnippetPreviewSettings","exports","previewRouteIndex","findIndex","newPreviewRoute","menu","splice"],"sources":["../../../src/internal/secret_internals.ts"],"sourcesContent":["import type {\n BootstrapData,\n BrickConf,\n CustomTemplate,\n RouteConf,\n SiteTheme,\n Storyboard,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport {\n flushStableLoadBricks,\n loadBricksImperatively,\n} from \"@next-core/loader\";\nimport { pick } from \"lodash\";\nimport {\n _internalApiGetRuntimeContext,\n _internalApiGetStoryboardInBootstrapData,\n _internalApiSetBootstrapData,\n getBrickPackages,\n} from \"./Runtime.js\";\nimport { RenderOutput, renderBrick, renderBricks } from \"./Renderer.js\";\nimport { RendererContext } from \"./RendererContext.js\";\nimport type { DataStore } from \"./data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./interfaces.js\";\nimport { mountTree, unmountTree } from \"./mount.js\";\nimport { httpErrorToString } from \"../handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"../themeAndMode.js\";\nimport { RenderTag } from \"./enums.js\";\nimport { computeRealValue } from \"./compute/computeRealValue.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"../isStrictMode.js\";\nimport { customTemplates } from \"../CustomTemplates.js\";\nimport { registerAppI18n } from \"./registerAppI18n.js\";\nimport { loadNotificationService } from \"../Notification.js\";\nimport { loadDialogService } from \"../Dialog.js\";\n\nexport interface RenderUseBrickResult {\n tagName: string | null;\n renderRoot: RenderRoot;\n rendererContext: RendererContext;\n}\n\nexport async function renderUseBrick(\n useBrick: UseSingleBrickConf,\n data: unknown\n): Promise<RenderUseBrickResult> {\n const tplStateStoreScope: DataStore<\"STATE\">[] = [];\n const runtimeContext: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n data,\n pendingPermissionsPreCheck: [],\n tplStateStoreScope,\n };\n\n runtimeContext.tplStateStoreMap ??= new Map();\n\n const rendererContext = new RendererContext(\"useBrick\");\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n // Will set during `mountUseBrick`\n createPortal: null!,\n };\n\n const transform = (useBrick as { transform?: Record<string, unknown> })\n .transform;\n const strict = isStrictMode();\n if (transform) {\n warnAboutStrictMode(\n strict,\n \"`useBrick.transform`\",\n 'please use \"properties\" instead, check your useBrick:',\n useBrick\n );\n }\n\n const output = await renderBrick(\n renderRoot,\n strict\n ? useBrick\n : {\n ...useBrick,\n properties: {\n ...useBrick.properties,\n ...transform,\n },\n },\n runtimeContext,\n rendererContext\n );\n\n flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n // Wait for local tpl state stores belong to current `useBrick` only.\n ...tplStateStoreScope.map((store) => store.waitForAll()),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\n\n if (output.node?.portal) {\n throw new Error(\"The root brick of useBrick cannot be a portal brick\");\n }\n\n renderRoot.child = output.node;\n\n const tagName = output.node ? output.node.type : null;\n\n return { tagName, renderRoot, rendererContext };\n}\n\nexport interface MountUseBrickResult {\n portal?: HTMLElement;\n}\n\nexport function mountUseBrick(\n { renderRoot, rendererContext }: RenderUseBrickResult,\n element: HTMLElement\n): MountUseBrickResult {\n let portal: HTMLElement | undefined;\n renderRoot.createPortal = () => {\n const portalRoot = document.querySelector(\n \"#portal-mount-point\"\n ) as HTMLElement;\n portal = document.createElement(\"div\");\n portalRoot.appendChild(portal);\n return portal;\n };\n\n mountTree(renderRoot, element);\n\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n\n return {\n portal,\n };\n}\n\nexport function unmountUseBrick(\n { rendererContext }: RenderUseBrickResult,\n mountResult: MountUseBrickResult\n): void {\n // if (mountResult.mainBrick) {\n // mountResult.mainBrick.unmount();\n // }\n if (mountResult.portal) {\n unmountTree(mountResult.portal);\n mountResult.portal.remove();\n }\n rendererContext.dispatchOnUnmount();\n rendererContext.dispose();\n}\n\nlet _rendererContext: RendererContext;\n\nexport function initializePreviewBootstrap(\n bootstrapData: Partial<BootstrapData>\n) {\n _internalApiSetBootstrapData(bootstrapData);\n // Todo: allow configuration of notification bricks.\n loadNotificationService(\"shoelace.show-notification\");\n loadDialogService(\"shoelace.show-dialog\");\n}\n\nexport async function renderPreviewBricks(\n bricks: BrickConf[],\n mountPoints: {\n main: HTMLElement;\n portal: HTMLElement;\n },\n options: {\n sandbox?: boolean;\n theme?: SiteTheme;\n } = {}\n) {\n const runtimeContext = {\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = _rendererContext;\n const rendererContext = (_rendererContext = new RendererContext(\"router\"));\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container: mountPoints.main,\n createPortal: mountPoints.portal,\n };\n\n let failed = false;\n let output: RenderOutput;\n try {\n output = await renderBricks(\n renderRoot,\n bricks,\n runtimeContext,\n rendererContext\n );\n\n output.blockingList.push(\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck\n );\n\n flushStableLoadBricks();\n\n await Promise.all(output.blockingList);\n } catch (error) {\n failed = true;\n output = {\n node: {\n tag: RenderTag.BRICK,\n type: \"div\",\n properties: {\n textContent: httpErrorToString(error),\n },\n return: renderRoot,\n runtimeContext: null!,\n },\n blockingList: [],\n menuRequests: [],\n };\n }\n\n renderRoot.child = output.node;\n\n previousRendererContext?.dispose();\n unmountTree(mountPoints.main);\n unmountTree(mountPoints.portal);\n\n if (options.sandbox) {\n setTheme(options.theme ?? \"light\");\n setMode(\"default\");\n\n if (!failed) {\n rendererContext.dispatchBeforePageLoad();\n }\n\n applyTheme();\n applyMode();\n }\n\n mountTree(renderRoot);\n\n if (options.sandbox) {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n}\n\nexport function legacyDoTransform(\n data: unknown,\n to: unknown,\n options?: unknown\n) {\n if (options) {\n throw new Error(\"Legacy doTransform does not support options in v3\");\n }\n return computeRealValue(\n to,\n {\n ..._internalApiGetRuntimeContext()!,\n data,\n },\n {\n noInject: true,\n }\n );\n}\n\n// istanbul ignore next\nexport function loadBricks(bricks: string[] | Set<string>) {\n return loadBricksImperatively(bricks, getBrickPackages());\n}\n\nexport function updateStoryboard(\n appId: string,\n storyboardPatch: Partial<Storyboard>\n): void {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n Object.assign(storyboard, {\n ...storyboardPatch,\n $$fulfilling: null,\n $$fulfilled: true,\n $$registerCustomTemplateProcessed: false,\n });\n registerAppI18n(storyboard);\n}\n\nexport function updateStoryboardByRoute(appId: string, newRoute: RouteConf) {\n const storyboard = _internalApiGetStoryboardInBootstrapData(appId)!;\n let match = false;\n const getKey = (route: RouteConf): string => `${route.path}.${route.exact}`;\n const replaceRoute = (routes: RouteConf[], key: string): RouteConf[] => {\n return routes.map((route) => {\n const routeKey = getKey(route);\n if (route.type === \"routes\") {\n route.routes = replaceRoute(route.routes, key);\n return route;\n } else if (routeKey === key) {\n match = true;\n return newRoute;\n } else {\n return route;\n }\n });\n };\n storyboard.routes = replaceRoute(storyboard.routes, getKey(newRoute));\n if (!match) {\n storyboard.routes.unshift(newRoute);\n }\n}\n\nexport function updateStoryboardByTemplate(\n appId: string,\n newTemplate: CustomTemplate,\n settings: unknown\n): void {\n const tplName = `${appId}.${newTemplate.name}`;\n // customTemplateRegistry.delete(tplName);\n customTemplates.define(tplName, {\n bricks: newTemplate.bricks,\n proxy: newTemplate.proxy,\n state: newTemplate.state,\n });\n updateTemplatePreviewSettings(appId, newTemplate.name, settings);\n}\n\nexport function updateTemplatePreviewSettings(\n appId: string,\n templateId: string,\n settings?: unknown\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/template-preview/${templateId}`,\n [\n {\n brick: templateId,\n ...pick(settings, \"properties\", \"events\", \"lifeCycle\", \"context\"),\n },\n ]\n );\n}\n\nexport function updateStoryboardBySnippet(\n appId: string,\n snippetData: {\n snippetId: string;\n bricks?: BrickConf[];\n }\n): void {\n _updatePreviewSettings(\n appId,\n `\\${APP.homepage}/_dev_only_/snippet-preview/${snippetData.snippetId}`,\n snippetData.bricks?.length ? snippetData.bricks : [{ brick: \"span\" }]\n );\n}\n\nexport const updateSnippetPreviewSettings = updateStoryboardBySnippet;\n\nfunction _updatePreviewSettings(\n appId: string,\n path: string,\n bricks: BrickConf[]\n) {\n const { routes } = _internalApiGetStoryboardInBootstrapData(appId)!;\n const previewRouteIndex = routes.findIndex((route) => route.path === path);\n const newPreviewRoute: RouteConf = {\n path,\n bricks,\n menu: false,\n exact: true,\n };\n if (previewRouteIndex === -1) {\n routes.unshift(newPreviewRoute);\n } else {\n routes.splice(previewRouteIndex, 1, newPreviewRoute);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AASA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAMA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AAGA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,iBAAA,GAAAT,OAAA;AACA,IAAAU,aAAA,GAAAV,OAAA;AACA,IAAAW,gBAAA,GAAAX,OAAA;AACA,IAAAY,gBAAA,GAAAZ,OAAA;AACA,IAAAa,aAAA,GAAAb,OAAA;AACA,IAAAc,OAAA,GAAAd,OAAA;AAQO,eAAee,cAAcA,CAClCC,QAA4B,EAC5BC,IAAa,EACkB;EAAA,IAAAC,qBAAA,EAAAC,YAAA;EAC/B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AAC,CACtE;AACH;AAEO,MAAMO,4BAA4B,GAAGL,yBAAyB;AAACM,OAAA,CAAAD,4BAAA,GAAAA,4BAAA;AAEtE,SAASR,sBAAsBA,CAC7BjC,KAAa,EACbe,IAAY,EACZlD,MAAmB,EACnB;EACA,MAAM;IAAEqD;EAAO,CAAC,GAAG,IAAAf,iDAAwC,EAACH,KAAK,CAAE;EACnE,MAAM2C,iBAAiB,GAAGzB,MAAM,CAAC0B,SAAS,CAAE9B,KAAK,IAAKA,KAAK,CAACC,IAAI,KAAKA,IAAI,CAAC;EAC1E,MAAM8B,eAA0B,GAAG;IACjC9B,IAAI;IACJlD,MAAM;IACNiF,IAAI,EAAE,KAAK;IACX9B,KAAK,EAAE;EACT,CAAC;EACD,IAAI2B,iBAAiB,KAAK,CAAC,CAAC,EAAE;IAC5BzB,MAAM,CAACG,OAAO,CAACwB,eAAe,CAAC;EACjC,CAAC,MAAM;IACL3B,MAAM,CAAC6B,MAAM,CAACJ,iBAAiB,EAAE,CAAC,EAAEE,eAAe,CAAC;EACtD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"CustomTemplates.js","names":["uniq","isStrictMode","warnAboutStrictMode","allowedNativeProps","Set","_registry","WeakMap","CustomTemplateRegistry","constructor","_classPrivateFieldInitSpec","writable","value","Map","define","tagName","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","_classPrivateFieldGet","has","console","warn","concat","customElements","get","strict","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","Object","entries","asVariable","push","mergeProperty","refTransform","error","ref","compatibleConstructor","_objectSpread","fromEntries","state","map","item","expose","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","_loop","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","_ret","_loop2","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","_loop3","_to$refMethod","refMethod","arguments","customTemplates","_state$filter$map"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nclass CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n\n define(tagName: string, constructor: CustomTemplateConstructor): void {\n let registered = this.#registry.has(tagName);\n if (registered) {\n // When open launchpad, the storyboard will be updated.\n // However, we can't *undefine* a custom element.\n // Just ignore re-registering custom templates.\n // eslint-disable-next-line no-console\n console.warn(`Custom template of \"${tagName}\" already registered.`);\n } else {\n registered = !!customElements.get(tagName);\n if (registered) {\n // eslint-disable-next-line no-console\n console.warn(\n `Custom template of \"${tagName}\" already defined by customElements.`\n );\n }\n }\n\n // Transform legacy `proxy.properties[].asVariable` as states.\n const strict = isStrictMode();\n const proxyProperties = (constructor.proxy?.properties ?? {}) as {\n [name: string]: LegacyTplPropProxy;\n };\n const validProxyProps: [string, CustomTemplateProxyBasicProperty][] = [];\n const legacyTplVariables: string[] = [];\n for (const [key, value] of Object.entries(proxyProperties)) {\n if (value.asVariable) {\n warnAboutStrictMode(strict, \"Template `asVariable`\", tagName, key);\n // istanbul ignore next\n if (!strict) {\n // For existed TPL usage, treat it as a STATE.\n legacyTplVariables.push(key);\n }\n } else if (value.mergeProperty || value.refTransform) {\n // eslint-disable-next-line no-console\n console.error(\n \"Template `mergeProperty` and `refTransform` are dropped in v3:\",\n tagName,\n key\n );\n } else if (value.ref) {\n validProxyProps.push([key, value]);\n }\n // Else: documentation only, for exposed states.\n }\n\n const compatibleConstructor = {\n ...constructor,\n proxy: {\n ...constructor.proxy,\n properties: Object.fromEntries(validProxyProps),\n },\n state: (constructor.state\n ? strict\n ? constructor.state\n : constructor.state.map((item) => ({\n // Make `expose` defaults to true in non-strict mode.\n expose: true,\n ...item,\n }))\n : []\n ).concat(legacyTplVariables.map((tpl) => ({ name: tpl, expose: true }))),\n };\n\n // Now we allow re-register custom template\n this.#registry.set(tagName, {\n ...compatibleConstructor,\n name: tagName,\n });\n\n const exposedStates = getExposedStates(compatibleConstructor.state);\n const proxyMethods = Object.entries(\n compatibleConstructor.proxy?.methods ?? {}\n );\n\n const props = exposedStates.concat(\n validProxyProps.map((entry) => entry[0])\n );\n const methods = proxyMethods.map((entry) => entry[0]);\n\n const nativeProps = props\n .concat(methods)\n .filter(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProps.length > 0) {\n warnAboutStrictMode(\n strict,\n \"Using native HTMLElement properties as template properties or methods\",\n tagName,\n ...nativeProps\n );\n // istanbul ignore next\n if (strict) {\n throw new Error(\n `In custom template \"${tagName}\", ${nativeProps\n .map((p) => `\"${p}\"`)\n .join(\n \", \"\n )} are native HTMLElement properties, and should be avoid to be used as brick properties or methods.`\n );\n }\n }\n\n if (registered) {\n return;\n }\n\n class TplElement extends HTMLElement {\n get $$typeof() {\n return \"custom-template\" as const;\n }\n\n static get _dev_only_definedProperties(): string[] {\n return props;\n }\n\n static get _dev_only_definedMethods(): string[] {\n return methods;\n }\n\n $$getElementByRef(this: RuntimeBrickElement, ref: string) {\n return this.$$tplStateStore?.hostBrick?.tplHostMetadata?.internalBricksByRef.get(\n ref\n )?.element;\n }\n\n connectedCallback() {\n let shadowRoot = this.shadowRoot;\n if (!shadowRoot) {\n shadowRoot = this.attachShadow({ mode: \"open\" });\n }\n const fragment = document.createDocumentFragment();\n const style = document.createElement(\"style\");\n style.textContent = \":host{display:block}:host([hidden]){display:none}\";\n const slot = document.createElement(\"slot\");\n fragment.appendChild(style);\n fragment.appendChild(slot);\n shadowRoot.appendChild(fragment);\n }\n\n disconnectedCallback() {\n if (this.shadowRoot) {\n this.shadowRoot.textContent = \"\";\n }\n }\n }\n\n for (const propName of exposedStates) {\n if (validProxyProps.some((entry) => entry[0] === propName)) {\n // eslint-disable-next-line no-console\n console.error(\n `Cannot define an exposed state that is also a proxy property: \"${propName}\" in ${tagName}`\n );\n continue;\n }\n Object.defineProperty(TplElement.prototype, propName, {\n get(this: RuntimeBrickElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.$$tplStateStore!.getValue(propName);\n },\n set(this: RuntimeBrickElement, value: unknown) {\n // 在 mount 过程中,先设置属性,再设置 `$$tplStateStore`,这样,当触发属性设置时,\n // 避免初始化的一次 state update 操作及其 onChange 事件。\n this.$$tplStateStore?.updateValue(propName, value, \"replace\");\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of validProxyProps) {\n Object.defineProperty(TplElement.prototype, from, {\n get(this: TplElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n unknown\n >;\n return element[to.refProperty ?? from];\n },\n set(this: TplElement, value: unknown) {\n // 同上 exposedState.set\n const element = this.$$getElementByRef?.(to.ref) as unknown as Record<\n string,\n unknown\n >;\n if (element) {\n element[to.refProperty ?? from] = value;\n }\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of proxyMethods) {\n Object.defineProperty(TplElement.prototype, from, {\n value(this: TplElement, ...args: unknown[]) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n element[to.refMethod ?? from](...args);\n },\n enumerable: true,\n });\n }\n\n customElements.define(tagName, TplElement);\n }\n\n get(tagName: string) {\n return this.#registry.get(tagName);\n }\n}\n\nexport const customTemplates = new CustomTemplateRegistry();\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n"],"mappings":";;;AAMA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,mBAAmB;;AAErE;AACA,IAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAAC,IAAAC,SAAA,oBAAAC,OAAA;AAQ/C,MAAMC,sBAAsB,CAAC;EAAAC,YAAA;IAAAC,0BAAA,OAAAJ,SAAA;MAAAK,QAAA;MAAAC,KAAA,EACN,IAAIC,GAAG;IAA0B;EAAA;EAEtDC,MAAMA,CAACC,OAAe,EAAEN,WAAsC,EAAQ;IAAA,IAAAO,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAGC,qBAAA,KAAI,EAAAf,SAAA,EAAWgB,GAAG,CAACP,OAAO,CAAC;IAC5C,IAAIK,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAG,OAAO,CAACC,IAAI,yBAAAC,MAAA,CAAwBV,OAAO,4BAAwB;IACrE,CAAC,MAAM;MACLK,UAAU,GAAG,CAAC,CAACM,cAAc,CAACC,GAAG,CAACZ,OAAO,CAAC;MAC1C,IAAIK,UAAU,EAAE;QACd;QACAG,OAAO,CAACC,IAAI,yBAAAC,MAAA,CACaV,OAAO,2CAC/B;MACH;IACF;;IAEA;IACA,IAAMa,MAAM,GAAG1B,YAAY,EAAE;IAC7B,IAAM2B,eAAe,IAAAb,qBAAA,IAA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E,CAAC,IAAInD,YAAY,EAAE;MAAAyD,MAAA,CAA3BP,KAAI,EAAEC,GAAE;IAYpB;IAEAhF,cAAc,CAACZ,MAAM,CAACC,OAAO,EAAEqD,UAAU,CAAC;EAC5C;EAEAzC,GAAGA,CAACZ,OAAe,EAAE;IACnB,OAAOM,qBAAA,KAAI,EAAAf,SAAA,EAAWqB,GAAG,CAACZ,OAAO,CAAC;EACpC;AACF;AAEA,OAAO,IAAMqG,eAAe,GAAG,IAAI5G,sBAAsB,EAAE;AAE3D,SAAS8C,gBAAgBA,CAACR,KAAgC,EAAY;EAAA,IAAAuE,iBAAA;EACpE;EACA,OAAOpH,IAAI,EAAAoH,iBAAA,GACTvE,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEc,MAAM,CAAEZ,IAAI,IAAKA,IAAI,CAACC,MAAM,CAAC,CAACF,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACG,IAAI,CAAC,cAAAkE,iBAAA,cAAAA,iBAAA,GAAI,EAAE,CACpE;AACH"}
1
+ {"version":3,"file":"CustomTemplates.js","names":["uniq","isStrictMode","warnAboutStrictMode","allowedNativeProps","Set","_registry","WeakMap","CustomTemplateRegistry","constructor","_classPrivateFieldInitSpec","writable","value","Map","define","tagName","_constructor$proxy$pr","_constructor$proxy","_compatibleConstructo","_compatibleConstructo2","registered","_classPrivateFieldGet","has","console","warn","concat","customElements","get","strict","proxyProperties","proxy","properties","validProxyProps","legacyTplVariables","key","Object","entries","asVariable","push","mergeProperty","refTransform","error","ref","compatibleConstructor","_objectSpread","fromEntries","state","map","item","expose","tpl","name","set","exposedStates","getExposedStates","proxyMethods","methods","props","entry","nativeProps","filter","prop","HTMLElement","prototype","length","Error","p","join","TplElement","$$typeof","_dev_only_definedProperties","_dev_only_definedMethods","$$getElementByRef","_this$$$tplStateStore","_this$$$tplStateStore2","_this$$$tplStateStore3","_this$$$tplStateStore4","$$tplStateStore","hostBrick","tplHostMetadata","internalBricksByRef","element","connectedCallback","shadowRoot","attachShadow","mode","fragment","document","createDocumentFragment","style","createElement","textContent","slot","appendChild","disconnectedCallback","_loop","propName","some","defineProperty","getValue","_this$$$tplStateStore5","updateValue","enumerable","_ret","_loop2","from","to","_to$refProperty","refProperty","_this$$$getElementByR","call","_to$refProperty2","_loop3","_from","_to","_to$refMethod","refMethod","arguments","customTemplates","_state$filter$map"],"sources":["../../src/CustomTemplates.ts"],"sourcesContent":["import type {\n ContextConf,\n CustomTemplate,\n CustomTemplateConstructor,\n CustomTemplateProxyBasicProperty,\n} from \"@next-core/types\";\nimport { uniq } from \"lodash\";\nimport type { RuntimeBrickElement } from \"./internal/interfaces.js\";\nimport { isStrictMode, warnAboutStrictMode } from \"./isStrictMode.js\";\n\n// Note: `prefix` is a native prop on Element, but it's only used in XML documents.\nconst allowedNativeProps = new Set([\"prefix\"]);\n\ninterface LegacyTplPropProxy extends CustomTemplateProxyBasicProperty {\n asVariable?: boolean;\n mergeProperty?: unknown;\n refTransform?: unknown;\n}\n\nclass CustomTemplateRegistry {\n readonly #registry = new Map<string, CustomTemplate>();\n\n define(tagName: string, constructor: CustomTemplateConstructor): void {\n let registered = this.#registry.has(tagName);\n if (registered) {\n // When open launchpad, the storyboard will be updated.\n // However, we can't *undefine* a custom element.\n // Just ignore re-registering custom templates.\n // eslint-disable-next-line no-console\n console.warn(`Custom template of \"${tagName}\" already registered.`);\n } else {\n registered = !!customElements.get(tagName);\n if (registered) {\n // eslint-disable-next-line no-console\n console.warn(\n `Custom template of \"${tagName}\" already defined by customElements.`\n );\n }\n }\n\n // Transform legacy `proxy.properties[].asVariable` as states.\n const strict = isStrictMode();\n const proxyProperties = (constructor.proxy?.properties ?? {}) as {\n [name: string]: LegacyTplPropProxy;\n };\n const validProxyProps: [string, CustomTemplateProxyBasicProperty][] = [];\n const legacyTplVariables: string[] = [];\n for (const [key, value] of Object.entries(proxyProperties)) {\n if (value.asVariable) {\n warnAboutStrictMode(strict, \"Template `asVariable`\", tagName, key);\n // istanbul ignore next\n if (!strict) {\n // For existed TPL usage, treat it as a STATE.\n legacyTplVariables.push(key);\n }\n } else if (value.mergeProperty || value.refTransform) {\n // eslint-disable-next-line no-console\n console.error(\n \"Template `mergeProperty` and `refTransform` are dropped in v3:\",\n tagName,\n key\n );\n } else if (value.ref) {\n validProxyProps.push([key, value]);\n }\n // Else: documentation only, for exposed states.\n }\n\n const compatibleConstructor = {\n ...constructor,\n proxy: {\n ...constructor.proxy,\n properties: Object.fromEntries(validProxyProps),\n },\n state: (constructor.state\n ? strict\n ? constructor.state\n : constructor.state.map((item) => ({\n // Make `expose` defaults to true in non-strict mode.\n expose: true,\n ...item,\n }))\n : []\n ).concat(legacyTplVariables.map((tpl) => ({ name: tpl, expose: true }))),\n };\n\n // Now we allow re-register custom template\n this.#registry.set(tagName, {\n ...compatibleConstructor,\n name: tagName,\n });\n\n const exposedStates = getExposedStates(compatibleConstructor.state);\n const proxyMethods = Object.entries(\n compatibleConstructor.proxy?.methods ?? {}\n );\n\n const props = exposedStates.concat(\n validProxyProps.map((entry) => entry[0])\n );\n const methods = proxyMethods.map((entry) => entry[0]);\n\n const nativeProps = props\n .concat(methods)\n .filter(\n (prop) => prop in HTMLElement.prototype && !allowedNativeProps.has(prop)\n );\n if (nativeProps.length > 0) {\n warnAboutStrictMode(\n strict,\n \"Using native HTMLElement properties as template properties or methods\",\n tagName,\n ...nativeProps\n );\n // istanbul ignore next\n if (strict) {\n throw new Error(\n `In custom template \"${tagName}\", ${nativeProps\n .map((p) => `\"${p}\"`)\n .join(\n \", \"\n )} are native HTMLElement properties, and should be avoid to be used as brick properties or methods.`\n );\n }\n }\n\n if (registered) {\n return;\n }\n\n class TplElement extends HTMLElement {\n get $$typeof() {\n return \"custom-template\" as const;\n }\n\n static get _dev_only_definedProperties(): string[] {\n return props;\n }\n\n static get _dev_only_definedMethods(): string[] {\n return methods;\n }\n\n $$getElementByRef(this: RuntimeBrickElement, ref: string) {\n return this.$$tplStateStore?.hostBrick?.tplHostMetadata?.internalBricksByRef.get(\n ref\n )?.element;\n }\n\n connectedCallback() {\n let shadowRoot = this.shadowRoot;\n if (!shadowRoot) {\n shadowRoot = this.attachShadow({ mode: \"open\" });\n }\n const fragment = document.createDocumentFragment();\n const style = document.createElement(\"style\");\n style.textContent = \":host{display:block}:host([hidden]){display:none}\";\n const slot = document.createElement(\"slot\");\n fragment.appendChild(style);\n fragment.appendChild(slot);\n shadowRoot.appendChild(fragment);\n }\n\n disconnectedCallback() {\n if (this.shadowRoot) {\n this.shadowRoot.textContent = \"\";\n }\n }\n }\n\n for (const propName of exposedStates) {\n if (validProxyProps.some((entry) => entry[0] === propName)) {\n // eslint-disable-next-line no-console\n console.error(\n `Cannot define an exposed state that is also a proxy property: \"${propName}\" in ${tagName}`\n );\n continue;\n }\n Object.defineProperty(TplElement.prototype, propName, {\n get(this: RuntimeBrickElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.$$tplStateStore!.getValue(propName);\n },\n set(this: RuntimeBrickElement, value: unknown) {\n // 在 mount 过程中,先设置属性,再设置 `$$tplStateStore`,这样,当触发属性设置时,\n // 避免初始化的一次 state update 操作及其 onChange 事件。\n this.$$tplStateStore?.updateValue(propName, value, \"replace\");\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of validProxyProps) {\n Object.defineProperty(TplElement.prototype, from, {\n get(this: TplElement) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n unknown\n >;\n return element[to.refProperty ?? from];\n },\n set(this: TplElement, value: unknown) {\n // 同上 exposedState.set\n const element = this.$$getElementByRef?.(to.ref) as unknown as Record<\n string,\n unknown\n >;\n if (element) {\n element[to.refProperty ?? from] = value;\n }\n },\n enumerable: true,\n });\n }\n\n for (const [from, to] of proxyMethods) {\n Object.defineProperty(TplElement.prototype, from, {\n value(this: TplElement, ...args: unknown[]) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const element = this.$$getElementByRef!(to.ref) as unknown as Record<\n string,\n Function\n >;\n element[to.refMethod ?? from](...args);\n },\n enumerable: true,\n });\n }\n\n customElements.define(tagName, TplElement);\n }\n\n get(tagName: string) {\n return this.#registry.get(tagName);\n }\n}\n\nexport const customTemplates = new CustomTemplateRegistry();\n\nfunction getExposedStates(state: ContextConf[] | undefined): string[] {\n // Allow duplicated state names which maybe mutually exclusive.\n return uniq(\n state?.filter((item) => item.expose).map((item) => item.name) ?? []\n );\n}\n"],"mappings":";;;AAMA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,SAASC,YAAY,EAAEC,mBAAmB,QAAQ,mBAAmB;;AAErE;AACA,IAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AAAC,IAAAC,SAAA,oBAAAC,OAAA;AAQ/C,MAAMC,sBAAsB,CAAC;EAAAC,YAAA;IAAAC,0BAAA,OAAAJ,SAAA;MAAAK,QAAA;MAAAC,KAAA,EACN,IAAIC,GAAG;IAA0B;EAAA;EAEtDC,MAAMA,CAACC,OAAe,EAAEN,WAAsC,EAAQ;IAAA,IAAAO,qBAAA,EAAAC,kBAAA,EAAAC,qBAAA,EAAAC,sBAAA;IACpE,IAAIC,UAAU,GAAGC,qBAAA,KAAI,EAAAf,SAAA,EAAWgB,GAAG,CAACP,OAAO,CAAC;IAC5C,IAAIK,UAAU,EAAE;MACd;MACA;MACA;MACA;MACAG,OAAO,CAACC,IAAI,yBAAAC,MAAA,CAAwBV,OAAO,4BAAwB;IACrE,CAAC,MAAM;MACLK,UAAU,GAAG,CAAC,CAACM,cAAc,CAACC,GAAG,CAACZ,OAAO,CAAC;MAC1C,IAAIK,UAAU,EAAE;QACd;QACAG,OAAO,CAACC,IAAI,yBAAAC,MAAA,CACaV,OAAO,2CAC/B;MACH;IACF;;IAEA;IACA,IAAMa,MAAM,GAAG1B,YAAY,EAAE;IAC7B,IAAM2B,eAAe,IAAAb,qBAAA,IAAAC,kBAAA,GAAIR,WAAW,CAAC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,CAAC,IAAInD,YAAY;MAAAyD,MAAA,CAAAC,KAAA,EAAAC,GAAA;IAAA;IAcrCxF,cAAc,CAACZ,MAAM,CAACC,OAAO,EAAEqD,UAAU,CAAC;EAC5C;EAEAzC,GAAGA,CAACZ,OAAe,EAAE;IACnB,OAAOM,qBAAA,KAAI,EAAAf,SAAA,EAAWqB,GAAG,CAACZ,OAAO,CAAC;EACpC;AACF;AAEA,OAAO,IAAMuG,eAAe,GAAG,IAAI9G,sBAAsB,EAAE;AAE3D,SAAS8C,gBAAgBA,CAACR,KAAgC,EAAY;EAAA,IAAAyE,iBAAA;EACpE;EACA,OAAOtH,IAAI,EAAAsH,iBAAA,GACTzE,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEc,MAAM,CAAEZ,IAAI,IAAKA,IAAI,CAACC,MAAM,CAAC,CAACF,GAAG,CAAEC,IAAI,IAAKA,IAAI,CAACG,IAAI,CAAC,cAAAoE,iBAAA,cAAAA,iBAAA,GAAI,EAAE,CACpE;AACH"}
@@ -0,0 +1,40 @@
1
+ import * as __secret_internals from "./internal/secret_internals.js";
2
+ var brick;
3
+ function show(options) {
4
+ if (brick) {
5
+ brick.resolve(options);
6
+ } else {
7
+ if (options.type === "confirm") {
8
+ if (confirm(options.content)) {
9
+ setTimeout(() => {
10
+ var _options$onOk;
11
+ (_options$onOk = options.onOk) === null || _options$onOk === void 0 ? void 0 : _options$onOk.call(options);
12
+ }, 1);
13
+ } else {
14
+ setTimeout(() => {
15
+ var _options$onCancel;
16
+ (_options$onCancel = options.onCancel) === null || _options$onCancel === void 0 ? void 0 : _options$onCancel.call(options);
17
+ }, 1);
18
+ }
19
+ } else {
20
+ alert(options.content);
21
+ if (options.onOk) {
22
+ setTimeout(() => {
23
+ options.onOk();
24
+ }, 1000);
25
+ }
26
+ }
27
+ }
28
+ }
29
+ export function loadDialogService(tagName) {
30
+ __secret_internals.loadBricks([tagName]).then(() => {
31
+ brick = document.createElement(tagName);
32
+ }, error => {
33
+ // eslint-disable-next-line no-console
34
+ console.error("Load dialog service failed:", error);
35
+ });
36
+ }
37
+ export var Dialog = Object.freeze({
38
+ show
39
+ });
40
+ //# sourceMappingURL=Dialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dialog.js","names":["__secret_internals","brick","show","options","resolve","type","confirm","content","setTimeout","_options$onOk","onOk","call","_options$onCancel","onCancel","alert","loadDialogService","tagName","loadBricks","then","document","createElement","error","console","Dialog","Object","freeze"],"sources":["../../src/Dialog.ts"],"sourcesContent":["import * as __secret_internals from \"./internal/secret_internals.js\";\n\nlet brick: {\n resolve(options: DialogOptions): void;\n};\n\nfunction show(options: DialogOptions) {\n if (brick) {\n brick.resolve(options);\n } else {\n if (options.type === \"confirm\") {\n if (confirm(options.content)) {\n setTimeout(() => {\n options.onOk?.();\n }, 1);\n } else {\n setTimeout(() => {\n options.onCancel?.();\n }, 1);\n }\n } else {\n alert(options.content);\n if (options.onOk) {\n setTimeout(() => {\n options.onOk!();\n }, 1000);\n }\n }\n }\n}\n\nexport function loadDialogService(tagName: string) {\n __secret_internals.loadBricks([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load dialog service failed:\", error);\n }\n );\n}\n\nexport interface DialogOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\" | \"confirm\";\n title?: string | null;\n content: string;\n whiteSpace?: string;\n onOk?: () => void;\n onCancel?: () => void;\n}\n\nexport const Dialog = Object.freeze({\n show,\n});\n"],"mappings":"AAAA,OAAO,KAAKA,kBAAkB,MAAM,gCAAgC;AAEpE,IAAIC,KAEH;AAED,SAASC,IAAIA,CAACC,OAAsB,EAAE;EACpC,IAAIF,KAAK,EAAE;IACTA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EACxB,CAAC,MAAM;IACL,IAAIA,OAAO,CAACE,IAAI,KAAK,SAAS,EAAE;MAC9B,IAAIC,OAAO,CAACH,OAAO,CAACI,OAAO,CAAC,EAAE;QAC5BC,UAAU,CAAC,MAAM;UAAA,IAAAC,aAAA;UACf,CAAAA,aAAA,GAAAN,OAAO,CAACO,IAAI,cAAAD,aAAA,uBAAZA,aAAA,CAAAE,IAAA,CAAAR,OAAO,CAAS;QAClB,CAAC,EAAE,CAAC,CAAC;MACP,CAAC,MAAM;QACLK,UAAU,CAAC,MAAM;UAAA,IAAAI,iBAAA;UACf,CAAAA,iBAAA,GAAAT,OAAO,CAACU,QAAQ,cAAAD,iBAAA,uBAAhBA,iBAAA,CAAAD,IAAA,CAAAR,OAAO,CAAa;QACtB,CAAC,EAAE,CAAC,CAAC;MACP;IACF,CAAC,MAAM;MACLW,KAAK,CAACX,OAAO,CAACI,OAAO,CAAC;MACtB,IAAIJ,OAAO,CAACO,IAAI,EAAE;QAChBF,UAAU,CAAC,MAAM;UACfL,OAAO,CAACO,IAAI,EAAG;QACjB,CAAC,EAAE,IAAI,CAAC;MACV;IACF;EACF;AACF;AAEA,OAAO,SAASK,iBAAiBA,CAACC,OAAe,EAAE;EACjDhB,kBAAkB,CAACiB,UAAU,CAAC,CAACD,OAAO,CAAC,CAAC,CAACE,IAAI,CAC3C,MAAM;IACJjB,KAAK,GAAGkB,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAQ;EAChD,CAAC,EACAK,KAAc,IAAK;IAClB;IACAC,OAAO,CAACD,KAAK,CAAC,6BAA6B,EAAEA,KAAK,CAAC;EACrD,CAAC,CACF;AACH;AAWA,OAAO,IAAME,MAAM,GAAGC,MAAM,CAACC,MAAM,CAAC;EAClCvB;AACF,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ import * as __secret_internals from "./internal/secret_internals.js";
2
+ var brick;
3
+ function show(options) {
4
+ if (brick) {
5
+ brick.resolve(options);
6
+ } else {
7
+ alert(options.message);
8
+ }
9
+ }
10
+ export function loadNotificationService(tagName) {
11
+ __secret_internals.loadBricks([tagName]).then(() => {
12
+ brick = document.createElement(tagName);
13
+ }, error => {
14
+ // eslint-disable-next-line no-console
15
+ console.error("Load notification service failed:", error);
16
+ });
17
+ }
18
+ export var Notification = Object.freeze({
19
+ show
20
+ });
21
+ //# sourceMappingURL=Notification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Notification.js","names":["__secret_internals","brick","show","options","resolve","alert","message","loadNotificationService","tagName","loadBricks","then","document","createElement","error","console","Notification","Object","freeze"],"sources":["../../src/Notification.ts"],"sourcesContent":["import * as __secret_internals from \"./internal/secret_internals.js\";\n\nlet brick: {\n resolve(options: NotificationOptions): void;\n};\n\nfunction show(options: NotificationOptions) {\n if (brick) {\n brick.resolve(options);\n } else {\n alert(options.message);\n }\n}\n\nexport function loadNotificationService(tagName: string) {\n __secret_internals.loadBricks([tagName]).then(\n () => {\n brick = document.createElement(tagName) as any;\n },\n (error: unknown) => {\n // eslint-disable-next-line no-console\n console.error(\"Load notification service failed:\", error);\n }\n );\n}\n\nexport interface NotificationOptions {\n type?: \"success\" | \"error\" | \"warn\" | \"info\";\n message: string;\n}\n\nexport const Notification = Object.freeze({\n show,\n});\n"],"mappings":"AAAA,OAAO,KAAKA,kBAAkB,MAAM,gCAAgC;AAEpE,IAAIC,KAEH;AAED,SAASC,IAAIA,CAACC,OAA4B,EAAE;EAC1C,IAAIF,KAAK,EAAE;IACTA,KAAK,CAACG,OAAO,CAACD,OAAO,CAAC;EACxB,CAAC,MAAM;IACLE,KAAK,CAACF,OAAO,CAACG,OAAO,CAAC;EACxB;AACF;AAEA,OAAO,SAASC,uBAAuBA,CAACC,OAAe,EAAE;EACvDR,kBAAkB,CAACS,UAAU,CAAC,CAACD,OAAO,CAAC,CAAC,CAACE,IAAI,CAC3C,MAAM;IACJT,KAAK,GAAGU,QAAQ,CAACC,aAAa,CAACJ,OAAO,CAAQ;EAChD,CAAC,EACAK,KAAc,IAAK;IAClB;IACAC,OAAO,CAACD,KAAK,CAAC,mCAAmC,EAAEA,KAAK,CAAC;EAC3D,CAAC,CACF;AACH;AAOA,OAAO,IAAME,YAAY,GAAGC,MAAM,CAACC,MAAM,CAAC;EACxCf;AACF,CAAC,CAAC"}
@@ -6,6 +6,18 @@ import { getGeneralGlobals } from "./internal/compute/getGeneralGlobals.js";
6
6
 
7
7
  /** @internal */
8
8
 
9
+ /** @internal */
10
+
11
+ /** @internal */
12
+
13
+ /** @internal */
14
+
15
+ /** @internal */
16
+
17
+ /** @internal */
18
+
19
+ /** @internal */
20
+
9
21
  /** @internal */
10
22
  export function StoryboardFunctionRegistryFactory() {
11
23
  var {
@@ -1 +1 @@
1
- {"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","supply","strictCollectMemberUsageInFunction","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","arguments","length","undefined","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","hasPermissionsCheck","has","set","name","source","typescript","processed","cooked","collector","createCollector","precooked","hooks","beforeVisit","function","rules","noVar","globalVariables","attemptToVisitGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","_objectSpread","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type { MicroApp, StoryboardFunction } from \"@next-core/types\";\nimport { cook, precookFunction, EstreeNode } from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { strictCollectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string>;\n hasPermissionsCheck: boolean;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n const deps = strictCollectMemberUsageInFunction(fn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n });\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: supply(\n precooked.attemptToVisitGlobals,\n getGeneralGlobals(precooked.attemptToVisitGlobals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n ),\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n }) as Function;\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = strictCollectMemberUsageInFunction(newFn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n };\n}\n"],"mappings":";A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A2B;IAC3B8B,wBAAwBA,CACtBnB,IAAY,EACZoB,IAA6B,EACvB;MACN,IAAMC,KAAK,GAAAC,aAAA,CAAAA,aAAA,KACNF,IAAI;QACPpB;MAAI,EACL;MACD,IAAMJ,IAAI,GAAG3B,kCAAkC,CAACoD,KAAK,EAAE,IAAI,CAAC;MAC5D,IAAMxB,mBAAmB,GAAG5B,kCAAkC,CAC5DoD,KAAK,EACL,aAAa,CACd,CAACvB,GAAG,CAAC,OAAO,CAAC;MACdpB,mBAAmB,CAACqB,GAAG,CAACC,IAAI,EAAE;QAC5BC,MAAM,EAAEmB,IAAI,CAACnB,MAAM;QACnBC,UAAU,EAAEkB,IAAI,CAAClB,UAAU;QAC3BN,IAAI;QACJC;MACF,CAAC,CAAC;IACJ,CAAC;IACD;AACJ;AACA;AACA;IACI0B,qBAAqBA,CAACC,aAAa,EAAE;MACnC,IAAMC,gBAAgB,GAAG,IAAIC,GAAG,EAAU;MAC1C,IAAM7B,mBAAmB,GAAIG,IAAY,IAAc;QACrD,IAAI,CAACyB,gBAAgB,CAAC3B,GAAG,CAACE,IAAI,CAAC,EAAE;UAC/ByB,gBAAgB,CAACE,GAAG,CAAC3B,IAAI,CAAC;UAC1B,IAAML,EAAE,GAAGjB,mBAAmB,CAACM,GAAG,CAACgB,IAAI,CAAC;UACxC,OACE,CAAC,CAACL,EAAE,KACHA,EAAE,CAACE,mBAAmB,IAAI,CAAC,GAAGF,EAAE,CAACC,IAAI,CAAC,CAACgC,IAAI,CAAC/B,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAO2B,aAAa,CAACI,IAAI,CAAC/B,mBAAmB,CAAC;IAChD;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","supply","strictCollectMemberUsageInFunction","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","arguments","length","undefined","registeredFunctions","Map","storyboardFunctions","Proxy","Object","freeze","get","target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","deps","hasPermissionsCheck","has","set","name","source","typescript","processed","cooked","collector","createCollector","precooked","hooks","beforeVisit","function","rules","noVar","globalVariables","attemptToVisitGlobals","isStoryboardFunction","beforeEvaluate","beforeCall","beforeBranch","updateStoryboardFunction","data","newFn","_objectSpread","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type { MicroApp, StoryboardFunction } from \"@next-core/types\";\nimport { cook, precookFunction, EstreeNode } from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { strictCollectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string>;\n hasPermissionsCheck: boolean;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n const deps = strictCollectMemberUsageInFunction(fn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n });\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: supply(\n precooked.attemptToVisitGlobals,\n getGeneralGlobals(precooked.attemptToVisitGlobals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n ),\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n }) as Function;\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = strictCollectMemberUsageInFunction(newFn, \"FN\");\n const hasPermissionsCheck = strictCollectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\"\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n };\n}\n"],"mappings":";AACA,SAASA,IAAI,EAAEC,eAAe,QAAoB,iBAAiB;AACnE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,kCAAkC,QAAQ,6BAA6B;AAChF,SAASC,iBAAiB,QAAQ,yCAAyC;;AAE3E;;AAGA;;AAMA;;AAiBA;;AAUA;;AAQA;;AAKA;;AAGA;AACA,OAAO,SAASC,iCAAiCA,CAAA,EAQb;EAAA,IARc;IAChDC,QAAQ;IACRC,aAAa;IACbC;EAKF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACJ,IAAMG,mBAAmB,GAAG,IAAIC,GAAG,EAAqC;;EAExE;EACA,IAAMC,mBAAmB,GAAG,IAAIC,KAAK,CAACC,MAA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JC;MACF,CAAC,CAAC;IACJ,CAAC;IACD;AACJ;AACA;AACA;IACI0B,qBAAqBA,CAACC,aAAa,EAAE;MACnC,IAAMC,gBAAgB,GAAG,IAAIC,GAAG,EAAU;MAC1C,IAAM7B,mBAAmB,GAAIG,IAAY,IAAc;QACrD,IAAI,CAACyB,gBAAgB,CAAC3B,GAAG,CAACE,IAAI,CAAC,EAAE;UAC/ByB,gBAAgB,CAACE,GAAG,CAAC3B,IAAI,CAAC;UAC1B,IAAML,EAAE,GAAGjB,mBAAmB,CAACM,GAAG,CAACgB,IAAI,CAAC;UACxC,OACE,CAAC,CAACL,EAAE,KACHA,EAAE,CAACE,mBAAmB,IAAI,CAAC,GAAGF,EAAE,CAACC,IAAI,CAAC,CAACgC,IAAI,CAAC/B,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAO2B,aAAa,CAACI,IAAI,CAAC/B,mBAAmB,CAAC;IAChD;EACF,CAAC;AACH"}
@@ -1,7 +1,10 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import { HttpAbortError, HttpFetchError, HttpResponseError } from "@next-core/http";
3
+ import { i18n } from "@next-core/i18n";
3
4
  import { getRuntime } from "./internal/Runtime.js";
4
5
  import { getHistory } from "./history.js";
6
+ import { K, NS } from "./internal/i18n.js";
7
+ import { Dialog } from "./Dialog.js";
5
8
 
6
9
  /**
7
10
  * 将 http 请求错误转换为可读的字符串。
@@ -59,19 +62,17 @@ export function handleHttpError(error) {
59
62
  return;
60
63
  }
61
64
  unauthenticatedConfirming = true;
62
- // i18next.t(`${NS_BRICK_KIT}:${K.LOGIN_TIMEOUT_MESSAGE}`)
63
- if (confirm("您还未登录或登录信息已过期,现在重新登录?")) {
64
- var ssoEnabled = getRuntime().getFeatureFlags()["sso-enabled"];
65
- var history = getHistory();
66
- history.push(ssoEnabled ? "/sso-auth/login" : "/auth/login", {
67
- from: _objectSpread(_objectSpread({}, history.location), {}, {
68
- state: undefined
69
- })
70
- });
71
- }
72
- setTimeout(() => {
73
- unauthenticatedConfirming = false;
74
- }, 1);
65
+ Dialog.show({
66
+ type: "confirm",
67
+ content: i18n.t("".concat(NS, ":").concat(K.LOGIN_TIMEOUT_MESSAGE)),
68
+ onOk() {
69
+ redirectToLogin();
70
+ unauthenticatedConfirming = false;
71
+ },
72
+ onCancel() {
73
+ unauthenticatedConfirming = false;
74
+ }
75
+ });
75
76
  return;
76
77
  }
77
78
 
@@ -80,11 +81,25 @@ export function handleHttpError(error) {
80
81
  var message = httpErrorToString(error);
81
82
  if (message !== lastErrorMessage) {
82
83
  lastErrorMessage = message;
83
- alert(message);
84
- setTimeout(() => {
85
- lastErrorMessage = undefined;
86
- }, 1000);
84
+ Dialog.show({
85
+ type: "error",
86
+ title: i18n.t("".concat(NS, ":").concat(K.REQUEST_FAILED)),
87
+ content: message,
88
+ whiteSpace: "pre-wrap",
89
+ onOk() {
90
+ lastErrorMessage = undefined;
91
+ }
92
+ });
87
93
  }
88
94
  return;
89
95
  }
96
+ function redirectToLogin() {
97
+ var ssoEnabled = getRuntime().getFeatureFlags()["sso-enabled"];
98
+ var history = getHistory();
99
+ history.push(ssoEnabled ? "/sso-auth/login" : "/auth/login", {
100
+ from: _objectSpread(_objectSpread({}, history.location), {}, {
101
+ state: undefined
102
+ })
103
+ });
104
+ }
90
105
  //# sourceMappingURL=handleHttpError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleHttpError.js","names":["HttpAbortError","HttpFetchError","HttpResponseError","getRuntime","getHistory","httpErrorToString","error","Event","target","HTMLScriptElement","src","responseJson","msg","toString","isUnauthenticatedError","response","status","code","unauthenticatedConfirming","lastErrorMessage","handleHttpError","window","NO_AUTH_GUARD","confirm","ssoEnabled","getFeatureFlags","history","push","from","_objectSpread","location","state","undefined","setTimeout","console","message","alert"],"sources":["../../src/handleHttpError.ts"],"sourcesContent":["import {\n HttpAbortError,\n HttpFetchError,\n HttpResponseError,\n} from \"@next-core/http\";\nimport { getRuntime } from \"./internal/Runtime.js\";\nimport { getHistory } from \"./history.js\";\n\n/**\n * 将 http 请求错误转换为可读的字符串。\n *\n * @remarks\n *\n * 将依次尝试读取返回的 JSON 格式数据的字符串类型的 `error` 和 `msg` 字段,如果没有找到则返回 `error.toString()` 的结果。\n *\n * @param error - 错误对象。\n *\n * @returns 转换为字符串的错误信息。\n */\nexport function httpErrorToString(error: unknown): string {\n if (error instanceof Event && error.target instanceof HTMLScriptElement) {\n return error.target.src;\n }\n if (error instanceof HttpFetchError) {\n // return i18next.t(`${NS_BRICK_KIT}:${K.NETWORK_ERROR}`);\n return \"网络错误,请检查您的网络连接。\";\n }\n if (error instanceof HttpResponseError) {\n if (error.responseJson) {\n if (typeof error.responseJson.error === \"string\") {\n return error.responseJson.error;\n } else if (typeof error.responseJson.msg === \"string\") {\n return error.responseJson.msg;\n }\n }\n }\n if (error == null) {\n return \"Unknown error\";\n }\n return error.toString();\n}\n\nexport function isUnauthenticatedError(error: unknown): boolean {\n return (\n error instanceof HttpResponseError &&\n error.response.status === 401 &&\n !!error.responseJson &&\n error.responseJson.code === 100003\n );\n}\n\nlet unauthenticatedConfirming = false;\n\nlet lastErrorMessage: string | undefined;\n\n/**\n * 处理 http 请求错误(使用 AntDesign 模态框弹出错误信息)。\n *\n * @param error - 错误对象。\n */\nexport function handleHttpError(error: unknown) {\n // Do nothing if aborted http requests\n if (error instanceof HttpAbortError) {\n return;\n }\n\n // Redirect to login page if not logged in.\n if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {\n if (unauthenticatedConfirming) {\n return;\n }\n unauthenticatedConfirming = true;\n // i18next.t(`${NS_BRICK_KIT}:${K.LOGIN_TIMEOUT_MESSAGE}`)\n if (confirm(\"您还未登录或登录信息已过期,现在重新登录?\")) {\n const ssoEnabled = getRuntime().getFeatureFlags()[\"sso-enabled\"];\n const history = getHistory();\n history.push(ssoEnabled ? \"/sso-auth/login\" : \"/auth/login\", {\n from: {\n ...history.location,\n state: undefined,\n },\n });\n }\n setTimeout(() => {\n unauthenticatedConfirming = false;\n }, 1);\n return;\n }\n\n // eslint-disable-next-line no-console\n console.error(error);\n\n const message = httpErrorToString(error);\n if (message !== lastErrorMessage) {\n lastErrorMessage = message;\n alert(message);\n setTimeout(() => {\n lastErrorMessage = undefined;\n }, 1000);\n }\n return;\n}\n"],"mappings":";AAAA,SACEA,cAAc,EACdC,cAAc,EACdC,iBAAiB,QACZ,iBAAiB;AACxB,SAASC,UAAU,QAAQ,uBAAuB;AAClD,SAASC,UAAU,QAAQ,cAAc;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAACC,KAAc,EAAU;EACxD,IAAIA,KAAK,YAAYC,KAAK,IAAID,KAAK,CAACE,MAAM,YAAYC,iBAAiB,EAAE;IACvE,OAAOH,KAAK,CAACE,MAAM,CAACE,GAAG;EACzB;EACA,IAAIJ,KAAK,YAAYL,cAAc,EAAE;IACnC;IACA,OAAO,iBAAiB;EAC1B;EACA,IAAIK,KAAK,YAAYJ,iBAAiB,EAAE;IACtC,IAAII,KAAK,CAACK,YAAY,EAAE;MACtB,IAAI,OAAOL,KAAK,CAACK,YAAY,CAACL,KAAK,KAAK,QAAQ,EAAE;QAChD,OAAOA,KAAK,CAACK,YAAY,CAACL,KAAK;MACjC,CAAC,MAAM,IAAI,OAAOA,KAAK,CAACK,YAAY,CAACC,GAAG,KAAK,QAAQ,EAAE;QACrD,OAAON,KAAK,CAACK,YAAY,CAACC,GAAG;MAC/B;IACF;EACF;EACA,IAAIN,KAAK,IAAI,IAAI,EAAE;IACjB,OAAO,eAAe;EACxB;EACA,OAAOA,KAAK,CAACO,QAAQ,EAAE;AACzB;AAEA,OAAO,SAASC,sBAAsBA,CAACR,KAAc,EAAW;EAC9D,OACEA,KAAK,YAAYJ,iBAAiB,IAClCI,KAAK,CAACS,QAAQ,CAACC,MAAM,KAAK,GAAG,IAC7B,CAAC,CAACV,KAAK,CAACK,YAAY,IACpBL,KAAK,CAACK,YAAY,CAACM,IAAI,KAAK,MAAM;AAEtC;AAEA,IAAIC,yBAAyB,GAAG,KAAK;AAErC,IAAIC,gBAAoC;;AAExC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACd,KAAc,EAAE;EAC9C;EACA,IAAIA,KAAK,YAAYN,cAAc,EAAE;IACnC;EACF;;EAEA;EACA,IAAIc,sBAAsB,CAACR,KAAK,CAAC,IAAI,CAACe,MAAM,CAACC,aAAa,EAAE;IAC1D,IAAIJ,yBAAyB,EAAE;MAC7B;IACF;IACAA,yBAAyB,GAAG,IAAI;IAChC;IACA,IAAIK,OAAO,CAAC,uBAAuB,CAAC,EAAE;MACpC,IAAMC,UAAU,GAAGrB,UAAU,EAAE,CAACsB,eAAe,EAAE,CAAC,aAAa,CAAC;MAChE,IAAMC,OAAO,GAAGtB,UAAU,EAAE;MAC5BsB,OAAO,CAACC,IAAI,CAACH,UAAU,GAAG,iBAAiB,GAAG,aAAa,EAAE;QAC3DI,IAAI,EAAAC,aAAA,CAAAA,aAAA,KACCH,OAAO,CAACI,QAAQ;UACnBC,KAAK,EAAEC;QAAS;MAEpB,CAAC,CAAC;IACJ;IACAC,UAAU,CAAC,MAAM;MACff,yBAAyB,GAAG,KAAK;IACnC,CAAC,EAAE,CAAC,CAAC;IACL;EACF;;EAEA;EACAgB,OAAO,CAAC5B,KAAK,CAACA,KAAK,CAAC;EAEpB,IAAM6B,OAAO,GAAG9B,iBAAiB,CAACC,KAAK,CAAC;EACxC,IAAI6B,OAAO,KAAKhB,gBAAgB,EAAE;IAChCA,gBAAgB,GAAGgB,OAAO;IAC1BC,KAAK,CAACD,OAAO,CAAC;IACdF,UAAU,CAAC,MAAM;MACfd,gBAAgB,GAAGa,SAAS;IAC9B,CAAC,EAAE,IAAI,CAAC;EACV;EACA;AACF"}
1
+ {"version":3,"file":"handleHttpError.js","names":["HttpAbortError","HttpFetchError","HttpResponseError","i18n","getRuntime","getHistory","K","NS","Dialog","httpErrorToString","error","Event","target","HTMLScriptElement","src","responseJson","msg","toString","isUnauthenticatedError","response","status","code","unauthenticatedConfirming","lastErrorMessage","handleHttpError","window","NO_AUTH_GUARD","show","type","content","t","concat","LOGIN_TIMEOUT_MESSAGE","onOk","redirectToLogin","onCancel","console","message","title","REQUEST_FAILED","whiteSpace","undefined","ssoEnabled","getFeatureFlags","history","push","from","_objectSpread","location","state"],"sources":["../../src/handleHttpError.ts"],"sourcesContent":["import {\n HttpAbortError,\n HttpFetchError,\n HttpResponseError,\n} from \"@next-core/http\";\nimport { i18n } from \"@next-core/i18n\";\nimport { getRuntime } from \"./internal/Runtime.js\";\nimport { getHistory } from \"./history.js\";\nimport { K, NS } from \"./internal/i18n.js\";\nimport { Dialog } from \"./Dialog.js\";\n\n/**\n * 将 http 请求错误转换为可读的字符串。\n *\n * @remarks\n *\n * 将依次尝试读取返回的 JSON 格式数据的字符串类型的 `error` 和 `msg` 字段,如果没有找到则返回 `error.toString()` 的结果。\n *\n * @param error - 错误对象。\n *\n * @returns 转换为字符串的错误信息。\n */\nexport function httpErrorToString(error: unknown): string {\n if (error instanceof Event && error.target instanceof HTMLScriptElement) {\n return error.target.src;\n }\n if (error instanceof HttpFetchError) {\n // return i18next.t(`${NS_BRICK_KIT}:${K.NETWORK_ERROR}`);\n return \"网络错误,请检查您的网络连接。\";\n }\n if (error instanceof HttpResponseError) {\n if (error.responseJson) {\n if (typeof error.responseJson.error === \"string\") {\n return error.responseJson.error;\n } else if (typeof error.responseJson.msg === \"string\") {\n return error.responseJson.msg;\n }\n }\n }\n if (error == null) {\n return \"Unknown error\";\n }\n return error.toString();\n}\n\nexport function isUnauthenticatedError(error: unknown): boolean {\n return (\n error instanceof HttpResponseError &&\n error.response.status === 401 &&\n !!error.responseJson &&\n error.responseJson.code === 100003\n );\n}\n\nlet unauthenticatedConfirming = false;\n\nlet lastErrorMessage: string | undefined;\n\n/**\n * 处理 http 请求错误(使用 AntDesign 模态框弹出错误信息)。\n *\n * @param error - 错误对象。\n */\nexport function handleHttpError(error: unknown) {\n // Do nothing if aborted http requests\n if (error instanceof HttpAbortError) {\n return;\n }\n\n // Redirect to login page if not logged in.\n if (isUnauthenticatedError(error) && !window.NO_AUTH_GUARD) {\n if (unauthenticatedConfirming) {\n return;\n }\n unauthenticatedConfirming = true;\n Dialog.show({\n type: \"confirm\",\n content: i18n.t(`${NS}:${K.LOGIN_TIMEOUT_MESSAGE}`),\n onOk() {\n redirectToLogin();\n unauthenticatedConfirming = false;\n },\n onCancel() {\n unauthenticatedConfirming = false;\n },\n });\n return;\n }\n\n // eslint-disable-next-line no-console\n console.error(error);\n\n const message = httpErrorToString(error);\n if (message !== lastErrorMessage) {\n lastErrorMessage = message;\n Dialog.show({\n type: \"error\",\n title: i18n.t(`${NS}:${K.REQUEST_FAILED}`),\n content: message,\n whiteSpace: \"pre-wrap\",\n onOk() {\n lastErrorMessage = undefined;\n },\n });\n }\n return;\n}\n\nfunction redirectToLogin() {\n const ssoEnabled = getRuntime().getFeatureFlags()[\"sso-enabled\"];\n const history = getHistory();\n history.push(ssoEnabled ? \"/sso-auth/login\" : \"/auth/login\", {\n from: {\n ...history.location,\n state: undefined,\n },\n });\n}\n"],"mappings":";AAAA,SACEA,cAAc,EACdC,cAAc,EACdC,iBAAiB,QACZ,iBAAiB;AACxB,SAASC,IAAI,QAAQ,iBAAiB;AACtC,SAASC,UAAU,QAAQ,uBAAuB;AAClD,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,CAAC,EAAEC,EAAE,QAAQ,oBAAoB;AAC1C,SAASC,MAAM,QAAQ,aAAa;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAACC,KAAc,EAAU;EACxD,IAAIA,KAAK,YAAYC,KAAK,IAAID,KAAK,CAACE,MAAM,YAAYC,iBAAiB,EAAE;IACvE,OAAOH,KAAK,CAACE,MAAM,CAACE,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0B,qBAAqB,EAAG;MACnDC,IAAIA,CAAA,EAAG;QACLC,eAAe,EAAE;QACjBZ,yBAAyB,GAAG,KAAK;MACnC,CAAC;MACDa,QAAQA,CAAA,EAAG;QACTb,yBAAyB,GAAG,KAAK;MACnC;IACF,CAAC,CAAC;IACF;EACF;;EAEA;EACAc,OAAO,CAAC1B,KAAK,CAACA,KAAK,CAAC;EAEpB,IAAM2B,OAAO,GAAG5B,iBAAiB,CAACC,KAAK,CAAC;EACxC,IAAI2B,OAAO,KAAKd,gBAAgB,EAAE;IAChCA,gBAAgB,GAAGc,OAAO;IAC1B7B,MAAM,CAACmB,IAAI,CAAC;MACVC,IAAI,EAAE,OAAO;MACbU,KAAK,EAAEnC,IAAI,CAAC2B,CAAC,IAAAC,MAAA,CAAIxB,EAAE,OAAAwB,MAAA,CAAIzB,CAAC,CAACiC,cAAc,EAAG;MAC1CV,OAAO,EAAEQ,OAAO;MAChBG,UAAU,EAAE,UAAU;MACtBP,IAAIA,CAAA,EAAG;QACLV,gBAAgB,GAAGkB,SAAS;MAC9B;IACF,CAAC,CAAC;EACJ;EACA;AACF;AAEA,SAASP,eAAeA,CAAA,EAAG;EACzB,IAAMQ,UAAU,GAAGtC,UAAU,EAAE,CAACuC,eAAe,EAAE,CAAC,aAAa,CAAC;EAChE,IAAMC,OAAO,GAAGvC,UAAU,EAAE;EAC5BuC,OAAO,CAACC,IAAI,CAACH,UAAU,GAAG,iBAAiB,GAAG,aAAa,EAAE;IAC3DI,IAAI,EAAAC,aAAA,CAAAA,aAAA,KACCH,OAAO,CAACI,QAAQ;MACnBC,KAAK,EAAER;IAAS;EAEpB,CAAC,CAAC;AACJ"}
package/dist/esm/index.js CHANGED
@@ -7,12 +7,14 @@ export * from "./getPageInfo.js";
7
7
  export * from "./handleHttpError.js";
8
8
  export * from "./history.js";
9
9
  export { createRuntime, getRuntime } from "./internal/Runtime.js";
10
- import * as _secret_internals from "./internal/secret_internals.js";
11
- export { _secret_internals as __secret_internals };
10
+ import * as __secret_internals from "./internal/secret_internals.js";
11
+ export { __secret_internals };
12
12
  export { getCssPropertyValue, getCurrentTheme, getCurrentMode, batchSetAppsLocalTheme, applyTheme } from "./themeAndMode.js";
13
13
  export { checkIfOfComputed, checkIfByTransform } from "./internal/compute/checkIf.js";
14
14
  export { registerWidgetFunctions } from "./internal/compute/WidgetFunctions.js";
15
15
  export { registerWidgetI18n } from "./internal/compute/WidgetI18n.js";
16
16
  export { StoryboardFunctionRegistryFactory } from "./StoryboardFunctionRegistry.js";
17
17
  export { matchPath } from "./internal/matchPath.js";
18
+ export { Notification } from "./Notification.js";
19
+ export { Dialog } from "./Dialog.js";
18
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createRuntime","getRuntime","_secret_internals","__secret_internals","getCssPropertyValue","getCurrentTheme","getCurrentMode","batchSetAppsLocalTheme","applyTheme","checkIfOfComputed","checkIfByTransform","registerWidgetFunctions","registerWidgetI18n","StoryboardFunctionRegistryFactory","matchPath"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomProcessors.js\";\nexport * from \"./CustomTemplates.js\";\nexport * from \"./fetchByProvider.js\";\nexport * from \"./getBasePath.js\";\nexport * from \"./getPageInfo.js\";\nexport * from \"./handleHttpError.js\";\nexport * from \"./history.js\";\nexport { createRuntime, getRuntime } from \"./internal/Runtime.js\";\nexport * as __secret_internals from \"./internal/secret_internals.js\";\nexport {\n getCssPropertyValue,\n getCurrentTheme,\n getCurrentMode,\n batchSetAppsLocalTheme,\n applyTheme,\n} from \"./themeAndMode.js\";\nexport {\n checkIfOfComputed,\n checkIfByTransform,\n} from \"./internal/compute/checkIf.js\";\nexport { registerWidgetFunctions } from \"./internal/compute/WidgetFunctions.js\";\nexport { registerWidgetI18n } from \"./internal/compute/WidgetI18n.js\";\nexport { StoryboardFunctionRegistryFactory } from \"./StoryboardFunctionRegistry.js\";\nexport { matchPath } from \"./internal/matchPath.js\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,cAAc;AAC5B,SAASA,aAAa,EAAEC,UAAU,QAAQ,uBAAuB;AAAC,YAAAC,iBAAA,MAC9B,gCAAgC;AAAA,SAAAA,iBAAA,IAAxDC,kBAAkB;AAC9B,SACEC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,EACdC,sBAAsB,EACtBC,UAAU,QACL,mBAAmB;AAC1B,SACEC,iBAAiB,EACjBC,kBAAkB,QACb,+BAA+B;AACtC,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,iCAAiC,QAAQ,iCAAiC;AACnF,SAASC,SAAS,QAAQ,yBAAyB"}
1
+ {"version":3,"file":"index.js","names":["createRuntime","getRuntime","__secret_internals","getCssPropertyValue","getCurrentTheme","getCurrentMode","batchSetAppsLocalTheme","applyTheme","checkIfOfComputed","checkIfByTransform","registerWidgetFunctions","registerWidgetI18n","StoryboardFunctionRegistryFactory","matchPath","Notification","Dialog"],"sources":["../../src/index.ts"],"sourcesContent":["export * from \"./auth.js\";\nexport * from \"./CustomProcessors.js\";\nexport * from \"./CustomTemplates.js\";\nexport * from \"./fetchByProvider.js\";\nexport * from \"./getBasePath.js\";\nexport * from \"./getPageInfo.js\";\nexport * from \"./handleHttpError.js\";\nexport * from \"./history.js\";\nexport { createRuntime, getRuntime } from \"./internal/Runtime.js\";\nimport * as __secret_internals from \"./internal/secret_internals.js\";\nexport { __secret_internals };\nexport {\n getCssPropertyValue,\n getCurrentTheme,\n getCurrentMode,\n batchSetAppsLocalTheme,\n applyTheme,\n} from \"./themeAndMode.js\";\nexport {\n checkIfOfComputed,\n checkIfByTransform,\n} from \"./internal/compute/checkIf.js\";\nexport { registerWidgetFunctions } from \"./internal/compute/WidgetFunctions.js\";\nexport { registerWidgetI18n } from \"./internal/compute/WidgetI18n.js\";\nexport { StoryboardFunctionRegistryFactory } from \"./StoryboardFunctionRegistry.js\";\nexport { matchPath } from \"./internal/matchPath.js\";\nexport { Notification, type NotificationOptions } from \"./Notification.js\";\nexport { Dialog, type DialogOptions } from \"./Dialog.js\";\n"],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,uBAAuB;AACrC,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,cAAc;AAC5B,SAASA,aAAa,EAAEC,UAAU,QAAQ,uBAAuB;AACjE,OAAO,KAAKC,kBAAkB,MAAM,gCAAgC;AACpE,SAASA,kBAAkB;AAC3B,SACEC,mBAAmB,EACnBC,eAAe,EACfC,cAAc,EACdC,sBAAsB,EACtBC,UAAU,QACL,mBAAmB;AAC1B,SACEC,iBAAiB,EACjBC,kBAAkB,QACb,+BAA+B;AACtC,SAASC,uBAAuB,QAAQ,uCAAuC;AAC/E,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,iCAAiC,QAAQ,iCAAiC;AACnF,SAASC,SAAS,QAAQ,yBAAyB;AACnD,SAASC,YAAY,QAAkC,mBAAmB;AAC1E,SAASC,MAAM,QAA4B,aAAa"}
@@ -19,7 +19,7 @@ export function bindTemplateProxy(brick) {
19
19
  tplHostMetadata.internalBricksByRef.set(ref, brick);
20
20
  var events = (_tplHostMetadata$prox = tplHostMetadata.proxy) === null || _tplHostMetadata$prox === void 0 ? void 0 : _tplHostMetadata$prox.events;
21
21
  if (events) {
22
- var _loop = function (from, to) {
22
+ var _loop = function (from) {
23
23
  if (to.ref === ref) {
24
24
  var _to$refEvent, _ref, _ref$$$proxyListeners;
25
25
  var listener = e => {
@@ -40,7 +40,7 @@ export function bindTemplateProxy(brick) {
40
40
  }
41
41
  };
42
42
  for (var [from, to] of Object.entries(events)) {
43
- _loop(from, to);
43
+ _loop(from);
44
44
  }
45
45
  }
46
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext.tplStateStoreId || !ref) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"unbindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.delete(ref);\n\n for (const [type, fn] of element!.$$proxyListeners ?? []) {\n element!.removeEventListener(type, fn);\n }\n delete element!.$$proxyListeners;\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEC;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACP,GAAG,EAAEF,KAAK,CAAC;EAEnD,IAAMU,MAAM,IAAAT,qBAAA,GAAGM,eAAe,CAACI,KAAK,cAAAV,qBAAA,uBAArBA,qBAAA,CAAuBS,MAAM;EAC5C,IAAIA,MAAM,EAAE;IAAA,IAAAE,KAAA,YAAAA,CACEC,IAAI,EAAEC,EAAE;MAClB,IAAIA,EAAE,CAACZ,GAAG,KAAKA,GAAG,EAAE;QAAA,IAAAa,YAAA,EAAAC,IAAA,EAAAC,qBAAA;QAClB,IAAMC,QAAQ,GAAIC,CAAQ,IAAK;UAC7B,IAAIA,CAAC,CAACC,OAAO,EAAE;YACbD,CAAC,CAACE,eAAe,EAAE;UACrB;UACAf,SAAS,CAAEF,OAAO,CAAEkB,aAAa,CAC/B,IAAIC,WAAW,CAACV,IAAI,EAAE;YACpBW,MAAM,EAAGL,CAAC,CAAiBK,MAAM;YACjCJ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A,IAAAA,iBAAA;IACxDlC,OAAO,CAAEmC,mBAAmB,CAACH,IAAI,EAAEC,EAAE,CAAC;EACxC;EACA,OAAOjC,OAAO,CAAE0B,gBAAgB;AAClC"}
1
+ {"version":3,"file":"bindTemplateProxy.js","names":["getTplStateStore","bindTemplateProxy","brick","_tplHostMetadata$prox","ref","runtimeContext","element","tplStateStoreId","hostBrick","tplHostMetadata","internalBricksByRef","set","events","proxy","_loop","from","to","_to$refEvent","_ref","_ref$$$proxyListeners","listener","e","bubbles","stopPropagation","dispatchEvent","CustomEvent","detail","cancelable","composed","eventType","refEvent","addEventListener","$$proxyListeners","push","Object","entries","unbindTemplateProxy","delete","type","fn","_$$proxyListeners","removeEventListener"],"sources":["../../../../src/internal/CustomTemplates/bindTemplateProxy.ts"],"sourcesContent":["import type { RuntimeBrick } from \"../interfaces.js\";\nimport { getTplStateStore } from \"./utils.js\";\n\nexport function bindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n // Error recovering brick may have no runtimeContext.\n if (!ref || !runtimeContext.tplStateStoreId) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"bindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.set(ref, brick);\n\n const events = tplHostMetadata.proxy?.events;\n if (events) {\n for (const [from, to] of Object.entries(events)) {\n if (to.ref === ref) {\n const listener = (e: Event) => {\n if (e.bubbles) {\n e.stopPropagation();\n }\n hostBrick!.element!.dispatchEvent(\n new CustomEvent(from, {\n detail: (e as CustomEvent).detail,\n bubbles: e.bubbles,\n cancelable: e.cancelable,\n composed: e.composed,\n })\n );\n };\n const eventType = to.refEvent ?? from;\n element!.addEventListener(eventType, listener);\n element!.$$proxyListeners ??= [];\n element!.$$proxyListeners.push([eventType, listener]);\n }\n }\n }\n}\n\nexport function unbindTemplateProxy(brick: RuntimeBrick) {\n const { ref, runtimeContext, element } = brick;\n\n if (!runtimeContext.tplStateStoreId || !ref) {\n return;\n }\n\n const { hostBrick } = getTplStateStore(runtimeContext, \"unbindTemplateProxy\");\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const tplHostMetadata = hostBrick!.tplHostMetadata!;\n\n tplHostMetadata.internalBricksByRef.delete(ref);\n\n for (const [type, fn] of element!.$$proxyListeners ?? []) {\n element!.removeEventListener(type, fn);\n }\n delete element!.$$proxyListeners;\n}\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,SAASC,iBAAiBA,CAACC,KAAmB,EAAE;EAAA,IAAAC,qBAAA;EACrD,IAAM;IAAEC,GAAG;IAAEC,cAAc;IAAEC;EAAQ,CAAC,GAAGJ,KAAK;;EAE9C;EACA,IAAI,CAACE,GAAG,IAAI,CAACC,cAAc,CAACE,eAAe,EAAE;IAC3C;EACF;EAEA,IAAM;IAAEC;EAAU,CAAC,GAAGR,gBAAgB,CAACK,cAAc,EAAE,mBAAmB,CAAC;EAC3E;EACA,IAAMI,eAAe,GAAGD,SAAS,CAAEC,eAAgB;EAEnDA,eAAe,CAACC,mBAAmB,CAACC,GAAG,CAACP,GAAG,EAAEF,KAAK,CAAC;EAEnD,IAAMU,MAAM,IAAAT,qBAAA,GAAGM,eAAe,CAACI,KAAK,cAAAV,qBAAA,uBAArBA,qBAAA,CAAuBS,MAAM;EAC5C,IAAIA,MAAM,EAAE;IAAA,IAAAE,KAAA,YAAAA,CAAAC,IAAA,EACuC;MAC/C,IAAIC,EAAE,CAACZ,GAAG,KAAKA,GAAG,EAAE;QAAA,IAAAa,YAAA,EAAAC,IAAA,EAAAC,qBAAA;QAClB,IAAMC,QAAQ,GAAIC,CAAQ,IAAK;UAC7B,IAAIA,CAAC,CAACC,OAAO,EAAE;YACbD,CAAC,CAACE,eAAe,EAAE;UACrB;UACAf,SAAS,CAAEF,OAAO,CAAEkB,aAAa,CAC/B,IAAIC,WAAW,CAACV,I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