@openartifactsai/editor-kit 0.0.0-stage → 0.23.0-rc.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.
Files changed (120) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +143 -2
  4. package/package.json +67 -4
  5. package/src/Announcer.d.ts +2 -0
  6. package/src/Announcer.js +8 -0
  7. package/src/FindBar.d.ts +31 -0
  8. package/src/FindBar.js +37 -0
  9. package/src/FoldToolbar.d.ts +58 -0
  10. package/src/FoldToolbar.js +438 -0
  11. package/src/PanelEdge.d.ts +20 -0
  12. package/src/PanelEdge.js +74 -0
  13. package/src/VideoShrinkNotice.d.ts +10 -0
  14. package/src/VideoShrinkNotice.js +81 -0
  15. package/src/WheelZoomItem.d.ts +12 -0
  16. package/src/WheelZoomItem.js +18 -0
  17. package/src/agent.d.ts +68 -0
  18. package/src/agent.js +113 -0
  19. package/src/announce.d.ts +21 -0
  20. package/src/announce.js +31 -0
  21. package/src/chrome.d.ts +208 -0
  22. package/src/chrome.js +148 -0
  23. package/src/clipboard.d.ts +19 -0
  24. package/src/clipboard.js +48 -0
  25. package/src/collab/CommentList.d.ts +32 -0
  26. package/src/collab/CommentList.js +165 -0
  27. package/src/collab/CommentViews.d.ts +131 -0
  28. package/src/collab/CommentViews.js +619 -0
  29. package/src/collab/HistoryViews.d.ts +38 -0
  30. package/src/collab/HistoryViews.js +103 -0
  31. package/src/collab/PresenceViews.d.ts +53 -0
  32. package/src/collab/PresenceViews.js +48 -0
  33. package/src/collab/cds/cds.d.ts +151 -0
  34. package/src/collab/cds/cds.js +231 -0
  35. package/src/collab/cds/comment-card.d.ts +113 -0
  36. package/src/collab/cds/comment-card.js +230 -0
  37. package/src/collab/cds/comment-composer.d.ts +35 -0
  38. package/src/collab/cds/comment-composer.js +125 -0
  39. package/src/collab/cds/comments-css.d.ts +2 -0
  40. package/src/collab/cds/comments-css.js +3 -0
  41. package/src/collab/cds/comments.css +504 -0
  42. package/src/collab/cds/edge-piles.d.ts +69 -0
  43. package/src/collab/cds/edge-piles.js +178 -0
  44. package/src/collab/cds/layer.d.ts +41 -0
  45. package/src/collab/cds/layer.js +144 -0
  46. package/src/collab/cds/markdown.d.ts +20 -0
  47. package/src/collab/cds/markdown.js +534 -0
  48. package/src/collab/cds/shield.d.ts +28 -0
  49. package/src/collab/cds/shield.js +114 -0
  50. package/src/collab/cds/time.d.ts +2 -0
  51. package/src/collab/cds/time.js +41 -0
  52. package/src/collab/collab.d.ts +102 -0
  53. package/src/collab/collab.js +121 -0
  54. package/src/collab/comments.d.ts +272 -0
  55. package/src/collab/comments.js +596 -0
  56. package/src/collab/history-wiring.d.ts +32 -0
  57. package/src/collab/history-wiring.js +53 -0
  58. package/src/collab/history.d.ts +59 -0
  59. package/src/collab/history.js +96 -0
  60. package/src/collab/mentions/mention-list.d.ts +63 -0
  61. package/src/collab/mentions/mention-list.js +257 -0
  62. package/src/collab/mentions.d.ts +112 -0
  63. package/src/collab/mentions.js +164 -0
  64. package/src/collab/peer-colors.d.ts +123 -0
  65. package/src/collab/peer-colors.js +273 -0
  66. package/src/collab/pins.d.ts +70 -0
  67. package/src/collab/pins.js +44 -0
  68. package/src/collab/presence.d.ts +92 -0
  69. package/src/collab/presence.js +158 -0
  70. package/src/design-systems.d.ts +46 -0
  71. package/src/design-systems.js +61 -0
  72. package/src/downloads.d.ts +31 -0
  73. package/src/downloads.js +46 -0
  74. package/src/file-drop.d.ts +33 -0
  75. package/src/file-drop.js +36 -0
  76. package/src/find.d.ts +64 -0
  77. package/src/find.js +147 -0
  78. package/src/follow.d.ts +141 -0
  79. package/src/follow.js +389 -0
  80. package/src/index.d.ts +32 -0
  81. package/src/index.js +32 -0
  82. package/src/keys.d.ts +18 -0
  83. package/src/keys.js +42 -0
  84. package/src/menu-fit.d.ts +12 -0
  85. package/src/menu-fit.js +9 -0
  86. package/src/merge.d.ts +23 -0
  87. package/src/merge.js +116 -0
  88. package/src/page-link.d.ts +33 -0
  89. package/src/page-link.js +75 -0
  90. package/src/project-sync.d.ts +161 -0
  91. package/src/project-sync.js +319 -0
  92. package/src/react.d.ts +20 -0
  93. package/src/react.js +20 -0
  94. package/src/read-retries.d.ts +55 -0
  95. package/src/read-retries.js +125 -0
  96. package/src/right-drag-pan.d.ts +128 -0
  97. package/src/right-drag-pan.js +253 -0
  98. package/src/roles.d.ts +39 -0
  99. package/src/roles.js +27 -0
  100. package/src/session.d.ts +56 -0
  101. package/src/session.js +57 -0
  102. package/src/shell.d.ts +60 -0
  103. package/src/shell.js +111 -0
  104. package/src/stash.d.ts +26 -0
  105. package/src/stash.js +69 -0
  106. package/src/styles.css +17 -0
  107. package/src/toolbar-fold.d.ts +106 -0
  108. package/src/toolbar-fold.js +130 -0
  109. package/src/video-shrink/index.d.ts +8 -0
  110. package/src/video-shrink/index.js +7 -0
  111. package/src/video-shrink/plan.d.ts +92 -0
  112. package/src/video-shrink/plan.js +133 -0
  113. package/src/video-shrink/protocol.d.ts +29 -0
  114. package/src/video-shrink/protocol.js +2 -0
  115. package/src/video-shrink/queue.d.ts +69 -0
  116. package/src/video-shrink/queue.js +287 -0
  117. package/src/video-shrink/worker.d.ts +8 -0
  118. package/src/video-shrink/worker.js +223 -0
  119. package/src/wheel-zoom.d.ts +14 -0
  120. package/src/wheel-zoom.js +48 -0
