@pngwasi/config-editor 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +1985 -2
- package/binding.d.ts +216 -0
- package/binding.js +634 -0
- package/index.d.ts +41 -0
- package/index.js +14 -0
- package/load.d.ts +18 -0
- package/load.js +57 -0
- package/package.json +70 -4
- package/pkg/config_editor.d.ts +2500 -0
- package/pkg/config_editor.js +3281 -0
- package/pkg/config_editor_bg.wasm +0 -0
- package/pkg/config_editor_bg.wasm.d.ts +110 -0
- package/preset.css +2899 -0
- package/setting-types.js +24 -0
- package/tools.d.ts +23 -0
- package/tools.js +19 -0
package/binding.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// `@pngwasi/config-editor/binding`: what the React, Vue and Svelte packages
|
|
2
|
+
// build on, for a package for another framework.
|
|
3
|
+
import {
|
|
4
|
+
type BaselineConflict,
|
|
5
|
+
type ChangeSummary,
|
|
6
|
+
type CloseRequest,
|
|
7
|
+
type Diagnostic,
|
|
8
|
+
ConfigDocuments,
|
|
9
|
+
ConfigEditor,
|
|
10
|
+
type DocumentSpec,
|
|
11
|
+
type EditorPath,
|
|
12
|
+
type EditorRange,
|
|
13
|
+
type EditorSettings,
|
|
14
|
+
type EditorView,
|
|
15
|
+
type FieldPath,
|
|
16
|
+
type HostDiagnostic,
|
|
17
|
+
type LanguageName,
|
|
18
|
+
type LineRange,
|
|
19
|
+
type SecretOptions,
|
|
20
|
+
type TextRangeInput,
|
|
21
|
+
} from "./pkg/config_editor.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Each key of `EditorSettings` and the JavaScript type of its values
|
|
25
|
+
* (generated from the Rust struct): the settings among a component's props,
|
|
26
|
+
* and how a framework declares them (Vue's runtime prop types). Plain data,
|
|
27
|
+
* usable before the WebAssembly module loads.
|
|
28
|
+
*/
|
|
29
|
+
export const SETTING_TYPES: Readonly<Record<keyof EditorSettings, "boolean" | "number" | "string" | "object">>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The props an `EditorBinding` reads: the document and its callbacks, the
|
|
33
|
+
* live props and every setting. React's names; each framework package maps
|
|
34
|
+
* its own (Vue's `modelValue`, …) onto them.
|
|
35
|
+
*/
|
|
36
|
+
export interface EditorBindingProps extends EditorSettings {
|
|
37
|
+
value?: string;
|
|
38
|
+
defaultValue?: string;
|
|
39
|
+
/** The `revision` `onChange` gave `value` with, when the parent stores it beside the value and never goes back to an older one: its echo is matched exactly (no pause). */
|
|
40
|
+
valueRevision?: number;
|
|
41
|
+
onChange?: (value: string, revision: number) => void;
|
|
42
|
+
language?: LanguageName;
|
|
43
|
+
editAs?: LanguageName | null;
|
|
44
|
+
onEditAsChange?: (language: LanguageName) => void;
|
|
45
|
+
onSyncChange?: (inSync: boolean) => void;
|
|
46
|
+
onChangeSummary?: (summary: ChangeSummary) => void;
|
|
47
|
+
onProblems?: (problems: Diagnostic[]) => void;
|
|
48
|
+
onPathChange?: (path: EditorPath) => void;
|
|
49
|
+
hostDiagnostics?: HostDiagnostic[];
|
|
50
|
+
readOnlyPaths?: FieldPath[];
|
|
51
|
+
readOnlyRanges?: TextRangeInput[];
|
|
52
|
+
secrets?: SecretOptions;
|
|
53
|
+
schema?: string;
|
|
54
|
+
onSchemaWarning?: (message: string) => void;
|
|
55
|
+
baseline?: string;
|
|
56
|
+
onSave?: (value: string, language: LanguageName) => void;
|
|
57
|
+
onDirtyChange?: (dirty: boolean) => void;
|
|
58
|
+
onBaselineConflict?: (event: BaselineConflict) => void;
|
|
59
|
+
fileName?: string;
|
|
60
|
+
readOnly?: boolean;
|
|
61
|
+
readOnlyReason?: string | null;
|
|
62
|
+
editorClassName?: string;
|
|
63
|
+
onError?: (error: unknown) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A framework component's imperative access to its editor (React's ref, Vue's exposed instance). */
|
|
67
|
+
export interface ConfigEditorHandle {
|
|
68
|
+
/** The current document, in `language`. */
|
|
69
|
+
readonly value: string;
|
|
70
|
+
/** The underlying `ConfigEditor` instance, once mounted. */
|
|
71
|
+
readonly editor: ConfigEditor | null;
|
|
72
|
+
/**
|
|
73
|
+
* Replaces the document, always, and reports it through the change
|
|
74
|
+
* callback so the host's state follows. A bound value equal to one still
|
|
75
|
+
* on its way through a late host is taken as that late echo; a reset to
|
|
76
|
+
* such a text goes through here.
|
|
77
|
+
*/
|
|
78
|
+
setValue(value: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* The unified diff (`diff -u`) of the baseline against the document, with
|
|
81
|
+
* `context` unchanged lines around each change (default 3); empty when
|
|
82
|
+
* they are the same.
|
|
83
|
+
*/
|
|
84
|
+
unifiedDiff(context?: number): string;
|
|
85
|
+
/** The path of what the caret is on, or `null` before the editor mounts. */
|
|
86
|
+
readonly currentPath: EditorPath | null;
|
|
87
|
+
/** Where the field at `path` is written in the text on screen, or `null`. */
|
|
88
|
+
rangeOf(path: FieldPath): EditorRange | null;
|
|
89
|
+
/** The path at a string index of the text on screen, or `null`. */
|
|
90
|
+
pathAt(offset: number): EditorPath | null;
|
|
91
|
+
/** Scrolls to the field at `path`, selects it and focuses the editor; `false` when there is no such field. */
|
|
92
|
+
reveal(path: FieldPath): boolean;
|
|
93
|
+
/** Selects `range` (string indices into the text on screen, as `rangeOf` gives them), scrolls it into view inside the editor and focuses the editor without moving the page; any stretch, comments and blank lines included. A range past the end is clamped. `false` before the editor mounts and for an empty document. */
|
|
94
|
+
revealRange(range: { start: number; end: number }): boolean;
|
|
95
|
+
/** Folds the block the field at `path` opens; `false` when there is none to fold. */
|
|
96
|
+
fold(path: FieldPath): boolean;
|
|
97
|
+
/** Opens the folds around the field at `path`; `false` when none was closed. */
|
|
98
|
+
unfold(path: FieldPath): boolean;
|
|
99
|
+
/** The text on screen (in the `editAs` language while editing as another), which `rangeOf` and `pathAt` index into; `""` before the editor mounts. */
|
|
100
|
+
readonly text: string;
|
|
101
|
+
/** The folded blocks, one-based `{ startLine, endLine }` (`startLine` stays visible). */
|
|
102
|
+
readonly foldedLines: LineRange[];
|
|
103
|
+
/** Folds every block. */
|
|
104
|
+
foldAll(): void;
|
|
105
|
+
/** Opens every fold. */
|
|
106
|
+
unfoldAll(): void;
|
|
107
|
+
/** Focuses the editor, keeping its selection. */
|
|
108
|
+
focus(): void;
|
|
109
|
+
/** Saves as `Ctrl+S` does (calls `onSave`); `false` when nothing was sent (no `onSave`, not mounted, or an `editAs` edit that cannot convert back yet). */
|
|
110
|
+
save(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Edits as `language` (`language` itself to go back), also when the
|
|
113
|
+
* `editAs` prop already says so: a prop that did not change is not sent
|
|
114
|
+
* again, so after an undo stepped back across the switch this asks for it
|
|
115
|
+
* again. Give the prop the same language. `false` before the editor mounts.
|
|
116
|
+
*/
|
|
117
|
+
editAs(language: LanguageName): boolean;
|
|
118
|
+
/** Whether the document differs from `baseline`. */
|
|
119
|
+
readonly isDirty: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The props a `DocumentsBinding` reads (React's names). */
|
|
123
|
+
export interface DocumentsBindingProps extends EditorSettings {
|
|
124
|
+
documents: DocumentSpec[];
|
|
125
|
+
activeId?: string;
|
|
126
|
+
onSelect?: (id: string) => void;
|
|
127
|
+
onClose?: (request: CloseRequest) => void;
|
|
128
|
+
onAdd?: () => void;
|
|
129
|
+
onChange?: (id: string, value: string) => void;
|
|
130
|
+
onSave?: (id: string, value: string, language: LanguageName) => void;
|
|
131
|
+
onDirtyChange?: (id: string, dirty: boolean) => void;
|
|
132
|
+
onProblems?: (id: string, problems: Diagnostic[]) => void;
|
|
133
|
+
onEditAsChange?: (id: string, language: LanguageName) => void;
|
|
134
|
+
onSyncChange?: (id: string, inSync: boolean) => void;
|
|
135
|
+
label?: string;
|
|
136
|
+
viewClassName?: string;
|
|
137
|
+
onError?: (error: unknown) => void;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A framework component's imperative access to its documents view. */
|
|
141
|
+
export interface ConfigDocumentsHandle {
|
|
142
|
+
/** The underlying `ConfigDocuments` instance, once mounted. */
|
|
143
|
+
readonly instance: ConfigDocuments | null;
|
|
144
|
+
/** The active document's id, or `null`. */
|
|
145
|
+
readonly activeId: string | null;
|
|
146
|
+
/** Shows the document `id` and focuses its editor; `false` when there is no such document. */
|
|
147
|
+
select(id: string): boolean;
|
|
148
|
+
/** Whether the document `id` differs from its baseline. */
|
|
149
|
+
isDirty(id: string): boolean;
|
|
150
|
+
/** Saves the document `id` as `Ctrl+S` does (calls `onSave`); `false` when nothing was sent. */
|
|
151
|
+
save(id: string): boolean;
|
|
152
|
+
/** Saves every document with unsaved edits; returns the ids sent. */
|
|
153
|
+
saveAll(): string[];
|
|
154
|
+
/**
|
|
155
|
+
* Edits the document `id` as `language` (its own language to go back), also
|
|
156
|
+
* when its `editAs` already says so: a prop that did not change is not
|
|
157
|
+
* sent again, so after an undo stepped back across the switch this asks
|
|
158
|
+
* for it again. Give the document the same `editAs`. `false` when there is
|
|
159
|
+
* no such document.
|
|
160
|
+
*/
|
|
161
|
+
editAs(id: string, language: LanguageName): boolean;
|
|
162
|
+
/** Focuses the active document's editor. */
|
|
163
|
+
focus(): void;
|
|
164
|
+
/**
|
|
165
|
+
* The editor of the document `id` (paths, folds, focus, saving), or `null`
|
|
166
|
+
* when there is no such document or the view has not mounted. Its queries
|
|
167
|
+
* answer `null` / `false` until the document has been shown once (or
|
|
168
|
+
* listed with `editAsText`, which mounts its editor at once).
|
|
169
|
+
*/
|
|
170
|
+
editor(id: string): EditorView | null;
|
|
171
|
+
/**
|
|
172
|
+
* Replaces the text of the document `id`, always (a revert or a reset to a
|
|
173
|
+
* text the user just passed through), and reports it through `onChange`
|
|
174
|
+
* for the parent's list. Returns whether it replaced the text: `false`
|
|
175
|
+
* when there is no such document or it holds that text already (nothing
|
|
176
|
+
* is reported then).
|
|
177
|
+
*/
|
|
178
|
+
setValue(id: string, value: string): boolean;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* What a framework component does with a `ConfigEditor`, written once: feed
|
|
183
|
+
* it the props (`attach` when the component's element exists, `update`
|
|
184
|
+
* after every change, `detach` on unmount) and expose `handle`. Settings and
|
|
185
|
+
* most props apply live; `language`, `schema`, `fileName`, `editorClassName`
|
|
186
|
+
* and the `secrets` patterns re-mount (the document, baseline and caret
|
|
187
|
+
* carried over); an echo of the bound value, late or out of order, never rolls the document back; a mount that
|
|
188
|
+
* failed on a bad prop is retried when a prop changes.
|
|
189
|
+
*/
|
|
190
|
+
export class EditorBinding {
|
|
191
|
+
/** `name` prefixes the errors logged without `onError` (the package's name). */
|
|
192
|
+
constructor(name: string, props?: EditorBindingProps);
|
|
193
|
+
/** The props as last given. */
|
|
194
|
+
readonly props: EditorBindingProps;
|
|
195
|
+
/** The editor, while mounted. */
|
|
196
|
+
readonly instance: ConfigEditor | null;
|
|
197
|
+
/** Whether the last mount threw (a bad prop). */
|
|
198
|
+
readonly failed: boolean;
|
|
199
|
+
/** The component's imperative API. */
|
|
200
|
+
readonly handle: ConfigEditorHandle;
|
|
201
|
+
attach(element: HTMLElement, props?: EditorBindingProps): void;
|
|
202
|
+
update(props: EditorBindingProps): void;
|
|
203
|
+
detach(): void;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** What a framework component does with a `ConfigDocuments` view (see `EditorBinding`); `label`, `viewClassName` and whether `onClose` and `onAdd` are set re-mount. */
|
|
207
|
+
export class DocumentsBinding {
|
|
208
|
+
constructor(name: string, props?: DocumentsBindingProps);
|
|
209
|
+
readonly props: DocumentsBindingProps;
|
|
210
|
+
readonly instance: ConfigDocuments | null;
|
|
211
|
+
readonly failed: boolean;
|
|
212
|
+
readonly handle: ConfigDocumentsHandle;
|
|
213
|
+
attach(element: HTMLElement, props?: DocumentsBindingProps): void;
|
|
214
|
+
update(props: DocumentsBindingProps): void;
|
|
215
|
+
detach(): void;
|
|
216
|
+
}
|