@peers-app/peers-ui 0.34.5 → 0.34.7

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.
Files changed (36) hide show
  1. package/dist/components/group-switcher.js +30 -2
  2. package/dist/components/markdown-editor/editor.d.ts +5 -4
  3. package/dist/components/markdown-editor/editor.js +10 -145
  4. package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
  5. package/dist/components/markdown-editor/lexical-editor.js +153 -0
  6. package/dist/components/markdown-render.d.ts +8 -0
  7. package/dist/components/markdown-render.js +143 -0
  8. package/dist/components/markdown-with-mentions.d.ts +1 -1
  9. package/dist/components/markdown-with-mentions.js +7 -129
  10. package/dist/components/trust-level-dropdown.d.ts +6 -1
  11. package/dist/components/trust-level-dropdown.js +43 -14
  12. package/dist/components/use-close-on-outside-press.d.ts +19 -0
  13. package/dist/components/use-close-on-outside-press.js +54 -0
  14. package/dist/isolated-screens/focus-relay.d.ts +24 -0
  15. package/dist/isolated-screens/focus-relay.js +104 -0
  16. package/dist/isolated-screens/frame-document.d.ts +7 -0
  17. package/dist/isolated-screens/frame-document.js +11 -1
  18. package/dist/isolated-screens/frame-protocol.d.ts +26 -0
  19. package/dist/isolated-screens/frame-protocol.js +21 -0
  20. package/dist/isolated-screens/frame-runtime.js +47 -14
  21. package/dist/isolated-screens/isolated-screen.d.ts +6 -0
  22. package/dist/isolated-screens/isolated-screen.js +40 -3
  23. package/dist/isolated-screens/piece-frames.js +57 -5
  24. package/dist/isolated-screens/piece-reach.js +17 -6
  25. package/dist/lazy-module.d.ts +17 -0
  26. package/dist/lazy-module.js +26 -0
  27. package/dist/notifications/notification-bell.js +2 -18
  28. package/dist/operator-console/console-session.js +1 -9
  29. package/dist/screens/groups/group-members.js +7 -17
  30. package/dist/screens/invites/accept-invite.js +15 -4
  31. package/dist/tabs-layout/network-status-indicator.js +2 -21
  32. package/dist/theme.css +8 -0
  33. package/dist/ui-contracts/piece-height.d.ts +8 -2
  34. package/dist/ui-contracts/piece-height.js +6 -1
  35. package/dist/ui-contracts/piece.js +1 -1
  36. package/package.json +4 -3
@@ -12,6 +12,31 @@ const groups_ipc_1 = require("../screens/groups/groups-ipc");
12
12
  const color_picker_1 = require("./color-picker");
13
13
  const icon_1 = require("./icon");
14
14
  const icon_picker_1 = require("./icon-picker");
