@arpproject/recrate 0.1.53 → 0.1.54

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,12 +11,11 @@ interface UseEntityNavigationStateOptions {
11
11
  iconView: boolean;
12
12
  tabPaneWidth: number;
13
13
  onSaveCrate: (activeEntityId?: string) => void;
14
- debugScroll?: (...args: any[]) => void;
15
14
  }
16
15
  interface CaptureViewContextOptions {
17
16
  updateActiveTab?: boolean;
18
17
  }
19
- declare const useEntityNavigationState: ({ activeTab, activeContentRef, contextEntity, state, restoreInProgressRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, onSaveCrate, debugScroll, }: UseEntityNavigationStateOptions) => {
18
+ declare const useEntityNavigationState: ({ activeTab, activeContentRef, contextEntity, state, restoreInProgressRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, onSaveCrate, }: UseEntityNavigationStateOptions) => {
20
19
  captureCurrentViewContext: (tabName?: string) => void;
21
20
  captureViewContext: (tabName?: string, explicitScrollTop?: number, options?: CaptureViewContextOptions) => void;
22
21
  saveCratePreservingView: (activeEntityId?: string) => void;
@@ -28,7 +28,6 @@ interface UseEntityScrollRestorationOptions {
28
28
  updateActiveTab?: boolean;
29
29
  }) => void;
30
30
  disabled?: boolean;
31
- debugScroll?: (...args: any[]) => void;
32
31
  }
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;
32
+ declare const useEntityScrollRestoration: ({ activeTab, activeContentRef, contextEntity, renderTabs, tabsLength, extraPropertiesLength, scrollRestoreNonce, setScrollRestoreNonce, navigationRestoreReadyRef, pendingRestoredTabRef, restoreInProgressRef, pendingAddedPropertyRef, showAddPanel, reverseSidebarVisible, highlightRequiredProperties, iconView, tabPaneWidth, state, isAiScrollRestoreSuppressed, captureViewContext, disabled, }: UseEntityScrollRestorationOptions) => void;
34
33
  export default useEntityScrollRestoration;
@@ -94106,9 +94106,8 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94106
94106
  const inputValue = useRef("");
94107
94107
  const searchVersion = useRef(0);
94108
94108
  const promiseTimeout = 2500;
