diff --git a/.github/workflows/affine.yml b/.github/workflows/affine.yml index 28ca2d429b..a5c0eafe70 100644 --- a/.github/workflows/affine.yml +++ b/.github/workflows/affine.yml @@ -3,8 +3,8 @@ name: Build AFFiNE-Local on: push: branches: [master] - pull_request: - branches: [master] + # pull_request: + # branches: [master] # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000000..e1a982e4f1 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,28 @@ +name: standard check + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + main: + name: Nx Cloud - Main Job + uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.6 + secrets: inherit + with: + main-branch-name: master + number-of-agents: 3 + parallel-commands: | + pnpm exec nx-cloud record -- pnpm exec nx format:check + parallel-commands-on-agents: | + pnpm exec nx affected --target=lint --parallel=3 --exclude=components-common,keck,theme + pnpm exec nx affected --target=build --parallel=3 + + agents: + name: Nx Cloud - Agents + uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.6 + secrets: inherit + with: + number-of-agents: 3 diff --git a/.github/workflows/keck.yml b/.github/workflows/keck.yml index a09d790455..32e1d56058 100644 --- a/.github/workflows/keck.yml +++ b/.github/workflows/keck.yml @@ -8,12 +8,12 @@ on: - 'apps/keck/**' - '.github/deployment' - '.github/workflows/keck.yml' - pull_request: - branches: [master] - paths: - - 'apps/keck/**' - - '.github/deployment' - - '.github/workflows/keck.yml' + # pull_request: + # branches: [master] + # paths: + # - 'apps/keck/**' + # - '.github/deployment' + # - '.github/workflows/keck.yml' # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8266d460df..8efce5cbd4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,8 +3,8 @@ name: Lint on: push: branches: [master] - pull_request: - branches: [master] + # pull_request: + # branches: [master] # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency diff --git a/.github/workflows/lisa.yml b/.github/workflows/lisa.yml index ead4c8fff2..f548ddeeed 100644 --- a/.github/workflows/lisa.yml +++ b/.github/workflows/lisa.yml @@ -3,8 +3,8 @@ name: Build Lisa on: push: branches: [master] - pull_request: - branches: [master] + # pull_request: + # branches: [master] # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency diff --git a/.github/workflows/venus.yml b/.github/workflows/venus.yml index 8b8841404c..699cf44dd3 100644 --- a/.github/workflows/venus.yml +++ b/.github/workflows/venus.yml @@ -7,11 +7,11 @@ on: - 'apps/venus/**' - '.github/deployment' - '.github/workflows/venus.yml' - pull_request: - branches: [master] - paths: - - 'apps/venus/**' - - '.github/workflows/venus.yml' + # pull_request: + # branches: [master] + # paths: + # - 'apps/venus/**' + # - '.github/workflows/venus.yml' # Cancels all previous workflow runs for pull requests that have not completed. # See https://docs.github.com/en/actions/using-jobs/using-concurrency diff --git a/apps/keck/src/index.ts b/apps/keck/src/index.ts index d76df31b53..31dadb7893 100644 --- a/apps/keck/src/index.ts +++ b/apps/keck/src/index.ts @@ -34,34 +34,31 @@ const _checkAuth = async ( response: http.ServerResponse, callback: (response: http.OutgoingMessage, workspace: string) => boolean ) => { + const url = new URL(request.url, `http://${request.headers.host}`); + const workspace = _getWorkspace(url.pathname); if (process.env.NODE_ENV === 'development') { - const url = new URL(request.url, `http://${request.headers.host}`); - const workspace = _getWorkspace(url.pathname); if (workspace) return callback(response, workspace); return false; - } else { - try { - const decodedToken = await firebaseAuth - .getAuth() - .verifyIdToken(request.headers.token as string); - const allowWorkspace = [AFFINE_COMMON_WORKSPACE, decodedToken.uid]; - const url = new URL(request.url, `http://${request.headers.host}`); - const workspace = _getWorkspace(url.pathname); - if (allowWorkspace.includes(workspace)) { - return callback(response, workspace); - } - } catch (error) { - console.log(error); - } - return false; } + try { + const decodedToken = await firebaseAuth + .getAuth() + .verifyIdToken(request.headers.token as string); + const allowWorkspace = [AFFINE_COMMON_WORKSPACE, decodedToken.uid]; + if (allowWorkspace.includes(workspace)) { + return callback(response, workspace); + } + } catch (error) { + console.log(error); + } + return false; }; const HOST = process.env.HOST || 'localhost'; const PORT = process.env.PORT || 3000; const _tokens = new LRUCache({ - max: 10240, + max: 1024 * 10, ttl: 1000 * 60 * 5, }); diff --git a/apps/ligo-virgo/src/pages/workspace/Home.tsx b/apps/ligo-virgo/src/pages/workspace/Home.tsx index c8ce89b6d4..a424a2052d 100644 --- a/apps/ligo-virgo/src/pages/workspace/Home.tsx +++ b/apps/ligo-virgo/src/pages/workspace/Home.tsx @@ -10,16 +10,13 @@ export function WorkspaceHome() { useEffect(() => { const navigate_to_user_initial_page = async () => { - const recent_pages = await services.api.userConfig.getRecentPages( - workspace_id, - user.id - ); - - const user_initial_page_id = - await services.api.userConfig.getUserInitialPage( + const [recent_pages, user_initial_page_id] = await Promise.all([ + services.api.userConfig.getRecentPages(workspace_id, user.id), + services.api.userConfig.getUserInitialPage( workspace_id, user.id - ); + ), + ]); if (recent_pages.length === 0) { await services.api.editorBlock.copyTemplateToPage( workspace_id, diff --git a/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx b/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx index 2513ce3c08..76c48efeb6 100644 --- a/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx +++ b/apps/ligo-virgo/src/pages/workspace/docs/Page.tsx @@ -93,43 +93,29 @@ const EditorContainer = ({ workspace: string; }) => { const [lockScroll, setLockScroll] = useState(false); - const scrollContainerRef = useRef(); + const [scrollContainer, setScrollContainer] = useState(); const editorRef = useRef(); + const onScroll = (event: UIEvent) => { editorRef.current.getHooks().onRootNodeScroll(event); editorRef.current.scrollManager.emitScrollEvent(event); }; - useEffect(() => { - editorRef.current.scrollManager.scrollContainer = - scrollContainerRef.current; - - editorRef.current.scrollManager.scrollController = { - lockScroll: () => setLockScroll(true), - unLockScroll: () => setLockScroll(false), - }; - }, []); - const { setPageClientWidth } = usePageClientWidth(); useEffect(() => { - if (scrollContainerRef.current) { + if (scrollContainer) { const obv = new ResizeObserver(e => { setPageClientWidth(e[0].contentRect.width); }); - obv.observe(scrollContainerRef.current); + obv.observe(scrollContainer); return () => obv.disconnect(); } - }, [setPageClientWidth]); + }, [setPageClientWidth, scrollContainer]); return ( { - scrollContainerRef.current = ref; - if (editorRef.current?.scrollManager) { - editorRef.current.scrollManager.scrollContainer = ref; - } - }} + ref={ref => setScrollContainer(ref)} onScroll={onScroll} > {pageId ? ( @@ -137,6 +123,11 @@ const EditorContainer = ({ workspace={workspace} rootBlockId={pageId} ref={editorRef} + scrollContainer={scrollContainer} + scrollController={{ + lockScroll: () => setLockScroll(true), + unLockScroll: () => setLockScroll(false), + }} /> ) : ( { > diff --git a/apps/ligo-virgo/src/pages/workspace/docs/components/tabs/Tabs.tsx b/apps/ligo-virgo/src/pages/workspace/docs/components/tabs/Tabs.tsx index 3722c5e162..fc06d826bc 100644 --- a/apps/ligo-virgo/src/pages/workspace/docs/components/tabs/Tabs.tsx +++ b/apps/ligo-virgo/src/pages/workspace/docs/components/tabs/Tabs.tsx @@ -11,15 +11,15 @@ const StyledTabs = styled('div')({ cursor: 'pointer', }); -const StyledDivider = styled(Divider)<{ isActive?: boolean }>( - ({ isActive }) => { - return { - flex: 1, - backgroundColor: isActive ? '#3E6FDB' : '#ECF1FB', - borderWidth: '2px', - }; - } -); +const StyledDivider = styled(Divider, { + shouldForwardProp: (prop: string) => !['isActive'].includes(prop), +})<{ isActive?: boolean }>(({ isActive }) => { + return { + flex: 1, + backgroundColor: isActive ? '#3E6FDB' : '#ECF1FB', + borderWidth: '2px', + }; +}); const TAB_TITLE = { PAGES: 'pages', diff --git a/apps/ligo-virgo/src/pages/workspace/docs/workspace-name.tsx b/apps/ligo-virgo/src/pages/workspace/docs/workspace-name.tsx index cf6f3a0313..6311497161 100644 --- a/apps/ligo-virgo/src/pages/workspace/docs/workspace-name.tsx +++ b/apps/ligo-virgo/src/pages/workspace/docs/workspace-name.tsx @@ -95,15 +95,11 @@ export const WorkspaceName = () => { if (!currentSpaceId) { return; } - - const name = await services.api.userConfig.getWorkspaceName( - currentSpaceId - ); + const [name, workspaceId] = await Promise.all([ + services.api.userConfig.getWorkspaceName(currentSpaceId), + services.api.userConfig.getWorkspaceId(currentSpaceId), + ]); setWorkspaceName(name); - - const workspaceId = await services.api.userConfig.getWorkspaceId( - currentSpaceId - ); setWorkspaceId(workspaceId); }, [currentSpaceId]); diff --git a/apps/ligo-virgo/webpack.config.js b/apps/ligo-virgo/webpack.config.js index edb5305b2b..fffec29165 100644 --- a/apps/ligo-virgo/webpack.config.js +++ b/apps/ligo-virgo/webpack.config.js @@ -34,11 +34,6 @@ module.exports = function (webpackConfig) { if (isProd) { config.module.rules.unshift(style9); - } else { - config.module.rules.push(style9); - } - - if (isProd) { config.entry = { main: [...config.entry.main, ...config.entry.polyfills], }; @@ -133,6 +128,7 @@ module.exports = function (webpackConfig) { }); config.module.rules.splice(6); } else { + config.module.rules.push(style9); config.output = { ...config.output, publicPath: '/', diff --git a/apps/venus/webpack.config.js b/apps/venus/webpack.config.js index 9b5aba0eef..c325851149 100644 --- a/apps/venus/webpack.config.js +++ b/apps/venus/webpack.config.js @@ -35,11 +35,6 @@ module.exports = function (webpackConfig) { if (isProd) { config.module.rules.unshift(style9); - } else { - config.module.rules.push(style9); - } - - if (isProd) { config.entry = { main: [...config.entry.main, ...config.entry.polyfills], }; @@ -124,6 +119,7 @@ module.exports = function (webpackConfig) { }); config.module.rules.splice(6); } else { + config.module.rules.push(style9); config.output = { ...config.output, publicPath: '/', diff --git a/libs/components/affine-editor/src/Editor.tsx b/libs/components/affine-editor/src/Editor.tsx index 62f266b46c..4f842de2fd 100644 --- a/libs/components/affine-editor/src/Editor.tsx +++ b/libs/components/affine-editor/src/Editor.tsx @@ -18,6 +18,12 @@ interface AffineEditorProps { scrollBlank?: boolean; isWhiteboard?: boolean; + + scrollContainer?: HTMLElement; + scrollController?: { + lockScroll: () => void; + unLockScroll: () => void; + }; } function _useConstantWithDispose( @@ -53,13 +59,32 @@ function _useConstantWithDispose( } export const AffineEditor = forwardRef( - ({ workspace, rootBlockId, scrollBlank = true, isWhiteboard }, ref) => { + ( + { + workspace, + rootBlockId, + scrollBlank = true, + isWhiteboard, + scrollController, + scrollContainer, + }, + ref + ) => { const editor = _useConstantWithDispose( workspace, rootBlockId, isWhiteboard ); + useEffect(() => { + if (scrollContainer) { + editor.scrollManager.scrollContainer = scrollContainer; + } + if (scrollController) { + editor.scrollManager.scrollController = scrollController; + } + }, [editor, scrollContainer, scrollController]); + useImperativeHandle(ref, () => editor); return ( diff --git a/libs/components/editor-blocks/package.json b/libs/components/editor-blocks/package.json index d497e04e0f..d558743117 100644 --- a/libs/components/editor-blocks/package.json +++ b/libs/components/editor-blocks/package.json @@ -31,6 +31,7 @@ "@mui/system": "^5.8.6", "code-example": "^3.3.6", "codemirror": "6.0.1", + "codemirror-lang-elixir": "^3.0.0", "keymap": "link:@codemirror/next/keymap", "nanoid": "^4.0.0", "react-resizable": "^3.0.4", diff --git a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx index 3b64cc3b1a..9ce542acf2 100644 --- a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx +++ b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx @@ -1,10 +1,9 @@ -import { FC, useState, useMemo, useRef, useEffect } from 'react'; +import { FC, useState, useRef, useEffect } from 'react'; import { StyleWithAtRules } from 'style9'; import { CreateView } from '@toeverything/framework/virgo'; -import CodeMirror from './CodeMirror'; +import CodeMirror, { ReactCodeMirrorRef } from './CodeMirror'; import { styled } from '@toeverything/components/ui'; -import DeleteSweepOutlinedIcon from '@mui/icons-material/DeleteSweepOutlined'; import { javascript } from '@codemirror/lang-javascript'; import { html } from '@codemirror/lang-html'; @@ -32,6 +31,7 @@ import { powerShell } from '@codemirror/legacy-modes/mode/powershell'; import { brainfuck } from '@codemirror/legacy-modes/mode/brainfuck'; import { stylus } from '@codemirror/legacy-modes/mode/stylus'; import { erlang } from '@codemirror/legacy-modes/mode/erlang'; +import { elixir } from 'codemirror-lang-elixir'; import { nginx } from '@codemirror/legacy-modes/mode/nginx'; import { perl } from '@codemirror/legacy-modes/mode/perl'; import { pascal } from '@codemirror/legacy-modes/mode/pascal'; @@ -45,7 +45,6 @@ import { dockerFile } from '@codemirror/legacy-modes/mode/dockerfile'; import { julia } from '@codemirror/legacy-modes/mode/julia'; import { r } from '@codemirror/legacy-modes/mode/r'; import { Extension } from '@codemirror/state'; -// import { Select } from '../../components/select'; import { Option, Select } from '@toeverything/components/ui'; import { @@ -87,6 +86,7 @@ const langs: Record = { brainfuck: () => StreamLanguage.define(brainfuck), stylus: () => StreamLanguage.define(stylus), erlang: () => StreamLanguage.define(erlang), + elixir: () => StreamLanguage.define(elixir), nginx: () => StreamLanguage.define(nginx), perl: () => StreamLanguage.define(perl), ruby: () => StreamLanguage.define(ruby), @@ -100,10 +100,8 @@ const langs: Record = { julia: () => StreamLanguage.define(julia), dockerfile: () => StreamLanguage.define(dockerFile), r: () => StreamLanguage.define(r), - // clike: () => StreamLanguage.define(clike), - // clike: () => clike({ }), }; - +const DEFAULT_LANG = 'javascript'; const CodeBlock = styled('div')(({ theme }) => ({ backgroundColor: '#F2F5F9', padding: '8px 24px', @@ -118,7 +116,7 @@ const CodeBlock = styled('div')(({ theme }) => ({ flexWrap: 'wrap', justifyContent: 'space-between', }, - '.delete-block': { + '.copy-block': { padding: '6px 10px', backgroundColor: '#fff', borderRadius: theme.affine.shape.borderRadius, @@ -130,29 +128,27 @@ const CodeBlock = styled('div')(({ theme }) => ({ })); export const CodeView: FC = ({ block, editor }) => { const initValue: string = block.getProperty('text')?.value?.[0]?.text; - const langType: string = block.getProperty('lang')?.value?.[0]?.text; - const [mode, setMode] = useState('javascript'); + const langType: string = block.getProperty('lang'); const [extensions, setExtensions] = useState(); - const codeMirror = useRef(); - useOnSelect(block.id, (is_select: boolean) => { + const codeMirror = useRef(); + useOnSelect(block.id, (_is_select: boolean) => { if (codeMirror.current) { - //@ts-ignore codeMirror?.current?.view?.focus(); } }); - const onChange = (value: any, codeEditor: any) => { + const onChange = (value: string) => { block.setProperty('text', { value: [{ text: value }], }); }; - useEffect(() => { - handleLangChange(langType ? langType : 'javascript'); - }, []); - function handleLangChange(lang: string) { + const handleLangChange = (lang: string) => { block.setProperty('lang', lang); - setMode(lang); setExtensions([langs[lang]()]); - } + }; + useEffect(() => { + handleLangChange(langType ? langType : DEFAULT_LANG); + }, []); + const copyCode = () => { copyToClipboard(initValue); }; @@ -171,19 +167,12 @@ export const CodeView: FC = ({ block, editor }) => { >
- {/* { - // setSelectedOption(selectedValue); handleLangChange(selectedValue); }} > @@ -197,17 +186,8 @@ export const CodeView: FC = ({ block, editor }) => {
-
+
Copy - {/* */}
diff --git a/libs/components/editor-core/src/ref-page/ModalPage.tsx b/libs/components/editor-core/src/ref-page/ModalPage.tsx index 276d5984d6..52e1d6554f 100644 --- a/libs/components/editor-core/src/ref-page/ModalPage.tsx +++ b/libs/components/editor-core/src/ref-page/ModalPage.tsx @@ -1,7 +1,6 @@ import { MuiBackdrop, styled, useTheme } from '@toeverything/components/ui'; import { createContext, ReactNode, useContext, useState } from 'react'; import { createPortal } from 'react-dom'; -import { useEditor } from '../Contexts'; import { RenderBlock } from '../render-block'; const Dialog = styled('div')({ @@ -44,8 +43,6 @@ const Modal = ({ open, children }: { open: boolean; children?: ReactNode }) => { }; const ModalPage = ({ blockId }: { blockId: string | null }) => { - const { editor } = useEditor(); - return ( {blockId && } diff --git a/libs/components/editor-plugins/src/menu/reference-menu/ReferenceMenu.tsx b/libs/components/editor-plugins/src/menu/reference-menu/ReferenceMenu.tsx index cbd443927a..accd73849b 100644 --- a/libs/components/editor-plugins/src/menu/reference-menu/ReferenceMenu.tsx +++ b/libs/components/editor-plugins/src/menu/reference-menu/ReferenceMenu.tsx @@ -116,7 +116,7 @@ export const ReferenceMenu = ({ editor, hooks, style }: ReferenceMenuProps) => { }; const handle_close = () => { - editor.blockHelper.removeSearchSlash(block_id); + block_id && editor.blockHelper.removeSearchSlash(block_id); }; return ( diff --git a/libs/datasource/db-service/src/services/workspace/page-tree.ts b/libs/datasource/db-service/src/services/workspace/page-tree.ts index 89e85b9998..9b4a348c2f 100644 --- a/libs/datasource/db-service/src/services/workspace/page-tree.ts +++ b/libs/datasource/db-service/src/services/workspace/page-tree.ts @@ -1,5 +1,5 @@ import type { BlockClientInstance } from '@toeverything/datasource/jwt'; -import { PAGE_TREE } from '../../utils'; +import { PAGE_TREE as pageTreeName } from '../../utils'; import type { ReturnUnobserve } from '../database/observer'; import { ServiceBaseClass } from '../base'; import { TreeItem } from './types'; @@ -7,22 +7,22 @@ import { TreeItem } from './types'; export type ObserveCallback = () => void; export class PageTree extends ServiceBaseClass { - private async fetch_page_tree(workspace: string) { - const workspace_db_block = await this.getWorkspaceDbBlock(workspace); - const page_tree_config = - workspace_db_block.getDecoration(PAGE_TREE); - return page_tree_config; + private async _fetchPageTree(workspace: string) { + const workspaceDbBlock = await this.getWorkspaceDbBlock(workspace); + const pageTreeConfig = + workspaceDbBlock.getDecoration(pageTreeName); + return pageTreeConfig; } async getPageTree(workspace: string): Promise { try { - const page_tree = await this.fetch_page_tree(workspace); - if (page_tree && page_tree.length) { + const pageTree = await this._fetchPageTree(workspace); + if (pageTree && pageTree.length) { const db = await this.database.getDatabase(workspace); - const pages = await update_tree_items_title( + const pages = await _updateTreeItemsTitle( db, - page_tree as [], + pageTree as [], {} ); return pages; @@ -36,8 +36,8 @@ export class PageTree extends ServiceBaseClass { /** @deprecated should implement more fine-grained crud methods instead of replacing each time with a new array */ async setPageTree(workspace: string, treeData: TreeItem[]) { - const workspace_db_block = await this.getWorkspaceDbBlock(workspace); - workspace_db_block.setDecoration(PAGE_TREE, treeData); + const workspaceDbBlock = await this.getWorkspaceDbBlock(workspace); + workspaceDbBlock.setDecoration(pageTreeName, treeData); } async addPage(workspace: string, treeData: TreeItem[] | string) { @@ -51,110 +51,107 @@ export class PageTree extends ServiceBaseClass { await dbBlock?.remove(); } - async addPageToWorkspacee( - target_workspace_id: string, - new_page_id: string - ) { - const items = await this.getPageTree(target_workspace_id); - await this.setPageTree(target_workspace_id, [ - { id: new_page_id, children: [] }, + async addPageToWorkspacee(targetWorkspaceId: string, newPageId: string) { + const items = await this.getPageTree(targetWorkspaceId); + await this.setPageTree(targetWorkspaceId, [ + { id: newPageId, children: [] }, ...items, ]); } async addChildPageToWorkspace( - target_workspace_id: string, - parent_page_id: string, - new_page_id: string + targetWorkspaceId: string, + parentPageId: string, + newPageId: string ) { - const pages = await this.getPageTree(target_workspace_id); - this.build_items_for_child_page(parent_page_id, new_page_id, pages); + const pages = await this.getPageTree(targetWorkspaceId); + this._buildItemsForChildPage(parentPageId, newPageId, pages); - await this.setPageTree(target_workspace_id, [...pages]); + await this.setPageTree(targetWorkspaceId, [...pages]); } async addPrevPageToWorkspace( - target_workspace_id: string, - parent_page_id: string, - new_page_id: string + targetWorkspaceId: string, + parentPageId: string, + newPageId: string ) { - const pages = await this.getPageTree(target_workspace_id); - this.build_items_for_prev_page(parent_page_id, new_page_id, pages); - await this.setPageTree(target_workspace_id, [...pages]); + const pages = await this.getPageTree(targetWorkspaceId); + this._buildItemsForPrevPage(parentPageId, newPageId, pages); + await this.setPageTree(targetWorkspaceId, [...pages]); } async addNextPageToWorkspace( - target_workspace_id: string, - parent_page_id: string, - new_page_id: string + targetWorkspaceId: string, + parentPageId: string, + newPageId: string ) { - const pages = await this.getPageTree(target_workspace_id); - this.build_items_for_next_page(parent_page_id, new_page_id, pages); - await this.setPageTree(target_workspace_id, [...pages]); + const pages = await this.getPageTree(targetWorkspaceId); + this._buildItemsForNextPage(parentPageId, newPageId, pages); + await this.setPageTree(targetWorkspaceId, [...pages]); } - private build_items_for_next_page( - parent_page_id: string, - new_page_id: string, + private _buildItemsForNextPage( + parentPageId: string, + newPageId: string, children: TreeItem[] ) { for (let i = 0; i < children.length; i++) { - const child_page = children[i]; - if (child_page.id === parent_page_id) { - const new_page = { - id: new_page_id, + const childPage = children[i]; + if (childPage.id === parentPageId) { + const newPage = { + id: newPageId, title: 'Untitled', children: [] as TreeItem[], }; - children = children.splice(i + 1, 0, new_page); - } else if (child_page.children && child_page.children.length) { - this.build_items_for_next_page( - parent_page_id, - new_page_id, - child_page.children + children = children.splice(i + 1, 0, newPage); + } else if (childPage.children && childPage.children.length) { + this._buildItemsForNextPage( + parentPageId, + newPageId, + childPage.children ); } } } - private build_items_for_prev_page( - parent_page_id: string, - new_page_id: string, + private _buildItemsForPrevPage( + parentPageId: string, + newPageId: string, children: TreeItem[] ) { for (let i = 0; i < children.length; i++) { - const child_page = children[i]; - if (child_page.id === parent_page_id) { - const new_page = { - id: new_page_id, + const childPage = children[i]; + if (childPage.id === parentPageId) { + const newPage = { + id: newPageId, title: 'Untitled', children: [] as TreeItem[], }; - children = children.splice(i - 1, 0, new_page); - } else if (child_page.children && child_page.children.length) { - this.build_items_for_prev_page( - parent_page_id, - new_page_id, - child_page.children + children = children.splice(i - 1, 0, newPage); + } else if (childPage.children && childPage.children.length) { + this._buildItemsForPrevPage( + parentPageId, + newPageId, + childPage.children ); } } } - private build_items_for_child_page( - parent_page_id: string, - new_page_id: string, + private _buildItemsForChildPage( + parentPageId: string, + newPageId: string, children: TreeItem[] ) { for (let i = 0; i < children.length; i++) { - const child_page = children[i]; - if (child_page.id === parent_page_id) { - child_page.children = child_page.children || []; - child_page.children.push({ - id: new_page_id, + const childPage = children[i]; + if (childPage.id === parentPageId) { + childPage.children = childPage.children || []; + childPage.children.push({ + id: newPageId, title: 'Untitled', children: [], }); - } else if (child_page.children && child_page.children.length) { - this.build_items_for_child_page( - parent_page_id, - new_page_id, - child_page.children + } else if (childPage.children && childPage.children.length) { + this._buildItemsForChildPage( + parentPageId, + newPageId, + childPage.children ); } } @@ -164,10 +161,10 @@ export class PageTree extends ServiceBaseClass { { workspace, page }: { workspace: string; page: string }, callback: ObserveCallback ): Promise { - const workspace_db_block = await this.getWorkspaceDbBlock(workspace); + const workspaceDbBlock = await this.getWorkspaceDbBlock(workspace); const unobserveWorkspace = await this._observe( workspace, - workspace_db_block.id, + workspaceDbBlock.id, (states, block) => { callback(); } @@ -187,12 +184,12 @@ export class PageTree extends ServiceBaseClass { } async unobserve({ workspace }: { workspace: string }) { - const workspace_db_block = await this.getWorkspaceDbBlock(workspace); - await this._unobserve(workspace, workspace_db_block.id); + const workspaceDbBlock = await this.getWorkspaceDbBlock(workspace); + await this._unobserve(workspace, workspaceDbBlock.id); } } -async function update_tree_items_title< +async function _updateTreeItemsTitle< TreeItem extends { id: string; title: string; children: TreeItem[] } >( db: BlockClientInstance, @@ -213,7 +210,7 @@ async function update_tree_items_title< } if (item.children.length) { - item.children = await update_tree_items_title( + item.children = await _updateTreeItemsTitle( db, item.children, cache diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 852beb66c2..27172f8157 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -401,6 +401,7 @@ importers: '@types/react-window': ^1.8.5 code-example: ^3.3.6 codemirror: 6.0.1 + codemirror-lang-elixir: ^3.0.0 keymap: link:@codemirror/next/keymap nanoid: ^4.0.0 react-resizable: ^3.0.4 @@ -437,6 +438,7 @@ importers: '@mui/system': 5.8.7_d6menda4vqwq6peqnkbe7mkj4i code-example: 3.3.6 codemirror: 6.0.1 + codemirror-lang-elixir: 3.0.0_@codemirror+language@6.2.0 keymap: link:@codemirror/next/keymap nanoid: 4.0.0 react-resizable: 3.0.4 @@ -4578,8 +4580,8 @@ packages: dependencies: '@babel/runtime': 7.18.6 '@emotion/cache': 11.9.3 - '@emotion/react': 11.9.3 - '@emotion/styled': 11.9.3_@emotion+react@11.9.3 + '@emotion/react': 11.9.3_@babel+core@7.18.6 + '@emotion/styled': 11.9.3_dc5dh2wp562rsjxvguwi2i3yzq csstype: 3.1.0 prop-types: 15.8.1 dev: false @@ -8518,6 +8520,14 @@ packages: engines: {node: '>=0.10.0'} dev: true + /codemirror-lang-elixir/3.0.0_@codemirror+language@6.2.0: + resolution: {integrity: sha512-Liy5MDxf+xw7aFqNfhLfntSK6vsRkI0lSlyytw23P1hWSrb0Bw5WunEB3iKJ49iUu8Kj2dx+vvMqD8I5ms7rSQ==} + peerDependencies: + '@codemirror/language': ^6.2.1 + dependencies: + '@codemirror/language': 6.2.0 + dev: false + /codemirror/6.0.1: resolution: {integrity: sha512-J8j+nZ+CdWmIeFIGXEFbFPtpiYacFMDR8GlHK3IyHQJMCaVRfGx9NT+Hxivv1ckLWPvNdZqndbr/7lVhrf/Svg==} dependencies: