@opengeni/react 6.1.0-canary.2 → 6.1.0-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +5 -0
  2. package/dist/{browser-viewer-NTD6UIPR.js → browser-viewer-LGH4IP47.js} +3 -3
  3. package/dist/chunk-AWEBVNVX.js +1398 -0
  4. package/dist/chunk-AWEBVNVX.js.map +1 -0
  5. package/dist/{chunk-NYESIADM.js → chunk-B7TTSUEW.js} +3 -1
  6. package/dist/chunk-B7TTSUEW.js.map +1 -0
  7. package/dist/{chunk-UWVY3OXF.js → chunk-BC7BFCMN.js} +277 -455
  8. package/dist/chunk-BC7BFCMN.js.map +1 -0
  9. package/dist/chunk-BRM6FVZA.js +302 -0
  10. package/dist/chunk-BRM6FVZA.js.map +1 -0
  11. package/dist/{chunk-KZ4QDBGM.js → chunk-GHSSI2BK.js} +925 -1265
  12. package/dist/chunk-GHSSI2BK.js.map +1 -0
  13. package/dist/{chunk-NLTS7JHI.js → chunk-JPHDWKZE.js} +5 -5
  14. package/dist/{chunk-L5VJYZIW.js → chunk-O53CQZ6T.js} +7 -7
  15. package/dist/{chunk-24M4YBCL.js → chunk-PNAVEK2U.js} +4 -4
  16. package/dist/components/preview-loading.d.ts +2 -0
  17. package/dist/composer.js +4 -4
  18. package/dist/connect-setup.d.ts +2 -0
  19. package/dist/connect.js +19 -8
  20. package/dist/connect.js.map +1 -1
  21. package/dist/index.js +27 -27
  22. package/dist/interaction.js +2 -2
  23. package/dist/machines.js +2 -2
  24. package/dist/plugin-discovery.d.ts +2 -0
  25. package/dist/realtime.js +20 -20
  26. package/dist/realtime.js.map +1 -1
  27. package/dist/session-ui.js +7 -7
  28. package/dist/session.js +3 -3
  29. package/package.json +3 -3
  30. package/src/components/markdown.tsx +13 -21
  31. package/src/components/preview-loading.tsx +154 -0
  32. package/src/connect-setup.tsx +17 -5
  33. package/src/hooks/use-composer.ts +6 -0
  34. package/src/plugin-discovery.tsx +10 -6
  35. package/src/realtime/realtime-control.tsx +6 -8
  36. package/styles/compiled.css +48 -8
  37. package/styles/index.css +45 -0
  38. package/dist/chunk-G5JFM6ZE.js +0 -911
  39. package/dist/chunk-G5JFM6ZE.js.map +0 -1
  40. package/dist/chunk-HQV2I5HV.js +0 -124
  41. package/dist/chunk-HQV2I5HV.js.map +0 -1
  42. package/dist/chunk-KZ4QDBGM.js.map +0 -1
  43. package/dist/chunk-NYESIADM.js.map +0 -1
  44. package/dist/chunk-UWVY3OXF.js.map +0 -1
  45. /package/dist/{browser-viewer-NTD6UIPR.js.map → browser-viewer-LGH4IP47.js.map} +0 -0
  46. /package/dist/{chunk-NLTS7JHI.js.map → chunk-JPHDWKZE.js.map} +0 -0
  47. /package/dist/{chunk-L5VJYZIW.js.map → chunk-O53CQZ6T.js.map} +0 -0
  48. /package/dist/{chunk-24M4YBCL.js.map → chunk-PNAVEK2U.js.map} +0 -0
