@abraca/nuxt 2.96.0 → 2.99.0
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/module.json +1 -1
- package/dist/runtime/components/ADocSubPageList.vue +8 -0
- package/dist/runtime/components/ANodePanel.vue +11 -1
- package/dist/runtime/components/ANodePanelStack.d.vue.ts +19 -0
- package/dist/runtime/components/ANodePanelStack.vue +35 -0
- package/dist/runtime/components/ANodePanelStack.vue.d.ts +19 -0
- package/dist/runtime/components/APresence.d.vue.ts +1 -13
- package/dist/runtime/components/APresence.vue.d.ts +1 -13
- package/dist/runtime/components/ATagsPopover.d.vue.ts +34 -0
- package/dist/runtime/components/ATagsPopover.vue +114 -0
- package/dist/runtime/components/ATagsPopover.vue.d.ts +34 -0
- package/dist/runtime/components/aware/AMedia.d.vue.ts +1 -1
- package/dist/runtime/components/aware/AMedia.vue.d.ts +1 -1
- package/dist/runtime/components/chat/AChatMessages.d.vue.ts +14 -0
- package/dist/runtime/components/chat/AChatMessages.vue +94 -14
- package/dist/runtime/components/chat/AChatMessages.vue.d.ts +14 -0
- package/dist/runtime/components/chat/AChatPanel.d.vue.ts +10 -0
- package/dist/runtime/components/chat/AChatPanel.vue +5 -1
- package/dist/runtime/components/chat/AChatPanel.vue.d.ts +10 -0
- package/dist/runtime/components/chat/ANodeChatPanel.d.vue.ts +10 -3
- package/dist/runtime/components/chat/ANodeChatPanel.vue +6 -2
- package/dist/runtime/components/chat/ANodeChatPanel.vue.d.ts +10 -3
- package/dist/runtime/components/docs/ADocsSearch.d.vue.ts +2 -2
- package/dist/runtime/components/docs/ADocsSearch.vue.d.ts +2 -2
- package/dist/runtime/components/docs/ADocsSearchButton.d.vue.ts +1 -1
- package/dist/runtime/components/docs/ADocsSearchButton.vue.d.ts +1 -1
- package/dist/runtime/components/editor/ALocationPickerPopover.vue +6 -2
- package/dist/runtime/components/editor/AMetaChip.vue +18 -16
- package/dist/runtime/components/renderers/AMapRenderer.vue +3 -2
- package/dist/runtime/components/settings/ASettingsAboutPanel.d.vue.ts +3 -0
- package/dist/runtime/components/settings/ASettingsAboutPanel.vue +143 -0
- package/dist/runtime/components/settings/ASettingsAboutPanel.vue.d.ts +3 -0
- package/dist/runtime/components/settings/ASettingsConnectionPanel.vue +65 -100
- package/dist/runtime/components/settings/ASettingsModal.vue +7 -2
- package/dist/runtime/components/settings/sections.d.ts +28 -2
- package/dist/runtime/components/settings/sections.js +23 -0
- package/dist/runtime/composables/awarenessView.d.ts +46 -0
- package/dist/runtime/composables/awarenessView.js +65 -0
- package/dist/runtime/composables/useAwareness.js +19 -28
- package/dist/runtime/composables/useAwarenessPeers.d.ts +1 -25
- package/dist/runtime/composables/useChat.d.ts +21 -0
- package/dist/runtime/composables/useChat.js +77 -3
- package/dist/runtime/composables/useDocOpen.d.ts +69 -0
- package/dist/runtime/composables/useDocOpen.js +158 -0
- package/dist/runtime/composables/useRendererBase.d.ts +1 -25
- package/dist/runtime/composables/useSettingsModal.d.ts +1 -1
- package/dist/runtime/composables/useSpaceConnections.js +1 -60
- package/dist/runtime/composables/useYDoc.d.ts +3 -75
- package/dist/runtime/composables/useYDoc.js +28 -33
- package/dist/runtime/extensions/views/DocLinkView.vue +15 -5
- package/dist/runtime/extensions/views/MetaFieldView.vue +61 -49
- package/dist/runtime/locale.d.ts +2 -0
- package/dist/runtime/locale.js +1 -0
- package/dist/runtime/utils/mapboxToken.d.ts +7 -0
- package/dist/runtime/utils/mapboxToken.js +7 -0
- package/dist/runtime/utils/observeYMap.d.ts +44 -0
- package/dist/runtime/utils/observeYMap.js +86 -0
- package/package.json +5 -5
|
@@ -5,6 +5,8 @@ import { useConnectionStatus } from "../../composables/useConnectionStatus";
|
|
|
5
5
|
import { useWebRTC } from "../../composables/useWebRTC";
|
|
6
6
|
import { useBroadcastSync } from "../../composables/useBroadcastSync";
|
|
7
7
|
import { useServerInfo } from "../../composables/useServerInfo";
|
|
8
|
+
import ASettingsGroup from "./ASettingsGroup.vue";
|
|
9
|
+
import ASettingsRow from "./ASettingsRow.vue";
|
|
8
10
|
const abra = useAbracadabra();
|
|
9
11
|
const { label: connLabel, color: connColor, icon: connIcon } = useConnectionStatus();
|
|
10
12
|
const { isConnected: p2pConnected, peerCount: p2pPeerCount, connect: connectP2P, disconnect: disconnectP2P } = useWebRTC();
|
|
@@ -21,126 +23,89 @@ async function toggleP2P() {
|
|
|
21
23
|
}
|
|
22
24
|
const serverName = computed(() => _serverName.value ?? currentUrl.value);
|
|
23
25
|
const serverVersion = computed(() => _serverVersion.value ?? "Unknown");
|
|
26
|
+
const p2pDescription = computed(() => {
|
|
27
|
+
const base = "Direct peer connections for lower latency.";
|
|
28
|
+
if (!p2pConnected.value) return base;
|
|
29
|
+
return `${base} ${p2pPeerCount.value} peer${p2pPeerCount.value === 1 ? "" : "s"} connected.`;
|
|
30
|
+
});
|
|
24
31
|
</script>
|
|
25
32
|
|
|
26
33
|
<template>
|
|
27
|
-
<div>
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<div class="flex items-center gap-2">
|
|
49
|
-
<UIcon
|
|
50
|
-
:name="connIcon"
|
|
51
|
-
class="size-4"
|
|
52
|
-
:class="`text-${connColor}`"
|
|
53
|
-
/>
|
|
54
|
-
<UBadge
|
|
55
|
-
:color="connColor"
|
|
56
|
-
variant="subtle"
|
|
57
|
-
:label="connLabel"
|
|
58
|
-
size="xs"
|
|
59
|
-
/>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
34
|
+
<div class="flex flex-col gap-8">
|
|
35
|
+
<ASettingsGroup
|
|
36
|
+
title="Server"
|
|
37
|
+
description="Where this client is connected, and how it got there."
|
|
38
|
+
>
|
|
39
|
+
<ASettingsRow
|
|
40
|
+
label="Status"
|
|
41
|
+
:description="serverName"
|
|
42
|
+
>
|
|
43
|
+
<UIcon
|
|
44
|
+
:name="connIcon"
|
|
45
|
+
class="size-4"
|
|
46
|
+
:class="`text-${connColor}`"
|
|
47
|
+
/>
|
|
48
|
+
<UBadge
|
|
49
|
+
:color="connColor"
|
|
50
|
+
variant="subtle"
|
|
51
|
+
:label="connLabel"
|
|
52
|
+
size="xs"
|
|
53
|
+
/>
|
|
54
|
+
</ASettingsRow>
|
|
62
55
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Server URL
|
|
68
|
-
</p>
|
|
69
|
-
<p class="text-xs text-(--ui-text-muted) mt-0.5">
|
|
70
|
-
The server you're connected to.
|
|
71
|
-
</p>
|
|
72
|
-
</div>
|
|
56
|
+
<ASettingsRow
|
|
57
|
+
label="Server URL"
|
|
58
|
+
description="The server you're connected to."
|
|
59
|
+
>
|
|
73
60
|
<code class="text-xs font-mono text-(--ui-text-muted) bg-(--ui-bg-elevated) px-2 py-1 rounded">
|
|
74
61
|
{{ currentUrl || "Not connected" }}
|
|
75
62
|
</code>
|
|
76
|
-
</
|
|
63
|
+
</ASettingsRow>
|
|
77
64
|
|
|
78
|
-
|
|
79
|
-
<div class="flex max-sm:flex-col justify-between sm:items-center gap-4 p-4">
|
|
80
|
-
<div>
|
|
81
|
-
<p class="text-sm font-medium">
|
|
82
|
-
Server Version
|
|
83
|
-
</p>
|
|
84
|
-
</div>
|
|
65
|
+
<ASettingsRow label="Server version">
|
|
85
66
|
<span class="text-sm text-(--ui-text-muted)">{{ serverVersion }}</span>
|
|
86
|
-
</
|
|
67
|
+
</ASettingsRow>
|
|
68
|
+
|
|
69
|
+
<ASettingsRow
|
|
70
|
+
label="Reconnect"
|
|
71
|
+
description="Force reconnection to the server."
|
|
72
|
+
>
|
|
73
|
+
<UButton
|
|
74
|
+
label="Reconnect"
|
|
75
|
+
icon="i-lucide-refresh-cw"
|
|
76
|
+
color="neutral"
|
|
77
|
+
variant="outline"
|
|
78
|
+
size="xs"
|
|
79
|
+
@click="abra.reconnect()"
|
|
80
|
+
/>
|
|
81
|
+
</ASettingsRow>
|
|
82
|
+
</ASettingsGroup>
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<template v-if="p2pConnected">
|
|
97
|
-
{{ p2pPeerCount }} peer{{ p2pPeerCount === 1 ? "" : "s" }} connected.
|
|
98
|
-
</template>
|
|
99
|
-
</p>
|
|
100
|
-
</div>
|
|
84
|
+
<ASettingsGroup
|
|
85
|
+
title="Transports"
|
|
86
|
+
description="Additional sync paths alongside the server socket."
|
|
87
|
+
>
|
|
88
|
+
<ASettingsRow
|
|
89
|
+
label="P2P sync (WebRTC)"
|
|
90
|
+
:description="p2pDescription"
|
|
91
|
+
>
|
|
101
92
|
<USwitch
|
|
102
93
|
v-model="p2pEnabled"
|
|
103
94
|
@update:model-value="toggleP2P"
|
|
104
95
|
/>
|
|
105
|
-
</
|
|
96
|
+
</ASettingsRow>
|
|
106
97
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Cross-Tab Sync
|
|
112
|
-
</p>
|
|
113
|
-
<p class="text-xs text-(--ui-text-muted) mt-0.5">
|
|
114
|
-
BroadcastChannel sync between browser tabs.
|
|
115
|
-
</p>
|
|
116
|
-
</div>
|
|
98
|
+
<ASettingsRow
|
|
99
|
+
label="Cross-tab sync"
|
|
100
|
+
description="BroadcastChannel sync between browser tabs."
|
|
101
|
+
>
|
|
117
102
|
<UBadge
|
|
118
103
|
:color="broadcastActive ? 'success' : 'neutral'"
|
|
119
104
|
variant="subtle"
|
|
120
105
|
:label="broadcastActive ? 'Active' : 'Inactive'"
|
|
121
106
|
size="xs"
|
|
122
107
|
/>
|
|
123
|
-
</
|
|
124
|
-
|
|
125
|
-
<!-- Reconnect -->
|
|
126
|
-
<div class="flex items-center justify-between gap-4 p-4">
|
|
127
|
-
<div>
|
|
128
|
-
<p class="text-sm font-medium">
|
|
129
|
-
Reconnect
|
|
130
|
-
</p>
|
|
131
|
-
<p class="text-xs text-(--ui-text-muted) mt-0.5">
|
|
132
|
-
Force reconnection to the server.
|
|
133
|
-
</p>
|
|
134
|
-
</div>
|
|
135
|
-
<UButton
|
|
136
|
-
label="Reconnect"
|
|
137
|
-
icon="i-lucide-refresh-cw"
|
|
138
|
-
color="neutral"
|
|
139
|
-
variant="outline"
|
|
140
|
-
size="xs"
|
|
141
|
-
@click="abra.reconnect()"
|
|
142
|
-
/>
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
108
|
+
</ASettingsRow>
|
|
109
|
+
</ASettingsGroup>
|
|
145
110
|
</div>
|
|
146
111
|
</template>
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
BUILTIN_SETTINGS_SECTIONS,
|
|
7
7
|
GROUP_LABELS,
|
|
8
8
|
GROUP_MODE,
|
|
9
|
+
pluginSections,
|
|
9
10
|
searchSections,
|
|
10
11
|
visibleSections
|
|
11
12
|
} from "./sections";
|
|
@@ -22,8 +23,12 @@ const headerTabs = [
|
|
|
22
23
|
{ value: "user", label: "User Settings", icon: "i-lucide-user" },
|
|
23
24
|
{ value: "admin", label: "Administration", icon: "i-lucide-shield" }
|
|
24
25
|
];
|
|
26
|
+
const allSections = computed(() => [
|
|
27
|
+
...BUILTIN_SETTINGS_SECTIONS,
|
|
28
|
+
...pluginSections(abra.registry)
|
|
29
|
+
]);
|
|
25
30
|
const modeSections = computed(
|
|
26
|
-
() => visibleSections(
|
|
31
|
+
() => visibleSections(allSections.value, isAdmin.value).filter((s) => GROUP_MODE[s.group] === settingsMode.value)
|
|
27
32
|
);
|
|
28
33
|
const filteredSections = computed(() => searchSections(search.value, modeSections.value));
|
|
29
34
|
const groupedSections = computed(() => {
|
|
@@ -57,7 +62,7 @@ watch(isOpen, (val) => {
|
|
|
57
62
|
if (val) {
|
|
58
63
|
showMobileNav.value = true;
|
|
59
64
|
search.value = "";
|
|
60
|
-
const target =
|
|
65
|
+
const target = allSections.value.find((s) => s.key === activeTab.value);
|
|
61
66
|
if (target) settingsMode.value = GROUP_MODE[target.group];
|
|
62
67
|
}
|
|
63
68
|
});
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { type Component } from 'vue';
|
|
16
16
|
import type { SettingsTab } from '../../composables/useSettingsModal.js';
|
|
17
|
-
export type SettingsGroup = 'user' | 'workspace' | 'admin';
|
|
17
|
+
export type SettingsGroup = 'user' | 'plugin' | 'workspace' | 'admin';
|
|
18
|
+
/** A plugin-contributed section's key. Namespaced so it can never collide with a built-in. */
|
|
19
|
+
export type PluginSectionKey = `plugin:${string}`;
|
|
18
20
|
export interface SettingsSectionDef {
|
|
19
|
-
key: SettingsTab;
|
|
21
|
+
key: SettingsTab | PluginSectionKey;
|
|
20
22
|
label: string;
|
|
21
23
|
icon: string;
|
|
22
24
|
group: SettingsGroup;
|
|
@@ -31,6 +33,30 @@ export interface SettingsSectionDef {
|
|
|
31
33
|
export declare const GROUP_MODE: Record<SettingsGroup, 'user' | 'admin'>;
|
|
32
34
|
export declare const GROUP_LABELS: Record<SettingsGroup, string>;
|
|
33
35
|
export declare const BUILTIN_SETTINGS_SECTIONS: SettingsSectionDef[];
|
|
36
|
+
/**
|
|
37
|
+
* Sections contributed by installed plugins.
|
|
38
|
+
*
|
|
39
|
+
* `AbracadabraPlugin.settingsPanel` has been part of the contract — and
|
|
40
|
+
* `PluginRegistry.getSettingsPanels()` part of the base registry — since the
|
|
41
|
+
* plugin system shipped, but nothing rendered them, so a plugin could declare a
|
|
42
|
+
* settings panel and watch it never appear. They are ordinary sections from
|
|
43
|
+
* here on: searchable, grouped, and selected the same way.
|
|
44
|
+
*
|
|
45
|
+
* Keys are namespaced `plugin:<plugin name>` so they can never collide with a
|
|
46
|
+
* built-in tab, and the name (not the label) is what a deep-link targets.
|
|
47
|
+
*/
|
|
48
|
+
export declare function pluginSections(registry: PluginSectionSource | null | undefined): SettingsSectionDef[];
|
|
49
|
+
/** The slice of the plugin registry `pluginSections` needs. */
|
|
50
|
+
export interface PluginSectionSource {
|
|
51
|
+
getPlugins?: () => readonly {
|
|
52
|
+
name: string;
|
|
53
|
+
settingsPanel?: {
|
|
54
|
+
label?: string;
|
|
55
|
+
icon?: string;
|
|
56
|
+
component?: unknown;
|
|
57
|
+
};
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
34
60
|
/** Filter to the sections visible for the current role. */
|
|
35
61
|
export declare function visibleSections(sections: SettingsSectionDef[], isAdmin: boolean): SettingsSectionDef[];
|
|
36
62
|
/** Case-insensitive search over label + keywords. */
|
|
@@ -10,13 +10,18 @@ import ASettingsTrashPanel from "./ASettingsTrashPanel.vue";
|
|
|
10
10
|
import ASettingsPluginsPanel from "./ASettingsPluginsPanel.vue";
|
|
11
11
|
import ASettingsInvitesPanel from "./ASettingsInvitesPanel.vue";
|
|
12
12
|
import ASettingsAdminPanel from "./ASettingsAdminPanel.vue";
|
|
13
|
+
import ASettingsAboutPanel from "./ASettingsAboutPanel.vue";
|
|
13
14
|
export const GROUP_MODE = {
|
|
14
15
|
user: "user",
|
|
16
|
+
// A plugin's own settings are the user's preferences for that plugin, not
|
|
17
|
+
// workspace administration — they belong beside Appearance, not beside Members.
|
|
18
|
+
plugin: "user",
|
|
15
19
|
workspace: "admin",
|
|
16
20
|
admin: "admin"
|
|
17
21
|
};
|
|
18
22
|
export const GROUP_LABELS = {
|
|
19
23
|
user: "Account",
|
|
24
|
+
plugin: "Plugins",
|
|
20
25
|
workspace: "Workspace",
|
|
21
26
|
admin: "Administration"
|
|
22
27
|
};
|
|
@@ -25,6 +30,7 @@ export const BUILTIN_SETTINGS_SECTIONS = [
|
|
|
25
30
|
{ key: "appearance", label: "Appearance", icon: "i-lucide-palette", group: "user", keywords: ["theme", "dark", "light", "motion", "font"], component: markRaw(ASettingsAppearancePanel) },
|
|
26
31
|
{ key: "security", label: "Security", icon: "i-lucide-shield", group: "user", keywords: ["passkey", "password", "account", "logout", "wipe"], component: markRaw(ASettingsSecurityPanel) },
|
|
27
32
|
{ key: "offline", label: "Offline", icon: "i-lucide-database", group: "user", keywords: ["sync", "storage", "cache"], component: markRaw(ASettingsOfflinePanel) },
|
|
33
|
+
{ key: "about", label: "About", icon: "i-lucide-info", group: "user", keywords: ["version", "server", "diagnostics", "health", "support"], component: markRaw(ASettingsAboutPanel) },
|
|
28
34
|
{ key: "spaces", label: "Spaces", icon: "i-lucide-layers", group: "workspace", keywords: ["workspace", "create", "switch"], component: markRaw(ASettingsSpacesPanel) },
|
|
29
35
|
{ key: "members", label: "Members", icon: "i-lucide-users", group: "workspace", keywords: ["people", "roles", "online"], component: markRaw(ASettingsMembersPanel) },
|
|
30
36
|
{ key: "connection", label: "Connection", icon: "i-lucide-wifi", group: "workspace", keywords: ["server", "p2p", "webrtc", "reconnect"], component: markRaw(ASettingsConnectionPanel) },
|
|
@@ -33,6 +39,23 @@ export const BUILTIN_SETTINGS_SECTIONS = [
|
|
|
33
39
|
{ key: "invites", label: "Invites", icon: "i-lucide-ticket", group: "admin", adminOnly: true, keywords: ["invite", "code", "join"], component: markRaw(ASettingsInvitesPanel) },
|
|
34
40
|
{ key: "admin", label: "Admin", icon: "i-lucide-shield-alert", group: "admin", adminOnly: true, keywords: ["users", "server", "manage"], component: markRaw(ASettingsAdminPanel) }
|
|
35
41
|
];
|
|
42
|
+
export function pluginSections(registry) {
|
|
43
|
+
const plugins = registry?.getPlugins?.() ?? [];
|
|
44
|
+
const sections = [];
|
|
45
|
+
for (const plugin of plugins) {
|
|
46
|
+
const panel = plugin?.settingsPanel;
|
|
47
|
+
if (!panel?.component) continue;
|
|
48
|
+
sections.push({
|
|
49
|
+
key: `plugin:${plugin.name}`,
|
|
50
|
+
label: panel.label || plugin.name,
|
|
51
|
+
icon: panel.icon || "i-lucide-plug",
|
|
52
|
+
group: "plugin",
|
|
53
|
+
keywords: [plugin.name],
|
|
54
|
+
component: markRaw(panel.component)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return sections;
|
|
58
|
+
}
|
|
36
59
|
export function visibleSections(sections, isAdmin) {
|
|
37
60
|
return sections.filter((s) => !s.adminOnly || isAdmin);
|
|
38
61
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One shared, rAF-throttled mirror of an Awareness instance.
|
|
3
|
+
*
|
|
4
|
+
* `useAwareness()` and `useAwarenessOf()` are plain functions, not singletons —
|
|
5
|
+
* every call site installed its **own** `change` listener, its **own**
|
|
6
|
+
* `requestAnimationFrame`, and rebuilt its **own** full copy of every peer's
|
|
7
|
+
* state. Across the module that is 11 + 12 call sites, so a single cursor move
|
|
8
|
+
* from a single peer woke 23 listeners, scheduled 23 frames, and produced 23
|
|
9
|
+
* identical clones of the same data — every one of them thrown away on the next
|
|
10
|
+
* pointer move. On a busy document that is the module's largest idle cost after
|
|
11
|
+
* the provider's own heartbeats.
|
|
12
|
+
*
|
|
13
|
+
* This module keeps exactly one mirror per Awareness instance, refcounted, so
|
|
14
|
+
* the work is done once and every consumer reads the same refs. Consumers that
|
|
15
|
+
* want a `Map` rather than an array get it from a `computed`, which is lazy and
|
|
16
|
+
* cached — so that shape is also built once per change, not once per consumer.
|
|
17
|
+
*
|
|
18
|
+
* Keyed on the **Awareness instance**, not the provider: a provider can swap
|
|
19
|
+
* its awareness (reconnect, server switch), and a child provider materialises
|
|
20
|
+
* its own lazily. A `WeakMap` means a discarded awareness takes its mirror with
|
|
21
|
+
* it even if a consumer leaks its handle.
|
|
22
|
+
*/
|
|
23
|
+
import { type ShallowRef, type ComputedRef } from 'vue';
|
|
24
|
+
/** A peer's awareness state, flattened with its client id. */
|
|
25
|
+
export interface AwarenessUser {
|
|
26
|
+
clientId: number;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}
|
|
29
|
+
export interface SharedAwarenessView {
|
|
30
|
+
/** Every peer's state, including the local client. Replaced wholesale per frame. */
|
|
31
|
+
states: ShallowRef<AwarenessUser[]>;
|
|
32
|
+
/** The same data keyed by client id, derived once however many consumers read it. */
|
|
33
|
+
statesMap: ComputedRef<Map<number, Record<string, unknown>>>;
|
|
34
|
+
/** The local client's own state, or the last one seen. */
|
|
35
|
+
currentUser: ShallowRef<AwarenessUser | null>;
|
|
36
|
+
/** Rebuild now, bypassing the frame throttle (used on first attach). */
|
|
37
|
+
flush: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Take a reference on the shared mirror for `awareness`, creating it on first
|
|
41
|
+
* use. **Every acquire must be paired with a `releaseAwarenessView`**, or the
|
|
42
|
+
* listener outlives its consumers.
|
|
43
|
+
*/
|
|
44
|
+
export declare function acquireAwarenessView(awareness: any): SharedAwarenessView;
|
|
45
|
+
/** Drop a reference; the last one out detaches the listener and the frame. */
|
|
46
|
+
export declare function releaseAwarenessView(awareness: any): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { shallowRef, computed } from "vue";
|
|
2
|
+
const views = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
function createEntry(awareness) {
|
|
4
|
+
const states = shallowRef([]);
|
|
5
|
+
const currentUser = shallowRef(null);
|
|
6
|
+
const statesMap = computed(() => {
|
|
7
|
+
const map = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const entry of states.value) {
|
|
9
|
+
const { clientId, ...rest } = entry;
|
|
10
|
+
map.set(clientId, rest);
|
|
11
|
+
}
|
|
12
|
+
return map;
|
|
13
|
+
});
|
|
14
|
+
let rafId = null;
|
|
15
|
+
const flush = () => {
|
|
16
|
+
rafId = null;
|
|
17
|
+
const next = [];
|
|
18
|
+
for (const [id, state] of awareness.getStates()) {
|
|
19
|
+
next.push({ clientId: id, ...state });
|
|
20
|
+
}
|
|
21
|
+
states.value = next;
|
|
22
|
+
const local = awareness.getLocalState();
|
|
23
|
+
if (local) currentUser.value = { clientId: awareness.clientID, ...local };
|
|
24
|
+
};
|
|
25
|
+
const schedule = () => {
|
|
26
|
+
if (typeof requestAnimationFrame === "undefined") {
|
|
27
|
+
flush();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (rafId === null) rafId = requestAnimationFrame(flush);
|
|
31
|
+
};
|
|
32
|
+
awareness.on("change", schedule);
|
|
33
|
+
flush();
|
|
34
|
+
return {
|
|
35
|
+
refs: 0,
|
|
36
|
+
states,
|
|
37
|
+
statesMap,
|
|
38
|
+
currentUser,
|
|
39
|
+
flush,
|
|
40
|
+
teardown() {
|
|
41
|
+
awareness.off("change", schedule);
|
|
42
|
+
if (rafId !== null) {
|
|
43
|
+
cancelAnimationFrame(rafId);
|
|
44
|
+
rafId = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function acquireAwarenessView(awareness) {
|
|
50
|
+
let entry = views.get(awareness);
|
|
51
|
+
if (!entry) {
|
|
52
|
+
entry = createEntry(awareness);
|
|
53
|
+
views.set(awareness, entry);
|
|
54
|
+
}
|
|
55
|
+
entry.refs++;
|
|
56
|
+
return entry;
|
|
57
|
+
}
|
|
58
|
+
export function releaseAwarenessView(awareness) {
|
|
59
|
+
const entry = views.get(awareness);
|
|
60
|
+
if (!entry) return;
|
|
61
|
+
entry.refs--;
|
|
62
|
+
if (entry.refs > 0) return;
|
|
63
|
+
entry.teardown();
|
|
64
|
+
views.delete(awareness);
|
|
65
|
+
}
|
|
@@ -1,44 +1,35 @@
|
|
|
1
1
|
import { shallowRef, computed, watch } from "vue";
|
|
2
2
|
import { tryOnScopeDispose } from "@vueuse/core";
|
|
3
3
|
import { useAbracadabra } from "./useAbracadabra.js";
|
|
4
|
+
import { acquireAwarenessView, releaseAwarenessView } from "./awarenessView.js";
|
|
4
5
|
export function useAwareness() {
|
|
5
6
|
const { provider } = useAbracadabra();
|
|
6
7
|
const states = shallowRef(/* @__PURE__ */ new Map());
|
|
7
|
-
|
|
8
|
+
let _attached = null;
|
|
9
|
+
let _stopMirror = null;
|
|
10
|
+
function _detach() {
|
|
11
|
+
_stopMirror?.();
|
|
12
|
+
_stopMirror = null;
|
|
13
|
+
if (_attached) {
|
|
14
|
+
releaseAwarenessView(_attached);
|
|
15
|
+
_attached = null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function _subscribe() {
|
|
19
|
+
_detach();
|
|
8
20
|
const awareness = provider.value?.awareness;
|
|
9
21
|
if (!awareness) {
|
|
10
22
|
states.value = /* @__PURE__ */ new Map();
|
|
11
23
|
return;
|
|
12
24
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const _throttledSync = () => {
|
|
19
|
-
if (_rafPending) return;
|
|
20
|
-
_rafPending = true;
|
|
21
|
-
_rafId = requestAnimationFrame(() => {
|
|
22
|
-
_rafPending = false;
|
|
23
|
-
_rafId = null;
|
|
24
|
-
_syncStates();
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
function _subscribe() {
|
|
28
|
-
_unsub?.();
|
|
29
|
-
_unsub = null;
|
|
30
|
-
const awareness = provider.value?.awareness;
|
|
31
|
-
if (!awareness) return;
|
|
32
|
-
_syncStates();
|
|
33
|
-
awareness.on("change", _throttledSync);
|
|
34
|
-
_unsub = () => awareness.off("change", _throttledSync);
|
|
25
|
+
const view = acquireAwarenessView(awareness);
|
|
26
|
+
_attached = awareness;
|
|
27
|
+
_stopMirror = watch(view.statesMap, (m) => {
|
|
28
|
+
states.value = m;
|
|
29
|
+
}, { immediate: true });
|
|
35
30
|
}
|
|
36
31
|
watch(provider, () => _subscribe(), { immediate: true });
|
|
37
|
-
tryOnScopeDispose(
|
|
38
|
-
_unsub?.();
|
|
39
|
-
_unsub = null;
|
|
40
|
-
if (_rafId !== null) cancelAnimationFrame(_rafId);
|
|
41
|
-
});
|
|
32
|
+
tryOnScopeDispose(_detach);
|
|
42
33
|
const localState = computed(() => {
|
|
43
34
|
const awareness = provider.value?.awareness;
|
|
44
35
|
if (!awareness) return {};
|
|
@@ -12,31 +12,7 @@ import type { AwarenessPeer, AwarenessUser } from '../types.js';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function useAwarenessPeers(): {
|
|
14
14
|
peers: import("vue").ComputedRef<AwarenessPeer[]>;
|
|
15
|
-
currentUser: import("vue").
|
|
16
|
-
[x: string]: any;
|
|
17
|
-
clientId: number;
|
|
18
|
-
user?: {
|
|
19
|
-
name?: string | undefined;
|
|
20
|
-
color?: string | undefined;
|
|
21
|
-
avatar?: string | undefined;
|
|
22
|
-
statusIcon?: string | undefined;
|
|
23
|
-
statusText?: string | undefined;
|
|
24
|
-
publicKey?: string | undefined;
|
|
25
|
-
} | undefined;
|
|
26
|
-
docId?: string | undefined;
|
|
27
|
-
} | null, AwarenessUser | {
|
|
28
|
-
[x: string]: any;
|
|
29
|
-
clientId: number;
|
|
30
|
-
user?: {
|
|
31
|
-
name?: string | undefined;
|
|
32
|
-
color?: string | undefined;
|
|
33
|
-
avatar?: string | undefined;
|
|
34
|
-
statusIcon?: string | undefined;
|
|
35
|
-
statusText?: string | undefined;
|
|
36
|
-
publicKey?: string | undefined;
|
|
37
|
-
} | undefined;
|
|
38
|
-
docId?: string | undefined;
|
|
39
|
-
} | null>;
|
|
15
|
+
currentUser: import("vue").ShallowRef<AwarenessUser | null, AwarenessUser | null>;
|
|
40
16
|
isIdle: (clientId: number, thresholdMs?: number) => boolean;
|
|
41
17
|
peersInDoc: (docId: MaybeRef<string>) => import("vue").ComputedRef<AwarenessPeer[]>;
|
|
42
18
|
};
|
|
@@ -18,6 +18,8 @@ export interface ChatMessage {
|
|
|
18
18
|
createdAt: number;
|
|
19
19
|
/** Id of the message this one replies to, if any (threaded reply). */
|
|
20
20
|
replyTo?: string;
|
|
21
|
+
/** When the message was last edited, if ever. Renders the "(edited)" marker. */
|
|
22
|
+
editedAt?: number;
|
|
21
23
|
}
|
|
22
24
|
export interface ChatChannel {
|
|
23
25
|
id: string;
|
|
@@ -69,6 +71,21 @@ declare function sendMessage(channelId: string, content: string, opts?: {
|
|
|
69
71
|
mentions?: string[];
|
|
70
72
|
replyTo?: string;
|
|
71
73
|
}): void;
|
|
74
|
+
/**
|
|
75
|
+
* Edit a previously-sent message.
|
|
76
|
+
*
|
|
77
|
+
* The server records an append-only `edit` entry against the original and
|
|
78
|
+
* clients fold it on read (`foldRecords`), so there is no separate broadcast
|
|
79
|
+
* to handle: the period doc's `messages` Y.Array changes, `pumpAll` re-folds,
|
|
80
|
+
* and `reconcileFolded` applies the new content. Only the sender (or an admin)
|
|
81
|
+
* is permitted server-side; a rejection comes back as a `serverError`.
|
|
82
|
+
*/
|
|
83
|
+
declare function editMessage(channelId: string, messageId: string, content: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Delete a message. Append-only server-side — a `tombstone` record, which
|
|
86
|
+
* `foldRecords` drops on the next fold. Same permission rule as edit.
|
|
87
|
+
*/
|
|
88
|
+
declare function deleteMessage(channelId: string, messageId: string): void;
|
|
72
89
|
/**
|
|
73
90
|
* Open the wrapper provider for the given channel, observe its
|
|
74
91
|
* `periods` Y.Array, and attach the active period subdoc so its
|
|
@@ -94,6 +111,8 @@ export declare function useChat(): {
|
|
|
94
111
|
typingByChannel: import("vue").Ref<Record<string, Map<string, string>>, Record<string, Map<string, string>>>;
|
|
95
112
|
totalUnreadCount: import("vue").ComputedRef<number>;
|
|
96
113
|
sendMessage: typeof sendMessage;
|
|
114
|
+
editMessage: typeof editMessage;
|
|
115
|
+
deleteMessage: typeof deleteMessage;
|
|
97
116
|
fetchHistory: typeof fetchHistory;
|
|
98
117
|
sendTyping: typeof sendTyping;
|
|
99
118
|
setActiveChannel: typeof setActiveChannel;
|
|
@@ -118,6 +137,8 @@ export declare function useChatChannel(channelId: string): {
|
|
|
118
137
|
mentions?: string[];
|
|
119
138
|
replyTo?: string;
|
|
120
139
|
}) => void;
|
|
140
|
+
edit: (messageId: string, content: string) => void;
|
|
141
|
+
remove: (messageId: string) => void;
|
|
121
142
|
loadHistory: (opts?: {
|
|
122
143
|
before?: number;
|
|
123
144
|
limit?: number;
|