moondown 0.1.0
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.
- package/LICENSE +201 -0
- package/README.md +435 -0
- package/dist/error-image-generic-FKEGJ3ZW.png +0 -0
- package/dist/index.cjs +8706 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +8699 -0
- package/dist/index.js.map +7 -0
- package/dist/style.css +728 -0
- package/package.json +89 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { Extension, EditorState } from '@codemirror/state';
|
|
2
|
+
import type { EditorView, ViewUpdate } from '@codemirror/view';
|
|
3
|
+
|
|
4
|
+
export type Theme = 'light' | 'dark';
|
|
5
|
+
export type MoondownTranslations = Record<string, string>;
|
|
6
|
+
export type AIStreamHandler = (
|
|
7
|
+
systemPrompt: string,
|
|
8
|
+
userPrompt: string,
|
|
9
|
+
signal: AbortSignal
|
|
10
|
+
) => Promise<ReadableStream<string>>;
|
|
11
|
+
|
|
12
|
+
export type MoondownPluginOrder = 'pre' | 'post';
|
|
13
|
+
|
|
14
|
+
export interface MoondownSlashCommand {
|
|
15
|
+
id: string;
|
|
16
|
+
title: string;
|
|
17
|
+
titleKey?: string;
|
|
18
|
+
icon?: string;
|
|
19
|
+
keywords?: ReadonlyArray<string>;
|
|
20
|
+
execute: (view: EditorView) => void | Promise<void | AbortController>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MoondownPluginSetupContext {
|
|
24
|
+
initialDoc: string;
|
|
25
|
+
config: Readonly<ResolvedEditorConfig>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface MoondownPluginViewContext {
|
|
29
|
+
view: EditorView;
|
|
30
|
+
config: Readonly<ResolvedEditorConfig>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface MoondownPlugin {
|
|
34
|
+
name: string;
|
|
35
|
+
order?: MoondownPluginOrder;
|
|
36
|
+
setup?: (context: MoondownPluginSetupContext) => Extension | Extension[] | void;
|
|
37
|
+
onViewCreated?: (context: MoondownPluginViewContext) => void;
|
|
38
|
+
onUpdate?: (update: ViewUpdate, context: MoondownPluginViewContext) => void;
|
|
39
|
+
onDestroy?: (context: MoondownPluginViewContext) => void;
|
|
40
|
+
slashCommands?: ReadonlyArray<MoondownSlashCommand>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface EditorConfig {
|
|
44
|
+
initialDoc?: string;
|
|
45
|
+
theme?: Theme;
|
|
46
|
+
syntaxHiding?: boolean;
|
|
47
|
+
placeholder?: string;
|
|
48
|
+
readOnly?: boolean;
|
|
49
|
+
onChange?: (update: ViewUpdate) => void;
|
|
50
|
+
onFocus?: () => void;
|
|
51
|
+
onBlur?: () => void;
|
|
52
|
+
translations?: MoondownTranslations;
|
|
53
|
+
locale?: string;
|
|
54
|
+
onAIStream?: AIStreamHandler;
|
|
55
|
+
plugins?: ReadonlyArray<MoondownPlugin>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ResolvedEditorConfig {
|
|
59
|
+
theme: Theme;
|
|
60
|
+
syntaxHiding: boolean;
|
|
61
|
+
placeholder: string;
|
|
62
|
+
readOnly: boolean;
|
|
63
|
+
onChange?: (update: ViewUpdate) => void;
|
|
64
|
+
onFocus?: () => void;
|
|
65
|
+
onBlur?: () => void;
|
|
66
|
+
translations: MoondownTranslations;
|
|
67
|
+
locale: string;
|
|
68
|
+
onAIStream: AIStreamHandler | null;
|
|
69
|
+
plugins: ReadonlyArray<MoondownPlugin>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface Range {
|
|
73
|
+
from: number;
|
|
74
|
+
to: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface Selection extends Range {
|
|
78
|
+
text: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface Coordinates {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
top?: number;
|
|
85
|
+
left?: number;
|
|
86
|
+
bottom?: number;
|
|
87
|
+
right?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface LineInfo {
|
|
91
|
+
number: number;
|
|
92
|
+
from: number;
|
|
93
|
+
to: number;
|
|
94
|
+
text: string;
|
|
95
|
+
length: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type ActionHandler = (view: EditorView) => boolean | Promise<boolean>;
|
|
99
|
+
export type StateChecker = (state: EditorState) => boolean;
|
|
100
|
+
export type EventHandler<T extends Event = Event> = (event: T, view: EditorView) => boolean | void;
|
|
101
|
+
|
|
102
|
+
export function defineMoondownPlugin<TPlugin extends MoondownPlugin>(plugin: TPlugin): TPlugin;
|
|
103
|
+
|
|
104
|
+
export function createExtensionPlugin(
|
|
105
|
+
name: string,
|
|
106
|
+
extension: Extension | Extension[],
|
|
107
|
+
options?: {
|
|
108
|
+
order?: MoondownPluginOrder;
|
|
109
|
+
slashCommands?: ReadonlyArray<MoondownSlashCommand>;
|
|
110
|
+
}
|
|
111
|
+
): MoondownPlugin;
|
|
112
|
+
|
|
113
|
+
export interface MoondownClass {
|
|
114
|
+
view: EditorView;
|
|
115
|
+
getValue(): string;
|
|
116
|
+
setValue(value: string): void;
|
|
117
|
+
toggleSyntaxHiding(enabled: boolean): void;
|
|
118
|
+
setTheme(theme: Theme): void;
|
|
119
|
+
setReadOnly(enabled: boolean): void;
|
|
120
|
+
setPlaceholder(text: string): void;
|
|
121
|
+
setAIStreamHandler(handler: AIStreamHandler): void;
|
|
122
|
+
setTranslations(translations: MoondownTranslations): void;
|
|
123
|
+
setLocale(locale: string): void;
|
|
124
|
+
getView(): EditorView;
|
|
125
|
+
focus(): void;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
declare class Moondown implements MoondownClass {
|
|
130
|
+
view: EditorView;
|
|
131
|
+
constructor(element: HTMLElement, initialDoc?: string, config?: EditorConfig);
|
|
132
|
+
getValue(): string;
|
|
133
|
+
setValue(value: string): void;
|
|
134
|
+
toggleSyntaxHiding(enabled: boolean): void;
|
|
135
|
+
setTheme(theme: Theme): void;
|
|
136
|
+
setReadOnly(enabled: boolean): void;
|
|
137
|
+
setPlaceholder(text: string): void;
|
|
138
|
+
setAIStreamHandler(handler: AIStreamHandler): void;
|
|
139
|
+
setTranslations(translations: MoondownTranslations): void;
|
|
140
|
+
setLocale(locale: string): void;
|
|
141
|
+
getView(): EditorView;
|
|
142
|
+
focus(): void;
|
|
143
|
+
destroy(): void;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { Moondown };
|
|
147
|
+
export default Moondown;
|