@arpproject/recrate 0.1.51 → 0.1.53

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.
@@ -66720,7 +66720,7 @@ const Text$2 = ({
66720
66720
  onSaveProperty
66721
66721
  }) => {
66722
66722
  const { t: t2 } = useTranslation();
66723
- const [displayValue, setDisplayValue] = useState(decodeValue(value));
66723
+ const [displayValue2, setDisplayValue] = useState(decodeValue(value));
66724
66724
  const [isValidTextValue, setIsValidTextValue] = useState(true);
66725
66725
  const textareaRef = useRef(null);
66726
66726
  const saveButtonRef = useRef(null);
@@ -66729,7 +66729,7 @@ const Text$2 = ({
66729
66729
  validateTextConstraints(decodeValue(value));
66730
66730
  }, [value]);
66731
66731
  useEffect(() => {
66732
- validateTextConstraints(displayValue);
66732
+ validateTextConstraints(displayValue2);
66733
66733
  }, []);
66734
66734
  const constraints = {
66735
66735
  minLength: definition == null ? void 0 : definition.minLength,
@@ -66738,7 +66738,7 @@ const Text$2 = ({
66738
66738
  dateFormat: definition == null ? void 0 : definition.dateFormat
66739
66739
  };
66740
66740
  function validateTextConstraints(valueToCheck) {
66741
- const valueToValidate = valueToCheck ?? displayValue ?? "";
66741
+ const valueToValidate = valueToCheck ?? displayValue2 ?? "";
66742
66742
  if (constraints.minLength !== void 0 && constraints.minLength > valueToValidate.length) {
66743
66743
  setIsValidTextValue(false);
66744
66744
  } else if (constraints.maxLength !== void 0 && constraints.maxLength < valueToValidate.length) {
@@ -66762,7 +66762,7 @@ const Text$2 = ({
66762
66762
  if (isValidTextValue) {
66763
66763
  onSaveProperty({
66764
66764
  property,
66765
- value: displayValue.trim()
66765
+ value: displayValue2.trim()
66766
66766
  });
66767
66767
  }
66768
66768
  }
@@ -66809,7 +66809,7 @@ const Text$2 = ({
66809
66809
  {
66810
66810
  size: "middle",
66811
66811
  type: type4,
66812
- value: displayValue,
66812
+ value: displayValue2,
66813
66813
  onChange: handleTextChange,
66814
66814
  onBlur: handleBlur,
66815
66815
  onKeyDown: (e3) => {
@@ -66822,7 +66822,7 @@ const Text$2 = ({
66822
66822
  Input2.TextArea,
66823
66823
  {
66824
66824
  ref: textareaRef,
66825
- value: displayValue,
66825
+ value: displayValue2,
66826
66826
  onChange: handleTextareaChange,
66827
66827
  onBlur: handleBlur,
66828
66828
  onKeyDown: (e3) => {
@@ -74334,55 +74334,6 @@ const AiEditedFieldBadge = ({
74334
74334
  const label = variant === "deleted" ? t2("ai_deleted_by_ai") : t2("ai_edited_by_ai");
74335
74335
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip2, { title: title ?? label, children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `recrate-ai-edited-icon ${className}`, "aria-label": ariaLabel ?? label, children: "✦" }) });
74336
74336
  };
74337
- const EntityId = ({
74338
- entity,
74339
- onUpdate,
74340
- aiEdited = false,
74341
- aiEditedVariant = "edited"
74342
- }) => {
74343
- var _a2;
74344
- const { t: t2 } = useTranslation();
74345
- const state = useStateStore();
74346
- const handleSave = async (data) => {
74347
- onUpdate(data);
74348
- };
74349
- const openInNewTab = (url2) => {
74350
- window.open(url2, "_blank");
74351
- };
74352
- const isDatasetOrFile = () => {
74353
- const types2 = Array.isArray(entity["@type"]) ? entity["@type"] : [entity["@type"]];
74354
- return entity["@id"] === "./" || types2.some((type4) => ["Dataset", "File"].includes(type4));
74355
- };
74356
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-row", children: [
74357
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-32 w-1/3 xl:w-1/5 recrate-property-name recrate-property-name-with-ai", children: [
74358
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "@id" }),
74359
- aiEdited && /* @__PURE__ */ jsxRuntimeExports.jsx(AiEditedFieldBadge, { variant: aiEditedVariant })
74360
- ] }),
74361
- !((_a2 = state.configuration) == null ? void 0 : _a2.readonly) ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-2/3 xl:w-4/5 flex flex-row recrate-property-value", children: [
74362
- isURL(entity["@id"]) && /* @__PURE__ */ jsxRuntimeExports.jsx(
74363
- Button$1,
74364
- {
74365
- type: "link",
74366
- icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {}),
74367
- onClick: () => openInNewTab(entity["@id"]),
74368
- title: String(t2("open_in_new_tab"))
74369
- }
74370
- ),
74371
- isDatasetOrFile() ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: entity["@id"] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-grow", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
74372
- Text$2,
74373
- {
74374
- property: "@id",
74375
- value: entity["@id"],
74376
- onSaveProperty: handleSave
74377
- }
74378
- ) })
74379
- ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-2/3 xl:w-4/5 flex flex-row recrate-property-value", children: isURL(entity["@id"]) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Typography.Link, { className: "text-large", style: { fontSize: "1em" }, href: entity["@id"], target: "_blank", rel: "noopener noreferrer", children: [
74380
- entity["@id"],
74381
- " ",
74382
- /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {})
74383
- ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: entity["@id"] }) })
74384
- ] });
74385
- };
74386
74337
  const valueIsEmpty$1 = (value) => {
74387
74338
  if (value === void 0 || value === null) return true;
74388
74339
  if (typeof value === "string") return value.trim().length === 0;
@@ -74425,6 +74376,109 @@ const AiFieldDiffView = ({
74425
74376
  ] })
74426
74377
  ] });
74427
74378
  };
