From dc4a69593bbd4dff4659219c74a58422e3950104 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:11:28 +0800 Subject: [PATCH 01/10] feat: export Trans component --- packages/i18n/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index a3fd46a1d2..cef066bb29 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,5 +1,5 @@ import i18next, { Resource } from 'i18next'; -import { initReactI18next, useTranslation } from 'react-i18next'; +import { Trans, initReactI18next, useTranslation } from 'react-i18next'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -23,7 +23,7 @@ declare module 'react-i18next' { // const STORAGE_KEY = 'i18n_lng'; -export { i18n, useTranslation, LOCALES }; +export { Trans, i18n, useTranslation, LOCALES }; const resources = LOCALES.reduce( (acc, { tag, res }) => ({ ...acc, [tag]: { translation: res } }), From d0da2a16c3105b47e4d9f85d3ba45665b3b2c1f6 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:14:17 +0800 Subject: [PATCH 02/10] feat: init languageDetector --- packages/i18n/package.json | 1 + packages/i18n/src/index.ts | 22 +++++++++++++--------- pnpm-lock.yaml | 8 ++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/i18n/package.json b/packages/i18n/package.json index cc559528e3..d4754700fb 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -19,6 +19,7 @@ }, "dependencies": { "i18next": "^21.9.1", + "i18next-browser-languagedetector": "^7.0.1", "prettier": "^2.7.1", "react-i18next": "^11.18.4" }, diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index cef066bb29..4095c417ad 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,5 +1,6 @@ import i18next, { Resource } from 'i18next'; import { Trans, initReactI18next, useTranslation } from 'react-i18next'; +import detector from 'i18next-browser-languagedetector'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -45,15 +46,18 @@ const language = standardizeLocale( ); const i18n = i18next.createInstance(); -i18n.use(initReactI18next).init({ - lng: language, - fallbackLng, - debug: false, - resources, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, -}); +i18n + .use(detector) + .use(initReactI18next) + .init({ + lng: language, + fallbackLng, + debug: false, + resources, + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + }, + }); i18n.on('languageChanged', () => { // localStorage.setItem(STORAGE_KEY, lng); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76ec8caa50..f37413be2d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,11 +162,13 @@ importers: specifiers: '@types/prettier': ^2.7.2 i18next: ^21.9.1 + i18next-browser-languagedetector: ^7.0.1 prettier: ^2.7.1 react-i18next: ^11.18.4 typescript: ^4.8.4 dependencies: i18next: 21.10.0 + i18next-browser-languagedetector: 7.0.1 prettier: 2.7.1 react-i18next: 11.18.6_i18next@21.10.0 devDependencies: @@ -5610,6 +5612,12 @@ packages: hasBin: true dev: true + /i18next-browser-languagedetector/7.0.1: + resolution: {integrity: sha512-Pa5kFwaczXJAeHE56CHG2aWzFBMJNUNghf0Pm4SwSrEMps/PTKqW90EYWlIvhuYStf3Sn1K0vw+gH3+TLdkH1g==} + dependencies: + '@babel/runtime': 7.20.7 + dev: false + /i18next/21.10.0: resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==} dependencies: From b3e703b6562d3ffed59098e7a829a94f37ca95aa Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:45:48 +0800 Subject: [PATCH 03/10] chore: remove language detector --- packages/i18n/package.json | 1 - pnpm-lock.yaml | 8 -------- 2 files changed, 9 deletions(-) diff --git a/packages/i18n/package.json b/packages/i18n/package.json index d4754700fb..cc559528e3 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -19,7 +19,6 @@ }, "dependencies": { "i18next": "^21.9.1", - "i18next-browser-languagedetector": "^7.0.1", "prettier": "^2.7.1", "react-i18next": "^11.18.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f37413be2d..76ec8caa50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -162,13 +162,11 @@ importers: specifiers: '@types/prettier': ^2.7.2 i18next: ^21.9.1 - i18next-browser-languagedetector: ^7.0.1 prettier: ^2.7.1 react-i18next: ^11.18.4 typescript: ^4.8.4 dependencies: i18next: 21.10.0 - i18next-browser-languagedetector: 7.0.1 prettier: 2.7.1 react-i18next: 11.18.6_i18next@21.10.0 devDependencies: @@ -5612,12 +5610,6 @@ packages: hasBin: true dev: true - /i18next-browser-languagedetector/7.0.1: - resolution: {integrity: sha512-Pa5kFwaczXJAeHE56CHG2aWzFBMJNUNghf0Pm4SwSrEMps/PTKqW90EYWlIvhuYStf3Sn1K0vw+gH3+TLdkH1g==} - dependencies: - '@babel/runtime': 7.20.7 - dev: false - /i18next/21.10.0: resolution: {integrity: sha512-YeuIBmFsGjUfO3qBmMOc0rQaun4mIpGKET5WDwvu8lU7gvwpcariZLNtL0Fzj+zazcHUrlXHiptcFhBMFaxzfg==} dependencies: From d0d0955c0e811ce951640cc7ec0e82ef64ff6276 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:47:13 +0800 Subject: [PATCH 04/10] feat: add language local storage --- packages/i18n/src/index.ts | 49 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts index 4095c417ad..714cc40f31 100644 --- a/packages/i18n/src/index.ts +++ b/packages/i18n/src/index.ts @@ -1,6 +1,5 @@ import i18next, { Resource } from 'i18next'; import { Trans, initReactI18next, useTranslation } from 'react-i18next'; -import detector from 'i18next-browser-languagedetector'; import { LOCALES } from './resources/index.js'; import type en_US from './resources/en.json'; @@ -22,7 +21,7 @@ declare module 'react-i18next' { } } -// const STORAGE_KEY = 'i18n_lng'; +const STORAGE_KEY = 'i18n_lng'; export { Trans, i18n, useTranslation, LOCALES }; @@ -34,33 +33,39 @@ const resources = LOCALES.reduce( const fallbackLng = LOCALES[0].tag; const standardizeLocale = (language: string) => { if (LOCALES.find(locale => locale.tag === language)) return language; + if (language === 'zh-CN' || language === 'zh') { + return 'zh-Hans'; + } + if (language.slice(0, 2).toLowerCase() === 'zh') { + return 'zh-Hant'; + } if (LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase())) return language; return fallbackLng; }; +let language = 'en'; -const language = standardizeLocale( - // localStorage.getItem(STORAGE_KEY) ?? - // (typeof navigator !== 'undefined' ? navigator.language : 'en') - 'en' -); - +if (typeof window !== 'undefined') { + const localStorageLanguage = localStorage.getItem(STORAGE_KEY); + if (localStorageLanguage) { + language = standardizeLocale(localStorageLanguage); + } else { + language = standardizeLocale(navigator.language); + } +} const i18n = i18next.createInstance(); -i18n - .use(detector) - .use(initReactI18next) - .init({ - lng: language, - fallbackLng, - debug: false, - resources, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, - }); +i18n.use(initReactI18next).init({ + lng: language, + fallbackLng, + debug: false, + resources, + interpolation: { + escapeValue: false, // not needed for react as it escapes by default + }, +}); -i18n.on('languageChanged', () => { - // localStorage.setItem(STORAGE_KEY, lng); +i18n.on('languageChanged', lng => { + localStorage.setItem(STORAGE_KEY, lng); }); // const I18nProvider = I18nextProvider; From 7860c563c73193f527b42ea40da029bf05299b56 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 18:49:04 +0800 Subject: [PATCH 05/10] chore: update i18n json --- packages/i18n/src/resources/en.json | 68 +++++++++++++++++++++++- packages/i18n/src/resources/zh-Hans.json | 66 +---------------------- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 78dcb2fb28..49a6bf3ab1 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -1,8 +1,11 @@ { "Quick search": "Quick search", + "Quick search placeholder": "Quick Search...", + "Quick search placeholder2": "Search in {{workspace}}", "All pages": "All pages", "Favourites": "Favourites", "No item": "No item", + "Settings": "Settings", "Import": "Import", "Trash": "Trash", "New Page": "New Page", @@ -54,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Link": "Hyperlink(with selected text)", + "Hyperlink(with selected text)": "Hyperlink(with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent", @@ -75,5 +78,66 @@ "Restore it": "Restore it", "TrashButtonGroupTitle": "Permanently delete", "TrashButtonGroupDescription": "Once deleted, you can't undo this action. Do you confirm?", - "Delete permanently": "Delete permanently" + "Delete permanently": "Delete permanently", + "recommendBrowser": " We recommend the <1>Chrome browser for optimal experience.", + "upgradeBrowser": "Please upgrade to the latest version of Chrome for the best experience.", + "Invite Members": "Invite Members", + "Invite placeholder": "Search mail (Gmail support only)", + "Non-Gmail": "Non-Gmail is not supported", + "Invite": "Invite", + "Loading": "Loading...", + "NotLoggedIn": "Currently not logged in", + "ClearData": "Clear local data", + "Continue with Google": "Continue with Google", + "Set up an AFFiNE account to sync data": "Set up an AFFiNE account to sync data", + "Stay logged out": "Stay logged out", + "All changes are saved locally": "All changes are saved locally", + "Ooops!": "Ooops!", + "mobile device": "Looks like you are browsing on a mobile device.", + "mobile device description": "We are still working on mobile support and recommend you use a desktop device.", + "Got it": "Got it", + "emptyAllPages": "This workspace is empty. Create a new page to begin editing.", + "emptyFavourite": "Click Add to Favourites and the page will appear here.", + "emptyTrash": "Click Add to Trash and the page will appear here.", + "still designed": "(This page is still being designed.)", + "My Workspaces": "My Workspaces", + "Create Or Import": "Create Or Import", + "Tips": "Tips: ", + "login success": "Login success", + "Sign in": "Sign in AFFiNE Cloud", + "Sign out": "Sign out of AFFiNE Cloud", + "Delete Workspace": "Delete Workspace", + "Delete Workspace Description": "Deleting (<1>{{workspace}}) cannot be undone, please proceed with caution. along with all its content.", + "Delete Workspace Description2": "Deleting (<1>{{workspace}}) will delete both local and cloud data, this operation cannot be undone, please proceed with caution.", + "Delete Workspace placeholder": "Please type “Delete” to confirm", + "Leave Workspace": "Leave Workspace", + "Leave Workspace Description": "After you leave, you will not be able to access all the contents of this workspace.", + "Leave": "Leave", + "Workspace Icon": "Workspace Icon", + "Workspace Name": "Workspace Name", + "Workspace Type": "Workspace Type", + "Export Workspace": "Export Workspace <1>{{workspace}} Is Coming", + "Users": "Users", + "Access level": "Access level", + "Pending": "Pending", + "Collaboration Description": "Collaborating with other members requires AFFiNE Cloud service.", + "Enable AFFiNE Cloud": "Enable AFFiNE Cloud", + "Enable AFFiNE Cloud Description": "If enabled, the data in this workspace will be backed up and synchronised via AFFiNE Cloud.", + "Enable": "Enable", + "Sign in and Enable": "Sign in and Enable", + "Skip": "Skip", + "Publishing": "Publishing to web requires AFFiNE Cloud service.", + "Share with link": "Share with link", + "Copy Link": "Copy Link", + "Publishing Description": "After publishing to the web, everyone can view the content of this workspace through the link.", + "Stop publishing": "Stop publishing", + "Publish to web": "Publish to web", + "Sync Description": "{{workspaceName}} is Local Workspace. All data is stored on the current device. You can enable AFFiNE Cloud for this workspace to keep data in sync with the cloud.", + "Sync Description2": "<1>{{workspaceName}} is Cloud Workspace. All data will be synchronized and saved to the AFFiNE", + "Download data to device": "Download {{CoreOrAll}} data to device", + "General": "General", + "Sync": "Sync", + "Collaboration": "Collaboration", + "Publish": "Publish", + "Workspace Settings": "Workspace Settings" } diff --git a/packages/i18n/src/resources/zh-Hans.json b/packages/i18n/src/resources/zh-Hans.json index 47095233d9..0967ef424b 100644 --- a/packages/i18n/src/resources/zh-Hans.json +++ b/packages/i18n/src/resources/zh-Hans.json @@ -1,65 +1 @@ -{ - "Quick search": "快速搜索", - "All pages": "全部页面", - "Favourites": "收藏夹", - "No item": "没有项目", - "Import": "导入", - "Trash": "回收站", - "New Page": "新建文章", - "New Keyword Page": "新建 '{{query}}' 为标题的文章", - "Find 0 result": "找到 0 个结果", - "Find results": "找到 {{number}} 个结果", - "Collapse sidebar": "关闭侧边栏", - "Expand sidebar": "展开侧边栏", - "Removed from Favourites": "已从收藏中移除", - "Remove from favourites": "从收藏中移除", - "Added to Favourites": "已添加到收藏", - "Add to favourites": "添加到收藏", - "Paper": "文章", - "Edgeless": "无边模式", - "Switch to": "跳转到", - "Convert to ": "转换成 ", - "Page": "文章", - "Export": "导出", - "Export to HTML": "导出到 HTML", - "Export to Markdown": "导出到 Markdown", - "Delete": "删除", - "Title": "标题", - "Untitled": "无标题", - "Created": "创建时间", - "Updated": "更新时间", - "Open in new tab": "在新页面打开", - "Favourite": "收藏", - "Favourited": "已收藏", - "Delete page?": "删除文章?", - "Delete permanently?": "永久删除?", - "will be moved to Trash": "{{title}} 将被移动到回收站", - "Once deleted, you can't undo this action.": "一次性删除,无法恢复。", - "Moved to Trash": "已移动到回收站", - "Permanently deleted": "已永久删除", - "restored": "{{title}} 已恢复", - "Cancel": "取消", - "Keyboard Shortcuts": "快捷键", - "Contact Us": "联系我们", - "Official Website": "官网", - "Get in touch!": "Get in touch!", - "AFFiNE Community": "AFFiNE Community", - "How is AFFiNE Alpha different?": "How is AFFiNE Alpha different?", - "Shortcuts": "Shortcuts", - "Undo": "Undo", - "Redo": "Redo", - "Bold": "Bold", - "Italic": "Italic", - "Underline": "Underline", - "Strikethrough": "Strikethrough", - "Inline code": "Inline code", - "Code block": "Code block", - "Link": "Link", - "Body text": "Body text", - "Heading": "Heading {{number}}", - "Increase indent": "Increase indent", - "Reduce indent": "Reduce indent", - "Markdown Syntax": "Markdown Syntax", - "Divider": "Divider", - "404 - Page Not Found": "404 - Page Not Found" -} +{} From 5189086c1b663d59fe32fd2ad4bf0ae9ef96fa73 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 19:03:20 +0800 Subject: [PATCH 06/10] chore: update keys --- packages/i18n/src/resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 49a6bf3ab1..635c083af3 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -57,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Hyperlink(with selected text)": "Hyperlink(with selected text)", + "Link": "Hyperlink(with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent", From c8ac8c5738342b87c7bafd71cbe5ee35fafae2e7 Mon Sep 17 00:00:00 2001 From: JimmFly Date: Tue, 10 Jan 2023 19:05:55 +0800 Subject: [PATCH 07/10] chore: update json --- packages/i18n/src/resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index 635c083af3..761f649c18 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -57,7 +57,7 @@ "Strikethrough": "Strikethrough", "Inline code": "Inline code", "Code block": "Code block", - "Link": "Hyperlink(with selected text)", + "Link": "Hyperlink (with selected text)", "Body text": "Body text", "Heading": "Heading {{number}}", "Increase indent": "Increase indent", From 6c792d0e6121fc0e943172a6c48b23c050a988e0 Mon Sep 17 00:00:00 2001 From: x1a0t <405028157@qq.com> Date: Tue, 10 Jan 2023 19:31:57 +0800 Subject: [PATCH 08/10] chore: update BlockSuite version --- packages/app/package.json | 6 ++--- packages/data-center/package.json | 4 +-- pnpm-lock.yaml | 44 +++++++++++++++---------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/app/package.json b/packages/app/package.json index aece2897f9..9bc91a9259 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -11,10 +11,10 @@ "dependencies": { "@affine/datacenter": "workspace:*", "@affine/i18n": "workspace:*", - "@blocksuite/blocks": "0.3.1-20230109032243-37ad3ba", - "@blocksuite/editor": "0.3.1-20230109032243-37ad3ba", + "@blocksuite/blocks": "0.4.0-20230110112105-ef07332", + "@blocksuite/editor": "0.4.0-20230110112105-ef07332", "@blocksuite/icons": "^2.0.2", - "@blocksuite/store": "0.3.1-20230109032243-37ad3ba", + "@blocksuite/store": "0.4.0-20230110112105-ef07332", "@emotion/css": "^11.10.0", "@emotion/react": "^11.10.4", "@emotion/server": "^11.10.0", diff --git a/packages/data-center/package.json b/packages/data-center/package.json index 9f9fc2d860..606f6e196c 100644 --- a/packages/data-center/package.json +++ b/packages/data-center/package.json @@ -26,8 +26,8 @@ "typescript": "^4.8.4" }, "dependencies": { - "@blocksuite/blocks": "^0.3.1-20230109032243-37ad3ba", - "@blocksuite/store": "^0.3.1-20230109032243-37ad3ba", + "@blocksuite/blocks": "0.4.0-20230110112105-ef07332", + "@blocksuite/store": "0.4.0-20230110112105-ef07332", "debug": "^4.3.4", "encoding": "^0.1.13", "firebase": "^9.15.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76ec8caa50..722b006877 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,10 +40,10 @@ importers: specifiers: '@affine/datacenter': workspace:* '@affine/i18n': workspace:* - '@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba - '@blocksuite/editor': 0.3.1-20230109032243-37ad3ba + '@blocksuite/blocks': 0.4.0-20230110112105-ef07332 + '@blocksuite/editor': 0.4.0-20230110112105-ef07332 '@blocksuite/icons': ^2.0.2 - '@blocksuite/store': 0.3.1-20230109032243-37ad3ba + '@blocksuite/store': 0.4.0-20230110112105-ef07332 '@emotion/css': ^11.10.0 '@emotion/react': ^11.10.4 '@emotion/server': ^11.10.0 @@ -81,10 +81,10 @@ importers: dependencies: '@affine/datacenter': link:../data-center '@affine/i18n': link:../i18n - '@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 - '@blocksuite/editor': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 + '@blocksuite/blocks': 0.4.0-20230110112105-ef07332_yjs@13.5.44 + '@blocksuite/editor': 0.4.0-20230110112105-ef07332_yjs@13.5.44 '@blocksuite/icons': 2.0.4_w5j4k42lgipnm43s3brx6h3c34 - '@blocksuite/store': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 + '@blocksuite/store': 0.4.0-20230110112105-ef07332_yjs@13.5.44 '@emotion/css': 11.10.0 '@emotion/react': 11.10.4_w5j4k42lgipnm43s3brx6h3c34 '@emotion/server': 11.10.0_@emotion+css@11.10.0 @@ -123,8 +123,8 @@ importers: packages/data-center: specifiers: - '@blocksuite/blocks': ^0.3.1-20230109032243-37ad3ba - '@blocksuite/store': ^0.3.1-20230109032243-37ad3ba + '@blocksuite/blocks': 0.4.0-20230110112105-ef07332 + '@blocksuite/store': 0.4.0-20230110112105-ef07332 '@playwright/test': ^1.29.1 '@types/debug': ^4.1.7 debug: ^4.3.4 @@ -140,8 +140,8 @@ importers: y-protocols: ^1.0.5 yjs: ^13.5.44 dependencies: - '@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 - '@blocksuite/store': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 + '@blocksuite/blocks': 0.4.0-20230110112105-ef07332_yjs@13.5.44 + '@blocksuite/store': 0.4.0-20230110112105-ef07332_yjs@13.5.44 debug: 4.3.4 encoding: 0.1.13 firebase: 9.15.0_encoding@0.1.13 @@ -1453,11 +1453,11 @@ packages: to-fast-properties: 2.0.0 dev: true - /@blocksuite/blocks/0.3.1-20230109032243-37ad3ba_yjs@13.5.44: - resolution: {integrity: sha512-UTlbk0Is7TMRBbvUyM2nivbqM/TLwRj1qArMYbOmvDGUNYadWo68cTwv/Ej2WwiKn22q4/4JHryGsv3gTCRz1Q==} + /@blocksuite/blocks/0.4.0-20230110112105-ef07332_yjs@13.5.44: + resolution: {integrity: sha512-dtwZRCWtirmheRQaITPOC/D9LZ3yFuYztqL/y2mz/BRSfHj8I71OVcX0HjFXx2TUdzhkea1GNYbp4226zZIiRA==} dependencies: - '@blocksuite/phasor': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 - '@blocksuite/store': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 + '@blocksuite/phasor': 0.4.0-20230110112105-ef07332_yjs@13.5.44 + '@blocksuite/store': 0.4.0-20230110112105-ef07332_yjs@13.5.44 '@tldraw/intersect': 1.8.0 autosize: 5.0.2 highlight.js: 11.7.0 @@ -1473,11 +1473,11 @@ packages: - yjs dev: false - /@blocksuite/editor/0.3.1-20230109032243-37ad3ba_yjs@13.5.44: - resolution: {integrity: sha512-bYbMn4EL/od+xP4K3u2kJT08kJBpK6H7b4cbRb9No3SUwgNHvvVNxia/QH1AQXyKaZQj/DHFgVxrw9GKo2GIPA==} + /@blocksuite/editor/0.4.0-20230110112105-ef07332_yjs@13.5.44: + resolution: {integrity: sha512-UqLVEZq/bKRJfe3e/Teur7grlnSo6oG55s00WSWu+nTIHnvgasIePJ6rpGC/pXwYdsuvVQnQzGesnrapNVtXqA==} dependencies: - '@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 - '@blocksuite/store': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44 + '@blocksuite/blocks': 0.4.0-20230110112105-ef07332_yjs@13.5.44 + '@blocksuite/store': 0.4.0-20230110112105-ef07332_yjs@13.5.44 lit: 2.5.0 marked: 4.2.5 turndown: 7.1.1 @@ -1498,16 +1498,16 @@ packages: react: 18.2.0 dev: false - /@blocksuite/phasor/0.3.1-20230109032243-37ad3ba_yjs@13.5.44: - resolution: {integrity: sha512-mL1gSQ3rzrjdQSbWPtgyMXpbbl266UUjw26d0aIjkOh+iMMI6rWtmKWDoiDkO7tejIjwSNQ4w5zJOjJRIj+mSA==} + /@blocksuite/phasor/0.4.0-20230110112105-ef07332_yjs@13.5.44: + resolution: {integrity: sha512-R5j/iK7WBFSk7vSk8HEAsxDwr+xDeY7JuzdGzzwnkcOaxuM6Eea6g0vMw7DPuWDAkvlcP7JsgXLnzWgFZh7qmA==} peerDependencies: yjs: ^13 dependencies: yjs: 13.5.44 dev: false - /@blocksuite/store/0.3.1-20230109032243-37ad3ba_yjs@13.5.44: - resolution: {integrity: sha512-zOUz19jfhuhsUkx9BGEQPZWbPyD/AgX0LB7ShVRdd3YM73x25hD6tPLLz1HEV2b69XokC0P9oSru4aNomm4jkg==} + /@blocksuite/store/0.4.0-20230110112105-ef07332_yjs@13.5.44: + resolution: {integrity: sha512-NisHLf0uSyFu5DUZD13QSsp33C9vnd7Jf7jdLOAPztQ2U05NcGFopjM2InhwBmtmQSHrd/qi25PjgnAJ7/HSNQ==} peerDependencies: yjs: ^13 dependencies: From b49a32c9c764368d8170efdb687030bce7c52b9b Mon Sep 17 00:00:00 2001 From: DarkSky Date: Wed, 11 Jan 2023 12:53:54 +0800 Subject: [PATCH 09/10] fix: dev server endpoint fix --- packages/app/next.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/next.config.js b/packages/app/next.config.js index df91a70108..478bbfa12e 100644 --- a/packages/app/next.config.js +++ b/packages/app/next.config.js @@ -11,7 +11,7 @@ const EDITOR_VERSION = enableDebugLocal const profileTarget = { ac: '100.85.73.88:12001', - dev: '100.85.73.88:12001', + dev: '100.77.180.48:11001', local: '127.0.0.1:3000', }; From db74706eca35ee74f5d3c64c00789c8aebf2d7c9 Mon Sep 17 00:00:00 2001 From: alt0 Date: Wed, 11 Jan 2023 15:07:04 +0800 Subject: [PATCH 10/10] refactor: datacenter only export workspaceUnit --- packages/data-center/src/datacenter.ts | 22 ++++++++++++++-------- packages/data-center/src/workspace-unit.ts | 4 ++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts index 1221b114f3..4b58662382 100644 --- a/packages/data-center/src/datacenter.ts +++ b/packages/data-center/src/datacenter.ts @@ -100,7 +100,8 @@ export class DataCenter { const workspace = createBlocksuiteWorkspace(workspaceMeta.id); await this._mainProvider.createWorkspace(workspace, workspaceMeta); - return workspace; + const workspaceUnit = this._workspaceUnitCollection.find(workspaceMeta.id); + return workspaceUnit; } /** @@ -154,18 +155,23 @@ export class DataCenter { * @returns {Promise} */ public async loadWorkspace(workspaceId: string) { - const workspaceInfo = this._workspaceUnitCollection.find(workspaceId); - assert(workspaceInfo, 'Workspace not found'); - const currentProvider = this.providerMap.get(workspaceInfo.provider); + const workspaceUnit = this._workspaceUnitCollection.find(workspaceId); + assert(workspaceUnit, 'Workspace not found'); + const currentProvider = this.providerMap.get(workspaceUnit.provider); if (currentProvider) { currentProvider.closeWorkspace(workspaceId); } - const provider = this.providerMap.get(workspaceInfo.provider); - assert(provider, `provide '${workspaceInfo.provider}' is not registered`); - this._logger(`Loading ${workspaceInfo.provider} workspace: `, workspaceId); + const provider = this.providerMap.get(workspaceUnit.provider); + assert(provider, `provide '${workspaceUnit.provider}' is not registered`); + this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId); const workspace = this._getBlocksuiteWorkspace(workspaceId); this._workspaceInstances.set(workspaceId, workspace); - return await provider.warpWorkspace(workspace); + await provider.warpWorkspace(workspace); + this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => { + workspaceUnit.setBlocksuiteWorkspace(null); + }); + workspaceUnit.setBlocksuiteWorkspace(workspace); + return workspaceUnit; } /** diff --git a/packages/data-center/src/workspace-unit.ts b/packages/data-center/src/workspace-unit.ts index 527e8647ef..4069b4200a 100644 --- a/packages/data-center/src/workspace-unit.ts +++ b/packages/data-center/src/workspace-unit.ts @@ -30,7 +30,7 @@ export class WorkspaceUnit { public provider!: string; public syncMode: 'all' | 'core' = 'core'; - private _blocksuiteWorkspace?: BlocksuiteWorkspace; + private _blocksuiteWorkspace?: BlocksuiteWorkspace | null; constructor(params: WorkspaceUnitCtorParams) { this.id = params.id; @@ -41,7 +41,7 @@ export class WorkspaceUnit { return this._blocksuiteWorkspace; } - setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) { + setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace | null) { if (blocksuiteWorkspace?.room !== this.id) { throw new Error('Workspace id inconsistent.'); }