@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.
- package/CHANGELOG.md +21 -0
- package/README.md +46 -4
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/messages/en.d.ts +7 -0
- package/dist/messages/en.d.ts.map +1 -1
- package/dist/messages/en.js +7 -0
- package/dist/messages/en.js.map +1 -1
- package/dist/messages/index.d.ts +7 -0
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/notion/AsidePanel.d.ts +64 -0
- package/dist/notion/AsidePanel.d.ts.map +1 -0
- package/dist/notion/AsidePanel.js +154 -0
- package/dist/notion/AsidePanel.js.map +1 -0
- package/dist/notion/Upload.d.ts +0 -2
- package/dist/notion/Upload.d.ts.map +1 -1
- package/dist/notion/Upload.js +1 -15
- package/dist/notion/Upload.js.map +1 -1
- package/dist/notion/format-file-size.d.ts +3 -0
- package/dist/notion/format-file-size.d.ts.map +1 -0
- package/dist/notion/format-file-size.js +17 -0
- package/dist/notion/format-file-size.js.map +1 -0
- package/dist/notion/overlay-open.d.ts +7 -0
- package/dist/notion/overlay-open.d.ts.map +1 -0
- package/dist/notion/overlay-open.js +28 -0
- package/dist/notion/overlay-open.js.map +1 -0
- package/dist/ui/tabs-variants.d.ts +6 -0
- package/dist/ui/tabs-variants.d.ts.map +1 -0
- package/dist/ui/tabs-variants.js +26 -0
- package/dist/ui/tabs-variants.js.map +1 -0
- package/dist/ui/tabs.d.ts +3 -7
- package/dist/ui/tabs.d.ts.map +1 -1
- package/dist/ui/tabs.js +2 -25
- package/dist/ui/tabs.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +16 -1
- package/src/messages/en.ts +7 -0
- package/src/notion/AsidePanel.tsx +346 -0
- package/src/notion/Upload.tsx +1 -16
- package/src/notion/format-file-size.ts +16 -0
- package/src/notion/overlay-open.ts +29 -0
- package/src/ui/tabs-variants.ts +29 -0
- package/src/ui/tabs.tsx +3 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-file-size.d.ts","sourceRoot":"","sources":["../../src/notion/format-file-size.ts"],"names":[],"mappings":"AAGA,mJAAmJ;AACnJ,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,CAWnE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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"];
|
|
3
|
+
/** 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. */
|
|
4
|
+
export function formatFileSize(bytes, locale = "en") {
|
|
5
|
+
const size = Number.isFinite(bytes) ? Math.max(0, bytes) : 0;
|
|
6
|
+
// Bytes in full ("820 bytes"): the short form of the unit is the bare word "byte" in English.
|
|
7
|
+
if (size < 1000)
|
|
8
|
+
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
|
+
}
|
|
17
|
+
//# sourceMappingURL=format-file-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-file-size.js","sourceRoot":"","sources":["../../src/notion/format-file-size.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAU,CAAC;AAE7E,mJAAmJ;AACnJ,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,MAAM,GAAG,IAAI;IACzD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,8FAA8F;IAC9F,IAAI,IAAI,GAAG,IAAI;QAAE,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACrI,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IACxB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,KAAK,IAAI,IAAI,CAAC;QACd,IAAI,IAAI,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a dialog, menu, listbox or popover is open under `root`: one with Radix `data-state="open"`, one that
|
|
3
|
+
* matches `:popover-open`, or a `dialog[open]`. A closed popover that stays in the page with `role="dialog"` does
|
|
4
|
+
* not count. A keyboard handler reads it before acting on Escape, so the overlay closes first.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isOverlayOpen(root: ParentNode): boolean;
|
|
7
|
+
//# sourceMappingURL=overlay-open.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-open.d.ts","sourceRoot":"","sources":["../../src/notion/overlay-open.ts"],"names":[],"mappings":"AAqBA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAEvD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Kept out of the "use client" AsidePanel module so a Server Component or a plain script can call it too.
|
|
2
|
+
// Overlays that handle Escape themselves: a Radix dialog, menu, listbox or popover while it is open, a native modal.
|
|
3
|
+
const OPEN_OVERLAY_SELECTORS = [
|
|
4
|
+
'[role="dialog"][data-state="open"]',
|
|
5
|
+
'[role="alertdialog"][data-state="open"]',
|
|
6
|
+
'[role="menu"][data-state="open"]',
|
|
7
|
+
'[role="listbox"][data-state="open"]',
|
|
8
|
+
"dialog[open]",
|
|
9
|
+
":popover-open",
|
|
10
|
+
];
|
|
11
|
+
function hasMatch(root, selector) {
|
|
12
|
+
try {
|
|
13
|
+
return root.querySelector(selector) !== null;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// A DOM that does not know the selector (`:popover-open` in an older engine) has no such overlay open.
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether a dialog, menu, listbox or popover is open under `root`: one with Radix `data-state="open"`, one that
|
|
22
|
+
* matches `:popover-open`, or a `dialog[open]`. A closed popover that stays in the page with `role="dialog"` does
|
|
23
|
+
* not count. A keyboard handler reads it before acting on Escape, so the overlay closes first.
|
|
24
|
+
*/
|
|
25
|
+
export function isOverlayOpen(root) {
|
|
26
|
+
return OPEN_OVERLAY_SELECTORS.some((selector) => hasMatch(root, selector));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=overlay-open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay-open.js","sourceRoot":"","sources":["../../src/notion/overlay-open.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAE1G,qHAAqH;AACrH,MAAM,sBAAsB,GAAG;IAC7B,oCAAoC;IACpC,yCAAyC;IACzC,kCAAkC;IAClC,qCAAqC;IACrC,cAAc;IACd,eAAe;CACP,CAAC;AAEX,SAAS,QAAQ,CAAC,IAAgB,EAAE,QAAgB;IAClD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,uGAAuG;QACvG,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const tabsListVariants: (props?: ({
|
|
2
|
+
variant?: "default" | "line" | null | undefined;
|
|
3
|
+
size?: "default" | "touch" | null | undefined;
|
|
4
|
+
scrollable?: boolean | null | undefined;
|
|
5
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
|
+
//# sourceMappingURL=tabs-variants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs-variants.d.ts","sourceRoot":"","sources":["../../src/ui/tabs-variants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB;;;;8EAyB5B,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export const tabsListVariants = cva("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", {
|
|
4
|
+
variants: {
|
|
5
|
+
variant: {
|
|
6
|
+
default: "bg-muted",
|
|
7
|
+
line: "gap-1 bg-transparent",
|
|
8
|
+
},
|
|
9
|
+
size: {
|
|
10
|
+
default: "",
|
|
11
|
+
// The triggers set the height: a fixed one would cap them at 35 px.
|
|
12
|
+
touch: "group-data-[orientation=horizontal]/tabs:h-auto",
|
|
13
|
+
},
|
|
14
|
+
// Keeps to its container's width and scrolls sideways; the line variant keeps room for the active underline.
|
|
15
|
+
scrollable: {
|
|
16
|
+
false: "",
|
|
17
|
+
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",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
variant: "line",
|
|
22
|
+
size: "default",
|
|
23
|
+
scrollable: false,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=tabs-variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs-variants.js","sourceRoot":"","sources":["../../src/ui/tabs-variants.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAE9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CACjC,mRAAmR,EACnR;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE,UAAU;YACnB,IAAI,EAAE,sBAAsB;SAC7B;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,EAAE;YACX,oEAAoE;YACpE,KAAK,EAAE,iDAAiD;SACzD;QACD,6GAA6G;QAC7G,UAAU,EAAE;YACV,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,uNAAuN;SAC9N;KACF;IACD,eAAe,EAAE;QACf,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,KAAK;KAClB;CACF,CACF,CAAA"}
|
package/dist/ui/tabs.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import type { VariantProps } from "class-variance-authority";
|
|
3
|
+
import { tabsListVariants } from "./tabs-variants.js";
|
|
3
4
|
import { Tabs as TabsPrimitive } from "radix-ui";
|
|
4
5
|
type TabsTriggerSize = "default" | "touch";
|
|
5
6
|
declare function Tabs({ className, orientation, ...props }: React.ComponentProps<typeof TabsPrimitive.Root>): React.JSX.Element;
|
|
6
|
-
declare const tabsListVariants: (props?: ({
|
|
7
|
-
variant?: "default" | "line" | null | undefined;
|
|
8
|
-
size?: "default" | "touch" | null | undefined;
|
|
9
|
-
scrollable?: boolean | null | undefined;
|
|
10
|
-
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
7
|
declare function TabsList({ className, variant, size, scrollable, ref, ...props }: React.ComponentProps<typeof TabsPrimitive.List> & VariantProps<typeof tabsListVariants>): React.JSX.Element;
|
|
12
8
|
declare function TabsTrigger({ className, size, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger> & {
|
|
13
9
|
size?: TabsTriggerSize;
|
|
14
10
|
}): React.JSX.Element;
|
|
15
11
|
declare function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>): React.JSX.Element;
|
|
16
|
-
export { Tabs, TabsList, TabsTrigger, TabsContent
|
|
12
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
|
17
13
|
//# sourceMappingURL=tabs.d.ts.map
|
package/dist/ui/tabs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/ui/tabs.tsx"],"names":[],"mappings":"AAEA,O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as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
-
import { cva } from "class-variance-authority";
|
|
5
4
|
import { cn } from "../lib/utils.js";
|
|
5
|
+
import { tabsListVariants } from "./tabs-variants.js";
|
|
6
6
|
import { Tabs as TabsPrimitive } from "radix-ui";
|
|
7
7
|
// A list's size reaches its triggers through context, so a trigger's own size can win over it.
|
|
8
8
|
const TabsTriggerSizeContext = React.createContext("default");
|
|
9
9
|
function Tabs({ className, orientation = "horizontal", ...props }) {
|
|
10
10
|
return (_jsx(TabsPrimitive.Root, { "data-slot": "tabs", "data-orientation": orientation, orientation: orientation, className: cn("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col has-data-[scrollable=true]:min-w-0", className), ...props }));
|
|
11
11
|
}
|
|
12
|
-
const tabsListVariants = cva("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", {
|
|
13
|
-
variants: {
|
|
14
|
-
variant: {
|
|
15
|
-
default: "bg-muted",
|
|
16
|
-
line: "gap-1 bg-transparent",
|
|
17
|
-
},
|
|
18
|
-
size: {
|
|
19
|
-
default: "",
|
|
20
|
-
// The triggers set the height: a fixed one would cap them at 35 px.
|
|
21
|
-
touch: "group-data-[orientation=horizontal]/tabs:h-auto",
|
|
22
|
-
},
|
|
23
|
-
// Keeps to its container's width and scrolls sideways; the line variant keeps room for the active underline.
|
|
24
|
-
scrollable: {
|
|
25
|
-
false: "",
|
|
26
|
-
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",
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
defaultVariants: {
|
|
30
|
-
variant: "line",
|
|
31
|
-
size: "default",
|
|
32
|
-
scrollable: false,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
12
|
// Scrolls a scrollable list so its active trigger sits in the middle, now and whenever the active tab changes.
|
|
36
13
|
function useCentredActiveTrigger(list, isScrollable) {
|
|
37
14
|
React.useEffect(() => {
|
|
@@ -69,5 +46,5 @@ function TabsTrigger({ className, size, ...props }) {
|
|
|
69
46
|
function TabsContent({ className, ...props }) {
|
|
70
47
|
return (_jsx(TabsPrimitive.Content, { "data-slot": "tabs-content", className: cn("flex-1 outline-none", className), ...props }));
|
|
71
48
|
}
|
|
72
|
-
export { Tabs, TabsList, TabsTrigger, TabsContent
|
|
49
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent };
|
|
73
50
|
//# sourceMappingURL=tabs.js.map
|
package/dist/ui/tabs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/ui/tabs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/ui/tabs.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,UAAU,CAAA;AAIhD,+FAA+F;AAC/F,MAAM,sBAAsB,GAAG,KAAK,CAAC,aAAa,CAAkB,SAAS,CAAC,CAAA;AAE9E,SAAS,IAAI,CAAC,EACZ,SAAS,EACT,WAAW,GAAG,YAAY,EAC1B,GAAG,KAAK,EACwC;IAChD,OAAO,CACL,KAAC,aAAa,CAAC,IAAI,iBACP,MAAM,sBACE,WAAW,EAC7B,WAAW,EAAE,WAAW,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AC,KAC3C,KAAK,GACT,CACH,CAAA;AACH,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softure-ai/theme-notion",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "SOFTURE AI Notion theme: shadcn/ui components (new-york v4, Radix, Tailwind CSS v4, lucide) with the Notion design system's tokens and deltas, ready to import.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -40,10 +40,25 @@ export * from "./ui/switch.js";
|
|
|
40
40
|
export { SWITCH_THUMB_SHADOW_CLASS } from "./ui/switch-thumb.js";
|
|
41
41
|
export * from "./ui/table.js";
|
|
42
42
|
export * from "./ui/tabs.js";
|
|
43
|
+
export { tabsListVariants } from "./ui/tabs-variants.js";
|
|
43
44
|
export * from "./ui/textarea.js";
|
|
44
45
|
export * from "./ui/tooltip.js";
|
|
45
46
|
|
|
46
47
|
export { ICON_STROKE_WIDTH } from "./notion/icon-stroke.js";
|
|
48
|
+
export {
|
|
49
|
+
AsidePanel,
|
|
50
|
+
AsidePanelProvider,
|
|
51
|
+
AsidePanelSidebarOpener,
|
|
52
|
+
AsidePanelToggle,
|
|
53
|
+
useAsidePanel,
|
|
54
|
+
type AsidePanelProps,
|
|
55
|
+
type AsidePanelProviderProps,
|
|
56
|
+
type AsidePanelSidebarOpenerProps,
|
|
57
|
+
type AsidePanelState,
|
|
58
|
+
type AsidePanelToggleProps,
|
|
59
|
+
type AsidePanelWidth,
|
|
60
|
+
} from "./notion/AsidePanel.js";
|
|
61
|
+
export { isOverlayOpen } from "./notion/overlay-open.js";
|
|
47
62
|
export { Code, CodeBlock, type CodeBlockProps } from "./notion/Code.js";
|
|
48
63
|
export { DetailTable, type DetailRow, type DetailTableProps } from "./notion/DetailTable.js";
|
|
49
64
|
export { FilterChip, FilterChipAdd, type FilterChipAddProps, type FilterChipProps } from "./notion/FilterChip.js";
|
|
@@ -92,7 +107,6 @@ export {
|
|
|
92
107
|
UploadField,
|
|
93
108
|
UploadItem,
|
|
94
109
|
UploadList,
|
|
95
|
-
formatFileSize,
|
|
96
110
|
type UploadFieldProps,
|
|
97
111
|
type UploadFileItem,
|
|
98
112
|
type UploadItemProps,
|
|
@@ -101,5 +115,6 @@ export {
|
|
|
101
115
|
type UploadMessagesOverride,
|
|
102
116
|
type UploadState,
|
|
103
117
|
} from "./notion/Upload.js";
|
|
118
|
+
export { formatFileSize } from "./notion/format-file-size.js";
|
|
104
119
|
export { UpdatePrompt, type UpdatePromptProps } from "./notion/UpdatePrompt.js";
|
|
105
120
|
export { TONES, TONE_COLORS, TONE_EDGE, TONE_FILL, TONE_TEXT, type Tone } from "./notion/tones.js";
|
package/src/messages/en.ts
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* replace it with the app's own wording from its message layer.
|
|
4
4
|
*/
|
|
5
5
|
export const en = {
|
|
6
|
+
asidePanel: {
|
|
7
|
+
show: "Show the panel",
|
|
8
|
+
hide: "Hide the panel",
|
|
9
|
+
widen: "Widen the panel",
|
|
10
|
+
narrow: "Narrow the panel",
|
|
11
|
+
showSidebar: "Show the menu and hide the panel",
|
|
12
|
+
},
|
|
6
13
|
breadcrumb: { label: "breadcrumb", more: "More" },
|
|
7
14
|
dialog: { close: "Close" },
|
|
8
15
|
filterChip: { add: "Add filter" },
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useIsMobile } from "@softure-ai/theme-kit/react";
|
|
4
|
+
import { ChevronsLeft, ChevronsRight, PanelLeft, PanelRightClose, PanelRightOpen } from "lucide-react";
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
type ComponentProps,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
type RefObject,
|
|
16
|
+
} from "react";
|
|
17
|
+
|
|
18
|
+
import { cn } from "../lib/utils.js";
|
|
19
|
+
import { en as messages } from "../messages/en.js";
|
|
20
|
+
import { Button } from "../ui/button.js";
|
|
21
|
+
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "../ui/sheet.js";
|
|
22
|
+
import { SidebarProvider } from "../ui/sidebar.js";
|
|
23
|
+
|
|
24
|
+
import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
|
|
25
|
+
import { isOverlayOpen } from "./overlay-open.js";
|
|
26
|
+
|
|
27
|
+
// `standard` takes two fifths of the shell, `half` splits the shell half and half between the content and the panel.
|
|
28
|
+
export type AsidePanelWidth = "standard" | "half";
|
|
29
|
+
|
|
30
|
+
// What the app keeps per signed-in user, so the panel opens the same way across screens, reloads and devices.
|
|
31
|
+
export interface AsidePanelState {
|
|
32
|
+
readonly isOpen: boolean;
|
|
33
|
+
readonly width: AsidePanelWidth;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type AsidePanelProviderProps = Omit<ComponentProps<typeof SidebarProvider>, "open" | "onOpenChange" | "hidden"> & {
|
|
37
|
+
// The kept state the panel starts from on a wide screen; a phone always starts closed.
|
|
38
|
+
readonly initialState: AsidePanelState;
|
|
39
|
+
// Called with the new state after each change on a wide screen; a failed save keeps the choice on the page.
|
|
40
|
+
readonly save?: (state: AsidePanelState) => void | Promise<void>;
|
|
41
|
+
// Receives a failed save (a rejected promise or a thrown error).
|
|
42
|
+
readonly onSaveError?: (error: unknown) => void;
|
|
43
|
+
// A screen that offers no panel: no toggle, no panel, and the sidebar stays open whatever the kept state says.
|
|
44
|
+
readonly isHidden?: boolean;
|
|
45
|
+
// The panel's `id`, which the toggle points at with `aria-controls`.
|
|
46
|
+
readonly panelId?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
interface AsidePanelContextValue {
|
|
50
|
+
readonly panelId: string;
|
|
51
|
+
readonly isOpen: boolean;
|
|
52
|
+
readonly width: AsidePanelWidth;
|
|
53
|
+
readonly isMobile: boolean;
|
|
54
|
+
readonly isHidden: boolean;
|
|
55
|
+
readonly isSidebarFolded: boolean;
|
|
56
|
+
readonly toggleRef: RefObject<HTMLButtonElement | null>;
|
|
57
|
+
readonly isHeadingFocusRequested: RefObject<boolean>;
|
|
58
|
+
readonly toggle: () => void;
|
|
59
|
+
readonly close: () => void;
|
|
60
|
+
readonly setWidth: (width: AsidePanelWidth) => void;
|
|
61
|
+
readonly openSidebar: () => void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const AsidePanelContext = createContext<AsidePanelContextValue | null>(null);
|
|
65
|
+
|
|
66
|
+
/** The panel's state and actions, for an app that builds its own toggle or reads whether the panel is open. */
|
|
67
|
+
export function useAsidePanel(): Pick<AsidePanelContextValue, "panelId" | "isOpen" | "width" | "isMobile" | "isHidden" | "isSidebarFolded" | "toggle" | "close" | "setWidth" | "openSidebar"> {
|
|
68
|
+
const context = useContext(AsidePanelContext);
|
|
69
|
+
if (context === null) throw new Error("useAsidePanel must be used within an AsidePanelProvider.");
|
|
70
|
+
return context;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function useAsidePanelContext(component: string): AsidePanelContextValue {
|
|
74
|
+
const context = useContext(AsidePanelContext);
|
|
75
|
+
if (context === null) throw new Error(`${component} must be used within an AsidePanelProvider.`);
|
|
76
|
+
return context;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The app shell's provider: renders `SidebarProvider` and keeps one side panel open at a time. While the right panel
|
|
81
|
+
* is open on a wide screen, the left sidebar is folded (offcanvas); opening the sidebar any way closes the panel.
|
|
82
|
+
* Use it in place of `SidebarProvider`; every other `SidebarProvider` prop passes through.
|
|
83
|
+
*/
|
|
84
|
+
export function AsidePanelProvider({
|
|
85
|
+
initialState,
|
|
86
|
+
save,
|
|
87
|
+
onSaveError,
|
|
88
|
+
isHidden = false,
|
|
89
|
+
panelId = "aside-panel",
|
|
90
|
+
defaultOpen = true,
|
|
91
|
+
children,
|
|
92
|
+
...props
|
|
93
|
+
}: AsidePanelProviderProps) {
|
|
94
|
+
const isMobile = useIsMobile();
|
|
95
|
+
const [kept, setKept] = useState<AsidePanelState>(initialState);
|
|
96
|
+
const [isMobileOpen, setMobileOpen] = useState(false);
|
|
97
|
+
const [isSidebarOpen, setSidebarOpen] = useState(defaultOpen);
|
|
98
|
+
const toggleRef = useRef<HTMLButtonElement>(null);
|
|
99
|
+
const isHeadingFocusRequested = useRef(false);
|
|
100
|
+
|
|
101
|
+
const isOpen = isHidden ? false : isMobile ? isMobileOpen : kept.isOpen;
|
|
102
|
+
const isSidebarShown = isSidebarOpen && !(kept.isOpen && !isMobile && !isHidden);
|
|
103
|
+
|
|
104
|
+
const keep = useCallback(
|
|
105
|
+
(next: AsidePanelState) => {
|
|
106
|
+
setKept(next);
|
|
107
|
+
if (save === undefined) return;
|
|
108
|
+
// The choice stays on the page when the save fails; the app hears about it through `onSaveError`.
|
|
109
|
+
Promise.resolve()
|
|
110
|
+
.then(() => save(next))
|
|
111
|
+
.catch((error: unknown) => onSaveError?.(error));
|
|
112
|
+
},
|
|
113
|
+
[save, onSaveError],
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const setPanelOpen = useCallback(
|
|
117
|
+
(next: boolean) => {
|
|
118
|
+
if (isMobile) setMobileOpen(next);
|
|
119
|
+
else if (next !== kept.isOpen) keep({ ...kept, isOpen: next });
|
|
120
|
+
},
|
|
121
|
+
[isMobile, kept, keep],
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const toggle = useCallback(() => {
|
|
125
|
+
if (!isOpen) isHeadingFocusRequested.current = true;
|
|
126
|
+
setPanelOpen(!isOpen);
|
|
127
|
+
}, [isOpen, setPanelOpen]);
|
|
128
|
+
|
|
129
|
+
const close = useCallback(() => setPanelOpen(false), [setPanelOpen]);
|
|
130
|
+
|
|
131
|
+
const setWidth = useCallback(
|
|
132
|
+
(width: AsidePanelWidth) => {
|
|
133
|
+
if (width !== kept.width) keep({ ...kept, width });
|
|
134
|
+
},
|
|
135
|
+
[kept, keep],
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const openSidebar = useCallback(() => {
|
|
139
|
+
setSidebarOpen(true);
|
|
140
|
+
if (kept.isOpen && !isMobile) keep({ ...kept, isOpen: false });
|
|
141
|
+
}, [isMobile, kept, keep]);
|
|
142
|
+
|
|
143
|
+
const changeSidebar = useCallback(
|
|
144
|
+
(next: boolean) => {
|
|
145
|
+
if (next) openSidebar();
|
|
146
|
+
else setSidebarOpen(false);
|
|
147
|
+
},
|
|
148
|
+
[openSidebar],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const value = useMemo<AsidePanelContextValue>(
|
|
152
|
+
() => ({
|
|
153
|
+
panelId,
|
|
154
|
+
isOpen,
|
|
155
|
+
width: kept.width,
|
|
156
|
+
isMobile,
|
|
157
|
+
isHidden,
|
|
158
|
+
isSidebarFolded: !isSidebarShown,
|
|
159
|
+
toggleRef,
|
|
160
|
+
isHeadingFocusRequested,
|
|
161
|
+
toggle,
|
|
162
|
+
close,
|
|
163
|
+
setWidth,
|
|
164
|
+
openSidebar,
|
|
165
|
+
}),
|
|
166
|
+
[panelId, isOpen, kept.width, isMobile, isHidden, isSidebarShown, toggle, close, setWidth, openSidebar],
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<AsidePanelContext.Provider value={value}>
|
|
171
|
+
<SidebarProvider open={isSidebarShown} onOpenChange={changeSidebar} {...props}>
|
|
172
|
+
{children}
|
|
173
|
+
</SidebarProvider>
|
|
174
|
+
</AsidePanelContext.Provider>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface AsidePanelToggleProps {
|
|
179
|
+
// The accessible names while closed and while open, from the app's message layer.
|
|
180
|
+
readonly showLabel?: string;
|
|
181
|
+
readonly hideLabel?: string;
|
|
182
|
+
readonly className?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The icon button at the top-right edge that shows and hides the panel; it stays in place either way. */
|
|
186
|
+
export function AsidePanelToggle({ showLabel = messages.asidePanel.show, hideLabel = messages.asidePanel.hide, className }: AsidePanelToggleProps) {
|
|
187
|
+
const { panelId, isOpen, isHidden, toggleRef, toggle } = useAsidePanelContext("AsidePanelToggle");
|
|
188
|
+
if (isHidden) return null;
|
|
189
|
+
const Icon = isOpen ? PanelRightClose : PanelRightOpen;
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<Button
|
|
193
|
+
ref={toggleRef}
|
|
194
|
+
type="button"
|
|
195
|
+
data-slot="aside-panel-toggle"
|
|
196
|
+
variant={isOpen ? "secondary" : "outline"}
|
|
197
|
+
size="icon"
|
|
198
|
+
aria-expanded={isOpen}
|
|
199
|
+
aria-controls={panelId}
|
|
200
|
+
aria-label={isOpen ? hideLabel : showLabel}
|
|
201
|
+
className={cn("fixed top-[calc(--spacing(2)+env(safe-area-inset-top))] right-[calc(--spacing(2)+env(safe-area-inset-right))] z-20", className)}
|
|
202
|
+
onClick={toggle}
|
|
203
|
+
>
|
|
204
|
+
<Icon aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
|
|
205
|
+
</Button>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface AsidePanelSidebarOpenerProps {
|
|
210
|
+
// The accessible name ("show the menu and hide the panel"), from the app's message layer.
|
|
211
|
+
readonly label?: string;
|
|
212
|
+
readonly className?: string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** The icon button at the top-left edge, shown only while the sidebar is folded: brings it back, closes the panel. */
|
|
216
|
+
export function AsidePanelSidebarOpener({ label = messages.asidePanel.showSidebar, className }: AsidePanelSidebarOpenerProps) {
|
|
217
|
+
const { isMobile, isSidebarFolded, openSidebar } = useAsidePanelContext("AsidePanelSidebarOpener");
|
|
218
|
+
if (isMobile || !isSidebarFolded) return null;
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<Button
|
|
222
|
+
type="button"
|
|
223
|
+
data-slot="aside-panel-sidebar-opener"
|
|
224
|
+
variant="outline"
|
|
225
|
+
size="icon"
|
|
226
|
+
aria-label={label}
|
|
227
|
+
className={cn("fixed top-[calc(--spacing(2)+env(safe-area-inset-top))] left-[calc(--spacing(2)+env(safe-area-inset-left))] z-20", className)}
|
|
228
|
+
onClick={openSidebar}
|
|
229
|
+
>
|
|
230
|
+
<PanelLeft aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
|
|
231
|
+
</Button>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface AsidePanelProps {
|
|
236
|
+
readonly title: string;
|
|
237
|
+
// The panel's body, rendered only while the panel is open: pass a lazily loaded component (`next/dynamic` with
|
|
238
|
+
// `ssr: false`, or `React.lazy`), so screens that never open the panel never load its code.
|
|
239
|
+
readonly children: ReactNode;
|
|
240
|
+
// The width switch's accessible names, from the app's message layer.
|
|
241
|
+
readonly widenLabel?: string;
|
|
242
|
+
readonly narrowLabel?: string;
|
|
243
|
+
// The phone sheet's close button text.
|
|
244
|
+
readonly closeLabel?: string;
|
|
245
|
+
readonly className?: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The panel: an `aside` beside the shell's content on a wide screen (the content narrows next to it), a right `Sheet`
|
|
250
|
+
* on a phone. Place it after `SidebarInset` inside `AsidePanelProvider`.
|
|
251
|
+
*/
|
|
252
|
+
export function AsidePanel({
|
|
253
|
+
title,
|
|
254
|
+
children,
|
|
255
|
+
widenLabel = messages.asidePanel.widen,
|
|
256
|
+
narrowLabel = messages.asidePanel.narrow,
|
|
257
|
+
closeLabel,
|
|
258
|
+
className,
|
|
259
|
+
}: AsidePanelProps) {
|
|
260
|
+
const { panelId, isOpen, width, isMobile, isHidden, toggleRef, isHeadingFocusRequested, close, setWidth } = useAsidePanelContext("AsidePanel");
|
|
261
|
+
const headingRef = useRef<HTMLHeadingElement>(null);
|
|
262
|
+
const headingId = `${panelId}-heading`;
|
|
263
|
+
const isDesktopOpen = isOpen && !isMobile && !isHidden;
|
|
264
|
+
|
|
265
|
+
// Opening from the toggle moves focus to the heading; a panel kept open on load leaves focus alone.
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
if (!isDesktopOpen || !isHeadingFocusRequested.current) return;
|
|
268
|
+
isHeadingFocusRequested.current = false;
|
|
269
|
+
headingRef.current?.focus();
|
|
270
|
+
}, [isDesktopOpen, isHeadingFocusRequested]);
|
|
271
|
+
|
|
272
|
+
// Escape closes the panel and returns focus to the toggle, unless an open overlay takes the key first.
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (!isDesktopOpen) return;
|
|
275
|
+
const closeOnEscape = (event: KeyboardEvent) => {
|
|
276
|
+
if (event.key !== "Escape" || event.defaultPrevented || isOverlayOpen(document)) return;
|
|
277
|
+
close();
|
|
278
|
+
toggleRef.current?.focus();
|
|
279
|
+
};
|
|
280
|
+
document.addEventListener("keydown", closeOnEscape);
|
|
281
|
+
return () => document.removeEventListener("keydown", closeOnEscape);
|
|
282
|
+
}, [isDesktopOpen, close, toggleRef]);
|
|
283
|
+
|
|
284
|
+
if (isHidden) return null;
|
|
285
|
+
|
|
286
|
+
if (isMobile) {
|
|
287
|
+
return (
|
|
288
|
+
<Sheet open={isOpen} onOpenChange={(next) => !next && close()}>
|
|
289
|
+
<SheetContent
|
|
290
|
+
id={panelId}
|
|
291
|
+
side="right"
|
|
292
|
+
data-slot="aside-panel-sheet"
|
|
293
|
+
aria-describedby={undefined}
|
|
294
|
+
closeLabel={closeLabel}
|
|
295
|
+
className={cn("w-full gap-0 sm:max-w-none", className)}
|
|
296
|
+
onOpenAutoFocus={(event) => {
|
|
297
|
+
event.preventDefault();
|
|
298
|
+
headingRef.current?.focus();
|
|
299
|
+
}}
|
|
300
|
+
onCloseAutoFocus={(event) => {
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
toggleRef.current?.focus();
|
|
303
|
+
}}
|
|
304
|
+
>
|
|
305
|
+
<SheetHeader className="border-b border-border">
|
|
306
|
+
<SheetTitle ref={headingRef} tabIndex={-1} className="outline-none">
|
|
307
|
+
{title}
|
|
308
|
+
</SheetTitle>
|
|
309
|
+
</SheetHeader>
|
|
310
|
+
<div data-slot="aside-panel-content" className="min-h-0 flex-1 overflow-y-auto">
|
|
311
|
+
{isOpen ? children : null}
|
|
312
|
+
</div>
|
|
313
|
+
</SheetContent>
|
|
314
|
+
</Sheet>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!isOpen) return null;
|
|
319
|
+
const isHalf = width === "half";
|
|
320
|
+
const WidthIcon = isHalf ? ChevronsRight : ChevronsLeft;
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<aside
|
|
324
|
+
id={panelId}
|
|
325
|
+
data-slot="aside-panel"
|
|
326
|
+
data-width={width}
|
|
327
|
+
aria-labelledby={headingId}
|
|
328
|
+
className={cn(
|
|
329
|
+
"sticky top-0 flex h-dvh w-2/5 shrink-0 flex-col border-l border-border bg-background text-foreground data-[width=half]:w-1/2",
|
|
330
|
+
className,
|
|
331
|
+
)}
|
|
332
|
+
>
|
|
333
|
+
<div data-slot="aside-panel-header" className="flex h-11 shrink-0 items-center gap-2 border-b border-border pr-12 pl-4">
|
|
334
|
+
<h2 ref={headingRef} id={headingId} tabIndex={-1} className="min-w-0 flex-1 truncate text-heading-3 outline-none">
|
|
335
|
+
{title}
|
|
336
|
+
</h2>
|
|
337
|
+
<Button type="button" variant="ghost" size="icon" aria-label={isHalf ? narrowLabel : widenLabel} onClick={() => setWidth(isHalf ? "standard" : "half")}>
|
|
338
|
+
<WidthIcon aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
|
|
339
|
+
</Button>
|
|
340
|
+
</div>
|
|
341
|
+
<div data-slot="aside-panel-content" className="min-h-0 flex-1 overflow-y-auto">
|
|
342
|
+
{children}
|
|
343
|
+
</div>
|
|
344
|
+
</aside>
|
|
345
|
+
);
|
|
346
|
+
}
|
package/src/notion/Upload.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { Button } from "../ui/button.js";
|
|
|
9
9
|
import { Field, FieldDescription, FieldError, FieldLabel } from "../ui/field.js";
|
|
10
10
|
import { Progress } from "../ui/progress.js";
|
|
11
11
|
|
|
12
|
+
import { formatFileSize } from "./format-file-size.js";
|
|
12
13
|
import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
|
|
13
14
|
import type { PaletteColor } from "./palette.js";
|
|
14
15
|
import { Status } from "./Status.js";
|
|
@@ -52,22 +53,6 @@ export interface UploadMessages {
|
|
|
52
53
|
/** The app's wording for the upload parts; each text left out keeps the built-in English one. */
|
|
53
54
|
export type UploadMessagesOverride = Partial<UploadMessages>;
|
|
54
55
|
|
|
55
|
-
const SIZE_UNITS = ["kilobyte", "megabyte", "gigabyte", "terabyte"] as const;
|
|
56
|
-
|
|
57
|
-
/** A file size for people, in decimal steps (1 kB = 1000 bytes), written by the locale: `formatFileSize(1500)` is "1.5 kB". */
|
|
58
|
-
export function formatFileSize(bytes: number, locale = "en"): string {
|
|
59
|
-
const size = Number.isFinite(bytes) ? Math.max(0, bytes) : 0;
|
|
60
|
-
// Bytes in full ("820 bytes"): the short form of the unit is the bare word "byte" in English.
|
|
61
|
-
if (size < 1000) return new Intl.NumberFormat(locale, { style: "unit", unit: "byte", unitDisplay: "long" }).format(Math.round(size));
|
|
62
|
-
let value = size / 1000;
|
|
63
|
-
let unit = 0;
|
|
64
|
-
while (value >= 1000 && unit < SIZE_UNITS.length - 1) {
|
|
65
|
-
value /= 1000;
|
|
66
|
-
unit += 1;
|
|
67
|
-
}
|
|
68
|
-
return new Intl.NumberFormat(locale, { style: "unit", unit: SIZE_UNITS[unit], unitDisplay: "short", maximumFractionDigits: 1 }).format(value);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
56
|
function mergeMessages(override: UploadMessagesOverride | undefined): UploadMessages {
|
|
72
57
|
return { ...en.upload, ...override };
|
|
73
58
|
}
|