Quellcode durchsuchen

fix(editor): resolve type errors blocking CI build

- Add @enesis/editor tsconfig path alias for vue-tsc resolution
- Remove unused imports (TextSelection, CloseReason) from Block.vue
- Fix view null-safety, cursorPosition watch type, content undefined guard
- Fix PatternSpec type with satisfies + narrow casts
- Fix taskState type (string → TaskState)
Zander Hawke vor 1 Woche
Ursprung
Commit
e8fd55e1d0

+ 2 - 1
apps/dev/tsconfig.app.json

@@ -12,7 +12,8 @@
 
     "paths": {
       "#build/ui/*": ["./node_modules/.nuxt-ui/ui/*"],
-      "~/*": ["./src/*"]
+      "~/*": ["./src/*"],
+      "@enesis/editor": ["../../packages/editor/src/index.ts"]
     }
   },
   "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]

+ 7 - 15
packages/editor/src/components/Block.vue

@@ -1,11 +1,7 @@
 <script setup lang="ts">
 import { watchDebounced } from "@vueuse/core"
-import {
-  EditorState,
-  Selection,
-  TextSelection,
-  type Transaction,
-} from "prosemirror-state"
+import { EditorState, Selection, type Transaction } from "prosemirror-state"
+import { schema } from "../lib/schema"
 import { EditorView } from "prosemirror-view"
 import { onMounted, onUnmounted, useTemplateRef, watch } from "vue"
 import { createBlockKeyboardHandler } from "../composables/useBlockKeyboardHandlers"
@@ -15,7 +11,6 @@ import {
 } from "../composables/useMarkdownDecorations"
 import { createPatternPlugin } from "../composables/usePatternPlugin"
 import type {
-  CloseReason,
   PatternClosePayload,
   PatternOpenPayload,
   PatternUpdatePayload,
@@ -125,14 +120,11 @@ function focusAt(cursorPosition?: "start" | "end" | number) {
   if (!view) return
   const doc = view.state.doc
 
-  // Helper: safely create a selection at the given position.
-  // Uses Selection.near() to avoid crashes when position falls on
-  // node boundaries (e.g., between paragraphs). TextSelection.create()
-  // throws fatal errors on non-textblock positions.
+  const v = view
   const setSafeSelection = (pos: number) => {
     const resolved = doc.resolve(pos)
     const safeSelection = Selection.near(resolved)
-    view.dispatch(view.state.tr.setSelection(safeSelection))
+    v.dispatch(v.state.tr.setSelection(safeSelection))
   }
 
   if (cursorPosition === "start") {
@@ -337,10 +329,10 @@ onUnmounted(() => {
 })
 
 watch(
-  () => [props.focused, props.cursorPosition],
+  () => [props.focused, props.cursorPosition] as const,
   ([focused, cursorPosition]) => {
     if (!view) return
-    setDecorationsFocus(!!focused)
+    setDecorationsFocus(focused)
     view.dispatch(view.state.tr)
     if (focused) focusAt(cursorPosition)
   },
@@ -358,7 +350,7 @@ watch(
 watchDebounced(
   () => content.value,
   (newContent) => {
-    if (!view) return
+    if (!view || newContent === undefined) return
     const currentContent = docToContent(view.state.doc)
     if (currentContent === newContent) return
 

+ 19 - 9
packages/editor/src/composables/usePatternPlugin.ts

@@ -31,24 +31,34 @@ export interface PatternSpec {
   priority?: number
 }
 
-const PATTERN_SPECS: PatternSpec[] = [
+const PATTERN_SPECS = [
   {
     start: "[[",
     end: "]]",
-    kind: "reference",
-    termination: "delimiter",
+    kind: "reference" as PatternKind,
+    termination: "delimiter" as Termination,
     priority: 3,
   },
   {
     start: "((",
     end: "))",
-    kind: "embed",
-    termination: "delimiter",
+    kind: "embed" as PatternKind,
+    termination: "delimiter" as Termination,
     priority: 3,
   },
-  { start: "/", kind: "command", termination: "boundary", priority: 2 },
-  { start: "#", kind: "tag", termination: "boundary", priority: 1 },
-].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0))
+  {
+    start: "/",
+    kind: "command" as PatternKind,
+    termination: "boundary" as Termination,
+    priority: 2,
+  },
+  {
+    start: "#",
+    kind: "tag" as PatternKind,
+    termination: "boundary" as Termination,
+    priority: 1,
+  },
+].sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)) satisfies PatternSpec[]
 
 export interface PatternSession {
   id: string
@@ -96,7 +106,7 @@ export interface PatternCallbacks {
 export const patternPluginKey = new PluginKey<PatternSession | null>("pattern")
 
 export function getPatternSession(state: EditorState): PatternSession | null {
-  return patternPluginKey.getState(state)
+  return patternPluginKey.getState(state) ?? null
 }
 const forceCloseMetaKey = "pattern-force-close"
 

+ 2 - 1
packages/editor/src/lib/markdown-rules/block-rules.ts

@@ -16,6 +16,7 @@ import type {
   BlockRule,
   CalloutType,
   ParseContext,
+  TaskState,
 } from "./types"
 
 const CALLOUT_TYPES: ReadonlySet<string> = new Set([
@@ -195,7 +196,7 @@ export function createTaskRule(): BlockRule {
       while (contentStart < node.to && ctx.doc[contentStart] === " ") {
         contentStart++
       }
-      const taskState = stateText.toUpperCase()
+      const taskState = stateText.toUpperCase() as TaskState
       return {
         type: "task",
         wrapperAttrs: { "data-task-state": taskState },