@peers-app/peers-ui 0.34.6 → 0.34.8

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 (56) hide show
  1. package/dist/command-palette/command-palette-ui.js +14 -14
  2. package/dist/command-palette/command-palette.d.ts +10 -3
  3. package/dist/command-palette/command-palette.js +60 -6
  4. package/dist/command-palette/frame-commands.d.ts +37 -0
  5. package/dist/command-palette/frame-commands.js +43 -0
  6. package/dist/components/markdown-editor/editor.d.ts +5 -4
  7. package/dist/components/markdown-editor/editor.js +10 -145
  8. package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
  9. package/dist/components/markdown-editor/lexical-editor.js +153 -0
  10. package/dist/components/markdown-render.d.ts +8 -0
  11. package/dist/components/markdown-render.js +143 -0
  12. package/dist/components/markdown-with-mentions.d.ts +1 -1
  13. package/dist/components/markdown-with-mentions.js +7 -129
  14. package/dist/components/trust-level-dropdown.d.ts +6 -1
  15. package/dist/components/trust-level-dropdown.js +43 -14
  16. package/dist/globals.d.ts +13 -2
  17. package/dist/globals.js +24 -2
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +9 -1
  20. package/dist/isolated-screens/config.js +1 -5
  21. package/dist/isolated-screens/focus-relay.d.ts +24 -0
  22. package/dist/isolated-screens/focus-relay.js +104 -0
  23. package/dist/isolated-screens/frame-document.d.ts +7 -0
  24. package/dist/isolated-screens/frame-document.js +11 -1
  25. package/dist/isolated-screens/frame-permissions.d.ts +11 -0
  26. package/dist/isolated-screens/frame-permissions.js +33 -0
  27. package/dist/isolated-screens/frame-protocol.d.ts +90 -0
  28. package/dist/isolated-screens/frame-protocol.js +49 -0
  29. package/dist/isolated-screens/frame-runtime.js +115 -16
  30. package/dist/isolated-screens/frame-viewport.d.ts +9 -0
  31. package/dist/isolated-screens/frame-viewport.js +36 -0
  32. package/dist/isolated-screens/global-widgets.d.ts +74 -0
  33. package/dist/isolated-screens/global-widgets.js +270 -0
  34. package/dist/isolated-screens/isolated-screen.d.ts +57 -1
  35. package/dist/isolated-screens/isolated-screen.js +266 -15
  36. package/dist/isolated-screens/piece-frames.js +57 -5
  37. package/dist/isolated-screens/piece-reach.d.ts +24 -0
  38. package/dist/isolated-screens/piece-reach.js +40 -13
  39. package/dist/isolated-screens/widget-box.d.ts +48 -0
  40. package/dist/isolated-screens/widget-box.js +193 -0
  41. package/dist/lazy-module.d.ts +17 -0
  42. package/dist/lazy-module.js +26 -0
  43. package/dist/operator-console/console-session.js +1 -9
  44. package/dist/operator-console/operator-console-state.js +5 -1
  45. package/dist/root-layout/root-layout-host.js +3 -1
  46. package/dist/screens/groups/group-members.js +7 -17
  47. package/dist/screens/invites/accept-invite.js +15 -4
  48. package/dist/screens/packages/package-info.js +2 -1
  49. package/dist/screens/packages/package-widgets-panel.d.ts +15 -0
  50. package/dist/screens/packages/package-widgets-panel.js +64 -0
  51. package/dist/tabs-layout/tabs-state.d.ts +5 -2
  52. package/dist/tabs-layout/tabs-state.js +41 -17
  53. package/dist/ui-contracts/piece-height.d.ts +8 -2
  54. package/dist/ui-contracts/piece-height.js +6 -1
  55. package/dist/ui-contracts/piece.js +1 -1
  56. package/package.json +4 -3
@@ -11,6 +11,10 @@ const tabs_state_1 = require("../tabs-layout/tabs-state");
11
11
  const app_catalog_1 = require("../ui-router/app-catalog");
12
12
  const routes_loader_1 = require("../ui-router/routes-loader");
13
13
  const command_palette_1 = require("./command-palette");
14
+ function chooseCommand(id) {
15
+ (0, command_palette_1.closeCommandPalette)();
16
+ (0, command_palette_1.executeCommand)(id);
17
+ }
14
18
  /** Searchable overlay for launching apps and running commands. */
15
19
  function CommandPaletteOverlay() {
16
20
  const [isOpen] = (0, hooks_1.useObservable)(command_palette_1.isCommandPaletteOpen);
@@ -71,16 +75,18 @@ function CommandPaletteOverlay() {
71
75
  allItems.push({ type: "app", app, id: `app-${app.packageId}-${app.path}` });
72
76
  });
