@nocobase/plugin-flow-engine 2.1.0-alpha.3 → 2.1.0-alpha.31

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 (264) hide show
  1. package/LICENSE +201 -661
  2. package/README.md +79 -9
  3. package/dist/ai/ai-employees/nathan/index.d.ts +10 -0
  4. package/dist/ai/ai-employees/nathan/index.js +42 -0
  5. package/dist/ai/ai-employees/nathan/prompt.md +168 -0
  6. package/dist/ai/ai-employees/nathan/skills/frontend-developer/SKILLS.md +86 -0
  7. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.js +2 -2
  8. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.js +2 -2
  9. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.js +2 -2
  10. package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.js +6 -4
  11. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/patchJSCode.d.ts +10 -0
  12. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/patchJSCode.js +65 -0
  13. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/readJSCode.d.ts +10 -0
  14. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/readJSCode.js +61 -0
  15. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/writeJSCode.d.ts +10 -0
  16. package/dist/ai/ai-employees/nathan/skills/frontend-developer/tools/writeJSCode.js +65 -0
  17. package/dist/ai/docs/runjs/context/block-model.md +35 -35
  18. package/dist/ai/docs/runjs/context/collection-field.md +53 -51
  19. package/dist/ai/docs/runjs/context/collection.md +39 -39
  20. package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
  21. package/dist/ai/docs/runjs/context/data-source.md +52 -44
  22. package/dist/ai/docs/runjs/context/element.md +44 -38
  23. package/dist/ai/docs/runjs/context/exit-all.md +37 -35
  24. package/dist/ai/docs/runjs/context/exit.md +38 -35
  25. package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
  26. package/dist/ai/docs/runjs/context/form.md +57 -57
  27. package/dist/ai/docs/runjs/context/get-model.md +22 -21
  28. package/dist/ai/docs/runjs/context/get-value.md +20 -19
  29. package/dist/ai/docs/runjs/context/get-var.md +61 -55
  30. package/dist/ai/docs/runjs/context/i18n.md +17 -14
  31. package/dist/ai/docs/runjs/context/import-async.md +333 -45
  32. package/dist/ai/docs/runjs/context/init-resource.md +20 -20
  33. package/dist/ai/docs/runjs/context/libs.md +31 -31
  34. package/dist/ai/docs/runjs/context/location.md +34 -31
  35. package/dist/ai/docs/runjs/context/logger.md +41 -40
  36. package/dist/ai/docs/runjs/context/make-resource.md +27 -26
  37. package/dist/ai/docs/runjs/context/message.md +42 -41
  38. package/dist/ai/docs/runjs/context/modal.md +44 -44
  39. package/dist/ai/docs/runjs/context/model.md +36 -33
  40. package/dist/ai/docs/runjs/context/notification.md +41 -40
  41. package/dist/ai/docs/runjs/context/off.md +14 -14
  42. package/dist/ai/docs/runjs/context/on.md +30 -29
  43. package/dist/ai/docs/runjs/context/open-view.md +40 -40
  44. package/dist/ai/docs/runjs/context/render.md +37 -32
  45. package/dist/ai/docs/runjs/context/request.md +46 -45
  46. package/dist/ai/docs/runjs/context/require-async.md +28 -25
  47. package/dist/ai/docs/runjs/context/resource.md +34 -34
  48. package/dist/ai/docs/runjs/context/route.md +36 -34
  49. package/dist/ai/docs/runjs/context/router.md +43 -31
  50. package/dist/ai/docs/runjs/context/set-value.md +18 -17
  51. package/dist/ai/docs/runjs/context/sql.md +7 -15
  52. package/dist/ai/docs/runjs/context/t.md +20 -17
  53. package/dist/ai/docs/runjs/context/view.md +49 -46
  54. package/dist/ai/docs/runjs/document.md +1 -0
  55. package/dist/ai/docs/runjs/import-modules.md +32 -32
  56. package/dist/ai/docs/runjs/index.md +13 -13
  57. package/dist/ai/docs/runjs/jsx.md +19 -19
  58. package/dist/ai/docs/runjs/model/form-block-model.md +1 -3
  59. package/dist/ai/docs/runjs/render.md +15 -15
  60. package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
  61. package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
  62. package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
  63. package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
  64. package/dist/ai/docs/runjs/window.md +5 -5
  65. package/dist/client/index.js +1 -1
  66. package/dist/externalVersion.js +12 -11
  67. package/dist/locale/en-US.json +1 -0
  68. package/dist/locale/index.d.ts +2 -0
  69. package/dist/locale/zh-CN.json +1 -0
  70. package/dist/node_modules/ses/dist/ses.cjs +1 -1
  71. package/dist/node_modules/ses/package.json +1 -1
  72. package/dist/node_modules/zod/index.cjs +1 -1
  73. package/dist/node_modules/zod/package.json +1 -1
  74. package/dist/server/collections/flowsql.js +1 -0
  75. package/dist/server/flow-surfaces/action-scope.d.ts +39 -0
  76. package/dist/server/flow-surfaces/action-scope.js +156 -0
  77. package/dist/server/flow-surfaces/apply/compiler.d.ts +13 -0
  78. package/dist/server/flow-surfaces/apply/compiler.js +971 -0
  79. package/dist/server/flow-surfaces/apply/layout.d.ts +34 -0
  80. package/dist/server/flow-surfaces/apply/layout.js +175 -0
  81. package/dist/server/flow-surfaces/apply/matching.d.ts +16 -0
  82. package/dist/server/flow-surfaces/apply/matching.js +181 -0
  83. package/dist/server/flow-surfaces/approval/blueprint-service.d.ts +84 -0
  84. package/dist/server/flow-surfaces/approval/blueprint-service.js +589 -0
  85. package/dist/server/flow-surfaces/approval/blueprint.d.ts +21 -0
  86. package/dist/server/flow-surfaces/approval/blueprint.js +187 -0
  87. package/dist/server/flow-surfaces/approval/builder.d.ts +225 -0
  88. package/dist/server/flow-surfaces/approval/builder.js +384 -0
  89. package/dist/server/flow-surfaces/approval/catalog-specs.d.ts +33 -0
  90. package/dist/server/flow-surfaces/approval/catalog-specs.js +156 -0
  91. package/dist/server/flow-surfaces/approval/index.d.ts +14 -0
  92. package/dist/server/flow-surfaces/approval/index.js +40 -0
  93. package/dist/server/flow-surfaces/approval/runtime-config.d.ts +44 -0
  94. package/dist/server/flow-surfaces/approval/runtime-config.js +299 -0
  95. package/dist/server/flow-surfaces/approval/semantic-use.d.ts +23 -0
  96. package/dist/server/flow-surfaces/approval/semantic-use.js +155 -0
  97. package/dist/server/flow-surfaces/association-interfaces.d.ts +10 -0
  98. package/dist/server/flow-surfaces/association-interfaces.js +39 -0
  99. package/dist/server/flow-surfaces/association-title-field.d.ts +20 -0
  100. package/dist/server/flow-surfaces/association-title-field.js +192 -0
  101. package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +15 -0
  102. package/dist/server/flow-surfaces/blueprint/compile-blocks.js +1251 -0
  103. package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +14 -0
  104. package/dist/server/flow-surfaces/blueprint/compile-plan.js +308 -0
  105. package/dist/server/flow-surfaces/blueprint/compile-reaction.d.ts +11 -0
  106. package/dist/server/flow-surfaces/blueprint/compile-reaction.js +72 -0
  107. package/dist/server/flow-surfaces/blueprint/defaults.d.ts +26 -0
  108. package/dist/server/flow-surfaces/blueprint/defaults.js +133 -0
  109. package/dist/server/flow-surfaces/blueprint/index.d.ts +12 -0
  110. package/dist/server/flow-surfaces/blueprint/index.js +44 -0
  111. package/dist/server/flow-surfaces/blueprint/normalize-document.d.ts +10 -0
  112. package/dist/server/flow-surfaces/blueprint/normalize-document.js +407 -0
  113. package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +25 -0
  114. package/dist/server/flow-surfaces/blueprint/private-utils.js +179 -0
  115. package/dist/server/flow-surfaces/blueprint/public-types.d.ts +201 -0
  116. package/dist/server/flow-surfaces/blueprint/public-types.js +24 -0
  117. package/dist/server/flow-surfaces/builder.d.ts +238 -0
  118. package/dist/server/flow-surfaces/builder.js +1261 -0
  119. package/dist/server/flow-surfaces/catalog-smart.d.ts +18 -0
  120. package/dist/server/flow-surfaces/catalog-smart.js +239 -0
  121. package/dist/server/flow-surfaces/catalog-smart.projector.d.ts +15 -0
  122. package/dist/server/flow-surfaces/catalog-smart.projector.js +157 -0
  123. package/dist/server/flow-surfaces/catalog-smart.types.d.ts +99 -0
  124. package/dist/server/flow-surfaces/catalog-smart.types.js +24 -0
  125. package/dist/server/flow-surfaces/catalog.d.ts +79 -0
  126. package/dist/server/flow-surfaces/catalog.js +3743 -0
  127. package/dist/server/flow-surfaces/chart-config.d.ts +121 -0
  128. package/dist/server/flow-surfaces/chart-config.js +1394 -0
  129. package/dist/server/flow-surfaces/compose-compiler.d.ts +115 -0
  130. package/dist/server/flow-surfaces/compose-compiler.js +174 -0
  131. package/dist/server/flow-surfaces/compose-runtime.d.ts +94 -0
  132. package/dist/server/flow-surfaces/compose-runtime.js +376 -0
  133. package/dist/server/flow-surfaces/configure-options.d.ts +23 -0
  134. package/dist/server/flow-surfaces/configure-options.js +904 -0
  135. package/dist/server/flow-surfaces/constants.d.ts +351 -0
  136. package/dist/server/flow-surfaces/constants.js +104 -0
  137. package/dist/server/flow-surfaces/context.d.ts +72 -0
  138. package/dist/server/flow-surfaces/context.js +556 -0
  139. package/dist/server/flow-surfaces/contract-guard.d.ts +19 -0
  140. package/dist/server/flow-surfaces/contract-guard.js +410 -0
  141. package/dist/server/flow-surfaces/core-field-default-bindings.d.ts +12 -0
  142. package/dist/server/flow-surfaces/core-field-default-bindings.js +157 -0
  143. package/dist/server/flow-surfaces/default-action-popup.d.ts +63 -0
  144. package/dist/server/flow-surfaces/default-action-popup.js +322 -0
  145. package/dist/server/flow-surfaces/default-block-actions.d.ts +32 -0
  146. package/dist/server/flow-surfaces/default-block-actions.js +210 -0
  147. package/dist/server/flow-surfaces/errors.d.ts +47 -0
  148. package/dist/server/flow-surfaces/errors.js +145 -0
  149. package/dist/server/flow-surfaces/executor.d.ts +23 -0
  150. package/dist/server/flow-surfaces/executor.js +132 -0
  151. package/dist/server/flow-surfaces/field-binding-registry.d.ts +24 -0
  152. package/dist/server/flow-surfaces/field-binding-registry.js +396 -0
  153. package/dist/server/flow-surfaces/field-semantics.d.ts +15 -0
  154. package/dist/server/flow-surfaces/field-semantics.js +84 -0
  155. package/dist/server/flow-surfaces/field-type-resolver.d.ts +45 -0
  156. package/dist/server/flow-surfaces/field-type-resolver.js +312 -0
  157. package/dist/server/flow-surfaces/filter-group.d.ts +15 -0
  158. package/dist/server/flow-surfaces/filter-group.js +94 -0
  159. package/dist/server/flow-surfaces/hidden-popup-calendar.d.ts +86 -0
  160. package/dist/server/flow-surfaces/hidden-popup-calendar.js +554 -0
  161. package/dist/server/flow-surfaces/hidden-popup-contract.d.ts +116 -0
  162. package/dist/server/flow-surfaces/hidden-popup-contract.js +611 -0
  163. package/dist/server/flow-surfaces/hidden-popup-kanban.d.ts +62 -0
  164. package/dist/server/flow-surfaces/hidden-popup-kanban.js +651 -0
  165. package/dist/server/flow-surfaces/index.d.ts +11 -0
  166. package/dist/server/flow-surfaces/index.js +302 -0
  167. package/dist/server/flow-surfaces/locator.d.ts +28 -0
  168. package/dist/server/flow-surfaces/locator.js +240 -0
  169. package/dist/server/flow-surfaces/node-use-sets.d.ts +15 -0
  170. package/dist/server/flow-surfaces/node-use-sets.js +135 -0
  171. package/dist/server/flow-surfaces/payload-shape.d.ts +9 -0
  172. package/dist/server/flow-surfaces/payload-shape.js +61 -0
  173. package/dist/server/flow-surfaces/placement.d.ts +33 -0
  174. package/dist/server/flow-surfaces/placement.js +199 -0
  175. package/dist/server/flow-surfaces/planning/action-specs.d.ts +179 -0
  176. package/dist/server/flow-surfaces/planning/action-specs.js +190 -0
  177. package/dist/server/flow-surfaces/planning/compiler.d.ts +37 -0
  178. package/dist/server/flow-surfaces/planning/compiler.js +376 -0
  179. package/dist/server/flow-surfaces/planning/context.d.ts +30 -0
  180. package/dist/server/flow-surfaces/planning/context.js +139 -0
  181. package/dist/server/flow-surfaces/planning/created-keys.d.ts +34 -0
  182. package/dist/server/flow-surfaces/planning/created-keys.js +375 -0
  183. package/dist/server/flow-surfaces/planning/key-kind.d.ts +11 -0
  184. package/dist/server/flow-surfaces/planning/key-kind.js +88 -0
  185. package/dist/server/flow-surfaces/planning/key-persistence.d.ts +34 -0
  186. package/dist/server/flow-surfaces/planning/key-persistence.js +148 -0
  187. package/dist/server/flow-surfaces/planning/key-registry.d.ts +40 -0
  188. package/dist/server/flow-surfaces/planning/key-registry.js +206 -0
  189. package/dist/server/flow-surfaces/planning/runtime.d.ts +37 -0
  190. package/dist/server/flow-surfaces/planning/runtime.js +259 -0
  191. package/dist/server/flow-surfaces/planning/step-link.d.ts +14 -0
  192. package/dist/server/flow-surfaces/planning/step-link.js +104 -0
  193. package/dist/server/flow-surfaces/planning/types.d.ts +55 -0
  194. package/dist/server/flow-surfaces/planning/types.js +24 -0
  195. package/dist/server/flow-surfaces/public-compatibility.d.ts +28 -0
  196. package/dist/server/flow-surfaces/public-compatibility.js +161 -0
  197. package/dist/server/flow-surfaces/public-data-surface-default-filter.d.ts +24 -0
  198. package/dist/server/flow-surfaces/public-data-surface-default-filter.js +152 -0
  199. package/dist/server/flow-surfaces/reaction/errors.d.ts +20 -0
  200. package/dist/server/flow-surfaces/reaction/errors.js +69 -0
  201. package/dist/server/flow-surfaces/reaction/field-value.d.ts +34 -0
  202. package/dist/server/flow-surfaces/reaction/field-value.js +181 -0
  203. package/dist/server/flow-surfaces/reaction/fingerprint.d.ts +16 -0
  204. package/dist/server/flow-surfaces/reaction/fingerprint.js +71 -0
  205. package/dist/server/flow-surfaces/reaction/linkage.d.ts +136 -0
  206. package/dist/server/flow-surfaces/reaction/linkage.js +882 -0
  207. package/dist/server/flow-surfaces/reaction/meta.d.ts +11 -0
  208. package/dist/server/flow-surfaces/reaction/meta.js +451 -0
  209. package/dist/server/flow-surfaces/reaction/registry.d.ts +156 -0
  210. package/dist/server/flow-surfaces/reaction/registry.js +206 -0
  211. package/dist/server/flow-surfaces/reaction/resolver.d.ts +22 -0
  212. package/dist/server/flow-surfaces/reaction/resolver.js +202 -0
  213. package/dist/server/flow-surfaces/reaction/types.d.ts +241 -0
  214. package/dist/server/flow-surfaces/reaction/types.js +24 -0
  215. package/dist/server/flow-surfaces/reaction/utils.d.ts +17 -0
  216. package/dist/server/flow-surfaces/reaction/utils.js +67 -0
  217. package/dist/server/flow-surfaces/reaction/value-expr.d.ts +15 -0
  218. package/dist/server/flow-surfaces/reaction/value-expr.js +209 -0
  219. package/dist/server/flow-surfaces/reference-guards.d.ts +19 -0
  220. package/dist/server/flow-surfaces/reference-guards.js +103 -0
  221. package/dist/server/flow-surfaces/route-sync.d.ts +50 -0
  222. package/dist/server/flow-surfaces/route-sync.js +393 -0
  223. package/dist/server/flow-surfaces/service-helpers.d.ts +42 -0
  224. package/dist/server/flow-surfaces/service-helpers.js +310 -0
  225. package/dist/server/flow-surfaces/service-utils.d.ts +120 -0
  226. package/dist/server/flow-surfaces/service-utils.js +878 -0
  227. package/dist/server/flow-surfaces/service.d.ts +896 -0
  228. package/dist/server/flow-surfaces/service.js +16248 -0
  229. package/dist/server/flow-surfaces/support-matrix.d.ts +31 -0
  230. package/dist/server/flow-surfaces/support-matrix.js +282 -0
  231. package/dist/server/flow-surfaces/surface-context.d.ts +52 -0
  232. package/dist/server/flow-surfaces/surface-context.js +440 -0
  233. package/dist/server/flow-surfaces/template-compatibility.d.ts +42 -0
  234. package/dist/server/flow-surfaces/template-compatibility.js +189 -0
  235. package/dist/server/flow-surfaces/template-display.d.ts +20 -0
  236. package/dist/server/flow-surfaces/template-display.js +289 -0
  237. package/dist/server/flow-surfaces/template-service-utils.d.ts +62 -0
  238. package/dist/server/flow-surfaces/template-service-utils.js +281 -0
  239. package/dist/server/flow-surfaces/types.d.ts +288 -0
  240. package/dist/server/flow-surfaces/types.js +24 -0
  241. package/dist/server/index.d.ts +1 -0
  242. package/dist/server/index.js +7 -2
  243. package/dist/server/migrations/20260508000000-remove-flow-model-options-runtime-uid.d.ts +13 -0
  244. package/dist/server/migrations/20260508000000-remove-flow-model-options-runtime-uid.js +67 -0
  245. package/dist/server/plugin.d.ts +0 -1
  246. package/dist/server/plugin.js +9 -34
  247. package/dist/server/repository.js +0 -5
  248. package/dist/server/variables/resolve.d.ts +21 -0
  249. package/dist/server/variables/resolve.js +79 -0
  250. package/dist/swagger/flow-surfaces.d.ts +6106 -0
  251. package/dist/swagger/flow-surfaces.examples.d.ts +1577 -0
  252. package/dist/swagger/flow-surfaces.examples.js +1816 -0
  253. package/dist/swagger/flow-surfaces.js +5375 -0
  254. package/dist/swagger/flow-surfaces.template-action-docs.d.ts +62 -0
  255. package/dist/swagger/flow-surfaces.template-action-docs.js +121 -0
  256. package/dist/swagger/flow-surfaces.template-schemas.d.ts +239 -0
  257. package/dist/swagger/flow-surfaces.template-schemas.js +255 -0
  258. package/dist/swagger/index.d.ts +6111 -0
  259. package/dist/swagger/index.js +50 -0
  260. package/package.json +3 -3
  261. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextApis.d.ts +0 -0
  262. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextEnvs.d.ts +0 -0
  263. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/getContextVars.d.ts +0 -0
  264. /package/dist/ai/{tools → ai-employees/nathan/skills/frontend-developer/tools}/lintAndTestJS.d.ts +0 -0
