move to biome (#297)
* switch to biome * writer format * migrate format * packages format * hudozka format * writer fix * biome config updated * migrate fix * packages fix * hudozka fix * claude updated
This commit is contained in:
1 parent
98dcaaa237
commit
467a218d00
112 files changed
+1472
-5914
No files matched your search
@@ -1,12 +1,12 @@
|
||||
import { Extension } from "@tiptap/core"
|
||||
import { PluginKey } from "@tiptap/pm/state"
|
||||
import type { Node as PmNode, ResolvedPos } from "@tiptap/pm/model"
|
||||
import { Fragment } from "@tiptap/pm/model"
|
||||
import type { ResolvedPos, Node as PmNode } from "@tiptap/pm/model"
|
||||
import { PluginKey } from "@tiptap/pm/state"
|
||||
import type { Editor } from "@tiptap/react"
|
||||
import type { SuggestionKeyDownProps, SuggestionOptions, SuggestionProps } from "@tiptap/suggestion"
|
||||
import Suggestion from "@tiptap/suggestion"
|
||||
import type { SuggestionOptions, SuggestionProps, SuggestionKeyDownProps } from "@tiptap/suggestion"
|
||||
import { createRoot } from "react-dom/client"
|
||||
import { generateBlockId } from "../lib/id"
|
||||
import type { Editor } from "@tiptap/react"
|
||||
import "./SlashCommands.css"
|
||||
|
||||
type SlashCommandItem = {
|
||||
@@ -34,13 +34,22 @@ function findTextBlockDepth($pos: ResolvedPos): number | null {
|
||||
return null
|
||||
}
|
||||
|
||||
function SlashMenu({ items, command, selectedIndex }: { items: SlashCommandItem[]; command: (item: SlashCommandItem) => void; selectedIndex: number }) {
|
||||
function SlashMenu({
|
||||
items,
|
||||
command,
|
||||
selectedIndex,
|
||||
}: {
|
||||
items: SlashCommandItem[]
|
||||
command: (item: SlashCommandItem) => void
|
||||
selectedIndex: number
|
||||
}) {
|
||||
if (items.length === 0) return null
|
||||
|
||||
return (
|
||||
<div className="slash-menu">
|
||||
{items.map((item, index) => (
|
||||
<button
|
||||
type="button"
|
||||
key={item.type}
|
||||
className={`slash-menu-item${index === selectedIndex ? " slash-menu-item--selected" : ""}`}
|
||||
onClick={() => command(item)}
|
||||
@@ -62,9 +71,7 @@ export const SlashCommands = Extension.create({
|
||||
pluginKey: slashCommandsPluginKey,
|
||||
startOfLine: true,
|
||||
items: ({ query }: { query: string }) => {
|
||||
return ITEMS.filter((item) =>
|
||||
item.label.toLowerCase().includes(query.toLowerCase())
|
||||
)
|
||||
return ITEMS.filter(item => item.label.toLowerCase().includes(query.toLowerCase()))
|
||||
},
|
||||
render: () => {
|
||||
let container: HTMLDivElement | null = null
|
||||
@@ -74,13 +81,9 @@ export const SlashCommands = Extension.create({
|
||||
let currentCommand: ((item: SlashCommandItem) => void) | null = null
|
||||
|
||||
function renderMenu() {
|
||||
if (!root) return
|
||||
if (!root || !currentCommand) return
|
||||
root.render(
|
||||
<SlashMenu
|
||||
items={currentItems}
|
||||
command={currentCommand!}
|
||||
selectedIndex={selectedIndex}
|
||||
/>
|
||||
<SlashMenu items={currentItems} command={currentCommand} selectedIndex={selectedIndex} />,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -153,7 +156,15 @@ export const SlashCommands = Extension.create({
|
||||
},
|
||||
}
|
||||
},
|
||||
command: ({ editor, range, props }: { editor: Editor; range: { from: number; to: number }; props: SlashCommandItem }) => {
|
||||
command: ({
|
||||
editor,
|
||||
range,
|
||||
props,
|
||||
}: {
|
||||
editor: Editor
|
||||
range: { from: number; to: number }
|
||||
props: SlashCommandItem
|
||||
}) => {
|
||||
// Delete the slash command text
|
||||
editor.chain().focus().deleteRange(range).run()
|
||||
|
||||
@@ -193,7 +204,7 @@ export const SlashCommands = Extension.create({
|
||||
if (curChild.content.size === 0 && i > 0) {
|
||||
splitAfter = i - 1
|
||||
} else if (curChild.content.size === 0 && i === 0) {
|
||||
splitAfter = -1 // cursor in empty first child
|
||||
splitAfter = -1 // cursor in empty first child
|
||||
} else {
|
||||
splitAfter = i
|
||||
}
|
||||
@@ -213,16 +224,14 @@ export const SlashCommands = Extension.create({
|
||||
children.push(textBlockNode.child(i))
|
||||
}
|
||||
// Skip if all children are empty paragraphs
|
||||
const hasContent = children.some((c) => c.content.size > 0)
|
||||
const hasContent = children.some(c => c.content.size > 0)
|
||||
if (hasContent) {
|
||||
fragments.push(textBlockType.create(null, children))
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the custom block
|
||||
fragments.push(schema.nodes[props.type].create(
|
||||
{ ...props.attrs, id },
|
||||
))
|
||||
fragments.push(schema.nodes[props.type].create({ ...props.attrs, id }))
|
||||
|
||||
// Build second textBlock (children after splitAfter) — skip empty
|
||||
const remaining = []
|
||||
@@ -231,7 +240,7 @@ export const SlashCommands = Extension.create({
|
||||
remaining.push(textBlockNode.child(i))
|
||||
}
|
||||
// Filter out empty paragraphs at the edges
|
||||
const nonEmpty = remaining.filter((c) => c.content.size > 0)
|
||||
const nonEmpty = remaining.filter(c => c.content.size > 0)
|
||||
if (nonEmpty.length > 0) {
|
||||
fragments.push(textBlockType.create(null, remaining))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user