zidane-ui 9.2.3 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/live.d.ts +8 -0
- package/dist/adapters/live.js +19 -8
- package/dist/adapters/server-composer-host.js +22 -9
- package/dist/adapters/server-git-host.js +5 -2
- package/dist/adapters/server-host.js +158 -27
- package/dist/adapters/server-machines-host.js +7 -0
- package/dist/adapters/server-media.d.ts +9 -1
- package/dist/adapters/server-media.js +14 -1
- package/dist/adapters/server-session-host.js +49 -0
- package/dist/adapters/server-settings-sections.js +4 -1
- package/dist/adapters/sse-host.js +3 -0
- package/dist/adapters/sse-protocol.d.ts +10 -0
- package/dist/appearance/ZoomIndicator.js +5 -8
- package/dist/chat/HostTranscript.d.ts +0 -12
- package/dist/chat/HostTranscript.js +20 -1
- package/dist/chat/SessionStreamsProvider.d.ts +9 -1
- package/dist/chat/SessionStreamsProvider.js +11 -2
- package/dist/chat/Transcript.d.ts +21 -11
- package/dist/chat/Transcript.js +346 -161
- package/dist/chat/composer/ModelOptionsPicker.js +6 -2
- package/dist/chat/composer/ModelPicker.d.ts +1 -1
- package/dist/chat/composer/PlacePicker.d.ts +3 -1
- package/dist/chat/composer/PlacePicker.js +5 -1
- package/dist/chat/composer/use-draft-target.js +15 -3
- package/dist/chat/headless/block-runs.js +26 -1
- package/dist/chat/headless/chip-views.js +1 -1
- package/dist/chat/headless/draft-target.d.ts +28 -1
- package/dist/chat/headless/draft-target.js +22 -1
- package/dist/chat/headless/host.d.ts +43 -7
- package/dist/chat/headless/hosts.d.ts +4 -0
- package/dist/chat/headless/index.d.ts +27 -26
- package/dist/chat/headless/index.js +15 -14
- package/dist/chat/headless/labels.d.ts +17 -0
- package/dist/chat/headless/labels.js +17 -0
- package/dist/chat/headless/markdown-chunks.d.ts +2 -1
- package/dist/chat/headless/markdown-chunks.js +12 -20
- package/dist/chat/headless/markdown-scan.d.ts +64 -0
- package/dist/chat/headless/markdown-scan.js +119 -0
- package/dist/chat/headless/markdown-stream.d.ts +64 -0
- package/dist/chat/headless/markdown-stream.js +143 -0
- package/dist/chat/headless/output-pager.d.ts +68 -0
- package/dist/chat/headless/output-pager.js +113 -0
- package/dist/chat/headless/prompt-origin.d.ts +2 -0
- package/dist/chat/headless/prompt-origin.js +6 -2
- package/dist/chat/headless/session-list.d.ts +10 -0
- package/dist/chat/headless/sidebar/activity.d.ts +14 -0
- package/dist/chat/headless/sidebar/activity.js +32 -0
- package/dist/chat/headless/sidebar/directory.d.ts +19 -2
- package/dist/chat/headless/sidebar/directory.js +19 -51
- package/dist/chat/headless/sidebar/environment.d.ts +15 -4
- package/dist/chat/headless/sidebar/environment.js +27 -9
- package/dist/chat/headless/sidebar/index.d.ts +2 -2
- package/dist/chat/headless/sidebar/index.js +2 -2
- package/dist/chat/headless/sidebar/labels.d.ts +19 -2
- package/dist/chat/headless/sidebar/labels.js +8 -1
- package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
- package/dist/chat/headless/sidebar/prewarm.js +114 -0
- package/dist/chat/headless/streams/actions.d.ts +4 -2
- package/dist/chat/headless/streams/actions.js +2 -1
- package/dist/chat/headless/streams/event-bytes.d.ts +17 -0
- package/dist/chat/headless/streams/event-bytes.js +46 -0
- package/dist/chat/headless/streams/live-events.d.ts +25 -1
- package/dist/chat/headless/streams/live-events.js +53 -2
- package/dist/chat/headless/streams/selectors.d.ts +3 -0
- package/dist/chat/headless/streams/selectors.js +8 -1
- package/dist/chat/headless/streams/session-streams.d.ts +15 -3
- package/dist/chat/headless/streams/session-streams.js +31 -3
- package/dist/chat/headless/streams/store.d.ts +45 -6
- package/dist/chat/headless/streams/store.js +85 -31
- package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
- package/dist/chat/headless/streams/transcript-map.js +85 -0
- package/dist/chat/headless/streams/transcript.d.ts +4 -2
- package/dist/chat/headless/streams/transcript.js +19 -7
- package/dist/chat/headless/streams/types.d.ts +2 -1
- package/dist/chat/headless/transcript/batch.js +5 -1
- package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
- package/dist/chat/headless/transcript/blob-media.js +23 -0
- package/dist/chat/headless/transcript/collapse.d.ts +10 -0
- package/dist/chat/headless/transcript/collapse.js +35 -6
- package/dist/chat/headless/transcript/derive.d.ts +98 -0
- package/dist/chat/headless/transcript/derive.js +89 -0
- package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
- package/dist/chat/headless/transcript/exchange-media.js +8 -5
- package/dist/chat/headless/transcript/fold-attachments.d.ts +2 -0
- package/dist/chat/headless/transcript/fold-attachments.js +3 -2
- package/dist/chat/headless/transcript/fold.d.ts +2 -1
- package/dist/chat/headless/transcript/fold.js +16 -6
- package/dist/chat/headless/transcript/incremental.d.ts +53 -0
- package/dist/chat/headless/transcript/incremental.js +181 -0
- package/dist/chat/headless/transcript/index.d.ts +2 -2
- package/dist/chat/headless/transcript/index.js +2 -2
- package/dist/chat/headless/transcript/nesting.js +2 -1
- package/dist/chat/headless/transcript/rail.d.ts +50 -1
- package/dist/chat/headless/transcript/rail.js +165 -23
- package/dist/chat/headless/transcript/rows.d.ts +5 -1
- package/dist/chat/headless/transcript/run-failures.js +2 -1
- package/dist/chat/headless/transcript/seams.d.ts +78 -0
- package/dist/chat/headless/transcript/seams.js +116 -0
- package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
- package/dist/chat/headless/transcript/tool-media.js +27 -9
- package/dist/chat/index.d.ts +9 -8
- package/dist/chat/index.js +18 -17
- package/dist/chat/sidebar/ProjectIcon.js +1 -1
- package/dist/chat/sidebar/RowChips.js +2 -2
- package/dist/chat/sidebar/SessionSidebar.d.ts +6 -0
- package/dist/chat/sidebar/SessionSidebar.js +23 -16
- package/dist/chat/sidebar/SidebarFilterMenu.js +0 -1
- package/dist/chat/sidebar/SidebarFold.js +17 -16
- package/dist/chat/sidebar/SidebarFooter.d.ts +8 -5
- package/dist/chat/sidebar/SidebarFooter.js +6 -6
- package/dist/chat/sidebar/SidebarSessionRow.d.ts +7 -1
- package/dist/chat/sidebar/SidebarSessionRow.js +11 -8
- package/dist/chat/sidebar/session-menu.d.ts +4 -0
- package/dist/chat/sidebar/session-menu.js +14 -2
- package/dist/chat/sidebar/sidebar-live.js +28 -4
- package/dist/chat/sidebar/useInboxRows.js +6 -6
- package/dist/chat/sidebar/useInboxTriage.js +50 -47
- package/dist/chat/sidebar/useSessionSearch.js +19 -18
- package/dist/chat/testing/contract.d.ts +5 -3
- package/dist/chat/testing/contract.js +66 -1
- package/dist/chat/transcript/DiffLines.d.ts +6 -1
- package/dist/chat/transcript/DiffLines.js +35 -20
- package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
- package/dist/chat/transcript/EditDiffBlock.js +89 -30
- package/dist/chat/transcript/FileChip.js +28 -0
- package/dist/chat/transcript/LazyRow.d.ts +40 -40
- package/dist/chat/transcript/LazyRow.js +100 -149
- package/dist/chat/transcript/MermaidDiagram.js +2 -1
- package/dist/chat/transcript/PromptEcho.js +3 -11
- package/dist/chat/transcript/SessionChip.d.ts +11 -0
- package/dist/chat/transcript/SessionChip.js +34 -0
- package/dist/chat/transcript/SubagentBlock.js +3 -2
- package/dist/chat/transcript/TranscriptRail.d.ts +25 -2
- package/dist/chat/transcript/TranscriptRail.js +175 -17
- package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
- package/dist/chat/transcript/TranscriptRow.js +4 -3
- package/dist/chat/transcript/actions.d.ts +37 -1
- package/dist/chat/transcript/actions.js +27 -1
- package/dist/chat/transcript/chip-details.d.ts +11 -0
- package/dist/chat/transcript/chip-details.js +17 -1
- package/dist/chat/transcript/clipped-output.d.ts +58 -0
- package/dist/chat/transcript/clipped-output.js +131 -0
- package/dist/chat/transcript/fold-attachments.js +10 -5
- package/dist/chat/transcript/fold-worker.js +5 -3
- package/dist/chat/transcript/fold.js +13 -4
- package/dist/chat/transcript/index.d.ts +11 -10
- package/dist/chat/transcript/index.js +10 -9
- package/dist/chat/transcript/markdown-cache.d.ts +17 -2
- package/dist/chat/transcript/markdown-cache.js +48 -4
- package/dist/chat/transcript/markdown.js +110 -55
- package/dist/chat/transcript/media-gallery.d.ts +3 -2
- package/dist/chat/transcript/media-gallery.js +19 -19
- package/dist/chat/transcript/messages.js +5 -4
- package/dist/chat/transcript/notices.js +2 -1
- package/dist/chat/transcript/prompt.d.ts +1 -1
- package/dist/chat/transcript/prompt.js +6 -4
- package/dist/chat/transcript/prose.js +2 -1
- package/dist/chat/transcript/root-items.d.ts +96 -0
- package/dist/chat/transcript/root-items.js +180 -0
- package/dist/chat/transcript/row-mount.d.ts +184 -0
- package/dist/chat/transcript/row-mount.js +532 -0
- package/dist/chat/transcript/row-parking.d.ts +152 -0
- package/dist/chat/transcript/row-parking.js +171 -0
- package/dist/chat/transcript/row-ui-state.d.ts +37 -0
- package/dist/chat/transcript/row-ui-state.js +53 -0
- package/dist/chat/transcript/run-rows.js +3 -2
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/chat/transcript/tasks.js +3 -2
- package/dist/chat/transcript/tool-media.d.ts +4 -2
- package/dist/chat/transcript/tool-media.js +15 -7
- package/dist/chat/transcript/tool-parts.d.ts +27 -4
- package/dist/chat/transcript/tool-parts.js +31 -6
- package/dist/chat/transcript/tool-payload.js +26 -11
- package/dist/chat/transcript/tool-row.d.ts +2 -1
- package/dist/chat/transcript/tool-row.js +38 -19
- package/dist/chat/transcript/use-transcript-rows.d.ts +25 -8
- package/dist/chat/transcript/use-transcript-rows.js +28 -46
- package/dist/chat/transcript/useHistoryBackfill.d.ts +42 -0
- package/dist/chat/transcript/useHistoryBackfill.js +170 -0
- package/dist/chat/transcript/useStickToBottom.js +2 -3
- package/dist/chat/transcript/useTranscriptFind.js +2 -4
- package/dist/chat/transcript/useTranscriptScroll.d.ts +7 -4
- package/dist/chat/transcript/useTranscriptScroll.js +12 -1
- package/dist/chat/transcript/useTranscriptSearch.d.ts +2 -2
- package/dist/chat/transcript/useTranscriptSearch.js +35 -19
- package/dist/chat/transcript/useTranscriptSelectionCopy.d.ts +5 -5
- package/dist/chat/transcript/useTranscriptSelectionCopy.js +28 -7
- package/dist/chat/transcript/view-scope.d.ts +26 -6
- package/dist/chat/transcript/view-scope.js +106 -20
- package/dist/code/editor/FileTree.d.ts +2 -0
- package/dist/code/editor/FileTree.js +1 -1
- package/dist/code/editor/FileView.js +16 -25
- package/dist/code/editor/find/useFind.js +17 -17
- package/dist/code/editor/useCodeDocument.js +22 -19
- package/dist/code/editor/useDetachCleanup.js +4 -3
- package/dist/code/use-highlighted-html.js +12 -13
- package/dist/components/IconButton.d.ts +3 -1
- package/dist/components/IconButton.js +7 -2
- package/dist/components/IconButtonTip.d.ts +3 -1
- package/dist/components/IconButtonTip.js +2 -1
- package/dist/components/RowActionsMenu.js +7 -14
- package/dist/components/Tooltip.d.ts +4 -1
- package/dist/components/Tooltip.js +8 -6
- package/dist/components/assign-ref.d.ts +8 -0
- package/dist/components/assign-ref.js +12 -0
- package/dist/components/floating/FloatingSurface.js +2 -2
- package/dist/components/floating/HoverCard.js +32 -14
- package/dist/components/floating/Popover.js +4 -7
- package/dist/components/floating/useAnchoredPosition.d.ts +5 -3
- package/dist/components/floating/useAnchoredPosition.js +7 -7
- package/dist/components/object-key.d.ts +7 -0
- package/dist/components/object-key.js +18 -0
- package/dist/components/palette/PaletteList.js +2 -7
- package/dist/components/tooltip-arming.d.ts +3 -0
- package/dist/components/tooltip-arming.js +8 -1
- package/dist/core.css +3 -3
- package/dist/dist/{index-E1Z0aPmi.d.ts → index-BheVJOLc.d.ts} +3 -1
- package/dist/dist/index.d.ts +2 -2
- package/dist/files/FilesTab.js +0 -1
- package/dist/files/TreeColumn.d.ts +2 -4
- package/dist/files/TreeColumn.js +0 -5
- package/dist/files/headless/host.d.ts +3 -7
- package/dist/files/headless/labels.d.ts +0 -1
- package/dist/files/headless/labels.js +0 -1
- package/dist/files/headless/workspace-diff.js +1 -1
- package/dist/files/useCodeReview.js +1 -3
- package/dist/files/useFilesDiagnostics.d.ts +1 -1
- package/dist/files/useFilesDiagnostics.js +4 -11
- package/dist/files/useOpenFiles.js +9 -12
- package/dist/files/useWorkspace.d.ts +5 -7
- package/dist/files/useWorkspace.js +4 -15
- package/dist/git/GitBar.js +5 -3
- package/dist/git/MoveSessionDialog.d.ts +18 -8
- package/dist/git/MoveSessionDialog.js +32 -53
- package/dist/git/MoveToDialog.d.ts +61 -0
- package/dist/git/MoveToDialog.js +240 -0
- package/dist/git/SandboxManager.js +9 -4
- package/dist/git/SyncChip.js +11 -4
- package/dist/git/TeleportSessionDialog.d.ts +69 -0
- package/dist/git/TeleportSessionDialog.js +440 -0
- package/dist/git/headless/host.d.ts +14 -0
- package/dist/git/headless/index.d.ts +2 -1
- package/dist/git/headless/index.js +2 -1
- package/dist/git/headless/labels.d.ts +44 -1
- package/dist/git/headless/labels.js +50 -0
- package/dist/git/headless/sandboxes.d.ts +1 -1
- package/dist/git/headless/sandboxes.js +4 -3
- package/dist/git/headless/teleport.d.ts +76 -0
- package/dist/git/headless/teleport.js +19 -0
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +4 -2
- package/dist/git/useEnvironmentChoices.d.ts +5 -2
- package/dist/git/useEnvironmentChoices.js +12 -4
- package/dist/hooks/useLatest.d.ts +8 -0
- package/dist/hooks/useLatest.js +17 -0
- package/dist/hooks/useMinuteTick.d.ts +6 -2
- package/dist/hooks/useMinuteTick.js +12 -6
- package/dist/hooks/useNearViewport.js +11 -8
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/keybindings/KeybindingsProvider.js +3 -4
- package/dist/keybindings/headless/catalog.d.ts +1 -1
- package/dist/keybindings/headless/catalog.js +18 -0
- package/dist/machines/AddServerForm.js +55 -3
- package/dist/machines/Banners.d.ts +2 -2
- package/dist/machines/Banners.js +3 -3
- package/dist/machines/DaemonMenu.js +1 -3
- package/dist/machines/HostsSection.js +5 -1
- package/dist/machines/OrganizationPanel.d.ts +25 -0
- package/dist/machines/OrganizationPanel.js +266 -0
- package/dist/machines/PersonalLayerPanel.d.ts +32 -0
- package/dist/machines/PersonalLayerPanel.js +360 -0
- package/dist/machines/headless/fixture-host.d.ts +10 -0
- package/dist/machines/headless/fixture-host.js +44 -0
- package/dist/machines/headless/host.d.ts +21 -1
- package/dist/machines/headless/index.d.ts +3 -1
- package/dist/machines/headless/index.js +3 -1
- package/dist/machines/headless/labels.d.ts +55 -0
- package/dist/machines/headless/labels.js +58 -1
- package/dist/machines/headless/layer.d.ts +64 -0
- package/dist/machines/headless/layer.js +56 -0
- package/dist/machines/headless/organization.d.ts +38 -0
- package/dist/machines/headless/organization.js +44 -0
- package/dist/machines/index.d.ts +3 -1
- package/dist/machines/index.js +3 -1
- package/dist/machines/testing/contract.d.ts +25 -1
- package/dist/machines/testing/contract.js +97 -1
- package/dist/motion/grow.js +12 -13
- package/dist/motion/swap.js +2 -5
- package/dist/motion/use-flip-list.d.ts +14 -0
- package/dist/motion/use-flip-list.js +17 -12
- package/dist/palette/headless/app-sources.js +37 -0
- package/dist/palette/headless/labels.js +3 -0
- package/dist/server/sse-handler.js +25 -2
- package/dist/session/DiffFileTree.js +1 -4
- package/dist/session/OpenSessionsDialog.d.ts +46 -0
- package/dist/session/OpenSessionsDialog.js +170 -0
- package/dist/session/PlanTracker.js +1 -2
- package/dist/session/ProjectHome.js +10 -9
- package/dist/session/RemindersPanel.js +10 -12
- package/dist/session/SecretsPanel.js +2 -1
- package/dist/session/SessionHeader.js +1 -0
- package/dist/session/SessionPeopleStack.d.ts +23 -0
- package/dist/session/SessionPeopleStack.js +65 -0
- package/dist/session/SessionPlaceMenu.js +5 -4
- package/dist/session/ShareSessionDialog.d.ts +32 -0
- package/dist/session/ShareSessionDialog.js +342 -0
- package/dist/session/TypingLine.d.ts +22 -0
- package/dist/session/TypingLine.js +31 -0
- package/dist/session/headless/host.d.ts +40 -1
- package/dist/session/headless/index.d.ts +4 -2
- package/dist/session/headless/index.js +3 -1
- package/dist/session/headless/labels.d.ts +49 -0
- package/dist/session/headless/labels.js +56 -0
- package/dist/session/headless/people.d.ts +29 -0
- package/dist/session/headless/people.js +53 -0
- package/dist/session/headless/place.d.ts +5 -0
- package/dist/session/headless/place.js +5 -1
- package/dist/session/headless/typing.d.ts +37 -0
- package/dist/session/headless/typing.js +60 -0
- package/dist/session/index.d.ts +5 -1
- package/dist/session/index.js +5 -1
- package/dist/settings/headless/fixture-performance.js +4 -2
- package/dist/settings/headless/performance.d.ts +4 -0
- package/dist/settings/headless/search.d.ts +1 -1
- package/dist/settings/headless/sections-host.d.ts +7 -2
- package/dist/settings/section.d.ts +15 -3
- package/dist/settings/section.js +15 -3
- package/dist/settings/sections/environments/EnvironmentsSection.js +30 -6
- package/dist/settings/sections/keybindings/labels.d.ts +3 -0
- package/dist/settings/sections/keybindings/labels.js +3 -0
- package/dist/settings/sections/keybindings/rows.js +12 -0
- package/dist/settings/sections/logs/LogsSection.js +5 -8
- package/dist/settings/sections/performance/PerformanceSection.js +8 -1
- package/dist/settings/sections/performance/labels.d.ts +2 -0
- package/dist/settings/sections/performance/labels.js +2 -0
- package/dist/styles.css +65 -9
- package/dist/terminal/HostTerminalSurface.js +28 -30
- package/dist/terminal/TerminalPanel.js +4 -12
- package/dist/terminal/TerminalProvider.d.ts +10 -2
- package/dist/terminal/TerminalProvider.js +10 -2
- package/dist/terminal/headless/labels.d.ts +0 -1
- package/dist/terminal/headless/labels.js +1 -2
- package/dist/terminal/headless/store.js +5 -1
- package/dist/views/headless/answers.d.ts +8 -2
- package/dist/views/headless/answers.js +58 -1
- package/dist/views/headless/placement.d.ts +78 -0
- package/dist/views/headless/placement.js +154 -44
- package/dist/workspace/LayoutBudget.js +1 -7
- package/package.json +2 -2
- package/src/styles/chat.css +3 -1
- package/src/styles/palette.css +3 -3
- package/src/styles/transcript.css +50 -5
- /package/dist/dist/{index-De9AbmxS.d.ts → index-ttmMvjgM.d.ts} +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
1
|
+
import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
// src/code/editor/useCodeDocument.ts
|
|
3
|
+
/** The same text at the same time: no news from disk. */
|
|
4
|
+
function sameText(a, b) {
|
|
5
|
+
return a.mtimeMs === b.mtimeMs && a.contents === b.contents;
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* Keeps one document's draft, dirty state and disk conflicts consistent; see the module comment.
|
|
5
9
|
*
|
|
@@ -55,25 +59,24 @@ function useCodeDocument({ doc, initialDraft = null, initialBase, save: write, r
|
|
|
55
59
|
if (reset) setResets((n) => n + 1);
|
|
56
60
|
onAdopt?.(next, reset);
|
|
57
61
|
}, [onAdopt]);
|
|
58
|
-
const seenDoc =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (doc
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const [seenDoc, setSeenDoc] = useState(() => sameText(doc, base) ? doc : null);
|
|
63
|
+
const [fromDisk, setFromDisk] = useState(null);
|
|
64
|
+
if (!seenDoc || !sameText(doc, seenDoc)) {
|
|
65
|
+
if (sameText(doc, base)) setSeenDoc(doc);
|
|
66
|
+
else if (dirty) {
|
|
67
|
+
if (!conflict) setConflict(true);
|
|
68
|
+
} else {
|
|
69
|
+
setSeenDoc(doc);
|
|
70
|
+
setBase(doc);
|
|
71
|
+
setConflict(false);
|
|
72
|
+
setResets((n) => n + 1);
|
|
73
|
+
setFromDisk(doc);
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
dirty,
|
|
75
|
-
adopt
|
|
76
|
-
]);
|
|
75
|
+
}
|
|
76
|
+
const adoptedFromDisk = useEffectEvent((next) => onAdopt?.(next, true));
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (fromDisk) adoptedFromDisk(fromDisk);
|
|
79
|
+
}, [fromDisk]);
|
|
77
80
|
const baseRef = useRef(base);
|
|
78
81
|
useLayoutEffect(() => {
|
|
79
82
|
baseRef.current = base;
|
|
@@ -17,15 +17,16 @@ function useDetachCleanup() {
|
|
|
17
17
|
const host = useRef(null);
|
|
18
18
|
const stash = useRef(/* @__PURE__ */ new Map());
|
|
19
19
|
useLayoutEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const stashed = stash.current;
|
|
21
|
+
for (const [root, children] of stashed) if (root.childElementCount === 0) root.append(...children);
|
|
22
|
+
stashed.clear();
|
|
22
23
|
const el = host.current;
|
|
23
24
|
return () => {
|
|
24
25
|
if (!el) return;
|
|
25
26
|
for (const c of el.querySelectorAll("diffs-container")) {
|
|
26
27
|
const root = c.shadowRoot;
|
|
27
28
|
if (!root) continue;
|
|
28
|
-
|
|
29
|
+
stashed.set(root, Array.from(root.childNodes));
|
|
29
30
|
root.replaceChildren();
|
|
30
31
|
}
|
|
31
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCodeHighlight } from "./CodeHighlightProvider.js";
|
|
2
|
-
import { useEffect, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
// src/code/use-highlighted-html.ts
|
|
4
4
|
/**
|
|
5
5
|
* A block's highlighted HTML, shared by `HighlightedCode` and the views that
|
|
@@ -25,17 +25,17 @@ function useHighlightedHtml(code, language, enabled) {
|
|
|
25
25
|
const { highlighter, theme } = useCodeHighlight();
|
|
26
26
|
const hydrated = useHydrated();
|
|
27
27
|
const [painted, setPainted] = useState(null);
|
|
28
|
-
const
|
|
28
|
+
const firstRun = useRef(true);
|
|
29
|
+
const cached = enabled && hydrated ? highlighter.cached(code, language, theme) : void 0;
|
|
30
|
+
if (cached !== void 0 && !(painted?.code === code && painted.language === language && painted.html === cached)) setPainted({
|
|
31
|
+
code,
|
|
32
|
+
language,
|
|
33
|
+
html: cached
|
|
34
|
+
});
|
|
29
35
|
useEffect(() => {
|
|
30
36
|
if (!enabled) return;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
firstRunRef.done = true;
|
|
34
|
-
setPainted({
|
|
35
|
-
code,
|
|
36
|
-
language,
|
|
37
|
-
html: cached
|
|
38
|
-
});
|
|
37
|
+
if (highlighter.cached(code, language, theme) !== void 0) {
|
|
38
|
+
firstRun.current = false;
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
let cancelled = false;
|
|
@@ -48,8 +48,8 @@ function useHighlightedHtml(code, language, enabled) {
|
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
|
-
if (
|
|
52
|
-
|
|
51
|
+
if (firstRun.current) {
|
|
52
|
+
firstRun.current = false;
|
|
53
53
|
run();
|
|
54
54
|
return () => {
|
|
55
55
|
cancelled = true;
|
|
@@ -65,7 +65,6 @@ function useHighlightedHtml(code, language, enabled) {
|
|
|
65
65
|
language,
|
|
66
66
|
theme,
|
|
67
67
|
highlighter,
|
|
68
|
-
firstRunRef,
|
|
69
68
|
enabled
|
|
70
69
|
]);
|
|
71
70
|
if (painted && painted.code === code && painted.language === language) return painted.html;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* along a toolbar), never as the browser's native title. `shortcut` adds the
|
|
12
12
|
* key binding that does the same thing, as keycaps.
|
|
13
13
|
*/
|
|
14
|
-
import { ButtonHTMLAttributes, FocusEvent, MouseEvent, ReactElement, ReactNode } from "react";
|
|
14
|
+
import { ButtonHTMLAttributes, FocusEvent, MouseEvent, PointerEvent, ReactElement, ReactNode } from "react";
|
|
15
15
|
declare const SIZES: {
|
|
16
16
|
readonly xs: "w-5 h-5 text-zg-meta";
|
|
17
17
|
readonly sm: "w-6 h-6 text-zg-ui";
|
|
@@ -58,6 +58,8 @@ export interface IconButtonRenderProps {
|
|
|
58
58
|
'onMouseLeave': (e: MouseEvent<HTMLElement>) => void;
|
|
59
59
|
/** Bring the tooltip in on the first keyboard focus. */
|
|
60
60
|
'onFocus': (e: FocusEvent<HTMLElement>) => void;
|
|
61
|
+
/** Tells the tooltip the button was pressed, so it stays hidden. */
|
|
62
|
+
'onPointerDown': (e: PointerEvent<HTMLElement>) => void;
|
|
61
63
|
/** Set to an empty string while the button is `active`, otherwise absent. */
|
|
62
64
|
'data-active'?: '';
|
|
63
65
|
/** The icon followed by any badges or overlays. */
|
|
@@ -24,7 +24,7 @@ function iconButtonClass({ size = "md", tone = "neutral", overlay = false } = {}
|
|
|
24
24
|
* `active` states lift it to the raised chip. Use `render` to draw another element, such as a
|
|
25
25
|
* link, with the same look. The ref goes to the `button`.
|
|
26
26
|
*/
|
|
27
|
-
const IconButton = forwardRef(({ icon, label, size, active = false, tone, className = "", type = "button", title, children, render, shortcut, onMouseEnter, onMouseLeave, onFocus, ...rest }, ref) => {
|
|
27
|
+
const IconButton = forwardRef(({ icon, label, size, active = false, tone, className = "", type = "button", title, children, render, shortcut, onMouseEnter, onMouseLeave, onFocus, onPointerDown, ...rest }, ref) => {
|
|
28
28
|
const [el, setEl] = useState(null);
|
|
29
29
|
const arm = useTooltipArming();
|
|
30
30
|
const setRef = useCallback((node) => {
|
|
@@ -53,6 +53,10 @@ const IconButton = forwardRef(({ icon, label, size, active = false, tone, classN
|
|
|
53
53
|
arm.handlers.onFocus();
|
|
54
54
|
onFocus?.(e);
|
|
55
55
|
},
|
|
56
|
+
"onPointerDown": (e) => {
|
|
57
|
+
arm.handlers.onPointerDown();
|
|
58
|
+
onPointerDown?.(e);
|
|
59
|
+
},
|
|
56
60
|
"children": /* @__PURE__ */ jsxs(Fragment$1, { children: [typeof icon === "string" ? /* @__PURE__ */ jsx("span", {
|
|
57
61
|
className: icon,
|
|
58
62
|
"aria-hidden": true
|
|
@@ -65,7 +69,8 @@ const IconButton = forwardRef(({ icon, label, size, active = false, tone, classN
|
|
|
65
69
|
label: title ?? label,
|
|
66
70
|
shortcut,
|
|
67
71
|
initial: arm.armed,
|
|
68
|
-
pointerInside: arm.pointerInside
|
|
72
|
+
pointerInside: arm.pointerInside,
|
|
73
|
+
pressed: arm.pressed
|
|
69
74
|
})
|
|
70
75
|
});
|
|
71
76
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [render ? render(look) : /* @__PURE__ */ jsx("button", {
|
|
@@ -10,10 +10,12 @@ export interface IconButtonTipProps {
|
|
|
10
10
|
initial: 'hover' | 'focus';
|
|
11
11
|
/** The pointer is over the button now. */
|
|
12
12
|
pointerInside: () => boolean;
|
|
13
|
+
/** The button was pressed before the tooltip loaded. */
|
|
14
|
+
pressed: () => boolean;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Shows the button's label, with its keycaps, on hover or keyboard focus.
|
|
16
18
|
*
|
|
17
19
|
* @param props - {@link IconButtonTipProps}.
|
|
18
20
|
*/
|
|
19
|
-
export declare function IconButtonTip({ anchor, label, shortcut, initial, pointerInside }: IconButtonTipProps): import("react").JSX.Element;
|
|
21
|
+
export declare function IconButtonTip({ anchor, label, shortcut, initial, pointerInside, pressed }: IconButtonTipProps): import("react").JSX.Element;
|
|
@@ -12,11 +12,12 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
*
|
|
13
13
|
* @param props - {@link IconButtonTipProps}.
|
|
14
14
|
*/
|
|
15
|
-
function IconButtonTip({ anchor, label, shortcut, initial, pointerInside }) {
|
|
15
|
+
function IconButtonTip({ anchor, label, shortcut, initial, pointerInside, pressed }) {
|
|
16
16
|
return /* @__PURE__ */ jsx(AnchoredTooltip, {
|
|
17
17
|
anchor,
|
|
18
18
|
initial,
|
|
19
19
|
pointerInside,
|
|
20
|
+
pressed,
|
|
20
21
|
portal: true,
|
|
21
22
|
label: shortcut ? /* @__PURE__ */ jsxs("span", {
|
|
22
23
|
className: "inline-flex items-center gap-2",
|
|
@@ -2,7 +2,7 @@ import { FloatingSurface } from "./floating/FloatingSurface.js";
|
|
|
2
2
|
import { returnFocus, useDismiss } from "./floating/usePopover.js";
|
|
3
3
|
import { KeyCombo } from "./Keycap.js";
|
|
4
4
|
import { Menu, MenuRow, MenuSeparator, focusMenuRow } from "./Menu.js";
|
|
5
|
-
import { useEffect, useRef, useState } from "react";
|
|
5
|
+
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
// src/components/RowActionsMenu.tsx
|
|
8
8
|
/** How long the pointer rests on a row before the rows it holds open beside it. */
|
|
@@ -64,14 +64,6 @@ function ArmedRowActionsMenu({ open, anchorRef, position, onClose, items, classN
|
|
|
64
64
|
const surfaceRef = useRef(null);
|
|
65
65
|
const subSurfaceRef = useRef(null);
|
|
66
66
|
const returnTo = useRef(null);
|
|
67
|
-
const placement = useRef({
|
|
68
|
-
anchorRef,
|
|
69
|
-
position
|
|
70
|
-
});
|
|
71
|
-
placement.current = {
|
|
72
|
-
anchorRef,
|
|
73
|
-
position
|
|
74
|
-
};
|
|
75
67
|
const [sub, setSub] = useState(null);
|
|
76
68
|
if (!open && sub?.open) setSub({
|
|
77
69
|
...sub,
|
|
@@ -79,13 +71,14 @@ function ArmedRowActionsMenu({ open, anchorRef, position, onClose, items, classN
|
|
|
79
71
|
});
|
|
80
72
|
const subRows = sub ? items.find((item) => item.id === sub.id)?.items : void 0;
|
|
81
73
|
const hover = useRef({});
|
|
82
|
-
|
|
83
|
-
if (!open) return;
|
|
84
|
-
const { anchorRef: anchor, position: at } = placement.current;
|
|
74
|
+
const opened = useEffectEvent(() => {
|
|
85
75
|
const active = document.activeElement;
|
|
86
76
|
const before = active instanceof HTMLElement && active !== document.body && !active.closest(".zg-float") ? active : null;
|
|
87
|
-
returnTo.current = !
|
|
77
|
+
returnTo.current = !position && anchorRef?.current || before || returnTo.current;
|
|
88
78
|
if (surfaceRef.current) focusMenuRow(surfaceRef.current);
|
|
79
|
+
});
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (open) opened();
|
|
89
82
|
}, [open]);
|
|
90
83
|
useEffect(() => {
|
|
91
84
|
if (sub?.open && sub.focus && subSurfaceRef.current) focusMenuRow(subSurfaceRef.current);
|
|
@@ -188,7 +181,7 @@ function ArmedRowActionsMenu({ open, anchorRef, position, onClose, items, classN
|
|
|
188
181
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(FloatingSurface, {
|
|
189
182
|
ref: surfaceRef,
|
|
190
183
|
open,
|
|
191
|
-
anchor: position ? { point: position } : {
|
|
184
|
+
anchor: position ? { point: position } : anchorRef ? { ref: anchorRef } : { element: null },
|
|
192
185
|
side: "bottom",
|
|
193
186
|
align: position ? "start" : "end",
|
|
194
187
|
offset: position ? 0 : 4,
|
|
@@ -67,6 +67,7 @@ export interface UseTooltip {
|
|
|
67
67
|
onMouseEnter: () => void;
|
|
68
68
|
onMouseLeave: () => void;
|
|
69
69
|
onFocus: () => void;
|
|
70
|
+
onPointerDown: () => void;
|
|
70
71
|
};
|
|
71
72
|
/** Render it next to the element (the bubble portals out; nothing shows in place). */
|
|
72
73
|
tip: ReactNode;
|
|
@@ -92,6 +93,8 @@ export interface AnchoredTooltipProps extends Omit<TooltipProps, 'children' | 'c
|
|
|
92
93
|
initial?: 'hover' | 'focus';
|
|
93
94
|
/** The pointer is over the anchor now, for `initial` hover. Default: the anchor matches `:hover`. */
|
|
94
95
|
pointerInside?: () => boolean;
|
|
96
|
+
/** The anchor was pressed before this mounted (a hover and a click in one go): it starts suppressed. */
|
|
97
|
+
pressed?: () => boolean;
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
100
|
* The tooltip on an element the caller already draws: it listens on `anchor` (no wrapper, no layout of
|
|
@@ -99,4 +102,4 @@ export interface AnchoredTooltipProps extends Omit<TooltipProps, 'children' | 'c
|
|
|
99
102
|
*
|
|
100
103
|
* @param props - {@link AnchoredTooltipProps}.
|
|
101
104
|
*/
|
|
102
|
-
export declare function AnchoredTooltip({ anchor, label, side, align, portal, maxWidth, disabled, initial, pointerInside: inside }: AnchoredTooltipProps): import("react").JSX.Element | null;
|
|
105
|
+
export declare function AnchoredTooltip({ anchor, label, side, align, portal, maxWidth, disabled, initial, pointerInside: inside, pressed }: AnchoredTooltipProps): import("react").JSX.Element | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readMenuExitMs, usePresence } from "../motion/presence.js";
|
|
2
2
|
import { useMotionLevel } from "../motion/reduced.js";
|
|
3
3
|
import { useTooltipArming } from "./tooltip-arming.js";
|
|
4
|
-
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
4
|
+
import { useEffect, useEffectEvent, useId, useLayoutEffect, useRef, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
7
7
|
// src/components/Tooltip.tsx
|
|
@@ -51,6 +51,7 @@ function Tooltip({ children, className = "", style, ...tip }) {
|
|
|
51
51
|
anchor: host,
|
|
52
52
|
initial: arm.armed,
|
|
53
53
|
pointerInside: arm.pointerInside,
|
|
54
|
+
pressed: arm.pressed,
|
|
54
55
|
...tip
|
|
55
56
|
})]
|
|
56
57
|
});
|
|
@@ -76,6 +77,7 @@ function useTooltip(label, options = {}) {
|
|
|
76
77
|
anchor,
|
|
77
78
|
initial: arm.armed,
|
|
78
79
|
pointerInside: arm.pointerInside,
|
|
80
|
+
pressed: arm.pressed,
|
|
79
81
|
portal: true,
|
|
80
82
|
...options,
|
|
81
83
|
label
|
|
@@ -88,7 +90,7 @@ function useTooltip(label, options = {}) {
|
|
|
88
90
|
*
|
|
89
91
|
* @param props - {@link AnchoredTooltipProps}.
|
|
90
92
|
*/
|
|
91
|
-
function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", portal = false, maxWidth, disabled = false, initial, pointerInside: inside }) {
|
|
93
|
+
function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", portal = false, maxWidth, disabled = false, initial, pointerInside: inside, pressed }) {
|
|
92
94
|
const y = side === "bottom" ? "top-full mt-1.5" : "bottom-full mb-1.5";
|
|
93
95
|
const x = align === "end" ? "right-0" : "left-1/2 -translate-x-1/2";
|
|
94
96
|
const id = useId();
|
|
@@ -100,11 +102,11 @@ function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", por
|
|
|
100
102
|
const bubbleRef = useRef(null);
|
|
101
103
|
const timer = useRef(void 0);
|
|
102
104
|
const pointerInside = useRef(false);
|
|
103
|
-
const focusedRef = useRef(false);
|
|
104
105
|
const enterRef = useRef(null);
|
|
105
|
-
|
|
106
|
+
const isFocused = useEffectEvent(() => focused);
|
|
106
107
|
const [pos, setPos] = useState(null);
|
|
107
108
|
const open = !disabled && (hovered || focused) && !suppressed && !dismissed;
|
|
109
|
+
if (open && vanished) setVanished(false);
|
|
108
110
|
const presence = usePresence(open, {
|
|
109
111
|
enter: portal,
|
|
110
112
|
exitMs: readMenuExitMs
|
|
@@ -116,7 +118,6 @@ function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", por
|
|
|
116
118
|
openCount += 1;
|
|
117
119
|
fadingOut?.();
|
|
118
120
|
fadingOut = null;
|
|
119
|
-
setVanished(false);
|
|
120
121
|
return () => {
|
|
121
122
|
openCount -= 1;
|
|
122
123
|
lastClosedAt = performance.now();
|
|
@@ -139,7 +140,7 @@ function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", por
|
|
|
139
140
|
pointerInside.current = false;
|
|
140
141
|
clearTimeout(timer.current);
|
|
141
142
|
setHovered(false);
|
|
142
|
-
if (!
|
|
143
|
+
if (!isFocused()) reset();
|
|
143
144
|
};
|
|
144
145
|
const press = () => setSuppressed(true);
|
|
145
146
|
const key = (e) => {
|
|
@@ -170,6 +171,7 @@ function AnchoredTooltip({ anchor, label, side = "bottom", align = "center", por
|
|
|
170
171
|
};
|
|
171
172
|
}, [anchor]);
|
|
172
173
|
useEffect(() => {
|
|
174
|
+
if (pressed?.()) setSuppressed(true);
|
|
173
175
|
if (initial === "hover" && (inside ? inside() : hovering(anchor))) enterRef.current?.();
|
|
174
176
|
const active = document.activeElement;
|
|
175
177
|
if (initial === "focus" && active && anchor.contains(active) && isFocusVisible(active)) setFocused(true);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Ref } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Hands `node` to a ref of either kind: calls a callback ref, sets an object ref's `current`.
|
|
4
|
+
*
|
|
5
|
+
* @param ref - The ref, or `undefined` for none.
|
|
6
|
+
* @param node - What it refers to now.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assignRef<T>(ref: Ref<T> | undefined, node: T | null): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/components/assign-ref.ts
|
|
2
|
+
/**
|
|
3
|
+
* Hands `node` to a ref of either kind: calls a callback ref, sets an object ref's `current`.
|
|
4
|
+
*
|
|
5
|
+
* @param ref - The ref, or `undefined` for none.
|
|
6
|
+
* @param node - What it refers to now.
|
|
7
|
+
*/
|
|
8
|
+
function assignRef(ref, node) {
|
|
9
|
+
if (typeof ref === "function") ref(node);
|
|
10
|
+
else if (ref) ref.current = node;
|
|
11
|
+
}
|
|
12
|
+
export { assignRef };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { menuTransition, useMotionPrefs } from "../../motion/springs.js";
|
|
2
|
+
import { assignRef } from "../assign-ref.js";
|
|
2
3
|
import { anchorNudge, useAnchoredPosition } from "./useAnchoredPosition.js";
|
|
3
4
|
import { forwardRef, useCallback, useRef, useSyncExternalStore } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -46,8 +47,7 @@ function Surface({ anchor, side = "bottom", align = "start", offset, width, clas
|
|
|
46
47
|
} : { opacity: 0 };
|
|
47
48
|
const setRef = useCallback((node) => {
|
|
48
49
|
localRef.current = node;
|
|
49
|
-
|
|
50
|
-
else if (forwardedRef) forwardedRef.current = node;
|
|
50
|
+
assignRef(forwardedRef, node);
|
|
51
51
|
}, [forwardedRef]);
|
|
52
52
|
const placed = placement !== null;
|
|
53
53
|
return /* @__PURE__ */ jsx(m.div, {
|
|
@@ -13,14 +13,13 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
*/
|
|
14
14
|
function HoverCard({ trigger, children, side = "right", align = "start", width, ariaLabel, testId, anchorTo }) {
|
|
15
15
|
const [open, setOpen] = useState(false);
|
|
16
|
-
const anchor = useRef(null);
|
|
17
|
-
const surface = useRef(null);
|
|
18
16
|
const timer = useRef(void 0);
|
|
19
17
|
const schedule = useCallback((next) => {
|
|
20
18
|
window.clearTimeout(timer.current);
|
|
21
19
|
timer.current = window.setTimeout(setOpen, next ? 250 : 150, next);
|
|
22
20
|
}, []);
|
|
23
21
|
const stay = useCallback(() => window.clearTimeout(timer.current), []);
|
|
22
|
+
const { triggerProps, anchor, placedAt, surface } = useHoverTrigger(anchorTo, schedule);
|
|
24
23
|
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
25
24
|
useEffect(() => {
|
|
26
25
|
if (!open) return void 0;
|
|
@@ -34,20 +33,10 @@ function HoverCard({ trigger, children, side = "right", align = "start", width,
|
|
|
34
33
|
window.addEventListener("keydown", onKey, true);
|
|
35
34
|
return () => window.removeEventListener("keydown", onKey, true);
|
|
36
35
|
}, [open]);
|
|
37
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [trigger({
|
|
38
|
-
ref: (node) => {
|
|
39
|
-
anchor.current = node;
|
|
40
|
-
},
|
|
41
|
-
onPointerEnter: () => schedule(true),
|
|
42
|
-
onPointerLeave: () => schedule(false),
|
|
43
|
-
onFocus: () => schedule(true),
|
|
44
|
-
onBlur: (e) => {
|
|
45
|
-
if (!surface.current?.contains(e.relatedTarget)) schedule(false);
|
|
46
|
-
}
|
|
47
|
-
}, open), /* @__PURE__ */ jsx(FloatingSurface, {
|
|
36
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [trigger(triggerProps, open), /* @__PURE__ */ jsx(FloatingSurface, {
|
|
48
37
|
ref: surface,
|
|
49
38
|
open,
|
|
50
|
-
anchor: {
|
|
39
|
+
anchor: { ref: placedAt },
|
|
51
40
|
side,
|
|
52
41
|
align,
|
|
53
42
|
width,
|
|
@@ -64,4 +53,33 @@ function HoverCard({ trigger, children, side = "right", align = "start", width,
|
|
|
64
53
|
children
|
|
65
54
|
})] });
|
|
66
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The trigger's props, and the refs the card is placed and kept open by: the trigger, what it is placed against
|
|
58
|
+
* (the trigger, or the element `anchorTo` names for it) and the card.
|
|
59
|
+
*
|
|
60
|
+
* @param anchorTo - The element to place against instead of the trigger.
|
|
61
|
+
* @param schedule - Opens (`true`) or closes the card after its delay.
|
|
62
|
+
*/
|
|
63
|
+
function useHoverTrigger(anchorTo, schedule) {
|
|
64
|
+
const anchor = useRef(null);
|
|
65
|
+
const placedAt = useRef(null);
|
|
66
|
+
const surface = useRef(null);
|
|
67
|
+
return {
|
|
68
|
+
triggerProps: {
|
|
69
|
+
ref: (node) => {
|
|
70
|
+
anchor.current = node;
|
|
71
|
+
placedAt.current = node && anchorTo ? anchorTo(node) ?? node : node;
|
|
72
|
+
},
|
|
73
|
+
onPointerEnter: () => schedule(true),
|
|
74
|
+
onPointerLeave: () => schedule(false),
|
|
75
|
+
onFocus: () => schedule(true),
|
|
76
|
+
onBlur: (e) => {
|
|
77
|
+
if (!surface.current?.contains(e.relatedTarget)) schedule(false);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
anchor,
|
|
81
|
+
placedAt,
|
|
82
|
+
surface
|
|
83
|
+
};
|
|
84
|
+
}
|
|
67
85
|
export { HoverCard };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignRef } from "../assign-ref.js";
|
|
1
2
|
import { focusMenuRow, handleMenuKeyDown } from "../Menu.js";
|
|
2
3
|
import { FloatingSurface } from "./FloatingSurface.js";
|
|
3
4
|
import { usePopover } from "./usePopover.js";
|
|
@@ -15,12 +16,8 @@ function Popover({ trigger, children, side = "top", align = "start", width, role
|
|
|
15
16
|
const popover = usePopover({ onDismiss });
|
|
16
17
|
const { open, triggerRef, surfaceRef } = popover;
|
|
17
18
|
const surfaceId = useId();
|
|
18
|
-
const setTriggerRef = useCallback((node) =>
|
|
19
|
-
|
|
20
|
-
}, [triggerRef]);
|
|
21
|
-
const setSurfaceRef = useCallback((node) => {
|
|
22
|
-
surfaceRef.current = node;
|
|
23
|
-
}, [surfaceRef]);
|
|
19
|
+
const setTriggerRef = useCallback((node) => assignRef(triggerRef, node), [triggerRef]);
|
|
20
|
+
const setSurfaceRef = useCallback((node) => assignRef(surfaceRef, node), [surfaceRef]);
|
|
24
21
|
useEffect(() => {
|
|
25
22
|
const surface = surfaceRef.current;
|
|
26
23
|
if (!open || !surface || surface.contains(document.activeElement)) return;
|
|
@@ -53,7 +50,7 @@ function Popover({ trigger, children, side = "top", align = "start", width, role
|
|
|
53
50
|
ref: setSurfaceRef,
|
|
54
51
|
id: surfaceId,
|
|
55
52
|
open,
|
|
56
|
-
anchor: {
|
|
53
|
+
anchor: { ref: triggerRef },
|
|
57
54
|
side,
|
|
58
55
|
align,
|
|
59
56
|
width,
|
|
@@ -3,11 +3,13 @@ export type Side = 'top' | 'bottom' | 'right' | 'left';
|
|
|
3
3
|
/** How a surface lines up along the anchor's edge: with its start, its centre or its end. */
|
|
4
4
|
export type Align = 'start' | 'center' | 'end';
|
|
5
5
|
/**
|
|
6
|
-
* What a surface is placed against: an element,
|
|
7
|
-
* An element of `null` yields no placement.
|
|
6
|
+
* What a surface is placed against: an element, the element a ref holds (read when the surface is measured, so no
|
|
7
|
+
* render reads it), or a viewport point such as a right-click. An element of `null` yields no placement.
|
|
8
8
|
*/
|
|
9
9
|
export type Anchor = {
|
|
10
10
|
element: HTMLElement | null;
|
|
11
|
+
} | {
|
|
12
|
+
ref: React.RefObject<HTMLElement | null>;
|
|
11
13
|
} | {
|
|
12
14
|
point: {
|
|
13
15
|
x: number;
|
|
@@ -78,7 +80,7 @@ export declare function placeSurface(a: Rect, size: {
|
|
|
78
80
|
* resize, on scroll outside the surface and when the surface's own size changes.
|
|
79
81
|
*
|
|
80
82
|
* @param open - Whether the surface is shown. No placement is computed while it is closed.
|
|
81
|
-
* @param anchor - The element or point to place against.
|
|
83
|
+
* @param anchor - The element, ref or point to place against.
|
|
82
84
|
* @param surfaceRef - Ref to the surface element, measured for its size.
|
|
83
85
|
* @param options - The preferred `side` (default `bottom`), `align` (default `start`) and `offset`
|
|
84
86
|
* in px (default 6).
|
|
@@ -46,7 +46,7 @@ function anchorRect(anchor) {
|
|
|
46
46
|
height: 0
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
return anchor.element?.getBoundingClientRect() ?? null;
|
|
49
|
+
return ("ref" in anchor ? anchor.ref.current : anchor.element)?.getBoundingClientRect() ?? null;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Computes where a surface goes next to an anchor. It tries `side`, flips to the opposite side
|
|
@@ -96,7 +96,7 @@ function placeSurface(a, size, side, align, offset, viewport = {
|
|
|
96
96
|
* resize, on scroll outside the surface and when the surface's own size changes.
|
|
97
97
|
*
|
|
98
98
|
* @param open - Whether the surface is shown. No placement is computed while it is closed.
|
|
99
|
-
* @param anchor - The element or point to place against.
|
|
99
|
+
* @param anchor - The element, ref or point to place against.
|
|
100
100
|
* @param surfaceRef - Ref to the surface element, measured for its size.
|
|
101
101
|
* @param options - The preferred `side` (default `bottom`), `align` (default `start`) and `offset`
|
|
102
102
|
* in px (default 6).
|
|
@@ -104,19 +104,18 @@ function placeSurface(a, size, side, align, offset, viewport = {
|
|
|
104
104
|
*/
|
|
105
105
|
function useAnchoredPosition(open, anchor, surfaceRef, { side = "bottom", align = "start", offset = 6 } = {}) {
|
|
106
106
|
const [placement, setPlacement] = useState(null);
|
|
107
|
+
if (!open && placement !== null) setPlacement(null);
|
|
107
108
|
const element = "element" in anchor ? anchor.element : null;
|
|
109
|
+
const ref = "ref" in anchor ? anchor.ref : null;
|
|
108
110
|
const px = "point" in anchor ? anchor.point.x : null;
|
|
109
111
|
const py = "point" in anchor ? anchor.point.y : null;
|
|
110
112
|
useLayoutEffect(() => {
|
|
111
|
-
if (!open)
|
|
112
|
-
setPlacement(null);
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
113
|
+
if (!open) return void 0;
|
|
115
114
|
const measure = () => {
|
|
116
115
|
const a = anchorRect(px !== null && py !== null ? { point: {
|
|
117
116
|
x: px,
|
|
118
117
|
y: py
|
|
119
|
-
} } : { element });
|
|
118
|
+
} } : ref ? { ref } : { element });
|
|
120
119
|
const surface = surfaceRef.current;
|
|
121
120
|
if (!a || !surface) return;
|
|
122
121
|
const next = placeSurface(a, {
|
|
@@ -142,6 +141,7 @@ function useAnchoredPosition(open, anchor, surfaceRef, { side = "bottom", align
|
|
|
142
141
|
}, [
|
|
143
142
|
open,
|
|
144
143
|
element,
|
|
144
|
+
ref,
|
|
145
145
|
px,
|
|
146
146
|
py,
|
|
147
147
|
surfaceRef,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/components/object-key.ts
|
|
2
|
+
const keys = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
let next = 0;
|
|
4
|
+
/**
|
|
5
|
+
* A number per object identity: the same object always gives the same number, another object a new one.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The object.
|
|
8
|
+
* @returns Its number.
|
|
9
|
+
*/
|
|
10
|
+
function objectKey(value) {
|
|
11
|
+
let key = keys.get(value);
|
|
12
|
+
if (key === void 0) {
|
|
13
|
+
key = ++next;
|
|
14
|
+
keys.set(value, key);
|
|
15
|
+
}
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
export { objectKey };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { KeyCombo } from "../Keycap.js";
|
|
2
2
|
import { MenuRow } from "../Menu.js";
|
|
3
|
+
import { objectKey } from "../object-key.js";
|
|
3
4
|
import { layoutPalette, placeOfRow, useMaxHeight } from "./palette-layout.js";
|
|
4
5
|
import { Fragment, memo, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -75,11 +76,6 @@ function PaletteList({ groups, cursor, query, nested, onHover, onRun, renderRow,
|
|
|
75
76
|
sections,
|
|
76
77
|
viewHeight
|
|
77
78
|
]);
|
|
78
|
-
const shownSections = useRef(sections);
|
|
79
|
-
const snap = shownSections.current !== sections;
|
|
80
|
-
useLayoutEffect(() => {
|
|
81
|
-
shownSections.current = sections;
|
|
82
|
-
}, [sections]);
|
|
83
79
|
const marked = placeOfRow(sections, cursor);
|
|
84
80
|
const from = scrollTop - 320;
|
|
85
81
|
const to = scrollTop + viewHeight + 320;
|
|
@@ -106,14 +102,13 @@ function PaletteList({ groups, cursor, query, nested, onHover, onRun, renderRow,
|
|
|
106
102
|
children: [marked && /* @__PURE__ */ jsx("div", {
|
|
107
103
|
"aria-hidden": true,
|
|
108
104
|
className: "zg-palette-cursor",
|
|
109
|
-
"data-snap": snap ? "" : void 0,
|
|
110
105
|
style: {
|
|
111
106
|
height: 34,
|
|
112
107
|
left: 6,
|
|
113
108
|
right: 6,
|
|
114
109
|
transform: `translateY(${marked.top}px)`
|
|
115
110
|
}
|
|
116
|
-
}), sections.map((s) => {
|
|
111
|
+
}, objectKey(sections)), sections.map((s) => {
|
|
117
112
|
const rowsTop = s.top + 30;
|
|
118
113
|
const lo = Math.max(0, Math.floor((from - rowsTop) / 34));
|
|
119
114
|
const hi = Math.min(s.rows.length - 1, Math.floor((to - rowsTop) / 34));
|
|
@@ -4,11 +4,14 @@ export interface TooltipArming {
|
|
|
4
4
|
armed: 'hover' | 'focus' | null;
|
|
5
5
|
/** The pointer is over the anchor now. */
|
|
6
6
|
pointerInside: () => boolean;
|
|
7
|
+
/** The anchor was pressed since the pointer came in: a press the tooltip, mounting after it, never heard. */
|
|
8
|
+
pressed: () => boolean;
|
|
7
9
|
/** Spread on the anchor (call them from your own handlers if you set the same ones). */
|
|
8
10
|
handlers: {
|
|
9
11
|
onMouseEnter: () => void;
|
|
10
12
|
onMouseLeave: () => void;
|
|
11
13
|
onFocus: () => void;
|
|
14
|
+
onPointerDown: () => void;
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
/**
|