74379
+ const EntityId = ({
74380
+ entity,
74381
+ onUpdate,
74382
+ aiEdited = false,
74383
+ aiEditedVariant = "edited",
74384
+ aiReview
74385
+ }) => {
74386
+ var _a2;
74387
+ const { t: t2 } = useTranslation();
74388
+ const state = useStateStore();
74389
+ const [showAiDiff, setShowAiDiff] = useState(false);
74390
+ const showAiReview = Boolean(aiReview);
74391
+ const isAiDelete = (aiReview == null ? void 0 : aiReview.operation) === "delete";
74392
+ const handleSave = async (data) => {
74393
+ onUpdate(data);
74394
+ };
74395
+ const openInNewTab = (url2) => {
74396
+ window.open(url2, "_blank");
74397
+ };
74398
+ const isDatasetOrFile = () => {
74399
+ const types2 = Array.isArray(entity["@type"]) ? entity["@type"] : [entity["@type"]];
74400
+ return entity["@id"] === "./" || types2.some((type4) => ["Dataset", "File"].includes(type4));
74401
+ };
74402
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
74403
+ "div",
74404
+ {
74405
+ className: `flex flex-row flex-grow ${showAiReview ? `p-2 recrate-property-background recrate-ai-review ${isAiDelete ? "recrate-ai-delete" : "recrate-ai-suggestion"}` : ""} recrate-property recrate-property-name-id`,
74406
+ children: [
74407
+ showAiReview && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate-ai-suggestion-badge", children: [
74408
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "recrate-ai-suggestion-badge-icon", children: "✦" }),
74409
+ isAiDelete ? t2("ai_delete_badge") : t2("ai_suggestion_badge")
74410
+ ] }),
74411
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-w-32 w-1/3 xl:w-1/5 flex flex-col recrate-property-heading", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate-property-name recrate-property-name-with-ai", children: [
74412
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "@id" }),
74413
+ aiEdited && /* @__PURE__ */ jsxRuntimeExports.jsx(AiEditedFieldBadge, { variant: aiEditedVariant })
74414
+ ] }) }),
74415
+ !((_a2 = state.configuration) == null ? void 0 : _a2.readonly) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-2/3 xl:w-4/5 flex flex-col flex-grow recrate-property-value", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `flex flex-row gap-2 ${showAiReview ? "recrate-ai-field-row" : ""}`, children: [
74416
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `flex flex-row flex-grow min-w-0 ${showAiReview ? "recrate-ai-field-control" : ""}`, children: showAiDiff && (aiReview == null ? void 0 : aiReview.previousValueDiffers) ? /* @__PURE__ */ jsxRuntimeExports.jsx(
74417
+ AiFieldDiffView,
74418
+ {
74419
+ previousValue: aiReview.previousValue,
74420
+ currentValue: entity["@id"],
74421
+ operation: aiReview.operation
74422
+ }
74423
+ ) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
74424
+ isURL(entity["@id"]) && /* @__PURE__ */ jsxRuntimeExports.jsx(
74425
+ Button$1,
74426
+ {
74427
+ type: "link",
74428
+ icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {}),
74429
+ onClick: () => openInNewTab(entity["@id"]),
74430
+ title: String(t2("open_in_new_tab"))
74431
+ }
74432
+ ),
74433
+ isDatasetOrFile() ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: entity["@id"] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-grow", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
74434
+ Text$2,
74435
+ {
74436
+ property: "@id",
74437
+ value: entity["@id"],
74438
+ onSaveProperty: handleSave
74439
+ }
74440
+ ) })
74441
+ ] }) }),
74442
+ showAiReview && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate-ai-actions", children: [
74443
+ (aiReview == null ? void 0 : aiReview.previousValueDiffers) && /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip2, { title: showAiDiff ? t2("ai_hide_diff") : t2("ai_show_diff"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
74444
+ Button$1,
74445
+ {
74446
+ size: "middle",
74447
+ className: "recrate-ai-action-diff",
74448
+ icon: /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$9, {}),
74449
+ "aria-label": showAiDiff ? String(t2("ai_hide_ai_diff_aria")) : String(t2("ai_show_ai_diff_aria")),
74450
+ "aria-pressed": showAiDiff,
74451
+ onClick: () => setShowAiDiff((visible) => !visible)
74452
+ }
74453
+ ) }),
74454
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip2, { title: isAiDelete ? t2("ai_approve_deletion_tooltip") : t2("ai_approve_suggested_value_tooltip"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
74455
+ Button$1,
74456
+ {
74457
+ size: "middle",
74458
+ className: "recrate-ai-action-approve",
74459
+ onClick: aiReview == null ? void 0 : aiReview.onApprove,
74460
+ children: isAiDelete ? t2("ai_delete") : t2("ai_accept")
74461
+ }
74462
+ ) }),
74463
+ (aiReview == null ? void 0 : aiReview.previousValueDiffers) && /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip2, { title: t2("ai_restore_previous_value_tooltip"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
74464
+ Button$1,
74465
+ {
74466
+ size: "middle",
74467
+ className: "recrate-ai-action-reject",
74468
+ onClick: aiReview == null ? void 0 : aiReview.onReject,
74469
+ children: isAiDelete ? t2("ai_restore") : t2("ai_reject")
74470
+ }
74471
+ ) })
74472
+ ] })
74473
+ ] }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-2/3 xl:w-4/5 flex flex-row recrate-property-value", children: isURL(entity["@id"]) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Typography.Link, { className: "text-large", style: { fontSize: "1em" }, href: entity["@id"], target: "_blank", rel: "noopener noreferrer", children: [
74474
+ entity["@id"],
74475
+ " ",
74476
+ /* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon$7, {})
74477
+ ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: entity["@id"] }) })
74478
+ ]
74479
+ }
74480
+ );
74481
+ };
74428
74482
  var ttl2jsonld$1 = { exports: {} };
74429
74483
  var ttl2jsonld = ttl2jsonld$1.exports;
74430
74484
  var hasRequiredTtl2jsonld;
@@ -79817,6 +79871,7 @@ const CoreEntityFields = ({
79817
79871
  }) => {
79818
79872
  const renderRequiredWarning = !readonly && missingRequiredData;
79819
79873
  const idIsVisible = shouldRenderCoreField("@id");
79874
+ const idAiReview = getCoreAiReviewProps("@id");
79820
79875
  const typeAiReview = getCoreAiReviewProps("@type");
79821
79876
  const nameAiReview = getCoreAiReviewProps("name");
79822
79877
  const typeWrapperClassName = typeAiReview ? "" : `p-2 recrate-property recrate-property-name-type ${selectedAiApprovalProperty === "@type" ? "recrate-ai-review-current" : ""}`;
@@ -79825,19 +79880,20 @@ const CoreEntityFields = ({
79825
79880
  const untabbedTypeWrapperClassName = typeAiReview ? "" : `my-2 ${typeWrapperClassName}`;
79826
79881
  const untabbedNameWrapperClassName = nameAiReview ? "" : `my-2 p-2 recrate-property recrate-property-name-name ${savedProperty === "name" ? untabbedNameSavedClassName : ""}`;
79827
79882
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
79828
- idIsVisible && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-row space-x-2 my-2 p-2", children: [
79883
+ idIsVisible && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: idAiReview ? "flex flex-row space-x-2" : "flex flex-row space-x-2 my-2 p-2", children: [
79829
79884
  /* @__PURE__ */ jsxRuntimeExports.jsx(
79830
79885
  "div",
79831
79886
  {
79832
79887
  "data-recrate-property": "@id",
79833
- className: `flex-grow recrate-property recrate-property-name-id ${savedProperty === "@id" ? "bg-green-200 rounded p-1 my-1" : ""} ${selectedAiApprovalProperty === "@id" ? "recrate-ai-review-current" : ""}`,
79888
+ className: idAiReview ? "flex-grow" : `flex-grow recrate-property recrate-property-name-id ${savedProperty === "@id" ? "bg-green-200 rounded p-1 my-1" : ""} ${selectedAiApprovalProperty === "@id" ? "recrate-ai-review-current" : ""}`,
79834
79889
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
79835
79890
  EntityId,
79836
79891
  {
79837
79892
  entity,
79838
79893
  onUpdate: onUpdateCoreProperty,
79839
79894
  aiEdited: fieldWasAiEdited("@id"),
79840
- aiEditedVariant: fieldAiEditedVariant("@id")
79895
+ aiEditedVariant: fieldAiEditedVariant("@id"),
79896
+ aiReview: idAiReview
79841
79897
  }
79842
79898
  )
79843
79899
  }
@@ -79883,14 +79939,15 @@ const CoreEntityFields = ({
79883
79939
  "div",
79884
79940
  {
79885
79941
  "data-recrate-property": "@id",
79886
- className: `p-2 recrate-property recrate-property-name-id ${savedProperty === "@id" ? "bg-green-200 rounded" : ""} ${selectedAiApprovalProperty === "@id" ? "recrate-ai-review-current" : ""}`,
79942
+ className: idAiReview ? "" : `p-2 recrate-property recrate-property-name-id ${savedProperty === "@id" ? "bg-green-200 rounded" : ""} ${selectedAiApprovalProperty === "@id" ? "recrate-ai-review-current" : ""}`,
79887
79943
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
79888
79944
  EntityId,
79889
79945
  {
79890
79946
  entity,
79891
79947
  onUpdate: onUpdateCoreProperty,
79892
79948
  aiEdited: fieldWasAiEdited("@id"),
79893
- aiEditedVariant: fieldAiEditedVariant("@id")
79949
+ aiEditedVariant: fieldAiEditedVariant("@id"),
79950
+ aiReview: idAiReview
79894
79951
  }
79895
79952
  )
79896
79953
  }
@@ -91952,6 +92009,7 @@ const DeletedLinkedEntityCard = ({
91952
92009
  label: field.label,
91953
92010
  value: field.previousValue
91954
92011
  }));
