@peers-app/peers-ui 0.27.3 → 0.27.4
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/screens/network-viewer/network-viewer-ipc.d.ts +3 -1
- package/dist/screens/network-viewer/network-viewer-ipc.js +6 -0
- package/dist/screens/network-viewer/sync-recovery.js +103 -1
- package/dist/screens/variables/variable-details.js +2 -1
- package/dist/tabs-layout/network-status-indicator.js +26 -12
- package/dist/tabs-layout/use-network-status.d.ts +6 -1
- package/dist/tabs-layout/use-network-status.js +27 -4
- package/package.json +9 -3
- package/.claude/settings.local.json +0 -34
- package/.github/README.md +0 -52
- package/.github/workflows/delete-all-artifacts.yml +0 -49
- package/.github/workflows/publish.yml +0 -51
- package/babel.config.js +0 -7
- package/biome.json +0 -198
- package/dist/app-updates/app-updates-consumer.test.d.ts +0 -1
- package/dist/app-updates/app-updates-consumer.test.js +0 -56
- package/dist/app-updates/app-updates-settings.test.d.ts +0 -1
- package/dist/app-updates/app-updates-settings.test.js +0 -93
- package/dist/app-updates/remote-app-update-panel.test.d.ts +0 -1
- package/dist/app-updates/remote-app-update-panel.test.js +0 -165
- package/dist/components/access-level-field.test.d.ts +0 -1
- package/dist/components/access-level-field.test.js +0 -28
- package/dist/components/message-logs/tool-access-approval-card.test.d.ts +0 -1
- package/dist/components/message-logs/tool-access-approval-card.test.js +0 -102
- package/dist/components/responsive-section-nav.test.d.ts +0 -1
- package/dist/components/responsive-section-nav.test.js +0 -45
- package/dist/globals-hash.test.d.ts +0 -1
- package/dist/globals-hash.test.js +0 -16
- package/dist/hooks/use-observable-state.test.d.ts +0 -1
- package/dist/hooks/use-observable-state.test.js +0 -64
- package/dist/hooks/use-observable.test.d.ts +0 -1
- package/dist/hooks/use-observable.test.js +0 -191
- package/dist/hooks/use-rows.test.d.ts +0 -1
- package/dist/hooks/use-rows.test.js +0 -175
- package/dist/hooks/use-tool.test.d.ts +0 -1
- package/dist/hooks/use-tool.test.js +0 -190
- package/dist/host-shell/host-shell-consumer.test.d.ts +0 -1
- package/dist/host-shell/host-shell-consumer.test.js +0 -28
- package/dist/root-layout/root-layout-host.test.d.ts +0 -1
- package/dist/root-layout/root-layout-host.test.js +0 -86
- package/dist/screens/account/account-screen.test.d.ts +0 -1
- package/dist/screens/account/account-screen.test.js +0 -51
- package/dist/screens/assistants/assistant-config.test.d.ts +0 -1
- package/dist/screens/assistants/assistant-config.test.js +0 -57
- package/dist/screens/contacts/contact-list.test.d.ts +0 -1
- package/dist/screens/contacts/contact-list.test.js +0 -48
- package/dist/screens/device-pairing/device-pairing.test.d.ts +0 -1
- package/dist/screens/device-pairing/device-pairing.test.js +0 -119
- package/dist/screens/devices/devices-list.test.d.ts +0 -1
- package/dist/screens/devices/devices-list.test.js +0 -53
- package/dist/screens/groups/group-list.test.d.ts +0 -1
- package/dist/screens/groups/group-list.test.js +0 -38
- package/dist/screens/identity/identity-routes.test.d.ts +0 -1
- package/dist/screens/identity/identity-routes.test.js +0 -51
- package/dist/screens/identity/identity-screen.test.d.ts +0 -1
- package/dist/screens/identity/identity-screen.test.js +0 -103
- package/dist/screens/invites/accept-invite.test.d.ts +0 -1
- package/dist/screens/invites/accept-invite.test.js +0 -103
- package/dist/screens/invites/activity-view.test.d.ts +0 -1
- package/dist/screens/invites/activity-view.test.js +0 -108
- package/dist/screens/invites/invite-classify.test.d.ts +0 -1
- package/dist/screens/invites/invite-classify.test.js +0 -115
- package/dist/screens/network-viewer/network-viewer-ipc.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer-ipc.test.js +0 -61
- package/dist/screens/network-viewer/network-viewer.section.test.d.ts +0 -1
- package/dist/screens/network-viewer/network-viewer.section.test.js +0 -63
- package/dist/screens/network-viewer/sync-recovery.test.d.ts +0 -1
- package/dist/screens/network-viewer/sync-recovery.test.js +0 -104
- package/dist/screens/packages/package-helpers.test.d.ts +0 -1
- package/dist/screens/packages/package-helpers.test.js +0 -53
- package/dist/screens/packages/package-runtime-status.test.d.ts +0 -1
- package/dist/screens/packages/package-runtime-status.test.js +0 -50
- package/dist/screens/packages/packages-ipc.test.d.ts +0 -1
- package/dist/screens/packages/packages-ipc.test.js +0 -43
- package/dist/screens/settings/settings-page.test.d.ts +0 -1
- package/dist/screens/settings/settings-page.test.js +0 -19
- package/dist/screens/tools/tool-access-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-access-ipc.test.js +0 -40
- package/dist/screens/tools/tool-catalog-ipc.test.d.ts +0 -1
- package/dist/screens/tools/tool-catalog-ipc.test.js +0 -52
- package/dist/tabs-layout/network-status-indicator.test.d.ts +0 -1
- package/dist/tabs-layout/network-status-indicator.test.js +0 -665
- package/dist/tabs-layout/tabs-state.test.d.ts +0 -1
- package/dist/tabs-layout/tabs-state.test.js +0 -110
- package/dist/tabs-layout/use-network-status.test.d.ts +0 -1
- package/dist/tabs-layout/use-network-status.test.js +0 -45
- package/dist/ui-router/ui-loader.test.d.ts +0 -1
- package/dist/ui-router/ui-loader.test.js +0 -91
- package/jest.config.js +0 -25
- package/release-guard.js +0 -10
- package/src/app-updates/app-update-controls.tsx +0 -73
- package/src/app-updates/app-updates-consumer.test.ts +0 -83
- package/src/app-updates/app-updates-consumer.ts +0 -121
- package/src/app-updates/app-updates-settings.test.tsx +0 -109
- package/src/app-updates/app-updates-settings.tsx +0 -136
- package/src/app-updates/remote-app-update-panel.test.tsx +0 -205
- package/src/app-updates/remote-app-update-panel.tsx +0 -210
- package/src/app-updates/use-app-update-status.ts +0 -16
- package/src/command-palette/command-palette-ui.tsx +0 -564
- package/src/command-palette/command-palette.ts +0 -242
- package/src/components/access-level-field.test.tsx +0 -32
- package/src/components/access-level-field.tsx +0 -68
- package/src/components/checkbox.tsx +0 -25
- package/src/components/group-switcher.tsx +0 -526
- package/src/components/input-date.tsx +0 -29
- package/src/components/input-number.tsx +0 -83
- package/src/components/input.tsx +0 -25
- package/src/components/inverse-lazy-list.tsx +0 -107
- package/src/components/io-schema-values.tsx +0 -103
- package/src/components/io-schema.tsx +0 -259
- package/src/components/lazy-list.tsx +0 -115
- package/src/components/list-screen.tsx +0 -126
- package/src/components/loading-indicator.tsx +0 -7
- package/src/components/markdown-editor/autolink-plugin.tsx +0 -29
- package/src/components/markdown-editor/editor-inline.tsx +0 -9
- package/src/components/markdown-editor/editor.tsx +0 -158
- package/src/components/markdown-editor/markdown-plugin.tsx +0 -202
- package/src/components/markdown-editor/mention-node.ts +0 -204
- package/src/components/markdown-editor/mentions-plugin.tsx +0 -354
- package/src/components/markdown-editor/move-line-plugin.tsx +0 -186
- package/src/components/markdown-editor/select-line-boundary-plugin.tsx +0 -95
- package/src/components/markdown-editor/theme.ts +0 -46
- package/src/components/markdown-editor/toolbar.tsx +0 -269
- package/src/components/markdown-with-mentions.tsx +0 -198
- package/src/components/message-logs/message-logs.tsx +0 -523
- package/src/components/message-logs/tool-access-approval-card.test.tsx +0 -127
- package/src/components/message-logs/tool-access-approval-card.tsx +0 -178
- package/src/components/messages/avatar.tsx +0 -171
- package/src/components/messages/channel-message-list.tsx +0 -189
- package/src/components/messages/channel-view.tsx +0 -92
- package/src/components/messages/message-compose.tsx +0 -192
- package/src/components/messages/message-display.tsx +0 -231
- package/src/components/messages/thread-message-list.tsx +0 -135
- package/src/components/qr-scanner.tsx +0 -180
- package/src/components/responsive-section-nav.test.tsx +0 -88
- package/src/components/responsive-section-nav.tsx +0 -92
- package/src/components/router.tsx +0 -175
- package/src/components/save-button.tsx +0 -134
- package/src/components/sortable-list.tsx +0 -130
- package/src/components/tabs.tsx +0 -76
- package/src/components/tooltip.tsx +0 -43
- package/src/components/trust-level-badge.tsx +0 -44
- package/src/components/trust-level-dropdown.tsx +0 -136
- package/src/components/typeahead.tsx +0 -357
- package/src/globals-hash.test.ts +0 -19
- package/src/globals.tsx +0 -226
- package/src/hooks/index.ts +0 -8
- package/src/hooks/use-host-contract.ts +0 -75
- package/src/hooks/use-observable-state.test.tsx +0 -101
- package/src/hooks/use-observable-state.ts +0 -29
- package/src/hooks/use-observable.test.tsx +0 -258
- package/src/hooks/use-observable.ts +0 -67
- package/src/hooks/use-on-screen.ts +0 -24
- package/src/hooks/use-promise.ts +0 -34
- package/src/hooks/use-rows.test.tsx +0 -196
- package/src/hooks/use-rows.ts +0 -120
- package/src/hooks/use-subscription.ts +0 -24
- package/src/hooks/use-tool.test.tsx +0 -225
- package/src/hooks/use-tool.ts +0 -116
- package/src/host-shell/host-shell-consumer.test.ts +0 -32
- package/src/host-shell/host-shell-consumer.ts +0 -53
- package/src/index.tsx +0 -42
- package/src/mention-configs.ts +0 -185
- package/src/operator-console/operator-console-state.ts +0 -119
- package/src/operator-console/operator-console.tsx +0 -233
- package/src/peers-services-registration.ts +0 -6
- package/src/root-layout/global-overlays.ts +0 -50
- package/src/root-layout/layout-picker.tsx +0 -47
- package/src/root-layout/layouts/full-screen-layout.tsx +0 -144
- package/src/root-layout/layouts/tabs-with-console-layout.tsx +0 -260
- package/src/root-layout/root-layout-host.test.tsx +0 -108
- package/src/root-layout/root-layout-host.tsx +0 -147
- package/src/root-layout/root-layout-registry.ts +0 -51
- package/src/root-layout/root-layout-state.ts +0 -55
- package/src/root-layout/root-layout.ts +0 -32
- package/src/screens/account/account-screen.test.tsx +0 -65
- package/src/screens/account/account-screen.tsx +0 -942
- package/src/screens/assistants/assistant-config.test.tsx +0 -54
- package/src/screens/assistants/assistant-config.tsx +0 -121
- package/src/screens/assistants/assistant-details.tsx +0 -89
- package/src/screens/assistants/assistant-info.tsx +0 -66
- package/src/screens/assistants/assistant-list.tsx +0 -145
- package/src/screens/assistants/assistant-tools.tsx +0 -82
- package/src/screens/console-logs/console-logs-list.tsx +0 -374
- package/src/screens/console-logs/log-display.tsx +0 -137
- package/src/screens/console-logs/log-filters.tsx +0 -64
- package/src/screens/console-logs/mobile-log-card.tsx +0 -161
- package/src/screens/console-logs/resizable-table-header.tsx +0 -110
- package/src/screens/contacts/contact-details.tsx +0 -123
- package/src/screens/contacts/contact-list.test.tsx +0 -59
- package/src/screens/contacts/contact-list.tsx +0 -286
- package/src/screens/contacts/index.ts +0 -2
- package/src/screens/data-explorer/data-explorer.tsx +0 -633
- package/src/screens/data-explorer/index.ts +0 -6
- package/src/screens/data-explorer/query-executor.tsx +0 -520
- package/src/screens/device-pairing/device-pairing.test.tsx +0 -143
- package/src/screens/device-pairing/device-pairing.tsx +0 -461
- package/src/screens/device-pairing/identity-ipc.ts +0 -25
- package/src/screens/device-pairing/index.ts +0 -2
- package/src/screens/device-pairing/use-device-pairing-state.ts +0 -15
- package/src/screens/devices/devices-list.test.tsx +0 -68
- package/src/screens/devices/devices-list.tsx +0 -365
- package/src/screens/devices/index.ts +0 -1
- package/src/screens/groups/group-details.tsx +0 -160
- package/src/screens/groups/group-invite-panel.tsx +0 -311
- package/src/screens/groups/group-list.test.tsx +0 -44
- package/src/screens/groups/group-list.tsx +0 -317
- package/src/screens/groups/group-members.tsx +0 -343
- package/src/screens/groups/index.ts +0 -3
- package/src/screens/identity/identity-routes.test.ts +0 -70
- package/src/screens/identity/identity-routes.ts +0 -301
- package/src/screens/identity/identity-screen.test.tsx +0 -138
- package/src/screens/identity/identity-screen.tsx +0 -282
- package/src/screens/identity/index.ts +0 -2
- package/src/screens/identity/invite-contact-panel.tsx +0 -45
- package/src/screens/identity/profile-invite.tsx +0 -93
- package/src/screens/invites/accept-invite.test.tsx +0 -115
- package/src/screens/invites/accept-invite.tsx +0 -318
- package/src/screens/invites/activity-view.test.tsx +0 -127
- package/src/screens/invites/activity-view.tsx +0 -162
- package/src/screens/invites/index.ts +0 -6
- package/src/screens/invites/invite-capture.ts +0 -104
- package/src/screens/invites/invite-classify.test.ts +0 -129
- package/src/screens/invites/invite-share.tsx +0 -104
- package/src/screens/invites/invites-ipc.ts +0 -25
- package/src/screens/invites/pending-invites-list.tsx +0 -256
- package/src/screens/network-viewer/connection-troubleshooter.tsx +0 -395
- package/src/screens/network-viewer/cpu-usage-graph.tsx +0 -294
- package/src/screens/network-viewer/device-details-modal.tsx +0 -339
- package/src/screens/network-viewer/group-details-modal.tsx +0 -421
- package/src/screens/network-viewer/index.ts +0 -8
- package/src/screens/network-viewer/network-viewer-ipc.test.ts +0 -72
- package/src/screens/network-viewer/network-viewer-ipc.ts +0 -39
- package/src/screens/network-viewer/network-viewer-section.ts +0 -12
- package/src/screens/network-viewer/network-viewer.section.test.tsx +0 -68
- package/src/screens/network-viewer/network-viewer.tsx +0 -708
- package/src/screens/network-viewer/remote-logs-panel.tsx +0 -190
- package/src/screens/network-viewer/sync-recovery.test.tsx +0 -114
- package/src/screens/network-viewer/sync-recovery.tsx +0 -461
- package/src/screens/network-viewer/usage-graph.tsx +0 -455
- package/src/screens/packages/local-folder-grants-panel.tsx +0 -290
- package/src/screens/packages/local-folders-ipc.ts +0 -28
- package/src/screens/packages/package-details.tsx +0 -166
- package/src/screens/packages/package-helpers.test.ts +0 -57
- package/src/screens/packages/package-helpers.ts +0 -137
- package/src/screens/packages/package-info.tsx +0 -354
- package/src/screens/packages/package-list.tsx +0 -519
- package/src/screens/packages/package-network-panel.tsx +0 -82
- package/src/screens/packages/package-new-local.tsx +0 -100
- package/src/screens/packages/package-runtime-status.test.tsx +0 -58
- package/src/screens/packages/package-runtime-status.tsx +0 -68
- package/src/screens/packages/package-versions.tsx +0 -298
- package/src/screens/packages/packages-ipc.test.ts +0 -47
- package/src/screens/packages/packages-ipc.ts +0 -125
- package/src/screens/peer-types/peer-type-details.tsx +0 -172
- package/src/screens/peer-types/peer-type-list.tsx +0 -64
- package/src/screens/search/global-search.tsx +0 -406
- package/src/screens/settings/color-mode-dropdown.tsx +0 -82
- package/src/screens/settings/settings-page.test.tsx +0 -24
- package/src/screens/settings/settings-page.tsx +0 -426
- package/src/screens/setup-user.tsx +0 -355
- package/src/screens/tools/tool-access-ipc.test.ts +0 -55
- package/src/screens/tools/tool-access-ipc.ts +0 -27
- package/src/screens/tools/tool-catalog-ipc.test.ts +0 -52
- package/src/screens/tools/tool-catalog-ipc.ts +0 -51
- package/src/screens/tools/tool-details.tsx +0 -52
- package/src/screens/tools/tool-info.tsx +0 -45
- package/src/screens/tools/tool-list.tsx +0 -106
- package/src/screens/tools/tool-schema.tsx +0 -44
- package/src/screens/tools/tool-test-details.tsx +0 -89
- package/src/screens/tools/tool-test-list.tsx +0 -73
- package/src/screens/variables/variable-details.tsx +0 -289
- package/src/screens/variables/variable-list.tsx +0 -110
- package/src/screens/welcome-modal.tsx +0 -294
- package/src/screens/workflows/workflow-details.tsx +0 -115
- package/src/screens/workflows/workflow-info.tsx +0 -22
- package/src/screens/workflows/workflow-instructions.tsx +0 -134
- package/src/screens/workflows/workflow-list.tsx +0 -117
- package/src/setupTests.ts +0 -38
- package/src/system-apps/assistants.app.ts +0 -7
- package/src/system-apps/console-logs.app.ts +0 -7
- package/src/system-apps/data-explorer.app.ts +0 -8
- package/src/system-apps/identity.app.ts +0 -9
- package/src/system-apps/index.ts +0 -77
- package/src/system-apps/mobile-settings.app.ts +0 -7
- package/src/system-apps/network-viewer.app.ts +0 -8
- package/src/system-apps/packages.app.ts +0 -7
- package/src/system-apps/search.app.ts +0 -8
- package/src/system-apps/settings.app.ts +0 -7
- package/src/system-apps/threads.app.ts +0 -7
- package/src/system-apps/tools.app.ts +0 -7
- package/src/system-apps/types.app.ts +0 -7
- package/src/system-apps/variables.app.ts +0 -7
- package/src/system-apps/workflows.app.ts +0 -7
- package/src/tabs-layout/network-status-indicator.test.tsx +0 -799
- package/src/tabs-layout/network-status-indicator.tsx +0 -756
- package/src/tabs-layout/tabs-layout.tsx +0 -857
- package/src/tabs-layout/tabs-state.test.ts +0 -152
- package/src/tabs-layout/tabs-state.ts +0 -587
- package/src/tabs-layout/use-network-status.test.tsx +0 -58
- package/src/tabs-layout/use-network-status.ts +0 -68
- package/src/ui-defaults/index.ts +0 -2
- package/src/ui-defaults/list-screen.tsx +0 -94
- package/src/ui-defaults/markdown-field.tsx +0 -87
- package/src/ui-router/routes-loader.ts +0 -193
- package/src/ui-router/ui-loader.test.tsx +0 -108
- package/src/ui-router/ui-loader.tsx +0 -606
- package/src/utils.ts +0 -95
- package/tsconfig.json +0 -18
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import type { IMentionData } from "@peers-app/peers-sdk";
|
|
2
|
-
import {
|
|
3
|
-
$applyNodeReplacement,
|
|
4
|
-
type DOMConversionMap,
|
|
5
|
-
type DOMConversionOutput,
|
|
6
|
-
type DOMExportOutput,
|
|
7
|
-
type EditorConfig,
|
|
8
|
-
type LexicalNode,
|
|
9
|
-
type NodeKey,
|
|
10
|
-
type SerializedTextNode,
|
|
11
|
-
type Spread,
|
|
12
|
-
TextNode,
|
|
13
|
-
} from "lexical";
|
|
14
|
-
import { mainContentPath } from "../../globals";
|
|
15
|
-
import { mentionConfigs } from "../../mention-configs";
|
|
16
|
-
|
|
17
|
-
/** Serialized Lexical payload for a Peers mention node. */
|
|
18
|
-
export type SerializedMentionNode = Spread<
|
|
19
|
-
{
|
|
20
|
-
data: IMentionData;
|
|
21
|
-
},
|
|
22
|
-
SerializedTextNode
|
|
23
|
-
>;
|
|
24
|
-
|
|
25
|
-
function $convertMentionElement(domNode: HTMLElement): DOMConversionOutput | null {
|
|
26
|
-
const mentionName = domNode.textContent?.substring(1);
|
|
27
|
-
const dataKind = domNode.getAttribute("data-kind") ?? "";
|
|
28
|
-
const dataId = domNode.getAttribute("data-id") ?? "";
|
|
29
|
-
const clickable = domNode.getAttribute("data-clickable");
|
|
30
|
-
|
|
31
|
-
if (mentionName && dataId) {
|
|
32
|
-
const data: IMentionData = {
|
|
33
|
-
kind: dataKind,
|
|
34
|
-
name: mentionName,
|
|
35
|
-
id: dataId,
|
|
36
|
-
clickable: clickable === "true" ? true : clickable === "false" ? false : undefined,
|
|
37
|
-
};
|
|
38
|
-
const node = $createMentionNode(data);
|
|
39
|
-
return {
|
|
40
|
-
node,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Lexical text entity that renders and navigates a typed Peers mention. */
|
|
48
|
-
export class MentionNode extends TextNode {
|
|
49
|
-
static getType(): string {
|
|
50
|
-
return "mention";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static clone(node: MentionNode): MentionNode {
|
|
54
|
-
return new MentionNode(node.data, node.__key);
|
|
55
|
-
}
|
|
56
|
-
static importJSON(serializedNode: SerializedMentionNode): MentionNode {
|
|
57
|
-
const node = $createMentionNode(serializedNode.data);
|
|
58
|
-
// node.setTextContent('@' + serializedNode.text);
|
|
59
|
-
node.setTextContent(serializedNode.text);
|
|
60
|
-
node.setFormat(serializedNode.format);
|
|
61
|
-
node.setDetail(serializedNode.detail);
|
|
62
|
-
node.setMode(serializedNode.mode);
|
|
63
|
-
node.setStyle(serializedNode.style);
|
|
64
|
-
return node;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
constructor(
|
|
68
|
-
public readonly data: IMentionData,
|
|
69
|
-
key?: NodeKey,
|
|
70
|
-
) {
|
|
71
|
-
// const prefix = (data.kind === 'assistant' || data.kind === 'user') ? '@' : '$';
|
|
72
|
-
const prefix = data.kind === "user" ? "@" : "";
|
|
73
|
-
super(prefix + data.name, key);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
exportJSON(): SerializedMentionNode {
|
|
77
|
-
return {
|
|
78
|
-
...super.exportJSON(),
|
|
79
|
-
type: "mention",
|
|
80
|
-
version: 1,
|
|
81
|
-
data: this.data,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
createDOM(config: EditorConfig): HTMLElement {
|
|
86
|
-
const dom = super.createDOM(config);
|
|
87
|
-
|
|
88
|
-
const kind = this.data.kind;
|
|
89
|
-
const mentionConfig = mentionConfigs.find((c) => c.kind === kind);
|
|
90
|
-
|
|
91
|
-
if (mentionConfig) {
|
|
92
|
-
dom.className = mentionConfig.styleClass || "mention-default-default";
|
|
93
|
-
} else {
|
|
94
|
-
dom.className = `mention-${this.data.kind}`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
dom.textContent = this.__text;
|
|
98
|
-
dom.setAttribute("data-kind", this.data.kind);
|
|
99
|
-
dom.setAttribute("data-id", this.data.id);
|
|
100
|
-
dom.setAttribute(
|
|
101
|
-
"data-clickable",
|
|
102
|
-
this.data.clickable === undefined ? "" : String(this.data.clickable),
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
// currently ignoring `clickable` attribute
|
|
106
|
-
// if (this.data.clickable !== false) {...
|
|
107
|
-
const onClick = mentionConfig?.onClick;
|
|
108
|
-
dom.style.cursor = "pointer";
|
|
109
|
-
dom.addEventListener("click", () => {
|
|
110
|
-
if (onClick) {
|
|
111
|
-
onClick(this.data);
|
|
112
|
-
} else {
|
|
113
|
-
const id = this.data.id;
|
|
114
|
-
const href = kind === "user" ? `identity/people/${id}` : `${kind}s/${id}`;
|
|
115
|
-
mainContentPath(href);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
if (mentionConfig && kind !== "user") {
|
|
120
|
-
const iconSpan = document.createElement("i");
|
|
121
|
-
iconSpan.className = `pe-1 ${mentionConfig.iconClass}`;
|
|
122
|
-
dom.prepend(iconSpan);
|
|
123
|
-
return dom;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// else if (kind === 'task') {
|
|
127
|
-
// const ckbx = document.createElement('input');
|
|
128
|
-
// ckbx.type = 'checkbox';
|
|
129
|
-
// ckbx.className = 'me-1';
|
|
130
|
-
// const taskId = this.data.id;
|
|
131
|
-
// Tasks().get(taskId).then(task => {
|
|
132
|
-
// if (!task) return;
|
|
133
|
-
// ckbx.checked = !!task.completeDT;
|
|
134
|
-
// ckbx.addEventListener('change', () => {
|
|
135
|
-
// task.completeDT = ckbx.checked ? new Date() : undefined;
|
|
136
|
-
// Tasks().update(task);
|
|
137
|
-
// });
|
|
138
|
-
// });
|
|
139
|
-
// const sub = Tasks().dataChanged.subscribe(evt => {
|
|
140
|
-
// const task = evt.dataObject as ITask;
|
|
141
|
-
// if (!task || task.taskId !== taskId) return;
|
|
142
|
-
// if (!document.body.contains(ckbx)) {
|
|
143
|
-
// sub.unsubscribe();
|
|
144
|
-
// } else {
|
|
145
|
-
// ckbx.checked = !!task.completeDT;
|
|
146
|
-
// }
|
|
147
|
-
// });
|
|
148
|
-
// dom.prepend(ckbx);
|
|
149
|
-
// }
|
|
150
|
-
|
|
151
|
-
return dom;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
exportDOM(): DOMExportOutput {
|
|
155
|
-
const element = document.createElement("span");
|
|
156
|
-
element.setAttribute("data-lexical-mention", "true");
|
|
157
|
-
element.textContent = this.__text;
|
|
158
|
-
element.setAttribute("data-kind", this.data.kind);
|
|
159
|
-
element.setAttribute("data-id", this.data.id);
|
|
160
|
-
element.setAttribute(
|
|
161
|
-
"data-clickable",
|
|
162
|
-
this.data.clickable === undefined ? "" : String(this.data.clickable),
|
|
163
|
-
);
|
|
164
|
-
return { element };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
static importDOM(): DOMConversionMap | null {
|
|
168
|
-
return {
|
|
169
|
-
span: (domNode: HTMLElement) => {
|
|
170
|
-
if (!domNode.hasAttribute("data-lexical-mention")) {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
conversion: $convertMentionElement,
|
|
175
|
-
priority: 1,
|
|
176
|
-
};
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
isTextEntity(): true {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
canInsertTextBefore(): boolean {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
canInsertTextAfter(): boolean {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** Create a segmented Lexical mention node from mention data. */
|
|
195
|
-
export function $createMentionNode(data: IMentionData): MentionNode {
|
|
196
|
-
const mentionNode = new MentionNode(data);
|
|
197
|
-
mentionNode.setMode("segmented").toggleDirectionless();
|
|
198
|
-
return $applyNodeReplacement(mentionNode);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/** Return whether a Lexical node is a {@link MentionNode}. */
|
|
202
|
-
export function $isMentionNode(node: LexicalNode | null | undefined): node is MentionNode {
|
|
203
|
-
return node instanceof MentionNode;
|
|
204
|
-
}
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
2
|
-
import {
|
|
3
|
-
LexicalTypeaheadMenuPlugin,
|
|
4
|
-
MenuOption,
|
|
5
|
-
type MenuTextMatch,
|
|
6
|
-
useBasicTypeaheadTriggerMatch,
|
|
7
|
-
} from "@lexical/react/LexicalTypeaheadMenuPlugin";
|
|
8
|
-
import { type IMentionData, type Observable, observable } from "@peers-app/peers-sdk";
|
|
9
|
-
import { $getSelection, type TextNode } from "lexical";
|
|
10
|
-
import { sortBy, uniqBy } from "lodash";
|
|
11
|
-
import * as React from "react";
|
|
12
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
13
|
-
import * as ReactDOM from "react-dom";
|
|
14
|
-
import type { IMentionConfig } from "../../mention-configs";
|
|
15
|
-
import { $createMentionNode } from "./mention-node";
|
|
16
|
-
|
|
17
|
-
const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
|
|
18
|
-
const NAME = `\\b[A-Z][^\\s${PUNCTUATION}]`;
|
|
19
|
-
|
|
20
|
-
const DocumentMentionsRegex = {
|
|
21
|
-
NAME,
|
|
22
|
-
PUNCTUATION,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const PUNC = DocumentMentionsRegex.PUNCTUATION;
|
|
26
|
-
|
|
27
|
-
const TRIGGERS = ["@", "<"].join("");
|
|
28
|
-
|
|
29
|
-
// Chars we expect to see in a mention (non-space, non-punctuation).
|
|
30
|
-
const VALID_CHARS = `[^${TRIGGERS}${PUNC}\\s]`;
|
|
31
|
-
|
|
32
|
-
// Non-standard series of chars. Each series must be preceded and followed by
|
|
33
|
-
// a valid char.
|
|
34
|
-
const VALID_JOINS =
|
|
35
|
-
"(?:" +
|
|
36
|
-
"\\.[ |$]|" + // E.g. "r. " in "Mr. Smith"
|
|
37
|
-
" |" + // E.g. " " in "Josh Duck"
|
|
38
|
-
"[" +
|
|
39
|
-
PUNC +
|
|
40
|
-
"]|" + // E.g. "-' in "Salier-Hellendag"
|
|
41
|
-
")";
|
|
42
|
-
|
|
43
|
-
const LENGTH_LIMIT = 75;
|
|
44
|
-
|
|
45
|
-
const AtSignMentionsRegex = new RegExp(
|
|
46
|
-
"(^|\\s|\\()(" +
|
|
47
|
-
"[" +
|
|
48
|
-
TRIGGERS +
|
|
49
|
-
"]" +
|
|
50
|
-
"((?:" +
|
|
51
|
-
VALID_CHARS +
|
|
52
|
-
VALID_JOINS +
|
|
53
|
-
"){0," +
|
|
54
|
-
LENGTH_LIMIT +
|
|
55
|
-
"})" +
|
|
56
|
-
")$",
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
// 50 is the longest alias length limit.
|
|
60
|
-
const ALIAS_LENGTH_LIMIT = 50;
|
|
61
|
-
|
|
62
|
-
// Regex used to match alias.
|
|
63
|
-
const AtSignMentionsRegexAliasRegex = new RegExp(
|
|
64
|
-
"(^|\\s|\\()(" +
|
|
65
|
-
"[" +
|
|
66
|
-
TRIGGERS +
|
|
67
|
-
"]" +
|
|
68
|
-
"((?:" +
|
|
69
|
-
VALID_CHARS +
|
|
70
|
-
"){0," +
|
|
71
|
-
ALIAS_LENGTH_LIMIT +
|
|
72
|
-
"})" +
|
|
73
|
-
")$",
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// At most, 5 suggestions are shown in the popup.
|
|
77
|
-
const SUGGESTION_LIST_LENGTH_LIMIT = 10;
|
|
78
|
-
export const MENTIONS_MAX_RESULTS = 10;
|
|
79
|
-
|
|
80
|
-
function useMentionLookupService(
|
|
81
|
-
mentionString: string | null,
|
|
82
|
-
mentionConfigs: IMentionConfig[] = [],
|
|
83
|
-
): IMentionData[] {
|
|
84
|
-
const [results, setResults] = useState<Array<IMentionData>>([]);
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (!mentionString) {
|
|
88
|
-
setResults([]);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
(async () => {
|
|
92
|
-
const prefix = mentionString[0];
|
|
93
|
-
mentionString = mentionString.slice(1);
|
|
94
|
-
// TODO simplify how users can include completed tasks in their search
|
|
95
|
-
const searchCompletedTasks = prefix === "$" && mentionString.startsWith("done");
|
|
96
|
-
if (searchCompletedTasks) {
|
|
97
|
-
mentionString = mentionString.slice(4);
|
|
98
|
-
}
|
|
99
|
-
let kind = "";
|
|
100
|
-
if (mentionString.includes(":")) {
|
|
101
|
-
const parts = mentionString.split(":");
|
|
102
|
-
kind = parts[0];
|
|
103
|
-
mentionString = parts[1] || "";
|
|
104
|
-
}
|
|
105
|
-
const config = mentionConfigs?.find((c) => c.kind === kind);
|
|
106
|
-
if (config) {
|
|
107
|
-
const results = await config.query(mentionString);
|
|
108
|
-
setResults(results);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const results = await Promise.all(mentionConfigs?.map((c) => c.query(mentionString || "")));
|
|
112
|
-
let allResults = results.flat();
|
|
113
|
-
allResults = uniqBy(allResults, "id");
|
|
114
|
-
let filteredResults = allResults;
|
|
115
|
-
if (prefix === "@") {
|
|
116
|
-
filteredResults = filteredResults.filter(
|
|
117
|
-
(result) => result.kind === "user" || result.kind === "assistant",
|
|
118
|
-
);
|
|
119
|
-
} else {
|
|
120
|
-
filteredResults = filteredResults.filter(
|
|
121
|
-
(result) => result.kind !== "user" && result.kind !== "assistant",
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
if (kind) {
|
|
125
|
-
filteredResults = allResults.filter(
|
|
126
|
-
(result) => result.kind.toLowerCase() === kind.toLowerCase(),
|
|
127
|
-
);
|
|
128
|
-
} else if (!filteredResults.length) {
|
|
129
|
-
filteredResults = allResults;
|
|
130
|
-
}
|
|
131
|
-
filteredResults = sortBy(filteredResults, (r) => {
|
|
132
|
-
return r.name.toLowerCase().indexOf((mentionString ?? "").toLowerCase());
|
|
133
|
-
});
|
|
134
|
-
filteredResults = filteredResults.slice(0, SUGGESTION_LIST_LENGTH_LIMIT);
|
|
135
|
-
setResults(filteredResults);
|
|
136
|
-
})();
|
|
137
|
-
}, [mentionString, mentionConfigs?.find, mentionConfigs?.map]);
|
|
138
|
-
|
|
139
|
-
return results;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function checkForAtSignMentions(text: string, minMatchLength: number): MenuTextMatch | null {
|
|
143
|
-
let match = AtSignMentionsRegex.exec(text);
|
|
144
|
-
|
|
145
|
-
if (match === null) {
|
|
146
|
-
match = AtSignMentionsRegexAliasRegex.exec(text);
|
|
147
|
-
}
|
|
148
|
-
if (match !== null) {
|
|
149
|
-
// The strategy ignores leading whitespace but we need to know it's
|
|
150
|
-
// length to add it to the leadOffset
|
|
151
|
-
const maybeLeadingWhitespace = match[1];
|
|
152
|
-
|
|
153
|
-
const matchingString = match[3];
|
|
154
|
-
if (matchingString.length >= minMatchLength) {
|
|
155
|
-
return {
|
|
156
|
-
leadOffset: match.index + maybeLeadingWhitespace.length,
|
|
157
|
-
matchingString: match[2],
|
|
158
|
-
replaceableString: match[2],
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getPossibleQueryMatch(text: string): MenuTextMatch | null {
|
|
166
|
-
return checkForAtSignMentions(text, 1);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
class MentionTypeaheadOption extends MenuOption {
|
|
170
|
-
name: string;
|
|
171
|
-
picture: JSX.Element;
|
|
172
|
-
id: string;
|
|
173
|
-
userId?: string;
|
|
174
|
-
|
|
175
|
-
constructor(
|
|
176
|
-
public readonly data: IMentionData,
|
|
177
|
-
picture: JSX.Element,
|
|
178
|
-
) {
|
|
179
|
-
super(data.name);
|
|
180
|
-
this.name = data.name;
|
|
181
|
-
this.picture = picture;
|
|
182
|
-
this.id = data.id;
|
|
183
|
-
// if (data.kind === 'assistant') {
|
|
184
|
-
// this.userId = data.userId;
|
|
185
|
-
// }
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function MentionsTypeaheadMenuItem({
|
|
190
|
-
index,
|
|
191
|
-
isSelected,
|
|
192
|
-
onClick,
|
|
193
|
-
onMouseEnter,
|
|
194
|
-
option,
|
|
195
|
-
}: {
|
|
196
|
-
index: number;
|
|
197
|
-
isSelected: boolean;
|
|
198
|
-
onClick: () => void;
|
|
199
|
-
onMouseEnter: () => void;
|
|
200
|
-
option: MentionTypeaheadOption;
|
|
201
|
-
}) {
|
|
202
|
-
let className = "item";
|
|
203
|
-
if (isSelected) {
|
|
204
|
-
className += " selected";
|
|
205
|
-
}
|
|
206
|
-
return (
|
|
207
|
-
<li
|
|
208
|
-
key={option.key}
|
|
209
|
-
tabIndex={-1}
|
|
210
|
-
className={className}
|
|
211
|
-
ref={option.setRefElement}
|
|
212
|
-
aria-selected={isSelected}
|
|
213
|
-
id={`typeahead-item-${index}`}
|
|
214
|
-
onMouseEnter={onMouseEnter}
|
|
215
|
-
onClick={onClick}
|
|
216
|
-
data-kind={option.data.kind}
|
|
217
|
-
data-id={option.id}
|
|
218
|
-
data-user-id={option.userId || undefined}
|
|
219
|
-
>
|
|
220
|
-
{option.picture}
|
|
221
|
-
<span className="text">{option.name}</span>
|
|
222
|
-
</li>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function MentionsPlugin(props: {
|
|
227
|
-
mentionConfigs?: IMentionConfig[];
|
|
228
|
-
mentionsOpen?: Observable<boolean>;
|
|
229
|
-
}): JSX.Element | null {
|
|
230
|
-
const [editor] = useLexicalComposerContext();
|
|
231
|
-
|
|
232
|
-
const [queryString, setQueryString] = useState<string | null>(null);
|
|
233
|
-
const results = useMentionLookupService(queryString, props.mentionConfigs);
|
|
234
|
-
const [_mentionsOpen] = useState(() => observable(false));
|
|
235
|
-
|
|
236
|
-
if (props.mentionsOpen) {
|
|
237
|
-
const finalMentionsOpen = _mentionsOpen() && results.length > 0;
|
|
238
|
-
if (props.mentionsOpen() !== finalMentionsOpen) {
|
|
239
|
-
props.mentionsOpen(finalMentionsOpen);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const checkForSlashTriggerMatch = useBasicTypeaheadTriggerMatch("/", {
|
|
244
|
-
minLength: 0,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const options = useMemo(
|
|
248
|
-
() =>
|
|
249
|
-
results
|
|
250
|
-
.map((result) => {
|
|
251
|
-
const picKey = `mention-pic-${result.kind}-${result.id}`;
|
|
252
|
-
let picture = <i key={picKey} className="bi bi-question pe-1" />;
|
|
253
|
-
const config = props.mentionConfigs?.find((c) => c.kind === result.kind);
|
|
254
|
-
if (config) {
|
|
255
|
-
if (config.picture) {
|
|
256
|
-
picture = config.picture(result);
|
|
257
|
-
} else {
|
|
258
|
-
picture = <i key={picKey} className={`${config.iconClass} pe-1`} />;
|
|
259
|
-
}
|
|
260
|
-
} else {
|
|
261
|
-
picture = <i key={picKey} className={"bi bi-question pe-1"} />;
|
|
262
|
-
}
|
|
263
|
-
return new MentionTypeaheadOption(result, picture);
|
|
264
|
-
})
|
|
265
|
-
.slice(0, SUGGESTION_LIST_LENGTH_LIMIT),
|
|
266
|
-
[results, props.mentionConfigs?.find],
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
const onSelectOption = useCallback(
|
|
270
|
-
(
|
|
271
|
-
selectedOption: MentionTypeaheadOption,
|
|
272
|
-
nodeToReplace: TextNode | null,
|
|
273
|
-
closeMenu: () => void,
|
|
274
|
-
) => {
|
|
275
|
-
editor.update(() => {
|
|
276
|
-
const mentionNode = $createMentionNode(selectedOption.data);
|
|
277
|
-
if (nodeToReplace) {
|
|
278
|
-
nodeToReplace.replace(mentionNode);
|
|
279
|
-
}
|
|
280
|
-
mentionNode.selectNext(); // Move cursor to the position after the mention
|
|
281
|
-
const selection = $getSelection();
|
|
282
|
-
if (selection !== null) {
|
|
283
|
-
selection.insertText(" "); // Insert a space after the mention
|
|
284
|
-
}
|
|
285
|
-
closeMenu();
|
|
286
|
-
});
|
|
287
|
-
},
|
|
288
|
-
[editor],
|
|
289
|
-
);
|
|
290
|
-
|
|
291
|
-
const checkForMentionMatch = useCallback(
|
|
292
|
-
(text: string) => {
|
|
293
|
-
const slashMatch = checkForSlashTriggerMatch(text, editor);
|
|
294
|
-
if (slashMatch !== null) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
return getPossibleQueryMatch(text);
|
|
298
|
-
},
|
|
299
|
-
[checkForSlashTriggerMatch, editor],
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
const _popoverRef = React.useRef<HTMLDivElement>(null);
|
|
303
|
-
|
|
304
|
-
return (
|
|
305
|
-
<LexicalTypeaheadMenuPlugin<MentionTypeaheadOption>
|
|
306
|
-
onQueryChange={setQueryString}
|
|
307
|
-
onSelectOption={onSelectOption}
|
|
308
|
-
triggerFn={checkForMentionMatch}
|
|
309
|
-
options={options}
|
|
310
|
-
onOpen={() => _mentionsOpen(true)}
|
|
311
|
-
onClose={() => _mentionsOpen(false)}
|
|
312
|
-
menuRenderFn={(
|
|
313
|
-
anchorElementRef,
|
|
314
|
-
{ selectedIndex, selectOptionAndCleanUp, setHighlightedIndex },
|
|
315
|
-
) => {
|
|
316
|
-
if (!(anchorElementRef.current && results.length)) {
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// distance from the top of the viewport to the top of the anchor element
|
|
321
|
-
const anchorTop = anchorElementRef.current.getBoundingClientRect().top;
|
|
322
|
-
const viewportHeight = window.innerHeight;
|
|
323
|
-
|
|
324
|
-
let className = "typeahead-popover mentions-menu";
|
|
325
|
-
if (anchorTop > viewportHeight / 2) {
|
|
326
|
-
className += " mentions-menu-popup";
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return ReactDOM.createPortal(
|
|
330
|
-
<div className={className}>
|
|
331
|
-
<ul>
|
|
332
|
-
{options.map((option, i: number) => (
|
|
333
|
-
<MentionsTypeaheadMenuItem
|
|
334
|
-
index={i}
|
|
335
|
-
isSelected={selectedIndex === i}
|
|
336
|
-
onClick={() => {
|
|
337
|
-
setHighlightedIndex(i);
|
|
338
|
-
selectOptionAndCleanUp(option);
|
|
339
|
-
}}
|
|
340
|
-
onMouseEnter={() => {
|
|
341
|
-
setHighlightedIndex(i);
|
|
342
|
-
}}
|
|
343
|
-
key={option.key}
|
|
344
|
-
option={option}
|
|
345
|
-
/>
|
|
346
|
-
))}
|
|
347
|
-
</ul>
|
|
348
|
-
</div>,
|
|
349
|
-
anchorElementRef.current,
|
|
350
|
-
);
|
|
351
|
-
}}
|
|
352
|
-
/>
|
|
353
|
-
);
|
|
354
|
-
}
|