diff --git a/package.json b/package.json index f7d412a..562b915 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "private": false, - "version": "0.4.0-alpha.10", + "version": "0.4.0-alpha.11", "workspaces": [ "packages/*" ], @@ -19,7 +19,7 @@ "upgrade:version": "vite-node ./scripts/upgrade-version.ts && pnpm i" }, "dependencies": { - "idraw": "0.4.0-beta.10", + "idraw": "0.4.0-beta.11", "antd": "5.12.1" }, "devDependencies": { diff --git a/packages/studio-base/package.json b/packages/studio-base/package.json index 55def76..01aee11 100644 --- a/packages/studio-base/package.json +++ b/packages/studio-base/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/studio-base", - "version": "0.4.0-alpha.10", + "version": "0.4.0-alpha.11", "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", @@ -22,7 +22,7 @@ "peerDependencies": { "antd": "^5.12.1", "classnames": "^2.3.2", - "idraw": "^0.4.0-beta.10", + "idraw": "^0.4.0-beta.11", "react": "^18.2.0", "react-color": "^2.19.3", "react-dom": "^18.2.0" diff --git a/packages/studio-base/src/modules/element-detail/content-attribute.tsx b/packages/studio-base/src/modules/element-detail/content-attribute.tsx index 9cb7398..9594676 100644 --- a/packages/studio-base/src/modules/element-detail/content-attribute.tsx +++ b/packages/studio-base/src/modules/element-detail/content-attribute.tsx @@ -67,12 +67,12 @@ export const ContentAttribute = (props: ContentAttributeProps) => { return ( <>
- {['rect', 'circle', 'text', 'group'].includes(element?.type as string) && ( + {['rect', 'circle', 'text', 'group', 'path'].includes(element?.type as string) && ( {moduleLocale.background} - + { {moduleLocale.opacity} - + diff --git a/packages/studio-base/src/modules/element-detail/index.tsx b/packages/studio-base/src/modules/element-detail/index.tsx index dfa5db1..d444a21 100644 --- a/packages/studio-base/src/modules/element-detail/index.tsx +++ b/packages/studio-base/src/modules/element-detail/index.tsx @@ -3,7 +3,7 @@ import type { CSSProperties } from 'react'; import classnames from 'classnames'; import type { Element, ElementType, RecursivePartial } from 'idraw'; import { getDefaultElementDetailConfig } from 'idraw'; -import { Collapse } from 'antd'; +import { Collapse, Empty } from 'antd'; import type { CollapseProps } from 'antd'; import { ConfigContext } from '../config-provider'; import { BasicAttribute } from './basic-attribute'; @@ -59,7 +59,7 @@ export const ElementDetail = (props: ElementDetailProps) => { { key: 'border-attribute', label: moduleLocale.borderAttribute, - children: ( + children: ['rect', 'circle', 'text', 'image', 'group'].includes(elem?.type as string) ? ( { onChange?.(e); }} /> + ) : ( + ) }, { @@ -87,7 +89,7 @@ export const ElementDetail = (props: ElementDetailProps) => { { key: 'shadow-attribute', label: moduleLocale.shadowAttribute, - children: ( + children: ['rect', 'circle', 'text', 'image', 'group'].includes(elem?.type as string) ? ( { onChange?.(e); }} /> + ) : ( + ) } ]; diff --git a/packages/studio/package.json b/packages/studio/package.json index f095fba..3f2f7e1 100644 --- a/packages/studio/package.json +++ b/packages/studio/package.json @@ -1,6 +1,6 @@ { "name": "@idraw/studio", - "version": "0.4.0-alpha.10", + "version": "0.4.0-alpha.11", "main": "dist/index.js", "module": "dist/index.js", "types": "dist/index.d.ts", @@ -20,13 +20,13 @@ "author": "chenshenhai", "license": "MIT", "dependencies": { - "@idraw/studio-base": "^0.4.0-alpha.10", + "@idraw/studio-base": "^0.4.0-alpha.11", "classnames": "^2.3.2", "is-hotkey": "^0.2.0" }, "peerDependencies": { "antd": "^5.12.1", - "idraw": "^0.4.0-beta.10", + "idraw": "^0.4.0-beta.11", "react": "^18.2.0", "react-color": "^2.19.3", "react-dom": "^18.2.0" diff --git a/packages/studio/src/modules/sketch/index.tsx b/packages/studio/src/modules/sketch/index.tsx index 063cd0a..f9edb15 100644 --- a/packages/studio/src/modules/sketch/index.tsx +++ b/packages/studio/src/modules/sketch/index.tsx @@ -121,6 +121,30 @@ export const Sketch = (props: SketchProps) => { idraw.selectElements([elem.uuid]); }; + const addElementCallback = (e: SharedEventMap['addElement']) => { + const { element, position = [] } = e; + const centerPoint = idraw.getViewCenter(); + const newEditingData = idraw.addElement( + { + ...element, + ...{ + x: centerPoint.x - element.w / 2, + y: centerPoint.y - element.h / 2 + } + }, + { position } + ); + const newTreeData = getElementTree(newEditingData); + dispatch({ + type: 'update', + payload: { + editingData: { ...newEditingData }, + treeData: newTreeData + } + }); + idraw.selectElements([element.uuid]); + }; + const deleteElementCallback = (e: SharedEventMap['deleteElement']) => { const { uuid } = e; idraw?.deleteElement(uuid); @@ -247,6 +271,7 @@ export const Sketch = (props: SketchProps) => { idraw.on('change', listenDataChange); idraw.on(middlewareEventScale, listenMiddlewareEventScale); sharedEvent.on('createElement', createElementCallback); + sharedEvent.on('addElement', addElementCallback); sharedEvent.on('deleteElement', deleteElementCallback); sharedEvent.on('resetEditingView', resetEditingViewCallback); sharedEvent.on('resetData', resetDataCallback); @@ -273,7 +298,8 @@ export const Sketch = (props: SketchProps) => { idraw.off(middlewareEventSelect, listenMiddlewareEventSelect); idraw.off('change', listenDataChange); idraw.off(middlewareEventScale, listenMiddlewareEventScale); - // sharedEvent.off('addElement', createElementCallback); + // sharedEvent.off('createElement', createElementCallback); + // sharedEvent.off('addElement', addElementCallback); // sharedEvent.off('deleteElement', deleteElementCallback); // sharedEvent.off('resetEditingView', resetEditingViewCallback); // sharedEvent.off('resetData', resetDataCallback); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84e4e6b..a6246de 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ importers: specifier: 5.12.1 version: 5.12.1(react-dom@18.2.0)(react@18.2.0) idraw: - specifier: 0.4.0-beta.10 - version: 0.4.0-beta.10 + specifier: 0.4.0-beta.11 + version: 0.4.0-beta.11 devDependencies: '@ant-design/icons': specifier: ^5.2.6 @@ -160,7 +160,7 @@ importers: packages/studio: dependencies: '@idraw/studio-base': - specifier: ^0.4.0-alpha.10 + specifier: ^0.4.0-alpha.11 version: link:../studio-base antd: specifier: ^5.12.1 @@ -169,8 +169,8 @@ importers: specifier: ^2.3.2 version: 2.3.2 idraw: - specifier: ^0.4.0-beta.10 - version: 0.4.0-beta.10 + specifier: ^0.4.0-beta.11 + version: 0.4.0-beta.11 is-hotkey: specifier: ^0.2.0 version: 0.2.0 @@ -206,8 +206,8 @@ importers: specifier: ^2.3.2 version: 2.3.2 idraw: - specifier: ^0.4.0-beta.10 - version: 0.4.0-beta.10 + specifier: ^0.4.0-beta.11 + version: 0.4.0-beta.11 react: specifier: ^18.2.0 version: 18.2.0 @@ -2022,42 +2022,42 @@ packages: react: 18.2.0 dev: false - /@idraw/board@0.4.0-beta.10(@idraw/renderer@0.4.0-beta.10)(@idraw/util@0.4.0-beta.10): - resolution: {integrity: sha512-qtAo7xXbo/Z0WlpaU93A+lURUL6ebKbwS8jITv/eUQhrCuA1joQmKxysL4bgqmcQww/EN5iH5S6+Z3JjiskfUw==} + /@idraw/board@0.4.0-beta.11(@idraw/renderer@0.4.0-beta.11)(@idraw/util@0.4.0-beta.11): + resolution: {integrity: sha512-Nvsdme59I9sd8u+V+b4NsleuMEMvF6GbMm1WWowgkG+UPuDwUAZfOAx7WTi3P1HuIxb9pzH2/TFIC4AdSd75xg==} peerDependencies: - '@idraw/renderer': ^0.4.0-beta.10 - '@idraw/util': ^0.4.0-beta.10 + '@idraw/renderer': ^0.4.0-beta.11 + '@idraw/util': ^0.4.0-beta.11 dependencies: - '@idraw/renderer': 0.4.0-beta.10(@idraw/util@0.4.0-beta.10) - '@idraw/util': 0.4.0-beta.10 + '@idraw/renderer': 0.4.0-beta.11(@idraw/util@0.4.0-beta.11) + '@idraw/util': 0.4.0-beta.11 dev: false - /@idraw/core@0.4.0-beta.10(@idraw/board@0.4.0-beta.10)(@idraw/renderer@0.4.0-beta.10)(@idraw/util@0.4.0-beta.10): - resolution: {integrity: sha512-0xmrU7Fi+99yaQfCkIt4uHq6wsGfz4+aL2O4kNla/r0KfxTmasWRnDbL2NQVA43zu+VbDnX/zFTNyRXjJsdeDQ==} + /@idraw/core@0.4.0-beta.11(@idraw/board@0.4.0-beta.11)(@idraw/renderer@0.4.0-beta.11)(@idraw/util@0.4.0-beta.11): + resolution: {integrity: sha512-/sJKne3hHv4K2rBn+SqjvrwPVRnt4GQxzGQpgwEpOGSaGSZDEYmkMu9Y9+CeEm7mPYxk/Dzt98JLCDUpl1d4xw==} peerDependencies: - '@idraw/board': ^0.4.0-beta.10 - '@idraw/renderer': ^0.4.0-beta.10 - '@idraw/util': ^0.4.0-beta.10 + '@idraw/board': ^0.4.0-beta.11 + '@idraw/renderer': ^0.4.0-beta.11 + '@idraw/util': ^0.4.0-beta.11 dependencies: - '@idraw/board': 0.4.0-beta.10(@idraw/renderer@0.4.0-beta.10)(@idraw/util@0.4.0-beta.10) - '@idraw/renderer': 0.4.0-beta.10(@idraw/util@0.4.0-beta.10) - '@idraw/util': 0.4.0-beta.10 + '@idraw/board': 0.4.0-beta.11(@idraw/renderer@0.4.0-beta.11)(@idraw/util@0.4.0-beta.11) + '@idraw/renderer': 0.4.0-beta.11(@idraw/util@0.4.0-beta.11) + '@idraw/util': 0.4.0-beta.11 dev: false - /@idraw/renderer@0.4.0-beta.10(@idraw/util@0.4.0-beta.10): - resolution: {integrity: sha512-GXxATN7i2aScg5PnByuN1Js+bd2+/CiM8nJM/RiRZjiFQJNB3AXGDYQlXPjGlMvKxseuxQBSNy7QpKUbXYjJUw==} + /@idraw/renderer@0.4.0-beta.11(@idraw/util@0.4.0-beta.11): + resolution: {integrity: sha512-IoUb3NT+fRlRBR1FGzEaIju0lo4w09lQ4Ov98y42tGPrtvxg/Ffyks3+XAa944rWdYToaCM7Upn5yZ6iWiprUg==} peerDependencies: - '@idraw/util': ^0.4.0-beta.10 + '@idraw/util': ^0.4.0-beta.11 dependencies: - '@idraw/util': 0.4.0-beta.10 + '@idraw/util': 0.4.0-beta.11 dev: false - /@idraw/types@0.4.0-beta.10: - resolution: {integrity: sha512-BNB8ZwCsx0POaJaxAE3Y28SLBExS/bqSgYqeF9nHzIp1xTM05sSYsgNMKpl/SiflqlLJBIfIi986k7GjGMbUww==} + /@idraw/types@0.4.0-beta.11: + resolution: {integrity: sha512-EKyl10ckX92SfACZ1OClkJx2BPTxeKBwc559kuZ3Xxodp0QZmCNnekM3gp8OoQ4N6RIMLKKlCLnzPDro1iOtqg==} dev: false - /@idraw/util@0.4.0-beta.10: - resolution: {integrity: sha512-YW6oufQsG+eRYf0FH4fQ39sdC/drVUAW4NeTfSzmQcK+uWwJ6nXL+IKuQNQ5dqC9uZN7h8CaZlcciBhgDBJdtA==} + /@idraw/util@0.4.0-beta.11: + resolution: {integrity: sha512-BcUkt4ivrD1EIPxHqv+8uglSnHxgVyv3Ua2fwoNSUdoWhVw9yPNfFJaTgo1RqkffoFDp1Hkzveej1EqW972kfQ==} dev: false /@isaacs/cliui@8.0.2: @@ -4877,14 +4877,14 @@ packages: safer-buffer: 2.1.2 dev: true - /idraw@0.4.0-beta.10: - resolution: {integrity: sha512-zGy69kEUbGlmIxcFaJto1zjo72q79ZGUJQ6utlXdmQ5EZVCHcozC6H1ixLnXGIXnw7ZDfj94joG9iHzMpKAy2g==} + /idraw@0.4.0-beta.11: + resolution: {integrity: sha512-P2PDmck8XVK2BJPTC2uGs8aHA79Ygfzp0e9hnEwSiMqPldo3iQRzcczbX4tFhpzvSoA2fXpOUiUcLvgVUJnyKQ==} dependencies: - '@idraw/board': 0.4.0-beta.10(@idraw/renderer@0.4.0-beta.10)(@idraw/util@0.4.0-beta.10) - '@idraw/core': 0.4.0-beta.10(@idraw/board@0.4.0-beta.10)(@idraw/renderer@0.4.0-beta.10)(@idraw/util@0.4.0-beta.10) - '@idraw/renderer': 0.4.0-beta.10(@idraw/util@0.4.0-beta.10) - '@idraw/types': 0.4.0-beta.10 - '@idraw/util': 0.4.0-beta.10 + '@idraw/board': 0.4.0-beta.11(@idraw/renderer@0.4.0-beta.11)(@idraw/util@0.4.0-beta.11) + '@idraw/core': 0.4.0-beta.11(@idraw/board@0.4.0-beta.11)(@idraw/renderer@0.4.0-beta.11)(@idraw/util@0.4.0-beta.11) + '@idraw/renderer': 0.4.0-beta.11(@idraw/util@0.4.0-beta.11) + '@idraw/types': 0.4.0-beta.11 + '@idraw/util': 0.4.0-beta.11 dev: false /ieee754@1.2.1: