@reiwuzen/blocky-react 1.0.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,106 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _reiwuzen_blocky from '@reiwuzen/blocky';
3
+ import { AnyBlock, Node, NodeSelection } from '@reiwuzen/blocky';
4
+ import React, { KeyboardEvent } from 'react';
5
+
6
+ type EditorStore = {
7
+ blocks: AnyBlock[];
8
+ activeBlockId: string | null;
9
+ setBlocks: (blocks: AnyBlock[]) => void;
10
+ updateBlock: (block: AnyBlock) => void;
11
+ insertAfter: (afterId: string, type?: AnyBlock["type"]) => string | null;
12
+ removeBlock: (id: string) => string;
13
+ duplicate: (id: string) => void;
14
+ move: (id: string, direction: "up" | "down") => void;
15
+ setActiveBlockId: (id: string | null) => void;
16
+ };
17
+
18
+ type EditorProps = {
19
+ /** Seed blocks — hydrated once on mount */
20
+ blocks?: AnyBlock[];
21
+ /**
22
+ * Called with serialized blocks when editable flips true → false.
23
+ * This is your "save" hook.
24
+ */
25
+ onChange?: (blocks: AnyBlock[]) => void;
26
+ editable?: boolean;
27
+ className?: string;
28
+ placeholder?: string;
29
+ };
30
+ declare function Editor({ blocks: seedBlocks, onChange, editable, className, placeholder, }: EditorProps): react_jsx_runtime.JSX.Element;
31
+
32
+ type Props$5 = {
33
+ editable: boolean;
34
+ blockRefs: React.RefObject<Map<string, HTMLSpanElement>>;
35
+ hydratedBlocks: React.RefObject<Set<string>>;
36
+ };
37
+ declare function BlockList({ editable, blockRefs, hydratedBlocks }: Props$5): react_jsx_runtime.JSX.Element;
38
+
39
+ type Props$4 = {
40
+ block: AnyBlock;
41
+ isActive: boolean;
42
+ editable: boolean;
43
+ onFocus: (id: string) => void;
44
+ onDragStart: (id: string) => void;
45
+ onDrop: (dragId: string, dropId: string) => void;
46
+ blockRefs: React.MutableRefObject<Map<string, HTMLSpanElement>>;
47
+ hydratedBlocks: React.MutableRefObject<Set<string>>;
48
+ };
49
+ declare function Block({ block, isActive, editable, onFocus, onDragStart, onDrop, blockRefs, hydratedBlocks, }: Props$4): react_jsx_runtime.JSX.Element;
50
+
51
+ type Props$3 = {
52
+ block: AnyBlock;
53
+ className?: string;
54
+ placeholder?: string;
55
+ editable: boolean;
56
+ onFocus: (id: string) => void;
57
+ blockRefs: React.MutableRefObject<Map<string, HTMLSpanElement>>;
58
+ hydratedBlocks: React.MutableRefObject<Set<string>>;
59
+ };
60
+ declare function EditableContent({ block, className, placeholder, editable, onFocus, blockRefs, hydratedBlocks, }: Props$3): react_jsx_runtime.JSX.Element;
61
+ declare function nodesToHtml(nodes: Node[]): string;
62
+ declare function domToNodes(el: HTMLElement): Node[];
63
+
64
+ type Props$2 = {
65
+ block: AnyBlock;
66
+ };
67
+ declare function FormatToolbar({ block }: Props$2): react_jsx_runtime.JSX.Element | null;
68
+
69
+ type Props$1 = {
70
+ block: AnyBlock;
71
+ onClose: () => void;
72
+ };
73
+ declare function BlockTypeSwitcher({ block, onClose }: Props$1): react_jsx_runtime.JSX.Element;
74
+
75
+ type Props = {
76
+ blockId: string;
77
+ onDragStart: (id: string) => void;
78
+ };
79
+ declare function DragHandle({ blockId, onDragStart }: Props): react_jsx_runtime.JSX.Element;
80
+
81
+ declare function useEditor<T>(selector: (state: EditorStore) => T): T;
82
+ declare function useBlocks(): _reiwuzen_blocky.AnyBlock[];
83
+ declare function useActiveBlockId(): string | null;
84
+ declare function useEditorActions(): {
85
+ setBlocks: (blocks: _reiwuzen_blocky.AnyBlock[]) => void;
86
+ updateBlock: (block: _reiwuzen_blocky.AnyBlock) => void;
87
+ insertBlockAfter: (afterId: string, type?: _reiwuzen_blocky.AnyBlock["type"]) => string | null;
88
+ removeBlock: (id: string) => string;
89
+ duplicateBlock: (id: string) => void;
90
+ moveBlock: (id: string, direction: "up" | "down") => void;
91
+ setActiveBlockId: (id: string | null) => void;
92
+ };
93
+
94
+ /**
95
+ * Returns a function that reads window.getSelection() and converts
96
+ * the flat browser offsets to a NodeSelection for the given block.
97
+ */
98
+ declare function useSelection(block: AnyBlock): () => NodeSelection | null;
99
+
100
+ type UseBlockKeyboardProps = {
101
+ block: AnyBlock;
102
+ onFocus: (id: string) => void;
103
+ };
104
+ declare function useBlockKeyboard({ block, onFocus }: UseBlockKeyboardProps): (e: KeyboardEvent<HTMLElement>) => void;
105
+
106
+ export { Block, BlockList, BlockTypeSwitcher, DragHandle, EditableContent, Editor, type EditorProps, FormatToolbar, domToNodes, nodesToHtml, useActiveBlockId, useBlockKeyboard, useBlocks, useEditor, useEditorActions, useSelection };
@@ -0,0 +1,106 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as _reiwuzen_blocky from '@reiwuzen/blocky';
3
+ import { AnyBlock, Node, NodeSelection } from '@reiwuzen/blocky';
4
+ import React, { KeyboardEvent } from 'react';
5
+
6
+ type EditorStore = {
7
+ blocks: AnyBlock[];
8
+ activeBlockId: string | null;
9
+ setBlocks: (blocks: AnyBlock[]) => void;
10
+ updateBlock: (block: AnyBlock) => void;
11
+ insertAfter: (afterId: string, type?: AnyBlock["type"]) => string | null;
12
+ removeBlock: (id: string) => string;
13
+ duplicate: (id: string) => void;
14
+ move: (id: string, direction: "up" | "down") => void;
15
+ setActiveBlockId: (id: string | null) => void;
16
+ };
17
+
18
+ type EditorProps = {
19
+ /** Seed blocks — hydrated once on mount */
20
+ blocks?: AnyBlock[];
21
+ /**
22
+ * Called with serialized blocks when editable flips true → false.
23
+ * This is your "save" hook.
24
+ */
25
+ onChange?: (blocks: AnyBlock[]) => void;
26
+ editable?: boolean;
27
+ className?: string;
28
+ placeholder?: string;
29
+ };
30
+ declare function Editor({ blocks: seedBlocks, onChange, editable, className, placeholder, }: EditorProps): react_jsx_runtime.JSX.Element;
31
+
32
+ type Props$5 = {
33
+ editable: boolean;
34
+ blockRefs: React.RefObject<Map<string, HTMLSpanElement>>;
35
+ hydratedBlocks: React.RefObject<Set<string>>;
36
+ };
37
+ declare function BlockList({ editable, blockRefs, hydratedBlocks }: Props$5): react_jsx_runtime.JSX.Element;
38
+
39
+ type Props$4 = {
40
+ block: AnyBlock;
41
+ isActive: boolean;
42
+ editable: boolean;
43
+ onFocus: (id: string) => void;
44
+ onDragStart: (id: string) => void;
45
+ onDrop: (dragId: string, dropId: string) => void;
46
+ blockRefs: React.MutableRefObject<Map<string, HTMLSpanElement>>;
47
+ hydratedBlocks: React.MutableRefObject<Set<string>>;
48
+ };
49
+ declare function Block({ block, isActive, editable, onFocus, onDragStart, onDrop, blockRefs, hydratedBlocks, }: Props$4): react_jsx_runtime.JSX.Element;
50
+
51
+ type Props$3 = {
52
+ block: AnyBlock;
53
+ className?: string;
54
+ placeholder?: string;
55
+ editable: boolean;
56
+ onFocus: (id: string) => void;
57
+ blockRefs: React.MutableRefObject<Map<string, HTMLSpanElement>>;
58
+ hydratedBlocks: React.MutableRefObject<Set<string>>;
59
+ };
60
+ declare function EditableContent({ block, className, placeholder, editable, onFocus, blockRefs, hydratedBlocks, }: Props$3): react_jsx_runtime.JSX.Element;
61
+ declare function nodesToHtml(nodes: Node[]): string;
62
+ declare function domToNodes(el: HTMLElement): Node[];
63
+
64
+ type Props$2 = {
65
+ block: AnyBlock;
66
+ };
67
+ declare function FormatToolbar({ block }: Props$2): react_jsx_runtime.JSX.Element | null;
68
+
69
+ type Props$1 = {
70
+ block: AnyBlock;
71
+ onClose: () => void;
72
+ };
73
+ declare function BlockTypeSwitcher({ block, onClose }: Props$1): react_jsx_runtime.JSX.Element;
74
+
75
+ type Props = {
76
+ blockId: string;
77
+ onDragStart: (id: string) => void;
78
+ };
79
+ declare function DragHandle({ blockId, onDragStart }: Props): react_jsx_runtime.JSX.Element;
80
+
81
+ declare function useEditor<T>(selector: (state: EditorStore) => T): T;
82
+ declare function useBlocks(): _reiwuzen_blocky.AnyBlock[];
83
+ declare function useActiveBlockId(): string | null;
84
+ declare function useEditorActions(): {
85
+ setBlocks: (blocks: _reiwuzen_blocky.AnyBlock[]) => void;
86
+ updateBlock: (block: _reiwuzen_blocky.AnyBlock) => void;
87
+ insertBlockAfter: (afterId: string, type?: _reiwuzen_blocky.AnyBlock["type"]) => string | null;
88
+ removeBlock: (id: string) => string;
89
+ duplicateBlock: (id: string) => void;
90
+ moveBlock: (id: string, direction: "up" | "down") => void;
91
+ setActiveBlockId: (id: string | null) => void;
92
+ };
93
+
94
+ /**
95
+ * Returns a function that reads window.getSelection() and converts
96
+ * the flat browser offsets to a NodeSelection for the given block.
97
+ */
98
+ declare function useSelection(block: AnyBlock): () => NodeSelection | null;
99
+
100
+ type UseBlockKeyboardProps = {
101
+ block: AnyBlock;
102
+ onFocus: (id: string) => void;
103
+ };
104
+ declare function useBlockKeyboard({ block, onFocus }: UseBlockKeyboardProps): (e: KeyboardEvent<HTMLElement>) => void;
105
+
106
+ export { Block, BlockList, BlockTypeSwitcher, DragHandle, EditableContent, Editor, type EditorProps, FormatToolbar, domToNodes, nodesToHtml, useActiveBlockId, useBlockKeyboard, useBlocks, useEditor, useEditorActions, useSelection };