73
77
  // Then add commands
74
- const visualOrderCommands = Object.entries(filteredCommands.reduce((acc, cmd) => {
78
+ const groupedCommands = Object.entries(filteredCommands.reduce((acc, cmd) => {
75
79
  const category = cmd.category || "Other";
76
80
  if (!acc[category])
77
81
  acc[category] = [];
78
82
  acc[category].push(cmd);
79
83
  return acc;
80
- }, {})).flatMap(([, commands]) => commands);
81
- visualOrderCommands.forEach((cmd) => {
82
- allItems.push({ type: "command", command: cmd, id: `command-${cmd.id}` });
83
- });
84
+ }, Object.create(null)));
85
+ for (const [, commands] of groupedCommands) {
86
+ for (const cmd of commands) {
87
+ allItems.push({ type: "command", command: cmd, id: `command-${cmd.id}` });
88
+ }
89
+ }
84
90
  // Focus input when opened
85
91
  (0, react_1.useEffect)(() => {
86
92
  if (isOpen && inputRef.current) {
@@ -112,7 +118,7 @@ function CommandPaletteOverlay() {
112
118
  (0, tabs_state_1.goToTabPath)(selectedItem.app.path);
113
119
  }
114
120
  else if (selectedItem?.type === "command" && selectedItem.command) {
115
- (0, command_palette_1.executeCommand)(selectedItem.command.id);
121
+ chooseCommand(selectedItem.command.id);
116
122
  }
117
123
  }
118
124
  };
@@ -189,13 +195,7 @@ function CommandPaletteOverlay() {
189
195
  minWidth: "16px",
190
196
  } }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "fw-medium", children: app.displayName }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted", style: { fontSize: "12px" }, children: app.packageId === "system-apps" ? "System App" : app.packageName })] })] }) }, `${app.packageId}-${app.path}`));
191
197
  })] })), filteredCommands.length > 0 &&