15
+ /** Room the open menu leaves between itself and the window's bottom edge, in pixels. */
16
+ const MENU_BOTTOM_GAP = 12;
17
+ /** The least the open menu's height is held to, however short the window. */
18
+ const MENU_MIN_HEIGHT = 200;
19
+ /**
20
+ * The tallest the open menu can be and still end above the window's bottom edge, measured from
21
+ * where it opens and kept current as the window resizes; undefined until it's open.
22
+ */
23
+ function useMenuMaxHeight(menu, open) {
24
+ const [maxHeight, setMaxHeight] = (0, react_1.useState)();
25
+ (0, react_1.useLayoutEffect)(() => {
26
+ if (!open)
27
+ return;
28
+ const measure = () => {
29
+ const top = menu.current?.getBoundingClientRect().top;
30
+ if (top === undefined)
31
+ return;
32
+ setMaxHeight(Math.max(MENU_MIN_HEIGHT, window.innerHeight - top - MENU_BOTTOM_GAP));
33
+ };
34
+ measure();
35
+ window.addEventListener("resize", measure);
36
+ return () => window.removeEventListener("resize", measure);
37
+ }, [menu, open]);
38
+ return maxHeight;
39
+ }
15
40
  /**
16
41
  * Header dropdown for switching the active group (or the personal context), opening the current
17
42
  * group's color-and-icon dialog, and creating a new group, which also installs the default
@@ -21,6 +46,8 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
21
46
  const [showDropdown, setShowDropdown] = (0, react_1.useState)(false);
22
47
  const [showCreateModal, setShowCreateModal] = (0, react_1.useState)(false);
23
48
  const [allGroups, setAllGroups] = (0, react_1.useState)([]);
49
+ const menu = (0, react_1.useRef)(null);
50
+ const menuMaxHeight = useMenuMaxHeight(menu, showDropdown);
24
51
  const userContext = (0, hooks_1.usePromise)(peers_sdk_1.getUserContext);
25
52
  // Load groups from user context, and again whenever a group is added, renamed, removed or
26
53
  // restored, on this device or another of the user's.
@@ -101,12 +128,13 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
101
128
  }, onMouseLeave: (e) => {
102
129
  e.currentTarget.style.backgroundColor = "transparent";
103
130
  e.currentTarget.style.color = isDark ? "#adb5bd" : "var(--peers-tab-strip-color)";
104
- }, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
131
+ }, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { ref: menu, className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
105
132
  left: 0,
106
133
  top: "100%",
107
134
  zIndex: 1000,
108
135
  minWidth: "200px",
109
- maxHeight: "300px",
136
+ // Down to the window's bottom edge, so a long list of groups shows whole.
137
+ maxHeight: menuMaxHeight ?? MENU_MIN_HEIGHT,
110
138
  overflowY: "auto",
111
139
  }, children: [(0, jsx_runtime_1.jsxs)("button", { className: `dropdown-item d-flex align-items-center ${!currentGroup ? "active" : ""}`, style: {
112
140
  cursor: "pointer",
@@ -1,6 +1,7 @@
1
- import { type IMentionLink, type Observable } from "@peers-app/peers-sdk";
2
- import React from "react";
3
- import { type IToolbarControl } from "./toolbar";
1
+ import type { IMentionLink, Observable } from "@peers-app/peers-sdk";
2
+ import type React from "react";
3
+ import type { IToolbarControl } from "./toolbar";
4
+ import "prismjs";
4
5
  /**
5
6
  * Hooks for working with the editor imperatively. The caller sets `onKeyDown`, which sees keys
6
7
  * first (return true to handle one; skipped while the mention picker is open). The editor sets
@@ -71,4 +72,4 @@ export interface IMarkdownEditorProps {
71
72
  *
72
73
  * Edits are written back to `value`.
73
74
  */
