Skip to content

Commit

Permalink
add excalidoc as file option
Browse files Browse the repository at this point in the history
  • Loading branch information
lebalz committed Nov 26, 2024
1 parent 6bddfdb commit 18992c8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/components/documents/Excalidoc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import { useDocument } from '@tdev-hooks/useDocument';
import { DocumentType } from '@tdev-api/document';

export const DEFAULT_HEIGHT = '600px' as const;
export const mdiExcalidraw =
'M19.692 18.8418a.1131.1131 90 00-.1092-.0247c-.8635-1.2757-1.962-2.4855-3.0254-3.654l-.1752-.1917c0-.0227-.0103-.0433-.0247-.0618a.1129.1129 90 00-.0701-.0412l-.035-.0371-.0247-.0185c-.0309-.0659-.1092-.1154-.1958-.0721-.3256.1669-.6183.406-.9068.6265-.3854.2947-.7625.6018-1.117.9315-.1443.134-.2865.2741-.406.4307-.0577.0763-.0144.1484.0556.1793-.2514.2473-.5049.5049-.7584.7708-.0227.0247-.035.0577-.033.0907s.0185.0639.0453.0845l.4452.3401s.0021.0062.0062.0082c.6368.6286 1.7539 1.5004 2.9368 2.4237.1752.1381.3524.2762.5297.4142.0804.0969.1566.1937.2308.2885.0392.0515.1134.0618.1649.0227.0268.0206.0536.0433.0804.0639a.1175.1175 90 00.1649-.0206c.0144-.0185.0206-.0412.0227-.0639.0082 0 .0144.0062.0206.0062.0309 0 .0639-.0124.0866-.0371l2.098-2.2918a.1154.1154 90 00-.0082-.1649l.0021-.0021Zm-6.0241-.7935c.0144.0185.0289.035.0433.0515.2391.202.4946.4204.7543.643l-1.0552-.8058s-.0659-.0453-.1072-.0742c-.0227-.0165-.0433-.033-.0639-.0495l-.0783-.0659s.0144-.0144.0206-.0227l.0721-.0721c.3545-.3586.9625-.9563 1.2757-1.2489-.3318.3339-1.0037 1.3128-.8594 1.6446h-.0021Zm3.6128 2.8461-.8697-.6636c-.3401-.3524-.7069-.7007-1.0799-1.0366.4699.3627.8718.6698.9315.7234.4555.406.4349.3318.7481.5997l.3772.2741c-.0371.033-.0742.068-.1092.101l.0021.0021Zm.2185.1669-.0165-.0124c.033-.0268.068-.0515.101-.0783l-.0824.0907h-.0021ZM3.7054 7.6035c.0289.1484.0556.2947.0824.4349.1422.7625.2741 1.4488.5255 1.9703l.0989.3957c.0392.1504.0948.338.1463.3772.5874.5194 1.488 1.2943 2.4504 2.0238.0433.033.103.0309.1443-.0021.0021.0041.0062.0062.0082.0082.0227.0206.0495.0309.0783.0309.033 0 .0639-.0124.0866-.0392 1.2324-1.3705 2.1496-2.4978 2.8029-3.4418.0412-.0515.0618-.1113.0598-.1731.0412-.0495.0845-.0989.1237-.1401a.115.115 90 00-.0206-.1772.1191.1191 90 00-.035-.0742c-.2865-.2762-.4987-.4761-.7131-.676-.3792-.3545-.7708-.7213-1.6013-1.5478-.0041-.0041-.0103-.0082-.0144-.0124a.1144.1144 90 00-.0453-.0289c-.2288-.0804-.6987-.1608-1.2901-.2638-.8697-.1484-2.0609-.3545-3.1326-.6739h-.0082V5.592s-.0041 0-.0062.0041h-.0021l.0082-.0041s-.0639.0021-.0763.0082c-.0165.0082-.0289.0185-.0392.0309s-.0185.0247-.0969.0412.0165 0 .0227 0h-.0227v.0062c.0144.0701.0103.1195.033.1999-.0041.0206.0433.2102.0495.2288l.3772 1.4962h.0062Zm6.3786 1.3478s-.0062.0082-.0082.0103l-.1319-.1463c.0453.0433.0907.0866.1401.136ZM8.6228 10.8866s-.0144.0165-.0206.0247l-.0041-.0041c.0082-.0062.0165-.0144.0268-.0206h-.0021Zm-1.4571 1.7456Zm.6224-5.8881c.0721.0721.3586.3401.4246.406-.2988-.136-1.0428-.4823-1.3891-.5935.3401.0598.8099.136.9645.1875Zm-3.9529-.5709c.1731.2968.3091 1.3375.4452 2.3495-.0763-.3256-.1422-.643-.204-.948-.1072-.5276-.2061-.9996-.3442-1.4179.0289.0021.0639.0062.101.0103 0 .0021 0 .0041.0041.0062h-.0021Zm-.0598-.2494c-.0474-.0041-.0907-.0082-.1278-.0103-.0041-.0082-.0062-.0165-.0082-.0247l.136.0371v-.0021Zm-.4575.0927v-.0041.0041Zm16.1866-.2432c.0082-.0474-.2267-.2556-.1525-.2597.1752-.0082.1772-.2782 0-.27-.2329.0124-.4678.0659-.6945.1092-.4081.0763-.8141.1608-1.2201.2494-.9047.1937-1.8074.3978-2.6998.6409-.2803.0763-.5894.1443-.847.2803-.0866.0453-.0824.1381-.035.1958-.0185.0103-.0371.0165-.0577.0185-.0763.0144-.1525.0268-.2288.0392a.1166.1166 90 00-.0804.1772c-.4781.6389-1.0222 1.3272-1.6116 2.0506-.5791.6616-1.1809 1.3664-1.7971 2.0898-1.9393 2.2794-4.1384 4.8638-6.5744 7.1391-.0474.0433-.0495.1175-.0062.1649.0103.0124.0247.0206.0392.0268-.033.0309-.0659.0618-.0989.0907-.0206.0185-.0289.0412-.033.0659-.0165.0165-.033.035-.0474.0515-.0433.0474-.0412.1216.0062.1649s.1216.0412.1649-.0062c.0082-.0082.0165-.0185.0247-.0268a.1731.1731 90 01.2514 0c.1422.1525.2762.2968.4019.4307l-.2844-.237a.1175.1175 90 00-.1649.0144c-.0412.0495-.035.1237.0144.1649l3.0543 2.5617c.0227.0185.0495.0268.0763.0268.0309 0 .0598-.0124.0824-.035l.0742-.0742a.1154.1154 90 00.1298-.0247c4.1404-4.159 7.475-7.3019 11.2939-10.1109.035-.0247.0515-.0659.0474-.1051a.1175.1175 90 00.0989-.0804c.7048-2.1557.8409-4.0642.8821-5.0019 0-.0062.0021-.0103.0041-.0144.0041-.0103.0062-.0206.0082-.0289.0062-.0227.0103-.0392.0103-.0392.0536-.1608.035-.3153-.0309-.4431v.0041ZM12.1016 9.1471c.1855-.2123.3689-.4204.5503-.6224-1.1871 1.5622-3.1532 3.9694-5.9375 6.8299 1.8961-2.098 3.8065-4.2723 5.3873-6.2075Zm-6.7083 10.8838-.0062-.0062c.0227.0041.0392.0082.0412.0082a.0969.0969 90 00-.035 0v-.0021Zm1.422 1.3231-.0103-.0082.0062-.0062c.0041 0 .0062.0041.0082.0041 0 .0041-.0041.0062-.0062.0103h.0021Zm1.7229-1.4859.2844-.2968c.0021.0021.0041.0062.0062.0103-.0969.0948-.1937.1917-.2927.2865h.0021Zm.4616-.4555c.0536-.0618.1154-.134.1793-.2102.0021-.0021.0041-.0062.0082-.0082.678-.6987 1.3767-1.4056 2.098-2.1125.0041-.0041.0103-.0082.0144-.0124.1772-.136.3751-.2865.5606-.4287-.9315.8903-1.8775 1.8095-2.8606 2.774v-.0021Zm4.4619-11.5165c-.3833.4987-.8038 1.1459-1.1603 1.6632-1.1253 1.6302-4.7484 5.6222-4.8288 5.6985-.5585.54-2.2423 2.1557-3.316 3.1677-.0289.0268-.0515.0495-.0701.0721a.1636.1636 90 01.0062-.2329c5.1152-4.8226 8.219-8.8393 9.4803-10.5891-.0268.068-.0495.1422-.1134.2246l.0021-.0041Zm3.4026 1.4633-.0021.0041c0-.0041-.0041-.0144.0021-.0041Zm-.1875-1.0573ZM15.463 10.2497c-.4658-.27-.6842-.6739-.5585-1.082l.0392-.136c.0165-.0392.035-.0783.0577-.1175.1216-.202.3071-.3813.5194-.4864.0103-.0041.0206-.0062.0309-.0082a.1638.1638 90 01-.0082-.0886c.0103-.0639.0515-.1195.136-.1195.1381 0 .5668.1278.7296.2679.0495.0392.0969.0824.1401.1298.0618.0721.1525.1896.1978.2741.0268.0124.0474.1278.0783.1875.0289.0948.0412.1917.0371.2885 0 .0041 0 .0041.0021.0062-.0062.0144 0 .0763-.0082.0824-.0206.1484-.0742.2947-.1546.4225-.0082.0103-.0144.0227-.0227.033 0 .0021-.0041.0041-.0062.0082-.0618.0886-.134.1711-.2226.2329-.2597.1834-.5626.2391-.8656.1628a1.3046 1.3046 90 01-.1175-.0515l-.0041-.0062Zm3.3531-.3359c-.101.4225-.2246.8635-.371 1.3149-.0062.0165-.0062.033-.0062.0474-.0206.0021-.0392.0103-.0556.0227-.9151.6719-1.7992 1.3643-2.6751 2.0836.7564-.6842 1.523-1.3643 2.3144-2.0506a1.3209 1.3209 90 00.4349-.7708l.1154-.6945.0062-.0206c.0515-.1463.2762-.0824.2411.068h-.0041Z' as const;
export const mdiExcalidrawOutline =
'M19.692 18.8418a.1131.1131 90 00-.1092-.0247c-.8635-1.2757-1.962-2.4855-3.0254-3.654l-.1752-.1917c0-.0227-.0103-.0433-.0247-.0618a.1129.1129 90 00-.0701-.0412l-.035-.0371-.0247-.0185c-.0309-.0659-.1092-.1154-.1958-.0721-.3256.1669-.6183.406-.9068.6265-.3854.2947-.7625.6018-1.117.9315-.1443.134-.2865.2741-.406.4307-.0577.0763-.0144.1484.0556.1793-.2514.2473-.5049.5049-.7584.7708-.0227.0247-.035.0577-.033.0907s.0185.0639.0453.0845l.4452.3401s.0021.0062.0062.0082c.6368.6286 1.7539 1.5004 2.9368 2.4237.1752.1381.3524.2762.5297.4142.0804.0969.1566.1937.2308.2885.0392.0515.1134.0618.1649.0227.0268.0206.0536.0433.0804.0639a.1175.1175 90 00.1649-.0206c.0144-.0185.0206-.0412.0227-.0639.0082 0 .0144.0062.0206.0062.0309 0 .0639-.0124.0866-.0371l2.098-2.2918a.1154.1154 90 00-.0082-.1649l.0021-.0021Zm-6.0241-.7935c1.3611-1.4553 1.8521-.3163.0433.0515.2391.202.4946.4204.7543.643l-1.0552-.8058s-.0659-.0453-.1072-.0742c-.0227-.0165-.0433-.033-.0639-.0495l-.0783-.0659s.0144-.0144.0206-.0227l.0721-.0721c.3545-.3586.9625-.9563 3.6214-1.5756-1.6365 1.2636-2.3084 2.2425-2.1641 2.5743h.0241Zm3.6128 2.8461-.8697-.6636c-.3401-.3524-.7069-.7007-3.365-2.4208 2.755 1.7469 2.278-7.794 2.987 1.471-1.5119-.0384 3.357-3.259-.432.315l-.4101.1144c-.0371.033-.0742.068-.1092.101l.0021.0021Zm.2185.1669-.0165-.0124c.033-.0268.068-.0515.101-.0783l-.0824.0907h-.0021ZM3.7054 7.6035c.0289.1484.0556.2947.0824.4349.1422.7625.2741 1.4488.5255 1.9703l.0989.3957c.0392.1504.0948.338.1463.3772.5874.5194 1.488 1.2943 2.4504 2.0238.0433.033.103.0309.1443-.0021.0021.0041.0062.0062.0082.0082.0227.0206.0495.0309.0783.0309.033 0 .0639-.0124.0866-.0392 1.2324-1.3705 2.1496-2.4978 2.8029-3.4418.0412-.0515.0618-.1113.0598-.1731.0412-.0495.0845-.0989.1237-.1401A.115.115 90 0010.2921 8.871a.1191.1191 90 00-.035-.0742c-.2865-.2762-.4987-.4761-.7131-.676-.3792-.3545-.7708-.7213-1.6013-1.5478-.0041-.0041-.0103-.0082-.0144-.0124A.1144.1144 90 007.883 6.5317c-.2288-.0804-.6987-.1608-1.2901-.2638-.8697-.1484-2.0609-.3545-3.1326-.6739H3.4521V5.592s-.0041 0-.0062.0041H3.4438L3.452 5.592s-.0639.0021-.0763.0082c-.0165.0082-.0289.0185-.0392.0309s-.0185.0247-.0969.0412.0165 0 .0227 0H3.2396v.0062c.0144.0701.0103.1195.033.1999-.0041.0206.0433.2102.0495.2288l.3772 1.4962h.0062ZM10.084 8.9513s-.0062.0082-.0082.0103l-.1319-.1463c.0453.0433.0907.0866.1401.136ZM8.6228 10.8866s-.0144.0165-.0206.0247l-.0041-.0041c.0082-.0062.0165-.0144.0268-.0206H8.6228ZM7.1657 12.6322Zm.6224-5.8881C3.569 11.33 9.984 8.936 8.2127 7.1501 6.45 19.557 7.1699 6.6678 3.701 5.912c3.4627.7044 3.9325.7806 4.0871.8321ZM3.8352 6.1732c.1731.2968.3091 1.3375.4452 2.3495-.0763-.3256-.1422-.643-.204-.948-.1072-.5276-.2061-.9996-.3442-1.4179.0289.0021.0639.0062.101.0103 0 .0021 0 .0041.0041.0062H3.8352Zm-.0598-.2494C9.179 13.687 3.917 8.19 3.6476 5.9135c2.9784 8.5395-.3586.3525-.0082-.0247l.136.0371V5.9238Zm-.4575.0927V6.0124v.0041Zm16.1866-.2432c.0082-.0474-.2267-.2556-.1525-.2597.1752-.0082.1772-.2782 0-.27-.2329.0124-.4678.0659-.6945.1092-.4081.0763-.8141.1608-1.2201.2494-.9047.1937-1.8074.3978-2.6998.6409-.2803.0763-.5894.1443-.847.2803-.0866.0453-.0824.1381-.035.1958-.0185.0103-.0371.0165-.0577.0185-.0763.0144-.1525.0268-.2288.0392a.1166.1166 90 00-.0804.1772c-.4781.6389-1.0222 1.3272-1.6116 2.0506-.5791.6616-1.1809 1.3664-1.7971 2.0898-1.9393 2.2794-4.1384 4.8638-6.5744 7.1391-.0474.0433-.0495.1175-.0062.1649.0103.0124.0247.0206.0392.0268-.033.0309-.0659.0618-.0989.0907-.0206.0185-.0289.0412-.033.0659-.0165.0165-.033.035-.0474.0515-.0433.0474-.0412.1216.0062.1649s.1216.0412.1649-.0062c.0082-.0082.0165-.0185.0247-.0268a.1731.1731 90 01.2514 0c.1422.1525.2762.2968.4019.4307l-.2844-.237a.1175.1175 90 00-.1649.0144c-.0412.0495-.035.1237.0144.1649L6.8278 21.7c.0227.0185.0495.0268.0763.0268.0309 0 .0598-.0124.0824-.035l.0742-.0742a.1154.1154 90 00.1298-.0247c4.1404-4.159 7.475-7.3019 11.2939-10.1109.035-.0247.0515-.0659.0474-.1051a.1175.1175 90 00.0989-.0804c.7048-2.1557.8409-4.0642.8821-5.0019 0-.0062.0021-.0103.0041-.0144.0041-.0103.0062-.0206.0082-.0289.0062-.0227.0103-.0392.0103-.0392.0536-.1608.035-.3153-.0309-.4431v.0041ZM12.1016 9.1471c.1855-.2123.3689-.4204.5503-.6224-1.1871 1.5622-3.1532 3.9694-5.9375 6.8299 1.8961-2.098 3.8065-4.2723 5.3873-6.2075ZM5.3933 20.0309l-.0062-.0062c.0227.0041.0392.0082.0412.0082a.0969.0969 90 00-.035 0v-.0021Zm1.422 1.3231-.0103-.0082.0062-.0062c.0041 0 .0062.0041.0082.0041 0 .0041-.0041.0062-.0062.0103h.0021Zm1.7229-1.4859.2844-.2968c.0021.0021.0041.0062.0062.0103-.0969.0948-.1937.1917-.2927.2865h.0021Zm.4616-.4555c.0536-.0618.1154-.134.1793-.2102.0021-.0021.0041-.0062.0082-.0082.678-.6987 1.3767-1.4056 2.098-2.1125.0041-.0041.0103-.0082.0144-.0124.1772-.136.3751-.2865.5606-.4287-.9315.8903-1.8775 1.8095-2.8606 2.774v-.0021ZM6.562 18.673c9.0017-9.9653 8.5812-9.3181 10.22-10.944.647-.099 3.2-.589 1.208-.261a.1636.1636 90 01-.437-.675c-.059.962-.137 3.122-1.551 4.81-.001-1.152.391.36-3.996 2.328L7.243 17.724ZM18.5956 9.8123l-.0021.0041c0-.0041-.0041-.0144.0021-.0041ZM16.6541 8.498ZM15.463 10.2497c-.4658-.27-.6842-.6739-.5585-1.082l.0392-.136c.0165-.0392.035-.0783.0577-.1175.1216-.202.3071-.3813.5194-.4864.0103-.0041.0206-.0062.0309-.0082a.1638.1638 90 01-.0082-.0886c.0103-.0639.0515-.1195.136-.1195.1381 0 .5668.1278.7296.2679.0495.0392.0969.0824.1401.1298.0618.0721.1525.1896.1978.2741.0268.0124.0474.1278.0783.1875.0289.0948.0412.1917.0371.2885 0 .0041 0 .0041.0021.0062-.0062.0144 0 .0763-.0082.0824-.0206.1484-.0742.2947-.1546.4225-.0082.0103-.0144.0227-.0227.033 0 .0021-.0041.0041-.0062.0082-.0618.0886-.134.1711-.2226.2329-.2597.1834-.5626.2391-.8656.1628a1.3046 1.3046 90 01-.1175-.0515l-.0041-.0062Zm3.3531-.3359c-.101.4225-.2246.8635-.371 1.3149-.0062.0165-.0062.033-.0062.0474-.0206.0021-.0392.0103-.0556.0227-.9151.6719-1.7992 1.3643-2.6751 2.0836.7564-.6842 1.523-1.3643 2.3144-2.0506a1.3209 1.3209 90 00.4349-.7708l.1154-.6945.0062-.0206c.0515-.1463.2762-.0824.2411.068h-.0041Z' as const;
export const ExcalidrawColor = '#6965db';

