Automerge backed Markdown editor for the Atmosphere
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import { Annotation, type ChangeSpec, type Transaction } from '@codemirror/state'
export type CoreInlineSpecName = 'bold' | 'italic' | 'strike' | 'inline-code'export type InlineSemanticSpecName = CoreInlineSpecName | (string & {})
export type InlineSemanticMarkOp = | { readonly kind: 'add-mark' readonly specName: InlineSemanticSpecName readonly range: { readonly start: number; readonly end: number } readonly attrs: unknown } | { readonly kind: 'unmark' readonly specName: InlineSemanticSpecName readonly range: { readonly start: number; readonly end: number } } | { readonly kind: 'synthesize-paste' readonly range: { readonly start: number; readonly end: number } }
export interface InlineSemanticChange { readonly ops: ReadonlyArray<InlineSemanticMarkOp>}
export interface InlineSemanticTextChange { readonly from: number readonly to: number readonly insert: string}
const CORE_INLINE_SPEC_NAMES = { '**': 'bold', '__': 'bold', '*': 'italic', '_': 'italic', '~~': 'strike', '`': 'inline-code', '``': 'inline-code', '```': 'inline-code',} as const satisfies Record<string, CoreInlineSpecName>
export function coreInlineSpecNameForDelimiter(delimiter: string): CoreInlineSpecName | undefined { return CORE_INLINE_SPEC_NAMES[delimiter as keyof typeof CORE_INLINE_SPEC_NAMES]}
export const INLINE_SEMANTIC_CHANGE_ANNOTATION = Annotation.define<InlineSemanticChange>()export const INLINE_SEMANTIC_TEXT_CHANGE_ANNOTATION = Annotation.define<InlineSemanticTextChange>()
export function readInlineSemanticChange( transaction: Transaction,): InlineSemanticChange | undefined { return transaction.annotation(INLINE_SEMANTIC_CHANGE_ANNOTATION)}
export function inlineSemanticTextChangeFromChangeSpec( change: ChangeSpec,): InlineSemanticTextChange | undefined { if ( typeof change === 'object' && change !== null && !Array.isArray(change) && 'from' in change && 'to' in change && 'insert' in change && typeof (change as { insert: unknown }).insert === 'string' ) { return { from: (change as { from: number }).from, to: (change as { to: number }).to, insert: (change as { insert: string }).insert, } } return undefined}
export function readInlineSemanticTextChange( transaction: Transaction,): InlineSemanticTextChange | undefined { return transaction.annotation(INLINE_SEMANTIC_TEXT_CHANGE_ANNOTATION)}