94109
- const querySearch = async (queryString) => {
94109
+ const querySearch = async (queryString, version2 = ++searchVersion.current) => {
94110
94110
  var _a2;
94111
- const version2 = ++searchVersion.current;
94112
94111
  setLoading(true);
94113
94112
  const lookup = new Lookup({
94114
94113
  config: (_a2 = crateManager == null ? void 0 : crateManager.profile) == null ? void 0 : _a2.lookup,
@@ -94159,44 +94158,60 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94159
94158
  }
94160
94159
  const responses = await Promise.all(lookups);
94161
94160
  const newMatches = [];
94161
+ const seenEntityIds = /* @__PURE__ */ new Set();
94162
+ const globalEntityIds = new Set(
94163
+ responses.filter((response) => response.endpoint === "global").flatMap((response) => response.documents ?? []).map((entity) => entity["@id"]).filter((id2) => id2 != null).map(String)
94164
+ );
94165
+ const uniqueEntities = (entities, source, limit) => {
94166
+ const unique = [];
94167
+ for (const entity of entities) {
94168
+ const id2 = entity["@id"] == null ? null : String(entity["@id"]);
94169
+ if (source === "internal" && id2 && globalEntityIds.has(id2)) continue;
94170
+ if (id2 && seenEntityIds.has(id2)) continue;
94171
+ if (id2) seenEntityIds.add(id2);
94172
+ unique.push({ ...entity, type: source });
94173
+ if (limit && unique.length === limit) break;
94174
+ }
94175
+ return unique;
94176
+ };
94177
+ const addMatchGroup = (label, entities) => {
94178
+ if (entities.length) newMatches.push({ label, entities });
94179
+ };
94162
94180
  responses.forEach((response) => {
94163
94181
  var _a3, _b, _c, _d, _e2, _f;
94164
94182
  if (response.endpoint === "internal" && ((_a3 = response.documents) == null ? void 0 : _a3.length)) {
94165
- newMatches.push({
94166
- label: t2("associate_existing_entity"),
94167
- entities: response.documents.map((e3) => ({ ...e3, type: "internal" })).slice(0, 5)
94168
- });
94183
+ addMatchGroup(
94184
+ t2("associate_existing_entity"),
94185
+ uniqueEntities(response.documents, "internal", 5)
94186
+ );
94169
94187
  } 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
- });
94188
+ addMatchGroup(
94189
+ t2("associate_global_entity"),
94190
+ uniqueEntities(response.documents, "global")
94191
+ );
94174
94192
  } else if (response.endpoint === "templates" && ((_c = response.documents) == null ? void 0 : _c.length)) {
94175
- newMatches.push({
94176
- label: t2("associate_entity_from_template"),
94177
- entities: response.documents.map((entity) => ({
94178
- ...entity,
94179
- type: "template"
94180
- }))
94181
- });
94193
+ addMatchGroup(
94194
+ t2("associate_entity_from_template"),
94195
+ uniqueEntities(response.documents, "template")
94196
+ );
94182
94197
  } else if (response.endpoint === "ror" && ((_d = response.documents) == null ? void 0 : _d.length)) {
94183
- newMatches.push({
94184
- label: t2("associate_organization_from_ror"),
94185
- entities: response.documents.map((entity) => ({ ...entity, type: "ror" }))
94186
- });
94198
+ addMatchGroup(
94199
+ t2("associate_organization_from_ror"),
94200
+ uniqueEntities(response.documents, "ror")
94201
+ );
94187
94202
  } else if (response.endpoint === "entities" && ((_e2 = response.documents) == null ? void 0 : _e2.length)) {
94188
- newMatches.push({
94189
- label: t2("associate_user_created_entity"),
94190
- entities: response.documents.map((entity) => ({ ...entity, type: "datapack" }))
94191
- });
94203
+ addMatchGroup(
94204
+ t2("associate_user_created_entity"),
94205
+ uniqueEntities(response.documents, "datapack")
94206
+ );
94192
94207
  } else if (response.endpoint === "datapacks" && ((_f = response.documents) == null ? void 0 : _f.length)) {
94193
- newMatches.push({
94194
- label: t2("associate_from_datapack"),
94195
- entities: response.documents.map((entity) => ({ ...entity, type: "datapack" }))
94196
- });
94208
+ addMatchGroup(
94209
+ t2("associate_from_datapack"),
94210
+ uniqueEntities(response.documents, "datapack")
94211
+ );
94197
94212
  }
94198
94213
  });
