@mhamz.01/easyflow-texteditor 0.1.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.
@@ -0,0 +1,251 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Editor as Editor$1 } from '@tiptap/react';
3
+ import * as react from 'react';
4
+ import react__default, { RefObject } from 'react';
5
+ import { Editor as Editor$2 } from '@tiptap/core';
6
+
7
+ interface EditorSubTab {
8
+ id: string;
9
+ title: string;
10
+ content: any | null;
11
+ }
12
+ interface EditorTab {
13
+ id: string;
14
+ title: string;
15
+ content: any | null;
16
+ subtabs: EditorSubTab[];
17
+ }
18
+
19
+ type EditorChangeSource = "editor" | "tab-switch" | "subtab-switch" | "add-tab" | "add-subtab" | "delete-tab" | "delete-subtab" | "restore" | "storage" | "manual";
20
+ interface EditorChangePayload {
21
+ tabs: EditorTab[];
22
+ activeTabId: string;
23
+ activeSubTabId: string | null;
24
+ source: EditorChangeSource;
25
+ }
26
+
27
+ interface EditorProps {
28
+ onChange?: (payload: EditorChangePayload) => void;
29
+ className?: string;
30
+ style?: React.CSSProperties;
31
+ }
32
+ declare function Editor({ onChange, className, style }: EditorProps): react_jsx_runtime.JSX.Element;
33
+
34
+ type UserRef<T> = ((instance: T | null) => void) | React.RefObject<T | null> | null | undefined;
35
+ declare const useComposedRef: <T extends HTMLElement>(libRef: React.RefObject<T | null>, userRef: UserRef<T>) => (instance: T | null) => void;
36
+
37
+ type RectState = Omit<DOMRect, "toJSON">;
38
+ interface ElementRectOptions {
39
+ /**
40
+ * The element to track. Can be an Element, ref, or selector string.
41
+ * Defaults to document.body if not provided.
42
+ */
43
+ element?: Element | React.RefObject<Element> | string | null;
44
+ /**
45
+ * Whether to enable rect tracking
46
+ */
47
+ enabled?: boolean;
48
+ /**
49
+ * Throttle delay in milliseconds for rect updates
50
+ */
51
+ throttleMs?: number;
52
+ /**
53
+ * Whether to use ResizeObserver for more accurate tracking
54
+ */
55
+ useResizeObserver?: boolean;
56
+ }
57
+ /**
58
+ * Custom hook that tracks an element's bounding rectangle and updates on resize, scroll, etc.
59
+ *
60
+ * @param options Configuration options for element rect tracking
61
+ * @returns The current bounding rectangle of the element
62
+ */
63
+ declare function useElementRect({ element, enabled, throttleMs, useResizeObserver, }?: ElementRectOptions): RectState;
64
+ /**
65
+ * Convenience hook for tracking document.body rect
66
+ */
67
+ declare function useBodyRect(options?: Omit<ElementRectOptions, "element">): RectState;
68
+ /**
69
+ * Convenience hook for tracking a ref element's rect
70
+ */
71
+ declare function useRefRect<T extends Element>(ref: React.RefObject<T>, options?: Omit<ElementRectOptions, "element">): RectState;
72
+
73
+ interface CursorVisibilityOptions {
74
+ /**
75
+ * The Tiptap editor instance
76
+ */
77
+ editor?: Editor$1 | null;
78
+ /**
79
+ * Reference to the toolbar element that may obscure the cursor
80
+ */
81
+ overlayHeight?: number;
82
+ }
83
+ /**
84
+ * Custom hook that ensures the cursor remains visible when typing in a Tiptap editor.
85
+ * Automatically scrolls the window when the cursor would be hidden by the toolbar.
86
+ *
87
+ * @param options.editor The Tiptap editor instance
88
+ * @param options.overlayHeight Toolbar height to account for
89
+ * @returns The bounding rect of the body
90
+ */
91
+ declare function useCursorVisibility({ editor, overlayHeight, }: CursorVisibilityOptions): RectState;
92
+
93
+ type BreakpointMode = "min" | "max";
94
+ /**
95
+ * Hook to detect whether the current viewport matches a given breakpoint rule.
96
+ * Example:
97
+ * useIsBreakpoint("max", 768) // true when width < 768
98
+ * useIsBreakpoint("min", 1024) // true when width >= 1024
99
+ */
100
+ declare function useIsBreakpoint(mode?: BreakpointMode, breakpoint?: number): boolean;
101
+
102
+ type Orientation = "horizontal" | "vertical" | "both";
103
+ interface MenuNavigationOptions<T> {
104
+ /**
105
+ * The Tiptap editor instance, if using with a Tiptap editor.
106
+ */
107
+ editor?: Editor$1 | null;
108
+ /**
109
+ * Reference to the container element for handling keyboard events.
110
+ */
111
+ containerRef?: React.RefObject<HTMLElement | null>;
112
+ /**
113
+ * Search query that affects the selected item.
114
+ */
115
+ query?: string;
116
+ /**
117
+ * Array of items to navigate through.
118
+ */
119
+ items: T[];
120
+ /**
121
+ * Callback fired when an item is selected.
122
+ */
123
+ onSelect?: (item: T) => void;
124
+ /**
125
+ * Callback fired when the menu should close.
126
+ */
127
+ onClose?: () => void;
128
+ /**
129
+ * The navigation orientation of the menu.
130
+ * @default "vertical"
131
+ */
132
+ orientation?: Orientation;
133
+ /**
134
+ * Whether to automatically select the first item when the menu opens.
135
+ * @default true
136
+ */
137
+ autoSelectFirstItem?: boolean;
138
+ }
139
+ /**
140
+ * Hook that implements keyboard navigation for dropdown menus and command palettes.
141
+ *
142
+ * Handles arrow keys, tab, home/end, enter for selection, and escape to close.
143
+ * Works with both Tiptap editors and regular DOM elements.
144
+ *
145
+ * @param options - Configuration options for the menu navigation
146
+ * @returns Object containing the selected index and a setter function
147
+ */
148
+ declare function useMenuNavigation<T>({ editor, containerRef, query, items, onSelect, onClose, orientation, autoSelectFirstItem, }: MenuNavigationOptions<T>): {
149
+ selectedIndex: number | undefined;
150
+ setSelectedIndex: react.Dispatch<react.SetStateAction<number>>;
151
+ };
152
+
153
+ declare function useIsMobile(): boolean;
154
+
155
+ type ScrollTarget = RefObject<HTMLElement> | Window | null | undefined;
156
+ interface UseScrollingOptions {
157
+ debounce?: number;
158
+ fallbackToDocument?: boolean;
159
+ }
160
+ declare function useScrolling(target?: ScrollTarget, options?: UseScrollingOptions): boolean;
161
+
162
+ interface ThrottleSettings {
163
+ leading?: boolean | undefined;
164
+ trailing?: boolean | undefined;
165
+ }
166
+ /**
167
+ * A hook that returns a throttled callback function.
168
+ *
169
+ * @param fn The function to throttle
170
+ * @param wait The time in ms to wait before calling the function
171
+ * @param dependencies The dependencies to watch for changes
172
+ * @param options The throttle options
173
+ */
174
+ declare function useThrottledCallback<T extends (...args: any[]) => any>(fn: T, wait?: number, dependencies?: React.DependencyList, options?: ThrottleSettings): {
175
+ (this: ThisParameterType<T>, ...args: Parameters<T>): ReturnType<T>;
176
+ cancel: () => void;
177
+ flush: () => void;
178
+ };
179
+
180
+ /**
181
+ * Hook that provides access to a Tiptap editor instance.
182
+ *
183
+ * Accepts an optional editor instance directly, or falls back to retrieving
184
+ * the editor from the Tiptap context if available. This allows components
185
+ * to work both when given an editor directly and when used within a Tiptap
186
+ * editor context.
187
+ *
188
+ * @param providedEditor - Optional editor instance to use instead of the context editor
189
+ * @returns The provided editor or the editor from context, whichever is available
190
+ */
191
+ declare function useTiptapEditor(providedEditor?: Editor$1 | null): {
192
+ editor: Editor$1 | null;
193
+ editorState?: Editor$1["state"];
194
+ canCommand?: Editor$1["can"];
195
+ };
196
+
197
+ /**
198
+ * Hook that executes a callback when the component unmounts.
199
+ *
200
+ * @param callback Function to be called on component unmount
201
+ */
202
+ declare const useUnmount: (callback: (...args: Array<any>) => any) => void;
203
+
204
+ interface WindowSizeState {
205
+ /**
206
+ * The width of the window's visual viewport in pixels.
207
+ */
208
+ width: number;
209
+ /**
210
+ * The height of the window's visual viewport in pixels.
211
+ */
212
+ height: number;
213
+ /**
214
+ * The distance from the top of the visual viewport to the top of the layout viewport.
215
+ * Particularly useful for handling mobile keyboard appearance.
216
+ */
217
+ offsetTop: number;
218
+ /**
219
+ * The distance from the left of the visual viewport to the left of the layout viewport.
220
+ */
221
+ offsetLeft: number;
222
+ /**
223
+ * The scale factor of the visual viewport.
224
+ * This is useful for scaling elements based on the current zoom level.
225
+ */
226
+ scale: number;
227
+ }
228
+ /**
229
+ * Hook that tracks the window's visual viewport dimensions, position, and provides
230
+ * a CSS transform for positioning elements.
231
+ *
232
+ * Uses the Visual Viewport API to get accurate measurements, especially important
233
+ * for mobile devices where virtual keyboards can change the visible area.
234
+ * Only updates state when values actually change to optimize performance.
235
+ *
236
+ * @returns An object containing viewport properties and a CSS transform string
237
+ */
238
+ declare function useWindowSize(): WindowSizeState;
239
+
240
+ type EditorBridgeValue = {
241
+ editorContent: Editor$2 | null;
242
+ setEditorContent: (editor: Editor$2 | null) => void;
243
+ debouncedSave: (editor: Editor$2) => void;
244
+ };
245
+ declare function EditorBridgeProvider({ children, value, }: {
246
+ children: react__default.ReactNode;
247
+ value: EditorBridgeValue;
248
+ }): react_jsx_runtime.JSX.Element;
249
+ declare function useEditorBridge(): EditorBridgeValue;
250
+
251
+ export { type CursorVisibilityOptions, Editor, EditorBridgeProvider, type EditorBridgeValue, type EditorChangePayload, type EditorChangeSource, type ElementRectOptions, type RectState, type WindowSizeState, useBodyRect, useComposedRef, useCursorVisibility, useEditorBridge, useElementRect, useIsBreakpoint, useIsMobile, useMenuNavigation, useRefRect, useScrolling, useThrottledCallback, useTiptapEditor, useUnmount, useWindowSize };
@@ -0,0 +1,251 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Editor as Editor$1 } from '@tiptap/react';
3
+ import * as react from 'react';
4
+ import react__default, { RefObject } from 'react';
5
+ import { Editor as Editor$2 } from '@tiptap/core';
6
+
7
+ interface EditorSubTab {
8
+ id: string;
9
+ title: string;
10
+ content: any | null;
11
+ }
12
+ interface EditorTab {
13
+ id: string;
14
+ title: string;
15
+ content: any | null;
16
+ subtabs: EditorSubTab[];
17
+ }
18
+
19
+ type EditorChangeSource = "editor" | "tab-switch" | "subtab-switch" | "add-tab" | "add-subtab" | "delete-tab" | "delete-subtab" | "restore" | "storage" | "manual";
20
+ interface EditorChangePayload {
21
+ tabs: EditorTab[];
22
+ activeTabId: string;
23
+ activeSubTabId: string | null;
24
+ source: EditorChangeSource;
25
+ }
26
+
27
+ interface EditorProps {
28
+ onChange?: (payload: EditorChangePayload) => void;
29
+ className?: string;
30
+ style?: React.CSSProperties;
31
+ }
32
+ declare function Editor({ onChange, className, style }: EditorProps): react_jsx_runtime.JSX.Element;
33
+
34
+ type UserRef<T> = ((instance: T | null) => void) | React.RefObject<T | null> | null | undefined;
35
+ declare const useComposedRef: <T extends HTMLElement>(libRef: React.RefObject<T | null>, userRef: UserRef<T>) => (instance: T | null) => void;
36
+
37
+ type RectState = Omit<DOMRect, "toJSON">;
38
+ interface ElementRectOptions {
39
+ /**
40
+ * The element to track. Can be an Element, ref, or selector string.
41
+ * Defaults to document.body if not provided.
42
+ */
43
+ element?: Element | React.RefObject<Element> | string | null;
44
+ /**
45
+ * Whether to enable rect tracking
46
+ */
47
+ enabled?: boolean;
48
+ /**
49
+ * Throttle delay in milliseconds for rect updates
50
+ */
51
+ throttleMs?: number;
52
+ /**
53
+ * Whether to use ResizeObserver for more accurate tracking
54
+ */
55
+ useResizeObserver?: boolean;
56
+ }
57
+ /**
58
+ * Custom hook that tracks an element's bounding rectangle and updates on resize, scroll, etc.
59
+ *
60
+ * @param options Configuration options for element rect tracking
61
+ * @returns The current bounding rectangle of the element
62
+ */
63
+ declare function useElementRect({ element, enabled, throttleMs, useResizeObserver, }?: ElementRectOptions): RectState;
64
+ /**
65
+ * Convenience hook for tracking document.body rect
66
+ */
67
+ declare function useBodyRect(options?: Omit<ElementRectOptions, "element">): RectState;
68
+ /**
69
+ * Convenience hook for tracking a ref element's rect
70
+ */
71
+ declare function useRefRect<T extends Element>(ref: React.RefObject<T>, options?: Omit<ElementRectOptions, "element">): RectState;
72
+
73
+ interface CursorVisibilityOptions {
74
+ /**
75
+ * The Tiptap editor instance
76
+ */
77
+ editor?: Editor$1 | null;
78
+ /**
79
+ * Reference to the toolbar element that may obscure the cursor
80
+ */
81
+ overlayHeight?: number;
82
+ }
83
+ /**
84
+ * Custom hook that ensures the cursor remains visible when typing in a Tiptap editor.
85
+ * Automatically scrolls the window when the cursor would be hidden by the toolbar.
86
+ *
87
+ * @param options.editor The Tiptap editor instance
88
+ * @param options.overlayHeight Toolbar height to account for
89
+ * @returns The bounding rect of the body
90
+ */
91
+ declare function useCursorVisibility({ editor, overlayHeight, }: CursorVisibilityOptions): RectState;
92
+
93
+ type BreakpointMode = "min" | "max";
94
+ /**
95
+ * Hook to detect whether the current viewport matches a given breakpoint rule.
96
+ * Example:
97
+ * useIsBreakpoint("max", 768) // true when width < 768
98
+ * useIsBreakpoint("min", 1024) // true when width >= 1024
99
+ */
100
+ declare function useIsBreakpoint(mode?: BreakpointMode, breakpoint?: number): boolean;
101
+
102
+ type Orientation = "horizontal" | "vertical" | "both";
103
+ interface MenuNavigationOptions<T> {
104
+ /**
105
+ * The Tiptap editor instance, if using with a Tiptap editor.
106
+ */
107
+ editor?: Editor$1 | null;
108
+ /**
109
+ * Reference to the container element for handling keyboard events.
110
+ */
111
+ containerRef?: React.RefObject<HTMLElement | null>;
112
+ /**
113
+ * Search query that affects the selected item.
114
+ */
115
+ query?: string;
116
+ /**
117
+ * Array of items to navigate through.
118
+ */
119
+ items: T[];
120
+ /**
121
+ * Callback fired when an item is selected.
122
+ */
123
+ onSelect?: (item: T) => void;
124
+ /**
125
+ * Callback fired when the menu should close.
126
+ */
127
+ onClose?: () => void;
128
+ /**
129
+ * The navigation orientation of the menu.
130
+ * @default "vertical"
131
+ */
132
+ orientation?: Orientation;
133
+ /**
134
+ * Whether to automatically select the first item when the menu opens.
135
+ * @default true
136
+ */
137
+ autoSelectFirstItem?: boolean;
138
+ }
139
+ /**
140
+ * Hook that implements keyboard navigation for dropdown menus and command palettes.
141
+ *
142
+ * Handles arrow keys, tab, home/end, enter for selection, and escape to close.
143
+ * Works with both Tiptap editors and regular DOM elements.
144
+ *
145
+ * @param options - Configuration options for the menu navigation
146
+ * @returns Object containing the selected index and a setter function
147
+ */
148
+ declare function useMenuNavigation<T>({ editor, containerRef, query, items, onSelect, onClose, orientation, autoSelectFirstItem, }: MenuNavigationOptions<T>): {
149
+ selectedIndex: number | undefined;
150
+ setSelectedIndex: react.Dispatch<react.SetStateAction<number>>;
151
+ };
152
+
153
+ declare function useIsMobile(): boolean;
154
+
155
+ type ScrollTarget = RefObject<HTMLElement> | Window | null | undefined;
156
+ interface UseScrollingOptions {
157
+ debounce?: number;
158
+ fallbackToDocument?: boolean;
159
+ }
160
+ declare function useScrolling(target?: ScrollTarget, options?: UseScrollingOptions): boolean;
161
+
162
+ interface ThrottleSettings {
163
+ leading?: boolean | undefined;
164
+ trailing?: boolean | undefined;
165
+ }
166
+ /**
167
+ * A hook that returns a throttled callback function.
168
+ *
169
+ * @param fn The function to throttle
170
+ * @param wait The time in ms to wait before calling the function
171
+ * @param dependencies The dependencies to watch for changes
172
+ * @param options The throttle options
173
+ */
174
+ declare function useThrottledCallback<T extends (...args: any[]) => any>(fn: T, wait?: number, dependencies?: React.DependencyList, options?: ThrottleSettings): {
175
+ (this: ThisParameterType<T>, ...args: Parameters<T>): ReturnType<T>;
176
+ cancel: () => void;
177
+ flush: () => void;
178
+ };
179
+
180
+ /**
181
+ * Hook that provides access to a Tiptap editor instance.
182
+ *
183
+ * Accepts an optional editor instance directly, or falls back to retrieving
184
+ * the editor from the Tiptap context if available. This allows components
185
+ * to work both when given an editor directly and when used within a Tiptap
186
+ * editor context.
187
+ *
188
+ * @param providedEditor - Optional editor instance to use instead of the context editor
189
+ * @returns The provided editor or the editor from context, whichever is available
190
+ */
191
+ declare function useTiptapEditor(providedEditor?: Editor$1 | null): {
192
+ editor: Editor$1 | null;
193
+ editorState?: Editor$1["state"];
194
+ canCommand?: Editor$1["can"];
195
+ };
196
+
197
+ /**
198
+ * Hook that executes a callback when the component unmounts.
199
+ *
200
+ * @param callback Function to be called on component unmount
201
+ */
202
+ declare const useUnmount: (callback: (...args: Array<any>) => any) => void;
203
+
204
+ interface WindowSizeState {
205
+ /**
206
+ * The width of the window's visual viewport in pixels.
207
+ */
208
+ width: number;
209
+ /**
210
+ * The height of the window's visual viewport in pixels.
211
+ */
212
+ height: number;
213
+ /**
214
+ * The distance from the top of the visual viewport to the top of the layout viewport.
215
+ * Particularly useful for handling mobile keyboard appearance.
216
+ */
217
+ offsetTop: number;
218
+ /**
219
+ * The distance from the left of the visual viewport to the left of the layout viewport.
220
+ */
221
+ offsetLeft: number;
222
+ /**
223
+ * The scale factor of the visual viewport.
224
+ * This is useful for scaling elements based on the current zoom level.
225
+ */
226
+ scale: number;
227
+ }
228
+ /**
229
+ * Hook that tracks the window's visual viewport dimensions, position, and provides
230
+ * a CSS transform for positioning elements.
231
+ *
232
+ * Uses the Visual Viewport API to get accurate measurements, especially important
233
+ * for mobile devices where virtual keyboards can change the visible area.
234
+ * Only updates state when values actually change to optimize performance.
235
+ *
236
+ * @returns An object containing viewport properties and a CSS transform string
237
+ */
238
+ declare function useWindowSize(): WindowSizeState;
239
+
240
+ type EditorBridgeValue = {
241
+ editorContent: Editor$2 | null;
242
+ setEditorContent: (editor: Editor$2 | null) => void;
243
+ debouncedSave: (editor: Editor$2) => void;
244
+ };
245
+ declare function EditorBridgeProvider({ children, value, }: {
246
+ children: react__default.ReactNode;
247
+ value: EditorBridgeValue;
248
+ }): react_jsx_runtime.JSX.Element;
249
+ declare function useEditorBridge(): EditorBridgeValue;
250
+
251
+ export { type CursorVisibilityOptions, Editor, EditorBridgeProvider, type EditorBridgeValue, type EditorChangePayload, type EditorChangeSource, type ElementRectOptions, type RectState, type WindowSizeState, useBodyRect, useComposedRef, useCursorVisibility, useEditorBridge, useElementRect, useIsBreakpoint, useIsMobile, useMenuNavigation, useRefRect, useScrolling, useThrottledCallback, useTiptapEditor, useUnmount, useWindowSize };