Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
cleanup the story
Oleg Isonen5f05d7e34ac3
diff --git a/app/canvas/features/wrapper-component/text-editor/config.ts b/app/canvas/features/wrapper-component/text-editor/config.tsindex f68fc5d775..5e50a7a73a 100644--- a/app/canvas/features/wrapper-component/text-editor/config.ts+++ b/app/canvas/features/wrapper-component/text-editor/config.ts@@ -1,7 +1,7 @@import { InstanceNode } from "./nodes/node-instance";export const config = {- namespace: "example",+ namespace: "ComponentTextEditor",onError(error: Error) {throw error;},diff --git a/app/canvas/features/wrapper-component/text-editor/editor.tsx b/app/canvas/features/wrapper-component/text-editor/editor.tsxindex e7b592d9d8..d664756aef 100644--- a/app/canvas/features/wrapper-component/text-editor/editor.tsx+++ b/app/canvas/features/wrapper-component/text-editor/editor.tsx@@ -1,26 +1,30 @@import { type ChildrenUpdates, type Instance } from "@webstudio-is/sdk";-import {- RichTextPlugin,- HistoryPlugin,- InstancePlugin,- ToolbarConnectorPlugin,- OnChangePlugin,-} from "~/canvas/features/wrapper-component/text-editor";+import { RichTextPlugin, HistoryPlugin } from "./lexical";+import { InstancePlugin } from "./plugins/plugin-instance";+import { ToolbarConnectorPlugin } from "./plugins/plugin-toolbar-connector";+import { OnChangePlugin } from "./plugins/plugin-on-change";type EditorProps = {+ children?: JSX.Element;editable: JSX.Element;- children: Array<Instance | string>;- onChange: (udpates: ChildrenUpdates) => void;+ instance: Instance;+ onChange: (updates: ChildrenUpdates) => void;};-export const Editor = ({ children, editable, onChange }: EditorProps) => {+export const Editor = ({+ instance,+ editable,+ children,+ onChange,+}: EditorProps) => {return (<><RichTextPlugin contentEditable={editable} placeholder="" /><OnChangePlugin onChange={onChange} /><HistoryPlugin />- <InstancePlugin>{children}</InstancePlugin>+ <InstancePlugin>{instance.children}</InstancePlugin><ToolbarConnectorPlugin />+ {children}</>);};diff --git a/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx b/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsxindex 69fdfc1ef3..0bdd910c6c 100644--- a/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx+++ b/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx@@ -1,7 +1,6 @@import type { ComponentStory, ComponentMeta } from "@storybook/react";import { action } from "@storybook/addon-actions";import { ExampleTextEditor } from "./example-text-editor";-import "./styles.css";export default {title: "Text Editor",diff --git a/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx b/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsxindex 04f31aa956..589f67df9d 100644--- a/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx+++ b/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx@@ -2,18 +2,14 @@ import {type ChildrenUpdates,publish,useAllUserProps,+ type Instance,} from "@webstudio-is/sdk";-import {- LexicalComposer,- RichTextPlugin,- ContentEditable,- HistoryPlugin,-} from "./lexical";-import { OnChangePlugin } from "./plugins/plugin-on-change";-import { InstancePlugin } from "./plugins/plugin-instance";+import { createInstance } from "~/shared/tree-utils";+import { Box, Button } from "~/shared/design-system";+import { LexicalComposer, ContentEditable } from "./lexical";import { TreeViewPlugin } from "./plugins/tree-view-plugin";import { config } from "./config";-import { createInstance } from "../../../../shared/tree-utils";+import { Editor } from "./editor";type ExampleTextEditorProps = {onChange: (state: ChildrenUpdates) => void;@@ -22,8 +18,14 @@ type ExampleTextEditorProps = {const Menu = () => {const [, setAllUserProps] = useAllUserProps();return (- <div className="editor-menu">- <button+ <Box+ css={{+ margin: 10,+ display: "flex",+ gap: 10,+ }}+ >+ <ButtononClick={() => {const instance = createInstance({ component: "Bold" });publish({@@ -33,8 +35,8 @@ const Menu = () => {}}>Bold- </button>- <button+ </Button>+ <ButtononClick={() => {const instance = createInstance({ component: "Italic" });publish({@@ -44,8 +46,8 @@ const Menu = () => {}}>Italic- </button>- <button+ </Button>+ <ButtononClick={() => {const instance = createInstance({ component: "Link" });publish({@@ -71,35 +73,70 @@ const Menu = () => {}}>Link- </button>- </div>+ </Button>+ </Box>);};+export const ExampleTextEditor = ({ onChange }: ExampleTextEditorProps) => {return (<><Menu /><LexicalComposer initialConfig={config}>- <div className="editor-container">- <RichTextPlugin- contentEditable={<ContentEditable className="editor-input" />}- placeholder=""- />- <OnChangePlugin onChange={onChange} />- <HistoryPlugin />- <InstancePlugin>- {[- "Pragraph you can edit ",+ <Box+ css={{+ background: "#fff",+ borderRadius: 2,+ maxWidth: 600,+ color: "#000",+ position: "relative",+ lineHeight: 1.5,+ fontWeight: 400,+ textAlign: "left",+ borderTopLeftRadius: 10,+ borderTopRightRadius: 10,+ overflow: "hidden",+ "& p": {+ margin: 0,+ },+ }}+ >+ <Editor+ editable={+ <ContentEditable+ style={{+ minHeight: 150,+ resize: "none",+ fontSize: "1em",+ position: "relative",+ tabSize: 1,+ outline: 0,+ padding: "15px 10px",+ caretColor: "#444",+ background: "#eee",+ }}+ />+ }+ instance={{- component: "Bold",+ component: "Paragraph",id: "62bd56ad8f5562223cb85cc2",cssRules: [],- children: ["bold"],- },- ]}- </InstancePlugin>+ children: [+ "Pragraph you can edit ",+ {+ component: "Bold",+ id: "62bd56ad8f5562223cb85cc2",+ cssRules: [],+ children: ["bold"],+ },+ ],+ } as Instance+ }+ onChange={onChange}+ /><TreeViewPlugin />- </div>+ </Box></LexicalComposer></>);diff --git a/app/canvas/features/wrapper-component/text-editor/content-editable.tsx b/app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsxsimilarity index 100%rename from app/canvas/features/wrapper-component/text-editor/content-editable.tsxrename to app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsxdiff --git a/app/canvas/features/wrapper-component/text-editor/use-is-editing.ts b/app/canvas/features/wrapper-component/text-editor/hooks/use-is-editing.tssimilarity index 100%rename from app/canvas/features/wrapper-component/text-editor/use-is-editing.tsrename to app/canvas/features/wrapper-component/text-editor/hooks/use-is-editing.tsdiff --git a/app/canvas/features/wrapper-component/text-editor/index.ts b/app/canvas/features/wrapper-component/text-editor/index.tsindex f057b52da6..22bd56ccca 100644--- a/app/canvas/features/wrapper-component/text-editor/index.ts+++ b/app/canvas/features/wrapper-component/text-editor/index.ts@@ -1,12 +1,5 @@-export {- LexicalComposer,- RichTextPlugin,- ContentEditable,- HistoryPlugin,- type EditorState,-} from "./lexical";+export { LexicalComposer } from "./lexical";export { config } from "./config";-export { InstancePlugin } from "./plugins/plugin-instance";-export { ToolbarConnectorPlugin } from "./plugins/plugin-toolbar-connector";-export { OnChangePlugin } from "./plugins/plugin-on-change";-export { useContentEditable } from "./content-editable";+export { useContentEditable } from "./hooks/use-content-editable";+export { useIsEditing } from "./hooks/use-is-editing";+export { Editor } from "./editor";diff --git a/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.css b/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.cssnew file mode 100644index 0000000000..a2203f4a70--- /dev/null+++ b/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.css@@ -0,0 +1,55 @@+.tree-view-output {+ display: block;+ background: #222;+ color: #fff;+ padding: 5px;+ font-size: 12px;+ white-space: pre-wrap;+ margin: 1px auto 10px auto;+ max-height: 250px;+ position: relative;+ border-bottom-left-radius: 10px;+ border-bottom-right-radius: 10px;+ overflow: hidden;+ line-height: 14px;+}++.debug-timetravel-panel {+ overflow: hidden;+ padding: 0 0 10px 0;+ margin: auto;+ display: flex;+}++.debug-timetravel-panel-slider {+ padding: 0;+ flex: 8;+}++.debug-timetravel-panel-button {+ padding: 0;+ border: 0;+ background: none;+ flex: 1;+ color: #fff;+ font-size: 12px;+}++.debug-timetravel-panel-button:hover {+ text-decoration: underline;+}++.debug-timetravel-button {+ border: 0;+ padding: 0;+ font-size: 12px;+ top: 10px;+ right: 15px;+ position: absolute;+ background: none;+ color: #fff;+}++.debug-timetravel-button:hover {+ text-decoration: underline;+}diff --git a/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx b/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsxindex 52e96bd621..ad13e8a5bf 100644--- a/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx+++ b/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx@@ -1,5 +1,7 @@import { useLexicalComposerContext, TreeView } from "../lexical";+import "./tree-view-plugin.css";+// Only used for storybookexport const TreeViewPlugin = () => {const [editor] = useLexicalComposerContext();return (diff --git a/app/canvas/features/wrapper-component/text-editor/styles.css b/app/canvas/features/wrapper-component/text-editor/styles.cssdeleted file mode 100644index cdc5831b15..0000000000--- a/app/canvas/features/wrapper-component/text-editor/styles.css+++ /dev/null@@ -1,120 +0,0 @@-body {- background: #eee;-}--h1 {- font-size: 24px;- color: #333;-}--.ltr {- text-align: left;-}--.rtl {- text-align: right;-}--.editor-menu {- margin: 10px;- display: flex;- gap: 10px;-}-.editor-container {- background: #fff;- border-radius: 2px;- max-width: 600px;- color: #000;- position: relative;- line-height: 20px;- font-weight: 400;- text-align: left;- border-top-left-radius: 10px;- border-top-right-radius: 10px;-}--.editor-input {- min-height: 150px;- resize: none;- font-size: 15px;- caret-color: rgb(5, 5, 5);- position: relative;- tab-size: 1;- outline: 0;- padding: 15px 10px;- caret-color: #444;-}--.editor-placeholder {- color: #999;- overflow: hidden;- position: absolute;- text-overflow: ellipsis;- top: 15px;- left: 10px;- font-size: 15px;- user-select: none;- display: inline-block;- pointer-events: none;-}--.editor-paragraph {- margin: 0 0 15px 0;- position: relative;-}--.tree-view-output {- display: block;- background: #222;- color: #fff;- padding: 5px;- font-size: 12px;- white-space: pre-wrap;- margin: 1px auto 10px auto;- max-height: 250px;- position: relative;- border-bottom-left-radius: 10px;- border-bottom-right-radius: 10px;- overflow: hidden;- line-height: 14px;-}--.debug-timetravel-panel {- overflow: hidden;- padding: 0 0 10px 0;- margin: auto;- display: flex;-}--.debug-timetravel-panel-slider {- padding: 0;- flex: 8;-}--.debug-timetravel-panel-button {- padding: 0;- border: 0;- background: none;- flex: 1;- color: #fff;- font-size: 12px;-}--.debug-timetravel-panel-button:hover {- text-decoration: underline;-}--.debug-timetravel-button {- border: 0;- padding: 0;- font-size: 12px;- top: 10px;- right: 15px;- position: absolute;- background: none;- color: #fff;-}--.debug-timetravel-button:hover {- text-decoration: underline;-}diff --git a/app/canvas/features/wrapper-component/wrapper-component.tsx b/app/canvas/features/wrapper-component/wrapper-component.tsxindex 8f24b34bca..26f9c9e391 100644--- a/app/canvas/features/wrapper-component/wrapper-component.tsx+++ b/app/canvas/features/wrapper-component/wrapper-component.tsx@@ -10,9 +10,7 @@ import { primitives } from "~/shared/canvas-components";import { useCss } from "./use-css";import { useDraggable } from "./use-draggable";import { useEnsureFocus } from "./use-ensure-focus";-import { Editor } from "./text-editor/editor";-import { useIsEditing } from "./text-editor/use-is-editing";-import { useContentEditable } from "~/canvas/features/wrapper-component/text-editor";+import { Editor, useContentEditable, useIsEditing } from "./text-editor";import noop from "lodash.noop";type WrapperComponentDevProps = {@@ -88,13 +86,12 @@ export const WrapperComponentDev = ({if (isEditing === false) return;return (<Editor+ instance={instance}editable={<Component {...props} />}onChange={(updates) => {onChangeChildren({ instanceId: instance.id, updates });}}- >- {instance.children}- </Editor>+ />);// eslint-disable-next-line react-hooks/exhaustive-deps}, [isEditing]);