@witchcraft/editor
    Preparing search index...

    A partial implementation of IFileInsertHandler.

    To use it extend it and define the saveFile and generatePreview methods. Everything else has a default implementation (but they can be overridden as needed).

    To use a custom id generation strategy, override generateId.

    Type Parameters

    • TFile extends File = File
    • TAttrs extends Record<string, unknown> = Record<string, unknown>
    • T extends { attrs: TAttrs; file: TFile; previewSrc?: string } = { attrs: TAttrs; file: TFile; previewSrc?: string }

    Hierarchy (View Summary)

    Implements

    Index
    • Type Parameters

      • TFile extends File = File
      • TAttrs extends Record<string, unknown> = Record<string, unknown>
      • T extends { attrs: TAttrs; file: TFile; previewSrc?: string } = { attrs: TAttrs; file: TFile; previewSrc?: string }

      Returns FileInsertHandler<TFile, TAttrs, T>

    insertionBatch: Map<string, BatchEntry> = ...

    Maps insert IDs to their batch info for position adjustment during concurrent replacements.

    • Adjust the insert position based on batch info. Looks up batch info from insertionBatch and scans for sibling files from the same batch, returning the correct position.

      Parameters

      • doc: Node
      • pos: number
      • id: string

      Returns number

    • Return the file (or whatever type you'd like) to allow the extension to handle it.

      If the function doesn't return anything, the file will be ignored. No placeholder will be created. The event will still be preventDefaulted.

      This can be used to filter out mime types you can't handle with a library like mime. Mime type filtering is not handled by the extension since it can be complicated.

      Parameters

      • file: File

      Returns TFile | undefined

    • Generate a preview for the placeholder widget before saving starts.

      If a preview is returned, it should be used to update the placeholder widget immediately, allowing the user to see a preview image as the file saves. It should also be passed to saveFile.

      Parameters

      • _file: TFile
      • _id: string
      • _editor: Editor

      Returns Promise<string | undefined>

    • Adds a widget decoration at the insert position. Uses generateId for the loading id.

      Parameters

      • file: TFile
      • editor: Editor
      • insertPos: number
      • Optional_originalPos: number

      Returns string

    • Orchestrates the entire file insertion lifecycle: filter, insert placeholders, save files concurrently, replace placeholders, and cleanup batch maps.

      This is what the insertFiles command calls internally.

      Parameters

      • files: File[]
      • editor: Editor
      • Optionalpos: number

      Returns Promise<void>

    • Return the position if it's inline, otherwise finds position after the closest parent item node.

      Parameters

      • _file: TFile
      • editor: Editor
      • Optionalpos: number

      Returns number | undefined

    • Removes the placeholder decoration by id.

      Parameters

      • _file: TFile
      • editor: Editor
      • _pos: number | undefined
      • _error: Error
      • id: string

      Returns void

    • Replace a placeholder decoration with a file node.

      Handles both inline (replace at position) and block (replace paragraph content) contexts.

      Parameters

      • editor: Editor
      • pos: number
      • attrs: Record<string, unknown>
      • id: string

      Returns void

    • Should load/save/upload the file and return the node attributes.

      The attrs object returned should be spread onto the file node. The previewSrc is the result of generatePreview.

      The id and editor are provided in case you're uploading the file or doing some other heavy operation and want to update the placeholder as soon as you can upload the file.

      Parameters

      • _file: TFile
      • _id: string
      • _editor: Editor
      • _previewSrc: string | undefined

      Returns Promise<T | undefined>