@softure-ai/theme-notion 0.11.0 → 0.12.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 (45) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +46 -4
  3. package/dist/index.d.ts +5 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +5 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/messages/en.d.ts +7 -0
  8. package/dist/messages/en.d.ts.map +1 -1
  9. package/dist/messages/en.js +7 -0
  10. package/dist/messages/en.js.map +1 -1
  11. package/dist/messages/index.d.ts +7 -0
  12. package/dist/messages/index.d.ts.map +1 -1
  13. package/dist/notion/AsidePanel.d.ts +64 -0
  14. package/dist/notion/AsidePanel.d.ts.map +1 -0
  15. package/dist/notion/AsidePanel.js +154 -0
  16. package/dist/notion/AsidePanel.js.map +1 -0
  17. package/dist/notion/Upload.d.ts +0 -2
  18. package/dist/notion/Upload.d.ts.map +1 -1
  19. package/dist/notion/Upload.js +1 -15
  20. package/dist/notion/Upload.js.map +1 -1
  21. package/dist/notion/format-file-size.d.ts +3 -0
  22. package/dist/notion/format-file-size.d.ts.map +1 -0
  23. package/dist/notion/format-file-size.js +17 -0
  24. package/dist/notion/format-file-size.js.map +1 -0
  25. package/dist/notion/overlay-open.d.ts +7 -0
  26. package/dist/notion/overlay-open.d.ts.map +1 -0
  27. package/dist/notion/overlay-open.js +28 -0
  28. package/dist/notion/overlay-open.js.map +1 -0
  29. package/dist/ui/tabs-variants.d.ts +6 -0
  30. package/dist/ui/tabs-variants.d.ts.map +1 -0
  31. package/dist/ui/tabs-variants.js +26 -0
  32. package/dist/ui/tabs-variants.js.map +1 -0
  33. package/dist/ui/tabs.d.ts +3 -7
  34. package/dist/ui/tabs.d.ts.map +1 -1
  35. package/dist/ui/tabs.js +2 -25
  36. package/dist/ui/tabs.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/index.ts +16 -1
  39. package/src/messages/en.ts +7 -0
  40. package/src/notion/AsidePanel.tsx +346 -0
  41. package/src/notion/Upload.tsx +1 -16
  42. package/src/notion/format-file-size.ts +16 -0
  43. package/src/notion/overlay-open.ts +29 -0
  44. package/src/ui/tabs-variants.ts +29 -0
  45. package/src/ui/tabs.tsx +3 -29
