@peers-app/peers-ui 0.34.12 → 0.34.13
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/dist/components/markdown-editor/editor.d.ts +36 -0
- package/dist/components/markdown-editor/editor.js +16 -0
- package/dist/components/markdown-editor/format-bar.d.ts +16 -0
- package/dist/components/markdown-editor/format-bar.js +132 -0
- package/dist/components/markdown-editor/format-commands.d.ts +25 -0
- package/dist/components/markdown-editor/format-commands.js +140 -0
- package/dist/components/markdown-editor/format.d.ts +36 -0
- package/dist/components/markdown-editor/format.js +47 -0
- package/dist/components/markdown-editor/lexical-editor.d.ts +1 -0
- package/dist/components/markdown-editor/lexical-editor.js +5 -1
- package/dist/components/markdown-editor/selection-effects-plugin.d.ts +8 -1
- package/dist/components/markdown-editor/selection-effects-plugin.js +25 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -1
- package/dist/theme.css +83 -0
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IMentionLink, Observable } from "@peers-app/peers-sdk";
|
|
2
2
|
import type React from "react";
|
|
3
|
+
import { type EditorFormat, type ISelectionAction } from "./format";
|
|
3
4
|
import type { IToolbarControl } from "./toolbar";
|
|
4
5
|
import "prismjs";
|
|
5
6
|
/**
|
|
@@ -25,6 +26,12 @@ export interface IEditorEffects {
|
|
|
25
26
|
* Returns false, changing nothing, when nothing is selected. Set by the editor.
|
|
26
27
|
*/
|
|
27
28
|
replaceSelectionWithMention?: (link: IMentionLink) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Type text at the caret, in place of any selection, and focus the editor, as if typed. An @
|
|
31
|
+
* button types `@`; as with a typed `@`, the mention picker opens once a name follows, if the
|
|
32
|
+
* `@` starts a word. Set by the editor once it has mounted.
|
|
33
|
+
*/
|
|
34
|
+
insertText?: (text: string) => void;
|
|
28
35
|
}
|
|
29
36
|
/** What {@link MarkdownEditor} takes. */
|
|
30
37
|
export interface IMarkdownEditorProps {
|
|
@@ -38,6 +45,14 @@ export interface IMarkdownEditorProps {
|
|
|
38
45
|
autoFocus?: boolean;
|
|
39
46
|
/** Leave out the formatting toolbar. */
|
|
40
47
|
hideToolbar?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* A bar over selected text, with a mouse or trackpad: bold, italic, strikethrough, link and
|
|
50
|
+
* code, then `selectionActions`. For an editor without the toolbar; a touch screen gets
|
|
51
|
+
* {@link MarkdownFormatRow} instead, where the app puts it.
|
|
52
|
+
*/
|
|
53
|
+
selectionToolbar?: boolean;
|
|
54
|
+
/** The app's own buttons on the bar over selected text, such as Notes' Make note. */
|
|
55
|
+
selectionActions?: ISelectionAction[];
|
|
41
56
|
/** Scroll inside the editor past this height. */
|
|
42
57
|
maxHeight?: string | number;
|
|
43
58
|
/**
|
|
@@ -73,3 +88,24 @@ export interface IMarkdownEditorProps {
|
|
|
73
88
|
* Edits are written back to `value`.
|
|
74
89
|
*/
|
|
75
90
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): React.FunctionComponentElement<IMarkdownEditorProps>;
|
|
91
|
+
/** What {@link MarkdownFormatRow} takes. */
|
|
92
|
+
export interface IMarkdownFormatRowProps {
|
|
93
|
+
/** The same object passed to the {@link MarkdownEditor} the row formats. */
|
|
94
|
+
effects: IEditorEffects;
|
|
95
|
+
/** The buttons, in order; every format if omitted. */
|
|
96
|
+
formats?: readonly EditorFormat[];
|
|
97
|
+
/** Classes for the row, for the app's own spacing. */
|
|
98
|
+
className?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A row of formatting buttons for a {@link MarkdownEditor}, placed wherever the app wants it, such
|
|
102
|
+
* as above a phone's keyboard behind an Aa button: bold, italic, strikethrough, link, code, the
|
|
103
|
+
* three list kinds and quote, each on while the selection has it. A press keeps the editor's focus
|
|
104
|
+
* and selection, except Link's, which opens the link field (as ⌘⇧K does). It works once the
|
|
105
|
+
* editor given the same `effects` has mounted.
|
|
106
|
+
*/
|
|
107
|
+
export declare function MarkdownFormatRow(props: IMarkdownFormatRowProps): React.FunctionComponentElement<{
|
|
108
|
+
effects: IEditorEffects;
|
|
109
|
+
formats: readonly EditorFormat[];
|
|
110
|
+
className?: string;
|
|
111
|
+
}>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MarkdownEditor = MarkdownEditor;
|
|
4
|
+
exports.MarkdownFormatRow = MarkdownFormatRow;
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const lazy_module_1 = require("../../lazy-module");
|
|
7
|
+
const format_1 = require("./format");
|
|
6
8
|
// Prism, which colors the editor's code blocks, still loads with peers-ui. When Prism first loads
|
|
7
9
|
// it colors every `language-*` code block on the page, and it becomes the page's `Prism`. Loaded
|
|
8
10
|
// at the first editor instead, it would rewrite code blocks React had already drawn, which then
|
|
@@ -27,3 +29,17 @@ const lexicalEditor = (0, lazy_module_1.lazyModule)(() => require("./lexical-edi
|
|
|
27
29
|
function MarkdownEditor(props) {
|
|
28
30
|
return (0, react_1.createElement)(lexicalEditor().LexicalMarkdownEditor, props);
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A row of formatting buttons for a {@link MarkdownEditor}, placed wherever the app wants it, such
|
|
34
|
+
* as above a phone's keyboard behind an Aa button: bold, italic, strikethrough, link, code, the
|
|
35
|
+
* three list kinds and quote, each on while the selection has it. A press keeps the editor's focus
|
|
36
|
+
* and selection, except Link's, which opens the link field (as ⌘⇧K does). It works once the
|
|
37
|
+
* editor given the same `effects` has mounted.
|
|
38
|
+
*/
|
|
39
|
+
function MarkdownFormatRow(props) {
|
|
40
|
+
return (0, react_1.createElement)(lexicalEditor().LexicalFormatRow, {
|
|
41
|
+
effects: props.effects,
|
|
42
|
+
formats: props.formats ?? format_1.ALL_FORMATS,
|
|
43
|
+
className: props.className,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IEditorEffects } from "./editor";
|
|
2
|
+
import { type EditorFormat, type ISelectionAction } from "./format";
|
|
3
|
+
/**
|
|
4
|
+
* The bar over selected text: bold, italic, strikethrough, link and code, then the app's own
|
|
5
|
+
* buttons. Only with a mouse or trackpad: on a touch screen the system's own menu takes the
|
|
6
|
+
* selection, and the app shows `MarkdownFormatRow` instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare function SelectionToolbarPlugin({ actions }: {
|
|
9
|
+
actions?: ISelectionAction[];
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
11
|
+
/** `MarkdownFormatRow`'s implementation. */
|
|
12
|
+
export declare function LexicalFormatRow({ effects, formats, className, }: {
|
|
13
|
+
effects: IEditorEffects;
|
|
14
|
+
formats: readonly EditorFormat[];
|
|
15
|
+
className?: string;
|
|
16
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelectionToolbarPlugin = SelectionToolbarPlugin;
|
|
4
|
+
exports.LexicalFormatRow = LexicalFormatRow;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
// The bar over selected text and the Aa row (`MarkdownFormatRow`). They load with the editor.
|
|
7
|
+
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const format_1 = require("./format");
|
|
10
|
+
const format_commands_1 = require("./format-commands");
|
|
11
|
+
/** A press on a bar's button keeps the editor's focus and selection, and a phone's keyboard. */
|
|
12
|
+
const keepFocus = (event) => event.preventDefault();
|
|
13
|
+
/** One button per format, on while the selection has it. */
|
|
14
|
+
function FormatButtons({ formats, state, onFormat, }) {
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: formats.map((format) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `editor-format-button${state[format] ? " active" : ""}`, "aria-label": format_1.FORMAT_BUTTONS[format].label, "aria-pressed": state[format], title: format_1.FORMAT_BUTTONS[format].label, tabIndex: -1, onPointerDown: keepFocus, onMouseDown: keepFocus, onClick: () => onFormat(format), children: (0, jsx_runtime_1.jsx)("i", { className: `bi bi-${format_1.FORMAT_BUTTONS[format].icon}` }) }, format))) }));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The bar's height and the gap to the text, for placing it above the selection or below: 32 px
|
|
19
|
+
* buttons, 3 px padding and a 1 px border make 40, then 16 to the text (theme.css).
|
|
20
|
+
*/
|
|
21
|
+
const BAR_ROOM_PX = 56;
|
|
22
|
+
/**
|
|
23
|
+
* Where the bar over the selection goes, relative to the editor's container: above the selected
|
|
24
|
+
* text, centered on it, or below it when there's no room above in the window.
|
|
25
|
+
*/
|
|
26
|
+
function barPlace(editor) {
|
|
27
|
+
const root = editor.getRootElement();
|
|
28
|
+
const selection = root?.ownerDocument.getSelection();
|
|
29
|
+
// Blink's isCollapsed getter requests layout even for a cached caret. A text control can
|
|
30
|
+
// report "Range" with a collapsed document selection, so keep that check for ranges.
|
|
31
|
+
if (!root || selection?.type !== "Range" || selection.isCollapsed)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (!root.contains(selection.anchorNode) || !root.contains(selection.focusNode))
|
|
34
|
+
return undefined;
|
|
35
|
+
if (!finePointer())
|
|
36
|
+
return undefined;
|
|
37
|
+
const container = root.closest(".editor-container");
|
|
38
|
+
if (!container)
|
|
39
|
+
return undefined;
|
|
40
|
+
const rect = selection.getRangeAt(0).getBoundingClientRect();
|
|
41
|
+
if (!rect.width && !rect.height)
|
|
42
|
+
return undefined;
|
|
43
|
+
const frame = container.getBoundingClientRect();
|
|
44
|
+
const below = rect.top < BAR_ROOM_PX;
|
|
45
|
+
return {
|
|
46
|
+
top: (below ? rect.bottom : rect.top) - frame.top,
|
|
47
|
+
left: rect.left - frame.left + rect.width / 2,
|
|
48
|
+
below,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** A pointer that can select text precisely: a mouse or trackpad, not a finger. */
|
|
52
|
+
const finePointer = () => typeof window === "undefined" ||
|
|
53
|
+
!window.matchMedia ||
|
|
54
|
+
window.matchMedia("(pointer: fine)").matches;
|
|
55
|
+
/**
|
|
56
|
+
* The bar over selected text: bold, italic, strikethrough, link and code, then the app's own
|
|
57
|
+
* buttons. Only with a mouse or trackpad: on a touch screen the system's own menu takes the
|
|
58
|
+
* selection, and the app shows `MarkdownFormatRow` instead.
|
|
59
|
+
*/
|
|
60
|
+
function SelectionToolbarPlugin({ actions }) {
|
|
61
|
+
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
62
|
+
const [place, setPlace] = (0, react_1.useState)();
|
|
63
|
+
const [state, setState] = (0, react_1.useState)(format_1.NO_FORMAT);
|
|
64
|
+
const bar = (0, react_1.useRef)(null);
|
|
65
|
+
(0, react_1.useEffect)(() => {
|
|
66
|
+
// While a mouse drag selects text the bar waits, so it doesn't appear under the pointer and
|
|
67
|
+
// catch an upward drag; it shows when the button comes up.
|
|
68
|
+
let dragging = false;
|
|
69
|
+
const update = () => {
|
|
70
|
+
const next = dragging ? undefined : barPlace(editor);
|
|
71
|
+
setPlace(next);
|
|
72
|
+
if (next)
|
|
73
|
+
setState(editor.getEditorState().read(format_commands_1.$formatState));
|
|
74
|
+
};
|
|
75
|
+
const down = (event) => {
|
|
76
|
+
const root = editor.getRootElement();
|
|
77
|
+
if (event.button !== 0 || !root?.contains(event.target))
|
|
78
|
+
return;
|
|
79
|
+
dragging = true;
|
|
80
|
+
setPlace(undefined);
|
|
81
|
+
};
|
|
82
|
+
const up = () => {
|
|
83
|
+
if (!dragging)
|
|
84
|
+
return;
|
|
85
|
+
dragging = false;
|
|
86
|
+
update();
|
|
87
|
+
};
|
|
88
|
+
const doc = editor.getRootElement()?.ownerDocument ?? document;
|
|
89
|
+
update();
|
|
90
|
+
doc.addEventListener("selectionchange", update);
|
|
91
|
+
doc.addEventListener("pointerdown", down, true);
|
|
92
|
+
doc.addEventListener("pointerup", up, true);
|
|
93
|
+
doc.addEventListener("pointercancel", up, true);
|
|
94
|
+
const stopUpdates = editor.registerUpdateListener(update);
|
|
95
|
+
return () => {
|
|
96
|
+
doc.removeEventListener("selectionchange", update);
|
|
97
|
+
doc.removeEventListener("pointerdown", down, true);
|
|
98
|
+
doc.removeEventListener("pointerup", up, true);
|
|
99
|
+
doc.removeEventListener("pointercancel", up, true);
|
|
100
|
+
stopUpdates();
|
|
101
|
+
};
|
|
102
|
+
}, [editor]);
|
|
103
|
+
// Kept inside the editor's container, so a selection near its edge doesn't push the bar out.
|
|
104
|
+
// Measured again when the app's actions change the visible bar's width; while it's hidden, a
|
|
105
|
+
// new actions array (as from typing) costs no measurement.
|
|
106
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
107
|
+
const element = bar.current;
|
|
108
|
+
const container = element?.parentElement;
|
|
109
|
+
if (!element || !container || !place)
|
|
110
|
+
return;
|
|
111
|
+
const half = element.offsetWidth / 2;
|
|
112
|
+
const left = Math.min(Math.max(place.left, half), container.clientWidth - half);
|
|
113
|
+
element.style.left = `${left}px`;
|
|
114
|
+
}, [place, place && actions]);
|
|
115
|
+
if (!place)
|
|
116
|
+
return null;
|
|
117
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: bar, className: `editor-selection-bar${place.below ? " below" : ""}`, role: "toolbar", "aria-label": "Format selected text", style: { top: place.top, left: place.left }, onPointerDown: keepFocus, onMouseDown: keepFocus, children: [(0, jsx_runtime_1.jsx)(FormatButtons, { formats: format_1.INLINE_FORMATS, state: state, onFormat: (format) => (0, format_commands_1.applyFormat)(editor, format) }), actions?.length ? (0, jsx_runtime_1.jsx)("span", { className: "editor-format-divider" }) : null, actions?.map((action) => ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "editor-format-button editor-format-action", title: action.title, disabled: action.disabled, onClick: action.onClick, children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${action.iconClass}` }), action.label] }, action.label)))] }));
|
|
118
|
+
}
|
|
119
|
+
/** The editor `effects` belongs to, kept current as it mounts and unmounts. */
|
|
120
|
+
function useEditorFor(effects) {
|
|
121
|
+
return (0, react_1.useSyncExternalStore)((changed) => (0, format_commands_1.onEditorAttached)(effects, changed), () => (0, format_commands_1.editorFor)(effects));
|
|
122
|
+
}
|
|
123
|
+
/** `MarkdownFormatRow`'s implementation. */
|
|
124
|
+
function LexicalFormatRow({ effects, formats, className, }) {
|
|
125
|
+
const editor = useEditorFor(effects);
|
|
126
|
+
const [state, setState] = (0, react_1.useState)(format_1.NO_FORMAT);
|
|
127
|
+
(0, react_1.useEffect)(() => (editor ? (0, format_commands_1.watchFormat)(editor, setState) : undefined), [editor]);
|
|
128
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: `editor-format-row${className ? ` ${className}` : ""}`, role: "toolbar", "aria-label": "Formatting", onPointerDown: keepFocus, onMouseDown: keepFocus, children: (0, jsx_runtime_1.jsx)(FormatButtons, { formats: formats, state: editor ? state : format_1.NO_FORMAT, onFormat: (format) => {
|
|
129
|
+
if (editor)
|
|
130
|
+
(0, format_commands_1.applyFormat)(editor, format);
|
|
131
|
+
} }) }));
|
|
132
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type LexicalEditor } from "lexical";
|
|
2
|
+
import type { IEditorEffects } from "./editor";
|
|
3
|
+
import { type EditorFormat, type IFormatState } from "./format";
|
|
4
|
+
/** Which formats the selection has. Inside an editor read. */
|
|
5
|
+
export declare function $formatState(): IFormatState;
|
|
6
|
+
/**
|
|
7
|
+
* Apply a format to the selection, or take it off when the selection has it; Link opens the link
|
|
8
|
+
* popup instead. With nothing selected, an inline format applies to what's typed next, as Cmd+B
|
|
9
|
+
* does.
|
|
10
|
+
*
|
|
11
|
+
* @param editor - The editor to change.
|
|
12
|
+
* @param format - What to apply.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyFormat(editor: LexicalEditor, format: EditorFormat): void;
|
|
15
|
+
/**
|
|
16
|
+
* Follow the selection's formats: `listener` hears them now and after every change, until the
|
|
17
|
+
* returned function is called.
|
|
18
|
+
*/
|
|
19
|
+
export declare function watchFormat(editor: LexicalEditor, listener: (state: IFormatState) => void): () => void;
|
|
20
|
+
/** Note that `effects` now belongs to `editor` (or to none), and tell whoever follows it. */
|
|
21
|
+
export declare function attachEditor(effects: IEditorEffects, editor: LexicalEditor | undefined): void;
|
|
22
|
+
/** The editor `effects` belongs to, if it's mounted. */
|
|
23
|
+
export declare function editorFor(effects: IEditorEffects): LexicalEditor | undefined;
|
|
24
|
+
/** Hear when `effects` gets or loses its editor, until the returned function is called. */
|
|
25
|
+
export declare function onEditorAttached(effects: IEditorEffects, listener: () => void): () => void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$formatState = $formatState;
|
|
4
|
+
exports.applyFormat = applyFormat;
|
|
5
|
+
exports.watchFormat = watchFormat;
|
|
6
|
+
exports.attachEditor = attachEditor;
|
|
7
|
+
exports.editorFor = editorFor;
|
|
8
|
+
exports.onEditorAttached = onEditorAttached;
|
|
9
|
+
// Formatting commands shared by the toolbar, the bar over selected text and the Aa row
|
|
10
|
+
// (`MarkdownFormatRow`). They load with the editor.
|
|
11
|
+
const list_1 = require("@lexical/list");
|
|
12
|
+
const rich_text_1 = require("@lexical/rich-text");
|
|
13
|
+
const utils_1 = require("@lexical/utils");
|
|
14
|
+
const lexical_1 = require("lexical");
|
|
15
|
+
const format_1 = require("./format");
|
|
16
|
+
const link_plugin_1 = require("./link-plugin");
|
|
17
|
+
/** Which formats the selection has. Inside an editor read. */
|
|
18
|
+
function $formatState() {
|
|
19
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
20
|
+
if (!(0, lexical_1.$isRangeSelection)(selection))
|
|
21
|
+
return format_1.NO_FORMAT;
|
|
22
|
+
const anchor = selection.anchor.getNode();
|
|
23
|
+
const list = (0, utils_1.$getNearestNodeOfType)(anchor, list_1.ListNode);
|
|
24
|
+
const listType = list?.getListType();
|
|
25
|
+
return {
|
|
26
|
+
bold: selection.hasFormat("bold"),
|
|
27
|
+
italic: selection.hasFormat("italic"),
|
|
28
|
+
strikethrough: selection.hasFormat("strikethrough"),
|
|
29
|
+
code: selection.hasFormat("code"),
|
|
30
|
+
link: (0, link_plugin_1.$selectedLink)(selection) !== null,
|
|
31
|
+
bulletList: listType === "bullet",
|
|
32
|
+
numberList: listType === "number",
|
|
33
|
+
checkList: listType === "check",
|
|
34
|
+
// Callouts also inherit from QuoteNode and keep their own markdown marker.
|
|
35
|
+
quote: anchor.getTopLevelElement()?.getType() === "quote",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Toggle paragraphs and ordinary quotes in the selection. Inside an editor update. */
|
|
39
|
+
function $toggleQuote() {
|
|
40
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
41
|
+
if (!(0, lexical_1.$isRangeSelection)(selection))
|
|
42
|
+
return;
|
|
43
|
+
const blocks = new Set();
|
|
44
|
+
let off = true;
|
|
45
|
+
for (const node of [selection.anchor.getNode(), ...selection.getNodes()]) {
|
|
46
|
+
const block = node.getTopLevelElement();
|
|
47
|
+
if (!(0, lexical_1.$isElementNode)(block))
|
|
48
|
+
continue;
|
|
49
|
+
if (block.getType() === "paragraph")
|
|
50
|
+
off = false;
|
|
51
|
+
else if (block.getType() !== "quote")
|
|
52
|
+
continue;
|
|
53
|
+
blocks.add(block);
|
|
54
|
+
}
|
|
55
|
+
// A quoted anchor toggles off even in a mixed range. From a protected block, quote any
|
|
56
|
+
// remaining paragraphs first so the next press can unquote the same range.
|
|
57
|
+
off ||= selection.anchor.getNode().getTopLevelElement()?.getType() === "quote";
|
|
58
|
+
for (const block of blocks) {
|
|
59
|
+
if (block.getType() !== (off ? "quote" : "paragraph"))
|
|
60
|
+
continue;
|
|
61
|
+
block.replace((off ? (0, lexical_1.$createParagraphNode)() : (0, rich_text_1.$createQuoteNode)())
|
|
62
|
+
.setIndent(block.getIndent())
|
|
63
|
+
.setFormat(block.getFormatType())
|
|
64
|
+
.setTextFormat(block.getTextFormat())
|
|
65
|
+
.setDirection(block.getDirection()), true);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Apply a format to the selection, or take it off when the selection has it; Link opens the link
|
|
70
|
+
* popup instead. With nothing selected, an inline format applies to what's typed next, as Cmd+B
|
|
71
|
+
* does.
|
|
72
|
+
*
|
|
73
|
+
* @param editor - The editor to change.
|
|
74
|
+
* @param format - What to apply.
|
|
75
|
+
*/
|
|
76
|
+
function applyFormat(editor, format) {
|
|
77
|
+
switch (format) {
|
|
78
|
+
case "bold":
|
|
79
|
+
case "italic":
|
|
80
|
+
case "strikethrough":
|
|
81
|
+
case "code":
|
|
82
|
+
editor.dispatchCommand(lexical_1.FORMAT_TEXT_COMMAND, format);
|
|
83
|
+
return;
|
|
84
|
+
case "link":
|
|
85
|
+
editor.dispatchCommand(link_plugin_1.OPEN_LINK_EDITOR_COMMAND, undefined);
|
|
86
|
+
return;
|
|
87
|
+
case "bulletList":
|
|
88
|
+
case "numberList":
|
|
89
|
+
case "checkList":
|
|
90
|
+
if (editor.getEditorState().read($formatState)[format])
|
|
91
|
+
editor.dispatchCommand(list_1.REMOVE_LIST_COMMAND, undefined);
|
|
92
|
+
else
|
|
93
|
+
editor.dispatchCommand(format === "bulletList"
|
|
94
|
+
? list_1.INSERT_UNORDERED_LIST_COMMAND
|
|
95
|
+
: format === "numberList"
|
|
96
|
+
? list_1.INSERT_ORDERED_LIST_COMMAND
|
|
97
|
+
: list_1.INSERT_CHECK_LIST_COMMAND, undefined);
|
|
98
|
+
return;
|
|
99
|
+
case "quote":
|
|
100
|
+
editor.update($toggleQuote);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Follow the selection's formats: `listener` hears them now and after every change, until the
|
|
106
|
+
* returned function is called.
|
|
107
|
+
*/
|
|
108
|
+
function watchFormat(editor, listener) {
|
|
109
|
+
listener(editor.getEditorState().read($formatState));
|
|
110
|
+
return editor.registerUpdateListener(({ editorState }) => {
|
|
111
|
+
listener(editorState.read($formatState));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// Which editor each `IEditorEffects` belongs to, so a row outside the editor (`MarkdownFormatRow`)
|
|
115
|
+
// can work with it once it's mounted, whichever of the two mounts first.
|
|
116
|
+
const editors = new WeakMap();
|
|
117
|
+
const waiting = new WeakMap();
|
|
118
|
+
/** Note that `effects` now belongs to `editor` (or to none), and tell whoever follows it. */
|
|
119
|
+
function attachEditor(effects, editor) {
|
|
120
|
+
if (editor)
|
|
121
|
+
editors.set(effects, editor);
|
|
122
|
+
else
|
|
123
|
+
editors.delete(effects);
|
|
124
|
+
for (const listener of waiting.get(effects) ?? [])
|
|
125
|
+
listener();
|
|
126
|
+
}
|
|
127
|
+
/** The editor `effects` belongs to, if it's mounted. */
|
|
128
|
+
function editorFor(effects) {
|
|
129
|
+
return editors.get(effects);
|
|
130
|
+
}
|
|
131
|
+
/** Hear when `effects` gets or loses its editor, until the returned function is called. */
|
|
132
|
+
function onEditorAttached(effects, listener) {
|
|
133
|
+
let listeners = waiting.get(effects);
|
|
134
|
+
if (!listeners) {
|
|
135
|
+
listeners = new Set();
|
|
136
|
+
waiting.set(effects, listeners);
|
|
137
|
+
}
|
|
138
|
+
listeners.add(listener);
|
|
139
|
+
return () => listeners.delete(listener);
|
|
140
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A formatting change the editor can make to the selection: bold, italic, strikethrough, inline
|
|
3
|
+
* code, a link, the three list kinds, or a quote. Each toggles: applied again, it's taken off.
|
|
4
|
+
* Link instead opens the link field, where a link is added, edited or removed.
|
|
5
|
+
*/
|
|
6
|
+
export type EditorFormat = "bold" | "italic" | "strikethrough" | "code" | "link" | "bulletList" | "numberList" | "checkList" | "quote";
|
|
7
|
+
/** Which formats the selection has, so their buttons show as on. */
|
|
8
|
+
export type IFormatState = Record<EditorFormat, boolean>;
|
|
9
|
+
/** No format on: the state before an editor reports one. */
|
|
10
|
+
export declare const NO_FORMAT: IFormatState;
|
|
11
|
+
/** Each format's button: a Bootstrap Icons name and its tooltip, with the shortcut if it has one. */
|
|
12
|
+
export declare const FORMAT_BUTTONS: Record<EditorFormat, {
|
|
13
|
+
icon: string;
|
|
14
|
+
label: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** The formats for selected text: the bar over a selection shows these. */
|
|
17
|
+
export declare const INLINE_FORMATS: readonly EditorFormat[];
|
|
18
|
+
/** Every format, in the order {@link MarkdownFormatRow} shows them. */
|
|
19
|
+
export declare const ALL_FORMATS: readonly EditorFormat[];
|
|
20
|
+
/**
|
|
21
|
+
* A button an app adds to the bar over selected text, after the formatting ones: Notes' Make note
|
|
22
|
+
* and Make task. The selection stays while it's clicked, so its handler can read and replace it
|
|
23
|
+
* through {@link IEditorEffects}.
|
|
24
|
+
*/
|
|
25
|
+
export interface ISelectionAction {
|
|
26
|
+
/** A Bootstrap Icons class, such as `bi-journal-plus`. */
|
|
27
|
+
iconClass: string;
|
|
28
|
+
/** The button's text. */
|
|
29
|
+
label: string;
|
|
30
|
+
/** Its tooltip. */
|
|
31
|
+
title?: string;
|
|
32
|
+
/** Greyed out, as while the action runs. */
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/** What it does. */
|
|
35
|
+
onClick: () => void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What the editor's formatting buttons do and look like. No Lexical here: apps import these types
|
|
3
|
+
// with peers-ui, while the commands that apply them load with the editor (format-commands.ts).
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.ALL_FORMATS = exports.INLINE_FORMATS = exports.FORMAT_BUTTONS = exports.NO_FORMAT = void 0;
|
|
6
|
+
/** No format on: the state before an editor reports one. */
|
|
7
|
+
exports.NO_FORMAT = {
|
|
8
|
+
bold: false,
|
|
9
|
+
italic: false,
|
|
10
|
+
strikethrough: false,
|
|
11
|
+
code: false,
|
|
12
|
+
link: false,
|
|
13
|
+
bulletList: false,
|
|
14
|
+
numberList: false,
|
|
15
|
+
checkList: false,
|
|
16
|
+
quote: false,
|
|
17
|
+
};
|
|
18
|
+
const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
19
|
+
const shortcut = (key) => (mac ? `⌘${key}` : `Ctrl+${key}`);
|
|
20
|
+
/** Each format's button: a Bootstrap Icons name and its tooltip, with the shortcut if it has one. */
|
|
21
|
+
exports.FORMAT_BUTTONS = {
|
|
22
|
+
bold: { icon: "type-bold", label: `Bold (${shortcut("B")})` },
|
|
23
|
+
italic: { icon: "type-italic", label: `Italic (${shortcut("I")})` },
|
|
24
|
+
strikethrough: { icon: "type-strikethrough", label: "Strikethrough" },
|
|
25
|
+
code: { icon: "code", label: "Code" },
|
|
26
|
+
link: { icon: "link-45deg", label: `Link (${mac ? "⌘⇧K" : "Ctrl+Shift+K"})` },
|
|
27
|
+
bulletList: { icon: "list-ul", label: "Bulleted list" },
|
|
28
|
+
numberList: { icon: "list-ol", label: "Numbered list" },
|
|
29
|
+
checkList: { icon: "check2-square", label: "Checklist" },
|
|
30
|
+
quote: { icon: "quote", label: "Quote" },
|
|
31
|
+
};
|
|
32
|
+
/** The formats for selected text: the bar over a selection shows these. */
|
|
33
|
+
exports.INLINE_FORMATS = [
|
|
34
|
+
"bold",
|
|
35
|
+
"italic",
|
|
36
|
+
"strikethrough",
|
|
37
|
+
"link",
|
|
38
|
+
"code",
|
|
39
|
+
];
|
|
40
|
+
/** Every format, in the order {@link MarkdownFormatRow} shows them. */
|
|
41
|
+
exports.ALL_FORMATS = [
|
|
42
|
+
...exports.INLINE_FORMATS,
|
|
43
|
+
"bulletList",
|
|
44
|
+
"numberList",
|
|
45
|
+
"checkList",
|
|
46
|
+
"quote",
|
|
47
|
+
];
|
|
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.LexicalFormatRow = void 0;
|
|
39
40
|
exports.LexicalMarkdownEditor = LexicalMarkdownEditor;
|
|
40
41
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
42
|
// The markdown editor itself, built on Lexical. It loads the first time an editor draws
|
|
@@ -64,6 +65,7 @@ const mention_chip_1 = require("../../mentions/mention-chip");
|
|
|
64
65
|
const autolink_plugin_1 = require("./autolink-plugin");
|
|
65
66
|
const blocks_1 = require("./blocks");
|
|
66
67
|
const code_plugin_1 = require("./code-plugin");
|
|
68
|
+
const format_bar_1 = require("./format-bar");
|
|
67
69
|
const link_plugin_1 = require("./link-plugin");
|
|
68
70
|
const markdown_plugin_1 = require("./markdown-plugin");
|
|
69
71
|
const mention_node_1 = require("./mention-node");
|
|
@@ -96,6 +98,8 @@ const editorConfig = {
|
|
|
96
98
|
// The editor theme
|
|
97
99
|
theme: theme_1.default,
|
|
98
100
|
};
|
|
101
|
+
var format_bar_2 = require("./format-bar");
|
|
102
|
+
Object.defineProperty(exports, "LexicalFormatRow", { enumerable: true, get: function () { return format_bar_2.LexicalFormatRow; } });
|
|
99
103
|
/** {@link MarkdownEditor}'s implementation. */
|
|
100
104
|
function LexicalMarkdownEditor(props) {
|
|
101
105
|
const { effects } = props;
|
|
@@ -124,7 +128,7 @@ function LexicalMarkdownEditor(props) {
|
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
130
|
const transformers = props.headings === false ? markdown_plugin_1.inlineMarkdownTransformers : markdown_plugin_1.documentMarkdownTransformers;
|
|
127
|
-
return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(link_plugin_1.LinksPlugin, {}), (0, jsx_runtime_1.jsx)(code_plugin_1.CodePlugin, {}), (0, jsx_runtime_1.jsx)(BlocksPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value, transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] })] }) }) }));
|
|
131
|
+
return ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: props.groupId, children: (0, jsx_runtime_1.jsx)(LexicalComposer_1.LexicalComposer, { initialConfig: { ...editorConfig }, children: (0, jsx_runtime_1.jsxs)("div", { className: "editor-container", children: [props.hideToolbar ? null : (0, jsx_runtime_1.jsx)(toolbar_1.ToolbarPlugin, { topRightControls: props.topRightControls }), (0, jsx_runtime_1.jsxs)("div", { className: "editor-inner", ref: editorRef, style: { maxHeight: props.maxHeight, overflowY: "auto" }, children: [(0, jsx_runtime_1.jsx)(LexicalRichTextPlugin_1.RichTextPlugin, { contentEditable: (0, jsx_runtime_1.jsx)(LexicalContentEditable_1.ContentEditable, { className: "editor-input p-2" }), placeholder: null, ErrorBoundary: LexicalErrorBoundary_1.LexicalErrorBoundary }), (0, jsx_runtime_1.jsx)(LexicalHistoryPlugin_1.HistoryPlugin, {}), props.autoFocus && (0, jsx_runtime_1.jsx)(LexicalAutoFocusPlugin_1.AutoFocusPlugin, { defaultSelection: "rootEnd" }), (0, jsx_runtime_1.jsx)(LexicalListPlugin_1.ListPlugin, {}), props.mentions !== false && ((0, jsx_runtime_1.jsx)(mentions_plugin_1.MentionsPlugin, { mentionsOpen: mentionsOpen, groupId: props.groupId })), (0, jsx_runtime_1.jsx)(autolink_plugin_1.LexicalAutoLinkPlugin, {}), (0, jsx_runtime_1.jsx)(link_plugin_1.LinksPlugin, {}), (0, jsx_runtime_1.jsx)(code_plugin_1.CodePlugin, {}), (0, jsx_runtime_1.jsx)(BlocksPlugin, {}), (0, jsx_runtime_1.jsx)(markdown_plugin_1.MarkdownPlugin, { markdownObs: props.value, transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalMarkdownShortcutPlugin_1.MarkdownShortcutPlugin, { transformers: transformers }), (0, jsx_runtime_1.jsx)(LexicalCheckListPlugin_1.CheckListPlugin, {}), (0, jsx_runtime_1.jsx)(LexicalTabIndentationPlugin_1.TabIndentationPlugin, {}), (0, jsx_runtime_1.jsx)(move_line_plugin_1.MoveLineWithAltArrowsPlugin, { mentionsOpen: mentionsOpen }), (0, jsx_runtime_1.jsx)(select_line_boundary_plugin_1.SelectToLineBoundaryPlugin, {}), (0, jsx_runtime_1.jsx)(OnKeyDownPlugin, { effects: props.effects, mentionsOpen: mentionsOpen }), effects ? (0, jsx_runtime_1.jsx)(selection_effects_plugin_1.SelectionEffectsPlugin, { effects: effects }) : null] }), props.selectionToolbar ? ((0, jsx_runtime_1.jsx)(format_bar_1.SelectionToolbarPlugin, { actions: props.selectionActions })) : null] }) }) }));
|
|
128
132
|
}
|
|
129
133
|
const OnKeyDownPlugin = (props) => {
|
|
130
134
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -9,9 +9,16 @@ export declare function $selectedText(): string;
|
|
|
9
9
|
* @returns false, changing nothing, when nothing is selected.
|
|
10
10
|
*/
|
|
11
11
|
export declare function $replaceSelectionWithMention(link: IMentionLink): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Type `text` at the caret, or in place of the selection; at the end when the editor has no
|
|
14
|
+
* selection. Inside an editor update.
|
|
15
|
+
*/
|
|
16
|
+
export declare function $insertTextAtCaret(text: string): void;
|
|
12
17
|
/**
|
|
13
18
|
* Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
|
|
14
|
-
* a link to something it makes from it (Notes' Make note and Make task)
|
|
19
|
+
* a link to something it makes from it (Notes' Make note and Make task) or type into the editor
|
|
20
|
+
* from a button (an @ that opens the mention picker), and ties `effects` to this editor for
|
|
21
|
+
* `MarkdownFormatRow`.
|
|
15
22
|
*/
|
|
16
23
|
export declare function SelectionEffectsPlugin({ effects }: {
|
|
17
24
|
effects: IEditorEffects;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.$selectedText = $selectedText;
|
|
4
4
|
exports.$replaceSelectionWithMention = $replaceSelectionWithMention;
|
|
5
|
+
exports.$insertTextAtCaret = $insertTextAtCaret;
|
|
5
6
|
exports.SelectionEffectsPlugin = SelectionEffectsPlugin;
|
|
6
7
|
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
7
8
|
const lexical_1 = require("lexical");
|
|
8
9
|
const react_1 = require("react");
|
|
10
|
+
const format_commands_1 = require("./format-commands");
|
|
9
11
|
const mention_node_1 = require("./mention-node");
|
|
10
12
|
/** The selected text as plain text, or empty when nothing is selected. Inside an editor read. */
|
|
11
13
|
function $selectedText() {
|
|
@@ -25,9 +27,24 @@ function $replaceSelectionWithMention(link) {
|
|
|
25
27
|
selection.insertNodes([(0, mention_node_1.$createMentionNode)(link)]);
|
|
26
28
|
return true;
|
|
27
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Type `text` at the caret, or in place of the selection; at the end when the editor has no
|
|
32
|
+
* selection. Inside an editor update.
|
|
33
|
+
*/
|
|
34
|
+
function $insertTextAtCaret(text) {
|
|
35
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
36
|
+
if ((0, lexical_1.$isRangeSelection)(selection))
|
|
37
|
+
selection.insertText(text);
|
|
38
|
+
else if ((0, lexical_1.$isNodeSelection)(selection))
|
|
39
|
+
selection.insertNodes([(0, lexical_1.$createTextNode)(text)]);
|
|
40
|
+
else
|
|
41
|
+
(0, lexical_1.$getRoot)().selectEnd().insertText(text);
|
|
42
|
+
}
|
|
28
43
|
/**
|
|
29
44
|
* Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
|
|
30
|
-
* a link to something it makes from it (Notes' Make note and Make task)
|
|
45
|
+
* a link to something it makes from it (Notes' Make note and Make task) or type into the editor
|
|
46
|
+
* from a button (an @ that opens the mention picker), and ties `effects` to this editor for
|
|
47
|
+
* `MarkdownFormatRow`.
|
|
31
48
|
*/
|
|
32
49
|
function SelectionEffectsPlugin({ effects }) {
|
|
33
50
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -40,9 +57,16 @@ function SelectionEffectsPlugin({ effects }) {
|
|
|
40
57
|
}, { discrete: true });
|
|
41
58
|
return replaced;
|
|
42
59
|
};
|
|
60
|
+
effects.insertText = (text) => {
|
|
61
|
+
editor.update(() => $insertTextAtCaret(text));
|
|
62
|
+
editor.focus();
|
|
63
|
+
};
|
|
64
|
+
(0, format_commands_1.attachEditor)(effects, editor);
|
|
43
65
|
return () => {
|
|
44
66
|
effects.getSelectedText = undefined;
|
|
45
67
|
effects.replaceSelectionWithMention = undefined;
|
|
68
|
+
effects.insertText = undefined;
|
|
69
|
+
(0, format_commands_1.attachEditor)(effects, undefined);
|
|
46
70
|
};
|
|
47
71
|
}, [editor, effects]);
|
|
48
72
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./components/icon";
|
|
|
5
5
|
export * from "./components/icon-picker";
|
|
6
6
|
export { configureIconSearchIndexes, type IconSearchIndexSource, type IIconSearchIndexSources, } from "./components/icon-search";
|
|
7
7
|
export * from "./components/inverse-lazy-list";
|
|
8
|
-
export type { IEditorEffects, IMarkdownEditorProps } from "./components/markdown-editor/editor";
|
|
9
|
-
export { MarkdownEditor } from "./components/markdown-editor/editor";
|
|
8
|
+
export type { IEditorEffects, IMarkdownEditorProps, IMarkdownFormatRowProps, } from "./components/markdown-editor/editor";
|
|
9
|
+
export { MarkdownEditor, MarkdownFormatRow } from "./components/markdown-editor/editor";
|
|
10
10
|
export * from "./components/markdown-editor/editor-inline";
|
|
11
|
+
export type { EditorFormat, IFormatState, ISelectionAction, } from "./components/markdown-editor/format";
|
|
12
|
+
export { ALL_FORMATS, INLINE_FORMATS } from "./components/markdown-editor/format";
|
|
11
13
|
export * from "./components/markdown-with-mentions";
|
|
12
14
|
export * from "./components/responsive-section-nav";
|
|
13
15
|
export * from "./components/sortable-list";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.windowWidth = exports.windowHeight = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = exports.unregisterCommand = exports.registerCommand = exports.executeCommand = void 0;
|
|
17
|
+
exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.windowWidth = exports.windowHeight = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.INLINE_FORMATS = exports.ALL_FORMATS = exports.MarkdownFormatRow = exports.MarkdownEditor = exports.configureIconSearchIndexes = exports.unregisterCommand = exports.registerCommand = exports.executeCommand = void 0;
|
|
18
18
|
// Commands in the command palette, with optional shortcuts. From a package's frame they go to the
|
|
19
19
|
// host's palette, under the package's name.
|
|
20
20
|
var command_palette_1 = require("./command-palette/command-palette");
|
|
@@ -30,7 +30,11 @@ Object.defineProperty(exports, "configureIconSearchIndexes", { enumerable: true,
|
|
|
30
30
|
__exportStar(require("./components/inverse-lazy-list"), exports);
|
|
31
31
|
var editor_1 = require("./components/markdown-editor/editor");
|
|
32
32
|
Object.defineProperty(exports, "MarkdownEditor", { enumerable: true, get: function () { return editor_1.MarkdownEditor; } });
|
|
33
|
+
Object.defineProperty(exports, "MarkdownFormatRow", { enumerable: true, get: function () { return editor_1.MarkdownFormatRow; } });
|
|
33
34
|
__exportStar(require("./components/markdown-editor/editor-inline"), exports);
|
|
35
|
+
var format_1 = require("./components/markdown-editor/format");
|
|
36
|
+
Object.defineProperty(exports, "ALL_FORMATS", { enumerable: true, get: function () { return format_1.ALL_FORMATS; } });
|
|
37
|
+
Object.defineProperty(exports, "INLINE_FORMATS", { enumerable: true, get: function () { return format_1.INLINE_FORMATS; } });
|
|
34
38
|
__exportStar(require("./components/markdown-with-mentions"), exports);
|
|
35
39
|
__exportStar(require("./components/responsive-section-nav"), exports);
|
|
36
40
|
__exportStar(require("./components/sortable-list"), exports);
|
package/dist/theme.css
CHANGED
|
@@ -2689,3 +2689,86 @@
|
|
|
2689
2689
|
--peers-viz-grid: rgba(255, 255, 255, 0.1);
|
|
2690
2690
|
--peers-viz-axis: rgba(255, 255, 255, 0.25);
|
|
2691
2691
|
}
|
|
2692
|
+
|
|
2693
|
+
/* The markdown editor's bar over selected text (`selectionToolbar`) and its Aa row
|
|
2694
|
+
* (`MarkdownFormatRow`): the same buttons, quiet until pressed. */
|
|
2695
|
+
.editor-container:has(> .editor-selection-bar) {
|
|
2696
|
+
position: relative;
|
|
2697
|
+
}
|
|
2698
|
+
.editor-selection-bar {
|
|
2699
|
+
position: absolute;
|
|
2700
|
+
z-index: 30;
|
|
2701
|
+
display: inline-flex;
|
|
2702
|
+
align-items: center;
|
|
2703
|
+
gap: 1px;
|
|
2704
|
+
padding: 3px;
|
|
2705
|
+
/* 16 px off the selected text, above it or below (Mark, 2026-12-03), so it never covers it.
|
|
2706
|
+
* As wide as its buttons, but never wider than the editor: in a narrow one it wraps. */
|
|
2707
|
+
width: max-content;
|
|
2708
|
+
max-width: 100%;
|
|
2709
|
+
flex-wrap: wrap;
|
|
2710
|
+
transform: translate(-50%, calc(-100% - 16px));
|
|
2711
|
+
border: 1px solid var(--bs-border-color);
|
|
2712
|
+
border-radius: 9px;
|
|
2713
|
+
background: var(--bs-tertiary-bg);
|
|
2714
|
+
box-shadow: 0 6px 18px rgb(0 0 0 / 0.35);
|
|
2715
|
+
white-space: nowrap;
|
|
2716
|
+
}
|
|
2717
|
+
.editor-selection-bar.below {
|
|
2718
|
+
transform: translate(-50%, 16px);
|
|
2719
|
+
}
|
|
2720
|
+
.editor-format-row {
|
|
2721
|
+
display: flex;
|
|
2722
|
+
align-items: center;
|
|
2723
|
+
gap: 2px;
|
|
2724
|
+
overflow-x: auto;
|
|
2725
|
+
scrollbar-width: none;
|
|
2726
|
+
}
|
|
2727
|
+
.editor-format-button {
|
|
2728
|
+
display: inline-flex;
|
|
2729
|
+
align-items: center;
|
|
2730
|
+
justify-content: center;
|
|
2731
|
+
gap: 5px;
|
|
2732
|
+
min-width: 32px;
|
|
2733
|
+
min-height: 32px;
|
|
2734
|
+
padding: 4px 8px;
|
|
2735
|
+
border: 0;
|
|
2736
|
+
border-radius: 7px;
|
|
2737
|
+
background: transparent;
|
|
2738
|
+
color: var(--bs-body-color);
|
|
2739
|
+
font-size: 13px;
|
|
2740
|
+
line-height: 1;
|
|
2741
|
+
flex: none;
|
|
2742
|
+
}
|
|
2743
|
+
/* Not on a pressed button, which would lose its look, nor on a touch screen, where :hover stays on
|
|
2744
|
+
* the button last tapped. */
|
|
2745
|
+
@media (hover: hover) {
|
|
2746
|
+
.editor-format-button:hover:not(:disabled, .active) {
|
|
2747
|
+
background: var(--bs-secondary-bg);
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
.editor-format-button.active {
|
|
2751
|
+
background: var(--bs-primary-bg-subtle);
|
|
2752
|
+
color: var(--bs-primary-text-emphasis);
|
|
2753
|
+
}
|
|
2754
|
+
.editor-format-action {
|
|
2755
|
+
max-width: 100%;
|
|
2756
|
+
white-space: normal;
|
|
2757
|
+
overflow-wrap: anywhere;
|
|
2758
|
+
}
|
|
2759
|
+
.editor-format-action:disabled {
|
|
2760
|
+
opacity: 0.65;
|
|
2761
|
+
}
|
|
2762
|
+
.editor-format-button .bi {
|
|
2763
|
+
font-size: 15px;
|
|
2764
|
+
}
|
|
2765
|
+
.editor-format-row .editor-format-button {
|
|
2766
|
+
min-width: 36px;
|
|
2767
|
+
min-height: 36px;
|
|
2768
|
+
}
|
|
2769
|
+
.editor-format-divider {
|
|
2770
|
+
width: 1px;
|
|
2771
|
+
height: 18px;
|
|
2772
|
+
margin: 0 4px;
|
|
2773
|
+
background: var(--bs-border-color);
|
|
2774
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.13",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.34.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.34.13",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.34.
|
|
50
|
+
"@peers-app/peers-sdk": "0.34.13",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|