@@ -0,0 +1,1251 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var compile_blocks_exports = {};
38
+ __export(compile_blocks_exports, {
39
+ collectReferencedBlockKeys: () => collectReferencedBlockKeys,
40
+ compileTabComposeValues: () => compileTabComposeValues
41
+ });
42
+ module.exports = __toCommonJS(compile_blocks_exports);
43
+ var import_lodash = __toESM(require("lodash"));
44
+ var import_errors = require("../errors");
45
+ var import_service_utils = require("../service-utils");
46
+ var import_default_block_actions = require("../default-block-actions");
47
+ var import_public_data_surface_default_filter = require("../public-data-surface-default-filter");
48
+ var import_public_compatibility = require("../public-compatibility");
49
+ var import_defaults = require("./defaults");
50
+ var import_hidden_popup_contract = require("../hidden-popup-contract");
51
+ var import_service_helpers = require("../service-helpers");
52
+ var import_private_utils = require("./private-utils");
53
+ var import_field_type_resolver = require("../field-type-resolver");
54
+ const APPLY_BLUEPRINT_BLOCK_TYPE_ENUM = [
55
+ "table",
56
+ "calendar",
57
+ "kanban",
58
+ "createForm",
59
+ "editForm",
60
+ "details",
61
+ "filterForm",
62
+ "list",
63
+ "gridCard",
64
+ "markdown",
65
+ "iframe",
66
+ "chart",
67
+ "actionPanel",
68
+ "jsBlock",
69
+ "tree"
70
+ ];
71
+ const APPLY_BLUEPRINT_BLOCK_ALLOWED_KEYS = [
72
+ "key",
73
+ "type",
74
+ "title",
75
+ "collection",
76
+ "dataSourceKey",
77
+ "associationPathName",
78
+ "binding",
79
+ "associationField",
80
+ "resource",
81
+ "template",
82
+ "settings",
83
+ "fields",
84
+ "fieldGroups",
85
+ "fieldsLayout",
86
+ "defaultFilter",
87
+ "actions",
88
+ "recordActions",
89
+ "script",
90
+ "chart"
91
+ ];
92
+ const APPLY_BLUEPRINT_FIELD_ALLOWED_KEYS = [
93
+ "key",
94
+ "field",
95
+ "associationPathName",
96
+ "renderer",
97
+ "type",
98
+ "fieldType",
99
+ "fields",
100
+ "titleField",
101
+ "openMode",
102
+ "popupSize",
103
+ "pageSize",
104
+ "showIndex",
105
+ "label",
106
+ "target",
107
+ "settings",
108
+ "popup",
109
+ "script",
110
+ "chart"
111
+ ];
112
+ const APPLY_BLUEPRINT_FIELD_GROUP_ALLOWED_KEYS = ["key", "title", "fields"];
113
+ const APPLY_BLUEPRINT_ACTION_ALLOWED_KEYS = ["key", "type", "title", "settings", "popup", "script", "chart"];
114
+ const APPLY_BLUEPRINT_POPUP_ALLOWED_KEYS = [
115
+ "title",
116
+ "mode",
117
+ "template",
118
+ "tryTemplate",
119
+ "defaultType",
120
+ "saveAsTemplate",
121
+ "blocks",
122
+ "layout"
123
+ ];
124
+ const APPLY_BLUEPRINT_POPUP_SAVE_AS_TEMPLATE_ALLOWED_KEYS = ["name", "description", "local"];
125
+ const APPLY_BLUEPRINT_LAYOUT_ALLOWED_KEYS = ["rows"];
126
+ const APPLY_BLUEPRINT_LAYOUT_CELL_ALLOWED_KEYS = ["key", "span"];
127
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_ALLOWED_KEYS = [
128
+ "binding",
129
+ "dataSourceKey",
130
+ "collectionName",
131
+ "associationField",
132
+ "associationName",
133
+ "associationPathName",
134
+ "sourceId",
135
+ "filterByTk"
136
+ ];
137
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_RAW_ONLY_KEYS = [
138
+ "associationName",
139
+ "associationPathName",
140
+ "sourceId",
141
+ "filterByTk"
142
+ ];
143
+ const APPLY_BLUEPRINT_BLOCK_RESOURCE_SHORTHAND_KEYS = [
144
+ "collection",
145
+ "dataSourceKey",
146
+ "associationPathName",
147
+ "binding",
148
+ "associationField"
149
+ ];
150
+ const APPLY_BLUEPRINT_RECORD_CAPABLE_BLOCK_TYPES = /* @__PURE__ */ new Set(["table", "details", "list", "gridCard"]);
151
+ const APPLY_BLUEPRINT_FIELD_GRID_BLOCK_TYPES = /* @__PURE__ */ new Set(["createForm", "editForm", "details", "filterForm"]);
152
+ const APPLY_BLUEPRINT_FIELD_GROUP_BLOCK_TYPES = /* @__PURE__ */ new Set(["createForm", "editForm", "details"]);
153
+ const APPLY_BLUEPRINT_AUTO_PROMOTED_RECORD_ACTION_TYPES = /* @__PURE__ */ new Set([
154
+ "view",
155
+ "edit",
156
+ "delete",
157
+ "updateRecord",
158
+ "duplicate"
159
+ ]);
160
+ const APPLY_BLUEPRINT_DEFAULT_POPUP_ACTION_TYPES = /* @__PURE__ */ new Set(["addNew", "addChild", "view", "edit"]);
161
+ const APPLY_BLUEPRINT_BLOCK_TYPES = new Set(APPLY_BLUEPRINT_BLOCK_TYPE_ENUM);
162
+ const APPLY_BLUEPRINT_ADD_CHILD_RECORD_ACTION_ERROR = "type 'addChild' must be authored under recordActions and is only valid when the live target catalog.recordActions exposes it for a tree collection table with treeTable enabled";
163
+ function assertNoBlockLevelLayout(input, context) {
164
+ if (Object.prototype.hasOwnProperty.call(input, "layout")) {
165
+ (0, import_errors.throwBadRequest)(`${context}.layout is not supported; layout is only allowed on tabs[] and popup`);
166
+ }
167
+ }
168
+ function normalizeApplyBlueprintCalendarPopupSettings(settings, blockContext, defaultsMetadata) {
169
+ return (0, import_hidden_popup_contract.normalizeBlockHiddenPopupSettings)(
170
+ settings,
171
+ blockContext,
172
+ ["quickCreatePopup", "eventPopup"],
173
+ defaultsMetadata,
174
+ import_errors.throwBadRequest
175
+ );
176
+ }
177
+ function normalizeApplyBlueprintKanbanPopupSettings(settings, blockContext, defaultsMetadata) {
178
+ return (0, import_hidden_popup_contract.normalizeBlockHiddenPopupSettings)(
179
+ settings,
180
+ blockContext,
181
+ ["quickCreatePopup", "cardPopup"],
182
+ defaultsMetadata,
183
+ import_errors.throwBadRequest
184
+ );
185
+ }
186
+ function assertApplyBlueprintFieldsLayoutHost(block, context) {
187
+ if (!Object.prototype.hasOwnProperty.call(block, "fieldsLayout")) {
188
+ return;
189
+ }
190
+ if ((0, import_private_utils.readOptionalString)(block.type) === "kanban") {
191
+ (0, import_errors.throwBadRequest)(`${context}.fieldsLayout is not supported on kanban main blocks; use fields[] only`);
192
+ }
193
+ if (APPLY_BLUEPRINT_FIELD_GRID_BLOCK_TYPES.has((0, import_private_utils.readOptionalString)(block.type) || "")) {
194
+ return;
195
+ }
196
+ (0, import_errors.throwBadRequest)(`${context}.fieldsLayout is only supported on createForm, editForm, details or filterForm`);
197
+ }
198
+ function assertApplyBlueprintCalendarMainContent(block, context) {
199
+ if ((0, import_private_utils.readOptionalString)(block.type) !== "calendar") {
200
+ return;
201
+ }
202
+ if (Object.prototype.hasOwnProperty.call(block, "fields")) {
203
+ (0, import_errors.throwBadRequest)(
204
+ `${context}.fields is not supported on calendar main blocks; add event fields under the quick-create or event-view popup host instead`
205
+ );
206
+ }
207
+ if (Object.prototype.hasOwnProperty.call(block, "fieldGroups")) {
208
+ (0, import_errors.throwBadRequest)(
209
+ `${context}.fieldGroups is not supported on calendar main blocks; add grouped fields under the quick-create or event-view popup host instead`
210
+ );
211
+ }
212
+ if (Object.prototype.hasOwnProperty.call(block, "recordActions")) {
213
+ (0, import_errors.throwBadRequest)(
214
+ `${context}.recordActions is not supported on calendar main blocks; configure event actions inside the event-view popup host instead`
215
+ );
216
+ }
217
+ }
218
+ function assertApplyBlueprintKanbanMainContent(block, context) {
219
+ if ((0, import_private_utils.readOptionalString)(block.type) !== "kanban") {
220
+ return;
221
+ }
222
+ if (Object.prototype.hasOwnProperty.call(block, "fieldGroups")) {
223
+ (0, import_errors.throwBadRequest)(`${context}.fieldGroups is not supported on kanban main blocks; use fields instead`);
224
+ }
225
+ if (Object.prototype.hasOwnProperty.call(block, "recordActions")) {
226
+ (0, import_errors.throwBadRequest)(`${context}.recordActions is not supported on kanban main blocks in v1`);
227
+ }
228
+ }
229
+ function assertApplyBlueprintTreeMainContent(block, context) {
230
+ if ((0, import_private_utils.readOptionalString)(block.type) !== "tree") {
231
+ return;
232
+ }
233
+ if (Object.prototype.hasOwnProperty.call(block, "fields")) {
234
+ (0, import_errors.throwBadRequest)(`${context}.fields is not supported on tree blocks`);
235
+ }
236
+ if (Object.prototype.hasOwnProperty.call(block, "fieldGroups")) {
237
+ (0, import_errors.throwBadRequest)(`${context}.fieldGroups is not supported on tree blocks`);
238
+ }
239
+ if (Object.prototype.hasOwnProperty.call(block, "actions")) {
240
+ (0, import_errors.throwBadRequest)(`${context}.actions is not supported on tree blocks`);
241
+ }
242
+ if (Object.prototype.hasOwnProperty.call(block, "recordActions")) {
243
+ (0, import_errors.throwBadRequest)(`${context}.recordActions is not supported on tree blocks`);
244
+ }
245
+ }
246
+ function assertApplyBlueprintBlockType(type, context) {
247
+ if (!type) {
248
+ return;
249
+ }
250
+ if (type === "form") {
251
+ (0, import_errors.throwBadRequest)(`${context}.type 'form' is unsupported in applyBlueprint; use 'editForm' or 'createForm'`);
252
+ }
253
+ if (!APPLY_BLUEPRINT_BLOCK_TYPES.has(type)) {
254
+ (0, import_errors.throwBadRequest)(
255
+ `${context}.type '${type}' is unsupported in applyBlueprint; supported types: ${APPLY_BLUEPRINT_BLOCK_TYPE_ENUM.join(
256
+ ", "
257
+ )}`
258
+ );
259
+ }
260
+ }
261
+ function normalizeEditPopupBlocks(input, context) {
262
+ input.forEach((block, index) => {
263
+ const blockType = (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type);
264
+ if (blockType === "form") {
265
+ (0, import_errors.throwBadRequest)(`${context}.blocks[${index}].type 'form' is unsupported in applyBlueprint; use 'editForm'`);
266
+ }
267
+ });
268
+ const editFormBlocks = input.filter((block) => (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type) === "editForm");
269
+ if (!editFormBlocks.length) {
270
+ (0, import_errors.throwBadRequest)(`${context} custom edit popup must contain exactly one editForm block`);
271
+ }
272
+ if (editFormBlocks.length > 1) {
273
+ (0, import_errors.throwBadRequest)(`${context} custom edit popup must contain exactly one editForm block`);
274
+ }
275
+ return input.map((block, index) => {
276
+ const blockType = (0, import_private_utils.readOptionalString)(block == null ? void 0 : block.type);
277
+ if (blockType !== "editForm") {
278
+ return block;
279
+ }
280
+ if (!import_lodash.default.isPlainObject(block)) {
281
+ return block;
282
+ }
283
+ if (!import_lodash.default.isUndefined(block.resource)) {
284
+ if (import_lodash.default.isPlainObject(block.resource)) {
285
+ const binding = "binding" in block.resource ? (0, import_private_utils.readOptionalString)(block.resource.binding) : void 0;
286
+ if (!binding) {
287
+ (0, import_errors.throwBadRequest)(
288
+ `${context}.blocks[${index}].resource must use binding='currentRecord' or be omitted in a custom edit popup`
289
+ );
290
+ }
291
+ if (binding !== "currentRecord") {
292
+ (0, import_errors.throwBadRequest)(
293
+ `${context}.blocks[${index}].resource.binding must be 'currentRecord' in a custom edit popup`
294
+ );
295
+ }
296
+ }
297
+ return block;
298
+ }
299
+ const shorthandBinding = (0, import_private_utils.readOptionalString)(block.binding);
300
+ if (!import_lodash.default.isUndefined(shorthandBinding)) {
301
+ if (shorthandBinding !== "currentRecord") {
302
+ (0, import_errors.throwBadRequest)(`${context}.blocks[${index}].binding must be 'currentRecord' in a custom edit popup`);
303
+ }
304
+ return block;
305
+ }
306
+ const hasRawShorthandResource = !import_lodash.default.isUndefined(block.collection) || !import_lodash.default.isUndefined(block.dataSourceKey) || !import_lodash.default.isUndefined(block.associationPathName) || !import_lodash.default.isUndefined(block.associationField);
307
+ if (hasRawShorthandResource) {
308
+ (0, import_errors.throwBadRequest)(
309
+ `${context}.blocks[${index}] must use binding='currentRecord' or omit resource entirely in a custom edit popup`
310
+ );
311
+ }
312
+ return {
313
+ ...block,
314
+ resource: {
315
+ binding: "currentRecord"
316
+ }
317
+ };
318
+ });
319
+ }
320
+ function readAssociationFieldFromSingleSegmentPath(value, context) {
321
+ const associationPathName = (0, import_private_utils.readOptionalString)(value);
322
+ if (!associationPathName) {
323
+ return void 0;
324
+ }
325
+ const segments = associationPathName.split(".").map((segment) => segment.trim()).filter(Boolean);
326
+ if (!segments.length) {
327
+ (0, import_errors.throwBadRequest)(`${context}.associationPathName must be a non-empty association field path`);
328
+ }
329
+ if (segments.length > 1) {
330
+ (0, import_errors.throwBadRequest)(
331
+ `${context}.associationPathName '${associationPathName}' must be a single association field name when used with ${context}.binding; prefer ${context}.associationField for popup relation tables`
332
+ );
333
+ }
334
+ return segments[0];
335
+ }
336
+ function normalizeAssociatedRecordsBindingFromAssociationPath(input, context) {
337
+ const binding = (0, import_private_utils.readOptionalString)(input.binding);
338
+ const associationLeaf = readAssociationFieldFromSingleSegmentPath(input.associationPathName, context);
339
+ if (!binding || !associationLeaf) {
340
+ return null;
341
+ }
342
+ if (binding !== "currentRecord" && binding !== "associatedRecords") {
343
+ (0, import_errors.throwBadRequest)(
344
+ `${context} cannot mix ${context}.binding='${binding}' with ${context}.associationPathName; use associatedRecords + associationField on popup collection blocks`
345
+ );
346
+ }
347
+ const associationField = (0, import_private_utils.readOptionalString)(input.associationField);
348
+ if (associationField && associationField !== associationLeaf) {
349
+ (0, import_errors.throwBadRequest)(
350
+ `${context}.associationField '${associationField}' conflicts with ${context}.associationPathName '${(0, import_private_utils.readOptionalString)(
351
+ input.associationPathName
352
+ )}'`
353
+ );
354
+ }
355
+ return {
356
+ binding: "associatedRecords",
357
+ associationField: associationField || associationLeaf
358
+ };
359
+ }
360
+ function readApplyBlueprintActionType(input) {
361
+ if (typeof input === "string") {
362
+ return (0, import_private_utils.readString)(input);
363
+ }
364
+ if (import_lodash.default.isPlainObject(input)) {
365
+ return (0, import_private_utils.readOptionalString)(input.type);
366
+ }
367
+ return void 0;
368
+ }
369
+ function splitApplyBlueprintBlockActionsByScope(block, context) {
370
+ const rawActions = readOptionalItems(block.actions, `${context}.actions`);
371
+ const rawRecordActions = readOptionalItems(block.recordActions, `${context}.recordActions`);
372
+ const blockType = (0, import_private_utils.readOptionalString)(block.type);
373
+ if (!blockType || !APPLY_BLUEPRINT_RECORD_CAPABLE_BLOCK_TYPES.has(blockType)) {
374
+ return {
375
+ actions: rawActions,
376
+ recordActions: rawRecordActions
377
+ };
378
+ }
379
+ const promotedRecordActions = [];
380
+ const remainingActions = [];
381
+ rawActions.forEach((action, index) => {
382
+ const actionType = readApplyBlueprintActionType(action);
383
+ if (actionType === "addChild") {
384
+ (0, import_errors.throwBadRequest)(`${context}.actions[${index}] ${APPLY_BLUEPRINT_ADD_CHILD_RECORD_ACTION_ERROR}`);
385
+ }
386
+ if (actionType && APPLY_BLUEPRINT_AUTO_PROMOTED_RECORD_ACTION_TYPES.has(actionType)) {
387
+ promotedRecordActions.push(action);
388
+ return;
389
+ }
390
+ remainingActions.push(action);
391
+ });
392
+ return {
393
+ actions: remainingActions,
394
+ recordActions: [...rawRecordActions, ...promotedRecordActions]
395
+ };
396
+ }
397
+ function resolveAssetSettings(settings, spec, assets, context) {
398
+ const nextSettings = (0, import_private_utils.cloneOptionalPlainObject)(settings, `${context}.settings`) || {};
399
+ const mergeAsset = (bucket, assetKey) => {
400
+ const normalizedKey = (0, import_private_utils.readOptionalString)(assetKey);
401
+ if (!normalizedKey) {
402
+ return;
403
+ }
404
+ const registry = assets[bucket] || {};
405
+ const asset = registry[normalizedKey];
406
+ if (!import_lodash.default.isPlainObject(asset)) {
407
+ (0, import_errors.throwBadRequest)(`${context} ${bucket.slice(0, -1)} asset '${normalizedKey}' is not defined in assets.${bucket}`);
408
+ }
409
+ import_lodash.default.merge(nextSettings, import_lodash.default.cloneDeep(asset));
410
+ };
411
+ mergeAsset("charts", spec.chart);
412
+ mergeAsset("scripts", spec.script);
413
+ return nextSettings;
414
+ }
415
+ function readOptionalItems(value, context) {
416
+ return (0, import_private_utils.readOptionalArray)(value, context) || [];
417
+ }
418
+ function ensureOptionalTemplate(value, context) {
419
+ return (0, import_private_utils.cloneOptionalPlainObject)(value, context);
420
+ }
421
+ function resolvePopupTitleSettings(settings, title) {
422
+ if (!title) {
423
+ return settings;
424
+ }
425
+ const nextSettings = import_lodash.default.cloneDeep(settings || {});
426
+ if (import_lodash.default.isUndefined(import_lodash.default.get(nextSettings, ["openView", "title"]))) {
427
+ import_lodash.default.set(nextSettings, ["openView", "title"], title);
428
+ }
429
+ return nextSettings;
430
+ }
431
+ function normalizeBlockResourceObject(input, context) {
432
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, context, APPLY_BLUEPRINT_BLOCK_RESOURCE_ALLOWED_KEYS);
433
+ const hasBinding = Object.prototype.hasOwnProperty.call(input, "binding");
434
+ if (hasBinding) {
435
+ const normalizedAssociatedRecords = normalizeAssociatedRecordsBindingFromAssociationPath(input, context);
436
+ const mixedRawKeys = APPLY_BLUEPRINT_BLOCK_RESOURCE_RAW_ONLY_KEYS.filter(
437
+ (key) => Object.prototype.hasOwnProperty.call(input, key) && !(normalizedAssociatedRecords && key === "associationPathName")
438
+ );
439
+ if (mixedRawKeys.length) {
440
+ (0, import_errors.throwBadRequest)(
441
+ `${context} cannot mix binding with ${mixedRawKeys.map((key) => `${context}.${key}`).join(", ")}`
442
+ );
443
+ }
444
+ return (0, import_service_utils.buildDefinedPayload)({
445
+ binding: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.binding) || (0, import_private_utils.assertNonEmptyString)(input.binding, `${context}.binding`),
446
+ dataSourceKey: (0, import_private_utils.readOptionalString)(input.dataSourceKey),
447
+ collectionName: (0, import_private_utils.readOptionalString)(input.collectionName),
448
+ associationField: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.associationField) || (0, import_private_utils.readOptionalString)(input.associationField)
449
+ });
450
+ }
451
+ if (Object.prototype.hasOwnProperty.call(input, "associationField")) {
452
+ (0, import_errors.throwBadRequest)(`${context}.associationField only works when ${context}.binding is provided`);
453
+ }
454
+ const collectionName = (0, import_private_utils.readOptionalString)(input.collectionName);
455
+ const normalized = (0, import_service_utils.buildDefinedPayload)({
456
+ dataSourceKey: (0, import_private_utils.readOptionalString)(input.dataSourceKey) || (collectionName ? "main" : void 0),
457
+ collectionName,
458
+ associationName: (0, import_private_utils.readOptionalString)(input.associationName),
459
+ associationPathName: (0, import_private_utils.readOptionalString)(input.associationPathName),
460
+ sourceId: input.sourceId,
461
+ filterByTk: input.filterByTk
462
+ });
463
+ if (!Object.keys(normalized).length) {
464
+ (0, import_errors.throwBadRequest)(`${context} cannot be empty`);
465
+ }
466
+ return normalized;
467
+ }
468
+ function buildBlockResource(block, context) {
469
+ if (!import_lodash.default.isUndefined(block.resource)) {
470
+ if (!import_lodash.default.isPlainObject(block.resource)) {
471
+ (0, import_errors.throwBadRequest)(`${context}.resource must be an object`);
472
+ }
473
+ const mixedShorthandKeys = APPLY_BLUEPRINT_BLOCK_RESOURCE_SHORTHAND_KEYS.filter(
474
+ (key) => Object.prototype.hasOwnProperty.call(block, key)
475
+ );
476
+ if (mixedShorthandKeys.length) {
477
+ (0, import_errors.throwBadRequest)(
478
+ `${context} cannot mix resource with ${mixedShorthandKeys.map((key) => `${context}.${key}`).join(", ")}`
479
+ );
480
+ }
481
+ return normalizeBlockResourceObject(block.resource, `${context}.resource`);
482
+ }
483
+ const binding = (0, import_private_utils.readOptionalString)(block.binding);
484
+ if (binding) {
485
+ const normalizedAssociatedRecords = normalizeAssociatedRecordsBindingFromAssociationPath(
486
+ block,
487
+ context
488
+ );
489
+ if (Object.prototype.hasOwnProperty.call(block, "associationPathName") && !normalizedAssociatedRecords) {
490
+ (0, import_errors.throwBadRequest)(`${context} cannot mix ${context}.binding with ${context}.associationPathName`);
491
+ }
492
+ return (0, import_service_utils.buildDefinedPayload)({
493
+ binding: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.binding) || binding,
494
+ dataSourceKey: (0, import_private_utils.readOptionalString)(block.dataSourceKey),
495
+ collectionName: (0, import_private_utils.readOptionalString)(block.collection),
496
+ associationField: (normalizedAssociatedRecords == null ? void 0 : normalizedAssociatedRecords.associationField) || (0, import_private_utils.readOptionalString)(block.associationField)
497
+ });
498
+ }
499
+ if (Object.prototype.hasOwnProperty.call(block, "associationField")) {
500
+ (0, import_errors.throwBadRequest)(`${context}.associationField only works when ${context}.binding is provided`);
501
+ }
502
+ const collectionName = (0, import_private_utils.readOptionalString)(block.collection);
503
+ if (!collectionName) {
504
+ return void 0;
505
+ }
506
+ return (0, import_service_utils.buildDefinedPayload)({
507
+ dataSourceKey: (0, import_private_utils.readOptionalString)(block.dataSourceKey) || "main",
508
+ collectionName,
509
+ associationPathName: (0, import_private_utils.readOptionalString)(block.associationPathName)
510
+ });
511
+ }
512
+ function ensureLayoutRows(layout, context) {
513
+ if (import_lodash.default.isUndefined(layout)) {
514
+ return void 0;
515
+ }
516
+ if (!import_lodash.default.isPlainObject(layout)) {
517
+ (0, import_errors.throwBadRequest)(`${context} must be an object`);
518
+ }
519
+ (0, import_private_utils.assertOnlyAllowedKeys)(layout, context, APPLY_BLUEPRINT_LAYOUT_ALLOWED_KEYS);
520
+ if (!Array.isArray(layout.rows) || !layout.rows.length) {
521
+ (0, import_errors.throwBadRequest)(`${context}.rows must be a non-empty array`);
522
+ }
523
+ return layout.rows.map((row, rowIndex) => {
524
+ if (!Array.isArray(row) || !row.length) {
525
+ (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}] must be a non-empty array`);
526
+ }
527
+ row.forEach((item, itemIndex) => {
528
+ if (typeof item === "string") {
529
+ return;
530
+ }
531
+ if (!import_lodash.default.isPlainObject(item)) {
532
+ (0, import_errors.throwBadRequest)(`${context}.rows[${rowIndex}][${itemIndex}] must be a string or object`);
533
+ }
534
+ (0, import_private_utils.assertOnlyAllowedKeys)(
535
+ item,
536
+ `${context}.rows[${rowIndex}][${itemIndex}]`,
537
+ APPLY_BLUEPRINT_LAYOUT_CELL_ALLOWED_KEYS
538
+ );
539
+ });
540
+ return row;
541
+ });
542
+ }
543
+ function autoLayoutFromBlockKeys(blockKeys) {
544
+ return {
545
+ rows: blockKeys.map((key) => [key])
546
+ };
547
+ }
548
+ function collectReferencedBlockKeys(layout, context) {
549
+ const referenced = /* @__PURE__ */ new Set();
550
+ const rows = ensureLayoutRows(layout, context) || [];
551
+ rows.forEach((row, rowIndex) => {
552
+ row.forEach((cell, itemIndex) => {
553
+ if (typeof cell === "string") {
554
+ const key2 = (0, import_private_utils.readString)(cell);
555
+ if (key2) {
556
+ referenced.add(key2);
557
+ }
558
+ return;
559
+ }
560
+ const key = (0, import_private_utils.assertNonEmptyString)(cell.key, `${context}.rows[${rowIndex}][${itemIndex}].key`);
561
+ if (key) {
562
+ referenced.add(key);
563
+ }
564
+ });
565
+ });
566
+ return referenced;
567
+ }
568
+ function compileLayout(layout, blockKeysByLocalKey, context) {
569
+ return compileScopedLayout(layout, blockKeysByLocalKey, context, "block");
570
+ }
571
+ function resolveScopedLayoutKey(rawKey, keysByLocalKey, context, kind) {
572
+ const resolved = keysByLocalKey.get(rawKey) || [...keysByLocalKey.values()].find((value) => value === rawKey);
573
+ if (!resolved) {
574
+ (0, import_errors.throwBadRequest)(`${context} references unknown ${kind} '${rawKey}'`);
575
+ }
576
+ return resolved;
577
+ }
578
+ function compileScopedLayout(layout, keysByLocalKey, context, kind) {
579
+ const rows = ensureLayoutRows(layout, context);
580
+ if (!rows) {
581
+ return void 0;
582
+ }
583
+ return {
584
+ rows: rows.map((row, rowIndex) => {
585
+ return row.map((item, itemIndex) => {
586
+ const cellContext = `${context}.rows[${rowIndex}][${itemIndex}]`;
587
+ if (typeof item === "string") {
588
+ const itemKey = (0, import_private_utils.readString)(item);
589
+ return resolveScopedLayoutKey(itemKey, keysByLocalKey, cellContext, kind);
590
+ }
591
+ const rawKey = (0, import_private_utils.assertNonEmptyString)(item.key, `${cellContext}.key`);
592
+ const resolved = resolveScopedLayoutKey(rawKey, keysByLocalKey, cellContext, kind);
593
+ return (0, import_service_utils.buildDefinedPayload)({
594
+ key: resolved,
595
+ span: import_lodash.default.isUndefined(item.span) ? void 0 : import_lodash.default.isNumber(item.span) ? item.span : (0, import_errors.throwBadRequest)(`${cellContext}.span must be a number`)
596
+ });
597
+ });
598
+ })
599
+ };
600
+ }
601
+ function buildCompactFieldLayoutRow(keys, blockType) {
602
+ const normalizedKeys = keys.filter(Boolean);
603
+ if (!normalizedKeys.length) {
604
+ return [];
605
+ }
606
+ if (blockType === "filterForm") {
607
+ const span = normalizedKeys.length === 1 ? 24 : normalizedKeys.length === 2 ? 12 : 8;
608
+ return normalizedKeys.map((key) => ({ key, span }));
609
+ }
610
+ if (normalizedKeys.length === 1) {
611
+ return [{ key: normalizedKeys[0], span: 24 }];
612
+ }
613
+ return normalizedKeys.map((key) => ({ key, span: 12 }));
614
+ }
615
+ function buildAutoCompiledFieldsLayout(fields, blockType) {
616
+ if (!APPLY_BLUEPRINT_FIELD_GRID_BLOCK_TYPES.has(blockType || "") || !fields.length) {
617
+ return void 0;
618
+ }
619
+ const rows = [];
620
+ const chunkSize = blockType === "filterForm" ? 3 : 2;
621
+ let pendingKeys = [];
622
+ const flushPending = () => {
623
+ if (!pendingKeys.length) {
624
+ return;
625
+ }
626
+ rows.push(buildCompactFieldLayoutRow(pendingKeys, blockType));
627
+ pendingKeys = [];
628
+ };
629
+ fields.forEach((field) => {
630
+ const key = (0, import_private_utils.readOptionalString)(field == null ? void 0 : field.key);
631
+ if (!key) {
632
+ return;
633
+ }
634
+ if ((0, import_private_utils.readOptionalString)(field == null ? void 0 : field.type) === "divider") {
635
+ flushPending();
636
+ rows.push([{ key, span: 24 }]);
637
+ return;
638
+ }
639
+ pendingKeys.push(key);
640
+ if (pendingKeys.length >= chunkSize) {
641
+ flushPending();
642
+ }
643
+ });
644
+ flushPending();
645
+ return rows.length ? { rows } : void 0;
646
+ }
647
+ function compileFieldGroups(fieldGroups, context) {
648
+ const expanded = [];
649
+ fieldGroups.forEach((group, groupIndex) => {
650
+ const groupContext = `${context}[${groupIndex}]`;
651
+ if (!import_lodash.default.isPlainObject(group)) {
652
+ (0, import_errors.throwBadRequest)(`${groupContext} must be an object`);
653
+ }
654
+ (0, import_private_utils.assertOnlyAllowedKeys)(group, groupContext, APPLY_BLUEPRINT_FIELD_GROUP_ALLOWED_KEYS);
655
+ const title = (0, import_private_utils.assertNonEmptyString)(group.title, `${groupContext}.title`);
656
+ const groupFields = readOptionalItems(group.fields, `${groupContext}.fields`);
657
+ if (!groupFields.length) {
658
+ (0, import_errors.throwBadRequest)(`${groupContext}.fields must be a non-empty array`);
659
+ }
660
+ const groupLocalKey = (0, import_private_utils.normalizeBlueprintLocalKey)(
661
+ group.key,
662
+ title || `group_${groupIndex + 1}`,
663
+ `${groupContext}.key`
664
+ );
665
+ expanded.push({
666
+ key: `${groupLocalKey}_divider`,
667
+ type: "divider",
668
+ settings: {
669
+ label: title,
670
+ orientation: "left"
671
+ }
672
+ });
673
+ expanded.push(...groupFields);
674
+ });
675
+ return expanded;
676
+ }
677
+ function resolveBlockFieldInputs(block, context) {
678
+ const hasFields = Object.prototype.hasOwnProperty.call(block, "fields");
679
+ const hasFieldGroups = Object.prototype.hasOwnProperty.call(block, "fieldGroups");
680
+ if (hasFields && hasFieldGroups) {
681
+ (0, import_errors.throwBadRequest)(`${context} cannot mix fields with fieldGroups`);
682
+ }
683
+ if (!hasFieldGroups) {
684
+ return readOptionalItems(block.fields, `${context}.fields`);
685
+ }
686
+ const blockType = (0, import_private_utils.readOptionalString)(block.type);
687
+ if (!APPLY_BLUEPRINT_FIELD_GROUP_BLOCK_TYPES.has(blockType || "")) {
688
+ (0, import_errors.throwBadRequest)(`${context}.fieldGroups is only supported on createForm, editForm or details`);
689
+ }
690
+ if (Object.prototype.hasOwnProperty.call(block, "fieldsLayout")) {
691
+ (0, import_errors.throwBadRequest)(`${context}.fieldsLayout cannot be combined with ${context}.fieldGroups`);
692
+ }
693
+ const fieldGroups = (0, import_private_utils.readOptionalArray)(
694
+ block.fieldGroups,
695
+ `${context}.fieldGroups`
696
+ );
697
+ if (!(fieldGroups == null ? void 0 : fieldGroups.length)) {
698
+ (0, import_errors.throwBadRequest)(`${context}.fieldGroups must be a non-empty array`);
699
+ }
700
+ return compileFieldGroups(fieldGroups, `${context}.fieldGroups`);
701
+ }
702
+ function resolveApplyBlueprintFieldLocalKey(input, index, context) {
703
+ if (typeof input === "string") {
704
+ return (0, import_private_utils.assertNonEmptyString)(input, `${context}[${index}]`);
705
+ }
706
+ if (!import_lodash.default.isPlainObject(input)) {
707
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be a string or object`);
708
+ }
709
+ const fieldPath = (0, import_private_utils.readOptionalString)(input.field);
710
+ const syntheticType = (0, import_private_utils.readOptionalString)(input.type);
711
+ if (!fieldPath && !syntheticType) {
712
+ (0, import_errors.throwBadRequest)(`${context}[${index}] requires field or type`);
713
+ }
714
+ if (fieldPath && syntheticType) {
715
+ (0, import_errors.throwBadRequest)(`${context}[${index}] cannot mix field with synthetic type`);
716
+ }
717
+ return (0, import_private_utils.normalizeBlueprintLocalKey)(
718
+ input.key,
719
+ fieldPath || (syntheticType ? `${syntheticType}_${index + 1}` : `field_${index + 1}`),
720
+ `${context}[${index}].key`
721
+ );
722
+ }
723
+ function buildCompiledFieldKeyMap(inputs, compiledFields, context) {
724
+ const fieldKeysByLocalKey = /* @__PURE__ */ new Map();
725
+ inputs.forEach((input, index) => {
726
+ var _a;
727
+ const localKey = resolveApplyBlueprintFieldLocalKey(input, index, context);
728
+ const compiledKey = (0, import_private_utils.readOptionalString)((_a = compiledFields[index]) == null ? void 0 : _a.key);
729
+ if (!compiledKey) {
730
+ (0, import_errors.throwBadRequest)(`${context}[${index}] key '${localKey}' is missing after field key compilation`);
731
+ }
732
+ if (fieldKeysByLocalKey.has(localKey)) {
733
+ (0, import_errors.throwBadRequest)(`${context}[${index}] key '${localKey}' is duplicated`);
734
+ }
735
+ fieldKeysByLocalKey.set(localKey, compiledKey);
736
+ });
737
+ return fieldKeysByLocalKey;
738
+ }
739
+ function shouldAttachDefaultPopupMetadata(popup, itemType, options = {}) {
740
+ return !import_lodash.default.isUndefined(popup) || options.autoRelationField || APPLY_BLUEPRINT_DEFAULT_POPUP_ACTION_TYPES.has(itemType || "");
741
+ }
742
+ function attachCompiledPopupDefaults(popup, metadata) {
743
+ return (0, import_defaults.attachFlowSurfaceApplyBlueprintPopupDefaults)(popup, metadata);
744
+ }
745
+ function attachDefaultActionPopupMetadata(popup, actionType, metadata) {
746
+ const defaultPopup = actionType === "addChild" && import_lodash.default.isUndefined(popup) ? {} : popup;
747
+ return attachCompiledPopupDefaults(defaultPopup, metadata);
748
+ }
749
+ function compilePopup(popup, scopePrefix, assets, context, defaults, options = {}) {
750
+ if (import_lodash.default.isUndefined(popup)) {
751
+ return {};
752
+ }
753
+ if (!import_lodash.default.isPlainObject(popup)) {
754
+ (0, import_errors.throwBadRequest)(`${context} must be an object`);
755
+ }
756
+ (0, import_private_utils.assertOnlyAllowedKeys)(popup, context, APPLY_BLUEPRINT_POPUP_ALLOWED_KEYS);
757
+ const popupTitle = (0, import_private_utils.readOptionalString)(popup.title);
758
+ const template = ensureOptionalTemplate(popup.template, `${context}.template`);
759
+ const tryTemplate = import_lodash.default.isUndefined(popup.tryTemplate) ? void 0 : import_lodash.default.isBoolean(popup.tryTemplate) ? popup.tryTemplate : (0, import_errors.throwBadRequest)(`${context}.tryTemplate must be a boolean`);
760
+ const defaultType = import_lodash.default.isUndefined(popup.defaultType) ? void 0 : popup.defaultType === "view" || popup.defaultType === "edit" ? popup.defaultType : (0, import_errors.throwBadRequest)(`${context}.defaultType must be 'view' or 'edit'`);
761
+ const saveAsTemplate = import_lodash.default.isUndefined(popup.saveAsTemplate) ? void 0 : import_lodash.default.isPlainObject(popup.saveAsTemplate) ? ((0, import_private_utils.assertOnlyAllowedKeys)(
762
+ popup.saveAsTemplate,
763
+ `${context}.saveAsTemplate`,
764
+ APPLY_BLUEPRINT_POPUP_SAVE_AS_TEMPLATE_ALLOWED_KEYS
765
+ ), {
766
+ name: (0, import_private_utils.assertNonEmptyString)(popup.saveAsTemplate.name, `${context}.saveAsTemplate.name`),
767
+ description: (0, import_private_utils.assertNonEmptyString)(popup.saveAsTemplate.description, `${context}.saveAsTemplate.description`),
768
+ local: (0, import_private_utils.readOptionalString)(popup.saveAsTemplate.local)
769
+ }) : (0, import_errors.throwBadRequest)(`${context}.saveAsTemplate must be an object`);
770
+ if (saveAsTemplate && template) {
771
+ (0, import_errors.throwBadRequest)(`${context}.saveAsTemplate cannot be combined with ${context}.template`);
772
+ }
773
+ if (template) {
774
+ return {
775
+ popup: {
776
+ template
777
+ },
778
+ popupTitle
779
+ };
780
+ }
781
+ const rawPopupBlocks = readOptionalItems(popup.blocks, `${context}.blocks`);
782
+ const popupBlocks = options.ownerActionType === "edit" && rawPopupBlocks.length ? normalizeEditPopupBlocks(rawPopupBlocks, context) : rawPopupBlocks;
783
+ if (saveAsTemplate && !popupBlocks.length && tryTemplate !== true) {
784
+ (0, import_errors.throwBadRequest)(`${context}.saveAsTemplate requires explicit popup.blocks`);
785
+ }
786
+ const compiledBlocks = popupBlocks.length ? compileBlocks(
787
+ popupBlocks,
788
+ scopePrefix,
789
+ assets,
790
+ `${context}.blocks`,
791
+ defaults,
792
+ collectReferencedBlockKeys(popup.layout, `${context}.layout`),
793
+ options.getCollection
794
+ ) : { blocks: [], blockKeysByLocalKey: /* @__PURE__ */ new Map() };
795
+ const layout = popupBlocks.length || popup.layout ? compileLayout(
796
+ popup.layout || autoLayoutFromBlockKeys(compiledBlocks.blocks.map((block) => block.key)),
797
+ compiledBlocks.blockKeysByLocalKey,
798
+ `${context}.layout`
799
+ ) : void 0;
800
+ const popupMode = (0, import_private_utils.readOptionalString)(popup.mode);
801
+ if (popupMode && popupMode !== "replace" && popupMode !== "append") {
802
+ (0, import_errors.throwBadRequest)(`${context}.mode must be 'replace' or 'append'`);
803
+ }
804
+ const compiledPopup = (0, import_service_utils.buildDefinedPayload)({
805
+ mode: popupMode || (popupBlocks.length || template || layout ? "replace" : void 0),
806
+ template,
807
+ ...tryTemplate ? { tryTemplate: true } : {},
808
+ ...defaultType ? { defaultType } : {},
809
+ ...saveAsTemplate ? { saveAsTemplate } : {},
810
+ blocks: compiledBlocks.blocks.length ? compiledBlocks.blocks : void 0,
811
+ layout
812
+ });
813
+ return {
814
+ popup: Object.keys(compiledPopup).length ? compiledPopup : {},
815
+ popupTitle
816
+ };
817
+ }
818
+ function resolveTargetBlockKey(value, localBlockKeys, context) {
819
+ if (import_lodash.default.isUndefined(value) || value === null || value === "") {
820
+ return void 0;
821
+ }
822
+ if (typeof value === "string") {
823
+ const normalized = (0, import_private_utils.readString)(value);
824
+ return localBlockKeys.get(normalized) || normalized;
825
+ }
826
+ (0, import_errors.throwBadRequest)(`${context} must be a string block key`);
827
+ }
828
+ function collectTreeConnectTargetKeys(settings, context) {
829
+ if (!import_lodash.default.isPlainObject(settings == null ? void 0 : settings.connectFields)) {
830
+ return [];
831
+ }
832
+ if (import_lodash.default.isUndefined(settings.connectFields.targets)) {
833
+ return [];
834
+ }
835
+ if (!Array.isArray(settings.connectFields.targets)) {
836
+ (0, import_errors.throwBadRequest)(`${context}.settings.connectFields.targets must be an array`);
837
+ }
838
+ const seenTargets = /* @__PURE__ */ new Set();
839
+ return settings.connectFields.targets.map((target, targetIndex) => {
840
+ if (!import_lodash.default.isPlainObject(target)) {
841
+ (0, import_errors.throwBadRequest)(`${context}.settings.connectFields.targets[${targetIndex}] must be an object`);
842
+ }
843
+ if (import_lodash.default.isUndefined(target.target) || target.target === null || target.target === "") {
844
+ return "";
845
+ }
846
+ if (typeof target.target !== "string") {
847
+ (0, import_errors.throwBadRequest)(`${context}.settings.connectFields.targets[${targetIndex}].target must be a string block key`);
848
+ }
849
+ const normalizedTarget = (0, import_service_utils.normalizeFlowSurfaceComposeKey)(
850
+ target.target,
851
+ `${context}.settings.connectFields.targets[${targetIndex}].target`
852
+ );
853
+ if (seenTargets.has(normalizedTarget)) {
854
+ (0, import_errors.throwBadRequest)(
855
+ `${context}.settings.connectFields.targets[${targetIndex}].target duplicate target '${normalizedTarget}' in tree connectFields`
856
+ );
857
+ }
858
+ seenTargets.add(normalizedTarget);
859
+ return normalizedTarget;
860
+ }).filter(Boolean);
861
+ }
862
+ function compileTreeConnectSettingsTargets(settings, localBlockKeys, context) {
863
+ if (!import_lodash.default.isPlainObject(settings == null ? void 0 : settings.connectFields) || !Array.isArray(settings.connectFields.targets)) {
864
+ return settings;
865
+ }
866
+ const nextSettings = import_lodash.default.cloneDeep(settings);
867
+ nextSettings.connectFields.targets = nextSettings.connectFields.targets.map((target, targetIndex) => {
868
+ if (!import_lodash.default.isPlainObject(target) || import_lodash.default.isUndefined(target.target) || target.target === null || target.target === "") {
869
+ return target;
870
+ }
871
+ return {
872
+ ...target,
873
+ target: resolveTargetBlockKey(
874
+ target.target,
875
+ localBlockKeys,
876
+ `${context}.settings.connectFields.targets[${targetIndex}].target`
877
+ )
878
+ };
879
+ });
880
+ return nextSettings;
881
+ }
882
+ function compileField(input, index, scopePrefix, assets, localBlockKeys, context, popupDefaultsMetadata, defaults, getCollection) {
883
+ if (typeof input === "string") {
884
+ const fieldPath2 = (0, import_private_utils.assertNonEmptyString)(input, `${context}[${index}]`);
885
+ return {
886
+ key: (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, fieldPath2), `${context}[${index}]`),
887
+ fieldPath: fieldPath2,
888
+ __autoPopupForRelationField: true,
889
+ ...popupDefaultsMetadata ? { [import_defaults.FLOW_SURFACE_APPLY_BLUEPRINT_POPUP_DEFAULTS_KEY]: import_lodash.default.cloneDeep(popupDefaultsMetadata) } : {}
890
+ };
891
+ }
892
+ if (!import_lodash.default.isPlainObject(input)) {
893
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be a string or object`);
894
+ }
895
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, `${context}[${index}]`, APPLY_BLUEPRINT_FIELD_ALLOWED_KEYS);
896
+ (0, import_field_type_resolver.assertNoInternalFieldKeys)(input, `${context}[${index}]`);
897
+ (0, import_field_type_resolver.assertNoInternalFieldKeys)(input.settings, `${context}[${index}].settings`);
898
+ const fieldPath = (0, import_private_utils.readOptionalString)(input.field);
899
+ const syntheticType = (0, import_private_utils.readOptionalString)(input.type);
900
+ const fieldType = (0, import_field_type_resolver.normalizePublicFieldType)(input.fieldType, `${context}[${index}]`);
901
+ const fields = (0, import_field_type_resolver.normalizePublicFieldNameList)(input.fields, `${context}[${index}].fields`);
902
+ if (!fieldPath && !syntheticType) {
903
+ (0, import_errors.throwBadRequest)(`${context}[${index}] requires field or type`);
904
+ }
905
+ if (fieldPath && syntheticType) {
906
+ (0, import_errors.throwBadRequest)(`${context}[${index}] cannot mix field with synthetic type`);
907
+ }
908
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(
909
+ input.key,
910
+ fieldPath || (syntheticType ? `${syntheticType}_${index + 1}` : `field_${index + 1}`),
911
+ `${context}[${index}].key`
912
+ );
913
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
914
+ let settings = resolveAssetSettings(input.settings, input, assets, `${context}[${index}]`);
915
+ if ((0, import_private_utils.readOptionalString)(input.label) && import_lodash.default.isUndefined(settings.label)) {
916
+ settings.label = (0, import_private_utils.readOptionalString)(input.label);
917
+ }
918
+ const popupResult = compilePopup(input.popup, `${key}.popup`, assets, `${context}[${index}].popup`, defaults, {
919
+ getCollection
920
+ });
921
+ settings = resolvePopupTitleSettings(settings, popupResult.popupTitle);
922
+ const popup = shouldAttachDefaultPopupMetadata(input.popup, void 0) ? attachCompiledPopupDefaults(popupResult.popup, popupDefaultsMetadata) : popupResult.popup;
923
+ return (0, import_service_utils.buildDefinedPayload)({
924
+ key,
925
+ fieldPath,
926
+ associationPathName: (0, import_private_utils.readOptionalString)(input.associationPathName),
927
+ renderer: (0, import_private_utils.readOptionalString)(input.renderer),
928
+ type: syntheticType,
929
+ fieldType,
930
+ fields,
931
+ titleField: (0, import_private_utils.readOptionalString)(input.titleField),
932
+ openMode: (0, import_private_utils.readOptionalString)(input.openMode),
933
+ popupSize: (0, import_private_utils.readOptionalString)(input.popupSize),
934
+ pageSize: input.pageSize,
935
+ showIndex: input.showIndex,
936
+ target: resolveTargetBlockKey(input.target, localBlockKeys, `${context}[${index}].target`),
937
+ settings: Object.keys(settings).length ? settings : void 0,
938
+ popup
939
+ });
940
+ }
941
+ function compileAction(input, index, scopePrefix, assets, context, popupDefaultsMetadata, defaults, getCollection) {
942
+ if (typeof input === "string") {
943
+ const type2 = (0, import_private_utils.assertNonEmptyString)(input, `${context}[${index}]`);
944
+ return {
945
+ key: (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, `${type2}_${index + 1}`), `${context}[${index}]`),
946
+ type: type2,
947
+ ...APPLY_BLUEPRINT_DEFAULT_POPUP_ACTION_TYPES.has(type2) ? { popup: attachDefaultActionPopupMetadata(void 0, type2, popupDefaultsMetadata) } : {}
948
+ };
949
+ }
950
+ if (!import_lodash.default.isPlainObject(input)) {
951
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be a string or object`);
952
+ }
953
+ (0, import_private_utils.assertOnlyAllowedKeys)(input, `${context}[${index}]`, APPLY_BLUEPRINT_ACTION_ALLOWED_KEYS);
954
+ const type = (0, import_private_utils.assertNonEmptyString)(input.type, `${context}[${index}].type`);
955
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(input.key, `${type}_${index + 1}`, `${context}[${index}].key`);
956
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
957
+ let settings = resolveAssetSettings(input.settings, input, assets, `${context}[${index}]`);
958
+ if ((0, import_private_utils.readOptionalString)(input.title) && import_lodash.default.isUndefined(settings.title)) {
959
+ settings.title = (0, import_private_utils.readOptionalString)(input.title);
960
+ }
961
+ const popupResult = compilePopup(input.popup, `${key}.popup`, assets, `${context}[${index}].popup`, defaults, {
962
+ ownerActionType: type,
963
+ getCollection
964
+ });
965
+ settings = resolvePopupTitleSettings(settings, popupResult.popupTitle);
966
+ const popup = shouldAttachDefaultPopupMetadata(input.popup, type) ? attachDefaultActionPopupMetadata(popupResult.popup, type, popupDefaultsMetadata) : popupResult.popup;
967
+ return (0, import_service_utils.buildDefinedPayload)({
968
+ key,
969
+ type,
970
+ settings: Object.keys(settings).length ? settings : void 0,
971
+ popup
972
+ });
973
+ }
974
+ function compileInjectedDefaultAction(descriptor, scopePrefix, context, index, popupDefaultsMetadata) {
975
+ const descriptorPopup = descriptor.popup ? import_lodash.default.cloneDeep(descriptor.popup) : void 0;
976
+ const popup = shouldAttachDefaultPopupMetadata(descriptorPopup, descriptor.type) ? attachCompiledPopupDefaults(descriptorPopup, popupDefaultsMetadata) : void 0;
977
+ return (0, import_service_utils.buildDefinedPayload)({
978
+ key: (0, import_service_utils.normalizeFlowSurfaceComposeKey)(
979
+ (0, import_private_utils.buildScopedKey)(scopePrefix, `${descriptor.type}_default_${index + 1}`),
980
+ `${context}[${index}]`
981
+ ),
982
+ type: descriptor.type,
983
+ popup
984
+ });
985
+ }
986
+ function isTreeCollection(collection) {
987
+ var _a;
988
+ return (collection == null ? void 0 : collection.template) === "tree" || ((_a = collection == null ? void 0 : collection.options) == null ? void 0 : _a.template) === "tree" || (collection == null ? void 0 : collection.tree) === true;
989
+ }
990
+ function resolveTreeChildrenFieldName(collection) {
991
+ const field = (0, import_service_helpers.getCollectionFields)(collection).find(
992
+ (candidate) => {
993
+ var _a;
994
+ return (candidate == null ? void 0 : candidate.treeChildren) === true || ((_a = candidate == null ? void 0 : candidate.options) == null ? void 0 : _a.treeChildren) === true;
995
+ }
996
+ );
997
+ return (0, import_service_helpers.getFieldName)(field);
998
+ }
999
+ function canInjectTreeTableAddChildDefault(block, getCollection) {
1000
+ if (!getCollection) {
1001
+ return false;
1002
+ }
1003
+ const resource = import_lodash.default.isPlainObject(block.resource) ? block.resource : void 0;
1004
+ const dataSourceKey = (0, import_private_utils.readOptionalString)(block.dataSourceKey) || (0, import_private_utils.readOptionalString)(resource == null ? void 0 : resource.dataSourceKey) || "main";
1005
+ const collectionName = (0, import_private_utils.readOptionalString)(block.collection) || (0, import_private_utils.readOptionalString)(resource == null ? void 0 : resource.collectionName);
1006
+ if (!collectionName) {
1007
+ return false;
1008
+ }
1009
+ const collection = getCollection(dataSourceKey, collectionName);
1010
+ if (!collection) {
1011
+ return false;
1012
+ }
1013
+ if (!isTreeCollection(collection)) {
1014
+ return false;
1015
+ }
1016
+ return !!resolveTreeChildrenFieldName(collection);
1017
+ }
1018
+ function hasExplicitAddChildRecordAction(recordActions) {
1019
+ return recordActions.some((action) => {
1020
+ if (typeof action === "string") {
1021
+ return action.trim() === "addChild";
1022
+ }
1023
+ return (0, import_private_utils.readOptionalString)(action == null ? void 0 : action.type) === "addChild";
1024
+ });
1025
+ }
1026
+ function buildTreeTableAddChildDefaultAction(scopePrefix, context, index, popupDefaultsMetadata) {
1027
+ const descriptorPopup = {
1028
+ tryTemplate: true,
1029
+ [import_default_block_actions.FLOW_SURFACE_INTERNAL_AUTO_SAVE_DEFAULT_POPUP_TEMPLATE_KEY]: true
1030
+ };
1031
+ return compileInjectedDefaultAction(
1032
+ {
1033
+ type: "addChild",
1034
+ scope: "recordActions",
1035
+ popup: descriptorPopup
1036
+ },
1037
+ scopePrefix,
1038
+ context,
1039
+ index,
1040
+ popupDefaultsMetadata
1041
+ );
1042
+ }
1043
+ function compileBlocks(input, scopePrefix, assets, context, defaults, requiredExplicitBlockKeys = /* @__PURE__ */ new Set(), getCollection) {
1044
+ const blockKeysByLocalKey = /* @__PURE__ */ new Map();
1045
+ const referencedBlockKeys = new Set(requiredExplicitBlockKeys);
1046
+ const rawBlocks = import_lodash.default.castArray(input || []);
1047
+ const popupDefaultsMetadata = (0, import_defaults.buildFlowSurfaceApplyBlueprintPopupDefaultsMetadata)(defaults);
1048
+ rawBlocks.forEach((block, index) => {
1049
+ if (!import_lodash.default.isPlainObject(block)) {
1050
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be an object`);
1051
+ }
1052
+ assertApplyBlueprintCalendarMainContent(block, `${context}[${index}]`);
1053
+ assertApplyBlueprintKanbanMainContent(block, `${context}[${index}]`);
1054
+ assertApplyBlueprintTreeMainContent(block, `${context}[${index}]`);
1055
+ const fields = resolveBlockFieldInputs(block, `${context}[${index}]`);
1056
+ collectTreeConnectTargetKeys(block.settings, `${context}[${index}]`).forEach((targetKey) => {
1057
+ referencedBlockKeys.add(targetKey);
1058
+ });
1059
+ fields.forEach((field, fieldIndex) => {
1060
+ if (typeof (field == null ? void 0 : field.target) !== "string" || !field.target.trim()) {
1061
+ return;
1062
+ }
1063
+ referencedBlockKeys.add(
1064
+ (0, import_service_utils.normalizeFlowSurfaceComposeKey)(field.target, `${context}[${index}].fields[${fieldIndex}].target`)
1065
+ );
1066
+ });
1067
+ });
1068
+ rawBlocks.forEach((block, index) => {
1069
+ if (!import_lodash.default.isPlainObject(block)) {
1070
+ (0, import_errors.throwBadRequest)(`${context}[${index}] must be an object`);
1071
+ }
1072
+ assertNoBlockLevelLayout(block, `${context}[${index}]`);
1073
+ assertApplyBlueprintFieldsLayoutHost(block, `${context}[${index}]`);
1074
+ (0, import_private_utils.assertOnlyAllowedKeys)(block, `${context}[${index}]`, APPLY_BLUEPRINT_BLOCK_ALLOWED_KEYS);
1075
+ assertApplyBlueprintBlockType((0, import_private_utils.readOptionalString)(block.type), `${context}[${index}]`);
1076
+ assertApplyBlueprintCalendarMainContent(block, `${context}[${index}]`);
1077
+ assertApplyBlueprintKanbanMainContent(block, `${context}[${index}]`);
1078
+ assertApplyBlueprintTreeMainContent(block, `${context}[${index}]`);
1079
+ const explicitKey = (0, import_private_utils.readString)(block.key);
1080
+ const fallback = block.type ? `${block.type}_${index + 1}` : `block_${index + 1}`;
1081
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(block.key, fallback, `${context}[${index}].key`);
1082
+ if (!explicitKey && referencedBlockKeys.has(localKey)) {
1083
+ (0, import_errors.throwBadRequest)(
1084
+ `${context}[${index}] must provide key explicitly because it is referenced by layout or field.target`
1085
+ );
1086
+ }
1087
+ if (blockKeysByLocalKey.has(localKey)) {
1088
+ (0, import_errors.throwBadRequest)(`${context}[${index}] key '${localKey}' is duplicated`);
1089
+ }
1090
+ const key = (0, import_service_utils.normalizeFlowSurfaceComposeKey)((0, import_private_utils.buildScopedKey)(scopePrefix, localKey), `${context}[${index}]`);
1091
+ blockKeysByLocalKey.set(localKey, key);
1092
+ });
1093
+ const blocks = rawBlocks.map((block, index) => {
1094
+ const blockContext = `${context}[${index}]`;
1095
+ const localKey = (0, import_private_utils.normalizeBlueprintLocalKey)(
1096
+ block.key,
1097
+ block.type ? `${block.type}_${index + 1}` : `block_${index + 1}`,
1098
+ `${blockContext}.key`
1099
+ );
1100
+ const key = blockKeysByLocalKey.get(localKey);
1101
+ if (!key) {
1102
+ (0, import_errors.throwBadRequest)(`${blockContext} key '${localKey}' is missing after block key compilation`);
1103
+ }
1104
+ const blockType = (0, import_private_utils.readOptionalString)(block.type);
1105
+ let settings = resolveAssetSettings(block.settings, block, assets, blockContext);
1106
+ if ((0, import_private_utils.readOptionalString)(block.title) && import_lodash.default.isUndefined(settings.title)) {
1107
+ settings.title = (0, import_private_utils.readOptionalString)(block.title);
1108
+ }
1109
+ settings = (0, import_public_compatibility.normalizeFlowSurfacePublicSortingAlias)({
1110
+ context: `${blockContext}.settings`,
1111
+ type: blockType,
1112
+ settings
1113
+ });
1114
+ if (blockType === "calendar") {
1115
+ settings = normalizeApplyBlueprintCalendarPopupSettings(settings, blockContext, popupDefaultsMetadata);
1116
+ } else if (blockType === "kanban") {
1117
+ settings = normalizeApplyBlueprintKanbanPopupSettings(settings, blockContext, popupDefaultsMetadata);
1118
+ }
1119
+ const template = ensureOptionalTemplate(block.template, `${blockContext}.template`);
1120
+ const blockDefaultFilter = (0, import_public_data_surface_default_filter.normalizeFlowSurfacePublicBlockDefaultFilter)("applyBlueprint", block.defaultFilter, {
1121
+ blockType,
1122
+ template,
1123
+ path: blockContext
1124
+ });
1125
+ if (!import_lodash.default.isUndefined(blockDefaultFilter)) {
1126
+ (0, import_public_data_surface_default_filter.assertFlowSurfaceConcreteDefaultFilterItem)("applyBlueprint", blockDefaultFilter, {
1127
+ path: blockContext
1128
+ });
1129
+ }
1130
+ const fieldInputs = resolveBlockFieldInputs(block, blockContext);
1131
+ const fields = fieldInputs.map(
1132
+ (field, fieldIndex) => compileField(
1133
+ field,
1134
+ fieldIndex,
1135
+ key,
1136
+ assets,
1137
+ blockKeysByLocalKey,
1138
+ `${blockContext}.fields`,
1139
+ popupDefaultsMetadata,
1140
+ defaults,
1141
+ getCollection
1142
+ )
1143
+ );
1144
+ const fieldsLayout = Object.prototype.hasOwnProperty.call(block, "fieldsLayout") ? compileScopedLayout(
1145
+ import_lodash.default.isUndefined(block.fieldsLayout) ? void 0 : import_lodash.default.isPlainObject(block.fieldsLayout) ? block.fieldsLayout : (0, import_errors.throwBadRequest)(`${blockContext}.fieldsLayout must be an object`),
1146
+ buildCompiledFieldKeyMap(fieldInputs, fields, `${blockContext}.fields`),
1147
+ `${blockContext}.fieldsLayout`,
1148
+ "field"
1149
+ ) : buildAutoCompiledFieldsLayout(fields, (0, import_private_utils.readOptionalString)(block.type));
1150
+ const { actions, recordActions } = splitApplyBlueprintBlockActionsByScope(block, blockContext);
1151
+ const explicitActions = actions.map(
1152
+ (action, actionIndex) => compileAction(
1153
+ action,
1154
+ actionIndex,
1155
+ key,
1156
+ assets,
1157
+ `${blockContext}.actions`,
1158
+ popupDefaultsMetadata,
1159
+ defaults,
1160
+ getCollection
1161
+ )
1162
+ );
1163
+ const explicitRecordActions = recordActions.map(
1164
+ (action, actionIndex) => compileAction(
1165
+ action,
1166
+ actionIndex,
1167
+ key,
1168
+ assets,
1169
+ `${blockContext}.recordActions`,
1170
+ popupDefaultsMetadata,
1171
+ defaults,
1172
+ getCollection
1173
+ )
1174
+ );
1175
+ const shouldInjectAddChild = blockType === "table" && import_lodash.default.isUndefined(template) && (settings == null ? void 0 : settings.treeTable) === true && canInjectTreeTableAddChildDefault(block, getCollection);
1176
+ const injectedActionIndexes = {
1177
+ actions: explicitActions.length,
1178
+ recordActions: explicitRecordActions.length
1179
+ };
1180
+ const mergedActions = (0, import_default_block_actions.mergeFlowSurfaceDefaultBlockActions)({
1181
+ blockType,
1182
+ template,
1183
+ actions: explicitActions,
1184
+ recordActions: explicitRecordActions,
1185
+ createAction: (descriptor) => compileInjectedDefaultAction(
1186
+ descriptor,
1187
+ key,
1188
+ `${blockContext}.${descriptor.scope}`,
1189
+ injectedActionIndexes[descriptor.scope]++,
1190
+ popupDefaultsMetadata
1191
+ )
1192
+ });
1193
+ const finalRecordActions = blockType === "table" && shouldInjectAddChild && !hasExplicitAddChildRecordAction(mergedActions.recordActions) ? [
1194
+ ...mergedActions.recordActions,
1195
+ buildTreeTableAddChildDefaultAction(
1196
+ key,
1197
+ `${blockContext}.recordActions`,
1198
+ injectedActionIndexes.recordActions++,
1199
+ popupDefaultsMetadata
1200
+ )
1201
+ ] : mergedActions.recordActions;
1202
+ const actionsWithDefaultFilter = (0, import_public_data_surface_default_filter.backfillFlowSurfaceFilterActionDefaultFilter)(
1203
+ mergedActions.actions,
1204
+ blockDefaultFilter
1205
+ );
1206
+ return (0, import_service_utils.buildDefinedPayload)({
1207
+ key,
1208
+ type: blockType,
1209
+ resource: buildBlockResource(block, blockContext),
1210
+ template,
1211
+ settings: Object.keys(settings).length ? compileTreeConnectSettingsTargets(settings, blockKeysByLocalKey, blockContext) : void 0,
1212
+ fields: blockType === "calendar" || blockType === "tree" ? void 0 : fields,
1213
+ fieldsLayout: blockType === "calendar" || blockType === "kanban" || blockType === "tree" ? void 0 : fieldsLayout,
1214
+ actions: blockType === "tree" ? void 0 : actionsWithDefaultFilter,
1215
+ recordActions: blockType === "calendar" || blockType === "kanban" || blockType === "tree" ? void 0 : finalRecordActions
1216
+ });
1217
+ });
1218
+ return {
1219
+ blocks,
1220
+ blockKeysByLocalKey
1221
+ };
1222
+ }
1223
+ function compileTabComposeValues(tab, document, tabIndex, options) {
1224
+ const tabPublicPath = (0, import_private_utils.buildApplyBlueprintTabPublicPath)(tabIndex);
1225
+ const blocksPath = `${tabPublicPath}.blocks`;
1226
+ const layoutPath = `${tabPublicPath}.layout`;
1227
+ const compiledBlocks = compileBlocks(
1228
+ tab.blocks,
1229
+ tab.key,
1230
+ document.assets,
1231
+ blocksPath,
1232
+ document.defaults,
1233
+ collectReferencedBlockKeys(tab.layout, layoutPath),
1234
+ options.getCollection
1235
+ );
1236
+ const layout = compileLayout(
1237
+ tab.layout || autoLayoutFromBlockKeys(compiledBlocks.blocks.map((block) => block.key)),
1238
+ compiledBlocks.blockKeysByLocalKey,
1239
+ layoutPath
1240
+ );
1241
+ return (0, import_service_utils.buildDefinedPayload)({
1242
+ mode: options.mode,
1243
+ blocks: compiledBlocks.blocks,
1244
+ layout
1245
+ });
1246
+ }
1247
+ // Annotate the CommonJS export names for ESM import in node:
1248
+ 0 && (module.exports = {
1249
+ collectReferencedBlockKeys,
1250
+ compileTabComposeValues
1251
+ });