[feature] unlock all action (#1820)

This PR adds an "Unlock all" action to the edit menu. 

- Selecting `unlock all` sets `isLocked` to false for all shapes on the
current page
- The option is disabled if the page is empty; but we don't check
whether there are locked shapes on the page (juice < squeeze)

Closes https://github.com/tldraw/tldraw/issues/1809

### Change Type

- [x] `minor` — New feature

### Test Plan

1. Create locked shapes
2. Select menu > edit > unlock all

### Release Notes

- Adds the unlock all feature.
This commit is contained in:
Steve Ruiz 2023-08-24 14:25:04 +02:00 committed by GitHub
parent df9f4254c4
commit af573bac51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 2 deletions

View file

@ -22,6 +22,7 @@
"action.copy": "Copy",
"action.cut": "Cut",
"action.delete": "Delete",
"action.unlock-all": "Unlock all",
"action.distribute-horizontal": "Distribute horizontally",
"action.distribute-vertical": "Distribute vertically",
"action.distribute-horizontal.short": "Distribute H",

File diff suppressed because one or more lines are too long

View file

@ -859,6 +859,23 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
},
checkbox: true,
},
{
id: 'unlock-all',
label: 'action.unlock-all',
readonlyOk: false,
onSelect(source) {
trackEvent('unlock-all', { source })
const updates = [] as TLShapePartial[]
for (const shape of editor.currentPageShapes) {
if (shape.isLocked) {
updates.push({ id: shape.id, type: shape.type, isLocked: false })
}
}
if (updates.length > 0) {
editor.updateShapes(updates)
}
},
},
{
id: 'toggle-focus-mode',
label: 'action.toggle-focus-mode',

View file

@ -83,6 +83,7 @@ export interface TLUiEventMap {
'stop-following': null
'open-cursor-chat': null
'zoom-tool': null
'unlock-all': null
}
type Join<T, K> = K extends null

View file

@ -172,7 +172,8 @@ export function TLUiMenuSchemaProvider({ overrides, children }: TLUiMenuSchemaPr
showEditLink && menuItem(actions['edit-link']),
menuItem(actions['duplicate'], { disabled: !oneSelected }),
allowGroup && menuItem(actions['group']),
allowUngroup && menuItem(actions['ungroup'])
allowUngroup && menuItem(actions['ungroup']),
menuItem(actions['unlock-all'], { disabled: emptyPage })
),
menuGroup('delete-group', menuItem(actions['delete'], { disabled: !oneSelected })),
menuGroup(

View file

@ -26,6 +26,7 @@ export type TLUiTranslationKey =
| 'action.copy'
| 'action.cut'
| 'action.delete'
| 'action.unlock-all'
| 'action.distribute-horizontal'
| 'action.distribute-vertical'
| 'action.distribute-horizontal.short'

View file

@ -26,6 +26,7 @@ export const DEFAULT_TRANSLATION = {
'action.copy': 'Copy',
'action.cut': 'Cut',
'action.delete': 'Delete',
'action.unlock-all': 'Unlock all',
'action.distribute-horizontal': 'Distribute horizontally',
'action.distribute-vertical': 'Distribute vertically',
'action.distribute-horizontal.short': 'Distribute H',