Skip to content

Commit dce34b7

Browse files
committed
Font-awesome dependencies have been removed
1 parent 59bf9f2 commit dce34b7

25 files changed

+432
-494
lines changed

src/commands/boldCommand.tsx

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import * as React from "react";
2-
import { Command } from "../types";
3-
import { TextApi, TextState } from "../types/CommandOptions";
4-
import { selectWord } from "../util/MarkdownUtil";
2+
import {Command} from "../types";
3+
import {TextApi, TextState} from "../types/CommandOptions";
4+
import {selectWord} from "../util/MarkdownUtil";
55

66
export const boldCommand: Command = {
7-
name: "bold",
8-
buttonContentBuilder: ({ iconProvider }) => iconProvider("bold"),
9-
buttonProps: { "aria-label": "Add bold text" },
10-
execute: (state0: TextState, api: TextApi) => {
11-
// Adjust the selection to encompass the whole word if the caret is inside one
12-
const newSelectionRange = selectWord({ text: state0.text, selection: state0.selection });
13-
const state1 = api.setSelectionRange(newSelectionRange);
14-
// Replaces the current selection with the bold mark up
15-
const state2 = api.replaceSelection(`**${state1.selectedText}**`);
16-
// Adjust the selection to not contain the **
17-
api.setSelectionRange({
18-
start: state2.selection.end - 2 - state1.selectedText.length,
19-
end: state2.selection.end - 2
20-
});
21-
},
22-
keyCommand: "bold",
7+
name: "bold",
8+
buttonProps: {"aria-label": "Add bold text"},
9+
execute: (state0: TextState, api: TextApi) => {
10+
// Adjust the selection to encompass the whole word if the caret is inside one
11+
const newSelectionRange = selectWord({text: state0.text, selection: state0.selection});
12+
const state1 = api.setSelectionRange(newSelectionRange);
13+
// Replaces the current selection with the bold mark up
14+
const state2 = api.replaceSelection(`**${state1.selectedText}**`);
15+
// Adjust the selection to not contain the **
16+
api.setSelectionRange({
17+
start: state2.selection.end - 2 - state1.selectedText.length,
18+
end: state2.selection.end - 2
19+
});
20+
},
21+
keyCommand: "bold",
2322
};

