refactor: move command registry to frontend/core (#7135)
move command registeration related logic out of infra module.
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.7",
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
"tinykeys": "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch",
|
|
||||||
"yjs": "^13.6.14",
|
"yjs": "^13.6.14",
|
||||||
"zod": "^3.22.4"
|
"zod": "^3.22.4"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
export * from './app-config-storage';
|
export * from './app-config-storage';
|
||||||
export * from './atom';
|
export * from './atom';
|
||||||
export * from './blocksuite';
|
export * from './blocksuite';
|
||||||
export * from './command';
|
|
||||||
export * from './framework';
|
export * from './framework';
|
||||||
export * from './initialization';
|
export * from './initialization';
|
||||||
export * from './livedata';
|
export * from './livedata';
|
||||||
|
|||||||
@@ -83,6 +83,7 @@
|
|||||||
"ses": "^1.4.1",
|
"ses": "^1.4.1",
|
||||||
"socket.io-client": "^4.7.5",
|
"socket.io-client": "^4.7.5",
|
||||||
"swr": "2.2.5",
|
"swr": "2.2.5",
|
||||||
|
"tinykeys": "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
"valtio": "^1.13.2",
|
"valtio": "^1.13.2",
|
||||||
"y-protocols": "^1.0.6",
|
"y-protocols": "^1.0.6",
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { ImportIcon, PlusIcon } from '@blocksuite/icons';
|
import { ImportIcon, PlusIcon } from '@blocksuite/icons';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
|
|
||||||
import { openCreateWorkspaceModalAtom } from '../atoms';
|
import { openCreateWorkspaceModalAtom } from '../atoms';
|
||||||
import type { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
import type { usePageHelper } from '../components/blocksuite/block-suite-page-list/utils';
|
||||||
|
import { registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineCreationCommands({
|
export function registerAffineCreationCommands({
|
||||||
store,
|
store,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { ContactWithUsIcon, NewIcon } from '@blocksuite/icons';
|
import { ContactWithUsIcon, NewIcon } from '@blocksuite/icons';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
|
|
||||||
import { openSettingModalAtom } from '../atoms';
|
import { openSettingModalAtom } from '../atoms';
|
||||||
import { popupWindow } from '../utils';
|
import { popupWindow } from '../utils';
|
||||||
|
import { registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineHelpCommands({
|
export function registerAffineHelpCommands({
|
||||||
t,
|
t,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { SidebarIcon } from '@blocksuite/icons';
|
import { SidebarIcon } from '@blocksuite/icons';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
|
|
||||||
import { appSidebarOpenAtom } from '../components/app-sidebar';
|
import { appSidebarOpenAtom } from '../components/app-sidebar';
|
||||||
|
import { registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineLayoutCommands({
|
export function registerAffineLayoutCommands({
|
||||||
t,
|
t,
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import { WorkspaceSubPath } from '@affine/core/shared';
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { ArrowRightBigIcon } from '@blocksuite/icons';
|
import { ArrowRightBigIcon } from '@blocksuite/icons';
|
||||||
import type { DocCollection } from '@blocksuite/store';
|
import type { DocCollection } from '@blocksuite/store';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
|
|
||||||
import { openSettingModalAtom, openWorkspaceListModalAtom } from '../atoms';
|
import { openSettingModalAtom, openWorkspaceListModalAtom } from '../atoms';
|
||||||
import type { useNavigateHelper } from '../hooks/use-navigate-helper';
|
import type { useNavigateHelper } from '../hooks/use-navigate-helper';
|
||||||
import { mixpanel } from '../utils/mixpanel';
|
import { mixpanel } from '../utils/mixpanel';
|
||||||
|
import { registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineNavigationCommands({
|
export function registerAffineNavigationCommands({
|
||||||
t,
|
t,
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { SettingsIcon } from '@blocksuite/icons';
|
import { SettingsIcon } from '@blocksuite/icons';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||||
import {
|
import { appSettingAtom } from '@toeverything/infra';
|
||||||
appSettingAtom,
|
|
||||||
PreconditionStrategy,
|
|
||||||
registerAffineCommand,
|
|
||||||
} from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
import type { useTheme } from 'next-themes';
|
import type { useTheme } from 'next-themes';
|
||||||
|
|
||||||
import { openQuickSearchModalAtom } from '../atoms';
|
import { openQuickSearchModalAtom } from '../atoms';
|
||||||
import type { useLanguageHelper } from '../hooks/affine/use-language-helper';
|
import type { useLanguageHelper } from '../hooks/affine/use-language-helper';
|
||||||
import { mixpanel } from '../utils';
|
import { mixpanel } from '../utils';
|
||||||
|
import { PreconditionStrategy, registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineSettingsCommands({
|
export function registerAffineSettingsCommands({
|
||||||
t,
|
t,
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ import { updateReadyAtom } from '@affine/core/hooks/use-app-updater';
|
|||||||
import { apis } from '@affine/electron-api';
|
import { apis } from '@affine/electron-api';
|
||||||
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import type { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { ResetIcon } from '@blocksuite/icons';
|
import { ResetIcon } from '@blocksuite/icons';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import type { createStore } from 'jotai';
|
import type { createStore } from 'jotai';
|
||||||
|
|
||||||
|
import { registerAffineCommand } from './registry';
|
||||||
|
|
||||||
export function registerAffineUpdatesCommands({
|
export function registerAffineUpdatesCommands({
|
||||||
t,
|
t,
|
||||||
store,
|
store,
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export * from './affine-layout';
|
|||||||
export * from './affine-navigation';
|
export * from './affine-navigation';
|
||||||
export * from './affine-settings';
|
export * from './affine-settings';
|
||||||
export * from './affine-updates';
|
export * from './affine-updates';
|
||||||
|
export * from './registry';
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
import {
|
||||||
|
type AffineCommand,
|
||||||
|
AffineCommandRegistry,
|
||||||
|
type CommandCategory,
|
||||||
|
PreconditionStrategy,
|
||||||
|
} from '@affine/core/commands';
|
||||||
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
|
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
|
||||||
import { useGetDocCollectionPageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
|
import { useGetDocCollectionPageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
|
||||||
import { useJournalHelper } from '@affine/core/hooks/use-journal';
|
import { useJournalHelper } from '@affine/core/hooks/use-journal';
|
||||||
@@ -12,17 +18,10 @@ import {
|
|||||||
TodayIcon,
|
TodayIcon,
|
||||||
ViewLayersIcon,
|
ViewLayersIcon,
|
||||||
} from '@blocksuite/icons';
|
} from '@blocksuite/icons';
|
||||||
import type {
|
import type { DocRecord, Workspace } from '@toeverything/infra';
|
||||||
AffineCommand,
|
|
||||||
CommandCategory,
|
|
||||||
DocRecord,
|
|
||||||
Workspace,
|
|
||||||
} from '@toeverything/infra';
|
|
||||||
import {
|
import {
|
||||||
AffineCommandRegistry,
|
|
||||||
DocsService,
|
DocsService,
|
||||||
GlobalContextService,
|
GlobalContextService,
|
||||||
PreconditionStrategy,
|
|
||||||
useLiveData,
|
useLiveData,
|
||||||
useService,
|
useService,
|
||||||
WorkspaceService,
|
WorkspaceService,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { CommandCategory } from '@toeverything/infra';
|
import type { CommandCategory } from '@affine/core/commands';
|
||||||
import { groupBy } from 'lodash-es';
|
import { groupBy } from 'lodash-es';
|
||||||
|
|
||||||
import { commandScore } from './command-score';
|
import { commandScore } from './command-score';
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { Loading } from '@affine/component/ui/loading';
|
import { Loading } from '@affine/component/ui/loading';
|
||||||
|
import type { CommandCategory } from '@affine/core/commands';
|
||||||
import { formatDate } from '@affine/core/components/page-list';
|
import { formatDate } from '@affine/core/components/page-list';
|
||||||
import { useDocEngineStatus } from '@affine/core/hooks/affine/use-doc-engine-status';
|
import { useDocEngineStatus } from '@affine/core/hooks/affine/use-doc-engine-status';
|
||||||
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import type { DocMeta } from '@blocksuite/store';
|
import type { DocMeta } from '@blocksuite/store';
|
||||||
import type { CommandCategory } from '@toeverything/infra';
|
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { Command } from 'cmdk';
|
import { Command } from 'cmdk';
|
||||||
import { useDebouncedValue } from 'foxact/use-debounced-value';
|
import { useDebouncedValue } from 'foxact/use-debounced-value';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { CommandCategory, DocMode } from '@toeverything/infra';
|
import type { CommandCategory } from '@affine/core/commands';
|
||||||
|
import type { DocMode } from '@toeverything/infra';
|
||||||
|
|
||||||
export interface CommandContext {
|
export interface CommandContext {
|
||||||
docMode: DocMode | undefined;
|
docMode: DocMode | undefined;
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { toast } from '@affine/component';
|
import { toast } from '@affine/component';
|
||||||
|
import {
|
||||||
|
PreconditionStrategy,
|
||||||
|
registerAffineCommand,
|
||||||
|
} from '@affine/core/commands';
|
||||||
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
|
import { useDocMetaHelper } from '@affine/core/hooks/use-block-suite-page-meta';
|
||||||
import { FavoriteItemsAdapter } from '@affine/core/modules/properties';
|
import { FavoriteItemsAdapter } from '@affine/core/modules/properties';
|
||||||
import { mixpanel } from '@affine/core/utils';
|
import { mixpanel } from '@affine/core/utils';
|
||||||
@@ -8,8 +12,6 @@ import { assertExists } from '@blocksuite/global/utils';
|
|||||||
import { EdgelessIcon, HistoryIcon, PageIcon } from '@blocksuite/icons';
|
import { EdgelessIcon, HistoryIcon, PageIcon } from '@blocksuite/icons';
|
||||||
import {
|
import {
|
||||||
DocService,
|
DocService,
|
||||||
PreconditionStrategy,
|
|
||||||
registerAffineCommand,
|
|
||||||
useLiveData,
|
useLiveData,
|
||||||
useService,
|
useService,
|
||||||
WorkspaceService,
|
WorkspaceService,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
import { registerAffineCommand } from '@affine/core/commands';
|
||||||
import { useSharingUrl } from '@affine/core/hooks/affine/use-share-url';
|
import { useSharingUrl } from '@affine/core/hooks/affine/use-share-url';
|
||||||
import { registerAffineCommand } from '@toeverything/infra';
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
export function useRegisterCopyLinkCommands({
|
export function useRegisterCopyLinkCommands({
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { registerAffineCommand } from '@affine/core/commands';
|
||||||
import { FindInPageService } from '@affine/core/modules/find-in-page/services/find-in-page';
|
import { FindInPageService } from '@affine/core/modules/find-in-page/services/find-in-page';
|
||||||
import { registerAffineCommand, useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
|
|
||||||
export function useRegisterFindInPageCommands() {
|
export function useRegisterFindInPageCommands() {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
PreconditionStrategy,
|
PreconditionStrategy,
|
||||||
registerAffineCommand,
|
registerAffineCommand,
|
||||||
useService,
|
} from '@affine/core/commands';
|
||||||
} from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { NavigatorService } from '../services/navigator';
|
import { NavigatorService } from '../services/navigator';
|
||||||
|
|||||||
@@ -68,7 +68,6 @@
|
|||||||
"react-router-dom": "^6.22.3",
|
"react-router-dom": "^6.22.3",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"semver": "^7.6.0",
|
"semver": "^7.6.0",
|
||||||
"tinykeys": "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch",
|
|
||||||
"tree-kill": "^1.2.2",
|
"tree-kill": "^1.2.2",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"undici": "^6.12.0",
|
"undici": "^6.12.0",
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ __metadata:
|
|||||||
ses: "npm:^1.4.1"
|
ses: "npm:^1.4.1"
|
||||||
socket.io-client: "npm:^4.7.5"
|
socket.io-client: "npm:^4.7.5"
|
||||||
swr: "npm:2.2.5"
|
swr: "npm:2.2.5"
|
||||||
|
tinykeys: "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch"
|
||||||
uuid: "npm:^9.0.1"
|
uuid: "npm:^9.0.1"
|
||||||
valtio: "npm:^1.13.2"
|
valtio: "npm:^1.13.2"
|
||||||
vitest: "npm:1.6.0"
|
vitest: "npm:1.6.0"
|
||||||
@@ -490,7 +491,6 @@ __metadata:
|
|||||||
react-router-dom: "npm:^6.22.3"
|
react-router-dom: "npm:^6.22.3"
|
||||||
rxjs: "npm:^7.8.1"
|
rxjs: "npm:^7.8.1"
|
||||||
semver: "npm:^7.6.0"
|
semver: "npm:^7.6.0"
|
||||||
tinykeys: "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch"
|
|
||||||
tree-kill: "npm:^1.2.2"
|
tree-kill: "npm:^1.2.2"
|
||||||
ts-node: "npm:^10.9.2"
|
ts-node: "npm:^10.9.2"
|
||||||
undici: "npm:^6.12.0"
|
undici: "npm:^6.12.0"
|
||||||
@@ -13908,7 +13908,6 @@ __metadata:
|
|||||||
nanoid: "npm:^5.0.7"
|
nanoid: "npm:^5.0.7"
|
||||||
react: "npm:^18.2.0"
|
react: "npm:^18.2.0"
|
||||||
rxjs: "npm:^7.8.1"
|
rxjs: "npm:^7.8.1"
|
||||||
tinykeys: "patch:tinykeys@npm%3A2.1.0#~/.yarn/patches/tinykeys-npm-2.1.0-819feeaed0.patch"
|
|
||||||
vite: "npm:^5.2.8"
|
vite: "npm:^5.2.8"
|
||||||
vite-plugin-dts: "npm:3.9.1"
|
vite-plugin-dts: "npm:3.9.1"
|
||||||
vitest: "npm:1.6.0"
|
vitest: "npm:1.6.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user