@use-kona/editor 0.1.2-rc.5 → 0.1.2-rc.7

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.
Files changed (29) hide show
  1. package/dist/core/serialize.d.ts +1 -1
  2. package/dist/core/serialize.js +3 -3
  3. package/dist/examples/{LanguageSelector.d.ts → CodeBlock.d.ts} +3 -1
  4. package/dist/examples/{LanguageSelector.js → CodeBlock.js} +36 -27
  5. package/dist/examples/CodeBlock.module.js +9 -0
  6. package/dist/examples/{LanguageSelector_module.css → CodeBlock_module.css} +19 -6
  7. package/dist/examples/Editor.d.ts +1 -1
  8. package/dist/examples/Editor.js +14 -9
  9. package/dist/examples/getPlugins.js +2 -2
  10. package/dist/examples/text.js +1 -1
  11. package/dist/plugins/BasicFormattingPlugin/BasicFormattingPlugin.js +12 -1
  12. package/dist/plugins/CodeBlockPlugin/CodeBlock.d.ts +0 -2
  13. package/dist/plugins/CodeBlockPlugin/CodeBlock.js +8 -14
  14. package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.d.ts +3 -2
  15. package/dist/plugins/CodeBlockPlugin/CodeBlockPlugin.js +11 -7
  16. package/dist/plugins/CodeBlockPlugin/styles_module.css +0 -3
  17. package/dist/plugins/CommandsPlugin/Menu.js +3 -2
  18. package/dist/plugins/CommandsPlugin/styles_module.css +20 -14
  19. package/dist/plugins/HeadingsPlugin/HeadingsPlugin.d.ts +2 -1
  20. package/dist/plugins/HeadingsPlugin/HeadingsPlugin.js +9 -0
  21. package/dist/plugins/LinksPlugin/LinksPlugin.d.ts +1 -0
  22. package/dist/plugins/LinksPlugin/LinksPlugin.js +3 -0
  23. package/dist/plugins/ListsPlugin/ListsPlugin.d.ts +1 -0
  24. package/dist/plugins/ListsPlugin/ListsPlugin.js +9 -0
  25. package/dist/plugins/MenuPlugin/styles_module.css +2 -2
  26. package/dist/types.d.ts +4 -3
  27. package/package.json +1 -1
  28. package/src/plugins/MenuPlugin/styles.module.css +2 -2
  29. package/dist/examples/LanguageSelector.module.js +0 -7
@@ -1,3 +1,3 @@
1
1
  import type { CustomElement, CustomText } from '../../types';
2
2
  import type { IPlugin } from '../types';
3
- export declare const serialize: (plugins: IPlugin[]) => (node: CustomElement | CustomElement[] | CustomText | CustomText[]) => string;
3
+ export declare const serialize: (plugins: IPlugin[]) => (node: CustomElement | CustomText) => string;
@@ -1,12 +1,12 @@
1
1
  import escape_html from "escape-html";
2
2
  import { Text } from "slate";
3
3
  const serialize = (plugins)=>(node)=>{
4
- const serializers = plugins.flatMap((plugin)=>plugin.blocks?.map((element)=>element.serialize)).filter(Boolean);
4
+ const serializers = plugins.flatMap((plugin)=>plugin.blocks?.map((element)=>element.serialize)).concat(plugins.flatMap((plugin)=>plugin.leafs?.map((element)=>element.serialize))).filter(Boolean);
5
5
  if (Array.isArray(node)) return node.map(serialize(plugins)).join('');
6
6
  if (Text.isText(node)) return serializers.reduce((prev, current)=>current?.(node) || prev, escape_html(node.text));
7
7
  {
8
- const children = node.children?.map((n)=>serialize(plugins)(n)).join('');
9
- if ('paragraph' === node.type) return `<p>${children}</p>`;
8
+ const children = node?.children?.map((n)=>serialize(plugins)(n)).join('');
9
+ if (node?.type === 'paragraph') return `<p>${children}</p>`;
10
10
  return serializers.reduce((prev, current)=>current?.(node, children) || prev, '') || children;
11
11
  }
12
12
  };
