Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marcos/testing #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hackernoon/rich-markdown-editor",
"description": "A rich text editor with Markdown shortcuts",
"version": "0.0.18",
"version": "0.0.19",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"license": "BSD-3-Clause",
Expand All @@ -25,6 +25,7 @@
},
"dependencies": {
"@hackernoon/uppload": "^3.2.3",
"@storybook/addon-postcss": "^2.0.0",
"copy-to-clipboard": "^3.0.8",
"fuzzy-search": "^3.2.1",
"gemoji": "6.x",
Expand Down Expand Up @@ -101,8 +102,8 @@
"eslint-plugin-react-hooks": "^4.0.8",
"jest": "^26.6.3",
"prettier": "^1.19.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"source-map-loader": "^0.2.4",
"styled-components": "^5.2.1",
"ts-loader": "^6.2.1",
Expand Down
4 changes: 3 additions & 1 deletion src/components/LinkToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Props = {
dictionary: typeof baseDictionary;
onCreateLink?: (title: string) => Promise<string>;
onSearchLink?: (term: string) => Promise<SearchResult[]>;
handleLinkSelected?: (href: string, title: string) => void
onClickLink: (href: string, event: MouseEvent) => void;
onShowToast?: (msg: string, code: string) => void;
onClose: () => void;
Expand Down Expand Up @@ -103,10 +104,11 @@ export default class LinkToolbar extends React.Component<Props> {
from: number;
to: number;
}) => {
const { view, onClose } = this.props;
const { view, onClose, handleLinkSelected } = this.props;

onClose();
this.props.view.focus();
if(handleLinkSelected) handleLinkSelected(href, title);

const { dispatch, state } = view;
const { from, to } = state.selection;
Expand Down
14 changes: 13 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export type Props = {
readOnlyWriteCheckboxes?: boolean;
dictionary?: Partial<typeof baseDictionary>;
dark?: boolean;
enablePeopleTag?: boolean; //enable people tagging system, based on onSearchLink
dir?: string;
theme?: typeof theme;
template?: boolean;
Expand All @@ -146,6 +147,7 @@ export type Props = {
onImageUploadStop?: () => void;
onCreateLink?: (title: string) => Promise<string>;
onSearchLink?: (term: string) => Promise<SearchResult[]>;
handleLinkSelected?: (href: string, title: string) => void; //check which link was selected from search list
onClickLink: (href: string, event: MouseEvent) => void;
onHoverLink?: (event: MouseEvent) => boolean;
onClickHashtag?: (tag: string, event: MouseEvent) => void;
Expand Down Expand Up @@ -750,6 +752,15 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {
}
);

handleKeyDown = (e:React.KeyboardEvent<HTMLDivElement>) => {
if(this.props.onKeyDown){
this?.props?.onKeyDown(e);
}
if(this.props.enablePeopleTag && this.props.onSearchLink && e.key === "@"){
this.handleOpenLinkMenu();
}
}

render() {
const {
dir,
Expand All @@ -765,7 +776,7 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {

return (
<Flex
onKeyDown={onKeyDown}
onKeyDown={this.handleKeyDown}
style={style}
className={className}
align="flex-start"
Expand Down Expand Up @@ -803,6 +814,7 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {
isActive={this.state.linkMenuOpen}
onCreateLink={this.props.onCreateLink}
onSearchLink={this.props.onSearchLink}
handleLinkSelected={this.props.handleLinkSelected}
onClickLink={this.props.onClickLink}
onShowToast={this.props.onShowToast}
onClose={this.handleCloseLinkMenu}
Expand Down
13 changes: 9 additions & 4 deletions src/lib/ComponentView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from "react";
import ReactDOM from "react-dom";
import { createRoot } from 'react-dom/client';

import { ThemeProvider } from "styled-components";
import { EditorView, Decoration } from "prosemirror-view";
import Extension from "../lib/Extension";
Expand Down Expand Up @@ -57,10 +59,13 @@ export default class ComponentView {
getPos: this.getPos,
});

ReactDOM.render(
<ThemeProvider theme={theme}>{children}</ThemeProvider>,
this.dom
);
const root = createRoot(this.dom);
root.render(<ThemeProvider theme={theme}>{children}</ThemeProvider>)

// ReactDOM.render(
// <ThemeProvider theme={theme}>{children}</ThemeProvider>,
// this.dom
// );
}

update(node) {
Expand Down
6 changes: 5 additions & 1 deletion src/nodes/Notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import toggleWrap from "../commands/toggleWrap";
import { WarningIcon, InfoIcon, StarredIcon } from "outline-icons";
import * as React from "react";
import ReactDOM from "react-dom";
import { createRoot } from 'react-dom/client';

import Node from "./Node";
import noticesRule from "../rules/notices";

Expand Down Expand Up @@ -72,7 +74,9 @@ export default class Notice extends Node {

const icon = document.createElement("div");
icon.className = "icon";
ReactDOM.render(component, icon);
const root = createRoot(component);
root.render(icon)
// ReactDOM.render(component, icon);

return [
"div",
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/BlockMenuTrigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InputRule } from "prosemirror-inputrules";
import ReactDOM from "react-dom";
import { createRoot } from 'react-dom/client';

import * as React from "react";
import { Plugin } from "prosemirror-state";
import { isInTable } from "prosemirror-tables";
Expand Down Expand Up @@ -46,7 +48,9 @@ export default class BlockMenuTrigger extends Extension {
const button = document.createElement("button");
button.className = "block-menu-trigger";
button.type = "button";
ReactDOM.render(<PlusIcon color="currentColor" />, button);
const root = createRoot(button)
// ReactDOM.render(<PlusIcon color="currentColor" />, button);
root.render(<PlusIcon color="currentColor" />);

return [
new Plugin({
Expand Down
2 changes: 0 additions & 2 deletions src/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ export default function Example(props) {
});
}}
onSearchLink={async term => {
console.log("Searched link: ", term);

// Delay to simulate time taken for remote API request to complete
return new Promise(resolve => {
setTimeout(() => {
Expand Down