Add link to the public libraries (#2469)
This commit is contained in:
parent
dd993adc5c
commit
5e57f408c5
@ -18,6 +18,7 @@ import {
|
|||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { fixBindingsAfterDuplication } from "../element/binding";
|
import { fixBindingsAfterDuplication } from "../element/binding";
|
||||||
import { ActionResult } from "./types";
|
import { ActionResult } from "./types";
|
||||||
|
import { GRID_SIZE } from "../constants";
|
||||||
|
|
||||||
export const actionDuplicateSelection = register({
|
export const actionDuplicateSelection = register({
|
||||||
name: "duplicateSelection",
|
name: "duplicateSelection",
|
||||||
@ -93,8 +94,8 @@ const duplicateElements = (
|
|||||||
groupIdMap,
|
groupIdMap,
|
||||||
element,
|
element,
|
||||||
{
|
{
|
||||||
x: element.x + 10,
|
x: element.x + GRID_SIZE / 2,
|
||||||
y: element.y + 10,
|
y: element.y + GRID_SIZE / 2,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
oldIdToDuplicatedId.set(element.id, newElement.id);
|
oldIdToDuplicatedId.set(element.id, newElement.id);
|
||||||
|
@ -6,6 +6,16 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
|
.browse-libraries {
|
||||||
|
position: absolute;
|
||||||
|
right: 12px;
|
||||||
|
top: 16px;
|
||||||
|
white-space: nowrap;
|
||||||
|
max-width: 140px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.layer-ui__library-message {
|
.layer-ui__library-message {
|
||||||
|
@ -118,70 +118,83 @@ const LibraryMenuItems = ({
|
|||||||
let addedPendingElements = false;
|
let addedPendingElements = false;
|
||||||
|
|
||||||
rows.push(
|
rows.push(
|
||||||
<Stack.Row
|
<>
|
||||||
align="center"
|
<a
|
||||||
gap={1}
|
className="browse-libraries"
|
||||||
key={"actions"}
|
href="https://libraries.excalidraw.com"
|
||||||
style={{ padding: "2px 0" }}
|
target="_excalidraw_libraries"
|
||||||
>
|
|
||||||
<ToolButton
|
|
||||||
key="import"
|
|
||||||
type="button"
|
|
||||||
title={t("buttons.load")}
|
|
||||||
aria-label={t("buttons.load")}
|
|
||||||
icon={load}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
importLibraryFromJSON()
|
trackEvent(EVENT_EXIT, "libraries");
|
||||||
.then(() => {
|
|
||||||
// Maybe we should close and open the menu so that the items get updated.
|
|
||||||
// But for now we just close the menu.
|
|
||||||
setAppState({ isLibraryOpen: false });
|
|
||||||
})
|
|
||||||
.catch(muteFSAbortError)
|
|
||||||
.catch((error) => {
|
|
||||||
setAppState({ errorMessage: error.message });
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
<ToolButton
|
{t("labels.libraries")}
|
||||||
key="export"
|
</a>
|
||||||
type="button"
|
|
||||||
title={t("buttons.export")}
|
<Stack.Row
|
||||||
aria-label={t("buttons.export")}
|
align="center"
|
||||||
icon={exportFile}
|
gap={1}
|
||||||
onClick={() => {
|
key={"actions"}
|
||||||
saveLibraryAsJSON()
|
style={{ padding: "2px 0" }}
|
||||||
.catch(muteFSAbortError)
|
>
|
||||||
.catch((error) => {
|
<ToolButton
|
||||||
setAppState({ errorMessage: error.message });
|
key="import"
|
||||||
});
|
type="button"
|
||||||
}}
|
title={t("buttons.load")}
|
||||||
/>
|
aria-label={t("buttons.load")}
|
||||||
</Stack.Row>,
|
icon={load}
|
||||||
|
onClick={() => {
|
||||||
|
importLibraryFromJSON()
|
||||||
|
.then(() => {
|
||||||
|
// Maybe we should close and open the menu so that the items get updated.
|
||||||
|
// But for now we just close the menu.
|
||||||
|
setAppState({ isLibraryOpen: false });
|
||||||
|
})
|
||||||
|
.catch(muteFSAbortError)
|
||||||
|
.catch((error) => {
|
||||||
|
setAppState({ errorMessage: error.message });
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ToolButton
|
||||||
|
key="export"
|
||||||
|
type="button"
|
||||||
|
title={t("buttons.export")}
|
||||||
|
aria-label={t("buttons.export")}
|
||||||
|
icon={exportFile}
|
||||||
|
onClick={() => {
|
||||||
|
saveLibraryAsJSON()
|
||||||
|
.catch(muteFSAbortError)
|
||||||
|
.catch((error) => {
|
||||||
|
setAppState({ errorMessage: error.message });
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack.Row>
|
||||||
|
</>,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let row = 0; row < numRows; row++) {
|
for (let row = 0; row < numRows; row++) {
|
||||||
const i = CELLS_PER_ROW * row;
|
const y = CELLS_PER_ROW * row;
|
||||||
const children = [];
|
const children = [];
|
||||||
for (let j = 0; j < CELLS_PER_ROW; j++) {
|
for (let x = 0; x < CELLS_PER_ROW; x++) {
|
||||||
const shouldAddPendingElements: boolean =
|
const shouldAddPendingElements: boolean =
|
||||||
pendingElements.length > 0 &&
|
pendingElements.length > 0 &&
|
||||||
!addedPendingElements &&
|
!addedPendingElements &&
|
||||||
i + j >= library.length;
|
y + x >= library.length;
|
||||||
addedPendingElements = addedPendingElements || shouldAddPendingElements;
|
addedPendingElements = addedPendingElements || shouldAddPendingElements;
|
||||||
|
|
||||||
children.push(
|
children.push(
|
||||||
<Stack.Col key={j}>
|
<Stack.Col key={x}>
|
||||||
<LibraryUnit
|
<LibraryUnit
|
||||||
elements={library[i + j]}
|
elements={library[y + x]}
|
||||||
pendingElements={
|
pendingElements={
|
||||||
shouldAddPendingElements ? pendingElements : undefined
|
shouldAddPendingElements ? pendingElements : undefined
|
||||||
}
|
}
|
||||||
onRemoveFromLibrary={onRemoveFromLibrary.bind(null, i + j)}
|
onRemoveFromLibrary={onRemoveFromLibrary.bind(null, y + x)}
|
||||||
onClick={
|
onClick={
|
||||||
shouldAddPendingElements
|
shouldAddPendingElements
|
||||||
? onAddToLibrary.bind(null, pendingElements)
|
? onAddToLibrary.bind(null, pendingElements)
|
||||||
: onInsertShape.bind(null, library[i + j])
|
: onInsertShape.bind(null, library[y + x])
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Stack.Col>,
|
</Stack.Col>,
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
"addToLibrary": "Add to library",
|
"addToLibrary": "Add to library",
|
||||||
"removeFromLibrary": "Remove from library",
|
"removeFromLibrary": "Remove from library",
|
||||||
"libraryLoadingMessage": "Loading library...",
|
"libraryLoadingMessage": "Loading library...",
|
||||||
|
"libraries": "Browse libraries",
|
||||||
"loadingScene": "Loading scene...",
|
"loadingScene": "Loading scene...",
|
||||||
"align": "Align",
|
"align": "Align",
|
||||||
"alignTop": "Align top",
|
"alignTop": "Align top",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user