@arpproject/recrate 0.1.45 → 0.1.46

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.
@@ -6,6 +6,7 @@ export declare const getProfileTabKey: (tab: any) => string;
6
6
  export declare const isProfileTab: (tab: any) => boolean;
7
7
  export declare const findAddedProfileTab: (tabs: any[], previousTabKeys: Set<string>) => any;
8
8
  export declare const isAboutTab: (tab: any) => boolean;
9
+ export declare const tabHasRenderableContent: (tab: any) => boolean;
9
10
  export declare const tabContainsProperty: (tab: any, property: string) => boolean;
10
11
  export declare const findTabForProperty: (tabs: any[], property: string) => any;
11
12
  export declare const addMissingReviewPropertiesToTabs: (tabs: any[], properties: string[]) => any[];
@@ -27,7 +27,8 @@ interface UseEntityScrollRestorationOptions {
27
27
  captureViewContext: (tabName?: string, explicitScrollTop?: number, options?: {
28
28
  updateActiveTab?: boolean;
29
29
  }) => void;
30
+ disabled?: boolean;
30
31
  debugScroll?: (...args: any[]) => void;
31
32
  }
32
- declare const useEntityScrollRestoration: ({ activeTab, activeContentRef, contextEntity, renderTabs, tabsLength, extraPropertiesLength, scrollRestoreNonce, setScrollRestoreNonce, navigationRestoreReadyRef, pendingRestoredTabRef, restoreInProgressRef, pendingAddedPropertyRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, state, isAiScrollRestoreSuppressed, captureViewContext, debugScroll, }: UseEntityScrollRestorationOptions) => void;
33
+ declare const useEntityScrollRestoration: ({ activeTab, activeContentRef, contextEntity, renderTabs, tabsLength, extraPropertiesLength, scrollRestoreNonce, setScrollRestoreNonce, navigationRestoreReadyRef, pendingRestoredTabRef, restoreInProgressRef, pendingAddedPropertyRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, state, isAiScrollRestoreSuppressed, captureViewContext, disabled, debugScroll, }: UseEntityScrollRestorationOptions) => void;
33
34
  export default useEntityScrollRestoration;
@@ -4809,7 +4809,7 @@ const seedToken = Object.assign(Object.assign({}, defaultPresetColors), {
4809
4809
  // Motion
4810
4810
  motion: true
4811
4811
  });
