-
Notifications
You must be signed in to change notification settings - Fork 0
feat(configurator): unified value editor + grouped undo (UX redesign, phase 5) #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <script lang="ts"> | ||
| import type { SlashedToken } from '../../types'; | ||
| import type { VarOption } from '../../lib/variableScales'; | ||
| import { detectMode, type ValueMode } from '../../lib/valueField'; | ||
|
|
||
| let { token, overrideValue, onSet, onReset, scaleOptions = [] }: { | ||
| token: SlashedToken; | ||
| overrideValue?: string; | ||
| onSet: (value: string) => void; | ||
| onReset: () => void; | ||
| /** Sibling scale steps offered as quick "relink" targets in Inherit mode. */ | ||
| scaleOptions?: VarOption[]; | ||
| } = $props(); | ||
|
|
||
| // Auto-detect the mode from the current value; a user tab-click overrides it | ||
| // until the value changes underneath (mirrors SliderRow's manualView idea). | ||
| // Crucially, an expression override always resolves to 'expression' mode, so | ||
| // a var()/calc() is shown verbatim and never silently parsed to a number. | ||
| let manualMode = $state<ValueMode | null>(null); | ||
| let mode = $derived<ValueMode>(manualMode ?? detectMode(overrideValue)); | ||
|
|
||
| let draft = $state(""); | ||
| let editing = $state(false); | ||
| let cancelling = $state(false); | ||
| // Reset a user-selected tab when another surface changes this token. | ||
| $effect(() => { | ||
| overrideValue; | ||
| manualMode = null; | ||
| }); | ||
| // Seed the text field from the live value whenever we're not mid-edit. | ||
| $effect(() => { | ||
| if (!editing) draft = overrideValue ?? token.value ?? ""; | ||
| }); | ||
|
|
||
| const RELINK = "__sf_relink__"; | ||
|
|
||
| function commit(raw: string) { | ||
| const v = raw.trim(); | ||
| if (!v || v === token.value) onReset(); | ||
| else onSet(v); | ||
| } | ||
|
|
||
| function setMode(m: ValueMode) { | ||
| manualMode = m; | ||
| if (m === "inherit") { onReset(); manualMode = null; } | ||
| } | ||
|
|
||
| const TABS: { id: ValueMode; label: string }[] = [ | ||
| { id: "inherit", label: "Inherit" }, | ||
| { id: "value", label: "Value" }, | ||
| { id: "expression", label: "Expression" }, | ||
| ]; | ||
| </script> | ||
|
|
||
| <div class="space-y-1"> | ||
| <!-- Mode tabs --> | ||
| <div class="flex items-center gap-0.5 p-0.5 rounded-md bg-black/5 dark:bg-white/5 w-fit"> | ||
| {#each TABS as t (t.id)} | ||
| <button | ||
| onclick={() => setMode(t.id)} | ||
| aria-pressed={mode === t.id} | ||
| class={`px-1.5 py-0.5 rounded text-[9px] font-bold transition-colors cursor-pointer ${ | ||
| mode === t.id | ||
| ? "bg-white dark:bg-slate-700 text-indigo-700 dark:text-indigo-300 shadow-sm" | ||
| : "text-slate-500 hover:text-slate-700 dark:hover:text-slate-300" | ||
| }`} | ||
| >{t.label}</button> | ||
| {/each} | ||
| </div> | ||
|
|
||
| {#if mode === "inherit"} | ||
| <div class="text-[10px] font-mono text-slate-500 dark:text-slate-500"> | ||
| default: <span class="text-slate-600 dark:text-slate-400">{token.value}</span> | ||
| </div> | ||
| {#if scaleOptions.length > 0} | ||
| <select | ||
| value={RELINK} | ||
| aria-label={`Relink ${token.name}`} | ||
| onchange={(e) => { | ||
| const v = (e.target as HTMLSelectElement).value; | ||
| if (v !== RELINK) onSet(v); | ||
| (e.target as HTMLSelectElement).value = RELINK; | ||
| }} | ||
| class="w-full bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded px-1.5 py-1 text-[10px] font-mono text-slate-700 dark:text-slate-300 focus:outline-none focus:border-indigo-500 cursor-pointer" | ||
| > | ||
| <option value={RELINK}>Relink to a scale step…</option> | ||
| {#each scaleOptions as o (o.value)} | ||
| <option value={o.value}>{o.label}</option> | ||
| {/each} | ||
| </select> | ||
| {/if} | ||
| {:else} | ||
| <!-- Value and Expression share a text field. The distinction is intent: | ||
| Value is a literal you type; Expression is a var()/calc() shown as-is. | ||
| Neither ever rewrites the other silently — switching is a tab click. --> | ||
| <input | ||
| type="text" | ||
| value={draft} | ||
| spellcheck="false" | ||
| placeholder={mode === "expression" ? "var(--sf-…) / calc(…)" : token.value} | ||
| onfocus={() => { editing = true; }} | ||
| oninput={(e) => { draft = (e.target as HTMLInputElement).value; }} | ||
| onblur={(e) => { | ||
| editing = false; | ||
| if (cancelling) { cancelling = false; return; } | ||
| commit((e.target as HTMLInputElement).value); | ||
| }} | ||
| onkeydown={(e) => { | ||
| if (e.key === "Enter") (e.currentTarget as HTMLInputElement).blur(); | ||
| if (e.key === "Escape") { | ||
| cancelling = true; | ||
| editing = false; | ||
| draft = overrideValue ?? token.value ?? ""; | ||
| (e.currentTarget as HTMLInputElement).blur(); | ||
| } | ||
| }} | ||
| class="w-full bg-black/8 dark:bg-white/8 border border-black/10 dark:border-white/10 rounded px-1.5 py-1 text-[10px] font-mono text-slate-800 dark:text-slate-200 focus:outline-none focus:border-indigo-500" | ||
| /> | ||
| {/if} | ||
| </div> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user selects a manual mode and the token's override later changes through undo, redo, theme application, import, or another editor surface,
manualModecontinues to overridedetectMode. A restoredvar()orcalc()expression therefore remains displayed as Value and can be overwritten without the deliberate mode switch promised by this editor.