@sovereignfs/ui 0.107.3 → 0.110.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.
@@ -0,0 +1,83 @@
1
+ import * as react from 'react';
2
+
3
+ /** The address to preview an image's source with, or nothing. */
4
+ type ImageSource = (source: string) => string | null | undefined;
5
+
6
+ type MarkdownEditorView = 'rich' | 'markdown';
7
+ interface MarkdownEditorProps {
8
+ /** The text, with whatever line breaks it has. Give it with `onChange`, or use `defaultValue`. */
9
+ value?: string;
10
+ defaultValue?: string;
11
+ /** The whole new text after the person changed it. What they did not touch keeps its bytes. */
12
+ onChange?: (value: string) => void;
13
+ /** What the text is called, for both views. */
14
+ 'aria-label': string;
15
+ /** The view shown. Left out, the editor keeps it, from `defaultView` (the rich one). */
16
+ view?: MarkdownEditorView;
17
+ defaultView?: MarkdownEditorView;
18
+ onViewChange?: (view: MarkdownEditorView) => void;
19
+ /**
20
+ * The address to preview an image with, for the source the text gives it, such as a path relative to the file. Without an
21
+ * address the image's description is shown and nothing is loaded. Give the same address for the same source: a new function
22
+ * that answers otherwise draws the images again.
23
+ */
24
+ imageSrc?: ImageSource;
25
+ readOnly?: boolean;
26
+ 'aria-describedby'?: string;
27
+ className?: string;
28
+ }
29
+ /**
30
+ * MarkdownEditor — a rich view and a Markdown view of one text, switched at any time. The text is what is edited: the rich view
31
+ * reads it when shown and writes it only when the person changes something there. A text the rich view cannot hold byte for byte
32
+ * (`checkMarkdownRoundTrip`) is shown there read only, with the reason, and edited in the Markdown view. No one loses a byte
33
+ * they did not touch.
34
+ *
35
+ * Nothing of a text runs or is fetched: raw HTML is shown as text, a link is not followed, and an image shows only what
36
+ * `imageSrc` gives for it.
37
+ */
38
+ declare function MarkdownEditor({ value, defaultValue, onChange, view, defaultView, onViewChange, imageSrc, readOnly, 'aria-label': label, 'aria-describedby': describedBy, className, }: MarkdownEditorProps): react.JSX.Element;
39
+
40
+ /**
41
+ * A Markdown text read into the editor's document, keeping how each thing was written: markers, fences, padding, the lines between
42
+ * blocks and characters spelled another way. What the editor does not model is kept as written and reported.
43
+ */
44
+
45
+ type UnsupportedReason = 'html' | 'footnote' | 'reference' | 'unsupported';
46
+
47
+ /**
48
+ * Whether the rich editor can hold a text without changing it: the text is read into the editor's document and written back, and
49
+ * only a text that comes back byte for byte may be edited there. Pure: no React, no browser, so a server can ask too.
50
+ */
51
+
52
+ /**
53
+ * - `html`, `footnote`, `reference`: raw HTML, a footnote, or a reference-style link or definition, which the rich view does not
54
+ * edit;
55
+ * - `line-endings`: line breaks of more than one kind;
56
+ * - `formatting`: something written in a way the rich view would rewrite;
57
+ * - `unsupported`: anything else it cannot hold, such as a table whose rows differ in length.
58
+ */
59
+ type MarkdownIssueReason = UnsupportedReason | 'line-endings' | 'formatting';
60
+ interface MarkdownIssue {
61
+ readonly reason: MarkdownIssueReason;
62
+ /** The line of the text it is on, from 1. */
63
+ readonly line: number;
64
+ /** For `formatting`: what the text has there, and what would be written instead. */
65
+ readonly found?: string;
66
+ readonly written?: string;
67
+ }
68
+ interface MarkdownRoundTrip {
69
+ /** The rich view may edit the text: it is written back exactly as it is. */
70
+ readonly editable: boolean;
71
+ /** Why not, in the order of the text. Empty when it may. */
72
+ readonly issues: readonly MarkdownIssue[];
73
+ }
74
+ /**
75
+ * Whether the rich editor can hold `text` without changing a byte of it, and if not, why: the check `MarkdownEditor` makes
76
+ * before it lets a text be edited in its rich view.
77
+ */
78
+ declare function checkMarkdownRoundTrip(text: string): MarkdownRoundTrip;
79
+ /** An issue in words, such as `Line 4: Raw HTML.` */
80
+ declare function describeMarkdownIssue(issue: MarkdownIssue): string;
81
+
82
+ export { MarkdownEditor, checkMarkdownRoundTrip, describeMarkdownIssue };
83
+ export type { ImageSource, MarkdownEditorProps, MarkdownEditorView, MarkdownIssue, MarkdownIssueReason, MarkdownRoundTrip };