@arpproject/recrate 0.1.51 → 0.1.52

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.
@@ -11,6 +11,13 @@ interface EntityIdProps {
11
11
  }) => void;
12
12
  aiEdited?: boolean;
13
13
  aiEditedVariant?: AiEditedFieldBadgeVariant;
14
+ aiReview?: {
15
+ operation?: string;
16
+ previousValue?: any;
17
+ previousValueDiffers?: boolean;
18
+ onApprove: () => void;
19
+ onReject: () => void;
20
+ };
14
21
  }
15
22
  export declare const EntityId: React.FC<EntityIdProps>;
16
23
  export default EntityId;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,7 +5,7 @@ interface RenderEntityProps {
5
5
  id: string;
6
6
  updateState?: boolean;
7
7
  }) => void;
8
- onSaveCrate: () => void;
8
+ onSaveCrate: (activeEntityId?: string) => void;
9
9
  onSaveEntityTemplate: () => void;
10
10
  onWarning: () => void;
11
11
  onError: () => void;
@@ -3,7 +3,9 @@ export declare const CONTEXT_APPROVAL_PROPERTY_NAME = "@context";
3
3
  export declare const getApprovalEntities: (approvalData: any) => any[];
4
4
  export declare const getEntityIdAliases: (id: string | undefined) => string[];
5
5
  export declare const entityIdsMatch: (left: string | undefined, right: string | undefined) => boolean;
6
+ export declare const resolveEntityByIdAliases: <T>(id: string | undefined, getEntity: (candidateId: string) => T | undefined, indexedEntityIds?: Iterable<string>) => T | undefined;
6
7
  export declare const isPendingEntityDeleteApproval: (entityApproval: any) => boolean;
8
+ export declare const isPendingEntityCreateApproval: (entityApproval: any) => boolean;
7
9
  export declare const getDeletedEntityFromApproval: (entityApproval: any) => any | undefined;
8
10
  export declare const getPendingDeletedEntityFromApproval: (approvalData: any, entityId: string | undefined) => any | undefined;
9
11
  export declare const getPendingDeletedEntitiesForReverseProperty: (approvalData: any, sourceEntityId: string | undefined, property: string) => any[];
@@ -9,7 +9,7 @@ interface UseEntityMutationHandlersOptions {
9
9
  updateState?: boolean;
10
10
  }) => void;
11
11
  refresh: () => void;
12
- saveCratePreservingView: () => void;
12
+ saveCratePreservingView: (activeEntityId?: string) => void;
13
13
  notifySave: (property: string) => void;
14
14
  onWarning: () => void;
15
15
  onError: () => void;
@@ -10,7 +10,7 @@ interface UseEntityNavigationStateOptions {
10
10
  highlightRequiredProperties: boolean;
11
11
  iconView: boolean;
12
12
  tabPaneWidth: number;
13
- onSaveCrate: () => void;
13
+ onSaveCrate: (activeEntityId?: string) => void;
14
14
  debugScroll?: (...args: any[]) => void;
15
15
  }
