persist file name to LS

This commit is contained in:
Aakansha Doshi 2024-02-05 19:26:52 +05:30
parent 1bb88cb5e9
commit 1db2869906
8 changed files with 25 additions and 18 deletions

View File

@ -45,7 +45,6 @@ import {
ResolvablePromise, ResolvablePromise,
resolvablePromise, resolvablePromise,
isRunningInIframe, isRunningInIframe,
getDateTime,
} from "../packages/excalidraw/utils"; } from "../packages/excalidraw/utils";
import { import {
FIREBASE_STORAGE_PREFIXES, FIREBASE_STORAGE_PREFIXES,
@ -105,6 +104,7 @@ import { openConfirmModal } from "../packages/excalidraw/components/OverwriteCon
import { OverwriteConfirmDialog } from "../packages/excalidraw/components/OverwriteConfirm/OverwriteConfirm"; import { OverwriteConfirmDialog } from "../packages/excalidraw/components/OverwriteConfirm/OverwriteConfirm";
import Trans from "../packages/excalidraw/components/Trans"; import Trans from "../packages/excalidraw/components/Trans";
import { ShareDialog, shareDialogStateAtom } from "./share/ShareDialog"; import { ShareDialog, shareDialogStateAtom } from "./share/ShareDialog";
import { getFileName } from "../packages/excalidraw/data/filename";
polyfill(); polyfill();
@ -691,7 +691,6 @@ const ExcalidrawWrapper = () => {
</div> </div>
); );
} }
return ( return (
<div <div
style={{ height: "100%" }} style={{ height: "100%" }}
@ -776,7 +775,7 @@ const ExcalidrawWrapper = () => {
excalidrawAPI.getSceneElements(), excalidrawAPI.getSceneElements(),
excalidrawAPI.getAppState(), excalidrawAPI.getAppState(),
excalidrawAPI.getFiles(), excalidrawAPI.getFiles(),
`${t("labels.untitled")}-${getDateTime()}`, getFileName(),
); );
}} }}
> >

View File

