dn-react-text-editor 0.2.4 → 0.3.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.
package/dist/input.d.mts CHANGED
@@ -1,21 +1,19 @@
1
- import React, { DetailedHTMLProps, HTMLAttributes, RefObject } from 'react';
2
- import { TextEditorController } from './create_text_editor.mjs';
1
+ import React, { DetailedHTMLProps, HTMLAttributes } from 'react';
2
+ import { TextEditorController } from './text_editor_controller.mjs';
3
+ import 'prosemirror-model';
3
4
  import 'prosemirror-state';
4
5
  import 'prosemirror-view';
6
+ import './attach_file.mjs';
5
7
  import './schema.mjs';
6
8
  import 'orderedmap';
7
- import 'prosemirror-model';
8
9
  import 'rxjs';
9
- import './commands.mjs';
10
- import './attach_file.mjs';
11
- import './text_editor_controller.mjs';
12
10
 
13
11
  type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
- ref: RefObject<TextEditorController | null>;
12
+ controller: TextEditorController;
15
13
  updateDelay?: number;
16
14
  name?: string;
17
15
  onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
18
16
  };
19
- declare function TextEditorInput({ ref, onChange, updateDelay, ...props }: Props): React.JSX.Element;
17
+ declare function TextEditorInput({ controller, onChange, updateDelay, ...props }: Props): React.JSX.Element;
20
18
 
21
19
  export { TextEditorInput };
package/dist/input.d.ts CHANGED
@@ -1,21 +1,19 @@
1
- import React, { DetailedHTMLProps, HTMLAttributes, RefObject } from 'react';
2
- import { TextEditorController } from './create_text_editor.js';
1
+ import React, { DetailedHTMLProps, HTMLAttributes } from 'react';
2
+ import { TextEditorController } from './text_editor_controller.js';
3
+ import 'prosemirror-model';
3
4
  import 'prosemirror-state';
4
5
  import 'prosemirror-view';
6
+ import './attach_file.js';
5
7
  import './schema.js';
6
8
  import 'orderedmap';
7
- import 'prosemirror-model';
8
9
  import 'rxjs';
9
- import './commands.js';
10
- import './attach_file.js';
11
- import './text_editor_controller.js';
12
10
 
13
11
  type Props = Omit<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
- ref: RefObject<TextEditorController | null>;
12
+ controller: TextEditorController;
15
13
  updateDelay?: number;
16
14
  name?: string;
17
15
  onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
18
16
  };
19
- declare function TextEditorInput({ ref, onChange, updateDelay, ...props }: Props): React.JSX.Element;
17
+ declare function TextEditorInput({ controller, onChange, updateDelay, ...props }: Props): React.JSX.Element;
20
18
 
21
19
  export { TextEditorInput };
package/dist/input.js CHANGED
@@ -36,17 +36,13 @@ module.exports = __toCommonJS(input_exports);
36
36
  var import_react = __toESM(require("react"));
37
37
  var import_rxjs = require("rxjs");