4812
- const round$1 = Math.round;
4812
+ const round = Math.round;
4813
4813
  function splitColorStr(str, parseNum) {
4814
4814
  const match2 = str.replace(/^[^(]*\((.*)/, "$1").replace(/\).*/, "").match(/\d*\.?\d+%?/g) || [];
4815
4815
  const numList = match2.map((item) => parseFloat(item));
@@ -4927,7 +4927,7 @@ class FastColor {
4927
4927
  if (delta === 0) {
4928
4928
  this._h = 0;
4929
4929
  } else {
4930
- this._h = round$1(60 * (this.r === this.getMax() ? (this.g - this.b) / delta + (this.g < this.b ? 6 : 0) : this.g === this.getMax() ? (this.b - this.r) / delta + 2 : (this.r - this.g) / delta + 4));
4930
+ this._h = round(60 * (this.r === this.getMax() ? (this.g - this.b) / delta + (this.g < this.b ? 6 : 0) : this.g === this.getMax() ? (this.b - this.r) / delta + 2 : (this.r - this.g) / delta + 4));
4931
4931
  }
4932
4932
  }
4933
4933
  return this._h;
@@ -5004,10 +5004,10 @@ class FastColor {
5004
5004
  const p2 = amount / 100;
5005
5005
  const calc = (key) => (color[key] - this[key]) * p2 + this[key];
5006
5006
  const rgba = {
5007
- r: round$1(calc("r")),
5008
- g: round$1(calc("g")),
5009
- b: round$1(calc("b")),
5010
- a: round$1(calc("a") * 100) / 100
5007
+ r: round(calc("r")),
5008
+ g: round(calc("g")),
5009
+ b: round(calc("b")),
5010
+ a: round(calc("a") * 100) / 100
5011
5011
  };
5012
5012
  return this._c(rgba);
5013
5013
  }
@@ -5039,7 +5039,7 @@ class FastColor {
5039
5039
  const bg = this._c(background2);
5040
5040
  const alpha2 = this.a + bg.a * (1 - this.a);
5041
5041
  const calc = (key) => {
5042
- return round$1((this[key] * this.a + bg[key] * bg.a * (1 - this.a)) / alpha2);
5042
+ return round((this[key] * this.a + bg[key] * bg.a * (1 - this.a)) / alpha2);
5043
5043
  };
5044
5044
  return this._c({
5045
5045
  r: calc("r"),
@@ -5072,7 +5072,7 @@ class FastColor {
5072
5072
  const bHex = (this.b || 0).toString(16);
5073
5073
  hex2 += bHex.length === 2 ? bHex : "0" + bHex;
5074
5074
  if (typeof this.a === "number" && this.a >= 0 && this.a < 1) {
5075
- const aHex = round$1(this.a * 255).toString(16);
5075
+ const aHex = round(this.a * 255).toString(16);
5076
5076
  hex2 += aHex.length === 2 ? aHex : "0" + aHex;
5077
5077
  }
5078
5078
  return hex2;
@@ -5089,8 +5089,8 @@ class FastColor {
5089
5089
  /** CSS support color pattern */
5090
5090
  toHslString() {
5091
5091
  const h = this.getHue();
5092
- const s2 = round$1(this.getSaturation() * 100);
5093
- const l2 = round$1(this.getLightness() * 100);
5092
+ const s2 = round(this.getSaturation() * 100);
5093
+ const l2 = round(this.getLightness() * 100);
5094
5094
  return this.a !== 1 ? `hsla(${h},${s2}%,${l2}%,${this.a})` : `hsl(${h},${s2}%,${l2}%)`;
5095
5095
  }
5096
5096
  /** Same as toHsb */
@@ -5166,7 +5166,7 @@ class FastColor {
5166
5166
  this._l = l2;
5167
5167
  this.a = typeof a === "number" ? a : 1;
5168
5168
  if (s2 <= 0) {
5169
- const rgb = round$1(l2 * 255);
5169
+ const rgb = round(l2 * 255);
5170
5170
  this.r = rgb;
5171
5171
  this.g = rgb;
5172
5172
  this.b = rgb;
@@ -5195,9 +5195,9 @@ class FastColor {
5195
5195
  b2 = secondComponent;
5196
5196
  }
5197
5197
  const lightnessModification = l2 - chroma / 2;
5198
- this.r = round$1((r2 + lightnessModification) * 255);
5199
- this.g = round$1((g2 + lightnessModification) * 255);
5200
- this.b = round$1((b2 + lightnessModification) * 255);
5198
+ this.r = round((r2 + lightnessModification) * 255);
5199
+ this.g = round((g2 + lightnessModification) * 255);
5200
+ this.b = round((b2 + lightnessModification) * 255);
5201
5201
  }
5202
5202
  fromHsv({
5203
5203
  h,
@@ -5209,7 +5209,7 @@ class FastColor {
5209
5209
  this._s = s2;
5210
5210
  this._v = v2;
5211
5211
  this.a = typeof a === "number" ? a : 1;
5212
- const vv = round$1(v2 * 255);
5212
+ const vv = round(v2 * 255);
5213
5213
  this.r = vv;
5214
5214
  this.g = vv;
5215
5215
  this.b = vv;
@@ -5219,9 +5219,9 @@ class FastColor {
5219
5219
  const hh = h / 60;
5220
5220
  const i = Math.floor(hh);
5221
5221
  const ff = hh - i;
5222
- const p2 = round$1(v2 * (1 - s2) * 255);
5223
- const q2 = round$1(v2 * (1 - s2 * ff) * 255);
5224
- const t2 = round$1(v2 * (1 - s2 * (1 - ff)) * 255);
5222
+ const p2 = round(v2 * (1 - s2) * 255);
5223
+ const q2 = round(v2 * (1 - s2 * ff) * 255);
5224
+ const t2 = round(v2 * (1 - s2 * (1 - ff)) * 255);
5225
5225
  switch (i) {
5226
5226
  case 0:
5227
5227
  this.g = t2;
@@ -5271,7 +5271,7 @@ class FastColor {
5271
5271
  fromRgbString(trimStr) {
5272
5272
  const cells = splitColorStr(trimStr, (num, txt) => (
5273
5273
  // Convert percentage to number. e.g. 50% -> 128
5274
- txt.includes("%") ? round$1(num / 100 * 255) : num
5274
+ txt.includes("%") ? round(num / 100 * 255) : num
5275
5275
  ));
5276
5276
  this.r = cells[0];
5277
5277
  this.g = cells[1];
@@ -60950,6 +60950,7 @@ const isAboutTab = (tab) => {
60950
60950
  const label = String((tab == null ? void 0 : tab.label) || (tab == null ? void 0 : tab.name) || "").toLowerCase();
60951
60951
  return name2 === "about" || label === "about";
60952
60952
  };
60953
+ const tabHasRenderableContent = (tab) => isAboutTab(tab) || Array.isArray(tab == null ? void 0 : tab.inputs) && tab.inputs.length > 0;
60953
60954
  const tabContainsProperty = (tab, property) => {
60954
60955
  var _a2;
60955
60956
  return (_a2 = tab == null ? void 0 : tab.inputs) == null ? void 0 : _a2.some((input) => (input == null ? void 0 : input.name) === property || (input == null ? void 0 : input.id) === property);
@@ -124140,10 +124141,12 @@ const useEntityScrollRestoration = ({
124140
124141
  state,
124141
124142
  isAiScrollRestoreSuppressed,
124142
124143
  captureViewContext,
124144
+ disabled: disabled2 = false,
124143
124145
  debugScroll = () => void 0
124144
124146
  }) => {
124145
124147
  useEffect(() => {
124146
124148
  var _a2, _b, _c, _d;
124149
+ if (disabled2) return;
124147
124150
  if (!navigationRestoreReadyRef.current) return;
124148
124151
  if (!(contextEntity == null ? void 0 : contextEntity["@id"])) return;
124149
124152
  if (((_a2 = pendingAddedPropertyRef.current) == null ? void 0 : _a2.entityId) === contextEntity["@id"]) return;
@@ -124228,9 +124231,10 @@ const useEntityScrollRestoration = ({
124228
124231
  window.cancelAnimationFrame(rafId);
124229
124232
  window.clearTimeout(timerId);
124230
124233
  };
124231
- }, [activeTab, contextEntity == null ? void 0 : contextEntity["@id"], renderTabs, tabsLength, scrollRestoreNonce]);
124234
+ }, [activeTab, contextEntity == null ? void 0 : contextEntity["@id"], renderTabs, tabsLength, scrollRestoreNonce, disabled2]);
124232
124235
  useEffect(() => {
124233
124236
  var _a2;
124237
+ if (disabled2) return;
124234
124238
  const pendingTab = pendingRestoredTabRef.current;
124235
124239
  if (!(contextEntity == null ? void 0 : contextEntity["@id"])) return;
124236
124240
  if (((_a2 = pendingAddedPropertyRef.current) == null ? void 0 : _a2.entityId) === contextEntity["@id"]) return;
@@ -124259,9 +124263,11 @@ const useEntityScrollRestoration = ({
124259
124263
  highlightRequiredProperties,
124260
124264
  iconView,
124261
124265
  tabPaneWidth,
124262
- contextEntity == null ? void 0 : contextEntity["@id"]
124266
+ contextEntity == null ? void 0 : contextEntity["@id"],
124267
+ disabled2
124263
124268
  ]);
124264
124269
  useEffect(() => {
124270
+ if (disabled2) return;
124265
124271
  const pendingAddedProperty = pendingAddedPropertyRef.current;
124266
124272
  if (!pendingAddedProperty || pendingAddedProperty.entityId !== (contextEntity == null ? void 0 : contextEntity["@id"])) return;
124267
124273
  if (pendingAddedProperty.tabName && pendingAddedProperty.tabName !== activeTab) return;
@@ -124331,7 +124337,7 @@ const useEntityScrollRestoration = ({
124331
124337
  window.cancelAnimationFrame(rafId);
124332
124338
  window.clearTimeout(timerId);
124333
124339
  };
124334
- }, [activeTab, contextEntity == null ? void 0 : contextEntity["@id"], tabsLength, extraPropertiesLength]);
124340
+ }, [activeTab, contextEntity == null ? void 0 : contextEntity["@id"], tabsLength, extraPropertiesLength, disabled2]);
124335
124341
  };
124336
124342
  const CORE_AI_REVIEW_PROPERTY_ORDER = ["@id", "@type", "name"];
124337
124343
  const getFieldNames = (field) => {
@@ -125001,7 +125007,7 @@ const hasFieldValue = (value) => {
125001
125007
  return true;
125002
125008
  };
125003
125009
  const RenderEntity = forwardRef((props, ref) => {
125004
- var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k;
125010
+ var _a2, _b, _c, _d, _e2, _f, _g, _h, _i, _j, _k, _l;
125005
125011
  const {
125006
125012
  entity,
125007
125013
  onLoadEntity,
@@ -125057,6 +125063,8 @@ const RenderEntity = forwardRef((props, ref) => {
125057
125063
  }, []);
125058
125064
  const [tabPaneWidth, setTabPaneWidth] = useState(initialTabPaneWidth);
125059
125065
  const labelTabPaneWidthRef = useRef(initialTabPaneWidth);
125066
+ const readonly = Boolean((_c = state.configuration) == null ? void 0 : _c.readonly);
125067
+ const previousReadonlyRef = useRef(readonly);
125060
125068
  const persistTabWidth = useMemo$1(() => debounce((w2) => {
125061
125069
  if (iconView) return;
125062
125070
  const clamped = clampLabelTabPaneWidth(w2);
@@ -125141,6 +125149,7 @@ const RenderEntity = forwardRef((props, ref) => {
125141
125149
  state,
125142
125150
  isAiScrollRestoreSuppressed,
125143
125151
  captureViewContext,
125152
+ disabled: readonly,
125144
125153
  debugScroll
125145
125154
  });
125146
125155
  const pendingAiApprovalRecords = useMemo$1(() => getPendingEntityApprovalRecords(approvalContext == null ? void 0 : approvalContext.roCrateApproval, contextEntity == null ? void 0 : contextEntity["@id"]), [approvalContext == null ? void 0 : approvalContext.roCrateApproval, contextEntity == null ? void 0 : contextEntity["@id"]]);
@@ -125321,10 +125330,11 @@ const RenderEntity = forwardRef((props, ref) => {
125321
125330
  setTabs(layout.tabs);
125322
125331
  const navState = isCurrentHistoryEntity ? latestEntry == null ? void 0 : latestEntry.navigationState : state.editorState.getNavigationState(entity2["@id"]);
125323
125332
  const tabNames = layout.tabs.map((tab) => tab.name);
125324
- const fallbackTab = tabNames.includes("about") ? "about" : tabNames[0] ?? "about";
125325
- const currentTabStillValid = layout.renderTabs && (contextEntity == null ? void 0 : contextEntity["@id"]) === entity2["@id"] && tabNames.includes(activeTab);
125333
+ const restorableTabNames = readonly ? tabNames : layout.tabs.filter(tabHasRenderableContent).map((tab) => tab.name);
125334
+ const fallbackTab = restorableTabNames.includes("about") ? "about" : restorableTabNames[0] ?? tabNames[0] ?? "about";
125335
+ const currentTabStillValid = layout.renderTabs && (contextEntity == null ? void 0 : contextEntity["@id"]) === entity2["@id"] && restorableTabNames.includes(activeTab);
125326
125336
  const savedActiveTab = (navState == null ? void 0 : navState.activeTab) ?? (isCurrentHistoryEntity ? latestEntry == null ? void 0 : latestEntry.tab : void 0);
125327
- const savedTabStillValid = layout.renderTabs && typeof savedActiveTab === "string" && tabNames.includes(savedActiveTab);
125337
+ const savedTabStillValid = layout.renderTabs && typeof savedActiveTab === "string" && restorableTabNames.includes(savedActiveTab);
125328
125338
  const restoredTab = savedTabStillValid ? savedActiveTab : currentTabStillValid ? activeTab : fallbackTab;
125329
125339
  const pendingAddedProfileSelection = pendingAddedProfileSelectionRef.current;
125330
125340
  const pendingAddedProfileTabKeys = Array.isArray((_a3 = navState == null ? void 0 : navState.uiState) == null ? void 0 : _a3.pendingAddedProfileTabKeys) ? navState.uiState.pendingAddedProfileTabKeys : readPendingAddedProfileTabKeys(entity2["@id"]);
@@ -125379,6 +125389,7 @@ const RenderEntity = forwardRef((props, ref) => {
125379
125389
  isCurrentHistoryEntity,
125380
125390
  renderTabs: layout.renderTabs,
125381
125391
  tabNames,
125392
+ restorableTabNames,
125382
125393
  savedActiveTab,
125383
125394
  savedTabStillValid,
125384
125395
  currentTabStillValid,
@@ -125423,6 +125434,13 @@ const RenderEntity = forwardRef((props, ref) => {
125423
125434
  if (!entityObj) return;
125424
125435
  init2({ entity: entityObj });
125425
125436
  };
125437
+ useEffect(() => {
125438
+ const wasReadonly = previousReadonlyRef.current;
125439
+ previousReadonlyRef.current = readonly;
125440
+ if (wasReadonly && !readonly && (entity == null ? void 0 : entity["@id"])) {
125441
+ refresh();
125442
+ }
125443
+ }, [readonly, entity == null ? void 0 : entity["@id"]]);
125426
125444
  const handleLoadEntityWithContext = (params) => {
125427
125445
  debugScroll("navigate", {
125428
125446
  fromEntityId: contextEntity == null ? void 0 : contextEntity["@id"],
@@ -125825,7 +125843,7 @@ const RenderEntity = forwardRef((props, ref) => {
125825
125843
  pendingDeletedEntityReviewProperties,
125826
125844
  displayedAiReviewPropertyOrder,
125827
125845
  profileManager == null ? void 0 : profileManager.$key,
125828
- (_c = profileManager == null ? void 0 : profileManager.profile) == null ? void 0 : _c.layouts,
125846
+ (_d = profileManager == null ? void 0 : profileManager.profile) == null ? void 0 : _d.layouts,
125829
125847
  tabs.length
125830
125848
  ]);
125831
125849
  useEffect(() => {
@@ -126351,13 +126369,13 @@ const RenderEntity = forwardRef((props, ref) => {
126351
126369
  }
126352
126370
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-row", children: [
126353
126371
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col w-full", children: [
126354
- ((_d = state.configuration) == null ? void 0 : _d.showControls) && /* @__PURE__ */ jsxRuntimeExports.jsx(
126372
+ ((_e2 = state.configuration) == null ? void 0 : _e2.showControls) && /* @__PURE__ */ jsxRuntimeExports.jsx(
126355
126373
  EntityEditorToolbar,
126356
126374
  {
126357
126375
  entity: contextEntity,
126358
126376
  quickSettingsVisible,
126359
126377
  reverseSidebarVisible,
126360
- enableReverseLinkBrowser: (_e2 = state.configuration) == null ? void 0 : _e2.enableReverseLinkBrowser,
126378
+ enableReverseLinkBrowser: (_f = state.configuration) == null ? void 0 : _f.enableReverseLinkBrowser,
126361
126379
  onLoadEntity: handleLoadEntityWithContext,
126362
126380
  onBack: () => {
126363
126381
  captureCurrentViewContext(activeTab);
@@ -126383,7 +126401,7 @@ const RenderEntity = forwardRef((props, ref) => {
126383
126401
  activePropertyLabel: selectedAiApprovalProperty ? getFieldTitle(selectedAiApprovalProperty) : void 0,
126384
126402
  remainingEntityCount: pendingOtherAiApprovalEntities.length,
126385
126403
  remainingFieldCount: pendingOtherAiApprovalFieldCount,
126386
- readonly: (_f = state.configuration) == null ? void 0 : _f.readonly,
126404
+ readonly: (_g = state.configuration) == null ? void 0 : _g.readonly,
126387
126405
  canGoPrevious: selectedAiApprovalIndex > 0,
126388
126406
  canGoNext: selectedAiApprovalIndex < pendingAiApprovals.length - 1,
126389
126407
  onPrevious: () => navigateToAiApproval(selectedAiApprovalIndex - 1),
@@ -126397,7 +126415,7 @@ const RenderEntity = forwardRef((props, ref) => {
126397
126415
  EntityEditorLayout,
126398
126416
  {
126399
126417
  renderTabs,
126400
- tabLocation: (_g = state.configuration) == null ? void 0 : _g.tabLocation,
126418
+ tabLocation: (_h = state.configuration) == null ? void 0 : _h.tabLocation,
126401
126419
  iconView,
126402
126420
  tabPaneWidth,
126403
126421
  scrollViewportHeight,
@@ -126410,7 +126428,7 @@ const RenderEntity = forwardRef((props, ref) => {
126410
126428
  quickSettingsHeader: renderQuickSettingsHeader(),
126411
126429
  untabbedContent: renderUntabbedEntityFields(),
126412
126430
  untabbedTopContent: renderUntabbedEntityFields({ untabbedNameSavedClassName: "bg-green-200 rounded p-1 my-1" }),
126413
- tabbedRequiredWarning: !((_h = state.configuration) == null ? void 0 : _h.readonly) && ((_i = tabs.find((t22) => t22.name === activeTab)) == null ? void 0 : _i.missingRequiredData) && /* @__PURE__ */ jsxRuntimeExports.jsx(
126431
+ tabbedRequiredWarning: !((_i = state.configuration) == null ? void 0 : _i.readonly) && ((_j = tabs.find((t22) => t22.name === activeTab)) == null ? void 0 : _j.missingRequiredData) && /* @__PURE__ */ jsxRuntimeExports.jsx(
126414
126432
  FloatingRequiredPropertiesWarning,
126415
126433
  {
126416
126434
  onClick: () => setHighlightRequiredProperties(!highlightRequiredProperties)
@@ -126418,7 +126436,7 @@ const RenderEntity = forwardRef((props, ref) => {
126418
126436
  ),
126419
126437
  tabbedAboutContent: activeTab === "about" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: showFieldHelp ? "space-y-3" : "space-y-1", children: [
126420
126438
  renderCoreEntityFields("tabbed"),
126421
- renderEntityPropertyFields(((_j = tabsWithAiReviewProperties.find((tab) => tab.name === "about")) == null ? void 0 : _j.inputs) ?? [], "tabbed")
126439
+ renderEntityPropertyFields(((_k = tabsWithAiReviewProperties.find((tab) => tab.name === "about")) == null ? void 0 : _k.inputs) ?? [], "tabbed")
126422
126440
  ] }),
126423
126441
  tabbedOtherTabsContent: tabsWithAiReviewProperties.map((tab) => {
126424
126442
  if (tab.name === activeTab && tab.name !== "about") {
@@ -126439,7 +126457,7 @@ const RenderEntity = forwardRef((props, ref) => {
126439
126457
  onClose: handleCloseContextReviewDialog,
126440
126458
  onUpdateContext: handleUpdateContext,
126441
126459
  approvalRecord: currentContextApprovalItem == null ? void 0 : currentContextApprovalItem.approvalRecord,
126442
- readonly: (_k = state.configuration) == null ? void 0 : _k.readonly,
126460
+ readonly: (_l = state.configuration) == null ? void 0 : _l.readonly,
126443
126461
  onAcceptAiContext: handleAcceptAiContext,
126444
126462
  onRejectAiContext: handleRejectAiContext
126445
126463
  }
@@ -126503,75 +126521,6 @@ function requireIsEmpty() {
126503
126521
  }
126504
126522
  var isEmptyExports = requireIsEmpty();
126505
126523
  const isEmpty = /* @__PURE__ */ getDefaultExportFromCjs(isEmptyExports);
126506
- var toFinite_1;
126507
- var hasRequiredToFinite;
126508
- function requireToFinite() {
126509
- if (hasRequiredToFinite) return toFinite_1;
126510
- hasRequiredToFinite = 1;
126511
- var toNumber = requireToNumber();
126512
- var INFINITY = 1 / 0, MAX_INTEGER = 17976931348623157e292;
126513
- function toFinite(value) {
126514
- if (!value) {
126515
- return value === 0 ? value : 0;
126516
- }
126517
- value = toNumber(value);
126518
- if (value === INFINITY || value === -INFINITY) {
126519
- var sign = value < 0 ? -1 : 1;
126520
- return sign * MAX_INTEGER;
126521
- }
126522
- return value === value ? value : 0;
126523
- }
126524
- toFinite_1 = toFinite;
126525
- return toFinite_1;
126526
- }
126527
- var toInteger_1;
126528
- var hasRequiredToInteger;
126529
- function requireToInteger() {
126530
- if (hasRequiredToInteger) return toInteger_1;
126531
- hasRequiredToInteger = 1;
126532
- var toFinite = requireToFinite();
126533
- function toInteger(value) {
126534
- var result = toFinite(value), remainder = result % 1;
126535
- return result === result ? remainder ? result - remainder : result : 0;
126536
- }
126537
- toInteger_1 = toInteger;
126538
- return toInteger_1;
126539
- }
126540
- var _createRound;
126541
- var hasRequired_createRound;
126542
- function require_createRound() {
126543
- if (hasRequired_createRound) return _createRound;
126544
- hasRequired_createRound = 1;
126545
- var root = require_root(), toInteger = requireToInteger(), toNumber = requireToNumber(), toString2 = requireToString$1();
126546
- var nativeIsFinite = root.isFinite, nativeMin = Math.min;
126547
- function createRound(methodName) {
126548
- var func = Math[methodName];
126549
- return function(number4, precision) {
126550
- number4 = toNumber(number4);
126551
- precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
126552
- if (precision && nativeIsFinite(number4)) {
126553
- var pair2 = (toString2(number4) + "e").split("e"), value = func(pair2[0] + "e" + (+pair2[1] + precision));
126554
- pair2 = (toString2(value) + "e").split("e");
126555
- return +(pair2[0] + "e" + (+pair2[1] - precision));
126556
- }
126557
- return func(number4);
126558
- };
126559
- }
126560
- _createRound = createRound;
126561
- return _createRound;
126562
- }
126563
- var round_1;
126564
- var hasRequiredRound;
126565
- function requireRound() {
126566
- if (hasRequiredRound) return round_1;
126567
- hasRequiredRound = 1;
126568
- var createRound = require_createRound();
126569
- var round2 = createRound("round");
126570
- round_1 = round2;
126571
- return round_1;
126572
- }
126573
- var roundExports = requireRound();
126574
- const round = /* @__PURE__ */ getDefaultExportFromCjs(roundExports);
126575
126524
  var uniq_1;
126576
126525
  var hasRequiredUniq;
126577
126526
  function requireUniq() {
@@ -126781,7 +126730,6 @@ class CrateManager {
126781
126730
  messages: []
126782
126731
  }
126783
126732
  };
126784
- const t0 = performance.now();
126785
126733
  if (!crate["@context"]) {
126786
126734
  this.__setError("init", `The crate file does not have a '@context'.`);
126787
126735
  return;
@@ -126866,25 +126814,27 @@ class CrateManager {
126866
126814
  );
126867
126815
  }
126868
126816
  }
126817
+ const reverseLinkIds = {};
126869
126818
  for (let i = 0; i < this.graphLength; i++) {
126870
126819
  const normalisedEntity = this.crate["@graph"][i];
126871
126820
  if (!normalisedEntity) continue;
126872
126821
  for (let property of Object.keys(normalisedEntity)) {
126873
126822
  if (this.coreProperties.includes(property)) continue;
126874
126823
  normalisedEntity[property].forEach((entry) => {
126824
+ var _a2, _b;
126875
126825
  if (entry == null ? void 0 : entry["@id"])
126876
126826
  entry["@id"] = idMap[entry["@id"]] ? idMap[entry["@id"]] : entry["@id"];
126877
126827
  if ((entry == null ? void 0 : entry["@id"]) && this.reverse[entry["@id"]]) {
126878
126828
  if (!this.reverse[entry["@id"]][property]) {
126879
126829
  this.reverse[entry["@id"]][property] = [];
126880
126830
  }
126881
- let links = this.reverse[entry["@id"]][property].map(
126882
- (l2) => l2["@id"]
126883
- );
126884
- if (!links.includes(normalisedEntity["@id"])) {
126831
+ reverseLinkIds[_a2 = entry["@id"]] ?? (reverseLinkIds[_a2] = {});
126832
+ (_b = reverseLinkIds[entry["@id"]])[property] ?? (_b[property] = /* @__PURE__ */ new Set());
126833
+ if (!reverseLinkIds[entry["@id"]][property].has(normalisedEntity["@id"])) {
126885
126834
  this.reverse[entry["@id"]][property].push({
126886
126835
  "@id": normalisedEntity["@id"]
126887
126836
  });
126837
+ reverseLinkIds[entry["@id"]][property].add(normalisedEntity["@id"]);
126888
126838
  }
126889
126839
  }
126890
126840
  });
@@ -126898,8 +126848,6 @@ class CrateManager {
126898
126848
  if (context) {
126899
126849
  this.providedContext = structuredClone(this.__normaliseContext(context));
126900
126850
  }
126901
- const t1 = performance.now();
126902
- console.debug(`Crate ingest and prep: ${round(t1 - t0, 1)}ms`);
126903
126851
  }
126904
126852
  /** Get the context
126905
126853
  * @returns the crate context
@@ -127970,7 +127918,6 @@ class CrateManager {
127970
127918
 
127971
127919
  */
127972
127920
  exportCrate() {
127973
- const t0 = performance.now();
127974
127921
  let entities = this.crate["@graph"].filter((e3) => {
127975
127922
  return !isUndefined(e3);
127976
127923
  }).map((e3) => {
@@ -127994,8 +127941,6 @@ class CrateManager {
127994
127941
  "@context": context.length === 1 ? context[0] : context,
127995
127942
  "@graph": entities
127996
127943
  };
127997
- const t1 = performance.now();
127998
- console.debug(`Crate export: ${round(t1 - t0, 1)}ms`);
127999
127944
  return crate;
128000
127945
  }
128001
127946
  /**
@@ -135246,7 +135191,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
135246
135191
  }) : null
135247
135192
  );
135248
135193
  var CacheProvider = EmotionCacheContext.Provider;
135249
- const version = "0.1.45";
135194
+ const version = "0.1.46";
135250
135195
  const pkg = {
135251
135196
  version
135252
135197
  };
@@ -135453,7 +135398,6 @@ function RecrateCrateBuilderInner(props) {
135453
135398
  resetTabOnEntityChange = false,
135454
135399
  resetTabOnProfileChange = false,
135455
135400
  quickSettingsVisible,
135456
- stateScopeKey,
135457
135401
  onReady,
135458
135402
  onError,
135459
135403
  onWarning,
@@ -135476,11 +135420,23 @@ function RecrateCrateBuilderInner(props) {
135476
135420
  const renderEntityRef = useRef(null);
135477
135421
  const lastHandledScrollRequestNonceRef = useRef(void 0);
135478
135422
  const keys2 = useRef({ cm: 0, pm: 0, lookups: 0 });
135423
+ const cmRef = useRef(null);
135479
135424
  const lastHandledEntityIdRef = useRef(void 0);
135425
+ const entityIdRef = useRef(entityId);
135426
+ const lastInitializedCrateRef = useRef(void 0);
135427
+ const lastInitializedProfileRef = useRef(void 0);
135428
+ const lastInitializedEntityTimestampsRef = useRef(void 0);
135429
+ const lastAppliedConfigurationRef = useRef(void 0);
135480
135430
  const hasProfileActionHandler = Boolean(onAddNewProfileRequest || onRemoveProfile);
135481
135431
  useEffect(() => {
135482
135432
  setApprovalState(roCrateApproval);
135483
135433
  }, [roCrateApproval]);
135434
+ useEffect(() => {
135435
+ cmRef.current = cm;
135436
+ }, [cm]);
135437
+ useEffect(() => {
135438
+ entityIdRef.current = entityId;
135439
+ }, [entityId]);
135484
135440
  const markApprovalPropertyApproved = useCallback((params) => {
135485
135441
  const { entityId: entityId2, propertyName: propertyName2, decision, value } = params;
135486
135442
  if (!entityId2 || !propertyName2) return;
@@ -135631,6 +135587,14 @@ function RecrateCrateBuilderInner(props) {
135631
135587
  lookup,
135632
135588
  hasProfileActionHandler
135633
135589
  ]);
135590
+ const createProfileManager = useCallback((profileToUse) => {
135591
+ const profileClone = profileToUse ? JSON.parse(JSON.stringify(profileToUse)) : {};
135592
+ const nextPm = new ProfileManager({
135593
+ profile: profileClone
135594
+ });
135595
+ nextPm.$key = ++keys2.current.pm;
135596
+ return nextPm;
135597
+ }, []);
135634
135598
  const init2 = useCallback(async () => {
135635
135599
  var _a2, _b;
135636
135600
  instance.changeLanguage(language2);
@@ -135640,6 +135604,29 @@ function RecrateCrateBuilderInner(props) {
135640
135604
  setError(false);
135641
135605
  return;
135642
135606
  }
135607
+ const currentCm = cmRef.current;
135608
+ const sameCrate = !!currentCm && lastInitializedCrateRef.current === crate;
135609
+ const sameEntityTimestampMode = lastInitializedEntityTimestampsRef.current === enableEntityTimestamps;
135610
+ if (sameCrate && sameEntityTimestampMode && lastInitializedProfileRef.current === profile) {
135611
+ if (lastAppliedConfigurationRef.current !== configuration) {
135612
+ state.setConfiguration(configuration);
135613
+ lastAppliedConfigurationRef.current = configuration;
135614
+ }
135615
+ setReady(true);
135616
+ return;
135617
+ }
135618
+ if (sameCrate && sameEntityTimestampMode) {
135619
+ const nextPm = createProfileManager(profile);
135620
+ currentCm.setProfileManager(nextPm);
135621
+ if (nextPm.context) currentCm.setContext(nextPm.context);
135622
+ setPm(nextPm);
135623
+ state.setConfiguration(configuration);
135624
+ lastInitializedProfileRef.current = profile;
135625
+ lastAppliedConfigurationRef.current = configuration;
135626
+ setReady(true);
135627
+ onReady == null ? void 0 : onReady();
135628
+ return;
135629
+ }
135643
135630
  const serialisedContext = JSON.stringify(crate["@context"] ?? "");
135644
135631
  schemaRegistry.setActiveSpecification(
135645
135632
  serialisedContext.includes("/ro/crate/1.1/") ? "1.1" : "1.2"
@@ -135648,11 +135635,7 @@ function RecrateCrateBuilderInner(props) {
135648
135635
  crate,
135649
135636
  entityTimestamps: enableEntityTimestamps
135650
135637
  });
135651
- const profileClone = profile ? JSON.parse(JSON.stringify(profile)) : {};
135652
- const newPm = new ProfileManager({
135653
- profile: profileClone
135654
- });
135655
- newPm.$key = ++keys2.current.pm;
135638
+ const newPm = createProfileManager(profile);
135656
135639
  newCm.setProfileManager(newPm);
135657
135640
  if (newPm.context) newCm.setContext(newPm.context);
135658
135641
  if (lookup) {
@@ -135672,6 +135655,10 @@ function RecrateCrateBuilderInner(props) {
135672
135655
  setCm(newCm);
135673
135656
  setPm(newPm);
135674
135657
  setError(false);
135658
+ lastInitializedCrateRef.current = crate;
135659
+ lastInitializedProfileRef.current = profile;
135660
+ lastInitializedEntityTimestampsRef.current = enableEntityTimestamps;
135661
+ lastAppliedConfigurationRef.current = configuration;
135675
135662
  state.setConfiguration(configuration);
135676
135663
  try {
135677
135664
  const graph = Array.isArray(crate == null ? void 0 : crate["@graph"]) ? crate["@graph"] : [];
@@ -135679,7 +135666,7 @@ function RecrateCrateBuilderInner(props) {
135679
135666
  graph.filter((entry) => entry && typeof entry === "object" && typeof entry["@id"] === "string").map((entry) => String(entry["@id"]))
135680
135667
  );
135681
135668
  state.editorState.prune(validIds);
135682
- const candidateIds = [(_a2 = state.editorState.latest()) == null ? void 0 : _a2.id, entityId, "./"];
135669
+ const candidateIds = [(_a2 = state.editorState.latest()) == null ? void 0 : _a2.id, entityIdRef.current, "./"];
135683
135670
  let nextEntity = null;
135684
135671
  for (const candidateId of candidateIds) {
135685
135672
  if (!candidateId) continue;
@@ -135703,7 +135690,7 @@ function RecrateCrateBuilderInner(props) {
135703
135690
  setError(true);
135704
135691
  onError == null ? void 0 : onError({ error: "Failed to initialize entity" });
135705
135692
  }
135706
- }, [crate, profile, entityId, lookup, configuration, enableEntityTimestamps, language2, onError, onReady, state.editorState]);
135693
+ }, [crate, profile, lookup, configuration, createProfileManager, enableEntityTimestamps, language2, onError, onReady, state.editorState]);
135707
135694
  const handleSetCurrentEntity = useCallback((params) => {
135708
135695
  const { id: id2, updateState = true } = params;
135709
135696
  if (!id2 || !cm) return;
@@ -135762,7 +135749,10 @@ function RecrateCrateBuilderInner(props) {
135762
135749
  lastHandledEntityIdRef.current = void 0;
135763
135750
  return;
135764
135751
  }
135765
- if (lastHandledEntityIdRef.current === entityId) {
135752
+ if (!cm) {
135753
+ return;
135754
+ }
135755
+ if (lastHandledEntityIdRef.current === entityId && entityId === (contextEntity == null ? void 0 : contextEntity["@id"])) {
135766
135756
  return;
135767
135757
  }
135768
135758
  lastHandledEntityIdRef.current = entityId;
@@ -135770,7 +135760,7 @@ function RecrateCrateBuilderInner(props) {
135770
135760
  const shouldPushToHistory = ((_a2 = state.editorState.latest()) == null ? void 0 : _a2.id) !== entityId;
135771
135761
  handleSetCurrentEntity({ id: entityId, updateState: shouldPushToHistory });
135772
135762
  }
135773
- }, [entityId, contextEntity, handleSetCurrentEntity, state.editorState]);
135763
+ }, [cm, entityId, contextEntity, handleSetCurrentEntity, state.editorState]);
135774
135764
  useEffect(() => {
135775
135765
  const request = scrollToFieldRequest;
135776
135766
  if (!(request == null ? void 0 : request.entityId) || !request.fieldName || !ready) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arpproject/recrate",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "type": "module",
5
5
  "main": "./dist/recrate.es.js",
6
6
  "module": "./dist/recrate.es.js",