interface ExcaliProps {
id: string;
Expand Down
48 changes: 45 additions & 3 deletions src/components/documents/FileSystem/Directory/NewItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Directory from '@tdev-models/documents/FileSystem/Directory';
import { Delta } from 'quill/core';
import DocumentStore from '@tdev-stores/DocumentStore';
import Icon from '@mdi/react';
import TextInput from '@tdev-components/shared/TextInput';
import { ExcalidrawColor, mdiExcalidraw } from '@tdev-components/documents/Excalidoc';

interface Props {
directory: Directory;
Expand All @@ -34,15 +36,27 @@ const withFile = async (store: DocumentStore, rootId: string, parentId: string,
});
};

const asPyName = (name: string) => {
if (!name) {
return 'programm.py';
}
if (/\.py$/i.test(name)) {
return name;
}
return `${name}.py`;
};

const NewItem = observer((props: Props) => {
const ref = React.useRef(null);
const [name, setName] = React.useState('');
const documentStore = useStore('documentStore');
const closeTooltip = () => (ref.current as any)?.close();
const { directory } = props;
if (!directory.root) {
return null;
}
const rootId = directory.root.id;
console.log(mdiLanguagePython);
return (
<Popup
trigger={
Expand All @@ -61,14 +75,15 @@ const NewItem = observer((props: Props) => {
</h4>
</div>
<div className={clsx('card__body', styles.body)}>
<TextInput onChange={setName} placeholder="Name" />
<Button
text="Neues Python Snippet"
color="rgb(19, 165, 0)"
size={0.8}
icon={mdiLanguagePython}
iconSide="left"
onClick={async () => {
withFile(documentStore, rootId, directory.id, 'programm.py')
withFile(documentStore, rootId, directory.id, asPyName(name))
.then((file) => {
if (file) {
return documentStore.create({
Expand All @@ -93,7 +108,7 @@ const NewItem = observer((props: Props) => {
icon={mdiFileDocument}
iconSide="left"
onClick={async () => {
withFile(documentStore, rootId, directory.id, 'notiz')
withFile(documentStore, rootId, directory.id, name || 'Noitz')
.then((file) => {
if (file) {
return documentStore.create({
Expand All @@ -111,6 +126,33 @@ const NewItem = observer((props: Props) => {
});
}}
/>
<Button
text="Neue Skizze"
color={ExcalidrawColor}
size={0.8}
icon={mdiExcalidraw}
iconSide="left"
onClick={async () => {
withFile(documentStore, rootId, directory.id, name || 'Skizze')
.then((file) => {
if (file) {
return documentStore.create({
documentRootId: rootId,
parentId: file.id,
type: DocumentType.Excalidoc,
data: {
elements: [],
files: {},
image: ''
}
});
}
})
.then(() => {
closeTooltip();
});
}}
/>
<Button
text="Neuer Ordner"
color="black"
Expand All @@ -123,7 +165,7 @@ const NewItem = observer((props: Props) => {
parentId: directory.id,
type: DocumentType.Dir,
data: {
name: 'Ordner',
name: name || 'Ordner',
isOpen: true
}
});
Expand Down
19 changes: 19 additions & 0 deletions src/components/documents/FileSystem/File/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { QuillV2Component } from '../../QuillV2';
import Actions from '../Actions';
import Name from '../Name';
import FsDetails from '../FsDetails';
import {
ExcalidocComponent,
ExcalidrawColor,
mdiExcalidraw,
mdiExcalidrawOutline
} from '@tdev-components/documents/Excalidoc';

interface Props {
file: FileModel;
Expand All @@ -31,6 +37,8 @@ const getColor = (type?: DocumentType) => {
return 'var(--ifm-color-blue)';
case DocumentType.Script:
return 'rgb(19, 165, 0)';
case DocumentType.Excalidoc:
return ExcalidrawColor;
default:
return undefined;
}
Expand All @@ -42,6 +50,8 @@ const getIcon = (type?: DocumentType) => {
return mdiFileDocumentOutline;
case DocumentType.Script:
return mdiFileCodeOutline;
case DocumentType.Excalidoc:
return mdiExcalidrawOutline;
default:
return mdiFileOutline;
}
Expand All @@ -53,6 +63,8 @@ const getOpenIcon = (type?: DocumentType) => {
return mdiFileDocument;
case DocumentType.Script:
return mdiFileCode;
case DocumentType.Excalidoc:
return mdiExcalidraw;
default:
return mdiFile;
}
Expand Down Expand Up @@ -91,6 +103,13 @@ const File = observer((props: Props) => {
{file.document.type === DocumentType.QuillV2 && (
<QuillV2Component quillDoc={file.document} className={styles.quill} />
)}
{file.document.type === DocumentType.Excalidoc && (
<ExcalidocComponent
documentId={file.document.id}
height="80vh"
allowImageInsertion
/>
)}
</>
)}
</div>
Expand Down

0 comments on commit 18992c8

Please sign in to comment.