diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 63ac7b1c7f..74e28e688c 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -941,6 +941,7 @@ "description": "A basic link component for internal and external links", "icon": "Link", "showSettingsBar": true, + "editable": true, "illegalChildren": ["section"], "settings": [ { diff --git a/packages/client/src/components/app/Heading.svelte b/packages/client/src/components/app/Heading.svelte index f3e283cf97..43ed0a066c 100644 --- a/packages/client/src/components/app/Heading.svelte +++ b/packages/client/src/components/app/Heading.svelte @@ -13,10 +13,8 @@ export let underline export let size - $: placeholder = $builderStore.inBuilder && !text - $: componentText = $builderStore.inBuilder - ? text || $component.name || "Placeholder text" - : text || "" + $: placeholder = $builderStore.inBuilder && !text && !$component.editing + $: componentText = getComponentText(text, $builderStore, $component) $: sizeClass = `spectrum-Heading--size${size || "M"}` $: alignClass = `align--${align || "left"}` @@ -24,6 +22,13 @@ // overrides the color when it's passed as inline style. $: styles = enrichStyles($component.styles, color) + const getComponentText = (text, builderState, componentState) => { + if (!builderState.inBuilder || componentState.editing) { + return text || "" + } + return text || componentState.name || "Placeholder text" + } + const enrichStyles = (styles, color) => { if (!color) { return styles diff --git a/packages/client/src/components/app/Link.svelte b/packages/client/src/components/app/Link.svelte index d948e11241..3a6d7c2438 100644 --- a/packages/client/src/components/app/Link.svelte +++ b/packages/client/src/components/app/Link.svelte @@ -14,19 +14,22 @@ export let underline export let size - $: external = url && typeof url === "string" && !url.startsWith("/") + $: externalLink = url && typeof url === "string" && !url.startsWith("/") $: target = openInNewTab ? "_blank" : "_self" $: placeholder = $builderStore.inBuilder && !text - $: componentText = $builderStore.inBuilder - ? text || "Placeholder link" - : text || "" + $: componentText = getComponentText(text, $builderStore, $component) - // Add color styles to main styles object, otherwise the styleable helper - // overrides the color when it's passed as inline style. // Add color styles to main styles object, otherwise the styleable helper // overrides the color when it's passed as inline style. $: styles = enrichStyles($component.styles, color) + const getComponentText = (text, builderState, componentState) => { + if (!builderState.inBuilder || componentState.editing) { + return text || "" + } + return text || componentState.name || "Placeholder text" + } + const enrichStyles = (styles, color) => { if (!color) { return styles @@ -39,10 +42,33 @@ }, } } + + // Convert contenteditable HTML to text and save + const updateText = e => { + const html = e.target.innerHTML + const sanitized = html + .replace(/<\/div>