@flytedan/flytebot-design-system 0.81.0 → 0.82.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1154,6 +1154,7 @@ __export(index_exports, {
1154
1154
  revokeAttachment: () => revokeAttachment,
1155
1155
  savePrefs: () => savePrefs,
1156
1156
  toAttachment: () => toAttachment,
1157
+ toSwitcherEntries: () => toSwitcherEntries,
1157
1158
  tokenize: () => tokenize,
1158
1159
  useAppearancePrefs: () => useAppearancePrefs,
1159
1160
  useAppearanceStore: () => useAppearanceStore,
@@ -1173,6 +1174,7 @@ __export(index_exports, {
1173
1174
  useRuntimeMode: () => useRuntimeMode,
1174
1175
  useServerTable: () => useServerTable,
1175
1176
  useSessionContext: () => useSessionContext,
1177
+ useSessionContextValue: () => useSessionContextValue,
1176
1178
  useSheetOpenMark: () => useSheetOpenMark,
1177
1179
  useShownExport: () => useShownExport,
1178
1180
  useStackedLayer: () => useStackedLayer,
@@ -2771,7 +2773,7 @@ function JobTray({ jobs: jobs2, onDismiss, className = "" }) {
2771
2773
  }
2772
2774
  function JobCard({ job, onDismiss }) {
2773
2775
  const title = textOf(job.title) || "Job";
2774
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: ["fd-job-card", "fd-job-card-" + job.status].filter(Boolean).join(" "), children: [
2776
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: ["fd-job-card", "fd-job-card--" + job.status].filter(Boolean).join(" "), children: [
2775
2777
  /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "fd-job-card-head", children: [
2776
2778
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("span", { className: "fd-job-card-title", children: job.title }),
2777
2779
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
@@ -5421,7 +5423,6 @@ function MiddleEllipsis({ text, middle = true }) {
5421
5423
  // src/components/data/FilterBar.tsx
5422
5424
  var import_jsx_runtime53 = require("react/jsx-runtime");
5423
5425
  var PANEL_WIDTH = { multiSelect: 280, range: 240, date: 300 };
5424
- var MULTISELECT_MAX_WIDTH = 640;
5425
5426
  var OPTION_CHROME = 88;
5426
5427
  var measureCtx;
5427
5428
  function textWidth(text, el) {
@@ -5681,7 +5682,7 @@ function MultiSelectPanel({
5681
5682
  const label = document.getElementById(listId)?.querySelector(".fd-opt-label");
5682
5683
  if (!label) return;
5683
5684
  const widest = optionsRef.current.reduce((m, o) => Math.max(m, textWidth(o.label, label)), 0);
5684
- const wanted = Math.min(MULTISELECT_MAX_WIDTH, Math.max(PANEL_WIDTH.multiSelect, Math.ceil(widest + OPTION_CHROME)));
5685
+ const wanted = Math.max(PANEL_WIDTH.multiSelect, Math.ceil(widest + OPTION_CHROME));
5685
5686
  setPanelWidth((w) => Math.max(w, wanted));
5686
5687
  };
5687
5688
  measure();
@@ -16452,8 +16453,43 @@ function BreadcrumbCrumb({
16452
16453
  return /* @__PURE__ */ (0, import_jsx_runtime112.jsx)("span", { className: ["fd-fb-crumb", over ? "is-drop-target" : ""].filter(Boolean).join(" "), ...dropHandlers, children: isCurrent ? /* @__PURE__ */ (0, import_jsx_runtime112.jsx)("span", { className: "fd-fb-crumb-current", "aria-current": "page", children: label }) : /* @__PURE__ */ (0, import_jsx_runtime112.jsx)("button", { type: "button", className: "fd-fb-crumb-link", onClick, children: label }) });
16453
16454
  }
16454
16455
 
16455
- // src/kits/query.ts
16456
+ // src/kits/sessionAdapter.ts
16456
16457
  var React87 = __toESM(require("react"), 1);
16458
+ function toSwitcherEntries(apps, currentAppKey) {
16459
+ return apps.filter((app) => app.url != null).map((app) => ({
16460
+ key: app.key,
16461
+ name: app.name,
16462
+ url: app.url,
16463
+ icon: app.icon ?? void 0,
16464
+ current: app.key === currentAppKey
16465
+ }));
16466
+ }
16467
+ function useSessionContextValue(session, { currentAppKey }) {
16468
+ const { user, apps, signOut, status } = session;
16469
+ const authorized = status === "authenticated";
16470
+ const pending = status === "unavailable";
16471
+ return React87.useMemo(
16472
+ () => ({
16473
+ user: { id: user.id, name: user.name, email: user.email, sso: true },
16474
+ roles: user.roles.map((r) => ({ id: r.key, name: r.name })),
16475
+ permissions: user.permissions,
16476
+ can: (permission) => {
16477
+ if (!authorized) return false;
16478
+ const need = Array.isArray(permission) ? permission : [permission];
16479
+ return need.every((p) => user.permissions.includes(p));
16480
+ },
16481
+ canAny: (permissions) => authorized && permissions.some((p) => user.permissions.includes(p)),
16482
+ hasRole: (roleId) => authorized && user.roles.some((r) => r.key === roleId),
16483
+ signOut,
16484
+ apps: toSwitcherEntries(apps, currentAppKey),
16485
+ pending
16486
+ }),
16487
+ [user, apps, signOut, authorized, pending, currentAppKey]
16488
+ );
16489
+ }
16490
+
16491
+ // src/kits/query.ts
16492
+ var React88 = __toESM(require("react"), 1);
16457
16493
 
16458
16494
  // src/kits/queryUrl.ts
16459
16495
  var historyUrlAdapter = {
@@ -16591,38 +16627,38 @@ function requestFor(params, query, paging, after) {
16591
16627
  }
16592
16628
  var toError = (e) => e instanceof Error ? e : new Error(String(e));
16593
16629
  function useServerTable({ endpoint, params, defaults, deps, prefsKey, paging = "page", url }) {
16594
- const [base] = React87.useState(() => {
16630
+ const [base] = React88.useState(() => {
16595
16631
  const store = PREFS || window.PlannerPrefs;
16596
16632
  const saved = prefsKey && store ? store.getTable(prefsKey) : {};
16597
16633
  return { ...DEFAULTS, ...defaults || {}, ...saved.pageSize ? { pageSize: saved.pageSize } : {}, ...saved.sort ? { sort: saved.sort, dir: saved.dir || "desc" } : {} };
16598
16634
  });
16599
- const [mountParams] = React87.useState(() => url ? (url.adapter ?? historyUrlAdapter).read() : null);
16600
- const address = React87.useRef(mountParams);
16601
- const [query, setQuery] = React87.useState(() => url && mountParams ? readQueryFromUrl(mountParams, url.scope, base, paging) : base);
16602
- const savePref = React87.useCallback((patch2) => {
16635
+ const [mountParams] = React88.useState(() => url ? (url.adapter ?? historyUrlAdapter).read() : null);
16636
+ const address = React88.useRef(mountParams);
16637
+ const [query, setQuery] = React88.useState(() => url && mountParams ? readQueryFromUrl(mountParams, url.scope, base, paging) : base);
16638
+ const savePref = React88.useCallback((patch2) => {
16603
16639
  const store = PREFS || window.PlannerPrefs;
16604
16640
  if (prefsKey && store) store.setTable(prefsKey, patch2);
16605
16641
  }, [prefsKey]);
16606
- const [res, setRes] = React87.useState(null);
16607
- const [loading, setLoading] = React87.useState(true);
16608
- const [loadingMore, setLoadingMore] = React87.useState(false);
16609
- const [failure, setFailure] = React87.useState(null);
16610
- const [reloadToken, setReloadToken] = React87.useState(0);
16611
- const moreController = React87.useRef(null);
16642
+ const [res, setRes] = React88.useState(null);
16643
+ const [loading, setLoading] = React88.useState(true);
16644
+ const [loadingMore, setLoadingMore] = React88.useState(false);
16645
+ const [failure, setFailure] = React88.useState(null);
16646
+ const [reloadToken, setReloadToken] = React88.useState(0);
16647
+ const moreController = React88.useRef(null);
16612
16648
  const depKey = (deps || []).join("|");
16613
16649
  const paramKey = JSON.stringify(params || {});
16614
16650
  const queryKey = JSON.stringify(query);
16615
- const lifetime = React87.useRef(null);
16616
- React87.useEffect(() => {
16651
+ const lifetime = React88.useRef(null);
16652
+ React88.useEffect(() => {
16617
16653
  const controller = new AbortController();
16618
16654
  lifetime.current = controller;
16619
16655
  return () => controller.abort();
16620
16656
  }, []);
16621
- const latest = React87.useRef({ res, loading, query, params, endpoint, url, base });
16622
- React87.useLayoutEffect(() => {
16657
+ const latest = React88.useRef({ res, loading, query, params, endpoint, url, base });
16658
+ React88.useLayoutEffect(() => {
16623
16659
  latest.current = { res, loading, query, params, endpoint, url, base };
16624
16660
  });
16625
- React87.useEffect(() => {
16661
+ React88.useEffect(() => {
16626
16662
  const controller = new AbortController();
16627
16663
  const { signal } = controller;
16628
16664
  setLoading(true);
@@ -16658,7 +16694,7 @@ function useServerTable({ endpoint, params, defaults, deps, prefsKey, paging = "
16658
16694
  };
16659
16695
  }, [endpoint, queryKey, paramKey, depKey, paging, reloadToken]);
16660
16696
  const adapter = url ? url.adapter ?? historyUrlAdapter : null;
16661
- React87.useEffect(() => {
16697
+ React88.useEffect(() => {
16662
16698
  if (!adapter) return;
16663
16699
  return adapter.subscribe((params2) => {
16664
16700
  const { url: u, base: b } = latest.current;
@@ -17008,12 +17044,12 @@ function createVersionStore(initialState, options) {
17008
17044
  }
17009
17045
 
17010
17046
  // src/kits/documentTitle.ts
17011
- var React88 = __toESM(require("react"), 1);
17047
+ var React89 = __toESM(require("react"), 1);
17012
17048
  function formatDocumentTitle(routeTitle, appName) {
17013
17049
  return [routeTitle, appName, "Flytedesk"].filter((part2) => !!part2 && part2.length > 0).join(" \xB7 ");
17014
17050
  }
17015
17051
  function useDocumentTitle(routeTitle, appName) {
17016
- React88.useEffect(() => {
17052
+ React89.useEffect(() => {
17017
17053
  if (typeof document === "undefined") return;
17018
17054
  document.title = formatDocumentTitle(routeTitle, appName);
17019
17055
  }, [routeTitle, appName]);
@@ -17115,17 +17151,17 @@ function createChatAdapter(transport, { onTurnStarted, deadlineMs = CHAT_CALL_DE
17115
17151
  }
17116
17152
 
17117
17153
  // src/kits/chatTransport/useChatThreads.ts
17118
- var React89 = __toESM(require("react"), 1);
17154
+ var React90 = __toESM(require("react"), 1);
17119
17155
  var THREADS_LOAD_FAILED = "Your earlier conversations could not be loaded.";
17120
17156
  var NEW_THREAD_FAILED = "A new conversation could not be started.";
17121
17157
  function useChatThreads(transport, { deadlineMs = CHAT_CALL_DEADLINE_MS } = {}) {
17122
17158
  const toast = useToast();
17123
- const [threads, setThreads] = React89.useState([]);
17124
- const [reads, setReads] = React89.useState(0);
17159
+ const [threads, setThreads] = React90.useState([]);
17160
+ const [reads, setReads] = React90.useState(0);
17125
17161
  const transportRef = useLatest(transport);
17126
17162
  const deadlineRef = useLatest(deadlineMs);
17127
- const refresh2 = React89.useCallback(() => setReads((n) => n + 1), []);
17128
- React89.useEffect(() => {
17163
+ const refresh2 = React90.useCallback(() => setReads((n) => n + 1), []);
17164
+ React90.useEffect(() => {
17129
17165
  const controller = new AbortController();
17130
17166
  const { signal } = controller;
17131
17167
  withDeadline("listThreads", deadlineRef.current, transportRef.current.listThreads(signal)).then(
@@ -17138,7 +17174,7 @@ function useChatThreads(transport, { deadlineMs = CHAT_CALL_DEADLINE_MS } = {})
17138
17174
  );
17139
17175
  return () => controller.abort();
17140
17176
  }, [reads, toast, transportRef, deadlineRef]);
17141
- const startNewThread = React89.useCallback(
17177
+ const startNewThread = React90.useCallback(
17142
17178
  (onCreated) => withDeadline("createThread", deadlineRef.current, transportRef.current.createThread()).then(
17143
17179
  ({ thread_id }) => {
17144
17180
  onCreated(thread_id);
@@ -17166,14 +17202,14 @@ function createExportDownloader({
17166
17202
  }
17167
17203
 
17168
17204
  // src/kits/exports/useExportJobs.ts
17169
- var React90 = __toESM(require("react"), 1);
17205
+ var React91 = __toESM(require("react"), 1);
17170
17206
  var EXPORT_POLL_INTERVAL_MS = 3e3;
17171
17207
  var EXPORT_IDLE_POLL_INTERVAL_MS = 3e4;
17172
17208
  function useExportJobs({ list, acknowledge }) {
17173
- const [rows, setRows] = React90.useState([]);
17209
+ const [rows, setRows] = React91.useState([]);
17174
17210
  const listRef = useLatest(list);
17175
17211
  const acknowledgeRef = useLatest(acknowledge);
17176
- const reload = React90.useCallback(
17212
+ const reload = React91.useCallback(
17177
17213
  () => listRef.current().then(
17178
17214
  (fresh) => setRows(fresh),
17179
17215
  () => {
@@ -17181,16 +17217,16 @@ function useExportJobs({ list, acknowledge }) {
17181
17217
  ),
17182
17218
  [listRef]
17183
17219
  );
17184
- React90.useEffect(() => {
17220
+ React91.useEffect(() => {
17185
17221
  void reload();
17186
17222
  }, [reload]);
17187
17223
  const anyLive = rows.some(isLiveExport);
17188
- React90.useEffect(() => {
17224
+ React91.useEffect(() => {
17189
17225
  const timer = setInterval(() => void reload(), anyLive ? EXPORT_POLL_INTERVAL_MS : EXPORT_IDLE_POLL_INTERVAL_MS);
17190
17226
  return () => clearInterval(timer);
17191
17227
  }, [anyLive, reload]);
17192
- const refresh2 = React90.useCallback(() => void reload(), [reload]);
17193
- const ackExport = React90.useCallback(
17228
+ const refresh2 = React91.useCallback(() => void reload(), [reload]);
17229
+ const ackExport = React91.useCallback(
17194
17230
  (id) => void acknowledgeRef.current(id).then(reload),
17195
17231
  [acknowledgeRef, reload]
17196
17232
  );
@@ -17198,7 +17234,7 @@ function useExportJobs({ list, acknowledge }) {
17198
17234
  }
17199
17235
 
17200
17236
  // src/kits/exports/ExportTray.tsx
17201
- var React91 = __toESM(require("react"), 1);
17237
+ var React92 = __toESM(require("react"), 1);
17202
17238
  var import_jsx_runtime113 = require("react/jsx-runtime");
17203
17239
  var EXPORT_KEPT_NOTE = "Kept for 24 hours";
17204
17240
  var EXPORT_FAILED_FALLBACK = "Unknown error.";
@@ -17218,7 +17254,7 @@ function exportToJob(job, onDownload) {
17218
17254
  return { ...base, status: "active" };
17219
17255
  }
17220
17256
  function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17221
- const jobs2 = React91.useMemo(() => exports2.map((job) => exportToJob(job, onDownload)), [exports2, onDownload]);
17257
+ const jobs2 = React92.useMemo(() => exports2.map((job) => exportToJob(job, onDownload)), [exports2, onDownload]);
17222
17258
  return /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(JobTray, { jobs: jobs2, onDismiss });
17223
17259
  }
17224
17260
  // Annotate the CommonJS export names for ESM import in node:
@@ -17468,6 +17504,7 @@ function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17468
17504
  revokeAttachment,
17469
17505
  savePrefs,
17470
17506
  toAttachment,
17507
+ toSwitcherEntries,
17471
17508
  tokenize,
17472
17509
  useAppearancePrefs,
17473
17510
  useAppearanceStore,
@@ -17487,6 +17524,7 @@ function ExportTray({ exports: exports2, onDownload, onDismiss }) {
17487
17524
  useRuntimeMode,
17488
17525
  useServerTable,
17489
17526
  useSessionContext,
17527
+ useSessionContextValue,
17490
17528
  useSheetOpenMark,
17491
17529
  useShownExport,
17492
17530
  useStackedLayer,