@use-kona/editor 0.1.8-rc.13 → 0.1.8-rc.14

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/editor.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useCallback, useImperativeHandle, useState } from "react";
3
- import { Transforms } from "slate";
3
+ import { Editor, Transforms } from "slate";
4
4
  import { ReactEditor, Slate } from "slate-react";
5
5
  import { createEditable } from "./core/createEditable.js";
6
6
  import { createEditor } from "./core/createEditor.js";
@@ -23,7 +23,11 @@ const KonaEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
23
23
  deserialize: deserialize(plugins),
24
24
  deleteNode,
25
25
  isEmpty: ()=>isEmpty(editor.children),
26
- focus: ()=>{
26
+ focus: (mode)=>{
27
+ if ('end' === mode) {
28
+ const endPoint = Editor.end(editor, []);
29
+ Transforms.select(editor, endPoint);
30
+ }
27
31
  ReactEditor.focus(editor);
28
32
  }
29
33
  };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { KeyboardEvent, ReactElement, ReactNode } from 'react';
2
- import type { DecoratedRange, Descendant, Editor, NodeEntry } from 'slate';
2
+ import type { DecoratedRange, Descendant, Editor, NodeEntry, NodeMatch } from 'slate';
3
3
  import type { RenderElementProps, RenderLeafProps } from 'slate-react';
4
4
  import type { CustomElement, CustomText } from '../types';
5
5
  export interface IPlugin<TEditor extends Editor = Editor, TBlock extends CustomElement = CustomElement, TLeaf extends CustomText = CustomText> {
@@ -46,6 +46,9 @@ export type UiParams = {
46
46
  export type EditorRef = {
47
47
  serialize: (node: CustomElement | CustomText) => string;
48
48
  deserialize: (element: HTMLElement) => (Descendant | string)[] | string | Descendant | null;
49
+ isEmpty: () => boolean;
50
+ deleteNode: (match: NodeMatch<CustomElement>) => void;
51
+ focus: (mode?: 'end') => void;
49
52
  };
50
53
  export type Serialize = (node: CustomElement | CustomText, children?: string) => string | undefined;
51
54
  export type Deserialize = (element: HTMLElement, children?: (string | Descendant)[]) => CustomElement | CustomText[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-kona/editor",
3
- "version": "0.1.8-rc.13",
3
+ "version": "0.1.8-rc.14",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
package/src/editor.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
2
- import { type Descendant, type NodeMatch, Transforms } from 'slate';
2
+ import {type Descendant, Editor, type NodeMatch, Transforms} from 'slate';
3
3
  import { ReactEditor, Slate } from 'slate-react';
4
4
  import type { CustomElement } from '../types';
5
5
  import { createEditable } from './core/createEditable';
@@ -36,7 +36,12 @@ export const KonaEditor = forwardRef<EditorRef, KonaEditorProps>(
36
36
  isEmpty: () => {
37
37
  return isEmpty(editor.children);
38
38
  },
39
- focus: () => {
39
+ focus: (mode?: 'end') => {
40
+ if (mode === 'end') {
41
+ const endPoint = Editor.end(editor, [])
42
+ Transforms.select(editor, endPoint)
43
+ }
44
+
40
45
  ReactEditor.focus(editor);
41
46
  },
42
47
  };
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { KeyboardEvent, ReactElement, ReactNode } from 'react';
2
- import type { DecoratedRange, Descendant, Editor, NodeEntry } from 'slate';
2
+ import type {DecoratedRange, Descendant, Editor, NodeEntry, NodeMatch} from 'slate';
3
3
  import type { RenderElementProps, RenderLeafProps } from 'slate-react';
4
4
  import type { CustomElement, CustomText } from '../types';
5
5
 
@@ -71,6 +71,9 @@ export type EditorRef = {
71
71
  deserialize: (
72
72
  element: HTMLElement,
73
73
  ) => (Descendant | string)[] | string | Descendant | null;
74
+ isEmpty: () => boolean;
75
+ deleteNode: (match: NodeMatch<CustomElement>) => void;
76
+ focus: (mode?: 'end') => void;
74
77
  };
75
78
 
76
79
  export type Serialize = (