@nocobase/plugin-flow-engine 2.1.0-beta.23 → 2.1.0-beta.25

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 (39) hide show
  1. package/dist/ai/ai-employees/nathan/index.js +1 -0
  2. package/dist/externalVersion.js +10 -10
  3. package/dist/node_modules/ses/package.json +1 -1
  4. package/dist/node_modules/zod/package.json +1 -1
  5. package/dist/server/flow-surfaces/blueprint/compile-blocks.d.ts +2 -1
  6. package/dist/server/flow-surfaces/blueprint/compile-blocks.js +142 -22
  7. package/dist/server/flow-surfaces/blueprint/compile-plan.d.ts +2 -1
  8. package/dist/server/flow-surfaces/blueprint/compile-plan.js +8 -8
  9. package/dist/server/flow-surfaces/blueprint/normalize-document.js +5 -14
  10. package/dist/server/flow-surfaces/blueprint/private-utils.d.ts +0 -1
  11. package/dist/server/flow-surfaces/blueprint/private-utils.js +0 -3
  12. package/dist/server/flow-surfaces/blueprint/public-types.d.ts +1 -1
  13. package/dist/server/flow-surfaces/builder.d.ts +1 -0
  14. package/dist/server/flow-surfaces/builder.js +167 -53
  15. package/dist/server/flow-surfaces/catalog.js +59 -3
  16. package/dist/server/flow-surfaces/compose-compiler.d.ts +0 -1
  17. package/dist/server/flow-surfaces/compose-compiler.js +0 -1
  18. package/dist/server/flow-surfaces/configure-options.js +4 -4
  19. package/dist/server/flow-surfaces/contract-guard.js +11 -3
  20. package/dist/server/flow-surfaces/default-block-actions.js +11 -10
  21. package/dist/server/flow-surfaces/field-type-resolver.d.ts +0 -1
  22. package/dist/server/flow-surfaces/field-type-resolver.js +3 -13
  23. package/dist/server/flow-surfaces/hidden-popup-calendar.d.ts +86 -0
  24. package/dist/server/flow-surfaces/hidden-popup-calendar.js +554 -0
  25. package/dist/server/flow-surfaces/hidden-popup-contract.d.ts +116 -0
  26. package/dist/server/flow-surfaces/hidden-popup-contract.js +611 -0
  27. package/dist/server/flow-surfaces/hidden-popup-kanban.d.ts +62 -0
  28. package/dist/server/flow-surfaces/hidden-popup-kanban.js +651 -0
  29. package/dist/server/flow-surfaces/placement.js +1 -0
  30. package/dist/server/flow-surfaces/public-compatibility.d.ts +28 -0
  31. package/dist/server/flow-surfaces/public-compatibility.js +161 -0
  32. package/dist/server/flow-surfaces/service-utils.d.ts +0 -1
  33. package/dist/server/flow-surfaces/service-utils.js +0 -6
  34. package/dist/server/flow-surfaces/service.d.ts +66 -10
  35. package/dist/server/flow-surfaces/service.js +1677 -795
  36. package/dist/swagger/flow-surfaces.d.ts +0 -29
  37. package/dist/swagger/flow-surfaces.js +8 -17
  38. package/dist/swagger/index.d.ts +0 -29
  39. package/package.json +2 -2
@@ -56,7 +56,6 @@ var import_reference_guards = require("./reference-guards");
56
56
  var import_key_registry = require("./planning/key-registry");
57
57
  var import_blueprint = require("./blueprint");
58
58
  var import_compile_blocks = require("./blueprint/compile-blocks");
59
- var import_private_utils = require("./blueprint/private-utils");
60
59
  var import_default_block_actions = require("./default-block-actions");
61
60
  var import_public_data_surface_default_filter = require("./public-data-surface-default-filter");
62
61
  var import_runtime = require("./planning/runtime");
@@ -77,6 +76,7 @@ var import_route_sync = require("./route-sync");
77
76
  var import_surface_context = require("./surface-context");
78
77
  var import_context = require("./context");
79
78
  var import_configure_options = require("./configure-options");
79
+ var import_public_compatibility = require("./public-compatibility");
80
80
  var import_service_helpers = require("./service-helpers");
81
81
  var import_errors2 = require("./reaction/errors");
82
82
  var import_template_display = require("./template-display");
@@ -93,6 +93,9 @@ var import_service_utils = require("./service-utils");
93
93
  var import_field_type_resolver = require("./field-type-resolver");
94
94
  var import_template_compatibility = require("./template-compatibility");
95
95
  var import_template_service_utils = require("./template-service-utils");
96
+ var import_hidden_popup_contract = require("./hidden-popup-contract");
97
+ var import_hidden_popup_calendar = require("./hidden-popup-calendar");
98
+ var import_hidden_popup_kanban = require("./hidden-popup-kanban");
96
99
  const FORM_BLOCK_USES = /* @__PURE__ */ new Set(["FormBlockModel", "CreateFormModel", "EditFormModel", ...import_approval.APPROVAL_FORM_BLOCK_USES]);
97
100
  const AUTO_SUBMIT_FORM_BLOCK_USES = /* @__PURE__ */ new Set(["CreateFormModel", "EditFormModel"]);
98
101
  const FLOW_SURFACE_DEFAULT_ACTION_SETTINGS_KEYS = /* @__PURE__ */ new Set(["filter"]);
@@ -121,12 +124,6 @@ const DEFAULT_CALENDAR_DATE_TIME_FIELD_TYPES = [
121
124
  ];
122
125
  const CALENDAR_DEFAULT_VIEWS = /* @__PURE__ */ new Set(["month", "week", "day"]);
123
126
  const CALENDAR_WEEK_STARTS = /* @__PURE__ */ new Set([0, 1]);
