@dou-ui/code 0.1.0-alpha.5 → 0.1.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"extension.js","names":[],"sources":["../src/extension.ts"],"sourcesContent":["import type { CodeMessages } from './locale'\nimport { type Component, type InjectionKey, type VNodeChild, inject } from 'vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeSelection } from './core/selection'\nimport type { CodeText } from './core/text'\nimport type { CodeState, CodeTransaction, CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose } from './types'\n\n/** How bad a diagnostic is, worst first. */\nexport type CodeDiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'\n\n/** A fix offered with a diagnostic. */\nexport interface CodeDiagnosticAction {\n label: string\n /** Makes the fix, usually with `context.transact`. */\n run: (context: CodeExtensionContext, diagnostic: CodeDiagnostic) => void\n}\n\n/**\n * A problem found in the text, from `from` to `to` (offsets in the text,\n * the same as a language service's ranges). An empty range marks the\n * character after it.\n */\nexport interface CodeDiagnostic {\n from: number\n to: number\n severity: CodeDiagnosticSeverity\n message: string\n /** Who found it, shown after the message, e.g. the name of a linter. */\n source?: string\n /** Fixes, shown under the message and with `Mod` + `.`. */\n actions?: CodeDiagnosticAction[]\n}\n\n/**\n * How a part of the text is drawn. Marks and line classes only change how\n * the text looks (colors, backgrounds, underlines, borders), never its\n * size, so the cursor still lands where the characters are; an inline\n * widget takes its own room in the line.\n */\nexport type CodeDecoration =\n /**\n * Classes on the characters from `from` to `to`. `style` sets inline\n * styles on them as well, e.g. a CSS variable holding a person's color;\n * where marks overlap, the later one's styles win.\n */\n | {\n type: 'mark'\n from: number\n to: number\n class: string\n title?: string\n style?: Readonly<Record<string, string>>\n }\n /** A class on a whole line (`line` from 1), e.g. a tinted background. */\n | { type: 'line'; line: number; class: string }\n /**\n * Something drawn inside a line, before the character at `pos`, such as\n * a color swatch or a parameter's name. It isn't text: the cursor steps\n * over it and copying leaves it out. `width` in px saves measuring it;\n * without it the widget is measured once drawn, and the width is kept by\n * `id`.\n */\n | { type: 'inline'; pos: number; render: () => VNodeChild; width?: number; id?: string }\n\n/**\n * A component drawn between lines, across the editor, e.g. a review\n * comment. The lines below move down to make room, and it moves with the\n * text as lines are added or removed above it.\n */\nexport interface CodeWidget {\n /** Tells widgets apart, unique among one extension's; its measured height is kept by it. */\n id: string\n /**\n * Where it is: below the line of text position `pos`, or below line\n * `line` (from 1); above with `position: 'above'`. Give one of them.\n */\n pos?: number\n line?: number\n /** Defaults to `below`. */\n position?: 'above' | 'below'\n render: () => VNodeChild\n /** Its height in px before it has been drawn and measured; defaults to one line. */\n height?: number\n /** What it is, read out when the cursor moves onto its line, e.g. \"戴兜的评论\". */\n label?: string\n}\n\n/** Something drawn in a column beside the line numbers, on line `line` (from 1). */\nexport interface CodeGutterMarker {\n line: number\n /** Drawn in the middle of the column. */\n icon?: Component\n /** Short text, when there is no icon. */\n text?: string\n class?: string\n /**\n * Shown on hover. Required when the column has `onPress`: the marker is\n * then a button, and this is its name.\n */\n title?: string\n /**\n * When the marker shows: `always`, or `hover`, out of sight until its\n * line is hovered, holds the cursor, or the marker has the focus, e.g. a\n * \"comment\" mark offered on every line. Defaults to `always`.\n */\n visible?: 'always' | 'hover'\n}\n\n/** A column of the gutter, left of the line numbers. */\nexport interface CodeGutter {\n name: string\n /** In px. Defaults to 16. */\n width?: number\n /** The markers on the lines in view; reactive state read here updates them. */\n markers: (context: CodeExtensionContext) => CodeGutterMarker[]\n /**\n * A press on the column, on line `line`, e.g. to set a breakpoint. A\n * marker in such a column is a button: the one on the cursor's line is\n * reached with Escape then Shift+Tab, and Enter or Space presses it.\n */\n onPress?: (\n line: number,\n event: PointerEvent | KeyboardEvent,\n context: CodeExtensionContext,\n ) => void\n}\n\n/** An undo history that takes the place of the editor's own, e.g. one shared with others. */\nexport interface CodeHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n /** Read in templates and computed values: keep them reactive. */\n canUndo: () => boolean\n canRedo: () => boolean\n /** The next change starts a new undo step, e.g. when the editor loses focus. */\n close?: () => void\n}\n\n/** A bar above or below the text, inside the editor's frame. */\nexport interface CodePanel {\n /** Tells panels apart, unique among one extension's. */\n name: string\n /** Defaults to `bottom`. */\n position?: 'top' | 'bottom'\n render: () => VNodeChild\n}\n\n/** What a completion is, shown as its icon. */\nexport type CodeCompletionKind =\n | 'keyword'\n | 'function'\n | 'method'\n | 'variable'\n | 'property'\n | 'constant'\n | 'class'\n | 'type'\n | 'module'\n | 'snippet'\n | 'text'\n\n/** One entry of the completion list. */\nexport interface CodeCompletion {\n /** Shown, and matched against what was typed. */\n label: string\n kind?: CodeCompletionKind\n /** Short, after the label, e.g. a type. */\n detail?: string\n /** Longer, below the list while this entry is picked: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n /** What goes into the text, if not the label. */\n insert?: string\n /** Inserted as a snippet instead: `${1:name}` places to fill in, Tab to the next, `$0` where it ends. */\n snippet?: string\n /** Moves the entry up (positive) or down among equally good matches. */\n boost?: number\n}\n\n/** What a completion source is asked with. */\nexport interface CodeCompletionRequest {\n /** The cursor. */\n pos: number\n /** The word right before the cursor, by the language's word characters; empty when there is none. */\n word: { from: number; to: number; text: string }\n /** Asked for from the keyboard (`Ctrl` + `Space`, `Alt` + `Esc`) rather than by typing. */\n explicit: boolean\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a hover or signature source is asked with. */\nexport interface CodePositionRequest {\n /** The position asked about: under the pointer, or the cursor. */\n pos: number\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a completion source answers: entries to put in place of `from`–cursor. */\nexport interface CodeCompletionResult {\n from: number\n options: CodeCompletion[]\n}\n\n/** Text shown on hover, or with the cursor on it from the keyboard. */\nexport interface CodeHoverResult {\n /** What it is about, `from`–`to`; defaults to the word under the pointer. */\n from?: number\n to?: number\n /** Plain text, or a render function for anything else. */\n content: string | (() => VNodeChild)\n}\n\n/** The parameters of the call the cursor is in. */\nexport interface CodeSignatureResult {\n /** The whole signature, e.g. `slice(start, end)`. */\n label: string\n /** Each parameter as `[from, to]` in `label`. */\n params: Array<[number, number]>\n /** Which parameter the cursor is at, from 0. */\n active: number\n /** Shown under the signature: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n}\n\nexport interface CodeExtension {\n name: string\n /** Higher runs first: its keys and hooks come before others. Defaults to 100. */\n priority?: number\n /** Keys tried before the built-in ones, and after the `keymap` prop. */\n keymap?: (context: CodeExtensionContext) => CodeKeymap\n /**\n * How parts of the text look, read while drawing: reactive state read\n * here updates them. Asked for the lines in view (`context.visible`),\n * which is all that needs them.\n */\n decorations?: (context: CodeExtensionContext) => CodeDecoration[]\n /** Columns beside the line numbers. */\n gutters?: CodeGutter[]\n /**\n * Components between lines. Unlike decorations, these are asked for the\n * whole text, since their heights place every line after them; keep\n * them few (comments, not one per line).\n */\n widgets?: (context: CodeExtensionContext) => CodeWidget[]\n /**\n * Lines left out of view: line numbers (from 1, not text positions), from\n * line `from` to line `to`, both left out,\n * e.g. the unchanged lines of a diff. Unlike a fold, nothing marks the\n * spot; put a widget there for that. Asked for the whole text; reactive\n * state read here updates them. Moving up and down steps over them.\n */\n hide?: (context: CodeExtensionContext) => Array<{ from: number; to: number }>\n /** Bars above or below the text; reactive state read here updates them. */\n panels?: (context: CodeExtensionContext) => CodePanel[]\n /**\n * Finds problems in the text. Run when the editor mounts and again a\n * moment after the text stops changing; an answer that arrives after\n * the text changed again is dropped, and the next run follows it.\n * Meanwhile the problems found move with the text.\n */\n lint?: (\n context: CodeExtensionContext,\n ) => CodeDiagnostic[] | null | undefined | Promise<CodeDiagnostic[] | null | undefined>\n /**\n * Offers completions while typing (after a word character or one of\n * `completionTriggers`) and on `Ctrl` + `Space` or `Alt` + `Esc`. Answers from every\n * extension are put in one list; a Promise is waited for, and dropped\n * when the text has moved on.\n */\n completion?: (\n request: CodeCompletionRequest,\n context: CodeExtensionContext,\n ) => CodeCompletionResult | null | undefined | Promise<CodeCompletionResult | null | undefined>\n /** Characters that ask for completions when typed, such as `.`. */\n completionTriggers?: string[]\n /**\n * Text about a position, shown on hover and with `Mod` + `I`. A Promise\n * is waited for; `signal` aborts when the pointer moves on.\n */\n hover?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeHoverResult | null | undefined | Promise<CodeHoverResult | null | undefined>\n /**\n * The parameters of the call around the cursor, shown while typing its\n * arguments. A Promise is waited for, and dropped when the cursor has\n * moved on.\n */\n signature?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeSignatureResult | null | undefined | Promise<CodeSignatureResult | null | undefined>\n /**\n * Sees every change before it is applied, in priority order, and may add\n * to it (positions are in the text before the change). Undo, redo, new\n * `v-model` values and other people's changes (`action: 'remote'`) don't\n * come through here.\n */\n transaction?: (tr: CodeTransaction, context: CodeExtensionContext) => void\n /**\n * Runs after every step the editor took, with the text and selection\n * already updated: typing, commands, undo and redo, new `v-model`\n * values and other people's changes. `result.meta.action` tells them\n * apart.\n */\n update?: (result: CodeTransactionResult, context: CodeExtensionContext) => void\n /**\n * Replaces the editor's undo history; the first extension that has one\n * wins. Called once per list of extensions: return the same handler\n * each time.\n */\n history?: (context: CodeExtensionContext) => CodeHistoryHandler\n /**\n * Buttons added to the toolbar shown over the selection on touch screens,\n * after cut, copy, paste and select all. Read again as the selection\n * changes.\n */\n menu?: (context: CodeExtensionContext) => CodeMenuItem[]\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: CodeExtensionContext) => void | (() => void)\n}\n\n/** A button of the touch toolbar, from an extension's `menu`. */\nexport interface CodeMenuItem {\n label: string\n run: (context: CodeExtensionContext) => void\n}\n\n/** What an extension sees of the editor: its instance, plus a little more. */\nexport interface CodeExtensionContext extends CodeEditorExpose {\n /** The text and selection now; reading them in `decorations` or `panels` follows every change. */\n readonly state: CodeState\n readonly doc: CodeText\n readonly selection: CodeSelection\n /** The lines in view: line numbers (from 1, not text positions), both ends in view. */\n readonly visible: { readonly from: number; readonly to: number }\n /** The problems found now, by all linters and the `diagnostics` prop, in text order. */\n readonly diagnostics: readonly CodeDiagnostic[]\n /** Whether the editor has focus; reading it in reactive code follows it. */\n readonly focused: boolean\n /** The editor's texts, in DouUI's locale or as given by the `messages` prop. */\n readonly messages: CodeMessages\n /** Reads a message out to screen readers. */\n announce: (message: string) => void\n /**\n * Runs the linter of the extension named `name` again now (every linter\n * without a name), for problems that arrive by themselves, such as ones a\n * server pushes.\n */\n relint: (name?: string) => void\n}\n\n/** Types an extension; returns it as it is. */\nexport function defineCodeExtension(extension: CodeExtension): CodeExtension {\n return extension\n}\n\nexport const CODE_EDITOR_KEY: InjectionKey<CodeExtensionContext> = Symbol('DouCodeEditor')\n\n/**\n * Internal: told each widget height an editor measures, by `extension/id`;\n * DouCodeDiff leaves a blank of the same height across from it.\n */\nexport const WIDGET_HEIGHT_KEY: InjectionKey<((key: string, height: number) => void) | null> =\n Symbol('DouCodeWidgetHeight')\n\n/** The editor a panel or gutter component is drawn in. */\nexport function useCodeEditor(): CodeExtensionContext {\n const context = inject(CODE_EDITOR_KEY, null)\n if (!context)\n throw new Error('[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>')\n return context\n}\n"],"mappings":";;;AAoWA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AAEA,IAAa,kBAAsD,OAAO,eAAe;;;;;AAMzF,IAAa,oBACX,OAAO,qBAAqB;;AAG9B,SAAgB,gBAAsC;CACpD,MAAM,UAAU,OAAO,iBAAiB,IAAI;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT"}
1
+ {"version":3,"file":"extension.js","names":[],"sources":["../src/extension.ts"],"sourcesContent":["import type { CodeMessages } from './locale'\nimport { type Component, type InjectionKey, type VNodeChild, inject } from 'vue'\nimport type { CodeKeymap } from './core/keymap'\nimport type { CodeSelection } from './core/selection'\nimport type { CodeText } from './core/text'\nimport type { CodeState, CodeTransaction, CodeTransactionResult } from './core/transaction'\nimport type { CodeEditorExpose } from './types'\n\n/** How bad a diagnostic is, worst first. */\nexport type CodeDiagnosticSeverity = 'error' | 'warning' | 'info' | 'hint'\n\n/** A fix offered with a diagnostic. */\nexport interface CodeDiagnosticAction {\n label: string\n /** Makes the fix, usually with `context.transact`. */\n run: (context: CodeExtensionContext, diagnostic: CodeDiagnostic) => void\n}\n\n/**\n * A problem found in the text, from `from` to `to` (offsets in the text,\n * the same as a language service's ranges). An empty range marks the\n * character after it.\n */\nexport interface CodeDiagnostic {\n from: number\n to: number\n severity: CodeDiagnosticSeverity\n message: string\n /** Who found it, shown after the message, e.g. the name of a linter. */\n source?: string\n /** Fixes, shown under the message and with `Mod` + `.`. */\n actions?: CodeDiagnosticAction[]\n}\n\n/**\n * How a part of the text is drawn. Marks and line classes only change how\n * the text looks (colors, backgrounds, underlines, borders), never its\n * size, so the cursor still lands where the characters are; an inline\n * widget takes its own room in the line.\n */\nexport type CodeDecoration =\n /**\n * Classes on the characters from `from` to `to`. `style` sets inline\n * styles on them as well, e.g. a CSS variable holding a person's color;\n * where marks overlap, the later one's styles win.\n */\n | {\n type: 'mark'\n from: number\n to: number\n class: string\n title?: string\n style?: Readonly<Record<string, string>>\n }\n /** A class on a whole line (`line` from 1), e.g. a tinted background. */\n | { type: 'line'; line: number; class: string }\n /**\n * Something drawn inside a line, before the character at `pos`, such as\n * a color swatch or a parameter's name. It isn't text: the cursor steps\n * over it and copying leaves it out. `width` in px saves measuring it;\n * without it the widget is measured once drawn, and the width is kept by\n * `id`.\n */\n | { type: 'inline'; pos: number; render: () => VNodeChild; width?: number; id?: string }\n\n/**\n * A component drawn between lines, across the editor, e.g. a review\n * comment. The lines below move down to make room, and it moves with the\n * text as lines are added or removed above it.\n */\nexport interface CodeWidget {\n /** Tells widgets apart, unique among one extension's; its measured height is kept by it. */\n id: string\n /**\n * Where it is: below the line of text position `pos`, or below line\n * `line` (from 1); above with `position: 'above'`. Give one of them.\n */\n pos?: number\n line?: number\n /** Defaults to `below`. */\n position?: 'above' | 'below'\n render: () => VNodeChild\n /** Its height in px before it has been drawn and measured; defaults to one line. */\n height?: number\n /** What it is, read out when the cursor moves onto its line, e.g. \"戴兜的评论\". */\n label?: string\n}\n\n/** Something drawn in a column beside the line numbers, on line `line` (from 1). */\nexport interface CodeGutterMarker {\n line: number\n /** Drawn in the middle of the column. */\n icon?: Component\n /** Short text, when there is no icon. */\n text?: string\n class?: string\n /**\n * Shown on hover. Required when the column has `onPress`: the marker is\n * then a button, and this is its name.\n */\n title?: string\n /**\n * When the marker shows: `always`, or `hover`, out of sight until its\n * line is hovered, holds the cursor, or the marker has the focus, e.g. a\n * \"comment\" mark offered on every line. Defaults to `always`.\n */\n visible?: 'always' | 'hover'\n}\n\n/**\n * The marker a column shows on every line without one of its own, out of\n * sight until the line is hovered (as `visible: 'hover'`), e.g. \"add a\n * breakpoint\" offered on every line.\n */\nexport interface CodeGutterHoverMarker extends Pick<CodeGutterMarker, 'icon' | 'text' | 'class'> {\n /**\n * Its name, as a marker's `title`; a function names the marker of each\n * line, e.g. \"Add a breakpoint on line 3\". It is called for every line in\n * view, often: keep it quick.\n */\n title?: string | ((line: number) => string)\n}\n\n/** A column of the gutter, left of the line numbers. */\nexport interface CodeGutter {\n name: string\n /** In px. Defaults to 16. */\n width?: number\n /** The markers on the lines in view; reactive state read here updates them. */\n markers?: (context: CodeExtensionContext) => CodeGutterMarker[]\n /** A marker on every other line, shown on hover. */\n hoverMarker?: CodeGutterHoverMarker\n /**\n * Where `onPress` answers: `any` cell of the column (the default), e.g. to\n * set a breakpoint on an empty line, or only its `markers`.\n */\n pressOn?: 'any' | 'markers'\n /**\n * A press on the column, on line `line`, e.g. to set a breakpoint. A\n * marker in such a column is a button: the one on the cursor's line is\n * reached with Escape then Shift+Tab, and Enter or Space presses it. A\n * finger or pen presses when it lifts in place; a tap on a marker still\n * out of sight first moves the cursor to its line, which shows it.\n */\n onPress?: (\n line: number,\n event: PointerEvent | KeyboardEvent,\n context: CodeExtensionContext,\n ) => void\n}\n\n/** An undo history that takes the place of the editor's own, e.g. one shared with others. */\nexport interface CodeHistoryHandler {\n /** `false` when there is nothing to undo. */\n undo: () => boolean\n redo: () => boolean\n /** Read in templates and computed values: keep them reactive. */\n canUndo: () => boolean\n canRedo: () => boolean\n /** The next change starts a new undo step, e.g. when the editor loses focus. */\n close?: () => void\n}\n\n/** A bar above or below the text, inside the editor's frame. */\nexport interface CodePanel {\n /** Tells panels apart, unique among one extension's. */\n name: string\n /** Defaults to `bottom`. */\n position?: 'top' | 'bottom'\n render: () => VNodeChild\n}\n\n/** What a completion is, shown as its icon. */\nexport type CodeCompletionKind =\n | 'keyword'\n | 'function'\n | 'method'\n | 'variable'\n | 'property'\n | 'constant'\n | 'class'\n | 'type'\n | 'module'\n | 'snippet'\n | 'text'\n\n/** One entry of the completion list. */\nexport interface CodeCompletion {\n /** Shown, and matched against what was typed. */\n label: string\n kind?: CodeCompletionKind\n /** Short, after the label, e.g. a type. */\n detail?: string\n /** Longer, below the list while this entry is picked: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n /** What goes into the text, if not the label. */\n insert?: string\n /** Inserted as a snippet instead: `${1:name}` places to fill in, Tab to the next, `$0` where it ends. */\n snippet?: string\n /** Moves the entry up (positive) or down among equally good matches. */\n boost?: number\n}\n\n/** What a completion source is asked with. */\nexport interface CodeCompletionRequest {\n /** The cursor. */\n pos: number\n /** The word right before the cursor, by the language's word characters; empty when there is none. */\n word: { from: number; to: number; text: string }\n /** Asked for from the keyboard (`Ctrl` + `Space`, `Alt` + `Esc`) rather than by typing. */\n explicit: boolean\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a hover or signature source is asked with. */\nexport interface CodePositionRequest {\n /** The position asked about: under the pointer, or the cursor. */\n pos: number\n /** Aborted when the answer is no longer wanted, so a slow source can stop. */\n signal: AbortSignal\n}\n\n/** What a completion source answers: entries to put in place of `from`–cursor. */\nexport interface CodeCompletionResult {\n from: number\n options: CodeCompletion[]\n}\n\n/** Text shown on hover, or with the cursor on it from the keyboard. */\nexport interface CodeHoverResult {\n /** What it is about, `from`–`to`; defaults to the word under the pointer. */\n from?: number\n to?: number\n /** Plain text, or a render function for anything else. */\n content: string | (() => VNodeChild)\n}\n\n/** The parameters of the call the cursor is in. */\nexport interface CodeSignatureResult {\n /** The whole signature, e.g. `slice(start, end)`. */\n label: string\n /** Each parameter as `[from, to]` in `label`. */\n params: Array<[number, number]>\n /** Which parameter the cursor is at, from 0. */\n active: number\n /** Shown under the signature: text, or a function returning VNodes. */\n info?: string | (() => VNodeChild)\n}\n\nexport interface CodeExtension {\n name: string\n /** Higher runs first: its keys and hooks come before others. Defaults to 100. */\n priority?: number\n /** Keys tried before the built-in ones, and after the `keymap` prop. */\n keymap?: (context: CodeExtensionContext) => CodeKeymap\n /**\n * How parts of the text look, read while drawing: reactive state read\n * here updates them. Asked for the lines in view (`context.visible`),\n * which is all that needs them.\n */\n decorations?: (context: CodeExtensionContext) => CodeDecoration[]\n /** Columns beside the line numbers. */\n gutters?: CodeGutter[]\n /**\n * Components between lines. Unlike decorations, these are asked for the\n * whole text, since their heights place every line after them; keep\n * them few (comments, not one per line).\n */\n widgets?: (context: CodeExtensionContext) => CodeWidget[]\n /**\n * Lines left out of view: line numbers (from 1, not text positions), from\n * line `from` to line `to`, both left out,\n * e.g. the unchanged lines of a diff. Unlike a fold, nothing marks the\n * spot; put a widget there for that. Asked for the whole text; reactive\n * state read here updates them. Moving up and down steps over them.\n */\n hide?: (context: CodeExtensionContext) => Array<{ from: number; to: number }>\n /** Bars above or below the text; reactive state read here updates them. */\n panels?: (context: CodeExtensionContext) => CodePanel[]\n /**\n * Finds problems in the text. Run when the editor mounts and again a\n * moment after the text stops changing; an answer that arrives after\n * the text changed again is dropped, and the next run follows it.\n * Meanwhile the problems found move with the text.\n */\n lint?: (\n context: CodeExtensionContext,\n ) => CodeDiagnostic[] | null | undefined | Promise<CodeDiagnostic[] | null | undefined>\n /**\n * Offers completions while typing (after a word character or one of\n * `completionTriggers`) and on `Ctrl` + `Space` or `Alt` + `Esc`. Answers from every\n * extension are put in one list; a Promise is waited for, and dropped\n * when the text has moved on.\n */\n completion?: (\n request: CodeCompletionRequest,\n context: CodeExtensionContext,\n ) => CodeCompletionResult | null | undefined | Promise<CodeCompletionResult | null | undefined>\n /** Characters that ask for completions when typed, such as `.`. */\n completionTriggers?: string[]\n /**\n * Text about a position, shown on hover and with `Mod` + `I`. A Promise\n * is waited for; `signal` aborts when the pointer moves on.\n */\n hover?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeHoverResult | null | undefined | Promise<CodeHoverResult | null | undefined>\n /**\n * The parameters of the call around the cursor, shown while typing its\n * arguments. A Promise is waited for, and dropped when the cursor has\n * moved on.\n */\n signature?: (\n request: CodePositionRequest,\n context: CodeExtensionContext,\n ) => CodeSignatureResult | null | undefined | Promise<CodeSignatureResult | null | undefined>\n /**\n * Sees every change before it is applied, in priority order, and may add\n * to it (positions are in the text before the change). Undo, redo, new\n * `v-model` values and other people's changes (`action: 'remote'`) don't\n * come through here.\n */\n transaction?: (tr: CodeTransaction, context: CodeExtensionContext) => void\n /**\n * Runs after every step the editor took, with the text and selection\n * already updated: typing, commands, undo and redo, new `v-model`\n * values and other people's changes. `result.meta.action` tells them\n * apart.\n */\n update?: (result: CodeTransactionResult, context: CodeExtensionContext) => void\n /**\n * Replaces the editor's undo history; the first extension that has one\n * wins. Called once per list of extensions: return the same handler\n * each time.\n */\n history?: (context: CodeExtensionContext) => CodeHistoryHandler\n /**\n * Buttons added to the toolbar shown over the selection on touch screens,\n * after cut, copy, paste and select all. Read again as the selection\n * changes.\n */\n menu?: (context: CodeExtensionContext) => CodeMenuItem[]\n /** Runs once the editor is mounted. Return a function to run when it unmounts. */\n setup?: (context: CodeExtensionContext) => void | (() => void)\n}\n\n/** A button of the touch toolbar, from an extension's `menu`. */\nexport interface CodeMenuItem {\n label: string\n run: (context: CodeExtensionContext) => void\n}\n\n/** What an extension sees of the editor: its instance, plus a little more. */\nexport interface CodeExtensionContext extends CodeEditorExpose {\n /** The text and selection now; reading them in `decorations` or `panels` follows every change. */\n readonly state: CodeState\n readonly doc: CodeText\n readonly selection: CodeSelection\n /** The lines in view: line numbers (from 1, not text positions), both ends in view. */\n readonly visible: { readonly from: number; readonly to: number }\n /** The problems found now, by all linters and the `diagnostics` prop, in text order. */\n readonly diagnostics: readonly CodeDiagnostic[]\n /** Whether the editor has focus; reading it in reactive code follows it. */\n readonly focused: boolean\n /** The editor's texts, in DouUI's locale or as given by the `messages` prop. */\n readonly messages: CodeMessages\n /** Reads a message out to screen readers. */\n announce: (message: string) => void\n /**\n * Runs the linter of the extension named `name` again now (every linter\n * without a name), for problems that arrive by themselves, such as ones a\n * server pushes.\n */\n relint: (name?: string) => void\n}\n\n/** Types an extension; returns it as it is. */\nexport function defineCodeExtension(extension: CodeExtension): CodeExtension {\n return extension\n}\n\nexport const CODE_EDITOR_KEY: InjectionKey<CodeExtensionContext> = Symbol('DouCodeEditor')\n\n/**\n * Internal: told each widget height an editor measures, by `extension/id`;\n * DouCodeDiff leaves a blank of the same height across from it.\n */\nexport const WIDGET_HEIGHT_KEY: InjectionKey<((key: string, height: number) => void) | null> =\n Symbol('DouCodeWidgetHeight')\n\n/** The editor a panel or gutter component is drawn in. */\nexport function useCodeEditor(): CodeExtensionContext {\n const context = inject(CODE_EDITOR_KEY, null)\n if (!context)\n throw new Error('[@dou-ui/code] useCodeEditor() must be called inside <DouCodeEditor>')\n return context\n}\n"],"mappings":";;;AA2XA,SAAgB,oBAAoB,WAAyC;CAC3E,OAAO;AACT;AAEA,IAAa,kBAAsD,OAAO,eAAe;;;;;AAMzF,IAAa,oBACX,OAAO,qBAAqB;;AAG9B,SAAgB,gBAAsC;CACpD,MAAM,UAAU,OAAO,iBAAiB,IAAI;CAC5C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,sEAAsE;CACxF,OAAO;AACT"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["CodeEditor","CodeKeys","CodeInput","CodeDiff"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport CodeDiff from './code-diff.vue'\nimport CodeInput from './code-input.vue'\nimport CodeKeys from './code-keys.vue'\n\nexport const DouCodeEditor = withInstall(CodeEditor)\nexport const DouCodeKeys = withInstall(CodeKeys)\nexport const DouCodeInput = withInstall(CodeInput)\nexport const DouCodeDiff = withInstall(CodeDiff)\nexport { diffText } from './core/diff'\nexport type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff'\nexport { defaultCodeKeys } from './code-keys'\nexport { defineCodeExtension, useCodeEditor } from './extension'\nexport type {\n CodeDecoration,\n CodeDiagnostic,\n CodeDiagnosticAction,\n CodeDiagnosticSeverity,\n CodeExtension,\n CodeExtensionContext,\n CodeGutter,\n CodeGutterMarker,\n CodeHistoryHandler,\n CodeCompletion,\n CodeCompletionKind,\n CodeCompletionRequest,\n CodePositionRequest,\n CodeCompletionResult,\n CodeHoverResult,\n CodeMenuItem,\n CodePanel,\n CodeSignatureResult,\n CodeWidget,\n} from './extension'\nexport default DouCodeEditor\n\nexport type {\n CodeDiffEmits,\n CodeDiffGutter,\n CodeDiffGutterMarker,\n CodeDiffProps,\n CodeDiffSide,\n CodeDiffWidget,\n CodeEditorEmits,\n CodeEditorExpose,\n CodeEditorProps,\n CodeInputEmits,\n CodeInputProps,\n CodeKey,\n CodeKeysProps,\n} from './types'\nexport { CodeText, splitLines } from './core/text'\nexport type { CodeLine } from './core/text'\nexport { ChangeSet } from './core/changes'\nexport type { CodeChange, CodeChangeSpec, MapAssoc } from './core/changes'\nexport {\n isEmptyRange,\n mainRange,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './core/selection'\nexport type { CodeRange, CodeSelection } from './core/selection'\nexport { CodeTransaction } from './core/transaction'\nexport type {\n CodeAction,\n CodeState,\n CodeTransactionMeta,\n CodeTransactionResult,\n} from './core/transaction'\nexport * as codeCommands from './core/commands'\nexport type { CodeCommand, CodeCommandTarget } from './core/commands'\nexport { defaultKeymap } from './core/keymap'\nexport { findPartner, matchBracket } from './core/brackets'\nexport type { BracketMatch } from './core/brackets'\nexport { CodeStream } from './language/stream'\nexport {\n copyPlain,\n defineCodeLanguage,\n languageFor,\n lineParts,\n samePlain,\n tokenizeLine,\n tokenTypes,\n} from './language/language'\nexport type {\n CodeLanguage,\n CodeLanguageSpec,\n CodeLineTokens,\n CodeTokenType,\n} from './language/language'\nexport { CodeHighlighter } from './language/highlighter'\nexport { createCodeHighlighter, highlightToHtml } from './language/to-html'\nexport { createJavaScript, javascript, jsx, tsx, typescript } from './languages/javascript'\nexport type { JavaScriptOptions, JavaScriptState } from './languages/javascript'\nexport { createCss, css, scss } from './languages/css'\nexport type { CssState } from './languages/css'\nexport { json } from './languages/json'\nexport type { JsonState } from './languages/json'\nexport { createHtml, html, vue } from './languages/html'\nexport type { HtmlState } from './languages/html'\nexport { createMarkdown, markdown } from './languages/markdown'\nexport type { MarkdownOptions, MarkdownState } from './languages/markdown'\nexport { python } from './languages/python'\nexport type { PythonState } from './languages/python'\nexport { shell } from './languages/shell'\nexport type { ShellState } from './languages/shell'\nexport { sql } from './languages/sql'\nexport type { SqlState } from './languages/sql'\nexport { yaml } from './languages/yaml'\nexport type { YamlState } from './languages/yaml'\nexport type { CodeKeyBinding, CodeKeymap } from './core/keymap'\nexport type { CodeAssistControl, CodeDiagnosticControl, CodeSearchControl } from './core/commands'\nexport { matchAfter, queryRegExp, replacementFor, searchText } from './core/search'\nexport type { CodeMatch, CodeSearchQuery, CodeSearchResult } from './core/search'\nexport { codeLocales } from './locale'\nexport type { CodeMessages } from './locale'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouCodeEditor: typeof DouCodeEditor\n DouCodeKeys: typeof DouCodeKeys\n DouCodeInput: typeof DouCodeInput\n DouCodeDiff: typeof DouCodeDiff\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,gBAAgB,YAAYA,mBAAU;AACnD,IAAa,cAAc,YAAYC,iBAAQ;AAC/C,IAAa,eAAe,YAAYC,kBAAS;AACjD,IAAa,cAAc,YAAYC,iBAAQ"}
1
+ {"version":3,"file":"index.js","names":["CodeEditor","CodeKeys","CodeInput","CodeDiff"],"sources":["../src/index.ts"],"sourcesContent":["import { withInstall } from 'dou-ui'\nimport CodeEditor from './code-editor.vue'\nimport CodeDiff from './code-diff.vue'\nimport CodeInput from './code-input.vue'\nimport CodeKeys from './code-keys.vue'\n\nexport const DouCodeEditor = withInstall(CodeEditor)\nexport const DouCodeKeys = withInstall(CodeKeys)\nexport const DouCodeInput = withInstall(CodeInput)\nexport const DouCodeDiff = withInstall(CodeDiff)\nexport { diffText } from './core/diff'\nexport type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff'\nexport { defaultCodeKeys } from './code-keys'\nexport { defineCodeExtension, useCodeEditor } from './extension'\nexport type {\n CodeDecoration,\n CodeDiagnostic,\n CodeDiagnosticAction,\n CodeDiagnosticSeverity,\n CodeExtension,\n CodeExtensionContext,\n CodeGutter,\n CodeGutterHoverMarker,\n CodeGutterMarker,\n CodeHistoryHandler,\n CodeCompletion,\n CodeCompletionKind,\n CodeCompletionRequest,\n CodePositionRequest,\n CodeCompletionResult,\n CodeHoverResult,\n CodeMenuItem,\n CodePanel,\n CodeSignatureResult,\n CodeWidget,\n} from './extension'\nexport default DouCodeEditor\n\nexport type {\n CodeDiffEmits,\n CodeDiffGutter,\n CodeDiffGutterMarker,\n CodeDiffHoverMarker,\n CodeDiffProps,\n CodeDiffSide,\n CodeDiffWidget,\n CodeEditorEmits,\n CodeEditorExpose,\n CodeEditorProps,\n CodeInputEmits,\n CodeInputProps,\n CodeKey,\n CodeKeysProps,\n} from './types'\nexport { CodeText, splitLines } from './core/text'\nexport type { CodeLine } from './core/text'\nexport { ChangeSet } from './core/changes'\nexport type { CodeChange, CodeChangeSpec, MapAssoc } from './core/changes'\nexport {\n isEmptyRange,\n mainRange,\n mapSelection,\n normalizeSelection,\n rangeFrom,\n rangeTo,\n sameSelection,\n selectionOf,\n} from './core/selection'\nexport type { CodeRange, CodeSelection } from './core/selection'\nexport { CodeTransaction } from './core/transaction'\nexport type {\n CodeAction,\n CodeState,\n CodeTransactionMeta,\n CodeTransactionResult,\n} from './core/transaction'\nexport * as codeCommands from './core/commands'\nexport type { CodeCommand, CodeCommandTarget } from './core/commands'\nexport { defaultKeymap } from './core/keymap'\nexport { findPartner, matchBracket } from './core/brackets'\nexport type { BracketMatch } from './core/brackets'\nexport { CodeStream } from './language/stream'\nexport {\n copyPlain,\n defineCodeLanguage,\n languageFor,\n lineParts,\n samePlain,\n tokenizeLine,\n tokenTypes,\n} from './language/language'\nexport type {\n CodeLanguage,\n CodeLanguageSpec,\n CodeLineTokens,\n CodeTokenType,\n} from './language/language'\nexport { CodeHighlighter } from './language/highlighter'\nexport { createCodeHighlighter, highlightToHtml } from './language/to-html'\nexport { createJavaScript, javascript, jsx, tsx, typescript } from './languages/javascript'\nexport type { JavaScriptOptions, JavaScriptState } from './languages/javascript'\nexport { createCss, css, scss } from './languages/css'\nexport type { CssState } from './languages/css'\nexport { json } from './languages/json'\nexport type { JsonState } from './languages/json'\nexport { createHtml, html, vue } from './languages/html'\nexport type { HtmlState } from './languages/html'\nexport { createMarkdown, markdown } from './languages/markdown'\nexport type { MarkdownOptions, MarkdownState } from './languages/markdown'\nexport { python } from './languages/python'\nexport type { PythonState } from './languages/python'\nexport { shell } from './languages/shell'\nexport type { ShellState } from './languages/shell'\nexport { sql } from './languages/sql'\nexport type { SqlState } from './languages/sql'\nexport { yaml } from './languages/yaml'\nexport type { YamlState } from './languages/yaml'\nexport type { CodeKeyBinding, CodeKeymap } from './core/keymap'\nexport type { CodeAssistControl, CodeDiagnosticControl, CodeSearchControl } from './core/commands'\nexport { matchAfter, queryRegExp, replacementFor, searchText } from './core/search'\nexport type { CodeMatch, CodeSearchQuery, CodeSearchResult } from './core/search'\nexport { codeLocales } from './locale'\nexport type { CodeMessages } from './locale'\n\ndeclare module 'vue' {\n export interface GlobalComponents {\n DouCodeEditor: typeof DouCodeEditor\n DouCodeKeys: typeof DouCodeKeys\n DouCodeInput: typeof DouCodeInput\n DouCodeDiff: typeof DouCodeDiff\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,gBAAgB,YAAYA,mBAAU;AACnD,IAAa,cAAc,YAAYC,iBAAQ;AAC/C,IAAa,eAAe,YAAYC,kBAAS;AACjD,IAAa,cAAc,YAAYC,iBAAQ"}
@@ -110,17 +110,39 @@ export interface CodeGutterMarker {
110
110
  */
111
111
  visible?: 'always' | 'hover';
112
112
  }
113
+ /**
114
+ * The marker a column shows on every line without one of its own, out of
115
+ * sight until the line is hovered (as `visible: 'hover'`), e.g. "add a
116
+ * breakpoint" offered on every line.
117
+ */
118
+ export interface CodeGutterHoverMarker extends Pick<CodeGutterMarker, 'icon' | 'text' | 'class'> {
119
+ /**
120
+ * Its name, as a marker's `title`; a function names the marker of each
121
+ * line, e.g. "Add a breakpoint on line 3". It is called for every line in
122
+ * view, often: keep it quick.
123
+ */
124
+ title?: string | ((line: number) => string);
125
+ }
113
126
  /** A column of the gutter, left of the line numbers. */
114
127
  export interface CodeGutter {
115
128
  name: string;
116
129
  /** In px. Defaults to 16. */
117
130
  width?: number;
118
131
  /** The markers on the lines in view; reactive state read here updates them. */
119
- markers: (context: CodeExtensionContext) => CodeGutterMarker[];
132
+ markers?: (context: CodeExtensionContext) => CodeGutterMarker[];
133
+ /** A marker on every other line, shown on hover. */
134
+ hoverMarker?: CodeGutterHoverMarker;
135
+ /**
136
+ * Where `onPress` answers: `any` cell of the column (the default), e.g. to
137
+ * set a breakpoint on an empty line, or only its `markers`.
138
+ */
139
+ pressOn?: 'any' | 'markers';
120
140
  /**
121
141
  * A press on the column, on line `line`, e.g. to set a breakpoint. A
122
142
  * marker in such a column is a button: the one on the cursor's line is
123
- * reached with Escape then Shift+Tab, and Enter or Space presses it.
143
+ * reached with Escape then Shift+Tab, and Enter or Space presses it. A
144
+ * finger or pen presses when it lifts in place; a tap on a marker still
145
+ * out of sight first moves the cursor to its line, which shows it.
124
146
  */
125
147
  onPress?: (line: number, event: PointerEvent | KeyboardEvent, context: CodeExtensionContext) => void;
126
148
  }
@@ -108,9 +108,9 @@ export { diffText } from './core/diff';
108
108
  export type { CodeDiffHunk, CodeDiffOptions, CodeDiffPart } from './core/diff';
109
109
  export { defaultCodeKeys } from './code-keys';
110
110
  export { defineCodeExtension, useCodeEditor } from './extension';
111
- export type { CodeDecoration, CodeDiagnostic, CodeDiagnosticAction, CodeDiagnosticSeverity, CodeExtension, CodeExtensionContext, CodeGutter, CodeGutterMarker, CodeHistoryHandler, CodeCompletion, CodeCompletionKind, CodeCompletionRequest, CodePositionRequest, CodeCompletionResult, CodeHoverResult, CodeMenuItem, CodePanel, CodeSignatureResult, CodeWidget, } from './extension';
111
+ export type { CodeDecoration, CodeDiagnostic, CodeDiagnosticAction, CodeDiagnosticSeverity, CodeExtension, CodeExtensionContext, CodeGutter, CodeGutterHoverMarker, CodeGutterMarker, CodeHistoryHandler, CodeCompletion, CodeCompletionKind, CodeCompletionRequest, CodePositionRequest, CodeCompletionResult, CodeHoverResult, CodeMenuItem, CodePanel, CodeSignatureResult, CodeWidget, } from './extension';
112
112
  export default DouCodeEditor;
113
- export type { CodeDiffEmits, CodeDiffGutter, CodeDiffGutterMarker, CodeDiffProps, CodeDiffSide, CodeDiffWidget, CodeEditorEmits, CodeEditorExpose, CodeEditorProps, CodeInputEmits, CodeInputProps, CodeKey, CodeKeysProps, } from './types';
113
+ export type { CodeDiffEmits, CodeDiffGutter, CodeDiffGutterMarker, CodeDiffHoverMarker, CodeDiffProps, CodeDiffSide, CodeDiffWidget, CodeEditorEmits, CodeEditorExpose, CodeEditorProps, CodeInputEmits, CodeInputProps, CodeKey, CodeKeysProps, } from './types';
114
114
  export { CodeText, splitLines } from './core/text';
115
115
  export type { CodeLine } from './core/text';
116
116
  export { ChangeSet } from './core/changes';
@@ -1,5 +1,5 @@
1
1
  import type { Component, VNodeChild } from 'vue';
2
- import type { CodeDiagnostic, CodeExtension, CodeGutterMarker } from './extension';
2
+ import type { CodeDiagnostic, CodeExtension, CodeGutterHoverMarker, CodeGutterMarker } from './extension';
3
3
  import type { CodeCommand } from './core/commands';
4
4
  import type { CodeKeymap } from './core/keymap';
5
5
  import type { CodeSearchQuery } from './core/search';
@@ -294,12 +294,33 @@ export type CodeDiffSide = 'original' | 'modified';
294
294
  export interface CodeDiffGutterMarker extends CodeGutterMarker {
295
295
  side: CodeDiffSide;
296
296
  }
297
+ /** `DouCodeDiff`'s `hoverMarker`: on the lines of one side only, with `side`. */
298
+ export interface CodeDiffHoverMarker extends Omit<CodeGutterHoverMarker, 'title'> {
299
+ /**
300
+ * Its name; a function names the marker of each line, with the line and
301
+ * side `onPress` gets there, e.g. "Comment on line 3 of the new text".
302
+ * It is called for every line in view, often: keep it quick.
303
+ */
304
+ title?: string | ((line: number, side: CodeDiffSide) => string);
305
+ /** Only on the lines of this side; on both when left out. */
306
+ side?: CodeDiffSide;
307
+ }
297
308
  /** A column of `DouCodeDiff`'s gutter, left of the line numbers. */
298
309
  export interface CodeDiffGutter {
299
310
  name: string;
300
311
  /** In px. Defaults to 16. */
301
312
  width?: number;
302
- markers: CodeDiffGutterMarker[];
313
+ markers?: CodeDiffGutterMarker[];
314
+ /**
315
+ * A marker on every other line, shown on hover. With `side`, the other
316
+ * side's column only answers presses on its own markers.
317
+ */
318
+ hoverMarker?: CodeDiffHoverMarker;
319
+ /**
320
+ * Where `onPress` answers: `any` cell of the column (the default), or only
321
+ * its markers. With a `hoverMarker` on one side, only markers anyway.
322
+ */
323
+ pressOn?: 'any' | 'markers';
303
324
  /**
304
325
  * A press on the column, on line `line` of `side`. Inline, a row both
305
326
  * texts share counts as the marker's side there, else as `modified`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dou-ui/code",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "DouUI 的代码编辑器:大文件流畅编辑、输入法友好、多光标与协同",
5
5
  "keywords": [
6
6
  "vue",
@@ -63,10 +63,10 @@
63
63
  "build": "vite build && vue-tsc -p tsconfig.build.json && bun scripts/build-style.ts"
64
64
  },
65
65
  "dependencies": {
66
- "@dou-ui/icons": "0.1.0-alpha.5"
66
+ "@dou-ui/icons": "0.1.0-alpha.6"
67
67
  },
68
68
  "peerDependencies": {
69
- "dou-ui": "0.1.0-alpha.5",
69
+ "dou-ui": "0.1.0-alpha.6",
70
70
  "vue": "^3.5.0",
71
71
  "yjs": "^13.6.0",
72
72
  "shiki": "^1.0.0 || ^2.0.0 || ^3.0.0"