@@ -1,10 +1,12 @@
1
+ import { type ReactNode } from 'react';
1
2
  import type { CustomElement } from '../../types';
2
3
  type Props = {
3
4
  value: string;
4
5
  onChange: (value: string) => void;
5
6
  params: {
6
7
  element: CustomElement;
8
+ Content: () => ReactNode;
7
9
  };
8
10
  };
9
- export declare const LanguageSelector: (props: Props) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const CodeBlock: (props: Props) => import("react/jsx-runtime").JSX.Element;
10
12
  export {};
@@ -1,9 +1,9 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useMemo } from "react";
3
3
  import { Node } from "slate";
4
+ import CodeBlock_module from "./CodeBlock.module.js";
4
5
  import { CheckIcon } from "./icons/check.js";
5
6
  import { CopyIcon } from "./icons/copy.js";
6
- import LanguageSelector_module from "./LanguageSelector.module.js";
7
7
  import { Button } from "./ui/Button/index.js";
8
8
  import { Dropdown } from "./ui/Dropdown/index.js";
9
9
  import { Menu } from "./ui/Menu/index.js";
@@ -93,10 +93,10 @@ const languages = [
93
93
  label: 'Plain Text'
94
94
  }
95
95
  ];
96
- const LanguageSelector = (props)=>{
97
- const { value: language, onChange, params } = props;
96
+ const CodeBlock = (props)=>{
97
+ const { value: language, onChange, params: { element, Content } } = props;
98
98
  const handleCopyClick = ()=>{
99
- const text = Array.from(Node.texts(params.element)).map((nodeEntry)=>nodeEntry[0].text).join('\n');
99
+ const text = Array.from(Node.texts(element)).map((nodeEntry)=>nodeEntry[0].text).join('\n');
100
100
  navigator.clipboard.writeText(text);
101
101
  };
102
102
  const menuConfig = useMemo(()=>({
@@ -121,34 +121,43 @@ const LanguageSelector = (props)=>{
121
121
  language
122
122
  ]);
123
123
  return /*#__PURE__*/ jsxs("div", {
124
- className: LanguageSelector_module.root,
124
+ className: CodeBlock_module.root,
125
125
  children: [
126
- /*#__PURE__*/ jsx(Dropdown, {
127
- config: menuConfig,
128
- Menu: /*#__PURE__*/ forwardRef((props, ref)=>/*#__PURE__*/ jsx("div", {
129
- ...props,
130
- ref: ref,
131
- className: [
132
- LanguageSelector_module.customMenu,
133
- props.className
134
- ].join(' ')
135
- })),
136
- children: ({ ref, onClick })=>/*#__PURE__*/ jsx(Button, {
137
- ref: ref,
126
+ /*#__PURE__*/ jsxs("div", {
127
+ className: CodeBlock_module.menu,
128
+ children: [
129
+ /*#__PURE__*/ jsx(Dropdown, {
130
+ config: menuConfig,
131
+ Menu: /*#__PURE__*/ forwardRef((props, ref)=>/*#__PURE__*/ jsx("div", {
132
+ ...props,
133
+ ref: ref,
134
+ className: [
135
+ CodeBlock_module.customMenu,
136
+ props.className
137
+ ].join(' ')
138
+ })),
139
+ children: ({ ref, onClick })=>/*#__PURE__*/ jsx(Button, {
140
+ ref: ref,
141
+ size: "sm",
142
+ onClick: onClick,
143
+ children: languages.find((l)=>l.value === language)?.label || 'Select language'
144
+ })
145
+ }),
146
+ /*#__PURE__*/ jsx(Button, {
138
147
  size: "sm",
139
- onClick: onClick,
140
- children: languages.find((l)=>l.value === language)?.label || 'Select language'
148
+ type: "button",
149
+ onClick: handleCopyClick,
150
+ children: /*#__PURE__*/ jsx(CopyIcon, {
151
+ size: 16
152
+ })
141
153
  })
154
+ ]
142
155
  }),
143
- /*#__PURE__*/ jsx(Button, {
144
- size: "sm",
145
- type: "button",
146
- onClick: handleCopyClick,
147
- children: /*#__PURE__*/ jsx(CopyIcon, {
148
- size: 16
149
- })
156
+ /*#__PURE__*/ jsx("div", {
157
+ className: CodeBlock_module.content,
158
+ children: /*#__PURE__*/ jsx(Content, {})
150
159
  })
151
160
  ]
152
161
  });
153
162
  };
154
- export { LanguageSelector };
163
+ export { CodeBlock };
@@ -0,0 +1,9 @@
1
+ import "./CodeBlock_module.css";
2
+ const CodeBlock_module = {
3
+ root: "root-qalHKY",
4
+ button: "button-NFVN8i",
5
+ menu: "menu-tWodT1",
6
+ content: "content-vvTcTm",
7
+ customMenu: "customMenu-PLCVVP"
8
+ };
9
+ export { CodeBlock_module as default };
@@ -1,12 +1,12 @@
1
- .root-lOdP_6 {
2
- border-bottom: 1px solid var(--kona-editor-border-color);
3
- justify-content: space-between;
4
- column-gap: 8px;
1
+ .root-qalHKY {
2
+ background-color: var(--kona-editor-alt-background-color);
3
+ border-radius: 8px;
4
+ flex-direction: column;
5
5
  padding: 4px;
6
6
  display: flex;
7
7
  }
8
8
 
9
- .button-GlQ_nf {
9
+ .button-NFVN8i {
10
10
  cursor: pointer;
11
11
  background-color: #0000;
12
12
  border-radius: 4px;
@@ -24,7 +24,20 @@
24
24
  }
25
25
  }
26
26
 
27
- .customMenu-eXoQR8 {
27
+ .menu-tWodT1 {
28
+ justify-content: space-between;
29
+ column-gap: 4px;
30
+ padding: 4px 0;
31
+ display: flex;
32
+ }
33
+
34
+ .content-vvTcTm {
35
+ background-color: var(--kona-editor-background-color);
36
+ border-radius: 6px;
37
+ padding: 8px 4px;
38
+ }
39
+
40
+ .customMenu-PLCVVP {
28
41
  background-color: var(--kona-editor-background-color);
29
42
  border: 1px solid var(--kona-editor-border-color);
30
43
  z-index: 21;
@@ -4,5 +4,5 @@ type Props = {
4
4
  value?: any;
5
5
  onChange?: (value: Descendant[]) => void;
6
6
  };
7
- export declare const ExampleEditor: (props: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const ExampleEditor: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<unknown>>;
8
8
  export {};
@@ -1,24 +1,29 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useEffect, useRef, useState } from "react";
2
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
3
3
  import { DndProvider } from "react-dnd";
4
4
  import { HTML5Backend } from "react-dnd-html5-backend";
5
5
  import { deserialize } from "../core/deserialize.js";
6
+ import { serialize } from "../core/serialize.js";
6
7
  import { KonaEditor } from "../editor.js";
7
8
  import Editor_module from "./Editor.module.js";
8
9
  import { getPlugins } from "./getPlugins.js";
9
10
  import { text as external_text_js_text } from "./text.js";
10
11
  const initialValue = external_text_js_text;
11
- const ExampleEditor = (props)=>{
12
- const { initialValueType = 'kona-editor' } = props;
12
+ const ExampleEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
13
+ const { value: defaultValue = external_text_js_text, initialValueType = 'kona-editor' } = props;
13
14
  const [plugins] = useState(getPlugins());
14
15
  const [value, setValue] = useState(null);
15
- const ref = useRef(null);
16
+ const editorRef = useRef(null);
17
+ useImperativeHandle(ref, ()=>({
18
+ serialize: serialize(plugins)
19
+ }), [
20
+ plugins
21
+ ]);
16
22
  useEffect(()=>{
17
- if ('kona-editor' === initialValueType) setValue(props.value);
23
+ if ('kona-editor' === initialValueType) setValue(defaultValue);
18
24
  else {
19
- const parsed = deserialize(plugins)(props.value);
25
+ const parsed = deserialize(plugins)(defaultValue);
20
26
  parsed && setValue(parsed);
21
- console.log(parsed);
22
27
  }
23
28
  }, []);
24
29
  return /*#__PURE__*/ jsx(DndProvider, {
@@ -28,12 +33,12 @@ const ExampleEditor = (props)=>{
28
33
  Editor_module.root
29
34
  ].join(' '),
30
35
  children: value && /*#__PURE__*/ jsx(KonaEditor, {
31
- ref: ref,
36
+ ref: editorRef,
32
37
  initialValue: value || initialValue,
33
38
  plugins: plugins,
34
39
  onChange: props.onChange || console.log
35
40
  })
36
41
  })
37
42
  });
38
- };
43
+ });
39
44
  export { ExampleEditor };
@@ -1,12 +1,12 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { BasicFormattingPlugin, BreaksPlugin, CodeBlockPlugin, CommandsPlugin, DnDPlugin, FloatingMenuPlugin, HeadingsPlugin, HighlightsPlugin, LinksPlugin, ListsPlugin, MenuPlugin, NodeIdPlugin, PlaceholderPlugin, ShortcutsPlugin, TableOfContentsPlugin } from "../plugins/index.js";
3
3
  import { Backdrop } from "./Backdrop.js";
4
+ import { CodeBlock } from "./CodeBlock.js";
4
5
  import { colors } from "./colors.js";
5
6
  import { DragBlock } from "./DragBlock.js";
6
7
  import { FloatingMenu } from "./FloatingMenu.js";
7
8
  import { getCommands } from "./getCommands.js";
8
9
  import { getShortcuts } from "./getShortcuts.js";
9
- import { LanguageSelector } from "./LanguageSelector.js";
10
10
  import { LinksHint } from "./LinksHint.js";
11
11
  import { Menu } from "./Menu.js";
12
12
  import { $store } from "./store.js";
@@ -113,7 +113,7 @@ const getPlugins = ()=>{
113
113
  }),
114
114
  new ListsPlugin({}),
115
115
  new CodeBlockPlugin({
116
- renderLanguageSelector: (value, onChange, params)=>/*#__PURE__*/ jsx(LanguageSelector, {
116
+ renderCodeBlock: (value, onChange, params)=>/*#__PURE__*/ jsx(CodeBlock, {
117
117
  value: value,
118
118
  onChange: onChange,
119
119
  params: {
@@ -44,7 +44,7 @@ const text_text = /*#__PURE__*/ jsx("fragment", null, /*#__PURE__*/ jsx("heading
44
44
  italic: true
45
45
  }, "Kona Editor"), ' ', "is a text editor based on Slate.js that I use in", ' ', /*#__PURE__*/ jsx("hlink", {
46
46
  url: "https://kona.to"
47
- }, "Kona application"), " for notes and event descriptions. I decided to open-source the editor for a few reasons:"), /*#__PURE__*/ jsx("numberedList", null, /*#__PURE__*/ jsx("listItem", null, "I had a lot of ", /*#__PURE__*/ jsx("htext", {
47
+ }, "Kona calendar"), " for notes and event descriptions. I decided to open-source the editor for a few reasons:"), /*#__PURE__*/ jsx("numberedList", null, /*#__PURE__*/ jsx("listItem", null, "I had a lot of ", /*#__PURE__*/ jsx("htext", {
48
48
  strikethrough: true
49
49
  }, "difficulties"), " fun while building this editor and there were always not enough examples of how to do it right. I wanted to make a little contribution to the community, so others could use my code as a reference."), /*#__PURE__*/ jsx("listItem", null, "I have always wanted to try to build something open-sourced, but there have not been enough good ideas on what to build. I think that an editor is a pretty decent starting point.")), /*#__PURE__*/ jsx("heading2", null, "Usage"), /*#__PURE__*/ jsx("codeBlock", {
50
50
  language: "tsx"
@@ -1,5 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { Editor } from "slate";
2
+ import escape_html from "escape-html";
3
+ import { Editor, Text } from "slate";
3
4
  import { jsx as external_slate_hyperscript_jsx } from "slate-hyperscript";
4
5
  class BasicFormattingPlugin {
5
6
  hotkeys = [
@@ -50,6 +51,16 @@ class BasicFormattingPlugin {
50
51
  children: content
51
52
  });
52
53
  },
54
+ serialize: (node)=>{
55
+ if (Text.isText(node)) {
56
+ let text = escape_html(node.text);
57
+ if (node.bold) text = `<strong>${text}</strong>`;
58
+ if (node.italic) text = `<em>${text}</em>`;
59
+ if (node.underline) text = `<u>${text}</u>`;
60
+ if (node.strikethrough) text = `<s>${text}</s>`;
61
+ return text;
62
+ }
63
+ },
53
64
  deserialize: (element, children)=>{
54
65
  const { nodeName } = element;
55
66
  let attrs = null;
@@ -1,9 +1,7 @@
1
- import type { ReactNode } from 'react';
2
1
  import type { RenderElementProps } from 'slate-react';
3
2
  import type { CodeElement } from './types';
4
3
  type Props = RenderElementProps & {
5
4
  element: CodeElement;
6
- renderLanguageSelector: (element: CodeElement) => ReactNode;
7
5
  };
8
6
  export declare const CodeBlock: (props: Props) => import("react/jsx-runtime").JSX.Element;
9
7
  export {};
@@ -1,21 +1,15 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import styles_module from "./styles.module.js";
3
- const CodeBlock = (props)=>/*#__PURE__*/ jsxs("div", {
3
+ const CodeBlock = (props)=>/*#__PURE__*/ jsx("div", {
4
4
  ...props.attributes,
5
5
  className: styles_module.root,
6
6
  spellCheck: false,
7
- children: [
8
- /*#__PURE__*/ jsx("div", {
9
- contentEditable: false,
10
- children: props.renderLanguageSelector(props.element)
11
- }),
12
- /*#__PURE__*/ jsx("div", {
13
- className: styles_module.content,
14
- children: /*#__PURE__*/ jsx("div", {
15
- className: styles_module.code,
16
- children: props.children
17
- })
7
+ children: /*#__PURE__*/ jsx("div", {
8
+ className: styles_module.content,
9
+ children: /*#__PURE__*/ jsx("div", {
10
+ className: styles_module.code,
11
+ children: props.children
18
12
  })
19
- ]
13
+ })
20
14
  });
21
15
  export { CodeBlock };
@@ -1,4 +1,4 @@
1
- import type { KeyboardEvent } from 'react';
1
+ import type { KeyboardEvent, ReactNode } from 'react';
2
2
  import { Editor, type NodeEntry } from 'slate';
3
3
  import { type RenderElementProps, type RenderLeafProps } from 'slate-react';
4
4
  import type { IPlugin } from '../../types';
@@ -25,7 +25,8 @@ import 'prismjs/components/prism-sql';
25
25
  import 'prismjs/components/prism-yaml';
26
26
  import 'prismjs/components/prism-markdown';
27
27
  type Options = {
28
- renderLanguageSelector: (value: string, onChange: (value: string) => void, params: {
28
+ renderCodeBlock: (language: string, onChange: (language: string) => void, params: {
29
+ Content: () => ReactNode;
29
30
  element: CodeElement;
30
31
  }) => React.ReactNode;
31
32
  };
@@ -1,4 +1,4 @@
1
- import { jsx } from "react/jsx-runtime";
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
2
  import prismjs from "prismjs";
3
3
  import { Editor, Element, Node, Transforms } from "slate";
4
4
  import { ReactEditor } from "slate-react";
@@ -136,6 +136,7 @@ class CodeBlockPlugin {
136
136
  {
137
137
  type: CodeBlockPlugin.CODE_ELEMENT,
138
138
  render: (props, editor)=>{
139
+ const { language } = props.element;
139
140
  const onChange = (language)=>{
140
141
  const path = ReactEditor.findPath(editor, props.element);
141
142
  Transforms.setNodes(editor, {
@@ -144,12 +145,15 @@ class CodeBlockPlugin {
144
145
  at: path
145
146
  });
146
147
  };
147
- return /*#__PURE__*/ jsx(CodeBlock, {
148
- ...props,
149
- element: props.element,
150
- renderLanguageSelector: (element)=>this.options.renderLanguageSelector(props.element.language, onChange, {
151
- element: element
152
- })
148
+ const Content = ()=>/*#__PURE__*/ jsx(CodeBlock, {
149
+ ...props,
150
+ element: props.element
151
+ });
152
+ return /*#__PURE__*/ jsx(Fragment, {
153
+ children: this.options.renderCodeBlock(language, onChange, {
154
+ element: props.element,
155
+ Content
156
+ })
153
157
  });
154
158
  }
155
159
  },
@@ -1,6 +1,4 @@
1
1
  .root-aY1XCj {
2
- border: 1px solid var(--kona-editor-border-color, #eee);
3
- border-radius: 4px;
4
2
  flex-direction: column;
5
3
  font-family: monospace;
6
4
  display: flex;
@@ -8,7 +6,6 @@
8
6
  }
9
7
 
10
8
  .content-HIkMJO {
11
- background-color: var(--kona-editor-background-color, #fff);
12
9
  display: flex;
13
10
  }
14
11
 
@@ -76,7 +76,6 @@ const Menu = (props)=>{
76
76
  case 'Escape':
77
77
  event.stopPropagation();
78
78
  $store.setKey('isOpen', false);
79
- close();
80
79
  break;
81
80
  }
82
81
  };
@@ -114,7 +113,9 @@ const Menu = (props)=>{
114
113
  children: [
115
114
  store.isOpen && /*#__PURE__*/ jsx("div", {
116
115
  className: styles_module.backdrop,
117
- onClick: close
116
+ onClick: ()=>{
117
+ $store.setKey('isOpen', false);
118
+ }
118
119
  }),
119
120
  /*#__PURE__*/ jsx("div", {
120
121
  ref: handleMenuLayout,
@@ -1,16 +1,9 @@
1
- :root {
2
- --menu-background-color: #fff;
3
- --menu-background-color-hover: #f9f9f9;
4
- --menu-text-color: #444;
5
- --menu-border-color: #ddd;
6
- }
7
-
8
1
  .menu-ZXHiGS {
9
- color: var(--menu-text-color, #444);
2
+ color: var(--kona-editor-text-color);
10
3
  z-index: 31;
11
4
  opacity: 0;
12
- background-color: var(--menu-background-color, #fff);
13
- border: 1px solid var(--menu-border-color, #ddd);
5
+ background-color: var(--kona-editor-background-color, #fff);
6
+ border: 1px solid var(--kona-editor-border-color, #ddd);
14
7
  border-radius: 4px;
15
8
  flex-direction: column;
16
9
  max-height: 200px;
@@ -24,13 +17,26 @@
24
17
  overflow-y: auto;
25
18
  transform: scale(.9);
26
19
  box-shadow: 0 1px 3px #00000006;
20
+
21
+ &::-webkit-scrollbar {
22
+ width: 6px;
23
+ }
24
+
25
+ &::-webkit-scrollbar-track {
26
+ background: none;
27
+ }
28
+
29
+ &::-webkit-scrollbar-thumb {
30
+ background-color: #00000040;
31
+ border-radius: 10px;
32
+ }
27
33
  }
28
34
 
29
35
  .button-yrhMLR {
30
36
  box-sizing: border-box;
31
37
  cursor: pointer;
32
38
  height: 40px;
33
- color: var(--menu-text-color, #444);
39
+ color: var(--kona-editor-text-color, #444);
34
40
  background: none;
35
41
  border: none;
36
42
  align-items: center;
@@ -40,15 +46,15 @@
40
46
  }
41
47
 
42
48
  .button-yrhMLR:hover, .active-Is5D6b {
43
- background-color: var(--menu-background-color-hover, #f9f9f9);
49
+ background-color: var(--kona-editor-alt-background-color, #f9f9f9);
44
50
  }
45
51
 
46
52
  .icon-Xca6dM {
47
53
  opacity: .5;
48
- background: var(--menu-background-color-hover, #f9f9f9);
54
+ background: var(--kona-editor-alt-background-color, #f9f9f9);
49
55
  width: 24px;
50
56
  height: 24px;
51
- color: var(--menu-text-color, #444);
57
+ color: var(--kona-editor-text-color, #444);
52
58
  border-radius: 4px;
53
59
  justify-content: center;
54
60
  align-items: center;
@@ -1,4 +1,4 @@
1
- import { Editor } from 'slate';
1
+ import { Descendant, Editor } from 'slate';
2
2
  import type { RenderElementProps } from 'slate-react';
3
3
  import type { IPlugin } from '../../types';
4
4
  export declare class HeadingsPlugin implements IPlugin {
@@ -9,6 +9,7 @@ export declare class HeadingsPlugin implements IPlugin {
9
9
  type: string;
10
10
  render: (props: RenderElementProps) => import("react/jsx-runtime").JSX.Element;
11
11
  deserialize: (element: HTMLElement, children: any) => import("../..").CustomElement | undefined;
12
+ serialize: (node: Descendant, children: any) => string | undefined;
12
13
  }[];
13
14
  static isHeading1Active(editor: Editor): boolean;
14
15
  static isHeading2Active(editor: Editor): boolean;
@@ -17,6 +17,9 @@ class HeadingsPlugin {
17
17
  if ('H1' === nodeName) return external_slate_hyperscript_jsx('element', {
18
18
  type: HeadingsPlugin.HeadingLevel1
19
19
  }, children);
20
+ },
21
+ serialize: (node, children)=>{
22
+ if (Element.isElement(node) && node.type === HeadingsPlugin.HeadingLevel1) return `<h1>${children}</h1>`;
20
23
  }
21
24
  },
22
25
  {
@@ -30,6 +33,9 @@ class HeadingsPlugin {
30
33
  if ('H2' === nodeName) return external_slate_hyperscript_jsx('element', {
31
34
  type: HeadingsPlugin.HeadingLevel2
32
35
  }, children);
36
+ },
37
+ serialize: (node, children)=>{
38
+ if (Element.isElement(node) && node.type === HeadingsPlugin.HeadingLevel2) return `<h2>${children}</h2>`;
33
39
  }
34
40
  },
35
41
  {
@@ -43,6 +49,9 @@ class HeadingsPlugin {
43
49
  if ('H3' === nodeName) return external_slate_hyperscript_jsx('element', {
44
50
  type: HeadingsPlugin.HeadingLevel3
45
51
  }, children);
52
+ },
53
+ serialize: (node, children)=>{
54
+ if (Element.isElement(node) && node.type === HeadingsPlugin.HeadingLevel3) return `<h3>${children}</h3>`;
46
55
  }
47
56
  }
48
57
  ];
@@ -11,6 +11,7 @@ export declare class LinksPlugin implements IPlugin {
11
11
  isInline: boolean;
12
12
  type: string;
13
13
  render: (props: RenderElementProps) => import("react/jsx-runtime").JSX.Element;
14
+ serialize: (element: any, children: any) => string | undefined;
14
15
  deserialize: (element: HTMLElement, children: any) => import("../..").CustomElement | undefined;
15
16
  }[];
16
17
  static addLink: (editor: Editor, url: string) => void;
@@ -49,6 +49,9 @@ class LinksPlugin {
49
49
  element: props.element,
50
50
  renderHint: this.options.renderHint
51
51
  }),
52
+ serialize: (element, children)=>{
53
+ if (Element.isElement(element) && element.type === LinksPlugin.LINK_TYPE) return `<a href="${element.url}">${children}</a>`;
54
+ },
52
55
  deserialize: (element, children)=>{
53
56
  if ('A' === element.tagName) {
54
57
  const url = element.getAttribute('href') || '';
@@ -17,6 +17,7 @@ export declare class ListsPlugin implements IPlugin {
17
17
  blocks: {
18
18
  type: string;
19
19
  render: (props: RenderElementProps) => import("react/jsx-runtime").JSX.Element;
20
+ serialize: (element: any, children: any) => string | undefined;
20
21
  deserialize: (element: HTMLElement, children: any) => CustomElement | undefined;
21
22
  }[];
22
23
  handlers: {
@@ -78,6 +78,9 @@ class ListsPlugin {
78
78
  ...props.attributes,
79
79
  children: props.children
80
80
  }),
81
+ serialize: (element, children)=>{
82
+ if (element.type === ListsPlugin.BULLETED_LIST_ELEMENT) return `<ul>${children}</ul>`;
83
+ },
81
84
  deserialize: (element, children)=>{
82
85
  const { nodeName } = element;
83
86
  if ('UL' === nodeName) return external_slate_hyperscript_jsx('element', {
@@ -92,6 +95,9 @@ class ListsPlugin {
92
95
  ...props.attributes,
93
96
  children: props.children
94
97
  }),
98
+ serialize: (element, children)=>{
99
+ if (element.type === ListsPlugin.NUMBERED_LIST_ELEMENT) return `<ol>${children}</ol>`;
100
+ },
95
101
  deserialize: (element, children)=>{
96
102
  const { nodeName } = element;
97
103
  if ('OL' === nodeName) return external_slate_hyperscript_jsx('element', {
@@ -106,6 +112,9 @@ class ListsPlugin {
106
112
  ...props.attributes,
107
113
  children: props.children
108
114
  }),
115
+ serialize: (element, children)=>{
116
+ if (element.type === ListsPlugin.BULLETED_LIST_ELEMENT) return `<li>${children}</li>`;
117
+ },
109
118
  deserialize: (element, children)=>{
110
119
  const { nodeName } = element;
111
120
  if ('LI' === nodeName) return external_slate_hyperscript_jsx('element', {
@@ -1,6 +1,6 @@
1
1
  .menu-PPuUUG {
2
- color: var(--text-color, #444);
3
- background-color: var(--background-color, #fff);
2
+ color: var(--kona-editor-text-color, #444);
3
+ background-color: var(--kona-editor-background-color, #fff);
4
4
  flex-direction: row;
5
5
  justify-content: space-between;
6
6
  display: flex;
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, Node, NodeEntry } from 'slate';
2
+ import type { DecoratedRange, Descendant, Editor, NodeEntry } 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> {
@@ -34,6 +34,7 @@ export type Leaf<T extends Editor, TLeaf extends CustomText = CustomText> = {
34
34
  leaf: CustomText & TLeaf;
35
35
  }, editor: T) => ReactElement | null;
36
36
  isVoid?: boolean;
37
+ serialize?: Serialize;
37
38
  deserialize?: Deserialize;
38
39
  };
39
40
  type Hotkey = readonly [string, (event: KeyboardEvent, editor: Editor) => void];
@@ -43,9 +44,9 @@ export type UiParams = {
43
44
  children: ReactNode;
44
45
  };
45
46
  export type EditorRef = {
46
- serialize: (node: CustomElement | CustomElement[] | CustomText | CustomText[]) => string;
47
+ serialize: (node: CustomElement | CustomText) => string;
47
48
  deserialize: (element: HTMLElement) => (Descendant | string)[] | string | Descendant | null;
48
49
  };
49
- export type Serialize = (node: Node, children?: string) => string | undefined;
50
+ export type Serialize = (node: CustomElement | CustomText, children?: string) => string | undefined;
50
51
  export type Deserialize = (element: HTMLElement, children?: (string | Descendant)[]) => CustomElement | CustomText[] | undefined;
51
52
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-kona/editor",
3
- "version": "0.1.2-rc.5",
3
+ "version": "0.1.2-rc.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -3,8 +3,8 @@
3
3
  display: flex;
4
4
  flex-direction: row;
5
5
  justify-content: space-between;
6
- color: var(--text-color, #444);
7
- background-color: var(--background-color, #fff);
6
+ color: var(--kona-editor-text-color, #444);
7
+ background-color: var(--kona-editor-background-color, #fff);
8
8
  }
9
9
 
10
10
  .editor {
@@ -1,7 +0,0 @@
1
- import "./LanguageSelector_module.css";
2
- const LanguageSelector_module = {
3
- root: "root-lOdP_6",
4
- button: "button-GlQ_nf",
5
- customMenu: "customMenu-eXoQR8"
6
- };
7
- export { LanguageSelector_module as default };