Rename shapes apis (#1787)

This PR updates APIs related to shapes in the Editor.

- removes the requirement for an `id` when creating shapes
- `shapesOnCurrentPage` -> `currentPageShapes`
- `findAncestor` -> `findShapeAncestor`
- `findCommonAncestor` -> `findCommonShapeAncestor`
- Adds `getCurrentPageShapeIds`
- `getAncestors` -> `getShapeAncestors`
- `getClipPath` -> `getShapeClipPath`
- `getGeometry` -> `getShapeGeometry`
- `getHandles` -> `getShapeHandles`
- `getTransform` -> `getShapeLocalTransform`
- `getPageTransform` -> `getShapePageTransform`
- `getOutlineSegments` -> `getShapeOutlineSegments`
- `getPageBounds` -> `getShapePageBounds`
- `getPageTransform` -> `getShapePageTransform`
- `getParentTransform` -> `getShapeParentTransform`
- `selectionBounds` -> `selectionRotatedPageBounds`

### Change Type

- [x] `major` — Breaking change

### Test Plan

- [x] Unit Tests
This commit is contained in:
Steve Ruiz 2023-08-02 19:12:25 +01:00 committed by GitHub
parent 39dbbca90e
commit bf27743595
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
104 changed files with 1151 additions and 1115 deletions

View file

@ -192,13 +192,13 @@ function HandlesWrapper() {
const isReadonly = useValue('isChangingStyle', () => editor.instanceState.isReadonly, [editor])
const handles = useValue(
'handles',
() => (editor.onlySelectedShape ? editor.getHandles(editor.onlySelectedShape) : undefined),
() => (editor.onlySelectedShape ? editor.getShapeHandles(editor.onlySelectedShape) : undefined),
[editor]
)
const transform = useValue(
'transform',
() =>
editor.onlySelectedShape ? editor.getPageTransform(editor.onlySelectedShape) : undefined,
editor.onlySelectedShape ? editor.getShapePageTransform(editor.onlySelectedShape) : undefined,
[editor]
)
@ -396,7 +396,7 @@ const DebugSvgCopy = track(function DupSvg({ id }: { id: TLShapeId }) {
const unsubscribe = react('shape to svg', async () => {
const renderId = Math.random()
latest = renderId
const bb = editor.getPageBounds(id)
const bb = editor.getShapePageBounds(id)
const el = await editor.getSvg([id], { padding: 0 })
if (el && bb && latest === renderId) {
el.style.setProperty('overflow', 'visible')
@ -443,7 +443,9 @@ const UiLogger = track(() => {
export function SelectionForegroundWrapper() {
const editor = useEditor()
const selectionRotation = useValue('selection rotation', () => editor.selectionRotation, [editor])
const selectionBounds = useValue('selection bounds', () => editor.selectionBounds, [editor])
const selectionBounds = useValue('selection bounds', () => editor.selectionRotatedPageBounds, [
editor,
])
const { SelectionForeground } = useEditorComponents()
if (!selectionBounds || !SelectionForeground) return null
return <SelectionForeground bounds={selectionBounds} rotation={selectionRotation} />
@ -452,7 +454,9 @@ export function SelectionForegroundWrapper() {
export function SelectionBackgroundWrapper() {
const editor = useEditor()
const selectionRotation = useValue('selection rotation', () => editor.selectionRotation, [editor])
const selectionBounds = useValue('selection bounds', () => editor.selectionBounds, [editor])
const selectionBounds = useValue('selection bounds', () => editor.selectionRotatedPageBounds, [
editor,
])
const { SelectionBackground } = useEditorComponents()
if (!selectionBounds || !SelectionBackground) return null
return <SelectionBackground bounds={selectionBounds} rotation={selectionRotation} />