@ -23,8 +23,9 @@ import { FILE_UPLOAD_MAX_BYTES } from "../app_constants";
import { encodeFilesForUpload } from "../data/FileManager"; import { encodeFilesForUpload } from "../data/FileManager";
import { MIME_TYPES } from "../../packages/excalidraw/constants"; import { MIME_TYPES } from "../../packages/excalidraw/constants";
import { trackEvent } from "../../packages/excalidraw/analytics"; import { trackEvent } from "../../packages/excalidraw/analytics";
import { getDateTime, getFrame } from "../../packages/excalidraw/utils"; import { getFrame } from "../../packages/excalidraw/utils";
import { ExcalidrawLogo } from "../../packages/excalidraw/components/ExcalidrawLogo"; import { ExcalidrawLogo } from "../../packages/excalidraw/components/ExcalidrawLogo";
import { getFileName } from "../../packages/excalidraw/data/filename";
export const exportToExcalidrawPlus = async ( export const exportToExcalidrawPlus = async (
elements: readonly NonDeletedExcalidrawElement[], elements: readonly NonDeletedExcalidrawElement[],
@ -122,7 +123,7 @@ export const ExportToExcalidrawPlus: React.FC<{
elements, elements,
appState, appState,
files, files,
`${t("labels.untitled")}-${getDateTime()}`, getFileName(),
); );
onSuccess(); onSuccess();
} catch (error: any) { } catch (error: any) {

View File

@ -13,7 +13,7 @@ import { exportCanvas, prepareElementsForExport } from "../data/index";
import { isTextElement } from "../element"; import { isTextElement } from "../element";
import { t } from "../i18n"; import { t } from "../i18n";
import { isFirefox } from "../constants"; import { isFirefox } from "../constants";
import { getDateTime } from "../utils"; import { getFileName } from "../data/filename";
export const actionCopy = register({ export const actionCopy = register({
name: "copy", name: "copy",
@ -139,7 +139,7 @@ export const actionCopyAsSvg = register({
{ {
...appState, ...appState,
exportingFrame, exportingFrame,
name: app.props.name || `${t("labels.untitled")}-${getDateTime()}`, name: app.props.name || getFileName(),
}, },
); );
return { return {
@ -186,7 +186,7 @@ export const actionCopyAsPng = register({
await exportCanvas("clipboard", exportedElements, appState, app.files, { await exportCanvas("clipboard", exportedElements, appState, app.files, {
...appState, ...appState,
exportingFrame, exportingFrame,
name: app.props.name || `${t("labels.untitled")}-${getDateTime()}`, name: app.props.name || getFileName(),
}); });
return { return {
appState: { appState: {

View File

@ -17,9 +17,9 @@ import { getNonDeletedElements } from "../element";
import { isImageFileHandle } from "../data/blob"; import { isImageFileHandle } from "../data/blob";
import { nativeFileSystemSupported } from "../data/filesystem"; import { nativeFileSystemSupported } from "../data/filesystem";
import { Theme } from "../element/types"; import { Theme } from "../element/types";
import { getFileName } from "../data/filename";
import "../components/ToolIcon.scss"; import "../components/ToolIcon.scss";
import { getDateTime } from "../utils";
export const actionChangeProjectName = register({ export const actionChangeProjectName = register({
name: "changeProjectName", name: "changeProjectName",
@ -149,13 +149,13 @@ export const actionSaveToActiveFile = register({
elements, elements,
appState, appState,
app.files, app.files,
app.props.name || `${t("labels.untitled")}-${getDateTime()}`, app.props.name || getFileName(),
) )
: await saveAsJSON( : await saveAsJSON(
elements, elements,
appState, appState,
app.files, app.files,
app.props.name || `${t("labels.untitled")}-${getDateTime()}`, app.props.name || getFileName(),
); );
return { return {
@ -201,7 +201,7 @@ export const actionSaveFileToDisk = register({
fileHandle: null, fileHandle: null,
}, },
app.files, app.files,
app.props.name || `${t("labels.untitled")}-${getDateTime()}`, app.props.name || getFileName(),
); );
return { return {
commitToHistory: false, commitToHistory: false,

View File

@ -270,7 +270,6 @@ import {
updateStable, updateStable,
addEventListener, addEventListener,
normalizeEOL, normalizeEOL,
getDateTime,
} from "../utils"; } from "../utils";
import { import {
createSrcDoc, createSrcDoc,
@ -410,6 +409,7 @@ import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils";
import { getRenderOpacity } from "../renderer/renderElement"; import { getRenderOpacity } from "../renderer/renderElement";
import { textWysiwyg } from "../element/textWysiwyg"; import { textWysiwyg } from "../element/textWysiwyg";
import { isOverScrollBars } from "../scene/scrollbars"; import { isOverScrollBars } from "../scene/scrollbars";
import { getFileName } from "../data/filename";
const AppContext = React.createContext<AppClassProperties>(null!); const AppContext = React.createContext<AppClassProperties>(null!);
const AppPropsContext = React.createContext<AppProps>(null!); const AppPropsContext = React.createContext<AppProps>(null!);
@ -1724,7 +1724,7 @@ class App extends React.Component<AppProps, AppState> {
this.files, this.files,
{ {
exportBackground: this.state.exportBackground, exportBackground: this.state.exportBackground,
name: this.props?.name || `${t("labels.untitled")}-${getDateTime()}`, name: this.props?.name || getFileName(),
viewBackgroundColor: this.state.viewBackgroundColor, viewBackgroundColor: this.state.viewBackgroundColor,
exportingFrame: opts.exportingFrame, exportingFrame: opts.exportingFrame,
}, },

View File

@ -34,8 +34,9 @@ import { Tooltip } from "./Tooltip";
import "./ImageExportDialog.scss"; import "./ImageExportDialog.scss";
import { useAppProps } from "./App"; import { useAppProps } from "./App";
import { FilledButton } from "./FilledButton"; import { FilledButton } from "./FilledButton";
import { cloneJSON, getDateTime } from "../utils"; import { cloneJSON } from "../utils";
import { prepareElementsForExport } from "../data"; import { prepareElementsForExport } from "../data";
import { getFileName } from "../data/filename";
const supportsContextFilters = const supportsContextFilters =
"filter" in document.createElement("canvas").getContext("2d")!; "filter" in document.createElement("canvas").getContext("2d")!;
@ -74,7 +75,7 @@ const ImageExportModal = ({
const appProps = useAppProps(); const appProps = useAppProps();
const [projectName, setProjectName] = useState( const [projectName, setProjectName] = useState(
appProps.name || `${t("labels.untitled")}-${getDateTime()}`, appProps.name || getFileName(),
); );
const [exportSelectionOnly, setExportSelectionOnly] = useState(hasSelection); const [exportSelectionOnly, setExportSelectionOnly] = useState(hasSelection);
const [exportWithBackground, setExportWithBackground] = useState( const [exportWithBackground, setExportWithBackground] = useState(

View File

@ -1,12 +1,15 @@
import "./TextInput.scss"; import "./TextInput.scss";
import React, { useState } from "react"; import React, { useState } from "react";
import { focusNearestParent, getDateTime } from "../utils"; import { focusNearestParent } from "../utils";
import "./ProjectName.scss"; import "./ProjectName.scss";
import { useExcalidrawContainer } from "./App"; import { useExcalidrawContainer } from "./App";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { t } from "../i18n"; import { t } from "../i18n";
import { EditorLocalStorage } from "../data/EditorLocalStorage";
import { EDITOR_LS_KEYS } from "../constants";
import { getFileName } from "../data/filename";
type Props = { type Props = {
value?: string; value?: string;
@ -19,10 +22,12 @@ type Props = {
export const ProjectName = (props: Props) => { export const ProjectName = (props: Props) => {
const { id } = useExcalidrawContainer(); const { id } = useExcalidrawContainer();
const [fileName, setFileName] = useState<string>( const [fileName, setFileName] = useState<string>(
props.value || `${t("labels.untitled")}-${getDateTime()}`, props.value || getFileName(),
); );
const handleBlur = (event: any) => { const handleBlur = (event: any) => {
EditorLocalStorage.set(EDITOR_LS_KEYS.EXCALIDRAW_FILE_NAME, fileName);
if (!props.ignoreFocus) { if (!props.ignoreFocus) {
focusNearestParent(event.target); focusNearestParent(event.target);
} }

View File

@ -380,4 +380,5 @@ export const EDITOR_LS_KEYS = {
// legacy naming (non)scheme // legacy naming (non)scheme
MERMAID_TO_EXCALIDRAW: "mermaid-to-excalidraw", MERMAID_TO_EXCALIDRAW: "mermaid-to-excalidraw",
PUBLISH_LIBRARY: "publish-library-data", PUBLISH_LIBRARY: "publish-library-data",
EXCALIDRAW_FILE_NAME: "excalidraw-file-name",
} as const; } as const;