@coldsmirk/inkstone-redis 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/monaco.d.ts +8 -9
- package/dist/react.d.ts +12 -68
- package/dist/react.js +25 -99
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). Built for the [**poly
|
|
|
8
8
|
|
|
9
9
|
- **`@coldsmirk/inkstone-redis`** — the framework-free core: the table, the line reader, the assist, the markers. Zero editor dependencies.
|
|
10
10
|
- **`@coldsmirk/inkstone-redis/monaco`** — `defineRedisLanguage(monaco)` (the `redis` id with its Monarch grammar, once per monaco module), `registerRedisLanguage(monaco, modelPath, hooks)` (completion, hover and signature help for one model), `setRedisMarkers` (the markers as Monaco's own). Peer: `monaco-editor`.
|
|
11
|
-
- **`@coldsmirk/inkstone-redis/react`** — `<RedisEditor>`: a controlled command editor built on `@coldsmirk/inkstone-react`'s `<
|
|
11
|
+
- **`@coldsmirk/inkstone-redis/react`** — `<RedisEditor>`: 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 key trees, and each line's markers refreshed on every change. Peers: `monaco-editor`, `react`.
|
|
12
12
|
|
|
13
13
|
## The shape
|
|
14
14
|
|
package/dist/monaco.d.ts
CHANGED
|
@@ -5,18 +5,18 @@ 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 line under.
|
|
11
11
|
*/
|
|
12
|
-
declare const REDIS_LANGUAGE_ID = "redis";
|
|
12
|
+
export declare const REDIS_LANGUAGE_ID = "redis";
|
|
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
|
* a model created under an id Monaco does not know yet is plain text until it is.
|
|
17
17
|
*/
|
|
18
|
-
declare function defineRedisLanguage(monaco: MonacoModule, languageId?: string, commands?: readonly RedisCommand[]): void;
|
|
19
|
-
interface RedisLanguageHooks {
|
|
18
|
+
export declare function defineRedisLanguage(monaco: MonacoModule, languageId?: string, commands?: readonly RedisCommand[]): void;
|
|
19
|
+
export interface RedisLanguageHooks {
|
|
20
20
|
/**
|
|
21
21
|
* The assist as it stands right now — read per request rather than captured, so the host
|
|
22
22
|
* can swap it without touching Monaco's registry; null answers nothing.
|
|
@@ -28,15 +28,14 @@ interface RedisLanguageHooks {
|
|
|
28
28
|
* caller's to hold: Monaco's registry outlives any editor, and a provider left behind would
|
|
29
29
|
* answer for a model that no longer exists.
|
|
30
30
|
*/
|
|
31
|
-
declare function registerRedisLanguage(monaco: MonacoModule, modelPath: string, hooks: RedisLanguageHooks, languageId?: string): IDisposable[];
|
|
31
|
+
export declare function registerRedisLanguage(monaco: MonacoModule, modelPath: string, hooks: RedisLanguageHooks, languageId?: string): IDisposable[];
|
|
32
32
|
/**
|
|
33
33
|
* The owner Monaco files this package's markers under.
|
|
34
34
|
*/
|
|
35
|
-
declare const REDIS_MARKER_OWNER = "inkstone-redis";
|
|
35
|
+
export declare const REDIS_MARKER_OWNER = "inkstone-redis";
|
|
36
36
|
/**
|
|
37
37
|
* Put `markers` on the model as Monaco's own, replacing this package's last set; the words
|
|
38
38
|
* beside each code are the host's, handed in per code.
|
|
39
39
|
*/
|
|
40
|
-
declare function setRedisMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly RedisMarker[], wording: (marker: RedisMarker) => string): void;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { MonacoModule, REDIS_LANGUAGE_ID, REDIS_MARKER_OWNER, RedisLanguageHooks, defineRedisLanguage, registerRedisLanguage, setRedisMarkers };
|
|
40
|
+
export declare function setRedisMarkers(monaco: MonacoModule, model: editor.ITextModel, markers: readonly RedisMarker[], wording: (marker: RedisMarker) => string): void;
|
|
41
|
+
//#endregion
|
package/dist/react.d.ts
CHANGED
|
@@ -1,79 +1,30 @@
|
|
|
1
1
|
import { h as RedisAssist, t as RedisMarker } from "./markers-Bmqe2Tjf.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 key 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 RedisEditorHandle = ConsoleEditorHandle;
|
|
14
10
|
/**
|
|
15
11
|
* Where the operator is in the document, in offsets — what `runnableLine` reads to decide the
|
|
16
|
-
* line a run sends.
|
|
17
|
-
* selected. It rides with the text because the two must belong to the same instant: the
|
|
18
|
-
* controlled `value` is one render behind the keystroke that triggered a run.
|
|
12
|
+
* line a run sends.
|
|
19
13
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
from: number;
|
|
23
|
-
to: number;
|
|
24
|
-
}
|
|
25
|
-
interface RedisEditorProps {
|
|
26
|
-
value: string;
|
|
27
|
-
onChange: (value: string) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Render with the dark theme; the component never reads the OS `prefers-color-scheme`.
|
|
30
|
-
*
|
|
31
|
-
* @default false
|
|
32
|
-
*/
|
|
33
|
-
dark?: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Editor height in px, or `"fill"` to consume the parent's resolved height (the parent must be
|
|
36
|
-
* a `min-height: 0` flex item).
|
|
37
|
-
*/
|
|
38
|
-
height?: number | "fill";
|
|
39
|
-
fontSize?: number;
|
|
40
|
-
/**
|
|
41
|
-
* UI locale for Monaco's chrome — page-global and locked by the first editor to mount.
|
|
42
|
-
*/
|
|
43
|
-
locale?: "en" | "zh-cn";
|
|
44
|
-
placeholder?: string;
|
|
45
|
-
/**
|
|
46
|
-
* The editor's accessible name, set on Monaco's own input surface.
|
|
47
|
-
*/
|
|
48
|
-
ariaLabel: string;
|
|
14
|
+
export type RedisCaret = ConsoleCaret;
|
|
15
|
+
export interface RedisEditorProps extends ConsoleEditorProps<RedisEditorHandle> {
|
|
49
16
|
/**
|
|
50
17
|
* The Monaco language id the model registers under; the grammar is defined under it.
|
|
51
18
|
*
|
|
52
19
|
* @default "redis"
|
|
53
20
|
*/
|
|
54
21
|
languageId?: string;
|
|
55
|
-
loading?: ReactNode;
|
|
56
|
-
failure?: ReactNode;
|
|
57
|
-
/**
|
|
58
|
-
* Ctrl/Cmd-Enter — the run key, handed the editor's live caret; the host reads the line to
|
|
59
|
-
* send off it with `runnableLine`.
|
|
60
|
-
*/
|
|
61
|
-
onRun?: (caret: RedisCaret) => void;
|
|
62
22
|
/**
|
|
63
23
|
* The label the run action shows in Monaco's own chrome.
|
|
64
24
|
*
|
|
65
25
|
* @default "Run command"
|
|
66
26
|
*/
|
|
67
27
|
runActionLabel?: string;
|
|
68
|
-
/**
|
|
69
|
-
* The caret moved, or the text under it changed.
|
|
70
|
-
*/
|
|
71
|
-
onCaret?: (caret: RedisCaret) => void;
|
|
72
|
-
onReady?: (handle: RedisEditorHandle) => void;
|
|
73
|
-
/**
|
|
74
|
-
* Runs after this component's own mount wiring, with the live editor and the monaco module.
|
|
75
|
-
*/
|
|
76
|
-
onMount?: (instance: editor.IStandaloneCodeEditor, monaco: MonacoModule) => void;
|
|
77
28
|
/**
|
|
78
29
|
* What completion, hover and signature help answer from; none of the three without it.
|
|
79
30
|
*/
|
|
@@ -83,20 +34,13 @@ interface RedisEditorProps {
|
|
|
83
34
|
* markers are drawn without it.
|
|
84
35
|
*/
|
|
85
36
|
markerWording?: (marker: RedisMarker) => string;
|
|
86
|
-
/**
|
|
87
|
-
* Extra construction options, merged under this editor's own (`ariaLabel`): the escape hatch
|
|
88
|
-
* a host reaches for a construction option no prop names — `overflowWidgetsDomNode`, where
|
|
89
|
-
* the page's own layers would otherwise stand over the editor's floating widgets (hover,
|
|
90
|
-
* completion, parameter hints) left inside it.
|
|
91
|
-
*/
|
|
92
|
-
options?: editor.IStandaloneEditorConstructionOptions;
|
|
93
37
|
}
|
|
94
38
|
/**
|
|
95
|
-
* The command-line editing surface:
|
|
96
|
-
* run key handing the caret over
|
|
97
|
-
*
|
|
98
|
-
* one split per line, cheap enough
|
|
39
|
+
* The command-line editing surface: `<MonacoConsoleEditor>` under the `redis` grammar, one
|
|
40
|
+
* command a line, the run key handing the caret over (`runnableLine` reads the line to send off
|
|
41
|
+
* it), the table's completion, hover and signature help wired through `registerRedisLanguage`,
|
|
42
|
+
* and each line's markers refreshed on every change (they are one split per line, cheap enough
|
|
43
|
+
* to run synchronously).
|
|
99
44
|
*/
|
|
100
|
-
declare function RedisEditor({
|
|
101
|
-
//#endregion
|
|
102
|
-
export { RedisCaret, RedisEditor, RedisEditorHandle, RedisEditorProps };
|
|
45
|
+
export declare function RedisEditor({ languageId, runActionLabel, assist, markerWording, ...props }: RedisEditorProps): ReactNode;
|
|
46
|
+
//#endregion
|
package/dist/react.js
CHANGED
|
@@ -1,106 +1,32 @@
|
|
|
1
1
|
import { t as lineMarkers } from "./markers-DFpfcLLE.js";
|
|
2
2
|
import { REDIS_LANGUAGE_ID, defineRedisLanguage, registerRedisLanguage, setRedisMarkers } 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 RedisEditor({ value, onChange, dark = false, height = 200, fontSize, locale, placeholder, ariaLabel, languageId = REDIS_LANGUAGE_ID, loading, failure, onRun, runActionLabel = "Run command", onCaret, onReady, onMount, assist, markerWording, options }) {
|
|
36
|
-
const [modelPath] = useState(() => `file:///inkstone-redis/${String(nextEditorId())}.redis`);
|
|
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
|
-
defineRedisLanguage(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) setRedisMarkers(monaco, model, lineMarkers(model.getValue()), wording);
|
|
79
|
-
};
|
|
80
|
-
bindings.current.push(live.onDidChangeCursorSelection(() => caretChangedRef.current?.(caretOf(live))), live.onDidChangeModelContent(mark), live.addAction({
|
|
81
|
-
id: "inkstone-redis.run",
|
|
82
|
-
label: runActionLabel,
|
|
83
|
-
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
|
|
84
|
-
run: (current) => runRef.current?.(caretOf(current))
|
|
85
|
-
}), ...registerRedisLanguage(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-redis-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 RedisEditor({ languageId = REDIS_LANGUAGE_ID, runActionLabel = "Run command", assist, markerWording, ...props }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(MonacoConsoleEditor, {
|
|
8
|
+
...props,
|
|
9
|
+
context: {
|
|
10
|
+
assist,
|
|
11
|
+
markerWording
|
|
12
|
+
},
|
|
13
|
+
extension: "redis",
|
|
14
|
+
language: languageId,
|
|
15
|
+
namespace: "inkstone-redis",
|
|
16
|
+
runActionLabel,
|
|
17
|
+
beforeMount: (monaco) => {
|
|
18
|
+
defineRedisLanguage(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) setRedisMarkers(monaco, model, lineMarkers(model.getValue()), wording);
|
|
25
|
+
};
|
|
26
|
+
const registered = [editor.onDidChangeModelContent(mark), ...registerRedisLanguage(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-redis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Redis command-line editing intelligence for Monaco: the command table of Redis 7.2 (names, syntax, arity), redis-cli's own line splitting, completion / hover / signature help, line markers, and a drop-in React command editor.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"redis",
|
|
@@ -42,15 +42,14 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"monaco-editor": "^0.
|
|
46
|
-
"react": "^19.
|
|
47
|
-
"react
|
|
48
|
-
"@coldsmirk/inkstone-react": "^0.30.0"
|
|
45
|
+
"monaco-editor": "^0.57.0",
|
|
46
|
+
"react": "^19.3.0",
|
|
47
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
|
-
"monaco-editor": "^0.
|
|
50
|
+
"monaco-editor": "^0.57.0",
|
|
52
51
|
"react": ">=19",
|
|
53
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
52
|
+
"@coldsmirk/inkstone-react": "^0.32.0"
|
|
54
53
|
},
|
|
55
54
|
"peerDependenciesMeta": {
|
|
56
55
|
"@coldsmirk/inkstone-react": {
|