2020-01-12 02:22:03 +04:00
|
|
|
import React from "react";
|
2020-04-08 21:00:27 +01:00
|
|
|
import {
|
|
|
|
ExcalidrawElement,
|
|
|
|
ExcalidrawTextElement,
|
|
|
|
TextAlign,
|
|
|
|
} from "../element/types";
|
2020-02-16 22:54:50 +01:00
|
|
|
import {
|
|
|
|
getCommonAttributeOfSelectedElements,
|
|
|
|
isSomeElementSelected,
|
|
|
|
} from "../scene";
|
2020-01-12 02:22:03 +04:00
|
|
|
import { ButtonSelect } from "../components/ButtonSelect";
|
2020-04-08 09:49:52 -07:00
|
|
|
import {
|
|
|
|
isTextElement,
|
|
|
|
redrawTextBoundingBox,
|
|
|
|
getNonDeletedElements,
|
|
|
|
} from "../element";
|
2020-01-15 20:42:02 +05:00
|
|
|
import { ColorPicker } from "../components/ColorPicker";
|
2020-01-21 00:16:22 +01:00
|
|
|
import { AppState } from "../../src/types";
|
2020-01-31 21:06:06 +00:00
|
|
|
import { t } from "../i18n";
|
2020-02-24 16:29:54 +01:00
|
|
|
import { DEFAULT_FONT } from "../appState";
|
2020-03-07 10:20:38 -05:00
|
|
|
import { register } from "./register";
|
2020-03-14 21:48:51 -07:00
|
|
|
import { newElementWith } from "../element/mutateElement";
|
2020-01-12 02:22:03 +04:00
|
|
|
|
|
|
|
const changeProperty = (
|
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-03-08 10:20:55 -07:00
|
|
|
appState: AppState,
|
2020-01-24 12:04:54 +02:00
|
|
|
callback: (element: ExcalidrawElement) => ExcalidrawElement,
|
2020-01-12 02:22:03 +04:00
|
|
|
) => {
|
2020-03-23 13:05:07 +02:00
|
|
|
return elements.map((element) => {
|
2020-03-08 10:20:55 -07:00
|
|
|
if (appState.selectedElementIds[element.id]) {
|
2020-01-12 02:22:03 +04:00
|
|
|
return callback(element);
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-03-23 13:05:07 +02:00
|
|
|
const getFormValue = function <T>(
|
2020-01-21 00:16:22 +01:00
|
|
|
elements: readonly ExcalidrawElement[],
|
2020-03-08 10:20:55 -07:00
|
|
|
appState: AppState,
|
2020-01-21 00:16:22 +01:00
|
|
|
getAttribute: (element: ExcalidrawElement) => T,
|
2020-01-24 12:04:54 +02:00
|
|
|
defaultValue?: T,
|
2020-01-21 00:16:22 +01:00
|
|
|
): T | null {
|
2020-03-08 10:20:55 -07:00
|
|
|
const editingElement = appState.editingElement;
|
2020-04-08 09:49:52 -07:00
|
|
|
const nonDeletedElements = getNonDeletedElements(elements);
|
2020-01-21 00:16:22 +01:00
|
|
|
return (
|
2020-01-22 20:51:56 +01:00
|
|
|
(editingElement && getAttribute(editingElement)) ??
|
2020-04-08 09:49:52 -07:00
|
|
|
(isSomeElementSelected(nonDeletedElements, appState)
|
|
|
|
? getCommonAttributeOfSelectedElements(
|
|
|
|
nonDeletedElements,
|
|
|
|
appState,
|
|
|
|
getAttribute,
|
|
|
|
)
|
2020-01-26 04:12:47 -08:00
|
|
|
: defaultValue) ??
|
2020-01-21 00:16:22 +01:00
|
|
|
null
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeStrokeColor = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeStrokeColor",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
strokeColor: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-24 12:04:54 +02:00
|
|
|
appState: { ...appState, currentItemStrokeColor: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-21 00:16:22 +01:00
|
|
|
<>
|
2020-01-25 14:52:03 -03:00
|
|
|
<h3 aria-hidden="true">{t("labels.stroke")}</h3>
|
2020-01-21 00:16:22 +01:00
|
|
|
<ColorPicker
|
|
|
|
type="elementStroke"
|
2020-01-25 14:52:03 -03:00
|
|
|
label={t("labels.stroke")}
|
2020-01-21 00:16:22 +01:00
|
|
|
color={getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.strokeColor,
|
2020-01-24 12:04:54 +02:00
|
|
|
appState.currentItemStrokeColor,
|
2020-01-21 00:16:22 +01:00
|
|
|
)}
|
|
|
|
onChange={updateData}
|
|
|
|
/>
|
|
|
|
</>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeBackgroundColor = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeBackgroundColor",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
backgroundColor: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-24 12:04:54 +02:00
|
|
|
appState: { ...appState, currentItemBackgroundColor: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-15 20:42:02 +05:00
|
|
|
<>
|
2020-01-25 14:52:03 -03:00
|
|
|
<h3 aria-hidden="true">{t("labels.background")}</h3>
|
2020-01-15 20:42:02 +05:00
|
|
|
<ColorPicker
|
|
|
|
type="elementBackground"
|
2020-01-25 14:52:03 -03:00
|
|
|
label={t("labels.background")}
|
2020-01-21 00:16:22 +01:00
|
|
|
color={getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.backgroundColor,
|
2020-01-24 12:04:54 +02:00
|
|
|
appState.currentItemBackgroundColor,
|
2020-01-21 00:16:22 +01:00
|
|
|
)}
|
2020-01-15 20:42:02 +05:00
|
|
|
onChange={updateData}
|
|
|
|
/>
|
|
|
|
</>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeFillStyle = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeFillStyle",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
fillStyle: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: { ...appState, currentItemFillStyle: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.fill")}</legend>
|
2020-01-12 02:22:03 +04:00
|
|
|
<ButtonSelect
|
|
|
|
options={[
|
2020-01-22 16:25:04 +02:00
|
|
|
{ value: "hachure", text: t("labels.hachure") },
|
2020-01-24 12:04:54 +02:00
|
|
|
{ value: "cross-hatch", text: t("labels.crossHatch") },
|
2020-03-27 19:38:03 +02:00
|
|
|
{ value: "solid", text: t("labels.solid") },
|
2020-01-12 02:22:03 +04:00
|
|
|
]}
|
2020-01-25 14:52:03 -03:00
|
|
|
group="fill"
|
2020-01-21 00:16:22 +01:00
|
|
|
value={getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.fillStyle,
|
2020-01-26 19:09:11 +00:00
|
|
|
appState.currentItemFillStyle,
|
2020-01-21 00:16:22 +01:00
|
|
|
)}
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(value) => {
|
2020-01-12 02:22:03 +04:00
|
|
|
updateData(value);
|
|
|
|
}}
|
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</fieldset>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeStrokeWidth = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeStrokeWidth",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
strokeWidth: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: { ...appState, currentItemStrokeWidth: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.strokeWidth")}</legend>
|
2020-01-12 02:22:03 +04:00
|
|
|
<ButtonSelect
|
2020-01-25 14:52:03 -03:00
|
|
|
group="stroke-width"
|
2020-01-12 02:22:03 +04:00
|
|
|
options={[
|
2020-01-22 16:25:04 +02:00
|
|
|
{ value: 1, text: t("labels.thin") },
|
|
|
|
{ value: 2, text: t("labels.bold") },
|
2020-01-24 12:04:54 +02:00
|
|
|
{ value: 4, text: t("labels.extraBold") },
|
2020-01-12 02:22:03 +04:00
|
|
|
]}
|
2020-01-21 00:16:22 +01:00
|
|
|
value={getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.strokeWidth,
|
2020-01-26 19:09:11 +00:00
|
|
|
appState.currentItemStrokeWidth,
|
2020-01-21 00:16:22 +01:00
|
|
|
)}
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(value) => updateData(value)}
|
2020-01-12 02:22:03 +04:00
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</fieldset>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeSloppiness = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeSloppiness",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
roughness: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: { ...appState, currentItemRoughness: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.sloppiness")}</legend>
|
2020-01-12 02:22:03 +04:00
|
|
|
<ButtonSelect
|
2020-01-25 14:52:03 -03:00
|
|
|
group="sloppiness"
|
2020-01-12 02:22:03 +04:00
|
|
|
options={[
|
2020-01-22 16:25:04 +02:00
|
|
|
{ value: 0, text: t("labels.architect") },
|
|
|
|
{ value: 1, text: t("labels.artist") },
|
2020-01-26 20:16:33 +01:00
|
|
|
{ value: 2, text: t("labels.cartoonist") },
|
2020-01-12 02:22:03 +04:00
|
|
|
]}
|
2020-01-21 00:16:22 +01:00
|
|
|
value={getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.roughness,
|
2020-01-26 19:09:11 +00:00
|
|
|
appState.currentItemRoughness,
|
2020-01-21 00:16:22 +01:00
|
|
|
)}
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(value) => updateData(value)}
|
2020-01-12 02:22:03 +04:00
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</fieldset>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeOpacity = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeOpacity",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) =>
|
2020-03-10 20:11:02 -07:00
|
|
|
newElementWith(el, {
|
|
|
|
opacity: value,
|
|
|
|
}),
|
|
|
|
),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: { ...appState, currentItemOpacity: value },
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<label className="control-label">
|
|
|
|
{t("labels.opacity")}
|
2020-01-12 02:22:03 +04:00
|
|
|
<input
|
|
|
|
type="range"
|
|
|
|
min="0"
|
|
|
|
max="100"
|
2020-02-02 17:09:50 -08:00
|
|
|
step="10"
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(event) => updateData(+event.target.value)}
|
|
|
|
onWheel={(event) => {
|
2020-02-28 23:03:53 +01:00
|
|
|
event.stopPropagation();
|
|
|
|
const target = event.target as HTMLInputElement;
|
2020-02-03 01:48:41 +00:00
|
|
|
const STEP = 10;
|
|
|
|
const MAX = 100;
|
|
|
|
const MIN = 0;
|
|
|
|
const value = +target.value;
|
|
|
|
|
2020-02-28 23:03:53 +01:00
|
|
|
if (event.deltaY < 0 && value < MAX) {
|
2020-02-03 01:48:41 +00:00
|
|
|
updateData(value + STEP);
|
2020-02-28 23:03:53 +01:00
|
|
|
} else if (event.deltaY > 0 && value > MIN) {
|
2020-02-03 01:48:41 +00:00
|
|
|
updateData(value - STEP);
|
|
|
|
}
|
|
|
|
}}
|
2020-01-12 02:22:03 +04:00
|
|
|
value={
|
2020-01-21 00:16:22 +01:00
|
|
|
getFormValue(
|
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => element.opacity,
|
2020-01-26 19:09:11 +00:00
|
|
|
appState.currentItemOpacity,
|
2020-01-22 20:51:56 +01:00
|
|
|
) ?? undefined
|
2020-01-12 02:22:03 +04:00
|
|
|
}
|
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</label>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeFontSize = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeFontSize",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) => {
|
2020-01-12 02:22:03 +04:00
|
|
|
if (isTextElement(el)) {
|
2020-03-14 21:48:51 -07:00
|
|
|
const element: ExcalidrawTextElement = newElementWith(el, {
|
2020-01-24 12:04:54 +02:00
|
|
|
font: `${value}px ${el.font.split("px ")[1]}`,
|
2020-03-10 20:11:02 -07:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
redrawTextBoundingBox(element);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return el;
|
2020-01-24 12:04:54 +02:00
|
|
|
}),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
currentItemFont: `${value}px ${
|
|
|
|
appState.currentItemFont.split("px ")[1]
|
|
|
|
}`,
|
|
|
|
},
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.fontSize")}</legend>
|
2020-01-12 02:22:03 +04:00
|
|
|
<ButtonSelect
|
2020-01-25 14:52:03 -03:00
|
|
|
group="font-size"
|
2020-01-12 02:22:03 +04:00
|
|
|
options={[
|
2020-01-22 16:25:04 +02:00
|
|
|
{ value: 16, text: t("labels.small") },
|
|
|
|
{ value: 20, text: t("labels.medium") },
|
|
|
|
{ value: 28, text: t("labels.large") },
|
2020-01-24 12:04:54 +02:00
|
|
|
{ value: 36, text: t("labels.veryLarge") },
|
2020-01-12 02:22:03 +04:00
|
|
|
]}
|
2020-01-21 00:16:22 +01:00
|
|
|
value={getFormValue(
|
2020-01-12 02:22:03 +04:00
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => isTextElement(element) && +element.font.split("px ")[0],
|
2020-02-24 16:29:54 +01:00
|
|
|
+(appState.currentItemFont || DEFAULT_FONT).split("px ")[0],
|
2020-01-12 02:22:03 +04:00
|
|
|
)}
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(value) => updateData(value)}
|
2020-01-12 02:22:03 +04:00
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</fieldset>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
|
2020-03-07 10:20:38 -05:00
|
|
|
export const actionChangeFontFamily = register({
|
2020-01-12 02:22:03 +04:00
|
|
|
name: "changeFontFamily",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
2020-03-23 13:05:07 +02:00
|
|
|
elements: changeProperty(elements, appState, (el) => {
|
2020-01-12 02:22:03 +04:00
|
|
|
if (isTextElement(el)) {
|
2020-03-14 21:48:51 -07:00
|
|
|
const element: ExcalidrawTextElement = newElementWith(el, {
|
2020-01-24 12:04:54 +02:00
|
|
|
font: `${el.font.split("px ")[0]}px ${value}`,
|
2020-03-10 20:11:02 -07:00
|
|
|
});
|
2020-01-12 02:22:03 +04:00
|
|
|
redrawTextBoundingBox(element);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return el;
|
2020-01-24 12:04:54 +02:00
|
|
|
}),
|
2020-01-25 18:58:57 +01:00
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
currentItemFont: `${
|
|
|
|
appState.currentItemFont.split("px ")[0]
|
|
|
|
}px ${value}`,
|
|
|
|
},
|
2020-03-19 14:51:05 +01:00
|
|
|
commitToHistory: true,
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
2020-01-31 21:06:06 +00:00
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
2020-01-25 14:52:03 -03:00
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.fontFamily")}</legend>
|
2020-01-12 02:22:03 +04:00
|
|
|
<ButtonSelect
|
2020-01-25 14:52:03 -03:00
|
|
|
group="font-family"
|
2020-01-12 02:22:03 +04:00
|
|
|
options={[
|
2020-01-21 01:14:10 +02:00
|
|
|
{ value: "Virgil", text: t("labels.handDrawn") },
|
|
|
|
{ value: "Helvetica", text: t("labels.normal") },
|
2020-01-24 12:04:54 +02:00
|
|
|
{ value: "Cascadia", text: t("labels.code") },
|
2020-01-12 02:22:03 +04:00
|
|
|
]}
|
2020-01-21 00:16:22 +01:00
|
|
|
value={getFormValue(
|
2020-01-12 02:22:03 +04:00
|
|
|
elements,
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-03-23 13:05:07 +02:00
|
|
|
(element) => isTextElement(element) && element.font.split("px ")[1],
|
2020-02-24 16:29:54 +01:00
|
|
|
(appState.currentItemFont || DEFAULT_FONT).split("px ")[1],
|
2020-01-12 02:22:03 +04:00
|
|
|
)}
|
2020-03-23 13:05:07 +02:00
|
|
|
onChange={(value) => updateData(value)}
|
2020-01-12 02:22:03 +04:00
|
|
|
/>
|
2020-01-25 14:52:03 -03:00
|
|
|
</fieldset>
|
2020-01-24 12:04:54 +02:00
|
|
|
),
|
2020-03-07 10:20:38 -05:00
|
|
|
});
|
2020-04-08 21:00:27 +01:00
|
|
|
|
|
|
|
export const actionChangeTextAlign = register({
|
|
|
|
name: "changeTextAlign",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return {
|
|
|
|
elements: changeProperty(elements, appState, (el) => {
|
|
|
|
if (isTextElement(el)) {
|
|
|
|
const element: ExcalidrawTextElement = newElementWith(el, {
|
|
|
|
textAlign: value,
|
|
|
|
});
|
|
|
|
redrawTextBoundingBox(element);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return el;
|
|
|
|
}),
|
|
|
|
appState: {
|
|
|
|
...appState,
|
|
|
|
currentItemTextAlign: value,
|
|
|
|
},
|
|
|
|
commitToHistory: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
PanelComponent: ({ elements, appState, updateData }) => (
|
|
|
|
<fieldset>
|
|
|
|
<legend>{t("labels.textAlign")}</legend>
|
|
|
|
<ButtonSelect<TextAlign | false>
|
|
|
|
group="text-align"
|
|
|
|
options={[
|
|
|
|
{ value: "left", text: t("labels.left") },
|
|
|
|
{ value: "center", text: t("labels.center") },
|
|
|
|
{ value: "right", text: t("labels.right") },
|
|
|
|
]}
|
|
|
|
value={getFormValue(
|
|
|
|
elements,
|
|
|
|
appState,
|
|
|
|
(element) => isTextElement(element) && element.textAlign,
|
|
|
|
appState.currentItemTextAlign,
|
|
|
|
)}
|
|
|
|
onChange={(value) => updateData(value)}
|
|
|
|
/>
|
|
|
|
</fieldset>
|
|
|
|
),
|
|
|
|
});
|