@f-office/docs-react 0.0.0-stage → 0.2.3
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/LICENSE +168 -0
- package/NOTICE +31 -0
- package/README.md +92 -2
- package/dist/chrome.d.ts +46 -0
- package/dist/dialogs.d.ts +6 -0
- package/dist/docs-app.d.ts +8 -0
- package/dist/docs-canvas.d.ts +11 -0
- package/dist/docs-provider.d.ts +66 -0
- package/dist/f-office-docs.d.ts +46 -0
- package/dist/header.d.ts +35 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1477 -0
- package/dist/keep.d.ts +62 -0
- package/dist/menus.d.ts +7 -0
- package/dist/page-keys.d.ts +13 -0
- package/dist/page-menu.d.ts +8 -0
- package/dist/start.d.ts +2 -0
- package/dist/styles.css +2 -0
- package/dist/theme.d.ts +17 -0
- package/dist/ui/context-menu.d.ts +8 -0
- package/dist/ui/dialog.d.ts +7 -0
- package/dist/ui/menu-shortcut.d.ts +5 -0
- package/dist/ui/menubar.d.ts +16 -0
- package/dist/ui/portal-theme.d.ts +5 -0
- package/dist/ui/utils.d.ts +3 -0
- package/dist/url-file.d.ts +25 -0
- package/package.json +87 -4
package/dist/keep.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type View } from "@f-office/docs/chrome";
|
|
2
|
+
/** The largest file kept across reloads, in bytes: 50 MB. */
|
|
3
|
+
export declare const KEEP_LIMIT = 50000000;
|
|
4
|
+
/** How long the view stays still before persisting it, in milliseconds. */
|
|
5
|
+
export declare const VIEW_DELAY = 400;
|
|
6
|
+
/** A document kept in browser-private storage: its name, bytes, and last view. */
|
|
7
|
+
export type Kept = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly bytes: ArrayBuffer;
|
|
10
|
+
readonly view: View | null;
|
|
11
|
+
};
|
|
12
|
+
/** Outcome of attempting to persist an opened file across reloads. */
|
|
13
|
+
export type KeepResult = "kept" | "too-large" | "failed";
|
|
14
|
+
/** User-facing note describing persistence status. */
|
|
15
|
+
export declare const KEEP_NOTES: Record<KeepResult, string>;
|
|
16
|
+
/** Storage slots for the persisted document. */
|
|
17
|
+
export type Slot = "name" | "bytes" | "view";
|
|
18
|
+
/** Storage adapter for reading, writing, and removing kept slots. */
|
|
19
|
+
export type Slots = {
|
|
20
|
+
read: (slot: Slot) => Promise<ArrayBuffer | null>;
|
|
21
|
+
write: (slot: Slot, data: ArrayBuffer) => Promise<void>;
|
|
22
|
+
remove: (slot: Slot) => Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Keeps the last opened file and its view in browser-private storage (OPFS with IndexedDB
|
|
26
|
+
* fallback) so reloads reopen it locally. Calls never throw and execute in order.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Keeper {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(slots: Promise<Slots | null>, delay?: number);
|
|
31
|
+
/** Loads the kept file, or `null` when none exists or storage cannot be read. */
|
|
32
|
+
load(): Promise<Kept | null>;
|
|
33
|
+
/** Persists a newly opened file, replacing any previously kept file. */
|
|
34
|
+
keep(name: string, bytes: ArrayBuffer): Promise<KeepResult>;
|
|
35
|
+
/** Persists the current view once scrolling/zooming settles for the debounce delay. */
|
|
36
|
+
keepView(view: View): void;
|
|
37
|
+
/** Immediately flushes any pending view write (e.g. on `pagehide`). */
|
|
38
|
+
flush(): Promise<void>;
|
|
39
|
+
/** Removes the kept file and view from browser storage. */
|
|
40
|
+
forget(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/** Minimal OPFS directory interface needed by {@link folderSlots}. */
|
|
43
|
+
export type Folder = {
|
|
44
|
+
getFileHandle: (name: string, options?: {
|
|
45
|
+
create?: boolean;
|
|
46
|
+
}) => Promise<{
|
|
47
|
+
getFile: () => Promise<Blob>;
|
|
48
|
+
createWritable: () => Promise<{
|
|
49
|
+
write: (data: ArrayBuffer) => Promise<void>;
|
|
50
|
+
close: () => Promise<void>;
|
|
51
|
+
}>;
|
|
52
|
+
}>;
|
|
53
|
+
removeEntry: (name: string) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/** Stores slots as `.bin` files in an OPFS folder. */
|
|
56
|
+
export declare function folderSlots(folder: Folder): Slots;
|
|
57
|
+
/** Stores slots in an IndexedDB object store. */
|
|
58
|
+
export declare function databaseSlots(database: IDBDatabase): Slots;
|
|
59
|
+
/** Opens the IndexedDB database, returning `null` when blocked. */
|
|
60
|
+
export declare function openDatabase(factory: IDBFactory): Promise<IDBDatabase | null>;
|
|
61
|
+
/** Browser-private storage: OPFS when writable, IndexedDB fallback, or `null` when unavailable. */
|
|
62
|
+
export declare function browserSlots(): Promise<Slots | null>;
|
package/dist/menus.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Menu bar (File, Edit, View, Tools, Help) bound to {@link useDocs}.
|
|
3
|
+
* Can be rendered inside {@link DocsHeader} or inside any host-provided custom header.
|
|
4
|
+
*/
|
|
5
|
+
export declare function DocsMenuBar({ className }: {
|
|
6
|
+
className?: string;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { FOfficeDocsElement } from "@f-office/docs";
|
|
3
|
+
import { type CommandId } from "@f-office/docs/chrome";
|
|
4
|
+
/** Command guard and runner for {@link useCommandKeys}. */
|
|
5
|
+
export type KeyCommands = {
|
|
6
|
+
readonly takes: (id: CommandId) => boolean;
|
|
7
|
+
readonly run: (id: CommandId) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Listens for page-level document shortcuts (Ctrl+O, Ctrl+P, zoom, find, etc.) and idle scroll
|
|
11
|
+
* keys using React 19 `useEffectEvent` so the window listener stays stable across renders.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useCommandKeys(commands: KeyCommands, docsRef: RefObject<FOfficeDocsElement | null>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { FOfficeDocsElement } from "@f-office/docs";
|
|
3
|
+
import { type MenuRequest } from "@f-office/docs/chrome";
|
|
4
|
+
/** Right-click / Shift+F10 context menu for pages inside {@link DocsCanvas}. */
|
|
5
|
+
export declare function PageMenu({ request, elementRef, }: {
|
|
6
|
+
request: MenuRequest | null;
|
|
7
|
+
elementRef: RefObject<FOfficeDocsElement | null>;
|
|
8
|
+
}): import("react").JSX.Element;
|
package/dist/start.d.ts
ADDED
package/dist/styles.css
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
|
|
2
|
+
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-duration:initial;--tw-ease:initial}}}@layer theme{:root,:host{--font-sans:system-ui, -apple-system, "Segoe UI", sans-serif;--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-black:#000;--spacing:.25rem;--container-xl:36rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--font-weight-normal:400;--font-weight-medium:500;--tracking-widest:.1em;--radius-2xl:1rem;--ease-out:cubic-bezier(0, 0, .2, 1);--animate-pulse:pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1)}}@layer base{.f-office-docs-root,.f-office-docs-root *,.f-office-docs-portal,.f-office-docs-portal *{box-sizing:border-box;border-style:solid;border-width:0;border-color:var(--f-office-border);outline-color:var(--f-office-ring)}@supports (color:color-mix(in lab, red, red)){.f-office-docs-root,.f-office-docs-root *,.f-office-docs-portal,.f-office-docs-portal *{outline-color:color-mix(in oklab, var(--f-office-ring) 50%, transparent)}}.f-office-docs-root :is(h1,h2,h3,p),.f-office-docs-portal :is(h1,h2,h3,p){font-weight:inherit;margin:0}.f-office-docs-root :is(button,select),.f-office-docs-portal :is(button,select){font:inherit;color:inherit;cursor:pointer;background-color:#0000}.f-office-docs-root kbd,.f-office-docs-portal kbd{font-family:ui-monospace,SFMono-Regular,Menlo,monospace}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.inset-0{inset:0}.inset-x-0{inset-inline:0}.top-0{top:0}.top-1\/2{top:50%}.top-4{top:calc(var(--spacing) * 4)}.right-4{right:calc(var(--spacing) * 4)}.left-1\/2{left:50%}.left-2{left:calc(var(--spacing) * 2)}.z-10{z-index:10}.z-50{z-index:50}.container{width:100%}@media (width>=40rem){.container{max-width:40rem}}@media (width>=48rem){.container{max-width:48rem}}@media (width>=64rem){.container{max-width:64rem}}@media (width>=80rem){.container{max-width:80rem}}@media (width>=96rem){.container{max-width:96rem}}.-mx-1{margin-inline:calc(var(--spacing) * -1)}.my-1{margin-block:var(--spacing)}.-ml-1\.5{margin-left:calc(var(--spacing) * -1.5)}.ml-auto{margin-left:auto}.block{display:block}.contents{display:contents}.flex{display:flex}.grid{display:grid}.hidden{display:none}.table{display:table}.size-2{width:calc(var(--spacing) * 2);height:calc(var(--spacing) * 2)}.size-4{width:calc(var(--spacing) * 4);height:calc(var(--spacing) * 4)}.size-5{width:calc(var(--spacing) * 5);height:calc(var(--spacing) * 5)}.size-10{width:calc(var(--spacing) * 10);height:calc(var(--spacing) * 10)}.h-0\.5{height:calc(var(--spacing) * .5)}.h-8{height:calc(var(--spacing) * 8)}.h-9{height:calc(var(--spacing) * 9)}.h-10{height:calc(var(--spacing) * 10)}.h-16{height:calc(var(--spacing) * 16)}.h-full{height:100%}.h-px{height:1px}.min-h-0{min-height:0}.w-1\/3{width:33.3333%}.w-\[min\(28rem\,calc\(100\%-2rem\)\)\]{width:min(28rem,100% - 2rem)}.w-auto{width:auto}.w-full{width:100%}.max-w-64{max-width:calc(var(--spacing) * 64)}.max-w-xl{max-width:var(--container-xl)}.min-w-0{min-width:0}.min-w-36{min-width:calc(var(--spacing) * 36)}.min-w-48{min-width:calc(var(--spacing) * 48)}.flex-1{flex:1}.shrink-0{flex-shrink:0}.-translate-x-1\/2{--tw-translate-x:calc(calc(1 / 2 * 100%) * -1);translate:var(--tw-translate-x) var(--tw-translate-y)}.-translate-y-1\/2{--tw-translate-y:calc(calc(1 / 2 * 100%) * -1);translate:var(--tw-translate-x) var(--tw-translate-y)}.transform{transform:var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,)}.animate-pulse{animation:var(--animate-pulse)}.cursor-default{cursor:default}.flex-col{flex-direction:column}.place-items-center{place-items:center}.items-center{align-items:center}.justify-center{justify-content:center}.gap-0\.5{gap:calc(var(--spacing) * .5)}.gap-2{gap:calc(var(--spacing) * 2)}.gap-3{gap:calc(var(--spacing) * 3)}.gap-4{gap:calc(var(--spacing) * 4)}.gap-10{gap:calc(var(--spacing) * 10)}.self-start{align-self:flex-start}.truncate{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-full{border-radius:2147483647px}.rounded-lg{border-radius:var(--f-office-radius)}.rounded-md{border-radius:calc(var(--f-office-radius) - 2px)}.rounded-xl{border-radius:calc(var(--f-office-radius) + 4px)}.border{border-style:var(--tw-border-style);border-width:1px}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-border{border-color:var(--f-office-border)}.bg-\[var\(--f-office-drop\)\]{background-color:var(--f-office-drop)}.bg-background,.bg-background\/85{background-color:var(--f-office-background)}@supports (color:color-mix(in lab, red, red)){.bg-background\/85{background-color:color-mix(in oklab, var(--f-office-background) 85%, transparent)}}.bg-black\/40{background-color:#0006}@supports (color:color-mix(in lab, red, red)){.bg-black\/40{background-color:color-mix(in oklab, var(--color-black) 40%, transparent)}}.bg-border{background-color:var(--f-office-border)}.bg-popover{background-color:var(--f-office-popover)}.bg-primary{background-color:var(--f-office-primary)}.bg-transparent{background-color:#0000}.fill-current{fill:currentColor}.p-1{padding:var(--spacing)}.p-6{padding:calc(var(--spacing) * 6)}.px-1\.5{padding-inline:calc(var(--spacing) * 1.5)}.px-2{padding-inline:calc(var(--spacing) * 2)}.px-3{padding-inline:calc(var(--spacing) * 3)}.px-4{padding-inline:calc(var(--spacing) * 4)}.px-6{padding-inline:calc(var(--spacing) * 6)}.py-0\.5{padding-block:calc(var(--spacing) * .5)}.py-1\.5{padding-block:calc(var(--spacing) * 1.5)}.py-14{padding-block:calc(var(--spacing) * 14)}.pr-4{padding-right:calc(var(--spacing) * 4)}.pl-6{padding-left:calc(var(--spacing) * 6)}.pl-8{padding-left:calc(var(--spacing) * 8)}.text-center{text-align:center}.font-mono{font-family:var(--font-mono)}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-6{--tw-leading:calc(var(--spacing) * 6);line-height:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.tracking-widest{--tw-tracking:var(--tracking-widest);letter-spacing:var(--tracking-widest)}.text-foreground{color:var(--f-office-foreground)}.text-muted-foreground{color:var(--f-office-muted-foreground)}.text-popover-foreground{color:var(--f-office-popover-foreground)}.text-primary{color:var(--f-office-primary)}.text-primary-foreground{color:var(--f-office-primary-foreground)}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a), 0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a), 0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.shadow-xl{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a), 0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.filter{filter:var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,)}.transition-\[width\]{transition-property:width;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.outline-none{--tw-outline-style:none;outline-style:none}.select-all{-webkit-user-select:all;user-select:all}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\:border-primary:hover{border-color:var(--f-office-primary)}.hover\:bg-accent:hover{background-color:var(--f-office-accent)}.hover\:opacity-90:hover{opacity:.9}}.focus\:bg-accent:focus{background-color:var(--f-office-accent)}.focus\:text-accent-foreground:focus{color:var(--f-office-accent-foreground)}.focus-visible\:outline-2:focus-visible{outline-style:var(--tw-outline-style);outline-width:2px}.focus-visible\:outline-offset-2:focus-visible{outline-offset:2px}.focus-visible\:outline-ring:focus-visible{outline-color:var(--f-office-ring)}.data-\[disabled\]\:pointer-events-none[data-disabled]{pointer-events:none}.data-\[disabled\]\:opacity-50[data-disabled]{opacity:.5}.data-\[highlighted\]\:bg-accent[data-highlighted],.data-\[state\=open\]\:bg-accent[data-state=open]{background-color:var(--f-office-accent)}@media (width>=40rem){.sm\:hidden{display:none}.sm\:inline{display:inline}.sm\:h-14{height:calc(var(--spacing) * 14)}.sm\:gap-3{gap:calc(var(--spacing) * 3)}.sm\:px-4{padding-inline:calc(var(--spacing) * 4)}.sm\:px-5{padding-inline:calc(var(--spacing) * 5)}}@media (width>=48rem){.md\:flex{display:flex}}}.f-office-docs-root,.f-office-docs-portal{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light dark;font-family:var(--font-sans);--f-office-radius:.75rem;--f-office-background:var(--lightningcss-light,#f7f8fc)var(--lightningcss-dark,#141416);--f-office-foreground:var(--lightningcss-light,#1d1d1f)var(--lightningcss-dark,#ecebe8);--f-office-card:var(--lightningcss-light,#fff)var(--lightningcss-dark,#232327);--f-office-card-foreground:var(--f-office-foreground);--f-office-popover:var(--lightningcss-light,#fff)var(--lightningcss-dark,#232327);--f-office-popover-foreground:var(--f-office-foreground);--f-office-primary:var(--lightningcss-light,#4137c8)var(--lightningcss-dark,#d697ff);--f-office-primary-foreground:var(--lightningcss-light,#fff)var(--lightningcss-dark,#1f0b3a);--f-office-secondary:var(--lightningcss-light,#eceef5)var(--lightningcss-dark,#2a2a2f);--f-office-secondary-foreground:var(--f-office-foreground);--f-office-muted:var(--lightningcss-light,#eceef5)var(--lightningcss-dark,#2a2a2f);--f-office-muted-foreground:var(--lightningcss-light,#5a5d68)var(--lightningcss-dark,#b3b2ab);--f-office-accent:var(--lightningcss-light,#1d1d1f12)var(--lightningcss-dark,#ecebe817);--f-office-accent-foreground:var(--f-office-foreground);--f-office-border:var(--lightningcss-light,#dcdfe8)var(--lightningcss-dark,#36363c);--f-office-input:var(--lightningcss-light,#dcdfe8)var(--lightningcss-dark,#36363c);--f-office-ring:var(--lightningcss-light,#4137c8)var(--lightningcss-dark,#d697ff);--f-office-drop:var(--lightningcss-light,#f3f1fe)var(--lightningcss-dark,#221c33)}@media (prefers-color-scheme:dark){.f-office-docs-root,.f-office-docs-portal{--lightningcss-light: ;--lightningcss-dark:initial}}:root[data-theme=light] .f-office-docs-root:not([data-f-office-theme]),:root[data-theme=light] .f-office-docs-portal:not([data-f-office-theme]),.f-office-docs-root[data-f-office-theme=light],.f-office-docs-portal[data-f-office-theme=light]{--lightningcss-light:initial;--lightningcss-dark: ;color-scheme:light}:root[data-theme=dark] .f-office-docs-root:not([data-f-office-theme]),:root[data-theme=dark] .f-office-docs-portal:not([data-f-office-theme]),.f-office-docs-root[data-f-office-theme=dark],.f-office-docs-portal[data-f-office-theme=dark]{--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark}.f-office-logo-dark,:root[data-theme=dark] :is(.f-office-docs-root,.f-office-docs-portal):not([data-f-office-theme]) .f-office-logo-light,[data-f-office-theme=dark] .f-office-logo-light{display:none}:root[data-theme=dark] :is(.f-office-docs-root,.f-office-docs-portal):not([data-f-office-theme]) .f-office-logo-dark,[data-f-office-theme=dark] .f-office-logo-dark{display:block}@media (prefers-color-scheme:dark){[data-f-office-theme=system] .f-office-logo-light,:root:not([data-theme=light]):not([data-theme=dark]) :is(.f-office-docs-root,.f-office-docs-portal):not([data-f-office-theme]) .f-office-logo-light{display:none}[data-f-office-theme=system] .f-office-logo-dark,:root:not([data-theme=light]):not([data-theme=dark]) :is(.f-office-docs-root,.f-office-docs-portal):not([data-f-office-theme]) .f-office-logo-dark{display:block}}@media (prefers-reduced-motion:reduce){.f-office-docs-root *,.f-office-docs-root :before,.f-office-docs-root :after,.f-office-docs-portal *,.f-office-docs-portal :before,.f-office-docs-portal :after{transition-duration:.01ms!important;animation-duration:.01ms!important}}@media (width<=639px){f-office-docs::part(outline-open){display:none}}@media print{@page{margin:0}.f-office-docs-root>:not(main),.f-office-docs-root main>:not(.f-office-docs-holder){display:none!important}body:has(.f-office-docs-root)>:not(:has(.f-office-docs-root)):not(.f-office-docs-root){display:none!important}.f-office-docs-root,.f-office-docs-holder{height:auto;display:block}.f-office-docs-root{background:#fff}body:has(.f-office-docs-root){background:#fff}}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes pulse{50%{opacity:.5}}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The themes of F-Office Docs: system, light, or dark. */
|
|
2
|
+
export declare const THEMES: readonly ["system", "light", "dark"];
|
|
3
|
+
export type Theme = (typeof THEMES)[number];
|
|
4
|
+
/** The names of the themes in menus and labels. */
|
|
5
|
+
export declare const THEME_NAMES: Record<Theme, string>;
|
|
6
|
+
/** Default localStorage key shared with f-office.org so theme stays consistent across pages. */
|
|
7
|
+
export declare const DEFAULT_THEME_STORAGE_KEY = "f-office-viewer:theme";
|
|
8
|
+
/** Browser storage subset that may throw in private windows or restricted iframes. */
|
|
9
|
+
export type StorageLike = () => Pick<globalThis.Storage, "getItem" | "setItem">;
|
|
10
|
+
/** Loads the persisted theme from storage, or `"system"` when absent or blocked. */
|
|
11
|
+
export declare function loadTheme(storage?: StorageLike, key?: string): Theme;
|
|
12
|
+
/** Persists `theme` to storage when available. */
|
|
13
|
+
export declare function saveTheme(theme: Theme, storage?: StorageLike, key?: string): void;
|
|
14
|
+
/** Applies `theme` via `data-theme` on `root` (`"system"` clears the attribute). */
|
|
15
|
+
export declare function applyTheme(theme: Theme, root?: HTMLElement): void;
|
|
16
|
+
/** Cycles to the next theme: system -> light -> dark -> system. */
|
|
17
|
+
export declare function nextTheme(theme: Theme): Theme;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
import { ContextMenu as MenuPrimitive } from "radix-ui";
|
|
3
|
+
declare const ContextMenu: import("react").FC<MenuPrimitive.ContextMenuProps>;
|
|
4
|
+
declare const ContextMenuTrigger: import("react").ForwardRefExoticComponent<MenuPrimitive.ContextMenuTriggerProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
5
|
+
declare function ContextMenuContent({ className, ...props }: ComponentProps<typeof MenuPrimitive.Content>): import("react").JSX.Element;
|
|
6
|
+
declare function ContextMenuItem({ className, ...props }: ComponentProps<typeof MenuPrimitive.Item>): import("react").JSX.Element;
|
|
7
|
+
declare function ContextMenuSeparator({ className, ...props }: ComponentProps<typeof MenuPrimitive.Separator>): import("react").JSX.Element;
|
|
8
|
+
export { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
import { Dialog as DialogPrimitive } from "radix-ui";
|
|
3
|
+
declare const Dialog: import("react").FC<DialogPrimitive.DialogProps>;
|
|
4
|
+
declare function DialogContent({ className, children, ...props }: ComponentProps<typeof DialogPrimitive.Content>): import("react").JSX.Element;
|
|
5
|
+
declare function DialogTitle({ className, ...props }: ComponentProps<typeof DialogPrimitive.Title>): import("react").JSX.Element;
|
|
6
|
+
declare function DialogDescription({ className, ...props }: ComponentProps<typeof DialogPrimitive.Description>): import("react").JSX.Element;
|
|
7
|
+
export { Dialog, DialogContent, DialogDescription, DialogTitle };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
/** The key of a menu item, at its right edge, in the menu bar and in a context menu. Screen
|
|
3
|
+
* readers read the item's `aria-keyshortcuts` in its place. */
|
|
4
|
+
declare function MenuShortcut({ className, ...props }: ComponentProps<"span">): import("react").JSX.Element;
|
|
5
|
+
export { MenuShortcut };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
import { Menubar as MenuPrimitive } from "radix-ui";
|
|
3
|
+
declare function MenubarMenu(props: ComponentProps<typeof MenuPrimitive.Menu>): import("react").JSX.Element;
|
|
4
|
+
declare function MenubarSub(props: ComponentProps<typeof MenuPrimitive.Sub>): import("react").JSX.Element;
|
|
5
|
+
declare function MenubarRadioGroup(props: ComponentProps<typeof MenuPrimitive.RadioGroup>): import("react").JSX.Element;
|
|
6
|
+
declare function Menubar({ className, ...props }: ComponentProps<typeof MenuPrimitive.Root>): import("react").JSX.Element;
|
|
7
|
+
declare function MenubarTrigger({ className, ...props }: ComponentProps<typeof MenuPrimitive.Trigger>): import("react").JSX.Element;
|
|
8
|
+
declare function MenubarContent({ className, align, sideOffset, ...props }: ComponentProps<typeof MenuPrimitive.Content>): import("react").JSX.Element;
|
|
9
|
+
declare function MenubarItem({ className, ...props }: ComponentProps<typeof MenuPrimitive.Item>): import("react").JSX.Element;
|
|
10
|
+
declare function MenubarCheckboxItem({ className, children, ...props }: ComponentProps<typeof MenuPrimitive.CheckboxItem>): import("react").JSX.Element;
|
|
11
|
+
declare function MenubarRadioItem({ className, children, ...props }: ComponentProps<typeof MenuPrimitive.RadioItem>): import("react").JSX.Element;
|
|
12
|
+
declare function MenubarSubTrigger({ className, children, ...props }: ComponentProps<typeof MenuPrimitive.SubTrigger>): import("react").JSX.Element;
|
|
13
|
+
declare function MenubarSubContent({ className, ...props }: ComponentProps<typeof MenuPrimitive.SubContent>): import("react").JSX.Element;
|
|
14
|
+
declare function MenubarSeparator({ className, ...props }: ComponentProps<typeof MenuPrimitive.Separator>): import("react").JSX.Element;
|
|
15
|
+
declare function MenubarLabel({ className, ...props }: ComponentProps<typeof MenuPrimitive.Label>): import("react").JSX.Element;
|
|
16
|
+
export { Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarLabel, MenubarMenu, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Theme } from "../theme.js";
|
|
2
|
+
/** Theme forwarded from `DocsProvider` to Radix portals mounted outside `.f-office-docs-root`. */
|
|
3
|
+
export declare const PortalThemeContext: import("react").Context<"system" | "light" | "dark" | undefined>;
|
|
4
|
+
/** Reads the active provider theme for portal elements (`undefined` outside `DocsProvider`). */
|
|
5
|
+
export declare function usePortalTheme(): Theme | undefined;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Query parameter naming a same-origin DOCX file to open (`?file=URL`). */
|
|
2
|
+
export declare const FILE_PARAMETER = "file";
|
|
3
|
+
/** Parsed URL file request: a validated same-origin URL, or a refusal reason. */
|
|
4
|
+
export type AskedFile = {
|
|
5
|
+
readonly kind: "address";
|
|
6
|
+
readonly address: URL;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "refused";
|
|
9
|
+
readonly why: string;
|
|
10
|
+
};
|
|
11
|
+
/** Document fetched from a same-origin URL. */
|
|
12
|
+
export type FetchedFile = {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly bytes: ArrayBuffer;
|
|
15
|
+
};
|
|
16
|
+
/** Parses `?file=URL` against `page`, allowing only same-origin URLs. */
|
|
17
|
+
export declare function askedFile(search: string, page: string): AskedFile | null;
|
|
18
|
+
/** Decoded filename from the last segment of `address`. */
|
|
19
|
+
export declare function fileName(address: URL): string;
|
|
20
|
+
/** Fetches a same-origin document, rejecting cross-origin redirects and non-2xx responses. */
|
|
21
|
+
export declare function fetchAskedFile(address: URL, signal?: AbortSignal, read?: typeof fetch): Promise<FetchedFile>;
|
|
22
|
+
/** Removes the `file` query parameter from the current URL while preserving other params. */
|
|
23
|
+
export declare function dropFileParameter(): void;
|
|
24
|
+
/** Fetches `asked` once (using React 19 `useEffectEvent` so callbacks need not be memoized). */
|
|
25
|
+
export declare function useAskedFile(asked: AskedFile | null, take: (file: FetchedFile) => void, refuse: (why: string) => void): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f-office/docs-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "React 19 components and composable Google Docs-style UI for F-Office Docs (<FOfficeDocs />, <DocsProvider>, <DocsApp />).",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@10.20.0",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"./dist/styles.css"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/osolmaz/f-office.git",
|
|
14
|
+
"directory": "packages/docs-react"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://f-office.org",
|
|
17
|
+
"bugs": "https://github.com/osolmaz/f-office/issues",
|
|
18
|
+
"keywords": [
|
|
19
|
+
"docx",
|
|
20
|
+
"docs",
|
|
21
|
+
"word",
|
|
22
|
+
"react",
|
|
23
|
+
"viewer",
|
|
24
|
+
"editor",
|
|
25
|
+
"pdf",
|
|
26
|
+
"office"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.18"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./styles.css": "./dist/styles.css"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE",
|
|
42
|
+
"NOTICE"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@f-office/docs": "^0.2.3",
|
|
46
|
+
"clsx": "^2.1.1",
|
|
47
|
+
"lucide-react": "^1.61.0",
|
|
48
|
+
"radix-ui": "^1.8.1",
|
|
49
|
+
"tailwind-merge": "^3.7.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": ">=19.0.0",
|
|
53
|
+
"react-dom": ">=19.0.0"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "node scripts/build.mjs",
|
|
57
|
+
"typecheck": "tsc --noEmit",
|
|
58
|
+
"lint": "eslint .",
|
|
59
|
+
"format": "prettier --check .",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"coverage": "vitest run --coverage",
|
|
62
|
+
"check": "pnpm format && pnpm lint && pnpm typecheck && pnpm build && pnpm test && pnpm coverage"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@eslint/js": "10.0.1",
|
|
66
|
+
"@tailwindcss/vite": "4.3.3",
|
|
67
|
+
"@testing-library/dom": "10.4.2",
|
|
68
|
+
"@testing-library/react": "16.3.3",
|
|
69
|
+
"@testing-library/user-event": "14.6.8",
|
|
70
|
+
"@types/node": "22.20.5",
|
|
71
|
+
"@types/react": "19.3.0",
|
|
72
|
+
"@types/react-dom": "19.3.0",
|
|
73
|
+
"@vitejs/plugin-react": "6.1.2",
|
|
74
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
75
|
+
"eslint": "10.13.0",
|
|
76
|
+
"eslint-plugin-react-hooks": "7.1.1",
|
|
77
|
+
"fake-indexeddb": "6.2.8",
|
|
78
|
+
"globals": "17.13.0",
|
|
79
|
+
"happy-dom": "21.0.4",
|
|
80
|
+
"prettier": "3.9.10",
|
|
81
|
+
"react": "19.3.1",
|
|
82
|
+
"react-dom": "19.3.1",
|
|
83
|
+
"tailwindcss": "4.3.3",
|
|
84
|
+
"typescript": "6.0.3",
|
|
85
|
+
"typescript-eslint": "8.72.0",
|
|
86
|
+
"vite": "8.3.5",
|
|
87
|
+
"vitest": "5.0.5"
|
|
88
|
+
}
|
|
89
|
+
}
|