@crewlethq/ui 0.17.0 → 0.18.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 (146) hide show
  1. package/README.md +36 -1
  2. package/dist/AccessDeniedCard/AccessDeniedCard.d.ts +39 -0
  3. package/dist/AccessDeniedCard/index.d.ts +3 -0
  4. package/dist/AccessDeniedCard/index.js +8 -0
  5. package/dist/AccessDeniedCard-WXM5DBDZ.css +8 -0
  6. package/dist/ArtifactCard/ArtifactCard.d.ts +61 -0
  7. package/dist/ArtifactCard/index.d.ts +3 -0
  8. package/dist/ArtifactCard/index.js +12 -0
  9. package/dist/ArtifactCard-EXVAEBV6.css +109 -0
  10. package/dist/AvatarPicker/index.js +4 -4
  11. package/dist/ChangeMark/ChangeMark.d.ts +26 -0
  12. package/dist/ChangeMark/index.d.ts +3 -0
  13. package/dist/ChangeMark/index.js +8 -0
  14. package/dist/ChangeMark-3VMTW7MT.css +22 -0
  15. package/dist/Combobox/index.js +1 -1
  16. package/dist/CommandPalette/index.js +3 -3
  17. package/dist/CursorFlag/CursorFlag.d.ts +34 -0
  18. package/dist/CursorFlag/index.d.ts +3 -0
  19. package/dist/CursorFlag/index.js +3 -0
  20. package/dist/CursorFlag-AJQJBUGY.css +61 -0
  21. package/dist/DataTable/index.js +6 -6
  22. package/dist/DataView/index.js +12 -12
  23. package/dist/DateTimePicker/index.js +2 -2
  24. package/dist/FollowBanner/FollowBanner.d.ts +35 -0
  25. package/dist/FollowBanner/index.d.ts +2 -0
  26. package/dist/FollowBanner/index.js +7 -0
  27. package/dist/FrameProtocol/index.d.ts +2 -0
  28. package/dist/FrameProtocol/index.js +2 -0
  29. package/dist/FrameProtocol/protocol.d.ts +164 -0
  30. package/dist/HuePicker/index.js +2 -2
  31. package/dist/LinkInterstitial/LinkInterstitial.d.ts +41 -0
  32. package/dist/LinkInterstitial/index.d.ts +3 -0
  33. package/dist/LinkInterstitial/index.js +11 -0
  34. package/dist/LinkInterstitial-ET4MSVSV.css +34 -0
  35. package/dist/ListInput/index.js +1 -1
  36. package/dist/LiveCursor/LiveCursor.d.ts +34 -0
  37. package/dist/LiveCursor/index.d.ts +3 -0
  38. package/dist/LiveCursor/index.js +4 -0
  39. package/dist/LiveCursor-DZHGIYWE.css +47 -0
  40. package/dist/MarkdownEditor/index.js +2 -2
  41. package/dist/Modal/index.js +2 -2
  42. package/dist/OrgTable/index.js +2 -2
  43. package/dist/PresenceModel/index.d.ts +2 -0
  44. package/dist/PresenceModel/index.js +3 -0
  45. package/dist/PresenceModel/presence.d.ts +80 -0
  46. package/dist/PresenceRing/PresenceRing.d.ts +31 -0
  47. package/dist/PresenceRing/index.d.ts +3 -0
  48. package/dist/PresenceRing/index.js +2 -0
  49. package/dist/PresenceRing-M4C22Q6U.css +68 -0
  50. package/dist/PresenceStack/PresenceStack.d.ts +36 -0
  51. package/dist/PresenceStack/index.d.ts +3 -0
  52. package/dist/PresenceStack/index.js +9 -0
  53. package/dist/PresenceStack-QSXQJND5.css +59 -0
  54. package/dist/PricingCard/index.js +2 -2
  55. package/dist/Principal/Principal.d.ts +35 -0
  56. package/dist/Principal/index.d.ts +2 -0
  57. package/dist/Principal/index.js +4 -0
  58. package/dist/PrincipalPicker/PrincipalPicker.d.ts +45 -0
  59. package/dist/PrincipalPicker/index.d.ts +3 -0
  60. package/dist/PrincipalPicker/index.js +12 -0
  61. package/dist/PrincipalPicker-7NNZTGUP.css +41 -0
  62. package/dist/SandboxedFrame/SandboxedFrame.d.ts +142 -0
  63. package/dist/SandboxedFrame/index.d.ts +3 -0
  64. package/dist/SandboxedFrame/index.js +8 -0
  65. package/dist/SandboxedFrame-L6HBQZCD.css +50 -0
  66. package/dist/ShareDialog/ShareDialog.d.ts +101 -0
  67. package/dist/ShareDialog/index.d.ts +5 -0
  68. package/dist/ShareDialog/index.js +19 -0
  69. package/dist/ShareDialog/roles.d.ts +10 -0
  70. package/dist/ShareDialog-YZ4F37MW.css +146 -0
  71. package/dist/SheetGrid/SheetGrid.d.ts +78 -0
  72. package/dist/SheetGrid/cells.d.ts +117 -0
  73. package/dist/SheetGrid/index.d.ts +5 -0
  74. package/dist/SheetGrid/index.js +18 -0
  75. package/dist/SheetGrid-4HOXDVIB.css +595 -0
  76. package/dist/SheetModel/clipboard.d.ts +37 -0
  77. package/dist/SheetModel/edits.d.ts +68 -0
  78. package/dist/SheetModel/index.d.ts +14 -0
  79. package/dist/SheetModel/index.js +3 -0
  80. package/dist/SheetModel/labels.d.ts +71 -0
  81. package/dist/SheetModel/navigation.d.ts +79 -0
  82. package/dist/SheetModel/options.d.ts +28 -0
  83. package/dist/SheetModel/types.d.ts +126 -0
  84. package/dist/SheetModel/values.d.ts +76 -0
  85. package/dist/SheetModel/view.d.ts +32 -0
  86. package/dist/Switcher/index.js +5 -5
  87. package/dist/Tag/Tag.d.ts +13 -0
  88. package/dist/Tag/index.js +1 -1
  89. package/dist/{Tag-4BRQS6GN.css → Tag-SRGTK5KI.css} +42 -0
  90. package/dist/TagsInput/index.js +2 -2
  91. package/dist/ThemeSwitcher/apply.d.ts +43 -0
  92. package/dist/ThemeSwitcher/index.d.ts +4 -2
  93. package/dist/ThemeSwitcher/index.js +3 -2
  94. package/dist/ThemeSwitcher/preferences.d.ts +2 -19
  95. package/dist/ThemeToggle/index.js +3 -2
  96. package/dist/TimeWindowPicker/index.js +3 -3
  97. package/dist/Timeline/Timeline.d.ts +7 -2
  98. package/dist/Timeline/index.js +1 -1
  99. package/dist/VersionTimeline/VersionTimeline.d.ts +76 -0
  100. package/dist/VersionTimeline/index.d.ts +3 -0
  101. package/dist/VersionTimeline/index.js +10 -0
  102. package/dist/VersionTimeline-EBJ6MIPJ.css +108 -0
  103. package/dist/{chunk-SBRE7IML.js → chunk-2ONWEDQT.js} +1 -1
  104. package/dist/chunk-2YR5ZPQ3.js +216 -0
  105. package/dist/chunk-3BYIWOTV.js +29 -0
  106. package/dist/chunk-3UAA4IWJ.js +98 -0
  107. package/dist/chunk-4KP4RC3O.js +25 -0
  108. package/dist/chunk-4U3GQ7D2.js +99 -0
  109. package/dist/chunk-5XACKNYR.js +53 -0
  110. package/dist/{chunk-RF5O4FYL.js → chunk-76FXDZAZ.js} +2 -2
  111. package/dist/chunk-A7EBCHEG.js +49 -0
  112. package/dist/{chunk-JCO3SIST.js → chunk-AQCV62K6.js} +1 -1
  113. package/dist/{chunk-O67VF5MS.js → chunk-AUQPBL4O.js} +2 -2
  114. package/dist/{chunk-HENOTGUV.js → chunk-BOW2VUCH.js} +2 -2
  115. package/dist/{chunk-UCYIRDND.js → chunk-DQSXWQMJ.js} +1 -1
  116. package/dist/chunk-ESKP3TXM.js +1 -0
  117. package/dist/chunk-F6V2PTN6.js +142 -0
  118. package/dist/chunk-FW7HN6AP.js +40 -0
  119. package/dist/chunk-FYXRWBJJ.js +1235 -0
  120. package/dist/{chunk-LOECRMHA.js → chunk-GFV4LJHH.js} +4 -3
  121. package/dist/chunk-I6POAB4V.js +20 -0
  122. package/dist/{chunk-PQ63NLFC.js → chunk-IFKBDRNJ.js} +1 -1
  123. package/dist/{chunk-XU4H6JQB.js → chunk-KVT3TJVG.js} +4 -4
  124. package/dist/chunk-LFZ45HV2.js +46 -0
  125. package/dist/{chunk-6TSZCBID.js → chunk-NP2C4Y4E.js} +1 -1
  126. package/dist/{chunk-FA2V2VT6.js → chunk-NZY77ZDU.js} +3 -3
  127. package/dist/chunk-PPAQFGS2.js +12 -0
  128. package/dist/chunk-S35G6PNC.js +80 -0
  129. package/dist/chunk-VYDFB6PJ.js +243 -0
  130. package/dist/chunk-WXAULPBH.js +135 -0
  131. package/dist/chunk-YM3GJHGW.js +69 -0
  132. package/dist/chunk-YYZRLLLY.js +822 -0
  133. package/dist/{chunk-K3OWD7BJ.js → chunk-Z24ZUSTX.js} +4 -19
  134. package/dist/chunk-ZXXDZJQN.js +36 -0
  135. package/dist/generated/index.d.ts +18 -0
  136. package/dist/generated/index.js +82 -62
  137. package/dist/index.js +82 -62
  138. package/dist/styles.css +1578 -149
  139. package/dist/utils/index.js +1 -1
  140. package/package.json +6 -6
  141. package/dist/{chunk-DEEVA6TV.js → chunk-2TZATTIU.js} +1 -1
  142. package/dist/{chunk-2UU5IGZI.js → chunk-5NVKTB6E.js} +1 -1
  143. package/dist/{chunk-CRVETI5L.js → chunk-CENOOTAV.js} +0 -0
  144. package/dist/{chunk-JF7X673Z.js → chunk-ERV5BUS3.js} +1 -1
  145. package/dist/{chunk-NXDEPUVG.js → chunk-PA4CYTBY.js} +1 -1
  146. package/dist/{chunk-77IEHFY4.js → chunk-QQGWES46.js} +1 -1