124
- const CALENDAR_POPUP_ACTION_KEYS = ["quickCreateAction", "eventViewAction"];
125
- const KANBAN_POPUP_ACTION_UID_SUFFIX_BY_KEY = {
126
- quickCreateAction: "-quick-create-action",
127
- cardViewAction: "-card-view-action"
128
- };
129
- const KANBAN_POPUP_ACTION_KEYS = Object.keys(KANBAN_POPUP_ACTION_UID_SUFFIX_BY_KEY);
130
127
  const CANONICAL_BLOCK_HEADER_USES = /* @__PURE__ */ new Set([
131
128
  "TableBlockModel",
132
129
  "CalendarBlockModel",
@@ -168,6 +165,7 @@ const FILTER_TARGET_BLOCK_USES = /* @__PURE__ */ new Set([
168
165
  ]);
169
166
  const TREE_CONNECT_TARGET_BLOCK_USES = new Set(FILTER_TARGET_BLOCK_USES);
170
167
  const EDITABLE_FIELD_WRAPPER_USES = /* @__PURE__ */ new Set(["FormItemModel", "FilterFormItemModel", "PatternFormItemModel"]);
168
+ const REQUIRED_COLLECTION_FIELD_FORM_WRAPPER_USES = /* @__PURE__ */ new Set(["FormItemModel", "PatternFormItemModel"]);
171
169
  const DISPLAY_FIELD_WRAPPER_USES = /* @__PURE__ */ new Set([
172
170
  "DetailsItemModel",
173
171
  "TableColumnModel",
@@ -262,6 +260,7 @@ const APPROVAL_CONFIRM_ACTION_USES = /* @__PURE__ */ new Set([
262
260
  "ApplyFormWithdrawModel"
263
261
  ]);
264
262
  const APPROVAL_ASSIGN_ACTION_USES = /* @__PURE__ */ new Set(["ApplyFormSubmitModel", "ApplyFormSaveDraftModel"]);
263
+ const UPDATE_ASSIGN_ACTION_USES = /* @__PURE__ */ new Set(["UpdateRecordActionModel", "BulkUpdateActionModel"]);
265
264
  const APPROVAL_COMMENT_ACTION_USES = /* @__PURE__ */ new Set([
266
265
  "ProcessFormApproveModel",
267
266
  "ProcessFormRejectModel",
@@ -288,6 +287,15 @@ const POPUP_RECORD_ACTION_CONTAINER_USES = /* @__PURE__ */ new Set([
288
287
  "GridCardItemModel"
289
288
  ]);
290
289
  const POPUP_UNSUPPORTED_COLLECTION_SCENES = /* @__PURE__ */ new Set(["select", "subForm", "bulkEditForm"]);
290
+ const POPUP_ASSOCIATED_RECORDS_BLOCK_USES = /* @__PURE__ */ new Set([
291
+ "TableBlockModel",
292
+ "CalendarBlockModel",
293
+ "KanbanBlockModel",
294
+ "ListBlockModel",
295
+ "GridCardBlockModel",
296
+ "MapBlockModel",
297
+ "CommentsBlockModel"
298
+ ]);
291
299
  const POPUP_COLLECTION_BLOCK_SCENES = {
292
300
  CreateFormModel: ["new"],
293
301
  EditFormModel: ["one", "many"],
@@ -306,6 +314,15 @@ const POPUP_COLLECTION_BLOCK_SCENES = {
306
314
  FilterFormBlockModel: ["filter"],
307
315
  FormBlockModel: []
308
316
  };
317
+ const UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH = [
318
+ "stepParams",
319
+ "assignSettings",
320
+ "assignFieldValues",
321
+ "assignedValues"
322
+ ];
323
+ const UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH = ["stepParams", "apply", "apply", "assignedValues"];
324
+ const UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH = ["assignSettings", "assignFieldValues", "assignedValues"];
325
+ const UPDATE_ACTION_APPLY_STEP_PATH = ["apply", "apply", "assignedValues"];
309
326
  const TABLE_COLUMN_STEP_PARAM_MIRRORS = [
310
327
  { domain: "props", key: "title", stepParamsPath: ["tableColumnSettings", "title", "title"] },
311
328
  { domain: "props", key: "tooltip", stepParamsPath: ["tableColumnSettings", "tooltip", "tooltip"] },
@@ -372,6 +389,14 @@ const FILTER_FORM_BLOCK_LAYOUT_STEP_PARAM_MIRRORS = [
372
389
  { domain: "props", key: "labelWidth", stepParamsPath: ["formFilterBlockModelSettings", "layout", "labelWidth"] },
373
390
  { domain: "props", key: "labelWrap", stepParamsPath: ["formFilterBlockModelSettings", "layout", "labelWrap"] }
374
391
  ];
392
+ const UPDATE_SETTINGS_POPUP_STEP_PARAM_REPLACE_PATHS_BY_USE = {
393
+ CalendarBlockModel: [
394
+ ["calendarSettings", "quickCreatePopupSettings"],
395
+ ["calendarSettings", "eventPopupSettings"]
396
+ ],
397
+ KanbanBlockModel: [["kanbanSettings", "popup"]],
398
+ KanbanCardItemModel: [["cardSettings", "popup"]]
399
+ };
375
400
  const DIVIDER_ITEM_STEP_PARAM_MIRRORS = [
376
401
  { domain: "props", key: "label", stepParamsPath: ["markdownItemSetting", "title", "label"] },
377
402
  { domain: "props", key: "orientation", stepParamsPath: ["markdownItemSetting", "title", "orientation"] },
@@ -511,6 +536,17 @@ class FlowSurfacesService {
511
536
  syncApprovalRuntimeConfigForSurfaceRoot: (root, transaction) => this.approvalRuntimeConfigService.syncApprovalRuntimeConfigForSurfaceRoot(root, transaction)
512
537
  });
513
538
  }
539
+ get hiddenPopupRuntime() {
540
+ return {
541
+ repository: this.repository,
542
+ buildPopupOpenViewWithTemplate: (input) => this.buildPopupOpenViewWithTemplate(input),
543
+ clearFlowTemplateUsagesForNodeTree: (uid2, transaction) => this.clearFlowTemplateUsagesForNodeTree(uid2, transaction),
544
+ ensurePopupHostDefaultContent: (input) => this.ensurePopupHostDefaultContent(input),
545
+ reconcilePopupOpenViewTransition: (uid2, currentOpenView, nextOpenView, transaction) => this.reconcilePopupOpenViewTransition(uid2, currentOpenView, nextOpenView, transaction),
546
+ removeNodeTreeWithBindings: (uid2, transaction) => this.removeNodeTreeWithBindings(uid2, transaction),
547
+ syncFlowTemplateUsagesForNodeTree: (uid2, transaction) => this.syncFlowTemplateUsagesForNodeTree(uid2, transaction)
548
+ };
549
+ }
514
550
  async setFlowModelNodeAsyncFlag(uid2, asyncFlag, transaction) {
515
551
  var _a, _b;
516
552
  const sequelize = (_a = this.db) == null ? void 0 : _a.sequelize;
@@ -994,8 +1030,7 @@ class FlowSurfacesService {
994
1030
  fieldTypes: relationFieldTypes,
995
1031
  current: (0, import_service_utils.buildDefinedPayload)({
996
1032
  fieldType: (0, import_field_type_resolver.getPublicFieldTypeForUse)(((_g = (_f = innerField == null ? void 0 : innerField.stepParams) == null ? void 0 : _f.fieldBinding) == null ? void 0 : _g.use) || (innerField == null ? void 0 : innerField.use)),
997
- fields: this.collectRelationNestedFieldPaths(innerField),
998
- selectorFields: this.collectRelationSelectorFieldPaths(innerField),
1033
+ fields: this.collectRelationFieldPaths(innerField),
999
1034
  titleField: ((_h = innerField == null ? void 0 : innerField.props) == null ? void 0 : _h.titleField) || ((_i = node == null ? void 0 : node.props) == null ? void 0 : _i.titleField)
1000
1035
  }),
1001
1036
  defaults: (0, import_service_utils.buildDefinedPayload)({
@@ -1014,12 +1049,11 @@ class FlowSurfacesService {
1014
1049
  const defaults = {
1015
1050
  titleField: defaultTitleField
1016
1051
  };
1017
- if (["subForm", "subFormList", "subDetails", "subDetailsList", "subTable", "popupSubTable"].includes(fieldType) && defaultTitleField) {
1052
+ if (["picker", "subForm", "subFormList", "subDetails", "subDetailsList", "subTable", "popupSubTable"].includes(
1053
+ fieldType
1054
+ ) && defaultTitleField) {
1018
1055
  defaults.fields = [defaultTitleField];
1019
1056
  }
1020
- if (fieldType === "picker" && defaultTitleField) {
1021
- defaults.selectorFields = [defaultTitleField];
1022
- }
1023
1057
  return {
1024
1058
  fieldType,
1025
1059
  defaults: (0, import_service_utils.buildDefinedPayload)(defaults)
@@ -1060,6 +1094,9 @@ class FlowSurfacesService {
1060
1094
  }
1061
1095
  return void 0;
1062
1096
  }
1097
+ collectRelationFieldPaths(fieldNode) {
1098
+ return this.collectRelationNestedFieldPaths(fieldNode) || this.collectRelationSelectorFieldPaths(fieldNode);
1099
+ }
1063
1100
  collectRelationSelectorFieldPaths(fieldNode) {
1064
1101
  var _a, _b, _c, _d, _e, _f;
1065
1102
  const fieldUse = String(((_b = (_a = fieldNode == null ? void 0 : fieldNode.stepParams) == null ? void 0 : _a.fieldBinding) == null ? void 0 : _b.use) || (fieldNode == null ? void 0 : fieldNode.use) || "").trim();
@@ -1067,7 +1104,7 @@ class FlowSurfacesService {
1067
1104
  return void 0;
1068
1105
  }
1069
1106
  const table = import_lodash.default.castArray(((_e = (_d = (_c = fieldNode == null ? void 0 : fieldNode.subModels) == null ? void 0 : _c["grid-block"]) == null ? void 0 : _d.subModels) == null ? void 0 : _e.items) || []).find(
1070
- (item) => (item == null ? void 0 : item.use) === "TableBlockModel"
1107
+ (item) => (item == null ? void 0 : item.use) === "TableSelectModel" || (item == null ? void 0 : item.use) === "TableBlockModel"
1071
1108
  );
1072
1109
  return import_lodash.default.castArray(((_f = table == null ? void 0 : table.subModels) == null ? void 0 : _f.columns) || []).map((item) => {
1073
1110
  var _a2, _b2, _c2;
@@ -1110,6 +1147,9 @@ class FlowSurfacesService {
1110
1147
  isPopupCollectionBlockSceneUnsupported(scene) {
1111
1148
  return POPUP_UNSUPPORTED_COLLECTION_SCENES.has(scene);
1112
1149
  }
1150
+ supportsPopupAssociatedRecordsBinding(blockUse) {
1151
+ return POPUP_ASSOCIATED_RECORDS_BLOCK_USES.has(blockUse);
1152
+ }
1113
1153
  isPopupCollectionBlockVisibleForScene(blockUse, popupProfile) {
1114
1154
  const blockScenes = this.getPopupCollectionBlockScenes(blockUse);
1115
1155
  if (this.isPopupCollectionBlockSceneUnsupported(popupProfile.scene)) {
@@ -1282,7 +1322,7 @@ class FlowSurfacesService {
1282
1322
  collectionName: popupProfile.collectionName
1283
1323
  });
1284
1324
  }
1285
- if (popupProfile.hasCurrentRecord && associationFields.length) {
1325
+ if (this.supportsPopupAssociatedRecordsBinding(blockUse) && popupProfile.hasCurrentRecord && associationFields.length) {
1286
1326
  bindings.push({
1287
1327
  key: "associatedRecords",
1288
1328
  label: "Associated records",
@@ -1379,11 +1419,24 @@ class FlowSurfacesService {
1379
1419
  filterByTk,
1380
1420
  associationName,
1381
1421
  sourceId,
1422
+ sourceIdInferred: !(0, import_service_helpers.hasConfiguredFlowContextValue)(openView == null ? void 0 : openView.sourceId) && (0, import_service_helpers.hasConfiguredFlowContextValue)(sourceId) && this.isSameConfiguredFlowContextValue(sourceId, "{{ctx.view.inputArgs.sourceId}}"),
1382
1423
  hasCurrentRecord,
1383
1424
  hasAssociationContext,
1384
1425
  scene
1385
1426
  };
1386
1427
  }
1428
+ resolvePopupCurrentRecordResourceFilterByTk(popupProfile, options = {}) {
1429
+ if (!(popupProfile == null ? void 0 : popupProfile.currentCollection)) {
1430
+ return popupProfile == null ? void 0 : popupProfile.filterByTk;
1431
+ }
1432
+ if (popupProfile.popupKind !== "associationPopup") {
1433
+ return popupProfile.filterByTk;
1434
+ }
1435
+ if (options.usePopupInputArgsWhenSourceIdInferred && popupProfile.sourceIdInferred && popupProfile.popupHostUse && POPUP_ACTION_USES.has(popupProfile.popupHostUse)) {
1436
+ return "{{ctx.view.inputArgs.filterByTk}}";
1437
+ }
1438
+ return `{{ctx.record.${this.getCollectionFilterTargetKey(popupProfile.currentCollection)}}}`;
1439
+ }
1387
1440
  resolvePopupAssociationFields(popupProfile, blockUse) {
1388
1441
  var _a;
1389
1442
  if (!popupProfile.currentCollection || !popupProfile.hasCurrentRecord) {
@@ -1526,7 +1579,17 @@ class FlowSurfacesService {
1526
1579
  );
1527
1580
  }
1528
1581
  const resourceBindings = this.buildPopupBlockResourceBindings(input.blockUse, input.popupProfile);
1529
- const requestedBinding = ((_b = input.semanticResource) == null ? void 0 : _b.binding) || this.classifyPopupRawResourceInit(input.popupProfile, input.resourceInit || {});
1582
+ let requestedBinding = ((_b = input.semanticResource) == null ? void 0 : _b.binding) || this.classifyPopupRawResourceInit(input.popupProfile, input.resourceInit || {});
1583
+ const useLegacyAssociationPopupCurrentRecord = this.shouldUseLegacyAssociationPopupCurrentRecordBinding({
1584
+ blockUse: input.blockUse,
1585
+ popupProfile: input.popupProfile,
1586
+ requestedBinding,
1587
+ semanticResource: input.semanticResource,
1588
+ resourceInit: input.resourceInit || {}
1589
+ });
1590
+ if (useLegacyAssociationPopupCurrentRecord) {
1591
+ requestedBinding = "currentRecord";
1592
+ }
1530
1593
  if (!this.isCatalogBlockVisibleForPopupProfile(input.blockUse, input.popupProfile) && requestedBinding && !["currentCollection", "otherRecords"].includes(requestedBinding)) {
1531
1594
  (0, import_errors.throwBadRequest)(
1532
1595
  `flowSurfaces ${input.actionName} block '${blockKey}' is not available in ${this.describePopupKind(
@@ -1548,6 +1611,17 @@ class FlowSurfacesService {
1548
1611
  resource: input.semanticResource
1549
1612
  });
1550
1613
  }
1614
+ if (useLegacyAssociationPopupCurrentRecord) {
1615
+ return this.compilePopupSemanticResourceInit({
1616
+ actionName: input.actionName,
1617
+ blockUse: input.blockUse,
1618
+ popupProfile: input.popupProfile,
1619
+ resourceBindings,
1620
+ resource: {
1621
+ binding: "currentRecord"
1622
+ }
1623
+ });
1624
+ }
1551
1625
  return this.assertPopupRawResourceInit({
1552
1626
  actionName: input.actionName,
1553
1627
  blockUse: input.blockUse,
@@ -1556,6 +1630,25 @@ class FlowSurfacesService {
1556
1630
  resourceInit: input.resourceInit || {}
1557
1631
  });
1558
1632
  }
1633
+ shouldUseLegacyAssociationPopupCurrentRecordBinding(input) {
1634
+ return !input.semanticResource && input.requestedBinding === "currentCollection" && this.shouldNormalizeLegacyAssociationPopupRecordBlockResource({
1635
+ blockUse: input.blockUse,
1636
+ popupProfile: input.popupProfile,
1637
+ resourceInit: input.resourceInit
1638
+ });
1639
+ }
1640
+ shouldNormalizeLegacyAssociationPopupRecordBlockResource(input) {
1641
+ if (!["DetailsBlockModel", "EditFormModel"].includes(input.blockUse)) {
1642
+ return false;
1643
+ }
1644
+ if (input.popupProfile.popupKind !== "associationPopup" || !input.popupProfile.hasCurrentRecord || !input.popupProfile.hasAssociationContext) {
1645
+ return false;
1646
+ }
1647
+ const normalized = (0, import_service_utils.normalizeSimpleResourceInit)(input.resourceInit) || {};
1648
+ const popupDataSourceKey = input.popupProfile.dataSourceKey || "main";
1649
+ const resourceDataSourceKey = normalized.dataSourceKey || "main";
1650
+ return !!input.popupProfile.collectionName && resourceDataSourceKey === popupDataSourceKey && normalized.collectionName === input.popupProfile.collectionName && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.filterByTk) && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.associationName) && !(0, import_service_helpers.hasConfiguredFlowContextValue)(normalized.sourceId);
1651
+ }
1559
1652
  compilePopupSemanticResourceInit(input) {
1560
1653
  const binding = input.resource.binding;
1561
1654
  const supportedBinding = input.resourceBindings.find((item) => item.key === binding);
@@ -1583,7 +1676,9 @@ class FlowSurfacesService {
1583
1676
  return (0, import_service_utils.buildDefinedPayload)({
1584
1677
  dataSourceKey: input.popupProfile.dataSourceKey || "main",
1585
1678
  collectionName: input.popupProfile.collectionName,
1586
- filterByTk: input.popupProfile.filterByTk,
1679
+ filterByTk: this.resolvePopupCurrentRecordResourceFilterByTk(input.popupProfile, {
1680
+ usePopupInputArgsWhenSourceIdInferred: true
1681
+ }),
1587
1682
  ...preserveAssociationContext ? {
1588
1683
  associationName: input.popupProfile.associationName,
1589
1684
  sourceId: input.popupProfile.sourceId
@@ -2420,19 +2515,6 @@ class FlowSurfacesService {
2420
2515
  `flowSurfaces applyBlueprint navigation.group.title '${groupTitle}' matches ${matchedRoutes.length} existing menu groups; pass navigation.group.routeId explicitly`
2421
2516
  );
2422
2517
  }
2423
- const reusedMetadataFields = import_private_utils.APPLY_BLUEPRINT_CREATE_MENU_GROUP_METADATA_KEYS.filter(
2424
- (key) => {
2425
- var _a2, _b;
2426
- return !import_lodash.default.isUndefined((_b = (_a2 = document.navigation) == null ? void 0 : _a2.group) == null ? void 0 : _b[key]);
2427
- }
2428
- );
2429
- if (reusedMetadataFields.length) {
2430
- (0, import_errors.throwBadRequest)(
2431
- `flowSurfaces applyBlueprint navigation.group.title '${groupTitle}' matched an existing menu group; do not also pass ${reusedMetadataFields.map((key) => `navigation.group.${key}`).join(
2432
- ", "
2433
- )} when reusing by title. Same-title reuse is title-only. Keep only navigation.group.title or use navigation.group.routeId for exact targeting, and call flowSurfaces:updateMenu separately if existing group metadata must change`
2434
- );
2435
- }
2436
2518
  const routeId = this.readRouteField(matchedRoutes[0], "id");
2437
2519
  if (import_lodash.default.isNil(routeId) || routeId === "") {
2438
2520
  (0, import_errors.throwBadRequest)(
@@ -2460,7 +2542,8 @@ class FlowSurfacesService {
2460
2542
  );
2461
2543
  }
2462
2544
  return (0, import_blueprint.compileFlowSurfaceApplyBlueprintRequest)(document, {
2463
- replaceTarget
2545
+ replaceTarget,
2546
+ getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey || "main", collectionName || "")
2464
2547
  });
2465
2548
  }
2466
2549
  async applyBlueprint(values, options = {}) {
@@ -2827,34 +2910,41 @@ class FlowSurfacesService {
2827
2910
  })
2828
2911
  );
2829
2912
  }
2830
- async assertPopupTemplateCompatibility(actionName, hostUid, template, transaction) {
2913
+ async assertPopupTemplateCompatibility(actionName, hostUid, template, options = {}) {
2831
2914
  const normalizedHostUid = String(hostUid || "").trim();
2832
2915
  if (!normalizedHostUid) {
2833
2916
  return;
2834
2917
  }
2835
2918
  const hostNode = await this.repository.findModelById(normalizedHostUid, {
2836
- transaction,
2919
+ transaction: options.transaction,
2837
2920
  includeAsyncNode: true
2838
2921
  });
2839
2922
  if (!(hostNode == null ? void 0 : hostNode.uid)) {
2840
2923
  return;
2841
2924
  }
2842
- const popupProfile = await this.resolvePopupBlockProfile(normalizedHostUid, null, hostNode, transaction).catch(
2843
- () => null
2844
- );
2925
+ const popupProfile = await this.resolvePopupBlockProfile(
2926
+ normalizedHostUid,
2927
+ null,
2928
+ hostNode,
2929
+ options.transaction
2930
+ ).catch(() => null);
2845
2931
  if (!(popupProfile == null ? void 0 : popupProfile.isPopupSurface)) {
2846
2932
  return;
2847
2933
  }
2848
- const disabledReason = await this.getPopupTemplateDisabledReason(template, {
2849
- target: { uid: normalizedHostUid },
2850
- resolved: {
2851
- uid: normalizedHostUid,
2934
+ const disabledReason = await this.getPopupTemplateDisabledReason(
2935
+ template,
2936
+ {
2852
2937
  target: { uid: normalizedHostUid },
2853
- kind: "node"
2938
+ resolved: {
2939
+ uid: normalizedHostUid,
2940
+ target: { uid: normalizedHostUid },
2941
+ kind: "node"
2942
+ },
2943
+ node: hostNode,
2944
+ popupProfile
2854
2945
  },
2855
- node: hostNode,
2856
- popupProfile
2857
- });
2946
+ options.popupActionContext
2947
+ );
2858
2948
  if (!disabledReason) {
2859
2949
  return;
2860
2950
  }
@@ -2981,7 +3071,7 @@ class FlowSurfacesService {
2981
3071
  "FLOW_SURFACE_TEMPLATE_POPUP_SOURCE_UNSUPPORTED"
2982
3072
  );
2983
3073
  }
2984
- if (popupTemplateUid && !this.isEditableDefaultActionPopupTemplateReference(node, openView)) {
3074
+ if (this.isPopupTemplateReferenceOpenViewState(openView) && !this.isEditableDefaultActionPopupTemplateReference(node, openView)) {
2985
3075
  (0, import_errors.throwBadRequest)(
2986
3076
  `flowSurfaces ${actionName} target '${node.uid}' already uses a popup template; convert it to copy first`,
2987
3077
  "FLOW_SURFACE_TEMPLATE_SOURCE_ALREADY_TEMPLATED"
@@ -3057,6 +3147,67 @@ class FlowSurfacesService {
3057
3147
  buildPopupTemplateReferenceOpenView(template, templateTargetUid) {
3058
3148
  return this.buildPopupTemplateOpenView(template, "reference", templateTargetUid);
3059
3149
  }
3150
+ shouldHydrateDetachedPopupTemplateBlockResourceContext(blockNode, context) {
3151
+ if (!this.isCollectionBlockUse(blockNode == null ? void 0 : blockNode.use) || !context.associationName || !context.sourceId) {
3152
+ return false;
3153
+ }
3154
+ const init = import_lodash.default.get(blockNode, ["stepParams", "resourceSettings", "init"]) || {};
3155
+ const popupDataSourceKey = context.dataSourceKey || "main";
3156
+ const blockDataSourceKey = init.dataSourceKey || "main";
3157
+ if (!context.collectionName || blockDataSourceKey !== popupDataSourceKey || init.collectionName !== context.collectionName) {
3158
+ return false;
3159
+ }
3160
+ const blockAssociationName = String(init.associationName || "").trim();
3161
+ if (blockAssociationName && blockAssociationName !== context.associationName) {
3162
+ return false;
3163
+ }
3164
+ if ((0, import_service_helpers.hasConfiguredFlowContextValue)(init.sourceId) && !this.isSameConfiguredFlowContextValue(init.sourceId, context.sourceId)) {
3165
+ return false;
3166
+ }
3167
+ return blockAssociationName !== context.associationName || !this.isSameConfiguredFlowContextValue(init.sourceId, context.sourceId);
3168
+ }
3169
+ collectDetachedPopupTemplateBlockResourceContextPatches(node, context, patches = []) {
3170
+ if (!node || typeof node !== "object") {
3171
+ return patches;
3172
+ }
3173
+ if (node.uid && this.shouldHydrateDetachedPopupTemplateBlockResourceContext(node, context)) {
3174
+ const nextStepParams = import_lodash.default.cloneDeep(node.stepParams || {});
3175
+ const currentInit = import_lodash.default.get(nextStepParams, ["resourceSettings", "init"]) || {};
3176
+ import_lodash.default.set(
3177
+ nextStepParams,
3178
+ ["resourceSettings", "init"],
3179
+ (0, import_service_utils.buildDefinedPayload)({
3180
+ ...currentInit,
3181
+ dataSourceKey: context.dataSourceKey || currentInit.dataSourceKey || "main",
3182
+ collectionName: context.collectionName || currentInit.collectionName,
3183
+ associationName: context.associationName,
3184
+ sourceId: context.sourceId
3185
+ })
3186
+ );
3187
+ patches.push({
3188
+ uid: node.uid,
3189
+ stepParams: nextStepParams
3190
+ });
3191
+ }
3192
+ for (const value of Object.values(node.subModels || {})) {
3193
+ for (const child of import_lodash.default.castArray(value)) {
3194
+ this.collectDetachedPopupTemplateBlockResourceContextPatches(child, context, patches);
3195
+ }
3196
+ }
3197
+ return patches;
3198
+ }
3199
+ async hydrateDetachedPopupTemplateBlockResourceContext(detachedTarget, context, transaction) {
3200
+ const patches = this.collectDetachedPopupTemplateBlockResourceContextPatches(detachedTarget, context);
3201
+ for (const patch of patches) {
3202
+ await this.repository.patch(
3203
+ {
3204
+ uid: patch.uid,
3205
+ stepParams: patch.stepParams
3206
+ },
3207
+ { transaction }
3208
+ );
3209
+ }
3210
+ }
3060
3211
  async hydrateDetachedPopupTemplateSourceContext(templateTargetUid, inferred, transaction) {
3061
3212
  if (inferred.templateType !== "popup") {
3062
3213
  return;
@@ -3073,32 +3224,32 @@ class FlowSurfacesService {
3073
3224
  return;
3074
3225
  }
3075
3226
  const resolvedOpenViewStep = (0, import_template_service_utils.findFlowTemplateOpenViewStep)(detachedTarget) || inferred.openViewStep;
3076
- if (!resolvedOpenViewStep) {
3077
- return;
3078
- }
3079
- const nextStepParams = import_lodash.default.cloneDeep(detachedTarget.stepParams || {});
3080
- const currentGroup = import_lodash.default.isPlainObject(nextStepParams[resolvedOpenViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[resolvedOpenViewStep.flowKey]) : {};
3081
- const currentOpenView = import_lodash.default.isPlainObject(currentGroup[resolvedOpenViewStep.stepKey]) ? import_lodash.default.omit((0, import_template_service_utils.stripTemplateInternalOpenViewFields)(currentGroup[resolvedOpenViewStep.stepKey]) || {}, ["uid"]) : {};
3082
- const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
3083
- ...currentOpenView,
3084
- dataSourceKey: inferred.dataSourceKey || currentOpenView.dataSourceKey,
3085
- collectionName: inferred.collectionName || currentOpenView.collectionName,
3086
- associationName: inferred.associationName || currentOpenView.associationName,
3087
- filterByTk: inferred.filterByTk || currentOpenView.filterByTk,
3088
- sourceId: inferred.sourceId || currentOpenView.sourceId
3089
- });
3090
- if (import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
3091
- return;
3227
+ if (resolvedOpenViewStep) {
3228
+ const nextStepParams = import_lodash.default.cloneDeep(detachedTarget.stepParams || {});
3229
+ const currentGroup = import_lodash.default.isPlainObject(nextStepParams[resolvedOpenViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[resolvedOpenViewStep.flowKey]) : {};
3230
+ const currentOpenView = import_lodash.default.isPlainObject(currentGroup[resolvedOpenViewStep.stepKey]) ? import_lodash.default.omit((0, import_template_service_utils.stripTemplateInternalOpenViewFields)(currentGroup[resolvedOpenViewStep.stepKey]) || {}, ["uid"]) : {};
3231
+ const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
3232
+ ...currentOpenView,
3233
+ dataSourceKey: inferred.dataSourceKey || currentOpenView.dataSourceKey,
3234
+ collectionName: inferred.collectionName || currentOpenView.collectionName,
3235
+ associationName: inferred.associationName || currentOpenView.associationName,
3236
+ filterByTk: inferred.filterByTk || currentOpenView.filterByTk,
3237
+ sourceId: inferred.sourceId || currentOpenView.sourceId
3238
+ });
3239
+ if (!import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
3240
+ currentGroup[resolvedOpenViewStep.stepKey] = nextOpenView;
3241
+ nextStepParams[resolvedOpenViewStep.flowKey] = currentGroup;
3242
+ await this.repository.patch(
3243
+ {
3244
+ uid: detachedTarget.uid,
3245
+ stepParams: nextStepParams
3246
+ },
3247
+ { transaction }
3248
+ );
3249
+ detachedTarget.stepParams = nextStepParams;
3250
+ }
3092
3251
  }
3093
- currentGroup[resolvedOpenViewStep.stepKey] = nextOpenView;
3094
- nextStepParams[resolvedOpenViewStep.flowKey] = currentGroup;
3095
- await this.repository.patch(
3096
- {
3097
- uid: detachedTarget.uid,
3098
- stepParams: nextStepParams
3099
- },
3100
- { transaction }
3101
- );
3252
+ await this.hydrateDetachedPopupTemplateBlockResourceContext(detachedTarget, inferred, transaction);
3102
3253
  }
3103
3254
  async clearFlowTemplateUsagesByModelUids(modelUids, transaction) {
3104
3255
  const usageRepo = this.getFlowTemplateUsageRepositorySafe();
@@ -3315,7 +3466,7 @@ class FlowSurfacesService {
3315
3466
  }
3316
3467
  const nextStepParams = import_lodash.default.cloneDeep(sourceNode.stepParams || {});
3317
3468
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[openViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[openViewStep.flowKey]) : {};
3318
- currentGroup[openViewStep.stepKey] = {
3469
+ let nextOpenView = {
3319
3470
  ...import_lodash.default.omit(openViewStep.openView || {}, [
3320
3471
  "popupTemplateUid",
3321
3472
  "popupTemplateMode",
@@ -3325,6 +3476,10 @@ class FlowSurfacesService {
3325
3476
  ]),
3326
3477
  ...this.buildPopupTemplateReferenceOpenView(template, templateTargetUid)
3327
3478
  };
3479
+ if (String(sourceNode.use || "").trim() === "AddChildActionModel") {
3480
+ nextOpenView = await this.normalizeAddChildOpenViewForAction(sourceNode, nextOpenView, transaction);
3481
+ }
3482
+ currentGroup[openViewStep.stepKey] = nextOpenView;
3328
3483
  nextStepParams[openViewStep.flowKey] = currentGroup;
3329
3484
  await this.cleanupLocalPopupSurfaceForHost(sourceNode.uid, transaction, sourceNode);
3330
3485
  await this.repository.patch(
@@ -3527,7 +3682,7 @@ class FlowSurfacesService {
3527
3682
  };
3528
3683
  }
3529
3684
  const openViewStep = (0, import_template_service_utils.findFlowTemplateOpenViewStep)(node);
3530
- const popupTemplateUid = String(((_a = openViewStep == null ? void 0 : openViewStep.openView) == null ? void 0 : _a.popupTemplateUid) || "").trim();
3685
+ const popupTemplateUid = this.isPopupTemplateReferenceOpenViewState(openViewStep == null ? void 0 : openViewStep.openView) ? String(((_a = openViewStep == null ? void 0 : openViewStep.openView) == null ? void 0 : _a.popupTemplateUid) || "").trim() : "";
3531
3686
  if (popupTemplateUid) {
3532
3687
  const template = await this.getFlowTemplateOrThrow(actionName, popupTemplateUid, {
3533
3688
  transaction,
@@ -3616,6 +3771,13 @@ class FlowSurfacesService {
3616
3771
  ]),
3617
3772
  ...this.buildPopupTemplateOpenView(resolved.template, "copy", popupUid)
3618
3773
  };
3774
+ if (String(node.use || "").trim() === "AddChildActionModel") {
3775
+ currentGroup[resolved.openViewStep.stepKey] = await this.normalizeAddChildOpenViewForAction(
3776
+ node,
3777
+ currentGroup[resolved.openViewStep.stepKey],
3778
+ options.transaction
3779
+ );
3780
+ }
3619
3781
  nextStepParams[resolved.openViewStep.flowKey] = currentGroup;
3620
3782
  await this.cleanupLocalPopupSurfaceForHost(node.uid, options.transaction, node);
3621
3783
  await this.repository.patch(
@@ -3819,19 +3981,52 @@ class FlowSurfacesService {
3819
3981
  });
3820
3982
  const result = await (0, import_compose_runtime.executeComposeRuntime)(plan, {
3821
3983
  removeExistingItem: async (uid2) => this.removeNodeTreeWithBindings(uid2, options.transaction),
3822
- createBlock: async (payload) => this.addBlock(payload, {
3823
- ...options,
3824
- deferAutoLayout: true,
3825
- enabledPackages,
3826
- skipDefaultBlockActions: true
3827
- }),
3984
+ createBlock: async (payload, spec) => {
3985
+ const calendarPopupSettings = spec.type === "calendar" && spec.settings ? import_lodash.default.pick(spec.settings, [
3986
+ "quickCreatePopup",
3987
+ "eventPopup",
3988
+ "quickCreatePopupSettings",
3989
+ "eventPopupSettings"
3990
+ ]) : {};
3991
+ const kanbanPopupSettings = spec.type === "kanban" && spec.settings ? import_lodash.default.pick(spec.settings, [
3992
+ "groupField",
3993
+ "groupOptions",
3994
+ "groupTitleField",
3995
+ "groupColorField",
3996
+ "styleVariant",
3997
+ "dragEnabled",
3998
+ "dragSortBy",
3999
+ "quickCreateEnabled",
4000
+ "enableCardClick",
4001
+ "quickCreatePopup",
4002
+ "cardPopup",
4003
+ "quickCreatePopupSettings",
4004
+ "cardPopupSettings"
4005
+ ]) : {};
4006
+ const hiddenPopupSettings = {
4007
+ ...calendarPopupSettings,
4008
+ ...kanbanPopupSettings
4009
+ };
4010
+ return this.addBlock(
4011
+ {
4012
+ ...payload,
4013
+ ...Object.keys(hiddenPopupSettings).length ? { settings: hiddenPopupSettings } : {}
4014
+ },
4015
+ {
4016
+ ...options,
4017
+ deferAutoLayout: true,
4018
+ enabledPackages,
4019
+ skipDefaultBlockActions: true
4020
+ }
4021
+ );
4022
+ },
3828
4023
  applyNodeSettings: async (actionName, targetUid, settings) => {
3829
4024
  if (!targetUid) {
3830
4025
  return;
3831
4026
  }
3832
4027
  await this.applyInlineNodeSettings(actionName, targetUid, settings, options);
3833
4028
  },
3834
- resolveBlockSettings: (settings, state) => this.resolveComposeBlockSettings(settings, state.keyMap),
4029
+ resolveBlockSettings: (settings, state, block) => this.resolveComposeBlockSettings(settings, state.keyMap, block),
3835
4030
  createField: async (payload) => this.addField(payload, {
3836
4031
  ...options,
3837
4032
  popupTemplateAliasSession
@@ -3893,83 +4088,89 @@ class FlowSurfacesService {
3893
4088
  if (!import_lodash.default.isPlainObject(values.changes) || !Object.keys(values.changes).length) {
3894
4089
  (0, import_errors.throwBadRequest)("flowSurfaces configure requires a non-empty changes object");
3895
4090
  }
3896
- (0, import_service_utils.ensureNoRawSimpleChangeKeys)(values.changes);
4091
+ let changes = values.changes;
4092
+ (0, import_service_utils.ensureNoRawSimpleChangeKeys)(changes);
3897
4093
  const resolved = await this.locator.resolve(target, options);
3898
4094
  const current = await this.loadResolvedNode(resolved, options.transaction);
4095
+ changes = (0, import_public_compatibility.normalizeFlowSurfacePublicSortingAlias)({
4096
+ context: "flowSurfaces configure changes",
4097
+ use: current == null ? void 0 : current.use,
4098
+ settings: changes
4099
+ });
3899
4100
  if (resolved.kind === "page" && resolved.pageRoute) {
3900
- return this.configurePage(target, values.changes, options);
4101
+ return this.configurePage(target, changes, options);
3901
4102
  }
3902
4103
  if (resolved.kind === "tab" && resolved.tabRoute) {
3903
- return this.configureTab(target, values.changes, options);
4104
+ return this.configureTab(target, changes, options);
3904
4105
  }
3905
4106
  if ((current == null ? void 0 : current.use) === "TableBlockModel") {
3906
- return this.configureTableBlock(target, values.changes, options);
4107
+ return this.configureTableBlock(target, changes, options);
3907
4108
  }
3908
4109
  if ((current == null ? void 0 : current.use) === "CalendarBlockModel") {
3909
- return this.configureCalendarBlock(target, current, values.changes, options);
4110
+ return this.configureCalendarBlock(target, current, changes, options);
3910
4111
  }
3911
4112
  if ((current == null ? void 0 : current.use) === "TreeBlockModel") {
3912
- return this.configureTreeBlock(target, current, values.changes, options);
4113
+ return this.configureTreeBlock(target, current, changes, options);
3913
4114
  }
3914
4115
  if ((current == null ? void 0 : current.use) === "KanbanBlockModel") {
3915
- return this.configureKanbanBlock(target, current, values.changes, options);
4116
+ return this.configureKanbanBlock(target, current, changes, options);
3916
4117
  }
3917
4118
  if (SIMPLE_FORM_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3918
- return this.configureFormBlock(target, current.use, values.changes, options);
4119
+ return this.configureFormBlock(target, current.use, changes, options);
3919
4120
  }
3920
4121
  if (DETAILS_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3921
- return this.configureDetailsBlock(target, values.changes, options);
4122
+ return this.configureDetailsBlock(target, changes, options);
3922
4123
  }
3923
4124
  if ((current == null ? void 0 : current.use) === "FilterFormBlockModel") {
3924
- return this.configureFilterFormBlock(target, values.changes, options);
4125
+ return this.configureFilterFormBlock(target, changes, options);
3925
4126
  }
3926
4127
  if (LIST_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3927
- return this.configureListBlock(target, values.changes, options);
4128
+ return this.configureListBlock(target, changes, options);
3928
4129
  }
3929
4130
  if (GRID_CARD_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3930
- return this.configureGridCardBlock(target, values.changes, options);
4131
+ return this.configureGridCardBlock(target, changes, options);
3931
4132
  }
3932
4133
  if (import_node_use_sets.JS_BLOCK_USES.has((current == null ? void 0 : current.use) || "")) {
3933
- return this.configureJSBlock(target, values.changes, options);
4134
+ return this.configureJSBlock(target, changes, options);
3934
4135
  }
3935
4136
  if ((current == null ? void 0 : current.use) === "MarkdownBlockModel") {
3936
- return this.configureMarkdownBlock(target, values.changes, options);
4137
+ return this.configureMarkdownBlock(target, changes, options);
3937
4138
  }
3938
4139
  if ((current == null ? void 0 : current.use) === "IframeBlockModel") {
3939
- return this.configureIframeBlock(target, values.changes, options);
4140
+ return this.configureIframeBlock(target, changes, options);
3940
4141
  }
3941
4142
  if ((current == null ? void 0 : current.use) === "ChartBlockModel") {
3942
- return this.configureChartBlock(target, values.changes, options);
4143
+ return this.configureChartBlock(target, changes, options);
3943
4144
  }
3944
4145
  if ((current == null ? void 0 : current.use) === "ActionPanelBlockModel") {
3945
- return this.configureActionPanelBlock(target, values.changes, options);
4146
+ return this.configureActionPanelBlock(target, changes, options);
3946
4147
  }
3947
4148
  if ((current == null ? void 0 : current.use) === "MapBlockModel") {
3948
- return this.configureMapBlock(target, values.changes, options);
4149
+ return this.configureMapBlock(target, changes, options);
3949
4150
  }
3950
4151
  if ((current == null ? void 0 : current.use) === "CommentsBlockModel") {
3951
- return this.configureCommentsBlock(target, values.changes, options);
4152
+ return this.configureCommentsBlock(target, changes, options);
3952
4153
  }
3953
4154
  if ((current == null ? void 0 : current.use) === "TableActionsColumnModel") {
3954
- return this.configureActionColumn(target, values.changes, options);
4155
+ return this.configureActionColumn(target, changes, options);
3955
4156
  }
3956
4157
  if (import_node_use_sets.FIELD_WRAPPER_USES.has((current == null ? void 0 : current.use) || "")) {
3957
- return this.configureFieldWrapper(target, current, values.changes, options);
4158
+ return this.configureFieldWrapper(target, current, changes, options);
3958
4159
  }
3959
4160
  if (import_node_use_sets.STANDALONE_FIELD_NODE_USES.has((current == null ? void 0 : current.use) || "")) {
3960
4161
  if ((current == null ? void 0 : current.use) === "JSColumnModel") {
3961
- return this.configureJSColumn(target, values.changes, options);
4162
+ return this.configureJSColumn(target, changes, options);
3962
4163
  }
3963
4164
  if ((current == null ? void 0 : current.use) === "DividerItemModel") {
3964
- return this.configureDividerItem(target, values.changes, options);
4165
+ return this.configureDividerItem(target, changes, options);
3965
4166
  }
3966
- return this.configureJSItem(target, values.changes, options);
4167
+ return this.configureJSItem(target, changes, options);
3967
4168
  }
3968
4169
  if ((0, import_service_utils.isFieldNodeUse)(current == null ? void 0 : current.use)) {
3969
- return this.configureFieldNode(target, values.changes, options);
4170
+ return this.configureFieldNode(target, changes, options);
3970
4171
  }
3971
4172
  if (import_node_use_sets.ACTION_BUTTON_USES.has((current == null ? void 0 : current.use) || "")) {
3972
- return this.configureActionNode(target, current.use, values.changes, {
4173
+ return this.configureActionNode(target, current.use, changes, {
3973
4174
  ...options,
3974
4175
  current
3975
4176
  });
@@ -4908,7 +5109,7 @@ class FlowSurfacesService {
4908
5109
  };
4909
5110
  }
4910
5111
  async addBlock(values, options = {}) {
4911
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5112
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4912
5113
  const templateRef = import_lodash.default.isUndefined(values == null ? void 0 : values.template) ? void 0 : this.normalizeFlowTemplateReference("addBlock", values.template, {
4913
5114
  allowUsage: true,
4914
5115
  expectedType: "block"
@@ -4940,12 +5141,16 @@ class FlowSurfacesService {
4940
5141
  const enabledPackages = await this.resolveEnabledPluginPackages(options);
4941
5142
  const hasInlineFields = Object.prototype.hasOwnProperty.call(values || {}, "fields") || Object.prototype.hasOwnProperty.call(values || {}, "fieldsLayout");
4942
5143
  let resolvedTarget = await this.locator.resolve(target, options);
4943
- let targetNode = await this.loadResolvedNode(resolvedTarget, options.transaction);
5144
+ let targetNode = await this.loadResolvedNode(resolvedTarget, options.transaction, {
5145
+ ensureManagedPopupTemplateTargets: true
5146
+ });
4944
5147
  const targetOpenView = this.resolvePopupHostOpenView(targetNode);
4945
5148
  if (this.isPopupFieldHostUse(targetNode == null ? void 0 : targetNode.use) && !targetOpenView) {
4946
5149
  await this.ensureLocalFieldPopupSurface("addBlock", target.uid, options, { popup: {} });
4947
5150
  resolvedTarget = await this.locator.resolve(target, options);
4948
- targetNode = await this.loadResolvedNode(resolvedTarget, options.transaction);
5151
+ targetNode = await this.loadResolvedNode(resolvedTarget, options.transaction, {
5152
+ ensureManagedPopupTemplateTargets: true
5153
+ });
4949
5154
  }
4950
5155
  const popupProfile = await this.resolvePopupBlockProfile(
4951
5156
  target.uid,
@@ -5003,11 +5208,13 @@ class FlowSurfacesService {
5003
5208
  const blockProps = catalogItem.use === "CalendarBlockModel" ? this.buildCalendarInitialBlockProps({
5004
5209
  actionName: "addBlock",
5005
5210
  resourceInit: effectiveResourceInit,
5006
- props: values.props
5211
+ props: values.props,
5212
+ settings: inlineSettings
5007
5213
  }) : catalogItem.use === "KanbanBlockModel" ? this.buildKanbanInitialBlockProps({
5008
5214
  actionName: "addBlock",
5009
5215
  resourceInit: effectiveResourceInit,
5010
- props: values.props
5216
+ props: values.props,
5217
+ settings: inlineSettings
5011
5218
  }) : values.props;
5012
5219
  const initialGrid = options.deferAutoLayout ? null : await this.repository.findModelById(parentUid, {
5013
5220
  transaction: options.transaction,
@@ -5017,10 +5224,42 @@ class FlowSurfacesService {
5017
5224
  use: catalogItem.use,
5018
5225
  containerUse: parentNode == null ? void 0 : parentNode.use,
5019
5226
  resourceInit: effectiveResourceInit,
5227
+ enableDefaultSorting: this.shouldEnableCreatedAtDefaultSorting(effectiveResourceInit),
5020
5228
  props: blockProps,
5021
5229
  decoratorProps: values.decoratorProps,
5022
- stepParams: values.stepParams
5023
- });
5230
+ stepParams: catalogItem.use === "CalendarBlockModel" ? this.buildCalendarInitialStepParams({
5231
+ stepParams: values.stepParams,
5232
+ props: values.props,
5233
+ settings: inlineSettings
5234
+ }) : catalogItem.use === "KanbanBlockModel" ? this.buildKanbanInitialStepParams({
5235
+ stepParams: values.stepParams,
5236
+ props: values.props,
5237
+ settings: inlineSettings
5238
+ }) : values.stepParams
5239
+ });
5240
+ if (catalogItem.use === "KanbanBlockModel") {
5241
+ const itemNode2 = (0, import_service_utils.getSingleNodeSubModel)((_a = tree.subModels) == null ? void 0 : _a.item);
5242
+ if (itemNode2) {
5243
+ const itemProps = this.buildKanbanInitialItemProps({
5244
+ props: values.props,
5245
+ settings: inlineSettings
5246
+ });
5247
+ const itemStepParams = this.buildKanbanInitialItemStepParams({
5248
+ stepParams: itemNode2.stepParams,
5249
+ props: values.props,
5250
+ settings: inlineSettings
5251
+ });
5252
+ if (Object.keys(itemProps).length) {
5253
+ itemNode2.props = {
5254
+ ...itemNode2.props || {},
5255
+ ...itemProps
5256
+ };
5257
+ }
5258
+ if (Object.keys(itemStepParams).length) {
5259
+ itemNode2.stepParams = itemStepParams;
5260
+ }
5261
+ }
5262
+ }
5024
5263
  this.contractGuard.validateNodeTreeAgainstContract(tree);
5025
5264
  const created = await this.repository.upsertModel(
5026
5265
  {
@@ -5031,13 +5270,13 @@ class FlowSurfacesService {
5031
5270
  },
5032
5271
  { transaction: options.transaction }
5033
5272
  );
5034
- const gridNode = (0, import_service_utils.getSingleNodeSubModel)((_a = tree.subModels) == null ? void 0 : _a.grid);
5035
- const itemNode = (0, import_service_utils.getSingleNodeSubModel)((_b = tree.subModels) == null ? void 0 : _b.item);
5036
- const itemGridNode = (0, import_service_utils.getSingleNodeSubModel)((_c = itemNode == null ? void 0 : itemNode.subModels) == null ? void 0 : _c.grid);
5037
- const columnNodes = (0, import_service_utils.getNodeSubModelList)((_d = tree.subModels) == null ? void 0 : _d.columns);
5273
+ const gridNode = (0, import_service_utils.getSingleNodeSubModel)((_b = tree.subModels) == null ? void 0 : _b.grid);
5274
+ const itemNode = (0, import_service_utils.getSingleNodeSubModel)((_c = tree.subModels) == null ? void 0 : _c.item);
5275
+ const itemGridNode = (0, import_service_utils.getSingleNodeSubModel)((_d = itemNode == null ? void 0 : itemNode.subModels) == null ? void 0 : _d.grid);
5276
+ const columnNodes = (0, import_service_utils.getNodeSubModelList)((_e = tree.subModels) == null ? void 0 : _e.columns);
5038
5277
  const blockGridUid = (gridNode == null ? void 0 : gridNode.uid) || (itemGridNode == null ? void 0 : itemGridNode.uid);
5039
5278
  const popupGridUid = popupSurface == null ? void 0 : popupSurface.gridUid;
5040
- const actionsColumnUid = catalogItem.use === "TableBlockModel" ? await this.ensureTableActionsColumn(created, options.transaction) : (_e = columnNodes.find((item) => item.use === "TableActionsColumnModel")) == null ? void 0 : _e.uid;
5279
+ const actionsColumnUid = catalogItem.use === "TableBlockModel" ? await this.ensureTableActionsColumn(created, options.transaction) : (_f = columnNodes.find((item) => item.use === "TableActionsColumnModel")) == null ? void 0 : _f.uid;
5041
5280
  const result = {
5042
5281
  uid: created,
5043
5282
  parentUid,
@@ -5055,8 +5294,52 @@ class FlowSurfacesService {
5055
5294
  popupGridUid: popupSurface.gridUid
5056
5295
  } : {}
5057
5296
  };
5058
- await this.applyInlineNodeSettings("addBlock", created, inlineSettings, options);
5059
- if ((_f = inlineFields == null ? void 0 : inlineFields.fields) == null ? void 0 : _f.length) {
5297
+ const ensureInitialBlockPopupHosts = async () => {
5298
+ if (catalogItem.use === "CalendarBlockModel") {
5299
+ const calendarNode = await this.repository.findModelById(created, {
5300
+ transaction: options.transaction,
5301
+ includeAsyncNode: true
5302
+ });
5303
+ if (calendarNode == null ? void 0 : calendarNode.uid) {
5304
+ await this.ensureCalendarBlockPopupHosts(calendarNode, options.transaction, {
5305
+ quickCreateAction: this.resolveCalendarInitialPopupOverride(
5306
+ inlineSettings,
5307
+ "quickCreatePopup",
5308
+ "quickCreatePopupSettings"
5309
+ ),
5310
+ eventViewAction: this.resolveCalendarInitialPopupOverride(
5311
+ inlineSettings,
5312
+ "eventPopup",
5313
+ "eventPopupSettings"
5314
+ )
5315
+ });
5316
+ }
5317
+ }
5318
+ if (catalogItem.use === "KanbanBlockModel") {
5319
+ const kanbanNode = await this.repository.findModelById(created, {
5320
+ transaction: options.transaction,
5321
+ includeAsyncNode: true
5322
+ });
5323
+ if (kanbanNode == null ? void 0 : kanbanNode.uid) {
5324
+ await this.ensureKanbanBlockPopupHosts(kanbanNode, options.transaction, {
5325
+ quickCreateAction: this.resolveKanbanInitialPopupOverride(
5326
+ inlineSettings,
5327
+ "quickCreatePopup",
5328
+ "quickCreatePopupSettings"
5329
+ ),
5330
+ cardViewAction: this.resolveKanbanInitialPopupOverride(inlineSettings, "cardPopup", "cardPopupSettings")
5331
+ });
5332
+ }
5333
+ }
5334
+ };
5335
+ await ensureInitialBlockPopupHosts();
5336
+ const inlineSettingsForConfigure = catalogItem.use === "CalendarBlockModel" ? this.omitHiddenPopupSettingsForConfigure(
5337
+ this.normalizeCalendarInlineSettingsForConfigure(inlineSettings),
5338
+ "calendar"
5339
+ ) : catalogItem.use === "KanbanBlockModel" ? this.omitHiddenPopupSettingsForConfigure(inlineSettings, "kanban") : inlineSettings;
5340
+ await this.applyInlineNodeSettings("addBlock", created, inlineSettingsForConfigure, options);
5341
+ await ensureInitialBlockPopupHosts();
5342
+ if ((_g = inlineFields == null ? void 0 : inlineFields.fields) == null ? void 0 : _g.length) {
5060
5343
  const fieldTargetUid = this.resolveComposeFieldContainerUid(inlineFields, result);
5061
5344
  const createdByKey = {};
5062
5345
  for (const fieldSpec of inlineFields.fields) {
@@ -5072,7 +5355,6 @@ class FlowSurfacesService {
5072
5355
  ...fieldSpec.type ? { type: fieldSpec.type } : {},
5073
5356
  ...fieldSpec.fieldType ? { fieldType: fieldSpec.fieldType } : {},
5074
5357
  ...!import_lodash.default.isUndefined(fieldSpec.fields) ? { fields: fieldSpec.fields } : {},
5075
- ...!import_lodash.default.isUndefined(fieldSpec.selectorFields) ? { selectorFields: fieldSpec.selectorFields } : {},
5076
5358
  ...fieldSpec.titleField ? { titleField: fieldSpec.titleField } : {},
5077
5359
  ...fieldSpec.openMode ? { openMode: fieldSpec.openMode } : {},
5078
5360
  ...fieldSpec.popupSize ? { popupSize: fieldSpec.popupSize } : {},
@@ -5105,7 +5387,7 @@ class FlowSurfacesService {
5105
5387
  includeAsyncNode: true
5106
5388
  });
5107
5389
  const layoutItems = import_lodash.default.castArray(
5108
- ((_i = (_h = (_g = layoutHost == null ? void 0 : layoutHost.subModels) == null ? void 0 : _g.grid) == null ? void 0 : _h.subModels) == null ? void 0 : _i.items) || ((_j = layoutHost == null ? void 0 : layoutHost.subModels) == null ? void 0 : _j.items) || []
5390
+ ((_j = (_i = (_h = layoutHost == null ? void 0 : layoutHost.subModels) == null ? void 0 : _h.grid) == null ? void 0 : _i.subModels) == null ? void 0 : _j.items) || ((_k = layoutHost == null ? void 0 : layoutHost.subModels) == null ? void 0 : _k.items) || []
5109
5391
  );
5110
5392
  const layoutPayload = this.buildComposeLayoutPayload({
5111
5393
  layout: inlineFields.fieldsLayout,
@@ -5297,6 +5579,7 @@ class FlowSurfacesService {
5297
5579
  collectionName: resolvedField.collectionName,
5298
5580
  fieldPath: resolvedField.fieldPath,
5299
5581
  associationPathName: resolvedField.associationPathName,
5582
+ ...(0, import_service_utils.hasOwnDefined)(values, "titleField") ? { explicitTitleField: values.titleField } : {},
5300
5583
  bindingChange: true,
5301
5584
  hasExistingTitleField: false,
5302
5585
  enabledPackages
@@ -5314,7 +5597,6 @@ class FlowSurfacesService {
5314
5597
  dataSourceKey: resolvedField.dataSourceKey,
5315
5598
  getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey, collectionName),
5316
5599
  fields: values.fields,
5317
- selectorFields: values.selectorFields,
5318
5600
  titleField: values.titleField,
5319
5601
  openMode: values.openMode,
5320
5602
  popupSize: values.popupSize,
@@ -5421,6 +5703,10 @@ class FlowSurfacesService {
5421
5703
  boundFieldCapability.fieldUse,
5422
5704
  values.fieldProps || {}
5423
5705
  );
5706
+ const requiredFieldWrapperDefaults = this.buildRequiredCollectionFieldFormWrapperDefaults({
5707
+ wrapperUse: boundFieldCapability.wrapperUse,
5708
+ field: resolvedField.field
5709
+ });
5424
5710
  const tree = (0, import_builder.buildFieldTree)({
5425
5711
  wrapperUse: boundFieldCapability.wrapperUse,
5426
5712
  fieldUse: boundFieldCapability.fieldUse,
@@ -5433,6 +5719,7 @@ class FlowSurfacesService {
5433
5719
  {},
5434
5720
  defaultFieldState.wrapperProps || {},
5435
5721
  wrapperShouldPersistTitleField ? { titleField: defaultTitleField } : {},
5722
+ requiredFieldWrapperDefaults.props,
5436
5723
  values.wrapperProps || {}
5437
5724
  ),
5438
5725
  fieldProps: import_lodash.default.merge(
@@ -5443,6 +5730,18 @@ class FlowSurfacesService {
5443
5730
  )
5444
5731
  });
5445
5732
  this.contractGuard.validateNodeTreeAgainstContract(tree.model);
5733
+ if (wrapperShouldPersistTitleField && boundFieldCapability.wrapperUse === "TableColumnModel") {
5734
+ tree.model.stepParams = import_lodash.default.merge({}, tree.model.stepParams || {}, {
5735
+ tableColumnSettings: {
5736
+ fieldNames: {
5737
+ label: defaultTitleField
5738
+ }
5739
+ }
5740
+ });
5741
+ }
5742
+ if (requiredFieldWrapperDefaults.stepParams) {
5743
+ tree.model.stepParams = import_lodash.default.merge({}, tree.model.stepParams || {}, requiredFieldWrapperDefaults.stepParams);
5744
+ }
5446
5745
  await this.repository.upsertModel(
5447
5746
  {
5448
5747
  parentId: container.parentUid,
@@ -5632,10 +5931,11 @@ class FlowSurfacesService {
5632
5931
  });
5633
5932
  const materializedContainer = await this.materializeRecordActionContainer(container, options.transaction);
5634
5933
  const resourceContext = container.ownerUid ? await this.locator.resolveCollectionContext(container.ownerUid, options.transaction).catch(() => null) : null;
5934
+ const resourceInit = this.isAddChildCatalogItem(actionCatalogItem) ? await this.resolveAddChildResourceInitForOwnerNode(container.ownerNode, options.transaction) : values.resourceInit || (resourceContext == null ? void 0 : resourceContext.resourceInit);
5635
5935
  const action = (0, import_builder.buildActionTree)({
5636
5936
  use: actionCatalogItem.use,
5637
5937
  containerUse: container.containerUse,
5638
- resourceInit: values.resourceInit || (resourceContext == null ? void 0 : resourceContext.resourceInit),
5938
+ resourceInit,
5639
5939
  props: values.props,
5640
5940
  decoratorProps: values.decoratorProps,
5641
5941
  stepParams: values.stepParams,
@@ -5927,7 +6227,8 @@ class FlowSurfacesService {
5927
6227
  const availableAliases = new Set(popupTemplateAliasSession ? popupTemplateAliasSession.keys() : []);
5928
6228
  document.tabs.forEach((tab, tabIndex) => {
5929
6229
  const composeValues = (0, import_compile_blocks.compileTabComposeValues)(tab, document, tabIndex, {
5930
- mode: document.mode === "replace" ? "replace" : "append"
6230
+ mode: document.mode === "replace" ? "replace" : "append",
6231
+ getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey || "main", collectionName || "")
5931
6232
  });
5932
6233
  this.validatePopupTemplateAliasesInBlocks(
5933
6234
  import_lodash.default.castArray(composeValues.blocks || []),
@@ -5945,6 +6246,21 @@ class FlowSurfacesService {
5945
6246
  }
5946
6247
  return settings;
5947
6248
  }
6249
+ shouldEnableCreatedAtDefaultSorting(resourceInit) {
6250
+ const collectionName = String((resourceInit == null ? void 0 : resourceInit.collectionName) || "").trim();
6251
+ if (!collectionName) {
6252
+ return false;
6253
+ }
6254
+ const dataSourceKey = String((resourceInit == null ? void 0 : resourceInit.dataSourceKey) || "main").trim() || "main";
6255
+ const collection = this.getCollection(dataSourceKey, collectionName);
6256
+ return !!(0, import_service_helpers.resolveFieldFromCollection)(collection, "createdAt");
6257
+ }
6258
+ normalizeBlockSortingInput(value, context) {
6259
+ return (0, import_public_compatibility.normalizeFlowSurfaceDefaultSorting)(value, context);
6260
+ }
6261
+ normalizeMapSortingInput(value, context) {
6262
+ return (0, import_public_compatibility.normalizeFlowSurfaceEmptySortingAsDefault)(value, context);
6263
+ }
5948
6264
  normalizeInlinePopup(actionName, popup) {
5949
6265
  if (import_lodash.default.isUndefined(popup)) {
5950
6266
  return void 0;
@@ -6103,8 +6419,33 @@ class FlowSurfacesService {
6103
6419
  shouldAutoSaveDefaultActionPopupTemplate(popup) {
6104
6420
  return (popup == null ? void 0 : popup[import_default_block_actions.FLOW_SURFACE_INTERNAL_AUTO_SAVE_DEFAULT_POPUP_TEMPLATE_KEY]) === true;
6105
6421
  }
6422
+ resolveDefaultActionPopupSemanticUse(use) {
6423
+ const normalizedUse = String(use || "").trim();
6424
+ if (normalizedUse === "AddChildActionModel") {
6425
+ return "AddNewActionModel";
6426
+ }
6427
+ if (normalizedUse === "CalendarQuickCreateActionModel") {
6428
+ return "AddNewActionModel";
6429
+ }
6430
+ if (normalizedUse === "CalendarEventViewActionModel") {
6431
+ return "ViewActionModel";
6432
+ }
6433
+ if (normalizedUse === "KanbanQuickCreateActionModel") {
6434
+ return "AddNewActionModel";
6435
+ }
6436
+ if (normalizedUse === "KanbanCardViewActionModel") {
6437
+ return "ViewActionModel";
6438
+ }
6439
+ return normalizedUse || void 0;
6440
+ }
6441
+ getDefaultActionPopupConfigForNode(actionNode) {
6442
+ return (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use));
6443
+ }
6444
+ isDefaultActionPopupUseForNode(actionNode) {
6445
+ return !!this.getDefaultActionPopupConfigForNode(actionNode);
6446
+ }
6106
6447
  shouldImplicitlyTemplateDefaultActionPopup(actionNode, popup) {
6107
- if (!(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupUse)(actionNode == null ? void 0 : actionNode.use)) {
6448
+ if (!this.isDefaultActionPopupUseForNode(actionNode)) {
6108
6449
  return false;
6109
6450
  }
6110
6451
  if (import_lodash.default.isPlainObject(popup == null ? void 0 : popup.template) || !import_lodash.default.isUndefined(popup == null ? void 0 : popup.saveAsTemplate)) {
@@ -6136,7 +6477,7 @@ class FlowSurfacesService {
6136
6477
  transaction,
6137
6478
  includeAsyncNode: true
6138
6479
  });
6139
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(actionNode == null ? void 0 : actionNode.use);
6480
+ const actionConfig = this.getDefaultActionPopupConfigForNode(actionNode);
6140
6481
  const popupProfile = (actionNode == null ? void 0 : actionNode.uid) ? await this.resolvePopupBlockProfile(actionNode.uid, null, actionNode, transaction).catch(() => null) : null;
6141
6482
  const popupType = actionConfig == null ? void 0 : actionConfig.type;
6142
6483
  const collectionLabel = String(
@@ -6185,10 +6526,13 @@ class FlowSurfacesService {
6185
6526
  if (explicitTitle) {
6186
6527
  return explicitTitle;
6187
6528
  }
6188
- if (!(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupUse)(actionNode == null ? void 0 : actionNode.use)) {
6529
+ if (!this.isDefaultActionPopupUseForNode(actionNode)) {
6189
6530
  return void 0;
6190
6531
  }
6191
- return (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(actionNode == null ? void 0 : actionNode.use, this.getActionButtonTitle(actionNode));
6532
+ return (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(
6533
+ this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use),
6534
+ this.getActionButtonTitle(actionNode)
6535
+ );
6192
6536
  }
6193
6537
  buildInlinePopupTemplateOpenView(popup, fallbackTitle) {
6194
6538
  const normalizedTitle = this.normalizeOptionalPopupTitle(popup == null ? void 0 : popup.title) || this.normalizeOptionalPopupTitle(fallbackTitle);
@@ -6291,13 +6635,16 @@ class FlowSurfacesService {
6291
6635
  return ["-updatedAt", "-createdAt", "uid"];
6292
6636
  }
6293
6637
  getPopupTryTemplateExpectedAssociationName(targetContext) {
6294
- var _a, _b, _c;
6295
- if ((_a = targetContext == null ? void 0 : targetContext.popupProfile) == null ? void 0 : _a.isPopupSurface) {
6638
+ var _a, _b, _c, _d, _e;
6639
+ if (String(((_a = targetContext == null ? void 0 : targetContext.node) == null ? void 0 : _a.use) || "").trim() === "AddChildActionModel") {
6640
+ return String(((_b = this.resolvePopupHostOpenView(targetContext.node)) == null ? void 0 : _b.associationName) || "").trim() || void 0;
6641
+ }
6642
+ if ((_c = targetContext == null ? void 0 : targetContext.popupProfile) == null ? void 0 : _c.isPopupSurface) {
6296
6643
  return String(targetContext.popupProfile.associationName || "").trim() || void 0;
6297
6644
  }
6298
- return String(((_c = (_b = targetContext == null ? void 0 : targetContext.resourceContext) == null ? void 0 : _b.resourceInit) == null ? void 0 : _c.associationName) || "").trim() || void 0;
6645
+ return String(((_e = (_d = targetContext == null ? void 0 : targetContext.resourceContext) == null ? void 0 : _d.resourceInit) == null ? void 0 : _e.associationName) || "").trim() || void 0;
6299
6646
  }
6300
- getPopupTryTemplatePriority(template, expectedAssociationName) {
6647
+ getPopupTryTemplatePriority(template, expectedAssociationName, options = {}) {
6301
6648
  const templateAssociationName = String(template.associationName || "").trim() || void 0;
6302
6649
  if (!expectedAssociationName) {
6303
6650
  return templateAssociationName ? null : 0;
@@ -6305,11 +6652,18 @@ class FlowSurfacesService {
6305
6652
  if (templateAssociationName === expectedAssociationName) {
6306
6653
  return 0;
6307
6654
  }
6655
+ if (options.requireExactAssociationName) {
6656
+ return null;
6657
+ }
6308
6658
  if (!templateAssociationName) {
6309
6659
  return 1;
6310
6660
  }
6311
6661
  return null;
6312
6662
  }
6663
+ shouldRequireExactPopupTryTemplateAssociation(targetContext) {
6664
+ var _a;
6665
+ return String(((_a = targetContext == null ? void 0 : targetContext.node) == null ? void 0 : _a.use) || "").trim() === "AddChildActionModel" && !!this.getPopupTryTemplateExpectedAssociationName(targetContext);
6666
+ }
6313
6667
  getRequestedPopupDefaultType(popup) {
6314
6668
  const normalized = String((popup == null ? void 0 : popup.defaultType) || "").trim();
6315
6669
  if (normalized === "view" || normalized === "edit") {
@@ -6330,7 +6684,21 @@ class FlowSurfacesService {
6330
6684
  if (this.isPopupFieldHostUse(targetUse)) {
6331
6685
  return ["view", "generic"];
6332
6686
  }
6333
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(targetUse);
6687
+ if (targetUse === "CalendarQuickCreateActionModel") {
6688
+ return ["addNew"];
6689
+ }
6690
+ if (targetUse === "CalendarEventViewActionModel") {
6691
+ return ["view", "generic"];
6692
+ }
6693
+ if (targetUse === "KanbanQuickCreateActionModel") {
6694
+ return ["addNew"];
6695
+ }
6696
+ if (targetUse === "KanbanCardViewActionModel") {
6697
+ return ["view", "generic"];
6698
+ }
6699
+ const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(
6700
+ this.resolveDefaultActionPopupSemanticUse(targetUse)
6701
+ );
6334
6702
  if (actionConfig) {
6335
6703
  return actionConfig.type === "view" ? ["view", "generic"] : [actionConfig.type];
6336
6704
  }
@@ -6402,9 +6770,12 @@ class FlowSurfacesService {
6402
6770
  targetContext,
6403
6771
  options.popupActionContext
6404
6772
  );
6773
+ const requireExactAssociationName = this.shouldRequireExactPopupTryTemplateAssociation(targetContext);
6405
6774
  for (const priority of [0, 1]) {
6406
6775
  for (const template of annotatedTemplates) {
6407
- if (template.available !== true || this.getPopupTryTemplatePriority(template, expectedAssociationName) !== priority) {
6776
+ if (template.available !== true || this.getPopupTryTemplatePriority(template, expectedAssociationName, {
6777
+ requireExactAssociationName
6778
+ }) !== priority) {
6408
6779
  continue;
6409
6780
  }
6410
6781
  if (await this.popupTemplateMatchesDefaultType(template, popup, {
@@ -6474,7 +6845,8 @@ class FlowSurfacesService {
6474
6845
  ...popupTemplateHasSourceId && template.sourceId ? { sourceId: template.sourceId } : {},
6475
6846
  popupTemplateHasFilterByTk,
6476
6847
  popupTemplateHasSourceId,
6477
- popupTemplateMode: mode
6848
+ popupTemplateMode: mode,
6849
+ popupTemplateUid: template.uid
6478
6850
  });
6479
6851
  if (mode === "copy") {
6480
6852
  return {
@@ -6482,16 +6854,21 @@ class FlowSurfacesService {
6482
6854
  popupTemplateContext: true
6483
6855
  };
6484
6856
  }
6485
- return {
6486
- ...base,
6487
- popupTemplateUid: template.uid
6488
- };
6857
+ return base;
6489
6858
  }
6490
6859
  isReferencedPopupTemplateOpenView(openView, hostUid) {
6491
- return !!this.resolveExternalPopupHostUid(hostUid, openView) && !!String((openView == null ? void 0 : openView.popupTemplateUid) || "").trim() && !(openView == null ? void 0 : openView.popupTemplateContext);
6860
+ return !!this.resolveExternalPopupHostUid(hostUid, openView) && this.isPopupTemplateReferenceOpenViewState(openView);
6861
+ }
6862
+ isPopupTemplateReferenceOpenViewState(openView) {
6863
+ const popupTemplateUid = String((openView == null ? void 0 : openView.popupTemplateUid) || "").trim();
6864
+ if (!popupTemplateUid || (openView == null ? void 0 : openView.popupTemplateContext)) {
6865
+ return false;
6866
+ }
6867
+ const popupTemplateMode = String((openView == null ? void 0 : openView.popupTemplateMode) || "reference").trim() || "reference";
6868
+ return popupTemplateMode !== "copy";
6492
6869
  }
6493
6870
  isEditableDefaultActionPopupTemplateReference(hostNode, openView) {
6494
- return (0, import_default_action_popup.isFlowSurfaceDefaultActionPopupUse)(hostNode == null ? void 0 : hostNode.use) && this.isReferencedPopupTemplateOpenView(openView, hostNode == null ? void 0 : hostNode.uid);
6871
+ return this.isDefaultActionPopupUseForNode(hostNode) && this.isReferencedPopupTemplateOpenView(openView, hostNode == null ? void 0 : hostNode.uid);
6495
6872
  }
6496
6873
  resolveExternalPopupHostUid(hostUid, openView) {
6497
6874
  const normalizedHostUid = String(hostUid || "").trim();
@@ -6573,12 +6950,10 @@ class FlowSurfacesService {
6573
6950
  transaction: options.transaction,
6574
6951
  expectedType: "popup"
6575
6952
  });
6576
- await this.assertPopupTemplateCompatibility(
6577
- actionName,
6578
- options.popupTemplateHostUid,
6579
- template,
6580
- options.transaction
6581
- );
6953
+ await this.assertPopupTemplateCompatibility(actionName, options.popupTemplateHostUid, template, {
6954
+ transaction: options.transaction,
6955
+ popupActionContext: options.popupActionContext
6956
+ });
6582
6957
  const resolvedUid = templateRef.mode === "copy" ? String(
6583
6958
  ((_a = await this.duplicateDetachedFlowModelTree(actionName, template.targetUid, options.transaction)) == null ? void 0 : _a.uid) || ""
6584
6959
  ) : template.targetUid;
@@ -6591,12 +6966,15 @@ class FlowSurfacesService {
6591
6966
  if (templateRef.mode === "copy") {
6592
6967
  await this.ensurePopupSurface(resolvedUid, options.transaction);
6593
6968
  }
6594
- const nextTemplateOpenView = this.buildPopupTemplateOpenView(template, templateRef.mode, resolvedUid);
6969
+ let nextTemplateOpenView = this.buildPopupTemplateOpenView(template, templateRef.mode, resolvedUid);
6595
6970
  Object.keys(normalizedOpenView).forEach((key) => {
6596
6971
  if (key === "template" || key === "popupTemplateUid" || key === "popupTemplateMode" || key === "popupTemplateContext" || key === "popupTemplateHasFilterByTk" || key === "popupTemplateHasSourceId") {
6597
6972
  delete normalizedOpenView[key];
6598
6973
  }
6599
6974
  });
6975
+ if (String(options.popupTemplateHostUse || "").trim() === "AddChildActionModel") {
6976
+ nextTemplateOpenView = import_lodash.default.omit(nextTemplateOpenView, ["sourceId"]);
6977
+ }
6600
6978
  Object.assign(normalizedOpenView, nextTemplateOpenView);
6601
6979
  }
6602
6980
  if (!import_lodash.default.isUndefined(normalizedOpenView.uid)) {
@@ -6604,8 +6982,11 @@ class FlowSurfacesService {
6604
6982
  if (!normalizedUid) {
6605
6983
  (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} openView.uid cannot be empty`);
6606
6984
  }
6985
+ const normalizedHostUid = String(options.popupTemplateHostUid || "").trim();
6607
6986
  normalizedOpenView.uid = normalizedUid;
6608
- await this.assertOpenViewUidTarget(actionName, normalizedUid, options);
6987
+ if (normalizedUid !== normalizedHostUid) {
6988
+ await this.assertOpenViewUidTarget(actionName, normalizedUid, options);
6989
+ }
6609
6990
  }
6610
6991
  if (!import_lodash.default.isUndefined(normalizedOpenView.mode)) {
6611
6992
  const rawMode = String(normalizedOpenView.mode || "").trim();
@@ -6795,14 +7176,28 @@ class FlowSurfacesService {
6795
7176
  (0, import_service_utils.rethrowInlineConfigurationError)(error, `flowSurfaces ${actionName} settings invalid`);
6796
7177
  }
6797
7178
  }
6798
- resolveComposeBlockSettings(settings, keyMap) {
6799
- if (!import_lodash.default.isPlainObject(settings == null ? void 0 : settings.connectFields) || !Array.isArray(settings.connectFields.targets)) {
6800
- return settings;
6801
- }
6802
- const nextSettings = import_lodash.default.cloneDeep(settings);
6803
- nextSettings.connectFields = {
6804
- ...nextSettings.connectFields,
6805
- targets: import_lodash.default.castArray(nextSettings.connectFields.targets).map((target) => {
7179
+ resolveComposeBlockSettings(settings, keyMap, block) {
7180
+ var _a, _b;
7181
+ let nextSettings = settings;
7182
+ if (((_a = block == null ? void 0 : block.spec) == null ? void 0 : _a.type) === "calendar") {
7183
+ nextSettings = import_lodash.default.omit(nextSettings, [
7184
+ "quickCreatePopup",
7185
+ "eventPopup",
7186
+ "quickCreatePopupSettings",
7187
+ "eventPopupSettings"
7188
+ ]);
7189
+ } else if (((_b = block == null ? void 0 : block.spec) == null ? void 0 : _b.type) === "kanban") {
7190
+ const omittedKeys = ["quickCreatePopup", "cardPopup", "quickCreatePopupSettings", "cardPopupSettings"];
7191
+ const withoutHiddenPopupSettings = import_lodash.default.omit(nextSettings, omittedKeys);
7192
+ nextSettings = Object.keys(withoutHiddenPopupSettings).length || omittedKeys.every((key) => !import_lodash.default.has(nextSettings, key)) ? withoutHiddenPopupSettings : {};
7193
+ }
7194
+ if (!import_lodash.default.isPlainObject(nextSettings == null ? void 0 : nextSettings.connectFields) || !Array.isArray(nextSettings.connectFields.targets)) {
7195
+ return nextSettings;
7196
+ }
7197
+ const resolvedSettings = import_lodash.default.cloneDeep(nextSettings);
7198
+ resolvedSettings.connectFields = {
7199
+ ...resolvedSettings.connectFields,
7200
+ targets: import_lodash.default.castArray(resolvedSettings.connectFields.targets).map((target) => {
6806
7201
  if (!import_lodash.default.isPlainObject(target) || import_lodash.default.isUndefined(target.target) || target.target === null || target.target === "") {
6807
7202
  return target;
6808
7203
  }
@@ -6814,7 +7209,7 @@ class FlowSurfacesService {
6814
7209
  return nextTarget;
6815
7210
  })
6816
7211
  };
6817
- return nextSettings;
7212
+ return resolvedSettings;
6818
7213
  }
6819
7214
  async applyInlineFieldPopup(actionName, result, popup, options) {
6820
7215
  popup = this.prepareInlinePopupTemplateAliases(actionName, popup, options.popupTemplateAliasSession);
@@ -7248,7 +7643,7 @@ class FlowSurfacesService {
7248
7643
  if (!(actionNode == null ? void 0 : actionNode.uid)) {
7249
7644
  return;
7250
7645
  }
7251
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(actionNode.use);
7646
+ const actionConfig = this.getDefaultActionPopupConfigForNode(actionNode);
7252
7647
  if (!actionConfig) {
7253
7648
  return;
7254
7649
  }
@@ -7258,7 +7653,7 @@ class FlowSurfacesService {
7258
7653
  }
7259
7654
  const uniqueKeySource = JSON.stringify(
7260
7655
  (0, import_service_utils.buildDefinedPayload)({
7261
- actionUse: actionNode.use,
7656
+ actionUse: this.resolveDefaultActionPopupSemanticUse(actionNode.use),
7262
7657
  dataSourceKey: openView == null ? void 0 : openView.dataSourceKey,
7263
7658
  collectionName: openView == null ? void 0 : openView.collectionName,
7264
7659
  associationName: openView == null ? void 0 : openView.associationName,
@@ -7295,7 +7690,7 @@ class FlowSurfacesService {
7295
7690
  if (options.autoCompleteDefaultPopup === false) {
7296
7691
  return false;
7297
7692
  }
7298
- if (!(0, import_default_action_popup.isFlowSurfaceDefaultActionPopupUse)(actionNode == null ? void 0 : actionNode.use)) {
7693
+ if (!this.isDefaultActionPopupUseForNode(actionNode)) {
7299
7694
  return false;
7300
7695
  }
7301
7696
  const openView = this.resolvePopupHostOpenView(actionNode);
@@ -7319,14 +7714,17 @@ class FlowSurfacesService {
7319
7714
  if (options.includeFallback === false) {
7320
7715
  return void 0;
7321
7716
  }
7322
- return (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(actionNode == null ? void 0 : actionNode.use, this.getActionButtonTitle(actionNode));
7717
+ return (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(
7718
+ this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use),
7719
+ this.getActionButtonTitle(actionNode)
7720
+ );
7323
7721
  }
7324
7722
  resolveGeneratedDefaultActionPopupMetadata(actionNode, popup, popupProfile) {
7325
7723
  const explicitTitle = this.normalizeOptionalPopupTitle(popup == null ? void 0 : popup.title);
7326
7724
  if (explicitTitle) {
7327
7725
  return void 0;
7328
7726
  }
7329
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(actionNode == null ? void 0 : actionNode.use);
7727
+ const actionConfig = this.getDefaultActionPopupConfigForNode(actionNode);
7330
7728
  if (!actionConfig) {
7331
7729
  return void 0;
7332
7730
  }
@@ -7347,7 +7745,9 @@ class FlowSurfacesService {
7347
7745
  if (!collectionName) {
7348
7746
  return [];
7349
7747
  }
7350
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(input.actionUse);
7748
+ const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(
7749
+ this.resolveDefaultActionPopupSemanticUse(input.actionUse)
7750
+ );
7351
7751
  if (!actionConfig) {
7352
7752
  return [];
7353
7753
  }
@@ -7381,7 +7781,7 @@ class FlowSurfacesService {
7381
7781
  }
7382
7782
  buildDefaultActionPopupKeyMap(actionNode, namespace) {
7383
7783
  var _a;
7384
- const actionConfig = (0, import_default_action_popup.getFlowSurfaceDefaultActionPopupConfigByUse)(actionNode == null ? void 0 : actionNode.use);
7784
+ const actionConfig = this.getDefaultActionPopupConfigForNode(actionNode);
7385
7785
  if (!actionConfig || !namespace) {
7386
7786
  return /* @__PURE__ */ new Map();
7387
7787
  }
@@ -7503,7 +7903,7 @@ class FlowSurfacesService {
7503
7903
  enabledPackages
7504
7904
  });
7505
7905
  return this.remapDefaultActionPopupBlocks(
7506
- (0, import_default_action_popup.buildFlowSurfaceDefaultActionPopupBlocks)(actionNode == null ? void 0 : actionNode.use, fields),
7906
+ (0, import_default_action_popup.buildFlowSurfaceDefaultActionPopupBlocks)(this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use), fields),
7507
7907
  keyMap,
7508
7908
  namespace
7509
7909
  );
@@ -7573,7 +7973,10 @@ class FlowSurfacesService {
7573
7973
  return normalizedTitle || void 0;
7574
7974
  }
7575
7975
  async syncDefaultActionPopupTabTitle(actionNode, popupTab, options) {
7576
- const popupTabTitle = this.normalizeOptionalPopupTitle(options.popupTabTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(actionNode == null ? void 0 : actionNode.use, this.getActionButtonTitle(actionNode));
7976
+ const popupTabTitle = this.normalizeOptionalPopupTitle(options.popupTabTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(
7977
+ this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use),
7978
+ this.getActionButtonTitle(actionNode)
7979
+ );
7577
7980
  if (!(popupTab == null ? void 0 : popupTab.uid) || !popupTabTitle || this.resolvePopupTabTitle(popupTab) === popupTabTitle) {
7578
7981
  return;
7579
7982
  }
@@ -7599,7 +8002,10 @@ class FlowSurfacesService {
7599
8002
  });
7600
8003
  const popupPage = (0, import_service_utils.getSingleNodeSubModel)((_a = popupHost == null ? void 0 : popupHost.subModels) == null ? void 0 : _a.page);
7601
8004
  const popupTab = import_lodash.default.castArray(((_b = popupPage == null ? void 0 : popupPage.subModels) == null ? void 0 : _b.tabs) || [])[0];
7602
- const popupTabTitle = this.normalizeOptionalPopupTitle(options.popupTabTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(actionNode == null ? void 0 : actionNode.use, this.getActionButtonTitle(actionNode));
8005
+ const popupTabTitle = this.normalizeOptionalPopupTitle(options.popupTabTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(
8006
+ this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use),
8007
+ this.getActionButtonTitle(actionNode)
8008
+ );
7603
8009
  if (!(popupTab == null ? void 0 : popupTab.uid) || !popupTabTitle || this.resolvePopupTabTitle(popupTab) === popupTabTitle) {
7604
8010
  return;
7605
8011
  }
@@ -7631,20 +8037,35 @@ class FlowSurfacesService {
7631
8037
  includeAsyncNode: true
7632
8038
  }) || fallbackActionNode;
7633
8039
  const openViewStep = (0, import_template_service_utils.findFlowTemplateOpenViewStep)(actionNode);
7634
- const openViewTitle = this.normalizeOptionalPopupTitle(options.openViewTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(actionNode == null ? void 0 : actionNode.use, this.getActionButtonTitle(actionNode));
8040
+ const openViewTitle = this.normalizeOptionalPopupTitle(options.openViewTitle) || (0, import_default_action_popup.resolveFlowSurfaceDefaultActionPopupTabTitle)(
8041
+ this.resolveDefaultActionPopupSemanticUse(actionNode == null ? void 0 : actionNode.use),
8042
+ this.getActionButtonTitle(actionNode)
8043
+ );
7635
8044
  if (!openViewStep || !openViewTitle) {
7636
8045
  return;
7637
8046
  }
7638
8047
  const currentOpenView = import_lodash.default.isPlainObject(openViewStep.openView) ? openViewStep.openView : {};
7639
- if (this.normalizeOptionalPopupTitle(currentOpenView.title) === openViewTitle) {
8048
+ const popupProfile = await this.resolvePopupBlockProfile(
8049
+ actionNode.uid,
8050
+ null,
8051
+ actionNode,
8052
+ options.transaction
8053
+ ).catch(() => null);
8054
+ const filterTargetKey = (popupProfile == null ? void 0 : popupProfile.currentCollection) ? this.getCollectionFilterTargetKey(popupProfile.currentCollection) : null;
8055
+ const defaultFilterByTk = this.resolvePopupCurrentRecordResourceFilterByTk(popupProfile);
8056
+ const currentFilterByTk = import_lodash.default.isString(currentOpenView.filterByTk) ? currentOpenView.filterByTk.trim() : "";
8057
+ const preserveCustomFilterByTk = currentFilterByTk && currentFilterByTk !== "{{ctx.view.inputArgs.filterByTk}}" && currentFilterByTk !== (filterTargetKey ? `{{ctx.record.${filterTargetKey}}}` : "");
8058
+ const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
8059
+ ...currentOpenView,
8060
+ title: openViewTitle,
8061
+ filterByTk: preserveCustomFilterByTk ? currentOpenView.filterByTk : defaultFilterByTk || currentOpenView.filterByTk
8062
+ });
8063
+ if (import_lodash.default.isEqual(nextOpenView, currentOpenView)) {
7640
8064
  return;
7641
8065
  }
7642
8066
  const nextStepParams = import_lodash.default.cloneDeep((actionNode == null ? void 0 : actionNode.stepParams) || {});
7643
8067
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[openViewStep.flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[openViewStep.flowKey]) : {};
7644
- currentGroup[openViewStep.stepKey] = (0, import_service_utils.buildDefinedPayload)({
7645
- ...currentOpenView,
7646
- title: openViewTitle
7647
- });
8068
+ currentGroup[openViewStep.stepKey] = nextOpenView;
7648
8069
  nextStepParams[openViewStep.flowKey] = currentGroup;
7649
8070
  await this.repository.patch(
7650
8071
  {
@@ -7679,12 +8100,16 @@ class FlowSurfacesService {
7679
8100
  const nextStepParams = import_lodash.default.cloneDeep(actionNode.stepParams || {});
7680
8101
  const currentGroup = import_lodash.default.isPlainObject(nextStepParams[flowKey]) ? import_lodash.default.cloneDeep(nextStepParams[flowKey]) : {};
7681
8102
  const currentGroupOpenView = import_lodash.default.isPlainObject(currentGroup[stepKey]) ? currentGroup[stepKey] : {};
8103
+ const filterTargetKey = (popupProfile == null ? void 0 : popupProfile.currentCollection) ? this.getCollectionFilterTargetKey(popupProfile.currentCollection) : null;
8104
+ const currentFilterByTk = import_lodash.default.isString(currentGroupOpenView == null ? void 0 : currentGroupOpenView.filterByTk) ? currentGroupOpenView.filterByTk.trim() : "";
8105
+ const defaultFilterByTk = this.resolvePopupCurrentRecordResourceFilterByTk(popupProfile);
8106
+ const preserveCustomFilterByTk = currentFilterByTk && currentFilterByTk !== "{{ctx.view.inputArgs.filterByTk}}" && currentFilterByTk !== "{{ctx.record." + filterTargetKey + "}}";
7682
8107
  const nextOpenView = (0, import_service_utils.buildDefinedPayload)({
7683
8108
  ...currentGroupOpenView,
7684
8109
  dataSourceKey: (currentOpenView == null ? void 0 : currentOpenView.dataSourceKey) || (popupProfile == null ? void 0 : popupProfile.dataSourceKey) || "main",
7685
8110
  collectionName,
7686
8111
  associationName: (currentOpenView == null ? void 0 : currentOpenView.associationName) || (popupProfile == null ? void 0 : popupProfile.associationName),
7687
- filterByTk: (popupProfile == null ? void 0 : popupProfile.filterByTk) || "{{ctx.view.inputArgs.filterByTk}}",
8112
+ filterByTk: preserveCustomFilterByTk ? currentGroupOpenView.filterByTk : defaultFilterByTk || (popupProfile == null ? void 0 : popupProfile.filterByTk) || "{{ctx.view.inputArgs.filterByTk}}",
7688
8113
  sourceId: (currentOpenView == null ? void 0 : currentOpenView.sourceId) || (popupProfile == null ? void 0 : popupProfile.sourceId)
7689
8114
  });
7690
8115
  if (import_lodash.default.isEqual(nextOpenView, currentGroupOpenView)) {
@@ -7761,7 +8186,7 @@ class FlowSurfacesService {
7761
8186
  openViewActionName: actionName
7762
8187
  }
7763
8188
  );
7764
- if ((0, import_default_action_popup.isFlowSurfaceDefaultActionPopupUse)(actionNode == null ? void 0 : actionNode.use) && templateRef.mode === "copy") {
8189
+ if (this.isDefaultActionPopupUseForNode(actionNode) && templateRef.mode === "copy") {
7765
8190
  await this.syncDefaultActionPopupCopiedTemplateTabTitle(actionUid, actionNode, {
7766
8191
  ...options,
7767
8192
  popupTabTitle: templateOpenViewTitle
@@ -7793,6 +8218,12 @@ class FlowSurfacesService {
7793
8218
  openViewActionName: actionName
7794
8219
  }
7795
8220
  );
8221
+ if (this.isDefaultActionPopupUseForNode(actionNode)) {
8222
+ await this.syncDefaultActionPopupOpenViewTitle(actionUid, actionNode, {
8223
+ ...options,
8224
+ openViewTitle: templateOpenViewTitle
8225
+ });
8226
+ }
7796
8227
  this.registerInlinePopupTemplateAlias(actionName, popup, matchedTemplate, options.popupTemplateAliasSession);
7797
8228
  return;
7798
8229
  }
@@ -7881,8 +8312,22 @@ class FlowSurfacesService {
7881
8312
  current.use
7882
8313
  );
7883
8314
  });
7884
- this.syncFilterActionSettingsForUpdateSettings(current, normalizedValues, nextPayload);
7885
- this.syncMirroredStepParamsForUpdateSettings(current, nextPayload);
8315
+ this.replaceExplicitPopupStepParamSubtreesForUpdateSettings(
8316
+ current,
8317
+ normalizedValues,
8318
+ nextPayload,
8319
+ options.replacePopupStepParamSubtrees === true
8320
+ );
8321
+ this.syncCalendarPopupPropsForUpdateSettings(current, normalizedValues, nextPayload);
8322
+ this.syncKanbanPopupPropsForUpdateSettings(current, normalizedValues, nextPayload);
8323
+ this.syncDefaultSortingForUpdateSettings(current, normalizedValues, nextPayload);
8324
+ this.syncFilterActionSettingsForUpdateSettings(current, normalizedValues, nextPayload);
8325
+ this.syncMirroredStepParamsForUpdateSettings(current, nextPayload);
8326
+ const updateActionAssignedValues = this.syncUpdateActionAssignedValuesForUpdateSettings(
8327
+ current,
8328
+ normalizedValues,
8329
+ nextPayload
8330
+ );
7886
8331
  const popupActionContext = options.popupActionContext || await this.resolveRecordContextPopupActionContextForHost(current, options.transaction);
7887
8332
  await this.normalizeOpenViewForUpdateSettings(
7888
8333
  options.openViewActionName || "updateSettings",
@@ -7891,6 +8336,7 @@ class FlowSurfacesService {
7891
8336
  {
7892
8337
  transaction: options.transaction,
7893
8338
  popupTemplateHostUid: options.popupTemplateHostUid,
8339
+ popupTemplateHostUse: current == null ? void 0 : current.use,
7894
8340
  popupActionContext
7895
8341
  }
7896
8342
  );
@@ -7935,6 +8381,9 @@ class FlowSurfacesService {
7935
8381
  };
7936
8382
  }
7937
8383
  await this.repository.patch(nextPayload, { transaction: options.transaction });
8384
+ if (!import_lodash.default.isUndefined(updateActionAssignedValues)) {
8385
+ await this.syncUpdateActionAssignFormItems(current.uid, updateActionAssignedValues, options.transaction);
8386
+ }
7938
8387
  if (!import_lodash.default.isUndefined((_a = nextPayload.stepParams) == null ? void 0 : _a.fieldSettings)) {
7939
8388
  await this.syncFieldBindingSettingsForNode(current, effectiveNode, options.transaction);
7940
8389
  } else if (current.use === "FilterFormItemModel") {
@@ -7942,12 +8391,22 @@ class FlowSurfacesService {
7942
8391
  } else if (current.use === "ChartBlockModel" && !import_lodash.default.isUndefined((_b = nextPayload.stepParams) == null ? void 0 : _b.chartSettings)) {
7943
8392
  await this.syncChartDataBindingsForNode(effectiveNode, options.transaction);
7944
8393
  }
7945
- if (current.use === "CalendarBlockModel") {
8394
+ if (!options.skipHiddenPopupHostEnsure && current.use === "CalendarBlockModel") {
7946
8395
  await this.ensureCalendarBlockPopupHosts(effectiveNode, options.transaction);
7947
8396
  }
7948
- if (current.use === "KanbanBlockModel") {
8397
+ if (!options.skipHiddenPopupHostEnsure && current.use === "KanbanBlockModel") {
7949
8398
  await this.ensureKanbanBlockPopupHosts(effectiveNode, options.transaction);
7950
8399
  }
8400
+ if (!options.skipHiddenPopupHostEnsure && current.use === "KanbanCardItemModel") {
8401
+ const parentUid = String(current.parentId || "").trim() || (current.uid ? await this.locator.findParentUid(current.uid, options.transaction).catch(() => "") : "") || void 0;
8402
+ const parentNode = parentUid ? await this.repository.findModelById(parentUid, {
8403
+ transaction: options.transaction,
8404
+ includeAsyncNode: true
8405
+ }) : null;
8406
+ if ((parentNode == null ? void 0 : parentNode.use) === "KanbanBlockModel") {
8407
+ await this.ensureKanbanBlockPopupHosts(parentNode, options.transaction);
8408
+ }
8409
+ }
7951
8410
  await this.syncFlowTemplateUsagesForNodeTree(current.uid, options.transaction);
7952
8411
  if (import_approval.APPROVAL_SINGLETON_ACTION_USES.has(current.use || "")) {
7953
8412
  await this.syncApprovalRuntimeConfigForNode(current.uid, options.transaction);
@@ -7957,6 +8416,234 @@ class FlowSurfacesService {
7957
8416
  updated: Object.keys(import_lodash.default.omit(nextPayload, ["uid"]))
7958
8417
  };
7959
8418
  }
8419
+ syncCalendarPopupPropsForUpdateSettings(current, normalizedValues, nextPayload) {
8420
+ if ((current == null ? void 0 : current.use) !== "CalendarBlockModel" || !import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.props)) {
8421
+ return;
8422
+ }
8423
+ let nextStepParams;
8424
+ for (const actionKey of import_hidden_popup_calendar.CALENDAR_POPUP_ACTION_KEYS) {
8425
+ const propKey = this.getCalendarPopupPropKey(actionKey);
8426
+ if (!Object.prototype.hasOwnProperty.call(normalizedValues.props, propKey)) {
8427
+ continue;
8428
+ }
8429
+ const value = normalizedValues.props[propKey];
8430
+ if (!import_lodash.default.has(normalizedValues, ["stepParams", "calendarSettings", propKey])) {
8431
+ nextStepParams = nextStepParams ?? import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8432
+ const currentSettings = import_lodash.default.get(nextStepParams, ["calendarSettings", propKey]);
8433
+ const popupSettings = import_lodash.default.isPlainObject(value) ? this.normalizeCalendarPopupSettings(
8434
+ actionKey,
8435
+ import_lodash.default.isPlainObject(currentSettings) ? { ...import_lodash.default.cloneDeep(currentSettings), ...import_lodash.default.cloneDeep(value) } : value
8436
+ ) : {};
8437
+ import_lodash.default.set(nextStepParams, ["calendarSettings", propKey], import_lodash.default.cloneDeep(popupSettings));
8438
+ }
8439
+ }
8440
+ this.stripPopupPropsFromPayload(nextPayload, import_hidden_popup_calendar.CALENDAR_POPUP_PROP_KEYS);
8441
+ if (nextStepParams) {
8442
+ nextPayload.stepParams = nextStepParams;
8443
+ }
8444
+ }
8445
+ replaceExplicitPopupStepParamSubtreesForUpdateSettings(current, normalizedValues, nextPayload, replacePopupStepParamSubtrees = false) {
8446
+ const replacePaths = UPDATE_SETTINGS_POPUP_STEP_PARAM_REPLACE_PATHS_BY_USE[(current == null ? void 0 : current.use) || ""];
8447
+ if (!(replacePaths == null ? void 0 : replacePaths.length) || !import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.stepParams)) {
8448
+ return;
8449
+ }
8450
+ let nextStepParams;
8451
+ for (const path of replacePaths) {
8452
+ const inputPath = ["stepParams", ...path];
8453
+ if (!import_lodash.default.has(normalizedValues, inputPath)) {
8454
+ continue;
8455
+ }
8456
+ nextStepParams = nextStepParams ?? import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8457
+ const value = import_lodash.default.get(normalizedValues, inputPath);
8458
+ const currentValue = import_lodash.default.get(nextStepParams, path);
8459
+ import_lodash.default.set(
8460
+ nextStepParams,
8461
+ path,
8462
+ this.normalizePopupStepParamReplacementForUpdateSettings(
8463
+ current,
8464
+ path,
8465
+ value,
8466
+ currentValue,
8467
+ replacePopupStepParamSubtrees
8468
+ )
8469
+ );
8470
+ }
8471
+ if (nextStepParams) {
8472
+ nextPayload.stepParams = nextStepParams;
8473
+ }
8474
+ }
8475
+ normalizePopupStepParamReplacementForUpdateSettings(current, path, value, currentValue, replacePopupStepParamSubtrees = false) {
8476
+ if (!import_lodash.default.isPlainObject(value)) {
8477
+ return {};
8478
+ }
8479
+ const mergedValue = !replacePopupStepParamSubtrees && import_lodash.default.isPlainObject(currentValue) ? { ...import_lodash.default.cloneDeep(currentValue), ...import_lodash.default.cloneDeep(value) } : value;
8480
+ if ((current == null ? void 0 : current.use) === "CalendarBlockModel") {
8481
+ const actionKey = path[1] === "quickCreatePopupSettings" ? "quickCreateAction" : "eventViewAction";
8482
+ return this.normalizeCalendarPopupSettings(actionKey, mergedValue);
8483
+ }
8484
+ if ((current == null ? void 0 : current.use) === "KanbanBlockModel") {
8485
+ return this.normalizeKanbanPopupSettings("quickCreateAction", mergedValue, current.uid);
8486
+ }
8487
+ if ((current == null ? void 0 : current.use) === "KanbanCardItemModel") {
8488
+ const parentUid = String((current == null ? void 0 : current.parentId) || "").trim() || void 0;
8489
+ return this.normalizeKanbanPopupSettings("cardViewAction", mergedValue, parentUid);
8490
+ }
8491
+ return import_lodash.default.cloneDeep(mergedValue);
8492
+ }
8493
+ stripPopupPropsFromPayload(nextPayload, keys) {
8494
+ if (!import_lodash.default.isPlainObject(nextPayload.props)) {
8495
+ return;
8496
+ }
8497
+ for (const key of keys) {
8498
+ if (Object.prototype.hasOwnProperty.call(nextPayload.props, key)) {
8499
+ delete nextPayload.props[key];
8500
+ }
8501
+ }
8502
+ }
8503
+ syncDefaultSortingForUpdateSettings(current, normalizedValues, nextPayload) {
8504
+ if (!import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.stepParams)) {
8505
+ return;
8506
+ }
8507
+ const currentUse = current == null ? void 0 : current.use;
8508
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8509
+ let changed = false;
8510
+ const normalizeGroupSort = (groupPath, context) => {
8511
+ const currentGroup = import_lodash.default.get(nextStepParams, groupPath);
8512
+ if (!import_lodash.default.isPlainObject(currentGroup)) {
8513
+ return;
8514
+ }
8515
+ if (!import_lodash.default.has(normalizedValues.stepParams, [...groupPath, "defaultSorting", "sort"])) {
8516
+ return;
8517
+ }
8518
+ const defaultSorting = import_lodash.default.get(currentGroup, ["defaultSorting", "sort"]);
8519
+ const normalizedSort = (0, import_public_compatibility.normalizeFlowSurfaceDefaultSorting)(defaultSorting, context);
8520
+ if (import_lodash.default.isEqual(defaultSorting, normalizedSort)) {
8521
+ return;
8522
+ }
8523
+ import_lodash.default.set(nextStepParams, [...groupPath, "defaultSorting", "sort"], normalizedSort);
8524
+ changed = true;
8525
+ };
8526
+ if (currentUse === "TableBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "tableSettings")) {
8527
+ normalizeGroupSort(["tableSettings"], "tableSettings.defaultSorting.sort");
8528
+ }
8529
+ if (currentUse === "DetailsBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "detailsSettings")) {
8530
+ normalizeGroupSort(["detailsSettings"], "detailsSettings.defaultSorting.sort");
8531
+ }
8532
+ if (currentUse === "ListBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "listSettings")) {
8533
+ normalizeGroupSort(["listSettings"], "listSettings.defaultSorting.sort");
8534
+ }
8535
+ if (currentUse === "GridCardBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "GridCardSettings")) {
8536
+ normalizeGroupSort(["GridCardSettings"], "GridCardSettings.defaultSorting.sort");
8537
+ }
8538
+ if (currentUse === "TreeBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "treeSettings")) {
8539
+ normalizeGroupSort(["treeSettings"], "treeSettings.defaultSorting.sort");
8540
+ }
8541
+ if (currentUse === "KanbanBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "kanbanSettings")) {
8542
+ normalizeGroupSort(["kanbanSettings"], "kanbanSettings.defaultSorting.sort");
8543
+ }
8544
+ if (currentUse === "MapBlockModel" && Object.prototype.hasOwnProperty.call(normalizedValues.stepParams, "createMapBlock")) {
8545
+ const createMapBlock = import_lodash.default.get(nextStepParams, ["createMapBlock"]);
8546
+ if (import_lodash.default.isPlainObject(createMapBlock)) {
8547
+ if (!import_lodash.default.has(normalizedValues.stepParams, ["createMapBlock", "lineSort", "sort"])) {
8548
+ return;
8549
+ }
8550
+ const defaultSorting = import_lodash.default.get(createMapBlock, ["lineSort", "sort"]);
8551
+ const normalizedSort = (0, import_public_compatibility.normalizeFlowSurfaceEmptySortingAsDefault)(
8552
+ defaultSorting,
8553
+ "createMapBlock.lineSort.sort"
8554
+ );
8555
+ if (!import_lodash.default.isEqual(defaultSorting, normalizedSort)) {
8556
+ import_lodash.default.set(nextStepParams, ["createMapBlock", "lineSort", "sort"], normalizedSort);
8557
+ changed = true;
8558
+ }
8559
+ }
8560
+ }
8561
+ if (changed) {
8562
+ nextPayload.stepParams = nextStepParams;
8563
+ }
8564
+ }
8565
+ syncKanbanPopupPropsForUpdateSettings(current, normalizedValues, nextPayload) {
8566
+ if (!import_lodash.default.isPlainObject(normalizedValues == null ? void 0 : normalizedValues.props)) {
8567
+ return;
8568
+ }
8569
+ if ((current == null ? void 0 : current.use) === "KanbanBlockModel") {
8570
+ const propToPopupKey = {
8571
+ popupMode: "mode",
8572
+ popupSize: "size",
8573
+ popupTemplateUid: "popupTemplateUid",
8574
+ popupPageModelClass: "pageModelClass",
8575
+ popupTargetUid: "uid"
8576
+ };
8577
+ const writtenProps = Object.keys(propToPopupKey).filter(
8578
+ (propKey) => Object.prototype.hasOwnProperty.call(normalizedValues.props, propKey)
8579
+ );
8580
+ const hasLegacyPopupSettings = Object.prototype.hasOwnProperty.call(
8581
+ normalizedValues.props,
8582
+ "quickCreatePopupSettings"
8583
+ );
8584
+ if (!writtenProps.length && !hasLegacyPopupSettings) {
8585
+ return;
8586
+ }
8587
+ if (import_lodash.default.has(normalizedValues, ["stepParams", "kanbanSettings", "popup"])) {
8588
+ this.stripPopupPropsFromPayload(nextPayload, import_hidden_popup_kanban.KANBAN_BLOCK_POPUP_PROP_KEYS);
8589
+ return;
8590
+ }
8591
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8592
+ const currentPopupSettings = import_lodash.default.get(nextStepParams, ["kanbanSettings", "popup"]);
8593
+ const popupSettings = import_lodash.default.cloneDeep(import_lodash.default.isPlainObject(currentPopupSettings) ? currentPopupSettings : {});
8594
+ if (import_lodash.default.isPlainObject(normalizedValues.props.quickCreatePopupSettings)) {
8595
+ Object.assign(popupSettings, import_lodash.default.cloneDeep(normalizedValues.props.quickCreatePopupSettings));
8596
+ }
8597
+ for (const propKey of writtenProps) {
8598
+ popupSettings[propToPopupKey[propKey]] = normalizedValues.props[propKey];
8599
+ }
8600
+ import_lodash.default.set(
8601
+ nextStepParams,
8602
+ ["kanbanSettings", "popup"],
8603
+ this.normalizeKanbanPopupSettings("quickCreateAction", popupSettings, current.uid)
8604
+ );
8605
+ nextPayload.stepParams = nextStepParams;
8606
+ this.stripPopupPropsFromPayload(nextPayload, import_hidden_popup_kanban.KANBAN_BLOCK_POPUP_PROP_KEYS);
8607
+ return;
8608
+ }
8609
+ if ((current == null ? void 0 : current.use) === "KanbanCardItemModel") {
8610
+ const propToPopupKey = {
8611
+ openMode: "mode",
8612
+ popupSize: "size",
8613
+ popupTemplateUid: "popupTemplateUid",
8614
+ pageModelClass: "pageModelClass",
8615
+ popupTargetUid: "uid"
8616
+ };
8617
+ const writtenProps = Object.keys(propToPopupKey).filter(
8618
+ (propKey) => Object.prototype.hasOwnProperty.call(normalizedValues.props, propKey)
8619
+ );
8620
+ const hasLegacyPopupSettings = Object.prototype.hasOwnProperty.call(normalizedValues.props, "cardPopupSettings");
8621
+ if (!writtenProps.length && !hasLegacyPopupSettings) {
8622
+ return;
8623
+ }
8624
+ if (import_lodash.default.has(normalizedValues, ["stepParams", "cardSettings", "popup"])) {
8625
+ this.stripPopupPropsFromPayload(nextPayload, import_hidden_popup_kanban.KANBAN_CARD_POPUP_PROP_KEYS);
8626
+ return;
8627
+ }
8628
+ const parentUid = String((current == null ? void 0 : current.parentId) || "").trim() || void 0;
8629
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8630
+ const currentPopupSettings = import_lodash.default.get(nextStepParams, ["cardSettings", "popup"]);
8631
+ const popupSettings = import_lodash.default.cloneDeep(import_lodash.default.isPlainObject(currentPopupSettings) ? currentPopupSettings : {});
8632
+ if (import_lodash.default.isPlainObject(normalizedValues.props.cardPopupSettings)) {
8633
+ Object.assign(popupSettings, import_lodash.default.cloneDeep(normalizedValues.props.cardPopupSettings));
8634
+ }
8635
+ for (const propKey of writtenProps) {
8636
+ popupSettings[propToPopupKey[propKey]] = normalizedValues.props[propKey];
8637
+ }
8638
+ import_lodash.default.set(
8639
+ nextStepParams,
8640
+ ["cardSettings", "popup"],
8641
+ this.normalizeKanbanPopupSettings("cardViewAction", popupSettings, parentUid)
8642
+ );
8643
+ nextPayload.stepParams = nextStepParams;
8644
+ this.stripPopupPropsFromPayload(nextPayload, import_hidden_popup_kanban.KANBAN_CARD_POPUP_PROP_KEYS);
8645
+ }
8646
+ }
7960
8647
  syncFilterActionSettingsForUpdateSettings(current, values, nextPayload) {
7961
8648
  if ((current == null ? void 0 : current.use) !== "FilterActionModel") {
7962
8649
  return;
@@ -8048,7 +8735,7 @@ class FlowSurfacesService {
8048
8735
  continue;
8049
8736
  }
8050
8737
  nextStepParams = nextStepParams ?? import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8051
- if (import_lodash.default.has(nextStepParams, mirror.stepParamsPath)) {
8738
+ if (import_lodash.default.has(nextStepParams, mirror.stepParamsPath) && (!import_lodash.default.isEqual(import_lodash.default.get(current == null ? void 0 : current.stepParams, mirror.stepParamsPath), import_lodash.default.get(current == null ? void 0 : current[mirror.domain], mirror.key)) || !import_lodash.default.isEqual(import_lodash.default.get(nextStepParams, mirror.stepParamsPath), import_lodash.default.get(current == null ? void 0 : current.stepParams, mirror.stepParamsPath)))) {
8052
8739
  continue;
8053
8740
  }
8054
8741
  import_lodash.default.set(nextStepParams, mirror.stepParamsPath, value);
@@ -8057,6 +8744,173 @@ class FlowSurfacesService {
8057
8744
  nextPayload.stepParams = nextStepParams;
8058
8745
  }
8059
8746
  }
8747
+ syncUpdateActionAssignedValuesForUpdateSettings(current, values, nextPayload) {
8748
+ if (!UPDATE_ASSIGN_ACTION_USES.has(current == null ? void 0 : current.use)) {
8749
+ return void 0;
8750
+ }
8751
+ const hasAssignSettingsAssignedValues = import_lodash.default.has(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH);
8752
+ const hasApplyAssignedValues = import_lodash.default.has(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH);
8753
+ if (!hasAssignSettingsAssignedValues && !hasApplyAssignedValues) {
8754
+ return void 0;
8755
+ }
8756
+ const nextStepParams = import_lodash.default.cloneDeep(nextPayload.stepParams ?? (current == null ? void 0 : current.stepParams) ?? {});
8757
+ const clearsAssignSettingsAssignedValues = hasAssignSettingsAssignedValues && import_lodash.default.isPlainObject(import_lodash.default.get(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH)) && !Object.keys(import_lodash.default.get(values, UPDATE_ACTION_ASSIGN_SETTINGS_ASSIGNED_VALUES_PATH)).length;
8758
+ const clearsApplyAssignedValues = hasApplyAssignedValues && import_lodash.default.isPlainObject(import_lodash.default.get(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH)) && !Object.keys(import_lodash.default.get(values, UPDATE_ACTION_APPLY_ASSIGNED_VALUES_PATH)).length;
8759
+ const assignSettingsAssignedValues = clearsAssignSettingsAssignedValues ? {} : import_lodash.default.cloneDeep(import_lodash.default.get(nextStepParams, UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH));
8760
+ const applyAssignedValues = clearsApplyAssignedValues ? {} : import_lodash.default.cloneDeep(import_lodash.default.get(nextStepParams, UPDATE_ACTION_APPLY_STEP_PATH));
8761
+ if (hasAssignSettingsAssignedValues && hasApplyAssignedValues && !import_lodash.default.isEqual(assignSettingsAssignedValues, applyAssignedValues)) {
8762
+ (0, import_errors.throwBadRequest)(
8763
+ "flowSurfaces updateSettings update action values 'stepParams.assignSettings.assignFieldValues.assignedValues' and 'stepParams.apply.apply.assignedValues' must match"
8764
+ );
8765
+ }
8766
+ const assignedValues = hasAssignSettingsAssignedValues ? assignSettingsAssignedValues : applyAssignedValues;
8767
+ if (!import_lodash.default.isPlainObject(assignedValues)) {
8768
+ (0, import_errors.throwBadRequest)(
8769
+ "flowSurfaces updateSettings update action values 'stepParams.assignSettings.assignFieldValues.assignedValues' requires an object payload"
8770
+ );
8771
+ }
8772
+ import_lodash.default.set(nextStepParams, UPDATE_ACTION_ASSIGN_SETTINGS_STEP_PATH, import_lodash.default.cloneDeep(assignedValues));
8773
+ import_lodash.default.set(nextStepParams, UPDATE_ACTION_APPLY_STEP_PATH, import_lodash.default.cloneDeep(assignedValues));
8774
+ nextPayload.stepParams = nextStepParams;
8775
+ return assignedValues;
8776
+ }
8777
+ async syncUpdateActionAssignFormItems(actionUid, assignedValues, transaction) {
8778
+ var _a, _b, _c, _d, _e, _f;
8779
+ const actionNode = await this.repository.findModelById(actionUid, {
8780
+ transaction,
8781
+ includeAsyncNode: true
8782
+ });
8783
+ if (!UPDATE_ASSIGN_ACTION_USES.has(actionNode == null ? void 0 : actionNode.use)) {
8784
+ return;
8785
+ }
8786
+ const resourceContext = await this.locator.resolveCollectionContext(actionUid, transaction).catch(() => null);
8787
+ const resourceInit = (resourceContext == null ? void 0 : resourceContext.resourceInit) || {};
8788
+ const dataSourceKey = resourceInit.dataSourceKey || "main";
8789
+ const collectionName = resourceInit.collectionName;
8790
+ const assignFormUid = await this.ensureUpdateActionAssignForm(actionNode, resourceInit, transaction);
8791
+ const assignFormGridUid = await this.ensureUpdateActionAssignFormGrid(assignFormUid, transaction);
8792
+ const refreshedGrid = await this.repository.findModelById(assignFormGridUid, {
8793
+ transaction,
8794
+ includeAsyncNode: true
8795
+ });
8796
+ const existingItems = import_lodash.default.castArray(((_a = refreshedGrid == null ? void 0 : refreshedGrid.subModels) == null ? void 0 : _a.items) || []);
8797
+ const existingItemsByFieldPath = /* @__PURE__ */ new Map();
8798
+ existingItems.forEach((item) => {
8799
+ var _a2, _b2, _c2;
8800
+ const fieldPath = String(((_c2 = (_b2 = (_a2 = item == null ? void 0 : item.stepParams) == null ? void 0 : _a2.fieldSettings) == null ? void 0 : _b2.init) == null ? void 0 : _c2.fieldPath) || "").trim();
8801
+ if (fieldPath && !existingItemsByFieldPath.has(fieldPath)) {
8802
+ existingItemsByFieldPath.set(fieldPath, item);
8803
+ }
8804
+ });
8805
+ const nextFieldPaths = new Set(Object.keys(assignedValues || {}).filter((fieldPath) => String(fieldPath).trim()));
8806
+ const keptFieldPaths = /* @__PURE__ */ new Set();
8807
+ for (const staleItem of existingItems) {
8808
+ const fieldPath = String(((_d = (_c = (_b = staleItem == null ? void 0 : staleItem.stepParams) == null ? void 0 : _b.fieldSettings) == null ? void 0 : _c.init) == null ? void 0 : _d.fieldPath) || "").trim();
8809
+ if (!fieldPath || !nextFieldPaths.has(fieldPath) || keptFieldPaths.has(fieldPath)) {
8810
+ await this.repository.remove(staleItem.uid, { transaction });
8811
+ continue;
8812
+ }
8813
+ keptFieldPaths.add(fieldPath);
8814
+ }
8815
+ for (const fieldPath of nextFieldPaths) {
8816
+ const existingItem = existingItemsByFieldPath.get(fieldPath);
8817
+ await this.repository.upsertModel(
8818
+ this.buildUpdateActionAssignFormItemTree({
8819
+ existingItem,
8820
+ uid: existingItem == null ? void 0 : existingItem.uid,
8821
+ fieldUid: (_f = (_e = existingItem == null ? void 0 : existingItem.subModels) == null ? void 0 : _e.field) == null ? void 0 : _f.uid,
8822
+ parentId: assignFormGridUid,
8823
+ dataSourceKey,
8824
+ collectionName,
8825
+ fieldPath,
8826
+ value: assignedValues[fieldPath]
8827
+ }),
8828
+ { transaction }
8829
+ );
8830
+ }
8831
+ }
8832
+ async ensureUpdateActionAssignForm(actionNode, resourceInit, transaction) {
8833
+ var _a;
8834
+ const existing = (_a = actionNode == null ? void 0 : actionNode.subModels) == null ? void 0 : _a.assignForm;
8835
+ if (existing == null ? void 0 : existing.uid) {
8836
+ return existing.uid;
8837
+ }
8838
+ const assignFormUid = (0, import_utils.uid)();
8839
+ await this.repository.upsertModel(
8840
+ {
8841
+ uid: assignFormUid,
8842
+ parentId: actionNode.uid,
8843
+ subKey: "assignForm",
8844
+ subType: "object",
8845
+ use: "AssignFormModel",
8846
+ stepParams: {
8847
+ resourceSettings: {
8848
+ init: import_lodash.default.cloneDeep(resourceInit || {})
8849
+ }
8850
+ }
8851
+ },
8852
+ { transaction }
8853
+ );
8854
+ return assignFormUid;
8855
+ }
8856
+ async ensureUpdateActionAssignFormGrid(assignFormUid, transaction) {
8857
+ return this.ensureGridChild(assignFormUid, "AssignFormGridModel", transaction);
8858
+ }
8859
+ buildUpdateActionAssignFormItemTree(input) {
8860
+ var _a;
8861
+ const init = import_lodash.default.pickBy(
8862
+ {
8863
+ dataSourceKey: input.dataSourceKey,
8864
+ collectionName: input.collectionName,
8865
+ fieldPath: input.fieldPath
8866
+ },
8867
+ (value) => !import_lodash.default.isUndefined(value)
8868
+ );
8869
+ const fieldUse = this.resolveUpdateActionAssignFormFieldUse(
8870
+ input.dataSourceKey,
8871
+ input.collectionName,
8872
+ input.fieldPath
8873
+ );
8874
+ const existingItem = input.existingItem || {};
8875
+ const existingField = ((_a = existingItem == null ? void 0 : existingItem.subModels) == null ? void 0 : _a.field) || {};
8876
+ const itemStepParams = import_lodash.default.cloneDeep(existingItem.stepParams || {});
8877
+ import_lodash.default.set(itemStepParams, ["fieldSettings", "init"], init);
8878
+ import_lodash.default.set(itemStepParams, ["fieldSettings", "assignValue", "value"], import_lodash.default.cloneDeep(input.value));
8879
+ const fieldStepParams = import_lodash.default.cloneDeep(existingField.stepParams || {});
8880
+ import_lodash.default.set(fieldStepParams, ["fieldSettings", "init"], init);
8881
+ return {
8882
+ uid: input.uid || (0, import_utils.uid)(),
8883
+ parentId: input.parentId,
8884
+ subKey: "items",
8885
+ subType: "array",
8886
+ use: "AssignFormItemModel",
8887
+ stepParams: itemStepParams,
8888
+ subModels: {
8889
+ field: {
8890
+ uid: input.fieldUid || (0, import_utils.uid)(),
8891
+ use: existingField.use || fieldUse,
8892
+ stepParams: fieldStepParams
8893
+ }
8894
+ }
8895
+ };
8896
+ }
8897
+ resolveUpdateActionAssignFormFieldUse(dataSourceKey, collectionName, fieldPath) {
8898
+ const collection = collectionName ? this.getCollection(dataSourceKey, collectionName) : null;
8899
+ const field = (0, import_service_helpers.resolveFieldFromCollection)(collection, fieldPath);
8900
+ if (field) {
8901
+ const registeredBinding = this.resolveRegisteredFieldBinding({
8902
+ containerUse: "AssignFormGridModel",
8903
+ field,
8904
+ dataSourceKey,
8905
+ useStrictOnly: true
8906
+ });
8907
+ if (registeredBinding == null ? void 0 : registeredBinding.modelClassName) {
8908
+ return registeredBinding.modelClassName;
8909
+ }
8910
+ return (0, import_service_helpers.inferFieldMenuEditableFieldUse)((0, import_service_helpers.getFieldInterface)(field)) || "InputFieldModel";
8911
+ }
8912
+ return "InputFieldModel";
8913
+ }
8060
8914
  normalizeCanonicalBlockHeaderWriteForUpdateSettings(current, values) {
8061
8915
  const semanticUse = (0, import_approval.normalizeApprovalSemanticUse)(current == null ? void 0 : current.use);
8062
8916
  if (!CANONICAL_BLOCK_HEADER_USES.has(semanticUse)) {
@@ -8157,11 +9011,15 @@ class FlowSurfacesService {
8157
9011
  }
8158
9012
  const requestedOpenView = import_lodash.default.get(nextPayload, openViewPath);
8159
9013
  const currentOpenView = import_lodash.default.get(current, openViewPath);
8160
- const nextOpenView = await this.normalizeOpenView(actionName, requestedOpenView, {
9014
+ let nextOpenView = await this.normalizeOpenView(actionName, requestedOpenView, {
8161
9015
  transaction: options.transaction,
8162
9016
  popupTemplateHostUid,
9017
+ popupTemplateHostUse: options.popupTemplateHostUse || (current == null ? void 0 : current.use),
8163
9018
  popupActionContext: options.popupActionContext
8164
9019
  });
9020
+ if (flowKey === "popupSettings" && String((current == null ? void 0 : current.use) || "").trim() === "AddChildActionModel" && import_lodash.default.isPlainObject(nextOpenView)) {
9021
+ nextOpenView = await this.normalizeAddChildOpenViewForAction(current, nextOpenView, options.transaction);
9022
+ }
8165
9023
  if (this.isTryTemplateOnlyOpenViewRequest(requestedOpenView) && import_lodash.default.isPlainObject(nextOpenView) && !Object.keys(nextOpenView).length) {
8166
9024
  this.unsetPayloadPathAndPruneEmptyParents(nextPayload, openViewPath);
8167
9025
  if (import_lodash.default.isEqual(nextPayload.stepParams, current.stepParams)) {
@@ -8714,7 +9572,7 @@ class FlowSurfacesService {
8714
9572
  if (!normalizedUid) {
8715
9573
  return null;
8716
9574
  }
8717
- for (const actionKey of CALENDAR_POPUP_ACTION_KEYS) {
9575
+ for (const actionKey of import_hidden_popup_calendar.CALENDAR_POPUP_ACTION_KEYS) {
8718
9576
  const suffix = `-${actionKey}`;
8719
9577
  if (normalizedUid.endsWith(suffix) && normalizedUid.length > suffix.length) {
8720
9578
  return {
@@ -8730,8 +9588,8 @@ class FlowSurfacesService {
8730
9588
  if (!normalizedUid) {
8731
9589
  return null;
8732
9590
  }
8733
- for (const actionKey of KANBAN_POPUP_ACTION_KEYS) {
8734
- const suffix = KANBAN_POPUP_ACTION_UID_SUFFIX_BY_KEY[actionKey];
9591
+ for (const actionKey of import_hidden_popup_kanban.KANBAN_POPUP_ACTION_KEYS) {
9592
+ const suffix = import_hidden_popup_kanban.KANBAN_POPUP_ACTION_UID_SUFFIX_BY_KEY[actionKey];
8735
9593
  if (normalizedUid.endsWith(suffix) && normalizedUid.length > suffix.length) {
8736
9594
  return {
8737
9595
  kanbanUid: normalizedUid.slice(0, -suffix.length),
@@ -8773,6 +9631,20 @@ class FlowSurfacesService {
8773
9631
  await this.ensureKanbanBlockPopupHosts(kanbanNode, options.transaction);
8774
9632
  }
8775
9633
  }
9634
+ const repairedTarget = await this.repository.findModelById(writeTarget.uid, {
9635
+ transaction: options.transaction,
9636
+ includeAsyncNode: true
9637
+ });
9638
+ if (repairedTarget == null ? void 0 : repairedTarget.uid) {
9639
+ return writeTarget;
9640
+ }
9641
+ const ownerNode = await this.repository.findModelById((parsedCalendarPopupTarget == null ? void 0 : parsedCalendarPopupTarget.calendarUid) || (parsedKanbanPopupTarget == null ? void 0 : parsedKanbanPopupTarget.kanbanUid), {
9642
+ transaction: options.transaction,
9643
+ includeAsyncNode: true
9644
+ }).catch(() => null);
9645
+ if (ownerNode == null ? void 0 : ownerNode.uid) {
9646
+ await this.ensureHiddenPopupBlockHostsInManagedPopupTarget(ownerNode, options.transaction);
9647
+ }
8776
9648
  return writeTarget;
8777
9649
  }
8778
9650
  normalizeRootUidValue(actionName, values) {
@@ -9181,6 +10053,19 @@ class FlowSurfacesService {
9181
10053
  isAddChildCatalogItem(item) {
9182
10054
  return (item == null ? void 0 : item.key) === "addChild" || (item == null ? void 0 : item.use) === "AddChildActionModel";
9183
10055
  }
10056
+ resolveTreeChildrenField(collection) {
10057
+ return (0, import_service_helpers.getCollectionFields)(collection).find(
10058
+ (field) => {
10059
+ var _a;
10060
+ return (field == null ? void 0 : field.treeChildren) === true || ((_a = field == null ? void 0 : field.options) == null ? void 0 : _a.treeChildren) === true;
10061
+ }
10062
+ );
10063
+ }
10064
+ resolveTreeChildrenAssociationName(collection) {
10065
+ const collectionName = (0, import_service_helpers.getCollectionName)(collection);
10066
+ const childrenFieldName = (0, import_service_helpers.getFieldName)(this.resolveTreeChildrenField(collection));
10067
+ return collectionName && childrenFieldName ? `${collectionName}.${childrenFieldName}` : void 0;
10068
+ }
9184
10069
  isTreeCollection(collection) {
9185
10070
  var _a;
9186
10071
  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;
@@ -9202,11 +10087,49 @@ class FlowSurfacesService {
9202
10087
  includeAsyncNode: true
9203
10088
  }) || node;
9204
10089
  }
9205
- async resolveOwnerCollectionForAddChild(node, transaction) {
10090
+ async resolveAddChildOwnerResourceContext(node, transaction) {
9206
10091
  var _a;
9207
10092
  const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
9208
10093
  const resourceInit = import_lodash.default.get(ownerNode, ["stepParams", "resourceSettings", "init"]) || ((ownerNode == null ? void 0 : ownerNode.uid) ? (_a = await this.locator.resolveCollectionContext(ownerNode.uid, transaction).catch(() => null)) == null ? void 0 : _a.resourceInit : null);
9209
- return this.resolveCollectionFromInit(resourceInit);
10094
+ return {
10095
+ ownerNode,
10096
+ resourceInit,
10097
+ collection: this.resolveCollectionFromInit(resourceInit)
10098
+ };
10099
+ }
10100
+ async resolveOwnerCollectionForAddChild(node, transaction) {
10101
+ return (await this.resolveAddChildOwnerResourceContext(node, transaction)).collection;
10102
+ }
10103
+ async resolveAddChildResourceInitForOwnerNode(node, transaction) {
10104
+ const { resourceInit, collection } = await this.resolveAddChildOwnerResourceContext(node, transaction);
10105
+ const associationName = this.resolveTreeChildrenAssociationName(collection);
10106
+ if (!associationName) {
10107
+ (0, import_errors.throwBadRequest)(
10108
+ `flowSurfaces addRecordAction type 'addChild' cannot resolve tree children association for '${String((resourceInit == null ? void 0 : resourceInit.collectionName) || "").trim() || "unknown"}'`
10109
+ );
10110
+ }
10111
+ return (0, import_service_utils.buildDefinedPayload)({
10112
+ dataSourceKey: (resourceInit == null ? void 0 : resourceInit.dataSourceKey) || "main",
10113
+ collectionName: resourceInit == null ? void 0 : resourceInit.collectionName,
10114
+ associationName
10115
+ });
10116
+ }
10117
+ async normalizeAddChildOpenViewForAction(actionNode, openView, transaction) {
10118
+ if (!import_lodash.default.isPlainObject(openView)) {
10119
+ return openView;
10120
+ }
10121
+ const parentUid = String((actionNode == null ? void 0 : actionNode.parentId) || "").trim() || ((actionNode == null ? void 0 : actionNode.uid) ? await this.locator.findParentUid(actionNode.uid, transaction).catch(() => "") : "");
10122
+ const parentNode = parentUid ? await this.repository.findModelById(parentUid, {
10123
+ transaction,
10124
+ includeAsyncNode: true
10125
+ }) : null;
10126
+ const addChildResourceInit = await this.resolveAddChildResourceInitForOwnerNode(parentNode, transaction);
10127
+ return (0, import_service_utils.buildDefinedPayload)({
10128
+ ...import_lodash.default.omit(import_lodash.default.cloneDeep(openView), ["sourceId"]),
10129
+ dataSourceKey: addChildResourceInit.dataSourceKey,
10130
+ collectionName: addChildResourceInit.collectionName,
10131
+ associationName: addChildResourceInit.associationName
10132
+ });
9210
10133
  }
9211
10134
  async canUseAddChildOnOwnerNode(node, transaction) {
9212
10135
  const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
@@ -9214,15 +10137,26 @@ class FlowSurfacesService {
9214
10137
  return false;
9215
10138
  }
9216
10139
  const collection = await this.resolveOwnerCollectionForAddChild(ownerNode, transaction);
9217
- return this.isTreeCollection(collection);
10140
+ return this.isTreeCollection(collection) && !!this.resolveTreeChildrenAssociationName(collection);
9218
10141
  }
9219
10142
  async assertAddChildSupportedForOwnerNode(node, context, transaction) {
9220
- if (await this.canUseAddChildOnOwnerNode(node, transaction)) {
9221
- return;
10143
+ const ownerNode = await this.resolveAddChildOwnerNode(node, transaction);
10144
+ if ((ownerNode == null ? void 0 : ownerNode.use) !== "TableBlockModel" || !this.isTreeTableEnabled(ownerNode)) {
10145
+ (0, import_errors.throwBadRequest)(
10146
+ `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
10147
+ );
10148
+ }
10149
+ const collection = await this.resolveOwnerCollectionForAddChild(ownerNode, transaction);
10150
+ if (!this.isTreeCollection(collection)) {
10151
+ (0, import_errors.throwBadRequest)(
10152
+ `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
10153
+ );
10154
+ }
10155
+ if (!this.resolveTreeChildrenAssociationName(collection)) {
10156
+ (0, import_errors.throwBadRequest)(
10157
+ `flowSurfaces ${context} type 'addChild' tree collection '${(0, import_service_helpers.getCollectionName)(collection) || "unknown"}' does not expose a tree children field`
10158
+ );
9222
10159
  }
9223
- (0, import_errors.throwBadRequest)(
9224
- `flowSurfaces ${context} type 'addChild' only supports tables bound to tree collections with tree table enabled`
9225
- );
9226
10160
  }
9227
10161
  async filterTargetRecordActions(items, node, transaction) {
9228
10162
  if (!items.some((item) => this.isAddChildCatalogItem(item))) {
@@ -10105,7 +11039,11 @@ class FlowSurfacesService {
10105
11039
  ...(0, import_service_utils.hasOwnDefined)(changes, "density") ? { tableDensity: { size: changes.density } } : {},
10106
11040
  ...(0, import_service_utils.hasOwnDefined)(changes, "quickEdit") ? { quickEdit: { editable: changes.quickEdit } } : {},
10107
11041
  ...(0, import_service_utils.hasOwnDefined)(changes, "showRowNumbers") ? { showRowNumbers: { showIndex: changes.showRowNumbers } } : {},
10108
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11042
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11043
+ defaultSorting: {
11044
+ sort: this.normalizeBlockSortingInput(changes.sorting, "tableSettings.sorting")
11045
+ }
11046
+ } : {},
10109
11047
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10110
11048
  ...(0, import_service_utils.hasOwnDefined)(changes, "treeTable") ? { treeTable: { treeTable: changes.treeTable } } : {},
10111
11049
  ...(0, import_service_utils.hasOwnDefined)(changes, "defaultExpandAllRows") ? { defaultExpandAllRows: { defaultExpandAllRows: changes.defaultExpandAllRows } } : {},
@@ -10148,20 +11086,44 @@ class FlowSurfacesService {
10148
11086
  changes,
10149
11087
  resetInvalidExisting: resourceChanged
10150
11088
  });
10151
- const quickCreatePopupSettings = Object.prototype.hasOwnProperty.call(changes, "quickCreatePopup") ? await this.normalizeCalendarPopupConfigureValue({
11089
+ const hasQuickCreatePopupChange = Object.prototype.hasOwnProperty.call(changes, "quickCreatePopup");
11090
+ const hasEventPopupChange = Object.prototype.hasOwnProperty.call(changes, "eventPopup");
11091
+ const quickCreatePopupSettingsInput = hasQuickCreatePopupChange ? await this.normalizeCalendarPopupConfigureValue({
10152
11092
  actionName: "configure calendar quickCreatePopup",
10153
11093
  blockUid: current.uid,
10154
11094
  actionKey: "quickCreateAction",
10155
11095
  value: changes.quickCreatePopup,
10156
11096
  transaction: options.transaction
10157
11097
  }) : void 0;
10158
- const eventPopupSettings = Object.prototype.hasOwnProperty.call(changes, "eventPopup") ? await this.normalizeCalendarPopupConfigureValue({
11098
+ const eventPopupSettingsInput = hasEventPopupChange ? await this.normalizeCalendarPopupConfigureValue({
10159
11099
  actionName: "configure calendar eventPopup",
10160
11100
  blockUid: current.uid,
10161
11101
  actionKey: "eventViewAction",
10162
11102
  value: changes.eventPopup,
10163
11103
  transaction: options.transaction
10164
11104
  }) : void 0;
11105
+ const currentQuickCreatePopupSettings = this.getCalendarPopupStoredSettings(current, "quickCreateAction");
11106
+ const currentEventPopupSettings = this.getCalendarPopupStoredSettings(current, "eventViewAction");
11107
+ const quickCreatePopupSettingsBase = resourceChanged ? this.stripCalendarPopupTargetSettingsForResourceChange("quickCreateAction", currentQuickCreatePopupSettings) : currentQuickCreatePopupSettings;
11108
+ const eventPopupSettingsBase = resourceChanged ? this.stripCalendarPopupTargetSettingsForResourceChange("eventViewAction", currentEventPopupSettings) : currentEventPopupSettings;
11109
+ const quickCreatePopupSettings = hasQuickCreatePopupChange ? import_lodash.default.isNull(changes.quickCreatePopup) ? quickCreatePopupSettingsInput || {} : this.mergeCalendarPopupSettings(
11110
+ "quickCreateAction",
11111
+ quickCreatePopupSettingsBase,
11112
+ quickCreatePopupSettingsInput
11113
+ ) : void 0;
11114
+ const eventPopupSettings = hasEventPopupChange ? import_lodash.default.isNull(changes.eventPopup) ? eventPopupSettingsInput || {} : this.mergeCalendarPopupSettings("eventViewAction", eventPopupSettingsBase, eventPopupSettingsInput) : void 0;
11115
+ const previousQuickCreateOpenView = this.buildCalendarPopupOpenView({
11116
+ blockNode: current,
11117
+ actionKey: "quickCreateAction",
11118
+ resourceInit: currentResourceInit,
11119
+ popupSettings: currentQuickCreatePopupSettings
11120
+ });
11121
+ const previousEventOpenView = this.buildCalendarPopupOpenView({
11122
+ blockNode: current,
11123
+ actionKey: "eventViewAction",
11124
+ resourceInit: currentResourceInit,
11125
+ popupSettings: currentEventPopupSettings
11126
+ });
10165
11127
  const result = await this.updateSettings(
10166
11128
  {
10167
11129
  target,
@@ -10170,9 +11132,7 @@ class FlowSurfacesService {
10170
11132
  defaultView,
10171
11133
  enableQuickCreateEvent: quickCreateEvent,
10172
11134
  showLunar,
10173
- weekStart,
10174
- quickCreatePopupSettings,
10175
- eventPopupSettings
11135
+ weekStart
10176
11136
  }),
10177
11137
  stepParams: {
10178
11138
  ...cardSettings ? { cardSettings } : {},
@@ -10191,7 +11151,10 @@ class FlowSurfacesService {
10191
11151
  "showLunar",
10192
11152
  "weekStart",
10193
11153
  "dataScope",
10194
- "linkageRules"
11154
+ "linkageRules",
11155
+ "quickCreatePopup",
11156
+ "eventPopup",
11157
+ "resource"
10195
11158
  ]) ? {
10196
11159
  calendarSettings: (0, import_service_utils.buildDefinedPayload)({
10197
11160
  ...(0, import_service_utils.hasOwnDefined)(changes, "titleField") ? { titleField: { titleField: fieldNames.title } } : {},
@@ -10203,20 +11166,39 @@ class FlowSurfacesService {
10203
11166
  ...(0, import_service_utils.hasOwnDefined)(changes, "showLunar") ? { showLunar: { showLunar: showLunar === true } } : {},
10204
11167
  ...(0, import_service_utils.hasOwnDefined)(changes, "weekStart") ? { weekStart: { weekStart } } : {},
10205
11168
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10206
- ...(0, import_service_utils.hasOwnDefined)(changes, "linkageRules") ? { linkageRules: { value: changes.linkageRules } } : {}
11169
+ ...(0, import_service_utils.hasOwnDefined)(changes, "linkageRules") ? { linkageRules: { value: changes.linkageRules } } : {},
11170
+ ...hasQuickCreatePopupChange ? { quickCreatePopupSettings: quickCreatePopupSettings || {} } : resourceChanged ? { quickCreatePopupSettings: quickCreatePopupSettingsBase } : {},
11171
+ ...hasEventPopupChange ? { eventPopupSettings: eventPopupSettings || {} } : resourceChanged ? { eventPopupSettings: eventPopupSettingsBase } : {}
10207
11172
  })
10208
11173
  } : {}
10209
11174
  }
10210
11175
  },
10211
- options
11176
+ {
11177
+ ...options,
11178
+ replacePopupStepParamSubtrees: resourceChanged,
11179
+ skipHiddenPopupHostEnsure: true
11180
+ }
10212
11181
  );
10213
11182
  const reloaded = await this.repository.findModelById(current.uid, {
10214
11183
  transaction: options.transaction,
10215
11184
  includeAsyncNode: true
10216
11185
  });
10217
- await this.ensureCalendarBlockPopupHosts(reloaded, options.transaction);
10218
- return result;
10219
- }
11186
+ await this.ensureCalendarBlockPopupHosts(
11187
+ reloaded,
11188
+ options.transaction,
11189
+ {
11190
+ quickCreateAction: hasQuickCreatePopupChange ? quickCreatePopupSettings : resourceChanged ? quickCreatePopupSettingsBase : void 0,
11191
+ eventViewAction: hasEventPopupChange ? eventPopupSettings : resourceChanged ? eventPopupSettingsBase : void 0
11192
+ },
11193
+ {
11194
+ displayFallbackOpenViews: {
11195
+ quickCreateAction: previousQuickCreateOpenView,
11196
+ eventViewAction: previousEventOpenView
11197
+ }
11198
+ }
11199
+ );
11200
+ return result;
11201
+ }
10220
11202
  async configureTreeBlock(target, current, changes, options) {
10221
11203
  var _a, _b;
10222
11204
  const allowedKeys = (0, import_configure_options.getConfigureOptionKeysForUse)("TreeBlockModel");
@@ -10260,7 +11242,11 @@ class FlowSurfacesService {
10260
11242
  ...(0, import_service_utils.hasOwnDefined)(changes, "titleField") ? { titleField: { titleField: nextFieldNames.title } } : {},
10261
11243
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? { pageSize: { pageSize: changes.pageSize } } : {},
10262
11244
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10263
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {}
11245
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11246
+ defaultSorting: {
11247
+ sort: this.normalizeBlockSortingInput(changes.sorting, "treeSettings.sorting")
11248
+ }
11249
+ } : {}
10264
11250
  })
10265
11251
  } : {}
10266
11252
  }
@@ -10435,20 +11421,44 @@ class FlowSurfacesService {
10435
11421
  const nextDragEnabled = requestedDragEnabled === true && !!nextDragSortBy;
10436
11422
  const nextStyleVariantProp = (0, import_service_utils.hasOwnDefined)(changes, "styleVariant") ? String(changes.styleVariant || "").trim() === "default" ? "default" : "color" : void 0;
10437
11423
  const nextStyleVariantSetting = (0, import_service_utils.hasOwnDefined)(changes, "styleVariant") ? String(changes.styleVariant || "").trim() : void 0;
10438
- const quickCreatePopup = Object.prototype.hasOwnProperty.call(changes, "quickCreatePopup") ? await this.normalizeKanbanPopupConfigureValue({
11424
+ const shouldWriteQuickCreatePopup = Object.prototype.hasOwnProperty.call(changes, "quickCreatePopup");
11425
+ const shouldWriteCardPopup = Object.prototype.hasOwnProperty.call(changes, "cardPopup");
11426
+ const quickCreatePopupInput = shouldWriteQuickCreatePopup ? await this.normalizeKanbanPopupConfigureValue({
10439
11427
  actionName: "configure kanban quickCreatePopup",
10440
11428
  blockUid: current.uid,
10441
11429
  actionKey: "quickCreateAction",
10442
11430
  value: changes.quickCreatePopup,
10443
11431
  transaction: options.transaction
10444
11432
  }) : void 0;
10445
- const cardPopup = Object.prototype.hasOwnProperty.call(changes, "cardPopup") ? await this.normalizeKanbanPopupConfigureValue({
11433
+ const cardPopupInput = shouldWriteCardPopup ? await this.normalizeKanbanPopupConfigureValue({
10446
11434
  actionName: "configure kanban cardPopup",
10447
11435
  blockUid: current.uid,
10448
11436
  actionKey: "cardViewAction",
10449
11437
  value: changes.cardPopup,
10450
11438
  transaction: options.transaction
10451
11439
  }) : void 0;
11440
+ const currentQuickCreatePopupSettings = this.getKanbanPopupStoredSettings(current, "quickCreateAction");
11441
+ const currentCardPopupSettings = this.getKanbanPopupStoredSettings(current, "cardViewAction");
11442
+ const quickCreatePopupBase = resourceChanged ? this.stripKanbanPopupTargetSettingsForResourceChange(
11443
+ "quickCreateAction",
11444
+ currentQuickCreatePopupSettings,
11445
+ current.uid
11446
+ ) : currentQuickCreatePopupSettings;
11447
+ const cardPopupBase = resourceChanged ? this.stripKanbanPopupTargetSettingsForResourceChange("cardViewAction", currentCardPopupSettings, current.uid) : currentCardPopupSettings;
11448
+ const quickCreatePopup = shouldWriteQuickCreatePopup ? import_lodash.default.isNull(changes.quickCreatePopup) ? quickCreatePopupInput || {} : this.mergeKanbanPopupSettings("quickCreateAction", quickCreatePopupBase, quickCreatePopupInput, current.uid) : void 0;
11449
+ const cardPopup = shouldWriteCardPopup ? import_lodash.default.isNull(changes.cardPopup) ? cardPopupInput || {} : this.mergeKanbanPopupSettings("cardViewAction", cardPopupBase, cardPopupInput, current.uid) : void 0;
11450
+ const previousQuickCreateOpenView = this.buildKanbanPopupOpenView({
11451
+ blockNode: current,
11452
+ actionKey: "quickCreateAction",
11453
+ resourceInit: currentResourceInit,
11454
+ popupSettings: currentQuickCreatePopupSettings
11455
+ });
11456
+ const previousCardOpenView = this.buildKanbanPopupOpenView({
11457
+ blockNode: current,
11458
+ actionKey: "cardViewAction",
11459
+ resourceInit: currentResourceInit,
11460
+ popupSettings: currentCardPopupSettings
11461
+ });
10452
11462
  const nextCardLayout = (0, import_service_utils.hasOwnDefined)(changes, "cardLayout") ? (0, import_service_utils.normalizeSimpleLayoutValue)(changes.cardLayout) : void 0;
10453
11463
  const shouldWriteGrouping = resourceChanged || (0, import_service_utils.hasOwnDefined)(changes, "groupField") || (0, import_service_utils.hasOwnDefined)(changes, "groupTitleField") || (0, import_service_utils.hasOwnDefined)(changes, "groupColorField") || (0, import_service_utils.hasOwnDefined)(changes, "groupOptions") || groupFieldChanged;
10454
11464
  const shouldWriteDrag = resourceChanged || (0, import_service_utils.hasOwnDefined)(changes, "dragEnabled") || (0, import_service_utils.hasOwnDefined)(changes, "dragSortBy") || groupFieldChanged;
@@ -10460,7 +11470,7 @@ class FlowSurfacesService {
10460
11470
  groupOptions: nextGroupOptions || []
10461
11471
  } : {},
10462
11472
  ...(0, import_service_utils.hasOwnDefined)(changes, "styleVariant") ? { styleVariant: nextStyleVariantProp } : {},
10463
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { globalSort: changes.sorting } : {},
11473
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { globalSort: this.normalizeBlockSortingInput(changes.sorting, "kanban.globalSort") } : {},
10464
11474
  ...shouldWriteDrag ? {
10465
11475
  dragEnabled: nextDragEnabled,
10466
11476
  dragSortBy: nextDragSortBy ?? null
@@ -10469,14 +11479,7 @@ class FlowSurfacesService {
10469
11479
  quickCreateEnabled: changes.quickCreateEnabled === true
10470
11480
  } : {},
10471
11481
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? { pageSize: changes.pageSize } : {},
10472
- ...(0, import_service_utils.hasOwnDefined)(changes, "columnWidth") ? { columnWidth: changes.columnWidth } : {},
10473
- ...(0, import_service_utils.hasOwnDefined)(changes, "quickCreatePopup") ? {
10474
- popupMode: (quickCreatePopup == null ? void 0 : quickCreatePopup.mode) ?? null,
10475
- popupSize: (quickCreatePopup == null ? void 0 : quickCreatePopup.size) ?? null,
10476
- popupTemplateUid: (quickCreatePopup == null ? void 0 : quickCreatePopup.popupTemplateUid) ?? null,
10477
- popupPageModelClass: (quickCreatePopup == null ? void 0 : quickCreatePopup.pageModelClass) ?? null,
10478
- popupTargetUid: (quickCreatePopup == null ? void 0 : quickCreatePopup.uid) ?? null
10479
- } : {}
11482
+ ...(0, import_service_utils.hasOwnDefined)(changes, "columnWidth") ? { columnWidth: changes.columnWidth } : {}
10480
11483
  });
10481
11484
  const blockStepParams = (0, import_service_utils.buildDefinedPayload)({
10482
11485
  ...blockCardSettings ? { cardSettings: blockCardSettings } : {},
@@ -10485,7 +11488,7 @@ class FlowSurfacesService {
10485
11488
  init: nextResourceInit
10486
11489
  }
10487
11490
  } : {},
10488
- ...shouldWriteGrouping || (0, import_service_utils.hasOwnDefined)(changes, "styleVariant") || (0, import_service_utils.hasOwnDefined)(changes, "sorting") || shouldWriteDrag || (0, import_service_utils.hasOwnDefined)(changes, "quickCreateEnabled") || (0, import_service_utils.hasOwnDefined)(changes, "quickCreatePopup") || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "columnWidth") || (0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? {
11491
+ ...shouldWriteGrouping || (0, import_service_utils.hasOwnDefined)(changes, "styleVariant") || (0, import_service_utils.hasOwnDefined)(changes, "sorting") || shouldWriteDrag || (0, import_service_utils.hasOwnDefined)(changes, "quickCreateEnabled") || shouldWriteQuickCreatePopup || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "columnWidth") || (0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? {
10489
11492
  kanbanSettings: (0, import_service_utils.buildDefinedPayload)({
10490
11493
  ...shouldWriteGrouping ? {
10491
11494
  grouping: (0, import_service_utils.buildDefinedPayload)({
@@ -10502,7 +11505,7 @@ class FlowSurfacesService {
10502
11505
  } : {},
10503
11506
  ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
10504
11507
  defaultSorting: {
10505
- sort: changes.sorting
11508
+ sort: this.normalizeBlockSortingInput(changes.sorting, "kanbanSettings.defaultSorting.sort")
10506
11509
  }
10507
11510
  } : {},
10508
11511
  ...shouldWriteDrag ? {
@@ -10518,7 +11521,7 @@ class FlowSurfacesService {
10518
11521
  quickCreateEnabled: changes.quickCreateEnabled === true
10519
11522
  }
10520
11523
  } : {},
10521
- ...(0, import_service_utils.hasOwnDefined)(changes, "quickCreatePopup") ? {
11524
+ ...shouldWriteQuickCreatePopup ? {
10522
11525
  popup: quickCreatePopup || {}
10523
11526
  } : {},
10524
11527
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? {
@@ -10543,13 +11546,6 @@ class FlowSurfacesService {
10543
11546
  ...(0, import_service_utils.hasOwnDefined)(changes, "enableCardClick") ? {
10544
11547
  enableCardClick: changes.enableCardClick === true
10545
11548
  } : {},
10546
- ...(0, import_service_utils.hasOwnDefined)(changes, "cardPopup") ? {
10547
- openMode: (cardPopup == null ? void 0 : cardPopup.mode) ?? null,
10548
- popupSize: (cardPopup == null ? void 0 : cardPopup.size) ?? null,
10549
- popupTemplateUid: (cardPopup == null ? void 0 : cardPopup.popupTemplateUid) ?? null,
10550
- pageModelClass: (cardPopup == null ? void 0 : cardPopup.pageModelClass) ?? null,
10551
- popupTargetUid: (cardPopup == null ? void 0 : cardPopup.uid) ?? null
10552
- } : {},
10553
11549
  ...(0, import_service_utils.hasOwnDefined)(changes, "cardLayout") ? {
10554
11550
  layout: nextCardLayout
10555
11551
  } : {},
@@ -10559,14 +11555,14 @@ class FlowSurfacesService {
10559
11555
  ...(0, import_service_utils.hasOwnDefined)(changes, "cardColon") ? { colon: changes.cardColon === true } : {}
10560
11556
  });
10561
11557
  const itemStepParams = (0, import_service_utils.buildDefinedPayload)({
10562
- ...(0, import_service_utils.hasOwnDefined)(changes, "enableCardClick") || (0, import_service_utils.hasOwnDefined)(changes, "cardPopup") || (0, import_service_utils.hasOwnDefined)(changes, "cardLayout") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelAlign") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWidth") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWrap") || (0, import_service_utils.hasOwnDefined)(changes, "cardColon") ? {
11558
+ ...(0, import_service_utils.hasOwnDefined)(changes, "enableCardClick") || shouldWriteCardPopup || (0, import_service_utils.hasOwnDefined)(changes, "cardLayout") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelAlign") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWidth") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWrap") || (0, import_service_utils.hasOwnDefined)(changes, "cardColon") ? {
10563
11559
  cardSettings: (0, import_service_utils.buildDefinedPayload)({
10564
11560
  ...(0, import_service_utils.hasOwnDefined)(changes, "enableCardClick") ? {
10565
11561
  click: {
10566
11562
  enableCardClick: changes.enableCardClick === true
10567
11563
  }
10568
11564
  } : {},
10569
- ...(0, import_service_utils.hasOwnDefined)(changes, "cardPopup") ? {
11565
+ ...shouldWriteCardPopup ? {
10570
11566
  popup: cardPopup || {}
10571
11567
  } : {},
10572
11568
  ...(0, import_service_utils.hasOwnDefined)(changes, "cardLayout") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelAlign") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWidth") || (0, import_service_utils.hasOwnDefined)(changes, "cardLabelWrap") || (0, import_service_utils.hasOwnDefined)(changes, "cardColon") ? {
@@ -10589,7 +11585,11 @@ class FlowSurfacesService {
10589
11585
  props: blockProps,
10590
11586
  stepParams: blockStepParams
10591
11587
  },
10592
- options
11588
+ {
11589
+ ...options,
11590
+ replacePopupStepParamSubtrees: resourceChanged,
11591
+ skipHiddenPopupHostEnsure: true
11592
+ }
10593
11593
  );
10594
11594
  import_lodash.default.castArray((blockResult == null ? void 0 : blockResult.updated) || []).forEach((key) => updated.add(String(key)));
10595
11595
  }
@@ -10602,7 +11602,11 @@ class FlowSurfacesService {
10602
11602
  props: itemProps,
10603
11603
  stepParams: itemStepParams
10604
11604
  },
10605
- options
11605
+ {
11606
+ ...options,
11607
+ replacePopupStepParamSubtrees: resourceChanged,
11608
+ skipHiddenPopupHostEnsure: true
11609
+ }
10606
11610
  );
10607
11611
  import_lodash.default.castArray((itemResult == null ? void 0 : itemResult.updated) || []).forEach((key) => updated.add(String(key)));
10608
11612
  }
@@ -10610,7 +11614,37 @@ class FlowSurfacesService {
10610
11614
  transaction: options.transaction,
10611
11615
  includeAsyncNode: true
10612
11616
  });
10613
- await this.ensureKanbanBlockPopupHosts(reloaded, options.transaction);
11617
+ const popupSettingsStorageNode = reloaded || current;
11618
+ if (resourceChanged && !shouldWriteQuickCreatePopup) {
11619
+ await this.replaceKanbanStoredPopupSettings(
11620
+ popupSettingsStorageNode,
11621
+ "quickCreateAction",
11622
+ quickCreatePopupBase,
11623
+ options.transaction
11624
+ );
11625
+ }
11626
+ if (resourceChanged && !shouldWriteCardPopup) {
11627
+ await this.replaceKanbanStoredPopupSettings(
11628
+ popupSettingsStorageNode,
11629
+ "cardViewAction",
11630
+ cardPopupBase,
11631
+ options.transaction
11632
+ );
11633
+ }
11634
+ await this.ensureKanbanBlockPopupHosts(
11635
+ reloaded,
11636
+ options.transaction,
11637
+ {
11638
+ quickCreateAction: shouldWriteQuickCreatePopup ? quickCreatePopup || {} : resourceChanged ? quickCreatePopupBase : void 0,
11639
+ cardViewAction: shouldWriteCardPopup ? cardPopup || {} : resourceChanged ? cardPopupBase : void 0
11640
+ },
11641
+ {
11642
+ displayFallbackOpenViews: {
11643
+ quickCreateAction: previousQuickCreateOpenView,
11644
+ cardViewAction: previousCardOpenView
11645
+ }
11646
+ }
11647
+ );
10614
11648
  return (0, import_service_utils.buildDefinedPayload)({
10615
11649
  uid: current.uid,
10616
11650
  ...updated.size ? { updated: Array.from(updated) } : {}
@@ -10710,7 +11744,11 @@ class FlowSurfacesService {
10710
11744
  colon: changes.colon
10711
11745
  })
10712
11746
  } : {},
10713
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11747
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11748
+ defaultSorting: {
11749
+ sort: this.normalizeBlockSortingInput(changes.sorting, "detailsSettings.sorting")
11750
+ }
11751
+ } : {},
10714
11752
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10715
11753
  ...(0, import_service_utils.hasOwnDefined)(changes, "linkageRules") ? { linkageRules: { value: changes.linkageRules } } : {}
10716
11754
  })
@@ -10780,7 +11818,11 @@ class FlowSurfacesService {
10780
11818
  listSettings: (0, import_service_utils.buildDefinedPayload)({
10781
11819
  ...(0, import_service_utils.hasOwnDefined)(changes, "pageSize") ? { pageSize: { pageSize: changes.pageSize } } : {},
10782
11820
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10783
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11821
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11822
+ defaultSorting: {
11823
+ sort: this.normalizeBlockSortingInput(changes.sorting, "listSettings.sorting")
11824
+ }
11825
+ } : {},
10784
11826
  ...(0, import_service_utils.hasOwnDefined)(changes, "layout") ? { layout: { layout: layoutValue } } : {}
10785
11827
  })
10786
11828
  } : {}
@@ -10810,7 +11852,11 @@ class FlowSurfacesService {
10810
11852
  ...columns ? { columnCount: { columnCount: columns } } : {},
10811
11853
  ...(0, import_service_utils.hasOwnDefined)(changes, "rowCount") ? { rowCount: { rowCount: changes.rowCount } } : {},
10812
11854
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10813
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { defaultSorting: { sort: changes.sorting } } : {},
11855
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
11856
+ defaultSorting: {
11857
+ sort: this.normalizeBlockSortingInput(changes.sorting, "GridCardSettings.sorting")
11858
+ }
11859
+ } : {},
10814
11860
  ...(0, import_service_utils.hasOwnDefined)(changes, "layout") ? { layout: { layout: layoutValue } } : {}
10815
11861
  })
10816
11862
  } : {}
@@ -10987,7 +12033,11 @@ class FlowSurfacesService {
10987
12033
  })
10988
12034
  } : {},
10989
12035
  ...(0, import_service_utils.hasOwnDefined)(changes, "dataScope") ? { dataScope: { filter: changes.dataScope } } : {},
10990
- ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? { lineSort: { sort: changes.sorting } } : {},
12036
+ ...(0, import_service_utils.hasOwnDefined)(changes, "sorting") ? {
12037
+ lineSort: {
12038
+ sort: this.normalizeMapSortingInput(changes.sorting, "createMapBlock.lineSort.sort")
12039
+ }
12040
+ } : {},
10991
12041
  ...(0, import_service_utils.hasOwnDefined)(changes, "zoom") ? { mapZoom: { zoom: changes.zoom } } : {}
10992
12042
  })
10993
12043
  } : {}
@@ -11162,7 +12212,6 @@ class FlowSurfacesService {
11162
12212
  "version",
11163
12213
  "fieldType",
11164
12214
  "fields",
11165
- "selectorFields",
11166
12215
  "openMode",
11167
12216
  "popupSize",
11168
12217
  "pageSize",
@@ -11277,7 +12326,7 @@ class FlowSurfacesService {
11277
12326
  let effectiveInnerFieldUse = innerField == null ? void 0 : innerField.use;
11278
12327
  let fieldTypeResolution;
11279
12328
  let relationTitleFieldToApply;
11280
- if ((0, import_service_utils.hasOwnDefined)(changes, "fieldType") || (0, import_service_utils.hasOwnDefined)(changes, "fields") || (0, import_service_utils.hasOwnDefined)(changes, "selectorFields") || (0, import_service_utils.hasOwnDefined)(changes, "titleField") || (0, import_service_utils.hasOwnDefined)(changes, "openMode") || (0, import_service_utils.hasOwnDefined)(changes, "popupSize") || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "showIndex")) {
12329
+ if ((0, import_service_utils.hasOwnDefined)(changes, "fieldType") || (0, import_service_utils.hasOwnDefined)(changes, "fields") || (0, import_service_utils.hasOwnDefined)(changes, "titleField") || (0, import_service_utils.hasOwnDefined)(changes, "openMode") || (0, import_service_utils.hasOwnDefined)(changes, "popupSize") || (0, import_service_utils.hasOwnDefined)(changes, "pageSize") || (0, import_service_utils.hasOwnDefined)(changes, "showIndex")) {
11281
12330
  if (!innerUid) {
11282
12331
  (0, import_errors.throwConflict)(
11283
12332
  `flowSurfaces configure field wrapper '${current == null ? void 0 : current.use}' cannot resolve inner field`,
@@ -11296,7 +12345,6 @@ class FlowSurfacesService {
11296
12345
  dataSourceKey: (_l = fieldSource.fieldSettingsInit) == null ? void 0 : _l.dataSourceKey,
11297
12346
  getCollection: (dataSourceKey, collectionName) => this.getCollection(dataSourceKey, collectionName),
11298
12347
  fields: changes.fields,
11299
- selectorFields: changes.selectorFields,
11300
12348
  titleField: (0, import_service_utils.hasOwnDefined)(wrapperChanges, "titleField") ? wrapperChanges.titleField : void 0,
11301
12349
  openMode: (0, import_service_utils.hasOwnDefined)(changes, "openMode") ? changes.openMode : void 0,
11302
12350
  popupSize: (0, import_service_utils.hasOwnDefined)(changes, "popupSize") ? changes.popupSize : void 0,
@@ -11327,7 +12375,7 @@ class FlowSurfacesService {
11327
12375
  targetCollection: fieldTypeResolution.targetCollection,
11328
12376
  relationFieldInit: fieldSource.fieldSettingsInit,
11329
12377
  fields: (0, import_service_utils.hasOwnDefined)(changes, "fields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.fields : void 0,
11330
- selectorFields: (0, import_service_utils.hasOwnDefined)(changes, "selectorFields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.selectorFields : void 0,
12378
+ selectorFields: (0, import_service_utils.hasOwnDefined)(changes, "fields") || shouldApplyFieldTypeDefaults ? fieldTypeResolution.selectorFields : void 0,
11331
12379
  titleField: relationTitleFieldToApply,
11332
12380
  openMode: fieldTypeResolution.openMode,
11333
12381
  popupSize: fieldTypeResolution.popupSize,
@@ -11547,7 +12595,17 @@ class FlowSurfacesService {
11547
12595
  }
11548
12596
  return import_lodash.default.cloneDeep(value);
11549
12597
  }
12598
+ normalizeActionAssignValues(actionName, value) {
12599
+ if (!import_lodash.default.isPlainObject(value)) {
12600
+ (0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} assignValues must be an object`);
12601
+ }
12602
+ return import_lodash.default.cloneDeep(value);
12603
+ }
11550
12604
  async configureActionNode(target, use, changes, options) {
12605
+ const currentNode = options.current || (target.uid ? await this.repository.findModelById(target.uid, {
12606
+ transaction: options.transaction,
12607
+ includeAsyncNode: true
12608
+ }) : null);
11551
12609
  changes = await this.normalizeActionPanelActionChanges(changes, options);
11552
12610
  const allowedKeys = (0, import_configure_options.getConfigureOptionKeysForUse)(use);
11553
12611
  (0, import_service_utils.assertSupportedSimpleChanges)("action", changes, allowedKeys);
@@ -11615,8 +12673,12 @@ class FlowSurfacesService {
11615
12673
  } else if (!POPUP_ACTION_USES.has(use)) {
11616
12674
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support openView`);
11617
12675
  } else {
12676
+ let openView = import_lodash.default.cloneDeep(changes.openView);
12677
+ if (use === "AddChildActionModel") {
12678
+ openView = await this.normalizeAddChildOpenViewForAction(currentNode, openView, options.transaction);
12679
+ }
11618
12680
  stepParams.popupSettings = {
11619
- openView: import_lodash.default.cloneDeep(changes.openView)
12681
+ openView
11620
12682
  };
11621
12683
  }
11622
12684
  }
@@ -11634,7 +12696,7 @@ class FlowSurfacesService {
11634
12696
  stepParams.submitSettings = {
11635
12697
  confirm: (0, import_service_utils.normalizeSimpleConfirm)(changes.confirm)
11636
12698
  };
11637
- } else if (["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
12699
+ } else if (UPDATE_ASSIGN_ACTION_USES.has(use)) {
11638
12700
  stepParams.assignSettings = {
11639
12701
  confirm: (0, import_service_utils.normalizeSimpleConfirm)(changes.confirm)
11640
12702
  };
@@ -11643,25 +12705,26 @@ class FlowSurfacesService {
11643
12705
  }
11644
12706
  }
11645
12707
  if ((0, import_service_utils.hasOwnDefined)(changes, "assignValues")) {
12708
+ const assignValues = this.normalizeActionAssignValues("configure", changes.assignValues);
11646
12709
  if (APPROVAL_ASSIGN_ACTION_USES.has(use)) {
11647
12710
  stepParams.clickSettings = {
11648
12711
  ...stepParams.clickSettings || {},
11649
12712
  assignFieldValues: {
11650
- assignedValues: changes.assignValues
12713
+ assignedValues: assignValues
11651
12714
  }
11652
12715
  };
11653
- } else if (!["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
12716
+ } else if (!UPDATE_ASSIGN_ACTION_USES.has(use)) {
11654
12717
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support assignValues`);
11655
12718
  } else {
11656
12719
  stepParams.assignSettings = {
11657
12720
  ...stepParams.assignSettings || {},
11658
12721
  assignFieldValues: {
11659
- assignedValues: changes.assignValues
12722
+ assignedValues: assignValues
11660
12723
  }
11661
12724
  };
11662
12725
  stepParams.apply = {
11663
12726
  apply: {
11664
- assignedValues: changes.assignValues
12727
+ assignedValues: assignValues
11665
12728
  }
11666
12729
  };
11667
12730
  }
@@ -11677,7 +12740,7 @@ class FlowSurfacesService {
11677
12740
  };
11678
12741
  }
11679
12742
  if ((0, import_service_utils.hasOwnDefined)(changes, "updateMode")) {
11680
- if (!["UpdateRecordActionModel", "BulkUpdateActionModel"].includes(use)) {
12743
+ if (!UPDATE_ASSIGN_ACTION_USES.has(use)) {
11681
12744
  (0, import_errors.throwBadRequest)(`flowSurfaces configure action '${use}' does not support updateMode`);
11682
12745
  }
11683
12746
  stepParams.assignSettings = {
@@ -11744,24 +12807,25 @@ class FlowSurfacesService {
11744
12807
  })
11745
12808
  };
11746
12809
  }
12810
+ const props = (0, import_service_utils.buildDefinedPayload)({
12811
+ title: changes.title,
12812
+ tooltip: changes.tooltip,
12813
+ icon: changes.icon,
12814
+ type: changes.type,
12815
+ htmlType: changes.htmlType,
12816
+ position: changes.position,
12817
+ danger: changes.danger,
12818
+ color: changes.color,
12819
+ ...(0, import_service_utils.hasOwnDefined)(changes, "filterableFieldNames") ? { filterableFieldNames: import_lodash.default.cloneDeep(changes.filterableFieldNames) } : {},
12820
+ ...(0, import_service_utils.hasOwnDefined)(changes, "defaultFilter") ? {
12821
+ defaultFilterValue: normalizedDefaultFilter,
12822
+ filterValue: import_lodash.default.cloneDeep(normalizedDefaultFilter)
12823
+ } : {}
12824
+ });
11747
12825
  return this.updateSettings(
11748
12826
  {
11749
12827
  target,
11750
- props: (0, import_service_utils.buildDefinedPayload)({
11751
- title: changes.title,
11752
- tooltip: changes.tooltip,
11753
- icon: changes.icon,
11754
- type: changes.type,
11755
- htmlType: changes.htmlType,
11756
- position: changes.position,
11757
- danger: changes.danger,
11758
- color: changes.color,
11759
- ...(0, import_service_utils.hasOwnDefined)(changes, "filterableFieldNames") ? { filterableFieldNames: import_lodash.default.cloneDeep(changes.filterableFieldNames) } : {},
11760
- ...(0, import_service_utils.hasOwnDefined)(changes, "defaultFilter") ? {
11761
- defaultFilterValue: normalizedDefaultFilter,
11762
- filterValue: import_lodash.default.cloneDeep(normalizedDefaultFilter)
11763
- } : {}
11764
- }),
12828
+ ...Object.keys(props).length ? { props } : {},
11765
12829
  stepParams: Object.keys(stepParams).length ? stepParams : void 0
11766
12830
  },
11767
12831
  {
@@ -12909,13 +13973,100 @@ class FlowSurfacesService {
12909
13973
  ) || (field == null ? void 0 : field.targetCollection) || null;
12910
13974
  }
12911
13975
  resolvePopupHostOpenView(node) {
12912
- for (const [flowKey, stepKey] of import_template_service_utils.POPUP_HOST_STEP_PARAM_PATHS) {
12913
- const openView = import_lodash.default.get(node, ["stepParams", flowKey, stepKey]);
12914
- if (import_lodash.default.isPlainObject(openView)) {
12915
- return openView;
13976
+ return (0, import_hidden_popup_contract.resolveHiddenPopupHostOpenView)(node);
13977
+ }
13978
+ popupHostHasLocalContent(actionNode) {
13979
+ return (0, import_hidden_popup_contract.hiddenPopupHostHasLocalContent)(actionNode);
13980
+ }
13981
+ shouldAutoBindPopupTemplate(openView, popupSettings, expectedHostUid, hostNode) {
13982
+ return (0, import_hidden_popup_contract.shouldAutoBindHiddenPopupTemplate)(openView, popupSettings, expectedHostUid, {
13983
+ hostHasLocalContent: !!(hostNode == null ? void 0 : hostNode.uid) && this.popupHostHasLocalContent(hostNode)
13984
+ });
13985
+ }
13986
+ async patchPopupOpenViewIfChanged(actionUid, openView, transaction) {
13987
+ const actionNode = await this.repository.findModelById(actionUid, {
13988
+ transaction,
13989
+ includeAsyncNode: true
13990
+ });
13991
+ if (!(actionNode == null ? void 0 : actionNode.uid)) {
13992
+ return false;
13993
+ }
13994
+ const currentOpenView = this.resolvePopupHostOpenView(actionNode);
13995
+ if (import_lodash.default.isEqual(currentOpenView, openView)) {
13996
+ return false;
13997
+ }
13998
+ await this.repository.patch(
13999
+ {
14000
+ uid: actionUid,
14001
+ stepParams: (0, import_hidden_popup_contract.buildHiddenPopupActionStepParams)(actionNode.stepParams, openView)
14002
+ },
14003
+ { transaction }
14004
+ );
14005
+ return true;
14006
+ }
14007
+ async buildPopupOpenViewWithTemplate(input) {
14008
+ var _a;
14009
+ const hasExplicitTargetSettings = (0, import_hidden_popup_contract.hasExplicitHiddenPopupTargetSettings)(input.popupSettings, input.actionUid);
14010
+ const shouldAutoBind = this.shouldAutoBindPopupTemplate(
14011
+ input.openView,
14012
+ input.popupSettings,
14013
+ input.actionUid,
14014
+ input.existingHost
14015
+ );
14016
+ if (!hasExplicitTargetSettings && !shouldAutoBind) {
14017
+ return input.openView;
14018
+ }
14019
+ const openViewForNormalize = shouldAutoBind && String(((_a = input.openView) == null ? void 0 : _a.uid) || "").trim() === input.actionUid ? { ...input.openView, uid: void 0, tryTemplate: true } : shouldAutoBind ? { ...input.openView, tryTemplate: true } : input.openView;
14020
+ const normalized = await this.normalizeOpenView(input.actionName, openViewForNormalize, {
14021
+ transaction: input.transaction,
14022
+ popupTemplateHostUid: input.actionUid,
14023
+ popupActionContext: {
14024
+ hasCurrentRecord: !!input.hasCurrentRecord
12916
14025
  }
14026
+ });
14027
+ const normalizedOpenView = input.normalizePopupSettings(normalized || input.openView);
14028
+ return input.mergeDisplaySettings(
14029
+ (0, import_service_utils.buildDefinedPayload)({
14030
+ ...input.openView,
14031
+ ...normalizedOpenView,
14032
+ uid: normalizedOpenView.uid || input.openView.uid,
14033
+ collectionName: normalizedOpenView.collectionName || input.openView.collectionName,
14034
+ dataSourceKey: normalizedOpenView.dataSourceKey || input.openView.dataSourceKey
14035
+ }),
14036
+ input.popupSettings,
14037
+ input.openView
14038
+ );
14039
+ }
14040
+ async completePopupHostDefaultContent(input) {
14041
+ const popup = (0, import_hidden_popup_contract.buildImplicitHiddenPopupDefaultContent)(input.popupSettings);
14042
+ if (!popup) {
14043
+ return;
12917
14044
  }
12918
- return null;
14045
+ await this.applyInlineActionPopup(input.actionName, input.actionUid, popup, {
14046
+ transaction: input.transaction,
14047
+ popupActionContext: {
14048
+ hasCurrentRecord: !!input.hasCurrentRecord
14049
+ }
14050
+ });
14051
+ }
14052
+ async ensurePopupHostDefaultContent(input) {
14053
+ let actionNode = await this.repository.findModelById(input.actionUid, {
14054
+ transaction: input.transaction,
14055
+ includeAsyncNode: true
14056
+ });
14057
+ const openView = this.resolvePopupHostOpenView(actionNode);
14058
+ if (!this.shouldAutoBindPopupTemplate(openView, input.popupSettings, input.actionUid) || String((openView == null ? void 0 : openView.popupTemplateUid) || "").trim() || this.popupHostHasLocalContent(actionNode)) {
14059
+ return false;
14060
+ }
14061
+ await this.completePopupHostDefaultContent(input);
14062
+ actionNode = await this.repository.findModelById(input.actionUid, {
14063
+ transaction: input.transaction,
14064
+ includeAsyncNode: true
14065
+ });
14066
+ const completedOpenView = this.resolvePopupHostOpenView(actionNode);
14067
+ const mergedCompletedOpenView = input.mergeDisplaySettings(completedOpenView, input.popupSettings, openView);
14068
+ await this.patchPopupOpenViewIfChanged(input.actionUid, mergedCompletedOpenView, input.transaction);
14069
+ return true;
12919
14070
  }
12920
14071
  resolvePopupSourceRecordCollectionName(popupAssociationName, hostContext) {
12921
14072
  var _a, _b, _c;
@@ -13193,108 +14344,60 @@ class FlowSurfacesService {
13193
14344
  });
13194
14345
  }
13195
14346
  normalizeKanbanPopupSettings(actionKey, popupSettings, blockUid) {
13196
- const nextParams = import_lodash.default.cloneDeep(popupSettings || {});
13197
- const actionUid = blockUid && actionKey ? this.getKanbanPopupActionUid(blockUid, actionKey) : void 0;
13198
- const popupTemplateUidProvided = Object.prototype.hasOwnProperty.call(nextParams, "popupTemplateUid");
13199
- const popupTemplateUid = typeof nextParams.popupTemplateUid === "string" ? nextParams.popupTemplateUid.trim() : nextParams.popupTemplateUid;
13200
- if (popupTemplateUidProvided && (popupTemplateUid === void 0 || popupTemplateUid === null || popupTemplateUid === "")) {
13201
- delete nextParams.popupTemplateUid;
13202
- delete nextParams.popupTemplateContext;
13203
- delete nextParams.popupTemplateHasFilterByTk;
13204
- delete nextParams.popupTemplateHasSourceId;
13205
- delete nextParams.uid;
13206
- }
13207
- const normalizedUid = typeof nextParams.uid === "string" ? nextParams.uid.trim() : nextParams.uid;
13208
- if (!normalizedUid || normalizedUid === blockUid || normalizedUid === actionUid) {
13209
- delete nextParams.uid;
13210
- } else {
13211
- nextParams.uid = normalizedUid;
13212
- }
13213
- if (typeof nextParams.mode === "string") {
13214
- nextParams.mode = OPEN_VIEW_MODE_ALIASES[nextParams.mode] || nextParams.mode;
13215
- }
13216
- if (typeof nextParams.size === "string" && !nextParams.size.trim()) {
13217
- delete nextParams.size;
13218
- }
13219
- if (typeof nextParams.pageModelClass === "string" && !nextParams.pageModelClass.trim()) {
13220
- delete nextParams.pageModelClass;
13221
- }
13222
- return nextParams;
13223
- }
13224
- getKanbanPopupActionUse(actionKey) {
13225
- return actionKey === "quickCreateAction" ? "KanbanQuickCreateActionModel" : "KanbanCardViewActionModel";
14347
+ return (0, import_hidden_popup_kanban.normalizeKanbanPopupSettings)(actionKey, popupSettings, blockUid);
13226
14348
  }
13227
14349
  getKanbanPopupActionUid(kanbanUid, actionKey) {
13228
- return `${kanbanUid}${KANBAN_POPUP_ACTION_UID_SUFFIX_BY_KEY[actionKey]}`;
14350
+ return (0, import_hidden_popup_kanban.getKanbanPopupActionUid)(kanbanUid, actionKey);
13229
14351
  }
13230
14352
  getKanbanBlockResourceInit(blockNode) {
13231
- const resourceInit = import_lodash.default.cloneDeep(import_lodash.default.get(blockNode, ["stepParams", "resourceSettings", "init"]) || {});
13232
- if (resourceInit.collectionName && !resourceInit.dataSourceKey) {
13233
- resourceInit.dataSourceKey = "main";
13234
- }
13235
- return resourceInit;
14353
+ return (0, import_hidden_popup_kanban.getKanbanBlockResourceInit)(blockNode);
14354
+ }
14355
+ buildKanbanInitialStepParams(input) {
14356
+ return (0, import_hidden_popup_kanban.buildKanbanInitialStepParams)(input);
14357
+ }
14358
+ buildKanbanInitialItemProps(input) {
14359
+ return (0, import_hidden_popup_kanban.buildKanbanInitialItemProps)(input);
14360
+ }
14361
+ buildKanbanInitialItemStepParams(input) {
14362
+ return (0, import_hidden_popup_kanban.buildKanbanInitialItemStepParams)(input);
13236
14363
  }
13237
14364
  getKanbanPopupStoredSettings(blockNode, actionKey) {
13238
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
13239
- const itemNode = (0, import_service_utils.getSingleNodeSubModel)((_a = blockNode == null ? void 0 : blockNode.subModels) == null ? void 0 : _a.item);
13240
- const rawPopupSettings = actionKey === "quickCreateAction" ? import_lodash.default.get(blockNode, ["stepParams", "kanbanSettings", "popup"]) || {
13241
- mode: (_b = blockNode == null ? void 0 : blockNode.props) == null ? void 0 : _b.popupMode,
13242
- size: (_c = blockNode == null ? void 0 : blockNode.props) == null ? void 0 : _c.popupSize,
13243
- popupTemplateUid: (_d = blockNode == null ? void 0 : blockNode.props) == null ? void 0 : _d.popupTemplateUid,
13244
- pageModelClass: (_e = blockNode == null ? void 0 : blockNode.props) == null ? void 0 : _e.popupPageModelClass,
13245
- uid: (_f = blockNode == null ? void 0 : blockNode.props) == null ? void 0 : _f.popupTargetUid
13246
- } : import_lodash.default.get(itemNode, ["stepParams", "cardSettings", "popup"]) || {
13247
- mode: (_g = itemNode == null ? void 0 : itemNode.props) == null ? void 0 : _g.openMode,
13248
- size: (_h = itemNode == null ? void 0 : itemNode.props) == null ? void 0 : _h.popupSize,
13249
- popupTemplateUid: (_i = itemNode == null ? void 0 : itemNode.props) == null ? void 0 : _i.popupTemplateUid,
13250
- pageModelClass: (_j = itemNode == null ? void 0 : itemNode.props) == null ? void 0 : _j.pageModelClass,
13251
- uid: (_k = itemNode == null ? void 0 : itemNode.props) == null ? void 0 : _k.popupTargetUid
13252
- };
13253
- return this.normalizeKanbanPopupSettings(actionKey, rawPopupSettings, blockNode == null ? void 0 : blockNode.uid);
14365
+ return (0, import_hidden_popup_kanban.getKanbanPopupStoredSettings)(blockNode, actionKey);
14366
+ }
14367
+ mergeKanbanPopupSettings(actionKey, current, value, blockUid) {
14368
+ return (0, import_hidden_popup_kanban.mergeKanbanPopupSettings)(actionKey, current, value, blockUid);
14369
+ }
14370
+ stripKanbanPopupTargetSettingsForResourceChange(actionKey, popupSettings, blockUid) {
14371
+ return (0, import_hidden_popup_kanban.stripKanbanPopupTargetSettingsForResourceChange)(actionKey, popupSettings, blockUid);
13254
14372
  }
13255
14373
  buildKanbanPopupOpenView(input) {
13256
- const actionUid = this.getKanbanPopupActionUid(input.blockNode.uid, input.actionKey);
13257
- const resourceInit = input.resourceInit || this.getKanbanBlockResourceInit(input.blockNode);
13258
- const defaults = (0, import_service_utils.buildDefinedPayload)({
13259
- mode: "drawer",
13260
- size: "medium",
13261
- pageModelClass: "ChildPageModel",
13262
- uid: actionUid,
13263
- collectionName: resourceInit.collectionName,
13264
- dataSourceKey: resourceInit.dataSourceKey || (resourceInit.collectionName ? "main" : void 0)
13265
- });
13266
- const current = this.getKanbanPopupStoredSettings(input.blockNode, input.actionKey);
13267
- return (0, import_service_utils.buildDefinedPayload)({
13268
- ...defaults,
13269
- ...current,
13270
- uid: current.uid || defaults.uid,
13271
- collectionName: current.collectionName || defaults.collectionName,
13272
- dataSourceKey: current.dataSourceKey || defaults.dataSourceKey
13273
- });
14374
+ return (0, import_hidden_popup_kanban.buildKanbanPopupOpenView)(input);
13274
14375
  }
13275
14376
  async normalizeKanbanPopupConfigureValue(input) {
13276
- if (import_lodash.default.isUndefined(input.value)) {
13277
- return void 0;
13278
- }
13279
- if (import_lodash.default.isNull(input.value)) {
13280
- return {};
13281
- }
13282
- const actionUid = this.getKanbanPopupActionUid(input.blockUid, input.actionKey);
13283
- const normalized = await this.normalizeOpenView(input.actionName, input.value, {
13284
- transaction: input.transaction,
13285
- popupTemplateHostUid: actionUid,
13286
- popupActionContext: {
13287
- hasCurrentRecord: input.actionKey === "cardViewAction"
13288
- }
14377
+ return (0, import_hidden_popup_kanban.normalizeKanbanPopupConfigureValue)({
14378
+ ...input,
14379
+ normalizeOpenView: (actionName, value, options) => this.normalizeOpenView(actionName, value, options)
13289
14380
  });
13290
- return this.normalizeKanbanPopupSettings(input.actionKey, normalized || {}, input.blockUid);
13291
14381
  }
13292
14382
  buildKanbanInitialBlockProps(input) {
13293
14383
  const { collection, collectionName, dataSourceKey } = this.assertKanbanCollectionCompatible(
13294
14384
  input.actionName,
13295
14385
  input.resourceInit
13296
14386
  );
13297
- const currentProps = import_lodash.default.cloneDeep(input.props || {});
14387
+ const currentProps = {
14388
+ ...import_lodash.default.isPlainObject(input.settings) ? import_lodash.default.pick(input.settings, [
14389
+ "groupField",
14390
+ "groupOptions",
14391
+ "groupTitleField",
14392
+ "groupColorField",
14393
+ "styleVariant",
14394
+ "dragEnabled",
14395
+ "dragSortBy",
14396
+ "quickCreateEnabled",
14397
+ "globalSort"
14398
+ ]) : {},
14399
+ ...import_lodash.default.cloneDeep(input.props || {})
14400
+ };
13298
14401
  const defaultGroupFieldName = this.getKanbanDefaultGroupFieldName(collection);
13299
14402
  const nextGroupFieldName = String(currentProps.groupField || defaultGroupFieldName || "").trim();
13300
14403
  const nextGroupField = this.getKanbanGroupField(collection, nextGroupFieldName);
@@ -13351,7 +14454,7 @@ class FlowSurfacesService {
13351
14454
  kind: "groupColorField"
13352
14455
  });
13353
14456
  }
13354
- return (0, import_service_utils.buildDefinedPayload)({
14457
+ const props = (0, import_service_utils.buildDefinedPayload)({
13355
14458
  ...currentProps,
13356
14459
  groupField: nextGroupFieldName,
13357
14460
  groupTitleField: nextGroupTitleField,
@@ -13360,8 +14463,26 @@ class FlowSurfacesService {
13360
14463
  styleVariant: currentProps.styleVariant || "color",
13361
14464
  quickCreateEnabled: currentProps.quickCreateEnabled === true,
13362
14465
  dragEnabled: nextDragEnabled,
13363
- dragSortBy: nextDragSortBy || void 0
13364
- });
14466
+ dragSortBy: nextDragSortBy || void 0,
14467
+ ...Object.prototype.hasOwnProperty.call(currentProps, "globalSort") ? { globalSort: this.normalizeBlockSortingInput(currentProps.globalSort, "kanban.globalSort") } : {}
14468
+ });
14469
+ delete props.quickCreatePopup;
14470
+ delete props.quickCreatePopupSettings;
14471
+ delete props.cardPopup;
14472
+ delete props.cardPopupSettings;
14473
+ for (const propKey of import_hidden_popup_kanban.KANBAN_BLOCK_POPUP_PROP_KEYS) {
14474
+ delete props[propKey];
14475
+ }
14476
+ for (const propKey of [
14477
+ "cardOpenMode",
14478
+ "cardPopupSize",
14479
+ "cardPopupTemplateUid",
14480
+ "cardPopupPageModelClass",
14481
+ "cardPopupTargetUid"
14482
+ ]) {
14483
+ delete props[propKey];
14484
+ }
14485
+ return props;
13365
14486
  }
13366
14487
  normalizeCalendarFieldPathInput(value, context, options = {}) {
13367
14488
  if (import_lodash.default.isUndefined(value)) {
@@ -13577,86 +14698,50 @@ class FlowSurfacesService {
13577
14698
  });
13578
14699
  }
13579
14700
  normalizeCalendarPopupSettings(actionKey, popupSettings) {
13580
- const nextParams = import_lodash.default.cloneDeep(popupSettings || {});
13581
- const popupTemplateUidProvided = Object.prototype.hasOwnProperty.call(nextParams, "popupTemplateUid");
13582
- const popupTemplateUid = typeof nextParams.popupTemplateUid === "string" ? nextParams.popupTemplateUid.trim() : nextParams.popupTemplateUid;
13583
- if (popupTemplateUidProvided && (popupTemplateUid === void 0 || popupTemplateUid === null || popupTemplateUid === "")) {
13584
- delete nextParams.popupTemplateUid;
13585
- delete nextParams.popupTemplateContext;
13586
- delete nextParams.popupTemplateHasFilterByTk;
13587
- delete nextParams.popupTemplateHasSourceId;
13588
- delete nextParams.uid;
13589
- }
13590
- if (actionKey === "quickCreateAction") {
13591
- const hasRecordScopedTemplate = !!nextParams.popupTemplateHasFilterByTk || !!nextParams.popupTemplateHasSourceId || !import_lodash.default.isUndefined(nextParams.filterByTk) || !import_lodash.default.isUndefined(nextParams.sourceId) || !!String(nextParams.associationName || "").trim();
13592
- if (hasRecordScopedTemplate) {
13593
- delete nextParams.popupTemplateUid;
13594
- delete nextParams.popupTemplateContext;
13595
- delete nextParams.popupTemplateHasFilterByTk;
13596
- delete nextParams.popupTemplateHasSourceId;
13597
- delete nextParams.uid;
13598
- }
13599
- delete nextParams.associationName;
13600
- delete nextParams.filterByTk;
13601
- delete nextParams.sourceId;
13602
- }
13603
- return nextParams;
13604
- }
13605
- getCalendarPopupActionUse(actionKey) {
13606
- return actionKey === "quickCreateAction" ? "CalendarQuickCreateActionModel" : "CalendarEventViewActionModel";
14701
+ return (0, import_hidden_popup_calendar.normalizeCalendarPopupSettings)(actionKey, popupSettings);
13607
14702
  }
13608
- getCalendarPopupPropKey(actionKey) {
13609
- return actionKey === "quickCreateAction" ? "quickCreatePopupSettings" : "eventPopupSettings";
14703
+ getCalendarBlockResourceInit(blockNode) {
14704
+ return (0, import_hidden_popup_calendar.getCalendarBlockResourceInit)(blockNode);
13610
14705
  }
13611
- getCalendarPopupActionUid(calendarUid, actionKey) {
13612
- return `${calendarUid}-${actionKey}`;
14706
+ getCalendarPopupStoredSettings(blockNode, actionKey) {
14707
+ return (0, import_hidden_popup_calendar.getCalendarPopupStoredSettings)(blockNode, actionKey);
13613
14708
  }
13614
- getCalendarBlockResourceInit(blockNode) {
13615
- const resourceInit = import_lodash.default.cloneDeep(import_lodash.default.get(blockNode, ["stepParams", "resourceSettings", "init"]) || {});
13616
- if (resourceInit.collectionName && !resourceInit.dataSourceKey) {
13617
- resourceInit.dataSourceKey = "main";
13618
- }
13619
- return resourceInit;
14709
+ getCalendarPopupPropKey(actionKey) {
14710
+ return (0, import_hidden_popup_calendar.getCalendarPopupPropKey)(actionKey);
14711
+ }
14712
+ buildCalendarInitialStepParams(input) {
14713
+ return (0, import_hidden_popup_calendar.buildCalendarInitialStepParams)(input);
13620
14714
  }
13621
14715
  buildCalendarPopupOpenView(input) {
13622
- const actionUid = this.getCalendarPopupActionUid(input.blockNode.uid, input.actionKey);
13623
- const resourceInit = input.resourceInit || this.getCalendarBlockResourceInit(input.blockNode);
13624
- const defaults = (0, import_service_utils.buildDefinedPayload)({
13625
- mode: "drawer",
13626
- size: "medium",
13627
- pageModelClass: "ChildPageModel",
13628
- uid: actionUid,
13629
- collectionName: resourceInit.collectionName,
13630
- dataSourceKey: resourceInit.dataSourceKey || (resourceInit.collectionName ? "main" : void 0)
13631
- });
13632
- const current = this.normalizeCalendarPopupSettings(
13633
- input.actionKey,
13634
- import_lodash.default.get(input.blockNode, ["props", this.getCalendarPopupPropKey(input.actionKey)]) || {}
13635
- );
13636
- return (0, import_service_utils.buildDefinedPayload)({
13637
- ...defaults,
13638
- ...current,
13639
- uid: current.uid || defaults.uid,
13640
- collectionName: current.collectionName || defaults.collectionName,
13641
- dataSourceKey: current.dataSourceKey || defaults.dataSourceKey
13642
- });
14716
+ return (0, import_hidden_popup_calendar.buildCalendarPopupOpenView)(input);
14717
+ }
14718
+ mergeCalendarPopupSettings(actionKey, current, value) {
14719
+ return (0, import_hidden_popup_calendar.mergeCalendarPopupSettings)(actionKey, current, value);
14720
+ }
14721
+ stripCalendarPopupTargetSettingsForResourceChange(actionKey, popupSettings) {
14722
+ return (0, import_hidden_popup_calendar.stripCalendarPopupTargetSettingsForResourceChange)(actionKey, popupSettings);
13643
14723
  }
13644
14724
  async normalizeCalendarPopupConfigureValue(input) {
13645
- if (import_lodash.default.isUndefined(input.value)) {
13646
- return void 0;
13647
- }
13648
- if (import_lodash.default.isNull(input.value)) {
13649
- return {};
13650
- }
13651
- const actionUid = this.getCalendarPopupActionUid(input.blockUid, input.actionKey);
13652
- const normalized = await this.normalizeOpenView(input.actionName, input.value, {
13653
- transaction: input.transaction,
13654
- popupTemplateHostUid: actionUid,
13655
- popupActionContext: {
13656
- hasCurrentRecord: input.actionKey === "eventViewAction"
13657
- }
14725
+ return (0, import_hidden_popup_calendar.normalizeCalendarPopupConfigureValue)({
14726
+ ...input,
14727
+ normalizeOpenView: (actionName, value, options) => this.normalizeOpenView(actionName, value, options)
13658
14728
  });
13659
- return this.normalizeCalendarPopupSettings(input.actionKey, normalized || {});
14729
+ }
14730
+ normalizeCalendarInlineSettingsForConfigure(settings) {
14731
+ return (0, import_hidden_popup_calendar.normalizeCalendarInlineSettingsForConfigure)(settings);
14732
+ }
14733
+ omitHiddenPopupSettingsForConfigure(settings, type) {
14734
+ if (!import_lodash.default.isPlainObject(settings)) {
14735
+ return settings;
14736
+ }
14737
+ const omittedKeys = type === "calendar" ? ["quickCreatePopup", "eventPopup", "quickCreatePopupSettings", "eventPopupSettings"] : ["quickCreatePopup", "cardPopup", "quickCreatePopupSettings", "cardPopupSettings"];
14738
+ return import_lodash.default.omit(settings, omittedKeys);
14739
+ }
14740
+ resolveCalendarInitialPopupOverride(settings, primaryKey, legacyKey) {
14741
+ return (0, import_hidden_popup_calendar.resolveCalendarInitialPopupOverride)(settings, primaryKey, legacyKey);
14742
+ }
14743
+ resolveKanbanInitialPopupOverride(settings, primaryKey, legacyKey) {
14744
+ return (0, import_hidden_popup_kanban.resolveKanbanInitialPopupOverride)(settings, primaryKey, legacyKey);
13660
14745
  }
13661
14746
  buildCalendarInitialBlockProps(input) {
13662
14747
  const { collection, collectionName } = this.assertCalendarCollectionCompatible(
@@ -13664,7 +14749,7 @@ class FlowSurfacesService {
13664
14749
  input.resourceInit
13665
14750
  );
13666
14751
  const currentProps = import_lodash.default.cloneDeep(input.props || {});
13667
- return {
14752
+ const props = {
13668
14753
  ...currentProps,
13669
14754
  fieldNames: this.normalizeCalendarFieldNamesForCollection({
13670
14755
  actionName: input.actionName,
@@ -13677,259 +14762,83 @@ class FlowSurfacesService {
13677
14762
  enableQuickCreateEvent: typeof currentProps.enableQuickCreateEvent === "boolean" ? currentProps.enableQuickCreateEvent : true,
13678
14763
  weekStart: typeof currentProps.weekStart === "number" ? currentProps.weekStart : 1
13679
14764
  };
13680
- }
13681
- async ensureCalendarBlockPopupHosts(blockNode, transaction) {
13682
- var _a;
13683
- if (!(blockNode == null ? void 0 : blockNode.uid) || blockNode.use !== "CalendarBlockModel") {
13684
- return blockNode;
13685
- }
13686
- const resourceInit = this.getCalendarBlockResourceInit(blockNode);
13687
- let changed = false;
13688
- for (const actionKey of CALENDAR_POPUP_ACTION_KEYS) {
13689
- const existing = (0, import_service_utils.getSingleNodeSubModel)((_a = blockNode.subModels) == null ? void 0 : _a[actionKey]);
13690
- const expectedUid = this.getCalendarPopupActionUid(blockNode.uid, actionKey);
13691
- const expectedUse = this.getCalendarPopupActionUse(actionKey);
13692
- const openView = this.buildCalendarPopupOpenView({
13693
- blockNode,
13694
- actionKey,
13695
- resourceInit
13696
- });
13697
- const currentOpenView = this.resolvePopupHostOpenView(existing);
13698
- const shouldReplaceExisting = (existing == null ? void 0 : existing.uid) && existing.uid !== expectedUid;
13699
- const shouldUpsert = !(existing == null ? void 0 : existing.uid) || shouldReplaceExisting || existing.use !== expectedUse || !import_lodash.default.isEqual(currentOpenView, openView);
13700
- if (!shouldUpsert) {
13701
- continue;
13702
- }
13703
- if (shouldReplaceExisting) {
13704
- await this.removeNodeTreeWithBindings(existing.uid, transaction);
13705
- }
13706
- if ((existing == null ? void 0 : existing.uid) && existing.uid === expectedUid && !import_lodash.default.isEqual(currentOpenView, openView)) {
13707
- await this.reconcilePopupOpenViewTransition(expectedUid, currentOpenView, openView, transaction);
13708
- }
13709
- const nextActionNode = {
13710
- ...(existing == null ? void 0 : existing.uid) && existing.uid === expectedUid ? import_lodash.default.cloneDeep(existing) : {},
13711
- uid: expectedUid,
13712
- use: expectedUse,
13713
- stepParams: import_lodash.default.merge({}, (existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing.stepParams || {}) : {}, {
13714
- popupSettings: {
13715
- openView
13716
- }
13717
- })
13718
- };
13719
- await this.repository.upsertModel(
13720
- {
13721
- parentId: blockNode.uid,
13722
- subKey: actionKey,
13723
- subType: "object",
13724
- ...nextActionNode
13725
- },
13726
- { transaction }
13727
- );
13728
- changed = true;
13729
- }
13730
- if (!changed) {
13731
- return blockNode;
13732
- }
13733
- return this.repository.findModelById(blockNode.uid, {
14765
+ delete props.quickCreatePopup;
14766
+ delete props.quickCreatePopupSettings;
14767
+ delete props.eventPopup;
14768
+ delete props.eventPopupSettings;
14769
+ return props;
14770
+ }
14771
+ async ensureCalendarBlockPopupHosts(blockNode, transaction, popupSettingsOverrides, options = {}) {
14772
+ return (0, import_hidden_popup_calendar.ensureCalendarBlockPopupHosts)(
14773
+ this.hiddenPopupRuntime,
14774
+ blockNode,
13734
14775
  transaction,
13735
- includeAsyncNode: true
13736
- });
14776
+ popupSettingsOverrides,
14777
+ options
14778
+ );
13737
14779
  }
13738
- async ensureCalendarBlockPopupHostsInTree(node, transaction) {
13739
- if (!node || typeof node !== "object") {
13740
- return node;
13741
- }
13742
- let current = node;
13743
- if (current.use === "CalendarBlockModel") {
13744
- current = await this.ensureCalendarBlockPopupHosts(current, transaction);
13745
- }
13746
- for (const [subKey, value] of Object.entries(current.subModels || {})) {
13747
- if (Array.isArray(value)) {
13748
- const nextItems = [];
13749
- let changed = false;
13750
- for (const item of value) {
13751
- const nextItem = await this.ensureCalendarBlockPopupHostsInTree(item, transaction);
13752
- nextItems.push(nextItem);
13753
- changed = changed || nextItem !== item;
13754
- }
13755
- if (changed) {
13756
- current.subModels[subKey] = nextItems;
13757
- }
13758
- continue;
13759
- }
13760
- const nextValue = await this.ensureCalendarBlockPopupHostsInTree(value, transaction);
13761
- if (nextValue !== value) {
13762
- current.subModels[subKey] = nextValue;
13763
- }
13764
- }
13765
- return current;
14780
+ projectCalendarBlockPopupHostsInTree(node) {
14781
+ return (0, import_hidden_popup_calendar.projectCalendarBlockPopupHostsInTree)(node);
14782
+ }
14783
+ async replaceKanbanStoredPopupSettings(blockNode, actionKey, popupSettings, transaction) {
14784
+ return (0, import_hidden_popup_kanban.replaceKanbanStoredPopupSettings)(
14785
+ this.hiddenPopupRuntime,
14786
+ blockNode,
14787
+ actionKey,
14788
+ popupSettings,
14789
+ transaction
14790
+ );
13766
14791
  }
13767
- projectCalendarBlockPopupHosts(node) {
13768
- var _a;
13769
- if (!node || typeof node !== "object") {
13770
- return node;
13771
- }
13772
- const current = node;
13773
- if (!(current == null ? void 0 : current.uid) || current.use !== "CalendarBlockModel") {
13774
- return node;
13775
- }
13776
- const resourceInit = this.getCalendarBlockResourceInit(current);
13777
- let nextSubModels = current.subModels;
13778
- let changed = false;
13779
- for (const actionKey of CALENDAR_POPUP_ACTION_KEYS) {
13780
- const existing = (0, import_service_utils.getSingleNodeSubModel)((_a = current.subModels) == null ? void 0 : _a[actionKey]);
13781
- const expectedUid = this.getCalendarPopupActionUid(current.uid, actionKey);
13782
- const expectedUse = this.getCalendarPopupActionUse(actionKey);
13783
- const openView = this.buildCalendarPopupOpenView({
13784
- blockNode: current,
13785
- actionKey,
13786
- resourceInit
13787
- });
13788
- const currentOpenView = this.resolvePopupHostOpenView(existing);
13789
- if ((existing == null ? void 0 : existing.uid) === expectedUid && existing.use === expectedUse && import_lodash.default.isEqual(currentOpenView, openView)) {
13790
- continue;
13791
- }
13792
- const nextActionNode = {
13793
- ...(existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing) : {},
13794
- uid: expectedUid,
13795
- use: expectedUse,
13796
- stepParams: import_lodash.default.merge({}, (existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing.stepParams || {}) : {}, {
13797
- popupSettings: {
13798
- openView
13799
- }
13800
- })
13801
- };
13802
- if (!changed) {
13803
- nextSubModels = {
13804
- ...current.subModels || {}
13805
- };
13806
- changed = true;
13807
- }
13808
- nextSubModels[actionKey] = nextActionNode;
13809
- }
13810
- if (!changed) {
13811
- return node;
13812
- }
13813
- return {
13814
- ...current,
13815
- subModels: nextSubModels
13816
- };
14792
+ async ensureKanbanBlockPopupHosts(blockNode, transaction, popupSettingsOverrides, options = {}) {
14793
+ return (0, import_hidden_popup_kanban.ensureKanbanBlockPopupHosts)(
14794
+ this.hiddenPopupRuntime,
14795
+ blockNode,
14796
+ transaction,
14797
+ popupSettingsOverrides,
14798
+ options
14799
+ );
13817
14800
  }
13818
- projectCalendarBlockPopupHostsInTree(node) {
13819
- if (!node || typeof node !== "object") {
13820
- return node;
13821
- }
13822
- let current = this.projectCalendarBlockPopupHosts(node);
13823
- let nextSubModels = current == null ? void 0 : current.subModels;
13824
- let changed = current !== node;
13825
- if (!nextSubModels || typeof nextSubModels !== "object") {
13826
- return current;
13827
- }
13828
- for (const [subKey, value] of Object.entries(nextSubModels)) {
13829
- if (Array.isArray(value)) {
13830
- const nextItems = [];
13831
- let itemsChanged = false;
13832
- for (const item of value) {
13833
- const nextItem = this.projectCalendarBlockPopupHostsInTree(item);
13834
- nextItems.push(nextItem);
13835
- itemsChanged = itemsChanged || nextItem !== item;
13836
- }
13837
- if (!itemsChanged) {
13838
- continue;
13839
- }
13840
- if (!changed) {
13841
- current = {
13842
- ...current,
13843
- subModels: {
13844
- ...nextSubModels
13845
- }
13846
- };
13847
- nextSubModels = current.subModels;
13848
- changed = true;
13849
- }
13850
- nextSubModels[subKey] = nextItems;
13851
- continue;
13852
- }
13853
- const nextValue = this.projectCalendarBlockPopupHostsInTree(value);
13854
- if (nextValue === value) {
13855
- continue;
13856
- }
13857
- if (!changed) {
13858
- current = {
13859
- ...current,
13860
- subModels: {
13861
- ...nextSubModels
13862
- }
13863
- };
13864
- nextSubModels = current.subModels;
13865
- changed = true;
13866
- }
13867
- nextSubModels[subKey] = nextValue;
13868
- }
13869
- return current;
14801
+ projectKanbanBlockPopupHostsInTree(node) {
14802
+ return (0, import_hidden_popup_kanban.projectKanbanBlockPopupHostsInTree)(node);
13870
14803
  }
13871
- async ensureKanbanBlockPopupHosts(blockNode, transaction) {
13872
- var _a;
13873
- if (!(blockNode == null ? void 0 : blockNode.uid) || blockNode.use !== "KanbanBlockModel") {
13874
- return blockNode;
14804
+ resolveManagedPopupTargetUidForHiddenPopupBackfill(hostNode) {
14805
+ const openView = this.resolvePopupHostOpenView(hostNode);
14806
+ const externalPopupHostUid = this.resolveExternalPopupHostUid(hostNode == null ? void 0 : hostNode.uid, openView);
14807
+ if (!externalPopupHostUid) {
14808
+ return void 0;
13875
14809
  }
13876
- const resourceInit = this.getKanbanBlockResourceInit(blockNode);
13877
- let changed = false;
13878
- for (const actionKey of KANBAN_POPUP_ACTION_KEYS) {
13879
- const existing = (0, import_service_utils.getSingleNodeSubModel)((_a = blockNode.subModels) == null ? void 0 : _a[actionKey]);
13880
- const expectedUid = this.getKanbanPopupActionUid(blockNode.uid, actionKey);
13881
- const expectedUse = this.getKanbanPopupActionUse(actionKey);
13882
- const openView = this.buildKanbanPopupOpenView({
13883
- blockNode,
13884
- actionKey,
13885
- resourceInit
13886
- });
13887
- const currentOpenView = this.resolvePopupHostOpenView(existing);
13888
- const shouldReplaceExisting = (existing == null ? void 0 : existing.uid) && existing.uid !== expectedUid;
13889
- const shouldUpsert = !(existing == null ? void 0 : existing.uid) || shouldReplaceExisting || existing.use !== expectedUse || !import_lodash.default.isEqual(currentOpenView, openView);
13890
- if (!shouldUpsert) {
13891
- continue;
13892
- }
13893
- if (shouldReplaceExisting) {
13894
- await this.removeNodeTreeWithBindings(existing.uid, transaction);
13895
- }
13896
- if ((existing == null ? void 0 : existing.uid) && existing.uid === expectedUid && !import_lodash.default.isEqual(currentOpenView, openView)) {
13897
- await this.reconcilePopupOpenViewTransition(expectedUid, currentOpenView, openView, transaction);
13898
- }
13899
- const nextActionNode = {
13900
- ...(existing == null ? void 0 : existing.uid) && existing.uid === expectedUid ? import_lodash.default.cloneDeep(existing) : {},
13901
- uid: expectedUid,
13902
- use: expectedUse,
13903
- stepParams: import_lodash.default.merge({}, (existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing.stepParams || {}) : {}, {
13904
- popupSettings: {
13905
- openView
13906
- }
13907
- })
13908
- };
13909
- await this.repository.upsertModel(
13910
- {
13911
- parentId: blockNode.uid,
13912
- subKey: actionKey,
13913
- subType: "object",
13914
- ...nextActionNode
13915
- },
13916
- { transaction }
13917
- );
13918
- changed = true;
14810
+ if ((openView == null ? void 0 : openView.popupTemplateContext) || String((openView == null ? void 0 : openView.popupTemplateUid) || "").trim()) {
14811
+ return externalPopupHostUid;
13919
14812
  }
13920
- if (!changed) {
13921
- return blockNode;
14813
+ return void 0;
14814
+ }
14815
+ async ensureHiddenPopupBlockHostsInManagedPopupTarget(hostNode, transaction, visitedPopupTargetUids = /* @__PURE__ */ new Set()) {
14816
+ const popupTargetUid = this.resolveManagedPopupTargetUidForHiddenPopupBackfill(hostNode);
14817
+ if (!popupTargetUid || visitedPopupTargetUids.has(popupTargetUid)) {
14818
+ return;
13922
14819
  }
13923
- return this.repository.findModelById(blockNode.uid, {
14820
+ visitedPopupTargetUids.add(popupTargetUid);
14821
+ const popupTarget = await this.repository.findModelById(popupTargetUid, {
13924
14822
  transaction,
13925
14823
  includeAsyncNode: true
14824
+ }).catch(() => null);
14825
+ if (!(popupTarget == null ? void 0 : popupTarget.uid)) {
14826
+ return;
14827
+ }
14828
+ await this.ensureHiddenPopupBlockHostsInTree(popupTarget, transaction, {
14829
+ ensureManagedPopupTemplateTargets: true,
14830
+ visitedPopupTargetUids
13926
14831
  });
13927
14832
  }
13928
- async ensureKanbanBlockPopupHostsInTree(node, transaction) {
14833
+ async ensureHiddenPopupBlockHostsInTree(node, transaction, options = {}) {
13929
14834
  if (!node || typeof node !== "object") {
13930
14835
  return node;
13931
14836
  }
14837
+ const visitedPopupTargetUids = options.visitedPopupTargetUids || /* @__PURE__ */ new Set();
13932
14838
  let current = node;
14839
+ if (current.use === "CalendarBlockModel") {
14840
+ current = await this.ensureCalendarBlockPopupHosts(current, transaction);
14841
+ }
13933
14842
  if (current.use === "KanbanBlockModel") {
13934
14843
  current = await this.ensureKanbanBlockPopupHosts(current, transaction);
13935
14844
  }
@@ -13938,7 +14847,10 @@ class FlowSurfacesService {
13938
14847
  const nextItems = [];
13939
14848
  let changed = false;
13940
14849
  for (const item of value) {
13941
- const nextItem = await this.ensureKanbanBlockPopupHostsInTree(item, transaction);
14850
+ const nextItem = await this.ensureHiddenPopupBlockHostsInTree(item, transaction, {
14851
+ ...options,
14852
+ visitedPopupTargetUids
14853
+ });
13942
14854
  nextItems.push(nextItem);
13943
14855
  changed = changed || nextItem !== item;
13944
14856
  }
@@ -13947,114 +14859,16 @@ class FlowSurfacesService {
13947
14859
  }
13948
14860
  continue;
13949
14861
  }
13950
- const nextValue = await this.ensureKanbanBlockPopupHostsInTree(value, transaction);
14862
+ const nextValue = await this.ensureHiddenPopupBlockHostsInTree(value, transaction, {
14863
+ ...options,
14864
+ visitedPopupTargetUids
14865
+ });
13951
14866
  if (nextValue !== value) {
13952
14867
  current.subModels[subKey] = nextValue;
13953
14868
  }
13954
14869
  }
13955
- return current;
13956
- }
13957
- projectKanbanBlockPopupHosts(node) {
13958
- var _a;
13959
- if (!node || typeof node !== "object") {
13960
- return node;
13961
- }
13962
- const current = node;
13963
- if (!(current == null ? void 0 : current.uid) || current.use !== "KanbanBlockModel") {
13964
- return node;
13965
- }
13966
- const resourceInit = this.getKanbanBlockResourceInit(current);
13967
- let nextSubModels = current.subModels;
13968
- let changed = false;
13969
- for (const actionKey of KANBAN_POPUP_ACTION_KEYS) {
13970
- const existing = (0, import_service_utils.getSingleNodeSubModel)((_a = current.subModels) == null ? void 0 : _a[actionKey]);
13971
- const expectedUid = this.getKanbanPopupActionUid(current.uid, actionKey);
13972
- const expectedUse = this.getKanbanPopupActionUse(actionKey);
13973
- const openView = this.buildKanbanPopupOpenView({
13974
- blockNode: current,
13975
- actionKey,
13976
- resourceInit
13977
- });
13978
- const currentOpenView = this.resolvePopupHostOpenView(existing);
13979
- if ((existing == null ? void 0 : existing.uid) === expectedUid && existing.use === expectedUse && import_lodash.default.isEqual(currentOpenView, openView)) {
13980
- continue;
13981
- }
13982
- const nextActionNode = {
13983
- ...(existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing) : {},
13984
- uid: expectedUid,
13985
- use: expectedUse,
13986
- stepParams: import_lodash.default.merge({}, (existing == null ? void 0 : existing.uid) === expectedUid ? import_lodash.default.cloneDeep(existing.stepParams || {}) : {}, {
13987
- popupSettings: {
13988
- openView
13989
- }
13990
- })
13991
- };
13992
- if (!changed) {
13993
- nextSubModels = {
13994
- ...current.subModels || {}
13995
- };
13996
- changed = true;
13997
- }
13998
- nextSubModels[actionKey] = nextActionNode;
13999
- }
14000
- if (!changed) {
14001
- return node;
14002
- }
14003
- return {
14004
- ...current,
14005
- subModels: nextSubModels
14006
- };
14007
- }
14008
- projectKanbanBlockPopupHostsInTree(node) {
14009
- if (!node || typeof node !== "object") {
14010
- return node;
14011
- }
14012
- let current = this.projectKanbanBlockPopupHosts(node);
14013
- let nextSubModels = current == null ? void 0 : current.subModels;
14014
- let changed = current !== node;
14015
- if (!nextSubModels || typeof nextSubModels !== "object") {
14016
- return current;
14017
- }
14018
- for (const [subKey, value] of Object.entries(nextSubModels)) {
14019
- if (Array.isArray(value)) {
14020
- const nextItems = [];
14021
- let itemsChanged = false;
14022
- for (const item of value) {
14023
- const nextItem = this.projectKanbanBlockPopupHostsInTree(item);
14024
- nextItems.push(nextItem);
14025
- itemsChanged = itemsChanged || nextItem !== item;
14026
- }
14027
- if (!itemsChanged) {
14028
- continue;
14029
- }
14030
- if (!changed) {
14031
- current = {
14032
- ...current,
14033
- subModels: {
14034
- ...nextSubModels
14035
- }
14036
- };
14037
- nextSubModels = current.subModels;
14038
- changed = true;
14039
- }
14040
- nextSubModels[subKey] = nextItems;
14041
- continue;
14042
- }
14043
- const nextValue = this.projectKanbanBlockPopupHostsInTree(value);
14044
- if (nextValue === value) {
14045
- continue;
14046
- }
14047
- if (!changed) {
14048
- current = {
14049
- ...current,
14050
- subModels: {
14051
- ...nextSubModels
14052
- }
14053
- };
14054
- nextSubModels = current.subModels;
14055
- changed = true;
14056
- }
14057
- nextSubModels[subKey] = nextValue;
14870
+ if (options.ensureManagedPopupTemplateTargets) {
14871
+ await this.ensureHiddenPopupBlockHostsInManagedPopupTarget(current, transaction, visitedPopupTargetUids);
14058
14872
  }
14059
14873
  return current;
14060
14874
  }
@@ -14591,6 +15405,31 @@ class FlowSurfacesService {
14591
15405
  usesAssociationValueBinding: false
14592
15406
  };
14593
15407
  }
15408
+ collectionFieldHasRequiredValidation(field) {
15409
+ var _a, _b, _c;
15410
+ const rules = [
15411
+ ...import_lodash.default.castArray(((_a = field == null ? void 0 : field.validation) == null ? void 0 : _a.rules) || []),
15412
+ ...import_lodash.default.castArray(((_c = (_b = field == null ? void 0 : field.options) == null ? void 0 : _b.validation) == null ? void 0 : _c.rules) || [])
15413
+ ];
15414
+ return rules.some((rule) => String((rule == null ? void 0 : rule.name) || "").trim() === "required");
15415
+ }
15416
+ buildRequiredCollectionFieldFormWrapperDefaults(input) {
15417
+ if (!REQUIRED_COLLECTION_FIELD_FORM_WRAPPER_USES.has(input.wrapperUse || "") || !this.collectionFieldHasRequiredValidation(input.field)) {
15418
+ return {};
15419
+ }
15420
+ return {
15421
+ props: {
15422
+ required: true
15423
+ },
15424
+ stepParams: {
15425
+ editItemSettings: {
15426
+ required: {
15427
+ required: true
15428
+ }
15429
+ }
15430
+ }
15431
+ };
15432
+ }
14594
15433
  getCollectionFieldOrBadRequest(collection, fieldPath, context) {
14595
15434
  const field = (0, import_service_helpers.resolveFieldFromCollection)(collection, fieldPath);
14596
15435
  if (!field) {
@@ -14874,10 +15713,12 @@ class FlowSurfacesService {
14874
15713
  }
14875
15714
  if (input.fieldUse === "RecordPickerFieldModel") {
14876
15715
  await this.applyRecordPickerFieldTypeSettings(input);
15716
+ } else if (input.fieldUse === "PopupSubTableFieldModel") {
15717
+ await this.ensureRelationSelectorGridTable(input);
14877
15718
  }
14878
15719
  }
14879
15720
  async applyRecordPickerFieldTypeSettings(input) {
14880
- var _a, _b, _c;
15721
+ var _a;
14881
15722
  const fieldNode = await this.repository.findModelById(input.fieldUid, {
14882
15723
  transaction: input.transaction,
14883
15724
  includeAsyncNode: true
@@ -14902,6 +15743,10 @@ class FlowSurfacesService {
14902
15743
  { transaction: input.transaction }
14903
15744
  );
14904
15745
  }
15746
+ await this.ensureRelationSelectorGridTable(input);
15747
+ }
15748
+ async ensureRelationSelectorGridTable(input) {
15749
+ var _a, _b, _c;
14905
15750
  if (!input.selectorFields) {
14906
15751
  return;
14907
15752
  }
@@ -14918,6 +15763,7 @@ class FlowSurfacesService {
14918
15763
  parentId: input.fieldUid,
14919
15764
  subKey: "grid-block",
14920
15765
  subType: "object",
15766
+ async: true,
14921
15767
  use: "BlockGridModel"
14922
15768
  },
14923
15769
  { transaction: input.transaction }
@@ -14930,30 +15776,67 @@ class FlowSurfacesService {
14930
15776
  if (!(grid == null ? void 0 : grid.uid)) {
14931
15777
  return;
14932
15778
  }
14933
- const existingTable = import_lodash.default.castArray(((_b = grid == null ? void 0 : grid.subModels) == null ? void 0 : _b.items) || []).find(
14934
- (item) => (item == null ? void 0 : item.use) === "TableBlockModel"
14935
- );
15779
+ const gridItems = import_lodash.default.castArray(((_a = grid == null ? void 0 : grid.subModels) == null ? void 0 : _a.items) || []);
15780
+ const existingTable = gridItems.find((item) => (item == null ? void 0 : item.use) === "TableSelectModel") || gridItems.find((item) => (item == null ? void 0 : item.use) === "TableBlockModel");
14936
15781
  const tableUid = (existingTable == null ? void 0 : existingTable.uid) || (0, import_utils.uid)();
14937
- if (!(existingTable == null ? void 0 : existingTable.uid)) {
14938
- await this.repository.upsertModel(
14939
- {
14940
- uid: tableUid,
14941
- parentId: grid.uid,
14942
- subKey: "items",
14943
- subType: "array",
14944
- use: "TableBlockModel",
14945
- stepParams: {
14946
- resourceSettings: {
14947
- init: {
14948
- dataSourceKey: ((_c = input.targetCollection) == null ? void 0 : _c.dataSourceKey) || "main",
14949
- collectionName: (0, import_service_helpers.getCollectionName)(input.targetCollection)
14950
- }
15782
+ for (const item of gridItems) {
15783
+ if ((item == null ? void 0 : item.uid) && item.uid !== tableUid) {
15784
+ await this.removeNodeTreeWithBindings(item.uid, input.transaction);
15785
+ }
15786
+ }
15787
+ await this.repository.upsertModel(
15788
+ {
15789
+ ...import_lodash.default.omit(import_lodash.default.cloneDeep(existingTable || {}), [
15790
+ "uid",
15791
+ "use",
15792
+ "subModels",
15793
+ "sortIndex",
15794
+ "parentId",
15795
+ "subKey",
15796
+ "subType"
15797
+ ]),
15798
+ uid: tableUid,
15799
+ parentId: grid.uid,
15800
+ subKey: "items",
15801
+ subType: "array",
15802
+ use: "TableSelectModel",
15803
+ stepParams: import_lodash.default.merge({}, import_lodash.default.cloneDeep((existingTable == null ? void 0 : existingTable.stepParams) || {}), {
15804
+ resourceSettings: {
15805
+ init: {
15806
+ dataSourceKey: ((_b = input.targetCollection) == null ? void 0 : _b.dataSourceKey) || "main",
15807
+ collectionName: (0, import_service_helpers.getCollectionName)(input.targetCollection)
14951
15808
  }
14952
15809
  }
15810
+ })
15811
+ },
15812
+ { transaction: input.transaction }
15813
+ );
15814
+ const layout = {
15815
+ rows: {
15816
+ row1: [[tableUid]]
15817
+ },
15818
+ sizes: {
15819
+ row1: [24]
15820
+ },
15821
+ rowOrder: ["row1"]
15822
+ };
15823
+ await this.repository.patch(
15824
+ {
15825
+ uid: grid.uid,
15826
+ props: {
15827
+ ...grid.props || {},
15828
+ ...layout
14953
15829
  },
14954
- { transaction: input.transaction }
14955
- );
14956
- }
15830
+ stepParams: {
15831
+ ...grid.stepParams || {},
15832
+ [GRID_SETTINGS_FLOW_KEY]: {
15833
+ ...((_c = grid.stepParams) == null ? void 0 : _c[GRID_SETTINGS_FLOW_KEY]) || {},
15834
+ [GRID_SETTINGS_LAYOUT_STEP_KEY]: layout
15835
+ }
15836
+ }
15837
+ },
15838
+ { transaction: input.transaction }
15839
+ );
14957
15840
  await this.replaceFieldSubModelArray({
14958
15841
  parentUid: tableUid,
14959
15842
  subKey: "columns",
@@ -15274,10 +16157,9 @@ class FlowSurfacesService {
15274
16157
  if (options.persistCalendarPopupHosts === false) {
15275
16158
  return this.projectKanbanBlockPopupHostsInTree(this.projectCalendarBlockPopupHostsInTree(node));
15276
16159
  }
15277
- return this.ensureKanbanBlockPopupHostsInTree(
15278
- await this.ensureCalendarBlockPopupHostsInTree(node, transaction),
15279
- transaction
15280
- );
16160
+ return this.ensureHiddenPopupBlockHostsInTree(node, transaction, {
16161
+ ensureManagedPopupTemplateTargets: options.ensureManagedPopupTemplateTargets === true
16162
+ });
15281
16163
  }
15282
16164
  normalizePopupTreeShape(node) {
15283
16165
  if (!node || typeof node !== "object") {