Compare commits
	
		
			2 Commits
		
	
	
		
			aakansha-c
			...
			fix_wysiwy
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 154f7bd8e5 | ||
|   | ba06565673 | 
							
								
								
									
										5
									
								
								.env
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,5 @@ | ||||
| REACT_APP_BACKEND_V1_GET_URL=https://json.excalidraw.com/api/v1/ | ||||
| REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/ | ||||
| REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/ | ||||
| REACT_APP_SOCKET_SERVER_URL=https://portal.excalidraw.com | ||||
| REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}' | ||||
| @@ -1,13 +0,0 @@ | ||||
| REACT_APP_BACKEND_V2_GET_URL=https://json-dev.excalidraw.com/api/v2/ | ||||
| REACT_APP_BACKEND_V2_POST_URL=https://json-dev.excalidraw.com/api/v2/post/ | ||||
|  | ||||
| REACT_APP_LIBRARY_URL=https://libraries.excalidraw.com | ||||
| REACT_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries | ||||
|  | ||||
| # collaboration WebSocket server (https://github.com/excalidraw/excalidraw-room) | ||||
| REACT_APP_WS_SERVER_URL=http://localhost:3002 | ||||
|  | ||||
| # set this only if using the collaboration workflow we use on excalidraw.com | ||||
| REACT_APP_PORTAL_URL= | ||||
|  | ||||
| REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyCMkxA60XIW8KbqMYL7edC4qT5l4qHX2h8","authDomain":"excalidraw-oss-dev.firebaseapp.com","projectId":"excalidraw-oss-dev","storageBucket":"excalidraw-oss-dev.appspot.com","messagingSenderId":"664559512677","appId":"1:664559512677:web:a385181f2928d328a7aa8c"}' | ||||
| @@ -1,15 +1 @@ | ||||
| REACT_APP_BACKEND_V2_GET_URL=https://json.excalidraw.com/api/v2/ | ||||
| REACT_APP_BACKEND_V2_POST_URL=https://json.excalidraw.com/api/v2/post/ | ||||
|  | ||||
| REACT_APP_LIBRARY_URL=https://libraries.excalidraw.com | ||||
| REACT_APP_LIBRARY_BACKEND=https://us-central1-excalidraw-room-persistence.cloudfunctions.net/libraries | ||||
|  | ||||
| REACT_APP_PORTAL_URL=https://portal.excalidraw.com | ||||
| # Fill to set socket server URL used for collaboration. | ||||
| # Meant for forks only: excalidraw.com uses custom REACT_APP_PORTAL_URL flow | ||||
| REACT_APP_WS_SERVER_URL= | ||||
|  | ||||
| REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyAd15pYlMci_xIp9ko6wkEsDzAAA0Dn0RU","authDomain":"excalidraw-room-persistence.firebaseapp.com","databaseURL":"https://excalidraw-room-persistence.firebaseio.com","projectId":"excalidraw-room-persistence","storageBucket":"excalidraw-room-persistence.appspot.com","messagingSenderId":"654800341332","appId":"1:654800341332:web:4a692de832b55bd57ce0c1"}' | ||||
|  | ||||
| # production-only vars | ||||
| REACT_APP_GOOGLE_ANALYTICS_ID=UA-387204-13 | ||||
|   | ||||
| @@ -5,4 +5,3 @@ package-lock.json | ||||
| firebase/ | ||||
| dist/ | ||||
| public/workbox | ||||
| src/packages/excalidraw/types | ||||
|   | ||||
| @@ -1,7 +1,6 @@ | ||||
| { | ||||
|   "extends": ["@excalidraw/eslint-config", "react-app"], | ||||
|   "rules": { | ||||
|     "import/no-anonymous-default-export": "off", | ||||
|     "no-restricted-globals": "off" | ||||
|     "import/no-anonymous-default-export": "off" | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										6
									
								
								.github/assets/crowdin.svg
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,6 +0,0 @@ | ||||
| <svg height="50" viewBox="0 0 257 50" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2"> | ||||
| 	<path fill="#fff" d="M-7.977-9.253h288.95v78.13H-7.977z" /> | ||||
| 	<path d="M67.626 32.315c-1.34 0-2.207 0-2.207-1.025 0-.236.079-.551.236-.946l4.02-8.907h12.929c1.34 0 2.128-.08 2.128.946 0 .315-.078.63-.236.946l-.788 1.734h5.439l1.104-2.444c.157-.394.157-.71.157-1.025 0-2.207-2.365-3.31-4.257-3.31H65.655l-5.754 12.691c-.158.394-.158.71-.158 1.025 0 2.365 1.97 3.547 4.73 3.547h20.26l1.26-3.232H67.627zm42.727-14.11H95.059l-6.937 17.342h5.518l5.519-14.032h8.435c1.34 0 2.05-.157 2.05.868 0 .315-.08.63-.237.946l-.789 1.734h5.518l1.104-2.444c.158-.394.158-.71.158-1.025 0-1.025-.552-1.892-1.734-2.522-.946-.473-2.208-.868-3.311-.868zm30.35 0h-21.285l-5.754 12.691c-.158.316-.158.63-.158 1.025 0 1.97 1.419 3.547 3.232 3.547h21.52l5.834-13.007c.158-.394.158-.71.158-1.024 0-2.05-1.734-3.233-3.547-3.233zm-6.701 14.19h-12.85c-1.34 0-1.97-.159-1.97-1.183 0-.316.079-.631.236-.946l4.178-8.908h12.929c1.26 0 1.891-.08 1.891.946 0 .315-.078.63-.236 1.025l-4.178 9.065zm13.953 3.152h28.695l7.41-17.264h-5.676l-6.149 14.032h-9.223l6.149-14.11h-5.676l-6.386 14.031h-6.306c-1.34 0-2.05-.157-2.05-1.182 0-.315.08-.63.237-.946l5.282-11.982h-5.519l-5.518 12.455c-1.103 3.39 2.207 4.966 4.73 4.966zm67.874-23.649l-5.913 1.577-1.97 4.73h-14.584c-3.548 0-6.7 1.576-8.278 4.73l-3.941 9.46c-.788 1.576.63 3.152 3.31 3.152h21.128l10.248-23.649zm-27.591 20.496c-1.183 0-1.735-.788-1.577-1.577l3.469-7.567c.788-1.813 2.68-1.892 4.414-1.892h11.825l-4.73 11.036h-13.401zm26.802 3.153l7.49-17.737-6.307 1.183-7.095 16.554h5.912zm8.435-19.944l1.656-3.705-6.228 1.261-1.577 3.705 6.15-1.26zm22.23 2.601h-20.417l-7.094 17.343h5.518l5.518-14.19h13.48c1.34 0 2.05-.078 2.05 1.026 0 .315-.08.63-.237.946l-5.518 12.297h5.518l5.834-13.007c.157-.315.157-.63.157-1.025 0-1.025-.552-1.892-1.734-2.522-.867-.473-1.892-.868-3.074-.868zm-192.82.868c-8.672-1.025-16.476.71-17.58 6.148 0 .237-.157 1.262-.157 1.42l1.419.157v2.207l-1.34-.157c.551 5.597 3.626 7.252 6.858 7.331h.236c1.42.079 2.917-.237 4.178-.788.08 0 .08-.08.08-.08v-.157c0-.079-.08-.079-.08-.157-.078 0-.078-.08-.157-.08-2.996.395-5.755-2.049-5.755-7.015 0-6.228 4.888-8.514 12.298-8.514.236.158.315-.237 0-.315zM36.803 30.344c.788 0 1.498.158 2.207.237.237 1.655 1.025 3.232 2.208 4.336-1.183-.158-2.208-.71-3.075-1.498a6.051 6.051 0 01-1.34-3.075zm2.68-5.439c0 .237-.157.552-.236.946h-1.025c-.552 0-1.025-.079-1.576-.158v-.157c.63-3.39 4.02-4.73 7.252-5.36a7.997 7.997 0 00-2.76 1.812c-.787.868-1.34 1.813-1.655 2.917z" fill="#2e3340" fill-rule="nonzero" /> | ||||
| 	<path d="M56.274 14.105c-6.543-1.813-34.055-4.02-34.055 11.273.946.158 1.577.315 2.05.394-.079 1.183 0 2.444 0 3.626l-2.444-.394c0 8.83 6.464 11.667 11.588 11.667.868 0 1.656-.078 2.523-.157 2.128-.237 4.178-.867 5.991-1.892.079 0 .079-.08.079-.08v-.157c0-.079-.079-.079-.079-.157-.079 0-.079-.08-.157-.08-4.336.868-10.17-.315-10.17-10.563 0-13.637 19.156-12.77 24.753-13.007.08 0 .08-.079.08-.079v-.157c0-.08 0-.08-.08-.158 0-.079 0-.079-.079-.079zM33.414 39.41a9.362 9.362 0 01-6.78-2.286c-1.892-1.656-3.074-3.942-3.31-6.385 1.655.236 3.704.394 5.438.473a9.43 9.43 0 001.577 4.808c.946 1.42 2.207 2.602 3.705 3.39h-.63zM28.92 24.984l-2.601-.237-2.602-.315c0-7.962 12.77-11.036 18.683-10.484-5.912 1.34-13.086 4.099-13.48 11.036z" fill="#2e3340" fill-rule="nonzero" /> | ||||
| 	<path d="M59.664 9.533c-7.962-2.68-17.027-4.02-25.462-3.941-12.22 0-27.67 3.626-28.064 16.081l3.31.788c-.393 1.577-.393 4.81-.393 4.81s-1.892-.553-2.917-.79c0 14.821 8.671 18.526 17.027 18.526 3.39 0 6.701-.552 9.854-1.734.08 0 .08-.08.08-.08v-.157c0-.079-.08-.079-.08-.157h-.157c-2.602 0-4.651.867-8.75-2.05-7.963-5.597-7.017-20.102 2.128-26.408 9.46-6.701 29.798-4.573 33.267-4.415h.157s.079 0 .079-.079v-.236l-.079-.158zm-36.42 34.292c-9.932 0-14.978-5.36-15.45-15.609 2.68.71 5.202 1.34 7.961 1.734-.157 4.02 1.262 7.962 4.02 11.037a12.488 12.488 0 005.046 2.916l-1.577-.078zM45.632 7.956c-12.06 0-26.014 1.42-28.773 14.584 0 0-7.41-1.182-9.066-1.576C9.843 4.409 38.38 5.67 49.89 7.956h-4.257z" fill="#2e3340" fill-rule="nonzero" /> | ||||
| </svg> | ||||
| Before Width: | Height: | Size: 4.1 KiB | 
							
								
								
									
										9
									
								
								.github/assets/sentry.svg
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,9 +0,0 @@ | ||||
| <svg class="__sntry__ css-15xgryy e10nushx5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 222 66" height="50" style="background-color: rgb(255, 255, 255);"> | ||||
| 	<defs> | ||||
| 		<style type="text/css"> | ||||
| 			@media (prefers-color-scheme: dark) {svg.__sntry__ { background-color: #584674 !important; }path.__sntry__ { fill: #ffffff !important; }} | ||||
| 		</style> | ||||
| 	</defs> | ||||
| 	<path d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z M124.32,28.28,109.56,9.22h-3.68V34.77h3.73V15.19l15.18,19.58h3.26V9.22h-3.73ZM87.15,23.54h13.23V20.22H87.14V12.53h14.93V9.21H83.34V34.77h18.92V31.45H87.14ZM71.59,20.3h0C66.44,19.06,65,18.08,65,15.7c0-2.14,1.89-3.59,4.71-3.59a12.06,12.06,0,0,1,7.07,2.55l2-2.83a14.1,14.1,0,0,0-9-3c-5.06,0-8.59,3-8.59,7.27,0,4.6,3,6.19,8.46,7.52C74.51,24.74,76,25.78,76,28.11s-2,3.77-5.09,3.77a12.34,12.34,0,0,1-8.3-3.26l-2.25,2.69a15.94,15.94,0,0,0,10.42,3.85c5.48,0,9-2.95,9-7.51C79.75,23.79,77.47,21.72,71.59,20.3ZM195.7,9.22l-7.69,12-7.64-12h-4.46L186,24.67V34.78h3.84V24.55L200,9.22Zm-64.63,3.46h8.37v22.1h3.84V12.68h8.37V9.22H131.08ZM169.41,24.8c3.86-1.07,6-3.77,6-7.63,0-4.91-3.59-8-9.38-8H154.67V34.76h3.8V25.58h6.45l6.48,9.2h4.44l-7-9.82Zm-10.95-2.5V12.6h7.17c3.74,0,5.88,1.77,5.88,4.84s-2.29,4.86-5.84,4.86Z" transform="translate(11, 11)" fill="#362d59" class="__sntry__"> | ||||
| 	</path> | ||||
| </svg> | ||||
| Before Width: | Height: | Size: 1.7 KiB | 
							
								
								
									
										3
									
								
								.github/assets/vercel.svg
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,3 +0,0 @@ | ||||
| <svg height="50" viewBox="0 0 164 50" xmlns="http://www.w3.org/2000/svg" style="background:#fff" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2"> | ||||
| 	<path d="M78.21 15.587c-5.672 0-9.762 3.864-9.762 9.661s4.604 9.66 10.276 9.66c3.427 0 6.448-1.416 8.319-3.805l-3.931-2.372c-1.038 1.186-2.615 1.879-4.388 1.879-2.461 0-4.552-1.342-5.328-3.489h14.397c.113-.601.18-1.223.18-1.879 0-5.79-4.09-9.655-9.763-9.655zm-4.86 7.783c.642-2.142 2.399-3.489 4.855-3.489 2.461 0 4.219 1.347 4.855 3.489h-9.71zm60.187-7.783c-5.673 0-9.763 3.864-9.763 9.661s4.604 9.66 10.276 9.66c3.427 0 6.449-1.416 8.319-3.805l-3.931-2.372c-1.038 1.186-2.615 1.879-4.388 1.879-2.461 0-4.552-1.342-5.328-3.489h14.397c.113-.601.18-1.223.18-1.879 0-5.79-4.09-9.655-9.762-9.655zm-4.856 7.783c.642-2.142 2.4-3.489 4.856-3.489 2.46 0 4.218 1.347 4.855 3.489h-9.711zm-20.054 1.878c0 3.22 2.015 5.367 5.139 5.367 2.116 0 3.704-1.003 4.52-2.64l3.947 2.378c-1.634 2.843-4.696 4.556-8.467 4.556-5.678 0-9.763-3.864-9.763-9.661s4.09-9.66 9.763-9.66c3.77 0 6.828 1.712 8.467 4.556l-3.946 2.377c-.817-1.637-2.405-2.64-4.521-2.64-3.12 0-5.139 2.147-5.139 5.367zm42.378-15.565v24.69h-4.624V9.682h4.624zM24.73 7l18.985 34.35H5.744L24.73 7zm47.465 2.683L57.956 35.446 43.72 9.683h5.338l8.9 16.102 8.898-16.102h5.339zm30.268 6.44v5.202a5.634 5.634 0 00-1.644-.263c-2.985 0-5.138 2.147-5.138 5.367v7.943h-4.624V16.124h4.624v4.938c0-2.727 3.036-4.938 6.782-4.938z" fill-rule="nonzero" /> | ||||
| </svg> | ||||
| Before Width: | Height: | Size: 1.4 KiB | 
							
								
								
									
										3
									
								
								.github/dependabot.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -10,7 +10,6 @@ updates: | ||||
|       - lipis | ||||
|     assignees: | ||||
|       - lipis | ||||
|     open-pull-requests-limit: 20 | ||||
|  | ||||
|   - package-ecosystem: npm | ||||
|     directory: /src/packages/excalidraw/ | ||||
| @@ -22,7 +21,6 @@ updates: | ||||
|       - ad1992 | ||||
|     assignees: | ||||
|       - ad1992 | ||||
|     open-pull-requests-limit: 20 | ||||
|  | ||||
|   - package-ecosystem: npm | ||||
|     directory: /src/packages/utils/ | ||||
| @@ -34,4 +32,3 @@ updates: | ||||
|       - ad1992 | ||||
|     assignees: | ||||
|       - ad1992 | ||||
|     open-pull-requests-limit: 20 | ||||
|   | ||||
							
								
								
									
										27
									
								
								.github/workflows/autorelease-excalidraw.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,27 +0,0 @@ | ||||
| name: Auto release @excalidraw/excalidraw-next | ||||
| on: | ||||
|   push: | ||||
|     branches: | ||||
|       - master | ||||
|  | ||||
| jobs: | ||||
|   Auto-release-excalidraw-next: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|         with: | ||||
|           fetch-depth: 2 | ||||
|       - name: Setup Node.js 14.x | ||||
|         uses: actions/setup-node@v2 | ||||
|         with: | ||||
|           node-version: 14.x | ||||
|       - name: Set up publish access | ||||
|         run: | | ||||
|           npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} | ||||
|         env: | ||||
|           NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||||
|       - name: Auto release | ||||
|         run: | | ||||
|           yarn add @actions/core | ||||
|           yarn autorelease | ||||
							
								
								
									
										55
									
								
								.github/workflows/autorelease-preview.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -1,55 +0,0 @@ | ||||
| name: Auto release preview @excalidraw/excalidraw-preview | ||||
| on: | ||||
|   issue_comment: | ||||
|     types: [created, edited] | ||||
|  | ||||
| jobs: | ||||
|   Auto-release-excalidraw-preview: | ||||
|     name: Auto release preview | ||||
|     if: github.event.comment.body == '@excalibot release package' && github.event.issue.pull_request | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - name: React to release comment | ||||
|         uses: peter-evans/create-or-update-comment@v1 | ||||
|         with: | ||||
|           token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }} | ||||
|           comment-id: ${{ github.event.comment.id }} | ||||
|           reactions: "+1" | ||||
|       - name: Get PR SHA | ||||
|         id: sha | ||||
|         uses: actions/github-script@v4 | ||||
|         with: | ||||
|           result-encoding: string | ||||
|           script: | | ||||
|             const { owner, repo, number } = context.issue; | ||||
|             const pr = await github.pulls.get({ | ||||
|               owner, | ||||
|               repo, | ||||
|               pull_number: number, | ||||
|             }); | ||||
|             return pr.data.head.sha | ||||
|       - uses: actions/checkout@v2 | ||||
|         with: | ||||
|           ref: ${{ steps.sha.outputs.result }} | ||||
|           fetch-depth: 2 | ||||
|       - name: Setup Node.js 14.x | ||||
|         uses: actions/setup-node@v2 | ||||
|         with: | ||||
|           node-version: 14.x | ||||
|       - name: Set up publish access | ||||
|         run: | | ||||
|           npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN} | ||||
|         env: | ||||
|           NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||||
|       - name: Auto release preview | ||||
|         id: "autorelease" | ||||
|         run: | | ||||
|           yarn add @actions/core | ||||
|           yarn autorelease preview ${{ github.event.issue.number }} | ||||
|       - name: Post comment post release | ||||
|         if: always() | ||||
|         uses: peter-evans/create-or-update-comment@v1 | ||||
|         with: | ||||
|           token: ${{ secrets.PUSH_TRANSLATIONS_COVERAGE_PAT }} | ||||
|           issue-number: ${{ github.event.issue.number }} | ||||
|           body: "@${{ github.event.comment.user.login }} ${{ steps.autorelease.outputs.result }}" | ||||
							
								
								
									
										29
									
								
								.github/workflows/build-packages.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,29 @@ | ||||
| name: Build packages | ||||
|  | ||||
| on: | ||||
|   push: | ||||
|     branches: | ||||
|       - master | ||||
|   pull_request: | ||||
|  | ||||
| jobs: | ||||
|   packages: | ||||
|     runs-on: ubuntu-latest | ||||
|  | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - name: Setup Node.js 14.x | ||||
|         uses: actions/setup-node@v2 | ||||
|         with: | ||||
|           node-version: 14.x | ||||
|       - name: Install dependencies | ||||
|         run: | | ||||
|           yarn --frozen-lockfile | ||||
|           yarn --cwd src/packages/excalidraw | ||||
|           yarn --cwd src/packages/utils | ||||
|       - name: Build @excalidraw/excalidraw | ||||
|         run: | | ||||
|           yarn --cwd src/packages/excalidraw run pack | ||||
|       - name: Build @excalidraw/utils | ||||
|         run: | | ||||
|           yarn --cwd src/packages/utils run pack | ||||
							
								
								
									
										2
									
								
								.github/workflows/publish-docker.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -11,7 +11,7 @@ jobs: | ||||
