@k2b/editor 0.15.1 → 0.16.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/package.json +5 -3
- package/src/Composer.tsx +62 -0
- package/src/charts.ts +1 -1
- package/src/composer-head.browser-fixture.tsx +38 -0
- package/src/composer.css +89 -0
- package/src/styles.css +42 -0
- package/src/v2-chrome.browser-fixture.tsx +89 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k2b/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Configurable Markdown editor for SolidJS: editor, toolbar, bubble menu, and slash menu on one shared state.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
".": "./src/index.ts",
|
|
11
11
|
"./markdown": "./src/markdown/index.ts",
|
|
12
12
|
"./styles.css": "./src/styles.css",
|
|
13
|
+
"./composer": "./src/Composer.tsx",
|
|
14
|
+
"./composer.css": "./src/composer.css",
|
|
13
15
|
"./markdown/lib/*": "./src/markdown/lib/*.ts",
|
|
14
16
|
"./markdown/urls": "./src/markdown/urls.ts",
|
|
15
17
|
"./markdown/mermaid-render": "./src/markdown/mermaid-render.ts",
|
|
@@ -70,8 +72,8 @@
|
|
|
70
72
|
"@codemirror/search": "6.7.2",
|
|
71
73
|
"@codemirror/state": "6.7.6",
|
|
72
74
|
"@codemirror/view": "6.43.15",
|
|
73
|
-
"@k2b/stdlib": "0.
|
|
74
|
-
"@k2b/ui": "0.
|
|
75
|
+
"@k2b/stdlib": "0.37.0",
|
|
76
|
+
"@k2b/ui": "0.67.0",
|
|
75
77
|
"@lezer/common": "1.5.5",
|
|
76
78
|
"@lezer/highlight": "1.2.5",
|
|
77
79
|
"@lezer/markdown": "1.8.1",
|
package/src/Composer.tsx
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type JSX, Show } from "solid-js";
|
|
2
|
+
|
|
3
|
+
export type ComposerProps = {
|
|
4
|
+
/** What the composer writes, for assistive technology, such as "Reply to Holzwerk Brandt". */
|
|
5
|
+
label: string;
|
|
6
|
+
/**
|
|
7
|
+
* The line above the text: to whom, such as a symbol, the quiet word "An" and the recipient. Its parts keep their
|
|
8
|
+
* width; only the last one (the recipient) gives way and is cut with "…" where the line is short.
|
|
9
|
+
*/
|
|
10
|
+
head?: JSX.Element;
|
|
11
|
+
/** The end of that line: the sender, Cc and Bcc. */
|
|
12
|
+
headEnd?: JSX.Element;
|
|
13
|
+
/** The text being written. Without it the composer rests and shows `placeholder`; a click on it calls `onStart`. */
|
|
14
|
+
children?: JSX.Element;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
onStart?: () => void;
|
|
17
|
+
/** Under the text, quiet: the signature that will be sent. */
|
|
18
|
+
signature?: JSX.Element;
|
|
19
|
+
/** The tools at the start of the foot: formatting, attachments, signature, AI. */
|
|
20
|
+
tools?: JSX.Element;
|
|
21
|
+
/** The deeds at the end of the foot: discard, then send. */
|
|
22
|
+
actions?: JSX.Element;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The frame of a message being written, as in Cloud's @k2b/ui v2 mockup: a round, framed card with a head line, the
|
|
27
|
+
* text and a foot with tools and the send action. It brings its own stylesheet (`@k2b/editor/composer.css`, on the
|
|
28
|
+
* v2 tokens), so the app around it writes no CSS. The app supplies the parts; the editor goes into `children`.
|
|
29
|
+
*/
|
|
30
|
+
export function Composer(props: ComposerProps) {
|
|
31
|
+
return (
|
|
32
|
+
<section class="k2-composer" data-k2-part="Composer" aria-label={props.label}>
|
|
33
|
+
<Show when={props.head !== undefined || props.headEnd !== undefined}>
|
|
34
|
+
<div class="k2-composer-head">
|
|
35
|
+
{props.head}
|
|
36
|
+
<Show when={props.headEnd !== undefined}>
|
|
37
|
+
<div class="k2-composer-head-end">{props.headEnd}</div>
|
|
38
|
+
</Show>
|
|
39
|
+
</div>
|
|
40
|
+
</Show>
|
|
41
|
+
<div class="k2-composer-write">
|
|
42
|
+
<Show
|
|
43
|
+
when={props.children !== undefined}
|
|
44
|
+
fallback={
|
|
45
|
+
<button type="button" class="k2-composer-start" onClick={() => props.onStart?.()}>
|
|
46
|
+
{props.placeholder}
|
|
47
|
+
</button>
|
|
48
|
+
}
|
|
49
|
+
>
|
|
50
|
+
{props.children}
|
|
51
|
+
</Show>
|
|
52
|
+
<Show when={props.signature !== undefined}>
|
|
53
|
+
<div class="k2-composer-signature">{props.signature}</div>
|
|
54
|
+
</Show>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="k2-composer-foot">
|
|
57
|
+
<div class="k2-composer-tools">{props.tools}</div>
|
|
58
|
+
<div class="k2-composer-actions">{props.actions}</div>
|
|
59
|
+
</div>
|
|
60
|
+
</section>
|
|
61
|
+
);
|
|
62
|
+
}
|
package/src/charts.ts
CHANGED
|
@@ -103,7 +103,7 @@ type BaseChartInput = Exclude<ChartInput, BalanceFlowInput>;
|
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* Plain-data chart options become the options of the shared
|
|
106
|
-
* renderer (`@k2b/ui` Chart and
|
|
106
|
+
* renderer (`@k2b/ui` Chart and `@k2b/ui/charts/core`) and a data table with the same rows the chart marks. Pure, so the
|
|
107
107
|
* schema, the browser, and the CLI read a chart the same way.
|
|
108
108
|
*/
|
|
109
109
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Button, Icon, Text } from "@k2b/ui/v2";
|
|
2
|
+
import { render } from "solid-js/web";
|
|
3
|
+
import { Composer } from "./Composer";
|
|
4
|
+
|
|
5
|
+
// The composer's head as Mail fills it on a phone: the reply's symbol, the quiet word "An", a long recipient, and the
|
|
6
|
+
// sender, Cc and Bcc at its end.
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
__k2Mounted?: boolean;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const root = document.getElementById("root");
|
|
15
|
+
if (!root) throw new Error("composer-head: #root is missing");
|
|
16
|
+
render(
|
|
17
|
+
() => (
|
|
18
|
+
<Composer
|
|
19
|
+
label="Antwort an Holzwerk Brandt"
|
|
20
|
+
head={
|
|
21
|
+
<>
|
|
22
|
+
<Icon name="arrow-back-up" tone="muted" />
|
|
23
|
+
<Text type="meta">An</Text>
|
|
24
|
+
<Text>Holzwerk Brandt GmbH & Co. KG, Plattenzuschnitt und Kantenbearbeitung</Text>
|
|
25
|
+
</>
|
|
26
|
+
}
|
|
27
|
+
headEnd={
|
|
28
|
+
<>
|
|
29
|
+
<Button variant="text">Cc</Button>
|
|
30
|
+
<Button variant="text">Bcc</Button>
|
|
31
|
+
</>
|
|
32
|
+
}
|
|
33
|
+
placeholder="Antwort schreiben"
|
|
34
|
+
/>
|
|
35
|
+
),
|
|
36
|
+
root,
|
|
37
|
+
);
|
|
38
|
+
window.__k2Mounted = true;
|
package/src/composer.css
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* The composer frame (Composer.tsx) on the @k2b/ui v2 tokens, measured from Cloud's v2 mockup (mail.html): a round
|
|
2
|
+
card, because one writes in it (rule 8), 8 px inside its column and 12 px from what stands above and below. It
|
|
3
|
+
draws only inside a v2 scope (`.k2-ui`). */
|
|
4
|
+
.k2-ui .k2-composer {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
margin: 12px 8px;
|
|
8
|
+
border: 1px solid var(--k2-line-control);
|
|
9
|
+
border-radius: var(--k2-r-card);
|
|
10
|
+
background: var(--k2-surface);
|
|
11
|
+
}
|
|
12
|
+
.k2-ui .k2-composer-head {
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: 8px;
|
|
16
|
+
min-height: var(--k2-h-bar);
|
|
17
|
+
padding: 4px 11px 0;
|
|
18
|
+
font: var(--k2-t-row);
|
|
19
|
+
color: var(--k2-text);
|
|
20
|
+
}
|
|
21
|
+
/* to whom: the parts of the head (a symbol, the word "An") keep their width; only the last one before the end (the
|
|
22
|
+
recipient) gives way and is cut with "…" */
|
|
23
|
+
.k2-ui .k2-composer-head > :not(.k2-composer-head-end) {
|
|
24
|
+
flex: none;
|
|
25
|
+
}
|
|
26
|
+
.k2-ui .k2-composer-head > :nth-last-child(1 of :not(.k2-composer-head-end)) {
|
|
27
|
+
flex: 0 1 auto;
|
|
28
|
+
min-width: 0;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
text-overflow: ellipsis;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
}
|
|
33
|
+
.k2-ui .k2-composer-head-end {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: 4px;
|
|
37
|
+
margin-left: auto;
|
|
38
|
+
}
|
|
39
|
+
/* body text in its role (14/20); the mockup's 22 px reading line is not one of the four roles */
|
|
40
|
+
.k2-ui .k2-composer-write {
|
|
41
|
+
display: flex;
|
|
42
|
+
flex-direction: column;
|
|
43
|
+
gap: 6px;
|
|
44
|
+
min-height: 104px;
|
|
45
|
+
padding: 8px 11px;
|
|
46
|
+
font: var(--k2-t-body);
|
|
47
|
+
color: var(--k2-subtle);
|
|
48
|
+
}
|
|
49
|
+
.k2-ui .k2-composer-start {
|
|
50
|
+
all: unset;
|
|
51
|
+
display: block;
|
|
52
|
+
font: inherit;
|
|
53
|
+
color: inherit;
|
|
54
|
+
cursor: text;
|
|
55
|
+
}
|
|
56
|
+
.k2-ui .k2-composer-start:focus-visible {
|
|
57
|
+
border-radius: var(--k2-r-mark);
|
|
58
|
+
box-shadow: 0 0 0 3px var(--k2-blue-ring);
|
|
59
|
+
}
|
|
60
|
+
.k2-ui .k2-composer-signature {
|
|
61
|
+
margin-top: auto;
|
|
62
|
+
font: var(--k2-t-row);
|
|
63
|
+
color: var(--k2-subtle);
|
|
64
|
+
/* a signature is lines of text: name, company, phone */
|
|
65
|
+
white-space: pre-line;
|
|
66
|
+
}
|
|
67
|
+
.k2-ui .k2-composer-foot {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
gap: 4px;
|
|
71
|
+
height: var(--k2-h-status);
|
|
72
|
+
padding: 0 11px;
|
|
73
|
+
}
|
|
74
|
+
.k2-ui .k2-composer-tools,
|
|
75
|
+
.k2-ui .k2-composer-actions {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
gap: 4px;
|
|
79
|
+
}
|
|
80
|
+
.k2-ui .k2-composer-actions {
|
|
81
|
+
margin-left: auto;
|
|
82
|
+
}
|
|
83
|
+
/* the tools of the foot are the small icon buttons of a 40 px place; the send action keeps its full height */
|
|
84
|
+
.k2-ui .k2-composer-foot .k2-btn[data-icon-only] {
|
|
85
|
+
width: var(--k2-h-control-small);
|
|
86
|
+
height: var(--k2-h-control-small);
|
|
87
|
+
padding: 0;
|
|
88
|
+
color: var(--k2-muted);
|
|
89
|
+
}
|
package/src/styles.css
CHANGED
|
@@ -9,6 +9,48 @@
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/* Inside a v2 screen (`.k2-ui`) the toolbar speaks v2, its behaviour unchanged: the v2 bar height (40 px), icon buttons
|
|
13
|
+
of the v2 hit area (28 px) and icon size (16 px), the first glyph on the v2 text edge (the button's 6 px inset
|
|
14
|
+
pulled out). Outside any layer, so it wins over the utility classes the toolbar carries for a v1 page. */
|
|
15
|
+
.k2-ui [data-k2b-editor-toolbar] {
|
|
16
|
+
min-height: var(--k2-h-bar);
|
|
17
|
+
padding-inline: calc(var(--k2-edge) - 6px);
|
|
18
|
+
color: var(--k2-muted);
|
|
19
|
+
}
|
|
20
|
+
.k2-ui [data-k2b-editor-toolbar] .k2b-icon-button {
|
|
21
|
+
width: var(--k2-h-control-small);
|
|
22
|
+
height: var(--k2-h-control-small);
|
|
23
|
+
min-width: var(--k2-h-control-small);
|
|
24
|
+
padding: 0;
|
|
25
|
+
border-radius: var(--k2-r-control);
|
|
26
|
+
}
|
|
27
|
+
/* one icon size for every control of the bar, a labelled control of the host included */
|
|
28
|
+
.k2-ui [data-k2b-editor-toolbar] .ti {
|
|
29
|
+
font-size: 16px;
|
|
30
|
+
line-height: 1;
|
|
31
|
+
}
|
|
32
|
+
/* the row of actions scrolls sideways; its box grows by the room of the focus ring on every side, its place stays */
|
|
33
|
+
.k2-ui [data-k2b-editor-toolbar] [role="toolbar"] {
|
|
34
|
+
margin: -4px;
|
|
35
|
+
padding: 4px;
|
|
36
|
+
scroll-padding-inline: 4px;
|
|
37
|
+
}
|
|
38
|
+
/* a neutral tint under the pointer, the tint of selection for a format that is on (as MarkdownEditor in v2) */
|
|
39
|
+
.k2-ui [data-k2b-editor-toolbar] .k2b-icon-button:hover:not(:disabled, [aria-disabled="true"], [aria-pressed="true"]) {
|
|
40
|
+
color: var(--k2-text);
|
|
41
|
+
background: var(--k2-n100);
|
|
42
|
+
}
|
|
43
|
+
.k2-ui [data-k2b-editor-toolbar] .k2b-icon-button[aria-pressed="true"] {
|
|
44
|
+
color: var(--k2-blue-ink);
|
|
45
|
+
background: var(--k2-blue-tint);
|
|
46
|
+
}
|
|
47
|
+
/* the same ring as MarkdownEditor's toolbar in v2: the shared focus tokens, in the blue of v2 */
|
|
48
|
+
.k2-ui [data-k2b-editor-toolbar] .k2b-icon-button:focus-visible {
|
|
49
|
+
outline: var(--k2b-focus-width) solid var(--k2-blue);
|
|
50
|
+
outline-offset: var(--k2b-focus-offset);
|
|
51
|
+
box-shadow: none;
|
|
52
|
+
}
|
|
53
|
+
|
|
12
54
|
/* The dictation bar's controls match the toolbar's own, so the row keeps its height when the bar stands in. */
|
|
13
55
|
[data-k2b-editor-toolbar] .k2b-dictation-bar {
|
|
14
56
|
--k2b-dictation-control: 1.75rem;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Button, LocaleProvider, MarkdownEditor } from "@k2b/ui";
|
|
2
|
+
import { Bar, Canvas, Pane, Text, Workspace } from "@k2b/ui/v2";
|
|
3
|
+
import { render } from "solid-js/web";
|
|
4
|
+
import { createEditor, Editor, markdownActions, Toolbar } from "./index";
|
|
5
|
+
|
|
6
|
+
// The two Markdown editors of Cloud inside a v2 screen, as Files, Tools and Notebooks place them: the editor of
|
|
7
|
+
// `@k2b/ui` (`MarkdownEditor`, embedded) and the shared editor of `@k2b/editor` with its toolbar, each in a `Canvas`
|
|
8
|
+
// below a v2 head. The page loads Cloud's stylesheet (v1 and v2), as every Cloud page does.
|
|
9
|
+
|
|
10
|
+
const offer = `# Angebot Einbauschrank Flur
|
|
11
|
+
|
|
12
|
+
Familie Oswald, Lindenweg 4
|
|
13
|
+
|
|
14
|
+
- Korpus Eiche, geölt
|
|
15
|
+
- Schiebetüren mit Spiegel
|
|
16
|
+
- **Lieferung** in KW 51`;
|
|
17
|
+
|
|
18
|
+
const root = document.getElementById("root");
|
|
19
|
+
// `data-shell` on the root: the page is the content of a Cloud shell, which is the v2 scope; the editors fill it
|
|
20
|
+
const inShell = root?.hasAttribute("data-shell") ?? false;
|
|
21
|
+
if (root)
|
|
22
|
+
render(() => {
|
|
23
|
+
const editor = createEditor();
|
|
24
|
+
const actions = markdownActions(editor, "de");
|
|
25
|
+
return (
|
|
26
|
+
<LocaleProvider locale="de">
|
|
27
|
+
{/* `?v1` renders the same page without the v2 scope: the editors as a v1 page shows them */}
|
|
28
|
+
<div
|
|
29
|
+
class={inShell || location.search.includes("v1") ? undefined : "k2-ui"}
|
|
30
|
+
style={inShell ? { display: "flex", flex: "1", "min-height": "0" } : { position: "fixed", inset: "0", display: "flex" }}
|
|
31
|
+
>
|
|
32
|
+
<Workspace head={<Bar start={<Text type="body">Angebot Einbauschrank Flur.md</Text>} />}>
|
|
33
|
+
<Pane.Split>
|
|
34
|
+
<Pane label="Datei" width={{ min: 320, default: 640 }}>
|
|
35
|
+
<Canvas label="Angebot Einbauschrank Flur.md" height={360}>
|
|
36
|
+
<div data-editor="ui" style={{ height: "100%" }}>
|
|
37
|
+
<MarkdownEditor
|
|
38
|
+
aria-label="Angebot Einbauschrank Flur.md"
|
|
39
|
+
value={offer}
|
|
40
|
+
fill
|
|
41
|
+
variant="embedded"
|
|
42
|
+
onSave={() => undefined}
|
|
43
|
+
onClose={() => undefined}
|
|
44
|
+
toolbarTrailing={
|
|
45
|
+
// controls of the host before save and close, as Files puts its history and download there
|
|
46
|
+
<>
|
|
47
|
+
<button type="button" class="k2b-markdown-editor__tool" aria-label="Verlauf" tabIndex={-1}>
|
|
48
|
+
<i class="ti ti-history" aria-hidden="true" />
|
|
49
|
+
</button>
|
|
50
|
+
<button type="button" class="k2b-markdown-editor__tool" aria-label="Herunterladen" tabIndex={-1}>
|
|
51
|
+
<i class="ti ti-download" aria-hidden="true" />
|
|
52
|
+
</button>
|
|
53
|
+
</>
|
|
54
|
+
}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
</Canvas>
|
|
58
|
+
</Pane>
|
|
59
|
+
<Pane label="Notiz">
|
|
60
|
+
<Canvas label="Notiz" height={360}>
|
|
61
|
+
<div data-editor="shared" style={{ display: "flex", "flex-direction": "column", height: "100%" }}>
|
|
62
|
+
<Toolbar
|
|
63
|
+
editor={editor}
|
|
64
|
+
groups={[
|
|
65
|
+
{ items: [actions.bold, actions.italic, actions.strikethrough, actions.code] },
|
|
66
|
+
{ items: [actions.bulletList, actions.numberedList, actions.quote] },
|
|
67
|
+
{ items: [actions.link, actions.table] },
|
|
68
|
+
]}
|
|
69
|
+
end={
|
|
70
|
+
// a labelled control of the host, as Notebooks puts its comments there
|
|
71
|
+
<Button size="xs" variant="ghost" aria-label="2 Kommentare">
|
|
72
|
+
<i class="ti ti-message-circle" aria-hidden="true" />
|
|
73
|
+
<span>2</span>
|
|
74
|
+
</Button>
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
{/* the host sets the text on the v2 edge, as a note column does */}
|
|
78
|
+
<div style={{ padding: "0 var(--k2-edge)", flex: "1", "min-height": "0" }}>
|
|
79
|
+
<Editor editor={editor} label="Notiz" initialValue={offer} maxLength={10000} toolbar={false} />
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</Canvas>
|
|
83
|
+
</Pane>
|
|
84
|
+
</Pane.Split>
|
|
85
|
+
</Workspace>
|
|
86
|
+
</div>
|
|
87
|
+
</LocaleProvider>
|
|
88
|
+
);
|
|
89
|
+
}, root);
|