@rathkit/rte-react 0.1.0-alpha.3 → 0.1.0-alpha.5
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/README.md +1 -1
- package/dist/editor.d.ts +11 -1
- package/dist/editor.js +12 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rathkit/rte-react
|
|
2
2
|
|
|
3
|
-
> **Alpha
|
|
3
|
+
> **Alpha.** Not for production: the APIs will change between releases. Published to the `next` tag only.
|
|
4
4
|
|
|
5
5
|
The editor for React: a component and hooks over the headless layer. A component re-renders only when the value it reads changes. No editor or accessibility logic lives here.
|
|
6
6
|
|
package/dist/editor.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { Editor } from "@rathkit/rte-core/dom";
|
|
2
|
+
import type { Selection } from "@rathkit/rte-core";
|
|
2
3
|
import { type StandardOptions } from "@rathkit/rte-core/standard";
|
|
3
|
-
export type RteOptions = Omit<StandardOptions, "element" | "html" | "readOnly">;
|
|
4
|
+
export type RteOptions = Omit<StandardOptions, "element" | "html" | "readOnly" | "disabled">;
|
|
4
5
|
export interface RteEditorProps extends RteOptions {
|
|
5
6
|
/** The starting HTML. Later changes to this prop are ignored: call `editor.setHtml` to replace the document. */
|
|
6
7
|
defaultValue?: string;
|
|
8
|
+
/** No edits; the editor can still be focused, selected in and copied from. Live. */
|
|
7
9
|
readOnly?: boolean;
|
|
10
|
+
/** Read-only, and not focusable or in the tab order. Live. */
|
|
11
|
+
disabled?: boolean;
|
|
8
12
|
/** The name screen readers announce for the editing surface. Required: an unnamed editor is an accessibility fault. */
|
|
9
13
|
label: string;
|
|
10
14
|
className?: string;
|
|
@@ -12,6 +16,12 @@ export interface RteEditorProps extends RteOptions {
|
|
|
12
16
|
onChange?: (html: string) => void;
|
|
13
17
|
/** Called once the editor exists, with the editor to run commands on and subscribe to. */
|
|
14
18
|
onReady?: (editor: Editor) => void;
|
|
19
|
+
/** Called when the editor gains the focus. */
|
|
20
|
+
onFocus?: (editor: Editor) => void;
|
|
21
|
+
/** Called when the editor loses the focus. */
|
|
22
|
+
onBlur?: (editor: Editor) => void;
|
|
23
|
+
/** Called when the selection moves or changes. */
|
|
24
|
+
onSelection?: (selection: Selection) => void;
|
|
15
25
|
}
|
|
16
26
|
/** The hook behind `RteEditor`, for those who draw their own surface: give `ref` to one element. */
|
|
17
27
|
export declare function useRteEditor(props: Omit<RteEditorProps, "label" | "className">): {
|
package/dist/editor.js
CHANGED
|
@@ -8,16 +8,16 @@ export function useRteEditor(props) {
|
|
|
8
8
|
useEffect(() => {
|
|
9
9
|
if (!element)
|
|
10
10
|
return;
|
|
11
|
-
const { defaultValue, readOnly, onChange: _c, onReady: _r, ...options } = latest.current;
|
|
12
|
-
const made = createEditor({ ...options, element, html: defaultValue ?? "", readOnly: readOnly ?? false });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
const { defaultValue, readOnly, disabled, onChange: _c, onReady: _r, onFocus: _f, onBlur: _b, onSelection: _s, ...options } = latest.current;
|
|
12
|
+
const made = createEditor({ ...options, element, html: defaultValue ?? "", readOnly: readOnly ?? false, disabled: disabled ?? false });
|
|
13
|
+
const offs = [
|
|
14
|
+
made.on("change", (html) => latest.current.onChange?.(html)),
|
|
15
|
+
made.on("focus", (e) => latest.current.onFocus?.(e)),
|
|
16
|
+
made.on("blur", (e) => latest.current.onBlur?.(e)),
|
|
17
|
+
made.on("selection", (selection) => latest.current.onSelection?.(selection)),
|
|
18
|
+
];
|
|
19
|
+
const stop = () => { for (const off of offs)
|
|
20
|
+
off(); };
|
|
21
21
|
setEditor(made);
|
|
22
22
|
latest.current.onReady?.(made);
|
|
23
23
|
return () => {
|
|
@@ -27,10 +27,11 @@ export function useRteEditor(props) {
|
|
|
27
27
|
};
|
|
28
28
|
}, [element]);
|
|
29
29
|
useEffect(() => { editor?.setReadOnly(props.readOnly ?? false); }, [editor, props.readOnly]);
|
|
30
|
+
useEffect(() => { editor?.setDisabled(props.disabled ?? false); }, [editor, props.disabled]);
|
|
30
31
|
return { ref, editor };
|
|
31
32
|
}
|
|
32
33
|
export function RteEditor(props) {
|
|
33
34
|
const { label, className, ...rest } = props;
|
|
34
35
|
const { ref } = useRteEditor(rest);
|
|
35
|
-
return createElement("div", { ref, "aria-label": label, className, "data-
|
|
36
|
+
return createElement("div", { ref, "aria-label": label, className, "data-rte-surface": "" });
|
|
36
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathkit/rte-react",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"description": "The editor for React: a component and hooks over the headless layer, with no editor or accessibility logic of its own.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rich-text",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@rathkit/rte-core": ">=0.1.0-alpha.
|
|
48
|
-
"@rathkit/rte-headless": ">=0.1.0-alpha.
|
|
47
|
+
"@rathkit/rte-core": ">=0.1.0-alpha.5 <0.2.0",
|
|
48
|
+
"@rathkit/rte-headless": ">=0.1.0-alpha.5 <0.2.0",
|
|
49
49
|
"react": ">=18"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|