@coze-editor/react-hooks 0.1.0-alpha.0fd19e

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,78 @@
1
+ import { EditorState, Transaction, StateField, Compartment, Text } from '@codemirror/state';
2
+ import { Injector } from '@coze-editor/react';
3
+ import * as react from 'react';
4
+ import { ReactPortal } from 'react';
5
+ import { EditorView } from '@codemirror/view';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
+
8
+ declare function useStateField<T = unknown>(create: (state: EditorState) => T, update?: (value: T, tr: Transaction) => T): StateField<T>;
9
+
10
+ interface IDRangeSpec {
11
+ from: number;
12
+ to: number;
13
+ id: string;
14
+ }
15
+ type Watcher = (specs: IDRangeSpec[]) => void;
16
+ declare function useRangesManager(): {
17
+ add(specs: IDRangeSpec[]): void;
18
+ remove(ids: string[]): void;
19
+ watch(watcher: Watcher): () => void;
20
+ };
21
+
22
+ declare function useFocused(): boolean;
23
+
24
+ type InjectorHandler = (injector: Injector) => ReturnType<typeof injector.inject> | undefined;
25
+ declare function useInjectorEffect(handler: InjectorHandler, deps?: any[]): void;
26
+
27
+ declare function useHTMLElement(defaultTagName?: string): HTMLElement;
28
+
29
+ declare function useCompartment(): Compartment;
30
+
31
+ declare function useLatest<T>(value: T): react.MutableRefObject<T>;
32
+
33
+ type ChangeListener = (event: {
34
+ change: [number, number, number, number, Text];
35
+ view: EditorView;
36
+ }) => void;
37
+ declare function useChangeListener(listener: ChangeListener): void;
38
+
39
+ type DocumentSelector<T> = (doc: Text) => T;
40
+ declare function useDocumentSelector<T>(selector: DocumentSelector<T>, defaultValue: T): T;
41
+
42
+ type DocumentListener = (doc: Text) => void;
43
+ declare function useDocumentListener(listener: DocumentListener): void;
44
+
45
+ declare function createPortalConnector(options?: {
46
+ sync?: boolean;
47
+ }): {
48
+ connect: (id: string, portal: ReactPortal) => void;
49
+ disconnect: (id: string) => void;
50
+ Portal: () => react_jsx_runtime.JSX.Element;
51
+ };
52
+ declare function usePortalConnector(options?: {
53
+ sync?: boolean;
54
+ }): {
55
+ connect: (id: string, portal: ReactPortal) => void;
56
+ disconnect: (id: string) => void;
57
+ Portal: () => react_jsx_runtime.JSX.Element;
58
+ };
59
+
60
+ interface EditorAPILike {
61
+ __private_eventmap: Record<string, any>;
62
+ }
63
+ declare function useEditorEvent<T extends EditorAPILike, K extends keyof T['__private_eventmap']>(editor: T, eventName: K, handler: T['__private_eventmap'][K]): void;
64
+
65
+ declare function useHistoryState(): {
66
+ canUndo: boolean;
67
+ canRedo: boolean;
68
+ };
69
+
70
+ declare function useMouseSelectionPopup(): {
71
+ anchor: number;
72
+ head: number;
73
+ from: number;
74
+ to: number;
75
+ visible: boolean;
76
+ };
77
+
78
+ export { createPortalConnector, useChangeListener, useCompartment, useDocumentListener, useDocumentSelector, useEditorEvent, useFocused, useHTMLElement, useHistoryState, useInjectorEffect, useLatest, useMouseSelectionPopup, usePortalConnector, useRangesManager, useStateField };
@@ -0,0 +1,78 @@
1
+ import { EditorState, Transaction, StateField, Compartment, Text } from '@codemirror/state';
2
+ import { Injector } from '@coze-editor/react';
3
+ import * as react from 'react';
4
+ import { ReactPortal } from 'react';
5
+ import { EditorView } from '@codemirror/view';
6
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
+
8
+ declare function useStateField<T = unknown>(create: (state: EditorState) => T, update?: (value: T, tr: Transaction) => T): StateField<T>;
9
+
10
+ interface IDRangeSpec {
11
+ from: number;
12
+ to: number;
13
+ id: string;
14
+ }
15
+ type Watcher = (specs: IDRangeSpec[]) => void;
16
+ declare function useRangesManager(): {
17
+ add(specs: IDRangeSpec[]): void;
18
+ remove(ids: string[]): void;
19
+ watch(watcher: Watcher): () => void;
20
+ };
21
+
22
+ declare function useFocused(): boolean;
23
+
24
+ type InjectorHandler = (injector: Injector) => ReturnType<typeof injector.inject> | undefined;
25
+ declare function useInjectorEffect(handler: InjectorHandler, deps?: any[]): void;
26
+
27
+ declare function useHTMLElement(defaultTagName?: string): HTMLElement;
28
+
29
+ declare function useCompartment(): Compartment;
30
+
31
+ declare function useLatest<T>(value: T): react.MutableRefObject<T>;
32
+
33
+ type ChangeListener = (event: {
34
+ change: [number, number, number, number, Text];
35
+ view: EditorView;
36
+ }) => void;
37
+ declare function useChangeListener(listener: ChangeListener): void;
38
+
39
+ type DocumentSelector<T> = (doc: Text) => T;
40
+ declare function useDocumentSelector<T>(selector: DocumentSelector<T>, defaultValue: T): T;
41
+
42
+ type DocumentListener = (doc: Text) => void;
43
+ declare function useDocumentListener(listener: DocumentListener): void;
44
+
45
+ declare function createPortalConnector(options?: {
46
+ sync?: boolean;
47
+ }): {
48
+ connect: (id: string, portal: ReactPortal) => void;
49
+ disconnect: (id: string) => void;
50
+ Portal: () => react_jsx_runtime.JSX.Element;
51
+ };
52
+ declare function usePortalConnector(options?: {
53
+ sync?: boolean;
54
+ }): {
55
+ connect: (id: string, portal: ReactPortal) => void;
56
+ disconnect: (id: string) => void;
57
+ Portal: () => react_jsx_runtime.JSX.Element;
58
+ };
59
+
60
+ interface EditorAPILike {
61
+ __private_eventmap: Record<string, any>;
62
+ }
63
+ declare function useEditorEvent<T extends EditorAPILike, K extends keyof T['__private_eventmap']>(editor: T, eventName: K, handler: T['__private_eventmap'][K]): void;
64
+
65
+ declare function useHistoryState(): {
66
+ canUndo: boolean;
67
+ canRedo: boolean;
68
+ };
69
+
70
+ declare function useMouseSelectionPopup(): {
71
+ anchor: number;
72
+ head: number;
73
+ from: number;
74
+ to: number;
75
+ visible: boolean;
76
+ };
77
+
78
+ export { createPortalConnector, useChangeListener, useCompartment, useDocumentListener, useDocumentSelector, useEditorEvent, useFocused, useHTMLElement, useHistoryState, useInjectorEffect, useLatest, useMouseSelectionPopup, usePortalConnector, useRangesManager, useStateField };