Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: lexical json parse tool for blake (#119)

Seamusf7bfce1de0a5
diff --git a/js/app/packages/app/component/split-layout/componentRegistry.tsx b/js/app/packages/app/component/split-layout/componentRegistry.tsx
index 81b907a158..031e59b30e 100644
--- a/js/app/packages/app/component/split-layout/componentRegistry.tsx
+++ b/js/app/packages/app/component/split-layout/componentRegistry.tsx
@@ -39,15 +39,6 @@ if (LOCAL_ONLY) {
import('@core/component/LexicalMarkdown/component/debug/EditorTestPage')
)
);
- registerComponent(
- 'md-parse',
- lazy(
- () =>
- import(
- '@core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage'
- )
- )
- );
registerComponent(
'data',
lazy(() => import('@core/internal/DataDebug'))
@@ -96,4 +87,13 @@ if (DEV_MODE_ENV) {
'pixel-icon',
lazy(() => import('@core/internal/PixelArtIconDemo'))
);
+ registerComponent(
+ 'md-parse',
+ lazy(
+ () =>
+ import(
+ '@core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage'
+ )
+ )
+ );
}
diff --git a/js/app/packages/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx b/js/app/packages/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx
index 1cec46df48..dd47606dfb 100644
--- a/js/app/packages/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/component/debug/MarkdownParseTestPage.tsx
@@ -1,4 +1,5 @@
-import { Bar } from '@core/component/TopBar/Bar';
+import { SplitHeaderLeft } from '@app/component/split-layout/components/SplitHeader';
+import { StaticSplitLabel } from '@app/component/split-layout/components/SplitLabel';
import { debounce } from '@solid-primitives/scheduled';
import {
type Accessor,
@@ -20,7 +21,11 @@ import {
tabIndentationPlugin,
tablePlugin,
} from '../../plugins';
-import { editorIsEmpty, setEditorStateFromMarkdown } from '../../utils';
+import {
+ editorIsEmpty,
+ initializeEditorWithState,
+ setEditorStateFromMarkdown,
+} from '../../utils';
import { DecoratorRenderer } from '../core/DecoratorRenderer';
import { NodeAccessoryRenderer } from '../core/NodeAccessoryRenderer';
import { StaticMarkdown, StaticMarkdownContext } from '../core/StaticMarkdown';
@@ -29,6 +34,7 @@ const KEYS = {
content: 'internal-markdown-test-string',
outputType: 'internal-markdown-output-type',
targetType: 'internal-markdown-target-type',
+ inputType: 'internal-markdown-input-type',
};
const getSavedStringFromLocalStorage = () => {
@@ -61,9 +67,20 @@ const getSavedTargetType = (): 'internal' | 'external' | 'both' => {
return 'internal';
};
+const getSavedInputType = (): 'markdown' | 'lexical-json' => {
+ try {
+ const saved = localStorage.getItem(KEYS.inputType);
+ if (saved === 'markdown' || saved === 'lexical-json') {
+ return saved;
+ }
+ } catch (_) {}
+ return 'markdown';
+};
+
export function TestEditor(props: {
value: Accessor<string>;
target: Accessor<'internal' | 'external' | 'both'>;
+ inputType: Accessor<'markdown' | 'lexical-json'>;
}) {
let mountRef!: HTMLDivElement;
const lexicalWrapper = createLexicalWrapper({
@@ -72,17 +89,40 @@ export function TestEditor(props: {
isInteractable: () => true,
});
const { editor, plugins, cleanup: cleanupLexical } = lexicalWrapper;
- setEditorStateFromMarkdown(editor, props.value(), props.target());
- const debouncedUpdateMarkdown = debounce(
- (markdown: string, target: 'internal' | 'external' | 'both') => {
- setEditorStateFromMarkdown(editor, markdown, target);
+ const setEditorContent = (
+ content: string,
+ target: 'internal' | 'external' | 'both',
+ inputType: 'markdown' | 'lexical-json'
+ ) => {
+ if (inputType === 'lexical-json') {
+ try {
+ const parsed = JSON.parse(content);
+ initializeEditorWithState(editor, parsed);
+ } catch (error) {
+ console.error('Invalid JSON:', error);
+ }
+ } else {
+ setEditorStateFromMarkdown(editor, content, target);
+ }
+ };
+
+ setEditorContent(props.value(), props.target(), props.inputType());
+ const debouncedUpdateContent = debounce(
+ (
+ content: string,
+ target: 'internal' | 'external' | 'both',
+ inputType: 'markdown' | 'lexical-json'
+ ) => {
+ setEditorContent(content, target, inputType);
},
50
);
createEffect(() => {
const value = props.value();
- debouncedUpdateMarkdown(value, props.target());
+ const target = props.target();
+ const inputType = props.inputType();
+ debouncedUpdateContent(value, target, inputType);
});
const [showPlaceholder, setShowPlaceholder] = createSignal(true);
@@ -134,7 +174,7 @@ export function TestEditor(props: {
);
}
export default function MarkdownParseTestPage() {
- const [rawMarkdown, setRawMarkdown] = createSignal(
+ const [rawContent, setRawContent] = createSignal(
getSavedStringFromLocalStorage()
);
@@ -144,110 +184,149 @@ export default function MarkdownParseTestPage() {
const [targetType, setTargetType] = createSignal<
'internal' | 'external' | 'both'
>(getSavedTargetType());
+ const [inputType, setInputType] = createSignal<'markdown' | 'lexical-json'>(
+ getSavedInputType()
+ );
const debouncedLocalSave = debounce(() => {
- const markdown = rawMarkdown();
+ const content = rawContent();
const output = outputType();
const target = targetType();
+ const input = inputType();
try {
- localStorage.setItem(KEYS.content, markdown);
+ localStorage.setItem(KEYS.content, content);
localStorage.setItem(KEYS.outputType, output);
localStorage.setItem(KEYS.targetType, target);
+ localStorage.setItem(KEYS.inputType, input);
} catch (_) {}
});
createEffect(() => {
- rawMarkdown();
+ rawContent();
outputType();
targetType();
+ inputType();
debouncedLocalSave();
});
return (
- <div class="flex flex-col h-full w-full">
- <Bar
- left={<div class="p-2 text-sm w-2xl truncate">Markdown Parse Test</div>}
- center={<div></div>}
- ></Bar>
- <div class="w-full h-full flex">
- <div class="w-1/2 h-full p-4 flex flex-col border-r border-edge">
- <h2 class="text-sm mb-2">Input Markdown</h2>
- <textarea
- class="w-full h-full p-4 resize-none border border-edge rounded font-mono text-ink text-sm bg-input"
- placeholder="Test markdown here..."
- value={rawMarkdown()}
- onInput={(e) => setRawMarkdown(e.target.value)}
- spellcheck={false}
- />
- </div>
-
- <div class="w-1/2 h-full p-4 flex flex-col">
- <h2 class="text-sm mb-2">Output</h2>
- <div class="h-px bg-edge mb-2"></div>
-
- <div class="flex gap-16 mb-4">
- <div class="flex items-center gap-1">
- <span class="text-sm text-ink-extra-muted">Render as</span>
+ <>
+ <SplitHeaderLeft>
+ <StaticSplitLabel label="Lexical Parse Playground" />
+ </SplitHeaderLeft>
+ <div class="flex flex-col h-full w-full">
+ <div class="w-full h-full flex">
+ <div class="w-1/2 h-full p-4 flex flex-col border-r border-edge">
+ <div class="flex items-center gap-2 mb-2">
+ <h2 class="text-sm">Input</h2>
<div class="flex bg-edge/50 rounded border-1 border-edge overflow-hidden">
<button
- class={`px-3 py-1 text-sm ${outputType() === 'static' ? 'bg-accent text-panel' : ''} border-r-1 border-edge`}
- onClick={() => setOutputType('static')}
+ class={`px-2 py-0.5 text-xs ${inputType() === 'markdown' ? 'bg-accent text-panel' : ''} border-r-1 border-edge`}
+ onClick={() => setInputType('markdown')}
>
- Static
+ Markdown
</button>
<button
- class={`px-3 py-1 text-sm ${outputType() === 'editor' ? 'bg-accent text-panel' : ''}`}
- onClick={() => setOutputType('editor')}
+ class={`px-2 py-0.5 text-xs ${inputType() === 'lexical-json' ? 'bg-accent text-panel' : ''}`}
+ onClick={() => setInputType('lexical-json')}
>
- Editor
+ Lexical JSON
</button>
</div>
</div>
+ <textarea
+ class="w-full h-full p-4 resize-none border border-edge rounded font-mono text-ink text-sm bg-input"
+ placeholder={
+ inputType() === 'markdown'
+ ? 'Test markdown here...'
+ : 'Test lexical JSON here...'
+ }
+ value={rawContent()}
+ onInput={(e) => setRawContent(e.target.value)}
+ spellcheck={false}
+ />
+ </div>
- <div class="flex items-center gap-2">
- <span class="text-sm text-ink-extra-muted">Target</span>
- <div class="flex bg-edge/50 rounded border-1 border-edge overflow-hidden">
- <button
- class={`px-3 py-1 text-sm ${targetType() === 'internal' ? 'bg-accent text-panel' : ''} border-r-1 border-edge`}
- onClick={() => setTargetType('internal')}
- >
- Internal
- </button>
- <button
- class={`px-3 py-1 text-sm ${targetType() === 'external' ? 'bg-accent text-panel' : ''}`}
- onClick={() => setTargetType('external')}
- >
- External
- </button>
- <button
- class={`px-3 py-1 text-sm ${targetType() === 'both' ? 'bg-accent text-panel' : ''}`}
- onClick={() => setTargetType('both')}
- >
- Both
- </button>
+ <div class="w-1/2 h-full p-4 flex flex-col">
+ <h2 class="text-sm mb-2">Output</h2>
+ <div class="h-px bg-edge mb-2"></div>
+
+ <div class="flex gap-16 mb-4">
+ <div class="flex items-center gap-1">
+ <span class="text-sm text-ink-extra-muted">Render as</span>
+ <div class="flex bg-edge/50 rounded border-1 border-edge overflow-hidden">
+ <button
+ class={`px-3 py-1 text-sm ${outputType() === 'static' ? 'bg-accent text-panel' : ''} border-r-1 border-edge`}
+ onClick={() => setOutputType('static')}
+ >
+ Static
+ </button>
+ <button
+ class={`px-3 py-1 text-sm ${outputType() === 'editor' ? 'bg-accent text-panel' : ''}`}
+ onClick={() => setOutputType('editor')}
+ >
+ Editor
+ </button>
+ </div>
</div>
- </div>
- </div>
- <div class="flex-1 overflow-auto bg-input border border-edge rounded p-4">
- <Show when={outputType() === 'static'}>
- <StaticMarkdownContext>
- <StaticMarkdown
- markdown={rawMarkdown()}
- target={targetType()}
- />
- </StaticMarkdownContext>
- </Show>
-
- <Show when={outputType() === 'editor'}>
- <div class="overflow-auto min-h-8 h-full relative">
- <TestEditor value={rawMarkdown} target={targetType} />
+ <div class="flex items-center gap-2">
+ <span class="text-sm text-ink-extra-muted">Target</span>
+ <div class="flex bg-edge/50 rounded border-1 border-edge overflow-hidden">
+ <button
+ class={`px-3 py-1 text-sm ${targetType() === 'internal' ? 'bg-accent text-panel' : ''} border-r-1 border-edge`}
+ onClick={() => setTargetType('internal')}
+ >
+ Internal
+ </button>
+ <button
+ class={`px-3 py-1 text-sm ${targetType() === 'external' ? 'bg-accent text-panel' : ''}`}
+ onClick={() => setTargetType('external')}
+ >
+ External
+ </button>
+ <button
+ class={`px-3 py-1 text-sm ${targetType() === 'both' ? 'bg-accent text-panel' : ''}`}
+ onClick={() => setTargetType('both')}
+ >
+ Both
+ </button>
+ </div>
</div>
- </Show>
+ </div>
+
+ <div class="flex-1 overflow-auto bg-input border border-edge rounded p-4">
+ <Show when={outputType() === 'static'}>
+ <StaticMarkdownContext>
+ <Show when={inputType() === 'markdown'}>
+ <StaticMarkdown
+ markdown={rawContent()}
+ target={targetType()}
+ />
+ </Show>
+ <Show when={inputType() === 'lexical-json'}>
+ <div class="text-ink-muted text-sm">
+ Static rendering not supported for Lexical JSON input. Use
+ Editor output to view JSON content.
+ </div>
+ </Show>
+ </StaticMarkdownContext>
+ </Show>
+
+ <Show when={outputType() === 'editor'}>
+ <div class="overflow-auto min-h-8 h-full relative">
+ <TestEditor
+ value={rawContent}
+ target={targetType}
+ inputType={inputType}
+ />
+ </div>
+ </Show>
+ </div>
</div>
</div>
</div>
- </div>
+ </>
);
}