74
- export declare function MarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
75
+ export declare function MarkdownEditor(props: IMarkdownEditorProps): React.FunctionComponentElement<IMarkdownEditorProps>;
@@ -1,99 +1,15 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.MarkdownEditor = MarkdownEditor;
40
- const jsx_runtime_1 = require("react/jsx-runtime");
41
- const code_1 = require("@lexical/code");
42
- const extension_1 = require("@lexical/extension");
43
- const link_1 = require("@lexical/link");
44
- const list_1 = require("@lexical/list");
45
- const LexicalAutoFocusPlugin_1 = require("@lexical/react/LexicalAutoFocusPlugin");
46
- const LexicalCheckListPlugin_1 = require("@lexical/react/LexicalCheckListPlugin");
47
- const LexicalComposer_1 = require("@lexical/react/LexicalComposer");
48
- const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
49
- const LexicalContentEditable_1 = require("@lexical/react/LexicalContentEditable");
50
- const LexicalErrorBoundary_1 = require("@lexical/react/LexicalErrorBoundary");
51
- const LexicalHistoryPlugin_1 = require("@lexical/react/LexicalHistoryPlugin");
52
- const LexicalListPlugin_1 = require("@lexical/react/LexicalListPlugin");
53
- const LexicalMarkdownShortcutPlugin_1 = require("@lexical/react/LexicalMarkdownShortcutPlugin");
54
- const LexicalRichTextPlugin_1 = require("@lexical/react/LexicalRichTextPlugin");
55
- const LexicalTabIndentationPlugin_1 = require("@lexical/react/LexicalTabIndentationPlugin");
56
- const rich_text_1 = require("@lexical/rich-text");
57
- const utils_1 = require("@lexical/utils");
58
- const peers_sdk_1 = require("@peers-app/peers-sdk");
59
- const lexical_1 = require("lexical");
60
- const react_1 = __importStar(require("react"));
61
- const mention_chip_1 = require("../../mentions/mention-chip");
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");
66
- const markdown_plugin_1 = require("./markdown-plugin");
67
- const mention_node_1 = require("./mention-node");
68
- const mentions_plugin_1 = require("./mentions-plugin");
69
- const move_line_plugin_1 = require("./move-line-plugin");
70
- const select_line_boundary_plugin_1 = require("./select-line-boundary-plugin");
71
- const selection_effects_plugin_1 = require("./selection-effects-plugin");
72
- const theme_1 = __importDefault(require("./theme"));
73
- const toolbar_1 = require("./toolbar");
74
- const editorConfig = {
75
- namespace: "PeersEditor",
76
- nodes: [
77
- rich_text_1.HeadingNode,
78
- rich_text_1.QuoteNode,
79
- blocks_1.CalloutNode,
80
- code_1.CodeNode,
81
- code_1.CodeHighlightNode,
82
- extension_1.HorizontalRuleNode,
83
- list_1.ListNode,
84
- list_1.ListItemNode,
85
- mention_node_1.MentionNode,
86
- // Lexical node registry typing is narrower than runtime; AutoLinkNode is required for links.
87
- link_1.AutoLinkNode,
88
- link_1.LinkNode,
89
- ],
90
- // Handling of errors during update
91
- onError(error) {
92
- throw error;
93
- },
94
- // The editor theme
95
- theme: theme_1.default,
96
- };
4
+ const react_1 = require("react");
5
+ const lazy_module_1 = require("../../lazy-module");
6
+ // Prism, which colors the editor's code blocks, still loads with peers-ui. When Prism first loads
7
+ // it colors every `language-*` code block on the page, and it becomes the page's `Prism`. Loaded
8
+ // at the first editor instead, it would rewrite code blocks React had already drawn, which then
9
+ // stop updating, and it would take the place of a package's own copy of Prism.
10
+ require("prismjs");
11
+ /** Lexical and the editor's plugins, loaded the first time an editor draws. */
12
+ const lexicalEditor = (0, lazy_module_1.lazyModule)(() => require("./lexical-editor"));
97
13
  /**
98
14
  * A rich-text editor whose value is markdown. It has:
99
15
  * - headings (unless `headings` is false), lists and checklists, quotes, and `==highlight==`;
@@ -109,56 +25,5 @@ const editorConfig = {
109
25
  * Edits are written back to `value`.
110
26
  */
111
27
  function MarkdownEditor(props) {
112
- const { effects } = props;
113
- const editorRef = react_1.default.useRef(null);
114
- const [mentionsOpen] = (0, react_1.useState)(() => {
115
- const obs = (0, peers_sdk_1.observable)(false);
116
- return obs;
117
- });
118
- if (effects) {
119
- effects.focus = () => {
120
- if (editorRef.current?.children[0]) {
121
- const div = editorRef.current.children[0];
122
- setTimeout(() => {
123
- div.focus();
124
- // Set the selection to the end of the div content
125
- const range = document.createRange();
126
- range.selectNodeContents(div);
127
- range.collapse(false);
128
- const selection = window.getSelection();
129
- if (selection) {
130
- selection.removeAllRanges();
131
- selection.addRange(range);
132
- }
133
- }, 10);
134
- }
135
- };
136
- }
137
- const transformers = props.headings === false ? markdown_plugin_1.inlineMarkdownTransformers : markdown_plugin_1.documentMarkdownTransformers;
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] })] }) }) }));
28
+ return (0, react_1.createElement)(lexicalEditor().LexicalMarkdownEditor, props);
139
29
  }