16
16
  interface CaptureViewContextOptions {
@@ -19,7 +19,7 @@ interface CaptureViewContextOptions {
19
19
  declare const useEntityNavigationState: ({ activeTab, activeContentRef, contextEntity, state, restoreInProgressRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, onSaveCrate, debugScroll, }: UseEntityNavigationStateOptions) => {
20
20
  captureCurrentViewContext: (tabName?: string) => void;
21
21
  captureViewContext: (tabName?: string, explicitScrollTop?: number, options?: CaptureViewContextOptions) => void;
22
- saveCratePreservingView: () => void;
22
+ saveCratePreservingView: (activeEntityId?: string) => void;
23
23
  saveTabToState: (tabName: string) => void;
24
24
  };
25
25
  export default useEntityNavigationState;
@@ -0,0 +1 @@
1
+ export {};
@@ -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"]) {
@@ -94545,6 +94620,24 @@ const EntityProperty = ({
94545
94620
  const linkedReviewInstances = linkInstances.map((instance2) => {
94546
94621
  var _a3;
94547
94622
  const targetEntityId = (_a3 = instance2.value) == null ? void 0 : _a3["@id"];
94623
+ const resolvedTargetEntity = resolveEntityByIdAliases(targetEntityId, (resolvedId) => {
94624
+ var _a4;
94625
+ return (_a4 = crateManager == null ? void 0 : crateManager.getEntity) == null ? void 0 : _a4.call(crateManager, { id: resolvedId, link: false, materialise: false });
94626
+ }, Object.keys((crateManager == null ? void 0 : crateManager.entityIdIndex) ?? {}));
94627
+ const deletedEntity = resolvedTargetEntity ? void 0 : getPendingDeletedEntityFromApproval(
94628
+ approvalContext == null ? void 0 : approvalContext.roCrateApproval,
94629
+ targetEntityId
94630
+ );
94631
+ if (deletedEntity) {
94632
+ return {
94633
+ ...instance2,
94634
+ value: {
94635
+ ...deletedEntity,
94636
+ __aiDeleteSourceEntityId: entity == null ? void 0 : entity["@id"],
94637
+ __aiDeleteSourceProperty: property
94638
+ }
94639
+ };
94640
+ }
94548
94641
  if (!targetEntityId || !Array.from(addedReferenceIds).some((id2) => entityIdsMatch(id2, targetEntityId))) {
94549
94642
  return instance2;
94550
94643
  }
@@ -123796,12 +123889,14 @@ const useScrollViewportHeight = ({
123796
123889
  characterData: true
123797
123890
  });
123798
123891
  }
123799
- requestAnimationFrame(() => computeScrollViewportHeight());
123892
+ const animationFrame = requestAnimationFrame(() => computeScrollViewportHeight());
123800
123893
  const delayedMeasure = window.setTimeout(() => computeScrollViewportHeight(), 120);
123801
123894
  return () => {
123802
123895
  resizeObserver2.disconnect();
123803
123896
  mutationObserver.disconnect();
123897
+ cancelAnimationFrame(animationFrame);
123804
123898
  window.clearTimeout(delayedMeasure);
123899
+ computeScrollViewportHeight.cancel();
123805
123900
  };
123806
123901
  }, [computeScrollViewportHeight, activeTab, renderTabs, tabsLength, entityId, reverseSidebarVisible]);
123807
123902
  return {
@@ -124171,10 +124266,10 @@ const useEntityNavigationState = ({
124171
124266
  state.editorState.update({ id: activeEntityId, tab: tabName });
124172
124267
  state.editorState.updateNavigationState({ activeTab: tabName });
124173
124268
  }, [contextEntity, state]);
124174
- const saveCratePreservingView = useCallback(() => {
124269
+ const saveCratePreservingView = useCallback((activeEntityId) => {
124175
124270
  saveTabToState(activeTab);
124176
124271
  captureCurrentViewContext(activeTab);
124177
- onSaveCrate();
124272
+ onSaveCrate(activeEntityId);
124178
124273
  }, [activeTab, captureCurrentViewContext, onSaveCrate, saveTabToState]);
124179
124274
  return {
124180
124275
  captureCurrentViewContext,
@@ -125284,17 +125379,9 @@ const RenderEntity = forwardRef((props, ref) => {
125284
125379
  if (isPendingEntityDeleteApproval(entityApproval)) {
125285
125380
  const reviewTarget = getDeletedEntityReviewTarget(entityApproval);
125286
125381
  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
- }));
125382
+ 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
125383
  }
125293
- return Boolean(crateManager == null ? void 0 : crateManager.getEntity({
125294
- id: entityId,
125295
- link: false,
125296
- materialise: false
125297
- }));
125384
+ 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
125385
  }, [approvalContext == null ? void 0 : approvalContext.roCrateApproval, crateManager]);
125299
125386
  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
125387
  const pendingOtherAiApprovalFieldCount = useMemo$1(() => pendingOtherAiApprovalEntities.reduce((count, entityApproval) => {
@@ -125320,21 +125407,19 @@ const RenderEntity = forwardRef((props, ref) => {
125320
125407
  if (isPendingEntityDeleteApproval(entityApproval)) {
125321
125408
  const reviewTarget = getDeletedEntityReviewTarget(entityApproval);
125322
125409
  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;
125410
+ 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) ?? {}));
125411
+ if (!targetEntity2) continue;
125329
125412
  setFieldTitleFilter("");
125330
125413
  if (hideEmptyFields) {
125331
125414
  setHideEmptyFields(false);
125332
125415
  }
125333
125416
  pendingAiScrollPropertyRef.current = reviewTarget.property;
125334
- onLoadEntity({ id: reviewTarget.entityId });
125417
+ onLoadEntity({ id: targetEntity2["@id"] });
125335
125418
  return;
125336
125419
  }
125337
- onLoadEntity({ id: nextEntityId });
125420
+ 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) ?? {}));
125421
+ if (!targetEntity) continue;
125422
+ onLoadEntity({ id: targetEntity["@id"] });
125338
125423
  return;
125339
125424
  }
125340
125425
  }, [approvalContext == null ? void 0 : approvalContext.roCrateApproval, crateManager, hideEmptyFields, onLoadEntity, pendingOtherAiApprovalEntities]);
