@ordinatio/ui 1.1.0 → 1.2.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.d.mts CHANGED
@@ -116,12 +116,59 @@ interface EmailThreadViewProps<T extends ThreadMessage = ThreadMessage> {
116
116
  */
117
117
  declare function EmailThreadView<T extends ThreadMessage = ThreadMessage>({ messages, initialExpanded, renderMessage, className, style, }: EmailThreadViewProps<T>): react_jsx_runtime.JSX.Element | null;
118
118
 
119
+ interface ArchiveButtonProps {
120
+ /** Called when the button is clicked, unless already archiving or disabled. */
121
+ onArchive: () => void;
122
+ /** True while an archive request is in flight — disables the button and shows a pending label. */
123
+ archiving: boolean;
124
+ /**
125
+ * True when archiving is not possible right now for a reason unrelated
126
+ * to an in-flight request (e.g. Cranberry's own provider-mismatch
127
+ * guard on a message whose stored provider no longer matches the
128
+ * account's current one) — disables the button without implying
129
+ * "in progress."
130
+ */
131
+ disabled?: boolean;
132
+ /** Label shown in the idle state. Default: "Archive". */
133
+ label?: string;
134
+ /** Label shown while `archiving` is true. Default: "Archiving…". */
135
+ archivingLabel?: string;
136
+ /**
137
+ * When provided, this component renders NAKED — no default inline
138
+ * styles at all, only `className` (and `style`, if also given). This
139
+ * diverges from EmailThreadView/EmailBodyRenderer's own convention of
140
+ * always applying their base styles and layering the consumer's style
141
+ * on top; a single `<button>` has no internal structure worth
142
+ * preserving once a consumer opts into their own classes, so "your
143
+ * className replaces our defaults entirely" is the more predictable
144
+ * contract here. Pass `style` alone (no `className`) to layer
145
+ * inline-style overrides onto the real defaults instead.
146
+ */
147
+ className?: string;
148
+ style?: CSSProperties;
149
+ }
150
+ /**
151
+ * A single archive control with an idle/in-flight/disabled state — no
152
+ * dropdown, no icon, no assumption about what surrounds it. Pair it with
153
+ * whatever toolbar layout the consuming app already has (see
154
+ * EmailToolbar in apps/web for the fuller, app-specific toolbar this was
155
+ * extracted from).
156
+ */
157
+ declare function ArchiveButton({ onArchive, archiving, disabled, label, archivingLabel, className, style, }: ArchiveButtonProps): react_jsx_runtime.JSX.Element;
158
+
119
159
  interface KeyboardShortcut {
120
160
  /** Key to listen for (e.g., 'r', 'e', 'Escape'). Case-insensitive. */
121
161
  key: string;
122
162
  /** Handler function */
123
163
  handler: () => void;
124
- /** Require modifier keys (default: none) */
164
+ /**
165
+ * Require modifier keys (default: none — fires only when no
166
+ * meta/ctrl/alt is pressed). Requiring `meta` or `ctrl` also lifts
167
+ * the typing guard AND ignoreTags: chords like Cmd+S / Cmd+Enter
168
+ * fire inside inputs and contenteditables (platform convention).
169
+ * Requiring only `alt` or `shift` does NOT lift it — Option+letter
170
+ * and Shift+letter produce real glyphs on macOS.
171
+ */
125
172
  modifiers?: {
126
173
  meta?: boolean;
127
174
  ctrl?: boolean;
@@ -134,11 +181,34 @@ interface UseKeyboardShortcutsOptions {
134
181
  shortcuts: KeyboardShortcut[];
135
182
  /** Whether shortcuts are active (default: true) */
136
183
  enabled?: boolean;
137
- /** Tags to ignore (default: INPUT, TEXTAREA, SELECT) */
184
+ /**
185
+ * EXTRA tag names on which unmodified shortcuts are also suppressed,
186
+ * IN ADDITION to the built-in typing guard (INPUT/TEXTAREA/SELECT,
187
+ * contenteditable, role="textbox", IME — see is-typing-context.ts).
188
+ * Additive only: the built-in guard cannot be disabled, so `[]`
189
+ * (the default) means "no extra tags", never "no guard". Legacy
190
+ * caveat: this check reads `e.target` directly (it predates the
191
+ * predicate), so unlike the built-in guard it does not see through
192
+ * shadow-DOM retargeting.
193
+ */
138
194
  ignoreTags?: string[];
139
195
  }
140
196
  /**
141
- * Register keyboard shortcuts that respect form inputs.
197
+ * Register keyboard shortcuts that respect typing.
198
+ *
199
+ * Contract:
200
+ * - Nothing fires during IME composition — modified or not (mid-
201
+ * composition chords can be IME candidate-control sequences).
202
+ * - Shortcuts WITHOUT required meta/ctrl are suppressed when
203
+ * isTypingContext(e) is true, plus any additive ignoreTags.
204
+ * - Shortcuts REQUIRING meta or ctrl bypass the typing guard and
205
+ * ignoreTags — including contenteditables. That last part is a
206
+ * deliberate delta from the pre-2026-08 hook (which suppressed
207
+ * them there): consumers want save/send chords to work from the
208
+ * Tiptap editor.
209
+ * - Matching is case-insensitive; a fired shortcut preventDefaults.
210
+ * - Malformed input (a bare array instead of { shortcuts }) is a
211
+ * loud one-time no-op, never a per-keydown TypeError.
142
212
  *
143
213
  * @example
144
214
  * useKeyboardShortcuts({
@@ -152,6 +222,19 @@ interface UseKeyboardShortcutsOptions {
152
222
  */
153
223
  declare function useKeyboardShortcuts({ shortcuts, enabled, ignoreTags, }: UseKeyboardShortcutsOptions): void;
154
224
 
225
+ /**
226
+ * True when a keydown event originates from a context where the user
227
+ * is typing text — a form field, a contenteditable (Tiptap et al.),
228
+ * an ARIA textbox, or mid-IME-composition. Keyboard shortcuts must
229
+ * never fire (and never preventDefault) for such events.
230
+ *
231
+ * Non-Element targets (window/document) return false on purpose: the
232
+ * iframe focus-reclaim hook re-dispatches synthetic keydowns on
233
+ * `window` precisely so shortcuts keep working while a read-only
234
+ * email iframe holds focus.
235
+ */
236
+ declare function isTypingContext(event: KeyboardEvent): boolean;
237
+
155
238
  interface ShortcutDefinition {
156
239
  /** Key to listen for (lowercase, single char or special: 'Escape', 'Enter') */
157
240
  key: string;
@@ -496,6 +579,10 @@ declare function isInlineLayout(layout: ReplyLayout): boolean;
496
579
  * Check if the layout renders the compose panel in a dialog/modal.
497
580
  */
498
581
  declare function isModalLayout(layout: ReplyLayout): boolean;
582
+ /**
583
+ * Check if the layout opens compose in a new browser window.
584
+ */
585
+ declare function isPopoutLayout(layout: ReplyLayout): boolean;
499
586
  interface SchedulePreset {
500
587
  label: string;
501
588
  date: Date;
@@ -636,4 +723,4 @@ declare const ACTIVITY_ICONS: Record<string, IconComponent>;
636
723
  /** Return the icon component for a given icon name, or Activity as fallback. */
637
724
  declare function resolveActivityIcon(name: string): IconComponent;
638
725
 
639
- export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, CLIENT_PROFILE_SHORTCUTS, type CachedFetchOptions, type ComposeMode, EmailBodyRenderer, type EmailBodyRendererProps, EmailThreadView, type EmailThreadViewProps, ErrorBoundary, type ErrorBoundaryProps, FORM_SHORTCUTS, GLOBAL_SHORTCUTS, INBOX_SHORTCUTS, type KeyboardShortcut, KeyboardShortcutsPanel, RENDER_ERRORS, REPLY_LAYOUT_OPTIONS, type RenderErrorResult, type ReplyLayout, type SchedulePreset, type ShortcutContext, type ShortcutDefinition, type ThreadMessage, type UseAutoSaveOptions, type UseAutoSaveResult, type UseKeyboardShortcutsOptions, type UsePollingOptions, type UsePollingResult, type UsePreferencesOptions, type UsePreferencesResult, type UseServerSearchOptions, type UseServerSearchResult, cachedFetch, canViewInline, clearCache, formatDateGroup, formatFileSize, formatPhone, formatPhoneInput, getNextMondayMorning, getNextWeekday, getQuickScheduleOptions, getShortcut, getTomorrowMorning, groupByDate, invalidateCache, isAudio, isDocument, isImage, isInlineLayout, isModalLayout, isPdf, isSpreadsheet, isValidScheduleDate, isVideo, opensInNewTab, parseCustomSchedule, prefetch, renderError, resolveActivityIcon, resolveContentType, stripHtml, stripPhone, truncatePreview, useAutoSave, useContextShortcuts, useIframeFocusReclaim, useKeyboardShortcuts, usePolling, usePreferences, useServerSearch, withErrorBoundary };
726
+ export { ACTIVITY_ICONS, ALL_SHORTCUT_CONTEXTS, ArchiveButton, type ArchiveButtonProps, CLIENT_PROFILE_SHORTCUTS, type CachedFetchOptions, type ComposeMode, EmailBodyRenderer, type EmailBodyRendererProps, EmailThreadView, type EmailThreadViewProps, ErrorBoundary, type ErrorBoundaryProps, FORM_SHORTCUTS, GLOBAL_SHORTCUTS, INBOX_SHORTCUTS, type KeyboardShortcut, KeyboardShortcutsPanel, RENDER_ERRORS, REPLY_LAYOUT_OPTIONS, type RenderErrorResult, type ReplyLayout, type SchedulePreset, type ShortcutContext, type ShortcutDefinition, type ThreadMessage, type UseAutoSaveOptions, type UseAutoSaveResult, type UseKeyboardShortcutsOptions, type UsePollingOptions, type UsePollingResult, type UsePreferencesOptions, type UsePreferencesResult, type UseServerSearchOptions, type UseServerSearchResult, cachedFetch, canViewInline, clearCache, formatDateGroup, formatFileSize, formatPhone, formatPhoneInput, getNextMondayMorning, getNextWeekday, getQuickScheduleOptions, getShortcut, getTomorrowMorning, groupByDate, invalidateCache, isAudio, isDocument, isImage, isInlineLayout, isModalLayout, isPdf, isPopoutLayout, isSpreadsheet, isTypingContext, isValidScheduleDate, isVideo, opensInNewTab, parseCustomSchedule, prefetch, renderError, resolveActivityIcon, resolveContentType, stripHtml, stripPhone, truncatePreview, useAutoSave, useContextShortcuts, useIframeFocusReclaim, useKeyboardShortcuts, usePolling, usePreferences, useServerSearch, withErrorBoundary };
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ 'use client';
2
+
1
3
  // src/components/error-boundary.tsx
2
4
  import { Component, useState } from "react";
3
5
 
@@ -648,23 +650,88 @@ function EmailThreadView({
648
650
  ] });
649
651
  }
650
652
 
653
+ // src/components/archive-button.tsx
654
+ import { jsx as jsx4 } from "react/jsx-runtime";
655
+ var defaultStyle = {
656
+ display: "inline-flex",
657
+ alignItems: "center",
658
+ gap: "8px",
659
+ padding: "8px 16px",
660
+ fontSize: "14px",
661
+ fontWeight: 500,
662
+ borderRadius: "6px",
663
+ border: "1px solid transparent",
664
+ backgroundColor: "#171717",
665
+ color: "#ffffff",
666
+ cursor: "pointer"
667
+ };
668
+ var disabledStyle = {
669
+ opacity: 0.5,
670
+ cursor: "not-allowed"
671
+ };
672
+ function ArchiveButton({
673
+ onArchive,
674
+ archiving,
675
+ disabled = false,
676
+ label = "Archive",
677
+ archivingLabel = "Archiving\u2026",
678
+ className,
679
+ style
680
+ }) {
681
+ const isDisabled = archiving || disabled;
682
+ return /* @__PURE__ */ jsx4(
683
+ "button",
684
+ {
685
+ type: "button",
686
+ onClick: onArchive,
687
+ disabled: isDisabled,
688
+ "aria-busy": archiving,
689
+ className,
690
+ style: className ? style : { ...defaultStyle, ...isDisabled ? disabledStyle : {}, ...style },
691
+ children: archiving ? archivingLabel : label
692
+ }
693
+ );
694
+ }
695
+
651
696
  // src/hooks/use-keyboard-shortcuts.ts
652
697
  import { useEffect as useEffect2, useCallback as useCallback2 } from "react";
653
- var DEFAULT_IGNORE_TAGS = ["INPUT", "TEXTAREA", "SELECT"];
698
+
699
+ // src/hooks/is-typing-context.ts
700
+ var TYPING_TAG_RE = /^(INPUT|TEXTAREA|SELECT)$/;
701
+ var EDITABLE_ANCESTOR_SELECTOR = '[contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"], [role="textbox"]';
702
+ function isTypingContext(event) {
703
+ if (event.isComposing || event.keyCode === 229) return true;
704
+ const path = typeof event.composedPath === "function" ? event.composedPath() : void 0;
705
+ const pathTarget = path && path.length > 0 ? path[0] : void 0;
706
+ const raw = pathTarget && typeof pathTarget.tagName === "string" ? pathTarget : event.target;
707
+ if (!raw || typeof raw.tagName !== "string") return false;
708
+ const el = raw;
709
+ if (TYPING_TAG_RE.test(el.tagName)) return true;
710
+ if (el.isContentEditable) return true;
711
+ if (typeof el.closest === "function" && el.closest(EDITABLE_ANCESTOR_SELECTOR)) return true;
712
+ return false;
713
+ }
714
+
715
+ // src/hooks/use-keyboard-shortcuts.ts
654
716
  function useKeyboardShortcuts({
655
717
  shortcuts,
656
718
  enabled = true,
657
- ignoreTags = DEFAULT_IGNORE_TAGS
719
+ ignoreTags = []
658
720
  }) {
721
+ const malformed = !Array.isArray(shortcuts);
722
+ useEffect2(() => {
723
+ if (malformed) {
724
+ console.error(
725
+ "[useKeyboardShortcuts] expected { shortcuts: KeyboardShortcut[] } \u2014 got a non-array `shortcuts` (legacy array call form?). All shortcuts for this caller are disabled until the call is fixed."
726
+ );
727
+ }
728
+ }, [malformed]);
659
729
  const handleKeyDown = useCallback2(
660
730
  (e) => {
661
- if (!enabled) return;
662
- const tag = e.target?.tagName;
663
- if (tag && ignoreTags.includes(tag)) return;
664
- if (e.target?.isContentEditable) return;
731
+ if (!enabled || malformed) return;
732
+ if (e.isComposing || e.keyCode === 229) return;
665
733
  for (const shortcut of shortcuts) {
666
- const keyMatch = e.key.toLowerCase() === shortcut.key.toLowerCase();
667
- if (!keyMatch) continue;
734
+ if (e.key.toLowerCase() !== shortcut.key.toLowerCase()) continue;
668
735
  const mods = shortcut.modifiers;
669
736
  if (mods) {
670
737
  if (mods.meta && !e.metaKey) continue;
@@ -674,12 +741,18 @@ function useKeyboardShortcuts({
674
741
  } else {
675
742
  if (e.metaKey || e.ctrlKey || e.altKey) continue;
676
743
  }
744
+ const bypassesTypingGuard = Boolean(mods && (mods.meta || mods.ctrl));
745
+ if (!bypassesTypingGuard) {
746
+ if (isTypingContext(e)) continue;
747
+ const tag = e.target?.tagName;
748
+ if (tag && ignoreTags.includes(tag)) continue;
749
+ }
677
750
  e.preventDefault();
678
751
  shortcut.handler();
679
752
  return;
680
753
  }
681
754
  },
682
- [shortcuts, enabled, ignoreTags]
755
+ [shortcuts, enabled, ignoreTags, malformed]
683
756
  );
684
757
  useEffect2(() => {
685
758
  window.addEventListener("keydown", handleKeyDown);
@@ -852,7 +925,7 @@ function getShortcut(context, action) {
852
925
 
853
926
  // src/components/keyboard-shortcuts-panel.tsx
854
927
  import { useEffect as useEffect3, useState as useState3 } from "react";
855
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
928
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
856
929
  function KeyboardShortcutsPanel({
857
930
  contexts = ALL_SHORTCUT_CONTEXTS
858
931
  }) {
@@ -875,32 +948,32 @@ function KeyboardShortcutsPanel({
875
948
  }, [open]);
876
949
  if (!open) return null;
877
950
  return /* @__PURE__ */ jsxs4(Fragment2, { children: [
878
- /* @__PURE__ */ jsx4(
951
+ /* @__PURE__ */ jsx5(
879
952
  "div",
880
953
  {
881
954
  className: "fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",
882
955
  onClick: () => setOpen(false)
883
956
  }
884
957
  ),
885
- /* @__PURE__ */ jsx4("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
958
+ /* @__PURE__ */ jsx5("div", { className: "fixed inset-x-0 top-[10%] z-50 mx-auto w-full max-w-lg", children: /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border bg-background shadow-2xl overflow-hidden", children: [
886
959
  /* @__PURE__ */ jsxs4("div", { className: "px-6 py-4 border-b", children: [
887
- /* @__PURE__ */ jsx4("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
960
+ /* @__PURE__ */ jsx5("h2", { className: "text-lg font-semibold", children: "Keyboard Shortcuts" }),
888
961
  /* @__PURE__ */ jsxs4("p", { className: "text-sm text-muted-foreground mt-0.5", children: [
889
962
  "Press ",
890
- /* @__PURE__ */ jsx4("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
963
+ /* @__PURE__ */ jsx5("kbd", { className: "px-1.5 py-0.5 bg-muted rounded text-xs font-mono", children: "?" }),
891
964
  " to toggle this panel"
892
965
  ] })
893
966
  ] }),
894
- /* @__PURE__ */ jsx4("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs4("div", { children: [
895
- /* @__PURE__ */ jsx4("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
896
- /* @__PURE__ */ jsx4("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between py-1", children: [
897
- /* @__PURE__ */ jsx4("span", { className: "text-sm", children: def.description }),
898
- /* @__PURE__ */ jsx4("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
967
+ /* @__PURE__ */ jsx5("div", { className: "px-6 py-4 max-h-[60vh] overflow-y-auto space-y-6", children: contexts.map((ctx) => /* @__PURE__ */ jsxs4("div", { children: [
968
+ /* @__PURE__ */ jsx5("h3", { className: "text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-2", children: ctx.label }),
969
+ /* @__PURE__ */ jsx5("div", { className: "space-y-1", children: Object.entries(ctx.shortcuts).map(([key, def]) => /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between py-1", children: [
970
+ /* @__PURE__ */ jsx5("span", { className: "text-sm", children: def.description }),
971
+ /* @__PURE__ */ jsx5("kbd", { className: "px-2 py-0.5 bg-muted rounded text-xs font-mono min-w-[2rem] text-center", children: def.display })
899
972
  ] }, key)) })
900
973
  ] }, ctx.name)) }),
901
974
  /* @__PURE__ */ jsxs4("div", { className: "px-6 py-3 border-t bg-muted/30 text-xs text-muted-foreground text-center", children: [
902
975
  "Press ",
903
- /* @__PURE__ */ jsx4("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
976
+ /* @__PURE__ */ jsx5("kbd", { className: "px-1 py-0.5 bg-muted rounded", children: "Esc" }),
904
977
  " to close"
905
978
  ] })
906
979
  ] }) })
@@ -1326,7 +1399,10 @@ function isInlineLayout(layout) {
1326
1399
  return layout === "SPLIT_HORIZONTAL" || layout === "SPLIT_VERTICAL";
1327
1400
  }
1328
1401
  function isModalLayout(layout) {
1329
- return layout === "MODAL" || layout === "POPOUT";
1402
+ return layout === "MODAL";
1403
+ }
1404
+ function isPopoutLayout(layout) {
1405
+ return layout === "POPOUT";
1330
1406
  }
1331
1407
  function getNextWeekday(dayOfWeek, hour) {
1332
1408
  const now = /* @__PURE__ */ new Date();
@@ -1605,6 +1681,7 @@ function resolveActivityIcon(name) {
1605
1681
  export {
1606
1682
  ACTIVITY_ICONS,
1607
1683
  ALL_SHORTCUT_CONTEXTS,
1684
+ ArchiveButton,
1608
1685
  CLIENT_PROFILE_SHORTCUTS,
1609
1686
  EmailBodyRenderer,
1610
1687
  EmailThreadView,
@@ -1635,7 +1712,9 @@ export {
1635
1712
  isInlineLayout,
1636
1713
  isModalLayout,
1637
1714
  isPdf,
1715
+ isPopoutLayout,
1638
1716
  isSpreadsheet,
1717
+ isTypingContext,
1639
1718
  isValidScheduleDate,
1640
1719
  isVideo,
1641
1720
  opensInNewTab,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordinatio/ui",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "Reusable React components and hooks for Ordinatio applications",
@@ -27,9 +27,6 @@
27
27
  "react": ">=18.0.0",
28
28
  "lucide-react": ">=0.400.0"
29
29
  },
30
- "dependencies": {
31
- "@ordinatio/activities": "1.0.3"
32
- },
33
30
  "devDependencies": {
34
31
  "@testing-library/jest-dom": "6.9.1",
35
32
  "@testing-library/react": "16.3.2",
@@ -37,12 +34,14 @@
37
34
  "jsdom": "^27.0.0",
38
35
  "lucide-react": "0.562.0",
39
36
  "react": "^19.0.0",
37
+ "tsup": "^8.5.1",
40
38
  "typescript": "5",
41
39
  "vitest": "4.0.18",
42
- "@ordinatio/activities": "1.0.3"
40
+ "@ordinatio/activities": "1.0.4"
43
41
  },
44
42
  "scripts": {
45
- "build": "tsup src/index.ts --format esm --dts --clean --external react",
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
46
45
  "test": "vitest",
47
46
  "test:run": "vitest run"
48
47
  }