@coldsmirk/inkstone-redis 0.31.0 → 0.33.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 +11 -66
- package/dist/react.js +25 -99
- package/package.json +3 -3
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/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
|
-
export
|
|
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
|
-
export
|
|
21
|
-
|
|
22
|
-
from: number;
|
|
23
|
-
to: number;
|
|
24
|
-
}
|
|
25
|
-
export 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,19 +34,13 @@ export 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
|
-
export declare function RedisEditor({
|
|
45
|
+
export declare function RedisEditor({ languageId, runActionLabel, assist, markerWording, ...props }: RedisEditorProps): ReactNode;
|
|
101
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.33.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",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"monaco-editor": "^0.57.0",
|
|
46
46
|
"react": "^19.3.0",
|
|
47
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
47
|
+
"@coldsmirk/inkstone-react": "^0.33.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"monaco-editor": "^0.57.0",
|
|
51
51
|
"react": ">=19",
|
|
52
|
-
"@coldsmirk/inkstone-react": "^0.
|
|
52
|
+
"@coldsmirk/inkstone-react": "^0.33.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@coldsmirk/inkstone-react": {
|