feat: support custom UI rendering inside export dialog (#3666)
* feat: support custom UI rendering inside export dialog * docs * add * remove assertion Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
0912fe1c93
commit
d63b6a3469
@ -22,16 +22,17 @@ const JSONExportModal = ({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
actionManager,
|
actionManager,
|
||||||
onExportToBackend,
|
|
||||||
exportOpts,
|
exportOpts,
|
||||||
|
canvas,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
actionManager: ActionsManagerInterface;
|
actionManager: ActionsManagerInterface;
|
||||||
onExportToBackend?: ExportCB;
|
|
||||||
onCloseRequest: () => void;
|
onCloseRequest: () => void;
|
||||||
exportOpts: ExportOpts;
|
exportOpts: ExportOpts;
|
||||||
|
canvas: HTMLCanvasElement | null;
|
||||||
}) => {
|
}) => {
|
||||||
|
const { onExportToBackend } = exportOpts;
|
||||||
return (
|
return (
|
||||||
<div className="ExportDialog ExportDialog--json">
|
<div className="ExportDialog ExportDialog--json">
|
||||||
<div className="ExportDialog-cards">
|
<div className="ExportDialog-cards">
|
||||||
@ -55,7 +56,7 @@ const JSONExportModal = ({
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
{exportOpts.onExportToBackend && (
|
{onExportToBackend && (
|
||||||
<Card color="pink">
|
<Card color="pink">
|
||||||
<div className="Card-icon">{link}</div>
|
<div className="Card-icon">{link}</div>
|
||||||
<h2>{t("exportDialog.link_title")}</h2>
|
<h2>{t("exportDialog.link_title")}</h2>
|
||||||
@ -66,10 +67,12 @@ const JSONExportModal = ({
|
|||||||
title={t("exportDialog.link_button")}
|
title={t("exportDialog.link_button")}
|
||||||
aria-label={t("exportDialog.link_button")}
|
aria-label={t("exportDialog.link_button")}
|
||||||
showAriaLabel={true}
|
showAriaLabel={true}
|
||||||
onClick={() => onExportToBackend!(elements)}
|
onClick={() => onExportToBackend(elements, appState, canvas)}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
{exportOpts.renderCustomUI &&
|
||||||
|
exportOpts.renderCustomUI(elements, appState, canvas)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -79,14 +82,14 @@ export const JSONExportDialog = ({
|
|||||||
elements,
|
elements,
|
||||||
appState,
|
appState,
|
||||||
actionManager,
|
actionManager,
|
||||||
onExportToBackend,
|
|
||||||
exportOpts,
|
exportOpts,
|
||||||
|
canvas,
|
||||||
}: {
|
}: {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
elements: readonly NonDeletedExcalidrawElement[];
|
elements: readonly NonDeletedExcalidrawElement[];
|
||||||
actionManager: ActionsManagerInterface;
|
actionManager: ActionsManagerInterface;
|
||||||
onExportToBackend?: ExportCB;
|
|
||||||
exportOpts: ExportOpts;
|
exportOpts: ExportOpts;
|
||||||
|
canvas: HTMLCanvasElement | null;
|
||||||
}) => {
|
}) => {
|
||||||
const [modalIsShown, setModalIsShown] = useState(false);
|
const [modalIsShown, setModalIsShown] = useState(false);
|
||||||
|
|
||||||
@ -113,9 +116,9 @@ export const JSONExportDialog = ({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onExportToBackend={onExportToBackend}
|
|
||||||
onCloseRequest={handleClose}
|
onCloseRequest={handleClose}
|
||||||
exportOpts={exportOpts}
|
exportOpts={exportOpts}
|
||||||
|
canvas={canvas}
|
||||||
/>
|
/>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
)}
|
)}
|
||||||
|
@ -387,15 +387,8 @@ const LayerUI = ({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
actionManager={actionManager}
|
actionManager={actionManager}
|
||||||
onExportToBackend={(elements) => {
|
|
||||||
UIOptions.canvasActions.export.onExportToBackend &&
|
|
||||||
UIOptions.canvasActions.export.onExportToBackend(
|
|
||||||
elements,
|
|
||||||
appState,
|
|
||||||
canvas,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
exportOpts={UIOptions.canvasActions.export}
|
exportOpts={UIOptions.canvasActions.export}
|
||||||
|
canvas={canvas}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -426,7 +426,9 @@ const ExcalidrawWrapper = () => {
|
|||||||
onPointerUpdate={collabAPI?.onPointerUpdate}
|
onPointerUpdate={collabAPI?.onPointerUpdate}
|
||||||
UIOptions={{
|
UIOptions={{
|
||||||
canvasActions: {
|
canvasActions: {
|
||||||
export: { onExportToBackend },
|
export: {
|
||||||
|
onExportToBackend,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
renderTopRightUI={renderTopRightUI}
|
renderTopRightUI={renderTopRightUI}
|
||||||
|
@ -13,10 +13,13 @@ Please add the latest change on the top under the correct section.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
**This changes are not yet released but you can still try it out in [@excalidraw/excalidraw-next](https://www.npmjs.com/package/@excalidraw/excalidraw-next).**
|
||||||
|
|
||||||
## Excalidraw API
|
## Excalidraw API
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
- Added prop `UIOptions.canvasActions.export.renderCustomUI` to support Custom UI rendering inside export dialog [#3666](https://github.com/excalidraw/excalidraw/pull/3666).
|
||||||
- Added prop `UIOptions.canvasActions.saveAsImage` to show/hide the **Save as image** button in the canvas actions. Defauls to `true` hence the **Save as Image** button is rendered [#3662](https://github.com/excalidraw/excalidraw/pull/3662).
|
- Added prop `UIOptions.canvasActions.saveAsImage` to show/hide the **Save as image** button in the canvas actions. Defauls to `true` hence the **Save as Image** button is rendered [#3662](https://github.com/excalidraw/excalidraw/pull/3662).
|
||||||
|
|
||||||
- Export dialog can be customised with [`UiOptions.canvasActions.export`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportOpts) [#3658](https://github.com/excalidraw/excalidraw/pull/3658).
|
- Export dialog can be customised with [`UiOptions.canvasActions.export`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#exportOpts) [#3658](https://github.com/excalidraw/excalidraw/pull/3658).
|
||||||
@ -35,6 +38,8 @@ Please add the latest change on the top under the correct section.
|
|||||||
- Removed `shouldAddWatermark: boolean` attribute from options for [export](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#export-utilities) APIs [#3639](https://github.com/excalidraw/excalidraw/pull/3639).
|
- Removed `shouldAddWatermark: boolean` attribute from options for [export](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#export-utilities) APIs [#3639](https://github.com/excalidraw/excalidraw/pull/3639).
|
||||||
- Removed `appState.shouldAddWatermark` so in case you were passing `shouldAddWatermark` in [initialData.AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42) it will not work anymore.
|
- Removed `appState.shouldAddWatermark` so in case you were passing `shouldAddWatermark` in [initialData.AppState](https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L42) it will not work anymore.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 0.8.0 (2021-05-15)
|
## 0.8.0 (2021-05-15)
|
||||||
|
|
||||||
## Excalidraw API
|
## Excalidraw API
|
||||||
|
@ -580,6 +580,7 @@ The below attributes can be set in `UIOptions.canvasActions.export` to customize
|
|||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `saveFileToDisk` | boolean | true | Implies if save file to disk button should be shown |
|
| `saveFileToDisk` | boolean | true | Implies if save file to disk button should be shown |
|
||||||
| `exportToBackend` | <pre> (exportedElements: readonly NonDeletedExcalidrawElement[],appState: AppState,canvas: HTMLCanvasElement | null) => void </pre> | | This callback is triggered when the shareable-link button is clicked in the export dialog. The link button will only be shown if this callback is passed. |
|
| `exportToBackend` | <pre> (exportedElements: readonly NonDeletedExcalidrawElement[],appState: AppState,canvas: HTMLCanvasElement | null) => void </pre> | | This callback is triggered when the shareable-link button is clicked in the export dialog. The link button will only be shown if this callback is passed. |
|
||||||
|
| `renderCustomUI` | <pre> (exportedElements: readonly NonDeletedExcalidrawElement[],appState: AppState,canvas: HTMLCanvasElement | null) => void </pre> | | This callback should be supplied if you want to render custom UI in the export dialog. |
|
||||||
|
|
||||||
#### `onPaste`
|
#### `onPaste`
|
||||||
|
|
||||||
|
@ -221,6 +221,11 @@ export type ExportOpts = {
|
|||||||
appState: AppState,
|
appState: AppState,
|
||||||
canvas: HTMLCanvasElement | null,
|
canvas: HTMLCanvasElement | null,
|
||||||
) => void;
|
) => void;
|
||||||
|
renderCustomUI?: (
|
||||||
|
exportedElements: readonly NonDeletedExcalidrawElement[],
|
||||||
|
appState: AppState,
|
||||||
|
canvas: HTMLCanvasElement | null,
|
||||||
|
) => JSX.Element;
|
||||||
};
|
};
|
||||||
|
|
||||||
type CanvasActions = {
|
type CanvasActions = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user