@@ -0,0 +1,16 @@
1
+ // A plain module (no "use client"), so a Server Component can call the formatter (issue #1005).
2
+ const SIZE_UNITS = ["kilobyte", "megabyte", "gigabyte", "terabyte"] as const;
3
+
4
+ /** A file size for people, in decimal steps (1 kB = 1000 bytes), written by the locale: `formatFileSize(1500)` is "1.5 kB". Safe on the server. */
5
+ export function formatFileSize(bytes: number, locale = "en"): string {
6
+ const size = Number.isFinite(bytes) ? Math.max(0, bytes) : 0;
7
+ // Bytes in full ("820 bytes"): the short form of the unit is the bare word "byte" in English.
8
+ if (size < 1000) return new Intl.NumberFormat(locale, { style: "unit", unit: "byte", unitDisplay: "long" }).format(Math.round(size));
9
+ let value = size / 1000;
10
+ let unit = 0;
11
+ while (value >= 1000 && unit < SIZE_UNITS.length - 1) {
12
+ value /= 1000;
13
+ unit += 1;
14
+ }
15
+ return new Intl.NumberFormat(locale, { style: "unit", unit: SIZE_UNITS[unit], unitDisplay: "short", maximumFractionDigits: 1 }).format(value);
16
+ }
@@ -0,0 +1,29 @@
1
+ // Kept out of the "use client" AsidePanel module so a Server Component or a plain script can call it too.
2
+
3
+ // Overlays that handle Escape themselves: a Radix dialog, menu, listbox or popover while it is open, a native modal.
4
+ const OPEN_OVERLAY_SELECTORS = [
5
+ '[role="dialog"][data-state="open"]',
6
+ '[role="alertdialog"][data-state="open"]',
7
+ '[role="menu"][data-state="open"]',
8
+ '[role="listbox"][data-state="open"]',
9
+ "dialog[open]",
10
+ ":popover-open",
11
+ ] as const;
12
+
13
+ function hasMatch(root: ParentNode, selector: string): boolean {
14
+ try {
15
+ return root.querySelector(selector) !== null;
16
+ } catch {
17
+ // A DOM that does not know the selector (`:popover-open` in an older engine) has no such overlay open.
18
+ return false;
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Whether a dialog, menu, listbox or popover is open under `root`: one with Radix `data-state="open"`, one that
24
+ * matches `:popover-open`, or a `dialog[open]`. A closed popover that stays in the page with `role="dialog"` does
25
+ * not count. A keyboard handler reads it before acting on Escape, so the overlay closes first.
26
+ */
27
+ export function isOverlayOpen(root: ParentNode): boolean {
28
+ return OPEN_OVERLAY_SELECTORS.some((selector) => hasMatch(root, selector));
29
+ }
@@ -0,0 +1,29 @@
1
+ // The class builder of TabsList, in a plain module so a Server Component can call it (issue #1008).
2
+ import { cva } from "class-variance-authority"
3
+
4
+ export const tabsListVariants = cva(
5
+ "group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",
6
+ {
7
+ variants: {
8
+ variant: {
9
+ default: "bg-muted",
10
+ line: "gap-1 bg-transparent",
11
+ },
12
+ size: {
13
+ default: "",
14
+ // The triggers set the height: a fixed one would cap them at 35 px.
15
+ touch: "group-data-[orientation=horizontal]/tabs:h-auto",
16
+ },
17
+ // Keeps to its container's width and scrolls sideways; the line variant keeps room for the active underline.
18
+ scrollable: {
19
+ false: "",
20
+ true: "relative w-full max-w-full min-w-0 justify-start overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:thin] group-data-[orientation=horizontal]/tabs:h-auto data-[variant=line]:pb-1.5 *:flex-none",
21
+ },
22
+ },
23
+ defaultVariants: {
24
+ variant: "line",
25
+ size: "default",
26
+ scrollable: false,
27
+ },
28
+ }
29
+ )
package/src/ui/tabs.tsx CHANGED
@@ -1,8 +1,9 @@
1
1
  "use client"
2
2
 
3
3
  import * as React from "react"
4
- import { cva, type VariantProps } from "class-variance-authority"
4
+ import type { VariantProps } from "class-variance-authority"
5
5
  import { cn } from "../lib/utils.js"
6
+ import { tabsListVariants } from "./tabs-variants.js"
6
7
  import { Tabs as TabsPrimitive } from "radix-ui"
7
8
 
8
9
  type TabsTriggerSize = "default" | "touch"
@@ -29,33 +30,6 @@ function Tabs({
29
30
  )
30
31
  }
31
32
 
32
- const tabsListVariants = cva(
33
- "group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",
34
- {
35
- variants: {
36
- variant: {
37
- default: "bg-muted",
38
- line: "gap-1 bg-transparent",
39
- },
40
- size: {
41
- default: "",
42
- // The triggers set the height: a fixed one would cap them at 35 px.
43
- touch: "group-data-[orientation=horizontal]/tabs:h-auto",
44
- },
45
- // Keeps to its container's width and scrolls sideways; the line variant keeps room for the active underline.
46
- scrollable: {
47
- false: "",
48
- true: "relative w-full max-w-full min-w-0 justify-start overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:thin] group-data-[orientation=horizontal]/tabs:h-auto data-[variant=line]:pb-1.5 *:flex-none",
49
- },
50
- },
51
- defaultVariants: {
52
- variant: "line",
53
- size: "default",
54
- scrollable: false,
55
- },
56
- }
57
- )
58
-
59
33
  // Scrolls a scrollable list so its active trigger sits in the middle, now and whenever the active tab changes.
60
34
  function useCentredActiveTrigger(list: React.RefObject<HTMLDivElement | null>, isScrollable: boolean) {
61
35
  React.useEffect(() => {
@@ -145,4 +119,4 @@ function TabsContent({
145
119
  )
146
120
  }
147
121
 
148
- export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants }
122
+ export { Tabs, TabsList, TabsTrigger, TabsContent }