@peers-app/peers-ui 0.33.21 → 0.33.23
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/command-palette/command-palette.js +3 -43
- package/dist/components/markdown-editor/autolink-plugin.d.ts +5 -1
- package/dist/components/markdown-editor/autolink-plugin.js +5 -8
- package/dist/components/markdown-editor/blocks.d.ts +83 -0
- package/dist/components/markdown-editor/blocks.js +201 -0
- package/dist/components/markdown-editor/code-plugin.d.ts +21 -0
- package/dist/components/markdown-editor/code-plugin.js +109 -0
- package/dist/components/markdown-editor/editor.d.ts +12 -5
- package/dist/components/markdown-editor/editor.js +27 -6
- package/dist/components/markdown-editor/link-plugin.d.ts +41 -0
- package/dist/components/markdown-editor/link-plugin.js +334 -0
- package/dist/components/markdown-editor/markdown-plugin.d.ts +23 -6
- package/dist/components/markdown-editor/markdown-plugin.js +94 -9
- package/dist/components/markdown-editor/mentions-plugin.d.ts +25 -0
- package/dist/components/markdown-editor/mentions-plugin.js +47 -22
- package/dist/components/markdown-editor/theme.d.ts +35 -0
- package/dist/components/markdown-editor/theme.js +36 -0
- package/dist/components/markdown-editor/toolbar.d.ts +11 -0
- package/dist/components/markdown-editor/toolbar.js +16 -5
- package/dist/components/qr-scanner.js +2 -34
- package/dist/theme.css +225 -4
- package/dist/ui-router/routes-loader.js +6 -9
- package/dist/ui-router/runnable-version.d.ts +9 -0
- package/dist/ui-router/runnable-version.js +20 -0
- package/dist/ui-router/ui-loader.js +2 -9
- package/package.json +10 -8
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.commandSearchQuery = exports.isCommandPaletteOpen = void 0;
|
|
37
4
|
exports.registerCommand = registerCommand;
|
|
@@ -83,10 +50,7 @@ const coreCommands = [
|
|
|
83
50
|
category: "Tabs",
|
|
84
51
|
action: () => {
|
|
85
52
|
closeCommandPalette();
|
|
86
|
-
|
|
87
|
-
Promise.resolve().then(() => __importStar(require("../tabs-layout/tabs-state"))).then(({ closeCurrentTab }) => {
|
|
88
|
-
closeCurrentTab();
|
|
89
|
-
});
|
|
53
|
+
(0, tabs_state_1.closeCurrentTab)();
|
|
90
54
|
},
|
|
91
55
|
},
|
|
92
56
|
{
|
|
@@ -98,9 +62,7 @@ const coreCommands = [
|
|
|
98
62
|
category: "Tabs",
|
|
99
63
|
action: () => {
|
|
100
64
|
closeCommandPalette();
|
|
101
|
-
|
|
102
|
-
switchToNextTab();
|
|
103
|
-
});
|
|
65
|
+
(0, tabs_state_1.switchToNextTab)();
|
|
104
66
|
},
|
|
105
67
|
},
|
|
106
68
|
{
|
|
@@ -112,9 +74,7 @@ const coreCommands = [
|
|
|
112
74
|
category: "Tabs",
|
|
113
75
|
action: () => {
|
|
114
76
|
closeCommandPalette();
|
|
115
|
-
|
|
116
|
-
switchToPreviousTab();
|
|
117
|
-
});
|
|
77
|
+
(0, tabs_state_1.switchToPreviousTab)();
|
|
118
78
|
},
|
|
119
79
|
},
|
|
120
80
|
{
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns web addresses (`https://…`, `www.…`) and email addresses in the text into links as
|
|
3
|
+
* they're typed or loaded. The text stays as typed, so these links are made again from it each
|
|
4
|
+
* time. Links made on purpose come from `LinksPlugin` (`link-plugin.tsx`).
|
|
5
|
+
*/
|
|
1
6
|
export declare function LexicalAutoLinkPlugin(): JSX.Element;
|
|
2
|
-
export default function LinkPlugin(): JSX.Element;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LexicalAutoLinkPlugin = LexicalAutoLinkPlugin;
|
|
4
|
-
exports.default = LinkPlugin;
|
|
5
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
5
|
const LexicalAutoLinkPlugin_1 = require("@lexical/react/LexicalAutoLinkPlugin");
|
|
7
6
|
const URL_REGEX = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?<![-.+():%])/;
|
|
@@ -14,13 +13,11 @@ const MATCHERS = [
|
|
|
14
13
|
return `mailto:${text}`;
|
|
15
14
|
}),
|
|
16
15
|
];
|
|
16
|
+
/**
|
|
17
|
+
* Turns web addresses (`https://…`, `www.…`) and email addresses in the text into links as
|
|
18
|
+
* they're typed or loaded. The text stays as typed, so these links are made again from it each
|
|
19
|
+
* time. Links made on purpose come from `LinksPlugin` (`link-plugin.tsx`).
|
|
20
|
+
*/
|
|
17
21
|
function LexicalAutoLinkPlugin() {
|
|
18
22
|
return (0, jsx_runtime_1.jsx)(LexicalAutoLinkPlugin_1.AutoLinkPlugin, { matchers: MATCHERS });
|
|
19
23
|
}
|
|
20
|
-
const LexicalLinkPlugin_1 = require("@lexical/react/LexicalLinkPlugin");
|
|
21
|
-
function LinkPlugin() {
|
|
22
|
-
const validateUrl = (url) => {
|
|
23
|
-
return url.startsWith("http://") || url.startsWith("https://") || url.startsWith("mailto:");
|
|
24
|
-
};
|
|
25
|
-
return (0, jsx_runtime_1.jsx)(LexicalLinkPlugin_1.LinkPlugin, { validateUrl: validateUrl });
|
|
26
|
-
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { ElementTransformer } from "@lexical/markdown";
|
|
2
|
+
import { QuoteNode, type SerializedQuoteNode } from "@lexical/rich-text";
|
|
3
|
+
import { type EditorConfig, type LexicalEditor, type LexicalNode, type LexicalUpdateJSON, type NodeKey, type Spread } from "lexical";
|
|
4
|
+
/**
|
|
5
|
+
* A divider (horizontal rule), both ways. `---`, `***` and `___` on a line of their own read as
|
|
6
|
+
* one, and typing one followed by a space makes one. It's written as `***`: the editor puts one
|
|
7
|
+
* newline between blocks, and a `---` line right under text makes that text a heading for other
|
|
8
|
+
* markdown readers.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HORIZONTAL_RULE_TRANSFORMER: ElementTransformer;
|
|
11
|
+
/**
|
|
12
|
+
* Dividers can be selected: a click selects one (Shift adds it to the selection), so Backspace or
|
|
13
|
+
* Delete removes it, and a selected one is marked with the `selected` class.
|
|
14
|
+
*
|
|
15
|
+
* @param editor - The editor, with {@link HorizontalRuleNode} registered.
|
|
16
|
+
* @returns A function that undoes the registration.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerHorizontalRules(editor: LexicalEditor): () => void;
|
|
19
|
+
/** The kinds of callout, as GitHub has them. */
|
|
20
|
+
export declare const CALLOUT_KINDS: readonly ["note", "tip", "important", "warning", "caution"];
|
|
21
|
+
/** A kind of callout: note, tip, important, warning or caution. */
|
|
22
|
+
export type CalloutKind = (typeof CALLOUT_KINDS)[number];
|
|
23
|
+
/** Each kind's title, shown at the top of its callout. */
|
|
24
|
+
export declare const CALLOUT_TITLES: Record<CalloutKind, string>;
|
|
25
|
+
/** A callout as JSON: a quote with its kind. */
|
|
26
|
+
export type SerializedCalloutNode = Spread<{
|
|
27
|
+
kind: CalloutKind;
|
|
28
|
+
}, SerializedQuoteNode>;
|
|
29
|
+
/**
|
|
30
|
+
* A callout: a quote with a kind (note, tip, important, warning or caution), drawn as a box with
|
|
31
|
+
* the kind's title. It's a {@link QuoteNode}, so the `> ` lines after its first one join it as
|
|
32
|
+
* they would a quote, and Backspace at its start turns it back into a paragraph.
|
|
33
|
+
*/
|
|
34
|
+
export declare class CalloutNode extends QuoteNode {
|
|
35
|
+
/** @internal */
|
|
36
|
+
__kind: CalloutKind;
|
|
37
|
+
/** Lexical's type name for callouts. */
|
|
38
|
+
static getType(): string;
|
|
39
|
+
/** A copy of `node`, for Lexical. */
|
|
40
|
+
static clone(node: CalloutNode): CalloutNode;
|
|
41
|
+
/** A callout from its JSON. */
|
|
42
|
+
static importJSON(serializedNode: SerializedCalloutNode): CalloutNode;
|
|
43
|
+
/**
|
|
44
|
+
* @param kind - The kind; a note if omitted.
|
|
45
|
+
* @param key - Lexical's key, when cloning.
|
|
46
|
+
*/
|
|
47
|
+
constructor(kind?: CalloutKind, key?: NodeKey);
|
|
48
|
+
/** The callout's kind. */
|
|
49
|
+
getKind(): CalloutKind;
|
|
50
|
+
/** Change the callout's kind. */
|
|
51
|
+
setKind(kind: CalloutKind): this;
|
|
52
|
+
/** The quote's element, marked with the kind (its title comes from `data-callout-title`). */
|
|
53
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
54
|
+
/** Redraw when the kind changes. */
|
|
55
|
+
updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean;
|
|
56
|
+
/** The callout's JSON. */
|
|
57
|
+
exportJSON(): SerializedCalloutNode;
|
|
58
|
+
/** Lexical's update from JSON, kind included. */
|
|
59
|
+
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedCalloutNode>): this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A new callout.
|
|
63
|
+
*
|
|
64
|
+
* @param kind - The kind; a note if omitted.
|
|
65
|
+
*/
|
|
66
|
+
export declare function $createCalloutNode(kind?: CalloutKind): CalloutNode;
|
|
67
|
+
/** Whether `node` is a callout. */
|
|
68
|
+
export declare function $isCalloutNode(node: LexicalNode | null | undefined): node is CalloutNode;
|
|
69
|
+
/**
|
|
70
|
+
* Callouts, both ways, in GitHub's form: a `> [!NOTE]` line, then the callout's lines as a
|
|
71
|
+
* quote's. Typing `[!NOTE] ` (or TIP, IMPORTANT, WARNING, CAUTION, in any case) at the start of a
|
|
72
|
+
* line or a quote makes one. A `[!NOTE]` line without the `>` stays text. It goes ahead of
|
|
73
|
+
* Lexical's quote transformer, which would otherwise write a callout as a plain quote.
|
|
74
|
+
*/
|
|
75
|
+
export declare const CALLOUT_TRANSFORMER: ElementTransformer;
|
|
76
|
+
/**
|
|
77
|
+
* Keeps callouts tidy: the line break that joins a callout's first `> ` line to its title line is
|
|
78
|
+
* dropped, so the text starts on the first line.
|
|
79
|
+
*
|
|
80
|
+
* @param editor - The editor, with {@link CalloutNode} registered.
|
|
81
|
+
* @returns A function that undoes the registration.
|
|
82
|
+
*/
|
|
83
|
+
export declare function registerCallouts(editor: LexicalEditor): () => void;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CALLOUT_TRANSFORMER = exports.CalloutNode = exports.CALLOUT_TITLES = exports.CALLOUT_KINDS = exports.HORIZONTAL_RULE_TRANSFORMER = void 0;
|
|
4
|
+
exports.registerHorizontalRules = registerHorizontalRules;
|
|
5
|
+
exports.$createCalloutNode = $createCalloutNode;
|
|
6
|
+
exports.$isCalloutNode = $isCalloutNode;
|
|
7
|
+
exports.registerCallouts = registerCallouts;
|
|
8
|
+
const extension_1 = require("@lexical/extension");
|
|
9
|
+
const rich_text_1 = require("@lexical/rich-text");
|
|
10
|
+
const utils_1 = require("@lexical/utils");
|
|
11
|
+
const lexical_1 = require("lexical");
|
|
12
|
+
// ─── Dividers ────────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
/**
|
|
14
|
+
* A divider (horizontal rule), both ways. `---`, `***` and `___` on a line of their own read as
|
|
15
|
+
* one, and typing one followed by a space makes one. It's written as `***`: the editor puts one
|
|
16
|
+
* newline between blocks, and a `---` line right under text makes that text a heading for other
|
|
17
|
+
* markdown readers.
|
|
18
|
+
*/
|
|
19
|
+
exports.HORIZONTAL_RULE_TRANSFORMER = {
|
|
20
|
+
dependencies: [extension_1.HorizontalRuleNode],
|
|
21
|
+
export: (node) => ((0, extension_1.$isHorizontalRuleNode)(node) ? "***" : null),
|
|
22
|
+
regExp: /^(---|\*\*\*|___)\s?$/,
|
|
23
|
+
replace: (parentNode, _children, _match, isImport) => {
|
|
24
|
+
const rule = (0, extension_1.$createHorizontalRuleNode)();
|
|
25
|
+
if (isImport || parentNode.getNextSibling() !== null) {
|
|
26
|
+
parentNode.replace(rule);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
parentNode.insertBefore(rule);
|
|
30
|
+
}
|
|
31
|
+
if (!isImport)
|
|
32
|
+
rule.selectNext();
|
|
33
|
+
},
|
|
34
|
+
type: "element",
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Dividers can be selected: a click selects one (Shift adds it to the selection), so Backspace or
|
|
38
|
+
* Delete removes it, and a selected one is marked with the `selected` class.
|
|
39
|
+
*
|
|
40
|
+
* @param editor - The editor, with {@link HorizontalRuleNode} registered.
|
|
41
|
+
* @returns A function that undoes the registration.
|
|
42
|
+
*/
|
|
43
|
+
function registerHorizontalRules(editor) {
|
|
44
|
+
let marked = new Set();
|
|
45
|
+
return (0, utils_1.mergeRegister)(editor.registerCommand(lexical_1.CLICK_COMMAND, (event) => {
|
|
46
|
+
const target = event.target;
|
|
47
|
+
if (!(target instanceof Node))
|
|
48
|
+
return false;
|
|
49
|
+
const node = (0, lexical_1.$getNodeFromDOMNode)(target);
|
|
50
|
+
if (!(0, extension_1.$isHorizontalRuleNode)(node))
|
|
51
|
+
return false;
|
|
52
|
+
const current = (0, lexical_1.$getSelection)();
|
|
53
|
+
const selection = event.shiftKey && (0, lexical_1.$isNodeSelection)(current) ? current.clone() : (0, lexical_1.$createNodeSelection)();
|
|
54
|
+
selection.add(node.getKey());
|
|
55
|
+
(0, lexical_1.$setSelection)(selection);
|
|
56
|
+
return true;
|
|
57
|
+
}, lexical_1.COMMAND_PRIORITY_LOW), editor.registerUpdateListener(({ editorState }) => {
|
|
58
|
+
const selected = editorState.read(() => {
|
|
59
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
60
|
+
const keys = new Set();
|
|
61
|
+
if ((0, lexical_1.$isNodeSelection)(selection)) {
|
|
62
|
+
for (const node of selection.getNodes()) {
|
|
63
|
+
if ((0, extension_1.$isHorizontalRuleNode)(node))
|
|
64
|
+
keys.add(node.getKey());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return keys;
|
|
68
|
+
});
|
|
69
|
+
for (const key of new Set([...marked, ...selected])) {
|
|
70
|
+
editor.getElementByKey(key)?.classList.toggle("selected", selected.has(key));
|
|
71
|
+
}
|
|
72
|
+
marked = selected;
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
// ─── Callouts ────────────────────────────────────────────────────────────────────────────────
|
|
76
|
+
/** The kinds of callout, as GitHub has them. */
|
|
77
|
+
exports.CALLOUT_KINDS = ["note", "tip", "important", "warning", "caution"];
|
|
78
|
+
/** Each kind's title, shown at the top of its callout. */
|
|
79
|
+
exports.CALLOUT_TITLES = {
|
|
80
|
+
note: "Note",
|
|
81
|
+
tip: "Tip",
|
|
82
|
+
important: "Important",
|
|
83
|
+
warning: "Warning",
|
|
84
|
+
caution: "Caution",
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A callout: a quote with a kind (note, tip, important, warning or caution), drawn as a box with
|
|
88
|
+
* the kind's title. It's a {@link QuoteNode}, so the `> ` lines after its first one join it as
|
|
89
|
+
* they would a quote, and Backspace at its start turns it back into a paragraph.
|
|
90
|
+
*/
|
|
91
|
+
class CalloutNode extends rich_text_1.QuoteNode {
|
|
92
|
+
/** @internal */
|
|
93
|
+
__kind;
|
|
94
|
+
/** Lexical's type name for callouts. */
|
|
95
|
+
static getType() {
|
|
96
|
+
return "callout";
|
|
97
|
+
}
|
|
98
|
+
/** A copy of `node`, for Lexical. */
|
|
99
|
+
static clone(node) {
|
|
100
|
+
return new CalloutNode(node.__kind, node.__key);
|
|
101
|
+
}
|
|
102
|
+
/** A callout from its JSON. */
|
|
103
|
+
static importJSON(serializedNode) {
|
|
104
|
+
return $createCalloutNode(serializedNode.kind).updateFromJSON(serializedNode);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @param kind - The kind; a note if omitted.
|
|
108
|
+
* @param key - Lexical's key, when cloning.
|
|
109
|
+
*/
|
|
110
|
+
constructor(kind = "note", key) {
|
|
111
|
+
super(key);
|
|
112
|
+
this.__kind = kind;
|
|
113
|
+
}
|
|
114
|
+
/** The callout's kind. */
|
|
115
|
+
getKind() {
|
|
116
|
+
return this.getLatest().__kind;
|
|
117
|
+
}
|
|
118
|
+
/** Change the callout's kind. */
|
|
119
|
+
setKind(kind) {
|
|
120
|
+
const writable = this.getWritable();
|
|
121
|
+
writable.__kind = kind;
|
|
122
|
+
return writable;
|
|
123
|
+
}
|
|
124
|
+
/** The quote's element, marked with the kind (its title comes from `data-callout-title`). */
|
|
125
|
+
createDOM(config) {
|
|
126
|
+
const element = super.createDOM(config);
|
|
127
|
+
element.classList.add("editor-callout", `editor-callout-${this.__kind}`);
|
|
128
|
+
element.setAttribute("data-callout-title", exports.CALLOUT_TITLES[this.__kind]);
|
|
129
|
+
return element;
|
|
130
|
+
}
|
|
131
|
+
/** Redraw when the kind changes. */
|
|
132
|
+
updateDOM(prevNode, dom, config) {
|
|
133
|
+
return prevNode.__kind !== this.__kind || super.updateDOM(prevNode, dom, config);
|
|
134
|
+
}
|
|
135
|
+
/** The callout's JSON. */
|
|
136
|
+
exportJSON() {
|
|
137
|
+
return { ...super.exportJSON(), kind: this.getKind() };
|
|
138
|
+
}
|
|
139
|
+
/** Lexical's update from JSON, kind included. */
|
|
140
|
+
updateFromJSON(serializedNode) {
|
|
141
|
+
return super.updateFromJSON(serializedNode).setKind(serializedNode.kind);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.CalloutNode = CalloutNode;
|
|
145
|
+
/**
|
|
146
|
+
* A new callout.
|
|
147
|
+
*
|
|
148
|
+
* @param kind - The kind; a note if omitted.
|
|
149
|
+
*/
|
|
150
|
+
function $createCalloutNode(kind = "note") {
|
|
151
|
+
return new CalloutNode(kind);
|
|
152
|
+
}
|
|
153
|
+
/** Whether `node` is a callout. */
|
|
154
|
+
function $isCalloutNode(node) {
|
|
155
|
+
return node instanceof CalloutNode;
|
|
156
|
+
}
|
|
157
|
+
function calloutKind(name) {
|
|
158
|
+
const kind = name.toLowerCase();
|
|
159
|
+
return exports.CALLOUT_KINDS.includes(kind) ? kind : "note";
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Callouts, both ways, in GitHub's form: a `> [!NOTE]` line, then the callout's lines as a
|
|
163
|
+
* quote's. Typing `[!NOTE] ` (or TIP, IMPORTANT, WARNING, CAUTION, in any case) at the start of a
|
|
164
|
+
* line or a quote makes one. A `[!NOTE]` line without the `>` stays text. It goes ahead of
|
|
165
|
+
* Lexical's quote transformer, which would otherwise write a callout as a plain quote.
|
|
166
|
+
*/
|
|
167
|
+
exports.CALLOUT_TRANSFORMER = {
|
|
168
|
+
dependencies: [CalloutNode],
|
|
169
|
+
export: (node, exportChildren) => {
|
|
170
|
+
if (!$isCalloutNode(node))
|
|
171
|
+
return null;
|
|
172
|
+
const title = `> [!${node.getKind().toUpperCase()}]`;
|
|
173
|
+
const text = exportChildren(node);
|
|
174
|
+
return text ? `${title}\n${text.replace(/^/gm, "> ")}` : title;
|
|
175
|
+
},
|
|
176
|
+
// `> [!NOTE]` in markdown; `[!NOTE] ` as typed, where the space after it is what ends a line
|
|
177
|
+
// without the `>` (Lexical drops the matched text before `replace` can decline it).
|
|
178
|
+
regExp: /^(?:>\s?\[!(note|tip|important|warning|caution)\]\s?|\[!(note|tip|important|warning|caution)\]\s)$/i,
|
|
179
|
+
replace: (parentNode, children, match, isImport) => {
|
|
180
|
+
const callout = $createCalloutNode(calloutKind(match[1] ?? match[2]));
|
|
181
|
+
callout.append(...children);
|
|
182
|
+
parentNode.replace(callout);
|
|
183
|
+
if (!isImport)
|
|
184
|
+
callout.select(0, 0);
|
|
185
|
+
},
|
|
186
|
+
type: "element",
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Keeps callouts tidy: the line break that joins a callout's first `> ` line to its title line is
|
|
190
|
+
* dropped, so the text starts on the first line.
|
|
191
|
+
*
|
|
192
|
+
* @param editor - The editor, with {@link CalloutNode} registered.
|
|
193
|
+
* @returns A function that undoes the registration.
|
|
194
|
+
*/
|
|
195
|
+
function registerCallouts(editor) {
|
|
196
|
+
return editor.registerNodeTransform(CalloutNode, (node) => {
|
|
197
|
+
const first = node.getFirstChild();
|
|
198
|
+
if ((0, lexical_1.$isLineBreakNode)(first) && node.getChildrenSize() > 1)
|
|
199
|
+
first.remove();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MultilineElementTransformer } from "@lexical/markdown";
|
|
2
|
+
import { type LexicalEditor } from "lexical";
|
|
3
|
+
/**
|
|
4
|
+
* Lexical's code fence transformer, except that a block in plain text is written as a bare ```
|
|
5
|
+
* fence. Code blocks that name no language are shown as plain text (Lexical would give them
|
|
6
|
+
* JavaScript), and this keeps their markdown as it was.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CODE_BLOCK_TRANSFORMER: MultilineElementTransformer;
|
|
9
|
+
/**
|
|
10
|
+
* Code blocks are colored by their language, through Prism. A block that names no language is
|
|
11
|
+
* shown as plain text (see {@link CODE_BLOCK_TRANSFORMER}).
|
|
12
|
+
*
|
|
13
|
+
* @param editor - The editor, with `CodeNode` and `CodeHighlightNode` registered.
|
|
14
|
+
* @returns A function that undoes the registration.
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerCodeBlocks(editor: LexicalEditor): () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Highlighting for code blocks, and a language picker at the top right of the block the caret is
|
|
19
|
+
* in. Picking "Plain text" leaves the block's fence without a language.
|
|
20
|
+
*/
|
|
21
|
+
export declare function CodePlugin(): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CODE_BLOCK_TRANSFORMER = void 0;
|
|
4
|
+
exports.registerCodeBlocks = registerCodeBlocks;
|
|
5
|
+
exports.CodePlugin = CodePlugin;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const code_1 = require("@lexical/code");
|
|
8
|
+
const code_prism_1 = require("@lexical/code-prism");
|
|
9
|
+
const markdown_1 = require("@lexical/markdown");
|
|
10
|
+
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
11
|
+
const utils_1 = require("@lexical/utils");
|
|
12
|
+
const lexical_1 = require("lexical");
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const react_dom_1 = require("react-dom");
|
|
15
|
+
/** The language a code block without one is shown in: none, as plain text. */
|
|
16
|
+
const PLAIN = "plain";
|
|
17
|
+
/** Prism, with plain text for a code block that names no language (Lexical's default is JavaScript). */
|
|
18
|
+
const tokenizer = { ...code_prism_1.PrismTokenizer, defaultLanguage: PLAIN };
|
|
19
|
+
/**
|
|
20
|
+
* Lexical's code fence transformer, except that a block in plain text is written as a bare ```
|
|
21
|
+
* fence. Code blocks that name no language are shown as plain text (Lexical would give them
|
|
22
|
+
* JavaScript), and this keeps their markdown as it was.
|
|
23
|
+
*/
|
|
24
|
+
exports.CODE_BLOCK_TRANSFORMER = {
|
|
25
|
+
...markdown_1.CODE,
|
|
26
|
+
export: (node, exportChildren) => {
|
|
27
|
+
const markdown = markdown_1.CODE.export?.(node, exportChildren) ?? null;
|
|
28
|
+
if (markdown === null || !(0, code_1.$isCodeNode)(node) || node.getLanguage() !== PLAIN)
|
|
29
|
+
return markdown;
|
|
30
|
+
return markdown.replace(/^(`{3,})plain/, "$1");
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Code blocks are colored by their language, through Prism. A block that names no language is
|
|
35
|
+
* shown as plain text (see {@link CODE_BLOCK_TRANSFORMER}).
|
|
36
|
+
*
|
|
37
|
+
* @param editor - The editor, with `CodeNode` and `CodeHighlightNode` registered.
|
|
38
|
+
* @returns A function that undoes the registration.
|
|
39
|
+
*/
|
|
40
|
+
function registerCodeBlocks(editor) {
|
|
41
|
+
return (0, code_prism_1.registerCodeHighlighting)(editor, tokenizer);
|
|
42
|
+
}
|
|
43
|
+
/** The languages the picker offers, plain text first. */
|
|
44
|
+
function languageOptions() {
|
|
45
|
+
const options = (0, code_prism_1.getCodeLanguageOptions)().filter(([value]) => value !== PLAIN);
|
|
46
|
+
return [[PLAIN, "Plain text"], ...options];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Highlighting for code blocks, and a language picker at the top right of the block the caret is
|
|
50
|
+
* in. Picking "Plain text" leaves the block's fence without a language.
|
|
51
|
+
*/
|
|
52
|
+
function CodePlugin() {
|
|
53
|
+
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
54
|
+
const [block, setBlock] = (0, react_1.useState)();
|
|
55
|
+
const refresh = (0, react_1.useCallback)(() => {
|
|
56
|
+
const root = editor.getRootElement();
|
|
57
|
+
const active = document.activeElement;
|
|
58
|
+
const picking = active instanceof HTMLElement && active.classList.contains("peers-code-language");
|
|
59
|
+
if (picking)
|
|
60
|
+
return;
|
|
61
|
+
const focused = !!root && !!active && (root === active || root.contains(active));
|
|
62
|
+
setBlock(focused
|
|
63
|
+
? editor.getEditorState().read(() => {
|
|
64
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
65
|
+
if (!(0, lexical_1.$isRangeSelection)(selection))
|
|
66
|
+
return undefined;
|
|
67
|
+
const node = selection.anchor.getNode();
|
|
68
|
+
const code = (0, code_1.$isCodeNode)(node) ? node : node.getParent();
|
|
69
|
+
if (!(0, code_1.$isCodeNode)(code))
|
|
70
|
+
return undefined;
|
|
71
|
+
const rect = editor.getElementByKey(code.getKey())?.getBoundingClientRect();
|
|
72
|
+
if (!rect)
|
|
73
|
+
return undefined;
|
|
74
|
+
return {
|
|
75
|
+
key: code.getKey(),
|
|
76
|
+
language: (0, code_prism_1.normalizeCodeLanguage)(code.getLanguage() || PLAIN),
|
|
77
|
+
rect,
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
: undefined);
|
|
81
|
+
}, [editor]);
|
|
82
|
+
(0, react_1.useEffect)(() => (0, utils_1.mergeRegister)(registerCodeBlocks(editor), editor.registerUpdateListener(() => refresh()), editor.registerCommand(lexical_1.BLUR_COMMAND, () => {
|
|
83
|
+
setTimeout(refresh, 0);
|
|
84
|
+
return false;
|
|
85
|
+
}, lexical_1.COMMAND_PRIORITY_LOW)), [editor, refresh]);
|
|
86
|
+
(0, react_1.useEffect)(() => {
|
|
87
|
+
if (!block)
|
|
88
|
+
return;
|
|
89
|
+
window.addEventListener("scroll", refresh, true);
|
|
90
|
+
window.addEventListener("resize", refresh);
|
|
91
|
+
return () => {
|
|
92
|
+
window.removeEventListener("scroll", refresh, true);
|
|
93
|
+
window.removeEventListener("resize", refresh);
|
|
94
|
+
};
|
|
95
|
+
}, [block, refresh]);
|
|
96
|
+
if (!block)
|
|
97
|
+
return null;
|
|
98
|
+
const options = languageOptions();
|
|
99
|
+
const known = options.some(([value]) => value === block.language);
|
|
100
|
+
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("select", { className: "peers-code-language form-select form-select-sm", style: { top: block.rect.top + 4, left: block.rect.right - 4 }, value: block.language, "aria-label": "Code language", onChange: (event) => {
|
|
101
|
+
const language = event.target.value;
|
|
102
|
+
editor.update(() => {
|
|
103
|
+
const node = (0, lexical_1.$getNodeByKey)(block.key);
|
|
104
|
+
if ((0, code_1.$isCodeNode)(node))
|
|
105
|
+
node.setLanguage(language);
|
|
106
|
+
});
|
|
107
|
+
editor.focus();
|
|
108
|
+
}, onBlur: () => setTimeout(refresh, 0), children: [known ? null : (0, jsx_runtime_1.jsx)("option", { value: block.language, children: block.language }), options.map(([value, name]) => ((0, jsx_runtime_1.jsx)("option", { value: value, children: name }, value)))] }), document.body);
|
|
109
|
+
}
|
|
@@ -58,10 +58,17 @@ export interface IMarkdownEditorProps {
|
|
|
58
58
|
headings?: boolean;
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
* A rich-text editor whose value is markdown
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
61
|
+
* A rich-text editor whose value is markdown. It has:
|
|
62
|
+
* - headings (unless `headings` is false), lists and checklists, quotes, and `==highlight==`;
|
|
63
|
+
* - links: clicking one opens it in the browser, ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button
|
|
64
|
+
* links the selected text, pasting a URL over selected text links it, and a popup on a link
|
|
65
|
+
* edits or removes it;
|
|
66
|
+
* - code blocks colored by language, with a language picker;
|
|
67
|
+
* - in documents (`headings` not false), dividers (`***`) and callouts (`> [!NOTE]`);
|
|
68
|
+
* - mentions: `<` finds people and records in every group, `@` people, and a trigger a mention
|
|
69
|
+
* source declares, such as `#`, that source's records. A pasted id becomes its record's chip,
|
|
70
|
+
* and a mention shows as a chip with the record's live title.
|
|
71
|
+
*
|
|
72
|
+
* Edits are written back to `value`.
|
|
66
73
|
*/
|
|
67
74
|
export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.MarkdownEditor = MarkdownEditor;
|
|
40
40
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
41
|
const code_1 = require("@lexical/code");
|
|
42
|
+
const extension_1 = require("@lexical/extension");
|
|
42
43
|
const link_1 = require("@lexical/link");
|
|
43
44
|
const list_1 = require("@lexical/list");
|
|
44
45
|
const LexicalAutoFocusPlugin_1 = require("@lexical/react/LexicalAutoFocusPlugin");
|
|
@@ -53,11 +54,15 @@ const LexicalMarkdownShortcutPlugin_1 = require("@lexical/react/LexicalMarkdownS
|
|
|
53
54
|
const LexicalRichTextPlugin_1 = require("@lexical/react/LexicalRichTextPlugin");
|
|
54
55
|
const LexicalTabIndentationPlugin_1 = require("@lexical/react/LexicalTabIndentationPlugin");
|
|
55
56
|
const rich_text_1 = require("@lexical/rich-text");
|
|
57
|
+
const utils_1 = require("@lexical/utils");
|
|
56
58
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
57
59
|
const lexical_1 = require("lexical");
|
|
58
60
|
const react_1 = __importStar(require("react"));
|
|
59
61
|
const mention_chip_1 = require("../../mentions/mention-chip");
|
|
60
62
|
const autolink_plugin_1 = require("./autolink-plugin");
|
|
63
|
+
const blocks_1 = require("./blocks");
|
|
64
|
+
const code_plugin_1 = require("./code-plugin");
|
|
65
|
+
const link_plugin_1 = require("./link-plugin");
|
|
61
66
|
const markdown_plugin_1 = require("./markdown-plugin");
|
|
62
67
|
const mention_node_1 = require("./mention-node");
|
|
63
68
|
const mentions_plugin_1 = require("./mentions-plugin");
|
|
@@ -71,7 +76,10 @@ const editorConfig = {
|
|
|
71
76
|
nodes: [
|
|
72
77
|
rich_text_1.HeadingNode,
|
|
73
78
|
rich_text_1.QuoteNode,
|
|
79
|
+
blocks_1.CalloutNode,
|
|
74
80
|
code_1.CodeNode,
|
|
81
|
+
code_1.CodeHighlightNode,
|
|
82
|
+
extension_1.HorizontalRuleNode,
|
|
75
83
|
list_1.ListNode,
|
|
76
84
|
list_1.ListItemNode,
|
|
77
85
|
mention_node_1.MentionNode,
|
|
@@ -87,11 +95,18 @@ const editorConfig = {
|
|
|
87
95
|
theme: theme_1.default,
|
|
88
96
|
};
|
|
89
97
|
/**
|
|
90
|
-
* A rich-text editor whose value is markdown
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
98
|
+
* A rich-text editor whose value is markdown. It has:
|
|
99
|
+
* - headings (unless `headings` is false), lists and checklists, quotes, and `==highlight==`;
|
|
100
|
+
* - links: clicking one opens it in the browser, ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button
|
|
101
|
+
* links the selected text, pasting a URL over selected text links it, and a popup on a link
|
|
102
|
+
* edits or removes it;
|
|
103
|
+
* - code blocks colored by language, with a language picker;
|
|
104
|
+
* - in documents (`headings` not false), dividers (`***`) and callouts (`> [!NOTE]`);
|
|
105
|
+
* - mentions: `<` finds people and records in every group, `@` people, and a trigger a mention
|
|
106
|
+
* source declares, such as `#`, that source's records. A pasted id becomes its record's chip,
|
|
107
|
+
* and a mention shows as a chip with the record's live title.
|
|
108
|
+
*
|
|
109
|
+
* Edits are written back to `value`.
|
|
95
110
|
*/
|
|
96
111
|
function MarkdownEditor(props) {
|
|
97
112
|
const { effects } = props;
|
|
@@ -120,7 +135,7 @@ function MarkdownEditor(props) {
|
|
|
120
135
|
};
|
|
121
136
|
}
|
|
122
137
|
const transformers = props.headings === false ? markdown_plugin_1.inlineMarkdownTransformers : markdown_plugin_1.documentMarkdownTransformers;
|
|
123
|
-
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)(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] })] }) }) }));
|
|
138
|
+
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] })] }) }) }));
|
|
124
139
|
}
|
|
125
140
|
const OnKeyDownPlugin = (props) => {
|
|
126
141
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -141,3 +156,9 @@ const OnKeyDownPlugin = (props) => {
|
|
|
141
156
|
}, [editor]);
|
|
142
157
|
return null;
|
|
143
158
|
};
|
|
159
|
+
/** Dividers that can be selected, and tidy callouts (see `blocks.ts`). */
|
|
160
|
+
const BlocksPlugin = () => {
|
|
161
|
+
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
162
|
+
(0, react_1.useEffect)(() => (0, utils_1.mergeRegister)((0, blocks_1.registerHorizontalRules)(editor), (0, blocks_1.registerCallouts)(editor)), [editor]);
|
|
163
|
+
return null;
|
|
164
|
+
};
|