@@ -1,911 +0,0 @@
1
- import {
2
- copyTextToClipboard,
3
- tableElementToTsv
4
- } from "./chunk-JVYQRRC4.js";
5
- import {
6
- Tooltip,
7
- TooltipContent,
8
- TooltipProvider,
9
- TooltipTrigger
10
- } from "./chunk-HQV2I5HV.js";
11
- import {
12
- cn
13
- } from "./chunk-22KP6LR5.js";
14
-
15
- // src/components/copy-button.tsx
16
- import { CheckIcon, CopyIcon } from "lucide-react";
17
- import { useEffect, useRef, useState } from "react";
18
- import { jsx, jsxs } from "react/jsx-runtime";
19
- var COPIED_MS = 1600;
20
- function CopyButton({
21
- text,
22
- label = "Copy",
23
- className,
24
- reveal = "group-hover"
25
- }) {
26
- const [copied, setCopied] = useState(false);
27
- const [tipOpen, setTipOpen] = useState(false);
28
- const timerRef = useRef(null);
29
- useEffect(() => {
30
- return () => {
31
- if (timerRef.current !== null) {
32
- clearTimeout(timerRef.current);
33
- }
34
- };
35
- }, []);
36
- const onClick = async (event) => {
37
- event.preventDefault();
38
- event.stopPropagation();
39
- const button = event.currentTarget;
40
- const pointerActivated = event.detail > 0;
41
- const value = typeof text === "function" ? text() : text;
42
- const ok = await copyTextToClipboard(value);
43
- if (!ok) {
44
- return;
45
- }
46
- setCopied(true);
47
- setTipOpen(true);
48
- if (timerRef.current !== null) {
49
- clearTimeout(timerRef.current);
50
- }
51
- timerRef.current = setTimeout(() => {
52
- timerRef.current = null;
53
- setCopied(false);
54
- setTipOpen(false);
55
- }, COPIED_MS);
56
- if (pointerActivated) {
57
- button.blur();
58
- }
59
- };
60
- const tip = copied ? "Copied" : label;
61
- return /* @__PURE__ */ jsxs(
62
- Tooltip,
63
- {
64
- open: copied ? true : tipOpen,
65
- onOpenChange: (next) => {
66
- if (!copied) {
67
- setTipOpen(next);
68
- }
69
- },
70
- children: [
71
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
72
- "button",
73
- {
74
- type: "button",
75
- "data-og-copy": "",
76
- "data-state": copied ? "copied" : "idle",
77
- "aria-label": tip,
78
- onClick,
79
- className: cn(
80
- "inline-flex size-7 shrink-0 items-center justify-center rounded-og-sm pointer-coarse:size-11",
81
- "text-og-fg-subtle transition-[opacity,color,background-color] duration-150",
82
- "hover:bg-og-surface-2/80 hover:text-og-fg",
83
- "focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-og-accent/40",
84
- reveal === "group-hover" && "opacity-0 group-hover/copy:opacity-100 group-focus-within/copy:opacity-100 pointer-coarse:opacity-70",
85
- copied && "opacity-100 text-og-accent",
86
- className
87
- ),
88
- children: copied ? /* @__PURE__ */ jsx(CheckIcon, { className: "size-3.5", "aria-hidden": true }) : /* @__PURE__ */ jsx(CopyIcon, { className: "size-3.5", "aria-hidden": true })
89
- }
90
- ) }),
91
- /* @__PURE__ */ jsx(TooltipContent, { side: "top", children: tip })
92
- ]
93
- }
94
- );
95
- }
96
- function CopyHoverFrame({
97
- children,
98
- className,
99
- copyText,
100
- label,
101
- align = "end",
102
- trailing
103
- }) {
104
- if (copyText.trim().length === 0) {
105
- return /* @__PURE__ */ jsx("div", { className, children });
106
- }
107
- return /* @__PURE__ */ jsxs("div", { className: cn("group/copy", className), children: [
108
- children,
109
- /* @__PURE__ */ jsxs(
110
- "div",
111
- {
112
- "data-og-annotation-chrome": "",
113
- className: cn(
114
- "flex h-6 items-center gap-1.5 pointer-coarse:h-11",
115
- align === "end" ? "justify-end" : "justify-start"
116
- ),
117
- children: [
118
- /* @__PURE__ */ jsx(
119
- CopyButton,
120
- {
121
- text: copyText,
122
- label,
123
- reveal: "group-hover",
124
- className: "size-6 pointer-coarse:size-11"
125
- }
126
- ),
127
- trailing
128
- ]
129
- }
130
- )
131
- ] });
132
- }
133
-
134
- // src/components/markdown.tsx
135
- import {
136
- Children,
137
- createContext,
138
- useContext,
139
- isValidElement,
140
- memo,
141
- useEffect as useEffect2,
142
- useMemo,
143
- useReducer,
144
- useRef as useRef2,
145
- useState as useState2
146
- } from "react";
147
- import ReactMarkdown, {
148
- defaultUrlTransform
149
- } from "react-markdown";
150
- import remarkGfm from "remark-gfm";
151
- import { LoaderCircleIcon } from "lucide-react";
152
-
153
- // src/lib/motion.ts
154
- import { flushSync } from "react-dom";
155
- var query;
156
- function prefersReducedMotion() {
157
- if (query === void 0) {
158
- query = typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(prefers-reduced-motion: reduce)") : null;
159
- }
160
- return query?.matches ?? false;
161
- }
162
-
163
- // src/lib/motion-inspect.ts
164
- var MOTION_INSPECT_SCALE = 1;
165
-
166
- // src/components/soften-streaming-markdown.ts
167
- function softenStreamingMarkdown(source) {
168
- if (source.length === 0) {
169
- return source;
170
- }
171
- let text = source;
172
- if (countFences(text) % 2 === 1) {
173
- text += text.endsWith("\n") ? "```" : "\n```";
174
- }
175
- const segments = splitByFences(text);
176
- for (const segment of segments) {
177
- if (segment.kind === "fence") {
178
- continue;
179
- }
180
- segment.value = closeInlineMarkers(segment.value);
181
- }
182
- let result = segments.map((segment) => segment.value).join("");
183
- if (text.endsWith("\n") && !result.endsWith("\n")) {
184
- result += "\n";
185
- }
186
- return result;
187
- }
188
- function countFences(text) {
189
- let count = 0;
190
- for (const line of text.split("\n")) {
191
- if (/^ {0,3}```/.test(line)) {
192
- count += 1;
193
- }
194
- }
195
- return count;
196
- }
197
- function splitByFences(text) {
198
- const segments = [];
199
- const lines = text.split("\n");
200
- let buf = [];
201
- let inFence = false;
202
- const flush = (kind, mode) => {
203
- if (buf.length === 0) {
204
- return;
205
- }
206
- let value = buf.join("\n");
207
- if (mode === "boundary") {
208
- value += "\n";
209
- }
210
- segments.push({ kind, value });
211
- buf = [];
212
- };
213
- for (const line of lines) {
214
- const isFence = /^ {0,3}```/.test(line);
215
- if (isFence) {
216
- if (inFence) {
217
- buf.push(line);
218
- flush("fence", "end");
219
- inFence = false;
220
- } else {
221
- flush("prose", "boundary");
222
- buf.push(line);
223
- inFence = true;
224
- }
225
- continue;
226
- }
227
- buf.push(line);
228
- }
229
- flush(inFence ? "fence" : "prose", "end");
230
- return segments;
231
- }
232
- function closeInlineMarkers(prose) {
233
- let text = prose;
234
- text = closeDelimiter(text, "~~");
235
- text = closeDelimiter(text, "**");
236
- text = closeDelimiter(text, "__");
237
- text = closeSingleBackticks(text);
238
- text = closeSingleAsterisks(text);
239
- text = closeUnfinishedLink(text);
240
- return text;
241
- }
242
- function closeDelimiter(text, delimiter) {
243
- let count = 0;
244
- let i = 0;
245
- while (i < text.length) {
246
- if (text[i] === "\\" && i + 1 < text.length) {
247
- i += 2;
248
- continue;
249
- }
250
- if (text.startsWith(delimiter, i)) {
251
- count += 1;
252
- i += delimiter.length;
253
- continue;
254
- }
255
- i += 1;
256
- }
257
- return count % 2 === 1 ? insertBeforeTrailingNewlines(text, delimiter) : text;
258
- }
259
- function insertBeforeTrailingNewlines(text, suffix) {
260
- let end = text.length;
261
- while (end > 0 && text[end - 1] === "\n") {
262
- end -= 1;
263
- }
264
- return text.slice(0, end) + suffix + text.slice(end);
265
- }
266
- function closeSingleBackticks(text) {
267
- let count = 0;
268
- for (let i = 0; i < text.length; i += 1) {
269
- if (text[i] === "\\" && i + 1 < text.length) {
270
- i += 1;
271
- continue;
272
- }
273
- if (text[i] === "`") {
274
- if (text.startsWith("```", i)) {
275
- i += 2;
276
- continue;
277
- }
278
- count += 1;
279
- }
280
- }
281
- return count % 2 === 1 ? insertBeforeTrailingNewlines(text, "`") : text;
282
- }
283
- function closeSingleAsterisks(text) {
284
- let count = 0;
285
- for (let i = 0; i < text.length; i += 1) {
286
- if (text[i] === "\\" && i + 1 < text.length) {
287
- i += 1;
288
- continue;
289
- }
290
- if (text[i] === "*" && text[i + 1] === "*") {
291
- i += 1;
292
- continue;
293
- }
294
- if (text[i] === "*") {
295
- count += 1;
296
- }
297
- }
298
- return count % 2 === 1 ? insertBeforeTrailingNewlines(text, "*") : text;
299
- }
300
- function closeUnfinishedLink(text) {
301
- const open = text.lastIndexOf("](");
302
- if (open === -1) {
303
- return text;
304
- }
305
- const after = text.slice(open + 2);
306
- if (after.includes(")")) {
307
- return text;
308
- }
309
- if (after.includes("[")) {
310
- return text;
311
- }
312
- return insertBeforeTrailingNewlines(text, ")");
313
- }
314
-
315
- // src/components/stream-reveal.ts
316
- var INK_FADE_MS = 420 * MOTION_INSPECT_SCALE;
317
- var INITIAL_ANIMATED_LIMIT = 400;
318
- function createStreamReveal() {
319
- let batches = [];
320
- let revealedChars = -1;
321
- return {
322
- observe(text, now) {
323
- if (revealedChars === -1) {
324
- revealedChars = text.length > INITIAL_ANIMATED_LIMIT ? text.length : 0;
325
- }
326
- if (text.length <= revealedChars) {
327
- revealedChars = Math.max(revealedChars, text.length);
328
- return;
329
- }
330
- batches.push({ start: revealedChars, end: text.length, birth: now });
331
- revealedChars = text.length;
332
- batches = batches.filter((batch) => batch.birth + INK_FADE_MS > now);
333
- },
334
- delayFor(offset, now) {
335
- const batch = findBatch(batches, offset);
336
- if (!batch) {
337
- return null;
338
- }
339
- const delay = batch.birth - now;
340
- return delay + INK_FADE_MS <= 0 ? null : delay;
341
- },
342
- hasActive(now) {
343
- const last = batches[batches.length - 1];
344
- return last !== void 0 && last.birth + INK_FADE_MS > now;
345
- }
346
- };
347
- }
348
- function findBatch(batches, offset) {
349
- let low = 0;
350
- let high = batches.length - 1;
351
- while (low <= high) {
352
- const mid = low + high >> 1;
353
- const batch = batches[mid];
354
- if (offset < batch.start) {
355
- high = mid - 1;
356
- } else if (offset >= batch.end) {
357
- low = mid + 1;
358
- } else {
359
- return batch;
360
- }
361
- }
362
- return null;
363
- }
364
- function rehypeStreamReveal(options) {
365
- const { reveal, now } = options;
366
- return (tree) => {
367
- walk(tree, false);
368
- };
369
- function walk(node, insideVerbatim) {
370
- if (!node.children) {
371
- return;
372
- }
373
- const verbatim = insideVerbatim || node.tagName === "code" || node.tagName === "pre";
374
- const next = [];
375
- for (const child of node.children) {
376
- if (child.type === "text" && !verbatim) {
377
- next.push(...splitTextNode(child));
378
- continue;
379
- }
380
- walk(child, verbatim);
381
- next.push(child);
382
- }
383
- node.children = next;
384
- }
385
- function splitTextNode(node) {
386
- const sourceOffset = node.position?.start?.offset;
387
- if (sourceOffset === void 0) {
388
- return [node];
389
- }
390
- const value = node.value;
391
- const out = [];
392
- let plain = "";
393
- const flushPlain = () => {
394
- if (plain.length > 0) {
395
- out.push({ type: "text", value: plain });
396
- plain = "";
397
- }
398
- };
399
- let i = 0;
400
- while (i < value.length) {
401
- const delay = reveal.delayFor(sourceOffset + i, now);
402
- let j = i + 1;
403
- while (j < value.length) {
404
- const nextDelay = reveal.delayFor(sourceOffset + j, now);
405
- if (nextDelay !== delay) {
406
- break;
407
- }
408
- j += 1;
409
- }
410
- const slice = value.slice(i, j);
411
- if (delay === null) {
412
- plain += slice;
413
- } else {
414
- flushPlain();
415
- out.push({
416
- type: "element",
417
- tagName: "span",
418
- properties: {
419
- className: ["og-stream-ink"],
420
- style: `animation-delay:${Math.round(delay)}ms`
421
- },
422
- children: [{ type: "text", value: slice }]
423
- });
424
- }
425
- i = j;
426
- }
427
- flushPlain();
428
- return out.length > 0 ? out : [node];
429
- }
430
- }
431
-
432
- // src/components/markdown.tsx
433
- import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
434
- var InteractiveContext = createContext({ source: "" });
435
- var baseComponents = {
436
- h1: ({ children, ...props }) => /* @__PURE__ */ jsx2(
437
- "h1",
438
- {
439
- className: "mt-5 mb-2.5 text-xl font-semibold tracking-tight text-og-fg first:mt-0",
440
- ...props,
441
- children
442
- }
443
- ),
444
- h2: ({ children, ...props }) => /* @__PURE__ */ jsx2("h2", { className: "mt-5 mb-2 text-lg font-semibold tracking-tight text-og-fg first:mt-0", ...props, children }),
445
- h3: ({ children, ...props }) => /* @__PURE__ */ jsx2(
446
- "h3",
447
- {
448
- className: "mt-4 mb-1.5 text-og-md font-semibold tracking-tight text-og-fg first:mt-0",
449
- ...props,
450
- children
451
- }
452
- ),
453
- h4: ({ children, ...props }) => /* @__PURE__ */ jsx2(
454
- "h4",
455
- {
456
- className: "mt-4 mb-1.5 text-og-sm font-semibold uppercase tracking-[0.04em] text-og-fg-muted first:mt-0",
457
- ...props,
458
- children
459
- }
460
- ),
461
- p: ({ children, ...props }) => /* @__PURE__ */ jsx2("p", { className: "my-2.5 leading-7 first:mt-0 last:mb-0", ...props, children }),
462
- strong: ({ children, ...props }) => /* @__PURE__ */ jsx2("strong", { className: "font-semibold text-og-fg", ...props, children }),
463
- em: ({ children, ...props }) => /* @__PURE__ */ jsx2("em", { className: "italic", ...props, children }),
464
- ul: ({ children, ...props }) => /* @__PURE__ */ jsx2(
465
- "ul",
466
- {
467
- className: "my-2.5 ml-5 flex list-disc flex-col gap-1 marker:text-og-fg-subtle first:mt-0 last:mb-0",
468
- ...props,
469
- children
470
- }
471
- ),
472
- ol: ({ children, ...props }) => /* @__PURE__ */ jsx2(
473
- "ol",
474
- {
475
- className: "my-2.5 ml-5 flex list-decimal flex-col gap-1 marker:text-og-fg-subtle first:mt-0 last:mb-0",
476
- ...props,
477
- children
478
- }
479
- ),
480
- // GFM task-list items carry a leading checkbox <input>; `list-none` + a
481
- // negative margin pull the checkbox back to the bullet column so it aligns
482
- // with the text.
483
- li: ({ children, ...props }) => /* @__PURE__ */ jsx2(
484
- "li",
485
- {
486
- className: "leading-7 marker:text-og-fg-subtle [&>ul]:my-1 [&>ol]:my-1 [&:has(>input)]:list-none [&:has(>input)]:-ml-5",
487
- ...props,
488
- children
489
- }
490
- ),
491
- input: ({ type, ...props }) => type === "checkbox" ? /* @__PURE__ */ jsx2(
492
- "input",
493
- {
494
- ...props,
495
- type: "checkbox",
496
- disabled: true,
497
- className: "mr-2 size-3.5 translate-y-[2px] cursor-default accent-og-accent align-baseline"
498
- }
499
- ) : /* @__PURE__ */ jsx2("input", { type, ...props }),
500
- blockquote: ({ children, ...props }) => /* @__PURE__ */ jsx2(
501
- "blockquote",
502
- {
503
- className: "my-3 border-l-2 border-og-border-strong pl-3.5 text-og-fg-muted [&>p]:my-1.5 first:mt-0 last:mb-0",
504
- ...props,
505
- children
506
- }
507
- ),
508
- hr: (props) => /* @__PURE__ */ jsx2("hr", { className: "my-4 border-0 border-t border-og-border", ...props }),
509
- // Inline `code` vs fenced code blocks. react-markdown v10 no longer passes an
510
- // `inline` flag; a fenced block is a <code> whose parent is <pre> (styled by
511
- // the `pre` renderer), so a `code` reaching here is treated as inline.
512
- code: ({ children, className: _className, ...props }) => /* @__PURE__ */ jsx2(
513
- "code",
514
- {
515
- className: "rounded-og-xs bg-og-surface-1 px-1 py-0.5 font-og-mono text-og-sm text-og-fg",
516
- ...props,
517
- children
518
- }
519
- ),
520
- // Fenced code — quiet mono block (no card / no nested vertical scroll).
521
- pre: InteractiveCodeBlock,
522
- // Tables stay unboxed (hairline rules); hover reveals a TSV copy control.
523
- table: ({ children, ...props }) => /* @__PURE__ */ jsx2(MarkdownTable, { ...props, children }),
524
- thead: ({ children, ...props }) => /* @__PURE__ */ jsx2("thead", { ...props, children }),
525
- th: ({ children, ...props }) => /* @__PURE__ */ jsx2(
526
- "th",
527
- {
528
- className: "border-b border-og-border px-0 py-1.5 pr-4 text-left font-medium text-og-fg first:pl-0",
529
- ...props,
530
- children
531
- }
532
- ),
533
- td: ({ children, ...props }) => /* @__PURE__ */ jsx2(
534
- "td",
535
- {
536
- className: "border-b border-og-border/70 px-0 py-1.5 pr-4 align-top text-og-fg-muted [tr:last-child>&]:border-b-0",
537
- ...props,
538
- children
539
- }
540
- ),
541
- img: MarkdownImage
542
- };
543
- var MARKDOWN_LINK_CLASS = "break-words font-medium text-og-accent-strong underline-offset-2 hover:underline";
544
- function markdownComponents(onSandboxFile) {
545
- return {
546
- ...baseComponents,
547
- a: ({ children, href, ...props }) => {
548
- const location = sandboxFileLocationFromHref(href);
549
- if (location !== null) {
550
- return /* @__PURE__ */ jsx2(SandboxMarkdownLink, { location, onSandboxFile, children });
551
- }
552
- if (isSandboxHref(href) || !href) {
553
- return /* @__PURE__ */ jsx2(
554
- "span",
555
- {
556
- className: "break-words font-medium text-og-fg-subtle underline decoration-dotted underline-offset-2",
557
- "aria-disabled": "true",
558
- title: isSandboxHref(href) ? "This sandbox file reference is invalid" : "This link is unavailable",
559
- children
560
- }
561
- );
562
- }
563
- return /* @__PURE__ */ jsx2(
564
- "a",
565
- {
566
- className: MARKDOWN_LINK_CLASS,
567
- target: "_blank",
568
- rel: "noreferrer noopener",
569
- href,
570
- ...props,
571
- children
572
- }
573
- );
574
- }
575
- };
576
- }
577
- function SandboxMarkdownLink({
578
- location,
579
- onSandboxFile,
580
- children
581
- }) {
582
- const [state, setState] = useState2("idle");
583
- const { path, line } = location;
584
- if (!onSandboxFile) {
585
- return /* @__PURE__ */ jsx2(
586
- "span",
587
- {
588
- className: "break-words font-medium text-og-fg-subtle underline decoration-dotted underline-offset-2",
589
- "aria-disabled": "true",
590
- title: "This sandbox file requires a session-aware handler",
591
- children
592
- }
593
- );
594
- }
595
- const idleTitle = line !== null ? `Open ${path} at line ${line}` : `Open ${path}`;
596
- return /* @__PURE__ */ jsxs2(
597
- "button",
598
- {
599
- type: "button",
600
- className: cn(
601
- MARKDOWN_LINK_CLASS,
602
- "inline-flex min-h-7 cursor-pointer items-center disabled:cursor-wait disabled:opacity-70 pointer-coarse:min-h-11"
603
- ),
604
- disabled: state === "loading",
605
- "aria-busy": state === "loading",
606
- title: state === "error" ? "Couldn't open this file. Select to retry." : idleTitle,
607
- onClick: () => {
608
- setState("loading");
609
- void Promise.resolve(onSandboxFile(path, line ?? void 0)).then(
610
- () => setState("idle"),
611
- () => setState("error")
612
- );
613
- },
614
- children: [
615
- children,
616
- state === "loading" ? " (opening\u2026)" : state === "error" ? " (retry)" : null
617
- ]
618
- }
619
- );
620
- }
621
- var SANDBOX_SCHEME = "sandbox:";
622
- var LEGACY_WORKSPACE_PREFIX = "/workspace/";
623
- var TRAILING_LINE = /:([0-9]+)$/u;
624
- var TRAILING_INVALID_LINE = /:-(?:[0-9]+)$|:[0-9]+-[0-9]+$/u;
625
- var CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/u;
626
- function isSandboxHref(href) {
627
- return href?.startsWith(SANDBOX_SCHEME) ?? false;
628
- }
629
- function sandboxFileLocationFromHref(href) {
630
- if (!href) return null;
631
- const encodedLocation = isSandboxHref(href) ? href.slice(SANDBOX_SCHEME.length) : href.startsWith(LEGACY_WORKSPACE_PREFIX) ? href : null;
632
- if (!encodedLocation || encodedLocation.includes("?") || encodedLocation.includes("#")) {
633
- return null;
634
- }
635
- if (TRAILING_INVALID_LINE.test(encodedLocation)) return null;
636
- const lineMatch = TRAILING_LINE.exec(encodedLocation);
637
- const encodedPath = lineMatch ? encodedLocation.slice(0, -lineMatch[0].length) : encodedLocation;
638
- const line = lineMatch?.[1] ? Number(lineMatch[1]) : null;
639
- if (line !== null && (!Number.isSafeInteger(line) || line < 1)) return null;
640
- if (!encodedPath) return null;
641
- try {
642
- const path = decodeURIComponent(encodedPath);
643
- return path && !CONTROL_CHARACTER.test(path) ? { path, line } : null;
644
- } catch {
645
- return null;
646
- }
647
- }
648
- function sandboxFilePathFromHref(href) {
649
- return sandboxFileLocationFromHref(href)?.path ?? null;
650
- }
651
- function retainedImageId(src) {
652
- return /^artifact:([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/i.exec(src)?.[1]?.toLowerCase() ?? null;
653
- }
654
- function MarkdownImage({ src, alt }) {
655
- const { renderImage } = useContext(InteractiveContext);
656
- if (!src) return /* @__PURE__ */ jsx2("span", { children: alt ?? "Image unavailable" });
657
- if (retainedImageId(src))
658
- return renderImage ? /* @__PURE__ */ jsx2(Fragment, { children: renderImage({ src, alt: alt ?? "" }) }) : /* @__PURE__ */ jsxs2("span", { children: [
659
- alt || "Image",
660
- " (preview unavailable)"
661
- ] });
662
- return /* @__PURE__ */ jsx2("img", { src, alt: alt ?? "", loading: "lazy", className: "my-3 max-w-full rounded-og-md" });
663
- }
664
- var markdownUrlTransform = (url, key, node) => key === "href" && node.tagName === "a" && isSandboxHref(url) || key === "src" && node.tagName === "img" && retainedImageId(url) ? url : defaultUrlTransform(url);
665
- var REVEAL_LINGER_MS = 480 * MOTION_INSPECT_SCALE;
666
- var MARKDOWN_SETTLE_MS = 480 * MOTION_INSPECT_SCALE;
667
- function nodeText(node) {
668
- if (node == null || typeof node === "boolean") {
669
- return "";
670
- }
671
- if (typeof node === "string" || typeof node === "number") {
672
- return String(node);
673
- }
674
- if (Array.isArray(node)) {
675
- return node.map(nodeText).join("");
676
- }
677
- if (isValidElement(node)) {
678
- return nodeText(node.props.children);
679
- }
680
- return "";
681
- }
682
- function fenceLanguage(children) {
683
- let found = null;
684
- Children.forEach(children, (child) => {
685
- if (found || !isValidElement(child)) {
686
- return;
687
- }
688
- const match = /language-([a-zA-Z0-9_+-]+)/.exec(child.props.className ?? "");
689
- if (match?.[1]) {
690
- found = match[1];
691
- }
692
- });
693
- return found;
694
- }
695
- function InteractiveCodeBlock({ children, node }) {
696
- const { source, render, streaming } = useContext(InteractiveContext);
697
- const language = fenceLanguage(children);
698
- if (render && (language === "opengeni-html" || language === "opengeni-site")) {
699
- const start = node?.position?.start.offset;
700
- const end = node?.position?.end.offset;
701
- const original = start !== void 0 && end !== void 0 && end <= source.length ? source.slice(start, end) : "";
702
- const lines = original.trimEnd().split("\n");
703
- const opening = lines[0]?.match(/^ {0,3}([\x60]{3,}|~{3,})/);
704
- const closing = lines.at(-1)?.replace(/^\s*(?:>\s*)+/, "").trim();
705
- const complete = opening && lines.length > 1 && closing && closing.length >= opening[1].length && [...closing].every((c) => c === opening[1][0]);
706
- if (!complete) {
707
- return /* @__PURE__ */ jsxs2(
708
- "div",
709
- {
710
- role: "status",
711
- "aria-live": "polite",
712
- "aria-busy": streaming === true,
713
- className: "my-3 flex min-h-32 items-center gap-3 rounded-og-md bg-og-surface-1/70 px-4 py-5",
714
- children: [
715
- streaming ? /* @__PURE__ */ jsx2(
716
- LoaderCircleIcon,
717
- {
718
- "aria-hidden": true,
719
- className: "size-5 shrink-0 text-og-fg-muted motion-safe:animate-spin"
720
- }
721
- ) : null,
722
- /* @__PURE__ */ jsxs2("div", { children: [
723
- /* @__PURE__ */ jsx2("div", { className: "text-og-sm font-medium text-og-fg", children: streaming ? "Preparing preview\u2026" : "Preview incomplete" }),
724
- /* @__PURE__ */ jsx2("div", { className: "mt-1 text-og-sm text-og-fg-muted", children: streaming ? "Generating the interactive content. It will appear here when ready." : "Generation stopped before the preview was ready." })
725
- ] })
726
- ]
727
- }
728
- );
729
- }
730
- return /* @__PURE__ */ jsx2(Fragment, { children: render({
731
- kind: language === "opengeni-html" ? "html" : "site",
732
- content: nodeText(children).replace(/\n$/, "")
733
- }) });
734
- }
735
- return /* @__PURE__ */ jsx2(MarkdownCodeBlock, { children });
736
- }
737
- function MarkdownCodeBlock({ children }) {
738
- const code = nodeText(children).replace(/\n$/, "");
739
- const language = fenceLanguage(children);
740
- return /* @__PURE__ */ jsxs2("div", { className: "group/copy relative mt-3 first:mt-0", children: [
741
- /* @__PURE__ */ jsxs2("div", { className: "pointer-events-none absolute top-1.5 right-1.5 z-10 flex items-center gap-1", children: [
742
- language ? /* @__PURE__ */ jsx2("span", { className: "rounded px-1 py-0.5 font-og-mono text-[10px] uppercase tracking-wide text-og-fg-subtle/80 opacity-0 transition-opacity group-hover/copy:opacity-100 pointer-coarse:opacity-70", children: language }) : null,
743
- /* @__PURE__ */ jsx2("div", { className: "pointer-events-auto", children: /* @__PURE__ */ jsx2(CopyButton, { text: code, label: "Copy code", reveal: "group-hover" }) })
744
- ] }),
745
- /* @__PURE__ */ jsx2(
746
- "pre",
747
- {
748
- tabIndex: 0,
749
- className: "overflow-x-auto overflow-y-hidden rounded-og-md bg-og-surface-1/70 px-3 py-2.5 font-og-mono text-og-sm leading-5 text-og-fg-muted [scrollbar-gutter:stable] [&>code]:block [&>code]:border-0 [&>code]:bg-transparent [&>code]:p-0 [&>code]:leading-5 [&>code]:text-inherit",
750
- children
751
- }
752
- )
753
- ] });
754
- }
755
- function MarkdownTable({ children, className, ...props }) {
756
- const wrapperRef = useRef2(null);
757
- const tableRef = useRef2(null);
758
- const layoutRef = useRef2(void 0);
759
- useEffect2(() => {
760
- const wrapper = wrapperRef.current;
761
- const table = tableRef.current;
762
- if (!wrapper?.closest("[data-og-wide-table-message]") || !table) return;
763
- let disposed = false;
764
- void import("./markdown-table-layout-PFUEZ2U4.js").then(({ observeMarkdownTableLayout }) => {
765
- if (!disposed) layoutRef.current = observeMarkdownTableLayout(wrapper, table);
766
- }).catch(() => {
767
- });
768
- return () => {
769
- disposed = true;
770
- layoutRef.current?.disconnect();
771
- layoutRef.current = void 0;
772
- };
773
- }, []);
774
- useEffect2(() => {
775
- layoutRef.current?.measure();
776
- }, [children]);
777
- return /* @__PURE__ */ jsxs2("div", { ref: wrapperRef, className: "group/copy relative mt-3 max-w-full first:mt-0", children: [
778
- /* @__PURE__ */ jsx2("div", { className: "pointer-events-none absolute top-0 right-0 z-10", children: /* @__PURE__ */ jsx2("div", { className: "pointer-events-auto", children: /* @__PURE__ */ jsx2(
779
- CopyButton,
780
- {
781
- text: () => tableElementToTsv(tableRef.current),
782
- label: "Copy table",
783
- reveal: "group-hover"
784
- }
785
- ) }) }),
786
- /* @__PURE__ */ jsx2("div", { className: "overflow-x-auto", tabIndex: 0, children: /* @__PURE__ */ jsx2(
787
- "table",
788
- {
789
- ref: tableRef,
790
- className: cn("w-full min-w-0 border-collapse text-og-base", className),
791
- ...props,
792
- children
793
- }
794
- ) })
795
- ] });
796
- }
797
- function MarkdownImpl({
798
- children,
799
- className,
800
- streaming = false,
801
- onSandboxFile,
802
- renderInteractiveBlock,
803
- renderImage
804
- }) {
805
- const revealRef = useRef2(null);
806
- const bodyRef = useRef2(null);
807
- const [, bump] = useReducer((n) => n + 1, 0);
808
- const [settling, setSettling] = useState2(false);
809
- const hadRevealRef = useRef2(false);
810
- const now = typeof performance !== "undefined" ? performance.now() : Date.now();
811
- const crystallize = (mutate) => {
812
- mutate();
813
- setSettling(true);
814
- bump();
815
- return setTimeout(() => setSettling(false), MARKDOWN_SETTLE_MS);
816
- };
817
- if (streaming && revealRef.current === null && !prefersReducedMotion()) {
818
- revealRef.current = createStreamReveal();
819
- }
820
- const reveal = revealRef.current;
821
- if (reveal !== null && streaming) {
822
- reveal.observe(children, now);
823
- }
824
- if (reveal !== null) {
825
- hadRevealRef.current = true;
826
- }
827
- const revealActive = reveal !== null && (streaming || reveal.hasActive(now));
828
- const rehypePlugins = revealActive && reveal !== null ? [[rehypeStreamReveal, { reveal, now }]] : void 0;
829
- useEffect2(() => {
830
- if (streaming || revealRef.current === null) {
831
- return;
832
- }
833
- let clearSettle;
834
- const timer = setTimeout(() => {
835
- const shouldSettle = hadRevealRef.current && !prefersReducedMotion();
836
- if (shouldSettle) {
837
- hadRevealRef.current = false;
838
- }
839
- if (shouldSettle) {
840
- clearSettle = crystallize(() => {
841
- revealRef.current = null;
842
- });
843
- } else {
844
- revealRef.current = null;
845
- bump();
846
- }
847
- }, REVEAL_LINGER_MS);
848
- return () => {
849
- clearTimeout(timer);
850
- if (clearSettle !== void 0) {
851
- clearTimeout(clearSettle);
852
- }
853
- };
854
- }, [streaming]);
855
- const wasStreamingRef = useRef2(streaming);
856
- useEffect2(() => {
857
- const ended = wasStreamingRef.current && !streaming;
858
- wasStreamingRef.current = streaming;
859
- if (!ended || revealRef.current !== null || prefersReducedMotion()) {
860
- return;
861
- }
862
- setSettling(true);
863
- const timer = setTimeout(() => setSettling(false), MARKDOWN_SETTLE_MS);
864
- return () => clearTimeout(timer);
865
- }, [streaming]);
866
- const parseText = streaming || revealActive ? softenStreamingMarkdown(children) : children;
867
- const components = useMemo(() => markdownComponents(onSandboxFile), [onSandboxFile]);
868
- const interactiveContext = useMemo(
869
- () => ({
870
- source: children,
871
- streaming,
872
- ...renderInteractiveBlock ? { render: renderInteractiveBlock } : {},
873
- ...renderImage ? { renderImage } : {}
874
- }),
875
- [children, streaming, renderInteractiveBlock, renderImage]
876
- );
877
- return /* @__PURE__ */ jsx2(InteractiveContext.Provider, { value: interactiveContext, children: /* @__PURE__ */ jsx2(TooltipProvider, { delayDuration: 400, children: /* @__PURE__ */ jsx2(
878
- "div",
879
- {
880
- ref: bodyRef,
881
- className: cn(
882
- "og-markdown-body min-w-0 break-words",
883
- settling && "og-markdown-settle",
884
- className
885
- ),
886
- children: /* @__PURE__ */ jsx2(
887
- ReactMarkdown,
888
- {
889
- remarkPlugins: [remarkGfm],
890
- rehypePlugins,
891
- components,
892
- urlTransform: markdownUrlTransform,
893
- children: parseText
894
- }
895
- )
896
- }
897
- ) }) });
898
- }
899
- var Markdown = memo(MarkdownImpl);
900
-
901
- export {
902
- prefersReducedMotion,
903
- MOTION_INSPECT_SCALE,
904
- CopyButton,
905
- CopyHoverFrame,
906
- sandboxFileLocationFromHref,
907
- sandboxFilePathFromHref,
908
- retainedImageId,
909
- Markdown
910
- };
911
- //# sourceMappingURL=chunk-G5JFM6ZE.js.map