Files
logseq/tldraw/packages/react/src/components/ContextBarContainer/ContextBarContainer.tsx
Konstantinos 95149e13f6 Feat: Export to image (#9037)
* feat: export to image

* chore: export selection on whiteboards

* fix: whiteboards zoom on export

* fix: loading position

* chore: support video thumb

* core: add export to  whiteboards context menu

* fix: context menu entry

* fix; copy image to clipboard

* fix: copy / export label

* fix: hide ui elements

* fix: remove random character

* fix: graph export

* chore: remove console log and jpg format

* style: run prettier

* fix: disable on multiple selected blocks

* fix: multiple blocks

* enhance: restrict bounds of selected shapes

* chore: export selection on whiteboards

* fix: whiteboards zoom on export

* chore: support video thumb

* core: add export to  whiteboards context menu

* fix: context menu entry

* fix; copy image to clipboard

* fix: copy / export label

* fix: hide ui elements

* fix: remove random character

* fix: graph export

* chore: remove console log and jpg format

* style: run prettier

* fix: disable on multiple selected blocks

* fix: multiple blocks

* enhance: restrict bounds of selected shapes

* Fix any html2canvas related functionality failing in publishing

* fix: portal header gradient on export

* chore: add comment about html2canvas-ignore attr

* fix: use export padding constant

* fix: export collapsed portals with size >  medium

* fix: reset export type

* enhance: export filename

---------

Co-authored-by: Gabriel Horner <gabriel@logseq.com>
Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
2023-04-12 17:39:22 +08:00

68 lines
1.8 KiB
TypeScript

import * as React from 'react'
import { observer } from 'mobx-react-lite'
import { TLBounds, BoundsUtils, TLOffset } from '@tldraw/core'
import { useRendererContext, useCounterScaledPosition } from '../../hooks'
import type { TLReactShape } from '../../lib'
export interface TLContextBarContainerProps<S extends TLReactShape> {
shapes: S[]
hidden: boolean
bounds: TLBounds
rotation?: number
}
export const ContextBarContainer = observer(function ContextBarContainer<S extends TLReactShape>({
shapes,
hidden,
bounds,
rotation = 0,
}: TLContextBarContainerProps<S>) {
const {
components: { ContextBar },
viewport: {
bounds: vpBounds,
camera: {
point: [x, y],
zoom,
},
},
} = useRendererContext()
const rBounds = React.useRef<HTMLDivElement>(null)
const rotatedBounds = BoundsUtils.getRotatedBounds(bounds, rotation)
const scaledBounds = BoundsUtils.multiplyBounds(rotatedBounds, zoom)
useCounterScaledPosition(rBounds, bounds, rotation, 10005)
if (!ContextBar) throw Error('Expected a ContextBar component.')
const screenBounds = BoundsUtils.translateBounds(scaledBounds, [x * zoom, y * zoom])
const offsets: TLOffset = {
left: screenBounds.minX,
right: vpBounds.width - screenBounds.maxX,
top: screenBounds.minY,
bottom: vpBounds.height - screenBounds.maxY,
width: screenBounds.width,
height: screenBounds.height,
}
return (
<div
ref={rBounds}
className="tl-counter-scaled-positioned"
aria-label="context-bar-container"
data-html2canvas-ignore="true"
>
<ContextBar
hidden={hidden}
shapes={shapes}
bounds={bounds}
offsets={offsets}
scaledBounds={scaledBounds}
rotation={rotation}
/>
</div>
)
})