38
38
  function TextEditorInput({
39
- ref,
39
+ controller,
40
40
  onChange,
41
41
  updateDelay = 0,
42
42
  ...props
43
43
  }) {
44
44
  const inputRef = import_react.default.useRef(null);
45
45
  (0, import_react.useEffect)(() => {
46
- const controller = ref.current;
47
- if (!controller) {
48
- return;
49
- }
50
46
  const sub = controller.subject.pipe(
51
47
  (0, import_rxjs.filter)((tr) => tr.docChanged),
52
48
  (0, import_rxjs.debounceTime)(updateDelay)
@@ -59,7 +55,6 @@ function TextEditorInput({
59
55
  });
60
56
  return () => {
61
57
  sub.unsubscribe();
62
- controller.view.destroy();
63
58
  };
64
59
  }, []);
65
60
  return /* @__PURE__ */ import_react.default.createElement("input", { ...props, ref: inputRef, type: "hidden", onInput: onChange });
package/dist/input.mjs CHANGED
@@ -4,17 +4,13 @@ import React, {
4
4
  } from "react";
5
5
  import { debounceTime, filter } from "rxjs";
6
6
  function TextEditorInput({
7
- ref,
7
+ controller,
8
8
  onChange,
9
9
  updateDelay = 0,
10
10
  ...props
11
11
  }) {
12
12
  const inputRef = React.useRef(null);
13
13
  useEffect(() => {
14
- const controller = ref.current;
15
- if (!controller) {
16
- return;
17
- }
18
14
  const sub = controller.subject.pipe(
19
15
  filter((tr) => tr.docChanged),
20
16
  debounceTime(updateDelay)
@@ -27,7 +23,6 @@ function TextEditorInput({
27
23
  });
28
24
  return () => {
29
25
  sub.unsubscribe();
30
- controller.view.destroy();
31
26
  };
32
27
  }, []);
33
28
  return /* @__PURE__ */ React.createElement("input", { ...props, ref: inputRef, type: "hidden", onInput: onChange });
@@ -1,5 +1,5 @@
1
1
  import * as prosemirror_model from 'prosemirror-model';
2
- import { Schema } from 'prosemirror-model';
2
+ import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model';
3
3
  import { EditorStateConfig, Transaction } from 'prosemirror-state';
4
4
  import { DirectEditorProps, EditorView } from 'prosemirror-view';
5
5
  import { GenerateMetadata, UploadFile } from './attach_file.mjs';
@@ -7,14 +7,6 @@ import { Subject } from 'rxjs';
7
7
  import './schema.mjs';
8
8
  import 'orderedmap';
9
9
 
10
- type TextEditorControllerProps = {
11
- mode?: "html" | "text";
12
- state?: Partial<EditorStateConfig>;
13
- editor?: Partial<DirectEditorProps>;
14
- defaultValue?: string | readonly string[] | number;
15
- updateDelay?: number;
16
- placeholder?: string;
17
- };
18
10
  type CreateTextEditorOptions = {
19
11
  className?: string;
20
12
  style?: string;
@@ -23,12 +15,32 @@ type CreateTextEditorOptions = {
23
15
  uploadFile?: UploadFile;
24
16
  };
25
17
  };
26
- declare function createTextEditorController(container: HTMLElement, schema: Schema, options: CreateTextEditorOptions, { mode, state, editor, defaultValue, updateDelay, placeholder, }: TextEditorControllerProps): {
27
- schema: Schema<any, any>;
28
- view: EditorView;
18
+ type TextEditorControllerProps = {
19
+ mode?: "html" | "text";
20
+ state?: Partial<EditorStateConfig>;
21
+ editor?: Partial<DirectEditorProps>;
22
+ defaultValue?: string | readonly string[] | number;
23
+ updateDelay?: number;
24
+ placeholder?: string;
25
+ autoFocus?: boolean;
26
+ };
27
+ declare class TextEditorController {
28
+ schema: Schema;
29
+ options: CreateTextEditorOptions;
30
+ props: TextEditorControllerProps;
29
31
  subject: Subject<Transaction>;
30
- value: string;
31
- commands: {
32
+ view?: EditorView;
33
+ prosemirrorParser: DOMParser;
34
+ prosemirrorSerializer: DOMSerializer;
35
+ get value(): string;
36
+ set value(value: string);
37
+ constructor(options?: CreateTextEditorOptions, props?: TextEditorControllerProps);
38
+ toInnerHTML(value: string): string;
39
+ attachFile(files: File[]): Promise<void>;
40
+ bind(container: HTMLElement): void;
41
+ toHTML(): string;
42
+ toTextContent(): string;
43
+ get commands(): {
32
44
  isBlockTypeActive: (node: prosemirror_model.NodeType, attrs?: prosemirror_model.Attrs | null, excludes?: prosemirror_model.NodeType[]) => false | undefined;
33
45
  setBlockType: (node: string, attrs?: prosemirror_model.Attrs | null) => void;
34
46
  toggleBlockType: (node: string, attrs?: prosemirror_model.Attrs | null) => void;
@@ -41,6 +53,7 @@ declare function createTextEditorController(container: HTMLElement, schema: Sche
41
53
  clear: () => void;
42
54
  attachFile: (files: File[]) => void;
43
55
  };
44
- };
56
+ dispose(): void;
57
+ }
45
58
 
46
- export { type CreateTextEditorOptions, type TextEditorControllerProps, createTextEditorController };
59
+ export { type CreateTextEditorOptions, TextEditorController, type TextEditorControllerProps };
@@ -1,5 +1,5 @@
1
1
  import * as prosemirror_model from 'prosemirror-model';
2
- import { Schema } from 'prosemirror-model';
2
+ import { Schema, DOMParser, DOMSerializer } from 'prosemirror-model';
3
3
  import { EditorStateConfig, Transaction } from 'prosemirror-state';
4
4
  import { DirectEditorProps, EditorView } from 'prosemirror-view';
5
5
  import { GenerateMetadata, UploadFile } from './attach_file.js';
@@ -7,14 +7,6 @@ import { Subject } from 'rxjs';
7
7
  import './schema.js';
8
8
  import 'orderedmap';
9
9
 
10
- type TextEditorControllerProps = {
11
- mode?: "html" | "text";
12
- state?: Partial<EditorStateConfig>;
13
- editor?: Partial<DirectEditorProps>;
14
- defaultValue?: string | readonly string[] | number;
15
- updateDelay?: number;
16
- placeholder?: string;
17
- };
18
10
  type CreateTextEditorOptions = {
19
11
  className?: string;
20
12
  style?: string;
@@ -23,12 +15,32 @@ type CreateTextEditorOptions = {
23
15
  uploadFile?: UploadFile;
24
16
  };
25
17
  };
26
- declare function createTextEditorController(container: HTMLElement, schema: Schema, options: CreateTextEditorOptions, { mode, state, editor, defaultValue, updateDelay, placeholder, }: TextEditorControllerProps): {
27
- schema: Schema<any, any>;
28
- view: EditorView;
18
+ type TextEditorControllerProps = {
19
+ mode?: "html" | "text";
20
+ state?: Partial<EditorStateConfig>;
21
+ editor?: Partial<DirectEditorProps>;
22
+ defaultValue?: string | readonly string[] | number;
23
+ updateDelay?: number;
24
+ placeholder?: string;
25
+ autoFocus?: boolean;
26
+ };
27
+ declare class TextEditorController {
28
+ schema: Schema;
29
+ options: CreateTextEditorOptions;
30
+ props: TextEditorControllerProps;
29
31
  subject: Subject<Transaction>;
30
- value: string;
31
- commands: {
32
+ view?: EditorView;
33
+ prosemirrorParser: DOMParser;
34
+ prosemirrorSerializer: DOMSerializer;
35
+ get value(): string;
36
+ set value(value: string);
37
+ constructor(options?: CreateTextEditorOptions, props?: TextEditorControllerProps);
38
+ toInnerHTML(value: string): string;
39
+ attachFile(files: File[]): Promise<void>;
40
+ bind(container: HTMLElement): void;
41
+ toHTML(): string;
42
+ toTextContent(): string;
43
+ get commands(): {
32
44
  isBlockTypeActive: (node: prosemirror_model.NodeType, attrs?: prosemirror_model.Attrs | null, excludes?: prosemirror_model.NodeType[]) => false | undefined;
33
45
  setBlockType: (node: string, attrs?: prosemirror_model.Attrs | null) => void;
34
46
  toggleBlockType: (node: string, attrs?: prosemirror_model.Attrs | null) => void;
@@ -41,6 +53,7 @@ declare function createTextEditorController(container: HTMLElement, schema: Sche
41
53
  clear: () => void;
42
54
  attachFile: (files: File[]) => void;
43
55
  };
44
- };
56
+ dispose(): void;
57
+ }
45
58
 
46
- export { type CreateTextEditorOptions, type TextEditorControllerProps, createTextEditorController };
59
+ export { type CreateTextEditorOptions, TextEditorController, type TextEditorControllerProps };