@next-core/runtime 1.4.2 → 1.5.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 (75) hide show
  1. package/dist/cjs/createRoot.js +5 -2
  2. package/dist/cjs/createRoot.js.map +1 -1
  3. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js +2 -1
  4. package/dist/cjs/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  5. package/dist/cjs/internal/CustomTemplates/utils.js.map +1 -1
  6. package/dist/cjs/internal/FormRenderer/constants.js +11 -0
  7. package/dist/cjs/internal/FormRenderer/constants.js.map +1 -0
  8. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js +122 -0
  9. package/dist/cjs/internal/FormRenderer/expandFormRenderer.js.map +1 -0
  10. package/dist/cjs/internal/FormRenderer/getDefaultProperties.js +165 -0
  11. package/dist/cjs/internal/FormRenderer/getDefaultProperties.js.map +1 -0
  12. package/dist/cjs/internal/FormRenderer/interfaces.js +6 -0
  13. package/dist/cjs/internal/FormRenderer/interfaces.js.map +1 -0
  14. package/dist/cjs/internal/FormRenderer/utils.js +20 -0
  15. package/dist/cjs/internal/FormRenderer/utils.js.map +1 -0
  16. package/dist/cjs/internal/Renderer.js +38 -5
  17. package/dist/cjs/internal/Renderer.js.map +1 -1
  18. package/dist/cjs/internal/RendererContext.js +4 -1
  19. package/dist/cjs/internal/RendererContext.js.map +1 -1
  20. package/dist/cjs/internal/Router.js +3 -2
  21. package/dist/cjs/internal/Router.js.map +1 -1
  22. package/dist/cjs/internal/bindListeners.js +9 -2
  23. package/dist/cjs/internal/bindListeners.js.map +1 -1
  24. package/dist/cjs/internal/compute/evaluate.js +21 -6
  25. package/dist/cjs/internal/compute/evaluate.js.map +1 -1
  26. package/dist/cjs/internal/compute/listenOnTrackingContext.js +7 -9
  27. package/dist/cjs/internal/compute/listenOnTrackingContext.js.map +1 -1
  28. package/dist/cjs/internal/data/DataStore.js +2 -2
  29. package/dist/cjs/internal/data/DataStore.js.map +1 -1
  30. package/dist/cjs/internal/interfaces.js.map +1 -1
  31. package/dist/cjs/internal/secret_internals.js +6 -3
  32. package/dist/cjs/internal/secret_internals.js.map +1 -1
  33. package/dist/esm/createRoot.js +5 -2
  34. package/dist/esm/createRoot.js.map +1 -1
  35. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js +2 -1
  36. package/dist/esm/internal/CustomTemplates/expandCustomTemplate.js.map +1 -1
  37. package/dist/esm/internal/CustomTemplates/utils.js.map +1 -1
  38. package/dist/esm/internal/FormRenderer/constants.js +3 -0
  39. package/dist/esm/internal/FormRenderer/constants.js.map +1 -0
  40. package/dist/esm/internal/FormRenderer/expandFormRenderer.js +111 -0
  41. package/dist/esm/internal/FormRenderer/expandFormRenderer.js.map +1 -0
  42. package/dist/esm/internal/FormRenderer/getDefaultProperties.js +136 -0
  43. package/dist/esm/internal/FormRenderer/getDefaultProperties.js.map +1 -0
  44. package/dist/esm/internal/FormRenderer/interfaces.js +2 -0
  45. package/dist/esm/internal/FormRenderer/interfaces.js.map +1 -0
  46. package/dist/esm/internal/FormRenderer/utils.js +15 -0
  47. package/dist/esm/internal/FormRenderer/utils.js.map +1 -0
  48. package/dist/esm/internal/Renderer.js +48 -12
  49. package/dist/esm/internal/Renderer.js.map +1 -1
  50. package/dist/esm/internal/RendererContext.js +4 -1
  51. package/dist/esm/internal/RendererContext.js.map +1 -1
  52. package/dist/esm/internal/Router.js +3 -2
  53. package/dist/esm/internal/Router.js.map +1 -1
  54. package/dist/esm/internal/bindListeners.js +9 -2
  55. package/dist/esm/internal/bindListeners.js.map +1 -1
  56. package/dist/esm/internal/compute/evaluate.js +22 -9
  57. package/dist/esm/internal/compute/evaluate.js.map +1 -1
  58. package/dist/esm/internal/compute/listenOnTrackingContext.js +7 -9
  59. package/dist/esm/internal/compute/listenOnTrackingContext.js.map +1 -1
  60. package/dist/esm/internal/data/DataStore.js +2 -2
  61. package/dist/esm/internal/data/DataStore.js.map +1 -1
  62. package/dist/esm/internal/interfaces.js.map +1 -1
  63. package/dist/esm/internal/secret_internals.js +6 -3
  64. package/dist/esm/internal/secret_internals.js.map +1 -1
  65. package/dist/types/createRoot.d.ts +7 -1
  66. package/dist/types/internal/CustomTemplates/expandCustomTemplate.d.ts +1 -1
  67. package/dist/types/internal/FormRenderer/constants.d.ts +7 -0
  68. package/dist/types/internal/FormRenderer/expandFormRenderer.d.ts +3 -0
  69. package/dist/types/internal/FormRenderer/getDefaultProperties.d.ts +2 -0
  70. package/dist/types/internal/FormRenderer/interfaces.d.ts +30 -0
  71. package/dist/types/internal/FormRenderer/utils.d.ts +5 -0
  72. package/dist/types/internal/Renderer.d.ts +2 -3
  73. package/dist/types/internal/RendererContext.d.ts +5 -1
  74. package/dist/types/internal/interfaces.d.ts +6 -0
  75. package/package.json +2 -2
@@ -17,7 +17,8 @@ var _registerAppI18n = require("./internal/registerAppI18n.js");
17
17
  var _registerCustomTemplates = require("./internal/registerCustomTemplates.js");