92012
+ const reviewEntityId = entity.__aiDeleteSourceEntityId ?? entity["@id"];
91955
92013
  if (showDeletedFields) {
91956
92014
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
91957
92015
  AiEntityDiffView,
@@ -91978,7 +92036,7 @@ const DeletedLinkedEntityCard = ({
91978
92036
  },
91979
92037
  styles: { body: { padding: "22px 12px 8px" } },
91980
92038
  hoverable: true,
91981
- onClick: () => onLoadEntity({ id: entity["@id"] }),
92039
+ onClick: () => onLoadEntity({ id: reviewEntityId }),
91982
92040
  children: [
91983
92041
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate-ai-suggestion-badge recrate-ai-entity-status-badge", children: [
91984
92042
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "recrate-ai-suggestion-badge-icon", children: "✦" }),
@@ -92093,7 +92151,7 @@ const UnlinkedLinkedEntityCard = ({
92093
92151
  },
92094
92152
  styles: { body: { padding: "22px 12px 8px" } },
92095
92153
  hoverable: true,
92096
- onClick: () => onLoadEntity({ id: targetEntityId }),
92154
+ onClick: () => onLoadEntity({ id: sourceEntityId }),
92097
92155
  children: [
92098
92156
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate-ai-suggestion-badge recrate-ai-entity-status-badge", children: [
92099
92157
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "recrate-ai-suggestion-badge-icon", children: "✦" }),
@@ -92278,6 +92336,14 @@ const stripLocalEntityIdPrefix = (id2) => {
92278
92336
  if (id2.startsWith("/")) return id2.slice(1);
92279
92337
  return id2;
92280
92338
  };
92339
+ const addLocalEntityIdAliases = (aliases, id2) => {
92340
+ if (!id2) return;
92341
+ const localPath = stripLocalEntityIdPrefix(id2);
92342
+ if (!localPath) return;
92343
+ aliases.add(localPath);
92344
+ aliases.add(`./${localPath}`);
92345
+ aliases.add(`file://./${localPath}`);
92346
+ };
92281
92347
  const getEntityIdAliases = (id2) => {
92282
92348
  if (!id2) return [];
92283
92349
  const aliases = /* @__PURE__ */ new Set([id2]);
@@ -92286,12 +92352,7 @@ const getEntityIdAliases = (id2) => {
92286
92352
  const isLocalFileUrl = decodedId.startsWith("file://./");
92287
92353
  const isLocalPath = !hasUrlScheme(decodedId) || isLocalFileUrl;
92288
92354
  if (decodedId !== "./" && isLocalPath) {
92289
- const localPath = stripLocalEntityIdPrefix(decodedId);
92290
- if (localPath) {
92291
- aliases.add(localPath);
92292
- aliases.add(`./${localPath}`);
92293
- aliases.add(`file://./${localPath}`);
92294
- }
92355
+ addLocalEntityIdAliases(aliases, decodedId);
92295
92356
  }
92296
92357
  return Array.from(aliases);
92297
92358
  };
@@ -92300,11 +92361,28 @@ const entityIdsMatch = (left, right) => {
92300
92361
  const rightAliases = new Set(getEntityIdAliases(right));
92301
92362
  return getEntityIdAliases(left).some((alias) => rightAliases.has(alias));
92302
92363
  };
92364
+ const resolveEntityByIdAliases = (id2, getEntity, indexedEntityIds = []) => {
92365
+ for (const candidateId of getEntityIdAliases(id2)) {
92366
+ const entity = getEntity(candidateId);
92367
+ if (entity !== void 0) return entity;
92368
+ }
92369
+ for (const indexedEntityId of Array.from(indexedEntityIds)) {
92370
+ if (!entityIdsMatch(indexedEntityId, id2)) continue;
92371
+ const entity = getEntity(indexedEntityId);
92372
+ if (entity !== void 0) return entity;
92373
+ }
92374
+ return void 0;
92375
+ };
92303
92376
  const isPendingEntityDeleteApproval = (entityApproval) => {
92304
92377
  const approvalRecords = entityApproval == null ? void 0 : entityApproval.approval;
92305
92378
  if (!Array.isArray(approvalRecords) || approvalRecords.length === 0) return false;
92306
92379
  return approvalRecords.every((approvalRecord) => (approvalRecord == null ? void 0 : approvalRecord.operation) === "delete") && approvalRecords.some((approvalRecord) => !approvalIsApproved(approvalRecord));
92307
92380
  };
92381
+ const isPendingEntityCreateApproval = (entityApproval) => {
92382
+ const approvalRecords = entityApproval == null ? void 0 : entityApproval.approval;
92383
+ if (!Array.isArray(approvalRecords) || approvalRecords.length === 0) return false;
92384
+ return approvalRecords.some((approvalRecord) => (approvalRecord == null ? void 0 : approvalRecord.propertyName) === "@id" && (approvalRecord == null ? void 0 : approvalRecord.operation) === "create" && !approvalIsApproved(approvalRecord));
92385
+ };
92308
92386
  const getDeletedEntityFromApproval = (entityApproval) => {
92309
92387
  if (!(entityApproval == null ? void 0 : entityApproval["@id"]) || !isPendingEntityDeleteApproval(entityApproval)) return void 0;
92310
92388
  const deletedEntity = entityApproval.approval.reduce((entity, approvalRecord) => {
@@ -92332,7 +92410,7 @@ const getDeletedEntityFromApproval = (entityApproval) => {
92332
92410
  };
92333
92411
  const getPendingDeletedEntityFromApproval = (approvalData, entityId) => {
92334
92412
  if (!entityId) return void 0;
92335
- const entityApproval = getApprovalEntities(approvalData).find((item) => entityIdsMatch(item == null ? void 0 : item["@id"], entityId));
92413
+ const entityApproval = getApprovalEntities(approvalData).find((item) => entityIdsMatch(item == null ? void 0 : item["@id"], entityId) && isPendingEntityDeleteApproval(item));
92336
92414
  return getDeletedEntityFromApproval(entityApproval);
92337
92415
  };
92338
92416
  const getPendingDeletedEntitiesForReverseProperty = (approvalData, sourceEntityId, property) => {
@@ -92490,24 +92568,16 @@ const RenderLinkedItem = ({
92490
92568
  const aiUnlinkSourceEntityId = typeof (entity == null ? void 0 : entity.__aiUnlinkSourceEntityId) === "string" ? entity.__aiUnlinkSourceEntityId : void 0;
92491
92569
  const isPendingAiEntityUnlink = Boolean((entity == null ? void 0 : entity.__aiUnlinkedEntity) && aiUnlinkSourceEntityId);
92492
92570
  const effectiveEntity = useMemo$1(() => {
92493
- const hasTypes = Boolean(entity == null ? void 0 : entity["@type"]);
92494
- const hasName = Boolean(entity == null ? void 0 : entity.name);
92495
- if (hasTypes && hasName) {
92496
- return entity;
92497
- }
92498
- const resolved = crateManager.getEntity({
92499
- id: entity["@id"],
92500
- link: false,
92501
- materialise: false
92502
- });
92571
+ const resolved = resolveEntityByIdAliases(entity["@id"], (resolvedId) => crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(crateManager.entityIdIndex ?? {}));
92503
92572
  if (!resolved) {
92504
92573
  return entity;
92505
92574
  }
92506
92575
  return {
92507
- ...resolved,
92508
92576
  ...entity,
92509
- "@type": (entity == null ? void 0 : entity["@type"]) ?? resolved["@type"],
92510
- name: (entity == null ? void 0 : entity.name) ?? resolved.name
92577
+ ...resolved,
92578
+ // Keep the link/approval id visible while using the indexed entity's
92579
+ // real type, name, and fields instead of a materialised Thing stub.
92580
+ "@id": entity["@id"]
92511
92581
  };
92512
92582
  }, [crateManager, entity]);
92513
92583
  const showMap = useMemo$1(() => {
@@ -92533,11 +92603,7 @@ const RenderLinkedItem = ({
92533
92603
  setAssociations([]);
92534
92604
  return;
92535
92605
  }
92536
- const sourceEntity = crateManager.getEntity({
92537
- id: entity["@id"],
92538
- link: false,
92539
- materialise: false
92540
- });
92606
+ const sourceEntity = resolveEntityByIdAliases(entity["@id"], (resolvedId) => crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(crateManager.entityIdIndex ?? {}));
92541
92607
  if (!sourceEntity) {
92542
92608
  setAssociations([]);
92543
92609
  return;
@@ -92552,7 +92618,16 @@ const RenderLinkedItem = ({
92552
92618
  resolveAssociations();
92553
92619
  }, [profileManager.$key, entity["@id"]]);
92554
92620
  const handleLoadEntity = (entityData) => {
92555
- onLoadEntity(entityData);
92621
+ const resolved = resolveEntityByIdAliases(entityData.id, (resolvedId) => crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(crateManager.entityIdIndex ?? {}));
92622
+ const hasPendingReview = getPendingEntityApprovalFieldCount(
92623
+ approvalContext == null ? void 0 : approvalContext.roCrateApproval,
92624
+ entityData.id
92625
+ ) > 0;
92626
+ if (!resolved && hasPendingReview && entityIdsMatch(entityData.id, entity == null ? void 0 : entity["@id"]) && !(entity == null ? void 0 : entity.__aiDeletedEntity) && !(entity == null ? void 0 : entity.__aiUnlinkedEntity)) {
92627
+ setShowAiEntityDiff(true);
92628
+ return;
92629
+ }
92630
+ onLoadEntity({ id: (resolved == null ? void 0 : resolved["@id"]) ?? entityData.id });
92556
92631
  };
92557
92632
  const handleUnlinkEntity = (unlinkData) => {
92558
92633
  if (unlinkData.entity && unlinkData.entity["@id"]) {
@@ -93799,6 +93874,10 @@ class Lookup {
93799
93874
  documents
93800
93875
  };
93801
93876
  }
93877
+ async globalEntities(type4, queryString) {
93878
+ const results = await this.lookup.globalEntities({ type: type4, queryString });
93879
+ return { endpoint: "global", documents: stringifyDocumentType(results.documents) };
93880
+ }
93802
93881
  async dataPacks(type4, queryString) {
93803
93882
  var _a2, _b;
93804
93883
  if (!queryString) return { endpoint: "datapacks", documents: [] };
@@ -93918,6 +93997,97 @@ function stringifyDocumentType(documents) {
93918
93997
  "@type": lodashExports.isArray(d2["@type"]) ? d2["@type"].join(", ") : d2["@type"]
93919
93998
  }));
93920
93999
  }
94000
+ const entityTypes = (entity) => (Array.isArray(entity["@type"]) ? entity["@type"] : [entity["@type"]]).filter((type4) => typeof type4 === "string");
94001
+ const entityName = (entity) => (Array.isArray(entity.name) ? entity.name.join(" ") : String(entity.name ?? "")).normalize("NFKC").trim().replace(/\s+/g, " ").toLocaleLowerCase();
94002
+ const literalValue = (value) => {
94003
+ if (Array.isArray(value)) {
94004
+ const values = value.map(literalValue).filter((item) => item !== void 0);
94005
+ return values.length ? values : void 0;
94006
+ }
94007
+ if (value && typeof value === "object") {
94008
+ if (typeof value["@id"] === "string") return void 0;
94009
+ const entries = Object.keys(value).sort().flatMap((key) => {
94010
+ const child = literalValue(value[key]);
94011
+ return child === void 0 ? [] : [[key, child]];
94012
+ });
94013
+ return entries.length ? Object.fromEntries(entries) : void 0;
94014
+ }
94015
+ return value;
94016
+ };
94017
+ const globalEntityValues = (entity) => {
94018
+ const values = {};
94019
+ for (const key of Object.keys(entity).sort()) {
94020
+ if (["@id", "@type", "@reverse", "type", "globalRecordId"].includes(key)) continue;
94021
+ const value = literalValue(entity[key]);
94022
+ if (value !== void 0) values[key] = value;
94023
+ }
94024
+ return values;
94025
+ };
94026
+ const comparableValues = (entity) => Object.fromEntries(
94027
+ Object.entries(globalEntityValues(entity)).map(([key, value]) => [
94028
+ key,
94029
+ key === "name" && Array.isArray(value) ? value.join(" ") : Array.isArray(value) && value.length === 1 ? value[0] : value
94030
+ ])
94031
+ );
94032
+ const globalEntityValuesMatch = (local, global2) => JSON.stringify(comparableValues(local)) === JSON.stringify(comparableValues(global2));
94033
+ const findGlobalEntityMatches = (crateManager, global2) => {
94034
+ const types2 = entityTypes(global2);
94035
+ const name2 = entityName(global2);
94036
+ return Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {}).flatMap((id2) => {
94037
+ const local = crateManager.getEntity({ id: id2, link: false, materialise: false });
94038
+ if (!local || !entityTypes(local).some((type4) => types2.includes(type4))) return [];
94039
+ if (id2 === global2["@id"] || name2 && entityName(local) === name2 || Object.keys(globalEntityValues(global2)).length > 0 && globalEntityValuesMatch(local, global2)) {
94040
+ return [local];
94041
+ }
94042
+ return [];
94043
+ });
94044
+ };
94045
+ const displayValue = (value) => {
94046
+ if (Array.isArray(value) && value.length === 1) value = value[0];
94047
+ return value === void 0 ? "—" : typeof value === "string" ? value : JSON.stringify(value);
94048
+ };
94049
+ const GlobalEntityConflictDialog = ({ global: global2, matches: matches2, onChoose, onCancel }) => {
94050
+ const { t: t2 } = useTranslation();
94051
+ const globalValues = globalEntityValues(global2);
94052
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
94053
+ Modal,
94054
+ {
94055
+ open: true,
94056
+ title: t2("global_entity_conflict_title"),
94057
+ onCancel,
94058
+ footer: /* @__PURE__ */ jsxRuntimeExports.jsx(Button$1, { onClick: onCancel, children: t2("global_entity_conflict_cancel") }),
94059
+ width: 760,
94060
+ children: [
94061
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: t2("global_entity_conflict_description") }),
94062
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: t2("global_entity_conflict_preserve_links") }),
94063
+ matches2.map((local) => {
94064
+ const localValues = globalEntityValues(local);
94065
+ const properties = [.../* @__PURE__ */ new Set([...Object.keys(localValues), ...Object.keys(globalValues)])].sort();
94066
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { marginTop: 20 }, children: [
94067
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: local.name }),
94068
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { overflowWrap: "anywhere", marginBottom: 8 }, children: local["@id"] }),
94069
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("table", { style: { width: "100%", tableLayout: "fixed", borderCollapse: "collapse" }, children: [
94070
+ /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { children: [
94071
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { scope: "col", children: t2("global_entity_conflict_property") }),
94072
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { scope: "col", children: t2("global_entity_conflict_crate_values") }),
94073
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { scope: "col", children: t2("global_entity_conflict_global_values") })
94074
+ ] }) }),
94075
+ /* @__PURE__ */ jsxRuntimeExports.jsx("tbody", { children: properties.map((property) => /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { children: [
94076
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { scope: "row", style: { textAlign: "left", padding: 6, overflowWrap: "anywhere" }, children: property }),
94077
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { style: { padding: 6, overflowWrap: "anywhere" }, children: displayValue(localValues[property]) }),
94078
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { style: { padding: 6, overflowWrap: "anywhere" }, children: displayValue(globalValues[property]) })
94079
+ ] }, property)) })
94080
+ ] }),
94081
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { display: "flex", flexWrap: "wrap", gap: 8, marginTop: 12 }, children: [
94082
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button$1, { type: "primary", onClick: () => onChoose(local, false), children: t2("global_entity_conflict_keep_crate") }),
94083
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Button$1, { onClick: () => onChoose(local, true), children: t2("global_entity_conflict_use_global") })
94084
+ ] })
94085
+ ] }, local["@id"]);
94086
+ })
94087
+ ]
94088
+ }
94089
+ );
94090
+ };
93921
94091
  const newEntityFromName = (type4, name2) => ({
93922
94092
  type: "new",
93923
94093
  "@id": name2,
@@ -93926,16 +94096,19 @@ const newEntityFromName = (type4, name2) => ({
93926
94096
  });
93927
94097
  const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
93928
94098
  const { t: t2 } = useTranslation();
94099
+ const { modal } = App.useApp();
93929
94100
  const crateManager = useContext(CrateManagerContext);
93930
94101
  const lookupHandler = useContext(LookupsContext);
93931
- useStateStore();
93932
94102
  const [loading, setLoading] = useState(false);
93933
94103
  const [selection2, setSelection] = useState(null);
93934
94104
  const [matches2, setMatches] = useState([]);
94105
+ const [conflict, setConflict] = useState(null);
93935
94106
  const inputValue = useRef("");
94107
+ const searchVersion = useRef(0);
93936
94108
  const promiseTimeout = 2500;
93937
94109
  const querySearch = async (queryString) => {
93938
94110
  var _a2;
94111
+ const version2 = ++searchVersion.current;
93939
94112
  setLoading(true);
93940
94113
  const lookup = new Lookup({
93941
94114
  config: (_a2 = crateManager == null ? void 0 : crateManager.profile) == null ? void 0 : _a2.lookup,
@@ -93947,6 +94120,15 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
93947
94120
  if (crateManager == null ? void 0 : crateManager.getEntities) {
93948
94121
  lookups.push(wrapPromise(lookup.getEntities(type4, queryString), promiseTimeout));
93949
94122
  }
94123
+ if (lookupHandler == null ? void 0 : lookupHandler.globalEntities) {
94124
+ lookups.push(wrapPromise(
94125
+ lookup.globalEntities(type4, queryString).catch((error2) => {
94126
+ console.error("Global entity lookup failed:", error2);
94127
+ return { endpoint: "global", documents: [] };
94128
+ }),
94129
+ promiseTimeout
94130
+ ));
94131
+ }
93950
94132
  if (lookupHandler == null ? void 0 : lookupHandler.dataPacks) {
93951
94133
  lookups.push(
93952
94134
  wrapPromise(lookup.dataPacks(type4, queryString), promiseTimeout, {
@@ -93978,13 +94160,18 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
93978
94160
  const responses = await Promise.all(lookups);
93979
94161
  const newMatches = [];
93980
94162
  responses.forEach((response) => {
93981
- var _a3, _b, _c, _d, _e2;
94163
+ var _a3, _b, _c, _d, _e2, _f;
93982
94164
  if (response.endpoint === "internal" && ((_a3 = response.documents) == null ? void 0 : _a3.length)) {
93983
94165
  newMatches.push({
93984
94166
  label: t2("associate_existing_entity"),
93985
94167
  entities: response.documents.map((e3) => ({ ...e3, type: "internal" })).slice(0, 5)
93986
94168
  });
93987
- } else if (response.endpoint === "templates" && ((_b = response.documents) == null ? void 0 : _b.length)) {
94169
+ } else if (response.endpoint === "global" && ((_b = response.documents) == null ? void 0 : _b.length)) {
94170
+ newMatches.push({
94171
+ label: t2("associate_global_entity"),
94172
+ entities: response.documents.map((entity) => ({ ...entity, type: "global" }))
94173
+ });
94174
+ } else if (response.endpoint === "templates" && ((_c = response.documents) == null ? void 0 : _c.length)) {
93988
94175
  newMatches.push({
93989
94176
  label: t2("associate_entity_from_template"),
93990
94177
  entities: response.documents.map((entity) => ({
@@ -93992,17 +94179,17 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
93992
94179
  type: "template"
93993
94180
  }))
93994
94181
  });
93995
- } else if (response.endpoint === "ror" && ((_c = response.documents) == null ? void 0 : _c.length)) {
94182
+ } else if (response.endpoint === "ror" && ((_d = response.documents) == null ? void 0 : _d.length)) {
93996
94183
  newMatches.push({
93997
94184
  label: t2("associate_organization_from_ror"),
93998
94185
  entities: response.documents.map((entity) => ({ ...entity, type: "ror" }))
93999
94186
  });
94000
- } else if (response.endpoint === "entities" && ((_d = response.documents) == null ? void 0 : _d.length)) {
94187
+ } else if (response.endpoint === "entities" && ((_e2 = response.documents) == null ? void 0 : _e2.length)) {
94001
94188
  newMatches.push({
94002
94189
  label: t2("associate_user_created_entity"),
94003
94190
  entities: response.documents.map((entity) => ({ ...entity, type: "datapack" }))
94004
94191
  });
94005
- } else if (response.endpoint === "datapacks" && ((_e2 = response.documents) == null ? void 0 : _e2.length)) {
94192
+ } else if (response.endpoint === "datapacks" && ((_f = response.documents) == null ? void 0 : _f.length)) {
94006
94193
  newMatches.push({
94007
94194
  label: t2("associate_from_datapack"),
94008
94195
  entities: response.documents.map((entity) => ({ ...entity, type: "datapack" }))
@@ -94015,21 +94202,63 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94015
94202
  entities: newEntity
94016
94203
  });
94017
94204
  }
94205
+ if (version2 !== searchVersion.current) return;
94018
94206
  setMatches(newMatches);
94019
94207
  setLoading(false);
94020
94208
  };
94021
- const debouncedQuerySearch = debounce(querySearch, 1e3, { leading: true });
94209
+ const debouncedQuerySearch = useMemo$1(
94210
+ () => debounce(querySearch, 1e3, { leading: true }),
94211
+ [type4, crateManager, lookupHandler, t2]
94212
+ );
94022
94213
  useEffect(() => {
94023
94214
  querySearch("");
94024
- }, [type4]);
94215
+ return () => {
94216
+ debouncedQuerySearch.cancel();
94217
+ searchVersion.current += 1;
94218
+ };
94219
+ }, [debouncedQuerySearch]);
94220
+ const mapGlobalEntity = (recordId, entityId) => {
94221
+ if (entityId && (lookupHandler == null ? void 0 : lookupHandler.onGlobalEntityAdded)) {
94222
+ void lookupHandler.onGlobalEntityAdded({ recordId, entityId }).catch((error2) => console.error("Failed to map global entity:", error2));
94223
+ }
94224
+ };
94225
+ const reuseGlobalEntity = (global2, local, useGlobalValues, explainReuse = false) => {
94226
+ const entityId = onLinkEntity({
94227
+ json: local,
94228
+ ...useGlobalValues ? { globalEntityValues: global2 } : {}
94229
+ });
94230
+ if (entityId !== null) {
94231
+ mapGlobalEntity(global2.globalRecordId, entityId ?? local["@id"]);
94232
+ if (explainReuse) {
94233
+ modal.info({
94234
+ title: t2("global_entity_already_exists_title"),
94235
+ content: t2("global_entity_reused_notice", { name: local.name || local["@id"] }),
94236
+ okText: t2("global_entity_reused_ok")
94237
+ });
94238
+ }
94239
+ }
94240
+ setConflict(null);
94241
+ };
94025
94242
  const handleSelect = (value, option) => {
94026
94243
  const entity = option.entity;
94027
94244
  if (entity) {
94245
+ const { globalRecordId, type: source, ...json } = entity;
94028
94246
  const updatedEntity = {
94029
- ...entity,
94247
+ ...json,
94248
+ ...source === "global" ? {} : { type: source },
94030
94249
  "@type": entity["@type"].split(", ").map((t22) => t22.trim())
94031
94250
  };
94032
- if ((entity == null ? void 0 : entity.type) === "internal") {
94251
+ if (source === "global") {
94252
+ const existing = findGlobalEntityMatches(crateManager, updatedEntity);
94253
+ if (existing.length === 1 && globalEntityValuesMatch(existing[0], updatedEntity)) {
94254
+ reuseGlobalEntity(entity, existing[0], false, true);
94255
+ } else if (existing.length) {
94256
+ setConflict({ global: entity, matches: existing });
94257
+ } else {
94258
+ const entityId = onCreateEntity({ json: updatedEntity, fromGlobalEntity: true });
94259
+ mapGlobalEntity(globalRecordId, entityId);
94260
+ }
94261
+ } else if (source === "internal") {
94033
94262
  onLinkEntity({ json: updatedEntity });
94034
94263
  } else {
94035
94264
  onCreateEntity({ json: updatedEntity });
@@ -94094,27 +94323,38 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94094
94323
  ] });
94095
94324
  }
94096
94325
  };
94097
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: loading ? "opacity-50" : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
94098
- Select,
94099
- {
94100
- showSearch: true,
94101
- size: "middle",
94102
- value: selection2,
94103
- placeholder: t2("select_existing_or_create_new") || "select an existing entity or create a new one",
94104
- defaultActiveFirstOption: false,
94105
- filterOption: false,
94106
- onSearch: handleSearch,
94107
- onInputKeyDown: handleInputKeyDown,
94108
- onChange: handleSelect,
94109
- notFoundContent: loading ? "Loading..." : "No results",
94110
- options: matches2.flatMap((group) => [
94111
- { label: /* @__PURE__ */ jsxRuntimeExports.jsx(Typography.Text, { strong: true, children: group.label }), options: group.entities.map((entity) => ({ label: renderOption({ entity }), value: entity["@id"], entity })) }
94112
- ]).flatMap((group) => [
94113
- { label: group.label, options: group.options }
94114
- ]),
94115
- optionRender: (option) => option.label
94116
- }
94117
- ) });
94326
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: loading ? "opacity-50" : "", children: [
94327
+ conflict && /* @__PURE__ */ jsxRuntimeExports.jsx(
94328
+ GlobalEntityConflictDialog,
94329
+ {
94330
+ global: conflict.global,
94331
+ matches: conflict.matches,
94332
+ onChoose: (local, useGlobalValues) => reuseGlobalEntity(conflict.global, local, useGlobalValues),
94333
+ onCancel: () => setConflict(null)
94334
+ }
94335
+ ),
94336
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
94337
+ Select,
94338
+ {
94339
+ showSearch: true,
94340
+ size: "middle",
94341
+ value: selection2,
94342
+ placeholder: t2("select_existing_or_create_new") || "select an existing entity or create a new one",
94343
+ defaultActiveFirstOption: false,
94344
+ filterOption: false,
94345
+ onSearch: handleSearch,
94346
+ onInputKeyDown: handleInputKeyDown,
94347
+ onChange: handleSelect,
94348
+ notFoundContent: loading ? "Loading..." : "No results",
94349
+ options: matches2.flatMap((group) => [
94350
+ { label: /* @__PURE__ */ jsxRuntimeExports.jsx(Typography.Text, { strong: true, children: group.label }), options: group.entities.map((entity) => ({ label: renderOption({ entity }), value: entity["@id"], entity })) }
94351
+ ]).flatMap((group) => [
94352
+ { label: group.label, options: group.options }
94353
+ ]),
94354
+ optionRender: (option) => option.label
94355
+ }
94356
+ )
94357
+ ] });
94118
94358
  };
