Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ test("emits warnings for modules that couldn't be imported locally", async () =>
});

test("emits warnings for modules that couldn't be imported via http", async () => {
const fetchMock = vi.fn().mockRejectedValue(new TypeError("network error"));
vi.stubGlobal("fetch", fetchMock);

const project = await loadProjectInMemory({
blob: await newProject({
settings: {
Expand All @@ -389,8 +392,6 @@ test("emits warnings for modules that couldn't be imported via http", async () =
consola.mockTypes(() => mock);

const fs = memfs().fs as unknown as typeof import("node:fs");
const fetchMock = vi.fn().mockRejectedValue(new TypeError("network error"));
vi.stubGlobal("fetch", fetchMock);

const errorsSpy = vi.spyOn(project.errors, "get").mockResolvedValue([
{
Expand Down
9 changes: 2 additions & 7 deletions packages/flashtype/src/app/import-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,12 @@ export async function importFile({
},
focus: true,
});

}

/**
* Imports content from the clipboard as a new file.
*/
export async function importFromClipboard(
context: ViewContext,
): Promise<void> {
export async function importFromClipboard(context: ViewContext): Promise<void> {
const content = await navigator.clipboard.readText();

if (!content?.trim()) {
Expand All @@ -122,9 +119,7 @@ export async function importFromClipboard(
/**
* Opens a file picker and imports the selected file.
*/
export async function importFromComputer(
context: ViewContext,
): Promise<void> {
export async function importFromComputer(context: ViewContext): Promise<void> {
const input = document.createElement("input");
input.type = "file";
input.accept = ".md,.txt,.markdown";
Expand Down
8 changes: 6 additions & 2 deletions packages/flashtype/src/views/agent-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,9 @@ export function AgentView({ context, instance }: AgentViewProps) {
<div className="w-full max-w-3xl mx-auto flex flex-col gap-4">
{hasKey ? (
<>
{(!messages || messages.length === 0) && !pending && !pendingMessage ? (
{(!messages || messages.length === 0) &&
!pending &&
!pendingMessage ? (
<AgentEmptyState />
) : (
<>
Expand All @@ -796,7 +798,9 @@ export function AgentView({ context, instance }: AgentViewProps) {
</div>
) : null}
{error ? (
<div className="px-3 py-1 text-xs text-rose-500">{error}</div>
<div className="px-3 py-1 text-xs text-rose-500">
{error}
</div>
) : null}
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export function FormattingToolbar({ className }: { className?: string }) {
const handleBlockChange = useCallback(
(value: ToolbarBlockType) => {
if (!editor) return;
const option = TOOLBAR_BLOCK_OPTIONS.find((entry) => entry.value === value);
const option = TOOLBAR_BLOCK_OPTIONS.find(
(entry) => entry.value === value,
);
option?.apply(editor);
setBlockMenuOpen(false);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import {
slashCommandsPluginKey,
type SlashCommandState,
} from "../editor/extensions/slash-commands";
import { SLASH_BLOCK_COMMANDS, type BlockCommand } from "../editor/block-commands";

function filterCommands(commands: BlockCommand[], query: string): BlockCommand[] {
import {
SLASH_BLOCK_COMMANDS,
type BlockCommand,
} from "../editor/block-commands";

function filterCommands(
commands: BlockCommand[],
query: string,
): BlockCommand[] {
if (!query) return commands;
const lowerQuery = query.toLowerCase();
return commands.filter(
(cmd) =>
cmd.label.toLowerCase().includes(lowerQuery) ||
cmd.keywords.some((kw) => kw.toLowerCase().includes(lowerQuery))
cmd.keywords.some((kw) => kw.toLowerCase().includes(lowerQuery)),
);
}

Expand All @@ -34,7 +40,7 @@ export function SlashCommandMenu() {

const filteredCommands = useMemo(
() => filterCommands(SLASH_BLOCK_COMMANDS, slashState.query),
[slashState.query]
[slashState.query],
);

// Reset selection when filtered list changes
Expand Down Expand Up @@ -132,14 +138,14 @@ export function SlashCommandMenu() {
// Execute the command insert action
command.insert(editor);
},
[editor]
[editor],
);

const handleItemClick = useCallback(
(command: BlockCommand) => {
executeCommand(command);
},
[executeCommand]
[executeCommand],
);

// Handle keyboard navigation
Expand All @@ -150,15 +156,15 @@ export function SlashCommandMenu() {
if (event.key === "ArrowDown") {
event.preventDefault();
setSelectedIndex((prev) =>
prev < filteredCommands.length - 1 ? prev + 1 : 0
prev < filteredCommands.length - 1 ? prev + 1 : 0,
);
return;
}

if (event.key === "ArrowUp") {
event.preventDefault();
setSelectedIndex((prev) =>
prev > 0 ? prev - 1 : filteredCommands.length - 1
prev > 0 ? prev - 1 : filteredCommands.length - 1,
);
return;
}
Expand All @@ -180,13 +186,19 @@ export function SlashCommandMenu() {

window.addEventListener("keydown", handleKeyDown, true);
return () => window.removeEventListener("keydown", handleKeyDown, true);
}, [slashState.active, editor, filteredCommands, selectedIndex, executeCommand]);
}, [
slashState.active,
editor,
filteredCommands,
selectedIndex,
executeCommand,
]);

// Scroll selected item into view
useEffect(() => {
if (!menuRef.current) return;
const selectedEl = menuRef.current.querySelector(
`[data-index="${selectedIndex}"]`
`[data-index="${selectedIndex}"]`,
);
if (selectedEl) {
selectedEl.scrollIntoView({ block: "nearest" });
Expand Down Expand Up @@ -241,11 +253,14 @@ export function SlashCommandMenu() {
onMouseEnter={() => setSelectedIndex(index)}
tabIndex={0}
>
<command.icon className="size-4 shrink-0 text-muted-foreground" aria-hidden />
<command.icon
className="size-4 shrink-0 text-muted-foreground"
aria-hidden
/>
<span>{command.label}</span>
</div>
))}
</div>,
document.body
document.body,
);
}
35 changes: 23 additions & 12 deletions packages/flashtype/src/views/markdown-view/editor/block-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,19 @@ export const BLOCK_COMMANDS: BlockCommand[] = [
}
rows.push({ type: "tableRow", content: cells });
}
editor.chain().focus().insertContent({ type: "table", content: rows }).run();
editor
.chain()
.focus()
.insertContent({ type: "table", content: rows })
.run();
},
},
];

/** Block commands that can be used in the toolbar (have toggle action) */
export const TOOLBAR_BLOCK_COMMANDS = BLOCK_COMMANDS.filter((cmd) => cmd.toggle);
export const TOOLBAR_BLOCK_COMMANDS = BLOCK_COMMANDS.filter(
(cmd) => cmd.toggle,
);

/** All block commands for slash menu */
export const SLASH_BLOCK_COMMANDS = BLOCK_COMMANDS;
Expand Down Expand Up @@ -214,17 +220,22 @@ const idToToolbarValue: Record<string, ToolbarBlockType> = {
};

/** Toolbar-specific label overrides (where different from slash menu) */
const toolbarLabelOverrides: Record<string, { label: string; description: string }> = {
const toolbarLabelOverrides: Record<
string,
{ label: string; description: string }
> = {
codeBlock: { label: "Code", description: "Code block" },
};

/** Block options formatted for toolbar dropdown */
export const TOOLBAR_BLOCK_OPTIONS: ToolbarBlockOption[] = TOOLBAR_BLOCK_COMMANDS
.filter((cmd) => idToToolbarValue[cmd.id])
.map((cmd) => ({
value: idToToolbarValue[cmd.id]!,
label: toolbarLabelOverrides[cmd.id]?.label ?? cmd.label,
description: toolbarLabelOverrides[cmd.id]?.description ?? cmd.description,
icon: cmd.icon,
apply: cmd.toggle!,
}));
export const TOOLBAR_BLOCK_OPTIONS: ToolbarBlockOption[] =
TOOLBAR_BLOCK_COMMANDS.filter((cmd) => idToToolbarValue[cmd.id]).map(
(cmd) => ({
value: idToToolbarValue[cmd.id]!,
label: toolbarLabelOverrides[cmd.id]?.label ?? cmd.label,
description:
toolbarLabelOverrides[cmd.id]?.description ?? cmd.description,
icon: cmd.icon,
apply: cmd.toggle!,
}),
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare module "@tiptap/core" {
}

export const slashCommandsPluginKey = new PluginKey<SlashCommandState>(
"slashCommands"
"slashCommands",
);

export type SlashCommandState = {
Expand Down Expand Up @@ -90,7 +90,7 @@ export const SlashCommandsExtension = Extension.create<SlashCommandsOptions>({
0,
$from.parentOffset,
undefined,
"\ufffc"
"\ufffc",
);

// Find the last "/" in the text before cursor
Expand Down Expand Up @@ -164,7 +164,9 @@ export const SlashCommandsExtension = Extension.create<SlashCommandsOptions>({
if (state?.active) {
// Close the menu
this.editor.view.dispatch(
this.editor.state.tr.setMeta(slashCommandsPluginKey, { close: true })
this.editor.state.tr.setMeta(slashCommandsPluginKey, {
close: true,
}),
);
return true;
}
Expand Down Expand Up @@ -194,7 +196,7 @@ export const SlashCommandsExtension = Extension.create<SlashCommandsOptions>({
dispatch(
tr
.delete(pluginState.range.from, pluginState.range.to)
.setMeta(slashCommandsPluginKey, { close: true })
.setMeta(slashCommandsPluginKey, { close: true }),
);
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion packages/lix/html-diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tailwindcss/postcss": "^4.1.10",
"@types/react": "^19.0.12",
"@types/react-dom": "^19.0.4",
"entities": "2.2.0",
"dedent": "1.5.1",
"prettier": "^3.5.1",
"react": "^19.1.0",
Expand All @@ -45,6 +46,6 @@
},
"dependencies": {
"diff": "^8.0.2",
"parse5": "^7.3.0"
"parse5": "^8.0.0"
}
}
Loading