18
18
  function unstable_createRoot(container, {
19
19
  portal: _portal,
20
- scope = "fragment"
20
+ scope = "fragment",
21
+ unknownBricks
21
22
  } = {}) {
22
23
  let portal = _portal;
23
24
  let createPortal;
@@ -54,7 +55,9 @@ function unstable_createRoot(container, {
54
55
  tplStateStoreMap: new Map()
55
56
  };
56
57
  const previousRendererContext = rendererContext;
57
- rendererContext = new _RendererContext.RendererContext(scope);
58
+ rendererContext = new _RendererContext.RendererContext(scope, {
59
+ unknownBricks
60
+ });
58
61
  const renderRoot = {
59
62
  tag: _enums.RenderTag.ROOT,
60
63
  container,
@@ -1 +1 @@
1
- {"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\" }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope);\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\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 flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\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?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n setTheme(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 (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AACA,IAAAS,gB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;;QACArE,eAAe,CAACsE,eAAe,EAAE;QACjCtE,eAAe,CAACuE,wBAAwB,EAAE;QAC1CvE,eAAe,CAACwE,qBAAqB,EAAE;MACzC;IACF,CAAC;IACDC,OAAOA,CAAA,EAAG;MACR,IAAI1E,SAAS,EAAE;QACb;MACF;MACAA,SAAS,GAAG,IAAI;MAChB,IAAA6D,kBAAW,EAAC1E,SAAS,CAAC;MACtB,IAAIC,MAAM,EAAE;QACV,IAAAyE,kBAAW,EAACzE,MAAM,CAAC;QACnB;QACA,IAAI,CAACC,OAAO,EAAE;UACZD,MAAM,CAACuF,MAAM,EAAE;QACjB;MACF;IACF;EACF,CAAC;AACH"}
1
+ {"version":3,"file":"createRoot.js","names":["_loader","require","_Renderer","_RendererContext","_DataStore","_mount","_handleHttpError","_themeAndMode","_enums","_StoryboardFunctions","_registerAppI18n","_registerCustomTemplates","unstable_createRoot","container","portal","_portal","scope","unknownBricks","createPortal","document","createElement","style","position","width","height","body","append","unmounted","rendererContext","clearI18nBundles","render","brick","theme","context","functions","templates","i18n","i18nData","Error","bricks","concat","runtimeContext","ctxStore","DataStore","pendingPermissionsPreCheck","tplStateStoreMap","Map","previousRendererContext","RendererContext","renderRoot","tag","RenderTag","ROOT","_clearI18nBundles","demoApp","id","homepage","app","demoStoryboard","meta","customTemplates","registerAppI18n","registerCustomTemplates","registerStoryboardFunctions","define","failed","output","renderBricks","flushStableLoadBricks","Promise","all","blockingList","waitForAll","values","map","store","error","node","BRICK","type","properties","textContent","httpErrorToString","return","menuRequests","child","dispatchOnUnmount","dispose","unmountTree","setTheme","setMode","dispatchBeforePageLoad","applyTheme","applyMode","mountTree","window","scrollTo","dispatchPageLoad","dispatchOnMount","initializeScrollIntoView","initializeMediaChange","unmount","remove"],"sources":["../../src/createRoot.ts"],"sourcesContent":["import type {\n BrickConf,\n ContextConf,\n CustomTemplate,\n MetaI18n,\n MicroApp,\n SiteTheme,\n Storyboard,\n StoryboardFunction,\n} from \"@next-core/types\";\nimport { flushStableLoadBricks } from \"@next-core/loader\";\nimport { RenderOutput, renderBricks } from \"./internal/Renderer.js\";\nimport { RendererContext } from \"./internal/RendererContext.js\";\nimport { DataStore } from \"./internal/data/DataStore.js\";\nimport type { RenderRoot, RuntimeContext } from \"./internal/interfaces.js\";\nimport { mountTree, unmountTree } from \"./internal/mount.js\";\nimport { httpErrorToString } from \"./handleHttpError.js\";\nimport { applyMode, applyTheme, setMode, setTheme } from \"./themeAndMode.js\";\nimport { RenderTag } from \"./internal/enums.js\";\nimport { registerStoryboardFunctions } from \"./internal/compute/StoryboardFunctions.js\";\nimport { registerAppI18n } from \"./internal/registerAppI18n.js\";\nimport { registerCustomTemplates } from \"./internal/registerCustomTemplates.js\";\n\nexport interface CreateRootOptions {\n portal?: HTMLElement;\n /**\n * Defaults to \"fragment\", only set it to \"page\" when the root is in a standalone iframe.\n * - page: render as whole page, triggering page life cycles, and enable register of functions/templates/i18n.\n * - fragment: render as fragment, not triggering page life cycles, and disable register of functions/templates/i18n.\n */\n scope?: \"page\" | \"fragment\";\n\n /**\n * Whether to throw error when encountering unknown bricks.\n *\n * Defaults to \"throw\".\n */\n unknownBricks?: \"silent\" | \"throw\";\n}\n\nexport interface RenderOptions {\n theme?: SiteTheme;\n context?: ContextConf[];\n functions?: StoryboardFunction[];\n templates?: CustomTemplate[];\n i18n?: MetaI18n;\n}\n\nexport function unstable_createRoot(\n container: HTMLElement,\n { portal: _portal, scope = \"fragment\", unknownBricks }: CreateRootOptions = {}\n) {\n let portal = _portal;\n let createPortal: RenderRoot[\"createPortal\"];\n if (_portal) {\n createPortal = _portal;\n } else {\n // Create portal container when necessary.\n createPortal = () => {\n portal = document.createElement(\"div\");\n portal.style.position = \"absolute\";\n portal.style.width = portal.style.height = \"0\";\n document.body.append(portal);\n return portal;\n };\n }\n let unmounted = false;\n let rendererContext: RendererContext | undefined;\n let clearI18nBundles: Function | undefined;\n\n return {\n async render(\n brick: BrickConf | BrickConf[],\n {\n theme,\n context,\n functions,\n templates,\n i18n: i18nData,\n }: RenderOptions = {}\n ) {\n if (unmounted) {\n throw new Error(\n \"The root is unmounted and cannot be rendered any more\"\n );\n }\n const bricks = ([] as BrickConf[]).concat(brick);\n const runtimeContext = {\n ctxStore: new DataStore(\"CTX\"),\n pendingPermissionsPreCheck: [],\n tplStateStoreMap: new Map<string, DataStore<\"STATE\">>(),\n } as Partial<RuntimeContext> as RuntimeContext;\n\n const previousRendererContext = rendererContext;\n rendererContext = new RendererContext(scope, { unknownBricks });\n\n const renderRoot: RenderRoot = {\n tag: RenderTag.ROOT,\n container,\n createPortal,\n };\n\n if (scope === \"page\") {\n const demoApp = {\n id: \"demo\",\n homepage: \"/demo\",\n } as MicroApp;\n runtimeContext.app = demoApp;\n const demoStoryboard = {\n app: demoApp,\n meta: {\n i18n: i18nData,\n customTemplates: templates,\n },\n } as Storyboard;\n\n // Register i18n.\n clearI18nBundles?.();\n clearI18nBundles = registerAppI18n(demoStoryboard);\n\n // Register custom templates.\n registerCustomTemplates(demoStoryboard);\n\n // Register functions.\n registerStoryboardFunctions(functions, demoApp);\n }\n\n runtimeContext.ctxStore.define(context, runtimeContext);\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 flushStableLoadBricks();\n\n await Promise.all([\n ...output.blockingList,\n runtimeContext.ctxStore.waitForAll(),\n ...[...runtimeContext.tplStateStoreMap.values()].map((store) =>\n store.waitForAll()\n ),\n ...runtimeContext.pendingPermissionsPreCheck,\n ]);\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?.dispatchOnUnmount();\n previousRendererContext?.dispose();\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n }\n\n if (scope === \"page\") {\n setTheme(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 (scope === \"page\") {\n window.scrollTo(0, 0);\n }\n\n if (!failed) {\n if (scope === \"page\") {\n rendererContext.dispatchPageLoad();\n // rendererContext.dispatchAnchorLoad();\n }\n rendererContext.dispatchOnMount();\n rendererContext.initializeScrollIntoView();\n rendererContext.initializeMediaChange();\n }\n },\n unmount() {\n if (unmounted) {\n return;\n }\n unmounted = true;\n unmountTree(container);\n if (portal) {\n unmountTree(portal);\n // Only remove the portal from its parent when it's dynamic created.\n if (!_portal) {\n portal.remove();\n }\n }\n },\n };\n}\n"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,oBAAA,GAAAR,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AACA,IAAAU,wBAAA,GAAAV,OAAA;AA2BO,SAASW,mBAAmBA,CACjCC,SAAsB,EACtB;EAAEC,MAAM,EAAEC,OAAO;EAAEC,KAAK,GAAG,UAAU;EAAEC;AAAiC,CAAC,GAAG,CAAC,CAAC,EAC9E;EACA,IAAIH,MAAM,GAAGC,OAAO;EACpB,IAAIG,YAAwC;EAC5C,IAAIH,OAAO,EAAE;IACXG,YAAY,GAAGH,OAAO;EACxB,CAAC,MAAM;IACL;IACAG,YAAY,GAAGA,CAAA,KAAM;MACnBJ,MAAM,GAAGK,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;MACtCN,MAAM,CAACO,KAAK,CAACC,QAAQ,GAAG,UAAU;MAClCR,M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 +18,9 @@ function expandCustomTemplate(tplTagName, brickConf, hostBrick, asyncHostPropert
18
18
  tplStateStoreId
19
19
  };
20
20
 
21
- // There is a boundary for `forEachItem` between template internals and externals.
21
+ // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.
22
22
  delete runtimeContext.forEachItem;
23
+ delete runtimeContext.formStateStoreId;
23
24
  const tplStateStore = new _DataStore.DataStore("STATE", hostBrick);
24
25
  runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);
25
26
  if (runtimeContext.tplStateStoreScope) {
@@ -1 +1 @@
1
- {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_CollectContracts","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostProperties","tplStateStoreId","uniqueId","runtimeContext","forEachItem","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { collectWidgetContract } from \"../data/CollectContracts.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties | undefined\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` between template internals and externals.\n delete runtimeContext.forEachItem;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostProperties);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostProperties,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACv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AAqBA,CAC5BC,mBAAwC,EACxCP,WAAgC,EACA;EAChC;EACA,IAAIO,mBAAmB,CAACC,EAAE,KAAK,IAAI,EAAE;IACnC,OAAOD,mBAAmB,CAACC,EAAE;EAC/B;EACA,MAAM;IACJf,UAAU;IACVX,KAAK,EAAE2B,eAAe;IACtBzB,QAAQ,EAAE0B,kBAAkB;IAC5B,GAAGC;EACL,CAAC,GAAGJ,mBAAmB;EAEvB,MAAMK,eAAe,GAAG,IAAAV,yBAAe,EACrCQ,kBAAkB,EAClBD,eAAe,CACmB;EAEpC,MAAM3B,KAAwB,GAAGc,MAAM,CAACiB,WAAW,CACjDjB,MAAM,CAACC,OAAO,CAACe,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAI,CAAC,CAAC,CAAC,CAACR,GAAG,CAAC,CAAC,CAACU,QAAQ,EAAEC,QAAQ,CAAC;IAAA,IAAAC,gBAAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd7B,MAAM,EAAE,EAAA0C,gBAAA,GAACD,QAAQ,CAACzC,MAAM,cAAA0C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CAAC;IAE5C,CAAC,CACF;EAAA,EAAC,CACH;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
1
+ {"version":3,"file":"expandCustomTemplate.js","names":["_lodash","require","_CustomTemplates","_DataStore","_setupTemplateProxy","_setupUseBrickInTemplate","_Renderer","_CollectContracts","expandCustomTemplate","tplTagName","brickConf","hostBrick","asyncHostProperties","tplStateStoreId","uniqueId","runtimeContext","forEachItem","formStateStoreId","tplStateStore","DataStore","tplStateStoreMap","set","tplStateStoreScope","push","bricks","proxy","state","contracts","customTemplates","get","collectWidgetContract","define","slots","originalExternalSlots","children","externalChildren","restBrickConf","newBrickConf","brick","tplHostMetadata","internalBricksByRef","Map","reversedProxies","properties","from","to","Object","entries","proxies","ref","hostContext","externalSlots","childrenToSlots","type","map","item","expandBrickInTemplate","brickConfInTemplate","if","slotsInTemplate","childrenInTemplate","restBrickConfInTemplate","transpiledSlots","fromEntries","slotName","slotConf","_slotConf$bricks","setupUseBrickInTemplate","setupTemplateProxy"],"sources":["../../../../src/internal/CustomTemplates/expandCustomTemplate.ts"],"sourcesContent":["import type {\n BrickConf,\n BrickConfInTemplate,\n SlotsConfInTemplate,\n SlotsConfOfBricks,\n UseSingleBrickConf,\n} from \"@next-core/types\";\nimport { uniqueId } from \"lodash\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport { RuntimeBrickConfWithTplSymbols } from \"./constants.js\";\nimport { setupTemplateProxy } from \"./setupTemplateProxy.js\";\nimport type {\n AsyncProperties,\n RuntimeBrick,\n TemplateHostBrick,\n TemplateHostContext,\n} from \"../interfaces.js\";\nimport { setupUseBrickInTemplate } from \"./setupUseBrickInTemplate.js\";\nimport { childrenToSlots } from \"../Renderer.js\";\nimport { collectWidgetContract } from \"../data/CollectContracts.js\";\n\nexport function expandCustomTemplate<T extends BrickConf | UseSingleBrickConf>(\n tplTagName: string,\n brickConf: T,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): T {\n const tplStateStoreId = uniqueId(\"tpl-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n tplStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `FORM_STATE` between template internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.formStateStoreId;\n\n const tplStateStore = new DataStore(\"STATE\", hostBrick);\n runtimeContext.tplStateStoreMap.set(tplStateStoreId, tplStateStore);\n if (runtimeContext.tplStateStoreScope) {\n runtimeContext.tplStateStoreScope.push(tplStateStore);\n }\n\n const { bricks, proxy, state, contracts } = customTemplates.get(tplTagName)!;\n collectWidgetContract(contracts);\n tplStateStore.define(state, runtimeContext, asyncHostProperties);\n\n const {\n slots: originalExternalSlots,\n children: externalChildren,\n ...restBrickConf\n } = brickConf;\n\n const newBrickConf = {\n ...restBrickConf,\n brick: tplTagName,\n } as T;\n\n hostBrick.tplHostMetadata = {\n internalBricksByRef: new Map(),\n tplStateStoreId,\n proxy,\n };\n\n // Reversed proxies are used for expand storyboard before rendering page.\n const reversedProxies: TemplateHostContext[\"reversedProxies\"] = {\n properties: new Map(),\n slots: new Map(),\n // mergeBases: new Map(),\n };\n\n if (proxy?.properties) {\n for (const [from, to] of Object.entries(proxy.properties)) {\n let proxies = reversedProxies.properties.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.properties.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n if (proxy?.slots) {\n for (const [from, to] of Object.entries(proxy.slots)) {\n let proxies = reversedProxies.slots.get(to.ref);\n if (!proxies) {\n proxies = [];\n reversedProxies.slots.set(to.ref, proxies);\n }\n proxies.push({\n from,\n to,\n });\n }\n }\n\n const hostContext: TemplateHostContext = {\n reversedProxies,\n asyncHostProperties,\n externalSlots: childrenToSlots(externalChildren, originalExternalSlots) as\n | SlotsConfOfBricks\n | undefined,\n tplStateStoreId,\n hostBrick: hostBrick as TemplateHostBrick,\n };\n\n newBrickConf.slots = {\n \"\": {\n type: \"bricks\",\n bricks: bricks.map((item) => expandBrickInTemplate(item, hostContext)),\n },\n };\n\n return newBrickConf;\n}\n\nfunction expandBrickInTemplate(\n brickConfInTemplate: BrickConfInTemplate,\n hostContext: TemplateHostContext\n): RuntimeBrickConfWithTplSymbols {\n // Ignore `if: null` to make `looseCheckIf` working.\n if (brickConfInTemplate.if === null) {\n delete brickConfInTemplate.if;\n }\n const {\n properties,\n slots: slotsInTemplate,\n children: childrenInTemplate,\n ...restBrickConfInTemplate\n } = brickConfInTemplate;\n\n const transpiledSlots = childrenToSlots(\n childrenInTemplate,\n slotsInTemplate\n ) as SlotsConfInTemplate | undefined;\n\n const slots: SlotsConfOfBricks = Object.fromEntries(\n Object.entries(transpiledSlots ?? {}).map(([slotName, slotConf]) => [\n slotName,\n {\n type: \"bricks\",\n bricks: (slotConf.bricks ?? []).map((item) =>\n expandBrickInTemplate(item, hostContext)\n ),\n },\n ])\n );\n\n return {\n ...restBrickConfInTemplate,\n properties: setupUseBrickInTemplate(properties, hostContext),\n slots,\n ...setupTemplateProxy(hostContext, restBrickConfInTemplate.ref, slots),\n };\n}\n"],"mappings":";;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,mBAAA,GAAAH,OAAA;AAOA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AAEO,SAASO,oBAAoBA,CAClCC,UAAkB,EAClBC,SAAY,EACZC,SAAuB,EACvBC,mBAAoC,EACjC;EACH,MAAMC,eAAe,GAAG,IAAAC,gBAAQ,EAAC,YAAY,CAAC;EAC9C,MAAMC,cAAc,GAAG;IACrB,GAAGJ,SAAS,CAACI,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAAc,CAACC,WAAW;EACjC,OAAOD,cAAc,CAACE,gBAAgB;EAEtC,MAAMC,aAAa,GAAG,IAAIC,oBAAS,CAAC,OAAO,EAAER,SAAS,CAAC;EACvDI,cAAc,CAACK,gBAAgB,CAACC,GAAG,CAACR,eAAe,EAAEK,aAAa,CAAC;EACnE,IAAIH,cAAc,CAACO,kBAAkB,EAAE;IACrCP,cAAc,CAACO,kBAAkB,CAACC,IAAI,CAACL,aAAa,CAAC;EACvD;EAEA,MAAM;IAAEM,MAAM;IAA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CAAC,CAAC,CAACR,GAAG,CAAC,CAAC,CAACU,QAAQ,EAAEC,QAAQ,CAAC;IAAA,IAAAC,gBAAA;IAAA,OAAK,CAClEF,QAAQ,EACR;MACEX,IAAI,EAAE,QAAQ;MACd7B,MAAM,EAAE,EAAA0C,gBAAA,GAACD,QAAQ,CAACzC,MAAM,cAAA0C,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEZ,GAAG,CAAEC,IAAI,IACvCC,qBAAqB,CAACD,IAAI,EAAEL,WAAW,CAAC;IAE5C,CAAC,CACF;EAAA,EAAC,CACH;EAED,OAAO;IACL,GAAGW,uBAAuB;IAC1BlB,UAAU,EAAE,IAAAwB,gDAAuB,EAACxB,UAAU,EAAEO,WAAW,CAAC;IAC5DlB,KAAK;IACL,GAAG,IAAAoC,sCAAkB,EAAClB,WAAW,EAAEW,uBAAuB,CAACZ,GAAG,EAAEjB,KAAK;EACvE,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store!;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement!;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACZ,UAASF,KAAM,iCAAgCC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAG,EAAC,CAClE;EACH;EACA,MAAME,KAAK,GAAGJ,gBAAgB,CAACK,GAAG,CAACN,eAAe,CAAC;EACnD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACZ,iDAAgDF,KAAM,IACrDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDAAkD,CACpD;EACH;EACA,OAAOE,KAAK;AACd;AAEO,SAASE,iBAAiBA,CAC/BC,cAA2C,EAC3CN,KAAa,EACbC,SAAkB,EACG;EACrB,MAAME,KAAK,GAAGN,gBAAgB,CAACS,cAAc,EAAEN,KAAK,EAAEC,SAAS,CAAC;EAChE,MAAMM,WAAW,GAAGJ,KAAK,CAACK,SAAS,CAAEC,OAAO;EAC5C,IAAI,CAACF,WAAW,EAAE;IAChB,MAAM,IAAIL,KAAK,CACZ,6CAA4CF,KAAM,IACjDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDAAkD,CACpD;EACH;EACA,OAAOM,WAAW;AACpB;AAEO,SAASG,0BAA0BA,CACxCC,KAAa,EACbC,KAAc,EACE;EAChB;EACA,IAAI,CAACD,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,KAAK,CAACG,UAAU,CAAC,MAAM,CAAC,IAAIF,KAAK,EAAE;IAC7D,MAAMG,OAAO,GAAI,GAAEH,KAAM,IAAGD,KAAM,EAAC;IACnC,IAAIK,gCAAe,CAACZ,GAAG,CAACW,OAAO,CAAC,EAAE;MAChC,OAAOA,OAAO;IAChB;EACF;EACA,IAAIC,gCAAe,CAACZ,GAAG,CAACO,KAAK,CAAC,EAAE;IAC9B,OAAOA,KAAK;EACd;EACA,OAAO,KAAK;AACd"}
1
+ {"version":3,"file":"utils.js","names":["_CustomTemplates","require","getTplStateStore","tplStateStoreId","tplStateStoreMap","using","extraInfo","Error","store","get","getTplHostElement","runtimeContext","hostElement","hostBrick","element","getTagNameOfCustomTemplate","brick","appId","includes","startsWith","tagName","customTemplates"],"sources":["../../../../src/internal/CustomTemplates/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeBrickElement, RuntimeContext } from \"../interfaces.js\";\nimport { customTemplates } from \"../../CustomTemplates.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"tplStateStoreId\" | \"tplStateStoreMap\"\n>;\n\nexport function getTplStateStore(\n { tplStateStoreId, tplStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"STATE\"> {\n if (!tplStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of a custom template${extraInfo ?? \"\"}`\n );\n }\n const store = tplStateStoreMap.get(tplStateStoreId);\n if (!store) {\n throw new Error(\n `Template state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n\nexport function getTplHostElement(\n runtimeContext: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): RuntimeBrickElement {\n const store = getTplStateStore(runtimeContext, using, extraInfo);\n const hostElement = store.hostBrick!.element;\n if (!hostElement) {\n throw new Error(\n `Template host element is gone when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return hostElement;\n}\n\nexport function getTagNameOfCustomTemplate(\n brick: string,\n appId?: string\n): false | string {\n // When a template is registered by an app, it's namespace maybe missed.\n if (!brick.includes(\".\") && brick.startsWith(\"tpl-\") && appId) {\n const tagName = `${appId}.${brick}`;\n if (customTemplates.get(tagName)) {\n return tagName;\n }\n }\n if (customTemplates.get(brick)) {\n return brick;\n }\n return false;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,gBAAA,GAAAC,OAAA;AAOO,SAASC,gBAAgBA,CAC9B;EAAEC,eAAe;EAAEC;AAA8C,CAAC,EAClEC,KAAa,EACbC,SAAkB,EACE;EACpB,IAAI,CAACH,eAAe,EAAE;IACpB,MAAM,IAAII,KAAK,CACZ,UAASF,KAAM,iCAAgCC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAG,EAAC,CAClE;EACH;EACA,MAAME,KAAK,GAAGJ,gBAAgB,CAACK,GAAG,CAACN,eAAe,CAAC;EACnD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACZ,iDAAgDF,KAAM,IACrDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDAAkD,CACpD;EACH;EACA,OAAOE,KAAK;AACd;AAEO,SAASE,iBAAiBA,CAC/BC,cAA2C,EAC3CN,KAAa,EACbC,SAAkB,EACG;EACrB,MAAME,KAAK,GAAGN,gBAAgB,CAACS,cAAc,EAAEN,KAAK,EAAEC,SAAS,CAAC;EAChE,MAAMM,WAAW,GAAGJ,KAAK,CAACK,SAAS,CAAEC,OAAO;EAC5C,IAAI,CAACF,WAAW,EAAE;IAChB,MAAM,IAAIL,KAAK,CACZ,6CAA4CF,KAAM,IACjDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDAAkD,CACpD;EACH;EACA,OAAOM,WAAW;AACpB;AAEO,SAASG,0BAA0BA,CACxCC,KAAa,EACbC,KAAc,EACE;EAChB;EACA,IAAI,CAACD,KAAK,CAACE,QAAQ,CAAC,GAAG,CAAC,IAAIF,KAAK,CAACG,UAAU,CAAC,MAAM,CAAC,IAAIF,KAAK,EAAE;IAC7D,MAAMG,OAAO,GAAI,GAAEH,KAAM,IAAGD,KAAM,EAAC;IACnC,IAAIK,gCAAe,CAACZ,GAAG,CAACW,OAAO,CAAC,EAAE;MAChC,OAAOA,OAAO;IAChB;EACF;EACA,IAAIC,gCAAe,CAACZ,GAAG,CAACO,KAAK,CAAC,EAAE;IAC9B,OAAOA,KAAK;EACd;EACA,OAAO,KAAK;AACd"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.symbolForFormStateStoreId = exports.FORM_RENDERER = void 0;
7
+ const FORM_RENDERER = "form-renderer.form-renderer";
8
+ exports.FORM_RENDERER = FORM_RENDERER;
9
+ const symbolForFormStateStoreId = Symbol.for("form.stateStoreId");
10
+ exports.symbolForFormStateStoreId = symbolForFormStateStoreId;
11
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","names":["FORM_RENDERER","exports","symbolForFormStateStoreId","Symbol","for"],"sources":["../../../../src/internal/FormRenderer/constants.ts"],"sourcesContent":["import type { BrickConf } from \"@next-core/types\";\n\nexport const FORM_RENDERER = \"form-renderer.form-renderer\";\nexport const symbolForFormStateStoreId = Symbol.for(\"form.stateStoreId\");\n\nexport type RuntimeBrickConfWithFormSymbols = BrickConf &\n RuntimeBrickConfOfFormSymbols;\n\nexport interface RuntimeBrickConfOfFormSymbols {\n [symbolForFormStateStoreId]?: string;\n}\n"],"mappings":";;;;;;AAEO,MAAMA,aAAa,GAAG,6BAA6B;AAACC,OAAA,CAAAD,aAAA,GAAAA,aAAA;AACpD,MAAME,yBAAyB,GAAGC,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC;AAACH,OAAA,CAAAC,yBAAA,GAAAA,yBAAA"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.expandFormRenderer = expandFormRenderer;
7
+ var _general = require("@next-core/utils/general");
8
+ var _lodash = require("lodash");
9
+ var _DataStore = require("../data/DataStore.js");
10
+ var _getDefaultProperties = require("./getDefaultProperties.js");
11
+ var _constants = require("./constants.js");
12
+ function expandFormRenderer(formData, hostBrickConf, hostBrick, asyncHostProperties) {
13
+ var _normalizedFormData$c, _hostBrickConf$proper;
14
+ const normalizedFormData = typeof formData === "string" ? JSON.parse(formData) : formData;
15
+ const formStateStoreId = (0, _lodash.uniqueId)("form-state-");
16
+ const runtimeContext = {
17
+ ...hostBrick.runtimeContext,
18
+ formStateStoreId
19
+ };
20
+
21
+ // There is a boundary for `forEachItem` and `STATE` between form internals and externals.
22
+ delete runtimeContext.forEachItem;
23
+ delete runtimeContext.tplStateStoreId;
24
+ const formStateStore = new _DataStore.DataStore("FORM_STATE");
25
+ runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);
26
+ if (runtimeContext.formStateStoreScope) {
27
+ runtimeContext.formStateStoreScope.push(formStateStore);
28
+ }
29
+
30
+ // Always add a state of `params`.
31
+ const context = (_normalizedFormData$c = normalizedFormData.context) !== null && _normalizedFormData$c !== void 0 ? _normalizedFormData$c : [];
32
+ if (!context.some(ctx => ctx.name === "params")) {
33
+ context.push({
34
+ name: "params"
35
+ });
36
+ }
37
+ formStateStore.define(context, runtimeContext, asyncHostProperties);
38
+ const formConf = formSchemaToBrick(normalizedFormData.formSchema, normalizedFormData.fields, formStateStoreId);
39
+ if (formConf.brick === "forms.general-form" && hostBrickConf.events) {
40
+ formConf.events = mergeEvents(formConf.events, hostBrickConf.events);
41
+ }
42
+ const renderRoot = typeof ((_hostBrickConf$proper = hostBrickConf.properties) === null || _hostBrickConf$proper === void 0 ? void 0 : _hostBrickConf$proper.renderRoot) !== "boolean" || hostBrickConf.properties.renderRoot;
43
+ if (renderRoot) {
44
+ return {
45
+ ...hostBrickConf,
46
+ slots: undefined,
47
+ children: [{
48
+ brick: "basic-bricks.micro-view",
49
+ properties: {
50
+ style: {
51
+ padding: "12px"
52
+ }
53
+ },
54
+ slots: {
55
+ content: {
56
+ bricks: [formConf],
57
+ type: "bricks"
58
+ }
59
+ }
60
+ }]
61
+ };
62
+ }
63
+ return {
64
+ ...hostBrickConf,
65
+ slots: undefined,
66
+ children: [formConf]
67
+ };
68
+ }
69
+ function formSchemaToBrick(schema, fields, formStateStoreId) {
70
+ const {
71
+ id,
72
+ bricks,
73
+ events,
74
+ context,
75
+ mountPoint,
76
+ instanceId: iid
77
+ } = schema;
78
+ let {
79
+ brick,
80
+ properties
81
+ } = schema;
82
+
83
+ // 根据字段类型获取默认配置
84
+ const field = fields.find(item => item.fieldId === id);
85
+ if (field) {
86
+ const defaults = (0, _getDefaultProperties.getDefaultProperties)(field);
87
+ if (!brick) {
88
+ brick = defaults.brick;
89
+ }
90
+ properties = {
91
+ ...defaults.properties,
92
+ ...properties
93
+ };
94
+ }
95
+ const brickConf = {
96
+ brick,
97
+ properties,
98
+ iid,
99
+ slot: mountPoint,
100
+ events,
101
+ context,
102
+ children: formSchemasToBricks(bricks, fields, formStateStoreId),
103
+ [_constants.symbolForFormStateStoreId]: formStateStoreId
104
+ };
105
+ if ((0, _general.hasOwnProperty)(schema, "if")) {
106
+ brickConf.if = schema.if;
107
+ }
108
+ return brickConf;
109
+ }
110
+ function formSchemasToBricks(schemas, fields, formStateStoreId) {
111
+ if (Array.isArray(schemas)) {
112
+ return schemas.map(schema => formSchemaToBrick(schema, fields, formStateStoreId));
113
+ }
114
+ }
115
+ function mergeEvents(targetEvents, sourceEvents) {
116
+ const events = targetEvents !== null && targetEvents !== void 0 ? targetEvents : {};
117
+ for (const [eventType, handlers] of Object.entries(sourceEvents)) {
118
+ events[eventType] = (0, _general.hasOwnProperty)(events, eventType) ? [events[eventType], handlers].flat() : handlers;
119
+ }
120
+ return events;
121
+ }
122
+ //# sourceMappingURL=expandFormRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expandFormRenderer.js","names":["_general","require","_lodash","_DataStore","_getDefaultProperties","_constants","expandFormRenderer","formData","hostBrickConf","hostBrick","asyncHostProperties","_normalizedFormData$c","_hostBrickConf$proper","normalizedFormData","JSON","parse","formStateStoreId","uniqueId","runtimeContext","forEachItem","tplStateStoreId","formStateStore","DataStore","formStateStoreMap","set","formStateStoreScope","push","context","some","ctx","name","define","formConf","formSchemaToBrick","formSchema","fields","brick","events","mergeEvents","renderRoot","properties","slots","undefined","children","style","padding","content","bricks","type","schema","id","mountPoint","instanceId","iid","field","find","item","fieldId","defaults","getDefaultProperties","brickConf","slot","formSchemasToBricks","symbolForFormStateStoreId","hasOwnProperty","if","schemas","Array","isArray","map","targetEvents","sourceEvents","eventType","handlers","Object","entries","flat"],"sources":["../../../../src/internal/FormRenderer/expandFormRenderer.ts"],"sourcesContent":["import type { BrickConf, BrickEventsMap } from \"@next-core/types\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport { uniqueId } from \"lodash\";\nimport { DataStore } from \"../data/DataStore.js\";\nimport type { AsyncProperties, RuntimeBrick } from \"../interfaces.js\";\nimport type {\n FieldProperties,\n FormDataProperties,\n FormSchemaProperties,\n} from \"./interfaces.js\";\nimport { getDefaultProperties } from \"./getDefaultProperties.js\";\nimport { symbolForFormStateStoreId } from \"./constants.js\";\n\nexport function expandFormRenderer(\n formData: unknown,\n hostBrickConf: BrickConf,\n hostBrick: RuntimeBrick,\n asyncHostProperties: AsyncProperties\n): BrickConf {\n const normalizedFormData = (\n typeof formData === \"string\" ? JSON.parse(formData) : formData\n ) as FormDataProperties;\n\n const formStateStoreId = uniqueId(\"form-state-\");\n const runtimeContext = {\n ...hostBrick.runtimeContext,\n formStateStoreId,\n };\n\n // There is a boundary for `forEachItem` and `STATE` between form internals and externals.\n delete runtimeContext.forEachItem;\n delete runtimeContext.tplStateStoreId;\n\n const formStateStore = new DataStore(\"FORM_STATE\");\n runtimeContext.formStateStoreMap.set(formStateStoreId, formStateStore);\n if (runtimeContext.formStateStoreScope) {\n runtimeContext.formStateStoreScope.push(formStateStore);\n }\n\n // Always add a state of `params`.\n const context = normalizedFormData.context ?? [];\n if (!context.some((ctx) => ctx.name === \"params\")) {\n context.push({ name: \"params\" });\n }\n\n formStateStore.define(context, runtimeContext, asyncHostProperties);\n\n const formConf = formSchemaToBrick(\n normalizedFormData.formSchema,\n normalizedFormData.fields,\n formStateStoreId\n );\n\n if (formConf.brick === \"forms.general-form\" && hostBrickConf.events) {\n formConf.events = mergeEvents(formConf.events, hostBrickConf.events);\n }\n\n const renderRoot =\n typeof hostBrickConf.properties?.renderRoot !== \"boolean\" ||\n hostBrickConf.properties.renderRoot;\n\n if (renderRoot) {\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [\n {\n brick: \"basic-bricks.micro-view\",\n properties: { style: { padding: \"12px\" } },\n slots: {\n content: { bricks: [formConf], type: \"bricks\" },\n },\n },\n ],\n };\n }\n\n return {\n ...hostBrickConf,\n slots: undefined,\n children: [formConf],\n };\n}\n\nfunction formSchemaToBrick(\n schema: FormSchemaProperties,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf {\n const { id, bricks, events, context, mountPoint, instanceId: iid } = schema;\n let { brick, properties } = schema;\n\n // 根据字段类型获取默认配置\n const field = fields.find((item: FieldProperties) => item.fieldId === id);\n if (field) {\n const defaults = getDefaultProperties(field);\n if (!brick) {\n brick = defaults.brick;\n }\n properties = {\n ...defaults.properties,\n ...properties,\n };\n }\n\n const brickConf = {\n brick,\n properties,\n iid,\n slot: mountPoint,\n events,\n context,\n children: formSchemasToBricks(bricks, fields, formStateStoreId),\n [symbolForFormStateStoreId]: formStateStoreId,\n } as BrickConf;\n\n if (hasOwnProperty(schema, \"if\")) {\n brickConf.if = schema.if;\n }\n\n return brickConf;\n}\n\nfunction formSchemasToBricks(\n schemas: FormSchemaProperties[] | undefined,\n fields: FieldProperties[],\n formStateStoreId: string\n): BrickConf[] | undefined {\n if (Array.isArray(schemas)) {\n return schemas.map((schema) =>\n formSchemaToBrick(schema, fields, formStateStoreId)\n );\n }\n}\n\nfunction mergeEvents(\n targetEvents: BrickEventsMap | undefined,\n sourceEvents: BrickEventsMap\n): BrickEventsMap {\n const events = targetEvents ?? {};\n\n for (const [eventType, handlers] of Object.entries(sourceEvents)) {\n events[eventType] = hasOwnProperty(events, eventType)\n ? [events[eventType], handlers].flat()\n : handlers;\n }\n\n return events;\n}\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAOA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAChCC,QAAiB,EACjBC,aAAwB,EACxBC,SAAuB,EACvBC,mBAAoC,EACzB;EAAA,IAAAC,qBAAA,EAAAC,qBAAA;EACX,MAAMC,kBAAkB,GACtB,OAAON,QAAQ,KAAK,QAAQ,GAAGO,IAAI,CAACC,KAAK,CAACR,QAAQ,CAAC,GAAGA,QACjC;EAEvB,MAAMS,gBAAgB,GAAG,IAAAC,gBAAQ,EAAC,aAAa,CAAC;EAChD,MAAMC,cAAc,GAAG;IACrB,GAAGT,SAAS,CAACS,cAAc;IAC3BF;EACF,CAAC;;EAED;EACA,OAAOE,cAA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f,MAAM,EAAE,IAAI,CAAC,EAAE;IAChCW,SAAS,CAACK,EAAE,GAAGhB,MAAM,CAACgB,EAAE;EAC1B;EAEA,OAAOL,SAAS;AAClB;AAEA,SAASE,mBAAmBA,CAC1BI,OAA2C,EAC3C/B,MAAyB,EACzBnB,gBAAwB,EACC;EACzB,IAAImD,KAAK,CAACC,OAAO,CAACF,OAAO,CAAC,EAAE;IAC1B,OAAOA,OAAO,CAACG,GAAG,CAAEpB,MAAM,IACxBhB,iBAAiB,CAACgB,MAAM,EAAEd,MAAM,EAAEnB,gBAAgB,CAAC,CACpD;EACH;AACF;AAEA,SAASsB,WAAWA,CAClBgC,YAAwC,EACxCC,YAA4B,EACZ;EAChB,MAAMlC,MAAM,GAAGiC,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,CAAC,CAAC;EAEjC,KAAK,MAAM,CAACE,SAAS,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,YAAY,CAAC,EAAE;IAChElC,MAAM,CAACmC,SAAS,CAAC,GAAG,IAAAR,uBAAc,EAAC3B,MAAM,EAAEmC,SAAS,CAAC,GACjD,CAACnC,MAAM,CAACmC,SAAS,CAAC,EAAEC,QAAQ,CAAC,CAACG,IAAI,EAAE,GACpCH,QAAQ;EACd;EAEA,OAAOpC,MAAM;AACf"}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDefaultProperties = getDefaultProperties;
7
+ function getDefaultProperties(field) {
8
+ let defaultValue;
9
+ const commonProps = {
10
+ id: field.fieldId,
11
+ name: field.fieldId,
12
+ label: field.name,
13
+ dataset: {
14
+ testid: field.fieldId
15
+ }
16
+ };
17
+ const getReadOnlyAndRequired = () => {
18
+ var _field$limit, _field$limit2;
19
+ return {
20
+ readOnly: (_field$limit = field.limit) === null || _field$limit === void 0 ? void 0 : _field$limit.includes("READONLY"),
21
+ required: (_field$limit2 = field.limit) === null || _field$limit2 === void 0 ? void 0 : _field$limit2.includes("REQUIRED")
22
+ };
23
+ };
24
+ switch (field.fieldType) {
25
+ case "INT":
26
+ defaultValue = {
27
+ brick: "forms.general-input-number",
28
+ properties: {
29
+ ...commonProps,
30
+ ...getReadOnlyAndRequired(),
31
+ placeholder: field.description,
32
+ precision: 0,
33
+ inputBoxStyle: {
34
+ width: "100%"
35
+ }
36
+ }
37
+ };
38
+ break;
39
+ case "BOOLEAN":
40
+ defaultValue = {
41
+ brick: "forms.general-switch",
42
+ properties: {
43
+ ...commonProps,
44
+ ...getReadOnlyAndRequired()
45
+ }
46
+ };
47
+ break;
48
+ case "FLOAT":
49
+ defaultValue = {
50
+ brick: "forms.general-input-number",
51
+ properties: {
52
+ ...commonProps,
53
+ ...getReadOnlyAndRequired(),
54
+ placeholder: field.description,
55
+ inputBoxStyle: {
56
+ width: "100%"
57
+ }
58
+ }
59
+ };
60
+ break;
61
+ case "ENUM":
62
+ defaultValue = {
63
+ brick: "forms.general-select",
64
+ properties: {
65
+ ...commonProps,
66
+ ...getReadOnlyAndRequired(),
67
+ options: [{
68
+ label: "选项一",
69
+ value: 1
70
+ }, {
71
+ label: "选项二",
72
+ value: 2
73
+ }],
74
+ placeholder: field.description,
75
+ inputBoxStyle: {
76
+ width: "100%"
77
+ }
78
+ }
79
+ };
80
+ break;
81
+ case "ENUMS":
82
+ defaultValue = {
83
+ brick: "forms.general-select",
84
+ properties: {
85
+ ...commonProps,
86
+ ...getReadOnlyAndRequired(),
87
+ mode: "multiple",
88
+ options: [{
89
+ label: "选项一",
90
+ value: 1
91
+ }, {
92
+ label: "选项二",
93
+ value: 2
94
+ }],
95
+ placeholder: field.description,
96
+ inputBoxStyle: {
97
+ width: "100%"
98
+ }
99
+ }
100
+ };
101
+ break;
102
+ case "DATE":
103
+ case "TIME":
104
+ defaultValue = {
105
+ brick: "forms.general-date-picker",
106
+ properties: {
107
+ ...commonProps,
108
+ ...getReadOnlyAndRequired(),
109
+ placeholder: field.description
110
+ }
111
+ };
112
+ break;
113
+ case "IP":
114
+ defaultValue = {
115
+ brick: "forms.general-input",
116
+ properties: {
117
+ ...commonProps,
118
+ ...getReadOnlyAndRequired(),
119
+ placeholder: field.description,
120
+ pattern: "((^s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))s*$)|(^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*$))",
121
+ message: {
122
+ pattern: "输入字符不匹配IP格式"
123
+ }
124
+ }
125
+ };
126
+ break;
127
+ case "JSON":
128
+ defaultValue = {
129
+ brick: "forms.general-textarea",
130
+ properties: {
131
+ ...commonProps
132
+ }
133
+ };
134
+ break;
135
+ case "ARRAY":
136
+ defaultValue = {
137
+ brick: "forms.general-select",
138
+ properties: {
139
+ ...commonProps
140
+ }
141
+ };
142
+ break;
143
+ case "STRUCTURE":
144
+ case "STRUCTURE_ARRAY":
145
+ defaultValue = {
146
+ brick: "forms.cmdb-instance-select-panel",
147
+ properties: {
148
+ ...commonProps,
149
+ ...getReadOnlyAndRequired()
150
+ }
151
+ };
152
+ break;
153
+ default:
154
+ defaultValue = {
155
+ brick: "forms.general-input",
156
+ properties: {
157
+ ...commonProps,
158
+ ...getReadOnlyAndRequired(),
159
+ placeholder: field.description
160
+ }
161
+ };
162
+ }
163
+ return defaultValue;
164
+ }
165
+ //# sourceMappingURL=getDefaultProperties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDefaultProperties.js","names":["getDefaultProperties","field","defaultValue","commonProps","id","fieldId","name","label","dataset","testid","getReadOnlyAndRequired","_field$limit","_field$limit2","readOnly","limit","includes","required","fieldType","brick","properties","placeholder","description","precision","inputBoxStyle","width","options","value","mode","pattern","message"],"sources":["../../../../src/internal/FormRenderer/getDefaultProperties.ts"],"sourcesContent":["import type { DefaultFieldProperties, FieldProperties } from \"./interfaces.js\";\n\nexport function getDefaultProperties(\n field: FieldProperties\n): DefaultFieldProperties {\n let defaultValue: DefaultFieldProperties;\n const commonProps = {\n id: field.fieldId,\n name: field.fieldId,\n label: field.name,\n dataset: {\n testid: field.fieldId,\n },\n };\n const getReadOnlyAndRequired = () => ({\n readOnly: field.limit?.includes(\"READONLY\"),\n required: field.limit?.includes(\"REQUIRED\"),\n });\n switch (field.fieldType) {\n case \"INT\":\n defaultValue = {\n brick: \"forms.general-input-number\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n precision: 0,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"BOOLEAN\":\n defaultValue = {\n brick: \"forms.general-switch\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n },\n };\n break;\n case \"FLOAT\":\n defaultValue = {\n brick: \"forms.general-input-number\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"ENUM\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n options: [\n { label: \"选项一\", value: 1 },\n { label: \"选项二\", value: 2 },\n ],\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"ENUMS\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n mode: \"multiple\",\n options: [\n { label: \"选项一\", value: 1 },\n { label: \"选项二\", value: 2 },\n ],\n placeholder: field.description,\n inputBoxStyle: { width: \"100%\" },\n },\n };\n break;\n case \"DATE\":\n case \"TIME\":\n defaultValue = {\n brick: \"forms.general-date-picker\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n },\n };\n break;\n case \"IP\":\n defaultValue = {\n brick: \"forms.general-input\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n pattern:\n \"((^s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))s*$)|(^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*$))\",\n message: {\n pattern: \"输入字符不匹配IP格式\",\n },\n },\n };\n break;\n case \"JSON\":\n defaultValue = {\n brick: \"forms.general-textarea\",\n properties: {\n ...commonProps,\n },\n };\n break;\n case \"ARRAY\":\n defaultValue = {\n brick: \"forms.general-select\",\n properties: {\n ...commonProps,\n },\n };\n break;\n case \"STRUCTURE\":\n case \"STRUCTURE_ARRAY\":\n defaultValue = {\n brick: \"forms.cmdb-instance-select-panel\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n },\n };\n break;\n default:\n defaultValue = {\n brick: \"forms.general-input\",\n properties: {\n ...commonProps,\n ...getReadOnlyAndRequired(),\n placeholder: field.description,\n },\n };\n }\n return defaultValue;\n}\n"],"mappings":";;;;;;AAEO,SAASA,oBAAoBA,CAClCC,KAAsB,EACE;EACxB,IAAIC,YAAoC;EACxC,MAAMC,WAAW,GAAG;IAClBC,EAAE,EAAEH,KAAK,CAACI,OAAO;IACjBC,IAAI,EAAEL,KAAK,CAACI,OAAO;IACnBE,KAAK,EAAEN,KAAK,CAACK,IAAI;IACjBE,OAAO,EAAE;MACPC,MAAM,EAAER,KAAK,CAACI;IAChB;EACF,CAAC;EACD,MAAMK,sBAAsB,GAAGA,CAAA;IAAA,IAAAC,YAAA,EAAAC,aAAA;IAAA,OAAO;MACpCC,QAAQ,GAAAF,YAAA,GAAEV,KAAK,CAACa,KAAK,cAAAH,YAAA,uBAAXA,YAAA,CAAaI,QAAQ,CAAC,UAAU,CAAC;MAC3CC,QAAQ,GAAAJ,aAAA,GAAEX,KAAK,CAACa,KAAK,cAAAF,aAAA,uBAAXA,aAAA,CAAaG,QAAQ,CAAC,UAAU;IAC5C,CAAC;EAAA,CAAC;EACF,QAAQd,KAAK,CAACgB,SAAS;IACrB,KAAK,KAAK;MACRf,YAAY,GAAG;QACbgB,KAAK,EAAE,4BAA4B;QACnCC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,EAAE;UAC3BU,WAAW,EAAEnB,KAAK,CAACoB,WAAW;UAC9BC,SAAS,EAAE,CAAC;UACZC,aAAa,EAAE;YAAEC,KAAK,EAAE;UAAO;QACjC;MACF,CA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,MAAM;MACTtB,YAAY,GAAG;QACbgB,KAAK,EAAE,2BAA2B;QAClCC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,EAAE;UAC3BU,WAAW,EAAEnB,KAAK,CAACoB;QACrB;MACF,CAAC;MACD;IACF,KAAK,IAAI;MACPnB,YAAY,GAAG;QACbgB,KAAK,EAAE,qBAAqB;QAC5BC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,EAAE;UAC3BU,WAAW,EAAEnB,KAAK,CAACoB,WAAW;UAC9BO,OAAO,EACL,6mCAA6mC;UAC/mCC,OAAO,EAAE;YACPD,OAAO,EAAE;UACX;QACF;MACF,CAAC;MACD;IACF,KAAK,MAAM;MACT1B,YAAY,GAAG;QACbgB,KAAK,EAAE,wBAAwB;QAC/BC,UAAU,EAAE;UACV,GAAGhB;QACL;MACF,CAAC;MACD;IACF,KAAK,OAAO;MACVD,YAAY,GAAG;QACbgB,KAAK,EAAE,sBAAsB;QAC7BC,UAAU,EAAE;UACV,GAAGhB;QACL;MACF,CAAC;MACD;IACF,KAAK,WAAW;IAChB,KAAK,iBAAiB;MACpBD,YAAY,GAAG;QACbgB,KAAK,EAAE,kCAAkC;QACzCC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB;QAC3B;MACF,CAAC;MACD;IACF;MACER,YAAY,GAAG;QACbgB,KAAK,EAAE,qBAAqB;QAC5BC,UAAU,EAAE;UACV,GAAGhB,WAAW;UACd,GAAGO,sBAAsB,EAAE;UAC3BU,WAAW,EAAEnB,KAAK,CAACoB;QACrB;MACF,CAAC;EAAC;EAEN,OAAOnB,YAAY;AACrB"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","names":[],"sources":["../../../../src/internal/FormRenderer/interfaces.ts"],"sourcesContent":["import type {\n BrickEventsMap,\n ContextConf,\n ResolveConf,\n} from \"@next-core/types\";\n\nexport interface FormDataProperties {\n formSchema: FormSchemaProperties;\n fields: FieldProperties[];\n context?: ContextConf[];\n // [key: string]: any;\n}\n\nexport interface FormSchemaProperties {\n id: string;\n brick?: string;\n sort?: number;\n mountPoint?: string;\n events?: BrickEventsMap;\n properties?: Record<string, unknown>;\n if?: string | boolean | ResolveConf;\n instanceId?: string;\n context?: ContextConf[];\n bricks?: FormSchemaProperties[];\n // [key: string]: any;\n}\n\nexport interface FieldProperties {\n defaultValue?: string;\n description?: string;\n fieldId: string;\n limit?: string[];\n name: string;\n fieldType: string;\n // [key: string]: any;\n}\n\nexport interface DefaultFieldProperties {\n brick: string;\n properties: Record<string, unknown>;\n}\n"],"mappings":""}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getFormStateStore = getFormStateStore;
7
+ function getFormStateStore({
8
+ formStateStoreId,
9
+ formStateStoreMap
10
+ }, using, extraInfo) {
11
+ if (!formStateStoreId) {
12
+ throw new Error(`Using "${using}" outside of form renderer${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}`);
13
+ }
14
+ const store = formStateStoreMap.get(formStateStoreId);
15
+ if (!store) {
16
+ throw new Error(`Form state store is not found when using "${using}"${extraInfo !== null && extraInfo !== void 0 ? extraInfo : ""}.\nThis is a bug of Brick Next, please report it.`);
17
+ }
18
+ return store;
19
+ }
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["getFormStateStore","formStateStoreId","formStateStoreMap","using","extraInfo","Error","store","get"],"sources":["../../../../src/internal/FormRenderer/utils.ts"],"sourcesContent":["import type { DataStore } from \"../data/DataStore.js\";\nimport type { RuntimeContext } from \"../interfaces.js\";\n\ntype MinimalTplStateStoreContext = Pick<\n RuntimeContext,\n \"formStateStoreId\" | \"formStateStoreMap\"\n>;\n\nexport function getFormStateStore(\n { formStateStoreId, formStateStoreMap }: MinimalTplStateStoreContext,\n using: string,\n extraInfo?: string\n): DataStore<\"FORM_STATE\"> {\n if (!formStateStoreId) {\n throw new Error(\n `Using \"${using}\" outside of form renderer${extraInfo ?? \"\"}`\n );\n }\n const store = formStateStoreMap.get(formStateStoreId);\n if (!store) {\n throw new Error(\n `Form state store is not found when using \"${using}\"${\n extraInfo ?? \"\"\n }.\\nThis is a bug of Brick Next, please report it.`\n );\n }\n return store;\n}\n"],"mappings":";;;;;;AAQO,SAASA,iBAAiBA,CAC/B;EAAEC,gBAAgB;EAAEC;AAA+C,CAAC,EACpEC,KAAa,EACbC,SAAkB,EACO;EACzB,IAAI,CAACH,gBAAgB,EAAE;IACrB,MAAM,IAAII,KAAK,CACZ,UAASF,KAAM,6BAA4BC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EAAG,EAAC,CAC9D;EACH;EACA,MAAME,KAAK,GAAGJ,iBAAiB,CAACK,GAAG,CAACN,gBAAgB,CAAC;EACrD,IAAI,CAACK,KAAK,EAAE;IACV,MAAM,IAAID,KAAK,CACZ,6CAA4CF,KAAM,IACjDC,SAAS,aAATA,SAAS,cAATA,SAAS,GAAI,EACd,mDAAkD,CACpD;EACH;EACA,OAAOE,KAAK;AACd"}