@@ -1,12 +1,13 @@
1
1
  import { StatusDot } from './chunk-WIATRXEJ.js';
2
2
  import { cx } from './chunk-ODEQTPFM.js';
3
- import './Tag-4BRQS6GN.css';
3
+ import './Tag-SRGTK5KI.css';
4
4
  import { XGlyph } from '@crewlethq/icons/glyphs';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
 
7
7
  function Tag(props) {
8
8
  const {
9
9
  variant = "neutral",
10
+ hue,
10
11
  appearance = "soft",
11
12
  size = "sm",
12
13
  leadingIcon,
@@ -31,7 +32,7 @@ function Tag(props) {
31
32
  const drawnSize = acts && size === "xs" ? "sm" : size;
32
33
  const classes = cx(
33
34
  "crewlet-tag",
34
- `crewlet-tag--${variant}`,
35
+ hue === void 0 ? `crewlet-tag--${variant}` : `crewlet-tag--hue-${hue}`,
35
36
  `crewlet-tag--${appearance}`,
36
37
  `crewlet-tag--${drawnSize}`,
37
38
  monospace && "crewlet-tag--monospace",
@@ -48,7 +49,7 @@ function Tag(props) {
48
49
  className
49
50
  );
50
51
  const inner = /* @__PURE__ */ jsxs(Fragment, { children: [
51
- dot ? /* @__PURE__ */ jsx(StatusDot, { tone: variant, className: "crewlet-tag__dot" }) : null,
52
+ dot ? /* @__PURE__ */ jsx(StatusDot, { tone: hue === void 0 ? variant : "neutral", className: "crewlet-tag__dot" }) : null,
52
53
  leadingIcon ? /* @__PURE__ */ jsx("span", { className: "crewlet-tag__icon", "aria-hidden": true, children: leadingIcon }) : null,
53
54
  /* @__PURE__ */ jsx("span", { className: "crewlet-tag__label", children }),
54
55
  count === void 0 ? null : /* @__PURE__ */ jsx("span", { className: "crewlet-tag__count", children: count })
@@ -0,0 +1,20 @@
1
+ import { cx } from './chunk-ODEQTPFM.js';
2
+ import './PresenceRing-M4C22Q6U.css';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ function presenceHueClass(hue) {
6
+ return `crewlet-presence-hue--${hue}`;
7
+ }
8
+ function PresenceRing({ hue, state = "active", inset = 1, className, style, children, ...rest }) {
9
+ return /* @__PURE__ */ jsx(
10
+ "span",
11
+ {
12
+ ...rest,
13
+ className: cx("crewlet-presence-ring", presenceHueClass(hue), state === "idle" && "crewlet-presence-ring--idle", className),
14
+ style: { "--crewlet-presence-ring-inset": `${inset}px`, ...style },
15
+ children
16
+ }
17
+ );
18
+ }
19
+
20
+ export { PresenceRing, presenceHueClass };
@@ -1,4 +1,4 @@
1
- import { Modal } from './chunk-DEEVA6TV.js';
1
+ import { Modal } from './chunk-2TZATTIU.js';
2
2
  import { useListbox, useHighlightRest } from './chunk-F73MC7EZ.js';
3
3
  import { Kbd } from './chunk-SMBKXWML.js';
4
4
  import { Input } from './chunk-4GB57WIT.js';
@@ -1,15 +1,15 @@
1
- import { RelativeTime } from './chunk-3CZ7XAVY.js';
2
1
  import { PageHeader } from './chunk-HOXGBLEY.js';
3
2
  import { Toolbar } from './chunk-PGRPNDWM.js';
4
- import { DataTable } from './chunk-RF5O4FYL.js';
3
+ import { DataTable } from './chunk-76FXDZAZ.js';
5
4
  import { Menu } from './chunk-NS7BVLL3.js';
6
- import { DateTimePicker } from './chunk-2UU5IGZI.js';
5
+ import { DateTimePicker } from './chunk-5NVKTB6E.js';
7
6
  import { useListbox, useOptionKeys } from './chunk-F73MC7EZ.js';
8
7
  import { Kbd } from './chunk-SMBKXWML.js';
9
8
  import { Input } from './chunk-4GB57WIT.js';
9
+ import { Popover } from './chunk-BWRGFKJP.js';
10
10
  import { Button } from './chunk-OG6CL3EB.js';
11
11
  import { IconButton } from './chunk-4FQT6ZAY.js';
12
- import { Popover } from './chunk-BWRGFKJP.js';
12
+ import { RelativeTime } from './chunk-3CZ7XAVY.js';
13
13
  import { Count } from './chunk-BHHIIK3M.js';
14
14
  import { VisuallyHidden } from './chunk-BZFWDIV6.js';
15
15
  import { cx } from './chunk-ODEQTPFM.js';
@@ -0,0 +1,46 @@
1
+ import { EmptyState } from './chunk-RA2ULG6H.js';
2
+ import { Card } from './chunk-EG6NYWVK.js';
3
+ import { cx } from './chunk-ODEQTPFM.js';
4
+ import './AccessDeniedCard-WXM5DBDZ.css';
5
+ import { ShieldGlyph, LockGlyph, EyeOffGlyph } from '@crewlethq/icons/glyphs';
6
+ import { jsx } from 'react/jsx-runtime';
7
+
8
+ var ACCESS_DENIED_REASONS = ["not-found", "no-access", "revoked", "app-locked"];
9
+ var LABELS = {
10
+ titles: {
11
+ "not-found": "This artifact does not exist, or it has not been shared with you",
12
+ "no-access": "You do not have access to this artifact",
13
+ revoked: "Your access to this artifact ended",
14
+ "app-locked": "Needs Artifacts access"
15
+ },
16
+ descriptions: {
17
+ "not-found": () => "Check the link, or ask whoever sent it to share the artifact with you.",
18
+ "no-access": (owner) => owner ? `Ask ${owner} to share it with you.` : "Ask its owner to share it with you.",
19
+ revoked: (owner) => owner ? `${owner} removed your access, or narrowed who can open it. Ask them if you still need it.` : "Its owner removed your access, or narrowed who can open it. Ask them if you still need it.",
20
+ "app-locked": () => "Your role does not include Artifacts. Ask an administrator to give you access."
21
+ }
22
+ };
23
+ var GLYPHS = {
24
+ "not-found": /* @__PURE__ */ jsx(EyeOffGlyph, { size: 32 }),
25
+ "no-access": /* @__PURE__ */ jsx(LockGlyph, { size: 32 }),
26
+ revoked: /* @__PURE__ */ jsx(LockGlyph, { size: 32 }),
27
+ "app-locked": /* @__PURE__ */ jsx(ShieldGlyph, { size: 32 })
28
+ };
29
+ function AccessDeniedCard({ reason, owner, action, headingLevel, className, labels }) {
30
+ const text = {
31
+ titles: { ...LABELS.titles, ...labels?.titles },
32
+ descriptions: { ...LABELS.descriptions, ...labels?.descriptions }
33
+ };
34
+ return /* @__PURE__ */ jsx(Card, { padding: "lg", className: cx("crewlet-access-denied-card", className), "data-reason": reason, children: /* @__PURE__ */ jsx(
35
+ EmptyState,
36
+ {
37
+ icon: GLYPHS[reason],
38
+ title: text.titles[reason],
39
+ description: text.descriptions[reason](owner),
40
+ action,
41
+ headingLevel
42
+ }
43
+ ) });
44
+ }
45
+
46
+ export { ACCESS_DENIED_REASONS, AccessDeniedCard };
@@ -1,4 +1,4 @@
1
- import { useThemePreference, useSystemTheme, resolveTheme } from './chunk-K3OWD7BJ.js';
1
+ import { useThemePreference, useSystemTheme, resolveTheme } from './chunk-Z24ZUSTX.js';
2
2
  import { IconButton } from './chunk-4FQT6ZAY.js';
3
3
  import { SunGlyph, MoonGlyph } from '@crewlethq/icons/glyphs';
4
4
  import { jsx } from 'react/jsx-runtime';
@@ -1,11 +1,11 @@
1
1
  import { Skeleton } from './chunk-W5J7R5EB.js';
2
- import { Modal } from './chunk-DEEVA6TV.js';
2
+ import { Modal } from './chunk-2TZATTIU.js';
3
3
  import { useListbox, useOptionKeys } from './chunk-F73MC7EZ.js';
4
- import { Input } from './chunk-4GB57WIT.js';
5
4
  import { KeyChip, highlightMatch } from './chunk-FYTIJM2T.js';
5
+ import { Input } from './chunk-4GB57WIT.js';
6
+ import { Popover } from './chunk-BWRGFKJP.js';
6
7
  import { announce } from './chunk-RSAQOKH3.js';
7
8
  import { useMediaMatch } from './chunk-IG75YMUN.js';
8
- import { Popover } from './chunk-BWRGFKJP.js';
9
9
  import { focusables, isComposing } from './chunk-R25RGPUB.js';
10
10
  import { VisuallyHidden } from './chunk-BZFWDIV6.js';
11
11
  import { cx } from './chunk-ODEQTPFM.js';
@@ -0,0 +1,12 @@
1
+ import { changeText, sheetLabels } from './chunk-YYZRLLLY.js';
2
+ import { Tooltip } from './chunk-QWOPX2MN.js';
3
+ import { cx } from './chunk-ODEQTPFM.js';
4
+ import './ChangeMark-3VMTW7MT.css';
5
+ import { jsx } from 'react/jsx-runtime';
6
+
7
+ function ChangeMark({ by, at, previous = null, locale, className, labels }) {
8
+ const text = changeText({ by, at }, sheetLabels(labels), previous, locale);
9
+ return /* @__PURE__ */ jsx(Tooltip, { content: text, children: /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: cx("crewlet-change-mark", className) }) });
10
+ }
11
+
12
+ export { ChangeMark };
@@ -0,0 +1,80 @@
1
+ import { NODE_HUES } from './chunk-AYKXMIOR.js';
2
+
3
+ // src/PresenceModel/presence.ts
4
+ var PRESENCE_ACTIVITIES = ["editing", "viewing", "idle"];
5
+ var BAND = {
6
+ editing: { human: 0, agent: 1 },
7
+ viewing: { human: 2, agent: 3 },
8
+ idle: { human: 4, agent: 5 }
9
+ };
10
+ function presenceOrder(members) {
11
+ return members.map((member, index) => ({ member, index })).sort((a, b) => BAND[a.member.activity][a.member.kind] - BAND[b.member.activity][b.member.kind] || a.index - b.index).map(({ member }) => member);
12
+ }
13
+ var LIVELINESS = { editing: 2, viewing: 1, idle: 0 };
14
+ function collapseSessions(members) {
15
+ const bySeat = /* @__PURE__ */ new Map();
16
+ const out = [];
17
+ for (const member of members) {
18
+ if (member.seat === void 0) {
19
+ out.push(member);
20
+ continue;
21
+ }
22
+ const at = bySeat.get(member.seat);
23
+ if (at === void 0) {
24
+ bySeat.set(member.seat, out.length);
25
+ out.push(member);
26
+ } else if (LIVELINESS[member.activity] > LIVELINESS[out[at].activity]) {
27
+ out[at] = member;
28
+ }
29
+ }
30
+ return out;
31
+ }
32
+ function assignPresenceHues(members, held = /* @__PURE__ */ new Map()) {
33
+ const out = /* @__PURE__ */ new Map();
34
+ const uses = new Map(NODE_HUES.map((hue) => [hue, 0]));
35
+ const take = (id, hue) => {
36
+ out.set(id, hue);
37
+ uses.set(hue, (uses.get(hue) ?? 0) + 1);
38
+ };
39
+ for (const member of members) {
40
+ if (member.kind === "agent" && member.hue !== void 0) take(member.id, member.hue);
41
+ }
42
+ for (const member of members) {
43
+ if (out.has(member.id)) continue;
44
+ const previous = held.get(member.id);
45
+ if (previous !== void 0) take(member.id, previous);
46
+ }
47
+ for (const member of members) {
48
+ if (out.has(member.id)) continue;
49
+ let pick = NODE_HUES[0];
50
+ for (const hue of NODE_HUES) if ((uses.get(hue) ?? 0) < (uses.get(pick) ?? 0)) pick = hue;
51
+ take(member.id, pick);
52
+ }
53
+ return out;
54
+ }
55
+ function joinNames(names, shown = 2) {
56
+ if (names.length === 0) return "";
57
+ if (names.length === 1) return names[0];
58
+ if (names.length <= shown) return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
59
+ const rest = names.length - shown;
60
+ return `${names.slice(0, shown).join(", ")} and ${rest === 1 ? "1 other" : `${rest} others`}`;
61
+ }
62
+ var PRESENCE_LABELS = {
63
+ activity: (activity, kind) => activity === "editing" ? "Editing" : activity === "idle" ? "Idle" : kind === "agent" ? "Reading" : "Viewing",
64
+ here: (others, withSelf) => {
65
+ if (withSelf) return others === 0 ? "Only you are here" : `You and ${others === 1 ? "1 other" : `${others} others`} are here`;
66
+ return others === 1 ? "1 person is here" : `${others} people are here`;
67
+ },
68
+ member: (member) => {
69
+ if (member.location) return `${member.name}, ${member.location}`;
70
+ return `${member.name}, ${PRESENCE_LABELS.activity(member.activity, member.kind).toLowerCase()}`;
71
+ },
72
+ more: (count) => `${count} more`,
73
+ editing: (names) => `${names} is editing`,
74
+ alsoHere: (names) => names.length === 0 ? "" : `${joinNames(names)} ${names.length === 1 ? "is" : "are"} also here.`
75
+ };
76
+ function presenceLabels(overrides) {
77
+ return { ...PRESENCE_LABELS, ...overrides };
78
+ }
79
+
80
+ export { PRESENCE_ACTIVITIES, PRESENCE_LABELS, assignPresenceHues, collapseSessions, joinNames, presenceLabels, presenceOrder };
@@ -0,0 +1,243 @@
1
+ import { Skeleton } from './chunk-W5J7R5EB.js';
2
+ import { frameThemeMessage, readFrameHello, frameOriginMatches, negotiateBridge, FRAME_MESSAGE, portTargetOrigin, checkFrameSandbox, httpOrigin, isFrameNonce, frameFragment, readOpenLink, externalUrl, isFocusExit } from './chunk-F6V2PTN6.js';
3
+ import { Callout } from './chunk-SVSCLHHI.js';
4
+ import { Button } from './chunk-OG6CL3EB.js';
5
+ import { cx } from './chunk-ODEQTPFM.js';
6
+ import './SandboxedFrame-L6HBQZCD.css';
7
+ import { useState, useMemo, useRef, useEffect } from 'react';
8
+ import { jsx, jsxs } from 'react/jsx-runtime';
9
+
10
+ var LABELS = {
11
+ loading: (title) => `Loading ${title}`,
12
+ failed: "This page failed to load.",
13
+ failedDetail: "It did not finish starting. Reload it, and if it fails again, ask its owner to republish it.",
14
+ navigated: "This page left its frame, so it was closed.",
15
+ navigatedDetail: "An artifact may only show its own pages. Reload it to open it again.",
16
+ refused: "This page cannot be shown safely.",
17
+ refusedDetail: "It arrived with a frame policy this dashboard does not accept.",
18
+ outdated: "This page needs a newer dashboard.",
19
+ outdatedDetail: "Reload the dashboard to update it, then open the page again.",
20
+ reload: "Reload"
21
+ };
22
+ var FRAME_HELLO_TIMEOUT_MS = 1e4;
23
+ function framePolicy(src, origin, mode, sandbox, nonce, theme) {
24
+ const verdict = checkFrameSandbox(sandbox, mode);
25
+ if (!verdict.ok) return { ok: false, refusal: { kind: "sandbox", tokens: verdict.refused } };
26
+ const served = httpOrigin(src);
27
+ if (served === null) return { ok: false, refusal: { kind: "src" } };
28
+ const named = mode === "per_artifact" ? origin === served : origin === served || origin === "null";
29
+ if (!named) return { ok: false, refusal: { kind: "src" } };
30
+ if (!isFrameNonce(nonce)) return { ok: false, refusal: { kind: "nonce" } };
31
+ const url = new URL(src);
32
+ url.hash = frameFragment(nonce, theme);
33
+ return { ok: true, url: url.href, sandbox: verdict.value, origin: served };
34
+ }
35
+ function SandboxedFrame(props) {
36
+ const { src, nonce, origin, mode, sandbox } = props;
37
+ return /* @__PURE__ */ jsx(FrameInstance, { ...props }, [src, nonce, origin, mode, sandbox].join("\n"));
38
+ }
39
+ function FrameInstance(props) {
40
+ const {
41
+ src,
42
+ origin,
43
+ mode,
44
+ sandbox,
45
+ allow,
46
+ title,
47
+ theme,
48
+ nonce,
49
+ onReady: _onReady,
50
+ onMessage: _onMessage,
51
+ onOpenLink: _onOpenLink,
52
+ onFocusExit: _onFocusExit,
53
+ onStateChange: _onStateChange,
54
+ onRefusal: _onRefusal,
55
+ onReload,
56
+ helloTimeoutMs = FRAME_HELLO_TIMEOUT_MS,
57
+ labels,
58
+ className,
59
+ ...rest
60
+ } = props;
61
+ const text = { ...LABELS, ...labels };
62
+ const [initialTheme] = useState(theme);
63
+ const policy = useMemo(
64
+ () => framePolicy(src, origin, mode, sandbox, nonce, initialTheme),
65
+ [src, origin, mode, sandbox, nonce, initialTheme]
66
+ );
67
+ const [state, setState] = useState(policy.ok ? "loading" : "refused");
68
+ const latest = useRef(props);
69
+ latest.current = props;
70
+ const frameRef = useRef(null);
71
+ const regionRef = useRef(null);
72
+ const portRef = useRef(null);
73
+ useEffect(() => {
74
+ if (!policy.ok) latest.current.onRefusal?.(policy.refusal);
75
+ }, [policy]);
76
+ useEffect(() => {
77
+ latest.current.onStateChange?.(state);
78
+ }, [state]);
79
+ useEffect(() => {
80
+ if (!policy.ok) return void 0;
81
+ const frame = frameRef.current;
82
+ if (!frame) return void 0;
83
+ let ended = false;
84
+ let greeted = 0;
85
+ let credit = false;
86
+ let owed = false;
87
+ let loadTimer;
88
+ const refuse = (refusal) => latest.current.onRefusal?.(refusal);
89
+ const closePort = () => {
90
+ portRef.current?.close();
91
+ portRef.current = null;
92
+ };
93
+ const end = (next) => {
94
+ ended = true;
95
+ clearTimeout(mountTimer);
96
+ clearTimeout(loadTimer);
97
+ closePort();
98
+ setState(next);
99
+ };
100
+ const onPortMessage = (port, event) => {
101
+ if (ended || portRef.current !== port) return;
102
+ const data = event.data;
103
+ const raw = readOpenLink(data);
104
+ if (raw !== null) {
105
+ const url = externalUrl(raw);
106
+ if (url) latest.current.onOpenLink?.(url);
107
+ else refuse({ kind: "link", url: raw });
108
+ return;
109
+ }
110
+ if (isFocusExit(data)) {
111
+ const exit = latest.current.onFocusExit;
112
+ if (exit) exit();
113
+ else regionRef.current?.focus();
114
+ return;
115
+ }
116
+ latest.current.onMessage?.(data, port);
117
+ };
118
+ const onWindowMessage = (event) => {
119
+ if (ended || event.source === null || event.source !== frame.contentWindow) return;
120
+ const hello = readFrameHello(event.data);
121
+ if (!hello) return;
122
+ if (!frameOriginMatches(mode, policy.origin, event.origin)) {
123
+ refuse({ kind: "origin", origin: event.origin });
124
+ return;
125
+ }
126
+ if (hello.nonce !== nonce) {
127
+ refuse({ kind: "hello-nonce" });
128
+ return;
129
+ }
130
+ if (greeted > 0 && (mode === "shared" || credit)) {
131
+ refuse({ kind: "rehello" });
132
+ if (mode === "shared") end("navigated");
133
+ return;
134
+ }
135
+ const bridge = negotiateBridge(hello.bridge);
136
+ if (bridge === null) {
137
+ refuse({ kind: "bridge", offered: hello.bridge });
138
+ end("outdated");
139
+ return;
140
+ }
141
+ const channel = new MessageChannel();
142
+ const message = { type: FRAME_MESSAGE.port, bridge };
143
+ event.source.postMessage(message, {
144
+ targetOrigin: portTargetOrigin(mode, policy.origin),
145
+ transfer: [channel.port2]
146
+ });
147
+ closePort();
148
+ const port = channel.port1;
149
+ portRef.current = port;
150
+ port.onmessage = (portEvent) => onPortMessage(port, portEvent);
151
+ port.postMessage(frameThemeMessage(latest.current.theme));
152
+ greeted += 1;
153
+ clearTimeout(mountTimer);
154
+ if (owed) {
155
+ owed = false;
156
+ clearTimeout(loadTimer);
157
+ } else {
158
+ credit = true;
159
+ }
160
+ setState("ready");
161
+ latest.current.onReady?.(port, hello);
162
+ };
163
+ const onLoad = () => {
164
+ if (ended) return;
165
+ if (credit) {
166
+ credit = false;
167
+ return;
168
+ }
169
+ owed = true;
170
+ clearTimeout(loadTimer);
171
+ loadTimer = setTimeout(() => end(greeted > 0 ? "navigated" : "failed"), helloTimeoutMs);
172
+ };
173
+ window.addEventListener("message", onWindowMessage);
174
+ frame.addEventListener("load", onLoad);
175
+ const mountTimer = setTimeout(() => {
176
+ if (greeted === 0) end("failed");
177
+ }, helloTimeoutMs);
178
+ return () => {
179
+ ended = true;
180
+ window.removeEventListener("message", onWindowMessage);
181
+ frame.removeEventListener("load", onLoad);
182
+ clearTimeout(mountTimer);
183
+ clearTimeout(loadTimer);
184
+ closePort();
185
+ };
186
+ }, [policy, mode, nonce, helloTimeoutMs]);
187
+ const { mode: themeMode, palette, density } = theme;
188
+ useEffect(() => {
189
+ portRef.current?.postMessage(frameThemeMessage({ mode: themeMode, palette, density }));
190
+ }, [themeMode, palette, density]);
191
+ const live = policy.ok && (state === "loading" || state === "ready");
192
+ const ending = END_TEXT[state];
193
+ const credentialless = { credentialless: "" };
194
+ return /* @__PURE__ */ jsxs(
195
+ "div",
196
+ {
197
+ ...rest,
198
+ ref: regionRef,
199
+ role: "region",
200
+ "aria-label": title,
201
+ "aria-busy": state === "loading" || void 0,
202
+ tabIndex: -1,
203
+ "data-state": state,
204
+ className: cx("crewlet-sandboxed-frame", className),
205
+ children: [
206
+ live ? /* @__PURE__ */ jsx(
207
+ "iframe",
208
+ {
209
+ ref: frameRef,
210
+ className: "crewlet-sandboxed-frame__frame",
211
+ src: policy.url,
212
+ sandbox: policy.sandbox,
213
+ allow: allow ?? "",
214
+ title,
215
+ referrerPolicy: "no-referrer",
216
+ ...credentialless
217
+ }
218
+ ) : null,
219
+ state === "loading" ? /* @__PURE__ */ jsx("div", { className: "crewlet-sandboxed-frame__loading", children: /* @__PURE__ */ jsx(Skeleton, { variant: "box", width: "100%", height: "100%", label: text.loading(title) }) }) : null,
220
+ ending ? /* @__PURE__ */ jsx("div", { className: "crewlet-sandboxed-frame__end", children: /* @__PURE__ */ jsx(
221
+ Callout,
222
+ {
223
+ variant: "danger",
224
+ title: text[ending.title],
225
+ live: "polite",
226
+ action: onReload ? /* @__PURE__ */ jsx(Button, { variant: "outline", size: "small", onClick: onReload, children: text.reload }) : void 0,
227
+ children: text[ending.detail]
228
+ }
229
+ ) }) : null
230
+ ]
231
+ }
232
+ );
233
+ }
234
+ var END_TEXT = {
235
+ loading: null,
236
+ ready: null,
237
+ failed: { title: "failed", detail: "failedDetail" },
238
+ navigated: { title: "navigated", detail: "navigatedDetail" },
239
+ refused: { title: "refused", detail: "refusedDetail" },
240
+ outdated: { title: "outdated", detail: "outdatedDetail" }
241
+ };
242
+
243
+ export { FRAME_HELLO_TIMEOUT_MS, SandboxedFrame };
@@ -0,0 +1,135 @@
1
+ import { Timeline } from './chunk-AUQPBL4O.js';
2
+ import { Button } from './chunk-OG6CL3EB.js';
3
+ import { PrincipalAvatar } from './chunk-4KP4RC3O.js';
4
+ import { RelativeTime } from './chunk-3CZ7XAVY.js';
5
+ import { cx } from './chunk-ODEQTPFM.js';
6
+ import './VersionTimeline-EBJ6MIPJ.css';
7
+ import { RotateCcwClockGlyph, PencilGlyph, ShieldGlyph, DatabaseGlyph, UploadGlyph } from '@crewlethq/icons/glyphs';
8
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
9
+
10
+ var LABELS = {
11
+ list: "Versions",
12
+ version: (version) => `Version ${version}`,
13
+ latest: "Latest",
14
+ publish: "Published",
15
+ restore: (from) => from === void 0 ? "Restored" : `Restored version ${from}`,
16
+ schema: "Schema changed",
17
+ capabilities: "Capabilities changed",
18
+ compare: "Compare",
19
+ compareWith: (version) => `Compare with version ${version}`,
20
+ restoreAction: "Restore",
21
+ restoreVersion: (version) => `Restore version ${version}`,
22
+ labelAction: "Name",
23
+ labelVersion: (version) => `Name version ${version}`,
24
+ retention: (oldestKept) => oldestKept > 2 ? `Versions 1 to ${oldestKept - 1} are past the retention window and are no longer kept.` : "Version 1 is past the retention window and is no longer kept."
25
+ };
26
+ var GLYPHS = {
27
+ publish: /* @__PURE__ */ jsx(UploadGlyph, { size: "xs" }),
28
+ restore: /* @__PURE__ */ jsx(RotateCcwClockGlyph, { size: "xs" }),
29
+ schema: /* @__PURE__ */ jsx(DatabaseGlyph, { size: "xs" }),
30
+ capabilities: /* @__PURE__ */ jsx(ShieldGlyph, { size: "xs" })
31
+ };
32
+ function VersionTimeline({
33
+ versions,
34
+ latest,
35
+ selected,
36
+ against,
37
+ onSelect,
38
+ onCompare,
39
+ onRestore,
40
+ onLabel,
41
+ oldestKept,
42
+ now,
43
+ labels,
44
+ className,
45
+ ...rest
46
+ }) {
47
+ const text = { ...LABELS, ...labels };
48
+ const newest = latest ?? versions.reduce((high, item) => Math.max(high, item.version), 0);
49
+ const gap = oldestKept !== void 0 && oldestKept > 1;
50
+ return /* @__PURE__ */ jsxs("nav", { ...rest, "aria-label": text.list, className: cx("crewlet-version-timeline", className), children: [
51
+ /* @__PURE__ */ jsx(Timeline, { children: versions.map((item) => {
52
+ const kind = item.kind ?? "publish";
53
+ const current = item.version === selected;
54
+ const compared = item.version === against;
55
+ const what = kind === "restore" ? text.restore(item.restoredFrom) : text[kind];
56
+ return /* @__PURE__ */ jsxs(
57
+ Timeline.Item,
58
+ {
59
+ marker: GLYPHS[kind],
60
+ label: false,
61
+ className: cx(current && "is-current", compared && "is-compared"),
62
+ children: [
63
+ /* @__PURE__ */ jsxs(
64
+ "button",
65
+ {
66
+ type: "button",
67
+ className: "crewlet-version-timeline__select",
68
+ "aria-current": current || void 0,
69
+ onClick: () => onSelect(item.version),
70
+ children: [
71
+ /* @__PURE__ */ jsxs("span", { className: "crewlet-version-timeline__head", children: [
72
+ /* @__PURE__ */ jsx("span", { className: "crewlet-version-timeline__number", children: text.version(item.version) }),
73
+ item.version === newest ? /* @__PURE__ */ jsx("span", { className: "crewlet-version-timeline__latest", children: text.latest }) : null,
74
+ item.label ? /* @__PURE__ */ jsx("span", { className: "crewlet-version-timeline__label", children: item.label }) : null
75
+ ] }),
76
+ /* @__PURE__ */ jsx("span", { className: "crewlet-version-timeline__summary", children: item.summary ?? what })
77
+ ]
78
+ }
79
+ ),
80
+ /* @__PURE__ */ jsxs("span", { className: "crewlet-version-timeline__meta", children: [
81
+ /* @__PURE__ */ jsx(PrincipalAvatar, { principal: item.author, size: "xs" }),
82
+ /* @__PURE__ */ jsx("span", { children: item.author.name }),
83
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: "\xB7" }),
84
+ /* @__PURE__ */ jsx(RelativeTime, { value: item.at, now }),
85
+ item.summary ? /* @__PURE__ */ jsxs(Fragment, { children: [
86
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: "\xB7" }),
87
+ /* @__PURE__ */ jsx("span", { children: what })
88
+ ] }) : null
89
+ ] }),
90
+ item.source ? /* @__PURE__ */ jsx("span", { className: "crewlet-version-timeline__source", children: item.source }) : null,
91
+ onCompare || onRestore || onLabel ? /* @__PURE__ */ jsxs("span", { className: "crewlet-version-timeline__actions", children: [
92
+ onCompare && !current ? /* @__PURE__ */ jsx(
93
+ Button,
94
+ {
95
+ size: "small",
96
+ variant: "ghost",
97
+ pressed: compared,
98
+ "aria-label": text.compareWith(item.version),
99
+ onClick: () => onCompare(compared ? null : item.version),
100
+ children: text.compare
101
+ }
102
+ ) : null,
103
+ onRestore && item.version !== newest ? /* @__PURE__ */ jsx(
104
+ Button,
105
+ {
106
+ size: "small",
107
+ variant: "ghost",
108
+ leadingIcon: /* @__PURE__ */ jsx(RotateCcwClockGlyph, {}),
109
+ "aria-label": text.restoreVersion(item.version),
110
+ onClick: () => onRestore(item.version),
111
+ children: text.restoreAction
112
+ }
113
+ ) : null,
114
+ onLabel ? /* @__PURE__ */ jsx(
115
+ Button,
116
+ {
117
+ size: "small",
118
+ variant: "ghost",
119
+ leadingIcon: /* @__PURE__ */ jsx(PencilGlyph, {}),
120
+ "aria-label": text.labelVersion(item.version),
121
+ onClick: () => onLabel(item.version),
122
+ children: text.labelAction
123
+ }
124
+ ) : null
125
+ ] }) : null
126
+ ]
127
+ },
128
+ item.version
129
+ );
130
+ }) }),
131
+ gap ? /* @__PURE__ */ jsx("p", { className: "crewlet-version-timeline__gap", children: text.retention(oldestKept) }) : null
132
+ ] });
133
+ }
134
+
135
+ export { VersionTimeline };