@coldsmirk/inkstone-elasticsearch 0.31.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/react.d.ts +10 -64
- package/dist/react.js +25 -99
- package/package.json +3 -3
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/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
|
-
export
|
|
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
|
-
export
|
|
20
|
-
|
|
21
|
-
from: number;
|
|
22
|
-
to: number;
|
|
23
|
-
}
|
|
24
|
-
export 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,18 +34,12 @@ export 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
|
-
export declare function ElasticsearchEditor({
|
|
44
|
+
export declare function ElasticsearchEditor({ languageId, runActionLabel, assist, markerWording, ...props }: ElasticsearchEditorProps): ReactNode;
|
|
99
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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@codemirror/view": "^6.43.14",
|
|
55
55
|
"monaco-editor": "^0.57.0",
|
|
56
56
|
"react": "^19.3.0",
|
|
57
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
57
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@codemirror/autocomplete": "^6.20.3",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@codemirror/view": "^6.43.0",
|
|
64
64
|
"monaco-editor": "^0.57.0",
|
|
65
65
|
"react": ">=19",
|
|
66
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
66
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
|
69
69
|
"@codemirror/autocomplete": {
|