Skip to content

Commit

Permalink
feat(ui): support modifying the toolbar items through setMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
jikkai committed Aug 15, 2024
1 parent bf697b6 commit e5c062d
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 27 deletions.
4 changes: 2 additions & 2 deletions common/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"./vite": "./vite/index.js"
},
"dependencies": {
"@typescript-eslint/parser": "^8.0.1",
"@typescript-eslint/parser": "^8.1.0",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-istanbul": "^2.0.5",
"happy-dom": "14.12.3",
"javascript-obfuscator": "^4.1.1",
"vite": "^5.4.0",
"vite-plugin-dts": "^4.0.2",
"vite-plugin-dts": "^4.0.3",
"vitest": "^2.0.5"
}
}
20 changes: 20 additions & 0 deletions packages/ui/src/services/menu/menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export class MenuService extends Disposable implements IMenuService {

setMenuItem(item: IMenuItem): void {
this._menuItemMap.set(item.id, item);
if (Array.isArray(item.positions)) {
item.positions.forEach((menu) => this._updateMenuItems(item, menu));
} else {
this._updateMenuItems(item, item.positions);
}

this._menuChanged$.next();
}

Expand Down Expand Up @@ -167,4 +173,18 @@ export class MenuService extends Disposable implements IMenuService {

menuList.push([menu.id, menu]);
}

private _updateMenuItems(menu: IMenuItem, position: MenuPosition | string) {
if (!this._menuByPositions.has(position)) {
this._menuByPositions.set(position, []);
}

const menuList = this._menuByPositions.get(position)!;
const index = menuList.findIndex((m) => m[0] === menu.id);
if (index > -1) {
menuList[index] = [menu.id, menu];
} else {
menuList.push([menu.id, menu]);
}
}
}
98 changes: 73 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5c062d

Please sign in to comment.