94199
- if (type4 !== "ANY") {
94214
+ if (type4 !== "ANY" && newEntity.length) {
94200
94215
  newMatches.push({
94201
94216
  label: t2("create_new_entity"),
94202
94217
  entities: newEntity
@@ -94268,7 +94283,10 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94268
94283
  };
94269
94284
  const handleSearch = (value) => {
94270
94285
  inputValue.current = value;
94271
- debouncedQuerySearch(value);
94286
+ const version2 = ++searchVersion.current;
94287
+ setMatches([]);
94288
+ setLoading(true);
94289
+ debouncedQuerySearch(value, version2);
94272
94290
  };
94273
94291
  const handleInputKeyDown = (event) => {
94274
94292
  const name2 = inputValue.current;
@@ -94346,11 +94364,14 @@ const AutoComplete = ({ type: type4, onLinkEntity, onCreateEntity }) => {
94346
94364
  onInputKeyDown: handleInputKeyDown,
94347
94365
  onChange: handleSelect,
94348
94366
  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
- ]),
94367
+ options: matches2.map((group, groupIndex) => ({
94368
+ label: /* @__PURE__ */ jsxRuntimeExports.jsx(Typography.Text, { strong: true, children: group.label }),
94369
+ options: group.entities.map((entity, entityIndex) => ({
94370
+ label: renderOption({ entity }),
94371
+ value: `${groupIndex}:${entityIndex}:${String(entity["@id"])}`,
94372
+ entity
94373
+ }))
94374
+ })),
94354
94375
  optionRender: (option) => option.label
94355
94376
  }
94356
94377
  )
@@ -124382,8 +124403,7 @@ const useEntityNavigationState = ({
124382
124403
  highlightRequiredProperties,
124383
124404
  iconView,
124384
124405
  tabPaneWidth,
124385
- onSaveCrate,
124386
- debugScroll = () => void 0
124406
+ onSaveCrate
124387
124407
  }) => {
124388
124408
  const getVisibleContextMarkers = useCallback((selector, dataAttribute) => {
124389
124409
  const source = activeContentRef.current;
@@ -124391,39 +124411,20 @@ const useEntityNavigationState = ({
124391
124411
  return Array.from(source.querySelectorAll(selector)).map((node2) => node2.getAttribute(dataAttribute)).filter((value) => Boolean(value));
124392
124412
  }, [activeContentRef]);
124393
124413
  const captureViewContext = useCallback((tabName = activeTab, explicitScrollTop, options = {}) => {
124394
- var _a2, _b, _c, _d, _e2, _f, _g, _h;
124414
+ var _a2, _b, _c, _d;
124395
124415
  const entityId = contextEntity == null ? void 0 : contextEntity["@id"];
124396
124416
  if (!entityId) return;
124397
124417
  const updateActiveTab = options.updateActiveTab !== false;
124398
124418
  if (restoreInProgressRef.current && typeof explicitScrollTop !== "number") {
124399
- debugScroll("capture.skipped-during-restore", {
124400
- entityId,
124401
- tabName,
124402
- latestId: (_a2 = state.editorState.latest()) == null ? void 0 : _a2.id
124403
- });
124404
124419
  return;
124405
124420
  }
124406
124421
  const previous = state.editorState.getNavigationState(entityId) ?? {};
124407
- const scrollTop = typeof explicitScrollTop === "number" ? explicitScrollTop : ((_b = activeContentRef.current) == null ? void 0 : _b.scrollTop) ?? ((_d = (_c = previous.tabStates) == null ? void 0 : _c[tabName]) == null ? void 0 : _d.scrollTop) ?? 0;
124422
+ const scrollTop = typeof explicitScrollTop === "number" ? explicitScrollTop : ((_a2 = activeContentRef.current) == null ? void 0 : _a2.scrollTop) ?? ((_c = (_b = previous.tabStates) == null ? void 0 : _b[tabName]) == null ? void 0 : _c.scrollTop) ?? 0;
124408
124423
  const nextTabState = {
124409
124424
  scrollTop,
124410
124425
  expandedSections: getVisibleContextMarkers('[aria-expanded="true"],[data-expanded="true"]', "data-section-id"),
124411
124426
  selectedItems: getVisibleContextMarkers('[aria-selected="true"],[data-selected="true"]', "data-item-id")
124412
124427
  };
124413
- debugScroll("capture", {
124414
- entityId,
124415
- tabName,
124416
- latestId: (_e2 = state.editorState.latest()) == null ? void 0 : _e2.id,
124417
- explicitScrollTop,
124418
- scrollTop,
124419
- updateActiveTab,
124420
- previousScrollTop: ((_g = (_f = previous.tabStates) == null ? void 0 : _f[tabName]) == null ? void 0 : _g.scrollTop) ?? null,
124421
- viewport: activeContentRef.current ? {
124422
- clientHeight: activeContentRef.current.clientHeight,
124423
- scrollHeight: activeContentRef.current.scrollHeight,
124424
- currentScrollTop: activeContentRef.current.scrollTop
124425
- } : null
124426
- });
124427
124428
  const navigationState = {
124428
124429
  ...updateActiveTab ? { activeTab: tabName } : {},
124429
124430
  tabStates: { [tabName]: nextTabState },
@@ -124435,7 +124436,7 @@ const useEntityNavigationState = ({
124435
124436
  tabPaneWidth
124436
124437
  }
124437
124438
  };
124438
- if (((_h = state.editorState.latest()) == null ? void 0 : _h.id) === entityId) {
124439
+ if (((_d = state.editorState.latest()) == null ? void 0 : _d.id) === entityId) {
124439
124440
  state.editorState.updateNavigationState(navigationState);
124440
124441
  } else {
124441
124442
  state.editorState.updateNavigationStateForId(entityId, navigationState);
@@ -124500,8 +124501,7 @@ const useEntityScrollRestoration = ({
124500
124501
  state,
124501
124502
  isAiScrollRestoreSuppressed,
124502
124503
  captureViewContext,
124503
- disabled: disabled2 = false,
124504
- debugScroll = () => void 0
124504
+ disabled: disabled2 = false
124505
124505
  }) => {
124506
124506
  useEffect(() => {
124507
124507
  var _a2, _b, _c, _d;
@@ -124513,16 +124513,6 @@ const useEntityScrollRestoration = ({
124513
124513
  const viewport = activeContentRef.current;
124514
124514
  if (!viewport) return;
124515
124515
  const restoreTarget = ((_d = (_c = (_b = state.editorState.getNavigationState(contextEntity["@id"])) == null ? void 0 : _b.tabStates) == null ? void 0 : _c[activeTab]) == null ? void 0 : _d.scrollTop) ?? 0;
124516
- debugScroll("restore.start", {
124517
- entityId: contextEntity["@id"],
124518
- activeTab,
124519
- restoreTarget,
124520
- viewport: {
124521
- clientHeight: viewport.clientHeight,
124522
- scrollHeight: viewport.scrollHeight,
124523
- scrollTop: viewport.scrollTop
124524
- }
124525
- });
124526
124516
  let cancelled = false;
124527
124517
  let rafId = 0;
124528
124518
  let timerId = 0;
@@ -124544,32 +124534,9 @@ const useEntityScrollRestoration = ({
124544
124534
  viewport.scrollTo({ top: target, behavior: "auto" });
124545
124535
  const contentReady = restoreTarget <= maxScrollable || restoreTarget === 0;
124546
124536
  const done = contentReady && Math.abs(viewport.scrollTop - target) <= 1;
124547
- debugScroll("restore.attempt", {
124548
- entityId: contextEntity["@id"],
124549
- activeTab,
124550
- attempts,
124551
- restoreTarget,
124552
- maxScrollable,
124553
- target,
124554
- actualScrollTop: viewport.scrollTop,
124555
- clientHeight: viewport.clientHeight,
124556
- scrollHeight: viewport.scrollHeight,
124557
- contentReady,
124558
- done
124559
- });
124560
124537
  if (done || attempts >= maxAttempts) {
124561
124538
  restoreInProgressRef.current = false;
124562
124539
  viewport.style.scrollBehavior = previousInlineScrollBehavior;
124563
- debugScroll("restore.stop", {
124564
- entityId: contextEntity["@id"],
124565
- activeTab,
124566
- attempts,
124567
- restoreTarget,
124568
- finalScrollTop: viewport.scrollTop,
124569
- maxScrollable,
124570
- contentReady,
124571
- done
124572
- });
124573
124540
  return;
124574
124541
  }
124575
124542
  timerId = window.setTimeout(() => {
@@ -124599,11 +124566,6 @@ const useEntityScrollRestoration = ({
124599
124566
  if (((_a2 = pendingAddedPropertyRef.current) == null ? void 0 : _a2.entityId) === contextEntity["@id"]) return;
124600
124567
  if (isAiScrollRestoreSuppressed()) return;
124601
124568
  if (pendingTab) {
124602
- debugScroll("restore.pending-tab", {
124603
- entityId: contextEntity["@id"],
124604
- pendingTab,
124605
- activeTab
124606
- });
124607
124569
  if (activeTab !== pendingTab) {
124608
124570
  return;
124609
124571
  }
@@ -125440,7 +125402,6 @@ const RenderEntity = forwardRef((props, ref) => {
125440
125402
  const pendingAiScrollPropertyRef = useRef(null);
125441
125403
  const aiScrollRestoreSuppressedUntilRef = useRef(0);
125442
125404
  const lastAutoNavigatedAiApprovalRef = useRef(null);
125443
- const debugScroll = (...args) => console.log("[recrate-scroll-debug]", ...args);
125444
125405
  const {
125445
125406
  activeContentRef,
125446
125407
  contentContainerRef,
@@ -125485,8 +125446,7 @@ const RenderEntity = forwardRef((props, ref) => {
125485
125446
  highlightRequiredProperties,
125486
125447
  iconView,
125487
125448
  tabPaneWidth,
125488
- onSaveCrate,
125489
- debugScroll
125449
+ onSaveCrate
125490
125450
  });
125491
125451
  useEntityScrollRestoration({
125492
125452
  activeTab,
@@ -125509,8 +125469,7 @@ const RenderEntity = forwardRef((props, ref) => {
125509
125469
  state,
125510
125470
  isAiScrollRestoreSuppressed,
125511
125471
  captureViewContext,
125512
- disabled: readonly,
125513
- debugScroll
125472
+ disabled: readonly
125514
125473
  });
125515
125474
  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"]]);
125516
125475
  const pendingAiApprovalProperties = useMemo$1(() => pendingAiApprovalRecords.map((approvalRecord) => approvalRecord == null ? void 0 : approvalRecord.propertyName).filter((property) => typeof property === "string" && property.length > 0), [pendingAiApprovalRecords]);
@@ -125733,20 +125692,6 @@ const RenderEntity = forwardRef((props, ref) => {
125733
125692
  willScrollToAddedProperty = true;
125734
125693
  }
125735
125694
  }
125736
- debugScroll("init", {
125737
- entityId: entity2["@id"],
125738
- latestId: latestEntry == null ? void 0 : latestEntry.id,
125739
- isCurrentHistoryEntity,
125740
- renderTabs: layout.renderTabs,
125741
- tabNames,
125742
- restorableTabNames,
125743
- savedActiveTab,
125744
- savedTabStillValid,
125745
- currentTabStillValid,
125746
- restoredTab,
125747
- nextActiveTab,
125748
- navState
125749
- });
125750
125695
  pendingRestoredTabRef.current = willScrollToAddedProperty ? null : nextActiveTab;
125751
125696
  setActiveTab(nextActiveTab);
125752
125697
  if (typeof ((_b2 = navState == null ? void 0 : navState.uiState) == null ? void 0 : _b2.showAddPanel) === "boolean") setShowAddPanel(navState.uiState.showAddPanel);
@@ -125792,11 +125737,6 @@ const RenderEntity = forwardRef((props, ref) => {
125792
125737
  }
125793
125738
  }, [readonly, entity == null ? void 0 : entity["@id"]]);
125794
125739
  const handleLoadEntityWithContext = (params) => {
125795
- debugScroll("navigate", {
125796
- fromEntityId: contextEntity == null ? void 0 : contextEntity["@id"],
125797
- activeTab,
125798
- params
125799
- });
125800
125740
  captureCurrentViewContext(activeTab);
125801
125741
  onLoadEntity(params);
125802
125742
  };
@@ -135678,7 +135618,7 @@ var EmotionCacheContext = /* @__PURE__ */ React.createContext(
135678
135618
  }) : null
135679
135619
  );
135680
135620
  var CacheProvider = EmotionCacheContext.Provider;
135681
- const version = "0.1.53";
135621
+ const version = "0.1.54";
135682
135622
  const pkg = {
135683
135623
  version
135684
135624
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arpproject/recrate",
3
- "version": "0.1.53",
3
+ "version": "0.1.54",
4
4
  "type": "module",
5
5
  "main": "./dist/recrate.es.js",
6
6
  "module": "./dist/recrate.es.js",