192
- Object.entries(filteredCommands.reduce((acc, cmd) => {
193
- const category = cmd.category || "Other";
194
- if (!acc[category])
195
- acc[category] = [];
196
- acc[category].push(cmd);
197
- return acc;
198
- }, {})).map(([category, commands]) => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "px-3 py-1 small text-muted fw-bold text-uppercase", style: { fontSize: "11px", letterSpacing: "0.5px" }, children: category }), commands.map((command) => {
198
+ groupedCommands.map(([category, commands]) => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "px-3 py-1 small text-muted fw-bold text-uppercase", style: { fontSize: "11px", letterSpacing: "0.5px" }, children: category }), commands.map((command) => {
199
199
  const commandId = `command-${command.id}`;
200
200
  const globalIndex = allItems.findIndex((item) => item.id === commandId);
201
201
  const isSelected = globalIndex === selectedIndex;
@@ -206,7 +206,7 @@ function CommandPaletteOverlay() {
206
206
  : ""}`, style: {
207
207
  cursor: "pointer",
208
208
  transition: "background-color 0.1s ease",
209
- }, onClick: () => (0, command_palette_1.executeCommand)(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: command.iconClassName, className: "me-3", style: {
209
+ }, onClick: () => chooseCommand(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: command.iconClassName, className: "me-3", style: {
210
210
  fontSize: "16px",
211
211
  color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
212
212
  minWidth: "16px",
@@ -8,8 +8,7 @@ export interface Command {
8
8
  description?: string;
9
9
  /**
10
10
  * Keyboard shortcut, as `Mod+Key` with modifiers in the order Cmd, Ctrl, Alt, Shift and the
11
- * key as `KeyboardEvent.key` names it (for example `Cmd+Alt+ArrowRight`). The shortcut map
12
- * is built when the palette initializes.
11
+ * key as `KeyboardEvent.key` names it (for example `Cmd+Alt+ArrowRight`).
13
12
  */
14
13
  shortcut?: string;
15
14
  /** Group heading; searched too. */
@@ -26,7 +25,9 @@ export declare const isCommandPaletteOpen: import("@peers-app/peers-sdk").Observ
26
25
  /** The palette's search text. Cleared when it opens or closes. */
27
26
  export declare const commandSearchQuery: import("@peers-app/peers-sdk").Observable<string>;
28
27
  /**
29
- * Add a command, or replace the one with its id.
28
+ * Add a command, or replace the one with its id. A package's command shows in the palette under
29
+ * its package's name, and its shortcut, which needs ⌘ or Ctrl, works from any app; a shortcut
30
+ * another command already has is refused.
30
31
  *
31
32
  * @param command - The command.
32
33
  */
@@ -37,6 +38,12 @@ export declare function registerCommand(command: Command): void;
37
38
  * @param commandId - The command's id.
38
39
  */
39
40
  export declare function unregisterCommand(commandId: string): void;
41
+ /**
42
+ * The command a shortcut runs, if any.
43
+ *
44
+ * @param shortcut - As `Command.shortcut`.
45
+ */
46
+ export declare function commandForShortcut(shortcut: string): Command | undefined;
40
47
  /**
41
48
  * Look up a command.
42
49
  *
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.commandSearchQuery = exports.isCommandPaletteOpen = void 0;
4
4
  exports.registerCommand = registerCommand;
5
5
  exports.unregisterCommand = unregisterCommand;
6
+ exports.commandForShortcut = commandForShortcut;
6
7
  exports.getCommand = getCommand;
7
8
  exports.getAllCommands = getAllCommands;
8
9
  exports.searchCommands = searchCommands;
@@ -15,12 +16,15 @@ exports.destroyCommandPalette = destroyCommandPalette;
15
16
  const peers_sdk_1 = require("@peers-app/peers-sdk");
16
17
  const frame_realm_1 = require("../isolated-screens/frame-realm");
17
18
  const tabs_state_1 = require("../tabs-layout/tabs-state");
19
+ const frame_commands_1 = require("./frame-commands");
18
20
  /** Whether the command palette is open. In memory only. */
19
21
  exports.isCommandPaletteOpen = (0, peers_sdk_1.observable)(false);
20
22
  /** The palette's search text. Cleared when it opens or closes. */
21
23
  exports.commandSearchQuery = (0, peers_sdk_1.observable)("");
22
24
  // Command registry
23
25
  const registeredCommands = new Map();
26
+ // Normalized shortcut → command id.
27
+ const shortcutToCommandMap = new Map();
24
28
  // Detect platform for keyboard shortcuts
25
29
  const isMac = typeof navigator !== "undefined" ? /Mac|iPod|iPhone|iPad/.test(navigator.userAgent) : false;
26
30
  const modKey = isMac ? "Cmd" : "Ctrl";
@@ -96,11 +100,37 @@ for (const cmd of coreCommands) {
96
100
  registeredCommands.set(cmd.id, cmd);
97
101
  }
98
102
  /**
99
- * Add a command, or replace the one with its id.
103
+ * Add a command, or replace the one with its id. A package's command shows in the palette under
104
+ * its package's name, and its shortcut, which needs ⌘ or Ctrl, works from any app; a shortcut
105
+ * another command already has is refused.
100
106
  *
101
107
  * @param command - The command.
102
108
  */
103
109
  function registerCommand(command) {
110
+ const hostBridge = (0, frame_commands_1.commandHostBridge)();
111
+ if (hostBridge) {
112
+ (0, frame_commands_1.setFrameCommandAction)(command.id, command.action);
113
+ hostBridge.register({
114
+ id: command.id,
115
+ label: command.label,
116
+ ...(command.description === undefined ? {} : { description: command.description }),
117
+ ...(command.shortcut === undefined ? {} : { shortcut: command.shortcut }),
118
+ ...(command.iconClassName === undefined ? {} : { iconClassName: command.iconClassName }),
119
+ });
120
+ }
121
+ else if (command.shortcut) {
122
+ const key = normalizeShortcut(command.shortcut);
123
+ const owner = shortcutToCommandMap.get(key);
124
+ if (owner && owner !== command.id) {
125
+ console.warn(`${command.shortcut} is already the shortcut for ${registeredCommands.get(owner)?.label ?? owner}`);
126
+ return;
127
+ }
128
+ releaseShortcut(registeredCommands.get(command.id));
129
+ shortcutToCommandMap.set(key, command.id);
130
+ }
131
+ else {
132
+ releaseShortcut(registeredCommands.get(command.id));
133
+ }
104
134
  registeredCommands.set(command.id, command);
105
135
  }
106
136
  /**
@@ -109,7 +139,31 @@ function registerCommand(command) {
109
139
  * @param commandId - The command's id.
110
140
  */
111
141
  function unregisterCommand(commandId) {
142
+ const command = registeredCommands.get(commandId);
112
143
  registeredCommands.delete(commandId);
144
+ const hostBridge = (0, frame_commands_1.commandHostBridge)();
145
+ if (hostBridge) {
146
+ (0, frame_commands_1.setFrameCommandAction)(commandId, undefined);
147
+ hostBridge.unregister(commandId);
148
+ return;
149
+ }
150
+ releaseShortcut(command);
151
+ }
152
+ function releaseShortcut(command) {
153
+ if (command?.shortcut) {
154
+ const key = normalizeShortcut(command.shortcut);
155
+ if (shortcutToCommandMap.get(key) === command.id)
156
+ shortcutToCommandMap.delete(key);
157
+ }
158
+ }
159
+ /**
160
+ * The command a shortcut runs, if any.
161
+ *
162
+ * @param shortcut - As `Command.shortcut`.
163
+ */
164
+ function commandForShortcut(shortcut) {
165
+ const commandId = shortcutToCommandMap.get(normalizeShortcut(shortcut));
166
+ return commandId ? registeredCommands.get(commandId) : undefined;
113
167
  }
114
168
  /**
115
169
  * Look up a command.
@@ -162,13 +216,13 @@ function toggleCommandPalette() {
162
216
  * @param commandId - The command's id.
163
217
  */
164
218
  function executeCommand(commandId) {
165
- const command = getCommand(commandId);
166
- if (command) {
167
- command.action();
168
- }
219
+ const host = (0, frame_commands_1.commandHostBridge)();
220
+ if (host)
221
+ host.run(commandId);
222
+ else
223
+ getCommand(commandId)?.action();
169
224
  }
170
225
  // Keyboard shortcut handling
171
- const shortcutToCommandMap = new Map();
172
226
  // Build shortcut map from registered commands
173
227
  function buildShortcutMap() {
174
228
  shortcutToCommandMap.clear();
@@ -0,0 +1,37 @@
1
+ import type { IFrameCommand } from "../isolated-screens/frame-protocol";
2
+ /**
3
+ * A package frame's commands: in a frame, `registerCommand` sends a command to the host's palette
4
+ * and keeps its action here, for when the host runs it. Kept apart from the palette, which imports
5
+ * the tabs, so the frame runtime can load it alone.
6
+ */
7
+ /** The host's palette, as a package's frame reaches it. */
8
+ export interface ICommandHostBridge {
9
+ /** Add one of the frame's commands to the host's palette. */
10
+ register(command: IFrameCommand): void;
11
+ /** Take one of them out. */
12
+ unregister(commandId: string): void;
13
+ /** Run one of the package's commands that another of its frames added. */
14
+ run(commandId: string): void;
15
+ }
16
+ /**
17
+ * Send this frame's commands to the host's palette. Only the frame runtime calls it.
18
+ *
19
+ * @param bridge - The host's side, or `undefined` to stop (tests).
20
+ */
21
+ export declare function bridgeCommandsToHost(bridge: ICommandHostBridge | undefined): void;
22
+ /** The host's palette, in a frame; `undefined` in the host's window. */
23
+ export declare function commandHostBridge(): ICommandHostBridge | undefined;
24
+ /**
25
+ * Keep a frame command's action, or drop it.
26
+ *
27
+ * @param commandId - The id the frame registered it under.
28
+ * @param action - What it runs; `undefined` to drop it.
29
+ */
30
+ export declare function setFrameCommandAction(commandId: string, action: (() => void) | undefined): void;
31
+ /**
32
+ * Run a command this frame registered, when the host's palette or a shortcut runs it. Only the
33
+ * frame runtime calls it.
34
+ *
35
+ * @param commandId - The id the frame registered it under.
36
+ */
37
+ export declare function runFrameCommand(commandId: string): void;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bridgeCommandsToHost = bridgeCommandsToHost;
4
+ exports.commandHostBridge = commandHostBridge;
5
+ exports.setFrameCommandAction = setFrameCommandAction;
6
+ exports.runFrameCommand = runFrameCommand;
7
+ let hostBridge;
8
+ const actions = new Map();
9
+ /**
10
+ * Send this frame's commands to the host's palette. Only the frame runtime calls it.
11
+ *
12
+ * @param bridge - The host's side, or `undefined` to stop (tests).
13
+ */
14
+ function bridgeCommandsToHost(bridge) {
15
+ hostBridge = bridge;
16
+ if (!bridge)
17
+ actions.clear();
18
+ }
19
+ /** The host's palette, in a frame; `undefined` in the host's window. */
20
+ function commandHostBridge() {
21
+ return hostBridge;
22
+ }
23
+ /**
24
+ * Keep a frame command's action, or drop it.
25
+ *
26
+ * @param commandId - The id the frame registered it under.
27
+ * @param action - What it runs; `undefined` to drop it.
28
+ */
29
+ function setFrameCommandAction(commandId, action) {
30
+ if (action)
31
+ actions.set(commandId, action);
32
+ else
33
+ actions.delete(commandId);
34
+ }
35
+ /**
36
+ * Run a command this frame registered, when the host's palette or a shortcut runs it. Only the
37
+ * frame runtime calls it.
38
+ *
39
+ * @param commandId - The id the frame registered it under.
40
+ */
41
+ function runFrameCommand(commandId) {
42
+ actions.get(commandId)?.();
43
+ }
@@ -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
+ }>;