import React from "react"; import { EVENT_CHANGE, EVENT_IO, trackEvent } from "../analytics"; import { load, save, saveAs } from "../components/icons"; import { ProjectName } from "../components/ProjectName"; import { ToolButton } from "../components/ToolButton"; import { loadFromJSON, saveAsJSON } from "../data"; import { t } from "../i18n"; import useIsMobile from "../is-mobile"; import { KEYS } from "../keys"; import { muteFSAbortError } from "../utils"; import { register } from "./register"; export const actionChangeProjectName = register({ name: "changeProjectName", perform: (_elements, appState, value) => { trackEvent(EVENT_CHANGE, "title"); return { appState: { ...appState, name: value }, commitToHistory: false }; }, PanelComponent: ({ appState, updateData }) => ( updateData(name)} /> ), }); export const actionChangeExportBackground = register({ name: "changeExportBackground", perform: (_elements, appState, value) => { return { appState: { ...appState, exportBackground: value }, commitToHistory: false, }; }, PanelComponent: ({ appState, updateData }) => ( ), }); export const actionChangeExportEmbedScene = register({ name: "changeExportEmbedScene", perform: (_elements, appState, value) => { return { appState: { ...appState, exportEmbedScene: value }, commitToHistory: false, }; }, PanelComponent: ({ appState, updateData }) => ( ), }); export const actionChangeShouldAddWatermark = register({ name: "changeShouldAddWatermark", perform: (_elements, appState, value) => { return { appState: { ...appState, shouldAddWatermark: value }, commitToHistory: false, }; }, PanelComponent: ({ appState, updateData }) => ( ), }); export const actionSaveScene = register({ name: "saveScene", perform: async (elements, appState, value) => { try { const { fileHandle } = await saveAsJSON(elements, appState); trackEvent(EVENT_IO, "save"); return { commitToHistory: false, appState: { ...appState, fileHandle } }; } catch (error) { if (error?.name !== "AbortError") { console.error(error); } return { commitToHistory: false }; } }, keyTest: (event) => event.key === KEYS.S && event[KEYS.CTRL_OR_CMD] && !event.shiftKey, PanelComponent: ({ updateData }) => ( updateData(null)} /> ), }); export const actionSaveAsScene = register({ name: "saveAsScene", perform: async (elements, appState, value) => { try { const { fileHandle } = await saveAsJSON(elements, { ...appState, fileHandle: null, }); trackEvent(EVENT_IO, "save as"); return { commitToHistory: false, appState: { ...appState, fileHandle } }; } catch (error) { if (error?.name !== "AbortError") { console.error(error); } return { commitToHistory: false }; } }, keyTest: (event) => event.key === KEYS.S && event.shiftKey && event[KEYS.CTRL_OR_CMD], PanelComponent: ({ updateData }) => (