@hero-design/rn 8.108.3-alpha.0 → 8.109.1

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,69 @@
1
+ import type { ReactElement, Ref } from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+ import type { TextUnit } from './types';
4
+ export interface RichTextEditorRef {
5
+ requestBlur: VoidFunction;
6
+ insertNodes: (nodes: Record<string, unknown>[]) => void;
7
+ deleteBackward: (unit?: TextUnit) => void;
8
+ setReadOnly: (readOnly: boolean) => void;
9
+ }
10
+ export type EditorValue = {
11
+ type: string;
12
+ children: any;
13
+ }[];
14
+ export interface BaseRichTextEditorProps {
15
+ /**
16
+ * If true, the editor will be focused when the user enters the screen
17
+ */
18
+ autoFocus?: boolean;
19
+ /**
20
+ * Error message
21
+ */
22
+ error?: string;
23
+ /**
24
+ * Field value
25
+ */
26
+ value?: EditorValue;
27
+ /**
28
+ * Unique name used to communicate with webview
29
+ */
30
+ name: string;
31
+ /**
32
+ * Callback function called when the field value changed
33
+ */
34
+ onChange: (data: EditorValue) => void;
35
+ /**
36
+ * Callback function called when the cursor position changed
37
+ */
38
+ onCursorChange?: (params: {
39
+ position: {
40
+ top: number;
41
+ };
42
+ }) => void;
43
+ /**
44
+ * Field placeholder
45
+ */
46
+ placeholder?: string;
47
+ /**
48
+ * Additional styles
49
+ */
50
+ style?: StyleProp<ViewStyle>;
51
+ /**
52
+ * Testing ID of the component
53
+ */
54
+ testID?: string;
55
+ /**
56
+ * Imperative ref to expose the component method
57
+ */
58
+ editorRef?: Ref<RichTextEditorRef>;
59
+ /**
60
+ * Callback function called when the editor is focused
61
+ */
62
+ onFocus?: () => void;
63
+ /**
64
+ * Callback function called when the editor is blurred
65
+ */
66
+ onBlur?: () => void;
67
+ }
68
+ declare const BaseRichTextEditor: ({ autoFocus, name, placeholder, onChange, onCursorChange, style, testID, editorRef, value, onFocus, onBlur, }: BaseRichTextEditorProps) => ReactElement;
69
+ export default BaseRichTextEditor;
@@ -1,54 +1,11 @@
1
1
  import React from 'react';
2
2
  import type { Ref } from 'react';
3
- import type { StyleProp, ViewStyle } from 'react-native';
4
- import type { TextUnit } from './types';
5
- export interface RichTextEditorRef {
6
- requestBlur: VoidFunction;
7
- insertNodes: (nodes: Record<string, unknown>[]) => void;
8
- deleteBackward: (unit?: TextUnit) => void;
9
- setReadOnly: (readOnly: boolean) => void;
10
- }
3
+ import type { BaseRichTextEditorProps, RichTextEditorRef } from './BaseRichTextEditor';
11
4
  export type EditorValue = {
12
5
  type: string;
13
6
  children: any;
14
7
  }[];
15
- export interface RichTextEditorProps {
16
- /**
17
- * If true, the editor will be focused when the user enters the screen
18
- */
19
- autoFocus?: boolean;
20
- /**
21
- * Error message
22
- */
23
- error?: string;
24
- /**
25
- * Field value
26
- */
27
- value?: EditorValue;
28
- /**
29
- * Unique name used to communicate with webview
30
- */
31
- name: string;
32
- /**
33
- * Callback function called when the field value changed
34
- */
35
- onChange: (data: EditorValue) => void;
36
- /**
37
- * Callback function called when the cursor position changed
38
- */
39
- onCursorChange?: (params: {
40
- position: {
41
- top: number;
42
- };
43
- }) => void;
44
- /**
45
- * Field placeholder
46
- */
47
- placeholder?: string;
48
- /**
49
- * Additional styles
50
- */
51
- style?: StyleProp<ViewStyle>;
8
+ export interface RichTextEditorProps extends Omit<BaseRichTextEditorProps, 'editorRef'> {
52
9
  /**
53
10
  * Field label
54
11
  */
@@ -7,3 +7,7 @@ export declare enum ToolbarEvents {
7
7
  HeadingOne = "heading-one",
8
8
  HeadingTwo = "heading-two"
9
9
  }
10
+ export declare enum EditorEvents {
11
+ EditorFocus = "editor-focus",
12
+ EditorBlur = "editor-blur"
13
+ }
@@ -0,0 +1,21 @@
1
+ import type { EditorEvents, ToolbarEvents } from '../constants';
2
+ type SubscribableEvent = ToolbarEvents | EditorEvents;
3
+ /**
4
+ * Hook to subscribe to events for a rich text editor
5
+ * @param editorName - The name of the editor to subscribe to events for
6
+ * @returns An object with two functions: emitEvent and subscribeToEvents
7
+ * @example
8
+ * const { emitEvent, subscribeToEvents } = useRichTextEditorEvents('editorName');
9
+ * subscribeToEvents(EditorEvents.EditorFocus, () => {
10
+ * console.log('Editor focused');
11
+ * });
12
+ * emitEvent({ type: EditorEvents.EditorFocus, data: null });
13
+ */
14
+ declare const useRichTextEditorEvents: (editorName: string) => {
15
+ emitEvent: <TEventName extends ToolbarEvents>({ type, data, }: {
16
+ type: TEventName;
17
+ data: unknown;
18
+ }) => void;
19
+ subscribeToEvents: <TEventName extends SubscribableEvent>(eventName: TEventName, onEvent: (data: unknown) => void) => () => void;
20
+ };
21
+ export default useRichTextEditorEvents;
@@ -1,7 +1,19 @@
1
- import type { RichTextEditorProps, RichTextEditorRef } from './RichTextEditor';
1
+ import { EditorEvents, ToolbarEvents } from './constants';
2
+ import type { RichTextEditorProps } from './RichTextEditor';
3
+ import type { RichTextEditorRef } from './BaseRichTextEditor';
2
4
  export type { RichTextEditorProps, RichTextEditorRef };
3
5
  declare const _default: import("react").ForwardRefExoticComponent<Omit<RichTextEditorProps, "forwardedRef"> & import("react").RefAttributes<RichTextEditorRef>> & {
4
- MentionList: <TMetaData>({ name: eventPrefix, render, }: import("./MentionList").MentionListProps<TMetaData>) => import("react").JSX.Element | null;
5
6
  Toolbar: ({ name, buttons, testID, }: import("./EditorToolbar").EditorToolbarProps) => import("react").JSX.Element | null;
7
+ MentionList: <TMetaData>({ name: eventPrefix, render, }: import("./MentionList").MentionListProps<TMetaData>) => import("react").JSX.Element | null;
8
+ EditorEvents: typeof EditorEvents;
9
+ ToolbarEvents: typeof ToolbarEvents;
10
+ useRichTextEditorEvents: (editorName: string) => {
11
+ emitEvent: <TEventName extends ToolbarEvents>({ type, data, }: {
12
+ type: TEventName;
13
+ data: unknown;
14
+ }) => void;
15
+ subscribeToEvents: <TEventName extends ToolbarEvents | EditorEvents>(eventName: TEventName, onEvent: (data: unknown) => void) => () => void;
16
+ };
17
+ Base: ({ autoFocus, name, placeholder, onChange, onCursorChange, style, testID, editorRef, value, onFocus, onBlur, }: import("./BaseRichTextEditor").BaseRichTextEditorProps) => import("react").ReactElement;
6
18
  };
7
19
  export default _default;