@peers-app/peers-ui 0.33.6 → 0.33.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.
- package/dist/components/markdown-editor/editor.d.ts +40 -3
- package/dist/components/markdown-editor/editor.js +8 -3
- package/dist/components/markdown-editor/markdown-plugin.d.ts +4 -1
- package/dist/components/markdown-editor/markdown-plugin.js +32 -20
- package/dist/components/markdown-editor/mention-node.d.ts +28 -15
- package/dist/components/markdown-editor/mention-node.js +75 -129
- package/dist/components/markdown-editor/mention-preview-card.d.ts +13 -0
- package/dist/components/markdown-editor/mention-preview-card.js +30 -0
- package/dist/components/markdown-editor/mentions-plugin.d.ts +43 -4
- package/dist/components/markdown-editor/mentions-plugin.js +211 -107
- package/dist/components/markdown-editor/selection-effects-plugin.d.ts +18 -0
- package/dist/components/markdown-editor/selection-effects-plugin.js +49 -0
- package/dist/components/markdown-with-mentions.d.ts +12 -2
- package/dist/components/markdown-with-mentions.js +110 -110
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1
- package/dist/mentions/mention-chip.d.ts +33 -0
- package/dist/mentions/mention-chip.js +76 -0
- package/dist/mentions/mention-chooser.d.ts +9 -0
- package/dist/mentions/mention-chooser.js +51 -0
- package/dist/mentions/mentions-client.d.ts +47 -0
- package/dist/mentions/mentions-client.js +198 -0
- package/dist/notifications/notifications-client.d.ts +3 -3
- package/dist/notifications/notifications-client.js +6 -63
- package/dist/root-layout/root-layout-host.js +2 -2
- package/dist/theme.css +224 -0
- package/dist/ui-router/open-in-group.d.ts +17 -0
- package/dist/ui-router/open-in-group.js +81 -0
- package/dist/ui-router/routes-loader.js +46 -27
- package/dist/ui-router/runnable-version.js +2 -1
- package/package.json +4 -4
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mentionsRevision = exports.mentionsContract = void 0;
|
|
4
|
+
exports.searchMentions = searchMentions;
|
|
5
|
+
exports.activeGroupId = activeGroupId;
|
|
6
|
+
exports.cachedMentionPlace = cachedMentionPlace;
|
|
7
|
+
exports.resolveMentionPlace = resolveMentionPlace;
|
|
8
|
+
exports.openMentionPlace = openMentionPlace;
|
|
9
|
+
exports.openMention = openMention;
|
|
10
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
11
|
+
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
12
|
+
const open_in_group_1 = require("../ui-router/open-in-group");
|
|
13
|
+
const mention_chooser_1 = require("./mention-chooser");
|
|
14
|
+
/** Shared handle for System Mentions on the local host. */
|
|
15
|
+
exports.mentionsContract = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getMentionsContractDefinition)());
|
|
16
|
+
/**
|
|
17
|
+
* Find records to mention: people, and records packages declare, best first.
|
|
18
|
+
*
|
|
19
|
+
* @param input - The words, optional kinds, the document's group, and a limit.
|
|
20
|
+
*/
|
|
21
|
+
async function searchMentions(input) {
|
|
22
|
+
const consumer = await exports.mentionsContract.get();
|
|
23
|
+
return (await consumer.tools.search(input)).results;
|
|
24
|
+
}
|
|
25
|
+
/** The active group's id (the user's id for Personal). */
|
|
26
|
+
async function activeGroupId() {
|
|
27
|
+
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
28
|
+
return userContext.currentlyActiveGroupId() || userContext.userId;
|
|
29
|
+
}
|
|
30
|
+
// ---- Rendering: each ref's nearest place, batched and cached until System Mentions changes. ----
|
|
31
|
+
/**
|
|
32
|
+
* Moves whenever the cached places are dropped because a mentionable record may have changed;
|
|
33
|
+
* mounted chips resolve again.
|
|
34
|
+
*/
|
|
35
|
+
exports.mentionsRevision = (0, peers_sdk_1.observable)(0);
|
|
36
|
+
const cache = new Map();
|
|
37
|
+
const inFlight = new Map();
|
|
38
|
+
const queued = new Map();
|
|
39
|
+
let flushing;
|
|
40
|
+
let watching;
|
|
41
|
+
let watchingTransport = false;
|
|
42
|
+
const keyOf = (groupId, ref) => `${groupId}|${ref.kind}/${ref.id}`;
|
|
43
|
+
/**
|
|
44
|
+
* Drop every cached place, so mounted chips resolve again. A resolve already under way may carry
|
|
45
|
+
* the old answer, so it's forgotten too: the chips ask again. A ref still waiting for the next
|
|
46
|
+
* request is asked after the change, so chips asking again share it.
|
|
47
|
+
*/
|
|
48
|
+
function dropCache() {
|
|
49
|
+
cache.clear();
|
|
50
|
+
inFlight.clear();
|
|
51
|
+
for (const batch of queued.values()) {
|
|
52
|
+
for (const [key, item] of batch)
|
|
53
|
+
inFlight.set(key, item.promise);
|
|
54
|
+
}
|
|
55
|
+
(0, exports.mentionsRevision)((0, exports.mentionsRevision)() + 1);
|
|
56
|
+
}
|
|
57
|
+
function watchChanges() {
|
|
58
|
+
if (!watchingTransport) {
|
|
59
|
+
watchingTransport = true;
|
|
60
|
+
// A new host connection brings a new consumer: watch its `changes`, and resolve again.
|
|
61
|
+
(0, peers_sdk_1.subscribeHostContractTransport)((transport) => {
|
|
62
|
+
watching = undefined;
|
|
63
|
+
if (transport) {
|
|
64
|
+
dropCache();
|
|
65
|
+
watchChanges();
|
|
66
|
+
}
|
|
67
|
+
}, { emitCurrent: false });
|
|
68
|
+
}
|
|
69
|
+
if (watching)
|
|
70
|
+
return;
|
|
71
|
+
// A reconnect while this load is pending starts another; only the current one subscribes.
|
|
72
|
+
const attempt = exports.mentionsContract
|
|
73
|
+
.get()
|
|
74
|
+
.then((consumer) => {
|
|
75
|
+
if (watching !== attempt)
|
|
76
|
+
return;
|
|
77
|
+
const { changes } = consumer.observables;
|
|
78
|
+
let seen = changes();
|
|
79
|
+
changes.subscribe((value) => {
|
|
80
|
+
if (value === seen)
|
|
81
|
+
return;
|
|
82
|
+
seen = value;
|
|
83
|
+
dropCache();
|
|
84
|
+
});
|
|
85
|
+
})
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
if (watching === attempt)
|
|
88
|
+
watching = undefined;
|
|
89
|
+
console.warn("[mentions] couldn't watch for changes", error);
|
|
90
|
+
});
|
|
91
|
+
watching = attempt;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A mention's place if it's already cached: the place, `null` when it's known to be nowhere the
|
|
95
|
+
* user can read, or `undefined` when it hasn't been resolved since the last change.
|
|
96
|
+
*
|
|
97
|
+
* @param ref - The mention.
|
|
98
|
+
* @param groupId - The document's group, or `""` when it isn't known.
|
|
99
|
+
*/
|
|
100
|
+
function cachedMentionPlace(ref, groupId = "") {
|
|
101
|
+
return cache.get(keyOf(groupId, ref));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Where a mention is, for rendering it: the first place found, looking in the document's group
|
|
105
|
+
* first. `null` when it's nowhere the user can read. Calls made together go in one request.
|
|
106
|
+
*
|
|
107
|
+
* @param ref - The mention.
|
|
108
|
+
* @param groupId - The document's group, or `""` when it isn't known.
|
|
109
|
+
*/
|
|
110
|
+
function resolveMentionPlace(ref, groupId = "") {
|
|
111
|
+
watchChanges();
|
|
112
|
+
const key = keyOf(groupId, ref);
|
|
113
|
+
const cached = cache.get(key);
|
|
114
|
+
if (cached !== undefined)
|
|
115
|
+
return Promise.resolve(cached);
|
|
116
|
+
const pending = inFlight.get(key);
|
|
117
|
+
if (pending)
|
|
118
|
+
return pending;
|
|
119
|
+
let done = () => { };
|
|
120
|
+
const promise = new Promise((resolve) => {
|
|
121
|
+
done = resolve;
|
|
122
|
+
});
|
|
123
|
+
const batch = queued.get(groupId) ?? new Map();
|
|
124
|
+
batch.set(key, { ref, done, promise });
|
|
125
|
+
queued.set(groupId, batch);
|
|
126
|
+
inFlight.set(key, promise);
|
|
127
|
+
if (!flushing)
|
|
128
|
+
flushing = setTimeout(() => void flush(), 0);
|
|
129
|
+
return promise;
|
|
130
|
+
}
|
|
131
|
+
async function flush() {
|
|
132
|
+
flushing = undefined;
|
|
133
|
+
const batches = [...queued];
|
|
134
|
+
queued.clear();
|
|
135
|
+
const revision = (0, exports.mentionsRevision)();
|
|
136
|
+
await Promise.all(batches.map(async ([groupId, batch]) => {
|
|
137
|
+
const entries = [...batch];
|
|
138
|
+
for (let at = 0; at < entries.length; at += peers_sdk_1.MENTIONS_RESOLVE_MAX_REFS) {
|
|
139
|
+
const chunk = entries.slice(at, at + peers_sdk_1.MENTIONS_RESOLVE_MAX_REFS);
|
|
140
|
+
const finish = ([key, item], place, keep) => {
|
|
141
|
+
// A change since this resolve started has dropped it; a newer one may be under way.
|
|
142
|
+
if (inFlight.get(key) === item.promise)
|
|
143
|
+
inFlight.delete(key);
|
|
144
|
+
if (keep && (0, exports.mentionsRevision)() === revision)
|
|
145
|
+
cache.set(key, place);
|
|
146
|
+
item.done(place);
|
|
147
|
+
};
|
|
148
|
+
try {
|
|
149
|
+
const consumer = await exports.mentionsContract.get();
|
|
150
|
+
const { results } = await consumer.tools.resolve({
|
|
151
|
+
refs: chunk.map(([, item]) => item.ref),
|
|
152
|
+
...(groupId ? { groupId } : {}),
|
|
153
|
+
nearest: true,
|
|
154
|
+
});
|
|
155
|
+
for (const [index, entry] of chunk.entries()) {
|
|
156
|
+
finish(entry, results[index]?.places[0] ?? null, true);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.warn("[mentions] couldn't resolve mentions", error);
|
|
161
|
+
for (const entry of chunk)
|
|
162
|
+
finish(entry, null, false);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
// ---- Opening ----
|
|
168
|
+
/**
|
|
169
|
+
* Open a place: in its group ({@link openInGroup}), or in the current group for a record that
|
|
170
|
+
* opens anywhere (a person).
|
|
171
|
+
*
|
|
172
|
+
* @param place - Where the record is.
|
|
173
|
+
*/
|
|
174
|
+
async function openMentionPlace(place) {
|
|
175
|
+
if (!place.groupId) {
|
|
176
|
+
(0, tabs_state_1.goToTabPath)(place.route);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
await (0, open_in_group_1.openInGroup)(place.route, place.groupId);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Open a mentioned record: every group is checked, and when it's in more than one place the
|
|
183
|
+
* user picks one. Nothing opens when it's nowhere the user can read.
|
|
184
|
+
*
|
|
185
|
+
* @param ref - The mention.
|
|
186
|
+
* @param groupId - The document's group.
|
|
187
|
+
*/
|
|
188
|
+
async function openMention(ref, groupId) {
|
|
189
|
+
const consumer = await exports.mentionsContract.get();
|
|
190
|
+
const { results } = await consumer.tools.resolve({
|
|
191
|
+
refs: [ref],
|
|
192
|
+
...(groupId ? { groupId } : {}),
|
|
193
|
+
});
|
|
194
|
+
const places = results[0]?.places ?? [];
|
|
195
|
+
const place = places.length > 1 ? await (0, mention_chooser_1.chooseMentionPlace)(places) : places[0];
|
|
196
|
+
if (place)
|
|
197
|
+
await openMentionPlace(place);
|
|
198
|
+
}
|
|
@@ -61,16 +61,16 @@ export declare function withJustOpened(rows: INotification[], justOpened: IJustO
|
|
|
61
61
|
countdownUntil?: number;
|
|
62
62
|
}[];
|
|
63
63
|
/**
|
|
64
|
-
* Open what a notification is about: mark it opened, switch to its group, and go to its link
|
|
64
|
+
* Open what a notification is about: mark it opened, switch to its group, and go to its link
|
|
65
|
+
* ({@link openInGroup}).
|
|
65
66
|
*
|
|
66
67
|
* One without a link opens the Notifications screen in the current group (the screen lists every
|
|
67
68
|
* group's, and switching groups reloads the app, a second cold start on a phone), and stays in
|
|
68
69
|
* its Active list for {@link JUST_OPENED_MS}. A link to a screen that shows any group itself
|
|
69
70
|
* (its route's `opensAnyGroup`) opens in place too, with `groupId` added for the screen to read.
|
|
71
|
+
* One from a group the user has left opens the Notifications screen.
|
|
70
72
|
*/
|
|
71
73
|
export declare function openNotification(notification: INotification): Promise<void>;
|
|
72
|
-
/** Finish a notification's group switch after the new group's routes and tabs have loaded. */
|
|
73
|
-
export declare function resumeNotificationNavigation(): Promise<void>;
|
|
74
74
|
/** How long {@link openNotificationById} waits for a notification to sync in, and how often it looks. */
|
|
75
75
|
export declare const OPEN_NOTIFICATION_WAIT: {
|
|
76
76
|
totalMs: number;
|
|
@@ -7,21 +7,18 @@ exports.listNotifications = listNotifications;
|
|
|
7
7
|
exports.actOnNotifications = actOnNotifications;
|
|
8
8
|
exports.withJustOpened = withJustOpened;
|
|
9
9
|
exports.openNotification = openNotification;
|
|
10
|
-
exports.resumeNotificationNavigation = resumeNotificationNavigation;
|
|
11
10
|
exports.openNotificationById = openNotificationById;
|
|
12
11
|
exports.timeAgo = timeAgo;
|
|
13
12
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
14
13
|
const react_1 = require("react");
|
|
15
14
|
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
16
15
|
const use_observable_1 = require("../hooks/use-observable");
|
|
17
|
-
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
18
16
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
19
|
-
const
|
|
17
|
+
const open_in_group_1 = require("../ui-router/open-in-group");
|
|
20
18
|
/** Shared handle for System Notifications on the local host; stable for `useHostContract`. */
|
|
21
19
|
exports.notificationsContract = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getNotificationsContractDefinition)());
|
|
22
20
|
/** Route of the Notifications system app. */
|
|
23
21
|
exports.NOTIFICATIONS_PATH = "notifications";
|
|
24
|
-
const pendingNavigationKey = "peers.notificationNavigation";
|
|
25
22
|
const emptySummary = {
|
|
26
23
|
count: 0,
|
|
27
24
|
dot: false,
|
|
@@ -143,12 +140,14 @@ function withJustOpened(rows, justOpened) {
|
|
|
143
140
|
return result;
|
|
144
141
|
}
|
|
145
142
|
/**
|
|
146
|
-
* Open what a notification is about: mark it opened, switch to its group, and go to its link
|
|
143
|
+
* Open what a notification is about: mark it opened, switch to its group, and go to its link
|
|
144
|
+
* ({@link openInGroup}).
|
|
147
145
|
*
|
|
148
146
|
* One without a link opens the Notifications screen in the current group (the screen lists every
|
|
149
147
|
* group's, and switching groups reloads the app, a second cold start on a phone), and stays in
|
|
150
148
|
* its Active list for {@link JUST_OPENED_MS}. A link to a screen that shows any group itself
|
|
151
149
|
* (its route's `opensAnyGroup`) opens in place too, with `groupId` added for the screen to read.
|
|
150
|
+
* One from a group the user has left opens the Notifications screen.
|
|
152
151
|
*/
|
|
153
152
|
async function openNotification(notification) {
|
|
154
153
|
await actOnNotifications({ action: "open", notificationIds: [notification.notificationId] });
|
|
@@ -157,64 +156,8 @@ async function openNotification(notification) {
|
|
|
157
156
|
(0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
|
|
158
157
|
return;
|
|
159
158
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const path = notification.link;
|
|
163
|
-
const member = () => target === userContext.userId || userContext.groupIds().includes(target);
|
|
164
|
-
// Match the path the tab will render, including the host's group and normal query encoding.
|
|
165
|
-
const inPlacePath = (0, identity_routes_1.canonicalizeRoute)(withGroupId(path, target));
|
|
166
|
-
if (opensAnyGroup(inPlacePath) && member()) {
|
|
167
|
-
(0, tabs_state_1.goToTabPath)(inPlacePath);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if ((userContext.currentlyActiveGroupId() || userContext.userId) !== target) {
|
|
171
|
-
// A group the user has left or disabled, from history: selecting it would create a context
|
|
172
|
-
// for it and keep it as the active group across restarts.
|
|
173
|
-
if (target !== userContext.userId && !userContext.groupIds().includes(target)) {
|
|
174
|
-
(0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
// Group switching reloads the renderer. Carry the destination through startup; navigating
|
|
178
|
-
// after a delay can lose the link or write it into the old group's tabs.
|
|
179
|
-
sessionStorage.setItem(pendingNavigationKey, JSON.stringify({ userId: userContext.userId, groupId: target, path }));
|
|
180
|
-
userContext.currentlyActiveGroupId(target);
|
|
181
|
-
await userContext.waitForActiveGroupPersistence();
|
|
182
|
-
await peers_sdk_1.rpcServerCalls.flushDatabases();
|
|
183
|
-
window.location.reload();
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
(0, tabs_state_1.goToTabPath)(path);
|
|
187
|
-
}
|
|
188
|
-
/** Whether the active group's screen for this path shows any of the user's groups itself. */
|
|
189
|
-
function opensAnyGroup(path) {
|
|
190
|
-
// UIRouter includes the rendered props in the context passed to isMatch too.
|
|
191
|
-
const context = { path, uiCategory: "screen", props: {} };
|
|
192
|
-
return !!(0, find_route_1.findRoute)(context, context.props)?.opensAnyGroup;
|
|
193
|
-
}
|
|
194
|
-
/** The path with `groupId` set in its query, replacing one the link carried. */
|
|
195
|
-
function withGroupId(path, groupId) {
|
|
196
|
-
const at = path.indexOf("?");
|
|
197
|
-
const route = at < 0 ? path : path.slice(0, at);
|
|
198
|
-
const params = new URLSearchParams(at < 0 ? "" : path.slice(at + 1));
|
|
199
|
-
params.set("groupId", groupId);
|
|
200
|
-
return `${route}?${params.toString()}`;
|
|
201
|
-
}
|
|
202
|
-
/** Finish a notification's group switch after the new group's routes and tabs have loaded. */
|
|
203
|
-
async function resumeNotificationNavigation() {
|
|
204
|
-
const pending = sessionStorage.getItem(pendingNavigationKey);
|
|
205
|
-
if (!pending)
|
|
206
|
-
return;
|
|
207
|
-
sessionStorage.removeItem(pendingNavigationKey);
|
|
208
|
-
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
209
|
-
try {
|
|
210
|
-
const target = JSON.parse(pending);
|
|
211
|
-
if (target.userId === userContext.userId &&
|
|
212
|
-
target.groupId === (userContext.currentlyActiveGroupId() || userContext.userId) &&
|
|
213
|
-
typeof target.path === "string")
|
|
214
|
-
(0, tabs_state_1.goToTabPath)(target.path);
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
// A stale or malformed session value must not prevent the shell from starting.
|
|
159
|
+
if (!(await (0, open_in_group_1.openInGroup)(notification.link, notification.groupId))) {
|
|
160
|
+
(0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
|
|
218
161
|
}
|
|
219
162
|
}
|
|
220
163
|
/** How long {@link openNotificationById} waits for a notification to sync in, and how often it looks. */
|
|
@@ -20,7 +20,6 @@ const react_1 = require("react");
|
|
|
20
20
|
const command_palette_ui_1 = require("../command-palette/command-palette-ui");
|
|
21
21
|
const globals_1 = require("../globals");
|
|
22
22
|
const hooks_1 = require("../hooks");
|
|
23
|
-
const notifications_client_1 = require("../notifications/notifications-client");
|
|
24
23
|
const identity_ipc_1 = require("../screens/device-pairing/identity-ipc");
|
|
25
24
|
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
26
25
|
const invite_capture_1 = require("../screens/invites/invite-capture");
|
|
@@ -28,6 +27,7 @@ const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown")
|
|
|
28
27
|
const setup_user_1 = require("../screens/setup-user");
|
|
29
28
|
const welcome_modal_1 = require("../screens/welcome-modal");
|
|
30
29
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
30
|
+
const open_in_group_1 = require("../ui-router/open-in-group");
|
|
31
31
|
const routes_loader_1 = require("../ui-router/routes-loader");
|
|
32
32
|
const global_overlays_1 = require("./global-overlays");
|
|
33
33
|
const root_layout_registry_1 = require("./root-layout-registry");
|
|
@@ -96,7 +96,7 @@ function RootLayoutBootstrap(props) {
|
|
|
96
96
|
peers_sdk_1.hasShownWelcomeModal.loadingPromise,
|
|
97
97
|
]);
|
|
98
98
|
(0, globals_1.initializeHashNavigation)();
|
|
99
|
-
await (0,
|
|
99
|
+
await (0, open_in_group_1.resumeGroupNavigation)();
|
|
100
100
|
if ((0, invite_capture_1.peekPendingInvite)()) {
|
|
101
101
|
(0, globals_1.mainContentPath)(identity_routes_1.IDENTITY_ACCEPT_PATH);
|
|
102
102
|
}
|
package/dist/theme.css
CHANGED
|
@@ -132,3 +132,227 @@
|
|
|
132
132
|
display: none;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
+
|
|
136
|
+
/* ─── Mentions ─────────────────────────────────────────────────────────
|
|
137
|
+
A mention chip (MentionChip) in the editor and in rendered markdown, the
|
|
138
|
+
picker's detail line, and the chooser for a record found in several places. */
|
|
139
|
+
|
|
140
|
+
.peers-mention {
|
|
141
|
+
background-color: rgba(var(--bs-link-color-rgb), 0.1);
|
|
142
|
+
border-radius: 4px;
|
|
143
|
+
color: var(--bs-link-color);
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
padding: 0 4px;
|
|
146
|
+
text-decoration: none;
|
|
147
|
+
box-decoration-break: clone;
|
|
148
|
+
-webkit-box-decoration-break: clone;
|
|
149
|
+
overflow-wrap: anywhere;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.peers-mention:hover,
|
|
153
|
+
.peers-mention:focus-visible {
|
|
154
|
+
background-color: rgba(var(--bs-link-color-rgb), 0.2);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.peers-mention-icon {
|
|
158
|
+
font-size: 0.9em;
|
|
159
|
+
margin-right: 3px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.peers-mention-done {
|
|
163
|
+
opacity: 0.7;
|
|
164
|
+
text-decoration: line-through;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* A mention that resolves nowhere the user can read: a dotted chip with a "?" and its label. */
|
|
168
|
+
.peers-mention.peers-mention-missing {
|
|
169
|
+
background: none;
|
|
170
|
+
border: 1px dotted var(--bs-secondary-color);
|
|
171
|
+
color: var(--bs-secondary-color);
|
|
172
|
+
cursor: default;
|
|
173
|
+
padding: 0 4px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* ─── The mention picker ───────────────────────────────────────────────
|
|
177
|
+
The list of results at the caret (above it in the window's lower half), and a
|
|
178
|
+
card beside the list for the highlighted result. On a narrow screen the card
|
|
179
|
+
sits under the list. */
|
|
180
|
+
|
|
181
|
+
.peers-mention-menu {
|
|
182
|
+
--peers-mention-menu-bg: var(--peers-surface-bg, var(--bs-tertiary-bg));
|
|
183
|
+
--peers-mention-menu-border: var(--peers-surface-border, var(--bs-border-color));
|
|
184
|
+
font-size: 14px;
|
|
185
|
+
line-height: 1.35;
|
|
186
|
+
position: relative;
|
|
187
|
+
width: 300px;
|
|
188
|
+
z-index: 1000;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.peers-mention-menu.is-above {
|
|
192
|
+
bottom: 100%;
|
|
193
|
+
margin-bottom: 30px;
|
|
194
|
+
position: absolute;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.peers-mention-menu-list,
|
|
198
|
+
.peers-mention-preview {
|
|
199
|
+
background-color: var(--peers-mention-menu-bg);
|
|
200
|
+
border: 1px solid var(--peers-mention-menu-border);
|
|
201
|
+
border-radius: 8px;
|
|
202
|
+
box-shadow:
|
|
203
|
+
0 8px 24px rgba(0, 0, 0, 0.18),
|
|
204
|
+
0 1px 3px rgba(0, 0, 0, 0.1);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.peers-mention-menu-list {
|
|
208
|
+
list-style: none;
|
|
209
|
+
margin: 0;
|
|
210
|
+
max-height: 320px;
|
|
211
|
+
overflow-y: auto;
|
|
212
|
+
padding: 4px;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.peers-mention-menu-item {
|
|
216
|
+
align-items: flex-start;
|
|
217
|
+
border-radius: 6px;
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
display: flex;
|
|
220
|
+
gap: 8px;
|
|
221
|
+
padding: 6px 8px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.peers-mention-menu-item.is-selected {
|
|
225
|
+
background-color: rgba(var(--bs-link-color-rgb), 0.14);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.peers-mention-menu-icon {
|
|
229
|
+
color: var(--bs-secondary-color);
|
|
230
|
+
flex: 0 0 16px;
|
|
231
|
+
text-align: center;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.peers-mention-menu-text {
|
|
235
|
+
display: flex;
|
|
236
|
+
flex-direction: column;
|
|
237
|
+
min-width: 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.peers-mention-menu-title {
|
|
241
|
+
color: var(--bs-body-color);
|
|
242
|
+
overflow: hidden;
|
|
243
|
+
text-overflow: ellipsis;
|
|
244
|
+
white-space: nowrap;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.peers-mention-menu-detail {
|
|
248
|
+
color: var(--bs-secondary-color);
|
|
249
|
+
font-size: 12px;
|
|
250
|
+
overflow: hidden;
|
|
251
|
+
text-overflow: ellipsis;
|
|
252
|
+
white-space: nowrap;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/* Beside the list, top edges level (bottom edges, when the menu opens above the caret). */
|
|
256
|
+
.peers-mention-preview {
|
|
257
|
+
left: calc(100% + 8px);
|
|
258
|
+
padding: 10px 12px;
|
|
259
|
+
position: absolute;
|
|
260
|
+
top: 0;
|
|
261
|
+
width: 300px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.peers-mention-menu.is-above .peers-mention-preview {
|
|
265
|
+
bottom: 0;
|
|
266
|
+
top: auto;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.peers-mention-menu.is-preview-left .peers-mention-preview {
|
|
270
|
+
left: auto;
|
|
271
|
+
right: calc(100% + 8px);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Room on neither side: under the list, as on a phone. */
|
|
275
|
+
.peers-mention-menu.is-preview-below .peers-mention-preview {
|
|
276
|
+
margin-top: 6px;
|
|
277
|
+
position: static;
|
|
278
|
+
width: auto;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.peers-mention-preview-kind {
|
|
282
|
+
align-items: center;
|
|
283
|
+
color: var(--bs-secondary-color);
|
|
284
|
+
display: flex;
|
|
285
|
+
font-size: 12px;
|
|
286
|
+
gap: 6px;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.peers-mention-preview-title {
|
|
290
|
+
color: var(--bs-body-color);
|
|
291
|
+
font-weight: 600;
|
|
292
|
+
margin-top: 4px;
|
|
293
|
+
overflow-wrap: anywhere;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.peers-mention-preview-where {
|
|
297
|
+
color: var(--bs-secondary-color);
|
|
298
|
+
font-size: 12px;
|
|
299
|
+
margin-top: 2px;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.peers-mention-preview-text {
|
|
303
|
+
-webkit-box-orient: vertical;
|
|
304
|
+
-webkit-line-clamp: 5;
|
|
305
|
+
color: var(--bs-body-color);
|
|
306
|
+
display: -webkit-box;
|
|
307
|
+
font-size: 13px;
|
|
308
|
+
margin: 8px 0 0;
|
|
309
|
+
opacity: 0.85;
|
|
310
|
+
overflow: hidden;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@media (max-width: 640px) {
|
|
314
|
+
.peers-mention-menu {
|
|
315
|
+
width: min(300px, calc(100vw - 24px));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.peers-mention-preview,
|
|
319
|
+
.peers-mention-menu.is-above .peers-mention-preview,
|
|
320
|
+
.peers-mention-menu.is-preview-left .peers-mention-preview {
|
|
321
|
+
margin-top: 6px;
|
|
322
|
+
position: static;
|
|
323
|
+
width: auto;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
.peers-mention-preview-text {
|
|
327
|
+
-webkit-line-clamp: 3;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.peers-mention-chooser {
|
|
332
|
+
align-items: center;
|
|
333
|
+
background-color: var(--peers-graph-overlay-color, rgba(0, 0, 0, 0.35));
|
|
334
|
+
display: flex;
|
|
335
|
+
inset: 0;
|
|
336
|
+
justify-content: center;
|
|
337
|
+
padding: 16px;
|
|
338
|
+
position: fixed;
|
|
339
|
+
z-index: 1080;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.peers-mention-chooser-card {
|
|
343
|
+
background-color: var(--peers-surface-bg, var(--bs-body-bg));
|
|
344
|
+
border: 1px solid var(--peers-surface-border, var(--bs-border-color));
|
|
345
|
+
border-radius: 8px;
|
|
346
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
|
|
347
|
+
max-height: 70vh;
|
|
348
|
+
overflow-y: auto;
|
|
349
|
+
width: min(420px, 100%);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.peers-mention-chooser-head {
|
|
353
|
+
align-items: center;
|
|
354
|
+
display: flex;
|
|
355
|
+
gap: 12px;
|
|
356
|
+
justify-content: space-between;
|
|
357
|
+
padding: 12px 16px;
|
|
358
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open a route that belongs to one of the user's groups, as a notification or a mention does.
|
|
3
|
+
*
|
|
4
|
+
* - A screen that shows any group itself (its route's `opensAnyGroup`) opens in place, with
|
|
5
|
+
* `groupId` added to the path for the screen to read.
|
|
6
|
+
* - A route in the active group opens as it is.
|
|
7
|
+
* - Otherwise Peers switches to the group, which reloads the window, and opens the route once the
|
|
8
|
+
* group's routes and tabs have loaded ({@link resumeGroupNavigation}).
|
|
9
|
+
*
|
|
10
|
+
* @param path - The route, such as `package-nav/<packageId>/app?taskId=<id>`.
|
|
11
|
+
* @param groupId - The group it belongs to; the user's id for Personal.
|
|
12
|
+
* @returns false, having opened nothing, when the group isn't one the user is in (left or
|
|
13
|
+
* disabled): selecting it would create a context for it and keep it across restarts.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openInGroup(path: string, groupId: string): Promise<boolean>;
|
|
16
|
+
/** Finish {@link openInGroup}'s group switch after the new group's routes and tabs have loaded. */
|
|
17
|
+
export declare function resumeGroupNavigation(): Promise<void>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openInGroup = openInGroup;
|
|
4
|
+
exports.resumeGroupNavigation = resumeGroupNavigation;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
7
|
+
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
8
|
+
const find_route_1 = require("./find-route");
|
|
9
|
+
// The name is from when only notifications opened links in other groups; kept so a switch
|
|
10
|
+
// already under way when the app updates still finishes.
|
|
11
|
+
const pendingNavigationKey = "peers.notificationNavigation";
|
|
12
|
+
/**
|
|
13
|
+
* Open a route that belongs to one of the user's groups, as a notification or a mention does.
|
|
14
|
+
*
|
|
15
|
+
* - A screen that shows any group itself (its route's `opensAnyGroup`) opens in place, with
|
|
16
|
+
* `groupId` added to the path for the screen to read.
|
|
17
|
+
* - A route in the active group opens as it is.
|
|
18
|
+
* - Otherwise Peers switches to the group, which reloads the window, and opens the route once the
|
|
19
|
+
* group's routes and tabs have loaded ({@link resumeGroupNavigation}).
|
|
20
|
+
*
|
|
21
|
+
* @param path - The route, such as `package-nav/<packageId>/app?taskId=<id>`.
|
|
22
|
+
* @param groupId - The group it belongs to; the user's id for Personal.
|
|
23
|
+
* @returns false, having opened nothing, when the group isn't one the user is in (left or
|
|
24
|
+
* disabled): selecting it would create a context for it and keep it across restarts.
|
|
25
|
+
*/
|
|
26
|
+
async function openInGroup(path, groupId) {
|
|
27
|
+
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
28
|
+
const member = () => groupId === userContext.userId || userContext.groupIds().includes(groupId);
|
|
29
|
+
// Match the path the tab will render, including the host's group and normal query encoding.
|
|
30
|
+
const inPlacePath = (0, identity_routes_1.canonicalizeRoute)(withGroupId(path, groupId));
|
|
31
|
+
if (opensAnyGroup(inPlacePath) && member()) {
|
|
32
|
+
(0, tabs_state_1.goToTabPath)(inPlacePath);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if ((userContext.currentlyActiveGroupId() || userContext.userId) !== groupId) {
|
|
36
|
+
if (!member())
|
|
37
|
+
return false;
|
|
38
|
+
// Group switching reloads the renderer. Carry the destination through startup; navigating
|
|
39
|
+
// after a delay can lose the link or write it into the old group's tabs.
|
|
40
|
+
sessionStorage.setItem(pendingNavigationKey, JSON.stringify({ userId: userContext.userId, groupId, path }));
|
|
41
|
+
userContext.currentlyActiveGroupId(groupId);
|
|
42
|
+
await userContext.waitForActiveGroupPersistence();
|
|
43
|
+
await peers_sdk_1.rpcServerCalls.flushDatabases();
|
|
44
|
+
window.location.reload();
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
(0, tabs_state_1.goToTabPath)(path);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
/** Finish {@link openInGroup}'s group switch after the new group's routes and tabs have loaded. */
|
|
51
|
+
async function resumeGroupNavigation() {
|
|
52
|
+
const pending = sessionStorage.getItem(pendingNavigationKey);
|
|
53
|
+
if (!pending)
|
|
54
|
+
return;
|
|
55
|
+
sessionStorage.removeItem(pendingNavigationKey);
|
|
56
|
+
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
57
|
+
try {
|
|
58
|
+
const target = JSON.parse(pending);
|
|
59
|
+
if (target.userId === userContext.userId &&
|
|
60
|
+
target.groupId === (userContext.currentlyActiveGroupId() || userContext.userId) &&
|
|
61
|
+
typeof target.path === "string")
|
|
62
|
+
(0, tabs_state_1.goToTabPath)(target.path);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// A stale or malformed session value must not prevent the shell from starting.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Whether the active group's screen for this path shows any of the user's groups itself. */
|
|
69
|
+
function opensAnyGroup(path) {
|
|
70
|
+
// UIRouter includes the rendered props in the context passed to isMatch too.
|
|
71
|
+
const context = { path, uiCategory: "screen", props: {} };
|
|
72
|
+
return !!(0, find_route_1.findRoute)(context, context.props)?.opensAnyGroup;
|
|
73
|
+
}
|
|
74
|
+
/** The path with `groupId` set in its query, replacing one the link carried. */
|
|
75
|
+
function withGroupId(path, groupId) {
|
|
76
|
+
const at = path.indexOf("?");
|
|
77
|
+
const route = at < 0 ? path : path.slice(0, at);
|
|
78
|
+
const params = new URLSearchParams(at < 0 ? "" : path.slice(at + 1));
|
|
79
|
+
params.set("groupId", groupId);
|
|
80
|
+
return `${route}?${params.toString()}`;
|
|
81
|
+
}
|