feat(web): use the Ace JSON editor everywhere, and restore the raw-JSON toggle
Extracts the Ace integration #2094 carried inline into a shared `elements/JsonEditor`, and renders it on every surface where the web client types or displays JSON. The element is deliberately text in, text out. The two editing contracts above it disagree about what an unparseable draft means — JsonObjectInput keeps the last valid object and says nothing to its parent, SchemaJsonField reports `undefined` and blocks submission (#2020) — so parsing, and the draft/value split that goes with it, stays with each caller. Surfaces: SchemaJsonField (inherited by all four SchemaForm consumers), a new "Edit as JSON" switch for the whole arguments object, the server.json File Contents box, the raw JSON-RPC request box, ContentViewer's JSON branch (read-only, inherited by its eleven consumers), and a new "Edit and replay" modal on a Protocol entry. Ace read-only replaces the CodeHighlight JSON path and the Prism `json` grammar loader is dropped: folding, not colorization, is what it adds, and two highlighters for one language drift. `wrap={false}` callers and untyped text that only looks like JSON keep the plain renderer. Closes #2151 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UL9retfvAXRgvi6EWk4SY4 Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
95db736a55
commit
1a2a36f0b8
1 changed files with 2026 additions and 448 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { act } from "@testing-library/react";
|
||||
import { act, screen } from "@testing-library/react";
|
||||
import type { Ace } from "ace-builds";
|
||||
|
||||
/**
|
||||
|
|
@ -56,3 +56,40 @@ export async function setAceText(
|
|||
export function aceLabel(label: string): RegExp {
|
||||
return new RegExp(label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The editor whose accessible name matches `label`, for a screen holding more
|
||||
* than one — a form with two JSON fields, or a JSON field beside the
|
||||
* raw-arguments editor.
|
||||
*
|
||||
* Goes via the labelled text input rather than indexing `.ace_editor` nodes,
|
||||
* because document order is not something a test should depend on: adding a
|
||||
* field above the one under test would silently retarget every assertion.
|
||||
*/
|
||||
export function getAceEditorByLabel(label: string | RegExp): Ace.Editor {
|
||||
const input = screen.getByLabelText(
|
||||
typeof label === "string" ? aceLabel(label) : label,
|
||||
);
|
||||
const container = input.closest(".ace_editor");
|
||||
const editor = (
|
||||
container as (HTMLElement & { env?: { editor?: Ace.Editor } }) | null
|
||||
)?.env?.editor;
|
||||
if (!editor) throw new Error(`No Ace editor labelled ${String(label)}`);
|
||||
return editor;
|
||||
}
|
||||
|
||||
/** {@link getAceText} for one of several editors. */
|
||||
export function getAceTextByLabel(label: string | RegExp): string {
|
||||
return getAceEditorByLabel(label).getValue();
|
||||
}
|
||||
|
||||
/** {@link setAceText} for one of several editors. */
|
||||
export async function setAceTextByLabel(
|
||||
label: string | RegExp,
|
||||
text: string,
|
||||
): Promise<void> {
|
||||
const editor = getAceEditorByLabel(label);
|
||||
await act(async () => {
|
||||
editor.setValue(text, 1);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue