Просмотр исходного кода

Merge pull request #8846 from weseek/support/reorganize-editor-module-exports

support: Reorganize editor module exports
Yuki Takei 1 год назад
Родитель
Сommit
698490a810
77 измененных файлов с 149 добавлено и 277 удалено
  1. 1 0
      .eslintrc.js
  2. 0 1
      apps/app/.eslintrc.js
  3. 0 147
      apps/app/src/client/models/MarkdownTable.js
  4. 1 1
      apps/app/src/client/services/side-effects/handsontable-modal-launcher-for-view.ts
  5. 1 1
      apps/app/src/components/Page/markdown-table-util-for-view.ts
  6. 1 1
      apps/app/src/components/PageEditor/HandsontableModal.tsx
  7. 1 1
      apps/app/src/components/PageEditor/LinkEditModal.tsx
  8. 1 1
      apps/app/src/components/PageEditor/MarkdownTableDataImportForm.tsx
  9. 1 2
      apps/app/src/components/PageEditor/markdown-table-util-for-editor.ts
  10. 1 2
      apps/app/src/stores/modal.tsx
  11. 4 7
      packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx
  12. 3 3
      packages/editor/src/components/CodeMirrorEditor/Toolbar/AttachmentsDropdownItem.tsx
  13. 1 1
      packages/editor/src/components/CodeMirrorEditor/Toolbar/LinkEditButton.tsx
  14. 1 1
      packages/editor/src/components/CodeMirrorEditor/Toolbar/Toolbar.tsx
  15. 1 1
      packages/editor/src/components/CodeMirrorEditorMain.tsx
  16. 1 1
      packages/editor/src/components/CodeMirrorEditorReadOnly.tsx
  17. 2 2
      packages/editor/src/components/playground/Playground.tsx
  18. 4 3
      packages/editor/src/components/playground/PlaygroundController.tsx
  19. 2 1
      packages/editor/src/consts/editor-settings.ts
  20. 16 0
      packages/editor/src/consts/editor-themes.ts
  21. 2 0
      packages/editor/src/consts/index.ts
  22. 10 0
      packages/editor/src/consts/keymaps.ts
  23. 1 0
      packages/editor/src/index.ts
  24. 0 0
      packages/editor/src/models/index.ts
  25. 0 0
      packages/editor/src/models/markdown-table.d.ts
  26. 0 0
      packages/editor/src/models/markdown-table.js
  27. 0 0
      packages/editor/src/services-internal/editor-theme/.eslintrc.cjs
  28. 0 0
      packages/editor/src/services-internal/editor-theme/ayu.ts
  29. 0 0
      packages/editor/src/services-internal/editor-theme/cobalt.ts
  30. 0 0
      packages/editor/src/services-internal/editor-theme/eclipse.ts
  31. 3 18
      packages/editor/src/services-internal/editor-theme/index.ts
  32. 1 1
      packages/editor/src/services-internal/editor-theme/material.ts
  33. 1 1
      packages/editor/src/services-internal/editor-theme/nord.ts
  34. 0 0
      packages/editor/src/services-internal/editor-theme/original-dark.ts
  35. 1 1
      packages/editor/src/services-internal/editor-theme/original-light.ts
  36. 0 0
      packages/editor/src/services-internal/editor-theme/rose-pine.ts
  37. 0 0
      packages/editor/src/services-internal/extensions/emojiAutocompletionSettings.ts
  38. 2 0
      packages/editor/src/services-internal/extensions/index.ts
  39. 2 3
      packages/editor/src/services-internal/extensions/setDataLine.ts
  40. 0 0
      packages/editor/src/services-internal/file-dropzone/index.ts
  41. 19 0
      packages/editor/src/services-internal/file-dropzone/use-file-dropzone/FileDropzoneOverlay.tsx
  42. 2 2
      packages/editor/src/services-internal/file-dropzone/use-file-dropzone/use-file-dropzone.ts
  43. 8 0
      packages/editor/src/services-internal/index.ts
  44. 3 12
      packages/editor/src/services-internal/keymaps/index.ts
  45. 1 1
      packages/editor/src/services-internal/keymaps/vim.ts
  46. 1 1
      packages/editor/src/services-internal/link-util/Linker.ts
  47. 2 0
      packages/editor/src/services-internal/link-util/index.ts
  48. 1 1
      packages/editor/src/services-internal/link-util/markdown-link-util.ts
  49. 1 0
      packages/editor/src/services-internal/list-util/index.ts
  50. 1 1
      packages/editor/src/services-internal/list-util/insert-newline-continue-markup.ts
  51. 1 0
      packages/editor/src/services-internal/paste-util/index.ts
  52. 0 0
      packages/editor/src/services-internal/paste-util/paste-markdown-util.ts
  53. 2 0
      packages/editor/src/services-internal/table/index.ts
  54. 2 2
      packages/editor/src/services-internal/table/insert-new-row-to-table-markdown.ts
  55. 2 2
      packages/editor/src/services-internal/table/use-show-table-icon.ts
  56. 0 1
      packages/editor/src/services/codemirror-editor/index.ts
  57. 0 19
      packages/editor/src/services/file-dropzone/use-file-dropzone/FileDropzoneOverlay.tsx
  58. 1 4
      packages/editor/src/services/index.ts
  59. 1 0
      packages/editor/src/services/use-codemirror-editor/index.ts
  60. 4 3
      packages/editor/src/services/use-codemirror-editor/use-codemirror-editor.ts
  61. 3 2
      packages/editor/src/services/use-codemirror-editor/utils/append-extensions.ts
  62. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/focus.ts
  63. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/fold-drawio.ts
  64. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/get-doc.ts
  65. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/init-doc.ts
  66. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/insert-markdown-elements.ts
  67. 3 2
      packages/editor/src/services/use-codemirror-editor/utils/insert-prefix.ts
  68. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/insert-text.ts
  69. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/replace-text.ts
  70. 1 1
      packages/editor/src/services/use-codemirror-editor/utils/set-caret-line.ts
  71. 1 2
      packages/editor/src/stores/codemirror-editor.ts
  72. 1 1
      packages/editor/src/stores/use-collaborative-editor-mode.ts
  73. 3 2
      packages/editor/src/stores/use-default-extensions.ts
  74. 8 6
      packages/editor/src/stores/use-editor-settings.ts
  75. 1 1
      packages/editor/src/stores/use-handsontable.ts
  76. 2 2
      packages/editor/src/stores/use-link-edit-modal.ts
  77. 1 1
      packages/editor/src/stores/use-resolved-theme.ts

+ 1 - 0
.eslintrc.js

@@ -48,6 +48,7 @@ module.exports = {
         'newlines-between': 'always',
       },
     ],
+    '@typescript-eslint/consistent-type-imports': 'warn',
     '@typescript-eslint/no-explicit-any': 'off',
     '@typescript-eslint/explicit-module-boundary-types': 'off',
     indent: [

+ 0 - 1
apps/app/.eslintrc.js

@@ -27,7 +27,6 @@ module.exports = {
       },
     ]],
     '@typescript-eslint/no-var-requires': 'off',
-    '@typescript-eslint/consistent-type-imports': 'warn',
 
     // set 'warn' temporarily -- 2021.08.02 Yuki Takei
     '@typescript-eslint/no-use-before-define': ['warn'],

+ 0 - 147
apps/app/src/client/models/MarkdownTable.js

@@ -1,147 +0,0 @@
-import csvToMarkdown from 'csv-to-markdown-table';
-import { markdownTable } from 'markdown-table';
-import stringWidth from 'string-width';
-
-// https://github.com/markdown-it/markdown-it/blob/d29f421927e93e88daf75f22089a3e732e195bd2/lib/rules_block/table.js#L83
-// https://regex101.com/r/7BN2fR/7
-const tableAlignmentLineRE = /^[-:|][-:|\s]*$/;
-const tableAlignmentLineNegRE = /^[^-:]*$/; // it is need to check to ignore empty row which is matched above RE
-const linePartOfTableRE = /^\|[^\r\n]*|[^\r\n]*\|$|([^|\r\n]+\|[^|\r\n]*)+/; // own idea
-
-const defaultOptions = { stringLength: stringWidth };
-
-/**
- * markdown table class for markdown-table module
- *   ref. https://github.com/wooorm/markdown-table
- */
-export default class MarkdownTable {
-
-  constructor(table, options) {
-    this.table = table || [];
-    this.options = Object.assign(options || {}, defaultOptions);
-
-    this.toString = this.toString.bind(this);
-  }
-
-  toString() {
-    return markdownTable(this.table, this.options);
-  }
-
-  /**
-   * returns cloned Markdowntable instance
-   * (This method clones only the table field.)
-   */
-  clone() {
-    const newTable = [];
-    for (let i = 0; i < this.table.length; i++) {
-      newTable.push([].concat(this.table[i]));
-    }
-    return new MarkdownTable(newTable, this.options);
-  }
-
-  /**
-   * normalize all cell data(trim & convert the newline character to space or pad '' if cell data is null)
-   */
-  normalizeCells() {
-    for (let i = 0; i < this.table.length; i++) {
-      for (let j = 0; j < this.table[i].length; j++) {
-        if (this.table[i][j] != null) {
-          this.table[i][j] = this.table[i][j].trim().replace(/\r?\n/g, ' ');
-        }
-        else {
-          this.table[i][j] = '';
-        }
-      }
-    }
-
-    return this;
-  }
-
-  /**
-   * return a MarkdownTable instance made from a string of HTML table tag
-   *
-   * If a parser error occurs, an error object with an error message is thrown.
-   * The error message is a innerHTML, so must not assign it into element.innerHTML because it can lead to Mutation-based XSS
-   */
-  static fromHTMLTableTag(str) {
-    // set up DOMParser
-    const domParser = new (window.DOMParser)();
-
-    // use DOMParser to prevent DOM based XSS (https://developer.mozilla.org/en-US/docs/Web/API/DOMParser)
-    const dom = domParser.parseFromString(str, 'application/xml');
-
-    if (dom.querySelector('parsererror')) {
-      throw new Error(dom.documentElement.innerHTML);
-    }
-
-    const tableElement = dom.querySelector('table');
-    const trElements = tableElement.querySelectorAll('tr');
-
-    const table = [];
-    let maxRowSize = 0;
-    for (let i = 0; i < trElements.length; i++) {
-      const row = [];
-      const cellElements = trElements[i].querySelectorAll('th,td');
-      for (let j = 0; j < cellElements.length; j++) {
-        row.push(cellElements[j].innerHTML);
-      }
-      table.push(row);
-
-      if (maxRowSize < row.length) maxRowSize = row.length;
-    }
-
-    const align = [];
-    for (let i = 0; i < maxRowSize; i++) {
-      align.push('');
-    }
-
-    return new MarkdownTable(table, { align });
-  }
-
-  /**
-   * return a MarkdownTable instance made from a string of delimiter-separated values
-   */
-  static fromDSV(str, delimiter) {
-    return MarkdownTable.fromMarkdownString(csvToMarkdown(str, delimiter, true));
-  }
-
-  /**
-   * return a MarkdownTable instance
-   *   ref. https://github.com/wooorm/markdown-table
-   * @param {string} str markdown string
-   */
-  static fromMarkdownString(str) {
-    const arrMDTableLines = str.split(/(\r\n|\r|\n)/);
-    const contents = [];
-    let aligns = [];
-    for (let n = 0; n < arrMDTableLines.length; n++) {
-      const line = arrMDTableLines[n];
-
-      if (tableAlignmentLineRE.test(line) && !tableAlignmentLineNegRE.test(line)) {
-        // parse line which described alignment
-        const alignRuleRE = [
-          { align: 'c', regex: /^:-+:$/ },
-          { align: 'l', regex: /^:-+$/ },
-          { align: 'r', regex: /^-+:$/ },
-        ];
-        let lineText = '';
-        lineText = line.replace(/^\||\|$/g, ''); // strip off pipe charactor which is placed head of line and last of line.
-        lineText = lineText.replace(/\s*/g, '');
-        aligns = lineText.split(/\|/).map((col) => {
-          const rule = alignRuleRE.find((rule) => { return col.match(rule.regex) });
-          return (rule != null) ? rule.align : '';
-        });
-      }
-      else if (linePartOfTableRE.test(line)) {
-        // parse line whether header or body
-        let lineText = '';
-        lineText = line.replace(/\s*\|\s*/g, '|');
-        lineText = lineText.replace(/^\||\|$/g, ''); // strip off pipe charactor which is placed head of line and last of line.
-        const row = lineText.split(/\|/);
-        contents.push(row);
-      }
-    }
-    return (new MarkdownTable(contents, { align: aligns }));
-  }
-
-}

+ 1 - 1
apps/app/src/client/services/side-effects/handsontable-modal-launcher-for-view.ts

@@ -4,7 +4,7 @@ import type EventEmitter from 'events';
 
 import { Origin } from '@growi/core';
 
-import type MarkdownTable from '~/client/models/MarkdownTable';
+import type { MarkdownTable } from '@growi/editor';
 import { extractRemoteRevisionDataFromErrorObj, updatePage as _updatePage } from '~/client/services/update-page';
 import { getMarkdownTableFromLine, replaceMarkdownTableInMarkdown } from '~/components/Page/markdown-table-util-for-view';
 import { useShareLinkId } from '~/stores/context';

+ 1 - 1
apps/app/src/components/Page/markdown-table-util-for-view.ts

@@ -1,4 +1,4 @@
-import MarkdownTable from '~/client/models/MarkdownTable';
+import { MarkdownTable } from '@growi/editor';
 
 export const getMarkdownTableFromLine = (markdown: string, bol: number, eol: number): MarkdownTable => {
   const tableLines = markdown.split(/\r\n|\r|\n/).slice(bol - 1, eol).join('\n');

+ 1 - 1
apps/app/src/components/PageEditor/HandsontableModal.tsx

@@ -1,5 +1,6 @@
 import React, { useState } from 'react';
 
+import { MarkdownTable } from '@growi/editor';
 import { useHandsontableModalForEditor } from '@growi/editor/src/stores/use-handsontable';
 import { HotTable } from '@handsontable/react';
 import type Handsontable from 'handsontable';
@@ -10,7 +11,6 @@ import {
 } from 'reactstrap';
 import { debounce } from 'throttle-debounce';
 
-import MarkdownTable from '~/client/models/MarkdownTable';
 import { replaceFocusedMarkdownTableWithEditor, getMarkdownTable } from '~/components/PageEditor/markdown-table-util-for-editor';
 import { useHandsontableModal } from '~/stores/modal';
 

+ 1 - 1
apps/app/src/components/PageEditor/LinkEditModal.tsx

@@ -2,7 +2,7 @@ import React, { useEffect, useState, useCallback } from 'react';
 
 import path from 'path';
 
-import Linker from '@growi/editor/src/services/link-util/Linker';
+import { Linker } from '@growi/editor/src/services-internal';
 import { useLinkEditModal } from '@growi/editor/src/stores/use-link-edit-modal';
 import { useTranslation } from 'next-i18next';
 import {

+ 1 - 1
apps/app/src/components/PageEditor/MarkdownTableDataImportForm.tsx

@@ -1,12 +1,12 @@
 import React, { useState } from 'react';
 
+import { MarkdownTable } from '@growi/editor';
 import { useTranslation } from 'next-i18next';
 import {
   Button,
   Collapse,
 } from 'reactstrap';
 
-import MarkdownTable from '~/client/models/MarkdownTable';
 
 type MarkdownTableDataImportFormProps = {
   onCancel: () => void,

+ 1 - 2
apps/app/src/components/PageEditor/markdown-table-util-for-editor.ts

@@ -1,6 +1,5 @@
 import type { EditorView } from '@codemirror/view';
-
-import MarkdownTable from '~/client/models/MarkdownTable';
+import { MarkdownTable } from '@growi/editor';
 
 // https://regex101.com/r/7BN2fR/10
 const linePartOfTableRE = /^([^\r\n|]*)\|(([^\r\n|]*\|)+)$/;

+ 1 - 2
apps/app/src/stores/modal.tsx

@@ -4,10 +4,9 @@ import type {
   IAttachmentHasId, IPageToDeleteWithMeta, IPageToRenameWithMeta, IUserGroupHasId,
 } from '@growi/core';
 import { useSWRStatic } from '@growi/core/dist/swr';
+import { MarkdownTable } from '@growi/editor';
 import type { SWRResponse } from 'swr';
 
-
-import MarkdownTable from '~/client/models/MarkdownTable';
 import type { BookmarkFolderItems } from '~/interfaces/bookmark-info';
 import type {
   OnDuplicatedFunction, OnRenamedFunction, OnDeletedFunction, OnPutBackedFunction, onDeletedBookmarkFolderFunction, OnSelectedFunction,

+ 4 - 7
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -1,6 +1,6 @@
+import type { DetailedHTMLProps } from 'react';
 import {
   forwardRef, useMemo, useRef, useEffect,
-  DetailedHTMLProps,
 } from 'react';
 
 import { indentUnit } from '@codemirror/language';
@@ -10,14 +10,11 @@ import {
 import { AcceptedUploadFileType } from '@growi/core';
 import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
 
-import { EditorSettings, GlobalCodeMirrorEditorKey } from '../../consts';
+import type { EditorSettings, GlobalCodeMirrorEditorKey } from '../../consts';
 import {
   useFileDropzone, FileDropzoneOverlay,
-} from '../../services';
-import {
-  adjustPasteData, getStrFromBol,
-} from '../../services/paste-util/paste-markdown-util';
-import { useShowTableIcon } from '../../services/table-util/use-show-table-icon';
+  adjustPasteData, getStrFromBol, useShowTableIcon,
+} from '../../services-internal';
 import { useDefaultExtensions, useCodeMirrorEditorIsolated, useEditorSettings } from '../../stores';
 
 import { Toolbar } from './Toolbar';

+ 3 - 3
packages/editor/src/components/CodeMirrorEditor/Toolbar/AttachmentsDropdownItem.tsx

@@ -1,11 +1,11 @@
-import { ReactNode } from 'react';
+import type { ReactNode } from 'react';
 
-import { AcceptedUploadFileType } from '@growi/core';
+import type { AcceptedUploadFileType } from '@growi/core';
 import {
   DropdownItem,
 } from 'reactstrap';
 
-import { useFileDropzone } from '../../../services';
+import { useFileDropzone } from '../../../services-internal';
 
 type Props = {
   acceptedUploadFileType: AcceptedUploadFileType,

+ 1 - 1
packages/editor/src/components/CodeMirrorEditor/Toolbar/LinkEditButton.tsx

@@ -3,7 +3,7 @@ import { useCallback } from 'react';
 import { DropdownItem } from 'reactstrap';
 
 import type { GlobalCodeMirrorEditorKey } from '../../../consts';
-import { getMarkdownLink, replaceFocusedMarkdownLinkWithEditor } from '../../../services/link-util/markdown-link-util';
+import { getMarkdownLink, replaceFocusedMarkdownLinkWithEditor } from '../../../services-internal';
 import { useCodeMirrorEditorIsolated } from '../../../stores';
 import { useLinkEditModal } from '../../../stores/use-link-edit-modal';
 

+ 1 - 1
packages/editor/src/components/CodeMirrorEditor/Toolbar/Toolbar.tsx

@@ -1,6 +1,6 @@
 import { memo } from 'react';
 
-import { AcceptedUploadFileType } from '@growi/core';
+import type { AcceptedUploadFileType } from '@growi/core';
 
 import type { GlobalCodeMirrorEditorKey } from '../../../consts';
 

+ 1 - 1
packages/editor/src/components/CodeMirrorEditorMain.tsx

@@ -5,7 +5,7 @@ import { keymap, scrollPastEnd } from '@codemirror/view';
 import type { IUserHasId } from '@growi/core/dist/interfaces';
 
 import { GlobalCodeMirrorEditorKey } from '../consts';
-import { setDataLine } from '../services/extensions/setDataLine';
+import { setDataLine } from '../services-internal';
 import { useCodeMirrorEditorIsolated, useCollaborativeEditorMode } from '../stores';
 
 import { CodeMirrorEditor, type CodeMirrorEditorProps } from '.';

+ 1 - 1
packages/editor/src/components/CodeMirrorEditorReadOnly.tsx

@@ -3,7 +3,7 @@ import { useEffect } from 'react';
 import { type Extension, EditorState } from '@codemirror/state';
 
 import { GlobalCodeMirrorEditorKey } from '../consts';
-import { setDataLine } from '../services/extensions/setDataLine';
+import { setDataLine } from '../services-internal';
 import { useCodeMirrorEditorIsolated } from '../stores';
 
 import { CodeMirrorEditor } from '.';

+ 2 - 2
packages/editor/src/components/playground/Playground.tsx

@@ -5,8 +5,8 @@ import {
 import { AcceptedUploadFileType } from '@growi/core';
 import { toast } from 'react-toastify';
 
-import { EditorSettings, GlobalCodeMirrorEditorKey } from '../../consts';
-import type { EditorTheme, KeyMapMode } from '../../services';
+import { GlobalCodeMirrorEditorKey } from '../../consts';
+import type { EditorSettings, EditorTheme, KeyMapMode } from '../../consts';
 import { useCodeMirrorEditorIsolated } from '../../stores';
 import { CodeMirrorEditorMain } from '../CodeMirrorEditorMain';
 

+ 4 - 3
packages/editor/src/components/playground/PlaygroundController.tsx

@@ -2,10 +2,11 @@ import { useCallback } from 'react';
 
 import { useForm } from 'react-hook-form';
 
-import { GlobalCodeMirrorEditorKey } from '../../consts';
+import type { EditorTheme, KeyMapMode } from '../../consts';
 import {
-  AllEditorTheme, AllKeyMap, EditorTheme, KeyMapMode,
-} from '../../services';
+  GlobalCodeMirrorEditorKey,
+  AllEditorTheme, AllKeyMap,
+} from '../../consts';
 import { useCodeMirrorEditorIsolated } from '../../stores';
 
 export const InitEditorValueRow = (): JSX.Element => {

+ 2 - 1
packages/editor/src/consts/editor-settings.ts

@@ -1,4 +1,5 @@
-import { EditorTheme, KeyMapMode } from '../services';
+import type { EditorTheme } from './editor-themes';
+import type { KeyMapMode } from './keymaps';
 
 export interface EditorSettings {
   theme: undefined | EditorTheme,

+ 16 - 0
packages/editor/src/consts/editor-themes.ts

@@ -0,0 +1,16 @@
+const EditorTheme = {
+  defaultlight: 'defaultlight',
+  eclipse: 'eclipse',
+  basic: 'basic',
+  ayu: 'ayu',
+  rosepine:  'rosepine',
+  defaultdark: 'defaultdark',
+  material: 'material',
+  nord: 'nord',
+  cobalt: 'cobalt',
+  kimbie: 'kimbie',
+} as const;
+
+export const DEFAULT_THEME = 'defaultlight';
+export const AllEditorTheme = Object.values(EditorTheme);
+export type EditorTheme = typeof EditorTheme[keyof typeof EditorTheme];

+ 2 - 0
packages/editor/src/consts/index.ts

@@ -1,3 +1,5 @@
 export * from './global-code-mirror-editor-key';
 export * from './ydoc-awareness-user-color';
 export * from './editor-settings';
+export * from './editor-themes';
+export * from './keymaps';

+ 10 - 0
packages/editor/src/consts/keymaps.ts

@@ -0,0 +1,10 @@
+const KeyMapMode = {
+  default: 'default',
+  vim: 'vim',
+  emacs: 'emacs',
+  vscode: 'vscode',
+} as const;
+
+export const DEFAULT_KEYMAP = 'default';
+export const AllKeyMap = Object.values(KeyMapMode);
+export type KeyMapMode = typeof KeyMapMode[keyof typeof KeyMapMode];

+ 1 - 0
packages/editor/src/index.ts

@@ -1,4 +1,5 @@
 export * from './components';
 export * from './consts';
+export * from './models';
 export * from './services';
 export * from './stores';

+ 0 - 0
packages/editor/src/services/table-util/index.ts → packages/editor/src/models/index.ts


+ 0 - 0
packages/editor/src/services/table-util/markdown-table.d.ts → packages/editor/src/models/markdown-table.d.ts


+ 0 - 0
packages/editor/src/services/table-util/markdown-table.js → packages/editor/src/models/markdown-table.js


+ 0 - 0
packages/editor/src/services/editor-theme/.eslintrc.cjs → packages/editor/src/services-internal/editor-theme/.eslintrc.cjs


+ 0 - 0
packages/editor/src/services/editor-theme/ayu.ts → packages/editor/src/services-internal/editor-theme/ayu.ts


+ 0 - 0
packages/editor/src/services/editor-theme/cobalt.ts → packages/editor/src/services-internal/editor-theme/cobalt.ts


+ 0 - 0
packages/editor/src/services/editor-theme/eclipse.ts → packages/editor/src/services-internal/editor-theme/eclipse.ts


+ 3 - 18
packages/editor/src/services/editor-theme/index.ts → packages/editor/src/services-internal/editor-theme/index.ts

@@ -1,4 +1,6 @@
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
+
+import type { EditorTheme } from '../../consts';
 
 export const getEditorTheme = async(themeName?: EditorTheme): Promise<Extension> => {
   switch (themeName) {
@@ -23,20 +25,3 @@ export const getEditorTheme = async(themeName?: EditorTheme): Promise<Extension>
   }
   return (await import('./original-light')).originalLight;
 };
-
-const EditorTheme = {
-  defaultlight: 'defaultlight',
-  eclipse: 'eclipse',
-  basic: 'basic',
-  ayu: 'ayu',
-  rosepine:  'rosepine',
-  defaultdark: 'defaultdark',
-  material: 'material',
-  nord: 'nord',
-  cobalt: 'cobalt',
-  kimbie: 'kimbie',
-} as const;
-
-export const DEFAULT_THEME = 'defaultlight';
-export const AllEditorTheme = Object.values(EditorTheme);
-export type EditorTheme = typeof EditorTheme[keyof typeof EditorTheme]

+ 1 - 1
packages/editor/src/services/editor-theme/material.ts → packages/editor/src/services-internal/editor-theme/material.ts

@@ -1,6 +1,6 @@
 // Ref: https://github.com/craftzdog/cm6-themes/blob/289d9e0ca6b500f4cdf68464f4f21dd8e2dd8963/packages/material-dark/src/index.ts
 import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
 import { EditorView } from '@codemirror/view';
 import { tags as t } from '@lezer/highlight';
 

+ 1 - 1
packages/editor/src/services/editor-theme/nord.ts → packages/editor/src/services-internal/editor-theme/nord.ts

@@ -1,7 +1,7 @@
 // Ref: https://github.com/craftzdog/cm6-themes/blob/221936c525dcfc05b298cc4d4a0ba284cb7c7138/packages/nord/src/index.ts
 
 import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
 import { EditorView } from '@codemirror/view';
 import { tags as t } from '@lezer/highlight';
 

+ 0 - 0
packages/editor/src/services/editor-theme/original-dark.ts → packages/editor/src/services-internal/editor-theme/original-dark.ts


+ 1 - 1
packages/editor/src/services/editor-theme/original-light.ts → packages/editor/src/services-internal/editor-theme/original-light.ts

@@ -1,6 +1,6 @@
 // Ref: https://github.com/uiwjs/react-codemirror/blob/bf3b862923d0cb04ccf4bb9da0791bdc7fd6d29b/themes/github/src/index.ts
 
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
 import { tags as t } from '@lezer/highlight';
 import { createTheme } from '@uiw/codemirror-themes';
 

+ 0 - 0
packages/editor/src/services/editor-theme/rose-pine.ts → packages/editor/src/services-internal/editor-theme/rose-pine.ts


+ 0 - 0
packages/editor/src/services/extensions/emojiAutocompletionSettings.ts → packages/editor/src/services-internal/extensions/emojiAutocompletionSettings.ts


+ 2 - 0
packages/editor/src/services-internal/extensions/index.ts

@@ -0,0 +1,2 @@
+export * from './emojiAutocompletionSettings';
+export * from './setDataLine';

+ 2 - 3
packages/editor/src/services/extensions/setDataLine.ts → packages/editor/src/services-internal/extensions/setDataLine.ts

@@ -3,9 +3,8 @@
 
 
 import { RangeSetBuilder } from '@codemirror/state';
-import {
-  EditorView, Decoration, ViewPlugin, DecorationSet, ViewUpdate,
-} from '@codemirror/view';
+import type { EditorView, DecorationSet, ViewUpdate } from '@codemirror/view';
+import { Decoration, ViewPlugin } from '@codemirror/view';
 
 const stripeDeco = (view: EditorView) => {
   const builder = new RangeSetBuilder<Decoration>();

+ 0 - 0
packages/editor/src/services/file-dropzone/index.ts → packages/editor/src/services-internal/file-dropzone/index.ts


+ 19 - 0
packages/editor/src/services-internal/file-dropzone/use-file-dropzone/FileDropzoneOverlay.tsx

@@ -0,0 +1,19 @@
+type Props = {
+  isEnabled: boolean,
+}
+
+export const FileDropzoneOverlay = (props: Props): JSX.Element => {
+  const { isEnabled } = props;
+
+  if (isEnabled) {
+    return (
+      <div className="overlay overlay-dropzone-active">
+        <span className="overlay-content">
+          <span className="overlay-icon material-symbols-outlined">
+          </span>
+        </span>
+      </div>
+    );
+  }
+  return <></>;
+};

+ 2 - 2
packages/editor/src/services/file-dropzone/use-file-dropzone/use-file-dropzone.ts → packages/editor/src/services-internal/file-dropzone/use-file-dropzone/use-file-dropzone.ts

@@ -1,8 +1,8 @@
 import { useCallback, useState } from 'react';
 
 import { AcceptedUploadFileType } from '@growi/core';
-import { useDropzone, Accept } from 'react-dropzone';
-import type { DropzoneOptions, DropzoneState } from 'react-dropzone';
+import { useDropzone } from 'react-dropzone';
+import type { DropzoneOptions, DropzoneState, Accept } from 'react-dropzone';
 
 
 type FileDropzoneState = DropzoneState & {

+ 8 - 0
packages/editor/src/services-internal/index.ts

@@ -0,0 +1,8 @@
+export * from './editor-theme';
+export * from './extensions';
+export * from './file-dropzone';
+export * from './keymaps';
+export * from './link-util';
+export * from './list-util';
+export * from './paste-util';
+export * from './table';

+ 3 - 12
packages/editor/src/services/keymaps/index.ts → packages/editor/src/services-internal/keymaps/index.ts

@@ -1,6 +1,8 @@
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
 import { keymap } from '@codemirror/view';
 
+import type { KeyMapMode } from '../../consts';
+
 
 export const getKeymap = async(keyMapName?: KeyMapMode, onSave?: () => void): Promise<Extension> => {
   switch (keyMapName) {
@@ -13,14 +15,3 @@ export const getKeymap = async(keyMapName?: KeyMapMode, onSave?: () => void): Pr
   }
   return keymap.of((await import('@codemirror/commands')).defaultKeymap);
 };
-
-const KeyMapMode = {
-  default: 'default',
-  vim: 'vim',
-  emacs: 'emacs',
-  vscode: 'vscode',
-} as const;
-
-export const DEFAULT_KEYMAP = 'default';
-export const AllKeyMap = Object.values(KeyMapMode);
-export type KeyMapMode = typeof KeyMapMode[keyof typeof KeyMapMode];

+ 1 - 1
packages/editor/src/services/keymaps/vim.ts → packages/editor/src/services-internal/keymaps/vim.ts

@@ -1,4 +1,4 @@
-import { Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
 import { Vim, vim } from '@replit/codemirror-vim';
 
 // vim useful keymap custom

+ 1 - 1
packages/editor/src/services/link-util/Linker.ts → packages/editor/src/services-internal/link-util/Linker.ts

@@ -1,6 +1,6 @@
 import { encodeSpaces } from '@growi/core/dist/utils/page-path-utils';
 
-export default class Linker {
+export class Linker {
 
   type: string;
 

+ 2 - 0
packages/editor/src/services-internal/link-util/index.ts

@@ -0,0 +1,2 @@
+export * from './Linker';
+export * from './markdown-link-util';

+ 1 - 1
packages/editor/src/services/link-util/markdown-link-util.ts → packages/editor/src/services-internal/link-util/markdown-link-util.ts

@@ -1,6 +1,6 @@
 import type { EditorView } from '@codemirror/view';
 
-import Linker from './Linker';
+import { Linker } from './Linker';
 
 const curPos = (editor: EditorView) => {
   return editor.state.selection.main.head;

+ 1 - 0
packages/editor/src/services-internal/list-util/index.ts

@@ -0,0 +1 @@
+export * from './insert-newline-continue-markup';

+ 1 - 1
packages/editor/src/services/list-util/insert-newline-continue-markup.ts → packages/editor/src/services-internal/list-util/insert-newline-continue-markup.ts

@@ -1,5 +1,5 @@
 import type { ChangeSpec } from '@codemirror/state';
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 // https://regex101.com/r/r9plEA/1
 const indentAndMarkRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]\s))(\s*)/;

+ 1 - 0
packages/editor/src/services-internal/paste-util/index.ts

@@ -0,0 +1 @@
+export * from './paste-markdown-util';

+ 0 - 0
packages/editor/src/services/paste-util/paste-markdown-util.ts → packages/editor/src/services-internal/paste-util/paste-markdown-util.ts


+ 2 - 0
packages/editor/src/services-internal/table/index.ts

@@ -0,0 +1,2 @@
+export * from './insert-new-row-to-table-markdown';
+export * from './use-show-table-icon';

+ 2 - 2
packages/editor/src/services/table-util/insert-new-row-to-table-markdown.ts → packages/editor/src/services-internal/table/insert-new-row-to-table-markdown.ts

@@ -1,6 +1,6 @@
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
-import { MarkdownTable } from './markdown-table';
+import { MarkdownTable } from '../../models';
 
 // https://regex101.com/r/7BN2fR/10
 const linePartOfTableRE = /^([^\r\n|]*)\|(([^\r\n|]*\|)+)$/;

+ 2 - 2
packages/editor/src/services/table-util/use-show-table-icon.ts → packages/editor/src/services-internal/table/use-show-table-icon.ts

@@ -1,10 +1,10 @@
 import { useEffect, useState } from 'react';
 
-import { ViewUpdate } from '@codemirror/view';
+import type { ViewUpdate } from '@codemirror/view';
 import { EditorView } from 'codemirror';
 
 
-import { UseCodeMirrorEditor } from '../codemirror-editor';
+import type { UseCodeMirrorEditor } from '../../services';
 
 import { isInTable } from './insert-new-row-to-table-markdown';
 

+ 0 - 1
packages/editor/src/services/codemirror-editor/index.ts

@@ -1 +0,0 @@
-export * from './use-codemirror-editor/use-codemirror-editor';

+ 0 - 19
packages/editor/src/services/file-dropzone/use-file-dropzone/FileDropzoneOverlay.tsx

@@ -1,19 +0,0 @@
-type Props = {
-  isEnabled: boolean,
-}
-
-export const FileDropzoneOverlay = (props: Props) => {
-  const { isEnabled } = props;
-
-    if (isEnabled) {
-      return (
-        <div className="overlay overlay-dropzone-active">
-          <span className="overlay-content">
-            <span className="overlay-icon material-symbols-outlined">
-            </span>
-          </span>
-        </div>
-      );
-    }
-    return <></>;
-}

+ 1 - 4
packages/editor/src/services/index.ts

@@ -1,4 +1 @@
-export * from './codemirror-editor';
-export * from './file-dropzone';
-export * from './editor-theme';
-export * from './keymaps';
+export * from './use-codemirror-editor';

+ 1 - 0
packages/editor/src/services/use-codemirror-editor/index.ts

@@ -0,0 +1 @@
+export * from './use-codemirror-editor';

+ 4 - 3
packages/editor/src/services/codemirror-editor/use-codemirror-editor/use-codemirror-editor.ts → packages/editor/src/services/use-codemirror-editor/use-codemirror-editor.ts

@@ -1,15 +1,16 @@
 import { useMemo } from 'react';
 
-import {
+import type {
   EditorState,
 } from '@codemirror/state';
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 import { useCodeMirror, type UseCodeMirror } from '@uiw/react-codemirror';
 import deepmerge from 'ts-deepmerge';
 
 import { useAppendExtensions, type AppendExtensions } from './utils/append-extensions';
 import { useFocus, type Focus } from './utils/focus';
-import { FoldDrawio, useFoldDrawio } from './utils/fold-drawio';
+import type { FoldDrawio } from './utils/fold-drawio';
+import { useFoldDrawio } from './utils/fold-drawio';
 import { useGetDoc, type GetDoc } from './utils/get-doc';
 import { useInitDoc, type InitDoc } from './utils/init-doc';
 import { useInsertMarkdownElements, type InsertMarkdowElements } from './utils/insert-markdown-elements';

+ 3 - 2
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/append-extensions.ts → packages/editor/src/services/use-codemirror-editor/utils/append-extensions.ts

@@ -1,7 +1,8 @@
 import { useCallback } from 'react';
 
-import { Compartment, Extension, StateEffect } from '@codemirror/state';
-import { EditorView } from '@codemirror/view';
+import type { Extension } from '@codemirror/state';
+import { Compartment, StateEffect } from '@codemirror/state';
+import type { EditorView } from '@codemirror/view';
 
 type CleanupFunctions = () => void;
 export type AppendExtensions = (extensions: Extension | Extension[]) => CleanupFunctions | undefined;

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/focus.ts → packages/editor/src/services/use-codemirror-editor/utils/focus.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type Focus = () => void;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/fold-drawio.ts → packages/editor/src/services/use-codemirror-editor/utils/fold-drawio.ts

@@ -1,7 +1,7 @@
 import { useEffect } from 'react';
 
 import { foldEffect } from '@codemirror/language';
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type FoldDrawio = void;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/get-doc.ts → packages/editor/src/services/use-codemirror-editor/utils/get-doc.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type GetDoc = () => string;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/init-doc.ts → packages/editor/src/services/use-codemirror-editor/utils/init-doc.ts

@@ -1,7 +1,7 @@
 import { useCallback } from 'react';
 
 import { Transaction } from '@codemirror/state';
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type InitDoc = (doc?: string) => void;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-markdown-elements.ts → packages/editor/src/services/use-codemirror-editor/utils/insert-markdown-elements.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type InsertMarkdowElements = (
   prefix: string,

+ 3 - 2
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-prefix.ts → packages/editor/src/services/use-codemirror-editor/utils/insert-prefix.ts

@@ -1,6 +1,7 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { ChangeSpec } from '@codemirror/state';
+import type { EditorView } from '@codemirror/view';
 
 export type InsertPrefix = (prefix: string, noSpaceIfPrefixExists?: boolean) => void;
 
@@ -16,7 +17,7 @@ export const useInsertPrefix = (view?: EditorView): InsertPrefix => {
     const endLine = view.state.doc.lineAt(to);
 
     // Insert prefix for each line
-    const lines = [];
+    const lines: ChangeSpec[] = [];
     let insertTextLength = 0;
     for (let i = startLine.number; i <= endLine.number; i++) {
       const line = view.state.doc.line(i);

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/insert-text.ts → packages/editor/src/services/use-codemirror-editor/utils/insert-text.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type InsertText = (text: string) => void;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/replace-text.ts → packages/editor/src/services/use-codemirror-editor/utils/replace-text.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type ReplaceText = (text: string) => void;
 

+ 1 - 1
packages/editor/src/services/codemirror-editor/use-codemirror-editor/utils/set-caret-line.ts → packages/editor/src/services/use-codemirror-editor/utils/set-caret-line.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 
 export type SetCaretLine = (lineNumber?: number) => void;
 

+ 1 - 2
packages/editor/src/stores/codemirror-editor.ts

@@ -5,8 +5,7 @@ import type { ReactCodeMirrorProps, UseCodeMirror } from '@uiw/react-codemirror'
 import type { SWRResponse } from 'swr';
 import deepmerge from 'ts-deepmerge';
 
-import type { UseCodeMirrorEditor } from '../services';
-import { useCodeMirrorEditor } from '../services';
+import { type UseCodeMirrorEditor, useCodeMirrorEditor } from '../services';
 
 
 const isValid = (u: UseCodeMirrorEditor) => {

+ 1 - 1
packages/editor/src/stores/use-collaborative-editor-mode.ts

@@ -8,7 +8,7 @@ import { SocketIOProvider } from 'y-socket.io';
 import * as Y from 'yjs';
 
 import { userColor } from '../consts';
-import { UseCodeMirrorEditor } from '../services';
+import type { UseCodeMirrorEditor } from '../services';
 
 type UserLocalState = {
   name: string;

+ 3 - 2
packages/editor/src/stores/use-default-extensions.ts

@@ -7,11 +7,12 @@ import { languages } from '@codemirror/language-data';
 import {
   Prec, type Extension,
 } from '@codemirror/state';
-import { keymap, EditorView, KeyBinding } from '@codemirror/view';
+import type { KeyBinding } from '@codemirror/view';
+import { keymap, EditorView } from '@codemirror/view';
 import { tags } from '@lezer/highlight';
 
 import type { UseCodeMirrorEditor } from '../services';
-import { emojiAutocompletionSettings } from '../services/extensions/emojiAutocompletionSettings';
+import { emojiAutocompletionSettings } from '../services-internal';
 
 
 // set new markdownKeymap instead of default one

+ 8 - 6
packages/editor/src/stores/use-editor-settings.ts

@@ -1,15 +1,17 @@
 import { useEffect, useCallback, useState } from 'react';
 
-import { Prec, Extension } from '@codemirror/state';
+import type { Extension } from '@codemirror/state';
+import { Prec } from '@codemirror/state';
 import {
   keymap, type Command, highlightActiveLine, highlightActiveLineGutter,
 } from '@codemirror/view';
 
-import type { EditorSettings } from '../consts';
-import type { UseCodeMirrorEditor, EditorTheme, KeyMapMode } from '../services';
-import { getEditorTheme, getKeymap } from '../services';
-import { insertNewlineContinueMarkup } from '../services/list-util/insert-newline-continue-markup';
-import { insertNewRowToMarkdownTable, isInTable } from '../services/table-util/insert-new-row-to-table-markdown';
+import type { EditorSettings, KeyMapMode, EditorTheme } from '../consts';
+import type { UseCodeMirrorEditor } from '../services';
+import {
+  getEditorTheme, getKeymap, insertNewlineContinueMarkup, insertNewRowToMarkdownTable, isInTable,
+} from '../services-internal';
+
 
 export const useEditorSettings = (
     codeMirrorEditor?: UseCodeMirrorEditor,

+ 1 - 1
packages/editor/src/stores/use-handsontable.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { EditorView } from '@codemirror/view';
+import type { EditorView } from '@codemirror/view';
 import { useSWRStatic } from '@growi/core/dist/swr';
 import type { SWRResponse } from 'swr';
 

+ 2 - 2
packages/editor/src/stores/use-link-edit-modal.ts

@@ -1,7 +1,7 @@
 import { useSWRStatic } from '@growi/core/dist/swr';
-import { SWRResponse } from 'swr';
+import type { SWRResponse } from 'swr';
 
-import Linker from '../services/link-util/Linker';
+import type { Linker } from '../services-internal';
 
 type LinkEditModalStatus = {
   isOpened: boolean,

+ 1 - 1
packages/editor/src/stores/use-resolved-theme.ts

@@ -1,6 +1,6 @@
 import { useCallback } from 'react';
 
-import { ColorScheme } from '@growi/core';
+import type { ColorScheme } from '@growi/core';
 import { useSWRStatic } from '@growi/core/dist/swr';
 import type { SWRResponse } from 'swr';
 import { mutate } from 'swr';