Skip to content

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.

feat: support folding text fragments in code editor (#4676)

Bogdan Chadkin8e4ef3eb370d
diff --git a/apps/builder/app/builder/shared/code-editor-base.tsx b/apps/builder/app/builder/shared/code-editor-base.tsx
index 3c9772a534..d0abfe9aac 100644
--- a/apps/builder/app/builder/shared/code-editor-base.tsx
+++ b/apps/builder/app/builder/shared/code-editor-base.tsx
@@ -25,7 +25,7 @@ import {
historyKeymap,
indentWithTab,
} from "@codemirror/commands";
-import { syntaxHighlighting } from "@codemirror/language";
+import { foldGutter, syntaxHighlighting } from "@codemirror/language";
import {
theme,
textVariants,
@@ -40,6 +40,7 @@ import {
FloatingPanel,
} from "@webstudio-is/design-system";
import { MaximizeIcon } from "@webstudio-is/icons";
+import { ChevronDownIcon, ChevronRightIcon } from "@webstudio-is/icons/svg";
import { solarizedLight } from "./code-highlight";
// This undocumented flag is required to keep contenteditable fields editable after the first activation of EditorView.
@@ -121,6 +122,10 @@ const editorContentStyle = css({
textDecoration: "underline wavy red",
backgroundColor: "rgba(255, 0, 0, 0.1)",
},
+ ".cm-gutters": {
+ backgroundColor: "transparent",
+ border: 0,
+ },
});
const shortcutStyle = css({
@@ -188,6 +193,17 @@ const keyBindings = [
indentWithTab,
];
+export const foldGutterExtension = foldGutter({
+ markerDOM: (isOpen) => {
+ const div = document.createElement("div");
+ div.style.width = "16px";
+ div.style.height = "16px";
+ div.style.cursor = "pointer";
+ div.innerHTML = isOpen ? ChevronDownIcon : ChevronRightIcon;
+ return div;
+ },
+});
+
export type EditorApi = {
replaceSelection: (string: string) => void;
focus: () => void;
diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsx
index 9820f7ee6a..a747935bbb 100644
--- a/apps/builder/app/builder/shared/code-editor.tsx
+++ b/apps/builder/app/builder/shared/code-editor.tsx
@@ -27,6 +27,7 @@ import {
EditorDialog,
EditorDialogButton,
EditorDialogControl,
+ foldGutterExtension,
getMinMaxHeightVars,
} from "./code-editor-base";
@@ -96,6 +97,11 @@ export const CodeEditor = forwardRef<
return [];
}, [lang]);
+ const dialogExtensions = useMemo(
+ () => [...extensions, foldGutterExtension],
+ [extensions]
+ );
+
// prevent clicking on autocomplete options propagating to body
// and closing dialogs and popovers
useEffect(() => {
@@ -113,14 +119,19 @@ export const CodeEditor = forwardRef<
document.removeEventListener("pointerdown", handlePointerDown, options);
};
}, []);
- const content = (
- <EditorContent {...editorContentProps} extensions={extensions} />
- );
return (
<div className={wrapperStyle()} ref={ref}>
<EditorDialogControl>
- {content}
- <EditorDialog title={title} content={content}>
+ {<EditorContent {...editorContentProps} extensions={extensions} />}
+ <EditorDialog
+ title={title}
+ content={
+ <EditorContent
+ {...editorContentProps}
+ extensions={dialogExtensions}
+ />
+ }
+ >
<EditorDialogButton />
</EditorDialog>
</EditorDialogControl>
diff --git a/apps/builder/app/builder/shared/expression-editor.tsx b/apps/builder/app/builder/shared/expression-editor.tsx
index d4a77e5a50..43c5304ecc 100644
--- a/apps/builder/app/builder/shared/expression-editor.tsx
+++ b/apps/builder/app/builder/shared/expression-editor.tsx
@@ -39,6 +39,7 @@ import {
EditorDialog,
EditorDialogButton,
EditorDialogControl,
+ foldGutterExtension,
type EditorApi,
} from "./code-editor-base";
@@ -518,7 +519,7 @@ export const ExpressionEditor = ({
// by spliting into separate component which is invoked
// only when dialog content is rendered
const ValuePreviewEditor = ({ value }: { value: unknown }) => {
- const extensions = useMemo(() => [javascript({})], []);
+ const extensions = useMemo(() => [javascript({}), foldGutterExtension], []);
return (
<EditorContent
readOnly={true}
diff --git a/apps/builder/package.json b/apps/builder/package.json
index 047df3dff9..88d0161706 100644
--- a/apps/builder/package.json
+++ b/apps/builder/package.json
@@ -18,16 +18,16 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
- "@codemirror/autocomplete": "^6.18.1",
+ "@codemirror/autocomplete": "^6.18.4",
"@codemirror/commands": "^6.7.1",
- "@codemirror/lang-css": "^6.3.0",
+ "@codemirror/lang-css": "^6.3.1",
"@codemirror/lang-html": "^6.4.9",
"@codemirror/lang-javascript": "^6.2.2",
- "@codemirror/lang-markdown": "^6.3.0",
- "@codemirror/language": "^6.10.3",
- "@codemirror/lint": "^6.8.2",
- "@codemirror/state": "^6.4.1",
- "@codemirror/view": "^6.34.1",
+ "@codemirror/lang-markdown": "^6.3.1",
+ "@codemirror/language": "^6.10.8",
+ "@codemirror/lint": "^6.8.4",
+ "@codemirror/state": "^6.5.0",
+ "@codemirror/view": "^6.36.1",
"@floating-ui/dom": "^1.6.11",
"@fontsource-variable/inter": "^5.0.20",
"@fontsource-variable/manrope": "^5.0.20",
diff --git a/packages/jsx-utils/package.json b/packages/jsx-utils/package.json
index 5ff4e125f2..fdedda0a91 100644
--- a/packages/jsx-utils/package.json
+++ b/packages/jsx-utils/package.json
@@ -30,7 +30,7 @@
"@webstudio-is/css-data": "workspace:*",
"@webstudio-is/react-sdk": "workspace:*",
"@webstudio-is/sdk": "workspace:*",
- "acorn": "^8.12.1",
+ "acorn": "^8.14.0",
"acorn-jsx": "^5.3.2",
"json5": "^2.2.3",
"zod": "^3.22.4"
diff --git a/packages/sdk/package.json b/packages/sdk/package.json
index 07d324cea6..ce8b8c909d 100644
--- a/packages/sdk/package.json
+++ b/packages/sdk/package.json
@@ -38,7 +38,7 @@
"dependencies": {
"@webstudio-is/css-engine": "workspace:*",
"@webstudio-is/fonts": "workspace:*",
- "acorn": "^8.12.1",
+ "acorn": "^8.14.0",
"acorn-walk": "^8.3.4",
"reserved-identifiers": "^1.0.0",
"type-fest": "^4.31.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a447e8ab9a..264715ddca 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -122,14 +122,14 @@ importers:
specifier: ^1.4.0
version: 1.4.0
'@codemirror/autocomplete':
- specifier: ^6.18.1
- version: 6.18.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
+ specifier: ^6.18.4
+ version: 6.18.4
'@codemirror/commands':
specifier: ^6.7.1
version: 6.7.1
'@codemirror/lang-css':
- specifier: ^6.3.0
- version: 6.3.0(@codemirror/[email protected])
+ specifier: ^6.3.1
+ version: 6.3.1
'@codemirror/lang-html':
specifier: ^6.4.9
version: 6.4.9
@@ -137,20 +137,20 @@ importers:
specifier: ^6.2.2
version: 6.2.2
'@codemirror/lang-markdown':
- specifier: ^6.3.0
- version: 6.3.0
+ specifier: ^6.3.1
+ version: 6.3.1
'@codemirror/language':
- specifier: ^6.10.3
- version: 6.10.3
+ specifier: ^6.10.8
+ version: 6.10.8
'@codemirror/lint':
- specifier: ^6.8.2
- version: 6.8.2
+ specifier: ^6.8.4
+ version: 6.8.4
'@codemirror/state':
- specifier: ^6.4.1
- version: 6.4.1
+ specifier: ^6.5.0
+ version: 6.5.0
'@codemirror/view':
- specifier: ^6.34.1
- version: 6.34.1
+ specifier: ^6.36.1
+ version: 6.36.1
'@floating-ui/dom':
specifier: ^1.6.11
version: 1.6.11
@@ -1546,11 +1546,11 @@ importers:
specifier: workspace:*
version: link:../sdk
acorn:
- specifier: ^8.12.1
- version: 8.12.1
+ specifier: ^8.14.0
+ version: 8.14.0
acorn-jsx:
specifier: ^5.3.2
- version: 5.3.2([email protected])
+ version: 5.3.2([email protected])
json5:
specifier: ^2.2.3
version: 2.2.3
@@ -1732,8 +1732,8 @@ importers:
specifier: workspace:*
version: link:../fonts
acorn:
- specifier: ^8.12.1
- version: 8.12.1
+ specifier: ^8.14.0
+ version: 8.14.0
acorn-walk:
specifier: ^8.3.4
version: 8.3.4
@@ -2309,19 +2309,14 @@ packages:
'@cloudflare/[email protected]':
resolution: {integrity: sha512-6Cu6NIAicmb8H6CkzFdQG5Ib+TDs9HU8AKQEGlxnbvEBDmhUNpmL30ETXpLS0asdeyc+rTb2xag0hSv0Z1BflQ==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-iWHdj/B1ethnHRTwZj+C1obmmuCzquH29EbcKr0qIjA9NfDeBDJ7vs+WOHsFeLeflE4o+dHfYndJloMKHUkWUA==}
- peerDependencies:
- '@codemirror/language': ^6.0.0
- '@codemirror/state': ^6.0.0
- '@codemirror/view': ^6.0.0
- '@lezer/common': ^1.0.0
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-sFAphGQIqyQZfP2ZBsSHV7xQvo9Py0rV0dW7W3IMRdS+zDuNb2l3no78CvUaWKGfzFjI4FTrLdUSj86IGb2hRA==}
'@codemirror/[email protected]':
resolution: {integrity: sha512-llTrboQYw5H4THfhN4U3qCnSZ1SOJ60ohhz+SzU0ADGtwlc533DtklQP0vSFaQuCPDn3BPpOd1GbbnUtwNjsrw==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-CyR4rUNG9OYcXDZwMPvJdtb6PHbBDKUc/6Na2BIwZ6dKab1JQqKa4di+RNRY9Myn7JB81vayKwJeQ7jEdmNVDA==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg==}
'@codemirror/[email protected]':
resolution: {integrity: sha512-aQv37pIMSlueybId/2PVSP6NPnmurFDVmZwzc7jszd2KAF8qd4VBbvNYPXWQq90WIARjsdVkPbw29pszmHws3Q==}
@@ -2329,20 +2324,20 @@ packages:
'@codemirror/[email protected]':
resolution: {integrity: sha512-VGQfY+FCc285AhWuwjYxQyUQcYurWlxdKYT4bqwr3Twnd5wP5WSeu52t4tvvuWmljT4EmgEgZCqSieokhtY8hg==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-lYrI8SdL/vhd0w0aHIEvIRLRecLF7MiiRfzXFZY94dFwHqC9HtgxgagJ8fyYNBldijGatf9wkms60d8SrAj6Nw==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-y3sSPuQjBKZQbQwe3ZJKrSW6Silyl9PnrU/Mf0m2OQgIlPoSYTtOvEL7xs94SVMkb8f4x+SQFnzXPdX4Wk2lsg==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-kDqEU5sCP55Oabl6E7m5N+vZRoc0iWqgDVhEKifcHzPzjqCegcO4amfrYVL9PmPZpl4G0yjkpTpUO/Ui8CzO8A==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-wcP8XPPhDH2vTqf181U8MbZnW+tDyPYy0UzVOa+oHORjyT+mhhom9vBd7dApJwoDz9Nb/a8kHjJIsuA/t8vNFw==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-PDFG5DjHxSEjOXk9TQYYVjZDqlZTFaDBfhQixHnQOEVDDNHUbEh/hstAjcQJaA6FQdZTD1hquXTK0rVBLADR1g==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-u4q7PnZlJUojeRe8FJa/njJcMctISGgPQ4PnWsd9268R4ZTtU+tfFYmwkBvgcrK2+QQ8tYFVALVb5fVJykKc5A==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-MwBHVK60IiIHDcoMet78lxt6iw5gJOGSbNbOIVBHWVXIH4/Nq1+GQgLLGgI1KlnN86WDXsPudVaqYHKBIx7Eyw==}
- '@codemirror/[email protected]':
- resolution: {integrity: sha512-t1zK/l9UiRqwUNPm+pdIT0qzJlzuVckbTEMVNFhfWkGiBQClstzg+78vedCvLSX0xJEZ6lwZbPpnljL7L6iwMQ==}
+ '@codemirror/[email protected]':
+ resolution: {integrity: sha512-miD1nyT4m4uopZaDdO2uXU/LLHliKNYL9kB1C1wJHrunHLm/rpkb5QVSokqgw9hFqEZakrdlb/VGWX8aYZTslQ==}
'@cspotcode/[email protected]':
resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}
@@ -3426,6 +3421,9 @@ packages:
resolution: {integrity: sha512-DGlzU/i8DC8k0uz1F+jeePrkATl0jWakauTzftMQOcbaMkHbNSRki/4E2tOzJWsVpoKYhe7iTJ03aepdwVUXUA==}
+ '@marijn/[email protected]':
+ resolution: {integrity: sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==}
+
'@mdx-js/[email protected]':
resolution: {integrity: sha512-jLuwRlz8DQfQNiUCJR50Y09CGPq3fLtmtUQfVrj79E0JWu3dvsVcxVIcfhR5h0iXu+/z++zDrYeiJqifRynJkA==}
@@ -4920,11 +4918,6 @@ packages:
resolution: {integrity: sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==}
engines: {node: '>=0.4.0'}
- resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==}
- engines: {node: '>=0.4.0'}
- hasBin: true
-
resolution: {integrity: sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==}
engines: {node: '>=0.4.0'}
@@ -9099,82 +9092,82 @@ snapshots:
'@cloudflare/[email protected]': {}
- '@codemirror/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/language': 6.10.3
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/language': 6.10.8
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
'@codemirror/[email protected]':
dependencies:
- '@codemirror/language': 6.10.3
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/language': 6.10.8
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
- '@codemirror/[email protected](@codemirror/[email protected])':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/autocomplete': 6.18.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
- '@codemirror/language': 6.10.3
- '@codemirror/state': 6.4.1
+ '@codemirror/autocomplete': 6.18.4
+ '@codemirror/language': 6.10.8
+ '@codemirror/state': 6.5.0
'@lezer/common': 1.2.3
'@lezer/css': 1.1.9
- transitivePeerDependencies:
- - '@codemirror/view'
'@codemirror/[email protected]':
dependencies:
- '@codemirror/autocomplete': 6.18.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
- '@codemirror/lang-css': 6.3.0(@codemirror/[email protected])
+ '@codemirror/autocomplete': 6.18.4
+ '@codemirror/lang-css': 6.3.1
'@codemirror/lang-javascript': 6.2.2
- '@codemirror/language': 6.10.3
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/language': 6.10.8
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
'@lezer/css': 1.1.9
'@lezer/html': 1.3.10
'@codemirror/[email protected]':
dependencies:
- '@codemirror/autocomplete': 6.18.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
- '@codemirror/language': 6.10.3
- '@codemirror/lint': 6.8.2
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/autocomplete': 6.18.4
+ '@codemirror/language': 6.10.8
+ '@codemirror/lint': 6.8.4
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
'@lezer/javascript': 1.4.19
- '@codemirror/[email protected]':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/autocomplete': 6.18.1(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@lezer/[email protected])
+ '@codemirror/autocomplete': 6.18.4
'@codemirror/lang-html': 6.4.9
- '@codemirror/language': 6.10.3
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/language': 6.10.8
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
'@lezer/markdown': 1.3.1
- '@codemirror/[email protected]':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
'@lezer/common': 1.2.3
'@lezer/highlight': 1.2.1
'@lezer/lr': 1.4.2
style-mod: 4.1.2
- '@codemirror/[email protected]':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/state': 6.4.1
- '@codemirror/view': 6.34.1
+ '@codemirror/state': 6.5.0
+ '@codemirror/view': 6.36.1
crelt: 1.0.6
- '@codemirror/[email protected]': {}
+ '@codemirror/[email protected]':
+ dependencies:
+ '@marijn/find-cluster-break': 1.0.2
- '@codemirror/[email protected]':
+ '@codemirror/[email protected]':
dependencies:
- '@codemirror/state': 6.4.1
+ '@codemirror/state': 6.5.0
style-mod: 4.1.2
w3c-keyname: 2.2.8
@@ -9932,6 +9925,8 @@ snapshots:
'@lezer/common': 1.2.3
'@lezer/highlight': 1.2.1
+ '@marijn/[email protected]': {}
+
'@mdx-js/[email protected]':
dependencies:
'@types/estree-jsx': 1.0.0
@@ -11733,19 +11728,13 @@ snapshots:
acorn-walk: 8.3.4
optional: true
- dependencies:
- acorn: 8.12.1
-
dependencies:
acorn: 8.14.0
dependencies:
- acorn: 8.12.1
-
+ acorn: 8.14.0
@@ -14263,7 +14252,7 @@ snapshots:
dependencies:
'@cspotcode/source-map-support': 0.8.1
- acorn: 8.12.1
+ acorn: 8.14.0
acorn-walk: 8.3.4
capnp-ts: 0.7.0
exit-hook: 2.2.1