@coldsmirk/inkstone-elasticsearch 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-elasticsearch`** — the framework-free core: the request reader, the endpoint table, the body vocabulary, the assist, the markers. Zero editor dependencies.
|
|
10
10
|
- **`@coldsmirk/inkstone-elasticsearch/monaco`** — `defineElasticsearchLanguage(monaco)` (the `elasticsearch` id with its Monarch grammar, once per monaco module), `registerElasticsearchLanguage(monaco, modelPath, hooks)` (completion and hover for one model), `setElasticsearchMarkers`. Peer: `monaco-editor`.
|
|
11
11
|
- **`@coldsmirk/inkstone-elasticsearch/codemirror`** — the same assist bound to CodeMirror 6: `elasticsearchCompletion(assist)` and `elasticsearchBodyCompletion(assist)` (completion sources), `elasticsearchHover(assist, wording)`, `elasticsearchDiagnostics(markers, wording)`. No grammar of its own — a body 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-elasticsearch/react`** — `<ElasticsearchEditor>`: a controlled request editor built on `@coldsmirk/inkstone-react`'s `<
|
|
12
|
+
- **`@coldsmirk/inkstone-elasticsearch/react`** — `<ElasticsearchEditor>`: a controlled request 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 index 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
|
@@ -10,23 +10,22 @@ import { Extension } from "@codemirror/state";
|
|
|
10
10
|
* places `./monaco` names as trigger characters, and the engine half answers nothing where
|
|
11
11
|
* the caret is nowhere in particular.
|
|
12
12
|
*/
|
|
13
|
-
declare function elasticsearchCompletion(assist: ElasticsearchAssist): CompletionSource;
|
|
13
|
+
export declare function elasticsearchCompletion(assist: ElasticsearchAssist): CompletionSource;
|
|
14
14
|
/**
|
|
15
15
|
* Completion over a body standing on its own — a one-line filter field, whose document is a
|
|
16
16
|
* `query` object and nothing else (`createElasticsearchBodyAssist`).
|
|
17
17
|
*/
|
|
18
|
-
declare function elasticsearchBodyCompletion(assist: ElasticsearchBodyAssist): CompletionSource;
|
|
18
|
+
export declare function elasticsearchBodyCompletion(assist: ElasticsearchBodyAssist): CompletionSource;
|
|
19
19
|
/**
|
|
20
20
|
* The endpoint's card under the pointer, as `./monaco`'s hover provider gives it.
|
|
21
21
|
*
|
|
22
22
|
* The markdown is handed over as text: rendering it is the host's, since a tooltip's DOM is
|
|
23
23
|
* the host's design and this package ships none.
|
|
24
24
|
*/
|
|
25
|
-
declare function elasticsearchHover(assist: ElasticsearchAssist, render: (markdown: string[]) => HTMLElement): Extension;
|
|
25
|
+
export declare function elasticsearchHover(assist: ElasticsearchAssist, render: (markdown: string[]) => HTMLElement): Extension;
|
|
26
26
|
/**
|
|
27
27
|
* This package's markers as CodeMirror's diagnostics, the words beside each code the host's,
|
|
28
28
|
* as `setElasticsearchMarkers` takes them.
|
|
29
29
|
*/
|
|
30
|
-
declare function elasticsearchDiagnostics(markers: readonly ElasticsearchMarker[], wording: (marker: ElasticsearchMarker) => string): Diagnostic[];
|
|
31
|
-
//#endregion
|
|
32
|
-
export { elasticsearchBodyCompletion, elasticsearchCompletion, elasticsearchDiagnostics, elasticsearchHover };
|
|
30
|
+
export declare function elasticsearchDiagnostics(markers: readonly ElasticsearchMarker[], wording: (marker: ElasticsearchMarker) => string): Diagnostic[];
|
|
31
|
+
//#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 request under.
|
|
11
11
|
*/
|
|
12
|
-
declare const ELASTICSEARCH_LANGUAGE_ID = "elasticsearch";
|
|
12
|
+
export declare const ELASTICSEARCH_LANGUAGE_ID = "elasticsearch";
|
|
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 defineElasticsearchLanguage(monaco: MonacoModule, languageId?: string): void;
|
|
18
|
-
interface ElasticsearchLanguageHooks {
|
|
17
|
+
export declare function defineElasticsearchLanguage(monaco: MonacoModule, languageId?: string): void;
|
|
18
|
+
export interface ElasticsearchLanguageHooks {
|
|
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 ElasticsearchLanguageHooks {
|
|
|
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 registerElasticsearchLanguage(monaco: MonacoModule, modelPath: string, hooks: ElasticsearchLanguageHooks, languageId?: string): IDisposable[];
|
|
29
|
+
export declare function registerElasticsearchLanguage(monaco: MonacoModule, modelPath: string, hooks: ElasticsearchLanguageHooks, languageId?: string): IDisposable[];
|
|
30
30
|
/**
|
|
31
31
|
* The owner Monaco files this package's markers under.
|
|
32
32
|
*/
|
|
33
|
-
declare const ELASTICSEARCH_MARKER_OWNER = "inkstone-elasticsearch";
|
|
33
|
+
export declare const ELASTICSEARCH_MARKER_OWNER = "inkstone-elasticsearch";
|
|
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 setElasticsearchMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly ElasticsearchMarker[], wording: (marker: ElasticsearchMarker) => string): void;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { ELASTICSEARCH_LANGUAGE_ID, ELASTICSEARCH_MARKER_OWNER, ElasticsearchLanguageHooks, MonacoModule, defineElasticsearchLanguage, registerElasticsearchLanguage, setElasticsearchMarkers };
|
|
38
|
+
export declare function setElasticsearchMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly ElasticsearchMarker[], wording: (marker: ElasticsearchMarker) => string): void;
|
|
39
|
+
//#endregion
|
package/dist/react.d.ts
CHANGED
|
@@ -1,78 +1,30 @@
|
|
|
1
1
|
import { a as ElasticsearchAssist, t as ElasticsearchMarker } from "./markers-CCVlVnBt.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 — an index tree is an input
|
|
8
7
|
* device — and the focus.
|
|
9
8
|
*/
|
|
10
|
-
|
|
11
|
-
insert: (text: string) => void;
|
|
12
|
-
focus: () => void;
|
|
13
|
-
}
|
|
9
|
+
export type ElasticsearchEditorHandle = ConsoleEditorHandle;
|
|
14
10
|
/**
|
|
15
11
|
* Where the operator is in the document, in offsets — what `runnableRequest` reads to decide
|
|
16
|
-
* the request a run sends.
|
|
17
|
-
* is selected; the text rides with them because the two must belong to the same instant.
|
|
12
|
+
* the request a run sends.
|
|
18
13
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
from: number;
|
|
22
|
-
to: number;
|
|
23
|
-
}
|
|
24
|
-
interface ElasticsearchEditorProps {
|
|
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 ElasticsearchCaret = ConsoleCaret;
|
|
15
|
+
export interface ElasticsearchEditorProps extends ConsoleEditorProps<ElasticsearchEditorHandle> {
|
|
48
16
|
/**
|
|
49
17
|
* The Monaco language id the model registers under; the grammar is defined under it.
|
|
50
18
|
*
|
|
51
19
|
* @default "elasticsearch"
|
|
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 request
|
|
58
|
-
* to send off it with `runnableRequest`.
|
|
59
|
-
*/
|
|
60
|
-
onRun?: (caret: ElasticsearchCaret) => void;
|
|
61
22
|
/**
|
|
62
23
|
* The label the run action shows in Monaco's own chrome.
|
|
63
24
|
*
|
|
64
25
|
* @default "Run request"
|
|
65
26
|
*/
|
|
66
27
|
runActionLabel?: string;
|
|
67
|
-
/**
|
|
68
|
-
* The caret moved, or the text under it changed.
|
|
69
|
-
*/
|
|
70
|
-
onCaret?: (caret: ElasticsearchCaret) => void;
|
|
71
|
-
onReady?: (handle: ElasticsearchEditorHandle) => 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 ElasticsearchEditorProps {
|
|
|
82
34
|
* markers are drawn without it.
|
|
83
35
|
*/
|
|
84
36
|
markerWording?: (marker: ElasticsearchMarker) => 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 request editing surface:
|
|
95
|
-
* in the console's spelling, the run key handing the caret over
|
|
96
|
-
*
|
|
39
|
+
* The request editing surface: `<MonacoConsoleEditor>` under the `elasticsearch` grammar, one or
|
|
40
|
+
* more requests in the console's spelling, the run key handing the caret over (`runnableRequest`
|
|
41
|
+
* reads the request to send off it), completion and hover wired through
|
|
42
|
+
* `registerElasticsearchLanguage`, and the markers refreshed on every change.
|
|
97
43
|
*/
|
|
98
|
-
declare function ElasticsearchEditor({
|
|
99
|
-
//#endregion
|
|
100
|
-
export { ElasticsearchCaret, ElasticsearchEditor, ElasticsearchEditorHandle, ElasticsearchEditorProps };
|
|
44
|
+
export declare function ElasticsearchEditor({ languageId, runActionLabel, assist, markerWording, ...props }: ElasticsearchEditorProps): ReactNode;
|
|
45
|
+
//#endregion
|
package/dist/react.js
CHANGED
|
@@ -1,106 +1,32 @@
|
|
|
1
1
|
import { t as requestMarkers } from "./markers-DDAAW21w.js";
|
|
2
2
|
import { ELASTICSEARCH_LANGUAGE_ID, defineElasticsearchLanguage, registerElasticsearchLanguage, setElasticsearchMarkers } 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 ElasticsearchEditor({ value, onChange, dark = false, height = 200, fontSize, locale, placeholder, ariaLabel, languageId = ELASTICSEARCH_LANGUAGE_ID, loading, failure, onRun, runActionLabel = "Run request", onCaret, onReady, onMount, assist, markerWording, options }) {
|
|
36
|
-
const [modelPath] = useState(() => `file:///inkstone-elasticsearch/${String(nextEditorId())}.es`);
|
|
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
|
-
defineElasticsearchLanguage(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) setElasticsearchMarkers(monaco, model, requestMarkers(model.getValue()), wording);
|
|
79
|
-
};
|
|
80
|
-
bindings.current.push(live.onDidChangeCursorSelection(() => caretChangedRef.current?.(caretOf(live))), live.onDidChangeModelContent(mark), live.addAction({
|
|
81
|
-
id: "inkstone-elasticsearch.run",
|
|
82
|
-
label: runActionLabel,
|
|
83
|
-
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
|
|
84
|
-
run: (current) => runRef.current?.(caretOf(current))
|
|
85
|
-
}), ...registerElasticsearchLanguage(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-elasticsearch-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 ElasticsearchEditor({ languageId = ELASTICSEARCH_LANGUAGE_ID, runActionLabel = "Run request", assist, markerWording, ...props }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(MonacoConsoleEditor, {
|
|
8
|
+
...props,
|
|
9
|
+
context: {
|
|
10
|
+
assist,
|
|
11
|
+
markerWording
|
|
12
|
+
},
|
|
13
|
+
extension: "es",
|
|
14
|
+
language: languageId,
|
|
15
|
+
namespace: "inkstone-elasticsearch",
|
|
16
|
+
runActionLabel,
|
|
17
|
+
beforeMount: (monaco) => {
|
|
18
|
+
defineElasticsearchLanguage(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) setElasticsearchMarkers(monaco, model, requestMarkers(model.getValue()), wording);
|
|
25
|
+
};
|
|
26
|
+
const registered = [editor.onDidChangeModelContent(mark), ...registerElasticsearchLanguage(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-elasticsearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Elasticsearch request editing intelligence for Monaco and CodeMirror: the console spelling (a method and a path, the body after), endpoint and index completion, body keys by context — a bare `_search` body included — request markers, and a drop-in React request editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elasticsearch",
|
|
@@ -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": {
|