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, make it pass ts
Oleg Isonenbe92c4506a36
diff --git a/app/shared/text-editor/example-text-editor.stories.tsx b/app/shared/text-editor/example-text-editor.stories.tsxindex 9f6534d067..01dbe938a5 100644--- a/app/shared/text-editor/example-text-editor.stories.tsx+++ b/app/shared/text-editor/example-text-editor.stories.tsx@@ -2,7 +2,19 @@ import React from "react";import type { ComponentStory, ComponentMeta } from "@storybook/react";import { ExampleTextEditor } from "./example-text-editor";import "./styles.css";-import { $getRoot, $getSelection, type EditorState } from "lexical";+import { $getRoot, $getSelection, type EditorState } from "./lexical";++// When the editor changes, you can get notified via the+// LexicalOnChangePlugin!+const onChange = (editorState: EditorState) => {+ editorState.read(() => {+ // Read the contents of the EditorState here.+ const root = $getRoot();+ const selection = $getSelection();++ console.log(root, selection);+ });+};export default {title: "Text Editor",@@ -17,15 +29,3 @@ export const TextEditor = Template.bind({});TextEditor.args = {onChange,};--// When the editor changes, you can get notified via the-// LexicalOnChangePlugin!-function onChange(editorState: EditorState) {- editorState.read(() => {- // Read the contents of the EditorState here.- const root = $getRoot();- const selection = $getSelection();-- console.log(root, selection);- });-}diff --git a/app/shared/text-editor/example-text-editor.tsx b/app/shared/text-editor/example-text-editor.tsxindex 150df4b571..d4c3b381e5 100644--- a/app/shared/text-editor/example-text-editor.tsx+++ b/app/shared/text-editor/example-text-editor.tsx@@ -1,13 +1,15 @@-import { LexicalComposer } from "@lexical/react/LexicalComposer";-import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";-import { ContentEditable } from "@lexical/react/LexicalContentEditable";-import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";-import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";+import { publish } from "@webstudio-is/sdk";+import {+ type EditorState,+ LexicalComposer,+ RichTextPlugin,+ ContentEditable,+ HistoryPlugin,+ OnChangePlugin,+} from "./lexical";import { InstancePlugin } from "./plugins/plugin-instance";import { TreeViewPlugin } from "./plugins/tree-view-plugin";import { config } from "./config";-import { publish } from "@webstudio-is/sdk";-import { type EditorState } from "lexical";type ExampleTextEditorProps = {onChange: (state: EditorState) => void;@@ -50,6 +52,8 @@ const Menu = () => (props: { href: "https://google.com", target: "_blank" },},});+ const url = prompt("Enter url");+ console.log(url);}}>Linkdiff --git a/app/shared/text-editor/index.ts b/app/shared/text-editor/index.tsdeleted file mode 100644index bf7f890243..0000000000--- a/app/shared/text-editor/index.ts+++ /dev/null@@ -1 +0,0 @@-export * from "./example-text-editor";diff --git a/app/shared/text-editor/lexical.ts b/app/shared/text-editor/lexical.tsnew file mode 100644index 0000000000..737218fc3f--- /dev/null+++ b/app/shared/text-editor/lexical.ts@@ -0,0 +1,17 @@+export type { EditorConfig, EditorState, LexicalCommand } from "lexical";+export {+ TextNode,+ createCommand,+ $isRangeSelection,+ $getSelection,+ $getRoot,+ COMMAND_PRIORITY_EDITOR,+ $getNodeByKey,+} from "lexical";+export { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";+export { LexicalComposer } from "@lexical/react/LexicalComposer";+export { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";+export { ContentEditable } from "@lexical/react/LexicalContentEditable";+export { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";+export { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";+export { TreeView } from "@lexical/react/LexicalTreeView";diff --git a/app/shared/text-editor/nodes/node-instance.tsx b/app/shared/text-editor/nodes/node-instance.tsxindex ea71933a68..dc2bfb57f4 100644--- a/app/shared/text-editor/nodes/node-instance.tsx+++ b/app/shared/text-editor/nodes/node-instance.tsx@@ -1,12 +1,16 @@-import { type EditorConfig, TextNode } from "lexical";+import { type EditorConfig, TextNode } from "../lexical";import { render } from "react-dom";+import type { Instance } from "@webstudio-is/sdk";type Options = {+ id: Instance["id"];component: JSX.Element;text: string;};export class InstanceNode extends TextNode {+ options: Options;+static getType(): "instance" {return "instance";}@@ -17,13 +21,13 @@ export class InstanceNode extends TextNode {constructor(options: Options) {// This makes sure caret is at the end of the selection after inserting this node instance- super(options.text);+ super(options.text, options.id);this.options = options;}createDOM(config: EditorConfig) {const container = super.createDOM(config);- render(this.options.component, container);+ render(this.options.component, this.container);return container;}@@ -50,6 +54,6 @@ export class InstanceNode extends TextNode {}}-export function $createInstanceNode(options: Options) {+export const $createInstanceNode = (options: Options) => {return new InstanceNode(options);-}+};diff --git a/app/shared/text-editor/plugins/plugin-instance.tsx b/app/shared/text-editor/plugins/plugin-instance.tsxindex 9fe7920411..cb9f702bb1 100644--- a/app/shared/text-editor/plugins/plugin-instance.tsx+++ b/app/shared/text-editor/plugins/plugin-instance.tsx@@ -1,19 +1,20 @@-import { $createInstanceNode, InstanceNode } from "../nodes/node-instance";import { useEffect } from "react";+import { useSubscribe, type Instance } from "@webstudio-is/sdk";+import { primitives } from "../../canvas-components";+import { $createInstanceNode, InstanceNode } from "../nodes/node-instance";import {createCommand,$isRangeSelection,$getSelection,COMMAND_PRIORITY_EDITOR,+ useLexicalComposerContext,type LexicalCommand,-} from "lexical";-import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";-import { useSubscribe } from "@webstudio-is/sdk";-import { primitives } from "../../canvas-components";+} from "../lexical";const INSERT_INSTANCE_COMMAND: LexicalCommand<Payload> = createCommand();type Payload = {+ id: Instance["id"];component: keyof typeof primitives;props: Record<string, unknown>;};@@ -35,6 +36,7 @@ export const InstancePlugin = () => {const instanceNode = $createInstanceNode({component: <Component {...payload.props}>{text}</Component>,text,+ id: payload.id,});selection.insertNodes([instanceNode]);}@@ -51,6 +53,5 @@ export const InstancePlugin = () => {editor.dispatchCommand<Payload>(INSERT_INSTANCE_COMMAND, payload);});-return null;};diff --git a/app/shared/text-editor/plugins/tree-view-plugin.tsx b/app/shared/text-editor/plugins/tree-view-plugin.tsxindex 8b16894757..52e96bd621 100644--- a/app/shared/text-editor/plugins/tree-view-plugin.tsx+++ b/app/shared/text-editor/plugins/tree-view-plugin.tsx@@ -1,5 +1,4 @@-import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";-import { TreeView } from "@lexical/react/LexicalTreeView";+import { useLexicalComposerContext, TreeView } from "../lexical";export const TreeViewPlugin = () => {const [editor] = useLexicalComposerContext();diff --git a/tsconfig.json b/tsconfig.jsonindex 749e4b959e..53a9511932 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -13,6 +13,8 @@"paths": {"~/*": ["./app/*"]},+ // Temporarily introduced because lexical lib has a prob with types https://github.com/facebook/lexical/issues/2528+ "skipLibCheck": true,// Remix takes care of building everything in `remix build`."noEmit": truediff --git a/yarn.lock b/yarn.lockindex abbd3faa56..015db2719a 100644--- a/yarn.lock+++ b/yarn.lock@@ -14536,7 +14536,7 @@ typedarray@^0.0.6:resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=version "4.6.4"resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.4.tgz#caa78bbc3a59e6a5c510d35703f6a09877ce45e9"integrity sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==