Skip to content

Commit 157e822

Browse files
committed
Initial release
1 parent aa57ce8 commit 157e822

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add `markedit-api` to your (TypeScript) project's devDependencies:
1616
```json
1717
{
1818
"devDependencies": {
19-
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.0.8"
19+
"markedit-api": "https://github.com/MarkEdit-app/MarkEdit-api#v0.1.0"
2020
}
2121
}
2222
```
@@ -60,7 +60,7 @@ MarkEdit.addExtension(extension); // Can also add an array of extensions
6060

6161
## Building
6262

63-
In your build configuration, mark used CodeMirror (and Lezer) dependencies as `external`.
63+
In your build configuration, mark used MarkEdit and CodeMirror dependencies as `external`.
6464

6565
Here is an example of [vite](https://vitejs.dev/) config:
6666

@@ -71,6 +71,7 @@ export default defineConfig({
7171
build: {
7272
rollupOptions: {
7373
external: [
74+
'markedit-api',
7475
'@codemirror/view',
7576
'@codemirror/state',
7677
// ...
@@ -89,11 +90,13 @@ It is recommended to build as [cjs](https://commonjs.org/), building as [umd](ht
8990
```
9091
rollupOptions: {
9192
external: [
93+
'markedit-api',
9294
'@codemirror/view',
9395
'@codemirror/state',
9496
],
9597
output: {
9698
globals: {
99+
'markedit-api': 'MarkEdit',
97100
'@codemirror/view': 'MarkEdit.codemirror.view',
98101
'@codemirror/state': 'MarkEdit.codemirror.state',
99102
},

main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MarkEdit = {};

markedit.d.ts

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,119 +9,131 @@ import type * as lezerCommon from '@lezer/common';
99
import type * as lezerHighlight from '@lezer/highlight';
1010
import type * as lezerLr from '@lezer/lr';
1111

12-
declare global {
13-
const MarkEdit: {
12+
export const MarkEdit: MarkEdit;
13+
14+
export interface MarkEdit {
15+
/**
16+
* CodeMirror EditorView instance of the current editor.
17+
*/
18+
editorView: EditorView;
19+
20+
/**
21+
* Convenient text editing interfaces.
22+
*/
23+
editorAPI: TextEditable;
24+
25+
/**
26+
* CodeMirror modules used by MarkEdit.
27+
*/
28+
codemirror: {
1429
/**
15-
* CodeMirror EditorView instance of the current editor.
30+
* The `@codemirror/view` module.
1631
*/
17-
editorView: EditorView;
32+
view: typeof cmView;
1833

1934
/**
20-
* Convenient text editing interfaces.
35+
* The `@codemirror/state` module.
2136
*/
22-
editorAPI: TextEditable;
37+
state: typeof cmState;
2338

2439
/**
25-
* Add an extension to MarkEdit.
26-
* @param extension CodeMirror extension.
40+
* The `@codemirror/language` module.
2741
*/
28-
addExtension: (extension: Extension) => void;
42+
language: typeof cmLanguage;
43+
};
2944

45+
/**
46+
* Lezer modules used by MarkEdit.
47+
*/
48+
lezer: {
3049
/**
31-
* CodeMirror modules used by MarkEdit.
50+
* The `@lezer/common` module.
3251
*/
33-
codemirror: {
34-
/**
35-
* The `@codemirror/view` module.
36-
*/
37-
view: typeof cmView;
38-
/**
39-
* The `@codemirror/state` module.
40-
*/
41-
state: typeof cmState;
42-
/**
43-
* The `@codemirror/language` module.
44-
*/
45-
language: typeof cmLanguage;
46-
};
52+
common: typeof lezerCommon;
4753

4854
/**
49-
* Lezer modules used by MarkEdit.
55+
* The `@lezer/highlight` module.
5056
*/
51-
lezer: {
52-
/**
53-
* The `@lezer/common` module.
54-
*/
55-
common: typeof lezerCommon;
56-
/**
57-
* The `@lezer/highlight` module.
58-
*/
59-
highlight: typeof lezerHighlight;
60-
/**
61-
* The `@lezer/lr` module.
62-
*/
63-
lr: typeof lezerLr;
64-
},
65-
}
57+
highlight: typeof lezerHighlight;
58+
59+
/**
60+
* The `@lezer/lr` module.
61+
*/
62+
lr: typeof lezerLr;
63+
},
64+
65+
/**
66+
* Add an extension to MarkEdit.
67+
* @param extension CodeMirror extension.
68+
*/
69+
addExtension: (extension: Extension) => void;
6670
}
6771

68-
declare interface TextEditable {
72+
export interface TextEditable {
6973
/**
7074
* Get text of the document.
7175
* @param range The range of the text. If no range is provided, the entire document is returned.
7276
*/
7377
getText(range?: TextRange): string;
78+
7479
/**
7580
* Set text for the document.
7681
* @param text The text to set.
7782
* @param range The range of the text. If no range is provided, the entire document is overwritten.
7883
*/
7984
setText(text: string, range?: TextRange): void;
85+
8086
/**
8187
* Get text selections.
8288
*/
8389
getSelections(): TextRange[];
90+
8491
/**
8592
* Set text selections.
8693
* @param ranges Text ranges to set.
8794
*/
8895
setSelections(ranges: TextRange[]): void;
96+
8997
/**
9098
* Get the line number (0-indexed) of given text position.
9199
* @param position The text position.
92100
*/
93101
getLineNumber(position: number): number;
102+
94103
/**
95104
* Get line range of given row (0-indexed).
96105
* @param row The line number.
97106
*/
98107
getLineRange(row: number): TextRange;
108+
99109
/**
100110
* Get number of lines.
101111
*/
102112
getLineCount(): number;
113+
103114
/**
104115
* Get line separator.
105116
*/
106117
getLineBreak(): string;
118+
107119
/**
108120
* Get CodeMirror syntax node name of given position.
109121
* @param position The text position.
110122
*/
111123
getNodeName(position: number): string;
124+
112125
/**
113126
* Undo a change.
114127
*/
115128
undo(): void;
129+
116130
/**
117131
* Redo a change.
118132
*/
119133
redo(): void;
120134
}
121135

122-
declare type TextRange = {
136+
export type TextRange = {
123137
from: number;
124138
to: number;
125-
};
126-
127-
export { MarkEdit, TextEditable, TextRange };
139+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "markedit-api",
3-
"version": "0.0.8",
3+
"version": "0.1.0",
44
"description": "Type definitions for the latest MakrEdit API.",
5-
"main": "",
5+
"main": "main.ts",
66
"types": "markedit.d.ts",
77
"license": "MIT",
88
"peerDependencies": {

0 commit comments

Comments
 (0)