src/commands/checkListCommand.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/commands/codeCommand.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {getBreaksNeededForEmptyLineAfter, getBreaksNeededForEmptyLineBefore, sel
55

66
export const codeCommand: Command = {
77
name: "code",
8-
buttonContentBuilder: ({iconProvider}) => iconProvider("code"),
98
buttonProps: {"aria-label": "Add bold text"},
109
execute: (state0: TextState, api: TextApi) => {
1110
// Adjust the selection to encompass the whole word if the caret is inside one

src/commands/headerCommand.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@ function setHeader(state0: TextState, api: TextApi, prefix: string) {
1818

1919
export const headerCommand: Command = {
2020
name: "header",
21-
buttonContentBuilder: ({iconProvider}) => iconProvider("heading"),
2221
buttonProps: {"aria-label": "Add header"},
2322
children: [
2423
{
2524
name: "header-1",
26-
buttonContentBuilder: () => <p className="header-1">Header 1</p>,
25+
icon: () => <p className="header-1">Header 1</p>,
2726
execute: (state: TextState, api: TextApi) => setHeader(state, api, "# "),
2827
},
2928
{
3029
name: "header-2",
31-
buttonContentBuilder: () => <p className="header-2">Header 2</p>,
30+
icon: () => <p className="header-2">Header 2</p>,
3231
execute: (state: TextState, api: TextApi) => setHeader(state, api, "## "),
3332
},
3433
{
3534
name: "header-3",
36-
buttonContentBuilder: () => <p className="header-3">Header 3</p>,
35+
icon: () => <p className="header-3">Header 3</p>,
3736
execute: (state: TextState, api: TextApi) => setHeader(state, api, "### "),
3837
},
3938
{
4039
name: "header-4",
41-
buttonContentBuilder: () => <p className="header-4">Header 4</p>,
40+
icon: () => <p className="header-4">Header 4</p>,
4241
execute: (state: TextState, api: TextApi) => setHeader(state, api, "#### "),
4342
},
4443
],

src/commands/imageCommand.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {selectWord} from "../util/MarkdownUtil";
55

66
export const imageCommand: Command = {
77
name: "image",
8-
buttonContentBuilder: ({iconProvider}) => iconProvider("image"),
98
buttonProps: {"aria-label": "Add image"},
109
execute: (state0: TextState, api: TextApi) => {
1110
// Adjust the selection to encompass the whole word if the caret is inside one

src/commands/index.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
import {boldCommand} from "./boldCommand";
2-
// import { codeCommand } from "./codeCommand";
3-
// import { headerCommand } from "./headerCommand";
4-
// import { imageCommand } from "./imageCommand";
52
import {italicCommand} from "./italicCommand";
63
import {strikeThroughCommand} from "./strikethroughCommand";
7-
// import { linkCommand } from "./linkCommand";
8-
// import { orderedListCommand } from "./orderedListCommand";
9-
// import { quoteCommand } from "./quoteCommand";
10-
// import { unorderedListCommand } from "./unorderedListCommand";
11-
// import { checkListCommand } from "./checkListCommand";
124
import {CommandGroup} from "../types";
135
import {headerCommand} from "./headerCommand";
146
import {linkCommand} from "./linkCommand";
157
import {quoteCommand} from "./quoteCommand";
168
import {codeCommand} from "./codeCommand";
179
import {imageCommand} from "./imageCommand";
18-
import {unorderedListCommand} from "./listCommands";
19-
20-
// const getDefaultCommands: () => CommandGroup[] = () => [
21-
// { commands: [headerCommand, strikeThroughCommand, italicCommand, strikethroughCommand] },
22-
// { commands: [linkCommand, quoteCommand, codeCommand, imageCommand] },
23-
// { commands: [unorderedListCommand, orderedListCommand, checkListCommand] }
24-
// ];
10+
import {checkedListCommand, orderedListCommand, unorderedListCommand} from "./listCommands";
2511

2612
const getDefaultCommands: () => CommandGroup[] = () => [
2713
{
@@ -31,7 +17,7 @@ const getDefaultCommands: () => CommandGroup[] = () => [
3117
commands: [linkCommand, quoteCommand, codeCommand, imageCommand]
3218
},
3319
{
34-
commands: [unorderedListCommand]
20+
commands: [unorderedListCommand, orderedListCommand, checkedListCommand]
3521
}
3622
];
3723

src/commands/italicCommand.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { TextApi, TextState } from "../types/CommandOptions";
44
import { selectWord } from "../util/MarkdownUtil";
55

66
export const italicCommand: Command = {
7-
name: "bold",
8-
buttonContentBuilder: ({ iconProvider }) => iconProvider("italic"),
7+
name: "italic",
98
buttonProps: { "aria-label": "Add italic text" },
109
execute: (state0: TextState, api: TextApi) => {
1110
// Adjust the selection to encompass the whole word if the caret is inside one

src/commands/linkCommand.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {selectWord} from "../util/MarkdownUtil";
55

66
export const linkCommand: Command = {
77
name: "link",
8-
buttonContentBuilder: ({iconProvider}) => iconProvider("link"),
98
buttonProps: {"aria-label": "Add bold text"},
109
execute: (state0: TextState, api: TextApi) => {
1110
// Adjust the selection to encompass the whole word if the caret is inside one

src/commands/listCommands.tsx

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,77 @@ export type AlterLineFunction = (line: string, index: number) => string;
88
/**
99
* Inserts insertionString before each line
1010
*/
11-
export function insertBeforeEachLine(selectedText: string, insert: string | AlterLineFunction):
11+
export function insertBeforeEachLine(selectedText: string, insertBefore: string | AlterLineFunction):
1212
{ modifiedText: string, insertionLength: number } {
1313
const lines = selectedText.split(/\n/);
1414

1515
let insertionLength = 0;
1616
const modifiedText = lines.map((item, index) => {
17-
if (typeof insert === "string") {
18-
insertionLength += insert.length;
19-
return insert + item;
20-
} else if (typeof insert === "function") {
21-
const insertionResult = insert(item, index);
17+
if (typeof insertBefore === "string") {
18+
insertionLength += insertBefore.length;
19+
return insertBefore + item;
20+
} else if (typeof insertBefore === "function") {
21+
const insertionResult = insertBefore(item, index);
2222
insertionLength += insertionResult.length;
23-
return insert(item, index) + item;
23+
return insertBefore(item, index) + item;
2424
}
2525
throw Error("insertion is expected to be either a string or a function");
2626
}).join("\n");
2727

2828
return {modifiedText, insertionLength}
2929
}
3030

31-
export const unorderedListCommand: Command = {
32-
name: "code",
33-
buttonContentBuilder: ({iconProvider}) => iconProvider("list-ul"),
34-
buttonProps: {"aria-label": "Add unordered list"},
35-
execute: (state0: TextState, api: TextApi) => {
36-
// Adjust the selection to encompass the whole word if the caret is inside one
37-
const newSelectionRange = selectWord({text: state0.text, selection: state0.selection});
38-
const state1 = api.setSelectionRange(newSelectionRange);
31+
export const makeList = (state0: TextState, api: TextApi, insertBefore: string | AlterLineFunction) => {
32+
// Adjust the selection to encompass the whole word if the caret is inside one
33+
const newSelectionRange = selectWord({text: state0.text, selection: state0.selection});
34+
const state1 = api.setSelectionRange(newSelectionRange);
3935

40-
const breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
41-
const breaksBefore = Array(breaksBeforeCount + 1).join("\n");
36+
const breaksBeforeCount = getBreaksNeededForEmptyLineBefore(state1.text, state1.selection.start);
37+
const breaksBefore = Array(breaksBeforeCount + 1).join("\n");
4238

43-
const breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
44-
const breaksAfter = Array(breaksAfterCount + 1).join("\n");
39+
const breaksAfterCount = getBreaksNeededForEmptyLineAfter(state1.text, state1.selection.end);
40+
const breaksAfter = Array(breaksAfterCount + 1).join("\n");
4541

46-
const modifiedText = insertBeforeEachLine(state1.selectedText, "- ");
42+
const modifiedText = insertBeforeEachLine(state1.selectedText, insertBefore);
4743

48-
api.replaceSelection(`${breaksBefore}${modifiedText.modifiedText}${breaksAfter}`);
44+
api.replaceSelection(`${breaksBefore}${modifiedText.modifiedText}${breaksAfter}`);
4945

50-
const selectionStart = state1.selection.start + breaksBeforeCount;
51-
const selectionEnd = selectionStart + modifiedText.modifiedText.length;
46+
// Specifically when the text has only one line, we can exclude the "- ", for example, from the selection
47+
const oneLinerOffset = state1.selectedText.indexOf("\n") === -1 ? modifiedText.insertionLength : 0;
5248

53-
// Adjust the selection to not contain the **
54-
api.setSelectionRange({
55-
start: selectionStart,
56-
end: selectionEnd
57-
});
49+
const selectionStart = state1.selection.start + breaksBeforeCount + oneLinerOffset;
50+
const selectionEnd = selectionStart + modifiedText.modifiedText.length - oneLinerOffset;
51+
52+
// Adjust the selection to not contain the **
53+
api.setSelectionRange({
54+
start: selectionStart,
55+
end: selectionEnd
56+
});
57+
}
58+
59+
export const unorderedListCommand: Command = {
60+
name: "unordered-list",
61+
buttonProps: {"aria-label": "Add unordered list"},
62+
execute: (state0: TextState, api: TextApi) => {
63+
makeList(state0, api, "- ")
64+
},
65+
keyCommand: "code",
66+
};
67+
68+
export const orderedListCommand: Command = {
69+
name: "ordered-list",
70+
buttonProps: {"aria-label": "Add ordered list"},
71+
execute: (state0: TextState, api: TextApi) => {
72+
makeList(state0, api, (item, index) => `${index + 1}. `)
73+
},
74+
keyCommand: "code",
75+
};
76+
77+
export const checkedListCommand: Command = {
78+
name: "checked-list",
79+
buttonProps: {"aria-label": "Add ordered list"},
80+
execute: (state0: TextState, api: TextApi) => {
81+
makeList(state0, api, (item, index) => `${index + 1}. `)
5882
},
5983
keyCommand: "code",
60-
}
84+
};

src/commands/orderedListCommand.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)