@outbuild-company/schedule-core 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -14138,6 +14138,14 @@ var PASTE_PLACEMENT = {
14138
14138
  END: "end"
14139
14139
  };
14140
14140
 
14141
+ // src/dispatch/confirmations.ts
14142
+ var LOOKAHEAD_CONFIRMATION_KIND = {
14143
+ HAS_LOOKAHEAD_TASKS: "has_lookahead_tasks"
14144
+ };
14145
+ var CUSTOM_ID_CONFIRMATION_KIND = {
14146
+ PASTE_CONFLICTS: "custom_id_paste_conflicts"
14147
+ };
14148
+
14141
14149
  // src/activity-copy-paste/paste.ts
14142
14150
  function childIdsInCorrelativeOrder(parentId, adapter) {
14143
14151
  return collectChildrenSnapshots(parentId, adapter).sort(compareActivitiesInVisualOrder).map((activity) => activity.id);
@@ -14193,6 +14201,59 @@ var invariantFailure = () => ({
14193
14201
  ok: false,
14194
14202
  reason: REJECTION_REASON.ACTIVITY_PASTE_INVARIANT_FAILED
14195
14203
  });
14204
+ function customIdHolders(adapter) {
14205
+ const holders = /* @__PURE__ */ new Map();
14206
+ adapter.forEachActivity((activity, activityId) => {
14207
+ if (activity.customId !== null) {
14208
+ holders.set(activity.customId, String(activityId));
14209
+ }
14210
+ });
14211
+ return holders;
14212
+ }
14213
+ function conflictingCustomIds(clipboard, deps) {
14214
+ const holders = customIdHolders(deps.adapter);
14215
+ const copiedCustomIds = /* @__PURE__ */ new Set();
14216
+ const conflicts = /* @__PURE__ */ new Set();
14217
+ for (const copied of clipboard.activities) {
14218
+ const customId = copied.overrides.customId;
14219
+ if (typeof customId !== "string" || customId.length === 0) continue;
14220
+ const isHeldByAnotherActivity = deps.customIdTracker.isCustomIdInUse(customId) && holders.get(customId) !== String(copied.originalId);
14221
+ if (isHeldByAnotherActivity || copiedCustomIds.has(customId)) {
14222
+ conflicts.add(customId);
14223
+ }
14224
+ copiedCustomIds.add(customId);
14225
+ }
14226
+ return [...conflicts];
14227
+ }
14228
+ function reserveFreeCopiedCustomIds(clipboard, deps) {
14229
+ const reserved = /* @__PURE__ */ new Set();
14230
+ for (const copied of clipboard.activities) {
14231
+ const customId = copied.overrides.customId;
14232
+ const isFreeCopiedCustomId = typeof customId === "string" && customId.length > 0 && !deps.customIdTracker.isCustomIdInUse(customId);
14233
+ if (!isFreeCopiedCustomId) continue;
14234
+ deps.customIdTracker.registerCustomId(customId);
14235
+ reserved.add(customId);
14236
+ }
14237
+ return reserved;
14238
+ }
14239
+ function releaseReservedCustomId(customId, reserved, deps) {
14240
+ if (typeof customId !== "string" || !reserved.has(customId)) return;
14241
+ deps.customIdTracker.releaseCustomId(customId);
14242
+ reserved.delete(customId);
14243
+ }
14244
+ function customIdConflictRejection(clipboard, options, deps) {
14245
+ if (options.regenerateConflictingCustomIds === true) return null;
14246
+ const customIds = conflictingCustomIds(clipboard, deps);
14247
+ if (customIds.length === 0) return null;
14248
+ return {
14249
+ ok: false,
14250
+ reason: REJECTION_REASON.CONFIRMATION_REQUIRED,
14251
+ confirmation: {
14252
+ kind: CUSTOM_ID_CONFIRMATION_KIND.PASTE_CONFLICTS,
14253
+ customIds
14254
+ }
14255
+ };
14256
+ }
14196
14257
  async function dispatchActivityPasteCopied(action, options, deps) {
14197
14258
  const clipboard = deps.activityClipboard.value;
14198
14259
  if (clipboard === null) {
@@ -14200,6 +14261,8 @@ async function dispatchActivityPasteCopied(action, options, deps) {
14200
14261
  }
14201
14262
  const destination = resolvePasteDestination(action.destination, deps.adapter);
14202
14263
  if (!destination.ok) return destination;
14264
+ const conflictRejection = customIdConflictRejection(clipboard, options, deps);
14265
+ if (conflictRejection !== null) return conflictRejection;
14203
14266
  const createOptions = createOptionsFor(action.destination, destination);
14204
14267
  const beforeSnapshot = await snapshotActivities(
14205
14268
  deps.adapter,
@@ -14209,7 +14272,9 @@ async function dispatchActivityPasteCopied(action, options, deps) {
14209
14272
  const originalToNew = /* @__PURE__ */ new Map();
14210
14273
  const createdIds = [];
14211
14274
  let previousRootId;
14275
+ const reservedCustomIds = reserveFreeCopiedCustomIds(clipboard, deps);
14212
14276
  for (const copied of clipboard.activities) {
14277
+ releaseReservedCustomId(copied.overrides.customId, reservedCustomIds, deps);
14213
14278
  const mappedParent = originalToNew.get(copied.originalParentId);
14214
14279
  const afterSiblingId = mappedParent === void 0 ? previousRootId ?? destination.afterSiblingId : void 0;
14215
14280
  const beforeSiblingId = mappedParent === void 0 && afterSiblingId === void 0 ? destination.beforeSiblingId : void 0;
@@ -14302,11 +14367,6 @@ async function dispatchActivityPasteCopied(action, options, deps) {
14302
14367
  };
14303
14368
  }
14304
14369
 
14305
- // src/dispatch/confirmations.ts
14306
- var LOOKAHEAD_CONFIRMATION_KIND = {
14307
- HAS_LOOKAHEAD_TASKS: "has_lookahead_tasks"
14308
- };
14309
-
14310
14370
  // src/dispatch/shared/hierarchy-cycle-guard.ts
14311
14371
  function reparentClosesEffectiveCycle(adapter, reparented) {
14312
14372
  return !validateReparenting(adapter, { reparented }).ok;
@@ -21046,7 +21106,7 @@ var ACTIVITY_COPY_FIELDS = [
21046
21106
 
21047
21107
  // src/activity-copy-paste/copy.ts
21048
21108
  function copyOverrides(activity) {
21049
- const overrides = {};
21109
+ const overrides = { customId: activity.customId };
21050
21110
  for (const field of ACTIVITY_COPY_FIELDS) {
21051
21111
  Object.assign(overrides, { [field]: cloneDomainValue(activity[field]) });
21052
21112
  }
@@ -38146,6 +38206,7 @@ exports.CONSTRAINT_TYPE = CONSTRAINT_TYPE;
38146
38206
  exports.CONSTRAINT_TYPE_TO_LABEL = CONSTRAINT_TYPE_TO_LABEL;
38147
38207
  exports.CONSTRAINT_WARNING_KIND = CONSTRAINT_WARNING_KIND;
38148
38208
  exports.CREATION_KIND = CREATION_KIND;
38209
+ exports.CUSTOM_ID_CONFIRMATION_KIND = CUSTOM_ID_CONFIRMATION_KIND;
38149
38210
  exports.DATA_DATE_PROPERTY_CONTRACT = P6_PROPERTY_CONTRACT;
38150
38211
  exports.DATE_GESTURE_KIND = DATE_GESTURE_KIND;
38151
38212
  exports.DEFAULT_HOURS_PER_DAY = DEFAULT_HOURS_PER_DAY;