Skip to content

Commit 574c00a

Browse files
committed
使用官方节点搜索功能
1 parent afbf491 commit 574c00a

File tree

2 files changed

+6
-52
lines changed

2 files changed

+6
-52
lines changed

src/components/pkb-producer/index.tsx

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type {
2929
NonDeletedExcalidrawElement,
3030
Theme,
3131
} from '@weiwenda/excalidraw/dist/excalidraw/element/types';
32+
import fallbackLangData from '@weiwenda/excalidraw/dist/excalidraw/locales/en.json';
3233
import './index.css';
3334
import './App.scss';
3435
import {SessionWithToolbarComponent} from '../session';
@@ -52,6 +53,7 @@ import {useLoaderData, useNavigate, useParams, useSearchParams} from 'react-rout
5253
import {uploadJson} from '../../share/ts/utils/APIUtils';
5354
import {copyToClipboard} from '../index';
5455
import {doAutoLayout} from './layoutUtils';
56+
import {NestedKeyOf} from '@weiwenda/excalidraw/dist/excalidraw/utility-types';
5557

5658
const {Search} = Input;
5759

@@ -103,7 +105,6 @@ export default function PkbProducer({
103105
const [showDetail, setShowDetail] = useState(session.clientStore.getClientSetting('curPkbShowDetail'));
104106
const [showShapes, setShowShapes] = useState(session.clientStore.getClientSetting('curPkbShowShapes'));
105107
const [showSelectedShapeActions, setShowSelectedShapeActions] = useState(session.clientStore.getClientSetting('curPkbShowSelectedShapeActions'));
106-
const [showSearch, setShowSearch] = useState(session.clientStore.getClientSetting('curPkbShowSearch'));
107108
const [showLibrary, setShowLibrary] = useState(session.clientStore.getClientSetting('curPkbShowLibrary'));
108109
const [docked, setDocked] = useState(false);
109110
const [theme, setTheme] = useState<Theme>('light');
@@ -139,7 +140,6 @@ export default function PkbProducer({
139140
setShowShapes(savedContent.tools?.showShapes ?? showShapes);
140141
setShowDetail(savedContent.tools?.showDetail ?? showDetail);
141142
setShowFilter(savedContent.tools?.showFilter ?? showFilter);
142-
setShowSearch(savedContent.tools?.showSearch ?? showSearch);
143143
setShowSelectedShapeActions(savedContent.tools?.showSelectedShapeActions ?? showSelectedShapeActions);
144144
// @ts-ignore
145145
const blob = new Blob([savedContent.libraryItems || serializeLibraryAsJSON(initialData.libraryItems)],
@@ -232,7 +232,6 @@ export default function PkbProducer({
232232
setShowShapes(session.clientStore.getClientSetting('curPkbShowShapes'));
233233
setShowFilter(session.clientStore.getClientSetting('curPkbShowFilter'));
234234
setShowDetail(session.clientStore.getClientSetting('curPkbShowDetail'));
235-
setShowSearch(session.clientStore.getClientSetting('curPkbShowSearch'));
236235
setShowSelectedShapeActions(session.clientStore.getClientSetting('curPkbShowSelectedShapeActions'));
237236
const convertedElements = convertToExcalidrawElements(elements);
238237
const finalElements = convertedElements.map(el => {
@@ -313,7 +312,6 @@ export default function PkbProducer({
313312
const newElement = cloneElement(
314313
Excalidraw,
315314
{
316-
langCode: 'zh-CN',
317315
excalidrawAPI: (api: ExcalidrawImperativeAPI) => setExcalidrawAPI(api),
318316
initialData: initialStatePromiseRef.current.promise,
319317
onLibraryChange: (libraryItems: LibraryItems) => {
@@ -330,7 +328,6 @@ export default function PkbProducer({
330328
session.clientStore.setClientSetting('curPkbShowLibrary', showLibrary);
331329
session.clientStore.setClientSetting('curPkbShowFilter', showFilter);
332330
session.clientStore.setClientSetting('curPkbShowDetail', showDetail);
333-
session.clientStore.setClientSetting('curPkbShowSearch', showSearch);
334331
session.clientStore.setClientSetting('curPkbShowShapes', showShapes);
335332
session.clientStore.setClientSetting('curPkbShowSelectedShapeActions', showSelectedShapeActions);
336333
}
@@ -367,7 +364,7 @@ export default function PkbProducer({
367364
<>
368365
<WelcomeScreen />
369366
{
370-
(showSearch || showFilter || showSelectedShapeActions) &&
367+
(showFilter || showSelectedShapeActions) &&
371368
<Draggable
372369
defaultClassName={'operation-board'}
373370
position={{x: boardX, y: boardY}}
@@ -377,42 +374,6 @@ export default function PkbProducer({
377374
}}
378375
>
379376
<div style={{width: '202px'}}>
380-
{
381-
showSearch &&
382-
<Search
383-
allowClear
384-
placeholder='节点搜索'
385-
onSearch={(text) => {
386-
if (!text) {
387-
return;
388-
}
389-
const res = text.matchAll(/"(.*?)"/g);
390-
let query: string[] = [];
391-
let parts;
392-
while (!(parts = res.next()).done) {
393-
query.push(parts.value[1]);
394-
}
395-
text = text.replaceAll(/"(.*?)"/g, '');
396-
query = query.concat(text.split(' ').filter((s) => s.length !== 0));
397-
let match = getTextElementsMatchingQuery(
398-
(excalidrawAPI?.getSceneElements() || []).filter((el) => el.type === 'text'),
399-
query
400-
);
401-
402-
if (match.length === 0) {
403-
excalidrawAPI?.setToast({message: '未找到匹配项', duration: 1000});
404-
return false;
405-
}
406-
// @ts-ignore
407-
excalidrawAPI?.updateScene({appState: {selectedElementIds: Object.fromEntries(
408-
match.map((e) => [e.id, true]),
409-
)}});
410-
if (match.length === 1) {
411-
excalidrawAPI?.scrollToContent(match[0]);
412-
}
413-
}}
414-
/>
415-
}
416377
{
417378
showFilter &&
418379
<div style={{background: 'var(--island-bg-color)', padding: '0.75rem',
@@ -464,7 +425,7 @@ export default function PkbProducer({
464425
setVisibleShapes(nextSelectedTags);
465426
}}
466427
>
467-
{t(`toolBar.rectangle`)}
428+
{t(`toolBar.${tag}` as NestedKeyOf<typeof fallbackLangData>)}
468429
</Tag.CheckableTag>
469430
))}
470431
</Flex>
@@ -787,7 +748,6 @@ export default function PkbProducer({
787748
showDetail,
788749
showLibrary,
789750
showShapes,
790-
showSearch,
791751
showFilter,
792752
showSelectedShapeActions
793753
}
@@ -830,7 +790,6 @@ export default function PkbProducer({
830790
showLibrary,
831791
showDetail,
832792
showShapes,
833-
showSearch,
834793
showFilter,
835794
showSelectedShapeActions
836795
}
@@ -869,11 +828,6 @@ export default function PkbProducer({
869828
onSelect={() => setShowLibrary(!showLibrary)}>
870829
素材库
871830
</MainMenu.Item>
872-
<MainMenu.Item icon={<FileSearchOutlined />}
873-
shortcut={showSearch ? 'ON' : 'OFF'}
874-
onSelect={() => setShowSearch(!showSearch)}>
875-
节点搜索工具
876-
</MainMenu.Item>
877831
<MainMenu.Item icon={<FilterOutlined />}
878832
shortcut={showFilter ? 'ON' : 'OFF'}
879833
onSelect={() => setShowFilter(!showFilter)}>

src/components/pkb-producer/layoutUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export const doAutoLayout = (selectedAlgorithm: string,
6161
) {
6262
if (
6363
elements[0].type === 'arrow' &&
64-
elements[0].startBinding &&
65-
elements[0].endBinding
64+
(elements[0] as ExcalidrawArrowElement).startBinding &&
65+
(elements[0] as ExcalidrawArrowElement).endBinding
6666
) {
6767
arrowEls.push(elements[0]);
6868
}

0 commit comments

Comments
 (0)