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

Replace slate-plugins with its successor, plate #841

Merged
merged 20 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
73cd1ff
Remove eslint deps, upgrade to the last 1.x apollo gql codegen package.
Lanny Mar 18, 2023
914b8b4
Well we can load the editor I guess?
Lanny Mar 19, 2023
da6bb6f
Got tables rendering, toolbar stuff for tables is still borked though.
Lanny Apr 5, 2023
9695274
Flagrant abuse of the typesystem.
Lanny Apr 11, 2023
4bed84a
Well, we're installable with this package-lock config, but not
Lanny Apr 11, 2023
ecba6eb
Merge branch 'master' of github.com:Journaly/journaly into plate-woo
Lanny Apr 11, 2023
cbcb91e
Maybe bumping the node version in CI will get us peer deps installed?
Lanny Apr 11, 2023
1476e3d
Update package-lock.json
robin-macpherson Apr 19, 2023
5fe0488
Fix issue with translations no loading after next upgrade
Lanny Apr 26, 2023
280bbc9
Fix memorization onKeyDown memoization hanging onto a stale value and…
Lanny Apr 26, 2023
096b7b0
Fix issue where state of editor wouldn't be run through `setValue`.
Lanny Apr 26, 2023
43f2a05
Fix serialization of table elements, honor plate's resizable table at…
Lanny Apr 26, 2023
e851d0a
Merge branch 'plate-woo' of github.com:Journaly/journaly into plate-woo
Lanny May 2, 2023
347b144
Merge branch 'master' of github.com:Journaly/journaly into plate-woo
Lanny May 2, 2023
1b5807e
Bump prisma and prisma/client deps to 3.15.2
Lanny May 2, 2023
cb7d6f2
Upgrade j-db-client version in web to use new prisma version.
Lanny May 2, 2023
abe98e3
Fix un-auth'd nav not getting appropriate styling.
Lanny May 2, 2023
4d6a008
Fix style regression on feature tables.
Lanny May 2, 2023
98b9cd8
Update serverless translation resolution process.
Lanny May 3, 2023
b89b0bc
Try a different translation resolution strategy during SSR. Just thro…
Lanny May 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
steps:
- checkout
- node/install:
node-version: 14.17.4
npm-version: 6.14.14
node-version: 16.17.0
npm-version: 8.15.0
- restore_cache:
keys:
- node-deps-v3-{{ checksum "packages/web/package-lock.json" }}
Expand Down
112 changes: 94 additions & 18 deletions packages/j-db-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/j-db-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@journaly/j-db-client",
"version": "13.19.0",
"version": "13.19.1",
"description": "Journaly's internal database client.",
"main": "dist/index",
"scripts": {
Expand All @@ -24,10 +24,10 @@
"author": "Journaly",
"license": "ISC",
"dependencies": {
"@prisma/client": "3.5.0"
"@prisma/client": "^3.15.2"
},
"devDependencies": {
"prisma": "3.5.0",
"prisma": "^3.15.2",
"typescript": "4.2.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ const Feature = ({ name, plan, status }: FeatureProps) => {
<CheckmarkCircleIcon color={color} />
<span className={status === 'coming soon' ? 'coming-soon' : ''}>{name}</span>
<style jsx>{`
display: flex;
align-items: center;
font-weight: 600;
li {
display: flex;
align-items: center;
font-weight: 600;
}

span {
margin-left: 10px;
Expand Down
112 changes: 64 additions & 48 deletions packages/web/components/JournalyEditor/JournalyEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import React, { useEffect, useMemo, useCallback } from 'react'
import { createEditor, Editor, Descendant } from 'slate'
import { Slate, withReact } from 'slate-react'
import { withHistory } from 'slate-history'
import { pipe, TablePlugin, EditablePlugins } from '@udecode/slate-plugins'
import { Editor } from 'slate'
import {
createPlateEditor,
Plate,
PlateProvider,
PlateEditor,
TElement,
createPlugins,
createTablePlugin,
createPlateUI,
} from '@udecode/plate'
import isHotkey from 'is-hotkey'

import theme from '@/theme'
import PostBodyStyles from '@/components/PostBodyStyles'
import Toolbar from './Toolbar'
import RenderElement from './RenderElement'
import RenderLeaf from './RenderLeaf'
import { withLinks, withImages, toggleMark, options, MarkType } from './helpers'
import { withLinks, withImages, toggleMark, MarkType } from './helpers'
import usePlayPolyphonicSound from '@/hooks/usePlayPolyphonicSound'
import useAutosavedState from '@/hooks/useAutosavedState'

Expand Down Expand Up @@ -46,14 +53,12 @@ const KEY_BLACK_LIST = new Set([
])

type JournalyEditorProps = {
value: Descendant[]
setValue: (value: Descendant[]) => void
value: TElement[]
setValue: (value: TElement[]) => void
slateRef: React.RefObject<Editor>
allowInlineImages: boolean
disabled?: boolean
}
const plugins = [TablePlugin(options)]

const JournalyEditor = ({
value,
setValue,
Expand All @@ -63,16 +68,25 @@ const JournalyEditor = ({
}: JournalyEditorProps) => {
const renderElement = useCallback((props) => <RenderElement {...props} />, [])
const renderLeaf = useCallback((props) => <RenderLeaf {...props} />, [])
const editor = useMemo(() => {
const withPlugins: ((ed: Editor) => Editor)[] = [withHistory, withLinks]

if (allowInlineImages) {
withPlugins.push(withImages)
}
const plugins = useMemo(() => {
return createPlugins(
[ createTablePlugin({}) ],
{
components: createPlateUI()
}
)
}, [])

const editor = useMemo(() => {
const editor = withLinks(createPlateEditor({
plugins: plugins as any
}) as Editor)

return pipe(withReact(createEditor()), ...withPlugins)
return allowInlineImages ? withImages(editor) : editor
}, [])


const [shouldPlayTypewriterSounds, setShouldPlayTypewriterSounds] = useAutosavedState(false, {
key: 'shouldPlayTypewriterSounds',
})
Expand All @@ -83,16 +97,24 @@ const JournalyEditor = ({
1,
)

const handlePlayTypewriterSound = (e: React.KeyboardEvent) => {
const onKeyDown = useCallback((event: React.KeyboardEvent) => {
if (shouldPlayTypewriterSounds) {
if (KEY_BLACK_LIST.has(e.key)) return
else if (e.key === 'Enter') {
if (KEY_BLACK_LIST.has(event.key)) return
else if (event.key === 'Enter') {
playTypewriterReturnSound()
} else {
playTypewriterSound()
}
}
}

Object.entries(HOTKEYS).forEach(([hotkey, mark]) => {
// Convert React keyboard event to native keyboard event
if (isHotkey(hotkey, event as unknown as KeyboardEvent)) {
event.preventDefault()
toggleMark(editor, mark)
}
})
}, [editor, shouldPlayTypewriterSounds, playTypewriterSound, playTypewriterReturnSound])

useEffect(() => {
;(slateRef as React.MutableRefObject<Editor>).current = editor
Expand All @@ -105,36 +127,30 @@ const JournalyEditor = ({
return (
<div className="editor-wrapper">
<div className="editor-container">
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}>
<Toolbar
allowInlineImages={allowInlineImages}
shouldPlayTypewriterSounds={shouldPlayTypewriterSounds}
onToggleShouldPlayTypewriterSounds={() =>
setShouldPlayTypewriterSounds(!shouldPlayTypewriterSounds)
}
/>
<EditablePlugins
plugins={plugins}
renderElement={[renderElement]}
renderLeaf={[renderLeaf]}
readOnly={disabled}
spellCheck
onKeyDown={[
(event: React.KeyboardEvent) => {
handlePlayTypewriterSound(event)
Object.entries(HOTKEYS).forEach(([hotkey, mark]) => {
// Convert React keyboard event to native keyboard event
if (isHotkey(hotkey, event as unknown as KeyboardEvent)) {
event.preventDefault()
toggleMark(editor, mark)
}
})
},
]}
onKeyDownDeps={[shouldPlayTypewriterSounds]}
data-testid="post-body"
<PlateProvider
editor={editor as PlateEditor}
onChange={(v) => setValue(v)}
value={value}
>
<Plate
editableProps={{
spellCheck: true,
readOnly: disabled,
onKeyDown: onKeyDown,
renderElement,
renderLeaf,
}}
firstChildren={(
<Toolbar
allowInlineImages={allowInlineImages}
shouldPlayTypewriterSounds={shouldPlayTypewriterSounds}
onToggleShouldPlayTypewriterSounds={() =>
setShouldPlayTypewriterSounds(!shouldPlayTypewriterSounds)
}
/>
)}
/>
</Slate>
</PlateProvider>
</div>
<PostBodyStyles parentClassName="editor-container" />
<style jsx>{`
Expand Down
10 changes: 1 addition & 9 deletions packages/web/components/JournalyEditor/RenderElement.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react'
import { renderElementTable } from '@udecode/slate-plugins'
import { useSelected, RenderElementProps } from 'slate-react'

import { isImageNode, isLinkNode, isTableFamilyNode } from '@/utils/slate'
import { isImageNode, isLinkNode } from '@/utils/slate'

const ImageElement = ({ attributes, element, children }: RenderElementProps) => {
const selected = useSelected()
Expand All @@ -25,13 +24,6 @@ const ImageElement = ({ attributes, element, children }: RenderElementProps) =>
const RenderElement = (props: RenderElementProps) => {
const { attributes, children, element } = props

if (isTableFamilyNode(element)) {
const tableElement = renderElementTable()({ attributes, children, element })
if (tableElement) {
return tableElement
}
}

switch (element.type) {
case 'block-quote':
return <blockquote {...attributes}>{children}</blockquote>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ const BaseToolbarButton = ({ onClick, active, children }: ButtonProps) => {

<style jsx>{`
.toolbar-button {
height: 100%;
width: 24px;
height: 24px;
padding: 1px;
box-sizing: content-box;
border: none;
border-radius: 5px;
background-color: ${theme.colors.gray800};
Expand Down
Loading