2026-03-01 09:12:45 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import Prism from 'prismjs'
|
|
|
|
|
import 'prismjs/components/prism-jsx'
|
|
|
|
|
import { ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from 'reka-ui'
|
2026-03-17 08:30:25 +00:00
|
|
|
import { useClipboard } from '@vueuse/core'
|
2026-03-17 13:48:12 +00:00
|
|
|
import { computed, ref } from 'vue'
|
2026-03-01 09:12:45 +00:00
|
|
|
|
Tailwind CSS v4 JSX export (#54)
* Add Tailwind CSS v4 JSX export format
- Add JSXFormat type ('openpencil' | 'tailwind') to sceneNodeToJSX/selectionToJSX
- Tailwind resolver (tailwind.ts): px→spacing (v4 multiplier), hex→color class,
fontSize/fontWeight/borderRadius named lookups with arbitrary value fallback
- Export: FRAME→div, TEXT→p, SECTION→section, className with TW utility classes
- CLI: export --format jsx --style tailwind
- CodePanel: format toggle button (OpenPencil / Tailwind)
- Rename Jsx→JSX in all public APIs (sceneNodeToJSX, selectionToJSX, renderJSX, etc.)
- 29 new Tailwind export tests, all 43 export tests pass
* Extract escapeJSXText — replace nested ternary with entity map lookup
* Deduplicate export-jsx: extract shared padding, corner radius, and node context helpers
* Update changelog
* Tighten Tailwind JSX export fidelity
2026-03-06 15:04:11 +00:00
|
|
|
import { selectionToJSX } from '@open-pencil/core'
|
2026-03-24 13:52:45 +00:00
|
|
|
import { useSceneComputed } from '@open-pencil/vue'
|
|
|
|
|
|
|
|
|
|
import { useEditorStore } from '@/stores/editor'
|
2026-03-01 09:12:45 +00:00
|
|
|
|
Tailwind CSS v4 JSX export (#54)
* Add Tailwind CSS v4 JSX export format
- Add JSXFormat type ('openpencil' | 'tailwind') to sceneNodeToJSX/selectionToJSX
- Tailwind resolver (tailwind.ts): px→spacing (v4 multiplier), hex→color class,
fontSize/fontWeight/borderRadius named lookups with arbitrary value fallback
- Export: FRAME→div, TEXT→p, SECTION→section, className with TW utility classes
- CLI: export --format jsx --style tailwind
- CodePanel: format toggle button (OpenPencil / Tailwind)
- Rename Jsx→JSX in all public APIs (sceneNodeToJSX, selectionToJSX, renderJSX, etc.)
- 29 new Tailwind export tests, all 43 export tests pass
* Extract escapeJSXText — replace nested ternary with entity map lookup
* Deduplicate export-jsx: extract shared padding, corner radius, and node context helpers
* Update changelog
* Tighten Tailwind JSX export fidelity
2026-03-06 15:04:11 +00:00
|
|
|
import type { JSXFormat } from '@open-pencil/core'
|
|
|
|
|
|
2026-03-24 13:52:45 +00:00
|
|
|
const store = useEditorStore()
|
2026-03-17 13:48:12 +00:00
|
|
|
const { copy, copied } = useClipboard({ copiedDuring: 2000 })
|
Tailwind CSS v4 JSX export (#54)
* Add Tailwind CSS v4 JSX export format
- Add JSXFormat type ('openpencil' | 'tailwind') to sceneNodeToJSX/selectionToJSX
- Tailwind resolver (tailwind.ts): px→spacing (v4 multiplier), hex→color class,
fontSize/fontWeight/borderRadius named lookups with arbitrary value fallback
- Export: FRAME→div, TEXT→p, SECTION→section, className with TW utility classes
- CLI: export --format jsx --style tailwind
- CodePanel: format toggle button (OpenPencil / Tailwind)
- Rename Jsx→JSX in all public APIs (sceneNodeToJSX, selectionToJSX, renderJSX, etc.)
- 29 new Tailwind export tests, all 43 export tests pass
* Extract escapeJSXText — replace nested ternary with entity map lookup
* Deduplicate export-jsx: extract shared padding, corner radius, and node context helpers
* Update changelog
* Tighten Tailwind JSX export fidelity
2026-03-06 15:04:11 +00:00
|
|
|
const jsxFormat = ref<JSXFormat>('openpencil')
|
|
|
|
|
|
|
|
|
|
function toggleFormat() {
|
|
|
|
|
jsxFormat.value = jsxFormat.value === 'openpencil' ? 'tailwind' : 'openpencil'
|
|
|
|
|
}
|
2026-03-01 09:12:45 +00:00
|
|
|
|
2026-03-24 13:52:45 +00:00
|
|
|
const jsxCode = useSceneComputed(
|
|
|
|
|
() => {
|
|
|
|
|
const ids = [...store.state.selectedIds]
|
|
|
|
|
if (ids.length === 0) return ''
|
|
|
|
|
return selectionToJSX(ids, store.graph, jsxFormat.value)
|
|
|
|
|
},
|
|
|
|
|
() => store.state.sceneVersion
|
|
|
|
|
)
|
2026-03-01 09:12:45 +00:00
|
|
|
|
|
|
|
|
const highlightedLines = computed(() => {
|
|
|
|
|
if (!jsxCode.value) return []
|
|
|
|
|
const grammar = Prism.languages.jsx ?? Prism.languages.javascript
|
Unify tool definitions: define once, adapt for AI/CLI/MCP
Move tool logic to @open-pencil/core/tools/schema.ts as framework-agnostic
ToolDef objects. AI adapter generates valibot schemas + Vercel AI tool()
wrappers automatically.
26 tools (was 10): create_shape, render (JSX), set_fill, set_stroke,
set_effects, set_layout, set_constraints, update_node, delete, clone,
rename, reparent, group/ungroup, find_nodes, get_node, get_page_tree,
get_selection, select, list_pages, switch_page, list_variables,
list_collections, create_component, create_instance, eval.
src/ai/tools.ts: 269→28 lines (adapter only).
Tests for all 3 interfaces:
- 26 core tool tests (FigmaAPI directly)
- 11 AI adapter tests (valibot + Vercel AI SDK tool())
- 12 CLI integration tests (eval command on .fig fixture)
323 total, all passing.
2026-03-01 11:59:19 +00:00
|
|
|
return jsxCode.value.split('\n').map((line) => Prism.highlight(line, grammar, 'jsx'))
|
2026-03-01 09:12:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function copyCode() {
|
2026-03-17 08:30:25 +00:00
|
|
|
copy(jsxCode.value)
|
2026-03-01 09:12:45 +00:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-03-04 14:18:26 +00:00
|
|
|
<div
|
|
|
|
|
v-if="!jsxCode"
|
|
|
|
|
data-test-id="code-panel-empty"
|
|
|
|
|
class="flex flex-1 items-center justify-center px-4 text-center"
|
|
|
|
|
>
|
2026-03-01 09:12:45 +00:00
|
|
|
<span class="text-xs text-muted">Select a layer to see its JSX code</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-04 14:18:26 +00:00
|
|
|
<div v-else data-test-id="code-panel" class="flex min-h-0 flex-1 flex-col">
|
|
|
|
|
<div
|
|
|
|
|
data-test-id="code-panel-header"
|
|
|
|
|
class="flex shrink-0 items-center justify-between border-b border-border px-3 py-1.5"
|
|
|
|
|
>
|
Tailwind CSS v4 JSX export (#54)
* Add Tailwind CSS v4 JSX export format
- Add JSXFormat type ('openpencil' | 'tailwind') to sceneNodeToJSX/selectionToJSX
- Tailwind resolver (tailwind.ts): px→spacing (v4 multiplier), hex→color class,
fontSize/fontWeight/borderRadius named lookups with arbitrary value fallback
- Export: FRAME→div, TEXT→p, SECTION→section, className with TW utility classes
- CLI: export --format jsx --style tailwind
- CodePanel: format toggle button (OpenPencil / Tailwind)
- Rename Jsx→JSX in all public APIs (sceneNodeToJSX, selectionToJSX, renderJSX, etc.)
- 29 new Tailwind export tests, all 43 export tests pass
* Extract escapeJSXText — replace nested ternary with entity map lookup
* Deduplicate export-jsx: extract shared padding, corner radius, and node context helpers
* Update changelog
* Tighten Tailwind JSX export fidelity
2026-03-06 15:04:11 +00:00
|
|
|
<div class="flex items-center gap-1.5">
|
|
|
|
|
<span class="text-[11px] text-muted">JSX</span>
|
|
|
|
|
<button
|
|
|
|
|
data-test-id="code-panel-format-toggle"
|
|
|
|
|
class="rounded px-1.5 py-0.5 text-[11px] text-muted hover:bg-hover hover:text-surface"
|
|
|
|
|
@click="toggleFormat"
|
|
|
|
|
>
|
|
|
|
|
{{ jsxFormat === 'openpencil' ? 'OpenPencil' : 'Tailwind' }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-03-01 09:12:45 +00:00
|
|
|
<button
|
2026-03-04 14:18:26 +00:00
|
|
|
data-test-id="code-panel-copy"
|
2026-03-01 09:12:45 +00:00
|
|
|
class="flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] text-muted hover:bg-hover hover:text-surface"
|
|
|
|
|
@click="copyCode"
|
|
|
|
|
>
|
|
|
|
|
<icon-lucide-check v-if="copied" class="size-3 text-green-400" />
|
|
|
|
|
<icon-lucide-copy v-else class="size-3" />
|
|
|
|
|
{{ copied ? 'Copied' : 'Copy' }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<ScrollAreaRoot class="min-h-0 flex-1">
|
|
|
|
|
<ScrollAreaViewport class="size-full">
|
|
|
|
|
<div class="p-3">
|
Unify tool definitions: define once, adapt for AI/CLI/MCP
Move tool logic to @open-pencil/core/tools/schema.ts as framework-agnostic
ToolDef objects. AI adapter generates valibot schemas + Vercel AI tool()
wrappers automatically.
26 tools (was 10): create_shape, render (JSX), set_fill, set_stroke,
set_effects, set_layout, set_constraints, update_node, delete, clone,
rename, reparent, group/ungroup, find_nodes, get_node, get_page_tree,
get_selection, select, list_pages, switch_page, list_variables,
list_collections, create_component, create_instance, eval.
src/ai/tools.ts: 269→28 lines (adapter only).
Tests for all 3 interfaces:
- 26 core tool tests (FigmaAPI directly)
- 11 AI adapter tests (valibot + Vercel AI SDK tool())
- 12 CLI integration tests (eval command on .fig fixture)
323 total, all passing.
2026-03-01 11:59:19 +00:00
|
|
|
<div v-for="(html, i) in highlightedLines" :key="i" class="flex text-xs leading-5">
|
2026-03-01 09:12:45 +00:00
|
|
|
<span
|
2026-03-09 12:46:20 +00:00
|
|
|
class="mr-3 shrink-0 text-right text-muted/40 select-none"
|
2026-03-01 09:12:45 +00:00
|
|
|
style="min-width: 1.5em"
|
Unify tool definitions: define once, adapt for AI/CLI/MCP
Move tool logic to @open-pencil/core/tools/schema.ts as framework-agnostic
ToolDef objects. AI adapter generates valibot schemas + Vercel AI tool()
wrappers automatically.
26 tools (was 10): create_shape, render (JSX), set_fill, set_stroke,
set_effects, set_layout, set_constraints, update_node, delete, clone,
rename, reparent, group/ungroup, find_nodes, get_node, get_page_tree,
get_selection, select, list_pages, switch_page, list_variables,
list_collections, create_component, create_instance, eval.
src/ai/tools.ts: 269→28 lines (adapter only).
Tests for all 3 interfaces:
- 26 core tool tests (FigmaAPI directly)
- 11 AI adapter tests (valibot + Vercel AI SDK tool())
- 12 CLI integration tests (eval command on .fig fixture)
323 total, all passing.
2026-03-01 11:59:19 +00:00
|
|
|
>{{ i + 1 }}</span
|
|
|
|
|
>
|
|
|
|
|
<pre
|
2026-03-09 12:46:20 +00:00
|
|
|
class="m-0 min-w-0 flex-1 break-words whitespace-pre-wrap"
|
Unify tool definitions: define once, adapt for AI/CLI/MCP
Move tool logic to @open-pencil/core/tools/schema.ts as framework-agnostic
ToolDef objects. AI adapter generates valibot schemas + Vercel AI tool()
wrappers automatically.
26 tools (was 10): create_shape, render (JSX), set_fill, set_stroke,
set_effects, set_layout, set_constraints, update_node, delete, clone,
rename, reparent, group/ungroup, find_nodes, get_node, get_page_tree,
get_selection, select, list_pages, switch_page, list_variables,
list_collections, create_component, create_instance, eval.
src/ai/tools.ts: 269→28 lines (adapter only).
Tests for all 3 interfaces:
- 26 core tool tests (FigmaAPI directly)
- 11 AI adapter tests (valibot + Vercel AI SDK tool())
- 12 CLI integration tests (eval command on .fig fixture)
323 total, all passing.
2026-03-01 11:59:19 +00:00
|
|
|
><code v-html="html" /></pre>
|
2026-03-01 09:12:45 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</ScrollAreaViewport>
|
2026-03-09 12:46:20 +00:00
|
|
|
<ScrollAreaScrollbar orientation="vertical" class="flex w-1.5 touch-none p-px select-none">
|
2026-03-01 09:12:45 +00:00
|
|
|
<ScrollAreaThumb class="relative flex-1 rounded-full bg-white/10" />
|
|
|
|
|
</ScrollAreaScrollbar>
|
|
|
|
|
</ScrollAreaRoot>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2026-03-16 20:01:51 +00:00
|
|
|
<style scoped>
|
2026-03-01 09:12:45 +00:00
|
|
|
.token.tag {
|
|
|
|
|
color: #7dd3fc;
|
|
|
|
|
}
|
|
|
|
|
.token.attr-name {
|
|
|
|
|
color: #c4b5fd;
|
|
|
|
|
}
|
|
|
|
|
.token.attr-value,
|
|
|
|
|
.token.string {
|
|
|
|
|
color: #86efac;
|
|
|
|
|
}
|
|
|
|
|
.token.number {
|
|
|
|
|
color: #fca5a5;
|
|
|
|
|
}
|
|
|
|
|
.token.punctuation {
|
|
|
|
|
color: #888;
|
|
|
|
|
}
|
|
|
|
|
.token.boolean {
|
|
|
|
|
color: #fca5a5;
|
|
|
|
|
}
|
|
|
|
|
.token.keyword {
|
|
|
|
|
color: #c4b5fd;
|
|
|
|
|
}
|
|
|
|
|
</style>
|