94119
94359
  const BulkAdd = ({ types: types2, primitives, onCreateEntity }) => {
94120
94360
  const { t: t2 } = useTranslation();
@@ -94296,12 +94536,14 @@ const Add = ({
94296
94536
  close();
94297
94537
  };
94298
94538
  const createEntity = (data) => {
94299
- onCreateEntity({ ...data, property, propertyId: definition.id });
94539
+ const entityId = onCreateEntity({ ...data, property, propertyId: definition.id });
94300
94540
  close();
94541
+ return entityId;
94301
94542
  };
94302
94543
  const linkEntity = (data) => {
94303
- onLinkEntity({ ...data, property, propertyId: definition.id });
94544
+ const entityId = onLinkEntity({ ...data, property, propertyId: definition.id });
94304
94545
  close();
94546
+ return entityId;
94305
94547
  };
94306
94548
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
94307
94549
  "div",
@@ -94545,6 +94787,24 @@ const EntityProperty = ({
94545
94787
  const linkedReviewInstances = linkInstances.map((instance2) => {
94546
94788
  var _a3;
94547
94789
  const targetEntityId = (_a3 = instance2.value) == null ? void 0 : _a3["@id"];
94790
+ const resolvedTargetEntity = resolveEntityByIdAliases(targetEntityId, (resolvedId) => {
94791
+ var _a4;
94792
+ return (_a4 = crateManager == null ? void 0 : crateManager.getEntity) == null ? void 0 : _a4.call(crateManager, { id: resolvedId, link: false, materialise: false });
94793
+ }, Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {}));
94794
+ const deletedEntity = resolvedTargetEntity ? void 0 : getPendingDeletedEntityFromApproval(
94795
+ approvalContext == null ? void 0 : approvalContext.roCrateApproval,
94796
+ targetEntityId
94797
+ );
94798
+ if (deletedEntity) {
94799
+ return {
94800
+ ...instance2,
94801
+ value: {
94802
+ ...deletedEntity,
94803
+ __aiDeleteSourceEntityId: entity == null ? void 0 : entity["@id"],
94804
+ __aiDeleteSourceProperty: property
94805
+ }
94806
+ };
94807
+ }
94548
94808
  if (!targetEntityId || !Array.from(addedReferenceIds).some((id2) => entityIdsMatch(id2, targetEntityId))) {
94549
94809
  return instance2;
94550
94810
  }
@@ -121426,7 +121686,7 @@ const DialogBrowseEntities = ({
121426
121686
  query: "",
121427
121687
  selectedEntityType: void 0
121428
121688
  });
121429
- const entityTypes = useMemo$1(() => crateManager.getEntityTypes(), [crateManager]);
121689
+ const entityTypes2 = useMemo$1(() => crateManager.getEntityTypes(), [crateManager]);
121430
121690
  const entities = useMemo$1(() => {
121431
121691
  const offset2 = (data.currentPage - 1) * data.pageSize;
121432
121692
  let entities2;
@@ -121480,7 +121740,7 @@ const DialogBrowseEntities = ({
121480
121740
  size: "middle",
121481
121741
  children: [
121482
121742
  /* @__PURE__ */ jsxRuntimeExports.jsx(Select.Option, { value: "", children: t2("filter_by_type") }),
121483
- entityTypes.map((t22) => /* @__PURE__ */ jsxRuntimeExports.jsx(Select.Option, { value: t22, children: t22 }, t22))
121743
+ entityTypes2.map((t22) => /* @__PURE__ */ jsxRuntimeExports.jsx(Select.Option, { value: t22, children: t22 }, t22))
121484
121744
  ]
121485
121745
  }
121486
121746
  ),
@@ -123796,12 +124056,14 @@ const useScrollViewportHeight = ({
123796
124056
  characterData: true
123797
124057
  });
123798
124058
  }
123799
- requestAnimationFrame(() => computeScrollViewportHeight());
124059
+ const animationFrame = requestAnimationFrame(() => computeScrollViewportHeight());
123800
124060
  const delayedMeasure = window.setTimeout(() => computeScrollViewportHeight(), 120);
123801
124061
  return () => {
123802
124062
  resizeObserver2.disconnect();
123803
124063
  mutationObserver.disconnect();
124064
+ cancelAnimationFrame(animationFrame);
123804
124065
  window.clearTimeout(delayedMeasure);
124066
+ computeScrollViewportHeight.cancel();
123805
124067
  };
123806
124068
  }, [computeScrollViewportHeight, activeTab, renderTabs, tabsLength, entityId, reverseSidebarVisible]);
123807
124069
  return {
@@ -123908,19 +124170,37 @@ const useEntityMutationHandlers = ({
123908
124170
  var _a2;
123909
124171
  try {
123910
124172
  (_a2 = data.json) == null ? true : delete _a2.type;
123911
- crateManager.ingestAndLink({
123912
- id: entity["@id"],
123913
- property: data.property,
123914
- propertyId: data.propertyId,
123915
- json: data.json
123916
- });
124173
+ let createdEntityId = data.json["@id"];
124174
+ if (data.fromGlobalEntity) {
124175
+ const existed = crateManager.getEntity({ id: createdEntityId, materialise: false, link: false });
124176
+ const added = crateManager.addEntity(data.json);
124177
+ createdEntityId = added["@id"];
124178
+ try {
124179
+ crateManager.linkEntity({
124180
+ id: entity["@id"],
124181
+ property: data.property,
124182
+ propertyId: data.propertyId,
124183
+ value: { "@id": createdEntityId }
124184
+ });
124185
+ } catch (error2) {
124186
+ if (!existed) crateManager.deleteEntity({ id: createdEntityId });
124187
+ throw error2;
124188
+ }
124189
+ } else {
124190
+ crateManager.ingestAndLink({
124191
+ id: entity["@id"],
124192
+ property: data.property,
124193
+ propertyId: data.propertyId,
124194
+ json: data.json
124195
+ });
124196
+ }
123917
124197
  let warnings = crateManager.getWarnings();
123918
124198
  if (warnings.hasWarning) {
123919
124199
  onWarning();
123920
124200
  }
123921
124201
  refresh();
123922
124202
  saveCratePreservingView();
123923
- return data.json["@id"];
124203
+ return createdEntityId;
123924
124204
  } catch (error2) {
123925
124205
  onError();
123926
124206
  return null;
@@ -123954,6 +124234,20 @@ const useEntityMutationHandlers = ({
123954
124234
  };
123955
124235
  const handleLinkEntity = (data) => {
123956
124236
  try {
124237
+ if (data.globalEntityValues) {
124238
+ const local = crateManager.getEntity({ id: data.json["@id"], link: false, materialise: false });
124239
+ if (!local) return null;
124240
+ for (const [property, value] of Object.entries(globalEntityValues(data.globalEntityValues))) {
124241
+ const values = Array.isArray(value) ? value : [value];
124242
+ if (property === "name") {
124243
+ crateManager.updateProperty({ id: local["@id"], property, value });
124244
+ } else {
124245
+ const localValues = Array.isArray(local[property]) ? local[property] : [local[property]];
124246
+ const references = localValues.filter((item) => item && typeof item === "object" && typeof item["@id"] === "string");
124247
+ crateManager.updateProperty({ id: local["@id"], property, value: [...references, ...values] });
124248
+ }
124249
+ }
124250
+ }
123957
124251
  crateManager.linkEntity({
123958
124252
  id: entity["@id"],
123959
124253
  property: data.property,
@@ -123962,8 +124256,10 @@ const useEntityMutationHandlers = ({
123962
124256
  });
123963
124257
  refresh();
123964
124258
  saveCratePreservingView();
124259
+ return data.json["@id"];
123965
124260
  } catch (error2) {
123966
124261
  onError();
124262
+ return null;
123967
124263
  }
123968
124264
  };
123969
124265
  const handleDeleteProperty = (data) => {
@@ -124171,10 +124467,10 @@ const useEntityNavigationState = ({
124171
124467
  state.editorState.update({ id: activeEntityId, tab: tabName });
124172
124468
  state.editorState.updateNavigationState({ activeTab: tabName });
124173
124469
  }, [contextEntity, state]);
124174
- const saveCratePreservingView = useCallback(() => {
124470
+ const saveCratePreservingView = useCallback((activeEntityId) => {
124175
124471
  saveTabToState(activeTab);
124176
124472
  captureCurrentViewContext(activeTab);
124177
- onSaveCrate();
124473
+ onSaveCrate(activeEntityId);
124178
124474
  }, [activeTab, captureCurrentViewContext, onSaveCrate, saveTabToState]);
124179
124475
  return {
124180
124476
  captureCurrentViewContext,
@@ -125284,17 +125580,9 @@ const RenderEntity = forwardRef((props, ref) => {
125284
125580
  if (isPendingEntityDeleteApproval(entityApproval)) {
125285
125581
  const reviewTarget = getDeletedEntityReviewTarget(entityApproval);
125286
125582
  if (!(reviewTarget == null ? void 0 : reviewTarget.entityId)) return false;
125287
- return Boolean(crateManager == null ? void 0 : crateManager.getEntity({
125288
- id: reviewTarget.entityId,
125289
- link: false,
125290
- materialise: false
125291
- }));
125583
+ return Boolean(resolveEntityByIdAliases(reviewTarget.entityId, (resolvedId) => crateManager == null ? void 0 : crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {})));
125292
125584
  }
125293
- return Boolean(crateManager == null ? void 0 : crateManager.getEntity({
125294
- id: entityId,
125295
- link: false,
125296
- materialise: false
125297
- }));
125585
+ return Boolean(resolveEntityByIdAliases(entityId, (resolvedId) => crateManager == null ? void 0 : crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {})));
125298
125586
  }, [approvalContext == null ? void 0 : approvalContext.roCrateApproval, crateManager]);
125299
125587
  const pendingOtherAiApprovalEntities = useMemo$1(() => getPendingApprovalEntities(approvalContext == null ? void 0 : approvalContext.roCrateApproval).filter((entityApproval) => !entityIdsMatch(entityApproval == null ? void 0 : entityApproval["@id"], contextEntity == null ? void 0 : contextEntity["@id"]) && canReviewAiApprovalEntity(entityApproval)), [approvalContext == null ? void 0 : approvalContext.roCrateApproval, canReviewAiApprovalEntity, contextEntity == null ? void 0 : contextEntity["@id"]]);
125300
125588
  const pendingOtherAiApprovalFieldCount = useMemo$1(() => pendingOtherAiApprovalEntities.reduce((count, entityApproval) => {
@@ -125320,21 +125608,19 @@ const RenderEntity = forwardRef((props, ref) => {
125320
125608
  if (isPendingEntityDeleteApproval(entityApproval)) {
125321
125609
  const reviewTarget = getDeletedEntityReviewTarget(entityApproval);
125322
125610
  if (!reviewTarget) continue;
125323
- const targetEntity = crateManager == null ? void 0 : crateManager.getEntity({
125324
- id: reviewTarget.entityId,
125325
- link: false,
125326
- materialise: false
125327
- });
125328
- if (!targetEntity) continue;
125611
+ const targetEntity2 = resolveEntityByIdAliases(reviewTarget.entityId, (resolvedId) => crateManager == null ? void 0 : crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {}));
125612
+ if (!targetEntity2) continue;
125329
125613
  setFieldTitleFilter("");
125330
125614
  if (hideEmptyFields) {
125331
125615
  setHideEmptyFields(false);
125332
125616
  }
125333
125617
  pendingAiScrollPropertyRef.current = reviewTarget.property;
125334
- onLoadEntity({ id: reviewTarget.entityId });
125618
+ onLoadEntity({ id: targetEntity2["@id"] });
125335
125619
  return;
125336
125620
  }
125337
- onLoadEntity({ id: nextEntityId });
125621
+ const targetEntity = resolveEntityByIdAliases(nextEntityId, (resolvedId) => crateManager == null ? void 0 : crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {}));
125622
+ if (!targetEntity) continue;
125623
+ onLoadEntity({ id: targetEntity["@id"] });
125338
125624
  return;
125339
125625
  }
125340
125626
  }, [approvalContext == null ? void 0 : approvalContext.roCrateApproval, crateManager, hideEmptyFields, onLoadEntity, pendingOtherAiApprovalEntities]);
@@ -125938,43 +126224,6 @@ const RenderEntity = forwardRef((props, ref) => {
125938
126224
  scrollToAiApprovalProperty
125939
126225
  ]);
125940
126226
  const isEntityReference2 = (value) => Boolean(value && typeof value === "object" && typeof value["@id"] === "string");
125941
- const restoreNonCoreApprovalValue = (approvalRecord) => {
125942
- const property = approvalRecord == null ? void 0 : approvalRecord.propertyName;
125943
- if (!property) return;
125944
- if (entityHasPropertyValue(contextEntity, property)) {
125945
- crateManager.deleteProperty({ id: entity["@id"], property });
125946
- }
125947
- const previousValue = approvalRecord == null ? void 0 : approvalRecord.previousValue;
125948
- if (!propertyValueHasContent(previousValue)) return;
125949
- const previousValues = Array.isArray(previousValue) ? previousValue : [previousValue];
125950
- if (previousValues.length === 0) return;
125951
- if (previousValues.every(isEntityReference2)) {
125952
- previousValues.forEach((value) => {
125953
- crateManager.setProperty({ id: entity["@id"], property, value });
125954
- });
125955
- return;
125956
- }
125957
- crateManager.updateProperty({
125958
- id: entity["@id"],
125959
- property,
125960
- value: previousValues
125961
- });
125962
- };
125963
- const restoreApprovalValue = (approvalRecord) => {
125964
- const property = approvalRecord == null ? void 0 : approvalRecord.propertyName;
125965
- if (!property) return;
125966
- if (["@id", "@type", "name"].includes(property)) {
125967
- if (propertyValueHasContent(approvalRecord == null ? void 0 : approvalRecord.previousValue)) {
125968
- crateManager.updateProperty({
125969
- id: entity["@id"],
125970
- property,
125971
- value: approvalRecord.previousValue
125972
- });
125973
- }
125974
- return;
125975
- }
125976
- restoreNonCoreApprovalValue(approvalRecord);
125977
- };
125978
126227
  const restoreEntityApprovalValue = (targetEntity, approvalRecord) => {
125979
126228
  const property = approvalRecord == null ? void 0 : approvalRecord.propertyName;
125980
126229
  const entityId = targetEntity == null ? void 0 : targetEntity["@id"];
@@ -126020,22 +126269,41 @@ const RenderEntity = forwardRef((props, ref) => {
126020
126269
  });
126021
126270
  };
126022
126271
  const handleRejectAiProperty = (approvalRecord) => {
126023
- var _a3;
126272
+ var _a3, _b2;
126024
126273
  try {
126025
- if (!(approvalRecord == null ? void 0 : approvalRecord.propertyName) || !propertyValueHasContent(approvalRecord.previousValue)) return;
126026
- (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalPropertyApproved) == null ? void 0 : _a3.call(approvalContext, {
126274
+ if (!(approvalRecord == null ? void 0 : approvalRecord.propertyName)) return;
126275
+ if (approvalRecord.propertyName === "@id" && approvalRecord.operation === "create") {
126276
+ crateManager.deleteEntity({ id: entity["@id"] });
126277
+ saveCratePreservingView("./");
126278
+ (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126279
+ entityId: entity["@id"],
126280
+ decision: "reject",
126281
+ value: { "@id": void 0 }
126282
+ });
126283
+ onLoadEntity({ id: "./" });
126284
+ return;
126285
+ }
126286
+ if (!propertyValueHasContent(approvalRecord.previousValue)) return;
126287
+ (_b2 = approvalContext == null ? void 0 : approvalContext.markApprovalPropertyApproved) == null ? void 0 : _b2.call(approvalContext, {
126027
126288
  entityId: entity["@id"],
126028
126289
  propertyName: approvalRecord.propertyName,
126029
126290
  decision: "reject",
126030
126291
  value: approvalRecord.previousValue
126031
126292
  });
126032
- crateManager.updateProperty({
126293
+ const previousEntityId = entity["@id"];
126294
+ const updatedEntity = crateManager.updateProperty({
126033
126295
  id: entity["@id"],
126034
126296
  property: approvalRecord.propertyName,
126035
126297
  value: approvalRecord.previousValue
126036
126298
  });
126037
- refresh();
126038
- saveCratePreservingView();
126299
+ const restoredEntityId = approvalRecord.propertyName === "@id" ? updatedEntity == null ? void 0 : updatedEntity["@id"] : void 0;
126300
+ if (restoredEntityId && restoredEntityId !== previousEntityId) {
126301
+ saveCratePreservingView(restoredEntityId);
126302
+ navigateToRestoredEntity(previousEntityId, restoredEntityId);
126303
+ } else {
126304
+ refresh();
126305
+ saveCratePreservingView();
126306
+ }
126039
126307
  notifySave(approvalRecord.propertyName);
126040
126308
  } catch (error2) {
126041
126309
  console.error(error2);
@@ -126081,11 +126349,14 @@ const RenderEntity = forwardRef((props, ref) => {
126081
126349
  });
126082
126350
  };
126083
126351
  const restoreEditedEntityApprovalValues = (entityId) => {
126084
- const targetEntity = crateManager.getEntity({
126085
- id: entityId,
126086
- link: false,
126087
- materialise: false
126088
- });
126352
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126353
+ const targetEntity = resolveEntityByIdAliases(entityId, (resolvedId) => crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(crateManager.entityIdIndex ?? {}));
126354
+ if (isPendingEntityCreateApproval(entityApproval)) {
126355
+ if (targetEntity) {
126356
+ crateManager.deleteEntity({ id: targetEntity["@id"] });
126357
+ }
126358
+ return { "@id": void 0 };
126359
+ }
126089
126360
  if (!targetEntity) return void 0;
126090
126361
  const approvalRecords = getPendingEntityApprovalRecords(
126091
126362
  approvalContext == null ? void 0 : approvalContext.roCrateApproval,
@@ -126101,22 +126372,53 @@ const RenderEntity = forwardRef((props, ref) => {
126101
126372
  approvalRecords.filter((approvalRecord) => (approvalRecord == null ? void 0 : approvalRecord.propertyName) === "@id").forEach((approvalRecord) => restoreEntityApprovalValue(targetEntity, approvalRecord));
126102
126373
  return restoredValues;
126103
126374
  };
126375
+ const getVerifiedRestoredEntityId = (entityId, restoredValues) => {
126376
+ const requestedId = typeof (restoredValues == null ? void 0 : restoredValues["@id"]) === "string" ? restoredValues["@id"].trim() : "";
126377
+ if (!requestedId || requestedId === entityId) return void 0;
126378
+ const restoredEntity = crateManager.getEntity({
126379
+ id: requestedId,
126380
+ link: false,
126381
+ materialise: false
126382
+ });
126383
+ return restoredEntity == null ? void 0 : restoredEntity["@id"];
126384
+ };
126385
+ const navigateToRestoredEntity = (previousEntityId, restoredEntityId) => {
126386
+ if (!restoredEntityId || restoredEntityId === previousEntityId) return;
126387
+ handleLoadEntityWithContext({ id: restoredEntityId });
126388
+ state.editorState.replaceId({ id: previousEntityId, newId: restoredEntityId });
126389
+ };
126104
126390
  const handleRejectAiEntityEdit = (editedEntity) => {
126105
126391
  var _a3;
126106
126392
  try {
126107
126393
  const entityId = editedEntity == null ? void 0 : editedEntity["@id"];
126108
126394
  if (!entityId) return;
126395
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126396
+ const rejectingCreatedEntity = isPendingEntityCreateApproval(entityApproval);
126109
126397
  const restoredValues = restoreEditedEntityApprovalValues(entityId);
126110
126398
  if (!restoredValues) return;
126111
- if (entityIdsMatch(entityId, entity == null ? void 0 : entity["@id"])) {
126399
+ const restoredEntityId = rejectingCreatedEntity ? void 0 : getVerifiedRestoredEntityId(entityId, restoredValues);
126400
+ const editsCurrentEntity = entityIdsMatch(entityId, entity == null ? void 0 : entity["@id"]);
126401
+ const rejectsCurrentCreatedEntity = rejectingCreatedEntity && editsCurrentEntity;
126402
+ if (editsCurrentEntity && !rejectingCreatedEntity) {
126112
126403
  refresh();
126113
126404
  }
126114
- saveCratePreservingView();
126405
+ let nextActiveEntityId;
126406
+ if (rejectsCurrentCreatedEntity) {
126407
+ nextActiveEntityId = "./";
126408
+ } else if (editsCurrentEntity) {
126409
+ nextActiveEntityId = restoredEntityId;
126410
+ }
126411
+ saveCratePreservingView(nextActiveEntityId);
126115
126412
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126116
126413
  entityId,
126117
126414
  decision: "reject",
126118
126415
  value: restoredValues
126119
126416
  });
126417
+ if (rejectsCurrentCreatedEntity) {
126418
+ onLoadEntity({ id: "./" });
126419
+ } else if (editsCurrentEntity) {
126420
+ navigateToRestoredEntity(entityId, restoredEntityId);
126421
+ }
126120
126422
  } catch (error2) {
126121
126423
  console.error(error2);
126122
126424
  onError();
@@ -126125,20 +126427,27 @@ const RenderEntity = forwardRef((props, ref) => {
126125
126427
  const handleRejectCurrentEntityAiApprovals = () => {
126126
126428
  var _a3;
126127
126429
  try {
126128
- const restoredValues = pendingAiApprovals.reduce((acc, approvalRecord) => {
126129
- if (approvalRecord == null ? void 0 : approvalRecord.propertyName) {
126130
- acc[approvalRecord.propertyName] = approvalRecord.previousValue;
126131
- }
126132
- restoreApprovalValue(approvalRecord);
126133
- return acc;
126134
- }, {});
126135
- refresh();
126136
- saveCratePreservingView();
126430
+ const entityId = entity == null ? void 0 : entity["@id"];
126431
+ if (!entityId) return;
126432
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126433
+ const rejectingCreatedEntity = isPendingEntityCreateApproval(entityApproval);
126434
+ const restoredValues = restoreEditedEntityApprovalValues(entityId);
126435
+ if (!restoredValues) return;
126436
+ const restoredEntityId = rejectingCreatedEntity ? void 0 : getVerifiedRestoredEntityId(entityId, restoredValues);
126437
+ if (!rejectingCreatedEntity) {
126438
+ refresh();
126439
+ }
126440
+ saveCratePreservingView(rejectingCreatedEntity ? "./" : restoredEntityId);
126137
126441
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126138
- entityId: entity["@id"],
126442
+ entityId,
126139
126443
  decision: "reject",
126140
126444
  value: restoredValues
126141
126445
  });
126446
+ if (rejectingCreatedEntity) {
126447
+ onLoadEntity({ id: "./" });
126448
+ } else {
126449
+ navigateToRestoredEntity(entityId, restoredEntityId);
126450
+ }
126142
126451
  } catch (error2) {
126143
126452
  console.error(error2);
126144
126453
  onError();
@@ -126276,6 +126585,9 @@ const RenderEntity = forwardRef((props, ref) => {
126276
126585
  var _a3;
126277
126586
  try {
126278
126587
  const restoredValues = {};
126588
+ const currentEntityId = entity == null ? void 0 : entity["@id"];
126589
+ let restoredCurrentEntityId;
126590
+ let rejectsCurrentCreatedEntity = false;
126279
126591
  const pendingEntities = getPendingApprovalEntities(approvalContext == null ? void 0 : approvalContext.roCrateApproval);
126280
126592
  pendingContextApprovalItems.forEach((approvalItem) => {
126281
126593
  var _a4;
@@ -126287,6 +126599,9 @@ const RenderEntity = forwardRef((props, ref) => {
126287
126599
  pendingEntities.forEach((entityApproval) => {
126288
126600
  const entityId = entityApproval == null ? void 0 : entityApproval["@id"];
126289
126601
  if (!entityId) return;
126602
+ if (isPendingEntityCreateApproval(entityApproval) && entityIdsMatch(entityId, currentEntityId)) {
126603
+ rejectsCurrentCreatedEntity = true;
126604
+ }
126290
126605
  if (isPendingEntityDeleteApproval(entityApproval)) {
126291
126606
  const deletedEntity = getDeletedEntityFromApproval(entityApproval);
126292
126607
  if (deletedEntity) {
@@ -126297,14 +126612,24 @@ const RenderEntity = forwardRef((props, ref) => {
126297
126612
  const restoredEntityValues = restoreEditedEntityApprovalValues(entityId);
126298
126613
  if (restoredEntityValues) {
126299
126614
  restoredValues[entityId] = restoredEntityValues;
126615
+ if (entityIdsMatch(entityId, currentEntityId)) {
126616
+ restoredCurrentEntityId = getVerifiedRestoredEntityId(entityId, restoredEntityValues);
126617
+ }
126300
126618
  }
126301
126619
  });
126302
126620
  refresh();
126303
- saveCratePreservingView();
126621
+ saveCratePreservingView(
126622
+ rejectsCurrentCreatedEntity ? "./" : restoredCurrentEntityId
126623
+ );
126304
126624
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalCrateApproved) == null ? void 0 : _a3.call(approvalContext, {
126305
126625
  decision: "reject",
126306
126626
  value: restoredValues
126307
126627
  });
126628
+ if (rejectsCurrentCreatedEntity) {
126629
+ onLoadEntity({ id: "./" });
126630
+ } else if (currentEntityId) {
126631
+ navigateToRestoredEntity(currentEntityId, restoredCurrentEntityId);
126632
+ }
126308
126633
  } catch (error2) {
126309
126634
  console.error(error2);
126310
126635
  onError();
@@ -130811,9 +131136,9 @@ class ProfileManager {
130811
131136
  var _a2;
130812
131137
  if (!((_a2 = this.profile) == null ? void 0 : _a2.layouts) || !this.profile.layouts.length) return null;
130813
131138
  let layouts = this.profile.layouts;
130814
- const entityTypes = this.normaliseEntityTypes(entity);
131139
+ const entityTypes2 = this.normaliseEntityTypes(entity);
130815
131140
  let layout = layouts.filter((layout2) => {
130816
- return intersection(layout2.appliesTo, entityTypes).length;
131141
+ return intersection(layout2.appliesTo, entityTypes2).length;
130817
131142
  });
130818
131143
  if (!layout.length) return null;
130819
131144
  let firstMatchingLayout = layout[0];
@@ -133989,6 +134314,19 @@ const en = {
133989
134314
  external_lookup_timeout_error: "External Lookup Timeout",
133990
134315
  ror_lookup_timeout_error: "ROR Lookup Timeout",
133991
134316
  associate_existing_entity: "Associate an entity already defined in this crate",
134317
+ associate_global_entity: "Global entities",
134318
+ global_entity_already_exists_title: "Entity already exists in this crate",
134319
+ global_entity_reused_notice: "“{{name}}” already exists in this crate with the same values. The existing entity was reused and linked to this field. No duplicate was added.",
134320
+ global_entity_reused_ok: "OK",
134321
+ global_entity_conflict_title: "This entity may already be in the crate",
134322
+ global_entity_conflict_description: "An entity with the same type and name, or the same values, already exists. Choose which values to keep.",
134323
+ global_entity_conflict_preserve_links: "The existing crate ID, links, and fields absent from the global version will be preserved.",
134324
+ global_entity_conflict_cancel: "Cancel",
134325
+ global_entity_conflict_property: "Field",
134326
+ global_entity_conflict_crate_values: "In this crate",
134327
+ global_entity_conflict_global_values: "Global version",
134328
+ global_entity_conflict_keep_crate: "Keep crate values",
134329
+ global_entity_conflict_use_global: "Use global values",
133992
134330
  associate_entity_from_template: "Associate an entity from saved templates",
133993
134331
  associate_organization_from_ror: "Associate an Organization defined in the Research Organization Registry",
133994
134332
  associate_user_created_entity: "Associate a user created entity",
@@ -134328,6 +134666,19 @@ const hu = {
134328
134666
  external_lookup_timeout_error: "Külső lekérdezési időtúllépés",
134329
134667
  ror_lookup_timeout_error: "ROR lekérdezési időtúllépés",
134330
134668
  associate_existing_entity: "Kapcsolj egy már ebben a csomagban definiált entitást",
134669
+ associate_global_entity: "Globális entitások",
134670
+ global_entity_already_exists_title: "Az entitás már szerepel a csomagban",
134671
+ global_entity_reused_notice: "„{{name}}” már szerepel ebben a csomagban azonos értékekkel. A meglévő entitást használtuk fel és kapcsoltuk ehhez a mezőhöz. Nem adtunk hozzá másolatot.",
134672
+ global_entity_reused_ok: "Rendben",
134673
+ global_entity_conflict_title: "Ez az entitás már szerepelhet a csomagban",
134674
+ global_entity_conflict_description: "Már létezik azonos típusú és nevű, vagy azonos értékekkel rendelkező entitás. Válaszd ki, melyik értékeket tartod meg.",
134675
+ global_entity_conflict_preserve_links: "A meglévő csomagbeli azonosító, kapcsolatok és a globális változatból hiányzó mezők megmaradnak.",
134676
+ global_entity_conflict_cancel: "Mégse",
134677
+ global_entity_conflict_property: "Mező",
134678
+ global_entity_conflict_crate_values: "Ebben a csomagban",
134679
+ global_entity_conflict_global_values: "Globális változat",
134680
+ global_entity_conflict_keep_crate: "Csomagbeli értékek megtartása",
134681
+ global_entity_conflict_use_global: "Globális értékek használata",
134331
134682
  associate_entity_from_template: "Kapcsolj egy mentett sablonból származó entitást",
134332
134683
  associate_organization_from_ror: "Kapcsolj egy a Research Organization Registryben definiált szervezetet",
134333
134684
  associate_user_created_entity: "Kapcsolj egy felhasználó által létrehozott entitást",
@@ -135327,7 +135678,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
135327
135678
  }) : null
135328
135679
  );
135329
135680
  var CacheProvider = EmotionCacheContext.Provider;
135330
- const version = "0.1.51";
135681
+ const version = "0.1.53";
135331
135682
  const pkg = {
135332
135683
  version
135333
135684
  };
@@ -135806,7 +136157,7 @@ function RecrateCrateBuilderInner(props) {
135806
136157
  let nextEntity = null;
135807
136158
  for (const candidateId of candidateIds) {
135808
136159
  if (!candidateId) continue;
135809
- const maybeEntity = newCm.getEntity({ id: candidateId, link: false, materialise: false });
136160
+ const maybeEntity = resolveEntityByIdAliases(candidateId, (resolvedId) => newCm.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(newCm.entityIdIndex));
135810
136161
  if (!isEmpty(maybeEntity)) {
135811
136162
  nextEntity = maybeEntity;
135812
136163
  break;
@@ -135831,7 +136182,7 @@ function RecrateCrateBuilderInner(props) {
135831
136182
  const { id: id2, updateState = true } = params;
135832
136183
  if (!id2 || !cm) return;
135833
136184
  try {
135834
- const entity = cm.getEntity({ id: id2, link: false, materialise: false });
136185
+ const entity = resolveEntityByIdAliases(id2, (resolvedId) => cm.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(cm.entityIdIndex));
135835
136186
  if (!isEmpty(entity)) {
135836
136187
  setContextEntity(entity);
135837
136188
  onNavigation == null ? void 0 : onNavigation({
@@ -135888,7 +136239,7 @@ function RecrateCrateBuilderInner(props) {
135888
136239
  if (!cm) {
135889
136240
  return;
135890
136241
  }
135891
- if (lastHandledEntityIdRef.current === entityId && entityId === (contextEntity == null ? void 0 : contextEntity["@id"])) {
136242
+ if (lastHandledEntityIdRef.current === entityId) {
135892
136243
  return;
135893
136244
  }
135894
136245
  lastHandledEntityIdRef.current = entityId;
@@ -135936,13 +136287,23 @@ function RecrateCrateBuilderInner(props) {
135936
136287
  scrollToFieldRequest == null ? void 0 : scrollToFieldRequest.fieldName,
135937
136288
  scrollToFieldRequest == null ? void 0 : scrollToFieldRequest.nonce
135938
136289
  ]);
135939
- const saveCrate = () => {
136290
+ const saveCrate = (requestedEntityId) => {
136291
+ var _a2;
135940
136292
  if (!cm) return;
135941
136293
  if (purgeUnlinkedEntities) {
135942
136294
  cm.purgeUnlinkedEntities();
135943
136295
  }
135944
136296
  const exported = cm.exportCrate();
135945
- const currentEntityId = typeof (contextEntity == null ? void 0 : contextEntity["@id"]) === "string" ? contextEntity["@id"] : void 0;
136297
+ const graph = Array.isArray(exported == null ? void 0 : exported["@graph"]) ? exported["@graph"] : [];
136298
+ const availableEntityIds = new Set(
136299
+ graph.map((item) => typeof (item == null ? void 0 : item["@id"]) === "string" ? item["@id"] : void 0).filter(Boolean)
136300
+ );
136301
+ const currentEntityId = [
136302
+ requestedEntityId,
136303
+ contextEntity == null ? void 0 : contextEntity["@id"],
136304
+ (_a2 = state.editorState.latest()) == null ? void 0 : _a2.id,
136305
+ "./"
136306
+ ].find((candidate) => typeof candidate === "string" && availableEntityIds.has(candidate));
135946
136307
  onSaveCrate == null ? void 0 : onSaveCrate({ crate: exported, entityId: currentEntityId });
135947
136308
  };
135948
136309
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate", children: [