@@ -125938,43 +126023,6 @@ const RenderEntity = forwardRef((props, ref) => {
125938
126023
  scrollToAiApprovalProperty
125939
126024
  ]);
125940
126025
  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
126026
  const restoreEntityApprovalValue = (targetEntity, approvalRecord) => {
125979
126027
  const property = approvalRecord == null ? void 0 : approvalRecord.propertyName;
125980
126028
  const entityId = targetEntity == null ? void 0 : targetEntity["@id"];
@@ -126020,22 +126068,41 @@ const RenderEntity = forwardRef((props, ref) => {
126020
126068
  });
126021
126069
  };
126022
126070
  const handleRejectAiProperty = (approvalRecord) => {
126023
- var _a3;
126071
+ var _a3, _b2;
126024
126072
  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, {
126073
+ if (!(approvalRecord == null ? void 0 : approvalRecord.propertyName)) return;
126074
+ if (approvalRecord.propertyName === "@id" && approvalRecord.operation === "create") {
126075
+ crateManager.deleteEntity({ id: entity["@id"] });
126076
+ saveCratePreservingView("./");
126077
+ (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126078
+ entityId: entity["@id"],
126079
+ decision: "reject",
126080
+ value: { "@id": void 0 }
126081
+ });
126082
+ onLoadEntity({ id: "./" });
126083
+ return;
126084
+ }
126085
+ if (!propertyValueHasContent(approvalRecord.previousValue)) return;
126086
+ (_b2 = approvalContext == null ? void 0 : approvalContext.markApprovalPropertyApproved) == null ? void 0 : _b2.call(approvalContext, {
126027
126087
  entityId: entity["@id"],
126028
126088
  propertyName: approvalRecord.propertyName,
126029
126089
  decision: "reject",
126030
126090
  value: approvalRecord.previousValue
126031
126091
  });
126032
- crateManager.updateProperty({
126092
+ const previousEntityId = entity["@id"];
126093
+ const updatedEntity = crateManager.updateProperty({
126033
126094
  id: entity["@id"],
126034
126095
  property: approvalRecord.propertyName,
126035
126096
  value: approvalRecord.previousValue
126036
126097
  });
126037
- refresh();
126038
- saveCratePreservingView();
126098
+ const restoredEntityId = approvalRecord.propertyName === "@id" ? updatedEntity == null ? void 0 : updatedEntity["@id"] : void 0;
126099
+ if (restoredEntityId && restoredEntityId !== previousEntityId) {
126100
+ saveCratePreservingView(restoredEntityId);
126101
+ navigateToRestoredEntity(previousEntityId, restoredEntityId);
126102
+ } else {
126103
+ refresh();
126104
+ saveCratePreservingView();
126105
+ }
126039
126106
  notifySave(approvalRecord.propertyName);
126040
126107
  } catch (error2) {
126041
126108
  console.error(error2);
@@ -126081,11 +126148,14 @@ const RenderEntity = forwardRef((props, ref) => {
126081
126148
  });
126082
126149
  };
126083
126150
  const restoreEditedEntityApprovalValues = (entityId) => {
126084
- const targetEntity = crateManager.getEntity({
126085
- id: entityId,
126086
- link: false,
126087
- materialise: false
126088
- });
126151
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126152
+ const targetEntity = resolveEntityByIdAliases(entityId, (resolvedId) => crateManager.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(crateManager.entityIdIndex ?? {}));
126153
+ if (isPendingEntityCreateApproval(entityApproval)) {
126154
+ if (targetEntity) {
126155
+ crateManager.deleteEntity({ id: targetEntity["@id"] });
126156
+ }
126157
+ return { "@id": void 0 };
126158
+ }
126089
126159
  if (!targetEntity) return void 0;
126090
126160
  const approvalRecords = getPendingEntityApprovalRecords(
126091
126161
  approvalContext == null ? void 0 : approvalContext.roCrateApproval,
@@ -126101,22 +126171,53 @@ const RenderEntity = forwardRef((props, ref) => {
126101
126171
  approvalRecords.filter((approvalRecord) => (approvalRecord == null ? void 0 : approvalRecord.propertyName) === "@id").forEach((approvalRecord) => restoreEntityApprovalValue(targetEntity, approvalRecord));
126102
126172
  return restoredValues;
126103
126173
  };
126174
+ const getVerifiedRestoredEntityId = (entityId, restoredValues) => {
126175
+ const requestedId = typeof (restoredValues == null ? void 0 : restoredValues["@id"]) === "string" ? restoredValues["@id"].trim() : "";
126176
+ if (!requestedId || requestedId === entityId) return void 0;
126177
+ const restoredEntity = crateManager.getEntity({
126178
+ id: requestedId,
126179
+ link: false,
126180
+ materialise: false
126181
+ });
126182
+ return restoredEntity == null ? void 0 : restoredEntity["@id"];
126183
+ };
126184
+ const navigateToRestoredEntity = (previousEntityId, restoredEntityId) => {
126185
+ if (!restoredEntityId || restoredEntityId === previousEntityId) return;
126186
+ handleLoadEntityWithContext({ id: restoredEntityId });
126187
+ state.editorState.replaceId({ id: previousEntityId, newId: restoredEntityId });
126188
+ };
126104
126189
  const handleRejectAiEntityEdit = (editedEntity) => {
126105
126190
  var _a3;
126106
126191
  try {
126107
126192
  const entityId = editedEntity == null ? void 0 : editedEntity["@id"];
126108
126193
  if (!entityId) return;
126194
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126195
+ const rejectingCreatedEntity = isPendingEntityCreateApproval(entityApproval);
126109
126196
  const restoredValues = restoreEditedEntityApprovalValues(entityId);
126110
126197
  if (!restoredValues) return;
126111
- if (entityIdsMatch(entityId, entity == null ? void 0 : entity["@id"])) {
126198
+ const restoredEntityId = rejectingCreatedEntity ? void 0 : getVerifiedRestoredEntityId(entityId, restoredValues);
126199
+ const editsCurrentEntity = entityIdsMatch(entityId, entity == null ? void 0 : entity["@id"]);
126200
+ const rejectsCurrentCreatedEntity = rejectingCreatedEntity && editsCurrentEntity;
126201
+ if (editsCurrentEntity && !rejectingCreatedEntity) {
126112
126202
  refresh();
126113
126203
  }
126114
- saveCratePreservingView();
126204
+ let nextActiveEntityId;
126205
+ if (rejectsCurrentCreatedEntity) {
126206
+ nextActiveEntityId = "./";
126207
+ } else if (editsCurrentEntity) {
126208
+ nextActiveEntityId = restoredEntityId;
126209
+ }
126210
+ saveCratePreservingView(nextActiveEntityId);
126115
126211
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126116
126212
  entityId,
126117
126213
  decision: "reject",
126118
126214
  value: restoredValues
126119
126215
  });
126216
+ if (rejectsCurrentCreatedEntity) {
126217
+ onLoadEntity({ id: "./" });
126218
+ } else if (editsCurrentEntity) {
126219
+ navigateToRestoredEntity(entityId, restoredEntityId);
126220
+ }
126120
126221
  } catch (error2) {
126121
126222
  console.error(error2);
126122
126223
  onError();
@@ -126125,20 +126226,27 @@ const RenderEntity = forwardRef((props, ref) => {
126125
126226
  const handleRejectCurrentEntityAiApprovals = () => {
126126
126227
  var _a3;
126127
126228
  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();
126229
+ const entityId = entity == null ? void 0 : entity["@id"];
126230
+ if (!entityId) return;
126231
+ const entityApproval = getEntityApproval(approvalContext == null ? void 0 : approvalContext.roCrateApproval, entityId);
126232
+ const rejectingCreatedEntity = isPendingEntityCreateApproval(entityApproval);
126233
+ const restoredValues = restoreEditedEntityApprovalValues(entityId);
126234
+ if (!restoredValues) return;
126235
+ const restoredEntityId = rejectingCreatedEntity ? void 0 : getVerifiedRestoredEntityId(entityId, restoredValues);
126236
+ if (!rejectingCreatedEntity) {
126237
+ refresh();
126238
+ }
126239
+ saveCratePreservingView(rejectingCreatedEntity ? "./" : restoredEntityId);
126137
126240
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalEntityApproved) == null ? void 0 : _a3.call(approvalContext, {
126138
- entityId: entity["@id"],
126241
+ entityId,
126139
126242
  decision: "reject",
126140
126243
  value: restoredValues
126141
126244
  });
126245
+ if (rejectingCreatedEntity) {
126246
+ onLoadEntity({ id: "./" });
126247
+ } else {
126248
+ navigateToRestoredEntity(entityId, restoredEntityId);
126249
+ }
126142
126250
  } catch (error2) {
126143
126251
  console.error(error2);
126144
126252
  onError();
@@ -126276,6 +126384,9 @@ const RenderEntity = forwardRef((props, ref) => {
126276
126384
  var _a3;
126277
126385
  try {
126278
126386
  const restoredValues = {};
126387
+ const currentEntityId = entity == null ? void 0 : entity["@id"];
126388
+ let restoredCurrentEntityId;
126389
+ let rejectsCurrentCreatedEntity = false;
126279
126390
  const pendingEntities = getPendingApprovalEntities(approvalContext == null ? void 0 : approvalContext.roCrateApproval);
126280
126391
  pendingContextApprovalItems.forEach((approvalItem) => {
126281
126392
  var _a4;
@@ -126287,6 +126398,9 @@ const RenderEntity = forwardRef((props, ref) => {
126287
126398
  pendingEntities.forEach((entityApproval) => {
126288
126399
  const entityId = entityApproval == null ? void 0 : entityApproval["@id"];
126289
126400
  if (!entityId) return;
126401
+ if (isPendingEntityCreateApproval(entityApproval) && entityIdsMatch(entityId, currentEntityId)) {
126402
+ rejectsCurrentCreatedEntity = true;
126403
+ }
126290
126404
  if (isPendingEntityDeleteApproval(entityApproval)) {
126291
126405
  const deletedEntity = getDeletedEntityFromApproval(entityApproval);
126292
126406
  if (deletedEntity) {
@@ -126297,14 +126411,24 @@ const RenderEntity = forwardRef((props, ref) => {
126297
126411
  const restoredEntityValues = restoreEditedEntityApprovalValues(entityId);
126298
126412
  if (restoredEntityValues) {
126299
126413
  restoredValues[entityId] = restoredEntityValues;
126414
+ if (entityIdsMatch(entityId, currentEntityId)) {
126415
+ restoredCurrentEntityId = getVerifiedRestoredEntityId(entityId, restoredEntityValues);
126416
+ }
126300
126417
  }
126301
126418
  });
126302
126419
  refresh();
126303
- saveCratePreservingView();
126420
+ saveCratePreservingView(
126421
+ rejectsCurrentCreatedEntity ? "./" : restoredCurrentEntityId
126422
+ );
126304
126423
  (_a3 = approvalContext == null ? void 0 : approvalContext.markApprovalCrateApproved) == null ? void 0 : _a3.call(approvalContext, {
126305
126424
  decision: "reject",
126306
126425
  value: restoredValues
126307
126426
  });
126427
+ if (rejectsCurrentCreatedEntity) {
126428
+ onLoadEntity({ id: "./" });
126429
+ } else if (currentEntityId) {
126430
+ navigateToRestoredEntity(currentEntityId, restoredCurrentEntityId);
126431
+ }
126308
126432
  } catch (error2) {
126309
126433
  console.error(error2);
126310
126434
  onError();
@@ -135327,7 +135451,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
135327
135451
  }) : null
135328
135452
  );
135329
135453
  var CacheProvider = EmotionCacheContext.Provider;
135330
- const version = "0.1.51";
135454
+ const version = "0.1.52";
135331
135455
  const pkg = {
135332
135456
  version
135333
135457
  };
@@ -135806,7 +135930,7 @@ function RecrateCrateBuilderInner(props) {
135806
135930
  let nextEntity = null;
135807
135931
  for (const candidateId of candidateIds) {
135808
135932
  if (!candidateId) continue;
135809
- const maybeEntity = newCm.getEntity({ id: candidateId, link: false, materialise: false });
135933
+ const maybeEntity = resolveEntityByIdAliases(candidateId, (resolvedId) => newCm.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(newCm.entityIdIndex));
135810
135934
  if (!isEmpty(maybeEntity)) {
135811
135935
  nextEntity = maybeEntity;
135812
135936
  break;
@@ -135831,7 +135955,7 @@ function RecrateCrateBuilderInner(props) {
135831
135955
  const { id: id2, updateState = true } = params;
135832
135956
  if (!id2 || !cm) return;
135833
135957
  try {
135834
- const entity = cm.getEntity({ id: id2, link: false, materialise: false });
135958
+ const entity = resolveEntityByIdAliases(id2, (resolvedId) => cm.getEntity({ id: resolvedId, link: false, materialise: false }), Object.keys(cm.entityIdIndex));
135835
135959
  if (!isEmpty(entity)) {
135836
135960
  setContextEntity(entity);
135837
135961
  onNavigation == null ? void 0 : onNavigation({
@@ -135888,7 +136012,7 @@ function RecrateCrateBuilderInner(props) {
135888
136012
  if (!cm) {
135889
136013
  return;
135890
136014
  }
135891
- if (lastHandledEntityIdRef.current === entityId && entityId === (contextEntity == null ? void 0 : contextEntity["@id"])) {
136015
+ if (lastHandledEntityIdRef.current === entityId) {
135892
136016
  return;
135893
136017
  }
135894
136018
  lastHandledEntityIdRef.current = entityId;
@@ -135936,13 +136060,23 @@ function RecrateCrateBuilderInner(props) {
135936
136060
  scrollToFieldRequest == null ? void 0 : scrollToFieldRequest.fieldName,
135937
136061
  scrollToFieldRequest == null ? void 0 : scrollToFieldRequest.nonce
135938
136062
  ]);
135939
- const saveCrate = () => {
136063
+ const saveCrate = (requestedEntityId) => {
136064
+ var _a2;
135940
136065
  if (!cm) return;
135941
136066
  if (purgeUnlinkedEntities) {
135942
136067
  cm.purgeUnlinkedEntities();
135943
136068
  }
135944
136069
  const exported = cm.exportCrate();
135945
- const currentEntityId = typeof (contextEntity == null ? void 0 : contextEntity["@id"]) === "string" ? contextEntity["@id"] : void 0;
136070
+ const graph = Array.isArray(exported == null ? void 0 : exported["@graph"]) ? exported["@graph"] : [];
136071
+ const availableEntityIds = new Set(
136072
+ graph.map((item) => typeof (item == null ? void 0 : item["@id"]) === "string" ? item["@id"] : void 0).filter(Boolean)
136073
+ );
136074
+ const currentEntityId = [
136075
+ requestedEntityId,
136076
+ contextEntity == null ? void 0 : contextEntity["@id"],
136077
+ (_a2 = state.editorState.latest()) == null ? void 0 : _a2.id,
136078
+ "./"
136079
+ ].find((candidate) => typeof candidate === "string" && availableEntityIds.has(candidate));
135946
136080
  onSaveCrate == null ? void 0 : onSaveCrate({ crate: exported, entityId: currentEntityId });
135947
136081
  };
135948
136082
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "recrate", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arpproject/recrate",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "type": "module",
5
5
  "main": "./dist/recrate.es.js",
6
6
  "module": "./dist/recrate.es.js",