8000 linting errors in the markdown editor package by Cronus1007 · Pull Request #287 · accordproject/web-components · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
8000

linting errors in the markdown editor package #287

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Popup} from 'semantic-ui-react';
import {useEditor} from 'slate-react';
import {BUTTON_COLORS, POPUP_STYLE} from '../utilities/constants';
import { Popup } from 'semantic-ui-react';
import { useEditor } from 'slate-react';
import { BUTTON_COLORS, POPUP_STYLE } from '../utilities/constants';
import Button from '../components/Button';

const HyperlinkButton = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,4 @@ HyperlinkModal.propTypes = {
showLinkModal: PropTypes.bool
};

export default HyperlinkModal;
export default HyperlinkModal;
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ const ToolbarMenu = React.forwardRef(
ToolbarMenu.displayName = 'ToolbarMenu';

export default ToolbarMenu;

23 changes: 10 additions & 13 deletions packages/ui-markdown-editor/src/FormattingToolbar/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import { ReactEditor, useEditor } from 'slate-react';
import { Transforms } from 'slate';

import { InsertImageButton } from '../plugins/withImages';
import ToolbarMenu from './ToolbarMenu';
Expand Down Expand Up @@ -59,28 +58,27 @@ const FormattingToolbar = ({
rect.top + rect.height + window.pageYOffset + CARET_TOP_OFFSET
}px`;
const hyperlinkCaret = el.children[0];
let calPos = rect.left - el.offsetWidth / 2 ;

let calPos = rect.left - el.offsetWidth / 2;

// When the modal goes off page from left side
if (calPos < 0) {
// start from 10px
// start from 10px
calPos = 10;
hyperlinkCaret.style.left = `${rect.left - 10}px`;
}

// calculate the endpoint of the modal
const rightEndPos = calPos + el.offsetWidth,
containerWidth = el.parentElement.offsetWidth;
const rightEndPos = calPos + el.offsetWidth;
const containerWidth = el.parentElement.offsetWidth;

// When the modal goes off the page from right side
if (rightEndPos > containerWidth) {
let diff = rightEndPos-containerWidth;
let diff = rightEndPos - containerWidth;
// extra space of 10px on right side to look clean
diff+=10;
calPos=calPos-diff;
let shift=diff-5;
hyperlinkCaret.style.left= `calc(50% + ${shift}px)`;
diff += 10;
calPos -= diff;
const shift = diff - 5;
hyperlinkCaret.style.left = `calc(50% + ${shift}px)`;
}

el.style.left = `${calPos}px`;
Expand Down Expand Up @@ -118,5 +116,4 @@ FormattingToolbar.propTypes = {
currentStyle: PropTypes.string,
};


export default FormattingToolbar;
export default FormattingToolbar;
4 changes: 2 additions & 2 deletions packages/ui-markdown-editor/src/components/icons/bold.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const icon = fillColor => (
</text>
</g>
</g>
);
);

const bold = {
type: 'bold',
Expand All @@ -31,4 +31,4 @@ const bold = {
icon,
};

export default bold;
export default bold;
20 changes: 10 additions & 10 deletions packages/ui-markdown-editor/src/components/icons/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const icon = fillColor => (
);

const code = {
type: 'code',
label: `Code (${MOD()}+Shift+9)`,
height: '25px',
width: '25px',
padding: '6px 2px 4px',
viewBox: '0 0 20 12',
icon,
};
export default code;
type: 'code',
label: `Code (${MOD()}+Shift+9)`,
height: '25px',
width: '25px',
padding: '6px 2px 4px',
viewBox: '0 0 20 12',
icon,
};

export default code;
2 changes: 1 addition & 1 deletion packages/ui-markdown-editor/src/components/icons/delete.js

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

2 changes: 1 addition & 1 deletion packages/ui-markdown-editor/src/components/icons/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { MOD } from '../../utilities/tooltipHelpers'
import { MOD } from '../../utilities/tooltipHelpers';

const icon = () => (
<g id="Page-1" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
Expand Down
20 changes: 10 additions & 10 deletions packages/ui-markdown-editor/src/components/icons/italic.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const icon = fillColor => (
);

const italic = {
type: 'italic',
label: `Italic (${MOD()}+I)`,
height: '25px',
width: '25px',
padding: '5px 7px',
viewBox: '0 0 10 13',
icon,
};
export default italic;
type: 'italic',
label: `Italic (${MOD()}+I)`,
height: '25px',
width: '25px',
padding: '5px 7px',
viewBox: '0 0 10 13',
icon,
};

export default italic;
2 changes: 1 addition & 1 deletion packages/ui-markdown-editor/src/components/icons/open.js

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

8 changes: 4 additions & 4 deletions packages/ui-markdown-editor/src/components/icons/tbreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { BUTTON_COLORS } from '../../utilities/constants';

const icon = () => (
<path className="st0" fill={BUTTON_COLORS.SYMBOL_INACTIVE} d="M14.8,6.5H6.7C6.4,6.5,6.2,6.2,6.2,6V1.9c0-0.3-0.3-0.5-0.5-0.5H4.8c-0.3,0-0.5,0.3-0.5,0.5v5.9
c0,0.3,0.3,0.5,0.5,0.5h11.9c0.3,0,0.5-0.3,0.5-0.5V1.9c0-0.3-0.3-0.5-0.5-0.5h-0.9c-0.3,0-0.5,0.3-0.5,0.5V6
C15.3,6.2,15.2,6.5,14.8,6.5 M6.7,12.9h8.2c0.3,0,0.5,0.3,0.5,0.5v4.1c0,0.3,0.3,0.5,0.5,0.5h0.9c0.3,0,0.5-0.3,0.5-0.5v-5.9
c0-0.3-0.3-0.5-0.5-0.5H4.8c-0.3,0-0.5,0.3-0.5,0.5v5.9c0,0.3,0.3,0.5,0.5,0.5h0.8c0.3,0,0.5-0.3,0.5-0.5v-4.1
C6.2,13.1,6.4,12.9,6.7,12.9 M0.6,7.4v4.5c0,0.4,0.5,0.7,0.8,0.3L3.7,10c0.2-0.2,0.2-0.5,0-0.7L1.5,7C1.1,6.7,0.6,7,0.6,7.4"/>
c0,0.3,0.3,0.5,0.5,0.5h11.9c0.3,0,0.5-0.3,0.5-0.5V1.9c0-0.3-0.3-0.5-0.5-0.5h-0.9c-0.3,0-0.5,0.3-0.5,0.5V6
C15.3,6.2,15.2,6.5,14.8,6.5 M6.7,12.9h8.2c0.3,0,0.5,0.3,0.5,0.5v4.1c0,0.3,0.3,0.5,0.5,0.5h0.9c0.3,0,0.5-0.3,0.5-0.5v-5.9
c0-0.3-0.3-0.5-0.5-0.5H4.8c-0.3,0-0.5,0.3-0.5,0.5v5.9c0,0.3,0.3,0.5,0.5,0.5h0.8c0.3,0,0.5-0.3,0.5-0.5v-4.1
C6.2,13.1,6.4,12.9,6.7,12.9 M0.6,7.4v4.5c0,0.4,0.5,0.7,0.8,0.3L3.7,10c0.2-0.2,0.2-0.5,0-0.7L1.5,7C1.1,6.7,0.6,7,0.6,7.4"/>
);

const tbreak = {
Expand Down
9 changes: 4 additions & 5 deletions packages/ui-markdown-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import { BUTTON_ACTIVE, BLOCK_STYLE } from './utilities/constants';
import withSchema from './utilities/schema';
import Element from './components';
import Leaf from './components/Leaf';
import { toggleMark, toggleBlock, insertThematicBreak,
insertLinebreak, insertHeadingbreak, isBlockHeading
} from './utilities/toolbarHelpers';
import { toggleMark, toggleBlock, insertThematicBreak,
insertLinebreak, insertHeadingbreak, isBlockHeading } from './utilities/toolbarHelpers';
import { withImages, insertImage } from './plugins/withImages';
import { withLinks, isSelectionLinkBody } from './plugins/withLinks';
import { withHtml } from './plugins/withHtml';
Expand All @@ -37,7 +36,7 @@ export const MarkdownEditor = (props) => {
canBeFormatted
} = props;
const [showLinkModal, setShowLinkModal] = useState(false);
const [currentStyle, setCurrentStyle] = useState('')
const [currentStyle, setCurrentStyle] = useState('');
const editor = useMemo(() => {
if (augmentEditor) {
return augmentEditor(
Expand Down Expand Up @@ -91,7 +90,7 @@ export const MarkdownEditor = (props) => {
return;
}

if (event.key === "Enter" && !isBlockHeading(editor)) {
if (event.key === 'Enter' && !isBlockHeading(editor)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-markdown-editor/src/utilities/hotkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const HOTKEYS = {
type: 'linebreak',
code: LINEBREAK,
},
'enter': {
enter: {
type: 'headingbreak',
code: HEADINGBREAK
}
Expand Down
19 changes: 8 additions & 11 deletions packages/ui-markdown-editor/src/utilities/toolbarHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export const toggleBlock = (editor, format) => {
const anchor = editor.selection.anchor.path.slice(0, -1).concat(0, editor.selection.anchor.path[editor.selection.anchor.path.length - 1]);
const focus = editor.selection.focus.path.slice(0, -1).concat(0, editor.selection.focus.path[editor.selection.focus.path.length - 1]);
// swap anchor and focus when selecting from bottom-top
if(anchor[1]>focus[1]){
[anchor[1],focus[1]]=[focus[1],anchor[1]];
if (anchor[1] > focus[1]) {
[anchor[1], focus[1]] = [focus[1], anchor[1]];
}
// eslint-disable-next-line no-restricted-syntax
for (const [node, path] of Node.descendants(
editor,
{ from: anchor, to: focus }
)) {
if (node.type === PARAGRAPH || HEADINGS.includes(node.type)) {
if (node.type === PARAGRAPH || HEADINGS.includes(node.type)) {
Transforms.wrapNodes(editor, listItemBlock, { at: path });
}
}
Expand Down Expand Up @@ -104,18 +104,15 @@ export const insertLinebreak = (editor, type) => {

export const insertHeadingbreak = (editor) => {
const text = { object: 'text', text: '' };
const n = { object: "block", type: 'paragraph', children: [text] };
const n = { object: 'block', type: 'paragraph', children: [text] };
Transforms.insertNodes(editor, n);
return;
}
};

export const isBlockHeading = (editor) => {
const [match] = Editor.nodes(editor, {
match: n => {
return n.type === 'heading_one'
match: n => n.type === 'heading_one'
|| n.type === 'heading_two'
|| n.type === 'heading_three'
},
|| n.type === 'heading_three',
});
return !!match;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const sliceWord = word => word.toString().slice(1);

const firstTwoLetters = word => word.toString().slice(0, 2);


/* Function to determine OS and MOD command of user */

export const MOD = () => {
Expand Down
0