@batchfy/codemirror-minimap 0.1.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 ADDED
@@ -0,0 +1,49 @@
1
+ # codemirror-minimap
2
+
3
+ A minimap for CodeMirror 6.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm i @batchfy/codemirror-minimap
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { basicSetup, EditorView } from "codemirror";
15
+ import { showMinimap } from "@batchfy/codemirror-minimap";
16
+
17
+ const create = (v: EditorView) => {
18
+ const dom = document.createElement("div");
19
+ return { dom };
20
+ };
21
+
22
+ const view = new EditorView({
23
+ doc: "",
24
+ extensions: [
25
+ basicSetup,
26
+ showMinimap.compute(["doc"], () => ({
27
+ create,
28
+
29
+ // All optional:
30
+ displayText: "characters", // or "blocks"
31
+ showOverlay: "always", // or "mouse-over"
32
+ autohide: false, // hide the minimap until hover
33
+ gutters: [{ 1: "#00FF00", 2: "green" }], // line number -> color
34
+ width: 120, // max width in px, defaults to 120
35
+ hideScrollbar: true, // hide the editor's native scrollbar, default true
36
+ eventHandlers: {
37
+ contextmenu: (e) => onContextMenu(e),
38
+ },
39
+ })),
40
+ ],
41
+ parent: document.querySelector("#editor"),
42
+ });
43
+ ```
44
+
45
+ Return `null` from `compute` to hide the minimap.
46
+
47
+ ## License
48
+
49
+ MIT
@@ -0,0 +1,63 @@
1
+ import { Facet } from "@codemirror/state";
2
+ import { DOMEventMap, EditorView } from "@codemirror/view";
3
+ import { MinimapConfig } from "./index.js";
4
+ import { Gutter } from "./Gutters.js";
5
+ type EventHandler<event extends keyof DOMEventMap> = (e: DOMEventMap[event], v: EditorView) => void;
6
+ type Options = {
7
+ /**
8
+ * Controls whether the minimap should be hidden on mouseout.
9
+ * Defaults to `false`.
10
+ */
11
+ autohide?: boolean;
12
+ enabled: boolean;
13
+ /**
14
+ * Determines how to render text. Defaults to `characters`.
15
+ */
16
+ displayText?: "blocks" | "characters";
17
+ /**
18
+ * Attach event handlers to the minimap container element.
19
+ */
20
+ eventHandlers?: {
21
+ [event in keyof DOMEventMap]?: EventHandler<event>;
22
+ };
23
+ /**
24
+ * The overlay shows the portion of the file currently in the viewport.
25
+ * Defaults to `always`.
26
+ */
27
+ showOverlay?: "always" | "mouse-over";
28
+ /**
29
+ * Enables a gutter to be drawn on the given line to the left
30
+ * of the minimap, with the given color. Accepts all valid CSS
31
+ * color values.
32
+ */
33
+ gutters?: Array<Gutter>;
34
+ /**
35
+ * Maximum width of the minimap in pixels. Defaults to `120`.
36
+ *
37
+ * This is an upper bound rather than a fixed size: when the editor is
38
+ * narrow the minimap shrinks proportionally so that it never dominates
39
+ * the viewport. A wider minimap shows more characters per line; it does
40
+ * not change the size the text is rendered at.
41
+ */
42
+ width?: number;
43
+ /**
44
+ * Hides the editor's native scrollbar while the minimap is shown, since
45
+ * the minimap and its viewport overlay already serve that role. Scrolling
46
+ * itself is unaffected -- only the scrollbar's appearance is suppressed.
47
+ * Defaults to `true`.
48
+ *
49
+ * Note that this hides the horizontal scrollbar too, as scrollbar
50
+ * visibility cannot be controlled per axis. Horizontal overflow stays
51
+ * discoverable through the minimap's shadow.
52
+ */
53
+ hideScrollbar?: boolean;
54
+ };
55
+ declare const Scale: {
56
+ readonly PixelMultiplier: 2;
57
+ readonly SizeRatio: 4;
58
+ readonly MaxWidth: 120;
59
+ };
60
+ declare const Config: Facet<MinimapConfig | null, Required<Options>>;
61
+ export { Config, Scale };
62
+ export type { Options };
63
+ //# sourceMappingURL=Config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,KAAK,YAAY,CAAC,KAAK,SAAS,MAAM,WAAW,IAAI,CACjD,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,EACrB,CAAC,EAAE,UAAU,KACZ,IAAI,CAAC;AAEV,KAAK,OAAO,GAAG;IACX;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;IAEtC;;OAEG;IACH,aAAa,CAAC,EAAE;SACX,KAAK,IAAI,MAAM,WAAW,CAAC,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC;KACrD,CAAC;IAEF;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;IAEtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAExB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;;;OASG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,KAAK;;;;CAOD,CAAC;AAEX,QAAA,MAAM,MAAM,gDA8BV,CAAC;AAEH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACzB,YAAY,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { DrawContext } from "./types.js";
2
+ declare const GUTTER_WIDTH = 4;
3
+ type Line = number;
4
+ type Color = string;
5
+ export type Gutter = Record<Line, Color>;
6
+ /**
7
+ * Draws a gutter to the canvas context for the given line number
8
+ */
9
+ declare function drawLineGutter(gutter: Record<Line, Color>, ctx: DrawContext, lineNumber: number): void;
10
+ export { GUTTER_WIDTH, drawLineGutter };
11
+ //# sourceMappingURL=Gutters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Gutters.d.ts","sourceRoot":"","sources":["../src/Gutters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,QAAA,MAAM,YAAY,IAAI,CAAC;AAEvB,KAAK,IAAI,GAAG,MAAM,CAAC;AACnB,KAAK,KAAK,GAAG,MAAM,CAAC;AACpB,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAEzC;;GAEG;AACH,iBAAS,cAAc,CACnB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,EAC3B,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,QAYrB;AAED,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { StateField, Transaction } from "@codemirror/state";
2
+ type Span = {
3
+ from: number;
4
+ to: number;
5
+ folded: boolean;
6
+ };
7
+ type Line = Array<Span>;
8
+ type Lines = Array<Line>;
9
+ declare const LinesState: StateField<Lines>;
10
+ /** Returns if the folds have changed in this update */
11
+ declare function foldsChanged(transactions: readonly Transaction[]): boolean;
12
+ export { foldsChanged, LinesState };
13
+ export type { Lines };
14
+ //# sourceMappingURL=LinesState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinesState.d.ts","sourceRoot":"","sources":["../src/LinesState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGzE,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAC1D,KAAK,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AACxB,KAAK,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;AAsEzB,QAAA,MAAM,UAAU,mBASd,CAAC;AAEH,uDAAuD;AACvD,iBAAS,YAAY,CAAC,YAAY,EAAE,SAAS,WAAW,EAAE,GAAG,OAAO,CAInE;AAED,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACpC,YAAY,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const Overlay: import("@codemirror/state").Extension[];
2
+ //# sourceMappingURL=Overlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Overlay.d.ts","sourceRoot":"","sources":["../src/Overlay.ts"],"names":[],"mappings":"AA+TA,eAAO,MAAM,OAAO,yCAAuB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { EditorView, ViewUpdate } from "@codemirror/view";
2
+ import { Diagnostic } from "@codemirror/lint";
3
+ import { LineBasedState } from "./linebasedstate.js";
4
+ import { DrawContext } from "./types.js";
5
+ type Severity = Diagnostic["severity"];
6
+ export declare class DiagnosticState extends LineBasedState<Severity> {
7
+ private count;
8
+ constructor(view: EditorView);
9
+ private shouldUpdate;
10
+ update(update: ViewUpdate): void;
11
+ drawLine(ctx: DrawContext, lineNumber: number): void;
12
+ /**
13
+ * Given a position and a set of line ranges, return
14
+ * the line number the position falls within
15
+ */
16
+ private findLine;
17
+ /**
18
+ * Colors from @codemirror/lint
19
+ * https://github.com/codemirror/lint/blob/e0671b43c02e72766ad1afe1579b7032fdcdb6c1/src/lint.ts#L597
20
+ */
21
+ private color;
22
+ /** Sorts severity from most to least severe */
23
+ private sort;
24
+ /** Assigns a score to severity, with most severe being the highest */
25
+ private score;
26
+ }
27
+ export declare function diagnostics(view: EditorView): DiagnosticState;
28
+ export {};
29
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACH,UAAU,EAIb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIzC,KAAK,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAEvC,qBAAa,eAAgB,SAAQ,cAAc,CAAC,QAAQ,CAAC;IACzD,OAAO,CAAC,KAAK,CAAiC;gBAE3B,IAAI,EAAE,UAAU;IAInC,OAAO,CAAC,YAAY;IAiCb,MAAM,CAAC,MAAM,EAAE,UAAU;IA4BzB,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM;IAgCpD;;;OAGG;IACH,OAAO,CAAC,QAAQ;IAgBhB;;;OAGG;IACH,OAAO,CAAC,KAAK;IAQb,+CAA+C;IAC/C,OAAO,CAAC,IAAI;IAIZ,sEAAsE;IACtE,OAAO,CAAC,KAAK;CAahB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,eAAe,CAE7D"}
@@ -0,0 +1,20 @@
1
+ import { Facet } from "@codemirror/state";
2
+ import { EditorView } from "@codemirror/view";
3
+ import { Options } from "./Config.js";
4
+ export interface MinimapConfig extends Omit<Options, "enabled"> {
5
+ /**
6
+ * A function that creates the element that contains the minimap
7
+ */
8
+ create: (view: EditorView) => {
9
+ dom: HTMLElement;
10
+ };
11
+ }
12
+ /**
13
+ * Facet used to show a minimap in the right gutter of the editor using the
14
+ * provided configuration.
15
+ *
16
+ * If you return `null`, a minimap will not be shown.
17
+ */
18
+ declare const showMinimap: Facet<MinimapConfig | null, MinimapConfig | null>;
19
+ export { showMinimap };
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAA0B,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAU,OAAO,EAAS,MAAM,aAAa,CAAC;AAgVrD,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;IAC3D;;OAEG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK;QAAE,GAAG,EAAE,WAAW,CAAA;KAAE,CAAC;CACtD;AAED;;;;;GAKG;AACH,QAAA,MAAM,WAAW,mDAaf,CAAC;AAEH,OAAO,EAAE,WAAW,EAAE,CAAC"}