From 94853235488272f570eca7d344b0148b161ffe1f Mon Sep 17 00:00:00 2001 From: Found Pan Tiger Date: Sun, 12 Dec 2021 17:12:16 +0800 Subject: [PATCH] deps: upgrade --- hooks/use-monaco.tsx | 59 - libs/markdown.ts | 2 - libs/monaco-config.ts | 299 ---- libs/plugins/emoji.ts | 21 - next-env.d.ts | 1 - package.json | 70 +- tsconfig.json | 3 +- yarn.lock | 3441 +++++++++++++++++------------------------ 8 files changed, 1460 insertions(+), 2436 deletions(-) delete mode 100644 libs/monaco-config.ts delete mode 100644 libs/plugins/emoji.ts diff --git a/hooks/use-monaco.tsx b/hooks/use-monaco.tsx index 4721e8f..9f4718c 100644 --- a/hooks/use-monaco.tsx +++ b/hooks/use-monaco.tsx @@ -1,9 +1,7 @@ import { useMonaco } from '@monaco-editor/react' import { useEffect } from 'react' import IDLE from 'monaco-themes/themes/IDLE.json' -import emojis from 'node-emoji' import type { editor } from 'monaco-editor/esm/vs/editor/editor.api' -import { id, language, conf } from 'libs/monaco-config' export function useMonacoColor() { const monaco = useMonaco() @@ -16,60 +14,3 @@ export function useMonacoColor() { }, [monaco]) return monaco?.editor.colorize } - -export function useMonacoEditor() { - const monaco = useMonaco() - useMonacoColor() - useEffect(() => { - if (!monaco) { - return - } - monaco.languages.register({ id }) - }, [monaco]) - useEffect(() => { - if (!monaco) { - return undefined - } - const { dispose } = monaco.languages.setLanguageConfiguration(id, conf) - return dispose - }, [monaco]) - useEffect(() => { - if (!monaco) { - return undefined - } - const { dispose } = monaco.languages.setMonarchTokensProvider(id, language) - return dispose - }, [monaco]) - useEffect(() => { - if (!monaco) { - return undefined - } - const { dispose } = monaco.languages.registerCompletionItemProvider(id, { - triggerCharacters: [':'], - provideCompletionItems(model, position, context) { - if (context.triggerKind === 0) { - return { - suggestions: [], - } - } - const word = model.getWordUntilPosition(position) - const range = { - startLineNumber: position.lineNumber, - endLineNumber: position.lineNumber, - startColumn: word.startColumn, - endColumn: word.endColumn, - } - return { - suggestions: emojis.search(word.word).map((e) => ({ - label: `${e.key} ${e.emoji}`, - kind: monaco.languages.CompletionItemKind.Function, - insertText: `${e.key}:`, - range, - })), - } - }, - }) - return dispose - }, [monaco]) - return monaco -} diff --git a/libs/markdown.ts b/libs/markdown.ts index 906ae92..104d77d 100644 --- a/libs/markdown.ts +++ b/libs/markdown.ts @@ -12,7 +12,6 @@ import rehype2react, { Options } from 'rehype-react' import MonaCode from 'components/mona-code' import LocalImage from 'components/local-image' import LocalLink from 'components/local-link' -import { emoji } from './plugins/emoji' export function process(value: string): ReactNode { const { result } = unified() @@ -20,7 +19,6 @@ export function process(value: string): ReactNode { .use(slug) .use(headings) .use(gfm) - .use(emoji) .use(remark2rehype) .use(sanitize, { ...defaultSchema, diff --git a/libs/monaco-config.ts b/libs/monaco-config.ts deleted file mode 100644 index 997fe8f..0000000 --- a/libs/monaco-config.ts +++ /dev/null @@ -1,299 +0,0 @@ -/* eslint-disable no-template-curly-in-string */ -/* eslint-disable no-useless-escape */ - -import type { languages } from 'monaco-editor' - -export const id = 'gfm' - -export const conf: languages.LanguageConfiguration = { - comments: { - blockComment: [''], - }, - brackets: [ - ['{', '}'], - ['[', ']'], - ['(', ')'], - ['「', '」'], - ['【', '】'], - ['(', ')'], - ], - autoClosingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '「', close: '」' }, - { open: '【', close: '】' }, - { open: '(', close: ')' }, - { open: '<', close: '>', notIn: ['string'] }, - { open: '*', close: '*', notIn: ['string'] }, - { open: '~', close: '~', notIn: ['string'] }, - { open: '`', close: '`', notIn: ['string'] }, - { open: '_', close: '_', notIn: ['string'] }, - ], - surroundingPairs: [ - { open: '{', close: '}' }, - { open: '[', close: ']' }, - { open: '(', close: ')' }, - { open: '「', close: '」' }, - { open: '【', close: '】' }, - { open: '(', close: ')' }, - { open: '<', close: '>' }, - { open: '*', close: '*' }, - { open: '~', close: '~' }, - { open: '`', close: '`' }, - { open: '_', close: '_' }, - ], - folding: { - markers: { - start: new RegExp('^\\s*'), - end: new RegExp('^\\s*'), - }, - }, -} - -export const language = { - defaultToken: '', - tokenPostfix: '.md', - - // escape codes - control: /[\\`*_\[\]{}()#+\-\.!]/, - noncontrol: /[^\\`*_\[\]{}()#+\-\.!]/, - escapes: /\\(?:@control)/, - - // escape codes for javascript/CSS strings - jsescapes: /\\(?:[btnfr\\"']|[0-7][0-7]?|[0-3][0-7]{2})/, - - // non matched elements - empty: [ - 'area', - 'base', - 'basefont', - 'br', - 'col', - 'frame', - 'hr', - 'img', - 'input', - 'isindex', - 'link', - 'meta', - 'param', - ], - - tokenizer: { - root: [ - // markdown tables - [/^\s*\|/, '@rematch', '@table_header'], - - // headers (with #) - [ - /^(\s{0,3})(#+)((?:[^\\#]|@escapes)+)((?:#+)?)/, - ['white', 'keyword', 'keyword', 'keyword'], - ], - - // headers (with =) - [/^\s*(=+|\-+)\s*$/, 'keyword'], - - // headers (with ***) - [/^\s*((\*[ ]?)+)\s*$/, 'meta.separator'], - - // quote - [/^\s*>+/, 'comment'], - - // list (starting with * or number) - [/^\s*([\*\-+:]|\d+\.)\s/, 'keyword'], - - // code block (4 spaces indent) - [/^(\t|[ ]{4})[^ ].*$/, 'string'], - - // code block (3 tilde) - [ - /^\s*~~~\s*((?:\w|[\/\-#])+)?\s*$/, - { token: 'string', next: '@codeblock' }, - ], - - // github style code blocks (with backticks and language) - [ - /^\s*```\s*((?:\w|[\/\-#])+).*$/, - { token: 'string', next: '@codeblockgh', nextEmbedded: '$1' }, - ], - - // github style code blocks (with backticks but no language) - [/^\s*```\s*$/, { token: 'string', next: '@codeblock' }], - - // markup within lines - { include: '@linecontent' }, - ], - - table_header: [ - { include: '@table_common' }, - [/[^\|]+/, 'keyword.table.header'], // table header - ], - - table_body: [{ include: '@table_common' }, { include: '@linecontent' }], - - table_common: [ - [/\s*[\-:]+\s*/, { token: 'keyword', switchTo: 'table_body' }], // header-divider - [/^\s*\|/, 'keyword.table.left'], // opening | - [/^\s*[^\|]/, '@rematch', '@pop'], // exiting - [/^\s*$/, '@rematch', '@pop'], // exiting - [ - /\|/, - { - cases: { - '@eos': 'keyword.table.right', // closing | - '@default': 'keyword.table.middle', // inner | - }, - }, - ], - ], - - codeblock: [ - [/^\s*~~~\s*$/, { token: 'string', next: '@pop' }], - [/^\s*```\s*$/, { token: 'string', next: '@pop' }], - [/.*$/, 'variable.source'], - ], - - // github style code blocks - codeblockgh: [ - [ - /```\s*$/, - { token: 'variable.source', next: '@pop', nextEmbedded: '@pop' }, - ], - [/[^`]+/, 'variable.source'], - ], - - linecontent: [ - // escapes - [/&\w+;/, 'string.escape'], - [/@escapes/, 'escape'], - - // various markup - [/\b__([^\\_]|@escapes|_(?!_))+__\b/, 'strong'], - [/\*\*([^\\*]|@escapes|\*(?!\*))+\*\*/, 'strong'], - [/\b_[^_]+_\b/, 'emphasis'], - [/\*([^\\*]|@escapes)+\*/, 'emphasis'], - [/`([^\\`]|@escapes)+`/, 'variable'], - - // emoji - [/:\+1:|:-1:|:[\w-]+:/, 'string'], - - // links - [/\{+[^}]+\}+/, 'string.target'], - [ - /(!?\[)((?:[^\]\\]|@escapes)*)(\]\([^\)]+\))/, - ['string.link', '', 'string.link'], - ], - [/(!?\[)((?:[^\]\\]|@escapes)*)(\])/, 'string.link'], - [/https?:\/\/[\w\.\-\/\?=&#%]+/, 'string.link'], - - // or html - { include: 'html' }, - ], - - // Note: it is tempting to rather switch to the real HTML mode instead of building our own here - // but currently there is a limitation in Monarch that prevents us from doing it: The opening - // '<' would start the HTML mode, however there is no way to jump 1 character back to let the - // HTML mode also tokenize the opening angle bracket. Thus, even though we could jump to HTML, - // we cannot correctly tokenize it in that mode yet. - html: [ - // html tags - [/<(\w+)\/>/, 'tag'], - [ - /<(\w+)/, - { - cases: { - '@empty': { token: 'tag', next: '@tag.$1' }, - '@default': { token: 'tag', next: '@tag.$1' }, - }, - }, - ], - [/<\/(\w+)\s*>/, { token: 'tag' }], - - [//, 'comment', '@pop'], - [/