|  | ||||
|     steps: | ||||
|       - uses: actions/checkout@v2 | ||||
|       - uses: docker/build-push-action@v2 | ||||
|       - uses: docker/build-push-action@v1 | ||||
|         with: | ||||
|           username: ${{ secrets.DOCKER_USERNAME }} | ||||
|           password: ${{ secrets.DOCKER_PASSWORD }} | ||||
|   | ||||
							
								
								
									
										7
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						| @@ -5,11 +5,9 @@ | ||||
| .env.test.local | ||||
| .envrc | ||||
| .eslintcache | ||||
| .history | ||||
| .idea | ||||
| .vercel | ||||
| .vscode | ||||
| .yarn | ||||
| *.log | ||||
| *.tgz | ||||
| build | ||||
| @@ -22,8 +20,3 @@ package-lock.json | ||||
| static | ||||
| yarn-debug.log* | ||||
| yarn-error.log* | ||||
| src/packages/excalidraw/types | ||||
| src/packages/excalidraw/example/public/bundle.js | ||||
| src/packages/excalidraw/example/public/excalidraw-assets-dev | ||||
| src/packages/excalidraw/example/public/excalidraw.development.js | ||||
|  | ||||
|   | ||||
| @@ -1,2 +0,0 @@ | ||||
| #!/bin/sh | ||||
| yarn lint-staged | ||||
| @@ -5,7 +5,7 @@ | ||||
| ### Option 1 - Manual | ||||
|  | ||||
| 1. Fork and clone the repo | ||||
| 1. Run `yarn` to install dependencies | ||||
| 1. Run `npm install` to install dependencies | ||||
| 1. Create a branch for your PR with `git checkout -b your-branch-name` | ||||
|  | ||||
| > To keep `master` branch pointing to remote repository and make pull requests from branches on your fork. To do this, run: | ||||
|   | ||||
| @@ -10,7 +10,7 @@ ARG NODE_ENV=production | ||||
| COPY . . | ||||
| RUN yarn build:app:docker | ||||
|  | ||||
| FROM nginx:1.21-alpine | ||||
| FROM nginx:1.17-alpine | ||||
|  | ||||
| COPY --from=build /opt/node_app/build /usr/share/nginx/html | ||||
|  | ||||
|   | ||||
							
								
								
									
										73
									
								
								README.md
									
									
									
									
									
								
							
							
						
						| @@ -28,14 +28,6 @@ If you like the project, you can become a sponsor at [Open Collective](https://o | ||||
|  | ||||
| <a href="https://opencollective.com/excalidraw#category-CONTRIBUTE" target="_blank"><img src="https://opencollective.com/excalidraw/tiers/backers.svg?avatarHeight=32"/></a> | ||||
|  | ||||
| Last but not least, we're thankful to these companies for offering their services for free: | ||||
|  | ||||
| [](https://vercel.com) [](https://sentry.io) [](https://crowdin.com) | ||||
|  | ||||
| ## Who's integrating Excalidraw | ||||
|  | ||||
| [Google Cloud](https://googlecloudcheatsheet.withgoogle.com/architecture) • [Meta](https://meta.com/) • [CodeSandbox](https://codesandbox.io/) • [Obsidian Excalidraw](https://github.com/zsviczian/obsidian-excalidraw-plugin) • [Replit](https://replit.com/) • [Slite](https://slite.com/) • [Notion](https://notion.so/) • [HackerRank](https://www.hackerrank.com/) • | ||||
|  | ||||
| ## Documentation | ||||
|  | ||||
| ### Shortcuts | ||||
| @@ -74,8 +66,6 @@ The first set of digits is the room. This is visible from the server that’s go | ||||
|  | ||||
| The second set of digits is the encryption key. The Excalidraw server doesn’t know about it. This is what all the participants use to encrypt/decrypt the messages. | ||||
|  | ||||
| > Note: Please ensure that the encryption key is 22 characters long. | ||||
|  | ||||
| ## Shape libraries | ||||
|  | ||||
| Find a growing list of libraries containing assets for your drawings at [libraries.excalidraw.com](https://libraries.excalidraw.com). | ||||
| @@ -99,7 +89,7 @@ These instructions will get you a copy of the project up and running on your loc | ||||
| #### Requirements | ||||
|  | ||||
| - [Node.js](https://nodejs.org/en/) | ||||
| - [Yarn](https://yarnpkg.com/getting-started/install) (v1 or v2.4.2+) | ||||
| - [Yarn](https://yarnpkg.com/getting-started/install) | ||||
| - [Git](https://git-scm.com/downloads) | ||||
|  | ||||
| #### Clone the repo | ||||
| @@ -108,61 +98,16 @@ These instructions will get you a copy of the project up and running on your loc | ||||
| git clone https://github.com/excalidraw/excalidraw.git | ||||
| ``` | ||||
|  | ||||
| #### Install the dependencies | ||||
|  | ||||
| ```bash | ||||
| yarn | ||||
| ``` | ||||
|  | ||||
| #### Start the server | ||||
|  | ||||
| ```bash | ||||
| yarn start | ||||
| ``` | ||||
|  | ||||
| Now you can open [http://localhost:3000](http://localhost:3000) and start coding in your favorite code editor. | ||||
|  | ||||
| #### Collaboration | ||||
|  | ||||
| For collaboration, you will need to set up [collab server](https://github.com/excalidraw/excalidraw-room) in local. | ||||
|  | ||||
| #### Commands | ||||
|  | ||||
| ##### Install the dependencies | ||||
|  | ||||
| ``` | ||||
| yarn | ||||
| ``` | ||||
|  | ||||
| ##### Run the project | ||||
|  | ||||
| ``` | ||||
| yarn start | ||||
| ``` | ||||
|  | ||||
| ##### Reformat all files with Prettier | ||||
|  | ||||
| ``` | ||||
| yarn fix | ||||
| ``` | ||||
|  | ||||
| ##### Run tests | ||||
|  | ||||
| ``` | ||||
| yarn test | ||||
| ``` | ||||
|  | ||||
| ##### Update test snapshots | ||||
|  | ||||
| ``` | ||||
| yarn test:update | ||||
| ``` | ||||
|  | ||||
| ##### Test for formatting with Prettier | ||||
|  | ||||
| ``` | ||||
| yarn test:code | ||||
| ``` | ||||
| | Command            | Description                       | | ||||
| | ------------------ | --------------------------------- | | ||||
| | `yarn`             | Install the dependencies          | | ||||
| | `yarn start`       | Run the project                   | | ||||
| | `yarn fix`         | Reformat all files with Prettier  | | ||||
| | `yarn test`        | Run tests                         | | ||||
| | `yarn test:update` | Update test snapshots             | | ||||
| | `yarn test:code`   | Test for formatting with Prettier | | ||||
|  | ||||
| #### Docker Compose | ||||
|  | ||||
|   | ||||
| @@ -2,8 +2,5 @@ | ||||
|   "firestore": { | ||||
|     "rules": "firestore.rules", | ||||
|     "indexes": "firestore.indexes.json" | ||||
|   }, | ||||
|   "storage": { | ||||
|     "rules": "storage.rules" | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,11 +0,0 @@ | ||||
| rules_version = '2'; | ||||
| service firebase.storage { | ||||
|   match /b/{bucket}/o { | ||||
|     match /{files}/rooms/{room}/{file} { | ||||
|     	allow get, write: if true; | ||||
|     } | ||||
|     match /{files}/shareLinks/{shareLink}/{file} { | ||||
|     	allow get, write: if true; | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										71
									
								
								package.json
									
									
									
									
									
								
							
							
						
						| @@ -19,67 +19,60 @@ | ||||
|     ] | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@sentry/browser": "6.2.5", | ||||
|     "@sentry/integrations": "6.2.5", | ||||
|     "@testing-library/jest-dom": "5.16.2", | ||||
|     "@testing-library/react": "12.1.2", | ||||
|     "@tldraw/vec": "1.4.3", | ||||
|     "@types/jest": "27.4.0", | ||||
|     "@types/pica": "5.1.3", | ||||
|     "@types/react": "17.0.39", | ||||
|     "@types/react-dom": "17.0.11", | ||||
|     "@types/socket.io-client": "1.4.36", | ||||
|     "browser-fs-access": "0.29.1", | ||||
|     "@sentry/browser": "6.2.1", | ||||
|     "@sentry/integrations": "6.2.1", | ||||
|     "@testing-library/jest-dom": "5.11.9", | ||||
|     "@testing-library/react": "11.2.5", | ||||
|     "@types/jest": "26.0.20", | ||||
|     "@types/react": "17.0.2", | ||||
|     "@types/react-dom": "17.0.1", | ||||
|     "@types/socket.io-client": "1.4.35", | ||||
|     "browser-fs-access": "0.14.1", | ||||
|     "clsx": "1.1.1", | ||||
|     "fake-indexeddb": "3.1.7", | ||||
|     "firebase": "8.3.3", | ||||
|     "i18next-browser-languagedetector": "6.1.2", | ||||
|     "idb-keyval": "6.0.3", | ||||
|     "image-blob-reduce": "3.0.1", | ||||
|     "jotai": "1.6.4", | ||||
|     "firebase": "8.2.10", | ||||
|     "i18next-browser-languagedetector": "6.0.1", | ||||
|     "lodash.throttle": "4.1.1", | ||||
|     "nanoid": "3.3.3", | ||||
|     "open-color": "1.9.1", | ||||
|     "nanoid": "3.1.20", | ||||
|     "open-color": "1.8.0", | ||||
|     "pako": "1.0.11", | ||||
|     "perfect-freehand": "1.0.16", | ||||
|     "png-chunk-text": "1.0.0", | ||||
|     "png-chunks-encode": "1.0.0", | ||||
|     "png-chunks-extract": "1.0.0", | ||||
|     "points-on-curve": "0.2.0", | ||||
|     "pwacompat": "2.0.17", | ||||
|     "react": "17.0.2", | ||||
|     "react-dom": "17.0.2", | ||||
|     "react": "17.0.1", | ||||
|     "react-dom": "17.0.1", | ||||
|     "react-scripts": "4.0.3", | ||||
|     "roughjs": "4.5.2", | ||||
|     "sass": "1.49.7", | ||||
|     "roughjs": "4.3.1", | ||||
|     "sass": "1.32.8", | ||||
|     "socket.io-client": "2.3.1", | ||||
|     "typescript": "4.5.5" | ||||
|     "typescript": "4.2.3" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@excalidraw/eslint-config": "1.0.0", | ||||
|     "@excalidraw/prettier-config": "1.0.2", | ||||
|     "@types/chai": "4.3.0", | ||||
|     "@types/lodash.throttle": "4.1.6", | ||||
|     "@types/pako": "1.0.3", | ||||
|     "@types/resize-observer-browser": "0.1.6", | ||||
|     "chai": "4.3.6", | ||||
|     "dotenv": "10.0.0", | ||||
|     "eslint-config-prettier": "8.3.0", | ||||
|     "@types/pako": "1.0.1", | ||||
|     "@types/resize-observer-browser": "0.1.5", | ||||
|     "eslint-config-prettier": "8.1.0", | ||||
|     "eslint-plugin-prettier": "3.3.1", | ||||
|     "husky": "7.0.4", | ||||
|     "firebase-tools": "9.5.0", | ||||
|     "husky": "4.3.8", | ||||
|     "jest-canvas-mock": "2.3.1", | ||||
|     "lint-staged": "12.3.7", | ||||
|     "lint-staged": "10.5.4", | ||||
|     "pepjs": "0.5.3", | ||||
|     "prettier": "2.5.1", | ||||
|     "prettier": "2.2.1", | ||||
|     "rewire": "5.0.0" | ||||
|   }, | ||||
|   "resolutions": { | ||||
|     "@typescript-eslint/typescript-estree": "5.10.2" | ||||
|   }, | ||||
|   "engines": { | ||||
|     "node": ">=14.0.0" | ||||
|   }, | ||||
|   "homepage": ".", | ||||
|   "husky": { | ||||
|     "hooks": { | ||||
|       "pre-commit": "lint-staged" | ||||
|     } | ||||
|   }, | ||||
|   "jest": { | ||||
|     "transformIgnorePatterns": [ | ||||
|       "node_modules/(?!(roughjs|points-on-curve|path-data-parser|points-on-path|browser-fs-access)/)" | ||||
| @@ -101,7 +94,6 @@ | ||||
|     "fix": "yarn fix:other && yarn fix:code", | ||||
|     "locales-coverage": "node scripts/build-locales-coverage.js", | ||||
|     "locales-coverage:description": "node scripts/locales-coverage-description.js", | ||||
|     "prepare": "husky install", | ||||
|     "prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore", | ||||
|     "start": "react-scripts start", | ||||
|     "test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watchAll=false", | ||||
| @@ -111,7 +103,6 @@ | ||||
|     "test:other": "yarn prettier --list-different", | ||||
|     "test:typecheck": "tsc", | ||||
|     "test:update": "yarn test:app --updateSnapshot --watchAll=false", | ||||
|     "test": "yarn test:app", | ||||
|     "autorelease": "node scripts/autorelease.js" | ||||
|     "test": "yarn test:app" | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -51,7 +51,8 @@ | ||||
|       name="twitter:description" | ||||
|       content="Excalidraw is a whiteboard tool that lets you easily sketch diagrams that have a hand-drawn feel to them." | ||||
|     /> | ||||
|  | ||||
|     <!-- OG tags require absolute url for images --> | ||||
|     <meta name="twitter:image" content="https://excalidraw.com/og-image.png" /> | ||||
|     <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> | ||||
|  | ||||
|     <!-- Excalidraw version --> | ||||
| @@ -72,6 +73,12 @@ | ||||
|       crossorigin="anonymous" | ||||
|     /> | ||||
|  | ||||
|     <link | ||||
|       href="%REACT_APP_SOCKET_SERVER_URL%/socket.io" | ||||
|       rel="preconnect" | ||||
|       crossorigin="anonymous" | ||||
|     /> | ||||
|  | ||||
|     <link | ||||
|       rel="manifest" | ||||
|       href="manifest.json" | ||||
| @@ -81,8 +88,6 @@ | ||||
|     <link rel="stylesheet" href="fonts.css" type="text/css" /> | ||||
|     <script> | ||||
|       window.EXCALIDRAW_ASSET_PATH = "/"; | ||||
|       // setting this so that libraries installation reuses this window tab. | ||||
|       window.name = "_excalidraw"; | ||||
|     </script> | ||||
|     <% if (process.env.REACT_APP_GOOGLE_ANALYTICS_ID) { %> | ||||
|     <script | ||||
| @@ -101,17 +106,16 @@ | ||||
|  | ||||
|     <!-- FIXME: remove this when we update CRA (fix SW caching) --> | ||||
|     <style> | ||||
|       body, | ||||
|       html { | ||||
|       body { | ||||
|         margin: 0; | ||||
|         --ui-font: system-ui, BlinkMacSystemFont, -apple-system, Segoe UI, | ||||
|           Roboto, Helvetica, Arial, sans-serif; | ||||
|         font-family: var(--ui-font); | ||||
|         -webkit-text-size-adjust: 100%; | ||||
|  | ||||
|         width: 100%; | ||||
|         height: 100%; | ||||
|         overflow: hidden; | ||||
|         -webkit-user-select: none; | ||||
|         user-select: none; | ||||
|         width: 100vw; | ||||
|         height: 100vh; | ||||
|       } | ||||
|  | ||||
|       .visually-hidden { | ||||
| @@ -121,28 +125,27 @@ | ||||
|         overflow: hidden; | ||||
|         clip: rect(1px, 1px, 1px, 1px); | ||||
|         white-space: nowrap; /* added line */ | ||||
|         user-select: none; | ||||
|       } | ||||
|  | ||||
|       #root { | ||||
|         height: 100%; | ||||
|         -webkit-touch-callout: none; | ||||
|         -webkit-user-select: none; | ||||
|         -khtml-user-select: none; | ||||
|         -moz-user-select: none; | ||||
|         -ms-user-select: none; | ||||
|         user-select: none; | ||||
|       .LoadingMessage { | ||||
|         position: absolute; | ||||
|         top: 0; | ||||
|         right: 0; | ||||
|         bottom: 0; | ||||
|         left: 0; | ||||
|         z-index: 999; | ||||
|         display: flex; | ||||
|         align-items: center; | ||||
|         justify-content: center; | ||||
|         pointer-events: none; | ||||
|       } | ||||
|  | ||||
|       @media screen and (min-width: 1200px) { | ||||
|         #root { | ||||
|           -webkit-touch-callout: default; | ||||
|           -webkit-user-select: auto; | ||||
|           -khtml-user-select: auto; | ||||
|           -moz-user-select: auto; | ||||
|           -ms-user-select: auto; | ||||
|           user-select: auto; | ||||
|         } | ||||
|       .LoadingMessage span { | ||||
|         background-color: var(--button-gray-1); | ||||
|         border-radius: 5px; | ||||
|         padding: 0.8em 1.2em; | ||||
|         color: var(--popup-text-color); | ||||
|         font-size: 1.3em; | ||||
|       } | ||||
|     </style> | ||||
|   </head> | ||||
| @@ -152,6 +155,10 @@ | ||||
|     <header> | ||||
|       <h1 class="visually-hidden">Excalidraw</h1> | ||||
|     </header> | ||||
|     <div id="root"></div> | ||||
|     <div id="root"> | ||||
|       <div class="LoadingMessage"> | ||||
|         <span>Loading scene...</span> | ||||
|       </div> | ||||
|     </div> | ||||
|   </body> | ||||
| </html> | ||||
|   | ||||
| @@ -26,49 +26,5 @@ | ||||
|       } | ||||
|     } | ||||
|   ], | ||||
|   "share_target": { | ||||
|     "action": "/web-share-target", | ||||
|     "method": "POST", | ||||
|     "enctype": "multipart/form-data", | ||||
|     "params": { | ||||
|       "files": [ | ||||
|         { | ||||
|           "name": "file", | ||||
|           "accept": ["application/vnd.excalidraw+json", "application/json", ".excalidraw"] | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   }, | ||||
|   "screenshots": [ | ||||
|     { | ||||
|       "src": "/screenshots/virtual-whiteboard.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     }, | ||||
|     { | ||||
|       "src": "/screenshots/wireframe.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     }, | ||||
|     { | ||||
|       "src": "/screenshots/illustration.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     }, | ||||
|     { | ||||
|       "src": "/screenshots/shapes.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     }, | ||||
|     { | ||||
|       "src": "/screenshots/collaboration.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     }, | ||||
|     { | ||||
|       "src": "/screenshots/export.png", | ||||
|       "type": "image/png", | ||||
|       "sizes": "462x945" | ||||
|     } | ||||
|   ] | ||||
|   "capture_links": "new_client" | ||||
| } | ||||
|   | ||||
| Before Width: | Height: | Size: 28 KiB | 
| Before Width: | Height: | Size: 25 KiB | 
| Before Width: | Height: | Size: 47 KiB | 
| Before Width: | Height: | Size: 25 KiB | 
| Before Width: | Height: | Size: 27 KiB | 
| Before Width: | Height: | Size: 27 KiB | 
| @@ -1,77 +0,0 @@ | ||||
| const fs = require("fs"); | ||||
| const { exec, execSync } = require("child_process"); | ||||
| const core = require("@actions/core"); | ||||
|  | ||||
| const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; | ||||
| const excalidrawPackage = `${excalidrawDir}/package.json`; | ||||
| const pkg = require(excalidrawPackage); | ||||
|  | ||||
| const getShortCommitHash = () => { | ||||
|   return execSync("git rev-parse --short HEAD").toString().trim(); | ||||
| }; | ||||
|  | ||||
| const publish = () => { | ||||
|   try { | ||||
|     execSync(`yarn  --frozen-lockfile`); | ||||
|     execSync(`yarn --frozen-lockfile`, { cwd: excalidrawDir }); | ||||
|     execSync(`yarn run build:umd`, { cwd: excalidrawDir }); | ||||
|     execSync(`yarn --cwd ${excalidrawDir} publish`); | ||||
|     console.info("Published 🎉"); | ||||
|     core.setOutput( | ||||
|       "result", | ||||
|       `**Preview version has been shipped** :rocket: | ||||
|     You can use [@excalidraw/excalidraw-preview@${pkg.version}](https://www.npmjs.com/package/@excalidraw/excalidraw-preview/v/${pkg.version}) for testing!`, | ||||
|     ); | ||||
|   } catch (error) { | ||||
|     core.setOutput("result", "package couldn't be published :warning:!"); | ||||
|     console.error(error); | ||||
|     process.exit(1); | ||||
|   } | ||||
| }; | ||||
| // get files changed between prev and head commit | ||||
| exec(`git diff --name-only HEAD^ HEAD`, async (error, stdout, stderr) => { | ||||
|   if (error || stderr) { | ||||
|     console.error(error); | ||||
|     core.setOutput("result", ":warning: Package couldn't be published!"); | ||||
|     process.exit(1); | ||||
|   } | ||||
|   const changedFiles = stdout.trim().split("\n"); | ||||
|   const filesToIgnoreRegex = /src\/excalidraw-app|packages\/utils/; | ||||
|  | ||||
|   const excalidrawPackageFiles = changedFiles.filter((file) => { | ||||
|     return ( | ||||
|       (file.indexOf("src") >= 0 || file.indexOf("package.json")) >= 0 && | ||||
|       !filesToIgnoreRegex.test(file) | ||||
|     ); | ||||
|   }); | ||||
|   if (!excalidrawPackageFiles.length) { | ||||
|     console.info("Skipping release as no valid diff found"); | ||||
|     core.setOutput("result", "Skipping release as no valid diff found"); | ||||
|     process.exit(0); | ||||
|   } | ||||
|  | ||||
|   // update package.json | ||||
|   pkg.name = "@excalidraw/excalidraw-next"; | ||||
|   let version = `${pkg.version}-${getShortCommitHash()}`; | ||||
|  | ||||
|   // update readme | ||||
|   let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8"); | ||||
|  | ||||
|   const isPreview = process.argv.slice(2)[0] === "preview"; | ||||
|   if (isPreview) { | ||||
|     // use pullNumber-commithash as the version for preview | ||||
|     const pullRequestNumber = process.argv.slice(3)[0]; | ||||
|     version = `${pkg.version}-${pullRequestNumber}-${getShortCommitHash()}`; | ||||
|     // replace "excalidraw-next" with "excalidraw-preview" | ||||
|     pkg.name = "@excalidraw/excalidraw-preview"; | ||||
|     data = data.replace(/excalidraw-next/g, "excalidraw-preview"); | ||||
|     data = data.trim(); | ||||
|   } | ||||
|   pkg.version = version; | ||||
|  | ||||
|   fs.writeFileSync(excalidrawPackage, JSON.stringify(pkg, null, 2), "utf8"); | ||||
|  | ||||
|   fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8"); | ||||
|   console.info("Publish in progress..."); | ||||
|   publish(); | ||||
| }); | ||||
| @@ -1,16 +1,11 @@ | ||||
| const { readdirSync, writeFileSync } = require("fs"); | ||||
| const files = readdirSync(`${__dirname}/../src/locales`); | ||||
|  | ||||
| const flatten = (object = {}, result = {}, extraKey = "") => { | ||||
|   for (const key in object) { | ||||
|     if (typeof object[key] !== "object") { | ||||
|       result[extraKey + key] = object[key]; | ||||
|     } else { | ||||
|       flatten(object[key], result, `${extraKey}${key}.`); | ||||
|     } | ||||
|   } | ||||
|   return result; | ||||
| }; | ||||
| const flatten = (object) => | ||||
|   Object.keys(object).reduce( | ||||
|     (initial, current) => ({ ...initial, ...object[current] }), | ||||
|     {}, | ||||
|   ); | ||||
|  | ||||
| const locales = files.filter( | ||||
|   (file) => file !== "README.md" && file !== "percentages.json", | ||||
| @@ -24,8 +19,10 @@ for (let index = 0; index < locales.length; index++) { | ||||
|  | ||||
|   const allKeys = Object.keys(data); | ||||
|   const translatedKeys = allKeys.filter((item) => data[item] !== ""); | ||||
|   const percentage = Math.floor((100 * translatedKeys.length) / allKeys.length); | ||||
|   percentages[currentLocale.replace(".json", "")] = percentage; | ||||
|  | ||||
|   const percentage = (100 * translatedKeys.length) / allKeys.length; | ||||
|  | ||||
|   percentages[currentLocale.replace(".json", "")] = parseInt(percentage); | ||||
| } | ||||
|  | ||||
| writeFileSync( | ||||
|   | ||||
| @@ -5,13 +5,10 @@ const THRESSHOLD = 85; | ||||
| const crowdinMap = { | ||||
|   "ar-SA": "en-ar", | ||||
|   "bg-BG": "en-bg", | ||||
|   "bn-BD": "en-bn", | ||||
|   "ca-ES": "en-ca", | ||||
|   "da-DK": "en-da", | ||||
|   "de-DE": "en-de", | ||||
|   "el-GR": "en-el", | ||||
|   "es-ES": "en-es", | ||||
|   "eu-ES": "en-eu", | ||||
|   "fa-IR": "en-fa", | ||||
|   "fi-FI": "en-fi", | ||||
|   "fr-FR": "en-fr", | ||||
| @@ -34,28 +31,18 @@ const crowdinMap = { | ||||
|   "pt-PT": "en-pt", | ||||
|   "ro-RO": "en-ro", | ||||
|   "ru-RU": "en-ru", | ||||
|   "si-LK": "en-silk", | ||||
|   "sk-SK": "en-sk", | ||||
|   "sv-SE": "en-sv", | ||||
|   "ta-IN": "en-ta", | ||||
|   "tr-TR": "en-tr", | ||||
|   "uk-UA": "en-uk", | ||||
|   "zh-CN": "en-zhcn", | ||||
|   "zh-HK": "en-zhhk", | ||||
|   "zh-TW": "en-zhtw", | ||||
|   "lt-LT": "en-lt", | ||||
|   "lv-LV": "en-lv", | ||||
|   "cs-CZ": "en-cs", | ||||
|   "kk-KZ": "en-kk", | ||||
| }; | ||||
|  | ||||
| const flags = { | ||||
|   "ar-SA": "🇸🇦", | ||||
|   "bg-BG": "🇧🇬", | ||||
|   "bn-BD": "🇧🇩", | ||||
|   "ca-ES": "🏳", | ||||
|   "cs-CZ": "🇨🇿", | ||||
|   "da-DK": "🇩🇰", | ||||
|   "de-DE": "🇩🇪", | ||||
|   "el-GR": "🇬🇷", | ||||
|   "es-ES": "🇪🇸", | ||||
| @@ -69,10 +56,7 @@ const flags = { | ||||
|   "it-IT": "🇮🇹", | ||||
|   "ja-JP": "🇯🇵", | ||||
|   "kab-KAB": "🏳", | ||||
|   "kk-KZ": "🇰🇿", | ||||
|   "ko-KR": "🇰🇷", | ||||
|   "lt-LT": "🇱🇹", | ||||
|   "lv-LV": "🇱🇻", | ||||
|   "my-MM": "🇲🇲", | ||||
|   "nb-NO": "🇳🇴", | ||||
|   "nl-NL": "🇳🇱", | ||||
| @@ -84,28 +68,21 @@ const flags = { | ||||
|   "pt-PT": "🇵🇹", | ||||
|   "ro-RO": "🇷🇴", | ||||
|   "ru-RU": "🇷🇺", | ||||
|   "si-LK": "🇱🇰", | ||||
|   "sk-SK": "🇸🇰", | ||||
|   "sv-SE": "🇸🇪", | ||||
|   "ta-IN": "🇮🇳", | ||||
|   "tr-TR": "🇹🇷", | ||||
|   "uk-UA": "🇺🇦", | ||||
|   "zh-CN": "🇨🇳", | ||||
|   "zh-HK": "🇭🇰", | ||||
|   "zh-TW": "🇹🇼", | ||||
| }; | ||||
|  | ||||
| const languages = { | ||||
|   "ar-SA": "العربية", | ||||
|   "bg-BG": "Български", | ||||
|   "bn-BD": "Bengali", | ||||
|   "ca-ES": "Català", | ||||
|   "cs-CZ": "Česky", | ||||
|   "da-DK": "Dansk", | ||||
|   "de-DE": "Deutsch", | ||||
|   "el-GR": "Ελληνικά", | ||||
|   "es-ES": "Español", | ||||
|   "eu-ES": "Euskara", | ||||
|   "fa-IR": "فارسی", | ||||
|   "fi-FI": "Suomi", | ||||
|   "fr-FR": "Français", | ||||
| @@ -116,10 +93,7 @@ const languages = { | ||||
|   "it-IT": "Italiano", | ||||
|   "ja-JP": "日本語", | ||||
|   "kab-KAB": "Taqbaylit", | ||||
|   "kk-KZ": "Қазақ тілі", | ||||
|   "ko-KR": "한국어", | ||||
|   "lt-LT": "Lietuvių", | ||||
|   "lv-LV": "Latviešu", | ||||
|   "my-MM": "Burmese", | ||||
|   "nb-NO": "Norsk bokmål", | ||||
|   "nl-NL": "Nederlands", | ||||
| @@ -131,14 +105,11 @@ const languages = { | ||||
|   "pt-PT": "Português", | ||||
|   "ro-RO": "Română", | ||||
|   "ru-RU": "Русский", | ||||
|   "si-LK": "සිංහල", | ||||
|   "sk-SK": "Slovenčina", | ||||
|   "sv-SE": "Svenska", | ||||
|   "ta-IN": "Tamil", | ||||
|   "tr-TR": "Türkçe", | ||||
|   "uk-UA": "Українська", | ||||
|   "zh-CN": "简体中文", | ||||
|   "zh-HK": "繁體中文 (香港)", | ||||
|   "zh-TW": "繁體中文", | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -1,39 +0,0 @@ | ||||
| const fs = require("fs"); | ||||
| const util = require("util"); | ||||
| const exec = util.promisify(require("child_process").exec); | ||||
| const updateReadme = require("./updateReadme"); | ||||
| const updateChangelog = require("./updateChangelog"); | ||||
|  | ||||
| const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; | ||||
| const excalidrawPackage = `${excalidrawDir}/package.json`; | ||||
|  | ||||
| const updatePackageVersion = (nextVersion) => { | ||||
|   const pkg = require(excalidrawPackage); | ||||
|   pkg.version = nextVersion; | ||||
|   const content = `${JSON.stringify(pkg, null, 2)}\n`; | ||||
|   fs.writeFileSync(excalidrawPackage, content, "utf-8"); | ||||
| }; | ||||
|  | ||||
| const release = async (nextVersion) => { | ||||
|   try { | ||||
|     updateReadme(); | ||||
|     await updateChangelog(nextVersion); | ||||
|     updatePackageVersion(nextVersion); | ||||
|     await exec(`git add -u`); | ||||
|     await exec( | ||||
|       `git commit -m "docs: release @excalidraw/excalidraw@${nextVersion}  🎉"`, | ||||
|     ); | ||||
|     /* eslint-disable no-console */ | ||||
|     console.log("Done!"); | ||||
|   } catch (error) { | ||||
|     console.error(error); | ||||
|     process.exit(1); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| const nextVersion = process.argv.slice(2)[0]; | ||||
| if (!nextVersion) { | ||||
|   console.error("Pass the next version to release!"); | ||||
|   process.exit(1); | ||||
| } | ||||
| release(nextVersion); | ||||
| @@ -1,104 +0,0 @@ | ||||
| const fs = require("fs"); | ||||
| const util = require("util"); | ||||
| const exec = util.promisify(require("child_process").exec); | ||||
|  | ||||
| const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; | ||||
| const excalidrawPackage = `${excalidrawDir}/package.json`; | ||||
| const pkg = require(excalidrawPackage); | ||||
| const lastVersion = pkg.version; | ||||
| const existingChangeLog = fs.readFileSync( | ||||
|   `${excalidrawDir}/CHANGELOG.md`, | ||||
|   "utf8", | ||||
| ); | ||||
|  | ||||
| const supportedTypes = ["feat", "fix", "style", "refactor", "perf", "build"]; | ||||
| const headerForType = { | ||||
|   feat: "Features", | ||||
|   fix: "Fixes", | ||||
|   style: "Styles", | ||||
|   refactor: " Refactor", | ||||
|   perf: "Performance", | ||||
|   build: "Build", | ||||
| }; | ||||
| const badCommits = []; | ||||
| const getCommitHashForLastVersion = async () => { | ||||
|   try { | ||||
|     const commitMessage = `"release @excalidraw/excalidraw@${lastVersion}"`; | ||||
|     const { stdout } = await exec( | ||||
|       `git log --format=format:"%H" --grep=${commitMessage}`, | ||||
|     ); | ||||
|     return stdout; | ||||
|   } catch (error) { | ||||
|     console.error(error); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| const getLibraryCommitsSinceLastRelease = async () => { | ||||
|   const commitHash = await getCommitHashForLastVersion(); | ||||
|   const { stdout } = await exec( | ||||
|     `git log --pretty=format:%s ${commitHash}...master`, | ||||
|   ); | ||||
|   const commitsSinceLastRelease = stdout.split("\n"); | ||||
|   const commitList = {}; | ||||
|   supportedTypes.forEach((type) => { | ||||
|     commitList[type] = []; | ||||
|   }); | ||||
|  | ||||
|   commitsSinceLastRelease.forEach((commit) => { | ||||
|     const indexOfColon = commit.indexOf(":"); | ||||
|     const type = commit.slice(0, indexOfColon); | ||||
|     if (!supportedTypes.includes(type)) { | ||||
|       return; | ||||
|     } | ||||
|     const messageWithoutType = commit.slice(indexOfColon + 1).trim(); | ||||
|     const messageWithCapitalizeFirst = | ||||
|       messageWithoutType.charAt(0).toUpperCase() + messageWithoutType.slice(1); | ||||
|     const prMatch = commit.match(/\(#([0-9]*)\)/); | ||||
|     if (prMatch) { | ||||
|       const prNumber = prMatch[1]; | ||||
|  | ||||
|       // return if the changelog already contains the pr number which would happen for package updates | ||||
|       if (existingChangeLog.includes(prNumber)) { | ||||
|         return; | ||||
|       } | ||||
|       const prMarkdown = `[#${prNumber}](https://github.com/excalidraw/excalidraw/pull/${prNumber})`; | ||||
|       const messageWithPRLink = messageWithCapitalizeFirst.replace( | ||||
|         /\(#[0-9]*\)/, | ||||
|         prMarkdown, | ||||
|       ); | ||||
|       commitList[type].push(messageWithPRLink); | ||||
|     } else { | ||||
|       badCommits.push(commit); | ||||
|       commitList[type].push(messageWithCapitalizeFirst); | ||||
|     } | ||||
|   }); | ||||
|   console.info("Bad commits:", badCommits); | ||||
|   return commitList; | ||||
| }; | ||||
|  | ||||
| const updateChangelog = async (nextVersion) => { | ||||
|   const commitList = await getLibraryCommitsSinceLastRelease(); | ||||
|   let changelogForLibrary = | ||||
|     "## Excalidraw Library\n\n**_This section lists the updates made to the excalidraw library and will not affect the integration._**\n\n"; | ||||
|   supportedTypes.forEach((type) => { | ||||
|     if (commitList[type].length) { | ||||
|       changelogForLibrary += `### ${headerForType[type]}\n\n`; | ||||
|       const commits = commitList[type]; | ||||
|       commits.forEach((commit) => { | ||||
|         changelogForLibrary += `- ${commit}\n\n`; | ||||
|       }); | ||||
|     } | ||||
|   }); | ||||
|   changelogForLibrary += "---\n"; | ||||
|   const lastVersionIndex = existingChangeLog.indexOf(`## ${lastVersion}`); | ||||
|   let updatedContent = | ||||
|     existingChangeLog.slice(0, lastVersionIndex) + | ||||
|     changelogForLibrary + | ||||
|     existingChangeLog.slice(lastVersionIndex); | ||||
|   const currentDate = new Date().toISOString().slice(0, 10); | ||||
|   const newVersion = `## ${nextVersion} (${currentDate})`; | ||||
|   updatedContent = updatedContent.replace(`## Unreleased`, newVersion); | ||||
|   fs.writeFileSync(`${excalidrawDir}/CHANGELOG.md`, updatedContent, "utf8"); | ||||
| }; | ||||
|  | ||||
| module.exports = updateChangelog; | ||||
| @@ -1,27 +0,0 @@ | ||||
| const fs = require("fs"); | ||||
|  | ||||
| const updateReadme = () => { | ||||
|   const excalidrawDir = `${__dirname}/../src/packages/excalidraw`; | ||||
|   let data = fs.readFileSync(`${excalidrawDir}/README_NEXT.md`, "utf8"); | ||||
|  | ||||
|   // remove note for unstable release | ||||
|   data = data.replace( | ||||
|     /<!-- unstable-readme-start-->[\s\S]*?<!-- unstable-readme-end-->/, | ||||
|     "", | ||||
|   ); | ||||
|  | ||||
|   // replace "excalidraw-next" with "excalidraw" | ||||
|   data = data.replace(/excalidraw-next/g, "excalidraw"); | ||||
|   data = data.trim(); | ||||
|  | ||||
|   const demoIndex = data.indexOf("### Demo"); | ||||
|   const excalidrawNextNote = | ||||
|     "#### Note\n\n**If you don't want to wait for the next stable release and try out the unreleased changes you can use [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**\n\n"; | ||||
|   // Add excalidraw next note to try out for unreleased changes | ||||
|   data = data.slice(0, demoIndex) + excalidrawNextNote + data.slice(demoIndex); | ||||
|  | ||||
|   // update readme | ||||
|   fs.writeFileSync(`${excalidrawDir}/README.md`, data, "utf8"); | ||||
| }; | ||||
|  | ||||
| module.exports = updateReadme; | ||||
| @@ -2,59 +2,20 @@ import { register } from "./register"; | ||||
| import { getSelectedElements } from "../scene"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { deepCopyElement } from "../element/newElement"; | ||||
| import { randomId } from "../random"; | ||||
| import { t } from "../i18n"; | ||||
| import { Library } from "../data/library"; | ||||
|  | ||||
| export const actionAddToLibrary = register({ | ||||
|   name: "addToLibrary", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState, _, app) => { | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|       true, | ||||
|     ); | ||||
|     if (selectedElements.some((element) => element.type === "image")) { | ||||
|       return { | ||||
|         commitToHistory: false, | ||||
|         appState: { | ||||
|           ...appState, | ||||
|           errorMessage: "Support for adding images to the library coming soon!", | ||||
|         }, | ||||
|       }; | ||||
|     } | ||||
|  | ||||
|     return app.library | ||||
|       .getLatestLibrary() | ||||
|       .then((items) => { | ||||
|         return app.library.setLibrary([ | ||||
|           { | ||||
|             id: randomId(), | ||||
|             status: "unpublished", | ||||
|             elements: selectedElements.map(deepCopyElement), | ||||
|             created: Date.now(), | ||||
|           }, | ||||
|           ...items, | ||||
|         ]); | ||||
|       }) | ||||
|       .then(() => { | ||||
|         return { | ||||
|           commitToHistory: false, | ||||
|           appState: { | ||||
|             ...appState, | ||||
|             toastMessage: t("toast.addedToLibrary"), | ||||
|           }, | ||||
|         }; | ||||
|       }) | ||||
|       .catch((error) => { | ||||
|         return { | ||||
|           commitToHistory: false, | ||||
|           appState: { | ||||
|             ...appState, | ||||
|             errorMessage: error.message, | ||||
|           }, | ||||
|         }; | ||||
|       }); | ||||
|     Library.loadLibrary().then((items) => { | ||||
|       Library.saveLibrary([...items, selectedElements.map(deepCopyElement)]); | ||||
|     }); | ||||
|     return false; | ||||
|   }, | ||||
|   contextItemLabel: "labels.addToLibrary", | ||||
| }); | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import { alignElements, Alignment } from "../align"; | ||||
| import { | ||||
|   AlignBottomIcon, | ||||
| @@ -8,13 +9,13 @@ import { | ||||
|   CenterVerticallyIcon, | ||||
| } from "../components/icons"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { getElementMap, getNonDeletedElements } from "../element"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { t } from "../i18n"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { getSelectedElements, isSomeElementSelected } from "../scene"; | ||||
| import { AppState } from "../types"; | ||||
| import { arrayToMap, getShortcutKey } from "../utils"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { register } from "./register"; | ||||
|  | ||||
| const enableActionGroup = ( | ||||
| @@ -34,16 +35,13 @@ const alignSelectedElements = ( | ||||
|  | ||||
|   const updatedElements = alignElements(selectedElements, alignment); | ||||
|  | ||||
|   const updatedElementsMap = arrayToMap(updatedElements); | ||||
|   const updatedElementsMap = getElementMap(updatedElements); | ||||
|  | ||||
|   return elements.map( | ||||
|     (element) => updatedElementsMap.get(element.id) || element, | ||||
|   ); | ||||
|   return elements.map((element) => updatedElementsMap[element.id] || element); | ||||
| }; | ||||
|  | ||||
| export const actionAlignTop = register({ | ||||
|   name: "alignTop", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -60,7 +58,7 @@ export const actionAlignTop = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<AlignTopIcon theme={appState.theme} />} | ||||
|       icon={<AlignTopIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.alignTop")} — ${getShortcutKey( | ||||
|         "CtrlOrCmd+Shift+Up", | ||||
| @@ -73,7 +71,6 @@ export const actionAlignTop = register({ | ||||
|  | ||||
| export const actionAlignBottom = register({ | ||||
|   name: "alignBottom", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -90,7 +87,7 @@ export const actionAlignBottom = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<AlignBottomIcon theme={appState.theme} />} | ||||
|       icon={<AlignBottomIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.alignBottom")} — ${getShortcutKey( | ||||
|         "CtrlOrCmd+Shift+Down", | ||||
| @@ -103,7 +100,6 @@ export const actionAlignBottom = register({ | ||||
|  | ||||
| export const actionAlignLeft = register({ | ||||
|   name: "alignLeft", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -120,7 +116,7 @@ export const actionAlignLeft = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<AlignLeftIcon theme={appState.theme} />} | ||||
|       icon={<AlignLeftIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.alignLeft")} — ${getShortcutKey( | ||||
|         "CtrlOrCmd+Shift+Left", | ||||
| @@ -133,8 +129,6 @@ export const actionAlignLeft = register({ | ||||
|  | ||||
| export const actionAlignRight = register({ | ||||
|   name: "alignRight", | ||||
|   trackEvent: { category: "element" }, | ||||
|  | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -151,7 +145,7 @@ export const actionAlignRight = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<AlignRightIcon theme={appState.theme} />} | ||||
|       icon={<AlignRightIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.alignRight")} — ${getShortcutKey( | ||||
|         "CtrlOrCmd+Shift+Right", | ||||
| @@ -164,8 +158,6 @@ export const actionAlignRight = register({ | ||||
|  | ||||
| export const actionAlignVerticallyCentered = register({ | ||||
|   name: "alignVerticallyCentered", | ||||
|   trackEvent: { category: "element" }, | ||||
|  | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -180,7 +172,7 @@ export const actionAlignVerticallyCentered = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<CenterVerticallyIcon theme={appState.theme} />} | ||||
|       icon={<CenterVerticallyIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={t("labels.centerVertically")} | ||||
|       aria-label={t("labels.centerVertically")} | ||||
| @@ -191,7 +183,6 @@ export const actionAlignVerticallyCentered = register({ | ||||
|  | ||||
| export const actionAlignHorizontallyCentered = register({ | ||||
|   name: "alignHorizontallyCentered", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -206,7 +197,7 @@ export const actionAlignHorizontallyCentered = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<CenterHorizontallyIcon theme={appState.theme} />} | ||||
|       icon={<CenterHorizontallyIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={t("labels.centerHorizontally")} | ||||
|       aria-label={t("labels.centerHorizontally")} | ||||
|   | ||||
| @@ -1,136 +0,0 @@ | ||||
| import { VERTICAL_ALIGN } from "../constants"; | ||||
| import { getNonDeletedElements, isTextElement } from "../element"; | ||||
| import { mutateElement } from "../element/mutateElement"; | ||||
| import { | ||||
|   getBoundTextElement, | ||||
|   measureText, | ||||
|   redrawTextBoundingBox, | ||||
| } from "../element/textElement"; | ||||
| import { | ||||
|   hasBoundTextElement, | ||||
|   isTextBindableContainer, | ||||
| } from "../element/typeChecks"; | ||||
| import { | ||||
|   ExcalidrawTextContainer, | ||||
|   ExcalidrawTextElement, | ||||
| } from "../element/types"; | ||||
| import { getSelectedElements } from "../scene"; | ||||
| import { getFontString } from "../utils"; | ||||
| import { register } from "./register"; | ||||
|  | ||||
| export const actionUnbindText = register({ | ||||
|   name: "unbindText", | ||||
|   contextItemLabel: "labels.unbindText", | ||||
|   trackEvent: { category: "element" }, | ||||
|   contextItemPredicate: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements(elements, appState); | ||||
|     return selectedElements.some((element) => hasBoundTextElement(element)); | ||||
|   }, | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|     ); | ||||
|     selectedElements.forEach((element) => { | ||||
|       const boundTextElement = getBoundTextElement(element); | ||||
|       if (boundTextElement) { | ||||
|         const { width, height, baseline } = measureText( | ||||
|           boundTextElement.originalText, | ||||
|           getFontString(boundTextElement), | ||||
|         ); | ||||
|         mutateElement(boundTextElement as ExcalidrawTextElement, { | ||||
|           containerId: null, | ||||
|           width, | ||||
|           height, | ||||
|           baseline, | ||||
|           text: boundTextElement.originalText, | ||||
|         }); | ||||
|         mutateElement(element, { | ||||
|           boundElements: element.boundElements?.filter( | ||||
|             (ele) => ele.id !== boundTextElement.id, | ||||
|           ), | ||||
|         }); | ||||
|       } | ||||
|     }); | ||||
|     return { | ||||
|       elements, | ||||
|       appState, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const actionBindText = register({ | ||||
|   name: "bindText", | ||||
|   contextItemLabel: "labels.bindText", | ||||
|   trackEvent: { category: "element" }, | ||||
|   contextItemPredicate: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements(elements, appState); | ||||
|  | ||||
|     if (selectedElements.length === 2) { | ||||
|       const textElement = | ||||
|         isTextElement(selectedElements[0]) || | ||||
|         isTextElement(selectedElements[1]); | ||||
|  | ||||
|       let bindingContainer; | ||||
|       if (isTextBindableContainer(selectedElements[0])) { | ||||
|         bindingContainer = selectedElements[0]; | ||||
|       } else if (isTextBindableContainer(selectedElements[1])) { | ||||
|         bindingContainer = selectedElements[1]; | ||||
|       } | ||||
|       if ( | ||||
|         textElement && | ||||
|         bindingContainer && | ||||
|         getBoundTextElement(bindingContainer) === null | ||||
|       ) { | ||||
|         return true; | ||||
|       } | ||||
|     } | ||||
|     return false; | ||||
|   }, | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|     ); | ||||
|  | ||||
|     let textElement: ExcalidrawTextElement; | ||||
|     let container: ExcalidrawTextContainer; | ||||
|  | ||||
|     if ( | ||||
|       isTextElement(selectedElements[0]) && | ||||
|       isTextBindableContainer(selectedElements[1]) | ||||
|     ) { | ||||
|       textElement = selectedElements[0]; | ||||
|       container = selectedElements[1]; | ||||
|     } else { | ||||
|       textElement = selectedElements[1] as ExcalidrawTextElement; | ||||
|       container = selectedElements[0] as ExcalidrawTextContainer; | ||||
|     } | ||||
|     mutateElement(textElement, { | ||||
|       containerId: container.id, | ||||
|       verticalAlign: VERTICAL_ALIGN.MIDDLE, | ||||
|     }); | ||||
|     mutateElement(container, { | ||||
|       boundElements: (container.boundElements || []).concat({ | ||||
|         type: "text", | ||||
|         id: textElement.id, | ||||
|       }), | ||||
|     }); | ||||
|     redrawTextBoundingBox(textElement, container); | ||||
|     const updatedElements = elements.slice(); | ||||
|     const textElementIndex = updatedElements.findIndex( | ||||
|       (ele) => ele.id === textElement.id, | ||||
|     ); | ||||
|     updatedElements.splice(textElementIndex, 1); | ||||
|     const containerIndex = updatedElements.findIndex( | ||||
|       (ele) => ele.id === container.id, | ||||
|     ); | ||||
|     updatedElements.splice(containerIndex + 1, 0, textElement); | ||||
|     return { | ||||
|       elements: updatedElements, | ||||
|       appState: { ...appState, selectedElementIds: { [container.id]: true } }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
| }); | ||||
| @@ -1,48 +1,38 @@ | ||||
| import React from "react"; | ||||
| import { getDefaultAppState } from "../appState"; | ||||
| import { ColorPicker } from "../components/ColorPicker"; | ||||
| import { eraser, zoomIn, zoomOut } from "../components/icons"; | ||||
| import { resetZoom, trash, zoomIn, zoomOut } from "../components/icons"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { DarkModeToggle } from "../components/DarkModeToggle"; | ||||
| import { THEME, ZOOM_STEP } from "../constants"; | ||||
| import { ZOOM_STEP } from "../constants"; | ||||
| import { getCommonBounds, getNonDeletedElements } from "../element"; | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { t } from "../i18n"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { getNormalizedZoom, getSelectedElements } from "../scene"; | ||||
| import { centerScrollOn } from "../scene/scroll"; | ||||
| import { getStateForZoom } from "../scene/zoom"; | ||||
| import { getNewZoom } from "../scene/zoom"; | ||||
| import { AppState, NormalizedZoomValue } from "../types"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { register } from "./register"; | ||||
| import { Tooltip } from "../components/Tooltip"; | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| import { getDefaultAppState, isEraserActive } from "../appState"; | ||||
| import ClearCanvas from "../components/ClearCanvas"; | ||||
| import clsx from "clsx"; | ||||
|  | ||||
| export const actionChangeViewBackgroundColor = register({ | ||||
|   name: "changeViewBackgroundColor", | ||||
|   trackEvent: false, | ||||
|   perform: (_, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, ...value }, | ||||
|       commitToHistory: !!value.viewBackgroundColor, | ||||
|       appState: { ...appState, viewBackgroundColor: value }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => { | ||||
|   PanelComponent: ({ appState, updateData }) => { | ||||
|     return ( | ||||
|       <div style={{ position: "relative" }}> | ||||
|         <ColorPicker | ||||
|           label={t("labels.canvasBackground")} | ||||
|           type="canvasBackground" | ||||
|           color={appState.viewBackgroundColor} | ||||
|           onChange={(color) => updateData({ viewBackgroundColor: color })} | ||||
|           isActive={appState.openPopup === "canvasColorPicker"} | ||||
|           setActive={(active) => | ||||
|             updateData({ openPopup: active ? "canvasColorPicker" : null }) | ||||
|           } | ||||
|           data-testid="canvas-background-picker" | ||||
|           elements={elements} | ||||
|           appState={appState} | ||||
|           onChange={(color) => updateData(color)} | ||||
|         /> | ||||
|       </div> | ||||
|     ); | ||||
| @@ -51,51 +41,54 @@ export const actionChangeViewBackgroundColor = register({ | ||||
|  | ||||
| export const actionClearCanvas = register({ | ||||
|   name: "clearCanvas", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (elements, appState, _, app) => { | ||||
|     app.imageCache.clear(); | ||||
|   perform: (elements, appState: AppState) => { | ||||
|     return { | ||||
|       elements: elements.map((element) => | ||||
|         newElementWith(element, { isDeleted: true }), | ||||
|       ), | ||||
|       appState: { | ||||
|         ...getDefaultAppState(), | ||||
|         files: {}, | ||||
|         theme: appState.theme, | ||||
|         penMode: appState.penMode, | ||||
|         penDetected: appState.penDetected, | ||||
|         appearance: appState.appearance, | ||||
|         elementLocked: appState.elementLocked, | ||||
|         exportBackground: appState.exportBackground, | ||||
|         exportEmbedScene: appState.exportEmbedScene, | ||||
|         gridSize: appState.gridSize, | ||||
|         shouldAddWatermark: appState.shouldAddWatermark, | ||||
|         showStats: appState.showStats, | ||||
|         pasteDialog: appState.pasteDialog, | ||||
|         activeTool: | ||||
|           appState.activeTool.type === "image" | ||||
|             ? { ...appState.activeTool, type: "selection" } | ||||
|             : appState.activeTool, | ||||
|       }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|  | ||||
|   PanelComponent: ({ updateData }) => <ClearCanvas onConfirm={updateData} />, | ||||
|   PanelComponent: ({ updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={trash} | ||||
|       title={t("buttons.clearReset")} | ||||
|       aria-label={t("buttons.clearReset")} | ||||
|       showAriaLabel={useIsMobile()} | ||||
|       onClick={() => { | ||||
|         if (window.confirm(t("alerts.clearReset"))) { | ||||
|           updateData(null); | ||||
|         } | ||||
|       }} | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionZoomIn = register({ | ||||
|   name: "zoomIn", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (_elements, appState, _, app) => { | ||||
|   perform: (_elements, appState) => { | ||||
|     const zoom = getNewZoom( | ||||
|       getNormalizedZoom(appState.zoom.value + ZOOM_STEP), | ||||
|       appState.zoom, | ||||
|       { left: appState.offsetLeft, top: appState.offsetTop }, | ||||
|       { x: appState.width / 2, y: appState.height / 2 }, | ||||
|     ); | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         ...getStateForZoom( | ||||
|           { | ||||
|             viewportX: appState.width / 2 + appState.offsetLeft, | ||||
|             viewportY: appState.height / 2 + appState.offsetTop, | ||||
|             nextZoom: getNormalizedZoom(appState.zoom.value + ZOOM_STEP), | ||||
|           }, | ||||
|           appState, | ||||
|         ), | ||||
|         zoom, | ||||
|       }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
| @@ -109,7 +102,6 @@ export const actionZoomIn = register({ | ||||
|       onClick={() => { | ||||
|         updateData(null); | ||||
|       }} | ||||
|       size="small" | ||||
|     /> | ||||
|   ), | ||||
|   keyTest: (event) => | ||||
| @@ -119,19 +111,18 @@ export const actionZoomIn = register({ | ||||
|  | ||||
| export const actionZoomOut = register({ | ||||
|   name: "zoomOut", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (_elements, appState, _, app) => { | ||||
|   perform: (_elements, appState) => { | ||||
|     const zoom = getNewZoom( | ||||
|       getNormalizedZoom(appState.zoom.value - ZOOM_STEP), | ||||
|       appState.zoom, | ||||
|       { left: appState.offsetLeft, top: appState.offsetTop }, | ||||
|       { x: appState.width / 2, y: appState.height / 2 }, | ||||
|     ); | ||||
|  | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         ...getStateForZoom( | ||||
|           { | ||||
|             viewportX: appState.width / 2 + appState.offsetLeft, | ||||
|             viewportY: appState.height / 2 + appState.offsetTop, | ||||
|             nextZoom: getNormalizedZoom(appState.zoom.value - ZOOM_STEP), | ||||
|           }, | ||||
|           appState, | ||||
|         ), | ||||
|         zoom, | ||||
|       }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
| @@ -145,7 +136,6 @@ export const actionZoomOut = register({ | ||||
|       onClick={() => { | ||||
|         updateData(null); | ||||
|       }} | ||||
|       size="small" | ||||
|     /> | ||||
|   ), | ||||
|   keyTest: (event) => | ||||
| @@ -155,38 +145,33 @@ export const actionZoomOut = register({ | ||||
|  | ||||
| export const actionResetZoom = register({ | ||||
|   name: "resetZoom", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (_elements, appState, _, app) => { | ||||
|   perform: (_elements, appState) => { | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         ...getStateForZoom( | ||||
|         zoom: getNewZoom( | ||||
|           1 as NormalizedZoomValue, | ||||
|           appState.zoom, | ||||
|           { left: appState.offsetLeft, top: appState.offsetTop }, | ||||
|           { | ||||
|             viewportX: appState.width / 2 + appState.offsetLeft, | ||||
|             viewportY: appState.height / 2 + appState.offsetTop, | ||||
|             nextZoom: getNormalizedZoom(1), | ||||
|             x: appState.width / 2, | ||||
|             y: appState.height / 2, | ||||
|           }, | ||||
|           appState, | ||||
|         ), | ||||
|       }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ updateData, appState }) => ( | ||||
|     <Tooltip label={t("buttons.resetZoom")} style={{ height: "100%" }}> | ||||
|       <ToolButton | ||||
|         type="button" | ||||
|         className="reset-zoom-button" | ||||
|         title={t("buttons.resetZoom")} | ||||
|         aria-label={t("buttons.resetZoom")} | ||||
|         onClick={() => { | ||||
|           updateData(null); | ||||
|         }} | ||||
|         size="small" | ||||
|       > | ||||
|         {(appState.zoom.value * 100).toFixed(0)}% | ||||
|       </ToolButton> | ||||
|     </Tooltip> | ||||
|   PanelComponent: ({ updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={resetZoom} | ||||
|       title={t("buttons.resetZoom")} | ||||
|       aria-label={t("buttons.resetZoom")} | ||||
|       onClick={() => { | ||||
|         updateData(null); | ||||
|       }} | ||||
|     /> | ||||
|   ), | ||||
|   keyTest: (event) => | ||||
|     (event.code === CODES.ZERO || event.code === CODES.NUM_ZERO) && | ||||
| @@ -225,12 +210,14 @@ const zoomToFitElements = ( | ||||
|       ? getCommonBounds(selectedElements) | ||||
|       : getCommonBounds(nonDeletedElements); | ||||
|  | ||||
|   const newZoom = { | ||||
|     value: zoomValueToFitBoundsOnViewport(commonBounds, { | ||||
|       width: appState.width, | ||||
|       height: appState.height, | ||||
|     }), | ||||
|   }; | ||||
|   const zoomValue = zoomValueToFitBoundsOnViewport(commonBounds, { | ||||
|     width: appState.width, | ||||
|     height: appState.height, | ||||
|   }); | ||||
|   const newZoom = getNewZoom(zoomValue, appState.zoom, { | ||||
|     left: appState.offsetLeft, | ||||
|     top: appState.offsetTop, | ||||
|   }); | ||||
|  | ||||
|   const [x1, y1, x2, y2] = commonBounds; | ||||
|   const centerX = (x1 + x2) / 2; | ||||
| @@ -254,7 +241,6 @@ const zoomToFitElements = ( | ||||
|  | ||||
| export const actionZoomToSelected = register({ | ||||
|   name: "zoomToSelection", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (elements, appState) => zoomToFitElements(elements, appState, true), | ||||
|   keyTest: (event) => | ||||
|     event.code === CODES.TWO && | ||||
| @@ -265,7 +251,6 @@ export const actionZoomToSelected = register({ | ||||
|  | ||||
| export const actionZoomToFit = register({ | ||||
|   name: "zoomToFit", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (elements, appState) => zoomToFitElements(elements, appState, false), | ||||
|   keyTest: (event) => | ||||
|     event.code === CODES.ONE && | ||||
| @@ -273,89 +258,3 @@ export const actionZoomToFit = register({ | ||||
|     !event.altKey && | ||||
|     !event[KEYS.CTRL_OR_CMD], | ||||
| }); | ||||
|  | ||||
| export const actionToggleTheme = register({ | ||||
|   name: "toggleTheme", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (_, appState, value) => { | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         theme: | ||||
|           value || (appState.theme === THEME.LIGHT ? THEME.DARK : THEME.LIGHT), | ||||
|       }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <div style={{ marginInlineStart: "0.25rem" }}> | ||||
|       <DarkModeToggle | ||||
|         value={appState.theme} | ||||
|         onChange={(theme) => { | ||||
|           updateData(theme); | ||||
|         }} | ||||
|       /> | ||||
|     </div> | ||||
|   ), | ||||
|   keyTest: (event) => event.altKey && event.shiftKey && event.code === CODES.D, | ||||
| }); | ||||
|  | ||||
| export const actionErase = register({ | ||||
|   name: "eraser", | ||||
|   trackEvent: { category: "toolbar" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const activeTool: any = { ...appState.activeTool }; | ||||
|  | ||||
|     if (appState.activeTool.type !== "eraser") { | ||||
|       if (appState.activeTool.type === "custom") { | ||||
|         activeTool.lastActiveToolBeforeEraser = { | ||||
|           type: "custom", | ||||
|           customType: appState.activeTool.customType, | ||||
|         }; | ||||
|       } else { | ||||
|         activeTool.lastActiveToolBeforeEraser = appState.activeTool.type; | ||||
|       } | ||||
|     } | ||||
|     if (isEraserActive(appState)) { | ||||
|       if (appState.activeTool.lastActiveToolBeforeEraser) { | ||||
|         if ( | ||||
|           typeof appState.activeTool.lastActiveToolBeforeEraser === "object" && | ||||
|           appState.activeTool.lastActiveToolBeforeEraser?.type === "custom" | ||||
|         ) { | ||||
|           activeTool.type = "custom"; | ||||
|           activeTool.customType = | ||||
|             appState.activeTool.lastActiveToolBeforeEraser.customType; | ||||
|         } else { | ||||
|           activeTool.type = appState.activeTool.lastActiveToolBeforeEraser; | ||||
|         } | ||||
|       } else { | ||||
|         activeTool.type = "selection"; | ||||
|       } | ||||
|     } else { | ||||
|       activeTool.type = "eraser"; | ||||
|     } | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         selectedElementIds: {}, | ||||
|         selectedGroupIds: {}, | ||||
|         activeTool, | ||||
|       }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event) => event.key === KEYS.E, | ||||
|   PanelComponent: ({ elements, appState, updateData, data }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={eraser} | ||||
|       className={clsx("eraser", { active: isEraserActive(appState) })} | ||||
|       title={`${t("toolBar.eraser")}-${getShortcutKey("E")}`} | ||||
|       aria-label={t("toolBar.eraser")} | ||||
|       onClick={() => { | ||||
|         updateData(null); | ||||
|       }} | ||||
|       size={data?.size || "medium"} | ||||
|     ></ToolButton> | ||||
|   ), | ||||
| }); | ||||
|   | ||||
| @@ -1,39 +1,30 @@ | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { | ||||
|   copyTextToSystemClipboard, | ||||
|   copyToClipboard, | ||||
|   probablySupportsClipboardWriteText, | ||||
| } from "../clipboard"; | ||||
| import { copyToClipboard } from "../clipboard"; | ||||
| import { actionDeleteSelected } from "./actionDeleteSelected"; | ||||
| import { getSelectedElements } from "../scene/selection"; | ||||
| import { exportCanvas } from "../data/index"; | ||||
| import { getNonDeletedElements, isTextElement } from "../element"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { t } from "../i18n"; | ||||
|  | ||||
| export const actionCopy = register({ | ||||
|   name: "copy", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState, _, app) => { | ||||
|     const selectedElements = getSelectedElements(elements, appState, true); | ||||
|  | ||||
|     copyToClipboard(selectedElements, appState, app.files); | ||||
|   perform: (elements, appState) => { | ||||
|     copyToClipboard(getNonDeletedElements(elements), appState); | ||||
|  | ||||
|     return { | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   contextItemLabel: "labels.copy", | ||||
|   // don't supply a shortcut since we handle this conditionally via onCopy event | ||||
|   keyTest: undefined, | ||||
|   // Don't assign keyTest since its handled via copy event | ||||
| }); | ||||
|  | ||||
| export const actionCut = register({ | ||||
|   name: "cut", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState, data, app) => { | ||||
|     actionCopy.perform(elements, appState, data, app); | ||||
|     return actionDeleteSelected.perform(elements, appState); | ||||
|     return actionDeleteSelected.perform(elements, appState, data, app); | ||||
|   }, | ||||
|   contextItemLabel: "labels.cut", | ||||
|   keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.code === CODES.X, | ||||
| @@ -41,7 +32,6 @@ export const actionCut = register({ | ||||
|  | ||||
| export const actionCopyAsSvg = register({ | ||||
|   name: "copyAsSvg", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: async (elements, appState, _data, app) => { | ||||
|     if (!app.canvas) { | ||||
|       return { | ||||
| @@ -51,7 +41,6 @@ export const actionCopyAsSvg = register({ | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|       true, | ||||
|     ); | ||||
|     try { | ||||
|       await exportCanvas( | ||||
| @@ -60,13 +49,13 @@ export const actionCopyAsSvg = register({ | ||||
|           ? selectedElements | ||||
|           : getNonDeletedElements(elements), | ||||
|         appState, | ||||
|         app.files, | ||||
|         app.canvas, | ||||
|         appState, | ||||
|       ); | ||||
|       return { | ||||
|         commitToHistory: false, | ||||
|       }; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|       return { | ||||
|         appState: { | ||||
| @@ -82,7 +71,6 @@ export const actionCopyAsSvg = register({ | ||||
|  | ||||
| export const actionCopyAsPng = register({ | ||||
|   name: "copyAsPng", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: async (elements, appState, _data, app) => { | ||||
|     if (!app.canvas) { | ||||
|       return { | ||||
| @@ -92,7 +80,6 @@ export const actionCopyAsPng = register({ | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|       true, | ||||
|     ); | ||||
|     try { | ||||
|       await exportCanvas( | ||||
| @@ -101,7 +88,7 @@ export const actionCopyAsPng = register({ | ||||
|           ? selectedElements | ||||
|           : getNonDeletedElements(elements), | ||||
|         appState, | ||||
|         app.files, | ||||
|         app.canvas, | ||||
|         appState, | ||||
|       ); | ||||
|       return { | ||||
| @@ -118,7 +105,7 @@ export const actionCopyAsPng = register({ | ||||
|         }, | ||||
|         commitToHistory: false, | ||||
|       }; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|       return { | ||||
|         appState: { | ||||
| @@ -132,35 +119,3 @@ export const actionCopyAsPng = register({ | ||||
|   contextItemLabel: "labels.copyAsPng", | ||||
|   keyTest: (event) => event.code === CODES.C && event.altKey && event.shiftKey, | ||||
| }); | ||||
|  | ||||
| export const copyText = register({ | ||||
|   name: "copyText", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|       true, | ||||
|     ); | ||||
|  | ||||
|     const text = selectedElements | ||||
|       .reduce((acc: string[], element) => { | ||||
|         if (isTextElement(element)) { | ||||
|           acc.push(element.text); | ||||
|         } | ||||
|         return acc; | ||||
|       }, []) | ||||
|       .join("\n\n"); | ||||
|     copyTextToSystemClipboard(text); | ||||
|     return { | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   contextItemPredicate: (elements, appState) => { | ||||
|     return ( | ||||
|       probablySupportsClipboardWriteText && | ||||
|       getSelectedElements(elements, appState, true).some(isTextElement) | ||||
|     ); | ||||
|   }, | ||||
|   contextItemLabel: "labels.copyText", | ||||
| }); | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import { isSomeElementSelected } from "../scene"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import React from "react"; | ||||
| import { trash } from "../components/icons"; | ||||
| import { t } from "../i18n"; | ||||
| import { register } from "./register"; | ||||
| @@ -11,7 +12,6 @@ import { newElementWith } from "../element/mutateElement"; | ||||
| import { getElementsInGroup } from "../groups"; | ||||
| import { LinearElementEditor } from "../element/linearElementEditor"; | ||||
| import { fixBindingsAfterDeletion } from "../element/binding"; | ||||
| import { isBoundToContainer } from "../element/typeChecks"; | ||||
|  | ||||
| const deleteSelectedElements = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
| @@ -22,12 +22,6 @@ const deleteSelectedElements = ( | ||||
|       if (appState.selectedElementIds[el.id]) { | ||||
|         return newElementWith(el, { isDeleted: true }); | ||||
|       } | ||||
|       if ( | ||||
|         isBoundToContainer(el) && | ||||
|         appState.selectedElementIds[el.containerId] | ||||
|       ) { | ||||
|         return newElementWith(el, { isDeleted: true }); | ||||
|       } | ||||
|       return el; | ||||
|     }), | ||||
|     appState: { | ||||
| @@ -58,12 +52,11 @@ const handleGroupEditingState = ( | ||||
|  | ||||
| export const actionDeleteSelected = register({ | ||||
|   name: "deleteSelectedElements", | ||||
|   trackEvent: { category: "element", action: "delete" }, | ||||
|   perform: (elements, appState) => { | ||||
|     if (appState.editingLinearElement) { | ||||
|       const { | ||||
|         elementId, | ||||
|         selectedPointsIndices, | ||||
|         activePointIndex, | ||||
|         startBindingElement, | ||||
|         endBindingElement, | ||||
|       } = appState.editingLinearElement; | ||||
| @@ -73,7 +66,8 @@ export const actionDeleteSelected = register({ | ||||
|       } | ||||
|       if ( | ||||
|         // case: no point selected → delete whole element | ||||
|         selectedPointsIndices == null || | ||||
|         activePointIndex == null || | ||||
|         activePointIndex === -1 || | ||||
|         // case: deleting last remaining point | ||||
|         element.points.length < 2 | ||||
|       ) { | ||||
| @@ -93,17 +87,15 @@ export const actionDeleteSelected = register({ | ||||
|       // We cannot do this inside `movePoint` because it is also called | ||||
|       // when deleting the uncommitted point (which hasn't caused any binding) | ||||
|       const binding = { | ||||
|         startBindingElement: selectedPointsIndices?.includes(0) | ||||
|           ? null | ||||
|           : startBindingElement, | ||||
|         endBindingElement: selectedPointsIndices?.includes( | ||||
|           element.points.length - 1, | ||||
|         ) | ||||
|           ? null | ||||
|           : endBindingElement, | ||||
|         startBindingElement: | ||||
|           activePointIndex === 0 ? null : startBindingElement, | ||||
|         endBindingElement: | ||||
|           activePointIndex === element.points.length - 1 | ||||
|             ? null | ||||
|             : endBindingElement, | ||||
|       }; | ||||
|  | ||||
|       LinearElementEditor.deletePoints(element, selectedPointsIndices); | ||||
|       LinearElementEditor.movePoint(element, activePointIndex, "delete"); | ||||
|  | ||||
|       return { | ||||
|         elements, | ||||
| @@ -112,17 +104,17 @@ export const actionDeleteSelected = register({ | ||||
|           editingLinearElement: { | ||||
|             ...appState.editingLinearElement, | ||||
|             ...binding, | ||||
|             selectedPointsIndices: | ||||
|               selectedPointsIndices?.[0] > 0 | ||||
|                 ? [selectedPointsIndices[0] - 1] | ||||
|                 : [0], | ||||
|             activePointIndex: activePointIndex > 0 ? activePointIndex - 1 : 0, | ||||
|           }, | ||||
|         }, | ||||
|         commitToHistory: true, | ||||
|       }; | ||||
|     } | ||||
|     let { elements: nextElements, appState: nextAppState } = | ||||
|       deleteSelectedElements(elements, appState); | ||||
|  | ||||
|     let { | ||||
|       elements: nextElements, | ||||
|       appState: nextAppState, | ||||
|     } = deleteSelectedElements(elements, appState); | ||||
|     fixBindingsAfterDeletion( | ||||
|       nextElements, | ||||
|       elements.filter(({ id }) => appState.selectedElementIds[id]), | ||||
| @@ -134,7 +126,7 @@ export const actionDeleteSelected = register({ | ||||
|       elements: nextElements, | ||||
|       appState: { | ||||
|         ...nextAppState, | ||||
|         activeTool: { ...appState.activeTool, type: "selection" }, | ||||
|         elementType: "selection", | ||||
|         multiElement: null, | ||||
|       }, | ||||
|       commitToHistory: isSomeElementSelected( | ||||
|   | ||||
| @@ -1,16 +1,17 @@ | ||||
| import React from "react"; | ||||
| import { | ||||
|   DistributeHorizontallyIcon, | ||||
|   DistributeVerticallyIcon, | ||||
| } from "../components/icons"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { distributeElements, Distribution } from "../disitrubte"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { getElementMap, getNonDeletedElements } from "../element"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { t } from "../i18n"; | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { CODES } from "../keys"; | ||||
| import { getSelectedElements, isSomeElementSelected } from "../scene"; | ||||
| import { AppState } from "../types"; | ||||
| import { arrayToMap, getShortcutKey } from "../utils"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { register } from "./register"; | ||||
|  | ||||
| const enableActionGroup = ( | ||||
| @@ -30,16 +31,13 @@ const distributeSelectedElements = ( | ||||
|  | ||||
|   const updatedElements = distributeElements(selectedElements, distribution); | ||||
|  | ||||
|   const updatedElementsMap = arrayToMap(updatedElements); | ||||
|   const updatedElementsMap = getElementMap(updatedElements); | ||||
|  | ||||
|   return elements.map( | ||||
|     (element) => updatedElementsMap.get(element.id) || element, | ||||
|   ); | ||||
|   return elements.map((element) => updatedElementsMap[element.id] || element); | ||||
| }; | ||||
|  | ||||
| export const distributeHorizontally = register({ | ||||
|   name: "distributeHorizontally", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -50,13 +48,12 @@ export const distributeHorizontally = register({ | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event) => | ||||
|     !event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.H, | ||||
|   keyTest: (event) => event.altKey && event.code === CODES.H, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<DistributeHorizontallyIcon theme={appState.theme} />} | ||||
|       icon={<DistributeHorizontallyIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.distributeHorizontally")} — ${getShortcutKey( | ||||
|         "Alt+H", | ||||
| @@ -69,7 +66,6 @@ export const distributeHorizontally = register({ | ||||
|  | ||||
| export const distributeVertically = register({ | ||||
|   name: "distributeVertically", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       appState, | ||||
| @@ -80,13 +76,12 @@ export const distributeVertically = register({ | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event) => | ||||
|     !event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.V, | ||||
|   keyTest: (event) => event.altKey && event.code === CODES.V, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<DistributeVerticallyIcon theme={appState.theme} />} | ||||
|       icon={<DistributeVerticallyIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.distributeVertically")} — ${getShortcutKey("Alt+V")}`} | ||||
|       aria-label={t("labels.distributeVertically")} | ||||
|   | ||||
| @@ -1,13 +1,15 @@ | ||||
| import React from "react"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { duplicateElement, getNonDeletedElements } from "../element"; | ||||
| import { getSelectedElements, isSomeElementSelected } from "../scene"; | ||||
| import { isSomeElementSelected } from "../scene"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { clone } from "../components/icons"; | ||||
| import { t } from "../i18n"; | ||||
| import { arrayToMap, getShortcutKey } from "../utils"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { LinearElementEditor } from "../element/linearElementEditor"; | ||||
| import { mutateElement } from "../element/mutateElement"; | ||||
| import { | ||||
|   selectGroupsForSelectedElements, | ||||
|   getSelectedGroupForElement, | ||||
| @@ -17,24 +19,41 @@ import { AppState } from "../types"; | ||||
| import { fixBindingsAfterDuplication } from "../element/binding"; | ||||
| import { ActionResult } from "./types"; | ||||
| import { GRID_SIZE } from "../constants"; | ||||
| import { bindTextToShapeAfterDuplication } from "../element/textElement"; | ||||
| import { isBoundToContainer } from "../element/typeChecks"; | ||||
|  | ||||
| export const actionDuplicateSelection = register({ | ||||
|   name: "duplicateSelection", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     // duplicate selected point(s) if editing a line | ||||
|     // duplicate point if selected while editing multi-point element | ||||
|     if (appState.editingLinearElement) { | ||||
|       const ret = LinearElementEditor.duplicateSelectedPoints(appState); | ||||
|  | ||||
|       if (!ret) { | ||||
|       const { activePointIndex, elementId } = appState.editingLinearElement; | ||||
|       const element = LinearElementEditor.getElement(elementId); | ||||
|       if (!element || activePointIndex === null) { | ||||
|         return false; | ||||
|       } | ||||
|  | ||||
|       const { points } = element; | ||||
|       const selectedPoint = points[activePointIndex]; | ||||
|       const nextPoint = points[activePointIndex + 1]; | ||||
|       mutateElement(element, { | ||||
|         points: [ | ||||
|           ...points.slice(0, activePointIndex + 1), | ||||
|           nextPoint | ||||
|             ? [ | ||||
|                 (selectedPoint[0] + nextPoint[0]) / 2, | ||||
|                 (selectedPoint[1] + nextPoint[1]) / 2, | ||||
|               ] | ||||
|             : [selectedPoint[0] + 30, selectedPoint[1] + 30], | ||||
|           ...points.slice(activePointIndex + 1), | ||||
|         ], | ||||
|       }); | ||||
|       return { | ||||
|         appState: { | ||||
|           ...appState, | ||||
|           editingLinearElement: { | ||||
|             ...appState.editingLinearElement, | ||||
|             activePointIndex: activePointIndex + 1, | ||||
|           }, | ||||
|         }, | ||||
|         elements, | ||||
|         appState: ret.appState, | ||||
|         commitToHistory: true, | ||||
|       }; | ||||
|     } | ||||
| @@ -88,12 +107,9 @@ const duplicateElements = ( | ||||
|   const finalElements: ExcalidrawElement[] = []; | ||||
|  | ||||
|   let index = 0; | ||||
|   const selectedElementIds = arrayToMap( | ||||
|     getSelectedElements(elements, appState, true), | ||||
|   ); | ||||
|   while (index < elements.length) { | ||||
|     const element = elements[index]; | ||||
|     if (selectedElementIds.get(element.id)) { | ||||
|     if (appState.selectedElementIds[element.id]) { | ||||
|       if (element.groupIds.length) { | ||||
|         const groupId = getSelectedGroupForElement(appState, element); | ||||
|         // if group selected, duplicate it atomically | ||||
| @@ -115,11 +131,7 @@ const duplicateElements = ( | ||||
|     } | ||||
|     index++; | ||||
|   } | ||||
|   bindTextToShapeAfterDuplication( | ||||
|     finalElements, | ||||
|     oldElements, | ||||
|     oldIdToDuplicatedId, | ||||
|   ); | ||||
|  | ||||
|   fixBindingsAfterDuplication(finalElements, oldElements, oldIdToDuplicatedId); | ||||
|  | ||||
|   return { | ||||
| @@ -129,9 +141,7 @@ const duplicateElements = ( | ||||
|         ...appState, | ||||
|         selectedGroupIds: {}, | ||||
|         selectedElementIds: newElements.reduce((acc, element) => { | ||||
|           if (!isBoundToContainer(element)) { | ||||
|             acc[element.id] = true; | ||||
|           } | ||||
|           acc[element.id] = true; | ||||
|           return acc; | ||||
|         }, {} as any), | ||||
|       }, | ||||
|   | ||||
| @@ -1,95 +1,34 @@ | ||||
| import { load, questionCircle, saveAs } from "../components/icons"; | ||||
| import React from "react"; | ||||
| import { trackEvent } from "../analytics"; | ||||
| import { load, questionCircle, save, saveAs } from "../components/icons"; | ||||
| import { ProjectName } from "../components/ProjectName"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import "../components/ToolIcon.scss"; | ||||
| import { Tooltip } from "../components/Tooltip"; | ||||
| import { DarkModeToggle } from "../components/DarkModeToggle"; | ||||
| import { DarkModeToggle, Appearence } from "../components/DarkModeToggle"; | ||||
| import { loadFromJSON, saveAsJSON } from "../data"; | ||||
| import { resaveAsImageWithScene } from "../data/resave"; | ||||
| import { t } from "../i18n"; | ||||
| import { useDeviceType } from "../components/App"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { CheckboxItem } from "../components/CheckboxItem"; | ||||
| import { getExportSize } from "../scene/export"; | ||||
| import { DEFAULT_EXPORT_PADDING, EXPORT_SCALES, THEME } from "../constants"; | ||||
| import { getSelectedElements, isSomeElementSelected } from "../scene"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { ActiveFile } from "../components/ActiveFile"; | ||||
| import { isImageFileHandle } from "../data/blob"; | ||||
| import { nativeFileSystemSupported } from "../data/filesystem"; | ||||
| import { Theme } from "../element/types"; | ||||
|  | ||||
| export const actionChangeProjectName = register({ | ||||
|   name: "changeProjectName", | ||||
|   trackEvent: false, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     trackEvent("change", "title"); | ||||
|     return { appState: { ...appState, name: value }, commitToHistory: false }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData, appProps }) => ( | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <ProjectName | ||||
|       label={t("labels.fileTitle")} | ||||
|       value={appState.name || "Unnamed"} | ||||
|       onChange={(name: string) => updateData(name)} | ||||
|       isNameEditable={ | ||||
|         typeof appProps.name === "undefined" && !appState.viewModeEnabled | ||||
|       } | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionChangeExportScale = register({ | ||||
|   name: "changeExportScale", | ||||
|   trackEvent: { category: "export", action: "scale" }, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, exportScale: value }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements: allElements, appState, updateData }) => { | ||||
|     const elements = getNonDeletedElements(allElements); | ||||
|     const exportSelected = isSomeElementSelected(elements, appState); | ||||
|     const exportedElements = exportSelected | ||||
|       ? getSelectedElements(elements, appState) | ||||
|       : elements; | ||||
|  | ||||
|     return ( | ||||
|       <> | ||||
|         {EXPORT_SCALES.map((s) => { | ||||
|           const [width, height] = getExportSize( | ||||
|             exportedElements, | ||||
|             DEFAULT_EXPORT_PADDING, | ||||
|             s, | ||||
|           ); | ||||
|  | ||||
|           const scaleButtonTitle = `${t( | ||||
|             "buttons.scale", | ||||
|           )} ${s}x (${width}x${height})`; | ||||
|  | ||||
|           return ( | ||||
|             <ToolButton | ||||
|               key={s} | ||||
|               size="small" | ||||
|               type="radio" | ||||
|               icon={`${s}x`} | ||||
|               name="export-canvas-scale" | ||||
|               title={scaleButtonTitle} | ||||
|               aria-label={scaleButtonTitle} | ||||
|               id="export-canvas-scale" | ||||
|               checked={s === appState.exportScale} | ||||
|               onChange={() => updateData(s)} | ||||
|             /> | ||||
|           ); | ||||
|         })} | ||||
|       </> | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const actionChangeExportBackground = register({ | ||||
|   name: "changeExportBackground", | ||||
|   trackEvent: { category: "export", action: "toggleBackground" }, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, exportBackground: value }, | ||||
| @@ -97,18 +36,19 @@ export const actionChangeExportBackground = register({ | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <CheckboxItem | ||||
|       checked={appState.exportBackground} | ||||
|       onChange={(checked) => updateData(checked)} | ||||
|     > | ||||
|     <label> | ||||
|       <input | ||||
|         type="checkbox" | ||||
|         checked={appState.exportBackground} | ||||
|         onChange={(event) => updateData(event.target.checked)} | ||||
|       />{" "} | ||||
|       {t("labels.withBackground")} | ||||
|     </CheckboxItem> | ||||
|     </label> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionChangeExportEmbedScene = register({ | ||||
|   name: "changeExportEmbedScene", | ||||
|   trackEvent: { category: "export", action: "embedScene" }, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, exportEmbedScene: value }, | ||||
| @@ -116,36 +56,57 @@ export const actionChangeExportEmbedScene = register({ | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <CheckboxItem | ||||
|       checked={appState.exportEmbedScene} | ||||
|       onChange={(checked) => updateData(checked)} | ||||
|     > | ||||
|     <label style={{ display: "flex" }}> | ||||
|       <input | ||||
|         type="checkbox" | ||||
|         checked={appState.exportEmbedScene} | ||||
|         onChange={(event) => updateData(event.target.checked)} | ||||
|       />{" "} | ||||
|       {t("labels.exportEmbedScene")} | ||||
|       <Tooltip label={t("labels.exportEmbedScene_details")} long={true}> | ||||
|         <div className="excalidraw-tooltip-icon">{questionCircle}</div> | ||||
|       <Tooltip | ||||
|         label={t("labels.exportEmbedScene_details")} | ||||
|         position="above" | ||||
|         long={true} | ||||
|       > | ||||
|         <div className="TooltipIcon">{questionCircle}</div> | ||||
|       </Tooltip> | ||||
|     </CheckboxItem> | ||||
|     </label> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionSaveToActiveFile = register({ | ||||
|   name: "saveToActiveFile", | ||||
|   trackEvent: { category: "export" }, | ||||
|   perform: async (elements, appState, value, app) => { | ||||
| export const actionChangeShouldAddWatermark = register({ | ||||
|   name: "changeShouldAddWatermark", | ||||
|   perform: (_elements, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, shouldAddWatermark: value }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <label> | ||||
|       <input | ||||
|         type="checkbox" | ||||
|         checked={appState.shouldAddWatermark} | ||||
|         onChange={(event) => updateData(event.target.checked)} | ||||
|       />{" "} | ||||
|       {t("labels.addWatermark")} | ||||
|     </label> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionSaveScene = register({ | ||||
|   name: "saveScene", | ||||
|   perform: async (elements, appState, value) => { | ||||
|     const fileHandleExists = !!appState.fileHandle; | ||||
|  | ||||
|     try { | ||||
|       const { fileHandle } = isImageFileHandle(appState.fileHandle) | ||||
|         ? await resaveAsImageWithScene(elements, appState, app.files) | ||||
|         : await saveAsJSON(elements, appState, app.files); | ||||
|  | ||||
|       const { fileHandle } = await saveAsJSON(elements, appState); | ||||
|       return { | ||||
|         commitToHistory: false, | ||||
|         appState: { | ||||
|           ...appState, | ||||
|           fileHandle, | ||||
|           toastMessage: fileHandleExists | ||||
|             ? fileHandle?.name | ||||
|             ? fileHandle.name | ||||
|               ? t("toast.fileSavedToFilename").replace( | ||||
|                   "{filename}", | ||||
|                   `"${fileHandle.name}"`, | ||||
| @@ -154,44 +115,39 @@ export const actionSaveToActiveFile = register({ | ||||
|             : null, | ||||
|         }, | ||||
|       }; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       if (error?.name !== "AbortError") { | ||||
|         console.error(error); | ||||
|       } else { | ||||
|         console.warn(error); | ||||
|       } | ||||
|       return { commitToHistory: false }; | ||||
|     } | ||||
|   }, | ||||
|   keyTest: (event) => | ||||
|     event.key === KEYS.S && event[KEYS.CTRL_OR_CMD] && !event.shiftKey, | ||||
|   PanelComponent: ({ updateData, appState }) => ( | ||||
|     <ActiveFile | ||||
|       onSave={() => updateData(null)} | ||||
|       fileName={appState.fileHandle?.name} | ||||
|   PanelComponent: ({ updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={save} | ||||
|       title={t("buttons.save")} | ||||
|       aria-label={t("buttons.save")} | ||||
|       showAriaLabel={useIsMobile()} | ||||
|       onClick={() => updateData(null)} | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionSaveFileToDisk = register({ | ||||
|   name: "saveFileToDisk", | ||||
|   trackEvent: { category: "export" }, | ||||
|   perform: async (elements, appState, value, app) => { | ||||
| export const actionSaveAsScene = register({ | ||||
|   name: "saveAsScene", | ||||
|   perform: async (elements, appState, value) => { | ||||
|     try { | ||||
|       const { fileHandle } = await saveAsJSON( | ||||
|         elements, | ||||
|         { | ||||
|           ...appState, | ||||
|           fileHandle: null, | ||||
|         }, | ||||
|         app.files, | ||||
|       ); | ||||
|       const { fileHandle } = await saveAsJSON(elements, { | ||||
|         ...appState, | ||||
|         fileHandle: null, | ||||
|       }); | ||||
|       return { commitToHistory: false, appState: { ...appState, fileHandle } }; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       if (error?.name !== "AbortError") { | ||||
|         console.error(error); | ||||
|       } else { | ||||
|         console.warn(error); | ||||
|       } | ||||
|       return { commitToHistory: false }; | ||||
|     } | ||||
| @@ -204,39 +160,35 @@ export const actionSaveFileToDisk = register({ | ||||
|       icon={saveAs} | ||||
|       title={t("buttons.saveAs")} | ||||
|       aria-label={t("buttons.saveAs")} | ||||
|       showAriaLabel={useDeviceType().isMobile} | ||||
|       hidden={!nativeFileSystemSupported} | ||||
|       showAriaLabel={useIsMobile()} | ||||
|       hidden={ | ||||
|         !("chooseFileSystemEntries" in window || "showOpenFilePicker" in window) | ||||
|       } | ||||
|       onClick={() => updateData(null)} | ||||
|       data-testid="save-as-button" | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionLoadScene = register({ | ||||
|   name: "loadScene", | ||||
|   trackEvent: { category: "export" }, | ||||
|   perform: async (elements, appState, _, app) => { | ||||
|   perform: async (elements, appState) => { | ||||
|     try { | ||||
|       const { | ||||
|         elements: loadedElements, | ||||
|         appState: loadedAppState, | ||||
|         files, | ||||
|       } = await loadFromJSON(appState, elements); | ||||
|       } = await loadFromJSON(appState); | ||||
|       return { | ||||
|         elements: loadedElements, | ||||
|         appState: loadedAppState, | ||||
|         files, | ||||
|         commitToHistory: true, | ||||
|       }; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       if (error?.name === "AbortError") { | ||||
|         console.warn(error); | ||||
|         return false; | ||||
|       } | ||||
|       return { | ||||
|         elements, | ||||
|         appState: { ...appState, errorMessage: error.message }, | ||||
|         files: app.files, | ||||
|         commitToHistory: false, | ||||
|       }; | ||||
|     } | ||||
| @@ -248,16 +200,14 @@ export const actionLoadScene = register({ | ||||
|       icon={load} | ||||
|       title={t("buttons.load")} | ||||
|       aria-label={t("buttons.load")} | ||||
|       showAriaLabel={useDeviceType().isMobile} | ||||
|       showAriaLabel={useIsMobile()} | ||||
|       onClick={updateData} | ||||
|       data-testid="load-button" | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionExportWithDarkMode = register({ | ||||
|   name: "exportWithDarkMode", | ||||
|   trackEvent: { category: "export", action: "toggleTheme" }, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     return { | ||||
|       appState: { ...appState, exportWithDarkMode: value }, | ||||
| @@ -274,9 +224,9 @@ export const actionExportWithDarkMode = register({ | ||||
|       }} | ||||
|     > | ||||
|       <DarkModeToggle | ||||
|         value={appState.exportWithDarkMode ? THEME.DARK : THEME.LIGHT} | ||||
|         onChange={(theme: Theme) => { | ||||
|           updateData(theme === THEME.DARK); | ||||
|         value={appState.exportWithDarkMode ? "dark" : "light"} | ||||
|         onChange={(appearance: Appearence) => { | ||||
|           updateData(appearance === "dark"); | ||||
|         }} | ||||
|         title={t("labels.toggleExportColorScheme")} | ||||
|       /> | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| import { KEYS } from "../keys"; | ||||
| import { isInvisiblySmallElement } from "../element"; | ||||
| import { resetCursor } from "../utils"; | ||||
| import React from "react"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { done } from "../components/icons"; | ||||
| import { t } from "../i18n"; | ||||
| @@ -17,11 +18,13 @@ import { isBindingElement } from "../element/typeChecks"; | ||||
|  | ||||
| export const actionFinalize = register({ | ||||
|   name: "finalize", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, _, { canvas, focusContainer }) => { | ||||
|   perform: (elements, appState, _, { canvas }) => { | ||||
|     if (appState.editingLinearElement) { | ||||
|       const { elementId, startBindingElement, endBindingElement } = | ||||
|         appState.editingLinearElement; | ||||
|       const { | ||||
|         elementId, | ||||
|         startBindingElement, | ||||
|         endBindingElement, | ||||
|       } = appState.editingLinearElement; | ||||
|       const element = LinearElementEditor.getElement(elementId); | ||||
|  | ||||
|       if (element) { | ||||
| @@ -39,7 +42,6 @@ export const actionFinalize = register({ | ||||
|               : undefined, | ||||
|           appState: { | ||||
|             ...appState, | ||||
|             cursorButton: "up", | ||||
|             editingLinearElement: null, | ||||
|           }, | ||||
|           commitToHistory: true, | ||||
| @@ -48,25 +50,20 @@ export const actionFinalize = register({ | ||||
|     } | ||||
|  | ||||
|     let newElements = elements; | ||||
|  | ||||
|     if (appState.pendingImageElement) { | ||||
|       mutateElement(appState.pendingImageElement, { isDeleted: true }, false); | ||||
|     } | ||||
|  | ||||
|     if (window.document.activeElement instanceof HTMLElement) { | ||||
|       focusContainer(); | ||||
|       window.document.activeElement.blur(); | ||||
|     } | ||||
|  | ||||
|     const multiPointElement = appState.multiElement | ||||
|       ? appState.multiElement | ||||
|       : appState.editingElement?.type === "freedraw" | ||||
|       : appState.editingElement?.type === "draw" | ||||
|       ? appState.editingElement | ||||
|       : null; | ||||
|  | ||||
|     if (multiPointElement) { | ||||
|       // pen and mouse have hover | ||||
|       if ( | ||||
|         multiPointElement.type !== "freedraw" && | ||||
|         multiPointElement.type !== "draw" && | ||||
|         appState.lastPointerDownWith !== "touch" | ||||
|       ) { | ||||
|         const { points, lastCommittedPoint } = multiPointElement; | ||||
| @@ -89,7 +86,7 @@ export const actionFinalize = register({ | ||||
|       const isLoop = isPathALoop(multiPointElement.points, appState.zoom.value); | ||||
|       if ( | ||||
|         multiPointElement.type === "line" || | ||||
|         multiPointElement.type === "freedraw" | ||||
|         multiPointElement.type === "draw" | ||||
|       ) { | ||||
|         if (isLoop) { | ||||
|           const linePoints = multiPointElement.points; | ||||
| @@ -121,47 +118,25 @@ export const actionFinalize = register({ | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|       if ( | ||||
|         !appState.activeTool.locked && | ||||
|         appState.activeTool.type !== "freedraw" | ||||
|       ) { | ||||
|       if (!appState.elementLocked && appState.elementType !== "draw") { | ||||
|         appState.selectedElementIds[multiPointElement.id] = true; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     if ( | ||||
|       (!appState.activeTool.locked && | ||||
|         appState.activeTool.type !== "freedraw") || | ||||
|       (!appState.elementLocked && appState.elementType !== "draw") || | ||||
|       !multiPointElement | ||||
|     ) { | ||||
|       resetCursor(canvas); | ||||
|     } | ||||
|     const activeTool: any = { ...appState.activeTool }; | ||||
|     if (appState.activeTool.lastActiveToolBeforeEraser) { | ||||
|       if ( | ||||
|         typeof appState.activeTool.lastActiveToolBeforeEraser === "object" && | ||||
|         appState.activeTool.lastActiveToolBeforeEraser.type === "custom" | ||||
|       ) { | ||||
|         activeTool.type = appState.activeTool.lastActiveToolBeforeEraser.type; | ||||
|         activeTool.customType = | ||||
|           appState.activeTool.lastActiveToolBeforeEraser.customType; | ||||
|       } else { | ||||
|         activeTool.type = appState.activeTool.lastActiveToolBeforeEraser; | ||||
|       } | ||||
|     } else { | ||||
|       activeTool.type = "selection"; | ||||
|     } | ||||
|     return { | ||||
|       elements: newElements, | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         cursorButton: "up", | ||||
|         activeTool: | ||||
|           (appState.activeTool.locked || | ||||
|             appState.activeTool.type === "freedraw") && | ||||
|         elementType: | ||||
|           (appState.elementLocked || appState.elementType === "draw") && | ||||
|           multiPointElement | ||||
|             ? appState.activeTool | ||||
|             : activeTool, | ||||
|             ? appState.elementType | ||||
|             : "selection", | ||||
|         draggingElement: null, | ||||
|         multiElement: null, | ||||
|         editingElement: null, | ||||
| @@ -169,16 +144,15 @@ export const actionFinalize = register({ | ||||
|         suggestedBindings: [], | ||||
|         selectedElementIds: | ||||
|           multiPointElement && | ||||
|           !appState.activeTool.locked && | ||||
|           appState.activeTool.type !== "freedraw" | ||||
|           !appState.elementLocked && | ||||
|           appState.elementType !== "draw" | ||||
|             ? { | ||||
|                 ...appState.selectedElementIds, | ||||
|                 [multiPointElement.id]: true, | ||||
|               } | ||||
|             : appState.selectedElementIds, | ||||
|         pendingImageElement: null, | ||||
|       }, | ||||
|       commitToHistory: appState.activeTool.type === "freedraw", | ||||
|       commitToHistory: appState.elementType === "draw", | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event, appState) => | ||||
| @@ -187,7 +161,7 @@ export const actionFinalize = register({ | ||||
|         (!appState.draggingElement && appState.multiElement === null))) || | ||||
|     ((event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) && | ||||
|       appState.multiElement !== null), | ||||
|   PanelComponent: ({ appState, updateData, data }) => ( | ||||
|   PanelComponent: ({ appState, updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={done} | ||||
| @@ -195,7 +169,6 @@ export const actionFinalize = register({ | ||||
|       aria-label={t("buttons.done")} | ||||
|       onClick={updateData} | ||||
|       visible={appState.multiElement != null} | ||||
|       size={data?.size || "medium"} | ||||
|     /> | ||||
|   ), | ||||
| }); | ||||
|   | ||||
| @@ -1,211 +0,0 @@ | ||||
| import { register } from "./register"; | ||||
| import { getSelectedElements } from "../scene"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { mutateElement } from "../element/mutateElement"; | ||||
| import { ExcalidrawElement, NonDeleted } from "../element/types"; | ||||
| import { normalizeAngle, resizeSingleElement } from "../element/resizeElements"; | ||||
| import { AppState } from "../types"; | ||||
| import { getTransformHandles } from "../element/transformHandles"; | ||||
| import { isFreeDrawElement, isLinearElement } from "../element/typeChecks"; | ||||
| import { updateBoundElements } from "../element/binding"; | ||||
| import { LinearElementEditor } from "../element/linearElementEditor"; | ||||
| import { arrayToMap } from "../utils"; | ||||
|  | ||||
| const enableActionFlipHorizontal = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: AppState, | ||||
| ) => { | ||||
|   const eligibleElements = getSelectedElements( | ||||
|     getNonDeletedElements(elements), | ||||
|     appState, | ||||
|   ); | ||||
|   return eligibleElements.length === 1 && eligibleElements[0].type !== "text"; | ||||
| }; | ||||
|  | ||||
| const enableActionFlipVertical = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: AppState, | ||||
| ) => { | ||||
|   const eligibleElements = getSelectedElements( | ||||
|     getNonDeletedElements(elements), | ||||
|     appState, | ||||
|   ); | ||||
|   return eligibleElements.length === 1; | ||||
| }; | ||||
|  | ||||
| export const actionFlipHorizontal = register({ | ||||
|   name: "flipHorizontal", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: flipSelectedElements(elements, appState, "horizontal"), | ||||
|       appState, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event) => event.shiftKey && event.code === "KeyH", | ||||
|   contextItemLabel: "labels.flipHorizontal", | ||||
|   contextItemPredicate: (elements, appState) => | ||||
|     enableActionFlipHorizontal(elements, appState), | ||||
| }); | ||||
|  | ||||
| export const actionFlipVertical = register({ | ||||
|   name: "flipVertical", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: flipSelectedElements(elements, appState, "vertical"), | ||||
|       appState, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   keyTest: (event) => event.shiftKey && event.code === "KeyV", | ||||
|   contextItemLabel: "labels.flipVertical", | ||||
|   contextItemPredicate: (elements, appState) => | ||||
|     enableActionFlipVertical(elements, appState), | ||||
| }); | ||||
|  | ||||
| const flipSelectedElements = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: Readonly<AppState>, | ||||
|   flipDirection: "horizontal" | "vertical", | ||||
| ) => { | ||||
|   const selectedElements = getSelectedElements( | ||||
|     getNonDeletedElements(elements), | ||||
|     appState, | ||||
|   ); | ||||
|  | ||||
|   // remove once we allow for groups of elements to be flipped | ||||
|   if (selectedElements.length > 1) { | ||||
|     return elements; | ||||
|   } | ||||
|  | ||||
|   const updatedElements = flipElements( | ||||
|     selectedElements, | ||||
|     appState, | ||||
|     flipDirection, | ||||
|   ); | ||||
|  | ||||
|   const updatedElementsMap = arrayToMap(updatedElements); | ||||
|  | ||||
|   return elements.map( | ||||
|     (element) => updatedElementsMap.get(element.id) || element, | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const flipElements = ( | ||||
|   elements: NonDeleted<ExcalidrawElement>[], | ||||
|   appState: AppState, | ||||
|   flipDirection: "horizontal" | "vertical", | ||||
| ): ExcalidrawElement[] => { | ||||
|   elements.forEach((element) => { | ||||
|     flipElement(element, appState); | ||||
|     // If vertical flip, rotate an extra 180 | ||||
|     if (flipDirection === "vertical") { | ||||
|       rotateElement(element, Math.PI); | ||||
|     } | ||||
|   }); | ||||
|   return elements; | ||||
| }; | ||||
|  | ||||
| const flipElement = ( | ||||
|   element: NonDeleted<ExcalidrawElement>, | ||||
|   appState: AppState, | ||||
| ) => { | ||||
|   const originalX = element.x; | ||||
|   const originalY = element.y; | ||||
|   const width = element.width; | ||||
|   const height = element.height; | ||||
|   const originalAngle = normalizeAngle(element.angle); | ||||
|  | ||||
|   let finalOffsetX = 0; | ||||
|   if (isLinearElement(element) || isFreeDrawElement(element)) { | ||||
|     finalOffsetX = | ||||
|       element.points.reduce((max, point) => Math.max(max, point[0]), 0) * 2 - | ||||
|       element.width; | ||||
|   } | ||||
|  | ||||
|   // Rotate back to zero, if necessary | ||||
|   mutateElement(element, { | ||||
|     angle: normalizeAngle(0), | ||||
|   }); | ||||
|   // Flip unrotated by pulling TransformHandle to opposite side | ||||
|   const transformHandles = getTransformHandles(element, appState.zoom); | ||||
|   let usingNWHandle = true; | ||||
|   let newNCoordsX = 0; | ||||
|   let nHandle = transformHandles.nw; | ||||
|   if (!nHandle) { | ||||
|     // Use ne handle instead | ||||
|     usingNWHandle = false; | ||||
|     nHandle = transformHandles.ne; | ||||
|     if (!nHandle) { | ||||
|       mutateElement(element, { | ||||
|         angle: originalAngle, | ||||
|       }); | ||||
|       return; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (isLinearElement(element)) { | ||||
|     for (let index = 1; index < element.points.length; index++) { | ||||
|       LinearElementEditor.movePoints(element, [ | ||||
|         { index, point: [-element.points[index][0], element.points[index][1]] }, | ||||
|       ]); | ||||
|     } | ||||
|     LinearElementEditor.normalizePoints(element); | ||||
|   } else { | ||||
|     // calculate new x-coord for transformation | ||||
|     newNCoordsX = usingNWHandle ? element.x + 2 * width : element.x - 2 * width; | ||||
|     resizeSingleElement( | ||||
|       new Map().set(element.id, element), | ||||
|       true, | ||||
|       element, | ||||
|       usingNWHandle ? "nw" : "ne", | ||||
|       false, | ||||
|       newNCoordsX, | ||||
|       nHandle[1], | ||||
|     ); | ||||
|     // fix the size to account for handle sizes | ||||
|     mutateElement(element, { | ||||
|       width, | ||||
|       height, | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   // Rotate by (360 degrees - original angle) | ||||
|   let angle = normalizeAngle(2 * Math.PI - originalAngle); | ||||
|   if (angle < 0) { | ||||
|     // check, probably unnecessary | ||||
|     angle = normalizeAngle(angle + 2 * Math.PI); | ||||
|   } | ||||
|   mutateElement(element, { | ||||
|     angle, | ||||
|   }); | ||||
|  | ||||
|   // Move back to original spot to appear "flipped in place" | ||||
|   mutateElement(element, { | ||||
|     x: originalX + finalOffsetX, | ||||
|     y: originalY, | ||||
|   }); | ||||
|  | ||||
|   updateBoundElements(element); | ||||
| }; | ||||
|  | ||||
| const rotateElement = (element: ExcalidrawElement, rotationAngle: number) => { | ||||
|   const originalX = element.x; | ||||
|   const originalY = element.y; | ||||
|   let angle = normalizeAngle(element.angle + rotationAngle); | ||||
|   if (angle < 0) { | ||||
|     // check, probably unnecessary | ||||
|     angle = normalizeAngle(2 * Math.PI + angle); | ||||
|   } | ||||
|   mutateElement(element, { | ||||
|     angle, | ||||
|   }); | ||||
|  | ||||
|   // Move back to original spot | ||||
|   mutateElement(element, { | ||||
|     x: originalX, | ||||
|     y: originalY, | ||||
|   }); | ||||
| }; | ||||
| @@ -1,6 +1,7 @@ | ||||
| import React from "react"; | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { t } from "../i18n"; | ||||
| import { arrayToMap, getShortcutKey } from "../utils"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { register } from "./register"; | ||||
| import { UngroupIcon, GroupIcon } from "../components/icons"; | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| @@ -17,9 +18,8 @@ import { | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { randomId } from "../random"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { AppState } from "../types"; | ||||
| import { isBoundToContainer } from "../element/typeChecks"; | ||||
|  | ||||
| const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => { | ||||
|   if (elements.length >= 2) { | ||||
| @@ -45,7 +45,6 @@ const enableActionGroup = ( | ||||
|   const selectedElements = getSelectedElements( | ||||
|     getNonDeletedElements(elements), | ||||
|     appState, | ||||
|     true, | ||||
|   ); | ||||
|   return ( | ||||
|     selectedElements.length >= 2 && !allElementsInSameGroup(selectedElements) | ||||
| @@ -54,12 +53,10 @@ const enableActionGroup = ( | ||||
|  | ||||
| export const actionGroup = register({ | ||||
|   name: "group", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements( | ||||
|       getNonDeletedElements(elements), | ||||
|       appState, | ||||
|       true, | ||||
|     ); | ||||
|     if (selectedElements.length < 2) { | ||||
|       // nothing to group | ||||
| @@ -87,9 +84,8 @@ export const actionGroup = register({ | ||||
|       } | ||||
|     } | ||||
|     const newGroupId = randomId(); | ||||
|     const selectElementIds = arrayToMap(selectedElements); | ||||
|     const updatedElements = elements.map((element) => { | ||||
|       if (!selectElementIds.get(element.id)) { | ||||
|       if (!appState.selectedElementIds[element.id]) { | ||||
|         return element; | ||||
|       } | ||||
|       return newElementWith(element, { | ||||
| @@ -104,8 +100,9 @@ export const actionGroup = register({ | ||||
|     // to the z order of the highest element in the layer stack | ||||
|     const elementsInGroup = getElementsInGroup(updatedElements, newGroupId); | ||||
|     const lastElementInGroup = elementsInGroup[elementsInGroup.length - 1]; | ||||
|     const lastGroupElementIndex = | ||||
|       updatedElements.lastIndexOf(lastElementInGroup); | ||||
|     const lastGroupElementIndex = updatedElements.lastIndexOf( | ||||
|       lastElementInGroup, | ||||
|     ); | ||||
|     const elementsAfterGroup = updatedElements.slice(lastGroupElementIndex + 1); | ||||
|     const elementsBeforeGroup = updatedElements | ||||
|       .slice(0, lastGroupElementIndex) | ||||
| @@ -137,7 +134,7 @@ export const actionGroup = register({ | ||||
|     <ToolButton | ||||
|       hidden={!enableActionGroup(elements, appState)} | ||||
|       type="button" | ||||
|       icon={<GroupIcon theme={appState.theme} />} | ||||
|       icon={<GroupIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.group")} — ${getShortcutKey("CtrlOrCmd+G")}`} | ||||
|       aria-label={t("labels.group")} | ||||
| @@ -148,18 +145,12 @@ export const actionGroup = register({ | ||||
|  | ||||
| export const actionUngroup = register({ | ||||
|   name: "ungroup", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const groupIds = getSelectedGroupIds(appState); | ||||
|     if (groupIds.length === 0) { | ||||
|       return { appState, elements, commitToHistory: false }; | ||||
|     } | ||||
|  | ||||
|     const boundTextElementIds: ExcalidrawTextElement["id"][] = []; | ||||
|     const nextElements = elements.map((element) => { | ||||
|       if (isBoundToContainer(element)) { | ||||
|         boundTextElementIds.push(element.id); | ||||
|       } | ||||
|       const nextGroupIds = removeFromSelectedGroups( | ||||
|         element.groupIds, | ||||
|         appState.selectedGroupIds, | ||||
| @@ -171,19 +162,11 @@ export const actionUngroup = register({ | ||||
|         groupIds: nextGroupIds, | ||||
|       }); | ||||
|     }); | ||||
|  | ||||
|     const updateAppState = selectGroupsForSelectedElements( | ||||
|       { ...appState, selectedGroupIds: {} }, | ||||
|       getNonDeletedElements(nextElements), | ||||
|     ); | ||||
|  | ||||
|     // remove binded text elements from selection | ||||
|     boundTextElementIds.forEach( | ||||
|       (id) => (updateAppState.selectedElementIds[id] = false), | ||||
|     ); | ||||
|     return { | ||||
|       appState: updateAppState, | ||||
|  | ||||
|       appState: selectGroupsForSelectedElements( | ||||
|         { ...appState, selectedGroupIds: {} }, | ||||
|         getNonDeletedElements(nextElements), | ||||
|       ), | ||||
|       elements: nextElements, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
| @@ -198,7 +181,7 @@ export const actionUngroup = register({ | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       hidden={getSelectedGroupIds(appState).length === 0} | ||||
|       icon={<UngroupIcon theme={appState.theme} />} | ||||
|       icon={<UngroupIcon appearance={appState.appearance} />} | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.ungroup")} — ${getShortcutKey("CtrlOrCmd+Shift+G")}`} | ||||
|       aria-label={t("labels.ungroup")} | ||||
|   | ||||
| @@ -1,14 +1,15 @@ | ||||
| import { Action, ActionResult } from "./types"; | ||||
| import React from "react"; | ||||
| import { undo, redo } from "../components/icons"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { t } from "../i18n"; | ||||
| import History, { HistoryEntry } from "../history"; | ||||
| import { SceneHistory, HistoryEntry } from "../history"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { AppState } from "../types"; | ||||
| import { isWindows, KEYS } from "../keys"; | ||||
| import { getElementMap } from "../element"; | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| import { fixBindingsAfterDeletion } from "../element/binding"; | ||||
| import { arrayToMap } from "../utils"; | ||||
|  | ||||
| const writeData = ( | ||||
|   prevElements: readonly ExcalidrawElement[], | ||||
| @@ -27,17 +28,17 @@ const writeData = ( | ||||
|       return { commitToHistory }; | ||||
|     } | ||||
|  | ||||
|     const prevElementMap = arrayToMap(prevElements); | ||||
|     const prevElementMap = getElementMap(prevElements); | ||||
|     const nextElements = data.elements; | ||||
|     const nextElementMap = arrayToMap(nextElements); | ||||
|     const nextElementMap = getElementMap(nextElements); | ||||
|  | ||||
|     const deletedElements = prevElements.filter( | ||||
|       (prevElement) => !nextElementMap.has(prevElement.id), | ||||
|       (prevElement) => !nextElementMap.hasOwnProperty(prevElement.id), | ||||
|     ); | ||||
|     const elements = nextElements | ||||
|       .map((nextElement) => | ||||
|         newElementWith( | ||||
|           prevElementMap.get(nextElement.id) || nextElement, | ||||
|           prevElementMap[nextElement.id] || nextElement, | ||||
|           nextElement, | ||||
|         ), | ||||
|       ) | ||||
| @@ -58,24 +59,22 @@ const writeData = ( | ||||
|   return { commitToHistory }; | ||||
| }; | ||||
|  | ||||
| type ActionCreator = (history: History) => Action; | ||||
| type ActionCreator = (history: SceneHistory) => Action; | ||||
|  | ||||
| export const createUndoAction: ActionCreator = (history) => ({ | ||||
|   name: "undo", | ||||
|   trackEvent: { category: "history" }, | ||||
|   perform: (elements, appState) => | ||||
|     writeData(elements, appState, () => history.undoOnce()), | ||||
|   keyTest: (event) => | ||||
|     event[KEYS.CTRL_OR_CMD] && | ||||
|     event.key.toLowerCase() === KEYS.Z && | ||||
|     !event.shiftKey, | ||||
|   PanelComponent: ({ updateData, data }) => ( | ||||
|   PanelComponent: ({ updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={undo} | ||||
|       aria-label={t("buttons.undo")} | ||||
|       onClick={updateData} | ||||
|       size={data?.size || "medium"} | ||||
|     /> | ||||
|   ), | ||||
|   commitToHistory: () => false, | ||||
| @@ -83,7 +82,6 @@ export const createUndoAction: ActionCreator = (history) => ({ | ||||
|  | ||||
| export const createRedoAction: ActionCreator = (history) => ({ | ||||
|   name: "redo", | ||||
|   trackEvent: { category: "history" }, | ||||
|   perform: (elements, appState) => | ||||
|     writeData(elements, appState, () => history.redoOnce()), | ||||
|   keyTest: (event) => | ||||
| @@ -91,13 +89,12 @@ export const createRedoAction: ActionCreator = (history) => ({ | ||||
|       event.shiftKey && | ||||
|       event.key.toLowerCase() === KEYS.Z) || | ||||
|     (isWindows && event.ctrlKey && !event.shiftKey && event.key === KEYS.Y), | ||||
|   PanelComponent: ({ updateData, data }) => ( | ||||
|   PanelComponent: ({ updateData }) => ( | ||||
|     <ToolButton | ||||
|       type="button" | ||||
|       icon={redo} | ||||
|       aria-label={t("buttons.redo")} | ||||
|       onClick={updateData} | ||||
|       size={data?.size || "medium"} | ||||
|     /> | ||||
|   ), | ||||
|   commitToHistory: () => false, | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import { menu, palette } from "../components/icons"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { t } from "../i18n"; | ||||
| @@ -9,7 +10,6 @@ import { HelpIcon } from "../components/HelpIcon"; | ||||
|  | ||||
| export const actionToggleCanvasMenu = register({ | ||||
|   name: "toggleCanvasMenu", | ||||
|   trackEvent: { category: "menu" }, | ||||
|   perform: (_, appState) => ({ | ||||
|     appState: { | ||||
|       ...appState, | ||||
| @@ -30,7 +30,6 @@ export const actionToggleCanvasMenu = register({ | ||||
|  | ||||
| export const actionToggleEditMenu = register({ | ||||
|   name: "toggleEditMenu", | ||||
|   trackEvent: { category: "menu" }, | ||||
|   perform: (_elements, appState) => ({ | ||||
|     appState: { | ||||
|       ...appState, | ||||
| @@ -55,7 +54,6 @@ export const actionToggleEditMenu = register({ | ||||
|  | ||||
| export const actionFullScreen = register({ | ||||
|   name: "toggleFullScreen", | ||||
|   trackEvent: { category: "canvas", predicate: (appState) => !isFullScreen() }, | ||||
|   perform: () => { | ||||
|     if (!isFullScreen()) { | ||||
|       allowFullScreen(); | ||||
| @@ -72,11 +70,7 @@ export const actionFullScreen = register({ | ||||
|  | ||||
| export const actionShortcuts = register({ | ||||
|   name: "toggleShortcuts", | ||||
|   trackEvent: { category: "menu", action: "toggleHelpDialog" }, | ||||
|   perform: (_elements, appState, _, { focusContainer }) => { | ||||
|     if (appState.showHelpDialog) { | ||||
|       focusContainer(); | ||||
|     } | ||||
|   perform: (_elements, appState) => { | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| import { getClientColors } from "../clients"; | ||||
| import React from "react"; | ||||
| import { getClientColors, getClientInitials } from "../clients"; | ||||
| import { Avatar } from "../components/Avatar"; | ||||
| import { centerScrollOn } from "../scene/scroll"; | ||||
| import { Collaborator } from "../types"; | ||||
| @@ -6,7 +7,6 @@ import { register } from "./register"; | ||||
|  | ||||
| export const actionGoToCollaborator = register({ | ||||
|   name: "goToCollaborator", | ||||
|   trackEvent: { category: "collab" }, | ||||
|   perform: (_elements, appState, value) => { | ||||
|     const point = value as Collaborator["pointer"]; | ||||
|     if (!point) { | ||||
| @@ -30,8 +30,8 @@ export const actionGoToCollaborator = register({ | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ appState, updateData, data }) => { | ||||
|     const clientId: string | undefined = data?.id; | ||||
|   PanelComponent: ({ appState, updateData, id }) => { | ||||
|     const clientId = id; | ||||
|     if (!clientId) { | ||||
|       return null; | ||||
|     } | ||||
| @@ -43,15 +43,16 @@ export const actionGoToCollaborator = register({ | ||||
|     } | ||||
|  | ||||
|     const { background, stroke } = getClientColors(clientId, appState); | ||||
|     const shortName = getClientInitials(collaborator.username); | ||||
|  | ||||
|     return ( | ||||
|       <Avatar | ||||
|         color={background} | ||||
|         border={stroke} | ||||
|         onClick={() => updateData(collaborator.pointer)} | ||||
|         name={collaborator.username || ""} | ||||
|         src={collaborator.src} | ||||
|       /> | ||||
|       > | ||||
|         {shortName} | ||||
|       </Avatar> | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
|   | ||||
| @@ -1,25 +1,19 @@ | ||||
| import React from "react"; | ||||
| import { AppState } from "../../src/types"; | ||||
| import { ButtonIconSelect } from "../components/ButtonIconSelect"; | ||||
| import { ButtonSelect } from "../components/ButtonSelect"; | ||||
| import { ColorPicker } from "../components/ColorPicker"; | ||||
| import { IconPicker } from "../components/IconPicker"; | ||||
| import { | ||||
|   ArrowheadArrowIcon, | ||||
|   ArrowheadBarIcon, | ||||
|   ArrowheadDotIcon, | ||||
|   ArrowheadTriangleIcon, | ||||
|   ArrowheadNoneIcon, | ||||
|   EdgeRoundIcon, | ||||
|   EdgeSharpIcon, | ||||
|   FillCrossHatchIcon, | ||||
|   FillHachureIcon, | ||||
|   FillSolidIcon, | ||||
|   FontFamilyCodeIcon, | ||||
|   FontFamilyHandDrawnIcon, | ||||
|   FontFamilyNormalIcon, | ||||
|   FontSizeExtraLargeIcon, | ||||
|   FontSizeLargeIcon, | ||||
|   FontSizeMediumIcon, | ||||
|   FontSizeSmallIcon, | ||||
|   SloppinessArchitectIcon, | ||||
|   SloppinessArtistIcon, | ||||
|   SloppinessCartoonistIcon, | ||||
| @@ -27,72 +21,42 @@ import { | ||||
|   StrokeStyleDottedIcon, | ||||
|   StrokeStyleSolidIcon, | ||||
|   StrokeWidthIcon, | ||||
|   TextAlignCenterIcon, | ||||
|   TextAlignLeftIcon, | ||||
|   TextAlignRightIcon, | ||||
|   TextAlignTopIcon, | ||||
|   TextAlignBottomIcon, | ||||
|   TextAlignMiddleIcon, | ||||
| } from "../components/icons"; | ||||
| import { | ||||
|   DEFAULT_FONT_FAMILY, | ||||
|   DEFAULT_FONT_SIZE, | ||||
|   FONT_FAMILY, | ||||
|   VERTICAL_ALIGN, | ||||
| } from "../constants"; | ||||
| import { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from "../constants"; | ||||
| import { | ||||
|   getNonDeletedElements, | ||||
|   isTextElement, | ||||
|   redrawTextBoundingBox, | ||||
| } from "../element"; | ||||
| import { mutateElement, newElementWith } from "../element/mutateElement"; | ||||
| import { | ||||
|   getBoundTextElement, | ||||
|   getContainerElement, | ||||
| } from "../element/textElement"; | ||||
| import { | ||||
|   isBoundToContainer, | ||||
|   isLinearElement, | ||||
|   isLinearElementType, | ||||
| } from "../element/typeChecks"; | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| import { isLinearElement, isLinearElementType } from "../element/typeChecks"; | ||||
| import { | ||||
|   Arrowhead, | ||||
|   ExcalidrawElement, | ||||
|   ExcalidrawLinearElement, | ||||
|   ExcalidrawTextElement, | ||||
|   FontFamilyValues, | ||||
|   FontFamily, | ||||
|   TextAlign, | ||||
|   VerticalAlign, | ||||
| } from "../element/types"; | ||||
| import { getLanguage, t } from "../i18n"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { randomInteger } from "../random"; | ||||
| import { | ||||
|   canChangeSharpness, | ||||
|   canHaveArrowheads, | ||||
|   getCommonAttributeOfSelectedElements, | ||||
|   getSelectedElements, | ||||
|   getTargetElements, | ||||
|   isSomeElementSelected, | ||||
| } from "../scene"; | ||||
| import { hasStrokeColor } from "../scene/comparisons"; | ||||
| import { arrayToMap } from "../utils"; | ||||
| import { register } from "./register"; | ||||
|  | ||||
| const FONT_SIZE_RELATIVE_INCREASE_STEP = 0.1; | ||||
|  | ||||
| const changeProperty = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: AppState, | ||||
|   callback: (element: ExcalidrawElement) => ExcalidrawElement, | ||||
|   includeBoundText = false, | ||||
| ) => { | ||||
|   const selectedElementIds = arrayToMap( | ||||
|     getSelectedElements(elements, appState, includeBoundText), | ||||
|   ); | ||||
|   return elements.map((element) => { | ||||
|     if ( | ||||
|       selectedElementIds.get(element.id) || | ||||
|       appState.selectedElementIds[element.id] || | ||||
|       element.id === appState.editingElement?.id | ||||
|     ) { | ||||
|       return callback(element); | ||||
| @@ -122,100 +86,17 @@ const getFormValue = function <T>( | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const offsetElementAfterFontResize = ( | ||||
|   prevElement: ExcalidrawTextElement, | ||||
|   nextElement: ExcalidrawTextElement, | ||||
| ) => { | ||||
|   if (isBoundToContainer(nextElement)) { | ||||
|     return nextElement; | ||||
|   } | ||||
|   return mutateElement( | ||||
|     nextElement, | ||||
|     { | ||||
|       x: | ||||
|         prevElement.textAlign === "left" | ||||
|           ? prevElement.x | ||||
|           : prevElement.x + | ||||
|             (prevElement.width - nextElement.width) / | ||||
|               (prevElement.textAlign === "center" ? 2 : 1), | ||||
|       // centering vertically is non-standard, but for Excalidraw I think | ||||
|       // it makes sense | ||||
|       y: prevElement.y + (prevElement.height - nextElement.height) / 2, | ||||
|     }, | ||||
|     false, | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const changeFontSize = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: AppState, | ||||
|   getNewFontSize: (element: ExcalidrawTextElement) => number, | ||||
|   fallbackValue?: ExcalidrawTextElement["fontSize"], | ||||
| ) => { | ||||
|   const newFontSizes = new Set<number>(); | ||||
|  | ||||
|   return { | ||||
|     elements: changeProperty( | ||||
|       elements, | ||||
|       appState, | ||||
|       (oldElement) => { | ||||
|         if (isTextElement(oldElement)) { | ||||
|           const newFontSize = getNewFontSize(oldElement); | ||||
|           newFontSizes.add(newFontSize); | ||||
|  | ||||
|           let newElement: ExcalidrawTextElement = newElementWith(oldElement, { | ||||
|             fontSize: newFontSize, | ||||
|           }); | ||||
|           redrawTextBoundingBox(newElement, getContainerElement(oldElement)); | ||||
|  | ||||
|           newElement = offsetElementAfterFontResize(oldElement, newElement); | ||||
|  | ||||
|           return newElement; | ||||
|         } | ||||
|  | ||||
|         return oldElement; | ||||
|       }, | ||||
|       true, | ||||
|     ), | ||||
|     appState: { | ||||
|       ...appState, | ||||
|       // update state only if we've set all select text elements to | ||||
|       // the same font size | ||||
|       currentItemFontSize: | ||||
|         newFontSizes.size === 1 | ||||
|           ? [...newFontSizes][0] | ||||
|           : fallbackValue ?? appState.currentItemFontSize, | ||||
|     }, | ||||
|     commitToHistory: true, | ||||
|   }; | ||||
| }; | ||||
|  | ||||
| // ----------------------------------------------------------------------------- | ||||
|  | ||||
| export const actionChangeStrokeColor = register({ | ||||
|   name: "changeStrokeColor", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       ...(value.currentItemStrokeColor && { | ||||
|         elements: changeProperty( | ||||
|           elements, | ||||
|           appState, | ||||
|           (el) => { | ||||
|             return hasStrokeColor(el.type) | ||||
|               ? newElementWith(el, { | ||||
|                   strokeColor: value.currentItemStrokeColor, | ||||
|                 }) | ||||
|               : el; | ||||
|           }, | ||||
|           true, | ||||
|         ), | ||||
|       }), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         ...value, | ||||
|       }, | ||||
|       commitToHistory: !!value.currentItemStrokeColor, | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
|         newElementWith(el, { | ||||
|           strokeColor: value, | ||||
|         }), | ||||
|       ), | ||||
|       appState: { ...appState, currentItemStrokeColor: value }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
| @@ -230,13 +111,7 @@ export const actionChangeStrokeColor = register({ | ||||
|           (element) => element.strokeColor, | ||||
|           appState.currentItemStrokeColor, | ||||
|         )} | ||||
|         onChange={(color) => updateData({ currentItemStrokeColor: color })} | ||||
|         isActive={appState.openPopup === "strokeColorPicker"} | ||||
|         setActive={(active) => | ||||
|           updateData({ openPopup: active ? "strokeColorPicker" : null }) | ||||
|         } | ||||
|         elements={elements} | ||||
|         appState={appState} | ||||
|         onChange={updateData} | ||||
|       /> | ||||
|     </> | ||||
|   ), | ||||
| @@ -244,21 +119,15 @@ export const actionChangeStrokeColor = register({ | ||||
|  | ||||
| export const actionChangeBackgroundColor = register({ | ||||
|   name: "changeBackgroundColor", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       ...(value.currentItemBackgroundColor && { | ||||
|         elements: changeProperty(elements, appState, (el) => | ||||
|           newElementWith(el, { | ||||
|             backgroundColor: value.currentItemBackgroundColor, | ||||
|           }), | ||||
|         ), | ||||
|       }), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         ...value, | ||||
|       }, | ||||
|       commitToHistory: !!value.currentItemBackgroundColor, | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
|         newElementWith(el, { | ||||
|           backgroundColor: value, | ||||
|         }), | ||||
|       ), | ||||
|       appState: { ...appState, currentItemBackgroundColor: value }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
| @@ -273,13 +142,7 @@ export const actionChangeBackgroundColor = register({ | ||||
|           (element) => element.backgroundColor, | ||||
|           appState.currentItemBackgroundColor, | ||||
|         )} | ||||
|         onChange={(color) => updateData({ currentItemBackgroundColor: color })} | ||||
|         isActive={appState.openPopup === "backgroundColorPicker"} | ||||
|         setActive={(active) => | ||||
|           updateData({ openPopup: active ? "backgroundColorPicker" : null }) | ||||
|         } | ||||
|         elements={elements} | ||||
|         appState={appState} | ||||
|         onChange={updateData} | ||||
|       /> | ||||
|     </> | ||||
|   ), | ||||
| @@ -287,7 +150,6 @@ export const actionChangeBackgroundColor = register({ | ||||
|  | ||||
| export const actionChangeFillStyle = register({ | ||||
|   name: "changeFillStyle", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
| @@ -307,17 +169,17 @@ export const actionChangeFillStyle = register({ | ||||
|           { | ||||
|             value: "hachure", | ||||
|             text: t("labels.hachure"), | ||||
|             icon: <FillHachureIcon theme={appState.theme} />, | ||||
|             icon: <FillHachureIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: "cross-hatch", | ||||
|             text: t("labels.crossHatch"), | ||||
|             icon: <FillCrossHatchIcon theme={appState.theme} />, | ||||
|             icon: <FillCrossHatchIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: "solid", | ||||
|             text: t("labels.solid"), | ||||
|             icon: <FillSolidIcon theme={appState.theme} />, | ||||
|             icon: <FillSolidIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|         ]} | ||||
|         group="fill" | ||||
| @@ -337,7 +199,6 @@ export const actionChangeFillStyle = register({ | ||||
|  | ||||
| export const actionChangeStrokeWidth = register({ | ||||
|   name: "changeStrokeWidth", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
| @@ -358,17 +219,32 @@ export const actionChangeStrokeWidth = register({ | ||||
|           { | ||||
|             value: 1, | ||||
|             text: t("labels.thin"), | ||||
|             icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={2} />, | ||||
|             icon: ( | ||||
|               <StrokeWidthIcon | ||||
|                 appearance={appState.appearance} | ||||
|                 strokeWidth={2} | ||||
|               /> | ||||
|             ), | ||||
|           }, | ||||
|           { | ||||
|             value: 2, | ||||
|             text: t("labels.bold"), | ||||
|             icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={6} />, | ||||
|             icon: ( | ||||
|               <StrokeWidthIcon | ||||
|                 appearance={appState.appearance} | ||||
|                 strokeWidth={6} | ||||
|               /> | ||||
|             ), | ||||
|           }, | ||||
|           { | ||||
|             value: 4, | ||||
|             text: t("labels.extraBold"), | ||||
|             icon: <StrokeWidthIcon theme={appState.theme} strokeWidth={10} />, | ||||
|             icon: ( | ||||
|               <StrokeWidthIcon | ||||
|                 appearance={appState.appearance} | ||||
|                 strokeWidth={10} | ||||
|               /> | ||||
|             ), | ||||
|           }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
| @@ -385,7 +261,6 @@ export const actionChangeStrokeWidth = register({ | ||||
|  | ||||
| export const actionChangeSloppiness = register({ | ||||
|   name: "changeSloppiness", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
| @@ -407,17 +282,17 @@ export const actionChangeSloppiness = register({ | ||||
|           { | ||||
|             value: 0, | ||||
|             text: t("labels.architect"), | ||||
|             icon: <SloppinessArchitectIcon theme={appState.theme} />, | ||||
|             icon: <SloppinessArchitectIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: 1, | ||||
|             text: t("labels.artist"), | ||||
|             icon: <SloppinessArtistIcon theme={appState.theme} />, | ||||
|             icon: <SloppinessArtistIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: 2, | ||||
|             text: t("labels.cartoonist"), | ||||
|             icon: <SloppinessCartoonistIcon theme={appState.theme} />, | ||||
|             icon: <SloppinessCartoonistIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
| @@ -434,7 +309,6 @@ export const actionChangeSloppiness = register({ | ||||
|  | ||||
| export const actionChangeStrokeStyle = register({ | ||||
|   name: "changeStrokeStyle", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
| @@ -455,17 +329,17 @@ export const actionChangeStrokeStyle = register({ | ||||
|           { | ||||
|             value: "solid", | ||||
|             text: t("labels.strokeStyle_solid"), | ||||
|             icon: <StrokeStyleSolidIcon theme={appState.theme} />, | ||||
|             icon: <StrokeStyleSolidIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: "dashed", | ||||
|             text: t("labels.strokeStyle_dashed"), | ||||
|             icon: <StrokeStyleDashedIcon theme={appState.theme} />, | ||||
|             icon: <StrokeStyleDashedIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: "dotted", | ||||
|             text: t("labels.strokeStyle_dotted"), | ||||
|             icon: <StrokeStyleDottedIcon theme={appState.theme} />, | ||||
|             icon: <StrokeStyleDottedIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
| @@ -482,7 +356,6 @@ export const actionChangeStrokeStyle = register({ | ||||
|  | ||||
| export const actionChangeOpacity = register({ | ||||
|   name: "changeOpacity", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
| @@ -503,6 +376,20 @@ export const actionChangeOpacity = register({ | ||||
|         max="100" | ||||
|         step="10" | ||||
|         onChange={(event) => updateData(+event.target.value)} | ||||
|         onWheel={(event) => { | ||||
|           event.stopPropagation(); | ||||
|           const target = event.target as HTMLInputElement; | ||||
|           const STEP = 10; | ||||
|           const MAX = 100; | ||||
|           const MIN = 0; | ||||
|           const value = +target.value; | ||||
|  | ||||
|           if (event.deltaY < 0 && value < MAX) { | ||||
|             updateData(value + STEP); | ||||
|           } else if (event.deltaY > 0 && value > MIN) { | ||||
|             updateData(value - STEP); | ||||
|           } | ||||
|         }} | ||||
|         value={ | ||||
|           getFormValue( | ||||
|             elements, | ||||
| @@ -518,54 +405,41 @@ export const actionChangeOpacity = register({ | ||||
|  | ||||
| export const actionChangeFontSize = register({ | ||||
|   name: "changeFontSize", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return changeFontSize(elements, appState, () => value, value); | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => { | ||||
|         if (isTextElement(el)) { | ||||
|           const element: ExcalidrawTextElement = newElementWith(el, { | ||||
|             fontSize: value, | ||||
|           }); | ||||
|           redrawTextBoundingBox(element); | ||||
|           return element; | ||||
|         } | ||||
|  | ||||
|         return el; | ||||
|       }), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         currentItemFontSize: value, | ||||
|       }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
|     <fieldset> | ||||
|       <legend>{t("labels.fontSize")}</legend> | ||||
|       <ButtonIconSelect | ||||
|       <ButtonSelect | ||||
|         group="font-size" | ||||
|         options={[ | ||||
|           { | ||||
|             value: 16, | ||||
|             text: t("labels.small"), | ||||
|             icon: <FontSizeSmallIcon theme={appState.theme} />, | ||||
|             testId: "fontSize-small", | ||||
|           }, | ||||
|           { | ||||
|             value: 20, | ||||
|             text: t("labels.medium"), | ||||
|             icon: <FontSizeMediumIcon theme={appState.theme} />, | ||||
|             testId: "fontSize-medium", | ||||
|           }, | ||||
|           { | ||||
|             value: 28, | ||||
|             text: t("labels.large"), | ||||
|             icon: <FontSizeLargeIcon theme={appState.theme} />, | ||||
|             testId: "fontSize-large", | ||||
|           }, | ||||
|           { | ||||
|             value: 36, | ||||
|             text: t("labels.veryLarge"), | ||||
|             icon: <FontSizeExtraLargeIcon theme={appState.theme} />, | ||||
|             testId: "fontSize-veryLarge", | ||||
|           }, | ||||
|           { value: 16, text: t("labels.small") }, | ||||
|           { value: 20, text: t("labels.medium") }, | ||||
|           { value: 28, text: t("labels.large") }, | ||||
|           { value: 36, text: t("labels.veryLarge") }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
|           elements, | ||||
|           appState, | ||||
|           (element) => { | ||||
|             if (isTextElement(element)) { | ||||
|               return element.fontSize; | ||||
|             } | ||||
|             const boundTextElement = getBoundTextElement(element); | ||||
|             if (boundTextElement) { | ||||
|               return boundTextElement.fontSize; | ||||
|             } | ||||
|             return null; | ||||
|           }, | ||||
|           (element) => isTextElement(element) && element.fontSize, | ||||
|           appState.currentItemFontSize || DEFAULT_FONT_SIZE, | ||||
|         )} | ||||
|         onChange={(value) => updateData(value)} | ||||
| @@ -574,70 +448,21 @@ export const actionChangeFontSize = register({ | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionDecreaseFontSize = register({ | ||||
|   name: "decreaseFontSize", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return changeFontSize(elements, appState, (element) => | ||||
|       Math.round( | ||||
|         // get previous value before relative increase (doesn't work fully | ||||
|         // due to rounding and float precision issues) | ||||
|         (1 / (1 + FONT_SIZE_RELATIVE_INCREASE_STEP)) * element.fontSize, | ||||
|       ), | ||||
|     ); | ||||
|   }, | ||||
|   keyTest: (event) => { | ||||
|     return ( | ||||
|       event[KEYS.CTRL_OR_CMD] && | ||||
|       event.shiftKey && | ||||
|       // KEYS.COMMA needed for MacOS | ||||
|       (event.key === KEYS.CHEVRON_LEFT || event.key === KEYS.COMMA) | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const actionIncreaseFontSize = register({ | ||||
|   name: "increaseFontSize", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return changeFontSize(elements, appState, (element) => | ||||
|       Math.round(element.fontSize * (1 + FONT_SIZE_RELATIVE_INCREASE_STEP)), | ||||
|     ); | ||||
|   }, | ||||
|   keyTest: (event) => { | ||||
|     return ( | ||||
|       event[KEYS.CTRL_OR_CMD] && | ||||
|       event.shiftKey && | ||||
|       // KEYS.PERIOD needed for MacOS | ||||
|       (event.key === KEYS.CHEVRON_RIGHT || event.key === KEYS.PERIOD) | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| export const actionChangeFontFamily = register({ | ||||
|   name: "changeFontFamily", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty( | ||||
|         elements, | ||||
|         appState, | ||||
|         (oldElement) => { | ||||
|           if (isTextElement(oldElement)) { | ||||
|             const newElement: ExcalidrawTextElement = newElementWith( | ||||
|               oldElement, | ||||
|               { | ||||
|                 fontFamily: value, | ||||
|               }, | ||||
|             ); | ||||
|             redrawTextBoundingBox(newElement, getContainerElement(oldElement)); | ||||
|             return newElement; | ||||
|           } | ||||
|       elements: changeProperty(elements, appState, (el) => { | ||||
|         if (isTextElement(el)) { | ||||
|           const element: ExcalidrawTextElement = newElementWith(el, { | ||||
|             fontFamily: value, | ||||
|           }); | ||||
|           redrawTextBoundingBox(element); | ||||
|           return element; | ||||
|         } | ||||
|  | ||||
|           return oldElement; | ||||
|         }, | ||||
|         true, | ||||
|       ), | ||||
|         return el; | ||||
|       }), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         currentItemFontFamily: value, | ||||
| @@ -646,47 +471,22 @@ export const actionChangeFontFamily = register({ | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => { | ||||
|     const options: { | ||||
|       value: FontFamilyValues; | ||||
|       text: string; | ||||
|       icon: JSX.Element; | ||||
|     }[] = [ | ||||
|       { | ||||
|         value: FONT_FAMILY.Virgil, | ||||
|         text: t("labels.handDrawn"), | ||||
|         icon: <FontFamilyHandDrawnIcon theme={appState.theme} />, | ||||
|       }, | ||||
|       { | ||||
|         value: FONT_FAMILY.Helvetica, | ||||
|         text: t("labels.normal"), | ||||
|         icon: <FontFamilyNormalIcon theme={appState.theme} />, | ||||
|       }, | ||||
|       { | ||||
|         value: FONT_FAMILY.Cascadia, | ||||
|         text: t("labels.code"), | ||||
|         icon: <FontFamilyCodeIcon theme={appState.theme} />, | ||||
|       }, | ||||
|     const options: { value: FontFamily; text: string }[] = [ | ||||
|       { value: 1, text: t("labels.handDrawn") }, | ||||
|       { value: 2, text: t("labels.normal") }, | ||||
|       { value: 3, text: t("labels.code") }, | ||||
|     ]; | ||||
|  | ||||
|     return ( | ||||
|       <fieldset> | ||||
|         <legend>{t("labels.fontFamily")}</legend> | ||||
|         <ButtonIconSelect<FontFamilyValues | false> | ||||
|         <ButtonSelect<FontFamily | false> | ||||
|           group="font-family" | ||||
|           options={options} | ||||
|           value={getFormValue( | ||||
|             elements, | ||||
|             appState, | ||||
|             (element) => { | ||||
|               if (isTextElement(element)) { | ||||
|                 return element.fontFamily; | ||||
|               } | ||||
|               const boundTextElement = getBoundTextElement(element); | ||||
|               if (boundTextElement) { | ||||
|                 return boundTextElement.fontFamily; | ||||
|               } | ||||
|               return null; | ||||
|             }, | ||||
|             (element) => isTextElement(element) && element.fontFamily, | ||||
|             appState.currentItemFontFamily || DEFAULT_FONT_FAMILY, | ||||
|           )} | ||||
|           onChange={(value) => updateData(value)} | ||||
| @@ -698,26 +498,19 @@ export const actionChangeFontFamily = register({ | ||||
|  | ||||
| export const actionChangeTextAlign = register({ | ||||
|   name: "changeTextAlign", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty( | ||||
|         elements, | ||||
|         appState, | ||||
|         (oldElement) => { | ||||
|           if (isTextElement(oldElement)) { | ||||
|             const newElement: ExcalidrawTextElement = newElementWith( | ||||
|               oldElement, | ||||
|               { textAlign: value }, | ||||
|             ); | ||||
|             redrawTextBoundingBox(newElement, getContainerElement(oldElement)); | ||||
|             return newElement; | ||||
|           } | ||||
|       elements: changeProperty(elements, appState, (el) => { | ||||
|         if (isTextElement(el)) { | ||||
|           const element: ExcalidrawTextElement = newElementWith(el, { | ||||
|             textAlign: value, | ||||
|           }); | ||||
|           redrawTextBoundingBox(element); | ||||
|           return element; | ||||
|         } | ||||
|  | ||||
|           return oldElement; | ||||
|         }, | ||||
|         true, | ||||
|       ), | ||||
|         return el; | ||||
|       }), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         currentItemTextAlign: value, | ||||
| @@ -725,121 +518,30 @@ export const actionChangeTextAlign = register({ | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => { | ||||
|     return ( | ||||
|       <fieldset> | ||||
|         <legend>{t("labels.textAlign")}</legend> | ||||
|         <ButtonIconSelect<TextAlign | false> | ||||
|           group="text-align" | ||||
|           options={[ | ||||
|             { | ||||
|               value: "left", | ||||
|               text: t("labels.left"), | ||||
|               icon: <TextAlignLeftIcon theme={appState.theme} />, | ||||
|             }, | ||||
|             { | ||||
|               value: "center", | ||||
|               text: t("labels.center"), | ||||
|               icon: <TextAlignCenterIcon theme={appState.theme} />, | ||||
|             }, | ||||
|             { | ||||
|               value: "right", | ||||
|               text: t("labels.right"), | ||||
|               icon: <TextAlignRightIcon theme={appState.theme} />, | ||||
|             }, | ||||
|           ]} | ||||
|           value={getFormValue( | ||||
|             elements, | ||||
|             appState, | ||||
|             (element) => { | ||||
|               if (isTextElement(element)) { | ||||
|                 return element.textAlign; | ||||
|               } | ||||
|               const boundTextElement = getBoundTextElement(element); | ||||
|               if (boundTextElement) { | ||||
|                 return boundTextElement.textAlign; | ||||
|               } | ||||
|               return null; | ||||
|             }, | ||||
|             appState.currentItemTextAlign, | ||||
|           )} | ||||
|           onChange={(value) => updateData(value)} | ||||
|         /> | ||||
|       </fieldset> | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
| export const actionChangeVerticalAlign = register({ | ||||
|   name: "changeVerticalAlign", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState, value) => { | ||||
|     return { | ||||
|       elements: changeProperty( | ||||
|         elements, | ||||
|         appState, | ||||
|         (oldElement) => { | ||||
|           if (isTextElement(oldElement)) { | ||||
|             const newElement: ExcalidrawTextElement = newElementWith( | ||||
|               oldElement, | ||||
|               { verticalAlign: value }, | ||||
|             ); | ||||
|  | ||||
|             redrawTextBoundingBox(newElement, getContainerElement(oldElement)); | ||||
|             return newElement; | ||||
|           } | ||||
|  | ||||
|           return oldElement; | ||||
|         }, | ||||
|         true, | ||||
|       ), | ||||
|       appState: { | ||||
|         ...appState, | ||||
|       }, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => { | ||||
|     return ( | ||||
|       <fieldset> | ||||
|         <ButtonIconSelect<VerticalAlign | false> | ||||
|           group="text-align" | ||||
|           options={[ | ||||
|             { | ||||
|               value: VERTICAL_ALIGN.TOP, | ||||
|               text: t("labels.alignTop"), | ||||
|               icon: <TextAlignTopIcon theme={appState.theme} />, | ||||
|             }, | ||||
|             { | ||||
|               value: VERTICAL_ALIGN.MIDDLE, | ||||
|               text: t("labels.centerVertically"), | ||||
|               icon: <TextAlignMiddleIcon theme={appState.theme} />, | ||||
|             }, | ||||
|             { | ||||
|               value: VERTICAL_ALIGN.BOTTOM, | ||||
|               text: t("labels.alignBottom"), | ||||
|               icon: <TextAlignBottomIcon theme={appState.theme} />, | ||||
|             }, | ||||
|           ]} | ||||
|           value={getFormValue(elements, appState, (element) => { | ||||
|             if (isTextElement(element) && element.containerId) { | ||||
|               return element.verticalAlign; | ||||
|             } | ||||
|             const boundTextElement = getBoundTextElement(element); | ||||
|             if (boundTextElement) { | ||||
|               return boundTextElement.verticalAlign; | ||||
|             } | ||||
|             return null; | ||||
|           })} | ||||
|           onChange={(value) => updateData(value)} | ||||
|         /> | ||||
|       </fieldset> | ||||
|     ); | ||||
|   }, | ||||
|   PanelComponent: ({ elements, appState, updateData }) => ( | ||||
|     <fieldset> | ||||
|       <legend>{t("labels.textAlign")}</legend> | ||||
|       <ButtonSelect<TextAlign | false> | ||||
|         group="text-align" | ||||
|         options={[ | ||||
|           { value: "left", text: t("labels.left") }, | ||||
|           { value: "center", text: t("labels.center") }, | ||||
|           { value: "right", text: t("labels.right") }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
|           elements, | ||||
|           appState, | ||||
|           (element) => isTextElement(element) && element.textAlign, | ||||
|           appState.currentItemTextAlign, | ||||
|         )} | ||||
|         onChange={(value) => updateData(value)} | ||||
|       /> | ||||
|     </fieldset> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionChangeSharpness = register({ | ||||
|   name: "changeSharpness", | ||||
|   trackEvent: false, | ||||
|   perform: (elements, appState, value) => { | ||||
|     const targetElements = getTargetElements( | ||||
|       getNonDeletedElements(elements), | ||||
| @@ -847,10 +549,10 @@ export const actionChangeSharpness = register({ | ||||
|     ); | ||||
|     const shouldUpdateForNonLinearElements = targetElements.length | ||||
|       ? targetElements.every((el) => !isLinearElement(el)) | ||||
|       : !isLinearElementType(appState.activeTool.type); | ||||
|       : !isLinearElementType(appState.elementType); | ||||
|     const shouldUpdateForLinearElements = targetElements.length | ||||
|       ? targetElements.every(isLinearElement) | ||||
|       : isLinearElementType(appState.activeTool.type); | ||||
|       : isLinearElementType(appState.elementType); | ||||
|     return { | ||||
|       elements: changeProperty(elements, appState, (el) => | ||||
|         newElementWith(el, { | ||||
| @@ -878,20 +580,20 @@ export const actionChangeSharpness = register({ | ||||
|           { | ||||
|             value: "sharp", | ||||
|             text: t("labels.sharp"), | ||||
|             icon: <EdgeSharpIcon theme={appState.theme} />, | ||||
|             icon: <EdgeSharpIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|           { | ||||
|             value: "round", | ||||
|             text: t("labels.round"), | ||||
|             icon: <EdgeRoundIcon theme={appState.theme} />, | ||||
|             icon: <EdgeRoundIcon appearance={appState.appearance} />, | ||||
|           }, | ||||
|         ]} | ||||
|         value={getFormValue( | ||||
|           elements, | ||||
|           appState, | ||||
|           (element) => element.strokeSharpness, | ||||
|           (canChangeSharpness(appState.activeTool.type) && | ||||
|             (isLinearElementType(appState.activeTool.type) | ||||
|           (canChangeSharpness(appState.elementType) && | ||||
|             (isLinearElementType(appState.elementType) | ||||
|               ? appState.currentItemLinearStrokeSharpness | ||||
|               : appState.currentItemStrokeSharpness)) || | ||||
|             null, | ||||
| @@ -904,7 +606,6 @@ export const actionChangeSharpness = register({ | ||||
|  | ||||
| export const actionChangeArrowhead = register({ | ||||
|   name: "changeArrowhead", | ||||
|   trackEvent: false, | ||||
|   perform: ( | ||||
|     elements, | ||||
|     appState, | ||||
| @@ -952,36 +653,41 @@ export const actionChangeArrowhead = register({ | ||||
|               { | ||||
|                 value: null, | ||||
|                 text: t("labels.arrowhead_none"), | ||||
|                 icon: <ArrowheadNoneIcon theme={appState.theme} />, | ||||
|                 icon: <ArrowheadNoneIcon appearance={appState.appearance} />, | ||||
|                 keyBinding: "q", | ||||
|               }, | ||||
|               { | ||||
|                 value: "arrow", | ||||
|                 text: t("labels.arrowhead_arrow"), | ||||
|                 icon: ( | ||||
|                   <ArrowheadArrowIcon theme={appState.theme} flip={!isRTL} /> | ||||
|                   <ArrowheadArrowIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={!isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|                 keyBinding: "w", | ||||
|               }, | ||||
|               { | ||||
|                 value: "bar", | ||||
|                 text: t("labels.arrowhead_bar"), | ||||
|                 icon: <ArrowheadBarIcon theme={appState.theme} flip={!isRTL} />, | ||||
|                 icon: ( | ||||
|                   <ArrowheadBarIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={!isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|                 keyBinding: "e", | ||||
|               }, | ||||
|               { | ||||
|                 value: "dot", | ||||
|                 text: t("labels.arrowhead_dot"), | ||||
|                 icon: <ArrowheadDotIcon theme={appState.theme} flip={!isRTL} />, | ||||
|                 keyBinding: "r", | ||||
|               }, | ||||
|               { | ||||
|                 value: "triangle", | ||||
|                 text: t("labels.arrowhead_triangle"), | ||||
|                 icon: ( | ||||
|                   <ArrowheadTriangleIcon theme={appState.theme} flip={!isRTL} /> | ||||
|                   <ArrowheadDotIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={!isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|                 keyBinding: "t", | ||||
|                 keyBinding: "r", | ||||
|               }, | ||||
|             ]} | ||||
|             value={getFormValue<Arrowhead | null>( | ||||
| @@ -1003,35 +709,40 @@ export const actionChangeArrowhead = register({ | ||||
|                 value: null, | ||||
|                 text: t("labels.arrowhead_none"), | ||||
|                 keyBinding: "q", | ||||
|                 icon: <ArrowheadNoneIcon theme={appState.theme} />, | ||||
|                 icon: <ArrowheadNoneIcon appearance={appState.appearance} />, | ||||
|               }, | ||||
|               { | ||||
|                 value: "arrow", | ||||
|                 text: t("labels.arrowhead_arrow"), | ||||
|                 keyBinding: "w", | ||||
|                 icon: ( | ||||
|                   <ArrowheadArrowIcon theme={appState.theme} flip={isRTL} /> | ||||
|                   <ArrowheadArrowIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|               }, | ||||
|               { | ||||
|                 value: "bar", | ||||
|                 text: t("labels.arrowhead_bar"), | ||||
|                 keyBinding: "e", | ||||
|                 icon: <ArrowheadBarIcon theme={appState.theme} flip={isRTL} />, | ||||
|                 icon: ( | ||||
|                   <ArrowheadBarIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|               }, | ||||
|               { | ||||
|                 value: "dot", | ||||
|                 text: t("labels.arrowhead_dot"), | ||||
|                 keyBinding: "r", | ||||
|                 icon: <ArrowheadDotIcon theme={appState.theme} flip={isRTL} />, | ||||
|               }, | ||||
|               { | ||||
|                 value: "triangle", | ||||
|                 text: t("labels.arrowhead_triangle"), | ||||
|                 icon: ( | ||||
|                   <ArrowheadTriangleIcon theme={appState.theme} flip={isRTL} /> | ||||
|                   <ArrowheadDotIcon | ||||
|                     appearance={appState.appearance} | ||||
|                     flip={isRTL} | ||||
|                   /> | ||||
|                 ), | ||||
|                 keyBinding: "t", | ||||
|               }, | ||||
|             ]} | ||||
|             value={getFormValue<Arrowhead | null>( | ||||
|   | ||||
| @@ -1,11 +1,10 @@ | ||||
| import { KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { selectGroupsForSelectedElements } from "../groups"; | ||||
| import { getNonDeletedElements, isTextElement } from "../element"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
|  | ||||
| export const actionSelectAll = register({ | ||||
|   name: "selectAll", | ||||
|   trackEvent: { category: "canvas" }, | ||||
|   perform: (elements, appState) => { | ||||
|     if (appState.editingLinearElement) { | ||||
|       return false; | ||||
| @@ -16,11 +15,7 @@ export const actionSelectAll = register({ | ||||
|           ...appState, | ||||
|           editingGroupId: null, | ||||
|           selectedElementIds: elements.reduce((map, element) => { | ||||
|             if ( | ||||
|               !element.isDeleted && | ||||
|               !(isTextElement(element) && element.containerId) && | ||||
|               element.locked === false | ||||
|             ) { | ||||
|             if (!element.isDeleted) { | ||||
|               map[element.id] = true; | ||||
|             } | ||||
|             return map; | ||||
|   | ||||
| @@ -1,71 +0,0 @@ | ||||
| import ExcalidrawApp from "../excalidraw-app"; | ||||
| import { t } from "../i18n"; | ||||
| import { CODES } from "../keys"; | ||||
| import { API } from "../tests/helpers/api"; | ||||
| import { Keyboard, Pointer, UI } from "../tests/helpers/ui"; | ||||
| import { fireEvent, render, screen } from "../tests/test-utils"; | ||||
| import { copiedStyles } from "./actionStyles"; | ||||
|  | ||||
| const { h } = window; | ||||
|  | ||||
| const mouse = new Pointer("mouse"); | ||||
|  | ||||
| describe("actionStyles", () => { | ||||
|   beforeEach(async () => { | ||||
|     await render(<ExcalidrawApp />); | ||||
|   }); | ||||
|   it("should copy & paste styles via keyboard", () => { | ||||
|     UI.clickTool("rectangle"); | ||||
|     mouse.down(10, 10); | ||||
|     mouse.up(20, 20); | ||||
|  | ||||
|     UI.clickTool("rectangle"); | ||||
|     mouse.down(10, 10); | ||||
|     mouse.up(20, 20); | ||||
|  | ||||
|     // Change some styles of second rectangle | ||||
|     UI.clickLabeledElement("Stroke"); | ||||
|     UI.clickLabeledElement(t("colors.c92a2a")); | ||||
|     UI.clickLabeledElement("Background"); | ||||
|     UI.clickLabeledElement(t("colors.e64980")); | ||||
|     // Fill style | ||||
|     fireEvent.click(screen.getByTitle("Cross-hatch")); | ||||
|     // Stroke width | ||||
|     fireEvent.click(screen.getByTitle("Bold")); | ||||
|     // Stroke style | ||||
|     fireEvent.click(screen.getByTitle("Dotted")); | ||||
|     // Roughness | ||||
|     fireEvent.click(screen.getByTitle("Cartoonist")); | ||||
|     // Opacity | ||||
|     fireEvent.change(screen.getByLabelText("Opacity"), { | ||||
|       target: { value: "60" }, | ||||
|     }); | ||||
|  | ||||
|     mouse.reset(); | ||||
|  | ||||
|     API.setSelectedElements([h.elements[1]]); | ||||
|  | ||||
|     Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => { | ||||
|       Keyboard.codeDown(CODES.C); | ||||
|     }); | ||||
|     const secondRect = JSON.parse(copiedStyles); | ||||
|     expect(secondRect.id).toBe(h.elements[1].id); | ||||
|  | ||||
|     mouse.reset(); | ||||
|     // Paste styles to first rectangle | ||||
|     API.setSelectedElements([h.elements[0]]); | ||||
|     Keyboard.withModifierKeys({ ctrl: true, alt: true }, () => { | ||||
|       Keyboard.codeDown(CODES.V); | ||||
|     }); | ||||
|  | ||||
|     const firstRect = API.getSelectedElement(); | ||||
|     expect(firstRect.id).toBe(h.elements[0].id); | ||||
|     expect(firstRect.strokeColor).toBe("#c92a2a"); | ||||
|     expect(firstRect.backgroundColor).toBe("#e64980"); | ||||
|     expect(firstRect.fillStyle).toBe("cross-hatch"); | ||||
|     expect(firstRect.strokeWidth).toBe(2); // Bold: 2 | ||||
|     expect(firstRect.strokeStyle).toBe("dotted"); | ||||
|     expect(firstRect.roughness).toBe(2); // Cartoonist: 2 | ||||
|     expect(firstRect.opacity).toBe(60); | ||||
|   }); | ||||
| }); | ||||
| @@ -12,14 +12,12 @@ import { | ||||
|   DEFAULT_FONT_FAMILY, | ||||
|   DEFAULT_TEXT_ALIGN, | ||||
| } from "../constants"; | ||||
| import { getContainerElement } from "../element/textElement"; | ||||
|  | ||||
| // `copiedStyles` is exported only for tests. | ||||
| export let copiedStyles: string = "{}"; | ||||
|  | ||||
| export const actionCopyStyles = register({ | ||||
|   name: "copyStyles", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const element = elements.find((el) => appState.selectedElementIds[el.id]); | ||||
|     if (element) { | ||||
| @@ -40,7 +38,6 @@ export const actionCopyStyles = register({ | ||||
|  | ||||
| export const actionPasteStyles = register({ | ||||
|   name: "pasteStyles", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const pastedElement = JSON.parse(copiedStyles); | ||||
|     if (!isExcalidrawElement(pastedElement)) { | ||||
| @@ -58,14 +55,13 @@ export const actionPasteStyles = register({ | ||||
|             opacity: pastedElement?.opacity, | ||||
|             roughness: pastedElement?.roughness, | ||||
|           }); | ||||
|           if (isTextElement(newElement) && isTextElement(element)) { | ||||
|           if (isTextElement(newElement)) { | ||||
|             mutateElement(newElement, { | ||||
|               fontSize: pastedElement?.fontSize || DEFAULT_FONT_SIZE, | ||||
|               fontFamily: pastedElement?.fontFamily || DEFAULT_FONT_FAMILY, | ||||
|               textAlign: pastedElement?.textAlign || DEFAULT_TEXT_ALIGN, | ||||
|             }); | ||||
|  | ||||
|             redrawTextBoundingBox(newElement, getContainerElement(newElement)); | ||||
|             redrawTextBoundingBox(newElement); | ||||
|           } | ||||
|           return newElement; | ||||
|         } | ||||
|   | ||||
| @@ -2,14 +2,12 @@ import { CODES, KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { GRID_SIZE } from "../constants"; | ||||
| import { AppState } from "../types"; | ||||
| import { trackEvent } from "../analytics"; | ||||
|  | ||||
| export const actionToggleGridMode = register({ | ||||
|   name: "gridMode", | ||||
|   trackEvent: { | ||||
|     category: "canvas", | ||||
|     predicate: (appState) => !appState.gridSize, | ||||
|   }, | ||||
|   perform(elements, appState) { | ||||
|     trackEvent("view", "mode", "grid"); | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|   | ||||
| @@ -1,63 +0,0 @@ | ||||
| import { newElementWith } from "../element/mutateElement"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { KEYS } from "../keys"; | ||||
| import { getSelectedElements } from "../scene"; | ||||
| import { arrayToMap } from "../utils"; | ||||
| import { register } from "./register"; | ||||
|  | ||||
| export const actionToggleLock = register({ | ||||
|   name: "toggleLock", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     const selectedElements = getSelectedElements(elements, appState, true); | ||||
|  | ||||
|     if (!selectedElements.length) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     const operation = getOperation(selectedElements); | ||||
|     const selectedElementsMap = arrayToMap(selectedElements); | ||||
|  | ||||
|     return { | ||||
|       elements: elements.map((element) => { | ||||
|         if (!selectedElementsMap.has(element.id)) { | ||||
|           return element; | ||||
|         } | ||||
|  | ||||
|         return newElementWith(element, { locked: operation === "lock" }); | ||||
|       }), | ||||
|       appState, | ||||
|       commitToHistory: true, | ||||
|     }; | ||||
|   }, | ||||
|   contextItemLabel: (elements, appState) => { | ||||
|     const selected = getSelectedElements(elements, appState, false); | ||||
|     if (selected.length === 1) { | ||||
|       return selected[0].locked | ||||
|         ? "labels.elementLock.unlock" | ||||
|         : "labels.elementLock.lock"; | ||||
|     } | ||||
|  | ||||
|     if (selected.length > 1) { | ||||
|       return getOperation(selected) === "lock" | ||||
|         ? "labels.elementLock.lockAll" | ||||
|         : "labels.elementLock.unlockAll"; | ||||
|     } | ||||
|  | ||||
|     throw new Error( | ||||
|       "Unexpected zero elements to lock/unlock. This should never happen.", | ||||
|     ); | ||||
|   }, | ||||
|   keyTest: (event, appState, elements) => { | ||||
|     return ( | ||||
|       event.key.toLocaleLowerCase() === KEYS.L && | ||||
|       event[KEYS.CTRL_OR_CMD] && | ||||
|       event.shiftKey && | ||||
|       getSelectedElements(elements, appState, false).length > 0 | ||||
|     ); | ||||
|   }, | ||||
| }); | ||||
|  | ||||
| const getOperation = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
| ): "lock" | "unlock" => (elements.some((el) => !el.locked) ? "lock" : "unlock"); | ||||
| @@ -1,9 +1,7 @@ | ||||
| import { register } from "./register"; | ||||
| import { CODES, KEYS } from "../keys"; | ||||
|  | ||||
| export const actionToggleStats = register({ | ||||
|   name: "stats", | ||||
|   trackEvent: { category: "menu" }, | ||||
|   perform(elements, appState) { | ||||
|     return { | ||||
|       appState: { | ||||
| @@ -15,6 +13,4 @@ export const actionToggleStats = register({ | ||||
|   }, | ||||
|   checked: (appState) => appState.showStats, | ||||
|   contextItemLabel: "stats.title", | ||||
|   keyTest: (event) => | ||||
|     !event[KEYS.CTRL_OR_CMD] && event.altKey && event.code === CODES.SLASH, | ||||
| }); | ||||
|   | ||||
| @@ -1,17 +1,16 @@ | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { trackEvent } from "../analytics"; | ||||
|  | ||||
| export const actionToggleViewMode = register({ | ||||
|   name: "viewMode", | ||||
|   trackEvent: { | ||||
|     category: "canvas", | ||||
|     predicate: (appState) => !appState.viewModeEnabled, | ||||
|   }, | ||||
|   perform(elements, appState) { | ||||
|     trackEvent("view", "mode", "view"); | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|         viewModeEnabled: !this.checked!(appState), | ||||
|         selectedElementIds: {}, | ||||
|       }, | ||||
|       commitToHistory: false, | ||||
|     }; | ||||
|   | ||||
| @@ -1,13 +1,12 @@ | ||||
| import { CODES, KEYS } from "../keys"; | ||||
| import { register } from "./register"; | ||||
| import { trackEvent } from "../analytics"; | ||||
|  | ||||
| export const actionToggleZenMode = register({ | ||||
|   name: "zenMode", | ||||
|   trackEvent: { | ||||
|     category: "canvas", | ||||
|     predicate: (appState) => !appState.zenModeEnabled, | ||||
|   }, | ||||
|   perform(elements, appState) { | ||||
|     trackEvent("view", "mode", "zen"); | ||||
|  | ||||
|     return { | ||||
|       appState: { | ||||
|         ...appState, | ||||
|   | ||||
| @@ -18,7 +18,6 @@ import { | ||||
|  | ||||
| export const actionSendBackward = register({ | ||||
|   name: "sendBackward", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: moveOneLeft(elements, appState), | ||||
| @@ -39,14 +38,13 @@ export const actionSendBackward = register({ | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.sendBackward")} — ${getShortcutKey("CtrlOrCmd+[")}`} | ||||
|     > | ||||
|       <SendBackwardIcon theme={appState.theme} /> | ||||
|       <SendBackwardIcon appearance={appState.appearance} /> | ||||
|     </button> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionBringForward = register({ | ||||
|   name: "bringForward", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: moveOneRight(elements, appState), | ||||
| @@ -67,14 +65,13 @@ export const actionBringForward = register({ | ||||
|       onClick={() => updateData(null)} | ||||
|       title={`${t("labels.bringForward")} — ${getShortcutKey("CtrlOrCmd+]")}`} | ||||
|     > | ||||
|       <BringForwardIcon theme={appState.theme} /> | ||||
|       <BringForwardIcon appearance={appState.appearance} /> | ||||
|     </button> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionSendToBack = register({ | ||||
|   name: "sendToBack", | ||||
|   trackEvent: { category: "element" }, | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: moveAllLeft(elements, appState), | ||||
| @@ -102,15 +99,13 @@ export const actionSendToBack = register({ | ||||
|           : getShortcutKey("CtrlOrCmd+Shift+[") | ||||
|       }`} | ||||
|     > | ||||
|       <SendToBackIcon theme={appState.theme} /> | ||||
|       <SendToBackIcon appearance={appState.appearance} /> | ||||
|     </button> | ||||
|   ), | ||||
| }); | ||||
|  | ||||
| export const actionBringToFront = register({ | ||||
|   name: "bringToFront", | ||||
|   trackEvent: { category: "element" }, | ||||
|  | ||||
|   perform: (elements, appState) => { | ||||
|     return { | ||||
|       elements: moveAllRight(elements, appState), | ||||
| @@ -138,7 +133,7 @@ export const actionBringToFront = register({ | ||||
|           : getShortcutKey("CtrlOrCmd+Shift+]") | ||||
|       }`} | ||||
|     > | ||||
|       <BringToFrontIcon theme={appState.theme} /> | ||||
|       <BringToFrontIcon appearance={appState.appearance} /> | ||||
|     </button> | ||||
|   ), | ||||
| }); | ||||
|   | ||||
| @@ -17,7 +17,6 @@ export { | ||||
|   actionChangeFontSize, | ||||
|   actionChangeFontFamily, | ||||
|   actionChangeTextAlign, | ||||
|   actionChangeVerticalAlign, | ||||
| } from "./actionProperties"; | ||||
|  | ||||
| export { | ||||
| @@ -27,7 +26,6 @@ export { | ||||
|   actionZoomOut, | ||||
|   actionResetZoom, | ||||
|   actionZoomToFit, | ||||
|   actionToggleTheme, | ||||
| } from "./actionCanvas"; | ||||
|  | ||||
| export { actionFinalize } from "./actionFinalize"; | ||||
| @@ -35,8 +33,8 @@ export { actionFinalize } from "./actionFinalize"; | ||||
| export { | ||||
|   actionChangeProjectName, | ||||
|   actionChangeExportBackground, | ||||
|   actionSaveToActiveFile, | ||||
|   actionSaveFileToDisk, | ||||
|   actionSaveScene, | ||||
|   actionSaveAsScene, | ||||
|   actionLoadScene, | ||||
| } from "./actionExport"; | ||||
|  | ||||
| @@ -68,20 +66,14 @@ export { | ||||
|   distributeVertically, | ||||
| } from "./actionDistribute"; | ||||
|  | ||||
| export { actionFlipHorizontal, actionFlipVertical } from "./actionFlip"; | ||||
|  | ||||
| export { | ||||
|   actionCopy, | ||||
|   actionCut, | ||||
|   actionCopyAsPng, | ||||
|   actionCopyAsSvg, | ||||
|   copyText, | ||||
| } from "./actionClipboard"; | ||||
|  | ||||
| export { actionToggleGridMode } from "./actionToggleGridMode"; | ||||
| export { actionToggleZenMode } from "./actionToggleZenMode"; | ||||
|  | ||||
| export { actionToggleStats } from "./actionToggleStats"; | ||||
| export { actionUnbindText, actionBindText } from "./actionBoundText"; | ||||
| export { actionLink } from "../element/Hyperlink"; | ||||
| export { actionToggleLock } from "./actionToggleLock"; | ||||
|   | ||||
| @@ -1,59 +1,33 @@ | ||||
| import React from "react"; | ||||
| import { | ||||
|   Action, | ||||
|   ActionsManagerInterface, | ||||
|   UpdaterFn, | ||||
|   ActionName, | ||||
|   ActionResult, | ||||
|   PanelComponentProps, | ||||
|   ActionSource, | ||||
| } from "./types"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { AppClassProperties, AppState } from "../types"; | ||||
| import { AppState, ExcalidrawProps } from "../types"; | ||||
| import { MODES } from "../constants"; | ||||
| import { trackEvent } from "../analytics"; | ||||
|  | ||||
| const trackAction = ( | ||||
|   action: Action, | ||||
|   source: ActionSource, | ||||
|   appState: Readonly<AppState>, | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   app: AppClassProperties, | ||||
|   value: any, | ||||
| ) => { | ||||
|   if (action.trackEvent) { | ||||
|     try { | ||||
|       if (typeof action.trackEvent === "object") { | ||||
|         const shouldTrack = action.trackEvent.predicate | ||||
|           ? action.trackEvent.predicate(appState, elements, value) | ||||
|           : true; | ||||
|         if (shouldTrack) { | ||||
|           trackEvent( | ||||
|             action.trackEvent.category, | ||||
|             action.trackEvent.action || action.name, | ||||
|             `${source} (${app.deviceType.isMobile ? "mobile" : "desktop"})`, | ||||
|           ); | ||||
|         } | ||||
|       } | ||||
|     } catch (error) { | ||||
|       console.error("error while logging action:", error); | ||||
|     } | ||||
|   } | ||||
| }; | ||||
| // This is the <App> component, but for now we don't care about anything but its | ||||
| // `canvas` state. | ||||
| type App = { canvas: HTMLCanvasElement | null; props: ExcalidrawProps }; | ||||
|  | ||||
| export class ActionManager { | ||||
|   actions = {} as Record<ActionName, Action>; | ||||
| export class ActionManager implements ActionsManagerInterface { | ||||
|   actions = {} as ActionsManagerInterface["actions"]; | ||||
|  | ||||
|   updater: (actionResult: ActionResult | Promise<ActionResult>) => void; | ||||
|  | ||||
|   getAppState: () => Readonly<AppState>; | ||||
|   getElementsIncludingDeleted: () => readonly ExcalidrawElement[]; | ||||
|   app: AppClassProperties; | ||||
|   app: App; | ||||
|  | ||||
|   constructor( | ||||
|     updater: UpdaterFn, | ||||
|     getAppState: () => AppState, | ||||
|     getElementsIncludingDeleted: () => readonly ExcalidrawElement[], | ||||
|     app: AppClassProperties, | ||||
|     app: App, | ||||
|   ) { | ||||
|     this.updater = (actionResult) => { | ||||
|       if (actionResult && "then" in actionResult) { | ||||
| @@ -77,15 +51,11 @@ export class ActionManager { | ||||
|     actions.forEach((action) => this.registerAction(action)); | ||||
|   } | ||||
|  | ||||
|   handleKeyDown(event: React.KeyboardEvent | KeyboardEvent) { | ||||
|     const canvasActions = this.app.props.UIOptions.canvasActions; | ||||
|   handleKeyDown(event: KeyboardEvent) { | ||||
|     const data = Object.values(this.actions) | ||||
|       .sort((a, b) => (b.keyPriority || 0) - (a.keyPriority || 0)) | ||||
|       .filter( | ||||
|         (action) => | ||||
|           (action.name in canvasActions | ||||
|             ? canvasActions[action.name as keyof typeof canvasActions] | ||||
|             : true) && | ||||
|           action.keyTest && | ||||
|           action.keyTest( | ||||
|             event, | ||||
| @@ -94,15 +64,9 @@ export class ActionManager { | ||||
|           ), | ||||
|       ); | ||||
|  | ||||
|     if (data.length !== 1) { | ||||
|       if (data.length > 1) { | ||||
|         console.warn("Canceling as multiple actions match this shortcut", data); | ||||
|       } | ||||
|     if (data.length === 0) { | ||||
|       return false; | ||||
|     } | ||||
|  | ||||
|     const action = data[0]; | ||||
|  | ||||
|     const { viewModeEnabled } = this.getAppState(); | ||||
|     if (viewModeEnabled) { | ||||
|       if (!Object.values(MODES).includes(data[0].name)) { | ||||
| @@ -110,48 +74,38 @@ export class ActionManager { | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     const elements = this.getElementsIncludingDeleted(); | ||||
|     const appState = this.getAppState(); | ||||
|     const value = null; | ||||
|  | ||||
|     trackAction(action, "keyboard", appState, elements, this.app, null); | ||||
|  | ||||
|     event.preventDefault(); | ||||
|     event.stopPropagation(); | ||||
|     this.updater(data[0].perform(elements, appState, value, this.app)); | ||||
|     this.updater( | ||||
|       data[0].perform( | ||||
|         this.getElementsIncludingDeleted(), | ||||
|         this.getAppState(), | ||||
|         null, | ||||
|         this.app, | ||||
|       ), | ||||
|     ); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   executeAction(action: Action, source: ActionSource = "api") { | ||||
|     const elements = this.getElementsIncludingDeleted(); | ||||
|     const appState = this.getAppState(); | ||||
|     const value = null; | ||||
|  | ||||
|     trackAction(action, source, appState, elements, this.app, value); | ||||
|  | ||||
|     this.updater(action.perform(elements, appState, value, this.app)); | ||||
|   executeAction(action: Action) { | ||||
|     this.updater( | ||||
|       action.perform( | ||||
|         this.getElementsIncludingDeleted(), | ||||
|         this.getAppState(), | ||||
|         null, | ||||
|         this.app, | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * @param data additional data sent to the PanelComponent | ||||
|    */ | ||||
|   renderAction = (name: ActionName, data?: PanelComponentProps["data"]) => { | ||||
|     const canvasActions = this.app.props.UIOptions.canvasActions; | ||||
|  | ||||
|     if ( | ||||
|       this.actions[name] && | ||||
|       "PanelComponent" in this.actions[name] && | ||||
|       (name in canvasActions | ||||
|         ? canvasActions[name as keyof typeof canvasActions] | ||||
|         : true) | ||||
|     ) { | ||||
|   // Id is an attribute that we can use to pass in data like keys. | ||||
|   // This is needed for dynamically generated action components | ||||
|   // like the user list. We can use this key to extract more | ||||
|   // data from app state. This is an alternative to generic prop hell! | ||||
|   renderAction = (name: ActionName, id?: string) => { | ||||
|     if (this.actions[name] && "PanelComponent" in this.actions[name]) { | ||||
|       const action = this.actions[name]; | ||||
|       const PanelComponent = action.PanelComponent!; | ||||
|       const elements = this.getElementsIncludingDeleted(); | ||||
|       const appState = this.getAppState(); | ||||
|       const updateData = (formState?: any) => { | ||||
|         trackAction(action, "ui", appState, elements, this.app, formState); | ||||
|  | ||||
|         this.updater( | ||||
|           action.perform( | ||||
|             this.getElementsIncludingDeleted(), | ||||
| @@ -167,8 +121,7 @@ export class ActionManager { | ||||
|           elements={this.getElementsIncludingDeleted()} | ||||
|           appState={this.getAppState()} | ||||
|           updateData={updateData} | ||||
|           appProps={this.app.props} | ||||
|           data={data} | ||||
|           id={id} | ||||
|         /> | ||||
|       ); | ||||
|     } | ||||
|   | ||||
| @@ -2,9 +2,7 @@ import { Action } from "./types"; | ||||
|  | ||||
| export let actions: readonly Action[] = []; | ||||
|  | ||||
| export const register = <T extends Action>(action: T) => { | ||||
| export const register = (action: Action): Action => { | ||||
|   actions = actions.concat(action); | ||||
|   return action as T & { | ||||
|     keyTest?: unknown extends T["keyTest"] ? never : T["keyTest"]; | ||||
|   }; | ||||
|   return action; | ||||
| }; | ||||
|   | ||||
| @@ -1,10 +1,8 @@ | ||||
| import { t } from "../i18n"; | ||||
| import { isDarwin } from "../keys"; | ||||
| import { getShortcutKey } from "../utils"; | ||||
| import { ActionName } from "./types"; | ||||
|  | ||||
| export type ShortcutName = SubtypeOf< | ||||
|   ActionName, | ||||
| export type ShortcutName = | ||||
|   | "cut" | ||||
|   | "copy" | ||||
|   | "paste" | ||||
| @@ -25,12 +23,7 @@ export type ShortcutName = SubtypeOf< | ||||
|   | "zenMode" | ||||
|   | "stats" | ||||
|   | "addToLibrary" | ||||
|   | "viewMode" | ||||
|   | "flipHorizontal" | ||||
|   | "flipVertical" | ||||
|   | "hyperlink" | ||||
|   | "toggleLock" | ||||
| >; | ||||
|   | "viewMode"; | ||||
|  | ||||
| const shortcutMap: Record<ShortcutName, string[]> = { | ||||
|   cut: [getShortcutKey("CtrlOrCmd+X")], | ||||
| @@ -62,17 +55,13 @@ const shortcutMap: Record<ShortcutName, string[]> = { | ||||
|   ungroup: [getShortcutKey("CtrlOrCmd+Shift+G")], | ||||
|   gridMode: [getShortcutKey("CtrlOrCmd+'")], | ||||
|   zenMode: [getShortcutKey("Alt+Z")], | ||||
|   stats: [getShortcutKey("Alt+/")], | ||||
|   stats: [], | ||||
|   addToLibrary: [], | ||||
|   flipHorizontal: [getShortcutKey("Shift+H")], | ||||
|   flipVertical: [getShortcutKey("Shift+V")], | ||||
|   viewMode: [getShortcutKey("Alt+R")], | ||||
|   hyperlink: [getShortcutKey("CtrlOrCmd+K")], | ||||
|   toggleLock: [getShortcutKey("CtrlOrCmd+Shift+L")], | ||||
| }; | ||||
|  | ||||
| export const getShortcutFromShortcutName = (name: ShortcutName) => { | ||||
|   const shortcuts = shortcutMap[name]; | ||||
|   // if multiple shortcuts available, take the first one | ||||
|   // if multiple shortcuts availiable, take the first one | ||||
|   return shortcuts && shortcuts.length > 0 ? shortcuts[0] : ""; | ||||
| }; | ||||
|   | ||||
| @@ -1,27 +1,14 @@ | ||||
| import React from "react"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { | ||||
|   AppClassProperties, | ||||
|   AppState, | ||||
|   ExcalidrawProps, | ||||
|   BinaryFiles, | ||||
| } from "../types"; | ||||
| import { ToolButtonSize } from "../components/ToolButton"; | ||||
|  | ||||
| export type ActionSource = "ui" | "keyboard" | "contextMenu" | "api"; | ||||
| import { AppState } from "../types"; | ||||
|  | ||||
| /** if false, the action should be prevented */ | ||||
| export type ActionResult = | ||||
|   | { | ||||
|       elements?: readonly ExcalidrawElement[] | null; | ||||
|       appState?: MarkOptional< | ||||
|         AppState, | ||||
|         "offsetTop" | "offsetLeft" | "width" | "height" | ||||
|       > | null; | ||||
|       files?: BinaryFiles | null; | ||||
|       appState?: MarkOptional<AppState, "offsetTop" | "offsetLeft"> | null; | ||||
|       commitToHistory: boolean; | ||||
|       syncHistory?: boolean; | ||||
|       replaceFiles?: boolean; | ||||
|     } | ||||
|   | false; | ||||
|  | ||||
| @@ -29,7 +16,7 @@ type ActionFn = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   appState: Readonly<AppState>, | ||||
|   formData: any, | ||||
|   app: AppClassProperties, | ||||
|   app: { canvas: HTMLCanvasElement | null }, | ||||
| ) => ActionResult | Promise<ActionResult>; | ||||
|  | ||||
| export type UpdaterFn = (res: ActionResult) => void; | ||||
| @@ -41,7 +28,6 @@ export type ActionName = | ||||
|   | "paste" | ||||
|   | "copyAsPng" | ||||
|   | "copyAsSvg" | ||||
|   | "copyText" | ||||
|   | "sendBackward" | ||||
|   | "bringForward" | ||||
|   | "sendToBack" | ||||
| @@ -56,7 +42,6 @@ export type ActionName = | ||||
|   | "changeBackgroundColor" | ||||
|   | "changeFillStyle" | ||||
|   | "changeStrokeWidth" | ||||
|   | "changeStrokeShape" | ||||
|   | "changeSloppiness" | ||||
|   | "changeStrokeStyle" | ||||
|   | "changeArrowhead" | ||||
| @@ -70,9 +55,9 @@ export type ActionName = | ||||
|   | "changeProjectName" | ||||
|   | "changeExportBackground" | ||||
|   | "changeExportEmbedScene" | ||||
|   | "changeExportScale" | ||||
|   | "saveToActiveFile" | ||||
|   | "saveFileToDisk" | ||||
|   | "changeShouldAddWatermark" | ||||
|   | "saveScene" | ||||
|   | "saveAsScene" | ||||
|   | "loadScene" | ||||
|   | "duplicateSelection" | ||||
|   | "deleteSelectedElements" | ||||
| @@ -85,7 +70,6 @@ export type ActionName = | ||||
|   | "zoomToSelection" | ||||
|   | "changeFontFamily" | ||||
|   | "changeTextAlign" | ||||
|   | "changeVerticalAlign" | ||||
|   | "toggleFullScreen" | ||||
|   | "toggleShortcuts" | ||||
|   | "group" | ||||
| @@ -101,65 +85,35 @@ export type ActionName = | ||||
|   | "alignHorizontallyCentered" | ||||
|   | "distributeHorizontally" | ||||
|   | "distributeVertically" | ||||
|   | "flipHorizontal" | ||||
|   | "flipVertical" | ||||
|   | "viewMode" | ||||
|   | "exportWithDarkMode" | ||||
|   | "toggleTheme" | ||||
|   | "increaseFontSize" | ||||
|   | "decreaseFontSize" | ||||
|   | "unbindText" | ||||
|   | "hyperlink" | ||||
|   | "eraser" | ||||
|   | "bindText" | ||||
|   | "toggleLock"; | ||||
|  | ||||
| export type PanelComponentProps = { | ||||
|   elements: readonly ExcalidrawElement[]; | ||||
|   appState: AppState; | ||||
|   updateData: (formData?: any) => void; | ||||
|   appProps: ExcalidrawProps; | ||||
|   data?: Partial<{ id: string; size: ToolButtonSize }>; | ||||
| }; | ||||
|   | "exportWithDarkMode"; | ||||
|  | ||||
| export interface Action { | ||||
|   name: ActionName; | ||||
|   PanelComponent?: React.FC<PanelComponentProps>; | ||||
|   PanelComponent?: React.FC<{ | ||||
|     elements: readonly ExcalidrawElement[]; | ||||
|     appState: AppState; | ||||
|     updateData: (formData?: any) => void; | ||||
|     id?: string; | ||||
|   }>; | ||||
|   perform: ActionFn; | ||||
|   keyPriority?: number; | ||||
|   keyTest?: ( | ||||
|     event: React.KeyboardEvent | KeyboardEvent, | ||||
|     event: KeyboardEvent, | ||||
|     appState: AppState, | ||||
|     elements: readonly ExcalidrawElement[], | ||||
|   ) => boolean; | ||||
|   contextItemLabel?: | ||||
|     | string | ||||
|     | (( | ||||
|         elements: readonly ExcalidrawElement[], | ||||
|         appState: Readonly<AppState>, | ||||
|       ) => string); | ||||
|   contextItemLabel?: string; | ||||
|   contextItemPredicate?: ( | ||||
|     elements: readonly ExcalidrawElement[], | ||||
|     appState: AppState, | ||||
|   ) => boolean; | ||||
|   checked?: (appState: Readonly<AppState>) => boolean; | ||||
|   trackEvent: | ||||
|     | false | ||||
|     | { | ||||
|         category: | ||||
|           | "toolbar" | ||||
|           | "element" | ||||
|           | "canvas" | ||||
|           | "export" | ||||
|           | "history" | ||||
|           | "menu" | ||||
|           | "collab" | ||||
|           | "hyperlink"; | ||||
|         action?: string; | ||||
|         predicate?: ( | ||||
|           appState: Readonly<AppState>, | ||||
|           elements: readonly ExcalidrawElement[], | ||||
|           value: any, | ||||
|         ) => boolean; | ||||
|       }; | ||||
| } | ||||
|  | ||||
| export interface ActionsManagerInterface { | ||||
|   actions: Record<ActionName, Action>; | ||||
|   registerAction: (action: Action) => void; | ||||
|   handleKeyDown: (event: KeyboardEvent) => boolean; | ||||
|   renderAction: (name: ActionName) => React.ReactElement | null; | ||||
| } | ||||
|   | ||||
							
								
								
									
										37
									
								
								src/align.ts
									
									
									
									
									
								
							
							
						
						| @@ -1,7 +1,13 @@ | ||||
| import { ExcalidrawElement } from "./element/types"; | ||||
| import { newElementWith } from "./element/mutateElement"; | ||||
| import { Box, getCommonBoundingBox } from "./element/bounds"; | ||||
| import { getMaximumGroups } from "./groups"; | ||||
| import { getCommonBounds } from "./element"; | ||||
|  | ||||
| interface Box { | ||||
|   minX: number; | ||||
|   minY: number; | ||||
|   maxX: number; | ||||
|   maxY: number; | ||||
| } | ||||
|  | ||||
| export interface Alignment { | ||||
|   position: "start" | "center" | "end"; | ||||
| @@ -31,6 +37,28 @@ export const alignElements = ( | ||||
|   }); | ||||
| }; | ||||
|  | ||||
| export const getMaximumGroups = ( | ||||
|   elements: ExcalidrawElement[], | ||||
| ): ExcalidrawElement[][] => { | ||||
|   const groups: Map<String, ExcalidrawElement[]> = new Map< | ||||
|     String, | ||||
|     ExcalidrawElement[] | ||||
|   >(); | ||||
|  | ||||
|   elements.forEach((element: ExcalidrawElement) => { | ||||
|     const groupId = | ||||
|       element.groupIds.length === 0 | ||||
|         ? element.id | ||||
|         : element.groupIds[element.groupIds.length - 1]; | ||||
|  | ||||
|     const currentGroupMembers = groups.get(groupId) || []; | ||||
|  | ||||
|     groups.set(groupId, [...currentGroupMembers, element]); | ||||
|   }); | ||||
|  | ||||
|   return Array.from(groups.values()); | ||||
| }; | ||||
|  | ||||
| const calculateTranslation = ( | ||||
|   group: ExcalidrawElement[], | ||||
|   selectionBoundingBox: Box, | ||||
| @@ -60,3 +88,8 @@ const calculateTranslation = ( | ||||
|       (groupBoundingBox[min] + groupBoundingBox[max]) / 2, | ||||
|   }; | ||||
| }; | ||||
|  | ||||
| const getCommonBoundingBox = (elements: ExcalidrawElement[]): Box => { | ||||
|   const [minX, minY, maxX, maxY] = getCommonBounds(elements); | ||||
|   return { minX, minY, maxX, maxY }; | ||||
| }; | ||||
|   | ||||
| @@ -3,20 +3,16 @@ export const trackEvent = | ||||
|   process.env?.REACT_APP_GOOGLE_ANALYTICS_ID && | ||||
|   typeof window !== "undefined" && | ||||
|   window.gtag | ||||
|     ? (category: string, action: string, label?: string, value?: number) => { | ||||
|         try { | ||||
|           window.gtag("event", action, { | ||||
|             event_category: category, | ||||
|             event_label: label, | ||||
|             value, | ||||
|           }); | ||||
|         } catch (error) { | ||||
|           console.error("error logging to ga", error); | ||||
|         } | ||||
|     ? (category: string, name: string, label?: string, value?: number) => { | ||||
|         window.gtag("event", name, { | ||||
|           event_category: category, | ||||
|           event_label: label, | ||||
|           value, | ||||
|         }); | ||||
|       } | ||||
|     : typeof process !== "undefined" && process.env?.JEST_WORKER_ID | ||||
|     ? (category: string, action: string, label?: string, value?: number) => {} | ||||
|     : (category: string, action: string, label?: string, value?: number) => { | ||||
|     ? (category: string, name: string, label?: string, value?: number) => {} | ||||
|     : (category: string, name: string, label?: string, value?: number) => { | ||||
|         // Uncomment the next line to track locally | ||||
|         // console.log("Track Event", { category, action, label, value }); | ||||
|         // console.info("Track Event", category, name, label, value); | ||||
|       }; | ||||
|   | ||||
							
								
								
									
										193
									
								
								src/appState.ts
									
									
									
									
									
								
							
							
						
						| @@ -3,23 +3,17 @@ import { | ||||
|   DEFAULT_FONT_FAMILY, | ||||
|   DEFAULT_FONT_SIZE, | ||||
|   DEFAULT_TEXT_ALIGN, | ||||
|   EXPORT_SCALES, | ||||
|   THEME, | ||||
| } from "./constants"; | ||||
| import { t } from "./i18n"; | ||||
| import { AppState, NormalizedZoomValue } from "./types"; | ||||
| import { getDateTime } from "./utils"; | ||||
|  | ||||
| const defaultExportScale = EXPORT_SCALES.includes(devicePixelRatio) | ||||
|   ? devicePixelRatio | ||||
|   : 1; | ||||
|  | ||||
| export const getDefaultAppState = (): Omit< | ||||
|   AppState, | ||||
|   "offsetTop" | "offsetLeft" | "width" | "height" | ||||
|   "offsetTop" | "offsetLeft" | ||||
| > => { | ||||
|   return { | ||||
|     theme: THEME.LIGHT, | ||||
|     appearance: "light", | ||||
|     collaborators: new Map(), | ||||
|     currentChartType: "bar", | ||||
|     currentItemBackgroundColor: "transparent", | ||||
| @@ -41,20 +35,15 @@ export const getDefaultAppState = (): Omit< | ||||
|     editingElement: null, | ||||
|     editingGroupId: null, | ||||
|     editingLinearElement: null, | ||||
|     activeTool: { | ||||
|       type: "selection", | ||||
|       locked: false, | ||||
|       lastActiveToolBeforeEraser: null, | ||||
|     }, | ||||
|     penMode: false, | ||||
|     penDetected: false, | ||||
|     elementLocked: false, | ||||
|     elementType: "selection", | ||||
|     errorMessage: null, | ||||
|     exportBackground: true, | ||||
|     exportScale: defaultExportScale, | ||||
|     exportEmbedScene: false, | ||||
|     exportWithDarkMode: false, | ||||
|     fileHandle: null, | ||||
|     gridSize: null, | ||||
|     height: window.innerHeight, | ||||
|     isBindingEnabled: true, | ||||
|     isLibraryOpen: false, | ||||
|     isLoading: false, | ||||
| @@ -64,7 +53,6 @@ export const getDefaultAppState = (): Omit< | ||||
|     multiElement: null, | ||||
|     name: `${t("labels.untitled")}-${getDateTime()}`, | ||||
|     openMenu: null, | ||||
|     openPopup: null, | ||||
|     pasteDialog: { shown: false, data: null }, | ||||
|     previousSelectedElementIds: {}, | ||||
|     resizingElement: null, | ||||
| @@ -74,6 +62,7 @@ export const getDefaultAppState = (): Omit< | ||||
|     selectedElementIds: {}, | ||||
|     selectedGroupIds: {}, | ||||
|     selectionElement: null, | ||||
|     shouldAddWatermark: false, | ||||
|     shouldCacheIgnoreZoom: false, | ||||
|     showHelpDialog: false, | ||||
|     showStats: false, | ||||
| @@ -81,13 +70,10 @@ export const getDefaultAppState = (): Omit< | ||||
|     suggestedBindings: [], | ||||
|     toastMessage: null, | ||||
|     viewBackgroundColor: oc.white, | ||||
|     width: window.innerWidth, | ||||
|     zenModeEnabled: false, | ||||
|     zoom: { | ||||
|       value: 1 as NormalizedZoomValue, | ||||
|     }, | ||||
|     zoom: { value: 1 as NormalizedZoomValue, translation: { x: 0, y: 0 } }, | ||||
|     viewModeEnabled: false, | ||||
|     pendingImageElement: null, | ||||
|     showHyperlinkPopup: false, | ||||
|   }; | ||||
| }; | ||||
|  | ||||
| @@ -101,88 +87,77 @@ const APP_STATE_STORAGE_CONF = (< | ||||
|     browser: boolean; | ||||
|     /** whether to keep when exporting to file/database */ | ||||
|     export: boolean; | ||||
|     /** server (shareLink/collab/...) */ | ||||
|     server: boolean; | ||||
|   }, | ||||
|   T extends Record<keyof AppState, Values>, | ||||
| >(config: { [K in keyof T]: K extends keyof AppState ? T[K] : never }) => | ||||
|   config)({ | ||||
|   theme: { browser: true, export: false, server: false }, | ||||
|   collaborators: { browser: false, export: false, server: false }, | ||||
|   currentChartType: { browser: true, export: false, server: false }, | ||||
|   currentItemBackgroundColor: { browser: true, export: false, server: false }, | ||||
|   currentItemEndArrowhead: { browser: true, export: false, server: false }, | ||||
|   currentItemFillStyle: { browser: true, export: false, server: false }, | ||||
|   currentItemFontFamily: { browser: true, export: false, server: false }, | ||||
|   currentItemFontSize: { browser: true, export: false, server: false }, | ||||
|   currentItemLinearStrokeSharpness: { | ||||
|     browser: true, | ||||
|     export: false, | ||||
|     server: false, | ||||
|   }, | ||||
|   currentItemOpacity: { browser: true, export: false, server: false }, | ||||
|   currentItemRoughness: { browser: true, export: false, server: false }, | ||||
|   currentItemStartArrowhead: { browser: true, export: false, server: false }, | ||||
|   currentItemStrokeColor: { browser: true, export: false, server: false }, | ||||
|   currentItemStrokeSharpness: { browser: true, export: false, server: false }, | ||||
|   currentItemStrokeStyle: { browser: true, export: false, server: false }, | ||||
|   currentItemStrokeWidth: { browser: true, export: false, server: false }, | ||||
|   currentItemTextAlign: { browser: true, export: false, server: false }, | ||||
|   cursorButton: { browser: true, export: false, server: false }, | ||||
|   draggingElement: { browser: false, export: false, server: false }, | ||||
|   editingElement: { browser: false, export: false, server: false }, | ||||
|   editingGroupId: { browser: true, export: false, server: false }, | ||||
|   editingLinearElement: { browser: false, export: false, server: false }, | ||||
|   activeTool: { browser: true, export: false, server: false }, | ||||
|   penMode: { browser: true, export: false, server: false }, | ||||
|   penDetected: { browser: true, export: false, server: false }, | ||||
|   errorMessage: { browser: false, export: false, server: false }, | ||||
|   exportBackground: { browser: true, export: false, server: false }, | ||||
|   exportEmbedScene: { browser: true, export: false, server: false }, | ||||
|   exportScale: { browser: true, export: false, server: false }, | ||||
|   exportWithDarkMode: { browser: true, export: false, server: false }, | ||||
|   fileHandle: { browser: false, export: false, server: false }, | ||||
|   gridSize: { browser: true, export: true, server: true }, | ||||
|   height: { browser: false, export: false, server: false }, | ||||
|   isBindingEnabled: { browser: false, export: false, server: false }, | ||||
|   isLibraryOpen: { browser: false, export: false, server: false }, | ||||
|   isLoading: { browser: false, export: false, server: false }, | ||||
|   isResizing: { browser: false, export: false, server: false }, | ||||
|   isRotating: { browser: false, export: false, server: false }, | ||||
|   lastPointerDownWith: { browser: true, export: false, server: false }, | ||||
|   multiElement: { browser: false, export: false, server: false }, | ||||
|   name: { browser: true, export: false, server: false }, | ||||
|   offsetLeft: { browser: false, export: false, server: false }, | ||||
|   offsetTop: { browser: false, export: false, server: false }, | ||||
|   openMenu: { browser: true, export: false, server: false }, | ||||
|   openPopup: { browser: false, export: false, server: false }, | ||||
|   pasteDialog: { browser: false, export: false, server: false }, | ||||
|   previousSelectedElementIds: { browser: true, export: false, server: false }, | ||||
|   resizingElement: { browser: false, export: false, server: false }, | ||||
|   scrolledOutside: { browser: true, export: false, server: false }, | ||||
|   scrollX: { browser: true, export: false, server: false }, | ||||
|   scrollY: { browser: true, export: false, server: false }, | ||||
|   selectedElementIds: { browser: true, export: false, server: false }, | ||||
|   selectedGroupIds: { browser: true, export: false, server: false }, | ||||
|   selectionElement: { browser: false, export: false, server: false }, | ||||
|   shouldCacheIgnoreZoom: { browser: true, export: false, server: false }, | ||||
|   showHelpDialog: { browser: false, export: false, server: false }, | ||||
|   showStats: { browser: true, export: false, server: false }, | ||||
|   startBoundElement: { browser: false, export: false, server: false }, | ||||
|   suggestedBindings: { browser: false, export: false, server: false }, | ||||
|   toastMessage: { browser: false, export: false, server: false }, | ||||
|   viewBackgroundColor: { browser: true, export: true, server: true }, | ||||
|   width: { browser: false, export: false, server: false }, | ||||
|   zenModeEnabled: { browser: true, export: false, server: false }, | ||||
|   zoom: { browser: true, export: false, server: false }, | ||||
|   viewModeEnabled: { browser: false, export: false, server: false }, | ||||
|   pendingImageElement: { browser: false, export: false, server: false }, | ||||
|   showHyperlinkPopup: { browser: false, export: false, server: false }, | ||||
|   T extends Record<keyof AppState, Values> | ||||
| >( | ||||
|   config: { [K in keyof T]: K extends keyof AppState ? T[K] : never }, | ||||
| ) => config)({ | ||||
|   appearance: { browser: true, export: false }, | ||||
|   collaborators: { browser: false, export: false }, | ||||
|   currentChartType: { browser: true, export: false }, | ||||
|   currentItemBackgroundColor: { browser: true, export: false }, | ||||
|   currentItemEndArrowhead: { browser: true, export: false }, | ||||
|   currentItemFillStyle: { browser: true, export: false }, | ||||
|   currentItemFontFamily: { browser: true, export: false }, | ||||
|   currentItemFontSize: { browser: true, export: false }, | ||||
|   currentItemLinearStrokeSharpness: { browser: true, export: false }, | ||||
|   currentItemOpacity: { browser: true, export: false }, | ||||
|   currentItemRoughness: { browser: true, export: false }, | ||||
|   currentItemStartArrowhead: { browser: true, export: false }, | ||||
|   currentItemStrokeColor: { browser: true, export: false }, | ||||
|   currentItemStrokeSharpness: { browser: true, export: false }, | ||||
|   currentItemStrokeStyle: { browser: true, export: false }, | ||||
|   currentItemStrokeWidth: { browser: true, export: false }, | ||||
|   currentItemTextAlign: { browser: true, export: false }, | ||||
|   cursorButton: { browser: true, export: false }, | ||||
|   draggingElement: { browser: false, export: false }, | ||||
|   editingElement: { browser: false, export: false }, | ||||
|   editingGroupId: { browser: true, export: false }, | ||||
|   editingLinearElement: { browser: false, export: false }, | ||||
|   elementLocked: { browser: true, export: false }, | ||||
|   elementType: { browser: true, export: false }, | ||||
|   errorMessage: { browser: false, export: false }, | ||||
|   exportBackground: { browser: true, export: false }, | ||||
|   exportEmbedScene: { browser: true, export: false }, | ||||
|   exportWithDarkMode: { browser: true, export: false }, | ||||
|   fileHandle: { browser: false, export: false }, | ||||
|   gridSize: { browser: true, export: true }, | ||||
|   height: { browser: false, export: false }, | ||||
|   isBindingEnabled: { browser: false, export: false }, | ||||
|   isLibraryOpen: { browser: false, export: false }, | ||||
|   isLoading: { browser: false, export: false }, | ||||
|   isResizing: { browser: false, export: false }, | ||||
|   isRotating: { browser: false, export: false }, | ||||
|   lastPointerDownWith: { browser: true, export: false }, | ||||
|   multiElement: { browser: false, export: false }, | ||||
|   name: { browser: true, export: false }, | ||||
|   offsetLeft: { browser: false, export: false }, | ||||
|   offsetTop: { browser: false, export: false }, | ||||
|   openMenu: { browser: true, export: false }, | ||||
|   pasteDialog: { browser: false, export: false }, | ||||
|   previousSelectedElementIds: { browser: true, export: false }, | ||||
|   resizingElement: { browser: false, export: false }, | ||||
|   scrolledOutside: { browser: true, export: false }, | ||||
|   scrollX: { browser: true, export: false }, | ||||
|   scrollY: { browser: true, export: false }, | ||||
|   selectedElementIds: { browser: true, export: false }, | ||||
|   selectedGroupIds: { browser: true, export: false }, | ||||
|   selectionElement: { browser: false, export: false }, | ||||
|   shouldAddWatermark: { browser: true, export: false }, | ||||
|   shouldCacheIgnoreZoom: { browser: true, export: false }, | ||||
|   showHelpDialog: { browser: false, export: false }, | ||||
|   showStats: { browser: true, export: false }, | ||||
|   startBoundElement: { browser: false, export: false }, | ||||
|   suggestedBindings: { browser: false, export: false }, | ||||
|   toastMessage: { browser: false, export: false }, | ||||
|   viewBackgroundColor: { browser: true, export: true }, | ||||
|   width: { browser: false, export: false }, | ||||
|   zenModeEnabled: { browser: true, export: false }, | ||||
|   zoom: { browser: true, export: false }, | ||||
|   viewModeEnabled: { browser: false, export: false }, | ||||
| }); | ||||
|  | ||||
| const _clearAppStateForStorage = < | ||||
|   ExportType extends "export" | "browser" | "server", | ||||
| >( | ||||
| const _clearAppStateForStorage = <ExportType extends "export" | "browser">( | ||||
|   appState: Partial<AppState>, | ||||
|   exportType: ExportType, | ||||
| ) => { | ||||
| @@ -195,10 +170,8 @@ const _clearAppStateForStorage = < | ||||
|   for (const key of Object.keys(appState) as (keyof typeof appState)[]) { | ||||
|     const propConfig = APP_STATE_STORAGE_CONF[key]; | ||||
|     if (propConfig?.[exportType]) { | ||||
|       const nextValue = appState[key]; | ||||
|  | ||||
|       // https://github.com/microsoft/TypeScript/issues/31445 | ||||
|       (stateForExport as any)[key] = nextValue; | ||||
|       // @ts-ignore see https://github.com/microsoft/TypeScript/issues/31445 | ||||
|       stateForExport[key] = appState[key]; | ||||
|     } | ||||
|   } | ||||
|   return stateForExport; | ||||
| @@ -211,13 +184,3 @@ export const clearAppStateForLocalStorage = (appState: Partial<AppState>) => { | ||||
| export const cleanAppStateForExport = (appState: Partial<AppState>) => { | ||||
|   return _clearAppStateForStorage(appState, "export"); | ||||
| }; | ||||
|  | ||||
| export const clearAppStateForDatabase = (appState: Partial<AppState>) => { | ||||
|   return _clearAppStateForStorage(appState, "server"); | ||||
| }; | ||||
|  | ||||
| export const isEraserActive = ({ | ||||
|   activeTool, | ||||
| }: { | ||||
|   activeTool: AppState["activeTool"]; | ||||
| }) => activeTool.type === "eraser"; | ||||
|   | ||||
| @@ -1,10 +1,5 @@ | ||||
| import colors from "./colors"; | ||||
| import { | ||||
|   DEFAULT_FONT_FAMILY, | ||||
|   DEFAULT_FONT_SIZE, | ||||
|   ENV, | ||||
|   VERTICAL_ALIGN, | ||||
| } from "./constants"; | ||||
| import { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, ENV } from "./constants"; | ||||
| import { newElement, newLinearElement, newTextElement } from "./element"; | ||||
| import { NonDeletedExcalidrawElement } from "./element/types"; | ||||
| import { randomId } from "./random"; | ||||
| @@ -108,7 +103,7 @@ const transposeCells = (cells: string[][]) => { | ||||
| }; | ||||
|  | ||||
| export const tryParseSpreadsheet = (text: string): ParseSpreadsheetResult => { | ||||
|   // Copy/paste from excel, spreadsheets, tsv, csv. | ||||
|   // Copy/paste from excel, spreadhseets, tsv, csv. | ||||
|   // For now we only accept 2 columns with an optional header | ||||
|  | ||||
|   // Check for tab separated values | ||||
| @@ -166,8 +161,7 @@ const commonProps = { | ||||
|   strokeSharpness: "sharp", | ||||
|   strokeStyle: "solid", | ||||
|   strokeWidth: 1, | ||||
|   verticalAlign: VERTICAL_ALIGN.MIDDLE, | ||||
|   locked: false, | ||||
|   verticalAlign: "middle", | ||||
| } as const; | ||||
|  | ||||
| const getChartDimentions = (spreadsheet: Spreadsheet) => { | ||||
|   | ||||
							
								
								
									
										114
									
								
								src/clipboard.ts
									
									
									
									
									
								
							
							
						
						| @@ -2,27 +2,20 @@ import { | ||||
|   ExcalidrawElement, | ||||
|   NonDeletedExcalidrawElement, | ||||
| } from "./element/types"; | ||||
| import { AppState, BinaryFiles } from "./types"; | ||||
| import { getSelectedElements } from "./scene"; | ||||
| import { AppState } from "./types"; | ||||
| import { SVG_EXPORT_TAG } from "./scene/export"; | ||||
| import { tryParseSpreadsheet, Spreadsheet, VALID_SPREADSHEET } from "./charts"; | ||||
| import { EXPORT_DATA_TYPES, MIME_TYPES } from "./constants"; | ||||
| import { isInitializedImageElement } from "./element/typeChecks"; | ||||
| import { isPromiseLike } from "./utils"; | ||||
| import { canvasToBlob } from "./data/blob"; | ||||
|  | ||||
| const TYPE_ELEMENTS = "excalidraw/elements"; | ||||
|  | ||||
| type ElementsClipboard = { | ||||
|   type: typeof EXPORT_DATA_TYPES.excalidrawClipboard; | ||||
|   elements: readonly NonDeletedExcalidrawElement[]; | ||||
|   files: BinaryFiles | undefined; | ||||
|   type: typeof TYPE_ELEMENTS; | ||||
|   created: number; | ||||
|   elements: ExcalidrawElement[]; | ||||
| }; | ||||
|  | ||||
| export interface ClipboardData { | ||||
|   spreadsheet?: Spreadsheet; | ||||
|   elements?: readonly ExcalidrawElement[]; | ||||
|   files?: BinaryFiles; | ||||
|   text?: string; | ||||
|   errorMessage?: string; | ||||
| } | ||||
|  | ||||
| let CLIPBOARD = ""; | ||||
| let PREFER_APP_CLIPBOARD = false; | ||||
|  | ||||
| @@ -38,16 +31,8 @@ export const probablySupportsClipboardBlob = | ||||
|   "ClipboardItem" in window && | ||||
|   "toBlob" in HTMLCanvasElement.prototype; | ||||
|  | ||||
| const clipboardContainsElements = ( | ||||
|   contents: any, | ||||
| ): contents is { elements: ExcalidrawElement[]; files?: BinaryFiles } => { | ||||
|   if ( | ||||
|     [ | ||||
|       EXPORT_DATA_TYPES.excalidraw, | ||||
|       EXPORT_DATA_TYPES.excalidrawClipboard, | ||||
|     ].includes(contents?.type) && | ||||
|     Array.isArray(contents.elements) | ||||
|   ) { | ||||
| const isElementsClipboard = (contents: any): contents is ElementsClipboard => { | ||||
|   if (contents?.type === TYPE_ELEMENTS) { | ||||
|     return true; | ||||
|   } | ||||
|   return false; | ||||
| @@ -56,27 +41,18 @@ const clipboardContainsElements = ( | ||||
| export const copyToClipboard = async ( | ||||
|   elements: readonly NonDeletedExcalidrawElement[], | ||||
|   appState: AppState, | ||||
|   files: BinaryFiles | null, | ||||
| ) => { | ||||
|   // select binded text elements when copying | ||||
|   const contents: ElementsClipboard = { | ||||
|     type: EXPORT_DATA_TYPES.excalidrawClipboard, | ||||
|     elements, | ||||
|     files: files | ||||
|       ? elements.reduce((acc, element) => { | ||||
|           if (isInitializedImageElement(element) && files[element.fileId]) { | ||||
|             acc[element.fileId] = files[element.fileId]; | ||||
|           } | ||||
|           return acc; | ||||
|         }, {} as BinaryFiles) | ||||
|       : undefined, | ||||
|     type: TYPE_ELEMENTS, | ||||
|     created: Date.now(), | ||||
|     elements: getSelectedElements(elements, appState), | ||||
|   }; | ||||
|   const json = JSON.stringify(contents); | ||||
|   CLIPBOARD = json; | ||||
|   try { | ||||
|     PREFER_APP_CLIPBOARD = false; | ||||
|     await copyTextToSystemClipboard(json); | ||||
|   } catch (error: any) { | ||||
|   } catch (error) { | ||||
|     PREFER_APP_CLIPBOARD = true; | ||||
|     console.error(error); | ||||
|   } | ||||
| @@ -89,7 +65,7 @@ const getAppClipboard = (): Partial<ElementsClipboard> => { | ||||
|  | ||||
|   try { | ||||
|     return JSON.parse(CLIPBOARD); | ||||
|   } catch (error: any) { | ||||
|   } catch (error) { | ||||
|     console.error(error); | ||||
|     return {}; | ||||
|   } | ||||
| @@ -125,11 +101,16 @@ const getSystemClipboard = async ( | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Attempts to parse clipboard. Prefers system clipboard. | ||||
|  * Attemps to parse clipboard. Prefers system clipboard. | ||||
|  */ | ||||
| export const parseClipboard = async ( | ||||
|   event: ClipboardEvent | null, | ||||
| ): Promise<ClipboardData> => { | ||||
| ): Promise<{ | ||||
|   spreadsheet?: Spreadsheet; | ||||
|   elements?: readonly ExcalidrawElement[]; | ||||
|   text?: string; | ||||
|   errorMessage?: string; | ||||
| }> => { | ||||
|   const systemClipboard = await getSystemClipboard(event); | ||||
|  | ||||
|   // if system clipboard empty, couldn't be resolved, or contains previously | ||||
| @@ -150,12 +131,15 @@ export const parseClipboard = async ( | ||||
|  | ||||
|   try { | ||||
|     const systemClipboardData = JSON.parse(systemClipboard); | ||||
|     if (clipboardContainsElements(systemClipboardData)) { | ||||
|       return { | ||||
|         elements: systemClipboardData.elements, | ||||
|         files: systemClipboardData.files, | ||||
|       }; | ||||
|     // system clipboard elements are newer than in-app clipboard | ||||
|     if ( | ||||
|       isElementsClipboard(systemClipboardData) && | ||||
|       (!appClipboardData?.created || | ||||
|         appClipboardData.created < systemClipboardData.created) | ||||
|     ) { | ||||
|       return { elements: systemClipboardData.elements }; | ||||
|     } | ||||
|     // in-app clipboard is newer than system clipboard | ||||
|     return appClipboardData; | ||||
|   } catch { | ||||
|     // system clipboard doesn't contain excalidraw elements → return plaintext | ||||
| @@ -167,35 +151,11 @@ export const parseClipboard = async ( | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export const copyBlobToClipboardAsPng = async (blob: Blob | Promise<Blob>) => { | ||||
|   let promise; | ||||
|   try { | ||||
|     // in Safari so far we need to construct the ClipboardItem synchronously | ||||
|     // (i.e. in the same tick) otherwise browser will complain for lack of | ||||
|     // user intent. Using a Promise ClipboardItem constructor solves this. | ||||
|     // https://bugs.webkit.org/show_bug.cgi?id=222262 | ||||
|     // | ||||
|     // not await so that we can detect whether the thrown error likely relates | ||||
|     // to a lack of support for the Promise ClipboardItem constructor | ||||
|     promise = navigator.clipboard.write([ | ||||
|       new window.ClipboardItem({ | ||||
|         [MIME_TYPES.png]: blob, | ||||
|       }), | ||||
|     ]); | ||||
|   } catch (error: any) { | ||||
|     // if we're using a Promise ClipboardItem, let's try constructing | ||||
|     // with resolution value instead | ||||
|     if (isPromiseLike(blob)) { | ||||
|       await navigator.clipboard.write([ | ||||
|         new window.ClipboardItem({ | ||||
|           [MIME_TYPES.png]: await blob, | ||||
|         }), | ||||
|       ]); | ||||
|     } else { | ||||
|       throw error; | ||||
|     } | ||||
|   } | ||||
|   await promise; | ||||
| export const copyCanvasToClipboardAsPng = async (canvas: HTMLCanvasElement) => { | ||||
|   const blob = await canvasToBlob(canvas); | ||||
|   await navigator.clipboard.write([ | ||||
|     new window.ClipboardItem({ "image/png": blob }), | ||||
|   ]); | ||||
| }; | ||||
|  | ||||
| export const copyTextToSystemClipboard = async (text: string | null) => { | ||||
| @@ -206,7 +166,7 @@ export const copyTextToSystemClipboard = async (text: string | null) => { | ||||
|       // not focused | ||||
|       await navigator.clipboard.writeText(text || ""); | ||||
|       copied = true; | ||||
|     } catch (error: any) { | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|     } | ||||
|   } | ||||
| @@ -246,7 +206,7 @@ const copyTextViaExecCommand = (text: string) => { | ||||
|     textarea.setSelectionRange(0, textarea.value.length); | ||||
|  | ||||
|     success = document.execCommand("copy"); | ||||
|   } catch (error: any) { | ||||
|   } catch (error) { | ||||
|     console.error(error); | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -1,16 +1,15 @@ | ||||
| import React from "react"; | ||||
| import { ActionManager } from "../actions/manager"; | ||||
| import { getNonDeletedElements } from "../element"; | ||||
| import { ExcalidrawElement, PointerType } from "../element/types"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { t } from "../i18n"; | ||||
| import { useDeviceType } from "../components/App"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { | ||||
|   canChangeSharpness, | ||||
|   canHaveArrowheads, | ||||
|   getTargetElements, | ||||
|   hasBackground, | ||||
|   hasStrokeStyle, | ||||
|   hasStrokeWidth, | ||||
|   hasStroke, | ||||
|   hasText, | ||||
| } from "../scene"; | ||||
| import { SHAPES } from "../shapes"; | ||||
| @@ -18,92 +17,57 @@ import { AppState, Zoom } from "../types"; | ||||
| import { capitalizeString, isTransparent, setCursorForShape } from "../utils"; | ||||
| import Stack from "./Stack"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
| import { hasStrokeColor } from "../scene/comparisons"; | ||||
| import { trackEvent } from "../analytics"; | ||||
| import { hasBoundTextElement, isBoundToContainer } from "../element/typeChecks"; | ||||
|  | ||||
| export const SelectedShapeActions = ({ | ||||
|   appState, | ||||
|   elements, | ||||
|   renderAction, | ||||
|   activeTool, | ||||
|   elementType, | ||||
| }: { | ||||
|   appState: AppState; | ||||
|   elements: readonly ExcalidrawElement[]; | ||||
|   renderAction: ActionManager["renderAction"]; | ||||
|   activeTool: AppState["activeTool"]["type"]; | ||||
|   elementType: ExcalidrawElement["type"]; | ||||
| }) => { | ||||
|   const targetElements = getTargetElements( | ||||
|     getNonDeletedElements(elements), | ||||
|     appState, | ||||
|   ); | ||||
|  | ||||
|   let isSingleElementBoundContainer = false; | ||||
|   if ( | ||||
|     targetElements.length === 2 && | ||||
|     (hasBoundTextElement(targetElements[0]) || | ||||
|       hasBoundTextElement(targetElements[1])) | ||||
|   ) { | ||||
|     isSingleElementBoundContainer = true; | ||||
|   } | ||||
|   const isEditing = Boolean(appState.editingElement); | ||||
|   const deviceType = useDeviceType(); | ||||
|   const isMobile = useIsMobile(); | ||||
|   const isRTL = document.documentElement.getAttribute("dir") === "rtl"; | ||||
|  | ||||
|   const showFillIcons = | ||||
|     hasBackground(activeTool) || | ||||
|     hasBackground(elementType) || | ||||
|     targetElements.some( | ||||
|       (element) => | ||||
|         hasBackground(element.type) && !isTransparent(element.backgroundColor), | ||||
|     ); | ||||
|   const showChangeBackgroundIcons = | ||||
|     hasBackground(activeTool) || | ||||
|     hasBackground(elementType) || | ||||
|     targetElements.some((element) => hasBackground(element.type)); | ||||
|  | ||||
|   const showLinkIcon = | ||||
|     targetElements.length === 1 || isSingleElementBoundContainer; | ||||
|  | ||||
|   let commonSelectedType: string | null = targetElements[0]?.type || null; | ||||
|  | ||||
|   for (const element of targetElements) { | ||||
|     if (element.type !== commonSelectedType) { | ||||
|       commonSelectedType = null; | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <div className="panelColumn"> | ||||
|       {((hasStrokeColor(activeTool) && | ||||
|         activeTool !== "image" && | ||||
|         commonSelectedType !== "image") || | ||||
|         targetElements.some((element) => hasStrokeColor(element.type))) && | ||||
|         renderAction("changeStrokeColor")} | ||||
|       {renderAction("changeStrokeColor")} | ||||
|       {showChangeBackgroundIcons && renderAction("changeBackgroundColor")} | ||||
|       {showFillIcons && renderAction("changeFillStyle")} | ||||
|  | ||||
|       {(hasStrokeWidth(activeTool) || | ||||
|         targetElements.some((element) => hasStrokeWidth(element.type))) && | ||||
|         renderAction("changeStrokeWidth")} | ||||
|  | ||||
|       {(activeTool === "freedraw" || | ||||
|         targetElements.some((element) => element.type === "freedraw")) && | ||||
|         renderAction("changeStrokeShape")} | ||||
|  | ||||
|       {(hasStrokeStyle(activeTool) || | ||||
|         targetElements.some((element) => hasStrokeStyle(element.type))) && ( | ||||
|       {(hasStroke(elementType) || | ||||
|         targetElements.some((element) => hasStroke(element.type))) && ( | ||||
|         <> | ||||
|           {renderAction("changeStrokeWidth")} | ||||
|           {renderAction("changeStrokeStyle")} | ||||
|           {renderAction("changeSloppiness")} | ||||
|         </> | ||||
|       )} | ||||
|  | ||||
|       {(canChangeSharpness(activeTool) || | ||||
|       {(canChangeSharpness(elementType) || | ||||
|         targetElements.some((element) => canChangeSharpness(element.type))) && ( | ||||
|         <>{renderAction("changeSharpness")}</> | ||||
|       )} | ||||
|  | ||||
|       {(hasText(activeTool) || | ||||
|       {(hasText(elementType) || | ||||
|         targetElements.some((element) => hasText(element.type))) && ( | ||||
|         <> | ||||
|           {renderAction("changeFontSize")} | ||||
| @@ -114,11 +78,7 @@ export const SelectedShapeActions = ({ | ||||
|         </> | ||||
|       )} | ||||
|  | ||||
|       {targetElements.some( | ||||
|         (element) => | ||||
|           hasBoundTextElement(element) || isBoundToContainer(element), | ||||
|       ) && renderAction("changeVerticalAlign")} | ||||
|       {(canHaveArrowheads(activeTool) || | ||||
|       {(canHaveArrowheads(elementType) || | ||||
|         targetElements.some((element) => canHaveArrowheads(element.type))) && ( | ||||
|         <>{renderAction("changeArrowhead")}</> | ||||
|       )} | ||||
| @@ -135,7 +95,7 @@ export const SelectedShapeActions = ({ | ||||
|         </div> | ||||
|       </fieldset> | ||||
|  | ||||
|       {targetElements.length > 1 && !isSingleElementBoundContainer && ( | ||||
|       {targetElements.length > 1 && ( | ||||
|         <fieldset> | ||||
|           <legend>{t("labels.align")}</legend> | ||||
|           <div className="buttonList"> | ||||
| @@ -168,15 +128,14 @@ export const SelectedShapeActions = ({ | ||||
|           </div> | ||||
|         </fieldset> | ||||
|       )} | ||||
|       {!isEditing && targetElements.length > 0 && ( | ||||
|       {!isMobile && !isEditing && targetElements.length > 0 && ( | ||||
|         <fieldset> | ||||
|           <legend>{t("labels.actions")}</legend> | ||||
|           <div className="buttonList"> | ||||
|             {!deviceType.isMobile && renderAction("duplicateSelection")} | ||||
|             {!deviceType.isMobile && renderAction("deleteSelectedElements")} | ||||
|             {renderAction("duplicateSelection")} | ||||
|             {renderAction("deleteSelectedElements")} | ||||
|             {renderAction("group")} | ||||
|             {renderAction("ungroup")} | ||||
|             {showLinkIcon && renderAction("hyperlink")} | ||||
|           </div> | ||||
|         </fieldset> | ||||
|       )} | ||||
| @@ -184,68 +143,69 @@ export const SelectedShapeActions = ({ | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const LIBRARY_ICON = ( | ||||
|   // fa-th-large | ||||
|   <svg viewBox="0 0 512 512"> | ||||
|     <path d="M296 32h192c13.255 0 24 10.745 24 24v160c0 13.255-10.745 24-24 24H296c-13.255 0-24-10.745-24-24V56c0-13.255 10.745-24 24-24zm-80 0H24C10.745 32 0 42.745 0 56v160c0 13.255 10.745 24 24 24h192c13.255 0 24-10.745 24-24V56c0-13.255-10.745-24-24-24zM0 296v160c0 13.255 10.745 24 24 24h192c13.255 0 24-10.745 24-24V296c0-13.255-10.745-24-24-24H24c-13.255 0-24 10.745-24 24zm296 184h192c13.255 0 24-10.745 24-24V296c0-13.255-10.745-24-24-24H296c-13.255 0-24 10.745-24 24v160c0 13.255 10.745 24 24 24z" /> | ||||
|   </svg> | ||||
| ); | ||||
|  | ||||
| export const ShapesSwitcher = ({ | ||||
|   canvas, | ||||
|   activeTool, | ||||
|   elementType, | ||||
|   setAppState, | ||||
|   onImageAction, | ||||
|   appState, | ||||
|   isLibraryOpen, | ||||
| }: { | ||||
|   canvas: HTMLCanvasElement | null; | ||||
|   activeTool: AppState["activeTool"]; | ||||
|   elementType: ExcalidrawElement["type"]; | ||||
|   setAppState: React.Component<any, AppState>["setState"]; | ||||
|   onImageAction: (data: { pointerType: PointerType | null }) => void; | ||||
|   appState: AppState; | ||||
|   isLibraryOpen: boolean; | ||||
| }) => ( | ||||
|   <> | ||||
|     {SHAPES.map(({ value, icon, key }, index) => { | ||||
|       const label = t(`toolBar.${value}`); | ||||
|       const letter = key && (typeof key === "string" ? key : key[0]); | ||||
|       const shortcut = letter | ||||
|         ? `${capitalizeString(letter)} ${t("helpDialog.or")} ${index + 1}` | ||||
|         : `${index + 1}`; | ||||
|       const letter = typeof key === "string" ? key : key[0]; | ||||
|       const shortcut = `${capitalizeString(letter)} ${t("helpDialog.or")} ${ | ||||
|         index + 1 | ||||
|       }`; | ||||
|       return ( | ||||
|         <ToolButton | ||||
|           className="Shape" | ||||
|           key={value} | ||||
|           type="radio" | ||||
|           icon={icon} | ||||
|           checked={activeTool.type === value} | ||||
|           checked={elementType === value} | ||||
|           name="editor-current-shape" | ||||
|           title={`${capitalizeString(label)} — ${shortcut}`} | ||||
|           keyBindingLabel={`${index + 1}`} | ||||
|           aria-label={capitalizeString(label)} | ||||
|           aria-keyshortcuts={shortcut} | ||||
|           data-testid={value} | ||||
|           onPointerDown={({ pointerType }) => { | ||||
|             if (!appState.penDetected && pointerType === "pen") { | ||||
|               setAppState({ | ||||
|                 penDetected: true, | ||||
|                 penMode: true, | ||||
|               }); | ||||
|             } | ||||
|           }} | ||||
|           onChange={({ pointerType }) => { | ||||
|             if (appState.activeTool.type !== value) { | ||||
|               trackEvent("toolbar", value, "ui"); | ||||
|             } | ||||
|             const nextActiveTool = { ...activeTool, type: value }; | ||||
|           onChange={() => { | ||||
|             setAppState({ | ||||
|               activeTool: nextActiveTool, | ||||
|               elementType: value, | ||||
|               multiElement: null, | ||||
|               selectedElementIds: {}, | ||||
|             }); | ||||
|             setCursorForShape(canvas, { | ||||
|               ...appState, | ||||
|               activeTool: nextActiveTool, | ||||
|             }); | ||||
|             if (value === "image") { | ||||
|               onImageAction({ pointerType }); | ||||
|             } | ||||
|             setCursorForShape(canvas, value); | ||||
|             setAppState({}); | ||||
|           }} | ||||
|         /> | ||||
|       ); | ||||
|     })} | ||||
|     <ToolButton | ||||
|       className="Shape ToolIcon_type_button__library" | ||||
|       type="button" | ||||
|       icon={LIBRARY_ICON} | ||||
|       name="editor-library" | ||||
|       keyBindingLabel="9" | ||||
|       aria-keyshortcuts="9" | ||||
|       title={`${capitalizeString(t("toolBar.library"))} — 9`} | ||||
|       aria-label={capitalizeString(t("toolBar.library"))} | ||||
|       onClick={() => { | ||||
|         setAppState({ isLibraryOpen: !isLibraryOpen }); | ||||
|       }} | ||||
|     /> | ||||
|   </> | ||||
| ); | ||||
|  | ||||
| @@ -258,9 +218,12 @@ export const ZoomActions = ({ | ||||
| }) => ( | ||||
|   <Stack.Col gap={1}> | ||||
|     <Stack.Row gap={1} align="center"> | ||||
|       {renderAction("zoomOut")} | ||||
|       {renderAction("zoomIn")} | ||||
|       {renderAction("zoomOut")} | ||||
|       {renderAction("resetZoom")} | ||||
|       <div style={{ marginInlineStart: 4 }}> | ||||
|         {(zoom.value * 100).toFixed(0)}% | ||||
|       </div> | ||||
|     </Stack.Row> | ||||
|   </Stack.Col> | ||||
| ); | ||||
|   | ||||
| @@ -1,21 +0,0 @@ | ||||
| .excalidraw { | ||||
|   .ActiveFile { | ||||
|     .ActiveFile__fileName { | ||||
|       display: flex; | ||||
|       align-items: center; | ||||
|  | ||||
|       span { | ||||
|         text-overflow: ellipsis; | ||||
|         overflow: hidden; | ||||
|         white-space: nowrap; | ||||
|         width: 9.3em; | ||||
|       } | ||||
|  | ||||
|       svg { | ||||
|         width: 1.15em; | ||||
|         margin-inline-end: 0.3em; | ||||
|         transform: scaleY(0.9); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,28 +0,0 @@ | ||||
| import Stack from "../components/Stack"; | ||||
| import { ToolButton } from "../components/ToolButton"; | ||||
| import { save, file } from "../components/icons"; | ||||
| import { t } from "../i18n"; | ||||
|  | ||||
| import "./ActiveFile.scss"; | ||||
|  | ||||
| type ActiveFileProps = { | ||||
|   fileName?: string; | ||||
|   onSave: () => void; | ||||
| }; | ||||
|  | ||||
| export const ActiveFile = ({ fileName, onSave }: ActiveFileProps) => ( | ||||
|   <Stack.Row className="ActiveFile" gap={1} align="center"> | ||||
|     <span className="ActiveFile__fileName"> | ||||
|       {file} | ||||
|       <span>{fileName}</span> | ||||
|     </span> | ||||
|     <ToolButton | ||||
|       type="icon" | ||||
|       icon={save} | ||||
|       title={t("buttons.save")} | ||||
|       aria-label={t("buttons.save")} | ||||
|       onClick={onSave} | ||||
|       data-testid="save-button" | ||||
|     /> | ||||
|   </Stack.Row> | ||||
| ); | ||||
| @@ -12,11 +12,5 @@ | ||||
|     cursor: pointer; | ||||
|     font-size: 0.8rem; | ||||
|     font-weight: 500; | ||||
|  | ||||
|     &-img { | ||||
|       width: 100%; | ||||
|       height: 100%; | ||||
|       border-radius: 100%; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,28 +1,20 @@ | ||||
| import "./Avatar.scss"; | ||||
|  | ||||
| import React from "react"; | ||||
| import { getClientInitials } from "../clients"; | ||||
|  | ||||
| type AvatarProps = { | ||||
|   children: string; | ||||
|   onClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; | ||||
|   color: string; | ||||
|   border: string; | ||||
|   name: string; | ||||
|   src?: string; | ||||
| }; | ||||
|  | ||||
| export const Avatar = ({ color, border, onClick, name, src }: AvatarProps) => { | ||||
|   const shortName = getClientInitials(name); | ||||
|   const style = src | ||||
|     ? undefined | ||||
|     : { background: color, border: `1px solid ${border}` }; | ||||
|   return ( | ||||
|     <div className="Avatar" style={style} onClick={onClick}> | ||||
|       {src ? ( | ||||
|         <img className="Avatar-img" src={src} alt={shortName} /> | ||||
|       ) : ( | ||||
|         shortName | ||||
|       )} | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
| export const Avatar = ({ children, color, border, onClick }: AvatarProps) => ( | ||||
|   <div | ||||
|     className="Avatar" | ||||
|     style={{ background: color, border: `1px solid ${border}` }} | ||||
|     onClick={onClick} | ||||
|   > | ||||
|     {children} | ||||
|   </div> | ||||
| ); | ||||
|   | ||||
| @@ -1,20 +1,26 @@ | ||||
| import React from "react"; | ||||
| import { ActionManager } from "../actions/manager"; | ||||
| import { AppState } from "../types"; | ||||
| import { DarkModeToggle } from "./DarkModeToggle"; | ||||
|  | ||||
| export const BackgroundPickerAndDarkModeToggle = ({ | ||||
|   appState, | ||||
|   setAppState, | ||||
|   actionManager, | ||||
|   showThemeBtn, | ||||
| }: { | ||||
|   actionManager: ActionManager; | ||||
|   appState: AppState; | ||||
|   setAppState: React.Component<any, AppState>["setState"]; | ||||
|   showThemeBtn: boolean; | ||||
| }) => ( | ||||
|   <div style={{ display: "flex" }}> | ||||
|     {actionManager.renderAction("changeViewBackgroundColor")} | ||||
|     {showThemeBtn && actionManager.renderAction("toggleTheme")} | ||||
|     <div style={{ marginInlineStart: "0.25rem" }}> | ||||
|       <DarkModeToggle | ||||
|         value={appState.appearance} | ||||
|         onChange={(appearance) => { | ||||
|           setAppState({ appearance }); | ||||
|         }} | ||||
|       /> | ||||
|     </div> | ||||
|   </div> | ||||
| ); | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import clsx from "clsx"; | ||||
|  | ||||
| export const ButtonIconCycle = <T extends any>({ | ||||
| @@ -13,11 +14,11 @@ export const ButtonIconCycle = <T extends any>({ | ||||
| }) => { | ||||
|   const current = options.find((op) => op.value === value); | ||||
|  | ||||
|   const cycle = () => { | ||||
|   function cycle() { | ||||
|     const index = options.indexOf(current!); | ||||
|     const next = (index + 1) % options.length; | ||||
|     onChange(options[next].value); | ||||
|   }; | ||||
|   } | ||||
|  | ||||
|   return ( | ||||
|     <label key={group} className={clsx({ active: current!.value !== null })}> | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import clsx from "clsx"; | ||||
|  | ||||
| // TODO: It might be "clever" to add option.icon to the existing component <ButtonSelect /> | ||||
| @@ -7,7 +8,7 @@ export const ButtonIconSelect = <T extends Object>({ | ||||
|   onChange, | ||||
|   group, | ||||
| }: { | ||||
|   options: { value: T; text: string; icon: JSX.Element; testId?: string }[]; | ||||
|   options: { value: T; text: string; icon: JSX.Element }[]; | ||||
|   value: T | null; | ||||
|   onChange: (value: T) => void; | ||||
|   group: string; | ||||
| @@ -24,7 +25,6 @@ export const ButtonIconSelect = <T extends Object>({ | ||||
|           name={group} | ||||
|           onChange={() => onChange(option.value)} | ||||
|           checked={value === option.value} | ||||
|           data-testid={option.testId} | ||||
|         /> | ||||
|         {option.icon} | ||||
|       </label> | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import clsx from "clsx"; | ||||
|  | ||||
| export const ButtonSelect = <T extends Object>({ | ||||
|   | ||||
| @@ -1,57 +0,0 @@ | ||||
| @import "../css/variables.module"; | ||||
|  | ||||
| .excalidraw { | ||||
|   .Card { | ||||
|     display: flex; | ||||
|     flex-direction: column; | ||||
|     align-items: center; | ||||
|  | ||||
|     max-width: 290px; | ||||
|  | ||||
|     margin: 1em; | ||||
|  | ||||
|     text-align: center; | ||||
|  | ||||
|     .Card-icon { | ||||
|       font-size: 2.6em; | ||||
|       display: flex; | ||||
|       flex: 0 0 auto; | ||||
|       padding: 1.4rem; | ||||
|       border-radius: 50%; | ||||
|       background: var(--card-color); | ||||
|       color: $oc-white; | ||||
|  | ||||
|       svg { | ||||
|         width: 2.8rem; | ||||
|         height: 2.8rem; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     .Card-details { | ||||
|       font-size: 0.96em; | ||||
|       min-height: 90px; | ||||
|       padding: 0 1em; | ||||
|       margin-bottom: auto; | ||||
|     } | ||||
|  | ||||
|     & .Card-button.ToolIcon_type_button { | ||||
|       height: 2.5rem; | ||||
|       margin-top: 1em; | ||||
|       margin-bottom: 0.3em; | ||||
|       background-color: var(--card-color); | ||||
|       &:hover { | ||||
|         background-color: var(--card-color-darker); | ||||
|       } | ||||
|       &:active { | ||||
|         background-color: var(--card-color-darkest); | ||||
|       } | ||||
|       .ToolIcon__label { | ||||
|         color: $oc-white; | ||||
|       } | ||||
|  | ||||
|       .Spinner { | ||||
|         --spinner-color: #fff; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,27 +0,0 @@ | ||||
| import OpenColor from "open-color"; | ||||
|  | ||||
| import "./Card.scss"; | ||||
|  | ||||
| export const Card: React.FC<{ | ||||
|   color: keyof OpenColor | "primary"; | ||||
| }> = ({ children, color }) => { | ||||
|   return ( | ||||
|     <div | ||||
|       className="Card" | ||||
|       style={{ | ||||
|         ["--card-color" as any]: | ||||
|           color === "primary" ? "var(--color-primary)" : OpenColor[color][7], | ||||
|         ["--card-color-darker" as any]: | ||||
|           color === "primary" | ||||
|             ? "var(--color-primary-darker)" | ||||
|             : OpenColor[color][8], | ||||
|         ["--card-color-darkest" as any]: | ||||
|           color === "primary" | ||||
|             ? "var(--color-primary-darkest)" | ||||
|             : OpenColor[color][9], | ||||
|       }} | ||||
|     > | ||||
|       {children} | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
| @@ -1,89 +0,0 @@ | ||||
| @import "../css/variables.module"; | ||||
|  | ||||
| .excalidraw { | ||||
|   .Checkbox { | ||||
|     margin: 4px 0.3em; | ||||
|     display: flex; | ||||
|     align-items: center; | ||||
|  | ||||
|     cursor: pointer; | ||||
|     user-select: none; | ||||
|  | ||||
|     -webkit-tap-highlight-color: transparent; | ||||
|  | ||||
|     &:hover:not(.is-checked) .Checkbox-box:not(:focus) { | ||||
|       box-shadow: 0 0 0 2px #{$oc-blue-4}; | ||||
|     } | ||||
|  | ||||
|     &:hover:not(.is-checked) .Checkbox-box:not(:focus) { | ||||
|       svg { | ||||
|         display: block; | ||||
|         opacity: 0.3; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     &:active { | ||||
|       .Checkbox-box { | ||||
|         box-shadow: 0 0 2px 1px inset #{$oc-blue-7} !important; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     &:hover { | ||||
|       .Checkbox-box { | ||||
|         background-color: fade-out($oc-blue-1, 0.8); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     &.is-checked { | ||||
|       .Checkbox-box { | ||||
|         background-color: #{$oc-blue-1}; | ||||
|         svg { | ||||
|           display: block; | ||||
|         } | ||||
|       } | ||||
|       &:hover .Checkbox-box { | ||||
|         background-color: #{$oc-blue-2}; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     .Checkbox-box { | ||||
|       width: 22px; | ||||
|       height: 22px; | ||||
|       padding: 0; | ||||
|       flex: 0 0 auto; | ||||
|  | ||||
|       margin: 0 1em; | ||||
|  | ||||
|       display: flex; | ||||
|       align-items: center; | ||||
|       justify-content: center; | ||||
|  | ||||
|       box-shadow: 0 0 0 2px #{$oc-blue-7}; | ||||
|       background-color: transparent; | ||||
|       border-radius: 4px; | ||||
|  | ||||
|       color: #{$oc-blue-7}; | ||||
|  | ||||
|       &:focus { | ||||
|         box-shadow: 0 0 0 3px #{$oc-blue-7}; | ||||
|       } | ||||
|  | ||||
|       svg { | ||||
|         display: none; | ||||
|         width: 16px; | ||||
|         height: 16px; | ||||
|         stroke-width: 3px; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     .Checkbox-label { | ||||
|       display: flex; | ||||
|       align-items: center; | ||||
|     } | ||||
|  | ||||
|     .excalidraw-tooltip-icon { | ||||
|       width: 1em; | ||||
|       height: 1em; | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,30 +0,0 @@ | ||||
| import React from "react"; | ||||
| import clsx from "clsx"; | ||||
| import { checkIcon } from "./icons"; | ||||
|  | ||||
| import "./CheckboxItem.scss"; | ||||
|  | ||||
| export const CheckboxItem: React.FC<{ | ||||
|   checked: boolean; | ||||
|   onChange: (checked: boolean, event: React.MouseEvent) => void; | ||||
|   className?: string; | ||||
| }> = ({ children, checked, onChange, className }) => { | ||||
|   return ( | ||||
|     <div | ||||
|       className={clsx("Checkbox", className, { "is-checked": checked })} | ||||
|       onClick={(event) => { | ||||
|         onChange(!checked, event); | ||||
|         ( | ||||
|           (event.currentTarget as HTMLDivElement).querySelector( | ||||
|             ".Checkbox-box", | ||||
|           ) as HTMLButtonElement | ||||
|         ).focus(); | ||||
|       }} | ||||
|     > | ||||
|       <button className="Checkbox-box" role="checkbox" aria-checked={checked}> | ||||
|         {checkIcon} | ||||
|       </button> | ||||
|       <div className="Checkbox-label">{children}</div> | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
| @@ -1,43 +0,0 @@ | ||||
| import { useState } from "react"; | ||||
| import { t } from "../i18n"; | ||||
| import { useDeviceType } from "./App"; | ||||
| import { trash } from "./icons"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
|  | ||||
| import ConfirmDialog from "./ConfirmDialog"; | ||||
|  | ||||
| const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => { | ||||
|   const [showDialog, setShowDialog] = useState(false); | ||||
|   const toggleDialog = () => { | ||||
|     setShowDialog(!showDialog); | ||||
|   }; | ||||
|  | ||||
|   return ( | ||||
|     <> | ||||
|       <ToolButton | ||||
|         type="button" | ||||
|         icon={trash} | ||||
|         title={t("buttons.clearReset")} | ||||
|         aria-label={t("buttons.clearReset")} | ||||
|         showAriaLabel={useDeviceType().isMobile} | ||||
|         onClick={toggleDialog} | ||||
|         data-testid="clear-canvas-button" | ||||
|       /> | ||||
|  | ||||
|       {showDialog && ( | ||||
|         <ConfirmDialog | ||||
|           onConfirm={() => { | ||||
|             onConfirm(); | ||||
|             toggleDialog(); | ||||
|           }} | ||||
|           onCancel={toggleDialog} | ||||
|           title={t("clearCanvasDialog.title")} | ||||
|         > | ||||
|           <p className="clear-canvas__content"> {t("alerts.clearReset")}</p> | ||||
|         </ConfirmDialog> | ||||
|       )} | ||||
|     </> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| export default ClearCanvas; | ||||
| @@ -1,7 +1,8 @@ | ||||
| import React from "react"; | ||||
| import clsx from "clsx"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
| import { t } from "../i18n"; | ||||
| import { useDeviceType } from "../components/App"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { users } from "./icons"; | ||||
|  | ||||
| import "./CollabButton.scss"; | ||||
| @@ -26,7 +27,7 @@ const CollabButton = ({ | ||||
|         type="button" | ||||
|         title={t("labels.liveCollaboration")} | ||||
|         aria-label={t("labels.liveCollaboration")} | ||||
|         showAriaLabel={useDeviceType().isMobile} | ||||
|         showAriaLabel={useIsMobile()} | ||||
|       > | ||||
|         {collaboratorCount > 0 && ( | ||||
|           <div className="CollabButton-collaborators">{collaboratorCount}</div> | ||||
|   | ||||
| @@ -46,7 +46,7 @@ | ||||
|     top: -11px; | ||||
|   } | ||||
|  | ||||
|   .color-picker-content--default { | ||||
|   .color-picker-content { | ||||
|     padding: 0.5rem; | ||||
|     display: grid; | ||||
|     grid-template-columns: repeat(5, auto); | ||||
| @@ -59,26 +59,6 @@ | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   .color-picker-content--canvas { | ||||
|     display: flex; | ||||
|     flex-direction: column; | ||||
|     padding: 0.25rem; | ||||
|  | ||||
|     &-title { | ||||
|       color: $oc-gray-6; | ||||
|       font-size: 12px; | ||||
|       padding: 0 0.25rem; | ||||
|     } | ||||
|  | ||||
|     &-colors { | ||||
|       padding: 0.5rem 0; | ||||
|  | ||||
|       .color-picker-swatch { | ||||
|         margin: 0 0.25rem; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   .color-picker-content .color-input-container { | ||||
|     grid-column: 1 / span 5; | ||||
|   } | ||||
| @@ -93,7 +73,7 @@ | ||||
|     box-sizing: border-box; | ||||
|     border: 1px solid #ddd; | ||||
|     background-color: currentColor !important; | ||||
|     filter: var(--theme-filter); | ||||
|     filter: var(--appearance-filter); | ||||
|  | ||||
|     &:focus { | ||||
|       /* TODO: only show the border when the color is too light to see as a shadow */ | ||||
| @@ -180,7 +160,7 @@ | ||||
|   } | ||||
|  | ||||
|   .color-picker-input { | ||||
|     width: 11ch; /* length of `transparent` */ | ||||
|     width: 12ch; /* length of `transparent` + 1 */ | ||||
|     margin: 0; | ||||
|     font-size: 1rem; | ||||
|     background-color: var(--input-bg-color); | ||||
| @@ -212,7 +192,7 @@ | ||||
|     position: relative; | ||||
|     overflow: hidden; | ||||
|     background-color: transparent !important; | ||||
|     filter: var(--theme-filter); | ||||
|     filter: var(--appearance-filter); | ||||
|  | ||||
|     &:after { | ||||
|       content: ""; | ||||
| @@ -238,7 +218,7 @@ | ||||
|       left: 2px; | ||||
|     } | ||||
|  | ||||
|     @include isMobile { | ||||
|     @media #{$is-mobile-query} { | ||||
|       display: none; | ||||
|     } | ||||
|   } | ||||
| @@ -259,7 +239,7 @@ | ||||
|     color: #d4d4d4; | ||||
|   } | ||||
|  | ||||
|   &.theme--dark { | ||||
|   &.Appearance_dark { | ||||
|     .color-picker-type-elementBackground .color-picker-keybinding { | ||||
|       color: $oc-black; | ||||
|     } | ||||
|   | ||||
| @@ -1,59 +1,11 @@ | ||||
| import React from "react"; | ||||
| import { Popover } from "./Popover"; | ||||
| import { isTransparent } from "../utils"; | ||||
|  | ||||
| import "./ColorPicker.scss"; | ||||
| import { isArrowKey, KEYS } from "../keys"; | ||||
| import { t, getLanguage } from "../i18n"; | ||||
| import { isWritableElement } from "../utils"; | ||||
| import colors from "../colors"; | ||||
| import { ExcalidrawElement } from "../element/types"; | ||||
| import { AppState } from "../types"; | ||||
|  | ||||
| const MAX_CUSTOM_COLORS = 5; | ||||
| const MAX_DEFAULT_COLORS = 15; | ||||
|  | ||||
| export const getCustomColors = ( | ||||
|   elements: readonly ExcalidrawElement[], | ||||
|   type: "elementBackground" | "elementStroke", | ||||
| ) => { | ||||
|   const customColors: string[] = []; | ||||
|   const updatedElements = elements | ||||
|     .filter((element) => !element.isDeleted) | ||||
|     .sort((ele1, ele2) => ele2.updated - ele1.updated); | ||||
|  | ||||
|   let index = 0; | ||||
|   const elementColorTypeMap = { | ||||
|     elementBackground: "backgroundColor", | ||||
|     elementStroke: "strokeColor", | ||||
|   }; | ||||
|   const colorType = elementColorTypeMap[type] as | ||||
|     | "backgroundColor" | ||||
|     | "strokeColor"; | ||||
|   while ( | ||||
|     index < updatedElements.length && | ||||
|     customColors.length < MAX_CUSTOM_COLORS | ||||
|   ) { | ||||
|     const element = updatedElements[index]; | ||||
|  | ||||
|     if ( | ||||
|       customColors.length < MAX_CUSTOM_COLORS && | ||||
|       isCustomColor(element[colorType], type) && | ||||
|       !customColors.includes(element[colorType]) | ||||
|     ) { | ||||
|       customColors.push(element[colorType]); | ||||
|     } | ||||
|     index++; | ||||
|   } | ||||
|   return customColors; | ||||
| }; | ||||
|  | ||||
| const isCustomColor = ( | ||||
|   color: string, | ||||
|   type: "elementBackground" | "elementStroke", | ||||
| ) => { | ||||
|   return !colors[type].includes(color); | ||||
| }; | ||||
|  | ||||
| const isValidColor = (color: string) => { | ||||
|   const style = new Option().style; | ||||
| @@ -62,7 +14,7 @@ const isValidColor = (color: string) => { | ||||
| }; | ||||
|  | ||||
| const getColor = (color: string): string | null => { | ||||
|   if (isTransparent(color)) { | ||||
|   if (color === "transparent") { | ||||
|     return color; | ||||
|   } | ||||
|  | ||||
| @@ -82,7 +34,6 @@ const keyBindings = [ | ||||
|   ["1", "2", "3", "4", "5"], | ||||
|   ["q", "w", "e", "r", "t"], | ||||
|   ["a", "s", "d", "f", "g"], | ||||
|   ["z", "x", "c", "v", "b"], | ||||
| ].flat(); | ||||
|  | ||||
| const Picker = ({ | ||||
| @@ -93,7 +44,6 @@ const Picker = ({ | ||||
|   label, | ||||
|   showInput = true, | ||||
|   type, | ||||
|   elements, | ||||
| }: { | ||||
|   colors: string[]; | ||||
|   color: string | null; | ||||
| @@ -102,20 +52,12 @@ const Picker = ({ | ||||
|   label: string; | ||||
|   showInput: boolean; | ||||
|   type: "canvasBackground" | "elementBackground" | "elementStroke"; | ||||
|   elements: readonly ExcalidrawElement[]; | ||||
| }) => { | ||||
|   const firstItem = React.useRef<HTMLButtonElement>(); | ||||
|   const activeItem = React.useRef<HTMLButtonElement>(); | ||||
|   const gallery = React.useRef<HTMLDivElement>(); | ||||
|   const colorInput = React.useRef<HTMLInputElement>(); | ||||
|  | ||||
|   const [customColors] = React.useState(() => { | ||||
|     if (type === "canvasBackground") { | ||||
|       return []; | ||||
|     } | ||||
|     return getCustomColors(elements, type); | ||||
|   }); | ||||
|  | ||||
|   React.useEffect(() => { | ||||
|     // After the component is first mounted focus on first input | ||||
|     if (activeItem.current) { | ||||
| @@ -142,42 +84,23 @@ const Picker = ({ | ||||
|     } else if (isArrowKey(event.key)) { | ||||
|       const { activeElement } = document; | ||||
|       const isRTL = getLanguage().rtl; | ||||
|       let isCustom = false; | ||||
|       let index = Array.prototype.indexOf.call( | ||||
|         gallery!.current!.querySelector(".color-picker-content--default")! | ||||
|           .children, | ||||
|       const index = Array.prototype.indexOf.call( | ||||
|         gallery!.current!.children, | ||||
|         activeElement, | ||||
|       ); | ||||
|       if (index === -1) { | ||||
|         index = Array.prototype.indexOf.call( | ||||
|           gallery!.current!.querySelector( | ||||
|             ".color-picker-content--canvas-colors", | ||||
|           )!.children, | ||||
|           activeElement, | ||||
|         ); | ||||
|         if (index !== -1) { | ||||
|           isCustom = true; | ||||
|         } | ||||
|       } | ||||
|       const parentSelector = isCustom | ||||
|         ? gallery!.current!.querySelector( | ||||
|             ".color-picker-content--canvas-colors", | ||||
|           )! | ||||
|         : gallery!.current!.querySelector(".color-picker-content--default")!; | ||||
|  | ||||
|       if (index !== -1) { | ||||
|         const length = parentSelector!.children.length - (showInput ? 1 : 0); | ||||
|         const length = gallery!.current!.children.length - (showInput ? 1 : 0); | ||||
|         const nextIndex = | ||||
|           event.key === (isRTL ? KEYS.ARROW_LEFT : KEYS.ARROW_RIGHT) | ||||
|             ? (index + 1) % length | ||||
|             : event.key === (isRTL ? KEYS.ARROW_RIGHT : KEYS.ARROW_LEFT) | ||||
|             ? (length + index - 1) % length | ||||
|             : !isCustom && event.key === KEYS.ARROW_DOWN | ||||
|             : event.key === KEYS.ARROW_DOWN | ||||
|             ? (index + 5) % length | ||||
|             : !isCustom && event.key === KEYS.ARROW_UP | ||||
|             : event.key === KEYS.ARROW_UP | ||||
|             ? (length + index - 5) % length | ||||
|             : index; | ||||
|         (parentSelector!.children![nextIndex] as HTMLElement)?.focus(); | ||||
|         (gallery!.current!.children![nextIndex] as any).focus(); | ||||
|       } | ||||
|       event.preventDefault(); | ||||
|     } else if ( | ||||
| @@ -185,66 +108,13 @@ const Picker = ({ | ||||
|       !isWritableElement(event.target) | ||||
|     ) { | ||||
|       const index = keyBindings.indexOf(event.key.toLowerCase()); | ||||
|       const isCustom = index >= MAX_DEFAULT_COLORS; | ||||
|       const parentSelector = isCustom | ||||
|         ? gallery!.current!.querySelector( | ||||
|             ".color-picker-content--canvas-colors", | ||||
|           )! | ||||
|         : gallery!.current!.querySelector(".color-picker-content--default")!; | ||||
|       const actualIndex = isCustom ? index - MAX_DEFAULT_COLORS : index; | ||||
|       (parentSelector!.children![actualIndex] as HTMLElement)?.focus(); | ||||
|  | ||||
|       (gallery!.current!.children![index] as any).focus(); | ||||
|       event.preventDefault(); | ||||
|     } else if (event.key === KEYS.ESCAPE || event.key === KEYS.ENTER) { | ||||
|       event.preventDefault(); | ||||
|       onClose(); | ||||
|     } | ||||
|     event.nativeEvent.stopImmediatePropagation(); | ||||
|     event.stopPropagation(); | ||||
|   }; | ||||
|  | ||||
|   const renderColors = (colors: Array<string>, custom: boolean = false) => { | ||||
|     return colors.map((_color, i) => { | ||||
|       const _colorWithoutHash = _color.replace("#", ""); | ||||
|       const keyBinding = custom | ||||
|         ? keyBindings[i + MAX_DEFAULT_COLORS] | ||||
|         : keyBindings[i]; | ||||
|       const label = custom | ||||
|         ? _colorWithoutHash | ||||
|         : t(`colors.${_colorWithoutHash}`); | ||||
|       return ( | ||||
|         <button | ||||
|           className="color-picker-swatch" | ||||
|           onClick={(event) => { | ||||
|             (event.currentTarget as HTMLButtonElement).focus(); | ||||
|             onChange(_color); | ||||
|           }} | ||||
|           title={`${label}${ | ||||
|             !isTransparent(_color) ? ` (${_color})` : "" | ||||
|           } — ${keyBinding.toUpperCase()}`} | ||||
|           aria-label={label} | ||||
|           aria-keyshortcuts={keyBindings[i]} | ||||
|           style={{ color: _color }} | ||||
|           key={_color} | ||||
|           ref={(el) => { | ||||
|             if (!custom && el && i === 0) { | ||||
|               firstItem.current = el; | ||||
|             } | ||||
|             if (el && _color === color) { | ||||
|               activeItem.current = el; | ||||
|             } | ||||
|           }} | ||||
|           onFocus={() => { | ||||
|             onChange(_color); | ||||
|           }} | ||||
|         > | ||||
|           {isTransparent(_color) ? ( | ||||
|             <div className="color-picker-transparent"></div> | ||||
|           ) : undefined} | ||||
|           <span className="color-picker-keybinding">{keyBinding}</span> | ||||
|         </button> | ||||
|       ); | ||||
|     }); | ||||
|   }; | ||||
|  | ||||
|   return ( | ||||
| @@ -266,20 +136,36 @@ const Picker = ({ | ||||
|         }} | ||||
|         tabIndex={0} | ||||
|       > | ||||
|         <div className="color-picker-content--default"> | ||||
|           {renderColors(colors)} | ||||
|         </div> | ||||
|         {!!customColors.length && ( | ||||
|           <div className="color-picker-content--canvas"> | ||||
|             <span className="color-picker-content--canvas-title"> | ||||
|               {t("labels.canvasColors")} | ||||
|             </span> | ||||
|             <div className="color-picker-content--canvas-colors"> | ||||
|               {renderColors(customColors, true)} | ||||
|             </div> | ||||
|           </div> | ||||
|         )} | ||||
|  | ||||
|         {colors.map((_color, i) => ( | ||||
|           <button | ||||
|             className="color-picker-swatch" | ||||
|             onClick={(event) => { | ||||
|               (event.currentTarget as HTMLButtonElement).focus(); | ||||
|               onChange(_color); | ||||
|             }} | ||||
|             title={`${_color} — ${keyBindings[i].toUpperCase()}`} | ||||
|             aria-label={_color} | ||||
|             aria-keyshortcuts={keyBindings[i]} | ||||
|             style={{ color: _color }} | ||||
|             key={_color} | ||||
|             ref={(el) => { | ||||
|               if (el && i === 0) { | ||||
|                 firstItem.current = el; | ||||
|               } | ||||
|               if (el && _color === color) { | ||||
|                 activeItem.current = el; | ||||
|               } | ||||
|             }} | ||||
|             onFocus={() => { | ||||
|               onChange(_color); | ||||
|             }} | ||||
|           > | ||||
|             {_color === "transparent" ? ( | ||||
|               <div className="color-picker-transparent"></div> | ||||
|             ) : undefined} | ||||
|             <span className="color-picker-keybinding">{keyBindings[i]}</span> | ||||
|           </button> | ||||
|         ))} | ||||
|         {showInput && ( | ||||
|           <ColorInput | ||||
|             color={color} | ||||
| @@ -351,20 +237,13 @@ export const ColorPicker = ({ | ||||
|   color, | ||||
|   onChange, | ||||
|   label, | ||||
|   isActive, | ||||
|   setActive, | ||||
|   elements, | ||||
|   appState, | ||||
| }: { | ||||
|   type: "canvasBackground" | "elementBackground" | "elementStroke"; | ||||
|   color: string | null; | ||||
|   onChange: (color: string) => void; | ||||
|   label: string; | ||||
|   isActive: boolean; | ||||
|   setActive: (active: boolean) => void; | ||||
|   elements: readonly ExcalidrawElement[]; | ||||
|   appState: AppState; | ||||
| }) => { | ||||
|   const [isActive, setActive] = React.useState(false); | ||||
|   const pickerButton = React.useRef<HTMLButtonElement>(null); | ||||
|  | ||||
|   return ( | ||||
| @@ -405,7 +284,6 @@ export const ColorPicker = ({ | ||||
|               label={label} | ||||
|               showInput={false} | ||||
|               type={type} | ||||
|               elements={elements} | ||||
|             /> | ||||
|           </Popover> | ||||
|         ) : null} | ||||
|   | ||||
| @@ -1,37 +0,0 @@ | ||||
| @import "../css/variables.module"; | ||||
|  | ||||
| .excalidraw { | ||||
|   .confirm-dialog { | ||||
|     &-buttons { | ||||
|       display: flex; | ||||
|       padding: 0.2rem 0; | ||||
|       justify-content: flex-end; | ||||
|     } | ||||
|     .ToolIcon__icon { | ||||
|       min-width: 2.5rem; | ||||
|       width: auto; | ||||
|       font-size: 1rem; | ||||
|     } | ||||
|  | ||||
|     .ToolIcon_type_button { | ||||
|       margin-left: 0.8rem; | ||||
|       padding: 0 0.5rem; | ||||
|     } | ||||
|  | ||||
|     &__content { | ||||
|       font-size: 1rem; | ||||
|     } | ||||
|  | ||||
|     &--confirm.ToolIcon_type_button { | ||||
|       background-color: $oc-red-6; | ||||
|  | ||||
|       &:hover { | ||||
|         background-color: $oc-red-8; | ||||
|       } | ||||
|  | ||||
|       .ToolIcon__icon { | ||||
|         color: $oc-white; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
| @@ -1,52 +0,0 @@ | ||||
| import { t } from "../i18n"; | ||||
| import { Dialog, DialogProps } from "./Dialog"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
|  | ||||
| import "./ConfirmDialog.scss"; | ||||
|  | ||||
| interface Props extends Omit<DialogProps, "onCloseRequest"> { | ||||
|   onConfirm: () => void; | ||||
|   onCancel: () => void; | ||||
|   confirmText?: string; | ||||
|   cancelText?: string; | ||||
| } | ||||
| const ConfirmDialog = (props: Props) => { | ||||
|   const { | ||||
|     onConfirm, | ||||
|     onCancel, | ||||
|     children, | ||||
|     confirmText = t("buttons.confirm"), | ||||
|     cancelText = t("buttons.cancel"), | ||||
|     className = "", | ||||
|     ...rest | ||||
|   } = props; | ||||
|   return ( | ||||
|     <Dialog | ||||
|       onCloseRequest={onCancel} | ||||
|       small={true} | ||||
|       {...rest} | ||||
|       className={`confirm-dialog ${className}`} | ||||
|     > | ||||
|       {children} | ||||
|       <div className="confirm-dialog-buttons"> | ||||
|         <ToolButton | ||||
|           type="button" | ||||
|           title={cancelText} | ||||
|           aria-label={cancelText} | ||||
|           label={cancelText} | ||||
|           onClick={onCancel} | ||||
|           className="confirm-dialog--cancel" | ||||
|         /> | ||||
|         <ToolButton | ||||
|           type="button" | ||||
|           title={confirmText} | ||||
|           aria-label={confirmText} | ||||
|           label={confirmText} | ||||
|           onClick={onConfirm} | ||||
|           className="confirm-dialog--confirm" | ||||
|         /> | ||||
|       </div> | ||||
|     </Dialog> | ||||
|   ); | ||||
| }; | ||||
| export default ConfirmDialog; | ||||
| @@ -76,7 +76,7 @@ | ||||
|     z-index: 1; | ||||
|   } | ||||
|  | ||||
|   @include isMobile { | ||||
|   @media #{$is-mobile-query} { | ||||
|     .context-menu-option { | ||||
|       display: block; | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,4 @@ | ||||
| import React from "react"; | ||||
| import { render, unmountComponentAtNode } from "react-dom"; | ||||
| import clsx from "clsx"; | ||||
| import { Popover } from "./Popover"; | ||||
| @@ -11,7 +12,6 @@ import { | ||||
| import { Action } from "../actions/types"; | ||||
| import { ActionManager } from "../actions/manager"; | ||||
| import { AppState } from "../types"; | ||||
| import { NonDeletedExcalidrawElement } from "../element/types"; | ||||
|  | ||||
| export type ContextMenuOption = "separator" | Action; | ||||
|  | ||||
| @@ -22,7 +22,6 @@ type ContextMenuProps = { | ||||
|   left: number; | ||||
|   actionManager: ActionManager; | ||||
|   appState: Readonly<AppState>; | ||||
|   elements: readonly NonDeletedExcalidrawElement[]; | ||||
| }; | ||||
|  | ||||
| const ContextMenu = ({ | ||||
| @@ -32,76 +31,68 @@ const ContextMenu = ({ | ||||
|   left, | ||||
|   actionManager, | ||||
|   appState, | ||||
|   elements, | ||||
| }: ContextMenuProps) => { | ||||
|   const isDarkTheme = !!document | ||||
|     .querySelector(".excalidraw") | ||||
|     ?.classList.contains("Appearance_dark"); | ||||
|   return ( | ||||
|     <Popover | ||||
|       onCloseRequest={onCloseRequest} | ||||
|       top={top} | ||||
|       left={left} | ||||
|       fitInViewport={true} | ||||
|       offsetLeft={appState.offsetLeft} | ||||
|       offsetTop={appState.offsetTop} | ||||
|       viewportWidth={appState.width} | ||||
|       viewportHeight={appState.height} | ||||
|     <div | ||||
|       className={clsx("excalidraw", { | ||||
|         "Appearance_dark Appearance_dark-background-none": isDarkTheme, | ||||
|       })} | ||||
|     > | ||||
|       <ul | ||||
|         className="context-menu" | ||||
|         onContextMenu={(event) => event.preventDefault()} | ||||
|       <Popover | ||||
|         onCloseRequest={onCloseRequest} | ||||
|         top={top} | ||||
|         left={left} | ||||
|         fitInViewport={true} | ||||
|       > | ||||
|         {options.map((option, idx) => { | ||||
|           if (option === "separator") { | ||||
|             return <hr key={idx} className="context-menu-option-separator" />; | ||||
|           } | ||||
|  | ||||
|           const actionName = option.name; | ||||
|           let label = ""; | ||||
|           if (option.contextItemLabel) { | ||||
|             if (typeof option.contextItemLabel === "function") { | ||||
|               label = t(option.contextItemLabel(elements, appState)); | ||||
|             } else { | ||||
|               label = t(option.contextItemLabel); | ||||
|         <ul | ||||
|           className="context-menu" | ||||
|           onContextMenu={(event) => event.preventDefault()} | ||||
|         > | ||||
|           {options.map((option, idx) => { | ||||
|             if (option === "separator") { | ||||
|               return <hr key={idx} className="context-menu-option-separator" />; | ||||
|             } | ||||
|           } | ||||
|           return ( | ||||
|             <li key={idx} data-testid={actionName} onClick={onCloseRequest}> | ||||
|               <button | ||||
|                 className={clsx("context-menu-option", { | ||||
|                   dangerous: actionName === "deleteSelectedElements", | ||||
|                   checkmark: option.checked?.(appState), | ||||
|                 })} | ||||
|                 onClick={() => | ||||
|                   actionManager.executeAction(option, "contextMenu") | ||||
|                 } | ||||
|               > | ||||
|                 <div className="context-menu-option__label">{label}</div> | ||||
|                 <kbd className="context-menu-option__shortcut"> | ||||
|                   {actionName | ||||
|                     ? getShortcutFromShortcutName(actionName as ShortcutName) | ||||
|                     : ""} | ||||
|                 </kbd> | ||||
|               </button> | ||||
|             </li> | ||||
|           ); | ||||
|         })} | ||||
|       </ul> | ||||
|     </Popover> | ||||
|  | ||||
|             const actionName = option.name; | ||||
|             const label = option.contextItemLabel | ||||
|               ? t(option.contextItemLabel) | ||||
|               : ""; | ||||
|             return ( | ||||
|               <li key={idx} data-testid={actionName} onClick={onCloseRequest}> | ||||
|                 <button | ||||
|                   className={clsx("context-menu-option", { | ||||
|                     dangerous: actionName === "deleteSelectedElements", | ||||
|                     checkmark: option.checked?.(appState), | ||||
|                   })} | ||||
|                   onClick={() => actionManager.executeAction(option)} | ||||
|                 > | ||||
|                   <div className="context-menu-option__label">{label}</div> | ||||
|                   <kbd className="context-menu-option__shortcut"> | ||||
|                     {actionName | ||||
|                       ? getShortcutFromShortcutName(actionName as ShortcutName) | ||||
|                       : ""} | ||||
|                   </kbd> | ||||
|                 </button> | ||||
|               </li> | ||||
|             ); | ||||
|           })} | ||||
|         </ul> | ||||
|       </Popover> | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const contextMenuNodeByContainer = new WeakMap<HTMLElement, HTMLDivElement>(); | ||||
|  | ||||
| const getContextMenuNode = (container: HTMLElement): HTMLDivElement => { | ||||
|   let contextMenuNode = contextMenuNodeByContainer.get(container); | ||||
| let contextMenuNode: HTMLDivElement; | ||||
| const getContextMenuNode = (): HTMLDivElement => { | ||||
|   if (contextMenuNode) { | ||||
|     return contextMenuNode; | ||||
|   } | ||||
|   contextMenuNode = document.createElement("div"); | ||||
|   container | ||||
|     .querySelector(".excalidraw-contextMenuContainer")! | ||||
|     .appendChild(contextMenuNode); | ||||
|   contextMenuNodeByContainer.set(container, contextMenuNode); | ||||
|   return contextMenuNode; | ||||
|   const div = document.createElement("div"); | ||||
|   document.body.appendChild(div); | ||||
|   return (contextMenuNode = div); | ||||
| }; | ||||
|  | ||||
| type ContextMenuParams = { | ||||
| @@ -110,17 +101,10 @@ type ContextMenuParams = { | ||||
|   left: ContextMenuProps["left"]; | ||||
|   actionManager: ContextMenuProps["actionManager"]; | ||||
|   appState: Readonly<AppState>; | ||||
|   container: HTMLElement; | ||||
|   elements: readonly NonDeletedExcalidrawElement[]; | ||||
| }; | ||||
|  | ||||
| const handleClose = (container: HTMLElement) => { | ||||
|   const contextMenuNode = contextMenuNodeByContainer.get(container); | ||||
|   if (contextMenuNode) { | ||||
|     unmountComponentAtNode(contextMenuNode); | ||||
|     contextMenuNode.remove(); | ||||
|     contextMenuNodeByContainer.delete(container); | ||||
|   } | ||||
| const handleClose = () => { | ||||
|   unmountComponentAtNode(getContextMenuNode()); | ||||
| }; | ||||
|  | ||||
| export default { | ||||
| @@ -137,12 +121,11 @@ export default { | ||||
|           top={params.top} | ||||
|           left={params.left} | ||||
|           options={options} | ||||
|           onCloseRequest={() => handleClose(params.container)} | ||||
|           onCloseRequest={handleClose} | ||||
|           actionManager={params.actionManager} | ||||
|           appState={params.appState} | ||||
|           elements={params.elements} | ||||
|         />, | ||||
|         getContextMenuNode(params.container), | ||||
|         getContextMenuNode(), | ||||
|       ); | ||||
|     } | ||||
|   }, | ||||
|   | ||||
| @@ -1,32 +1,41 @@ | ||||
| import "./ToolIcon.scss"; | ||||
|  | ||||
| import React from "react"; | ||||
| import { t } from "../i18n"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
| import { THEME } from "../constants"; | ||||
| import { Theme } from "../element/types"; | ||||
|  | ||||
| export type Appearence = "light" | "dark"; | ||||
|  | ||||
| // We chose to use only explicit toggle and not a third option for system value, | ||||
| // but this could be added in the future. | ||||
| export const DarkModeToggle = (props: { | ||||
|   value: Theme; | ||||
|   onChange: (value: Theme) => void; | ||||
|   value: Appearence; | ||||
|   onChange: (value: Appearence) => void; | ||||
|   title?: string; | ||||
| }) => { | ||||
|   const title = | ||||
|     props.title || | ||||
|     (props.value === "dark" ? t("buttons.lightMode") : t("buttons.darkMode")); | ||||
|   const title = props.title | ||||
|     ? props.title | ||||
|     : props.value === "dark" | ||||
|     ? t("buttons.lightMode") | ||||
|     : t("buttons.darkMode"); | ||||
|  | ||||
|   return ( | ||||
|     <ToolButton | ||||
|       type="icon" | ||||
|       icon={props.value === THEME.LIGHT ? ICONS.MOON : ICONS.SUN} | ||||
|     <label | ||||
|       className={`ToolIcon ToolIcon_type_floating ToolIcon_size_M`} | ||||
|       title={title} | ||||
|       aria-label={title} | ||||
|       onClick={() => | ||||
|         props.onChange(props.value === THEME.DARK ? THEME.LIGHT : THEME.DARK) | ||||
|       } | ||||
|       data-testid="toggle-dark-mode" | ||||
|     /> | ||||
|     > | ||||
|       <input | ||||
|         className="ToolIcon_type_checkbox ToolIcon_toggle_opaque" | ||||
|         type="checkbox" | ||||
|         onChange={(event) => | ||||
|           props.onChange(event.target.checked ? "dark" : "light") | ||||
|         } | ||||
|         checked={props.value === "dark"} | ||||
|         aria-label={title} | ||||
|       /> | ||||
|       <div className="ToolIcon__icon"> | ||||
|         {props.value === "light" ? ICONS.MOON : ICONS.SUN} | ||||
|       </div> | ||||
|     </label> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -31,7 +31,7 @@ | ||||
|     padding: 0 16px 16px; | ||||
|   } | ||||
|  | ||||
|   @include isMobile { | ||||
|   @media #{$is-mobile-query} { | ||||
|     .Dialog { | ||||
|       --metric: calc(var(--space-factor) * 4); | ||||
|       --inset-left: #{"max(var(--metric), var(--sal))"}; | ||||
|   | ||||
| @@ -1,30 +1,23 @@ | ||||
| import clsx from "clsx"; | ||||
| import React, { useEffect, useState } from "react"; | ||||
| import React, { useEffect } from "react"; | ||||
| import { useCallbackRefState } from "../hooks/useCallbackRefState"; | ||||
| import { t } from "../i18n"; | ||||
| import { useExcalidrawContainer, useDeviceType } from "../components/App"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { KEYS } from "../keys"; | ||||
| import "./Dialog.scss"; | ||||
| import { back, close } from "./icons"; | ||||
| import { Island } from "./Island"; | ||||
| import { Modal } from "./Modal"; | ||||
| import { AppState } from "../types"; | ||||
|  | ||||
| export interface DialogProps { | ||||
| export const Dialog = (props: { | ||||
|   children: React.ReactNode; | ||||
|   className?: string; | ||||
|   small?: boolean; | ||||
|   onCloseRequest(): void; | ||||
|   title: React.ReactNode; | ||||
|   autofocus?: boolean; | ||||
|   theme?: AppState["theme"]; | ||||
|   closeOnClickOutside?: boolean; | ||||
| } | ||||
|  | ||||
| export const Dialog = (props: DialogProps) => { | ||||
| }) => { | ||||
|   const [islandNode, setIslandNode] = useCallbackRefState<HTMLDivElement>(); | ||||
|   const [lastActiveElement] = useState(document.activeElement); | ||||
|   const { id } = useExcalidrawContainer(); | ||||
|  | ||||
|   useEffect(() => { | ||||
|     if (!islandNode) { | ||||
| @@ -72,29 +65,22 @@ export const Dialog = (props: DialogProps) => { | ||||
|     return focusableElements ? Array.from(focusableElements) : []; | ||||
|   }; | ||||
|  | ||||
|   const onClose = () => { | ||||
|     (lastActiveElement as HTMLElement).focus(); | ||||
|     props.onCloseRequest(); | ||||
|   }; | ||||
|  | ||||
|   return ( | ||||
|     <Modal | ||||
|       className={clsx("Dialog", props.className)} | ||||
|       labelledBy="dialog-title" | ||||
|       maxWidth={props.small ? 550 : 800} | ||||
|       onCloseRequest={onClose} | ||||
|       theme={props.theme} | ||||
|       closeOnClickOutside={props.closeOnClickOutside} | ||||
|       onCloseRequest={props.onCloseRequest} | ||||
|     > | ||||
|       <Island ref={setIslandNode}> | ||||
|         <h2 id={`${id}-dialog-title`} className="Dialog__title"> | ||||
|         <h2 id="dialog-title" className="Dialog__title"> | ||||
|           <span className="Dialog__titleContent">{props.title}</span> | ||||
|           <button | ||||
|             className="Modal__close" | ||||
|             onClick={onClose} | ||||
|             onClick={props.onCloseRequest} | ||||
|             aria-label={t("buttons.close")} | ||||
|           > | ||||
|             {useDeviceType().isMobile ? back : close} | ||||
|             {useIsMobile() ? back : close} | ||||
|           </button> | ||||
|         </h2> | ||||
|         <div className="Dialog__content">{props.children}</div> | ||||
|   | ||||
| @@ -2,7 +2,6 @@ import React, { useState } from "react"; | ||||
| import { t } from "../i18n"; | ||||
|  | ||||
| import { Dialog } from "./Dialog"; | ||||
| import { useExcalidrawContainer } from "./App"; | ||||
|  | ||||
| export const ErrorDialog = ({ | ||||
|   message, | ||||
| @@ -12,7 +11,6 @@ export const ErrorDialog = ({ | ||||
|   onClose?: () => void; | ||||
| }) => { | ||||
|   const [modalIsShown, setModalIsShown] = useState(!!message); | ||||
|   const { container: excalidrawContainer } = useExcalidrawContainer(); | ||||
|  | ||||
|   const handleClose = React.useCallback(() => { | ||||
|     setModalIsShown(false); | ||||
| @@ -20,9 +18,7 @@ export const ErrorDialog = ({ | ||||
|     if (onClose) { | ||||
|       onClose(); | ||||
|     } | ||||
|     // TODO: Fix the A11y issues so this is never needed since we should always focus on last active element | ||||
|     excalidrawContainer?.focus(); | ||||
|   }, [onClose, excalidrawContainer]); | ||||
|   }, [onClose]); | ||||
|  | ||||
|   return ( | ||||
|     <> | ||||
| @@ -32,7 +28,14 @@ export const ErrorDialog = ({ | ||||
|           onCloseRequest={handleClose} | ||||
|           title={t("errorDialog.title")} | ||||
|         > | ||||
|           <div style={{ whiteSpace: "pre-wrap" }}>{message}</div> | ||||
|           <div> | ||||
|             {message.split("\n").map((line) => ( | ||||
|               <> | ||||
|                 {line} | ||||
|                 <br /> | ||||
|               </> | ||||
|             ))} | ||||
|           </div> | ||||
|         </Dialog> | ||||
|       )} | ||||
|     </> | ||||
|   | ||||
| @@ -16,7 +16,7 @@ | ||||
|     max-height: 25rem; | ||||
|   } | ||||
|  | ||||
|   &.theme--dark .ExportDialog__preview canvas { | ||||
|   &.Appearance_dark .ExportDialog__preview canvas { | ||||
|     filter: none; | ||||
|   } | ||||
|  | ||||
| @@ -28,7 +28,16 @@ | ||||
|     justify-content: space-between; | ||||
|   } | ||||
|  | ||||
|   @include isMobile { | ||||
|   .ExportDialog__name { | ||||
|     grid-column: project-name; | ||||
|     margin: auto; | ||||
|  | ||||
|     .TextInput { | ||||
|       height: calc(1rem - 3px); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   @media #{$is-mobile-query} { | ||||
|     .ExportDialog { | ||||
|       display: flex; | ||||
|       flex-direction: column; | ||||
| @@ -57,63 +66,4 @@ | ||||
|       overflow-y: auto; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   .ExportDialog--json { | ||||
|     .ExportDialog-cards { | ||||
|       display: grid; | ||||
|       grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); | ||||
|       justify-items: center; | ||||
|       row-gap: 2em; | ||||
|  | ||||
|       @media (max-width: 460px) { | ||||
|         grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); | ||||
|         .Card-details { | ||||
|           min-height: 40px; | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       .ProjectName { | ||||
|         width: fit-content; | ||||
|         margin: 1em auto; | ||||
|         align-items: flex-start; | ||||
|         flex-direction: column; | ||||
|  | ||||
|         .TextInput { | ||||
|           width: auto; | ||||
|         } | ||||
|       } | ||||
|  | ||||
|       .ProjectName-label { | ||||
|         margin: 0.625em 0; | ||||
|         font-weight: bold; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   button.ExportDialog-imageExportButton { | ||||
|     width: 5rem; | ||||
|     height: 5rem; | ||||
|     margin: 0 0.2em; | ||||
|  | ||||
|     border-radius: 1rem; | ||||
|     background-color: var(--button-color); | ||||
|     box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.28), | ||||
|       0 6px 10px 0 rgba(0, 0, 0, 0.14); | ||||
|  | ||||
|     font-family: Cascadia; | ||||
|     font-size: 1.8em; | ||||
|     color: $oc-white; | ||||
|  | ||||
|     &:hover { | ||||
|       background-color: var(--button-color-darker); | ||||
|     } | ||||
|     &:active { | ||||
|       background-color: var(--button-color-darkest); | ||||
|       box-shadow: none; | ||||
|     } | ||||
|  | ||||
|     svg { | ||||
|       width: 0.9em; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										284
									
								
								src/components/ExportDialog.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						| @@ -0,0 +1,284 @@ | ||||
| import React, { useEffect, useRef, useState } from "react"; | ||||
| import { render, unmountComponentAtNode } from "react-dom"; | ||||
| import { ActionsManagerInterface } from "../actions/types"; | ||||
| import { probablySupportsClipboardBlob } from "../clipboard"; | ||||
| import { canvasToBlob } from "../data/blob"; | ||||
| import { NonDeletedExcalidrawElement } from "../element/types"; | ||||
| import { CanvasError } from "../errors"; | ||||
| import { t } from "../i18n"; | ||||
| import useIsMobile from "../is-mobile"; | ||||
| import { getSelectedElements, isSomeElementSelected } from "../scene"; | ||||
| import { exportToCanvas, getExportSize } from "../scene/export"; | ||||
| import { AppState } from "../types"; | ||||
| import { Dialog } from "./Dialog"; | ||||
| import "./ExportDialog.scss"; | ||||
| import { clipboard, exportFile, link } from "./icons"; | ||||
| import Stack from "./Stack"; | ||||
| import { ToolButton } from "./ToolButton"; | ||||
|  | ||||
| const scales = [1, 2, 3]; | ||||
| const defaultScale = scales.includes(devicePixelRatio) ? devicePixelRatio : 1; | ||||
|  | ||||
| const supportsContextFilters = | ||||
|   "filter" in document.createElement("canvas").getContext("2d")!; | ||||
|  | ||||
| export const ErrorCanvasPreview = () => { | ||||
|   return ( | ||||
|     <div> | ||||
|       <h3>{t("canvasError.cannotShowPreview")}</h3> | ||||
|       <p> | ||||
|         <span>{t("canvasError.canvasTooBig")}</span> | ||||
|       </p> | ||||
|       <em>({t("canvasError.canvasTooBigTip")})</em> | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| const renderPreview = ( | ||||
|   content: HTMLCanvasElement | Error, | ||||
|   previewNode: HTMLDivElement, | ||||
| ) => { | ||||
|   unmountComponentAtNode(previewNode); | ||||
|   previewNode.innerHTML = ""; | ||||
|   if (content instanceof HTMLCanvasElement) { | ||||
|     previewNode.appendChild(content); | ||||
|   } else { | ||||
|     render(<ErrorCanvasPreview />, previewNode); | ||||
|   } | ||||
| }; | ||||
|  | ||||
| export type ExportCB = ( | ||||
|   elements: readonly NonDeletedExcalidrawElement[], | ||||
|   scale?: number, | ||||
| ) => void; | ||||
|  | ||||
| const ExportModal = ({ | ||||
|   elements, | ||||
|   appState, | ||||
|   exportPadding = 10, | ||||
|   actionManager, | ||||
|   onExportToPng, | ||||
|   onExportToSvg, | ||||
|   onExportToClipboard, | ||||
|   onExportToBackend, | ||||
| }: { | ||||
|   appState: AppState; | ||||
|   elements: readonly NonDeletedExcalidrawElement[]; | ||||
|   exportPadding?: number; | ||||
|   actionManager: ActionsManagerInterface; | ||||
|   onExportToPng: ExportCB; | ||||
|   onExportToSvg: ExportCB; | ||||
|   onExportToClipboard: ExportCB; | ||||
|   onExportToBackend?: ExportCB; | ||||
|   onCloseRequest: () => void; | ||||
| }) => { | ||||
|   const someElementIsSelected = isSomeElementSelected(elements, appState); | ||||
|   const [scale, setScale] = useState(defaultScale); | ||||
|   const [exportSelected, setExportSelected] = useState(someElementIsSelected); | ||||
|   const previewRef = useRef<HTMLDivElement>(null); | ||||
|   const { | ||||
|     exportBackground, | ||||
|     viewBackgroundColor, | ||||
|     shouldAddWatermark, | ||||
|   } = appState; | ||||
|  | ||||
|   const exportedElements = exportSelected | ||||
|     ? getSelectedElements(elements, appState) | ||||
|     : elements; | ||||
|  | ||||
|   useEffect(() => { | ||||
|     setExportSelected(someElementIsSelected); | ||||
|   }, [someElementIsSelected]); | ||||
|  | ||||
|   useEffect(() => { | ||||
|     const previewNode = previewRef.current; | ||||
|     if (!previewNode) { | ||||
|       return; | ||||
|     } | ||||
|     try { | ||||
|       const canvas = exportToCanvas(exportedElements, appState, { | ||||
|         exportBackground, | ||||
|         viewBackgroundColor, | ||||
|         exportPadding, | ||||
|         scale, | ||||
|         shouldAddWatermark, | ||||
|       }); | ||||
|  | ||||
|       // if converting to blob fails, there's some problem that will | ||||
|       // likely prevent preview and export (e.g. canvas too big) | ||||
|       canvasToBlob(canvas) | ||||
|         .then(() => { | ||||
|           renderPreview(canvas, previewNode); | ||||
|         }) | ||||
|         .catch((error) => { | ||||
|           console.error(error); | ||||
|           renderPreview(new CanvasError(), previewNode); | ||||
|         }); | ||||
|     } catch (error) { | ||||
|       console.error(error); | ||||
|       renderPreview(new CanvasError(), previewNode); | ||||
|     } | ||||
|   }, [ | ||||
|     appState, | ||||
|     exportedElements, | ||||
|     exportBackground, | ||||
|     exportPadding, | ||||
|     viewBackgroundColor, | ||||
|     scale, | ||||
|     shouldAddWatermark, | ||||
|   ]); | ||||
|  | ||||
|   return ( | ||||
|     <div className="ExportDialog"> | ||||
|       <div className="ExportDialog__preview" ref={previewRef} /> | ||||
|       {supportsContextFilters && | ||||
|         actionManager.renderAction("exportWithDarkMode")} | ||||
|       <Stack.Col gap={2} align="center"> | ||||
|         <div className="ExportDialog__actions"> | ||||
|           <Stack.Row gap={2}> | ||||
|             <ToolButton | ||||
|               type="button" | ||||
|               label="PNG" | ||||
|               title={t("buttons.exportToPng")} | ||||
|               aria-label={t("buttons.exportToPng")} | ||||
|               onClick={() => onExportToPng(exportedElements, scale)} | ||||
|             /> | ||||
|             <ToolButton | ||||
|               type="button" | ||||
|               label="SVG" | ||||
|               title={t("buttons.exportToSvg")} | ||||
|               aria-label={t("buttons.exportToSvg")} | ||||
|               onClick={() => onExportToSvg(exportedElements, scale)} | ||||
|             /> | ||||
|             {probablySupportsClipboardBlob && ( | ||||
|               <ToolButton | ||||
|                 type="button" | ||||
|                 icon={clipboard} | ||||
|                 title={t("buttons.copyPngToClipboard")} | ||||
|                 aria-label={t("buttons.copyPngToClipboard")} | ||||
|                 onClick={() => onExportToClipboard(exportedElements, scale)} | ||||
|               /> | ||||
|             )} | ||||
|             {onExportToBackend && ( | ||||
|               <ToolButton | ||||
|                 type="button" | ||||
|                 icon={link} | ||||
|                 title={t("buttons.getShareableLink")} | ||||
|                 aria-label={t("buttons.getShareableLink")} | ||||
|                 onClick={() => onExportToBackend(exportedElements)} | ||||
|               /> | ||||
|             )} | ||||
|           </Stack.Row> | ||||
|           <div className="ExportDialog__name"> | ||||
|             {actionManager.renderAction("changeProjectName")} | ||||
|           </div> | ||||
|           <Stack.Row gap={2}> | ||||
|             {scales.map((s) => { | ||||
|               const [width, height] = getExportSize( | ||||
|                 exportedElements, | ||||
|                 exportPadding, | ||||
|                 shouldAddWatermark, | ||||
|                 s, | ||||
|               ); | ||||
|  | ||||
|               const scaleButtonTitle = `${t( | ||||
|                 "buttons.scale", | ||||
|               )} ${s}x (${width}x${height})`; | ||||
|  | ||||
|               return ( | ||||
|                 <ToolButton | ||||
|                   key={s} | ||||
|                   size="s" | ||||
|                   type="radio" | ||||
|                   icon={`${s}x`} | ||||
|                   name="export-canvas-scale" | ||||
|                   title={scaleButtonTitle} | ||||
|                   aria-label={scaleButtonTitle} | ||||
|                   id="export-canvas-scale" | ||||
|                   checked={s === scale} | ||||
|                   onChange={() => setScale(s)} | ||||
|                 /> | ||||
|               ); | ||||
|             })} | ||||
|           </Stack.Row> | ||||
|         </div> | ||||
|         {actionManager.renderAction("changeExportBackground")} | ||||
|         {someElementIsSelected && ( | ||||
|           <div> | ||||
|             <label> | ||||
|               <input | ||||
|                 type="checkbox" | ||||
|                 checked={exportSelected} | ||||
|                 onChange={(event) => | ||||
|                   setExportSelected(event.currentTarget.checked) | ||||
|                 } | ||||
|               />{" "} | ||||
|               {t("labels.onlySelected")} | ||||
|             </label> | ||||
|           </div> | ||||
|         )} | ||||
|         {actionManager.renderAction("changeExportEmbedScene")} | ||||
|         {actionManager.renderAction("changeShouldAddWatermark")} | ||||
|       </Stack.Col> | ||||
|     </div> | ||||
|   ); | ||||
| }; | ||||
|  | ||||
| export const ExportDialog = ({ | ||||
|   elements, | ||||
|   appState, | ||||
|   exportPadding = 10, | ||||
|   actionManager, | ||||
|   onExportToPng, | ||||
|   onExportToSvg, | ||||
|   onExportToClipboard, | ||||
|   onExportToBackend, | ||||
| }: { | ||||
|   appState: AppState; | ||||
|   elements: readonly NonDeletedExcalidrawElement[]; | ||||
|   exportPadding?: number; | ||||
|   actionManager: ActionsManagerInterface; | ||||
|   onExportToPng: ExportCB; | ||||
|   onExportToSvg: ExportCB; | ||||
|   onExportToClipboard: ExportCB; | ||||
|   onExportToBackend?: ExportCB; | ||||
| }) => { | ||||
|   const [modalIsShown, setModalIsShown] = useState(false); | ||||
|   const triggerButton = useRef<HTMLButtonElement>(null); | ||||
|  | ||||
|   const handleClose = React.useCallback(() => { | ||||
|     setModalIsShown(false); | ||||
|     triggerButton.current?.focus(); | ||||
|   }, []); | ||||
|  | ||||
|   return ( | ||||
|     <> | ||||
|       <ToolButton | ||||
|         onClick={() => { | ||||
|           setModalIsShown(true); | ||||
|         }} | ||||
|         icon={exportFile} | ||||
|         type="button" | ||||
|         aria-label={t("buttons.export")} | ||||
|         showAriaLabel={useIsMobile()} | ||||
|         title={t("buttons.export")} | ||||
|         ref={triggerButton} | ||||
|       /> | ||||
|       {modalIsShown && ( | ||||
|         <Dialog onCloseRequest={handleClose} title={t("buttons.export")}> | ||||
|           <ExportModal | ||||
|             elements={elements} | ||||
|             appState={appState} | ||||
|             exportPadding={exportPadding} | ||||
|             actionManager={actionManager} | ||||
|             onExportToPng={onExportToPng} | ||||
|             onExportToSvg={onExportToSvg} | ||||
|             onExportToClipboard={onExportToClipboard} | ||||
|             onExportToBackend={onExportToBackend} | ||||
|             onCloseRequest={handleClose} | ||||
|           /> | ||||
|         </Dialog> | ||||
|       )} | ||||
|     </> | ||||
|   ); | ||||
| }; | ||||
| @@ -1,5 +1,6 @@ | ||||
| .excalidraw { | ||||
|   .FixedSideContainer { | ||||
|     --margin: 0.25rem; | ||||
|     position: absolute; | ||||
|     pointer-events: none; | ||||
|   } | ||||
| @@ -9,9 +10,9 @@ | ||||
|   } | ||||
|  | ||||
|   .FixedSideContainer_side_top { | ||||
|     left: var(--space-factor); | ||||
|     top: var(--space-factor); | ||||
|     right: var(--space-factor); | ||||
|     left: var(--margin); | ||||
|     top: var(--margin); | ||||
|     right: var(--margin); | ||||
|     z-index: 2; | ||||
|   } | ||||
|  | ||||
| @@ -22,16 +23,16 @@ | ||||
|  | ||||
| /* TODO: if these are used, make sure to implement RTL support | ||||
| .FixedSideContainer_side_left { | ||||
|   left: var(--space-factor); | ||||
|   top: var(--space-factor); | ||||
|   bottom: var(--space-factor); | ||||
|   left: var(--margin); | ||||
|   top: var(--margin); | ||||
|   bottom: var(--margin); | ||||
|   z-index: 1; | ||||
| } | ||||
|  | ||||
| .FixedSideContainer_side_right { | ||||
|   right: var(--space-factor); | ||||
|   top: var(--space-factor); | ||||
|   bottom: var(--space-factor); | ||||
|   right: var(--margin); | ||||
|   top: var(--margin); | ||||
|   bottom: var(--margin); | ||||
|   z-index: 3; | ||||
| } | ||||
| */ | ||||
|   | ||||