weml-monaco 0.3.3 → 0.4.2

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.
@@ -0,0 +1,108 @@
1
+ import * as monaco from 'monaco-editor';
2
+
3
+ declare const WEML_LANGUAGE_ID = "weml";
4
+
5
+ interface WemlNormalizationFailure extends Error {
6
+ code: string;
7
+ line?: number;
8
+ column?: number;
9
+ expectedTag?: string | null;
10
+ actualTag?: string | null;
11
+ }
12
+ /** Normalises a WEML document string into its canonical, reproducible form. */
13
+ declare function formatWemlText(input: string): string;
14
+ declare function isWemlNormalizationFailure(error: unknown): error is WemlNormalizationFailure;
15
+ declare function isWemlStructureValidationFailure(error: unknown): error is WemlNormalizationFailure;
16
+ /** User-facing reason shown when canonical formatting is deliberately skipped. */
17
+ declare function canonicalFormattingFailureMessage(error: unknown): string;
18
+
19
+ declare function validateWemlModel(m: typeof monaco, model: monaco.editor.ITextModel): monaco.editor.IMarkerData[];
20
+
21
+ interface WemlActionOptions {
22
+ /** Optional sink for the short status messages the VS Code extension shows in the status bar. */
23
+ onStatus?: (message: string) => void;
24
+ }
25
+ /** Wraps the current selection in `<tag [type=...]>…</tag>` (toolbar dropdown / hotkeys). */
26
+ declare function wrapSelection(editor: monaco.editor.ICodeEditor, tag: string, type?: string): void;
27
+ /** Inserts a snippet by its toolbar-button id (composite label or plain tag). */
28
+ declare function insertSnippetById(editor: monaco.editor.ICodeEditor, id: string): void;
29
+ /** Renumbers every `<div>` id in document order to a sequential 1..n. */
30
+ declare function renumberDivIds(editor: monaco.editor.ICodeEditor, options?: WemlActionOptions): void;
31
+ /**
32
+ * Cycles the whole document between the standard HTML formatting (even steps) and
33
+ * the canonical WEML normalizer (odd steps). The step counter advances on every
34
+ * invocation, even when the formatter produces no change, so the cycle stays in
35
+ * sync — matching the VS Code `weml.cycleFormat` command.
36
+ */
37
+ declare function cycleFormat(editor: monaco.editor.ICodeEditor, options?: WemlActionOptions): void;
38
+ /**
39
+ * Registers the WEML editor actions on a specific editor instance: cycle-format
40
+ * (Alt+Shift+F), renumber div ids, and wrap-format bold/italic/underline
41
+ * (Ctrl+B / Ctrl+I / Ctrl+U). Returns an `IDisposable` that removes them.
42
+ *
43
+ * `editor.addAction` is per-editor (Monaco has no global command registry akin
44
+ * to the VS Code extension host), so call this for every WEML editor — or just
45
+ * use `createWemlToolbar`, which calls it for you.
46
+ */
47
+ declare function registerWemlEditorActions(m: typeof monaco, editor: monaco.editor.IStandaloneCodeEditor, options?: WemlActionOptions): monaco.IDisposable;
48
+
49
+ interface WemlToolbarOptions extends WemlActionOptions {
50
+ /** If given, the toolbar element is appended here. Otherwise it is only returned. */
51
+ container?: HTMLElement;
52
+ /** Include the (stub) search row, matching the VS Code toolbar. Default: true. */
53
+ includeSearchRow?: boolean;
54
+ /**
55
+ * Handler for the search row. When omitted the row is a no-op stub (as in the
56
+ * VS Code extension). Receives the query text and the language code.
57
+ */
58
+ onSearch?: (query: string, lang: string) => void;
59
+ }
60
+ interface WemlToolbar extends monaco.IDisposable {
61
+ /** The toolbar's root DOM element. */
62
+ element: HTMLElement;
63
+ }
64
+ /**
65
+ * Builds the WEML toolbar for a Monaco editor and wires every button to the same
66
+ * operations as the VS Code toolbar (wrap selection, snippet insertion, renumber
67
+ * div ids). Also registers the editor actions/keybindings (Ctrl+B/I/U,
68
+ * Alt+Shift+F, renumber) via `registerWemlEditorActions`.
69
+ *
70
+ * Returns the root element plus a `dispose()` that removes the toolbar and its
71
+ * actions.
72
+ */
73
+ declare function createWemlToolbar(m: typeof monaco, editor: monaco.editor.IStandaloneCodeEditor, options?: WemlToolbarOptions): WemlToolbar;
74
+
75
+ interface IdEdit {
76
+ /** Replacement range in the source text (start === end means a pure insertion). */
77
+ start: number;
78
+ end: number;
79
+ newText: string;
80
+ }
81
+ /**
82
+ * Computes the edits needed to renumber every `<div>` id to its 1-based position
83
+ * in document order. Divs that already carry the right id produce no edit; a div
84
+ * without an `id` attribute gets one inserted right after the tag name.
85
+ */
86
+ declare function planDivIdRenumber(text: string): IdEdit[];
87
+
88
+ /**
89
+ * Builds a `<tag ...>SELECTION</tag>` snippet body for wrapping `selection`.
90
+ * - `type` (e.g. for `w-format`) fills `type="..."` directly.
91
+ * - `a` gets only `href="$1"` (it lists both href and id as required, but a
92
+ * wrapped selection is a link).
93
+ * - otherwise the tag's required attributes become `name="$1"` placeholders.
94
+ * An empty selection leaves a tab stop where the content goes.
95
+ */
96
+ declare function buildWrapSnippet(tag: string, type: string | undefined, selection: string): string;
97
+
98
+ interface RegisterWemlOptions {
99
+ /** File extensions to associate with the language (default: [".weml"]). */
100
+ extensions?: string[];
101
+ /** Debounce for re-validating a model after edits, in ms (default: 300). */
102
+ diagnosticsDebounceMs?: number;
103
+ /** Set to false to skip live diagnostics/markers entirely (default: true). */
104
+ diagnostics?: boolean;
105
+ }
106
+ declare function registerWeml(m: typeof monaco, options?: RegisterWemlOptions): monaco.IDisposable;
107
+
108
+ export { type IdEdit, type RegisterWemlOptions, WEML_LANGUAGE_ID, type WemlActionOptions, type WemlNormalizationFailure, type WemlToolbar, type WemlToolbarOptions, buildWrapSnippet, canonicalFormattingFailureMessage, createWemlToolbar, cycleFormat, formatWemlText, insertSnippetById, isWemlNormalizationFailure, isWemlStructureValidationFailure, planDivIdRenumber, registerWeml, registerWemlEditorActions, renumberDivIds, validateWemlModel, wrapSelection };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,101 @@
1
- import type * as monaco from 'monaco-editor';
2
- export { WEML_LANGUAGE_ID } from './language';
3
- export { canonicalFormattingFailureMessage, formatWemlText, isWemlNormalizationFailure, isWemlStructureValidationFailure, type WemlNormalizationFailure, } from './formatter';
4
- export { validateWemlModel } from './providers/diagnostics';
5
- export { createWemlToolbar, type WemlToolbar, type WemlToolbarOptions, } from './toolbar/toolbar';
6
- export { registerWemlEditorActions, wrapSelection, insertSnippetById, renumberDivIds, cycleFormat, type WemlActionOptions, } from './toolbar/actions';
7
- export { planDivIdRenumber, type IdEdit } from './toolbar/divRenumber';
8
- export { buildWrapSnippet } from './toolbar/wrap';
9
- export interface RegisterWemlOptions {
1
+ import * as monaco from 'monaco-editor';
2
+
3
+ declare const WEML_LANGUAGE_ID = "weml";
4
+
5
+ interface WemlNormalizationFailure extends Error {
6
+ code: string;
7
+ line?: number;
8
+ column?: number;
9
+ expectedTag?: string | null;
10
+ actualTag?: string | null;
11
+ }
12
+ /** Normalises a WEML document string into its canonical, reproducible form. */
13
+ declare function formatWemlText(input: string): string;
14
+ declare function isWemlNormalizationFailure(error: unknown): error is WemlNormalizationFailure;
15
+ declare function isWemlStructureValidationFailure(error: unknown): error is WemlNormalizationFailure;
16
+ /** User-facing reason shown when canonical formatting is deliberately skipped. */
17
+ declare function canonicalFormattingFailureMessage(error: unknown): string;
18
+
19
+ declare function validateWemlModel(m: typeof monaco, model: monaco.editor.ITextModel): monaco.editor.IMarkerData[];
20
+
21
+ interface WemlActionOptions {
22
+ /** Optional sink for the short status messages the VS Code extension shows in the status bar. */
23
+ onStatus?: (message: string) => void;
24
+ }
25
+ /** Wraps the current selection in `<tag [type=...]>…</tag>` (toolbar dropdown / hotkeys). */
26
+ declare function wrapSelection(editor: monaco.editor.ICodeEditor, tag: string, type?: string): void;
27
+ /** Inserts a snippet by its toolbar-button id (composite label or plain tag). */
28
+ declare function insertSnippetById(editor: monaco.editor.ICodeEditor, id: string): void;
29
+ /** Renumbers every `<div>` id in document order to a sequential 1..n. */
30
+ declare function renumberDivIds(editor: monaco.editor.ICodeEditor, options?: WemlActionOptions): void;
31
+ /**
32
+ * Cycles the whole document between the standard HTML formatting (even steps) and
33
+ * the canonical WEML normalizer (odd steps). The step counter advances on every
34
+ * invocation, even when the formatter produces no change, so the cycle stays in
35
+ * sync — matching the VS Code `weml.cycleFormat` command.
36
+ */
37
+ declare function cycleFormat(editor: monaco.editor.ICodeEditor, options?: WemlActionOptions): void;
38
+ /**
39
+ * Registers the WEML editor actions on a specific editor instance: cycle-format
40
+ * (Alt+Shift+F), renumber div ids, and wrap-format bold/italic/underline
41
+ * (Ctrl+B / Ctrl+I / Ctrl+U). Returns an `IDisposable` that removes them.
42
+ *
43
+ * `editor.addAction` is per-editor (Monaco has no global command registry akin
44
+ * to the VS Code extension host), so call this for every WEML editor — or just
45
+ * use `createWemlToolbar`, which calls it for you.
46
+ */
47
+ declare function registerWemlEditorActions(m: typeof monaco, editor: monaco.editor.IStandaloneCodeEditor, options?: WemlActionOptions): monaco.IDisposable;
48
+
49
+ interface WemlToolbarOptions extends WemlActionOptions {
50
+ /** If given, the toolbar element is appended here. Otherwise it is only returned. */
51
+ container?: HTMLElement;
52
+ /** Include the (stub) search row, matching the VS Code toolbar. Default: true. */
53
+ includeSearchRow?: boolean;
54
+ /**
55
+ * Handler for the search row. When omitted the row is a no-op stub (as in the
56
+ * VS Code extension). Receives the query text and the language code.
57
+ */
58
+ onSearch?: (query: string, lang: string) => void;
59
+ }
60
+ interface WemlToolbar extends monaco.IDisposable {
61
+ /** The toolbar's root DOM element. */
62
+ element: HTMLElement;
63
+ }
64
+ /**
65
+ * Builds the WEML toolbar for a Monaco editor and wires every button to the same
66
+ * operations as the VS Code toolbar (wrap selection, snippet insertion, renumber
67
+ * div ids). Also registers the editor actions/keybindings (Ctrl+B/I/U,
68
+ * Alt+Shift+F, renumber) via `registerWemlEditorActions`.
69
+ *
70
+ * Returns the root element plus a `dispose()` that removes the toolbar and its
71
+ * actions.
72
+ */
73
+ declare function createWemlToolbar(m: typeof monaco, editor: monaco.editor.IStandaloneCodeEditor, options?: WemlToolbarOptions): WemlToolbar;
74
+
75
+ interface IdEdit {
76
+ /** Replacement range in the source text (start === end means a pure insertion). */
77
+ start: number;
78
+ end: number;
79
+ newText: string;
80
+ }
81
+ /**
82
+ * Computes the edits needed to renumber every `<div>` id to its 1-based position
83
+ * in document order. Divs that already carry the right id produce no edit; a div
84
+ * without an `id` attribute gets one inserted right after the tag name.
85
+ */
86
+ declare function planDivIdRenumber(text: string): IdEdit[];
87
+
88
+ /**
89
+ * Builds a `<tag ...>SELECTION</tag>` snippet body for wrapping `selection`.
90
+ * - `type` (e.g. for `w-format`) fills `type="..."` directly.
91
+ * - `a` gets only `href="$1"` (it lists both href and id as required, but a
92
+ * wrapped selection is a link).
93
+ * - otherwise the tag's required attributes become `name="$1"` placeholders.
94
+ * An empty selection leaves a tab stop where the content goes.
95
+ */
96
+ declare function buildWrapSnippet(tag: string, type: string | undefined, selection: string): string;
97
+
98
+ interface RegisterWemlOptions {
10
99
  /** File extensions to associate with the language (default: [".weml"]). */
11
100
  extensions?: string[];
12
101
  /** Debounce for re-validating a model after edits, in ms (default: 300). */
@@ -14,4 +103,6 @@ export interface RegisterWemlOptions {
14
103
  /** Set to false to skip live diagnostics/markers entirely (default: true). */
15
104
  diagnostics?: boolean;
16
105
  }
17
- export declare function registerWeml(m: typeof monaco, options?: RegisterWemlOptions): monaco.IDisposable;
106
+ declare function registerWeml(m: typeof monaco, options?: RegisterWemlOptions): monaco.IDisposable;
107
+
108
+ export { type IdEdit, type RegisterWemlOptions, WEML_LANGUAGE_ID, type WemlActionOptions, type WemlNormalizationFailure, type WemlToolbar, type WemlToolbarOptions, buildWrapSnippet, canonicalFormattingFailureMessage, createWemlToolbar, cycleFormat, formatWemlText, insertSnippetById, isWemlNormalizationFailure, isWemlStructureValidationFailure, planDivIdRenumber, registerWeml, registerWemlEditorActions, renumberDivIds, validateWemlModel, wrapSelection };
@@ -0,0 +1,12 @@
1
+ // Types for the IIFE build (`dist/index.global.js`, exposed as `weml-monaco/global`), which
2
+ // attaches the whole API to `window.WemlMonaco` instead of exporting anything.
3
+ // Copied next to the bundle at build time — see `onSuccess` in tsup.config.ts.
4
+
5
+ import type * as WemlMonacoApi from './index.js';
6
+
7
+ declare global {
8
+ // eslint-disable-next-line no-var
9
+ var WemlMonaco: typeof WemlMonacoApi;
10
+ }
11
+
12
+ export {};