-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Move some files to typescript #264
base: master
Are you sure you want to change the base?
Changes from all commits
dc87566
c1196cd
7037fe6
f149036
35e6518
76c1281
d66dcd0
97910f0
700e105
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ import { Plugin } from "prosemirror-state"; | |
export const Placeholder = Extension.create({ | ||
name: "placeholder", | ||
|
||
addOptions: { | ||
emptyEditorClass: "is-editor-empty", | ||
emptyNodeClass: "is-empty", | ||
placeholder: "Write something …", | ||
showOnlyWhenEditable: true, | ||
showOnlyCurrent: true, | ||
addOptions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this converted into a function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has something to do with the internals of tiptap's type inference. It's how they recommend doing it in the typescript compatibility section of their docs and it was causing an error to leave it as-is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, 👌 |
||
return { | ||
emptyEditorClass: "is-editor-empty", | ||
emptyNodeClass: "is-empty", | ||
placeholder: "Write something …", | ||
showOnlyWhenEditable: true, | ||
showOnlyCurrent: true, | ||
} | ||
}, | ||
|
||
addProseMirrorPlugins() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from "react"; | ||
import React, { CSSProperties } from "react"; | ||
import { AnchorStyle } from "../styled/menu"; | ||
import ImagePopover from "./image"; | ||
import { BubbleMenu } from "./bubble-menu/bubble-menu-react"; | ||
|
@@ -40,8 +40,16 @@ function DanteTooltipLink({ enableLinkMode, selected }) { | |
); | ||
} | ||
|
||
interface LinkState { | ||
link_mode: boolean | ||
url?: string | ||
menu_style: { | ||
minWidth?: string, | ||
} | ||
} | ||
|
||
export default function MenuBar({ editor, fixed }) { | ||
const [linkState, setLinkState] = useState({ | ||
const [linkState, setLinkState] = useState<LinkState>({ | ||
link_mode: false, | ||
menu_style: { | ||
minWidth: "200px", | ||
|
@@ -63,7 +71,7 @@ export default function MenuBar({ editor, fixed }) { | |
} | ||
|
||
function displayActiveMenu() { | ||
if (this.state.show) { | ||
if (show) { | ||
return "dante-menu--active"; | ||
} else { | ||
return ""; | ||
|
@@ -117,7 +125,7 @@ export default function MenuBar({ editor, fixed }) { | |
editor.chain().focus().setColor(style).run(); | ||
} | ||
|
||
function fixedStyles() { | ||
function fixedStyles(): CSSProperties { | ||
if (!fixed) return { width: `${11 * 43}px` }; | ||
if (fixed) return { position: `sticky`, top: "0" }; | ||
} | ||
|
@@ -128,7 +136,7 @@ export default function MenuBar({ editor, fixed }) { | |
|
||
return ( | ||
<AnchorStyle | ||
fixed={fixed} | ||
//fixed={fixed} // This wasn't present in the type for AnchorStyle and didn't appear to be referenced anywhere | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets keep this for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be able to add fixed as a prop to AnchorStyle, but I'm still trying to figure out how to work with the types on those styled components |
||
className={`dante-menu ${displayLinkMode()}`} | ||
style={fixedStyles()} | ||
> | ||
|
@@ -171,7 +179,7 @@ export default function MenuBar({ editor, fixed }) { | |
|
||
<DanteTooltipLink | ||
selected={editor.isActive("link")} | ||
editor={editor} | ||
//editor={editor} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep this from now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. I'll add the editor into the tooltip props instead. |
||
enableLinkMode={_enableLinkMode} | ||
/> | ||
<li | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ export const AnchorStyle = styled.div` | |
height: 0; | ||
width: 0; | ||
position: absolute; | ||
left: ${(props) => (props.arrowPosition ? props.arrowPosition : "50%")}; | ||
left: ${(props) => (props['arrowPosition'] ? props['arrowPosition'] : "50%")}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this change needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That property wasn't showing up on the props type signature, but the type was indexable by arbitrary strings. I can try typing the styled div with a <{arrowPosition: string}> generic and see if that works. It would certainly be less hacky. |
||
pointer-events: none; | ||
border: ${(props) => props.theme.dante_menu_caret_size} solid transparent; | ||
margin-left: -${(props) => math(`${props.theme.dante_menu_caret_size} / 2`)}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import '@emotion/react' | ||
|
||
// This is the prescribed method for using custom themes with emotion and typescript | ||
// @see https://emotion.sh/docs/typescript | ||
declare module '@emotion/react' { | ||
export interface Theme { | ||
dante_font_family_serif: string | ||
dante_font_family_sans: string | ||
dante_font_family_mono: string | ||
dante_font_family_base: string | ||
|
||
// Editor | ||
dante_editor_font_size: string | ||
dante_editor_line_height: string | ||
|
||
//dante_font_family_sans_serif: "comic-sans", | ||
dante_visual_debugger: string | ||
dante_text_color: string | ||
dante_inversed_color: string | ||
dante_accent_color: string | ||
dante_control_color: string | ||
dante_popover_color: string | ||
|
||
//dante_font_size_base: '24px', | ||
//line_height_base: '1.428571429', // 20/14 | ||
|
||
tooltip_color: string | ||
tooltip_background_color: string | ||
tooltip_border_color: string | ||
tooltip_color_opacity: string | ||
tooltip_color_opacity_hover: string | ||
tooltip_background_opacity: string | ||
tooltip_border_width: string | ||
tooltip_border_radius: string | ||
|
||
tooltip_caret_size: string | ||
menu_tone: string | ||
|
||
tooltip_button_spacing: string | ||
tooltip_menu_spacing: string | ||
|
||
tooltip_items: number // Fix this and remove it | ||
tooltip_item_delay: number | ||
tooltip_size: string | ||
tooltip_line_height: string | ||
|
||
tooltip_default_transition: string | ||
tooltip_forward_transition: string | ||
tooltip_backward_transition: string | ||
|
||
dante_code_background: string | ||
dante_code_color: string | ||
|
||
// Menu | ||
|
||
//background: #2A2B32; | ||
|
||
dante_menu_height: string | ||
dante_menu_background: string | ||
dante_menu_color: string | ||
dante_menu_border_radius: string | ||
dante_menu_box_shadow: string | ||
dante_menu_icon_size: string | ||
dante_menu_icon_color: string | ||
dante_menu_icon_accent: string | ||
dante_menu_divider_color: string | ||
dante_menu_border_width: string | ||
dante_menu_border_color: string | ||
dante_menu_caret_size: string | ||
dante_bg_color: string | ||
|
||
// highlight theme | ||
// highlight theme | ||
// find other themes at https://highlightjs.org/static/demo/ | ||
// https://github.com/highlightjs/highlight.js/tree/main/src/styles | ||
hljs_color: string | ||
hljs_background: string | ||
hljs_emphasis_color: string | ||
hljs_literal_color: string | ||
hljs_selector_class_color: string | ||
hljs_name_color: string | ||
hljs_title_color: string | ||
hljs_variable_color: string | ||
hljs_class_title_color: string | ||
hljs_link_color: string | ||
hljs_deletion_color: string | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is needed
this.editor
? is this working?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are actually two ways to do this because it looks like tiptap both passes the object in and binds the function to it.
So this:
Can become:
Or this:
But if you do the second one, it seems like it no longer recognizes the type of the editor argument for some reason.
Given that these functions are being bound to the object within tiptap and their this argument is very well typed, I assume this works. It also matches their documentation. I did some minimal testing to make sure I didn't massively break anything, but I'm sure it needs more attention.