Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

feat: emoji #514

Closed
wants to merge 21 commits into from
Closed

feat: emoji #514

wants to merge 21 commits into from

Conversation

JiangWeixian
Copy link
Contributor

@JiangWeixian JiangWeixian commented Aug 4, 2021

@JiangWeixian JiangWeixian changed the title chore: wip feat: emoji Aug 4, 2021
@tommoor
Copy link
Member

tommoor commented Aug 12, 2021

Anything I can do to help here? Thanks~

@JiangWeixian
Copy link
Contributor Author

Anything I can do to help here? Thanks~

😂 sorry, I a little bit busy recently, this pr almost done, i will check some details as quick as possible

@JiangWeixian JiangWeixian marked this pull request as ready for review August 14, 2021 02:49
@tommoor
Copy link
Member

tommoor commented Aug 27, 2021

I found this replacement issue when testing:

Kapture.2021-08-26.at.19.34.12.mp4

package.json Outdated
@@ -9,6 +9,7 @@
"scripts": {
"test": "jest",
"lint": "tsc --noEmit && eslint '*/**/*.{js,ts,tsx}' --quiet",
"lint:fox": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove as lint --fix works

Comment on lines 160 to 162
insertItem = item => {
this.insertBlock(item);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method isn't needed, insertEmoji?

>
<List>
{items.map((item, index) => {
if (item.name === "separator") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that you've made it look like the block insert menu, a lot of this is copied straight over which means it's begging for an abstraction so that the code can be reused between popover menus such as @mentions in the future too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, i will make an abstraction to reused code between emoji and block

onClick={disabled ? undefined : onClick}
ref={ref}
>
&nbsp;&nbsp;{title}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the title needs to include the string eg "grinning" next to the emoji, kind of like GitHub – it will help it to look a little nicer too. The emoji might want bumping up in size a touch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now, it look like this image

src/index.tsx Outdated
@@ -314,6 +318,10 @@ class RichMarkdownEditor extends React.PureComponent<Props, State> {
dictionary,
onShowToast: this.props.onShowToast,
}),
new Emoji({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need add emoji to disableExtensions in props.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, i will~

Comment on lines 96 to 101
console.log(
match &&
state.selection.$from.parent.type.name === "paragraph" &&
!isInTable(state),
match
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another debug statement left behind

@@ -0,0 +1,92 @@
import { InputRule } from "prosemirror-inputrules";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BlockMenuTrigger and EmojiTrigger has lot of copy/paste code, but i not sure to create a common plugin or common trigger extension

selectedIndex: number;
};

class BlockMenu extends React.Component<Props, State> {
Copy link
Contributor Author

@JiangWeixian JiangWeixian Aug 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this maybe a big change, EmojiMenu BlockMenu wii reuse CommonBlockMenu

onClick: () => void;
}
) => React.ReactNode;
filterable?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter items by search

}
) => React.ReactNode;
filterable?: boolean;
items: T[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render menu item list

onShowToast?: (message: string, id: string) => void;
onLinkToolbarOpen?: () => void;
onClose: () => void;
onClearSearch: () => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emojimenu and blockmenu has different clearsearch behavior


const ref = this.menuRef.current;
const offsetHeight = ref ? ref.offsetHeight : 0;
const node = findDomRefAtPos(selection.from, domAtPos);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emoji should allow insert inside para

Copy link
Member

@tommoor tommoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great – getting so close!

package.json Outdated
@@ -26,8 +26,12 @@
},
"dependencies": {
"copy-to-clipboard": "^3.0.8",
"fuzzy-search": "^3.2.1",
"gemoji": "^7.0.0",
"install": "^0.13.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"install": "^0.13.0",

Not needed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my fault

import Extension from "../lib/Extension";
import { run } from "./BlockMenuTrigger";

const OPEN_REGEX = /:([0-9a-zA-Z_]+)?$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to account for ":+" and ":-" starts in the regex here for thumbs up/down

}) => {
return (
<Title>
{emoji}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap the emoji to give it 16px size but keep the text size the same as the other menu?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ~

);
}

export default withTheme(EmojiMenuItem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default withTheme(EmojiMenuItem);
export default EmojiMenuItem;

Shouldn't need withTheme here

return {
...item,
name: "emoji",
title: name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use "description" from gemoji here so that the text doesn't contain "_"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not.. gemoji description longer than name

{
  "emoji": "😍",
  "names": ["heart_eyes"],
  "tags": ["love", "crush"],
  "description": "smiling face with heart-eyes",
  "category": "Smileys & Emotion"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, maybe we can humanize the name then? (Capitalize, remove underscores)

Feels very strange to show underscores in user facing UI. I know GitHub does it, but GitHub is weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you are right, i will try it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@JiangWeixian JiangWeixian requested a review from tommoor September 4, 2021 13:02
@tommoor
Copy link
Member

tommoor commented Sep 11, 2021

Hey hey, just testing out the branch and when I go to insert an emoji it always places the text undefined instead…

@JiangWeixian
Copy link
Contributor Author

JiangWeixian commented Sep 11, 2021

Hey hey, just testing out the branch and when I go to insert an emoji it always places the text undefined instead…

emoji.mp4

@tommoor
Copy link
Member

tommoor commented Sep 25, 2021

I had to make a couple of local fixes, but squashed and merged here – bbaf157

Thank you!

@tommoor tommoor closed this Sep 25, 2021
@tommoor
Copy link
Member

tommoor commented Sep 26, 2021

Unfortunately the published version with this merged doesn't seem to work because of gemoji – I haven't yet figured out how to work around it.

[api] node:internal/modules/cjs/loader:1126
[api]       throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
[api]       ^
[api]
[api] Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/tom/Projects/outline/node_modules/gemoji/index.js
[api] require() of ES modules is not supported.
[api] require() of /Users/tom/Projects/outline/node_modules/gemoji/index.js from /Users/tom/Projects/outline/node_modules/rich-markdown-editor/dist/components/EmojiMenu.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
[api] Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/tom/Projects/outline/node_modules/gemoji/package.json.
[api]

@JiangWeixian
Copy link
Contributor Author

😓 it looks require esm not supported, i will try changed tsconfig.json: module https://www.typescriptlang.org/tsconfig#es6

@JiangWeixian
Copy link
Contributor Author

its wired, i try it on my webpack project, it works fine

@tommoor
Copy link
Member

tommoor commented Sep 26, 2021

What did you change? Changing module: es6 here prevents the lib from building

@JiangWeixian
Copy link
Contributor Author

What did you change? Changing module: es6 here prevents the lib from building

i did not change yet, just download v11.18.0, there is mini app https://github.com/JiangWeixian/esm-app

@tommoor
Copy link
Member

tommoor commented Sep 26, 2021

Ah, okay. It no longer works in outline, so it likely won't work in many other projects.

@JiangWeixian
Copy link
Contributor Author

Ah, okay. It no longer works in outline, so it likely won't work in many other projects.

I try it on react-scripts, it works fine. Is there any mini repo contain this error 🙈.

@tommoor
Copy link
Member

tommoor commented Sep 26, 2021

I'm not sure, Outline is not a complicated build system – https://github.com/outline/outline/blob/main/server/.babelrc

I pretty much lost my whole evening to this, so signing off for now.

@JiangWeixian
Copy link
Contributor Author

(Maybe) Solution 1

convert outline server to native esm

Solution 2

I lock gemoji version to cjs version #555

@guatedude2
Copy link

guatedude2 commented Sep 27, 2021

Any idea why I'm getting this error when I run tests within my project?

 FAIL  apps/registration/src/legacy/components/WelcomeText/WelcomeText.test.tsx
  ● Test suite failed to run

    Cannot find module 'gemoji/name-to-emoji' from 'node_modules/rich-markdown-editor/dist/nodes/Emoji.js'

    Require stack:
      node_modules/rich-markdown-editor/dist/nodes/Emoji.js
      node_modules/rich-markdown-editor/dist/index.js
      packages/ui/src/components/content/RichContentEditor/BaseEditor.tsx
      packages/ui/src/components/content/Markdown/Markdown.tsx
      packages/ui/src/components/content/Markdown/index.ts
      packages/ui/src/components/index.ts
      apps/registration/src/legacy/components/WelcomeText/WelcomeText.tsx
      apps/registration/src/legacy/components/WelcomeText/index.ts
      apps/registration/src/legacy/components/WelcomeText/WelcomeText.test.tsx

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
      at Object.<anonymous> (node_modules/rich-markdown-editor/src/nodes/Emoji.tsx:3:1)

Rich Markdown Editor version: "rich-markdown-editor": "^11.18.2"

I tried resetting the lock file and event installing gemoji without success.

@JiangWeixian
Copy link
Contributor Author

JiangWeixian commented Sep 27, 2021

@tommoor @guatedude2 took look at this pr #557, fix this issue....

@guatedude2
Copy link

@tommoor @guatedude2 took look at this pr #557, fix this issue....

Thanks @JiangWeixian I'll keep an eye out on the PR!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants