diff --git a/website/playground/EditorState.js b/website/playground/EditorState.js deleted file mode 100644 index 21c620dce..000000000 --- a/website/playground/EditorState.js +++ /dev/null @@ -1,43 +0,0 @@ -import { reactive, watch } from "vue"; -import * as storage from "./storage.js"; - -export default { - name: "EditorState", - setup(_, { slots }) { - const stateToggler = (property) => () => { - state[property] = !state[property]; - }; - const state = reactive({ - showSidebar: window.innerWidth > window.innerHeight, - showAst: false, - showPreprocessedAst: false, - showDoc: false, - showComments: false, - showSecondFormat: false, - showInput: true, - showOutput: true, - rethrowEmbedErrors: false, - toggleSidebar: stateToggler("showSidebar"), - toggleAst: stateToggler("showAst"), - togglePreprocessedAst: stateToggler("showPreprocessedAst"), - toggleDoc: stateToggler("showDoc"), - toggleComments: stateToggler("showComments"), - toggleSecondFormat: stateToggler("showSecondFormat"), - toggleInput: stateToggler("showInput"), - toggleOutput: stateToggler("showOutput"), - toggleEmbedErrors: stateToggler("rethrowEmbedErrors"), - ...storage.get("editor_state"), - }); - - const render = () => slots.default(state); - - watch( - () => state, - () => { - storage.set("editor_state", state); - }, - { deep: true }, - ); - return render; - }, -}; diff --git a/website/playground/Playground.jsx b/website/playground/Playground.jsx index 5dc53d88b..0a6c7cc11 100644 --- a/website/playground/Playground.jsx +++ b/website/playground/Playground.jsx @@ -1,8 +1,8 @@ import { reactive, watch } from "vue"; import { Button, ClipboardButton } from "./buttons.jsx"; import getCodeSample from "./codeSamples.mjs"; +import { editorState } from "./composables/editor-state.js"; import generateDummyId from "./dummyId.js"; -import EditorState from "./EditorState.js"; import formatMarkdown from "./markdown.js"; import { getCodemirrorMode } from "./panel/language.js"; import { DebugPanel, InputPanel, OutputPanel } from "./panels.jsx"; @@ -238,309 +238,299 @@ function setup(props) { const { content, options } = state; return ( - - {(editorState) => ( - - {({ formatted, debug, cursorOffset }) => { - const { content, options } = state; - const fullReport = getMarkdown({ - formatted, - reformatted: debug.reformatted, - full: true, - }); - const showFullReport = - encodeURIComponent(fullReport).length < MAX_LENGTH; - const isDocExplorer = options.parser === "doc-explorer"; + + {({ formatted, debug, cursorOffset }) => { + const { content, options } = state; + const fullReport = getMarkdown({ + formatted, + reformatted: debug.reformatted, + full: true, + }); + const showFullReport = + encodeURIComponent(fullReport).length < MAX_LENGTH; + const isDocExplorer = options.parser === "doc-explorer"; - return ( - <> -
- - - {isDocExplorer ? null : ( - - - - )} - {isDocExplorer ? null : ( - - - )} - - - - {isDocExplorer ? null : ( - - )} - {isDocExplorer ? null : ( - - )} - {isDocExplorer ? null : ( - - )} - - {isDocExplorer ? null : ( - - )} - {isDocExplorer ? null : ( - - )} - {editorState.showDoc && !isDocExplorer ? ( - getMarkdown({ doc: debug.doc })} - disabled={!debug.doc} - > - Copy doc - - ) : null} - -
- -
-
-
- {editorState.showInput ? ( - - ) : null} - {editorState.showAst ? ( - - ) : null} - {editorState.showPreprocessedAst && !isDocExplorer ? ( - - ) : null} - {editorState.showDoc && !isDocExplorer ? ( - - ) : null} - {editorState.showComments && !isDocExplorer ? ( - - ) : null} - {editorState.showOutput ? ( - - ) : null} - {editorState.showSecondFormat && !isDocExplorer ? ( - - ) : null} -
-
-
-
- - - - Copy config JSON - - -
-
- - Copy link - - - getMarkdown({ - formatted, - reformatted: debug.reformatted, - }) + return ( + <> +
+ + + {isDocExplorer ? null : ( + + + + )} + {isDocExplorer ? null : ( + + + )} + + + + {isDocExplorer ? null : ( + + )} + {isDocExplorer ? null : ( + + )} + {isDocExplorer ? null : ( + + )} + + {isDocExplorer ? null : ( + + )} + {isDocExplorer ? null : ( + + )} + {editorState.showDoc && !isDocExplorer ? ( + getMarkdown({ doc: debug.doc })} + disabled={!debug.doc} + > + Copy doc - - (showFullReport ? "" : fullReport)} - > - Report issue - - -
+ ) : null} + +
+
- - ); - }} - - )} - + +
+ {editorState.showInput ? ( + + ) : null} + {editorState.showAst ? ( + + ) : null} + {editorState.showPreprocessedAst && !isDocExplorer ? ( + + ) : null} + {editorState.showDoc && !isDocExplorer ? ( + + ) : null} + {editorState.showComments && !isDocExplorer ? ( + + ) : null} + {editorState.showOutput ? ( + + ) : null} + {editorState.showSecondFormat && !isDocExplorer ? ( + + ) : null} +
+
+
+
+ + + + Copy config JSON + + +
+
+ + Copy link + + + getMarkdown({ + formatted, + reformatted: debug.reformatted, + }) + } + > + Copy markdown + + + (showFullReport ? "" : fullReport)} + > + Report issue + + +
+
+ + ); + }} + ); }; diff --git a/website/playground/composables/editor-state.js b/website/playground/composables/editor-state.js new file mode 100644 index 000000000..421192995 --- /dev/null +++ b/website/playground/composables/editor-state.js @@ -0,0 +1,38 @@ +import { reactive, watch } from "vue"; +import * as storage from "../storage.js"; + +const stateToggler = (property) => () => { + state[property] = !state[property]; +}; + +const state = reactive({ + showSidebar: window.innerWidth > window.innerHeight, + showAst: false, + showPreprocessedAst: false, + showDoc: false, + showComments: false, + showSecondFormat: false, + showInput: true, + showOutput: true, + rethrowEmbedErrors: false, + toggleSidebar: stateToggler("showSidebar"), + toggleAst: stateToggler("showAst"), + togglePreprocessedAst: stateToggler("showPreprocessedAst"), + toggleDoc: stateToggler("showDoc"), + toggleComments: stateToggler("showComments"), + toggleSecondFormat: stateToggler("showSecondFormat"), + toggleInput: stateToggler("showInput"), + toggleOutput: stateToggler("showOutput"), + toggleEmbedErrors: stateToggler("rethrowEmbedErrors"), + ...storage.get("editor_state"), +}); + +watch( + () => state, + () => { + storage.set("editor_state", state); + }, + { deep: true }, +); + +export { state as editorState };