@coldsmirk/inkstone-mongodb 0.30.0 → 0.32.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/README.md +1 -1
- package/dist/codemirror.d.ts +5 -6
- package/dist/monaco.d.ts +8 -9
- package/dist/react.d.ts +11 -66
- package/dist/react.js +25 -99
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). Built for the [**poly
|
|
|
9
9
|
- **`@coldsmirk/inkstone-mongodb`** — the framework-free core: the document reader, the command table, the operator vocabularies, the assist, the markers. Zero editor dependencies.
|
|
10
10
|
- **`@coldsmirk/inkstone-mongodb/monaco`** — `defineMongodbLanguage(monaco)` (the `mongodb` id with its Monarch grammar, once per monaco module), `registerMongodbLanguage(monaco, modelPath, hooks)` (completion and hover for one model), `setMongodbMarkers`. Peer: `monaco-editor`.
|
|
11
11
|
- **`@coldsmirk/inkstone-mongodb/codemirror`** — the same assist bound to CodeMirror 6: `mongodbCompletion(assist)` and `mongodbFilterCompletion(assist)` (completion sources), `mongodbHover(assist, wording)`, `mongodbDiagnostics(markers, wording)`. No grammar of its own — a filter document is JSON, so pair it with `@codemirror/lang-json`; it does not close brackets or quotes either, so add `closeBrackets()` where a key's own quotes matter. Peers: `@codemirror/autocomplete`, `@codemirror/view`.
|
|
12
|
-
- **`@coldsmirk/inkstone-mongodb/react`** — `<MongodbEditor>`: a controlled command editor built on `@coldsmirk/inkstone-react`'s `<
|
|
12
|
+
- **`@coldsmirk/inkstone-mongodb/react`** — `<MongodbEditor>`: a controlled command editor built on `@coldsmirk/inkstone-react`'s `<MonacoConsoleEditor>`, with a run key (Ctrl/Cmd-Enter handing over the live caret), caret tracking, an insert handle for collection trees, and the markers refreshed on every change. Peers: `monaco-editor`, `react`.
|
|
13
13
|
|
|
14
14
|
## The shape
|
|
15
15
|
|
package/dist/codemirror.d.ts
CHANGED
|
@@ -6,21 +6,20 @@ import { Extension } from "@codemirror/state";
|
|
|
6
6
|
/**
|
|
7
7
|
* Completion over a whole command document, off an assist built with the host's catalog.
|
|
8
8
|
*/
|
|
9
|
-
declare function mongodbCompletion(assist: MongodbAssist): CompletionSource;
|
|
9
|
+
export declare function mongodbCompletion(assist: MongodbAssist): CompletionSource;
|
|
10
10
|
/**
|
|
11
11
|
* Completion over a query document standing on its own — a one-line filter field, whose
|
|
12
12
|
* document is the filter and nothing else (`createMongodbFilterAssist`).
|
|
13
13
|
*/
|
|
14
|
-
declare function mongodbFilterCompletion(assist: MongodbFilterAssist): CompletionSource;
|
|
14
|
+
export declare function mongodbFilterCompletion(assist: MongodbFilterAssist): CompletionSource;
|
|
15
15
|
/**
|
|
16
16
|
* The command's card under the pointer, as `./monaco`'s hover provider gives it. The markdown
|
|
17
17
|
* is handed over as text: rendering it is the host's, since a tooltip's DOM is the host's
|
|
18
18
|
* design and this package ships none.
|
|
19
19
|
*/
|
|
20
|
-
declare function mongodbHover(assist: MongodbAssist, render: (markdown: string[]) => HTMLElement): Extension;
|
|
20
|
+
export declare function mongodbHover(assist: MongodbAssist, render: (markdown: string[]) => HTMLElement): Extension;
|
|
21
21
|
/**
|
|
22
22
|
* This package's markers as CodeMirror's diagnostics, the words beside each code the host's.
|
|
23
23
|
*/
|
|
24
|
-
declare function mongodbDiagnostics(markers: readonly MongodbMarker[], wording: (marker: MongodbMarker) => string): Diagnostic[];
|
|
25
|
-
//#endregion
|
|
26
|
-
export { mongodbCompletion, mongodbDiagnostics, mongodbFilterCompletion, mongodbHover };
|
|
24
|
+
export declare function mongodbDiagnostics(markers: readonly MongodbMarker[], wording: (marker: MongodbMarker) => string): Diagnostic[];
|
|
25
|
+
//#endregion
|
package/dist/monaco.d.ts
CHANGED
|
@@ -5,17 +5,17 @@ import { IDisposable, editor } from "monaco-editor";
|
|
|
5
5
|
/**
|
|
6
6
|
* The monaco module itself, as `onMount` hands it over.
|
|
7
7
|
*/
|
|
8
|
-
type MonacoModule = typeof monacoEditor;
|
|
8
|
+
export type MonacoModule = typeof monacoEditor;
|
|
9
9
|
/**
|
|
10
10
|
* The language id the editor registers a command document under.
|
|
11
11
|
*/
|
|
12
|
-
declare const MONGODB_LANGUAGE_ID = "mongodb";
|
|
12
|
+
export declare const MONGODB_LANGUAGE_ID = "mongodb";
|
|
13
13
|
/**
|
|
14
14
|
* Register the language — the id, its Monarch grammar and its bracket configuration — once per
|
|
15
15
|
* monaco module. Call it before the first model of the language is created (`beforeMount`).
|
|
16
16
|
*/
|
|
17
|
-
declare function defineMongodbLanguage(monaco: MonacoModule, languageId?: string): void;
|
|
18
|
-
interface MongodbLanguageHooks {
|
|
17
|
+
export declare function defineMongodbLanguage(monaco: MonacoModule, languageId?: string): void;
|
|
18
|
+
export interface MongodbLanguageHooks {
|
|
19
19
|
/**
|
|
20
20
|
* The assist as it stands right now — read per request rather than captured, so the host
|
|
21
21
|
* can swap it without touching Monaco's registry; null answers nothing.
|
|
@@ -26,15 +26,14 @@ interface MongodbLanguageHooks {
|
|
|
26
26
|
* Register completion and hover for one model. The disposables are the caller's to hold:
|
|
27
27
|
* Monaco's registry outlives any editor.
|
|
28
28
|
*/
|
|
29
|
-
declare function registerMongodbLanguage(monaco: MonacoModule, modelPath: string, hooks: MongodbLanguageHooks, languageId?: string): IDisposable[];
|
|
29
|
+
export declare function registerMongodbLanguage(monaco: MonacoModule, modelPath: string, hooks: MongodbLanguageHooks, languageId?: string): IDisposable[];
|
|
30
30
|
/**
|
|
31
31
|
* The owner Monaco files this package's markers under.
|
|
32
32
|
*/
|
|
33
|
-
declare const MONGODB_MARKER_OWNER = "inkstone-mongodb";
|
|
33
|
+
export declare const MONGODB_MARKER_OWNER = "inkstone-mongodb";
|
|
34
34
|
/**
|
|
35
35
|
* Put `markers` on the model as Monaco's own, replacing this package's last set; the words
|
|
36
36
|
* beside each code are the host's, handed in per code.
|
|
37
37
|
*/
|
|
38
|
-
declare function setMongodbMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly MongodbMarker[], wording: (marker: MongodbMarker) => string): void;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { MONGODB_LANGUAGE_ID, MONGODB_MARKER_OWNER, MonacoModule, MongodbLanguageHooks, defineMongodbLanguage, registerMongodbLanguage, setMongodbMarkers };
|
|
38
|
+
export declare function setMongodbMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly MongodbMarker[], wording: (marker: MongodbMarker) => string): void;
|
|
39
|
+
//#endregion
|
package/dist/react.d.ts
CHANGED
|
@@ -1,78 +1,30 @@
|
|
|
1
1
|
import { m as MongodbAssist, t as MongodbMarker } from "./markers-Co8ntyUI.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ConsoleCaret, ConsoleEditorHandle, ConsoleEditorProps } from "@coldsmirk/inkstone-react/monaco";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
|
-
import { editor } from "monaco-editor";
|
|
5
4
|
//#region src/react.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* What a host reaches into the editor for: inserting at the caret — a collection tree is an
|
|
8
7
|
* input device — and the focus.
|
|
9
8
|
*/
|
|
10
|
-
|
|
11
|
-
insert: (text: string) => void;
|
|
12
|
-
focus: () => void;
|
|
13
|
-
}
|
|
9
|
+
export type MongodbEditorHandle = ConsoleEditorHandle;
|
|
14
10
|
/**
|
|
15
11
|
* Where the operator is in the document, in offsets — what `runnableDocument` reads to decide
|
|
16
|
-
* what a run sends.
|
|
17
|
-
* selected; the text rides with them because the two must belong to the same instant.
|
|
12
|
+
* what a run sends.
|
|
18
13
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
from: number;
|
|
22
|
-
to: number;
|
|
23
|
-
}
|
|
24
|
-
interface MongodbEditorProps {
|
|
25
|
-
value: string;
|
|
26
|
-
onChange: (value: string) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Render with the dark theme; the component never reads the OS `prefers-color-scheme`.
|
|
29
|
-
*
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
dark?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Editor height in px, or `"fill"` to consume the parent's resolved height (the parent must be
|
|
35
|
-
* a `min-height: 0` flex item).
|
|
36
|
-
*/
|
|
37
|
-
height?: number | "fill";
|
|
38
|
-
fontSize?: number;
|
|
39
|
-
/**
|
|
40
|
-
* UI locale for Monaco's chrome — page-global and locked by the first editor to mount.
|
|
41
|
-
*/
|
|
42
|
-
locale?: "en" | "zh-cn";
|
|
43
|
-
placeholder?: string;
|
|
44
|
-
/**
|
|
45
|
-
* The editor's accessible name, set on Monaco's own input surface.
|
|
46
|
-
*/
|
|
47
|
-
ariaLabel: string;
|
|
14
|
+
export type MongodbCaret = ConsoleCaret;
|
|
15
|
+
export interface MongodbEditorProps extends ConsoleEditorProps<MongodbEditorHandle> {
|
|
48
16
|
/**
|
|
49
17
|
* The Monaco language id the model registers under; the grammar is defined under it.
|
|
50
18
|
*
|
|
51
19
|
* @default "mongodb"
|
|
52
20
|
*/
|
|
53
21
|
languageId?: string;
|
|
54
|
-
loading?: ReactNode;
|
|
55
|
-
failure?: ReactNode;
|
|
56
|
-
/**
|
|
57
|
-
* Ctrl/Cmd-Enter — the run key, handed the editor's live caret; the host reads the document
|
|
58
|
-
* to send off it with `runnableDocument`.
|
|
59
|
-
*/
|
|
60
|
-
onRun?: (caret: MongodbCaret) => void;
|
|
61
22
|
/**
|
|
62
23
|
* The label the run action shows in Monaco's own chrome.
|
|
63
24
|
*
|
|
64
25
|
* @default "Run command"
|
|
65
26
|
*/
|
|
66
27
|
runActionLabel?: string;
|
|
67
|
-
/**
|
|
68
|
-
* The caret moved, or the text under it changed.
|
|
69
|
-
*/
|
|
70
|
-
onCaret?: (caret: MongodbCaret) => void;
|
|
71
|
-
onReady?: (handle: MongodbEditorHandle) => void;
|
|
72
|
-
/**
|
|
73
|
-
* Runs after this component's own mount wiring, with the live editor and the monaco module.
|
|
74
|
-
*/
|
|
75
|
-
onMount?: (instance: editor.IStandaloneCodeEditor, monaco: MonacoModule) => void;
|
|
76
28
|
/**
|
|
77
29
|
* What completion and hover answer from; neither without it.
|
|
78
30
|
*/
|
|
@@ -82,19 +34,12 @@ interface MongodbEditorProps {
|
|
|
82
34
|
* markers are drawn without it.
|
|
83
35
|
*/
|
|
84
36
|
markerWording?: (marker: MongodbMarker) => string;
|
|
85
|
-
/**
|
|
86
|
-
* Extra construction options, merged under this editor's own (`ariaLabel`): the escape hatch
|
|
87
|
-
* a host reaches for a construction option no prop names — `overflowWidgetsDomNode`, where
|
|
88
|
-
* the page's own layers would otherwise stand over the editor's floating widgets (hover,
|
|
89
|
-
* completion, parameter hints) left inside it.
|
|
90
|
-
*/
|
|
91
|
-
options?: editor.IStandaloneEditorConstructionOptions;
|
|
92
37
|
}
|
|
93
38
|
/**
|
|
94
|
-
* The command editing surface:
|
|
95
|
-
* shell's spelling, the run key handing the caret over
|
|
96
|
-
*
|
|
39
|
+
* The command editing surface: `<MonacoConsoleEditor>` under the `mongodb` grammar, one command
|
|
40
|
+
* document in the shell's spelling, the run key handing the caret over (`runnableDocument` reads
|
|
41
|
+
* what to send off it), completion and hover wired through `registerMongodbLanguage`, and the
|
|
42
|
+
* markers refreshed on every change.
|
|
97
43
|
*/
|
|
98
|
-
declare function MongodbEditor({
|
|
99
|
-
//#endregion
|
|
100
|
-
export { MongodbCaret, MongodbEditor, MongodbEditorHandle, MongodbEditorProps };
|
|
44
|
+
export declare function MongodbEditor({ languageId, runActionLabel, assist, markerWording, ...props }: MongodbEditorProps): ReactNode;
|
|
45
|
+
//#endregion
|
package/dist/react.js
CHANGED
|
@@ -1,106 +1,32 @@
|
|
|
1
1
|
import { t as documentMarkers } from "./markers-30Z4EFiH.js";
|
|
2
2
|
import { MONGODB_LANGUAGE_ID, defineMongodbLanguage, registerMongodbLanguage, setMongodbMarkers } from "./monaco.js";
|
|
3
|
-
import {
|
|
4
|
-
import { useEffect, useInsertionEffect, useRef, useState } from "react";
|
|
3
|
+
import { MonacoConsoleEditor } from "@coldsmirk/inkstone-react/monaco";
|
|
5
4
|
import { jsx } from "react/jsx-runtime";
|
|
6
5
|
//#region src/react.tsx
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
from: model.getOffsetAt(selection.getStartPosition()),
|
|
32
|
-
to: model.getOffsetAt(selection.getEndPosition())
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
function MongodbEditor({ value, onChange, dark = false, height = 200, fontSize, locale, placeholder, ariaLabel, languageId = MONGODB_LANGUAGE_ID, loading, failure, onRun, runActionLabel = "Run command", onCaret, onReady, onMount, assist, markerWording, options }) {
|
|
36
|
-
const [modelPath] = useState(() => `file:///inkstone-mongodb/${String(nextEditorId())}.mongodb`);
|
|
37
|
-
const bindings = useRef([]);
|
|
38
|
-
const assistRef = useLatest(assist ?? null);
|
|
39
|
-
const runRef = useLatest(onRun);
|
|
40
|
-
const caretChangedRef = useLatest(onCaret);
|
|
41
|
-
const readyRef = useLatest(onReady);
|
|
42
|
-
const mountRef = useLatest(onMount);
|
|
43
|
-
const wordingRef = useLatest(markerWording);
|
|
44
|
-
useEffect(() => () => {
|
|
45
|
-
for (const binding of bindings.current) binding.dispose();
|
|
46
|
-
bindings.current = [];
|
|
47
|
-
}, []);
|
|
48
|
-
const fill = height === "fill";
|
|
49
|
-
return /* @__PURE__ */ jsx("div", {
|
|
50
|
-
style: fill ? {
|
|
51
|
-
height: "100%",
|
|
52
|
-
minHeight: 0
|
|
53
|
-
} : { height },
|
|
54
|
-
children: /* @__PURE__ */ jsx(MonacoEditor, {
|
|
55
|
-
showLineNumbers: true,
|
|
56
|
-
dark,
|
|
57
|
-
failure,
|
|
58
|
-
fontSize,
|
|
59
|
-
height: fill ? "100%" : height,
|
|
60
|
-
language: languageId,
|
|
61
|
-
loading,
|
|
62
|
-
locale,
|
|
63
|
-
options: {
|
|
64
|
-
...options,
|
|
65
|
-
ariaLabel
|
|
66
|
-
},
|
|
67
|
-
path: modelPath,
|
|
68
|
-
placeholder,
|
|
69
|
-
value,
|
|
70
|
-
beforeMount: (monaco) => {
|
|
71
|
-
defineMongodbLanguage(monaco, languageId);
|
|
72
|
-
},
|
|
73
|
-
onChange,
|
|
74
|
-
onMount: (live, monaco) => {
|
|
75
|
-
const mark = () => {
|
|
76
|
-
const model = live.getModel();
|
|
77
|
-
const wording = wordingRef.current;
|
|
78
|
-
if (model !== null && wording !== void 0) setMongodbMarkers(monaco, model, documentMarkers(model.getValue()), wording);
|
|
79
|
-
};
|
|
80
|
-
bindings.current.push(live.onDidChangeCursorSelection(() => caretChangedRef.current?.(caretOf(live))), live.onDidChangeModelContent(mark), live.addAction({
|
|
81
|
-
id: "inkstone-mongodb.run",
|
|
82
|
-
label: runActionLabel,
|
|
83
|
-
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
|
|
84
|
-
run: (current) => runRef.current?.(caretOf(current))
|
|
85
|
-
}), ...registerMongodbLanguage(monaco, modelPath, { assist: () => assistRef.current }, languageId));
|
|
86
|
-
mark();
|
|
87
|
-
readyRef.current?.({
|
|
88
|
-
insert: (text) => {
|
|
89
|
-
const selection = live.getSelection();
|
|
90
|
-
if (selection) live.executeEdits("inkstone-mongodb-insert", [{
|
|
91
|
-
range: selection,
|
|
92
|
-
text,
|
|
93
|
-
forceMoveMarkers: true
|
|
94
|
-
}]);
|
|
95
|
-
live.focus();
|
|
96
|
-
},
|
|
97
|
-
focus: () => {
|
|
98
|
-
live.focus();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
mountRef.current?.(live, monaco);
|
|
102
|
-
}
|
|
103
|
-
})
|
|
6
|
+
function MongodbEditor({ languageId = MONGODB_LANGUAGE_ID, runActionLabel = "Run command", assist, markerWording, ...props }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(MonacoConsoleEditor, {
|
|
8
|
+
...props,
|
|
9
|
+
context: {
|
|
10
|
+
assist,
|
|
11
|
+
markerWording
|
|
12
|
+
},
|
|
13
|
+
extension: "mongodb",
|
|
14
|
+
language: languageId,
|
|
15
|
+
namespace: "inkstone-mongodb",
|
|
16
|
+
runActionLabel,
|
|
17
|
+
beforeMount: (monaco) => {
|
|
18
|
+
defineMongodbLanguage(monaco, languageId);
|
|
19
|
+
},
|
|
20
|
+
register: ({ monaco, editor, path, context }) => {
|
|
21
|
+
const mark = () => {
|
|
22
|
+
const model = editor.getModel();
|
|
23
|
+
const wording = context().markerWording;
|
|
24
|
+
if (model !== null && wording !== void 0) setMongodbMarkers(monaco, model, documentMarkers(model.getValue()), wording);
|
|
25
|
+
};
|
|
26
|
+
const registered = [editor.onDidChangeModelContent(mark), ...registerMongodbLanguage(monaco, path, { assist: () => context().assist ?? null }, languageId)];
|
|
27
|
+
mark();
|
|
28
|
+
return registered;
|
|
29
|
+
}
|
|
104
30
|
});
|
|
105
31
|
}
|
|
106
32
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coldsmirk/inkstone-mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "MongoDB command editing intelligence for Monaco and CodeMirror: a command document in the shell's own spelling, the database commands and their fields, query, update and aggregation operators by context — a bare filter document included — collection completion, markers, and a drop-in React command editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mongodb",
|
|
@@ -50,21 +50,20 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@codemirror/autocomplete": "^6.20.3",
|
|
52
52
|
"@codemirror/lint": "^6.9.7",
|
|
53
|
-
"@codemirror/state": "^6.6
|
|
54
|
-
"@codemirror/view": "^6.43.
|
|
55
|
-
"monaco-editor": "^0.
|
|
56
|
-
"react": "^19.
|
|
57
|
-
"react
|
|
58
|
-
"@coldsmirk/inkstone-react": "^0.30.0"
|
|
53
|
+
"@codemirror/state": "^6.7.6",
|
|
54
|
+
"@codemirror/view": "^6.43.14",
|
|
55
|
+
"monaco-editor": "^0.57.0",
|
|
56
|
+
"react": "^19.3.0",
|
|
57
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
59
58
|
},
|
|
60
59
|
"peerDependencies": {
|
|
61
60
|
"@codemirror/autocomplete": "^6.20.3",
|
|
62
61
|
"@codemirror/lint": "^6.9.7",
|
|
63
62
|
"@codemirror/state": "^6.6.0",
|
|
64
63
|
"@codemirror/view": "^6.43.0",
|
|
65
|
-
"monaco-editor": "^0.
|
|
64
|
+
"monaco-editor": "^0.57.0",
|
|
66
65
|
"react": ">=19",
|
|
67
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
66
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
68
67
|
},
|
|
69
68
|
"peerDependenciesMeta": {
|
|
70
69
|
"@codemirror/autocomplete": {
|