Skip to content

Commit

Permalink
Merge pull request #90 from idrawjs/dev-v0.4
Browse files Browse the repository at this point in the history
feat: enhance clipboard action
  • Loading branch information
chenshenhai authored Aug 11, 2024
2 parents 0cd7e49 + 4027cf2 commit 772374a
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 131 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": false,
"version": "0.4.0-alpha.36",
"version": "0.4.0-alpha.37",
"workspaces": [
"packages/*"
],
Expand All @@ -21,7 +21,7 @@
"upgrade:version": "npm run version:reset && pnpm i"
},
"dependencies": {
"idraw": "0.4.0-beta.36",
"idraw": "0.4.0-beta.37",
"antd": "5.19.3"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/studio-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/studio-base",
"version": "0.4.0-alpha.36",
"version": "0.4.0-alpha.37",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -24,7 +24,7 @@
"@rc-component/color-picker": "^1.5.3",
"antd": "^5.19.3",
"classnames": "^2.3.2",
"idraw": "^0.4.0-beta.36",
"idraw": "^0.4.0-beta.37",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/studio-base/src/modules/element-tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ export const ElementTree = React.forwardRef((props: ElementTreeProps, ref: any)
onDelete,
onExpand,
onGoToGroup,
// reverse // TODO
reverse = true
reverse
} = props;

const onSelectNode: TreeProps['onSelect'] = (skeys, info) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/studio/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idraw/studio",
"version": "0.4.0-alpha.36",
"version": "0.4.0-alpha.37",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -21,13 +21,13 @@
"license": "MIT",
"dependencies": {
"@rc-component/color-picker": "^1.5.3",
"@idraw/studio-base": "workspace:^0.4.0-alpha.36",
"@idraw/studio-base": "workspace:^0.4.0-alpha.37",
"classnames": "^2.5.1",
"is-hotkey": "^0.2.0"
},
"peerDependencies": {
"antd": "^5.19.3",
"idraw": "^0.4.0-beta.36",
"idraw": "^0.4.0-beta.37",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/src/modules/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useContextMenuOptions: HookUseContextMenuOptions = (opts: { sharedE
const updateContextMenuOptions: UpdateContextMenuOptions = (opts) => {
const { selectedElements } = opts;
innerItems?.forEach((item) => {
if (item && ['copy', 'paste', 'cut', 'delete'].includes(item?.key as string)) {
if (item && ['copy', 'cut', 'delete'].includes(item?.key as string)) {
(item as any).disabled = selectedElements?.length > 0 ? false : true;
}
});
Expand Down
12 changes: 11 additions & 1 deletion packages/studio/src/modules/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Sketch } from '../sketch';
// import SplitPane from '../split-pane';
import type { SharedEvent, SharedStore, HookUseContextMenuOptions, GetTemplates } from '../../types';
import { Context } from '../context';
import { generatePasteEventCallback } from '../../shared/event';

const modName = 'mod-dashboard';
const leftSiderDefaultWidth = 240;
Expand All @@ -24,6 +25,7 @@ export interface DashboardProps {
logo?: React.ReactNode;
navigationMenu?: React.ReactNode;
navigationCenter?: React.ReactNode;
reverseTree?: boolean;
defaultSelectedElementUUIDs?: string[];
sharedStore: SharedStore;
sharedEvent: SharedEvent;
Expand Down Expand Up @@ -55,7 +57,8 @@ export const Dashboard = forwardRef<HTMLDivElement, DashboardProps>((props: Dash
useContextMenuOptions,
handleKeyboard,
getPageTemplates,
getMaterialTemplates
getMaterialTemplates,
reverseTree
} = props;
const { state } = useContext(Context);
const { editMode } = state;
Expand All @@ -69,9 +72,14 @@ export const Dashboard = forwardRef<HTMLDivElement, DashboardProps>((props: Dash
}
handleKeyboard(e, { sharedEvent, sharedStore });
};

const pasteCallback = generatePasteEventCallback({ sharedStore, sharedEvent });

window.addEventListener('keydown', hotKeyCallback);
window.addEventListener('paste', pasteCallback);
return () => {
window.removeEventListener('keydown', hotKeyCallback);
window.removeEventListener('paste', pasteCallback);
};
}, []);

Expand Down Expand Up @@ -182,6 +190,7 @@ export const Dashboard = forwardRef<HTMLDivElement, DashboardProps>((props: Dash
<PanelPage
height={height - headerHeight}
className={leftClassName}
reverseTree={!!reverseTree}
defaultSelectedElementUUIDs={defaultSelectedElementUUIDs}
sharedEvent={sharedEvent}
sharedStore={sharedStore}
Expand All @@ -192,6 +201,7 @@ export const Dashboard = forwardRef<HTMLDivElement, DashboardProps>((props: Dash
<PanelLayer
height={height - headerHeight}
className={leftClassName}
reverseTree={!!reverseTree}
// defaultSelectedElementUUIDs={defaultSelectedElementUUIDs}
sharedEvent={sharedEvent}
sharedStore={sharedStore}
Expand Down
13 changes: 7 additions & 6 deletions packages/studio/src/modules/hot-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ export const handleKeyboard = (
}
) => {
const { sharedEvent } = opts;
// if (isHotkey('mod+v', e)) {
// sharedEvent.trigger('paste');
// } else
if (isHotkey('mod+c', e)) {
sharedEvent.trigger('copy', undefined);
} else if (isHotkey('mod+v', e)) {
sharedEvent.trigger('paste', undefined);
sharedEvent.trigger('copy');
} else if (isHotkey('mod+x', e)) {
sharedEvent.trigger('cut', undefined);
sharedEvent.trigger('cut');
} else if (isHotkey('del', e)) {
sharedEvent.trigger('delete', undefined);
sharedEvent.trigger('delete');
} else if (isHotkey('backspace', e)) {
sharedEvent.trigger('delete', undefined);
sharedEvent.trigger('delete');
} else if (isHotkey('mod+s', e)) {
console.log('Save ... '); // TODO
}
Expand Down
4 changes: 3 additions & 1 deletion packages/studio/src/modules/panel-layer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ export interface PanelLayerProps {
height: number;
style?: CSSProperties;
// defaultSelectedElementUUIDs?: string[];
reverseTree: boolean;
sharedStore: SharedStore;
sharedEvent: SharedEvent;
useContextMenuOptions: HookUseContextMenuOptions;
}

export const PanelLayer = (props: PanelLayerProps) => {
const { className, style, height, sharedStore, sharedEvent, useContextMenuOptions } = props;
const { className, style, height, sharedStore, sharedEvent, reverseTree, useContextMenuOptions } = props;
const { state, dispatch } = useContext(Context);
const { elementTree, selectedUUIDs, editingData } = state;

Expand Down Expand Up @@ -128,6 +129,7 @@ export const PanelLayer = (props: PanelLayerProps) => {
<ElementTree
ref={refTree}
height={elementsHeight}
reverse={reverseTree}
treeData={elementTree}
selectedKeys={selectedUUIDs}
onTitleChange={({ uuid, value }) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/studio/src/modules/panel-page/add-page-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export interface AddPageButtonProps {
sharedStore: SharedStore;
inPageOverview: boolean;
getPageTemplates?: GetTemplates;
disabled: boolean;
}

export const AddPageButton = (props: AddPageButtonProps) => {
const { className, style, parentModName, inPageOverview, sharedEvent, sharedStore, getPageTemplates } = props;
const { className, style, parentModName, inPageOverview, sharedEvent, sharedStore, getPageTemplates, disabled } = props;
const rootClassName = generateClassName(parentModName, modName);
const [moduleLocale] = useLocale('PanelPage');
const { getContainer } = useContext(ConfigContext);
Expand All @@ -38,6 +39,7 @@ export const AddPageButton = (props: AddPageButtonProps) => {
type="text"
style={style}
className={classnames(rootClassName, className)}
disabled={disabled}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
Expand Down
15 changes: 11 additions & 4 deletions packages/studio/src/modules/panel-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface PanelPageProps {
sharedEvent: SharedEvent;
useContextMenuOptions: HookUseContextMenuOptions;
getPageTemplates?: GetTemplates;
reverseTree: boolean;
}

const pageTreeKey = 'page-tree';
Expand All @@ -31,7 +32,7 @@ const pageTreeHeightRatio = 1;
const elementTreeHeightRatio = 3;

export const PanelPage = (props: PanelPageProps) => {
const { className, style, height, defaultSelectedElementUUIDs = [], sharedStore, sharedEvent, useContextMenuOptions, getPageTemplates } = props;
const { className, style, height, defaultSelectedElementUUIDs = [], sharedStore, sharedEvent, useContextMenuOptions, getPageTemplates, reverseTree } = props;
const { state, dispatch } = useContext(Context);
const { pageTree, elementTree, selectedUUIDs, editingData, editingDataPosition, data } = state;

Expand Down Expand Up @@ -73,7 +74,7 @@ export const PanelPage = (props: PanelPageProps) => {
useEffect(() => {
const idraw = sharedStore.getStatic('idraw');
const listenSelectedPage = (e: { uuids?: string[] }) => {
if (refInPageOverview.current === true) {
if (inPageOverview === true) {
const { uuids = [] } = e;
setSelectedPageUUIDs([...uuids]);
}
Expand All @@ -83,7 +84,7 @@ export const PanelPage = (props: PanelPageProps) => {
return () => {
idraw?.off(eventKeys.SELECT, listenSelectedPage);
};
}, []);
}, [inPageOverview]);

useEffect(() => {
if (editingDataPosition.length === 1 && pageTree.length > 0) {
Expand Down Expand Up @@ -127,7 +128,10 @@ export const PanelPage = (props: PanelPageProps) => {
const pageKeys: string[] = [];
if (pageTree.length > 0) {
pageKeys.push(pageTree[0].uuid);
sharedEvent.trigger('resetEditingView', { type: 'go-to-page', position: [0] });
sharedEvent.trigger('resetEditingView', {
type: 'go-to-page',
position: reverseTree === true ? [pageTree.length > 0 ? pageTree.length - 1 : 0] : [0]
});
}
setSelectedPageUUIDs(pageKeys);
idraw?.enable('selectInGroup');
Expand Down Expand Up @@ -238,6 +242,7 @@ export const PanelPage = (props: PanelPageProps) => {
</div>
<div style={{ display: 'flex' }}>
<AddPageButton
disabled={inPageOverview}
inPageOverview={inPageOverview}
parentModName={modName}
sharedEvent={sharedEvent}
Expand All @@ -253,6 +258,7 @@ export const PanelPage = (props: PanelPageProps) => {
<PageTree
ref={refPageTree}
height={pageTreeHeight}
reverse={reverseTree}
treeData={pageTree}
selectedKeys={selectedPageUUIDs}
onTitleChange={({ uuid, value }) => {
Expand Down Expand Up @@ -355,6 +361,7 @@ export const PanelPage = (props: PanelPageProps) => {
<ElementTree
ref={refElementTree}
height={elementTreeHeight}
reverse={reverseTree}
treeData={elementTree}
selectedKeys={selectedUUIDs}
// expandedKeys={expandedElementKeys}
Expand Down
Loading

0 comments on commit 772374a

Please sign in to comment.