@use-kona/editor 0.1.8-rc.2 → 0.1.8-rc.4

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.
@@ -9,6 +9,7 @@ type Options = {
9
9
  }) => ReactNode;
10
10
  renderEmoji: (emoji: string) => ReactNode;
11
11
  ignoreNodes?: string[];
12
+ portalTarget?: Element | null;
12
13
  };
13
14
  export declare class EmojiPlugin implements IPlugin {
14
15
  options: Options;
@@ -49,6 +49,7 @@ class EmojiPlugin {
49
49
  if (!isOpen) return null;
50
50
  return /*#__PURE__*/ jsx(Menu, {
51
51
  isOpen: isOpen,
52
+ portalTarget: this.options.portalTarget,
52
53
  children: this.options.renderMenu({
53
54
  insertEmoji: (emoji, query, editor)=>{
54
55
  this.$store.setKey('isOpen', false);
@@ -2,6 +2,7 @@ import { type ReactNode } from 'react';
2
2
  type Props = {
3
3
  isOpen: boolean;
4
4
  children: ReactNode;
5
+ portalTarget?: Element | null;
5
6
  };
6
7
  export declare const Menu: (props: Props) => import("react").ReactPortal;
7
8
  export {};
@@ -4,7 +4,7 @@ import { createPortal } from "react-dom";
4
4
  import { useFocused, useSlateSelection } from "slate-react";
5
5
  import styles_module from "./styles.module.js";
6
6
  const Menu = (props)=>{
7
- const { isOpen, children } = props;
7
+ const { isOpen, children, portalTarget } = props;
8
8
  const isFocused = useFocused();
9
9
  const selection = useSlateSelection();
10
10
  const ref = useRef(null);
@@ -48,6 +48,6 @@ const Menu = (props)=>{
48
48
  style: style,
49
49
  className: styles_module.root,
50
50
  children: children
51
- }), document.body);
51
+ }), portalTarget || document.body);
52
52
  };
53
53
  export { Menu };
package/dist/utils.js CHANGED
@@ -2,7 +2,7 @@ import { Text } from "slate";
2
2
  const isEmpty = (children)=>{
3
3
  const [first] = children || [];
4
4
  if (Text.isText(first)) return '' === first.text.trim();
5
- if (children && children.length <= 1 && Text.isText(first?.children?.[0])) return first.children.every((child)=>'' === child.text.trim());
5
+ if (children && children.length <= 1 && Text.isText(first?.children?.[0])) return first.children.every((child)=>child.text?.trim() === '');
6
6
  return false;
7
7
  };
8
8
  export { isEmpty };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-kona/editor",
3
- "version": "0.1.8-rc.2",
3
+ "version": "0.1.8-rc.4",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -15,6 +15,7 @@ type Options = {
15
15
  }) => ReactNode;
16
16
  renderEmoji: (emoji: string) => ReactNode;
17
17
  ignoreNodes?: string[];
18
+ portalTarget?: Element | null;
18
19
  };
19
20
 
20
21
  export class EmojiPlugin implements IPlugin {
@@ -80,7 +81,7 @@ export class EmojiPlugin implements IPlugin {
80
81
  }
81
82
 
82
83
  return (
83
- <Menu isOpen={isOpen}>
84
+ <Menu isOpen={isOpen} portalTarget={this.options.portalTarget}>
84
85
  {this.options.renderMenu({
85
86
  insertEmoji: (emoji, query, editor) => {
86
87
  this.$store.setKey('isOpen', false);
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  type CSSProperties,
3
3
  type ReactNode,
4
- useLayoutEffect, useRef,
4
+ useLayoutEffect,
5
+ useRef,
5
6
  useState,
6
7
  } from 'react';
7
8
  import { createPortal } from 'react-dom';
@@ -11,10 +12,11 @@ import styles from './styles.module.css';
11
12
  type Props = {
12
13
  isOpen: boolean;
13
14
  children: ReactNode;
15
+ portalTarget?: Element | null;
14
16
  };
15
17
 
16
18
  export const Menu = (props: Props) => {
17
- const { isOpen, children } = props;
19
+ const { isOpen, children, portalTarget } = props;
18
20
 
19
21
  const isFocused = useFocused();
20
22
  const selection = useSlateSelection();
@@ -67,11 +69,10 @@ export const Menu = (props: Props) => {
67
69
  }
68
70
  }, []);
69
71
 
70
-
71
72
  return createPortal(
72
73
  <div ref={ref} style={style} className={styles.root}>
73
74
  {children}
74
75
  </div>,
75
- document.body,
76
+ portalTarget || document.body,
76
77
  );
77
78
  };
package/src/utils.ts CHANGED
@@ -8,7 +8,7 @@ export const isEmpty = (children: Descendant[]) => {
8
8
  }
9
9
 
10
10
  if (children && children.length <= 1 && Text.isText(first?.children?.[0])) {
11
- return first.children.every((child) => child.text.trim() === '');
11
+ return first.children.every((child) => child.text?.trim() === '');
12
12
  }
13
13
 
14
14
  return false;