@kabmo-labs/kabmo 0.28.0 → 0.29.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/bunfig.toml +6 -0
- package/dist/client/index.html +2 -2
- package/dist/client/index.js +481 -472
- package/dist/client/static/js/{index-xzvyrxya.js → index-43z47ngg.js} +1193 -1049
- package/dist/client/static/js/index-naa91727.css +1 -0
- package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
- package/package.json +3 -2
- package/public/manifest.webmanifest +1 -0
- package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
- package/src/client/components/common/ComposerTextarea.tsx +6 -0
- package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
- package/src/client/components/common/ReloadPageButton.tsx +11 -2
- package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
- package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
- package/src/client/components/common/file-icon/index.tsx +7 -1
- package/src/client/components/common/harness-glyph/brands.ts +7 -1
- package/src/client/components/common/image-viewer/index.tsx +37 -165
- package/src/client/components/common/picker-search/index.tsx +70 -0
- package/src/client/components/common/search-select/index.tsx +2 -7
- package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
- package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
- package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
- package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
- package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +6 -4
- package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +25 -0
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
- package/src/client/components/settings/Sidebar.tsx +6 -8
- package/src/client/components/settings/categories/HarnessSettings.tsx +4 -2
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +2 -2
- package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
- package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
- package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
- package/src/client/components/settings/groups.test.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
- package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +8 -3
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +42 -15
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +28 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +28 -10
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
- package/src/client/components/workspace/editor/FilePane.tsx +32 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +4 -0
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +1 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +5 -2
- package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
- package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
- package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
- package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
- package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
- package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
- package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
- package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
- package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
- package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
- package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
- package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
- package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
- package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
- package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
- package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
- package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
- package/src/client/components/workspace/file-explorer/index.tsx +53 -29
- package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
- package/src/client/data/settings/omp-schema.json +169 -22
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +37 -0
- package/src/client/hooks/chat/composer/history.test.ts +267 -0
- package/src/client/hooks/chat/composer/history.ts +146 -0
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
- package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
- package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
- package/src/client/hooks/editor/file-editor-types.ts +15 -0
- package/src/client/hooks/editor/save-bytes.ts +79 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +30 -0
- package/src/client/hooks/editor/use-file-editor.ts +53 -5
- package/src/client/hooks/editor/use-file-read.ts +21 -2
- package/src/client/hooks/editor/use-grid-selection.ts +160 -0
- package/src/client/hooks/models/use-harness-update.test.ts +35 -2
- package/src/client/hooks/models/use-harness-update.ts +49 -10
- package/src/client/hooks/workspace/diff-file.test.ts +72 -0
- package/src/client/hooks/workspace/diff-file.ts +12 -6
- package/src/client/hooks/workspace/file-archive.ts +220 -0
- package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
- package/src/client/hooks/workspace/file-clipboard.ts +37 -26
- package/src/client/hooks/workspace/file-selection.test.ts +67 -0
- package/src/client/hooks/workspace/file-selection.ts +156 -0
- package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
- package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
- package/src/client/lib/editor/workbook-drafts.ts +42 -0
- package/src/client/lib/launch/file-handlers.ts +2 -2
- package/src/client/lib/scrollbar-activity.test.ts +21 -88
- package/src/client/lib/scrollbar-activity.ts +71 -73
- package/src/client/lib/scrollbar-events.ts +143 -0
- package/src/client/lib/scrollbar-input.test.ts +126 -0
- package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
- package/src/client/tailwind.css +32 -1
- package/src/server/db.server.test.ts +50 -1
- package/src/server/db.server.ts +36 -3
- package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
- package/src/server/lib/chat/prompt-history.server.ts +65 -0
- package/src/server/lib/chat/schema.server.ts +35 -0
- package/src/server/lib/db/schema.ts +3 -0
- package/src/server/lib/fs/archive.test.ts +139 -0
- package/src/server/lib/fs/archive.ts +259 -0
- package/src/server/lib/fs/git-diff.test.ts +26 -1
- package/src/server/lib/fs/git-diff.ts +43 -15
- package/src/server/lib/harness/launch-table.ts +19 -0
- package/src/server/lib/harness/provider-entry.ts +1 -1
- package/src/server/lib/harness/provider-file.server.ts +1 -1
- package/src/server/lib/harness/provider-sources.server.ts +2 -1
- package/src/server/lib/harness/provider-write.server.ts +2 -1
- package/src/server/lib/harness/update-job-store.ts +12 -0
- package/src/server/lib/harness/update-queue.server.ts +15 -10
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +5 -1
- package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
- package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
- package/src/server/lib/omp/session/delete.server.ts +1 -0
- package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
- package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
- package/src/server/lib/panels/auto-update.server.test.ts +5 -2
- package/src/server/lib/panels/git-update.server.test.ts +5 -2
- package/src/server/lib/panels/install.server.test.ts +5 -2
- package/src/server/lib/panels/remove.server.test.ts +5 -2
- package/src/server/routes/agent/command.ts +11 -0
- package/src/server/routes/agent/new.ts +5 -0
- package/src/server/routes/chat/index.ts +5 -0
- package/src/server/routes/chat/prompt-history.test.ts +67 -0
- package/src/server/routes/chat/prompt-history.ts +31 -0
- package/src/server/routes/chat/stream.test.ts +21 -0
- package/src/server/routes/chat/stream.ts +5 -0
- package/src/server/routes/fs/action-archive.test.ts +128 -0
- package/src/server/routes/fs/action-bulk.ts +106 -0
- package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
- package/src/server/routes/fs/action-transfer.test.ts +26 -0
- package/src/server/routes/fs/action.ts +91 -11
- package/src/server/routes/fs/archive.ts +20 -0
- package/src/server/routes/fs/grant.test.ts +5 -2
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.test.ts +6 -2
- package/src/server/routes/harness/import-action.ts +1 -1
- package/src/server/routes/harness/root.ts +6 -1
- package/src/server/routes/harness/summary.test.ts +50 -0
- package/src/server/routes/harness/update-status.ts +41 -2
- package/src/server/routes/harness/update.test.ts +56 -2
- package/src/server/routes/sessions/delete.test.ts +4 -0
- package/src/shared/lib/chat/ask-form/index.ts +39 -31
- package/src/shared/lib/chat/ask-form/labels.ts +46 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
- package/src/shared/lib/chat/ask-form.test.ts +57 -0
- package/src/shared/lib/chat/ask-questions.ts +31 -0
- package/src/shared/lib/chat/composer/history.test.ts +67 -0
- package/src/shared/lib/chat/composer/history.ts +61 -0
- package/src/shared/lib/chat/irc-notice.ts +42 -0
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +2 -0
- package/src/shared/lib/chat/todo/parser.ts +6 -4
- package/src/shared/lib/fs/archive.test.ts +101 -0
- package/src/shared/lib/fs/archive.ts +191 -0
- package/src/shared/lib/fs/clipboard.test.ts +32 -7
- package/src/shared/lib/fs/clipboard.ts +59 -14
- package/src/shared/lib/fs/csv.test.ts +50 -0
- package/src/shared/lib/fs/csv.ts +40 -0
- package/src/shared/lib/fs/document-kind.test.ts +13 -6
- package/src/shared/lib/fs/document-kind.ts +18 -6
- package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
- package/src/shared/lib/fs/file-kind.test.ts +2 -7
- package/src/shared/lib/fs/file-kind.ts +4 -2
- package/src/shared/lib/fs/grid-edit.test.ts +24 -0
- package/src/shared/lib/fs/grid-edit.ts +29 -0
- package/src/shared/lib/fs/grid-selection.test.ts +137 -0
- package/src/shared/lib/fs/grid-selection.ts +138 -0
- package/src/shared/lib/harness/brand-color.ts +5 -0
- package/src/shared/lib/harness/catalog.test.ts +22 -0
- package/src/shared/lib/harness/catalog.ts +12 -1
- package/src/shared/lib/harness/config-fields.test.ts +25 -0
- package/src/shared/lib/harness/config-fields.ts +33 -3
- package/src/shared/lib/harness/dialects.ts +1 -1
- package/src/shared/lib/harness/mcp-facts.ts +4 -0
- package/src/shared/lib/harness/provider-contracts.ts +109 -0
- package/src/shared/lib/harness/provider-facts.test.ts +2 -1
- package/src/shared/lib/harness/provider-facts.ts +24 -115
- package/src/shared/lib/harness/provider-lookup.ts +37 -0
- package/src/shared/lib/harness/providers.ts +2 -1
- package/src/shared/lib/harness/updates.ts +10 -0
- package/src/shared/lib/omp/session/mapper.test.ts +31 -0
- package/src/shared/lib/omp/session/mapper.ts +17 -0
- package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
- package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
- package/src/shared/lib/omp/session/messages-map.ts +17 -0
- package/src/shared/lib/omp/session/wait.ts +10 -1
- package/src/shared/lib/settings/sections.ts +8 -4
- package/src/shared/lib/ui/picker-filter.test.ts +23 -0
- package/src/shared/lib/ui/picker-filter.ts +20 -0
- package/src/shared/types/chat.ts +4 -0
- package/src/shared/types/harness.ts +5 -1
- package/src/shared/types/omp/session.ts +18 -0
- package/src/shared/types/settings/state.ts +6 -6
- package/src/shared/types/todo.ts +3 -1
- package/src/test-support/file-actions.test-util.ts +4 -0
- package/src/test-support/file-archive.test-util.ts +41 -0
- package/src/test-support/file-clipboard.test-util.ts +9 -6
- package/src/test-support/harness-table.test-util.ts +2 -0
- package/src/test-support/preload.ts +46 -0
- package/dist/client/static/js/index-81f7berm.css +0 -1
|
@@ -68,6 +68,20 @@ describe('ReloadPageButton', () => {
|
|
|
68
68
|
expect(reloads).toBe(1);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
+
test('spins its glyph for the reload it asked for', () => {
|
|
72
|
+
const el = mount(h(ReloadPageButton, { className: 'p-1.5' }));
|
|
73
|
+
const button = el.querySelector('button');
|
|
74
|
+
const icon = () => button?.querySelector('svg')?.getAttribute('class') ?? '';
|
|
75
|
+
expect(icon()).not.toContain('animate-spin');
|
|
76
|
+
act(() => {
|
|
77
|
+
button?.dispatchEvent(new Event('click', { bubbles: true }));
|
|
78
|
+
});
|
|
79
|
+
// A control that looks identical after the click reads as dead while the
|
|
80
|
+
// browser is still tearing the page down.
|
|
81
|
+
expect(icon()).toContain('animate-spin');
|
|
82
|
+
expect(button?.getAttribute('aria-busy')).toBe('true');
|
|
83
|
+
});
|
|
84
|
+
|
|
71
85
|
test('sizes its icon per surface while keeping the caller class', () => {
|
|
72
86
|
const el = mount(h(ReloadPageButton, { size: 18, className: 'w-8 h-8' }));
|
|
73
87
|
const button = el.querySelector('button');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useState } from 'preact/hooks';
|
|
1
2
|
import { RefreshCw } from 'lucide-preact';
|
|
2
3
|
|
|
3
4
|
interface ReloadPageButtonProps {
|
|
@@ -16,15 +17,23 @@ interface ReloadPageButtonProps {
|
|
|
16
17
|
* "Refresh" while the other says "Reload".
|
|
17
18
|
*/
|
|
18
19
|
export function ReloadPageButton({ size = 16, className }: ReloadPageButtonProps) {
|
|
20
|
+
// The navigation tears this tree down, but the request itself can take a
|
|
21
|
+
// visible moment; the glyph spins for it rather than looking like a dead
|
|
22
|
+
// control. Nothing else reads the flag, so it is never cleared.
|
|
23
|
+
const [reloading, setReloading] = useState(false);
|
|
19
24
|
return (
|
|
20
25
|
<button
|
|
21
26
|
type="button"
|
|
22
|
-
onClick={() =>
|
|
27
|
+
onClick={() => {
|
|
28
|
+
setReloading(true);
|
|
29
|
+
window.location.reload();
|
|
30
|
+
}}
|
|
23
31
|
className={className}
|
|
24
32
|
title="Reload page"
|
|
25
33
|
aria-label="Reload page"
|
|
34
|
+
aria-busy={reloading}
|
|
26
35
|
>
|
|
27
|
-
<RefreshCw size={size} />
|
|
36
|
+
<RefreshCw size={size} className={reloading ? 'animate-spin' : undefined} />
|
|
28
37
|
</button>
|
|
29
38
|
);
|
|
30
39
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The natural size the diagram viewer renders at.
|
|
8
|
+
*
|
|
9
|
+
* The regression this pins was reported as "zooming the preview looks
|
|
10
|
+
* pixelated": mermaid keeps `useMaxWidth` on for every diagram type except
|
|
11
|
+
* flowchart and sequence, and that branch emits `width="100%"` with the real
|
|
12
|
+
* size only in the `viewBox`. `Number.parseFloat('100%')` reads 100, so the
|
|
13
|
+
* snapshot claimed a 100 px-wide diagram — the viewer drew it at 100 px and
|
|
14
|
+
* magnified that rendering. The test therefore asserts the measured number, not
|
|
15
|
+
* that a viewer opened.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
19
|
+
import { Window } from 'happy-dom';
|
|
20
|
+
import { readDiagramBlock } from '@/client/components/common/diagram-viewer/read-block';
|
|
21
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
22
|
+
|
|
23
|
+
/** A `.mermaid-block` holding one SVG with `attrs`, in a fresh window. */
|
|
24
|
+
function mount(attrs: Record<string, string>): HTMLElement {
|
|
25
|
+
const win = new Window();
|
|
26
|
+
installDomGlobals(win);
|
|
27
|
+
const block = win.document.createElement('div') as unknown as HTMLElement;
|
|
28
|
+
block.className = 'mermaid-block';
|
|
29
|
+
const svg = win.document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
30
|
+
for (const [name, value] of Object.entries(attrs)) svg.setAttribute(name, value);
|
|
31
|
+
block.appendChild(svg as never);
|
|
32
|
+
win.document.body.appendChild(block as never);
|
|
33
|
+
return block;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('readDiagramBlock', () => {
|
|
37
|
+
afterEach(() => restoreDomGlobals());
|
|
38
|
+
|
|
39
|
+
test('a percentage width measures the viewBox, not 100 px', () => {
|
|
40
|
+
// Mermaid's `useMaxWidth: true` markup: no height, natural size in viewBox.
|
|
41
|
+
const block = mount({
|
|
42
|
+
width: '100%',
|
|
43
|
+
style: 'max-width: 166.984375px;',
|
|
44
|
+
viewBox: '0 0 166.984375 294',
|
|
45
|
+
});
|
|
46
|
+
expect(readDiagramBlock(block)).toMatchObject({ width: 166.984375, height: 294 });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a px width/height pair is used verbatim', () => {
|
|
50
|
+
// Mermaid's `useMaxWidth: false` markup (flowchart, sequence).
|
|
51
|
+
const block = mount({ width: '3804', height: '64', viewBox: '0 0 3804 64' });
|
|
52
|
+
expect(readDiagramBlock(block)).toMatchObject({ width: 3804, height: 64 });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('a non-zero viewBox origin is not mistaken for a size', () => {
|
|
56
|
+
// Mindmap/timeline start their viewBox at a negative origin.
|
|
57
|
+
const block = mount({ width: '100%', viewBox: '-5 -61 895 476.6' });
|
|
58
|
+
expect(readDiagramBlock(block)).toMatchObject({ width: 895, height: 476.6 });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a percentage width with no viewBox never divides by zero', () => {
|
|
62
|
+
const block = mount({ width: '100%' });
|
|
63
|
+
expect(readDiagramBlock(block)).toMatchObject({ width: 1, height: 1 });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('a block with no direct SVG child has no snapshot', () => {
|
|
67
|
+
const block = mount({});
|
|
68
|
+
block.querySelector(':scope > svg')?.remove();
|
|
69
|
+
expect(readDiagramBlock(block)).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -29,25 +29,49 @@ export function readDiagramBlock(block: HTMLElement): DiagramSnapshot | null {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Mermaid writes numeric px `width`/`height` attributes
|
|
33
|
-
* `useMaxWidth
|
|
34
|
-
*
|
|
32
|
+
* Mermaid writes numeric px `width`/`height` attributes only for the diagram
|
|
33
|
+
* types whose `useMaxWidth` is off — the app pins it off for flowcharts and
|
|
34
|
+
* sequence diagrams. Every other type (class, state, ER, mindmap, timeline,
|
|
35
|
+
* gantt, pie, …) keeps `useMaxWidth` on and emits `width="100%"`, no `height`,
|
|
36
|
+
* the natural size in `style="max-width: Npx"`, and the `viewBox`.
|
|
37
|
+
*
|
|
38
|
+
* `Number.parseFloat('100%')` is 100, so reading that attribute as a pixel size
|
|
39
|
+
* sized the viewer's canvas to 100 px: the diagram was drawn 100 px wide and
|
|
40
|
+
* the zoom magnified that tiny rendering into a blurry bitmap. A percentage is
|
|
41
|
+
* not a pixel size — only a unitless or `px` number is.
|
|
42
|
+
*/
|
|
43
|
+
function px(value: string | number | null | undefined): number | null {
|
|
44
|
+
if (typeof value === 'number') return Number.isFinite(value) && value > 0 ? value : null;
|
|
45
|
+
if (!value) return null;
|
|
46
|
+
const match = /^\s*(\d+(?:\.\d+)?)(?:px)?\s*$/.exec(value);
|
|
47
|
+
if (!match) return null;
|
|
48
|
+
const parsed = Number.parseFloat(match[1]);
|
|
49
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The `viewBox`'s width/height, which is the natural size for a diagram that
|
|
53
|
+
* declares `width="100%"`. Read from the attribute rather than
|
|
54
|
+
* `svg.viewBox.baseVal` so a detached SVG (and a DOM without the SVG geometry
|
|
55
|
+
* API) still measures. */
|
|
56
|
+
function viewBoxSize(svg: SVGSVGElement): { width: number; height: number } | null {
|
|
57
|
+
const raw = svg.getAttribute('viewBox');
|
|
58
|
+
if (!raw) return null;
|
|
59
|
+
const parts = raw.trim().split(/[\s,]+/).map(Number);
|
|
60
|
+
if (parts.length !== 4 || parts.some((part) => !Number.isFinite(part))) return null;
|
|
61
|
+
return { width: parts[2], height: parts[3] };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The natural size, in order of trust: a real px attribute, the `viewBox`, then
|
|
66
|
+
* the rendered box (a `viewBox`-only diagram is valid SVG too, and a detached
|
|
67
|
+
* SVG reports a 0×0 border box). 1 is the floor, so callers can never divide by
|
|
68
|
+
* a zero-sized diagram.
|
|
35
69
|
*/
|
|
36
70
|
function measure(svg: SVGSVGElement): { width: number; height: number } {
|
|
37
|
-
const box = svg
|
|
71
|
+
const box = viewBoxSize(svg);
|
|
38
72
|
const rendered = svg.getBoundingClientRect();
|
|
39
73
|
return {
|
|
40
|
-
width:
|
|
41
|
-
height:
|
|
74
|
+
width: px(svg.getAttribute('width')) ?? px(box?.width) ?? px(rendered.width) ?? 1,
|
|
75
|
+
height: px(svg.getAttribute('height')) ?? px(box?.height) ?? px(rendered.height) ?? 1,
|
|
42
76
|
};
|
|
43
77
|
}
|
|
44
|
-
|
|
45
|
-
/** First candidate that resolves to a usable positive number; 1 otherwise, so
|
|
46
|
-
* callers can never divide by a zero-sized diagram. */
|
|
47
|
-
function positive(...candidates: (string | number | null | undefined)[]): number {
|
|
48
|
-
for (const candidate of candidates) {
|
|
49
|
-
const value = typeof candidate === 'number' ? candidate : Number.parseFloat(candidate ?? '');
|
|
50
|
-
if (Number.isFinite(value) && value > 0) return value;
|
|
51
|
-
}
|
|
52
|
-
return 1;
|
|
53
|
-
}
|
|
@@ -152,7 +152,13 @@ export function FileIcon({ name, isFolder, isOpen, size = 14, className = '' }:
|
|
|
152
152
|
// which made them the only icons in the app that ignored BOTH modes. Their
|
|
153
153
|
// hue is now a role in `shared/lib/icons/tint.ts`, so the palette decides it
|
|
154
154
|
// and `monochrome` finally reaches them.
|
|
155
|
-
if (
|
|
155
|
+
if (
|
|
156
|
+
lowerName.endsWith('.csv') ||
|
|
157
|
+
lowerName.endsWith('.tsv') ||
|
|
158
|
+
lowerName.endsWith('.xls') ||
|
|
159
|
+
lowerName.endsWith('.xlsx') ||
|
|
160
|
+
lowerName.endsWith('.xlsm')
|
|
161
|
+
) {
|
|
156
162
|
return <FileSpreadsheet size={size} className={className} />;
|
|
157
163
|
}
|
|
158
164
|
if (lowerName.endsWith('.pdf') || lowerName.endsWith('.docx')) {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* `minimax`, `cursor`, `qwen`, `antigravity`, `pi`).
|
|
14
14
|
* 2. The vendor's own logo with its plate and gradient dropped — omp's
|
|
15
15
|
* `favicon.svg`, whose gradient `url(#g)` and dark background rect were
|
|
16
|
-
* removed so the mark paints in `currentColor` like every other one
|
|
16
|
+
* removed so the mark paints in `currentColor` like every other one; the
|
|
17
|
+
* same treatment for jcode (`jcode.sh/favicon.svg`, stroke → ring path).
|
|
17
18
|
*
|
|
18
19
|
* `body` is inner markup only: the caller owns the `<svg>`, so a mark inherits
|
|
19
20
|
* the surrounding ink and never carries a hardcoded colour. That is also why
|
|
@@ -62,4 +63,9 @@ antigravity: { ink: [0, 1, 24, 22.11], body: "<path d=\"M21.751 22.607c1.34 1.00
|
|
|
62
63
|
pi: { ink: [1, 1, 22, 22], body: "<path clip-rule=\"evenodd\" d=\"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z\"></path><path d=\"M17.5 12H23v11h-5.5V12z\"></path>" },
|
|
63
64
|
// Z.ai's own mark (ZCode is that vendor's agent), monochrome variant.
|
|
64
65
|
zcode: { ink: [0, 2, 24, 20], body: "<path d=\"M12.105 2L9.927 4.953H.653L2.83 2h9.276zM23.254 19.048L21.078 22h-9.242l2.174-2.952h9.244zM24 2L9.264 22H0L14.736 2H24z\"></path>" },
|
|
66
|
+
// jcode.sh's mark: a ring (circle r=152, stroke 104 in a 512 box), converted to
|
|
67
|
+
// one even-odd path so it paints as ink like every other glyph.
|
|
68
|
+
jcode: { ink: [52, 52, 408, 408], body: "<path fill-rule=\"evenodd\" d=\"M256 52a204 204 0 1 0 0 408a204 204 0 1 0 0-408zM256 156a100 100 0 1 0 0 200a100 100 0 1 0 0-200z\"></path>" },
|
|
69
|
+
// Grok's own mark from @lobehub/icons-static-svg (monochrome variant).
|
|
70
|
+
grok: { ink: [0, 0, 24, 24], body: "<path d=\"M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815\"></path>" },
|
|
65
71
|
};
|
|
@@ -10,20 +10,14 @@
|
|
|
10
10
|
* surface entirely: an `<img>` against the raw-byte route, a checker backdrop
|
|
11
11
|
* for transparency, and zoom/pan that mirror the diagram viewer so the two
|
|
12
12
|
* full-size viewers behave the same way.
|
|
13
|
+
*
|
|
14
|
+
* The zoom/pan itself is `ZoomPanStage`: the same interaction draws a rendered
|
|
15
|
+
* diagram, and two copies of the fit arithmetic is how the two surfaces drift.
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
18
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
16
|
-
import type { TargetedPointerEvent, TargetedWheelEvent } from 'preact';
|
|
17
19
|
import { AlertTriangle, Loader2 } from 'lucide-preact';
|
|
18
|
-
|
|
19
|
-
const MIN_SCALE = 0.1;
|
|
20
|
-
const MAX_SCALE = 16;
|
|
21
|
-
/** Zoom step for the buttons and the +/- keys. */
|
|
22
|
-
const ZOOM_STEP = 1.4;
|
|
23
|
-
/** Wheel `deltaY` → scale exponent, matching the diagram viewer's feel. */
|
|
24
|
-
const WHEEL_SENSITIVITY = 0.0015;
|
|
25
|
-
/** Pixels kept clear around a fitted picture. */
|
|
26
|
-
const FIT_MARGIN = 48;
|
|
20
|
+
import { ZoomPanStage } from '@/client/components/common/zoom-pan-stage';
|
|
27
21
|
|
|
28
22
|
interface ImageViewerProps {
|
|
29
23
|
/** Raw-byte URL; a different URL is a different picture. */
|
|
@@ -32,26 +26,14 @@ interface ImageViewerProps {
|
|
|
32
26
|
className?: string;
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
interface Drag {
|
|
36
|
-
pointerId: number;
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
29
|
/**
|
|
42
30
|
* The stateful surface, keyed on `src` by `ImageViewer` — remounting on a new
|
|
43
31
|
* URL is what guarantees a refresh cannot inherit the previous picture's fit,
|
|
44
32
|
* pan offset, or decode error.
|
|
45
33
|
*/
|
|
46
34
|
function ImageSurface({ src, name, className = '' }: ImageViewerProps) {
|
|
47
|
-
const stageRef = useRef<HTMLDivElement>(null);
|
|
48
35
|
const imageRef = useRef<HTMLImageElement>(null);
|
|
49
|
-
const dragRef = useRef<Drag | null>(null);
|
|
50
|
-
|
|
51
36
|
const [natural, setNatural] = useState<{ width: number; height: number } | null>(null);
|
|
52
|
-
const [scale, setScale] = useState(1);
|
|
53
|
-
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
|
54
|
-
const [dragging, setDragging] = useState(false);
|
|
55
37
|
const [error, setError] = useState<string | null>(null);
|
|
56
38
|
|
|
57
39
|
/** Read the decoded size off the element; false while it is not decodable yet. */
|
|
@@ -69,153 +51,43 @@ function ImageSurface({ src, name, className = '' }: ImageViewerProps) {
|
|
|
69
51
|
measure();
|
|
70
52
|
}, [measure]);
|
|
71
53
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
setScale(
|
|
80
|
-
Math.min(
|
|
81
|
-
1,
|
|
82
|
-
Math.max(MIN_SCALE, (stage.width - FIT_MARGIN) / width, (stage.height - FIT_MARGIN) / height),
|
|
83
|
-
),
|
|
54
|
+
if (error) {
|
|
55
|
+
return (
|
|
56
|
+
<div className={`flex h-full w-full flex-col items-center justify-center gap-2 px-6 text-center bg-paper ${className}`}>
|
|
57
|
+
<AlertTriangle size={20} className="text-error" />
|
|
58
|
+
<span className="font-sans text-xs text-error">Could not read {name}</span>
|
|
59
|
+
<span className="break-all font-mono text-[11px] text-ink/50">{error}</span>
|
|
60
|
+
</div>
|
|
84
61
|
);
|
|
85
|
-
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
// Fit once per picture. Re-measuring on every render would fight an
|
|
89
|
-
// in-progress zoom, and `natural` only changes for a new decode.
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
if (natural) fitToView();
|
|
92
|
-
}, [natural, fitToView]);
|
|
93
|
-
|
|
94
|
-
const zoomBy = useCallback((factor: number) => {
|
|
95
|
-
setScale((current) => Math.min(MAX_SCALE, Math.max(MIN_SCALE, current * factor)));
|
|
96
|
-
}, []);
|
|
97
|
-
|
|
98
|
-
const handleWheel = useCallback(
|
|
99
|
-
(event: TargetedWheelEvent<HTMLDivElement>) => {
|
|
100
|
-
// Without this the editor panel scrolls while zooming.
|
|
101
|
-
event.preventDefault();
|
|
102
|
-
zoomBy(Math.exp(-event.deltaY * WHEEL_SENSITIVITY));
|
|
103
|
-
},
|
|
104
|
-
[zoomBy],
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const handlePointerDown = useCallback((event: TargetedPointerEvent<HTMLDivElement>) => {
|
|
108
|
-
if (event.button !== 0 || !natural) return;
|
|
109
|
-
dragRef.current = { pointerId: event.pointerId, x: event.clientX, y: event.clientY };
|
|
110
|
-
event.currentTarget.setPointerCapture(event.pointerId);
|
|
111
|
-
setDragging(true);
|
|
112
|
-
}, [natural]);
|
|
113
|
-
|
|
114
|
-
const handlePointerMove = useCallback((event: TargetedPointerEvent<HTMLDivElement>) => {
|
|
115
|
-
const drag = dragRef.current;
|
|
116
|
-
if (!drag || drag.pointerId !== event.pointerId) return;
|
|
117
|
-
const dx = event.clientX - drag.x;
|
|
118
|
-
const dy = event.clientY - drag.y;
|
|
119
|
-
drag.x = event.clientX;
|
|
120
|
-
drag.y = event.clientY;
|
|
121
|
-
setOffset((current) => ({ x: current.x + dx, y: current.y + dy }));
|
|
122
|
-
}, []);
|
|
123
|
-
|
|
124
|
-
const endDrag = useCallback((event: TargetedPointerEvent<HTMLDivElement>) => {
|
|
125
|
-
if (dragRef.current?.pointerId !== event.pointerId) return;
|
|
126
|
-
dragRef.current = null;
|
|
127
|
-
setDragging(false);
|
|
128
|
-
}, []);
|
|
129
|
-
|
|
130
|
-
const handleDoubleClick = useCallback(() => {
|
|
131
|
-
if (Math.abs(scale - 1) < 0.01) fitToView();
|
|
132
|
-
else {
|
|
133
|
-
setScale(1);
|
|
134
|
-
setOffset({ x: 0, y: 0 });
|
|
135
|
-
}
|
|
136
|
-
}, [scale, fitToView]);
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
const onKeyDown = (event: globalThis.KeyboardEvent) => {
|
|
140
|
-
if (event.key !== '+' && event.key !== '=' && event.key !== '-' && event.key !== '_' && event.key !== '0') return;
|
|
141
|
-
// The stage owns these keys only while it has focus; a window-level
|
|
142
|
-
// listener would steal `-`/`0` from the composer and the file search box.
|
|
143
|
-
const target = event.target as HTMLElement | null;
|
|
144
|
-
if (!target || !stageRef.current?.contains(target)) return;
|
|
145
|
-
event.preventDefault();
|
|
146
|
-
if (event.key === '0') fitToView();
|
|
147
|
-
else if (event.key === '+' || event.key === '=') zoomBy(ZOOM_STEP);
|
|
148
|
-
else zoomBy(1 / ZOOM_STEP);
|
|
149
|
-
};
|
|
150
|
-
window.addEventListener('keydown', onKeyDown);
|
|
151
|
-
return () => window.removeEventListener('keydown', onKeyDown);
|
|
152
|
-
}, [zoomBy, fitToView]);
|
|
153
|
-
|
|
154
|
-
const percent = Math.round(scale * 100);
|
|
155
|
-
const dimensions = natural ? `${natural.width} × ${natural.height} px` : '';
|
|
62
|
+
}
|
|
156
63
|
|
|
157
64
|
return (
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
>
|
|
170
|
-
{error ? (
|
|
171
|
-
<div className="flex h-full flex-col items-center justify-center gap-2 px-6 text-center">
|
|
172
|
-
<AlertTriangle size={20} className="text-error" />
|
|
173
|
-
<span className="font-sans text-xs text-error">Could not read {name}</span>
|
|
174
|
-
<span className="break-all font-mono text-[11px] text-ink/50">{error}</span>
|
|
65
|
+
<ZoomPanStage
|
|
66
|
+
className={className}
|
|
67
|
+
// The natural size is what the stage has to fit; the element's own layout
|
|
68
|
+
// box is the picture at 1×, which is what `measure` reads.
|
|
69
|
+
measureKey={natural}
|
|
70
|
+
caption={natural ? `${natural.width} × ${natural.height} px` : ''}
|
|
71
|
+
overlay={
|
|
72
|
+
natural ? null : (
|
|
73
|
+
<div className="absolute inset-0 flex items-center justify-center gap-2 text-xs text-ink/40">
|
|
74
|
+
<Loader2 size={14} className="animate-spin" />
|
|
75
|
+
<span>Loading image…</span>
|
|
175
76
|
</div>
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
onLoad={measure}
|
|
191
|
-
onError={() => setError('The file could not be decoded as an image.')}
|
|
192
|
-
className="image-canvas max-h-none max-w-none select-none"
|
|
193
|
-
style={{
|
|
194
|
-
transform: `translate3d(${offset.x}px, ${offset.y}px, 0) scale(${scale})`,
|
|
195
|
-
visibility: natural ? 'visible' : 'hidden',
|
|
196
|
-
}}
|
|
197
|
-
/>
|
|
198
|
-
</div>
|
|
199
|
-
</>
|
|
200
|
-
)}
|
|
201
|
-
</div>
|
|
202
|
-
|
|
203
|
-
<div className="flex flex-shrink-0 items-center justify-between border-t border-ink/10 bg-canvas px-3 py-1.5 font-mono text-[10px] text-ink/50">
|
|
204
|
-
<span>{dimensions}</span>
|
|
205
|
-
<div className="flex items-center gap-3">
|
|
206
|
-
<button type="button" onClick={() => zoomBy(1 / ZOOM_STEP)} className="hover:text-ink" title="Zoom out (-)">
|
|
207
|
-
−
|
|
208
|
-
</button>
|
|
209
|
-
<span className="w-10 text-center tabular-nums">{percent}%</span>
|
|
210
|
-
<button type="button" onClick={() => zoomBy(ZOOM_STEP)} className="hover:text-ink" title="Zoom in (+)">
|
|
211
|
-
+
|
|
212
|
-
</button>
|
|
213
|
-
<button type="button" onClick={fitToView} className="hover:text-ink" title="Fit to view (0)">
|
|
214
|
-
Fit
|
|
215
|
-
</button>
|
|
216
|
-
</div>
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
>
|
|
80
|
+
<img
|
|
81
|
+
ref={imageRef}
|
|
82
|
+
src={src}
|
|
83
|
+
alt={name}
|
|
84
|
+
draggable={false}
|
|
85
|
+
onLoad={measure}
|
|
86
|
+
onError={() => setError('The file could not be decoded as an image.')}
|
|
87
|
+
className="image-canvas max-h-none max-w-none select-none"
|
|
88
|
+
style={{ visibility: natural ? 'visible' : 'hidden' }}
|
|
89
|
+
/>
|
|
90
|
+
</ZoomPanStage>
|
|
219
91
|
);
|
|
220
92
|
}
|
|
221
93
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The filter row inside a composer picker.
|
|
8
|
+
*
|
|
9
|
+
* Every popover in the composer's target pair answers the same question — "which
|
|
10
|
+
* of these N rows is the one I meant" — and each used to be a plain scroller. The
|
|
11
|
+
* row is one component so the three controls cannot drift into three looks, and
|
|
12
|
+
* so the field can be given the popover's own border and height rather than a
|
|
13
|
+
* per-control approximation.
|
|
14
|
+
*
|
|
15
|
+
* Focus is taken on mount: the row only exists while the popover is open, so the
|
|
16
|
+
* user's next keystroke is a query instead of an arrow key walk.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
20
|
+
import { Search, X } from 'lucide-preact';
|
|
21
|
+
|
|
22
|
+
interface PickerSearchProps {
|
|
23
|
+
value: string;
|
|
24
|
+
onChange: (value: string) => void;
|
|
25
|
+
/** Names both the field and its clear control. */
|
|
26
|
+
ariaLabel: string;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function PickerSearch({ value, onChange, ariaLabel, placeholder = 'Search…' }: PickerSearchProps) {
|
|
31
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
inputRef.current?.focus();
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className="flex items-center gap-1.5 border-b border-ink/5 px-2.5 py-1.5">
|
|
39
|
+
<Search size={11} className="shrink-0 text-ink/35" aria-hidden="true" />
|
|
40
|
+
<input
|
|
41
|
+
ref={inputRef}
|
|
42
|
+
type="text"
|
|
43
|
+
value={value}
|
|
44
|
+
aria-label={ariaLabel}
|
|
45
|
+
placeholder={placeholder}
|
|
46
|
+
onInput={(event) => onChange(event.currentTarget.value)}
|
|
47
|
+
onKeyDown={(event) => {
|
|
48
|
+
// The popover is inside a form-less composer; Escape closing the field
|
|
49
|
+
// is the one key a reader presses without thinking.
|
|
50
|
+
if (event.key === 'Escape') {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
onChange('');
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
className="min-w-0 flex-1 bg-transparent text-xs text-ink outline-none placeholder:text-ink/35"
|
|
56
|
+
/>
|
|
57
|
+
{value.length > 0 && (
|
|
58
|
+
<button
|
|
59
|
+
type="button"
|
|
60
|
+
onClick={() => onChange('')}
|
|
61
|
+
title="Clear search"
|
|
62
|
+
aria-label="Clear search"
|
|
63
|
+
className="shrink-0 rounded p-0.5 text-ink/40 transition-colors cursor-pointer hover:bg-ink/10 hover:text-ink"
|
|
64
|
+
>
|
|
65
|
+
<X size={11} />
|
|
66
|
+
</button>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -31,6 +31,7 @@ import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
|
|
|
31
31
|
import { Check, ChevronDown, Search } from 'lucide-preact';
|
|
32
32
|
import { AnchoredMenu } from '@/client/components/common/anchored-menu';
|
|
33
33
|
import { anchorRectOf, type AnchorRect } from '@/shared/lib/ui/menu-anchor';
|
|
34
|
+
import { matchesPickerQuery } from '@/shared/lib/ui/picker-filter';
|
|
34
35
|
|
|
35
36
|
/** One option: the value stored, and what a reader sees. */
|
|
36
37
|
export interface SearchSelectOption {
|
|
@@ -60,12 +61,6 @@ interface SearchSelectProps {
|
|
|
60
61
|
const TRIGGER_CLASS =
|
|
61
62
|
'flex w-full min-w-0 items-center justify-between gap-2 rounded-md border border-ink/20 bg-paper px-2 py-1.5 text-left font-mono text-[11px] text-ink transition-colors hover:border-ink/40 focus:border-ink/50 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50';
|
|
62
63
|
|
|
63
|
-
/** Case- and separator-insensitive match, so "claude sonnet" finds `claude-sonnet-5`. */
|
|
64
|
-
function matches(haystack: string, needle: string): boolean {
|
|
65
|
-
const fold = (text: string) => text.toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
66
|
-
return fold(haystack).includes(fold(needle));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
64
|
export function SearchSelect({
|
|
70
65
|
value,
|
|
71
66
|
options,
|
|
@@ -90,7 +85,7 @@ export function SearchSelect({
|
|
|
90
85
|
const filtered = useMemo(() => {
|
|
91
86
|
const needle = query.trim();
|
|
92
87
|
if (!needle) return options;
|
|
93
|
-
return options.filter((option) =>
|
|
88
|
+
return options.filter((option) => matchesPickerQuery(`${option.label} ${option.value} ${option.hint ?? ''}`, needle));
|
|
94
89
|
}, [options, query]);
|
|
95
90
|
|
|
96
91
|
/** Rows grouped by `group`, in the order the groups first appear. */
|