140
- const OnKeyDownPlugin = (props) => {
141
- const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
142
- // Intentionally `[editor]` only: `props.effects` is a stable object ref whose `onKeyDown` is
143
- // imperatively reassigned by callers each render; the closure reads the latest value at event time.
144
- (0, react_1.useEffect)(() => {
145
- const removeListener = editor.registerCommand(lexical_1.KEY_DOWN_COMMAND, (event) => {
146
- if (props.mentionsOpen()) {
147
- return false;
148
- }
149
- if (props.effects?.onKeyDown) {
150
- const result = props.effects.onKeyDown(event);
151
- return !!result;
152
- }
153
- return false;
154
- }, lexical_1.COMMAND_PRIORITY_LOW);
155
- return removeListener;
156
- }, [editor]);
157
- return null;
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
- };
@@ -0,0 +1,3 @@
1
+ import type { IMarkdownEditorProps } from "./editor";
2
+ /** {@link MarkdownEditor}'s implementation. */
3
+ export declare function LexicalMarkdownEditor(props: IMarkdownEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,153 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.LexicalMarkdownEditor = LexicalMarkdownEditor;
40
+ const jsx_runtime_1 = require("react/jsx-runtime");
41
+ // The markdown editor itself, built on Lexical. It loads the first time an editor draws
42
+ // (`MarkdownEditor` in editor.tsx), not when peers-ui loads: see `lazyModule`.
43
+ const code_1 = require("@lexical/code");
44
+ const extension_1 = require("@lexical/extension");
45
+ const link_1 = require("@lexical/link");
46
+ const list_1 = require("@lexical/list");
47
+ const LexicalAutoFocusPlugin_1 = require("@lexical/react/LexicalAutoFocusPlugin");
48
+ const LexicalCheckListPlugin_1 = require("@lexical/react/LexicalCheckListPlugin");
49
+ const LexicalComposer_1 = require("@lexical/react/LexicalComposer");
50
+ const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
51
+ const LexicalContentEditable_1 = require("@lexical/react/LexicalContentEditable");
52
+ const LexicalErrorBoundary_1 = require("@lexical/react/LexicalErrorBoundary");
53
+ const LexicalHistoryPlugin_1 = require("@lexical/react/LexicalHistoryPlugin");
54
+ const LexicalListPlugin_1 = require("@lexical/react/LexicalListPlugin");
55
+ const LexicalMarkdownShortcutPlugin_1 = require("@lexical/react/LexicalMarkdownShortcutPlugin");
56
+ const LexicalRichTextPlugin_1 = require("@lexical/react/LexicalRichTextPlugin");
57
+ const LexicalTabIndentationPlugin_1 = require("@lexical/react/LexicalTabIndentationPlugin");
58
+ const rich_text_1 = require("@lexical/rich-text");
59
+ const utils_1 = require("@lexical/utils");
60
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
61
+ const lexical_1 = require("lexical");
62
+ const react_1 = __importStar(require("react"));
63
+ const mention_chip_1 = require("../../mentions/mention-chip");
64
+ const autolink_plugin_1 = require("./autolink-plugin");
65
+ const blocks_1 = require("./blocks");
66
+ const code_plugin_1 = require("./code-plugin");
67
+ const link_plugin_1 = require("./link-plugin");
68
+ const markdown_plugin_1 = require("./markdown-plugin");
69
+ const mention_node_1 = require("./mention-node");
70
+ const mentions_plugin_1 = require("./mentions-plugin");
71
+ const move_line_plugin_1 = require("./move-line-plugin");
72
+ const select_line_boundary_plugin_1 = require("./select-line-boundary-plugin");
73
+ const selection_effects_plugin_1 = require("./selection-effects-plugin");
74
+ const theme_1 = __importDefault(require("./theme"));
75
+ const toolbar_1 = require("./toolbar");
76
+ const editorConfig = {
77
+ namespace: "PeersEditor",
78
+ nodes: [
79
+ rich_text_1.HeadingNode,
80
+ rich_text_1.QuoteNode,
81
+ blocks_1.CalloutNode,
82
+ code_1.CodeNode,
83
+ code_1.CodeHighlightNode,
84
+ extension_1.HorizontalRuleNode,
85
+ list_1.ListNode,
86
+ list_1.ListItemNode,
87
+ mention_node_1.MentionNode,
88
+ // Lexical node registry typing is narrower than runtime; AutoLinkNode is required for links.
89
+ link_1.AutoLinkNode,
90
+ link_1.LinkNode,
91
+ ],
92
+ // Handling of errors during update
93
+ onError(error) {
94
+ throw error;
95
+ },
96
+ // The editor theme
97
+ theme: theme_1.default,
98
+ };
99
+ /** {@link MarkdownEditor}'s implementation. */
100
+ function LexicalMarkdownEditor(props) {
101
+ const { effects } = props;
102
+ const editorRef = react_1.default.useRef(null);
103
+ const [mentionsOpen] = (0, react_1.useState)(() => {
104
+ const obs = (0, peers_sdk_1.observable)(false);
105
+ return obs;
106
+ });
107
+ if (effects) {
108
+ effects.focus = () => {
109
+ if (editorRef.current?.children[0]) {
110
+ const div = editorRef.current.children[0];
111
+ setTimeout(() => {
112
+ div.focus();
113
+ // Set the selection to the end of the div content
114
+ const range = document.createRange();
115
+ range.selectNodeContents(div);
116
+ range.collapse(false);
117
+ const selection = window.getSelection();
118
+ if (selection) {
119
+ selection.removeAllRanges();
120
+ selection.addRange(range);
121
+ }
122
+ }, 10);
123
+ }
124
+ };
125
+ }
126
+ 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] })] }) }) }));
128
+ }
129
+ const OnKeyDownPlugin = (props) => {
130
+ const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
131
+ // Intentionally `[editor]` only: `props.effects` is a stable object ref whose `onKeyDown` is
132
+ // imperatively reassigned by callers each render; the closure reads the latest value at event time.
133
+ (0, react_1.useEffect)(() => {
134
+ const removeListener = editor.registerCommand(lexical_1.KEY_DOWN_COMMAND, (event) => {
135
+ if (props.mentionsOpen()) {
136
+ return false;
137
+ }
138
+ if (props.effects?.onKeyDown) {
139
+ const result = props.effects.onKeyDown(event);
140
+ return !!result;
141
+ }
142
+ return false;
143
+ }, lexical_1.COMMAND_PRIORITY_LOW);
144
+ return removeListener;
145
+ }, [editor]);
146
+ return null;
147
+ };
148
+ /** Dividers that can be selected, and tidy callouts (see `blocks.ts`). */
149
+ const BlocksPlugin = () => {
150
+ const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
151
+ (0, react_1.useEffect)(() => (0, utils_1.mergeRegister)((0, blocks_1.registerHorizontalRules)(editor), (0, blocks_1.registerCallouts)(editor)), [editor]);
152
+ return null;
153
+ };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ /** {@link mentionUrlTransform}'s implementation. */
3
+ export declare function mentionUrlTransform(url: string): string;
4
+ /** {@link MarkdownWithMentions}'s implementation. */
5
+ export declare const MarkdownRender: React.FC<{
6
+ content: string;
7
+ groupId?: string;
8
+ }>;
@@ -0,0 +1,143 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.MarkdownRender = void 0;
40
+ exports.mentionUrlTransform = mentionUrlTransform;
41
+ const jsx_runtime_1 = require("react/jsx-runtime");
42
+ // Markdown rendered with react-markdown and remark-gfm. It loads the first time markdown is
43
+ // drawn (`MarkdownWithMentions` in markdown-with-mentions.tsx) or `mentionUrlTransform` is
44
+ // called, not when peers-ui loads: see `lazyModule`.
45
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
46
+ const react_1 = __importDefault(require("react"));
47
+ const react_markdown_1 = __importStar(require("react-markdown"));
48
+ const remark_gfm_1 = __importDefault(require("remark-gfm"));
49
+ const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
50
+ const mention_chip_1 = require("../mentions/mention-chip");
51
+ /** The text in some rendered markdown children. */
52
+ function textOf(children) {
53
+ return react_1.default.Children.toArray(children)
54
+ .map((child) => {
55
+ if (typeof child === "string" || typeof child === "number")
56
+ return String(child);
57
+ if (react_1.default.isValidElement(child)) {
58
+ return textOf(child.props.children);
59
+ }
60
+ return "";
61
+ })
62
+ .join("");
63
+ }
64
+ /** A link: a mention becomes a chip, and a web link opens in the system browser. */
65
+ const LinkRenderer = (props) => {
66
+ const { href } = props;
67
+ const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
68
+ if (mention)
69
+ return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
70
+ return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: (e) => {
71
+ if (href?.startsWith("http")) {
72
+ e.preventDefault();
73
+ void (0, host_shell_consumer_1.openOnHost)(href);
74
+ }
75
+ }, children: props.children }));
76
+ };
77
+ /**
78
+ * An image. `![label](peers://…)` is a mention typed right after a `!` ("Thanks![Plan](…)"),
79
+ * which the editor shows as `!` and a chip, so it renders the same here.
80
+ */
81
+ const ImageRenderer = ({ node: _node, src, alt, ...props }) => {
82
+ const mention = typeof src === "string" ? (0, peers_sdk_1.parseMentionUrl)(src) : undefined;
83
+ if (mention) {
84
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["!", (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: alt ?? "" })] }));
85
+ }
86
+ return (0, jsx_runtime_1.jsx)("img", { src: src, alt: alt, ...props });
87
+ };
88
+ /** Text with the older `<$kind:Name:id>` mentions turned into chips (a name alone without an id). */
89
+ const processTextWithMentions = (text) => {
90
+ const parts = [];
91
+ const regex = new RegExp((0, peers_sdk_1.mentionRegex)().source, "g");
92
+ let lastIndex = 0;
93
+ for (const match of text.matchAll(regex)) {
94
+ const at = match.index ?? 0;
95
+ if (at > lastIndex)
96
+ parts.push(text.slice(lastIndex, at));
97
+ const [, , kind, name, id] = match;
98
+ const label = name.replace(/_/g, " ");
99
+ const ref = id ? (0, peers_sdk_1.parseMentionUrl)(`peers://${kind.toLowerCase()}/${id}`) : undefined;
100
+ parts.push(ref ? (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...ref, label: label }, at) : label);
101
+ lastIndex = at + match[0].length;
102
+ }
103
+ if (lastIndex < text.length)
104
+ parts.push(text.slice(lastIndex));
105
+ return parts;
106
+ };
107
+ const createElementWithMentions = (Element) => {
108
+ return ({ node: _node, ...props }) => {
109
+ return ((0, jsx_runtime_1.jsx)(Element, { ...props, children: react_1.default.Children.map(props.children, (child) => {
110
+ if (typeof child === "string") {
111
+ return processTextWithMentions(child);
112
+ }
113
+ return child;
114
+ }) }));
115
+ };
116
+ };
117
+ const components = {
118
+ p: createElementWithMentions("p"),
119
+ h1: createElementWithMentions("h1"),
120
+ h2: createElementWithMentions("h2"),
121
+ h3: createElementWithMentions("h3"),
122
+ h4: createElementWithMentions("h4"),
123
+ h5: createElementWithMentions("h5"),
124
+ h6: createElementWithMentions("h6"),
125
+ li: createElementWithMentions("li"),
126
+ a: LinkRenderer,
127
+ img: ImageRenderer,
128
+ strong: createElementWithMentions("strong"),
129
+ em: createElementWithMentions("em"),
130
+ blockquote: createElementWithMentions("blockquote"),
131
+ code: createElementWithMentions("code"),
132
+ td: createElementWithMentions("td"),
133
+ th: createElementWithMentions("th"),
134
+ };
135
+ /** {@link mentionUrlTransform}'s implementation. */
136
+ function mentionUrlTransform(url) {
137
+ return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
138
+ }
139
+ /** {@link MarkdownWithMentions}'s implementation. */
140
+ const MarkdownRender = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
141
+ // @ts-expect-error react-markdown's component props are narrower than these wrappers
142
+ components: components, children: content }) }) }));
143
+ exports.MarkdownRender = MarkdownRender;
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import type React from "react";
2
2
  /**
3
3
  * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
4
4
  * blanks `javascript:` and other unsafe schemes in text other members wrote.