@actuate-media/cms-admin 0.11.0 → 0.12.1
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/LICENSE +21 -21
- package/dist/__tests__/components/comment-mark.test.d.ts +2 -0
- package/dist/__tests__/components/comment-mark.test.d.ts.map +1 -0
- package/dist/__tests__/components/comment-mark.test.js +89 -0
- package/dist/__tests__/components/comment-mark.test.js.map +1 -0
- package/dist/__tests__/components/comment-side-panel.test.d.ts +2 -0
- package/dist/__tests__/components/comment-side-panel.test.d.ts.map +1 -0
- package/dist/__tests__/components/comment-side-panel.test.js +291 -0
- package/dist/__tests__/components/comment-side-panel.test.js.map +1 -0
- package/dist/__tests__/components/notification-bell.test.d.ts +2 -0
- package/dist/__tests__/components/notification-bell.test.d.ts.map +1 -0
- package/dist/__tests__/components/notification-bell.test.js +200 -0
- package/dist/__tests__/components/notification-bell.test.js.map +1 -0
- package/dist/__tests__/components/offline-status.test.d.ts +2 -0
- package/dist/__tests__/components/offline-status.test.d.ts.map +1 -0
- package/dist/__tests__/components/offline-status.test.js +56 -0
- package/dist/__tests__/components/offline-status.test.js.map +1 -0
- package/dist/__tests__/components/presence-chips-helpers.test.d.ts +2 -0
- package/dist/__tests__/components/presence-chips-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/components/presence-chips-helpers.test.js +35 -0
- package/dist/__tests__/components/presence-chips-helpers.test.js.map +1 -0
- package/dist/__tests__/fields/component-block-helpers.test.d.ts +7 -0
- package/dist/__tests__/fields/component-block-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/fields/component-block-helpers.test.js +592 -0
- package/dist/__tests__/fields/component-block-helpers.test.js.map +1 -0
- package/dist/__tests__/lib/active-editor.test.d.ts +2 -0
- package/dist/__tests__/lib/active-editor.test.d.ts.map +1 -0
- package/dist/__tests__/lib/active-editor.test.js +57 -0
- package/dist/__tests__/lib/active-editor.test.js.map +1 -0
- package/dist/__tests__/lib/coauthor-client.test.d.ts +2 -0
- package/dist/__tests__/lib/coauthor-client.test.d.ts.map +1 -0
- package/dist/__tests__/lib/coauthor-client.test.js +173 -0
- package/dist/__tests__/lib/coauthor-client.test.js.map +1 -0
- package/dist/__tests__/lib/collaboration-provider.test.d.ts +2 -0
- package/dist/__tests__/lib/collaboration-provider.test.d.ts.map +1 -0
- package/dist/__tests__/lib/collaboration-provider.test.js +335 -0
- package/dist/__tests__/lib/collaboration-provider.test.js.map +1 -0
- package/dist/__tests__/lib/comment-anchor.test.d.ts +2 -0
- package/dist/__tests__/lib/comment-anchor.test.d.ts.map +1 -0
- package/dist/__tests__/lib/comment-anchor.test.js +173 -0
- package/dist/__tests__/lib/comment-anchor.test.js.map +1 -0
- package/dist/__tests__/lib/comments-client.test.d.ts +2 -0
- package/dist/__tests__/lib/comments-client.test.d.ts.map +1 -0
- package/dist/__tests__/lib/comments-client.test.js +202 -0
- package/dist/__tests__/lib/comments-client.test.js.map +1 -0
- package/dist/__tests__/lib/notifications-client.test.d.ts +2 -0
- package/dist/__tests__/lib/notifications-client.test.d.ts.map +1 -0
- package/dist/__tests__/lib/notifications-client.test.js +155 -0
- package/dist/__tests__/lib/notifications-client.test.js.map +1 -0
- package/dist/__tests__/lib/slash-command.test.d.ts +2 -0
- package/dist/__tests__/lib/slash-command.test.d.ts.map +1 -0
- package/dist/__tests__/lib/slash-command.test.js +123 -0
- package/dist/__tests__/lib/slash-command.test.js.map +1 -0
- package/dist/actuate-admin.css +1 -1
- package/dist/components/AICoauthorBubbleMenu.d.ts +18 -0
- package/dist/components/AICoauthorBubbleMenu.d.ts.map +1 -0
- package/dist/components/AICoauthorBubbleMenu.js +113 -0
- package/dist/components/AICoauthorBubbleMenu.js.map +1 -0
- package/dist/components/CoauthorResultPopover.d.ts +28 -0
- package/dist/components/CoauthorResultPopover.d.ts.map +1 -0
- package/dist/components/CoauthorResultPopover.js +42 -0
- package/dist/components/CoauthorResultPopover.js.map +1 -0
- package/dist/components/CommandPalette.d.ts +1 -1
- package/dist/components/CommandPalette.d.ts.map +1 -1
- package/dist/components/CommandPalette.js +138 -40
- package/dist/components/CommandPalette.js.map +1 -1
- package/dist/components/CommentMark.d.ts +54 -0
- package/dist/components/CommentMark.d.ts.map +1 -0
- package/dist/components/CommentMark.js +104 -0
- package/dist/components/CommentMark.js.map +1 -0
- package/dist/components/CommentSidePanel.d.ts +86 -0
- package/dist/components/CommentSidePanel.d.ts.map +1 -0
- package/dist/components/CommentSidePanel.js +165 -0
- package/dist/components/CommentSidePanel.js.map +1 -0
- package/dist/components/LivePreview.d.ts.map +1 -1
- package/dist/components/LivePreview.js +80 -16
- package/dist/components/LivePreview.js.map +1 -1
- package/dist/components/NotificationBell.d.ts +45 -0
- package/dist/components/NotificationBell.d.ts.map +1 -0
- package/dist/components/NotificationBell.js +90 -0
- package/dist/components/NotificationBell.js.map +1 -0
- package/dist/components/OfflineStatus.d.ts +39 -0
- package/dist/components/OfflineStatus.d.ts.map +1 -0
- package/dist/components/OfflineStatus.js +47 -0
- package/dist/components/OfflineStatus.js.map +1 -0
- package/dist/components/PresenceChips.d.ts +31 -0
- package/dist/components/PresenceChips.d.ts.map +1 -0
- package/dist/components/PresenceChips.js +58 -0
- package/dist/components/PresenceChips.js.map +1 -0
- package/dist/components/TipTapEditor.d.ts +61 -1
- package/dist/components/TipTapEditor.d.ts.map +1 -1
- package/dist/components/TipTapEditor.js +211 -8
- package/dist/components/TipTapEditor.js.map +1 -1
- package/dist/components/ui/Badge.d.ts +1 -1
- package/dist/fields/ComponentBlockField.d.ts +25 -0
- package/dist/fields/ComponentBlockField.d.ts.map +1 -0
- package/dist/fields/ComponentBlockField.js +74 -0
- package/dist/fields/ComponentBlockField.js.map +1 -0
- package/dist/fields/FieldRenderer.d.ts +3 -0
- package/dist/fields/FieldRenderer.d.ts.map +1 -1
- package/dist/fields/FieldRenderer.js +3 -1
- package/dist/fields/FieldRenderer.js.map +1 -1
- package/dist/fields/PropInput.d.ts +14 -0
- package/dist/fields/PropInput.d.ts.map +1 -0
- package/dist/fields/PropInput.js +163 -0
- package/dist/fields/PropInput.js.map +1 -0
- package/dist/fields/component-block-helpers.d.ts +96 -0
- package/dist/fields/component-block-helpers.d.ts.map +1 -0
- package/dist/fields/component-block-helpers.js +323 -0
- package/dist/fields/component-block-helpers.js.map +1 -0
- package/dist/fields/index.d.ts +4 -0
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +2 -0
- package/dist/fields/index.js.map +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/active-editor.d.ts +6 -0
- package/dist/lib/active-editor.d.ts.map +1 -0
- package/dist/lib/active-editor.js +35 -0
- package/dist/lib/active-editor.js.map +1 -0
- package/dist/lib/coauthor-client.d.ts +72 -0
- package/dist/lib/coauthor-client.d.ts.map +1 -0
- package/dist/lib/coauthor-client.js +98 -0
- package/dist/lib/coauthor-client.js.map +1 -0
- package/dist/lib/collaboration-provider.d.ts +142 -0
- package/dist/lib/collaboration-provider.d.ts.map +1 -0
- package/dist/lib/collaboration-provider.js +168 -0
- package/dist/lib/collaboration-provider.js.map +1 -0
- package/dist/lib/comment-anchor.d.ts +86 -0
- package/dist/lib/comment-anchor.d.ts.map +1 -0
- package/dist/lib/comment-anchor.js +139 -0
- package/dist/lib/comment-anchor.js.map +1 -0
- package/dist/lib/comments-client.d.ts +106 -0
- package/dist/lib/comments-client.d.ts.map +1 -0
- package/dist/lib/comments-client.js +138 -0
- package/dist/lib/comments-client.js.map +1 -0
- package/dist/lib/notifications-client.d.ts +68 -0
- package/dist/lib/notifications-client.d.ts.map +1 -0
- package/dist/lib/notifications-client.js +85 -0
- package/dist/lib/notifications-client.js.map +1 -0
- package/dist/lib/slash-command.d.ts +39 -0
- package/dist/lib/slash-command.d.ts.map +1 -0
- package/dist/lib/slash-command.js +50 -0
- package/dist/lib/slash-command.js.map +1 -0
- package/package.json +20 -4
- package/src/__tests__/components/comment-mark.test.ts +99 -0
- package/src/__tests__/components/comment-side-panel.test.tsx +343 -0
- package/src/__tests__/components/notification-bell.test.tsx +213 -0
- package/src/__tests__/components/offline-status.test.tsx +66 -0
- package/src/__tests__/components/presence-chips-helpers.test.ts +44 -0
- package/src/__tests__/fields/component-block-helpers.test.ts +674 -0
- package/src/__tests__/lib/active-editor.test.ts +70 -0
- package/src/__tests__/lib/coauthor-client.test.ts +213 -0
- package/src/__tests__/lib/collaboration-provider.test.ts +425 -0
- package/src/__tests__/lib/comment-anchor.test.ts +188 -0
- package/src/__tests__/lib/comments-client.test.ts +239 -0
- package/src/__tests__/lib/notifications-client.test.ts +195 -0
- package/src/__tests__/lib/slash-command.test.ts +146 -0
- package/src/components/AICoauthorBubbleMenu.tsx +187 -0
- package/src/components/CoauthorResultPopover.tsx +193 -0
- package/src/components/CommandPalette.tsx +397 -209
- package/src/components/CommentMark.ts +138 -0
- package/src/components/CommentSidePanel.tsx +521 -0
- package/src/components/LivePreview.tsx +117 -11
- package/src/components/NotificationBell.tsx +242 -0
- package/src/components/OfflineStatus.tsx +90 -0
- package/src/components/PresenceChips.tsx +150 -0
- package/src/components/TipTapEditor.tsx +310 -12
- package/src/fields/ComponentBlockField.tsx +179 -0
- package/src/fields/FieldRenderer.tsx +8 -0
- package/src/fields/PropInput.tsx +552 -0
- package/src/fields/component-block-helpers.ts +341 -0
- package/src/fields/index.ts +4 -0
- package/src/index.ts +27 -0
- package/src/lib/active-editor.ts +39 -0
- package/src/lib/coauthor-client.ts +160 -0
- package/src/lib/collaboration-provider.ts +306 -0
- package/src/lib/comment-anchor.ts +179 -0
- package/src/lib/comments-client.ts +208 -0
- package/src/lib/notifications-client.ts +146 -0
- package/src/lib/slash-command.ts +67 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { listNotifications as defaultListNotifications, markAllNotificationsRead as defaultMarkAllRead, markNotificationRead as defaultMarkRead, notificationSummary, unreadCount as defaultUnreadCount, } from '../lib/notifications-client.js';
|
|
5
|
+
const defaultApi = {
|
|
6
|
+
list: (opts) => defaultListNotifications(opts),
|
|
7
|
+
unread: () => defaultUnreadCount(),
|
|
8
|
+
markRead: (id) => defaultMarkRead(id),
|
|
9
|
+
markAllRead: () => defaultMarkAllRead(),
|
|
10
|
+
};
|
|
11
|
+
export function NotificationBell({ pollIntervalMs = 30_000, onSelect, onError, api = defaultApi, className, }) {
|
|
12
|
+
const [open, setOpen] = useState(false);
|
|
13
|
+
const [unread, setUnread] = useState(0);
|
|
14
|
+
const [items, setItems] = useState([]);
|
|
15
|
+
const [loading, setLoading] = useState(false);
|
|
16
|
+
const mountedRef = useRef(true);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
return () => {
|
|
19
|
+
mountedRef.current = false;
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
const refreshUnread = useCallback(async () => {
|
|
23
|
+
const out = await api.unread();
|
|
24
|
+
if (!mountedRef.current)
|
|
25
|
+
return;
|
|
26
|
+
if (!out.ok) {
|
|
27
|
+
onError?.(out.error);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setUnread(out.result);
|
|
31
|
+
}, [api, onError]);
|
|
32
|
+
const refreshList = useCallback(async (includeRead = false) => {
|
|
33
|
+
setLoading(true);
|
|
34
|
+
const out = await api.list({ includeRead });
|
|
35
|
+
if (!mountedRef.current)
|
|
36
|
+
return;
|
|
37
|
+
if (!out.ok) {
|
|
38
|
+
onError?.(out.error);
|
|
39
|
+
setItems([]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
setItems(out.result);
|
|
43
|
+
}
|
|
44
|
+
setLoading(false);
|
|
45
|
+
}, [api, onError]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
void refreshUnread();
|
|
48
|
+
if (!pollIntervalMs)
|
|
49
|
+
return;
|
|
50
|
+
const id = setInterval(() => void refreshUnread(), pollIntervalMs);
|
|
51
|
+
return () => clearInterval(id);
|
|
52
|
+
}, [refreshUnread, pollIntervalMs]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!open)
|
|
55
|
+
return;
|
|
56
|
+
void refreshList(false);
|
|
57
|
+
}, [open, refreshList]);
|
|
58
|
+
const handleClickRow = useCallback(async (n) => {
|
|
59
|
+
// Optimistic update: drop the unread count + tag the row read.
|
|
60
|
+
if (!n.readAt) {
|
|
61
|
+
setUnread((v) => Math.max(0, v - 1));
|
|
62
|
+
setItems((arr) => arr.map((row) => (row.id === n.id ? { ...row, readAt: new Date().toISOString() } : row)));
|
|
63
|
+
const out = await api.markRead(n.id);
|
|
64
|
+
if (!out.ok) {
|
|
65
|
+
onError?.(out.error);
|
|
66
|
+
// Roll back on failure.
|
|
67
|
+
setUnread((v) => v + 1);
|
|
68
|
+
setItems((arr) => arr.map((row) => (row.id === n.id ? { ...row, readAt: null } : row)));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
onSelect?.(n);
|
|
72
|
+
}, [api, onError, onSelect]);
|
|
73
|
+
const handleMarkAll = useCallback(async () => {
|
|
74
|
+
const previous = items.slice();
|
|
75
|
+
const now = new Date().toISOString();
|
|
76
|
+
setItems(items.map((n) => ({ ...n, readAt: n.readAt ?? now })));
|
|
77
|
+
setUnread(0);
|
|
78
|
+
const out = await api.markAllRead();
|
|
79
|
+
if (!out.ok) {
|
|
80
|
+
onError?.(out.error);
|
|
81
|
+
setItems(previous);
|
|
82
|
+
await refreshUnread();
|
|
83
|
+
}
|
|
84
|
+
}, [api, items, onError, refreshUnread]);
|
|
85
|
+
return (_jsxs("div", { className: `relative ${className ?? ''}`, "data-testid": "notification-bell", children: [_jsxs("button", { type: "button", className: "relative rounded p-1.5 text-gray-600 hover:bg-gray-100 hover:text-gray-900", "aria-label": "Notifications", "aria-haspopup": "menu", "aria-expanded": open, onClick: () => setOpen((v) => !v), "data-testid": "bell-button", children: [_jsx(BellIcon, {}), unread > 0 && (_jsx("span", { className: "absolute -top-0.5 -right-0.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-red-600 px-1 text-[10px] font-semibold text-white", "data-testid": "bell-badge", children: unread > 99 ? '99+' : unread }))] }), open && (_jsxs("div", { role: "menu", className: "absolute right-0 z-50 mt-1 w-80 rounded border border-gray-200 bg-white shadow-lg", "data-testid": "bell-dropdown", children: [_jsxs("header", { className: "flex items-center justify-between border-b border-gray-100 px-3 py-2", children: [_jsx("span", { className: "text-sm font-semibold text-gray-900", children: "Notifications" }), _jsx("button", { type: "button", className: "text-xs text-gray-600 hover:text-gray-900 disabled:opacity-50", onClick: handleMarkAll, disabled: unread === 0, "data-testid": "bell-mark-all", children: "Mark all read" })] }), _jsx("div", { className: "max-h-80 overflow-y-auto", "aria-busy": loading, "data-testid": "bell-list", children: loading ? (_jsx("p", { className: "px-3 py-2 text-xs text-gray-500", children: "Loading\u2026" })) : items.length === 0 ? (_jsx("p", { className: "px-3 py-2 text-xs text-gray-500", children: "All caught up." })) : (_jsx("ul", { children: items.map((n) => (_jsx("li", { children: _jsxs("button", { type: "button", role: "menuitem", className: `block w-full px-3 py-2 text-left text-xs hover:bg-gray-50 ${n.readAt ? 'text-gray-500' : 'font-medium text-gray-900'}`, onClick: () => handleClickRow(n), "data-testid": `bell-row-${n.id}`, "data-read": n.readAt ? 'true' : 'false', children: [_jsx("div", { children: notificationSummary(n) }), _jsx("div", { className: "mt-0.5 text-[10px] text-gray-400", children: n.createdAt })] }) }, n.id))) })) })] }))] }));
|
|
86
|
+
}
|
|
87
|
+
function BellIcon() {
|
|
88
|
+
return (_jsxs("svg", { "aria-hidden": "true", width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("path", { d: "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }), _jsx("path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0" })] }));
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=NotificationBell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationBell.js","sourceRoot":"","sources":["../../src/components/NotificationBell.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEvE,OAAO,EAGL,iBAAiB,IAAI,wBAAwB,EAC7C,wBAAwB,IAAI,kBAAkB,EAC9C,oBAAoB,IAAI,eAAe,EACvC,mBAAmB,EACnB,WAAW,IAAI,kBAAkB,GAClC,MAAM,gCAAgC,CAAA;AA+BvC,MAAM,UAAU,GAAqB;IACnC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC;IAC9C,MAAM,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;IAClC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC;IACrC,WAAW,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;CACxC,CAAA;AAcD,MAAM,UAAU,gBAAgB,CAAC,EAC/B,cAAc,GAAG,MAAM,EACvB,QAAQ,EACR,OAAO,EACP,GAAG,GAAG,UAAU,EAChB,SAAS,GACa;IACtB,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACvC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACvC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAiB,EAAE,CAAC,CAAA;IACtD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC7C,MAAM,UAAU,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,EAAE,EAAE,eACpB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,aAEtC,wBAAM,mBAAmB,CAAC,CAAC,CAAC,GAAO,EACnC,cAAK,SAAS,EAAC,kCAAkC,YAAE,CAAC,CAAC,SAAS,GAAO,IAC9D,IAbF,CAAC,CAAC,EAAE,CAcR,CACN,CAAC,GACC,CACN,GACG,IACF,CACP,IACG,CACP,CAAA;AACH,CAAC;AAED,SAAS,QAAQ;IACf,OAAO,CACL,8BACc,MAAM,EAClB,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,aAEtB,eAAM,CAAC,EAAC,2CAA2C,GAAG,EACtD,eAAM,CAAC,EAAC,gCAAgC,GAAG,IACvC,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CollaborationStatus, OfflinePersistenceStatus } from '../lib/collaboration-provider.js';
|
|
3
|
+
/**
|
|
4
|
+
* Compact connection + offline-draft indicator. Rendered alongside the
|
|
5
|
+
* presence chips above the editor toolbar so editors get a single,
|
|
6
|
+
* always-visible signal:
|
|
7
|
+
*
|
|
8
|
+
* - **Saved & synced** — IndexedDB store is ready and the gateway
|
|
9
|
+
* socket is connected.
|
|
10
|
+
* - **Saved locally** — IndexedDB ready but the socket is disconnected
|
|
11
|
+
* (offline drafts in flight; will sync on reconnect).
|
|
12
|
+
* - **Syncing local copy…** — IndexedDB is replaying the last snapshot
|
|
13
|
+
* into the doc. The editor is still usable but undo / cursor sync
|
|
14
|
+
* may flicker briefly.
|
|
15
|
+
* - **Local drafts unsupported** — `indexedDB` is unavailable; the
|
|
16
|
+
* editor will rely on the gateway only. Refresh loses uncommitted
|
|
17
|
+
* edits.
|
|
18
|
+
* - **Local drafts failed** — IndexedDB threw on init (quota, private
|
|
19
|
+
* browsing). Same risk as "unsupported", but with a different cause.
|
|
20
|
+
*
|
|
21
|
+
* Keeping the component dumb and prop-driven keeps the unit tests
|
|
22
|
+
* trivial — the parent owns the status transitions.
|
|
23
|
+
*/
|
|
24
|
+
export interface OfflineStatusProps {
|
|
25
|
+
connection: CollaborationStatus;
|
|
26
|
+
offline: OfflinePersistenceStatus;
|
|
27
|
+
}
|
|
28
|
+
export declare function OfflineStatus({ connection, offline }: OfflineStatusProps): React.JSX.Element;
|
|
29
|
+
export type OfflineTone = 'good' | 'warn' | 'info' | 'bad';
|
|
30
|
+
/**
|
|
31
|
+
* Pure helper that maps the (connection, offline) status pair to a
|
|
32
|
+
* single user-facing label + colour tone. Exported so the unit tests
|
|
33
|
+
* can exercise every combination without rendering React.
|
|
34
|
+
*/
|
|
35
|
+
export declare function describeOfflineStatus(connection: CollaborationStatus, offline: OfflinePersistenceStatus): {
|
|
36
|
+
label: string;
|
|
37
|
+
tone: OfflineTone;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=OfflineStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfflineStatus.d.ts","sourceRoot":"","sources":["../../src/components/OfflineStatus.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,kCAAkC,CAAA;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,mBAAmB,CAAA;IAC/B,OAAO,EAAE,wBAAwB,CAAA;CAClC;AAED,wBAAgB,aAAa,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,kBAAkB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAa5F;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,CAAA;AAgB1D;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,mBAAmB,EAC/B,OAAO,EAAE,wBAAwB,GAChC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAetC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
export function OfflineStatus({ connection, offline }) {
|
|
4
|
+
const { label, tone } = describeOfflineStatus(connection, offline);
|
|
5
|
+
const baseClass = 'inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-medium';
|
|
6
|
+
const toneClass = TONE_CLASSES[tone];
|
|
7
|
+
return (_jsxs("span", { className: `${baseClass} ${toneClass}`, "data-testid": "offline-status", "data-tone": tone, children: [_jsx("span", { "aria-hidden": "true", className: `inline-block h-1.5 w-1.5 rounded-full ${DOT_CLASSES[tone]}` }), label] }));
|
|
8
|
+
}
|
|
9
|
+
const TONE_CLASSES = {
|
|
10
|
+
good: 'bg-emerald-50 text-emerald-700',
|
|
11
|
+
warn: 'bg-amber-50 text-amber-800',
|
|
12
|
+
info: 'bg-blue-50 text-blue-700',
|
|
13
|
+
bad: 'bg-red-50 text-red-700',
|
|
14
|
+
};
|
|
15
|
+
const DOT_CLASSES = {
|
|
16
|
+
good: 'bg-emerald-500',
|
|
17
|
+
warn: 'bg-amber-500',
|
|
18
|
+
info: 'bg-blue-500',
|
|
19
|
+
bad: 'bg-red-500',
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Pure helper that maps the (connection, offline) status pair to a
|
|
23
|
+
* single user-facing label + colour tone. Exported so the unit tests
|
|
24
|
+
* can exercise every combination without rendering React.
|
|
25
|
+
*/
|
|
26
|
+
export function describeOfflineStatus(connection, offline) {
|
|
27
|
+
if (offline === 'error')
|
|
28
|
+
return { label: 'Local drafts failed', tone: 'bad' };
|
|
29
|
+
if (offline === 'unsupported') {
|
|
30
|
+
// No local persistence; the WebSocket is the only safety net.
|
|
31
|
+
if (connection === 'connected')
|
|
32
|
+
return { label: 'Synced', tone: 'good' };
|
|
33
|
+
if (connection === 'connecting')
|
|
34
|
+
return { label: 'Connecting…', tone: 'info' };
|
|
35
|
+
return { label: 'Offline — drafts not persisted', tone: 'warn' };
|
|
36
|
+
}
|
|
37
|
+
if (offline === 'loading' || offline === 'pending') {
|
|
38
|
+
return { label: 'Restoring local copy…', tone: 'info' };
|
|
39
|
+
}
|
|
40
|
+
// offline === 'ready' from here on.
|
|
41
|
+
if (connection === 'connected')
|
|
42
|
+
return { label: 'Saved & synced', tone: 'good' };
|
|
43
|
+
if (connection === 'connecting')
|
|
44
|
+
return { label: 'Saved locally — reconnecting…', tone: 'warn' };
|
|
45
|
+
return { label: 'Saved locally — offline', tone: 'warn' };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=OfflineStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OfflineStatus.js","sourceRoot":"","sources":["../../src/components/OfflineStatus.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAmCZ,MAAM,UAAU,aAAa,CAAC,EAAE,UAAU,EAAE,OAAO,EAAsB;IACvE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAClE,MAAM,SAAS,GAAG,8EAA8E,CAAA;IAChG,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,CACL,gBAAM,SAAS,EAAE,GAAG,SAAS,IAAI,SAAS,EAAE,iBAAc,gBAAgB,eAAY,IAAI,aACxF,8BACc,MAAM,EAClB,SAAS,EAAE,yCAAyC,WAAW,CAAC,IAAI,CAAC,EAAE,GACvE,EACD,KAAK,IACD,CACR,CAAA;AACH,CAAC;AAID,MAAM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,EAAE,CAAA;AAC3D,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
+
import { type CollaborationStatus } from '../lib/collaboration-provider.js';
|
|
3
|
+
export interface PresenceChipsProps {
|
|
4
|
+
/** Awareness instance returned from `createCollaborationProvider`. */
|
|
5
|
+
awareness: Awareness;
|
|
6
|
+
/**
|
|
7
|
+
* Optional connection status. When provided the strip renders a small
|
|
8
|
+
* status pill (Connected / Connecting / Disconnected) on the left side.
|
|
9
|
+
*/
|
|
10
|
+
status?: CollaborationStatus;
|
|
11
|
+
/**
|
|
12
|
+
* Hide the local user from the strip. Defaults to `true` — the local user
|
|
13
|
+
* already knows they're editing.
|
|
14
|
+
*/
|
|
15
|
+
hideSelf?: boolean;
|
|
16
|
+
/** Max chips to show before collapsing to "+N". Defaults to 5. */
|
|
17
|
+
maxVisible?: number;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Small avatar / initials strip showing who else is currently editing the
|
|
22
|
+
* document. Subscribes to the supplied `Awareness` instance for live
|
|
23
|
+
* updates.
|
|
24
|
+
*
|
|
25
|
+
* The component is intentionally stateless about transport — it only reads
|
|
26
|
+
* from Awareness and `status`. Wiring is the caller's job.
|
|
27
|
+
*/
|
|
28
|
+
export declare function PresenceChips({ awareness, status, hideSelf, maxVisible, className, }: PresenceChipsProps): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
/** Convert "Alice Cooper" → "AC", single names → "A", empty → "?". */
|
|
30
|
+
export declare function nameToInitials(name: string): string;
|
|
31
|
+
//# sourceMappingURL=PresenceChips.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresenceChips.d.ts","sourceRoot":"","sources":["../../src/components/PresenceChips.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,kCAAkC,CAAA;AAEzC,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,SAAS,EAAE,SAAS,CAAA;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,MAAM,EACN,QAAe,EACf,UAAc,EACd,SAAS,GACV,EAAE,kBAAkB,2CA8CpB;AAiDD,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUnD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { summarisePresence, } from '../lib/collaboration-provider.js';
|
|
5
|
+
/**
|
|
6
|
+
* Small avatar / initials strip showing who else is currently editing the
|
|
7
|
+
* document. Subscribes to the supplied `Awareness` instance for live
|
|
8
|
+
* updates.
|
|
9
|
+
*
|
|
10
|
+
* The component is intentionally stateless about transport — it only reads
|
|
11
|
+
* from Awareness and `status`. Wiring is the caller's job.
|
|
12
|
+
*/
|
|
13
|
+
export function PresenceChips({ awareness, status, hideSelf = true, maxVisible = 5, className, }) {
|
|
14
|
+
const [snapshot, setSnapshot] = useState(() => summarisePresence(awareness));
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const update = () => {
|
|
17
|
+
setSnapshot(summarisePresence(awareness));
|
|
18
|
+
};
|
|
19
|
+
update();
|
|
20
|
+
awareness.on('update', update);
|
|
21
|
+
awareness.on('change', update);
|
|
22
|
+
return () => {
|
|
23
|
+
awareness.off('update', update);
|
|
24
|
+
awareness.off('change', update);
|
|
25
|
+
};
|
|
26
|
+
}, [awareness]);
|
|
27
|
+
const visible = hideSelf
|
|
28
|
+
? snapshot.users.filter((u) => u.clientId !== snapshot.selfClientId)
|
|
29
|
+
: snapshot.users;
|
|
30
|
+
const overflow = Math.max(0, visible.length - maxVisible);
|
|
31
|
+
const shown = visible.slice(0, maxVisible);
|
|
32
|
+
return (_jsxs("div", { className: `inline-flex items-center gap-1.5 text-xs ${className ?? ''}`, "data-testid": "presence-chips", children: [status && _jsx(StatusPill, { status: status }), shown.length === 0 && status !== 'connecting' && (_jsx("span", { className: "text-gray-500", "data-testid": "presence-empty", children: "You're the only one here" })), shown.map(({ clientId, user }) => (_jsx(Chip, { name: user.name, color: user.color, avatarUrl: user.avatarUrl }, clientId))), overflow > 0 && (_jsxs("span", { className: "rounded-full bg-gray-100 px-2 py-0.5 text-gray-700", "data-testid": "presence-overflow", children: ["+", overflow] }))] }));
|
|
33
|
+
}
|
|
34
|
+
function StatusPill({ status }) {
|
|
35
|
+
const palette = {
|
|
36
|
+
connected: { dot: 'bg-emerald-500', label: 'Live', text: 'text-emerald-700' },
|
|
37
|
+
connecting: { dot: 'bg-amber-400 animate-pulse', label: 'Connecting', text: 'text-amber-700' },
|
|
38
|
+
disconnected: { dot: 'bg-gray-300', label: 'Offline', text: 'text-gray-500' },
|
|
39
|
+
};
|
|
40
|
+
const cfg = palette[status];
|
|
41
|
+
return (_jsxs("span", { className: `inline-flex items-center gap-1 rounded-full bg-gray-50 px-2 py-0.5 ${cfg.text}`, "data-testid": `presence-status-${status}`, children: [_jsx("span", { className: `h-1.5 w-1.5 rounded-full ${cfg.dot}` }), cfg.label] }));
|
|
42
|
+
}
|
|
43
|
+
function Chip({ name, color, avatarUrl }) {
|
|
44
|
+
const initials = nameToInitials(name);
|
|
45
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1 rounded-full bg-white px-1.5 py-0.5 ring-1 ring-gray-200", title: name, "data-testid": "presence-chip", children: [avatarUrl ? (_jsx("img", { src: avatarUrl, alt: "", className: "h-4 w-4 rounded-full object-cover", style: { boxShadow: `0 0 0 1.5px ${color}` } })) : (_jsx("span", { "aria-hidden": "true", className: "flex h-4 w-4 items-center justify-center rounded-full text-[8px] font-semibold text-white", style: { backgroundColor: color }, children: initials })), _jsx("span", { className: "max-w-[80px] truncate text-gray-700", children: name })] }));
|
|
46
|
+
}
|
|
47
|
+
/** Convert "Alice Cooper" → "AC", single names → "A", empty → "?". */
|
|
48
|
+
export function nameToInitials(name) {
|
|
49
|
+
const cleaned = name.trim();
|
|
50
|
+
if (!cleaned)
|
|
51
|
+
return '?';
|
|
52
|
+
const parts = cleaned.split(/\s+/).slice(0, 2);
|
|
53
|
+
return (parts
|
|
54
|
+
.map((p) => (p[0] ?? '').toUpperCase())
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.join('') || '?');
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=PresenceChips.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresenceChips.js","sourceRoot":"","sources":["../../src/components/PresenceChips.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGlD,OAAO,EACL,iBAAiB,GAGlB,MAAM,kCAAkC,CAAA;AAoBzC;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,SAAS,EACT,MAAM,EACN,QAAQ,GAAG,IAAI,EACf,UAAU,GAAG,CAAC,EACd,SAAS,GACU;IACnB,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAmB,GAAG,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAA;IAE9F,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,GAAG,EAAE;YAClB,WAAW,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAA;QAC3C,CAAC,CAAA;QACD,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,EAAC,2FAA2F,EACrG,KAAK,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,YAEhC,QAAQ,GACJ,CACR,EACD,eAAM,SAAS,EAAC,qCAAqC,YAAE,IAAI,GAAQ,IAC9D,CACR,CAAA;AACH,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;IAC3B,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,CAAA;IACxB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CACL,KAAK;SACF,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;SACtC,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,EAAE,CAAC,IAAI,GAAG,CACnB,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,69 @@
|
|
|
1
|
+
import { type CollaborationUser } from '../lib/collaboration-provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for real-time collaboration on this editor.
|
|
4
|
+
*
|
|
5
|
+
* When supplied the editor switches into CRDT mode: history is delegated to
|
|
6
|
+
* Yjs, edits sync through the cms-core realtime gateway, and a presence
|
|
7
|
+
* strip with live cursors appears beside the toolbar. The `content` prop is
|
|
8
|
+
* ignored in collaboration mode (the gateway is the source of truth);
|
|
9
|
+
* `onChange` still fires on every local update so existing autosave wiring
|
|
10
|
+
* keeps working.
|
|
11
|
+
*/
|
|
12
|
+
export interface TipTapCollaborationConfig {
|
|
13
|
+
documentId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Base URL of the realtime gateway. `wss://your.app/api/cms/realtime/sync`
|
|
16
|
+
* in production, `ws://localhost:3000/api/cms/realtime/sync` for dev.
|
|
17
|
+
*/
|
|
18
|
+
url: string;
|
|
19
|
+
user: CollaborationUser;
|
|
20
|
+
/** Extra query params (e.g. auth token for cross-origin deployments). */
|
|
21
|
+
params?: Record<string, string>;
|
|
22
|
+
}
|
|
1
23
|
export interface TipTapEditorProps {
|
|
2
24
|
content: string;
|
|
3
25
|
onChange: (html: string) => void;
|
|
4
26
|
placeholder?: string;
|
|
5
27
|
editable?: boolean;
|
|
6
28
|
className?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Toggle the AI co-author bubble menu on text selection.
|
|
31
|
+
* Defaults to `true` when the editor is editable. Set to `false` to opt
|
|
32
|
+
* out (e.g. for preview-only renders, or environments where the
|
|
33
|
+
* `/ai/coauthor` endpoint is intentionally disabled).
|
|
34
|
+
*/
|
|
35
|
+
enableAI?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Enable real-time collaboration via the cms-core realtime gateway. When
|
|
38
|
+
* set, the editor swaps in Yjs-backed history + the collaboration cursor
|
|
39
|
+
* extension and renders a presence strip above the toolbar.
|
|
40
|
+
*/
|
|
41
|
+
collaboration?: TipTapCollaborationConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Enable inline comments. When set, the `CommentMark` extension is
|
|
44
|
+
* loaded and a `CommentSidePanel` renders next to the editor. Anchors
|
|
45
|
+
* are encoded against the active Yjs text node when collaboration is
|
|
46
|
+
* also on, so highlights survive concurrent edits.
|
|
47
|
+
*
|
|
48
|
+
* Comments are independent of the collaboration prop — you can attach
|
|
49
|
+
* comments to a static document, but cross-user "live" highlighting
|
|
50
|
+
* only kicks in when collaboration is also enabled.
|
|
51
|
+
*/
|
|
52
|
+
comments?: TipTapCommentsConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for the comments side panel. The panel issues REST calls
|
|
56
|
+
* against the slice-4 endpoints; this prop is just the small set of
|
|
57
|
+
* presentation + identity bits the panel can't infer from the editor.
|
|
58
|
+
*/
|
|
59
|
+
export interface TipTapCommentsConfig {
|
|
60
|
+
documentId: string;
|
|
61
|
+
/** Logged-in user id — gates edit + delete affordances. */
|
|
62
|
+
currentUserId: string;
|
|
63
|
+
/** Set to true to expose moderation actions on every comment. */
|
|
64
|
+
isAdmin?: boolean;
|
|
65
|
+
/** Error sink so the host shell can show a toast. */
|
|
66
|
+
onError?: (message: string) => void;
|
|
7
67
|
}
|
|
8
|
-
export declare function TipTapEditor({ content, onChange, placeholder, editable, className, }: TipTapEditorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
68
|
+
export declare function TipTapEditor({ content, onChange, placeholder, editable, className, enableAI, collaboration, comments, }: TipTapEditorProps): import("react/jsx-runtime").JSX.Element | null;
|
|
9
69
|
//# sourceMappingURL=TipTapEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TipTapEditor.d.ts","sourceRoot":"","sources":["../../src/components/TipTapEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TipTapEditor.d.ts","sourceRoot":"","sources":["../../src/components/TipTapEditor.tsx"],"names":[],"mappings":"AAWA,OAAO,EAIL,KAAK,iBAAiB,EAEvB,MAAM,kCAAkC,CAAA;AAgDzC;;;;;;;;;GASG;AACH,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,iBAAiB,CAAA;IACvB,yEAAyE;IACzE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,yBAAyB,CAAA;IACzC;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAA;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAA;IACrB,iEAAiE;IACjE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qDAAqD;IACrD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACpC;AAwVD,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,QAAQ,EACR,WAAW,EACX,QAAe,EACf,SAAS,EACT,QAAe,EACf,aAAa,EACb,QAAQ,GACT,EAAE,iBAAiB,kDAiOnB"}
|