@kabmo-labs/kabmo 0.16.0 → 0.17.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/README.md +2 -2
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +417 -417
- package/dist/client/static/js/index-3ve31rzx.css +1 -0
- package/dist/client/static/js/{index-cpydmygd.js → index-rerjq5th.js} +839 -837
- package/package.json +1 -1
- package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
- package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
- package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
- package/src/client/components/common/code-surface/extensions.ts +7 -4
- package/src/client/components/common/code-surface/theme.ts +34 -9
- package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
- package/src/client/components/common/code-surface/whitespace.ts +140 -0
- package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
- package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
- package/src/client/components/common/server-control/index.tsx +118 -0
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
- package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
- package/src/client/components/settings/Modal.tsx +9 -3
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
- package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
- package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
- package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
- package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
- package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
- package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
- package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
- package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
- package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
- package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
- package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
- package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
- package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
- package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
- package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
- package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
- package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
- package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
- package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
- package/src/client/components/workspace/file-explorer/index.tsx +21 -20
- package/src/client/data/settings/omp-schema.json +91 -4
- package/src/client/data/settings/project.ts +9 -28
- package/src/client/data/settings/skill.ts +6 -32
- package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
- package/src/client/hooks/settings/projects/index.ts +294 -0
- package/src/client/hooks/settings/projects.test.ts +237 -0
- package/src/client/hooks/settings/skill-catalog.ts +101 -9
- package/src/client/hooks/settings/skill-git-import.ts +153 -0
- package/src/client/hooks/shell/servers.test.ts +166 -0
- package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
- package/src/client/hooks/ui/updates/shell-download.ts +1 -1
- package/src/client/hooks/ui/updates/shell-update.ts +2 -6
- package/src/client/hooks/workspace/file-row-drag.ts +41 -0
- package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
- package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
- package/src/client/hooks/workspace/root-drop-target.ts +77 -0
- package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
- package/src/client/lib/desktop/dropped-paths.ts +1 -1
- package/src/client/lib/desktop/titlebar.test.ts +12 -3
- package/src/client/lib/desktop/titlebar.ts +1 -1
- package/src/client/lib/shell/desktop.ts +117 -0
- package/src/client/lib/shell/servers.ts +75 -0
- package/src/client/lib/shell/transport.ts +216 -0
- package/src/client/main.tsx +9 -0
- package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
- package/src/server/lib/omp/config/skill-sources.ts +49 -0
- package/src/server/lib/omp/config/skills-git-install.ts +155 -0
- package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
- package/src/server/lib/omp/config/skills-git.test.ts +220 -0
- package/src/server/lib/workspace/project-model.server.test.ts +102 -0
- package/src/server/lib/workspace/project-model.server.ts +47 -0
- package/src/server/lib/workspace/project-patch.server.ts +156 -0
- package/src/server/routes/agent/new.ts +8 -1
- package/src/server/routes/settings/agents.ts +19 -7
- package/src/server/routes/settings/projects.ts +53 -19
- package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
- package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
- package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
- package/src/server/routes/settings/skills.test.ts +225 -0
- package/src/server/routes/settings/skills.ts +18 -15
- package/src/shared/lib/fs/folder-chain.test.ts +81 -1
- package/src/shared/lib/fs/folder-chain.ts +84 -0
- package/src/shared/lib/omp/config/schema.test.ts +35 -0
- package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
- package/src/shared/lib/omp/session/job-progress.ts +31 -0
- package/src/shared/lib/omp/session/proc.ts +5 -0
- package/src/shared/lib/omp/session/wait.ts +5 -0
- package/src/shared/lib/ui/mobile-overlay.ts +61 -0
- package/src/shared/lib/ui/svg-scope.test.ts +97 -0
- package/src/shared/lib/ui/svg-scope.ts +134 -0
- package/src/shared/lib/workspace/project-accent.test.ts +69 -0
- package/src/shared/lib/workspace/project-accent.ts +63 -0
- package/src/shared/lib/workspace/project-icon.ts +40 -0
- package/src/shared/lib/workspace/project-model.test.ts +79 -0
- package/src/shared/lib/workspace/project-model.ts +64 -0
- package/src/shared/types/settings/skill.ts +53 -3
- package/src/test-support/file-explorer-disk.test-util.ts +25 -1
- package/src/test-support/file-explorer-drag.test-util.ts +88 -0
- package/src/test-support/file-explorer.test-util.ts +47 -47
- package/dist/client/static/js/index-fjnq2z2d.css +0 -1
- package/src/client/components/common/code-surface/indent-guide.ts +0 -104
- package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
- package/src/client/hooks/desktop/servers.test.ts +0 -73
- package/src/client/lib/desktop/bridge.ts +0 -203
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
- package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
|
@@ -62,6 +62,90 @@ function foldNode(node: FsNode): FsNode {
|
|
|
62
62
|
return current;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Whether this row is a folded chain — one row standing for several directories.
|
|
67
|
+
*
|
|
68
|
+
* Decided by the LABEL alone, and that is load-bearing in both directions: a
|
|
69
|
+
* directory name cannot contain a separator, so a `/` in a folder's `name` can
|
|
70
|
+
* only come from the fold. Comparing `name` with `path` does not work, because a
|
|
71
|
+
* chain folded at the listing's own root is labelled with the whole path
|
|
72
|
+
* (`name === path === 'dev/src/main/code'`) while still standing for four
|
|
73
|
+
* directories — every surface that asks "does this row hide levels?" (drop
|
|
74
|
+
* targets, the rename and delete dialogs, the unfold menu row) reads this one
|
|
75
|
+
* answer, so they cannot disagree about the same row.
|
|
76
|
+
*/
|
|
77
|
+
export function isChainRow(node: { type: 'file' | 'folder'; name: string }): boolean {
|
|
78
|
+
return node.type === 'folder' && node.name.includes('/');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The paths of the directories a collapsed row STANDS FOR, outermost first —
|
|
83
|
+
* or null when the row's label does not name a chain.
|
|
84
|
+
*
|
|
85
|
+
* The fold is a RENDERING decision, not a filesystem fact, and it hides
|
|
86
|
+
* destinations: `dev/src/main` is not a row, so it cannot be dropped on,
|
|
87
|
+
* renamed, or created inside — a drop on the one row lands in the deepest
|
|
88
|
+
* directory (`code`) instead. The panel keeps a set of chains the user asked to
|
|
89
|
+
* unfold and projects it onto the tree the listing hands over
|
|
90
|
+
* (`unfoldChains`), and this is the one place that turns the row's LABEL
|
|
91
|
+
* (`dev/src/main/code`) plus its `path` (the deepest directory) back into the
|
|
92
|
+
* levels between them.
|
|
93
|
+
*/
|
|
94
|
+
export function chainLevelPaths(path: string, label: string): string[] | null {
|
|
95
|
+
const names = label.split('/');
|
|
96
|
+
const segments = path.split('/');
|
|
97
|
+
if (names.length < 2 || names.length > segments.length || names.some((name) => !name)) return null;
|
|
98
|
+
const outer = segments.slice(0, segments.length - names.length);
|
|
99
|
+
return names.map((_, index) => [...outer, ...names.slice(0, index + 1)].join('/'));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Drawn rows with the chains named in `unfolded` split back into one row per
|
|
104
|
+
* directory, so every level of a folded chain becomes a real drop target, a
|
|
105
|
+
* real rename target and a real place to create something.
|
|
106
|
+
*
|
|
107
|
+
* The deepest row keeps its own `children` — and therefore its own read — so
|
|
108
|
+
* unfolding a chain never costs a request. Whether the intermediate rows are
|
|
109
|
+
* DRAWN open is the panel's business, not this projection's: they are ordinary
|
|
110
|
+
* rows, opened through the panel's expansion set like any other folder.
|
|
111
|
+
*/
|
|
112
|
+
export function unfoldChains(nodes: FsNode[], unfolded: ReadonlySet<string>): {
|
|
113
|
+
nodes: FsNode[];
|
|
114
|
+
/** The outermost level of each chain that was actually unfolded → its deepest path. */
|
|
115
|
+
roots: Map<string, string>;
|
|
116
|
+
} {
|
|
117
|
+
const roots = new Map<string, string>();
|
|
118
|
+
if (unfolded.size === 0) return { nodes, roots };
|
|
119
|
+
let changed = false;
|
|
120
|
+
const walk = (list: FsNode[]): FsNode[] => list.flatMap((node) => {
|
|
121
|
+
if (node.type !== 'folder') return [node];
|
|
122
|
+
const children = Array.isArray(node.children) ? walk(node.children) : node.children;
|
|
123
|
+
const row: FsNode = children === node.children ? node : { ...node, children };
|
|
124
|
+
const levels = unfolded.has(node.path) ? chainLevelPaths(node.path, node.name) : null;
|
|
125
|
+
if (!levels) return [row];
|
|
126
|
+
changed = true;
|
|
127
|
+
roots.set(levels[0]!, node.path);
|
|
128
|
+
// Rebuilt from the outside in, so the deepest row is the original one —
|
|
129
|
+
// its children, its expansion state and its git answer all stay attached.
|
|
130
|
+
let deepest: FsNode = { ...row, name: levels[levels.length - 1]!.split('/').pop()! };
|
|
131
|
+
for (let depth = levels.length - 1; depth > 0; depth -= 1) {
|
|
132
|
+
const path = levels[depth - 1]!;
|
|
133
|
+
deepest = {
|
|
134
|
+
name: path.split('/').pop()!,
|
|
135
|
+
path,
|
|
136
|
+
type: 'folder',
|
|
137
|
+
// A rule matching any level of the chain answers for the deepest too
|
|
138
|
+
// (see `foldNode`), so every level wears the row's own answer.
|
|
139
|
+
ignored: row.ignored,
|
|
140
|
+
children: [deepest],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return [deepest];
|
|
144
|
+
});
|
|
145
|
+
const next = walk(nodes);
|
|
146
|
+
return { nodes: changed ? next : nodes, roots };
|
|
147
|
+
}
|
|
148
|
+
|
|
65
149
|
/**
|
|
66
150
|
* The paths of the DRAWN rows that contain `path`, outermost first.
|
|
67
151
|
*
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
import { SCHEMA_EXTRAS } from '@/shared/lib/omp/config/schema-extras';
|
|
25
25
|
import { ALL_SCHEMA_ENTRIES, OMP_SCHEMA, configValue, entriesForTab, isConditionMet, matchesSearch } from '@/shared/lib/omp/config/schema';
|
|
26
26
|
import type { ConfigEntry } from '@/server/lib/omp/config/config-cli';
|
|
27
|
+
import type { SchemaEntry } from '@/shared/lib/omp/config/schema-types';
|
|
27
28
|
|
|
28
29
|
/** Build a config snapshot from `{ key: value }` pairs. */
|
|
29
30
|
function snapshot(values: Record<string, unknown>): Record<string, ConfigEntry> {
|
|
@@ -86,6 +87,25 @@ describe('OMP_SCHEMA', () => {
|
|
|
86
87
|
expect(entry?.ui.tab).toBe('interaction');
|
|
87
88
|
expect(entry?.ui.group).toBe('Approvals');
|
|
88
89
|
});
|
|
90
|
+
|
|
91
|
+
test('the rows omp 18.15.0 adds are offered', () => {
|
|
92
|
+
// Measured against `omp config list --json` on 18.15.0: all four exist and
|
|
93
|
+
// every one accepts a write through `omp config set`. A schema regenerated
|
|
94
|
+
// without them is a release of settings the panel cannot reach.
|
|
95
|
+
const expected: Record<string, { type: SchemaEntry['type']; tab: string; group: string }> = {
|
|
96
|
+
'providers.openai-codex.daybreak': { type: 'boolean', tab: 'providers', group: 'Protocol' },
|
|
97
|
+
'task.perCallModel': { type: 'enum', tab: 'tasks', group: 'Subagents' },
|
|
98
|
+
'task.perCallModelAllow': { type: 'array', tab: 'tasks', group: 'Subagents' },
|
|
99
|
+
'title.refreshAfterPrompts': { type: 'number', tab: 'tasks', group: 'Modes' },
|
|
100
|
+
};
|
|
101
|
+
for (const [key, want] of Object.entries(expected)) {
|
|
102
|
+
const entry = OMP_SCHEMA.entries[key];
|
|
103
|
+
expect({ key, entry: entry && { type: entry.type, tab: entry.ui.tab, group: entry.ui.group } }).toEqual({
|
|
104
|
+
key,
|
|
105
|
+
entry: want,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
89
109
|
});
|
|
90
110
|
|
|
91
111
|
describe('ALL_SCHEMA_ENTRIES', () => {
|
|
@@ -163,6 +183,21 @@ describe('isConditionMet', () => {
|
|
|
163
183
|
test('an unknown condition degrades to visible', () => {
|
|
164
184
|
expect(isConditionMet('someFutureCondition', {})).toBe(true);
|
|
165
185
|
});
|
|
186
|
+
|
|
187
|
+
test('the provenance conditions degrade to visible, deliberately', () => {
|
|
188
|
+
// These three hide an editor row when a PROJECT layer supplies the value,
|
|
189
|
+
// because the editor writes the GLOBAL layer and promoting a repository's
|
|
190
|
+
// list would be the bug. `omp config list --json` carries no provenance, so
|
|
191
|
+
// the client cannot answer them — visible is the decision, not an oversight.
|
|
192
|
+
// `perCallModelAllowNotProject` arrived with 18.15.0's `task.perCallModelAllow`.
|
|
193
|
+
for (const condition of [
|
|
194
|
+
'contextFilesExtraNotProject',
|
|
195
|
+
'restrictedFoldersNotProject',
|
|
196
|
+
'perCallModelAllowNotProject',
|
|
197
|
+
]) {
|
|
198
|
+
expect({ condition, met: isConditionMet(condition, {}) }).toEqual({ condition, met: true });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
166
201
|
});
|
|
167
202
|
|
|
168
203
|
describe('entriesForTab', () => {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { describe, expect, test } from 'bun:test';
|
|
13
|
-
import { jobProgressLine, jobProgressParts } from '@/shared/lib/omp/session/job-progress';
|
|
13
|
+
import { jobSubject, jobProgressLine, jobProgressParts } from '@/shared/lib/omp/session/job-progress';
|
|
14
14
|
|
|
15
15
|
const RUNNING = {
|
|
16
16
|
status: 'running',
|
|
@@ -74,3 +74,39 @@ describe('jobProgressLine', () => {
|
|
|
74
74
|
expect(jobProgressLine({ status: 'failed', requests: 12 })).toBeUndefined();
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* omp 18.15.0 records the caller's `i` intent on the job and leads its own
|
|
80
|
+
* `/jobs` rows with it. Measured with the release's own `snapshotJobs`, given a
|
|
81
|
+
* bash job whose call carried `intent: "Start the dev server"`:
|
|
82
|
+
*
|
|
83
|
+
* [{ id: 'bg_1', type: 'bash', status: 'running', label: 'bun run dev',
|
|
84
|
+
* intent: 'Start the dev server', durationMs: 42000 }]
|
|
85
|
+
*
|
|
86
|
+
* The label is still the raw command line, so both lines are drawn: the purpose
|
|
87
|
+
* as the subject, the command beneath it.
|
|
88
|
+
*/
|
|
89
|
+
describe('jobSubject', () => {
|
|
90
|
+
test('leads with the model\'s intent and keeps the command beneath', () => {
|
|
91
|
+
expect(jobSubject({ intent: 'Start the dev server', label: 'bun run dev' })).toEqual({
|
|
92
|
+
primary: 'Start the dev server',
|
|
93
|
+
secondary: 'bun run dev',
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('a row without an intent falls back to its label alone', () => {
|
|
98
|
+
// Every `task` job, and every job omp recorded before 18.15.0.
|
|
99
|
+
expect(jobSubject({ label: 'audit the diff' })).toEqual({ primary: 'audit the diff' });
|
|
100
|
+
expect(jobSubject({})).toEqual({ primary: undefined });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('a multi-line intent is collapsed to one line', () => {
|
|
104
|
+
expect(jobSubject({ intent: 'Start\nthe dev server', label: 'bun run dev' }).primary).toBe(
|
|
105
|
+
'Start the dev server',
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('a blank intent is an absence, not an empty subject', () => {
|
|
110
|
+
expect(jobSubject({ intent: ' ', label: 'bun run dev' })).toEqual({ primary: 'bun run dev' });
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -82,3 +82,34 @@ export function jobProgressLine(job: JobProgressFields, options: JobProgressOpti
|
|
|
82
82
|
const parts = jobProgressParts(job, options);
|
|
83
83
|
return parts.length > 0 ? parts.join(' · ') : undefined;
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
/** The two fields a job row leads with. */
|
|
87
|
+
export interface JobSubjectFields {
|
|
88
|
+
/** What the job is for, in the MODEL's words — the `i` intent of the call
|
|
89
|
+
* that started it (omp 18.15.0). Only the tools that start a single job set
|
|
90
|
+
* it, so a subagent task row never has one. */
|
|
91
|
+
intent?: string;
|
|
92
|
+
/** The raw command line (bash) or the task's own label. */
|
|
93
|
+
label?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* What a job row says: the intent first, the command beneath it.
|
|
98
|
+
*
|
|
99
|
+
* omp 18.15.0 records the caller's `i` intent on the job and leads its own
|
|
100
|
+
* `/jobs` rows with it, because `bun run dev` does not say what the job is FOR.
|
|
101
|
+
* Kabmo drew the label alone, so the purpose the model had already stated was
|
|
102
|
+
* dropped and the raw command stood in for it. Resolved in one place so the
|
|
103
|
+
* `wait` card, the `proc://` card and their fact chips cannot disagree about
|
|
104
|
+
* which line is the subject.
|
|
105
|
+
*
|
|
106
|
+
* `primary` falls back to the label when there is no intent, so a row always
|
|
107
|
+
* has something to draw; `secondary` is only present when both exist (the
|
|
108
|
+
* command is still worth reading, under the purpose it serves).
|
|
109
|
+
*/
|
|
110
|
+
export function jobSubject(job: JobSubjectFields): { primary?: string; secondary?: string } {
|
|
111
|
+
const intent = job.intent?.replace(/\s+/g, ' ').trim();
|
|
112
|
+
const label = job.label?.trim();
|
|
113
|
+
if (!intent) return { primary: label };
|
|
114
|
+
return { primary: intent, secondary: label };
|
|
115
|
+
}
|
|
@@ -93,6 +93,10 @@ export interface ProcJob {
|
|
|
93
93
|
type?: string;
|
|
94
94
|
status?: string;
|
|
95
95
|
label?: string;
|
|
96
|
+
/** What the job is for, in the MODEL's words — the `i` intent of the call
|
|
97
|
+
* that started it (omp 18.15.0). Absent on rows omp built before the
|
|
98
|
+
* release, on subagent tasks, and on a call the model gave no intent. */
|
|
99
|
+
intent?: string;
|
|
96
100
|
durationMs?: number;
|
|
97
101
|
exitCode?: number;
|
|
98
102
|
/** Self-estimated completion of a subagent task (0–100). */
|
|
@@ -181,6 +185,7 @@ function jobOf(value: unknown): ProcJob | undefined {
|
|
|
181
185
|
type: asString(value.type),
|
|
182
186
|
status: asString(value.status),
|
|
183
187
|
label: asString(value.label),
|
|
188
|
+
intent: asString(value.intent),
|
|
184
189
|
durationMs: asNumber(value.durationMs),
|
|
185
190
|
exitCode: asNumber(value.exitCode),
|
|
186
191
|
completionPercent: asNumber(value.completionPercent),
|
|
@@ -38,6 +38,10 @@ export interface WaitJob {
|
|
|
38
38
|
type?: string;
|
|
39
39
|
status?: string;
|
|
40
40
|
label?: string;
|
|
41
|
+
/** What the job is for, in the MODEL's words — the `i` intent of the call
|
|
42
|
+
* that started it (omp 18.15.0); absent on subagent tasks and on a call the
|
|
43
|
+
* model gave no intent. */
|
|
44
|
+
intent?: string;
|
|
41
45
|
/** Elapsed time AT SNAPSHOT TIME — omp computes `now - startTime` while the
|
|
42
46
|
* job runs, so a live snapshot's value is the real elapsed clock. */
|
|
43
47
|
durationMs?: number;
|
|
@@ -124,6 +128,7 @@ function jobOf(value: unknown): WaitJob | undefined {
|
|
|
124
128
|
type: asString(value.type),
|
|
125
129
|
status: asString(value.status),
|
|
126
130
|
label: asString(value.label),
|
|
131
|
+
intent: asString(value.intent),
|
|
127
132
|
durationMs: asNumber(value.durationMs),
|
|
128
133
|
exitCode: asNumber(value.exitCode),
|
|
129
134
|
completionPercent: asNumber(value.completionPercent),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where a phone's header overlays hang, in ONE place.
|
|
8
|
+
*
|
|
9
|
+
* Both the session picker (`MobileHeader`) and the server panel hang below the
|
|
10
|
+
* 3.5rem title bar, and both used to state the same six numbers inline. They
|
|
11
|
+
* drifted once already: the server panel was drawn `absolute` at 340px, which
|
|
12
|
+
* on a 390px phone runs off the right edge and past the bottom in landscape.
|
|
13
|
+
*
|
|
14
|
+
* Pinned to the VIEWPORT with both insets rather than anchored to the trigger:
|
|
15
|
+
* a trigger is not always near the edge it would have to grow from, and the
|
|
16
|
+
* safe area is a property of the device, not of the button.
|
|
17
|
+
*
|
|
18
|
+
* `100dvh`, not `100vh`: a landscape phone's visible height is the dynamic one,
|
|
19
|
+
* and a `vh` cap left the last rows under the browser's own chrome.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** The title bar both phone headers draw. */
|
|
23
|
+
export const MOBILE_HEADER_REM = 3.5;
|
|
24
|
+
|
|
25
|
+
/** The gap between that bar and the overlay. */
|
|
26
|
+
const GAP_REM = 0.375;
|
|
27
|
+
|
|
28
|
+
/** The inset kept from the screen's left and right edges. */
|
|
29
|
+
const INSET_REM = 0.75;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A type alias rather than an interface: preact's `CSSProperties` carries an
|
|
33
|
+
* index signature, and an interface has no implicit one, so the object below is
|
|
34
|
+
* not assignable to a `style` prop otherwise.
|
|
35
|
+
*/
|
|
36
|
+
export type MobileOverlayStyle = {
|
|
37
|
+
top: string;
|
|
38
|
+
left: string;
|
|
39
|
+
right: string;
|
|
40
|
+
maxWidth: string;
|
|
41
|
+
maxHeight: string;
|
|
42
|
+
overflowY: 'auto';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The style for an overlay hanging below the phone's title bar.
|
|
47
|
+
*
|
|
48
|
+
* `maxWidth` keeps a wide phone from stretching a menu across the screen; the
|
|
49
|
+
* `maxHeight` subtracts the bar, the gap and the safe area, so a landscape
|
|
50
|
+
* phone scrolls the overlay instead of running it past the bottom edge.
|
|
51
|
+
*/
|
|
52
|
+
export function mobileOverlayStyle(maxWidthRem = 18): MobileOverlayStyle {
|
|
53
|
+
return {
|
|
54
|
+
top: `calc(${MOBILE_HEADER_REM}rem + env(safe-area-inset-top, 0px) + ${GAP_REM}rem)`,
|
|
55
|
+
left: `max(${INSET_REM}rem, env(safe-area-inset-left, 0px))`,
|
|
56
|
+
right: `max(${INSET_REM}rem, env(safe-area-inset-right, 0px))`,
|
|
57
|
+
maxWidth: `${maxWidthRem}rem`,
|
|
58
|
+
maxHeight: `calc(100dvh - ${MOBILE_HEADER_REM}rem - env(safe-area-inset-top, 0px) - ${GAP_REM + INSET_REM}rem)`,
|
|
59
|
+
overflowY: 'auto',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Scoping an SVG's ids, and the two failures it exists to prevent.
|
|
8
|
+
*
|
|
9
|
+
* Both are silent: the picture still draws, just with the wrong paint. These
|
|
10
|
+
* cases therefore assert the REFERENCES, not the declarations — a rename that
|
|
11
|
+
* updated `id="body"` but left `fill="url(#body)"` pointing at the old name
|
|
12
|
+
* would look correct in any test that only counted ids.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { nextSvgScopePrefix, scopeSvgIds } from '@/shared/lib/ui/svg-scope';
|
|
17
|
+
|
|
18
|
+
describe('scopeSvgIds', () => {
|
|
19
|
+
test('renames the declaration and every reference shape with it', () => {
|
|
20
|
+
const svg = [
|
|
21
|
+
'<svg xmlns="http://www.w3.org/2000/svg">',
|
|
22
|
+
'<defs>',
|
|
23
|
+
'<linearGradient id="body"><stop offset="0" stop-color="#fff"/></linearGradient>',
|
|
24
|
+
'<clipPath id="cut"><circle cx="1" cy="1" r="1"/></clipPath>',
|
|
25
|
+
'<style>#body { stroke: url(#cut); }</style>',
|
|
26
|
+
'</defs>',
|
|
27
|
+
'<ellipse fill="url(#body)" clip-path="url(#cut)" style="stroke:url(#body)"/>',
|
|
28
|
+
'<use xlink:href="#body"/>',
|
|
29
|
+
'</svg>',
|
|
30
|
+
].join('');
|
|
31
|
+
|
|
32
|
+
const scoped = scopeSvgIds(svg, 'svg7-');
|
|
33
|
+
|
|
34
|
+
expect(scoped).toContain('id="svg7-body"');
|
|
35
|
+
expect(scoped).toContain('id="svg7-cut"');
|
|
36
|
+
expect(scoped).toContain('fill="url(#svg7-body)"');
|
|
37
|
+
expect(scoped).toContain('clip-path="url(#svg7-cut)"');
|
|
38
|
+
expect(scoped).toContain('style="stroke:url(#svg7-body)"');
|
|
39
|
+
expect(scoped).toContain('xlink:href="#svg7-body"');
|
|
40
|
+
// The stylesheet's SELECTOR half is rewritten...
|
|
41
|
+
expect(scoped).toContain('#svg7-body { stroke: url(#svg7-cut); }');
|
|
42
|
+
// ...and no reference still names an unprefixed id (colours like `#fff`
|
|
43
|
+
// are not references, so they are matched by the URI forms only).
|
|
44
|
+
expect(scoped).not.toMatch(/url\(#(?!svg7-)/);
|
|
45
|
+
expect(scoped).not.toMatch(/href="#(?!svg7-)/);
|
|
46
|
+
expect(scoped).toContain('stop-color="#fff"');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a stylesheet declaration keeps a hex colour that looks like an id', () => {
|
|
50
|
+
// `#abc` in a DECLARATION is a colour, and an id named `abc` is not a
|
|
51
|
+
// reason to rewrite it: doing so would repaint the shape with nothing.
|
|
52
|
+
const scoped = scopeSvgIds(
|
|
53
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><style>#abc, #def { fill: #abc }</style><rect id="abc"/><rect id="def"/></svg>',
|
|
54
|
+
'svg2-',
|
|
55
|
+
);
|
|
56
|
+
expect(scoped).toContain('#svg2-abc, #svg2-def { fill: #abc }');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('a cross-document href is left alone, a same-document fragment is not', () => {
|
|
60
|
+
const scoped = scopeSvgIds(
|
|
61
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><g id="g1"/><use href="other.svg#g1"/><use href="#g1"/></svg>',
|
|
62
|
+
'svg9-',
|
|
63
|
+
);
|
|
64
|
+
expect(scoped).toContain('href="other.svg#g1"');
|
|
65
|
+
expect(scoped).toContain('href="#svg9-g1"');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('an ARIA idref LIST is rewritten entry by entry', () => {
|
|
69
|
+
const scoped = scopeSvgIds(
|
|
70
|
+
'<svg xmlns="http://www.w3.org/2000/svg"><title id="t1">t</title><desc id="d1">d</desc><g id="g1" aria-labelledby="t1 d1 g1 outside"/></svg>',
|
|
71
|
+
'svg4-',
|
|
72
|
+
);
|
|
73
|
+
// `outside` is not declared here, so it is not ours to rename.
|
|
74
|
+
expect(scoped).toContain('aria-labelledby="svg4-t1 svg4-d1 svg4-g1 outside"');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('markup with no id is returned as the SAME string', () => {
|
|
78
|
+
const markup = '<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4"/></svg>';
|
|
79
|
+
expect(scopeSvgIds(markup, 'svg1-')).toBe(markup);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('an already-scoped document is not prefixed twice', () => {
|
|
83
|
+
const scoped = scopeSvgIds('<svg><rect id="a"/><use href="#a"/></svg>', 'svg5-');
|
|
84
|
+
expect(scopeSvgIds(scoped, 'svg5-')).toBe(scoped);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('nextSvgScopePrefix', () => {
|
|
89
|
+
test('every call is a fresh, XML-name-safe prefix', () => {
|
|
90
|
+
const a = nextSvgScopePrefix();
|
|
91
|
+
const b = nextSvgScopePrefix();
|
|
92
|
+
expect(a).not.toBe(b);
|
|
93
|
+
expect(a).toMatch(/^svg\d+-$/);
|
|
94
|
+
// An id may not begin with a digit, so the prefix cannot either.
|
|
95
|
+
expect(a).toMatch(/^[A-Za-z_]/);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Give an SVG document its own id namespace.
|
|
8
|
+
*
|
|
9
|
+
* Two defects are one defect: an id namespace authored in isolation being
|
|
10
|
+
* shared with the page it is drawn into.
|
|
11
|
+
*
|
|
12
|
+
* 1. **DOMPurify DELETES an id the page already owns.** Its clobbering guard
|
|
13
|
+
* drops an `id`/`name` whose value is `in document` (`SANITIZE_DOM`, on by
|
|
14
|
+
* default), and `document.body`, `document.title` and friends are always in
|
|
15
|
+
* it. Measured in Chromium on a real app icon: the `<linearGradient
|
|
16
|
+
* id="body">` lost its id while `fill="url(#body)"` stayed, so the two
|
|
17
|
+
* shapes that gradient paints — the chicken's body and head — came out
|
|
18
|
+
* filled with the background's dark green instead of cream, and nothing was
|
|
19
|
+
* logged. Prefixing the id is what satisfies the guard. `SANITIZE_NAMED_PROPS`
|
|
20
|
+
* is NOT a substitute: it prefixes the declaration (`user-content-body`) and
|
|
21
|
+
* leaves `url(#body)` pointing at the old name, which is a worse break —
|
|
22
|
+
* measured, `urlRefRewritten: false`.
|
|
23
|
+
* 2. **Two previews share every definition.** `defs` ids are document-scoped,
|
|
24
|
+
* so the same icon opened twice — or a file reusing a name the app's own
|
|
25
|
+
* inline SVG already defines — silently resolves to the FIRST match, and the
|
|
26
|
+
* second picture paints with the first one's gradient.
|
|
27
|
+
*
|
|
28
|
+
* The rewrite is TEXT, deliberately: it runs on markup that has not been
|
|
29
|
+
* sanitized yet, and parsing untrusted SVG into the live document is the thing
|
|
30
|
+
* the sanitizer exists to prevent (a detached `<img src onerror>` still fires).
|
|
31
|
+
* Renaming a string cannot execute anything.
|
|
32
|
+
*
|
|
33
|
+
* Every reference form that can carry an id is rewritten with its declaration,
|
|
34
|
+
* because a rename that missed one would silently point at nothing: `url(#id)`
|
|
35
|
+
* (fill, stroke, filters, clip-path, mask, marker-*, and the same values inside
|
|
36
|
+
* a `<style>` block), `href`/`xlink:href`, `#id` selectors in a `<style>`
|
|
37
|
+
* block, and the ARIA idref lists. Bare-name references are NOT rewritten:
|
|
38
|
+
* SMIL's `begin="id.click"` would be one, and DOMPurify strips `<animate>`/`<set>`
|
|
39
|
+
* outright, so a rewrite there would invent a rule with no example.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/** An `id="…"` declaration, any quote style, any spacing around `=`. */
|
|
43
|
+
const ID_DECLARATION = /(\sid\s*=\s*)(["'])([^"']*)\2/g;
|
|
44
|
+
|
|
45
|
+
/** `url(#id)`, quoted or not — how a paint server, filter or clip is referenced. */
|
|
46
|
+
const URL_REFERENCE = /url\(\s*(["']?)#([A-Za-z_][\w-]*)\1\s*\)/g;
|
|
47
|
+
|
|
48
|
+
/** `href="#id"` / `xlink:href="#id"`: a same-document fragment ONLY. */
|
|
49
|
+
const HREF_FRAGMENT = /(\s(?:xlink:href|href)\s*=\s*)(["'])(#[^"']*)\2/g;
|
|
50
|
+
|
|
51
|
+
/** The ARIA attributes whose value is a whitespace-separated list of ids. */
|
|
52
|
+
const ARIA_IDREF =
|
|
53
|
+
/(\saria-(?:labelledby|describedby|controls|owns|flowto|activedescendant|details|errormessage)\s*=\s*)(["'])([^"']*)\2/g;
|
|
54
|
+
|
|
55
|
+
/** A `<style>` element, whose body is stylesheet text rather than markup. */
|
|
56
|
+
const STYLE_ELEMENT = /(<style\b[^>]*>)([\s\S]*?)(<\/style\s*>)/g;
|
|
57
|
+
|
|
58
|
+
/** One stylesheet rule, split so only the SELECTOR half is read for ids. */
|
|
59
|
+
const STYLE_RULE = /([^{}]*)\{([^{}]*)\}/g;
|
|
60
|
+
|
|
61
|
+
/** A `#name` token inside a selector. */
|
|
62
|
+
const SELECTOR_REFERENCE = /#([A-Za-z_][\w-]*)/g;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Prefix every id in `markup` with `prefix`, and rewrite the references that
|
|
66
|
+
* point at them.
|
|
67
|
+
*
|
|
68
|
+
* `prefix` must be unique in the page and XML-name safe (`svg3-`, not `3-`).
|
|
69
|
+
* Markup with no id is returned as the SAME string, so a caller can tell
|
|
70
|
+
* nothing was scoped.
|
|
71
|
+
*/
|
|
72
|
+
export function scopeSvgIds(markup: string, prefix: string): string {
|
|
73
|
+
if (!markup || !markup.includes('id')) return markup;
|
|
74
|
+
|
|
75
|
+
const renamed = new Map<string, string>();
|
|
76
|
+
for (const match of markup.matchAll(ID_DECLARATION)) {
|
|
77
|
+
const id = match[3];
|
|
78
|
+
if (id && !id.startsWith(prefix)) renamed.set(id, `${prefix}${id}`);
|
|
79
|
+
}
|
|
80
|
+
if (renamed.size === 0) return markup;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
markup
|
|
84
|
+
.replace(ID_DECLARATION, (all, head: string, quote: string, id: string) => {
|
|
85
|
+
const next = renamed.get(id);
|
|
86
|
+
return next ? `${head}${quote}${next}${quote}` : all;
|
|
87
|
+
})
|
|
88
|
+
.replace(URL_REFERENCE, (all, quote: string, name: string) => {
|
|
89
|
+
const next = renamed.get(name);
|
|
90
|
+
return next ? `url(${quote}#${next}${quote})` : all;
|
|
91
|
+
})
|
|
92
|
+
// Only a fragment is ours. `href="other.svg#id"` names an id in ANOTHER
|
|
93
|
+
// document, which this prefix has no authority over.
|
|
94
|
+
.replace(HREF_FRAGMENT, (all, head: string, quote: string, value: string) => {
|
|
95
|
+
const next = renamed.get(value.slice(1));
|
|
96
|
+
return next ? `${head}${quote}#${next}${quote}` : all;
|
|
97
|
+
})
|
|
98
|
+
.replace(ARIA_IDREF, (all, head: string, quote: string, value: string) => {
|
|
99
|
+
const next = value
|
|
100
|
+
.split(/\s+/)
|
|
101
|
+
.map((name) => renamed.get(name) ?? name)
|
|
102
|
+
.join(' ');
|
|
103
|
+
return next === value ? all : `${head}${quote}${next}${quote}`;
|
|
104
|
+
})
|
|
105
|
+
// A stylesheet's DECLARATIONS may hold `url(#id)`, already rewritten
|
|
106
|
+
// above; only its selector half can hold a bare `#id`. Reading the
|
|
107
|
+
// declaration half would rewrite a hex colour that happens to be shaped
|
|
108
|
+
// like a name (`fill:#abc` where an id `abc` exists).
|
|
109
|
+
.replace(STYLE_ELEMENT, (all, open: string, body: string, close: string) => {
|
|
110
|
+
const next = body.replace(STYLE_RULE, (rule, selector: string, declarations: string) => {
|
|
111
|
+
const rewritten = selector.replace(SELECTOR_REFERENCE, (token, name: string) => {
|
|
112
|
+
const mapped = renamed.get(name);
|
|
113
|
+
return mapped ? `#${mapped}` : token;
|
|
114
|
+
});
|
|
115
|
+
return rewritten === selector ? rule : `${rewritten}{${declarations}}`;
|
|
116
|
+
});
|
|
117
|
+
return next === body ? all : `${open}${next}${close}`;
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A prefix no other preview shares.
|
|
124
|
+
*
|
|
125
|
+
* A module counter, not `useId`: measured, two Preact roots mounted on one page
|
|
126
|
+
* both allocate `P0-0`, so two previews in two roots would collide on exactly
|
|
127
|
+
* the ids this exists to keep apart. A process counter cannot.
|
|
128
|
+
*/
|
|
129
|
+
let sequence = 0;
|
|
130
|
+
|
|
131
|
+
export function nextSvgScopePrefix(): string {
|
|
132
|
+
sequence += 1;
|
|
133
|
+
return `svg${sequence}-`;
|
|
134
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A custom accent is user input that ends up in a CSS `color`, so the only
|
|
8
|
+
* accepted shape is a hex colour and the only stored shape is lowercase
|
|
9
|
+
* six-digit. These cases pin both, plus the fact that the palette has no entry
|
|
10
|
+
* that is already the custom default (the picker would look like an eleventh
|
|
11
|
+
* preset).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
DEFAULT_CUSTOM_ACCENT,
|
|
18
|
+
PROJECT_ACCENT_OPTIONS,
|
|
19
|
+
isHexAccent,
|
|
20
|
+
normalizeHexAccent,
|
|
21
|
+
} from '@/shared/lib/workspace/project-accent';
|
|
22
|
+
|
|
23
|
+
describe('normalizeHexAccent', () => {
|
|
24
|
+
test('expands the short form and lowercases', () => {
|
|
25
|
+
expect(normalizeHexAccent('#ABC')).toBe('#aabbcc');
|
|
26
|
+
expect(normalizeHexAccent('#0F8')).toBe('#00ff88');
|
|
27
|
+
expect(normalizeHexAccent('#38BDF8')).toBe('#38bdf8');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('leaves a six-digit colour alone apart from case', () => {
|
|
31
|
+
expect(normalizeHexAccent('#7c3aed')).toBe('#7c3aed');
|
|
32
|
+
expect(normalizeHexAccent('#7C3AED')).toBe('#7c3aed');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('refuses everything that is not a hex colour', () => {
|
|
36
|
+
// A style value is not a colour: this is the injection the server now blocks.
|
|
37
|
+
for (const value of ['red', 'red;background:url(//x)', 'rgb(1,2,3)', '#1234', '#1234567', '7c3aed', '#gggggg', '', ' #fff']) {
|
|
38
|
+
expect(normalizeHexAccent(value)).toBeNull();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('isHexAccent', () => {
|
|
44
|
+
test('accepts only the stored form', () => {
|
|
45
|
+
expect(isHexAccent('#38bdf8')).toBe(true);
|
|
46
|
+
expect(isHexAccent('#ABC')).toBe(false);
|
|
47
|
+
expect(isHexAccent('')).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('the palette table', () => {
|
|
52
|
+
test('every preset is already in stored form', () => {
|
|
53
|
+
for (const option of PROJECT_ACCENT_OPTIONS) {
|
|
54
|
+
if (option.value === '') continue;
|
|
55
|
+
expect(normalizeHexAccent(option.value)).toBe(option.value);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('the custom default is not a preset', () => {
|
|
60
|
+
// Otherwise picking "custom" would highlight a swatch instead.
|
|
61
|
+
expect(PROJECT_ACCENT_OPTIONS.some((option) => option.value === DEFAULT_CUSTOM_ACCENT)).toBe(false);
|
|
62
|
+
expect(normalizeHexAccent(DEFAULT_CUSTOM_ACCENT)).toBe(DEFAULT_CUSTOM_ACCENT);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('None is the only empty entry, and it comes first', () => {
|
|
66
|
+
expect(PROJECT_ACCENT_OPTIONS.filter((option) => option.value === '')).toHaveLength(1);
|
|
67
|
+
expect(PROJECT_ACCENT_OPTIONS[0]?.value).toBe('');
|
|
68
|
+
});
|
|
69
|
+
});
|