@@ -0,0 +1,178 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn, Icon } from "./cds.js";
3
+ /** A tab's widest (above, below) or tallest (left, right). */
4
+ const PILE_MAX = 148;
5
+ /** A tab's thickness, and the room a tab at the bottom keeps over the toolbar. */
6
+ const PILE_GAP = 24;
7
+ /** The window needs this width for any tab. */
8
+ const MIN_WIDTH = 164;
9
+ /** …and this much height between its top inset and bottom for the top or bottom tab; more when both show. */
10
+ const MIN_HEIGHT = 64;
11
+ const MIN_HEIGHT_BOTH = 96;
12
+ /** …and this much for a side tab; more when the top or bottom tab comes near the window's corners. */
13
+ const SIDE_MIN_HEIGHT = 180;
14
+ const SIDE_MIN_HEIGHT_TIGHT = 228;
15
+ /** The most a toolbar at the bottom lifts the bottom tab. */
16
+ const FOOT_MAX = 120;
17
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
18
+ /** The part of the box below the top inset. */
19
+ function band(box, top) {
20
+ return { top: Math.max(box.top, top, 0), bottom: box.top + box.height };
21
+ }
22
+ /** Which edge a point (viewport px) is past, if any. */
23
+ export function sideOf(box, point, top) {
24
+ const { top: t, bottom } = band(box, top);
25
+ if (point.y < t)
26
+ return 'above';
27
+ if (point.y > bottom)
28
+ return 'below';
29
+ if (point.x < box.left)
30
+ return 'left';
31
+ if (point.x > box.left + box.width)
32
+ return 'right';
33
+ return 'in';
34
+ }
35
+ /** Where a side's tab goes (its anchor point and transform), or null when the window has no room for it. */
36
+ function place(box, side, minHeight, { top: inset, floor = 0, gutter = 0, reserveRight = 0 }) {
37
+ const { top, bottom } = band(box, Math.max(floor, inset));
38
+ const reserve = side === 'above' ? reserveRight : 0;
39
+ if (bottom - top < minHeight || box.width < MIN_WIDTH + reserve)
40
+ return null;
41
+ const middle = (top + bottom) / 2;
42
+ if (side === 'left')
43
+ return { left: box.left + gutter, top: middle, transform: 'translateY(-50%)' };
44
+ if (side === 'right')
45
+ return { left: box.left + box.width - gutter, top: middle, transform: 'translate(-100%, -50%)' };
46
+ const half = PILE_MAX / 2 + 8;
47
+ return {
48
+ left: clamp(box.left + box.width / 2, box.left + half, box.left + box.width - half - reserve),
49
+ top: side === 'above' ? top : bottom - gutter,
50
+ transform: side === 'above' ? 'translateX(-50%)' : 'translate(-50%, -100%)',
51
+ };
52
+ }
53
+ export function edgePiles({ points, openId, box, top, floor, foot, reserveRight }) {
54
+ const past = { above: [], below: [], left: [], right: [] };
55
+ const sideById = new Map();
56
+ for (const point of points) {
57
+ if (point.id === openId)
58
+ continue;
59
+ const side = sideOf(box, point, top);
60
+ if (side === 'in')
61
+ continue;
62
+ past[side].push(point);
63
+ sideById.set(point.id, side);
64
+ }
65
+ // Nearest the edge first: a click shows the first.
66
+ past.above.sort((a, b) => b.y - a.y);
67
+ past.below.sort((a, b) => a.y - b.y);
68
+ past.left.sort((a, b) => b.x - a.x);
69
+ past.right.sort((a, b) => a.x - b.x);
70
+ const minHeight = past.above.length > 0 && past.below.length > 0 ? MIN_HEIGHT_BOTH : MIN_HEIGHT;
71
+ const above = past.above.length ? place(box, 'above', minHeight, { top, floor, reserveRight }) : null;
72
+ const visible = band(box, Math.max(floor, top));
73
+ const lift = foot > 0 ? Math.min(foot, FOOT_MAX, Math.max(0, visible.bottom - visible.top - (past.above.length > 0 ? PILE_GAP : 0) - PILE_GAP)) : 0;
74
+ const below = past.below.length ? place(box, 'below', minHeight, { top, gutter: lift }) : null;
75
+ // The side tabs need more height when the top or bottom tab comes within a tab's thickness of the corners.
76
+ const room = [above, below].flatMap(style => style && typeof style.left === 'number' ? [style.left - PILE_MAX / 2 - box.left, box.left + box.width - (style.left + PILE_MAX / 2)] : []);
77
+ const near = room.length > 0 ? Math.min(...room) : null;
78
+ const sideMin = near !== null && near < PILE_GAP + 8 ? SIDE_MIN_HEIGHT_TIGHT : SIDE_MIN_HEIGHT;
79
+ const left = past.left.length ? place(box, 'left', sideMin, { top }) : null;
80
+ const right = past.right.length ? place(box, 'right', sideMin, { top }) : null;
81
+ const styles = { above, below, left, right };
82
+ const piled = new Set();
83
+ for (const [id, side] of sideById)
84
+ if (styles[side])
85
+ piled.add(id);
86
+ const sides = Object.fromEntries(Object.keys(past).map(side => [side, { ids: past[side].map(p => p.id), style: styles[side] }]));
87
+ return { sides, floating: lift > 0, piled };
88
+ }
89
+ // ---------- the tabs ----------
90
+ const PILE_CLASS = 'pointer-events-auto relative flex items-center gap-xs border bg-surface-popover text-secondary shadow-sm cursor-[var(--cds-cursor-interactive)] outline-none focus-visible:outline-hidden focus-visible:shadow-focus';
91
+ const SHAPE_CLASS = {
92
+ above: 'h-6 ps-xs pe-sm',
93
+ below: 'h-6 border-b-0 ps-xs pe-sm',
94
+ left: 'w-6 flex-col py-sm',
95
+ right: 'w-6 flex-col py-sm',
96
+ floating: 'h-6 rounded-[10px] ps-xs pe-sm',
97
+ };
98
+ const SHAPE_STYLE = {
99
+ above: { maxWidth: PILE_MAX, borderTopWidth: 0, borderBottomLeftRadius: 10, borderBottomRightRadius: 10 },
100
+ below: { maxWidth: PILE_MAX, borderTopLeftRadius: 10, borderTopRightRadius: 10 },
101
+ left: { maxHeight: PILE_MAX, borderLeftWidth: 0, borderTopRightRadius: 10, borderBottomRightRadius: 10 },
102
+ right: { maxHeight: PILE_MAX, borderRightWidth: 0, borderTopLeftRadius: 10, borderBottomLeftRadius: 10 },
103
+ floating: { maxWidth: PILE_MAX },
104
+ };
105
+ /** The caret points at the edge. */
106
+ const CARET_TURN = { above: 'rotate(180deg)', below: undefined, left: 'rotate(90deg)', right: 'rotate(-90deg)' };
107
+ const WHERE = { above: 'above', below: 'below', left: 'to the left', right: 'to the right' };
108
+ function Pile({ side, ids, style, floating, onOpen }) {
109
+ const count = ids.length;
110
+ const vertical = side === 'left' || side === 'right';
111
+ const shape = side === 'below' && floating ? 'floating' : side;
112
+ const caret = (_jsx("span", { "aria-hidden": true, className: "flex", style: { transform: CARET_TURN[side] }, children: _jsx(Icon, { name: "CaretDown", size: "xs", className: "opacity-60" }) }, "caret"));
113
+ const label = (_jsxs("span", { "aria-hidden": true, className: "flex min-h-0 min-w-0 items-baseline gap-1 overflow-hidden whitespace-nowrap text-caption leading-none", style: vertical ? { writingMode: 'vertical-rl', transform: side === 'left' ? 'rotate(180deg)' : undefined } : undefined, children: ["More comments", _jsx("span", { dir: "ltr", className: "text-muted tabular-nums", children: count > 99 ? '99+' : count })] }, "label"));
114
+ return (_jsx("div", { style: { position: 'fixed', ...style, pointerEvents: 'none' }, children: _jsx("button", { type: "button", "data-comment-edge-pile": side, "data-comment-edge-pile-threads": ids.join(' '), "aria-label": `More comments: jump to ${count === 1 ? '1 comment' : `${count} comments`} ${WHERE[side]}`, className: cn(PILE_CLASS, SHAPE_CLASS[shape]), style: SHAPE_STYLE[shape], onClick: () => ids[0] && onOpen(ids[0]), children: side === 'left' ? [label, caret] : [caret, label] }) }));
115
+ }
116
+ export function EdgePiles({ piles, onOpen }) {
117
+ return ['above', 'below', 'left', 'right'].map(side => {
118
+ const { ids, style } = piles.sides[side];
119
+ return style && ids.length > 0 ? _jsx(Pile, { side: side, ids: ids, style: style, floating: piles.floating, onOpen: onOpen }, side) : null;
120
+ });
121
+ }
122
+ // ---------- the pin stack ----------
123
+ export function stackPins(pins, right, size) {
124
+ const near = size * 0.75;
125
+ const overlaps = (a, ax, b, bx) => ax - bx < b.w - size + near && bx - ax < a.w - size + near && Math.abs(b.y - a.y) < near;
126
+ const sorted = [...pins].sort((a, b) => a.x - b.x || a.y - b.y);
127
+ const groups = [];
128
+ for (const pin of sorted) {
129
+ const group = groups.find(g => g.some(other => overlaps(pin, pin.x, other, other.x)));
130
+ if (group)
131
+ group.push(pin);
132
+ else
133
+ groups.push([pin]);
134
+ }
135
+ const layout = (group) => {
136
+ if (group.length < 2)
137
+ return group.map(p => p.x);
138
+ const start = group[0].x;
139
+ if (start + group.reduce((sum, p) => sum + p.w - 6, 6) > right) {
140
+ const xs = [];
141
+ let edge = start + group[0].w;
142
+ for (const p of group) {
143
+ xs.push(edge - p.w);
144
+ edge -= p.w - 6;
145
+ }
146
+ return xs;
147
+ }
148
+ let x = start;
149
+ return group.map(p => {
150
+ const at = x;
151
+ x += p.w - 6;
152
+ return at;
153
+ });
154
+ };
155
+ let merged = true;
156
+ while (merged && groups.length > 1) {
157
+ merged = false;
158
+ const xs = groups.map(layout);
159
+ outer: for (let i = 0; i < groups.length; i++) {
160
+ for (let j = i + 1; j < groups.length; j++) {
161
+ if (groups[i].some((a, ai) => groups[j].some((b, bi) => overlaps(a, xs[i][ai], b, xs[j][bi])))) {
162
+ groups[i] = [...groups[i], ...groups[j]].sort((a, b) => a.x - b.x || a.y - b.y);
163
+ groups.splice(j, 1);
164
+ merged = true;
165
+ break outer;
166
+ }
167
+ }
168
+ }
169
+ }
170
+ const shift = new Map();
171
+ for (const group of groups) {
172
+ if (group.length < 2)
173
+ continue;
174
+ const xs = layout(group);
175
+ group.forEach((p, i) => shift.set(p.id, xs[i] - p.x));
176
+ }
177
+ return shift;
178
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Where the comments UI draws: a shadow root carrying its own stylesheet (comments-css.ts, compiled from
3
+ * comments.css), so its class strings mean what they mean there and never meet the editor's own Tailwind.
4
+ *
5
+ * {@link CommentsLayer} is a shadow host in the editor's tree (a full-surface layer, a panel, a toolbar seat); its
6
+ * children are portalled into the shadow root under a `.cds-root` (density, light or dark from the page, rem scale).
7
+ * Views that may be drawn on their own (a thread card in a side panel) wrap themselves in one; inside a layer they
8
+ * draw straight into it ({@link useInLayer}).
9
+ *
10
+ * Events: every host joins one shield (shield.ts), installed when this module loads, so a key typed in a comment
11
+ * never reaches the editor's window and document listeners (its shortcuts), and presses in the layer never start its
12
+ * gestures. React still bubbles the layer's events up the editor's component tree (a portal's events do), so the
13
+ * layer stops them at its root (all but mouseup, which must reach the document).
14
+ */
15
+ import { type CSSProperties, type ReactNode } from 'react';
16
+ export declare const useInLayer: () => boolean;
17
+ /** Dark when the page says so (data-mode, data-theme, a dark/light class), else when the system is; and the root font scale. */
18
+ export declare function usePageTheme(win?: Window): {
19
+ dark: boolean;
20
+ remScale: number;
21
+ };
22
+ export interface CommentsLayerProps {
23
+ /** Classes of the host element (in the editor's tree, styled by the editor's CSS). */
24
+ className?: string;
25
+ style?: CSSProperties;
26
+ /** Laid out as `display: contents` inside the shadow root (the default), or as a flex row (a toolbar seat). */
27
+ inline?: boolean;
28
+ /** An Escape no view in the layer took (default: nothing). */
29
+ onEscape?(): boolean | void;
30
+ children: ReactNode;
31
+ /** A data attribute for the host, so an editor can find it. */
32
+ mark?: string;
33
+ }
34
+ /** A shadow host whose children draw with the comments styles (see the module comment). */
35
+ export declare function CommentsLayer({ className, style, inline, onEscape, children, mark }: CommentsLayerProps): ReactNode;
36
+ /** Draws `children` in a layer of their own unless already inside one. */
37
+ export declare function InLayer({ children, className, style }: {
38
+ children: ReactNode;
39
+ className?: string;
40
+ style?: CSSProperties;
41
+ }): ReactNode;
@@ -0,0 +1,144 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Where the comments UI draws: a shadow root carrying its own stylesheet (comments-css.ts, compiled from
4
+ * comments.css), so its class strings mean what they mean there and never meet the editor's own Tailwind.
5
+ *
6
+ * {@link CommentsLayer} is a shadow host in the editor's tree (a full-surface layer, a panel, a toolbar seat); its
7
+ * children are portalled into the shadow root under a `.cds-root` (density, light or dark from the page, rem scale).
8
+ * Views that may be drawn on their own (a thread card in a side panel) wrap themselves in one; inside a layer they
9
+ * draw straight into it ({@link useInLayer}).
10
+ *
11
+ * Events: every host joins one shield (shield.ts), installed when this module loads, so a key typed in a comment
12
+ * never reaches the editor's window and document listeners (its shortcuts), and presses in the layer never start its
13
+ * gestures. React still bubbles the layer's events up the editor's component tree (a portal's events do), so the
14
+ * layer stops them at its root (all but mouseup, which must reach the document).
15
+ */
16
+ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
17
+ import { isComposingKey } from '@openartifactsai/ui';
18
+ import { createContext, useContext, useEffect, useLayoutEffect, useState } from 'react';
19
+ import { createPortal } from 'react-dom';
20
+ import { COMMENTS_CSS } from "./comments-css.js";
21
+ import { CdsRootContext } from "./cds.js";
22
+ import { closeMenus } from "./comment-card.js";
23
+ import { installShield } from "./shield.js";
24
+ /** Set inside a layer: views draw straight into it. */
25
+ const InLayerContext = createContext(false);
26
+ export const useInLayer = () => useContext(InLayerContext);
27
+ let shield = null;
28
+ let sheet = null;
29
+ /** The window's shield, installed once (before an editor's own listeners, when this module loads in a browser). */
30
+ function shieldOf(win) {
31
+ shield ??= installShield(win, {
32
+ onPointerDown(inside, event) {
33
+ if (!inside) {
34
+ closeMenus();
35
+ return;
36
+ }
37
+ const target = event.composedPath()[0];
38
+ if (!(target instanceof win.Element) || !target.closest('[data-cds=Menu], [data-popup-open]'))
39
+ closeMenus();
40
+ },
41
+ });
42
+ return shield;
43
+ }
44
+ // The layer's font (Inter) is declared on the page by editor-kit's styles.css: @font-face is ignored in a shadow root.
45
+ if (typeof window !== 'undefined' && typeof document !== 'undefined')
46
+ shieldOf(window);
47
+ /** Puts the comments sheet in a shadow root: one constructed sheet shared by every layer, else a <style>. */
48
+ function adoptSheet(shadow) {
49
+ const win = shadow.ownerDocument.defaultView;
50
+ if (win && 'adoptedStyleSheets' in shadow && typeof win.CSSStyleSheet === 'function') {
51
+ try {
52
+ if (!sheet) {
53
+ sheet = new win.CSSStyleSheet();
54
+ sheet.replaceSync(COMMENTS_CSS);
55
+ }
56
+ shadow.adoptedStyleSheets = [sheet];
57
+ return;
58
+ }
59
+ catch {
60
+ // A sheet from another realm, or no constructable sheets: a <style> instead.
61
+ }
62
+ }
63
+ const style = shadow.ownerDocument.createElement('style');
64
+ style.textContent = COMMENTS_CSS;
65
+ shadow.append(style);
66
+ }
67
+ /** Dark when the page says so (data-mode, data-theme, a dark/light class), else when the system is; and the root font scale. */
68
+ export function usePageTheme(win = window) {
69
+ const read = () => {
70
+ const doc = win.document;
71
+ const html = doc.documentElement;
72
+ const attr = html.getAttribute('data-mode') ?? html.getAttribute('data-theme') ?? doc.body?.getAttribute('data-theme');
73
+ const system = win.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
74
+ const dark = attr === 'dark' || html.classList.contains('dark') || (attr !== 'light' && !html.classList.contains('light') && system);
75
+ const rootSize = Number.parseFloat(win.getComputedStyle(html).fontSize) || 16;
76
+ return { dark, remScale: 16 / rootSize };
77
+ };
78
+ const [theme, setTheme] = useState(read);
79
+ useEffect(() => {
80
+ const update = () => setTheme((prev) => {
81
+ const next = read();
82
+ return next.dark === prev.dark && next.remScale === prev.remScale ? prev : next;
83
+ });
84
+ const media = win.matchMedia?.('(prefers-color-scheme: dark)');
85
+ media?.addEventListener?.('change', update);
86
+ const observer = new MutationObserver(update);
87
+ observer.observe(win.document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-mode', 'class', 'style'] });
88
+ if (win.document.body)
89
+ observer.observe(win.document.body, { attributes: true, attributeFilter: ['data-theme'] });
90
+ return () => {
91
+ media?.removeEventListener?.('change', update);
92
+ observer.disconnect();
93
+ };
94
+ }, [win]);
95
+ return theme;
96
+ }
97
+ const stop = (event) => event.stopPropagation();
98
+ /** A shadow host whose children draw with the comments styles (see the module comment). */
99
+ export function CommentsLayer({ className, style, inline = false, onEscape, children, mark = 'data-comments-layer' }) {
100
+ const [host, setHost] = useState(null);
101
+ const [container, setContainer] = useState(null);
102
+ const [portal, setPortal] = useState(null);
103
+ const { dark, remScale } = usePageTheme();
104
+ useLayoutEffect(() => {
105
+ if (!host)
106
+ return;
107
+ const win = host.ownerDocument.defaultView;
108
+ const shadow = host.shadowRoot ?? host.attachShadow({ mode: 'open' });
109
+ if (!shadow.querySelector('[data-cds-container]')) {
110
+ adoptSheet(shadow);
111
+ const div = host.ownerDocument.createElement('div');
112
+ div.setAttribute('data-cds-container', '');
113
+ div.style.display = 'contents';
114
+ shadow.append(div);
115
+ }
116
+ setContainer(shadow.querySelector('[data-cds-container]'));
117
+ const release = win ? shieldOf(win).addHost(host) : undefined;
118
+ return () => release?.();
119
+ }, [host]);
120
+ const root = (_jsxs("div", { className: "cds-root", "data-density": "comfortable", "data-platform": "web", "data-mode": dark ? 'dark' : 'light', style: { '--cds-rem-scale': remScale, ...(inline ? { display: 'flex', alignItems: 'center' } : { display: 'contents' }) },
121
+ // The layer's events stop here: past it, React would hand them to the editor's components.
122
+ onPointerDown: stop, onPointerUp: stop, onPointerMove: stop, onMouseDown: stop,
123
+ // Not mouseup: React's stop stops the native event too, and Base UI's menus disarm their press-drag-release from
124
+ // a mouseup on the document (without it a menu item's click is taken twice). See shield.ts.
125
+ onClick: stop, onDoubleClick: stop, onContextMenu: stop, onWheel: stop, onKeyUp: stop, onKeyDown: (event) => {
126
+ event.stopPropagation();
127
+ if (event.key !== 'Escape')
128
+ return;
129
+ if (closeMenus()) {
130
+ event.preventDefault();
131
+ return;
132
+ }
133
+ if (!event.defaultPrevented && !isComposingKey(event.nativeEvent) && onEscape?.())
134
+ event.preventDefault();
135
+ }, children: [_jsx(CdsRootContext.Provider, { value: { container: portal, dark }, children: _jsx(InLayerContext.Provider, { value: true, children: _jsx(BaseTooltip.Provider, { children: children }) }) }), _jsx("div", { ref: setPortal, "data-layer-portal": "", style: { position: 'relative', zIndex: 60 } })] }));
136
+ const attrs = { [mark]: '' };
137
+ return (_jsx("div", { ref: setHost, className: className, style: style, ...attrs, children: container ? createPortal(root, container) : null }));
138
+ }
139
+ /** Draws `children` in a layer of their own unless already inside one. */
140
+ export function InLayer({ children, className, style }) {
141
+ if (useInLayer())
142
+ return children;
143
+ return (_jsx(CommentsLayer, { className: className, style: style, children: children }));
144
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Markdown in comment bodies: the small subset its comment cards
3
+ * render when the boot flag commentMarkdownEnabled is on. Fenced code, block quotes, ## to ###### headings (bold,
4
+ * not bigger), - / * / 1. lists, inline code, *em*, **strong**, ~~del~~. Links and bare URLs are kept out of emphasis but
5
+ * stay text. Block mode is a thread's card; flat mode (one run of text: quotes in italics, list items as "• " / "1. ")
6
+ * is a row in the "All comments" panel. Same limits, flanking rules and class strings.
7
+ *
8
+ * `mentions`: the `@names` a message names (the agent's, and the people in its `to`) are drawn in the accent colour
9
+ * wherever they stand in plain runs of text (not in code).
10
+ *
11
+ * Left out: the screen-reader text form (it labels the drawer's hidden "go to comment" button, which the local panel
12
+ * does not have).
13
+ */
14
+ import { type ReactNode } from 'react';
15
+ export declare const COMMENT_MARKDOWN = true;
16
+ /** A comment's text as React children: Markdown when it has any, else the text itself. flat: a panel row. */
17
+ export declare function commentMarkdown(text: string, { flat, mentions }?: {
18
+ flat?: boolean;
19
+ mentions?: readonly string[];
20
+ }): ReactNode;