Skip to content

Commit 1bbfe42

Browse files
authored
feat: paste HTML with tailwind classes (#5296)
Ref #2651 Added command to let users paste tailwind fragments. - all classes are converted to local styles - breakpoints are adapted to desktop-first if possible - images are automatically uploaded
1 parent 701793d commit 1bbfe42

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

apps/builder/app/builder/features/command-panel/command-panel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ const $shortcutOptions = computed([$commandMetas], (commandMetas) => {
459459
const shortcutOptions: ShortcutOption[] = [];
460460
for (const [name, meta] of commandMetas) {
461461
if (!meta.hidden) {
462-
const label = humanizeString(name);
462+
const label = meta.label ?? humanizeString(name);
463463
const keys = meta.defaultHotkeys?.[0]?.split("+");
464464
shortcutOptions.push({
465465
tokens: ["shortcuts", "commands", label],
@@ -493,7 +493,7 @@ const ShortcutOptionsGroup = ({ options }: { options: ShortcutOption[] }) => {
493493
emitCommand(name as never);
494494
}}
495495
>
496-
<Text variant="labelsTitleCase">{label}</Text>
496+
<Text variant="labelsSentenceCase">{label}</Text>
497497
{keys && <Kbd value={keys} />}
498498
</CommandItem>
499499
))}

apps/builder/app/builder/shared/commands.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
} from "@webstudio-is/sdk";
77
import type { Instance } from "@webstudio-is/sdk";
88
import { toast } from "@webstudio-is/design-system";
9-
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
109
import { createCommandsEmitter, type Command } from "~/shared/commands-emitter";
1110
import {
1211
$editingItemSelector,
@@ -576,10 +575,12 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
576575
},
577576
{
578577
name: "wrapInElement",
578+
label: "Wrap in an Element",
579579
handler: () => wrapIn(elementComponent),
580580
},
581581
{
582582
name: "wrapInLink",
583+
label: "Wrap in a Link",
583584
handler: () => wrapIn(elementComponent, "a"),
584585
},
585586
{
@@ -588,27 +589,26 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({
588589
},
589590
{
590591
name: "replaceWithElement",
592+
label: "Replace with an Element",
591593
handler: () => replaceWith(elementComponent),
592594
},
593595
{
594596
name: "replaceWithLink",
597+
label: "Replace with a Link",
595598
handler: () => replaceWith(elementComponent, "a"),
596599
},
597600

598-
...(isFeatureEnabled("tailwind")
599-
? [
600-
{
601-
name: "pasteHtmlWithTailwindClasses",
602-
handler: async () => {
603-
const html = await navigator.clipboard.readText();
604-
let fragment = generateFragmentFromHtml(html);
605-
fragment = await denormalizeSrcProps(fragment);
606-
fragment = await generateFragmentFromTailwind(fragment);
607-
return insertWebstudioFragmentAt(fragment);
608-
},
609-
},
610-
]
611-
: []),
601+
{
602+
name: "pasteTailwind",
603+
label: "Paste HTML with Tailwind classes",
604+
handler: async () => {
605+
const html = await navigator.clipboard.readText();
606+
let fragment = generateFragmentFromHtml(html);
607+
fragment = await denormalizeSrcProps(fragment);
608+
fragment = await generateFragmentFromTailwind(fragment);
609+
return insertWebstudioFragmentAt(fragment);
610+
},
611+
},
612612

613613
// history
614614

apps/builder/app/shared/commands-emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { clientSyncStore } from "~/shared/sync";
55
type CommandMeta<CommandName extends string> = {
66
// @todo category, description
77
name: CommandName;
8+
label?: string;
89
/** default because hotkeys can be customized from ui */
910
defaultHotkeys?: string[];
1011
/** set to false when default browser or radix behavior is desired */

0 commit comments

Comments
 (0)