mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-30 10:16:46 +01:00
Merge pull request #2749 from storytold/feat/2424-code-connect-raw
M10, #2424: code connect takes a raw template, with no import line or escaping
This commit is contained in:
12 files changed
+175
-21
No files matched your search
@@ -239,7 +239,7 @@ pub struct Annotation {
|
||||
/// (`figcraft_engine::code_connect`).
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct CodeLink {
|
||||
/// `react`, `leptos`, `vue`, `swiftui`, `compose`, `arkui` or `flutter`.
|
||||
/// `react`, `leptos`, `vue`, `swiftui`, `compose`, `arkui`, `flutter` or `raw`.
|
||||
pub language: String,
|
||||
/// What the snippet imports from (`@acme/ui`, a Swift module, a Kotlin name).
|
||||
#[serde(default, skip_serializing_if = "String::is_empty")]
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
//! Code connect's raw language (#2424): a template language with no import line, such as Blade,
|
||||
//! Django, ERB or Twig, gets its template back as written, values in place and unescaped.
|
||||
|
||||
use crate::Session;
|
||||
use crate::code_connect_tests::{card, code};
|
||||
use crate::components::tests::{ex, idv};
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn a_raw_template_comes_back_as_written_with_the_values_in_place() {
|
||||
let mut s = Session::new();
|
||||
let c = card(&mut s);
|
||||
let i = idv(&ex(&mut s, "instance.create", json!({"component": c, "x": 300, "y": 0})));
|
||||
ex(&mut s, "instance.setProperties", json!({"ids": [i], "properties": {"Show dot": false, "Title": "Say \"hi\" & <b>bye</b>"}}));
|
||||
let template = "<livewire:card title=\"{Title}\" dot=\"{Show dot}\" :size=\"$size\">{Show dot ? \"•\" : \"\"}</livewire:card>";
|
||||
let v = ex(&mut s, "codeConnect.set", json!({"id": i, "language": "raw", "name": "card", "template": template}));
|
||||
let want = "<livewire:card title=\"Say \"hi\" & <b>bye</b>\" dot=\"false\" :size=\"$size\"></livewire:card>\n";
|
||||
assert_eq!(v["code"], want, "no import line, nothing escaped");
|
||||
assert_eq!(code(&mut s, i, "raw"), want);
|
||||
assert_eq!(ex(&mut s, "inspect.code", json!({"id": i, "language": "raw"}))["connected"], true);
|
||||
assert!(code(&mut s, i, "react").contains("function"), "the React code is still generated");
|
||||
// A raw template has no import line to take a path.
|
||||
assert!(s.execute("codeConnect.set", &json!({"id": c, "language": "raw", "importPath": "app/Livewire"})).is_err());
|
||||
// It has no component definition either.
|
||||
assert!(s.execute("inspect.componentCode", &json!({"id": i, "language": "raw"})).is_err());
|
||||
// Out to the connect file and into another design.
|
||||
let text = ex(&mut s, "codeConnect.export", json!({}))["text"].as_str().unwrap().to_string();
|
||||
let mut t = Session::new();
|
||||
let c2 = card(&mut t);
|
||||
assert_eq!(ex(&mut t, "codeConnect.import", json!({"json": text}))["linked"], 1);
|
||||
assert!(code(&mut t, c2, "raw").starts_with("<livewire:card title=\"Hello\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_new_raw_link_passes_every_property_as_an_attribute() {
|
||||
let mut s = Session::new();
|
||||
let c = card(&mut s);
|
||||
let v = ex(&mut s, "codeConnect.set", json!({"id": c, "language": "raw"}));
|
||||
let snippet = v["code"].as_str().unwrap();
|
||||
assert!(snippet.starts_with('<') && snippet.contains("=\"Hello\"") && snippet.contains("=\"true\""), "{snippet}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layer_not_connected_in_raw_is_html() {
|
||||
let mut s = Session::new();
|
||||
let f = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 100, "height": 50, "name": "Box"})));
|
||||
assert_eq!(code(&mut s, f, "raw"), code(&mut s, f, "html"));
|
||||
assert_eq!(ex(&mut s, "inspect.code", json!({"id": f, "language": "raw"}))["connected"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_swapped_in_component_connected_in_raw_is_written_by_its_name() {
|
||||
let mut s = Session::new();
|
||||
let icon = |s: &mut Session, name: &str, x: i32| {
|
||||
let f = idv(&ex(s, "frame.create", json!({"x": x, "y": 0, "width": 24, "height": 24, "name": name})));
|
||||
idv(&ex(s, "component.create", json!({"ids": [f]})))
|
||||
};
|
||||
let (heart, star) = (icon(&mut s, "Heart", 0), icon(&mut s, "Star", 40));
|
||||
ex(&mut s, "codeConnect.set", json!({"id": star, "language": "raw", "name": "star_icon", "template": "<x-star />"}));
|
||||
let f = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 100, "width": 120, "height": 40, "name": "Button"})));
|
||||
let nested = idv(&ex(&mut s, "instance.create", json!({"component": heart, "x": 8, "y": 108, "parent": f})));
|
||||
let button = idv(&ex(&mut s, "component.create", json!({"ids": [f]})));
|
||||
ex(&mut s, "component.addProperty", json!({"id": button, "name": "Icon", "type": "instanceSwap", "default": heart, "layer": nested}));
|
||||
let i = idv(&ex(&mut s, "instance.create", json!({"component": button, "x": 0, "y": 300})));
|
||||
ex(&mut s, "instance.setProperties", json!({"ids": [i], "properties": {"Icon": star}}));
|
||||
ex(&mut s, "codeConnect.set", json!({"id": button, "language": "raw", "name": "button", "template": "<x-button icon=\"{Icon}\" />"}));
|
||||
assert_eq!(code(&mut s, i, "raw"), "<x-button icon=\"star_icon\" />\n");
|
||||
}
|
||||
@@ -7,12 +7,12 @@ use crate::{EngineError, Session};
|
||||
use figcraft_doc::*;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
fn code(s: &mut Session, id: NodeId, lang: &str) -> String {
|
||||
pub(crate) fn code(s: &mut Session, id: NodeId, lang: &str) -> String {
|
||||
ex(s, "inspect.code", json!({"id": id, "language": lang}))["code"].as_str().unwrap_or_default().to_string()
|
||||
}
|
||||
|
||||
/// A "Card" component with a "Title" text property and a "Show dot" boolean property.
|
||||
fn card(s: &mut Session) -> NodeId {
|
||||
pub(crate) fn card(s: &mut Session) -> NodeId {
|
||||
let f = idv(&ex(s, "frame.create", json!({"x": 0, "y": 0, "width": 200, "height": 100, "name": "Card"})));
|
||||
let title = idv(&ex(s, "text.create", json!({"text": "Hello", "x": 10, "y": 10, "parent": f, "props": {"name": "Title"}})));
|
||||
let dot = idv(&ex(s, "shape.ellipse", json!({"x": 170, "y": 10, "width": 20, "height": 20, "parent": f, "props": {"name": "Dot"}})));
|
||||
|
||||
@@ -43,7 +43,17 @@ const MAX_WARNINGS: usize = 50;
|
||||
/// The languages a component can be connected in.
|
||||
pub fn language(s: &str) -> Option<CodeLang> {
|
||||
CodeLang::from_id(s).filter(|l| {
|
||||
matches!(l, CodeLang::React | CodeLang::Leptos | CodeLang::Vue | CodeLang::SwiftUi | CodeLang::Compose | CodeLang::ArkUi | CodeLang::Flutter)
|
||||
matches!(
|
||||
l,
|
||||
CodeLang::React
|
||||
| CodeLang::Leptos
|
||||
| CodeLang::Vue
|
||||
| CodeLang::SwiftUi
|
||||
| CodeLang::Compose
|
||||
| CodeLang::ArkUi
|
||||
| CodeLang::Flutter
|
||||
| CodeLang::Raw
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -281,7 +291,14 @@ fn expr(doc: &Document, c: &Component, p: &Param, v: &Value, lang: CodeLang) ->
|
||||
(Some(l), CodeLang::SwiftUi) => format!("{}()", l.name),
|
||||
(Some(l), CodeLang::ArkUi) => format!("() => {{ {}() }}", l.name),
|
||||
(Some(l), CodeLang::Flutter) => format!("{}()", l.name),
|
||||
(Some(l), CodeLang::Raw) => l.name.clone(),
|
||||
(Some(l), _) => format!("{{ {}() }}", l.name),
|
||||
// A raw template takes the value as text: no quotes or escapes.
|
||||
(None, CodeLang::Raw) => match v {
|
||||
Value::String(s) => s.clone(),
|
||||
Value::Null => String::new(),
|
||||
v => v.to_string(),
|
||||
},
|
||||
(None, _) => value_expr(doc, c, p, v, lang),
|
||||
}
|
||||
}
|
||||
@@ -478,6 +495,7 @@ fn default_template(c: &Component, lang: CodeLang, name: &str) -> String {
|
||||
CodeLang::Vue => format!("<{name}{} />", params.iter().map(|p| format!(" :{p}={{{p}}}")).collect::<String>()),
|
||||
CodeLang::SwiftUi | CodeLang::Flutter => format!("{name}({})", params.iter().map(|p| format!("{p}: {{{p}}}")).collect::<Vec<_>>().join(", ")),
|
||||
CodeLang::ArkUi => format!("{name}({{ {} }})", params.iter().map(|p| format!("{p}: {{{p}}}")).collect::<Vec<_>>().join(", ")),
|
||||
CodeLang::Raw => format!("<{name}{} />", params.iter().map(|p| format!(" {p}=\"{{{p}}}\"")).collect::<String>()),
|
||||
_ => format!("{name}({})", params.iter().map(|p| format!("{p} = {{{p}}}")).collect::<Vec<_>>().join(", ")),
|
||||
}
|
||||
}
|
||||
@@ -508,6 +526,7 @@ pub fn check(c: &Component, link: &CodeLink, lang: CodeLang) -> std::result::Res
|
||||
CodeLang::Leptos => path.chars().all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == ':'),
|
||||
CodeLang::Vue => path.chars().all(|ch| ch.is_ascii_alphanumeric() || "_./@-".contains(ch)),
|
||||
CodeLang::Flutter => path.chars().all(|ch| ch.is_ascii_alphanumeric() || "_./:-".contains(ch)),
|
||||
CodeLang::Raw => path.is_empty(),
|
||||
_ => path.chars().all(|ch| ch.is_ascii_alphanumeric() || ch == '_' || ch == '.'),
|
||||
};
|
||||
if path.chars().count() > MAX_IMPORT || !path_ok {
|
||||
@@ -516,6 +535,7 @@ pub fn check(c: &Component, link: &CodeLink, lang: CodeLang) -> std::result::Res
|
||||
CodeLang::ArkUi => format!("importPath: a module path without quotes, up to {MAX_IMPORT} characters"),
|
||||
CodeLang::Leptos => format!("importPath: a Rust module path (letters, digits, _ and ::), up to {MAX_IMPORT} characters"),
|
||||
CodeLang::Vue => format!("importPath: a module path (letters, digits, _ . / @ and -), up to {MAX_IMPORT} characters"),
|
||||
CodeLang::Raw => "importPath: a raw template has no import line; leave it empty".into(),
|
||||
CodeLang::Flutter => {
|
||||
format!("importPath: a Dart import (package:acme/card.dart; letters, digits, _ . / : and -), up to {MAX_IMPORT} characters")
|
||||
}
|
||||
@@ -568,7 +588,7 @@ fn text(cmd: &str, p: &Value, key: &str) -> Result<Option<String>> {
|
||||
/// The `language` parameter (default React).
|
||||
fn lang_param(cmd: &str, p: &Value) -> Result<CodeLang> {
|
||||
match text(cmd, p, "language")? {
|
||||
Some(l) => language(&l).ok_or_else(|| bad(cmd, "language: react|leptos|vue|swiftui|compose|arkui|flutter")),
|
||||
Some(l) => language(&l).ok_or_else(|| bad(cmd, "language: react|leptos|vue|swiftui|compose|arkui|flutter|raw")),
|
||||
None => Ok(CodeLang::React),
|
||||
}
|
||||
}
|
||||
@@ -689,7 +709,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
spec!(
|
||||
"codeConnect.set",
|
||||
"Connect to code",
|
||||
"{id? (component, set or instance; default the selection), language?: react|leptos|vue|swiftui|compose|arkui|flutter (default react), importPath?, name? (default the generated name), template? (default a call passing every property), source? (the file, relative to the code repository), values? ({property: {design value: code value}}), notes?} links the component (its set, for a variant) to its code component; fields left out keep their current value. Placeholders: {property} (its name or parameter name) and {property ? \"a\" : \"b\"}; other {…} stay as written → {component, language, code (the snippet for the layer), unknown (placeholder names that aren't properties)}",
|
||||
"{id? (component, set or instance; default the selection), language?: react|leptos|vue|swiftui|compose|arkui|flutter|raw (default react; raw: the template as written, no import line or escaping), importPath? (not for raw), name? (default the generated name), template? (default a call passing every property), source? (the file, relative to the code repository), values? ({property: {design value: code value}}), notes?} links the component (its set, for a variant) to its code component; fields left out keep their current value. Placeholders: {property} (its name or parameter name) and {property ? \"a\" : \"b\"}; other {…} stay as written → {component, language, code (the snippet for the layer), unknown (placeholder names that aren't properties)}",
|
||||
true,
|
||||
|s, p| {
|
||||
let cmd = "codeConnect.set";
|
||||
@@ -835,7 +855,7 @@ fn import(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
(field("component"), field("language").and_then(language), field("name"), e.get("template").and_then(Value::as_str))
|
||||
else {
|
||||
warnings.push(format!(
|
||||
"link {}: needs component, language (react|leptos|vue|swiftui|compose|arkui|flutter), name and template strings",
|
||||
"link {}: needs component, language (react|leptos|vue|swiftui|compose|arkui|flutter|raw), name and template strings",
|
||||
i + 1
|
||||
));
|
||||
continue;
|
||||
|
||||
@@ -45,15 +45,14 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![spec!(
|
||||
"inspect.code",
|
||||
"Code for layer",
|
||||
"{id?, language?: css|html|react|leptos|vue|tailwind|swiftui|compose|arkui|flutter|uno (default css; html, react, leptos and vue are the whole layer tree; components take their properties as parameters, instances pass their values; a component connected to code (codeConnect.set) gives its import and snippet instead; tailwind is React with Tailwind CSS v4 utilities for pages: fluid auto layout boxes, instances inlined with their overrides, bound variables as theme utilities), mobile? (tailwind: a mobile frame with the same layer names; the code is mobile first with the desktop layer's classes behind lg:), unit?: px|rem (CSS, HTML, React, Leptos and Vue; default px), rootFontSize? (rem: pixels per rem, default 16)} → {code, language, connected}",
|
||||
"{id?, language?: css|html|react|leptos|vue|tailwind|swiftui|compose|arkui|flutter|uno|raw (default css; raw is a component's code connect template as written, other layers HTML; html, react, leptos and vue are the whole layer tree; components take their properties as parameters, instances pass their values; a component connected to code (codeConnect.set) gives its import and snippet instead; tailwind is React with Tailwind CSS v4 utilities for pages: fluid auto layout boxes, instances inlined with their overrides, bound variables as theme utilities), mobile? (tailwind: a mobile frame with the same layer names; the code is mobile first with the desktop layer's classes behind lg:), unit?: px|rem (CSS, HTML, React, Leptos and Vue; default px), rootFontSize? (rem: pixels per rem, default 16)} → {code, language, connected}",
|
||||
false,
|
||||
|s, p| {
|
||||
let cmd = "inspect.code";
|
||||
let id = targets(s, p).first().copied().ok_or_else(|| bad(cmd, "select a layer"))?;
|
||||
let lang = match string(p, "language") {
|
||||
Some(l) => {
|
||||
CodeLang::from_id(&l).ok_or_else(|| bad(cmd, "language: css|html|react|leptos|vue|tailwind|swiftui|compose|arkui|flutter|uno"))?
|
||||
}
|
||||
Some(l) => CodeLang::from_id(&l)
|
||||
.ok_or_else(|| bad(cmd, "language: css|html|react|leptos|vue|tailwind|swiftui|compose|arkui|flutter|uno|raw"))?,
|
||||
None => CodeLang::Css,
|
||||
};
|
||||
let rem = match string(p, "unit").map(|u| u.to_ascii_lowercase()).as_deref() {
|
||||
@@ -109,10 +108,13 @@ pub enum CodeLang {
|
||||
Flutter,
|
||||
/// Uno Platform C# Markup (.NET): a fluent C# expression tree of WinUI elements.
|
||||
Uno,
|
||||
/// A code connect template written out as is (Blade, Django, ERB, Twig…): no import line and
|
||||
/// no escaping. A layer not connected in it is HTML + CSS.
|
||||
Raw,
|
||||
}
|
||||
|
||||
impl CodeLang {
|
||||
pub const ALL: [CodeLang; 11] = [
|
||||
pub const ALL: [CodeLang; 12] = [
|
||||
CodeLang::Css,
|
||||
CodeLang::Html,
|
||||
CodeLang::React,
|
||||
@@ -124,6 +126,7 @@ impl CodeLang {
|
||||
CodeLang::ArkUi,
|
||||
CodeLang::Flutter,
|
||||
CodeLang::Uno,
|
||||
CodeLang::Raw,
|
||||
];
|
||||
pub fn id(self) -> &'static str {
|
||||
match self {
|
||||
@@ -138,6 +141,7 @@ impl CodeLang {
|
||||
CodeLang::ArkUi => "arkui",
|
||||
CodeLang::Flutter => "flutter",
|
||||
CodeLang::Uno => "uno",
|
||||
CodeLang::Raw => "raw",
|
||||
}
|
||||
}
|
||||
pub fn label(self) -> &'static str {
|
||||
@@ -153,6 +157,7 @@ impl CodeLang {
|
||||
CodeLang::ArkUi => "ArkUI",
|
||||
CodeLang::Flutter => "Flutter",
|
||||
CodeLang::Uno => "Uno C# Markup",
|
||||
CodeLang::Raw => "Raw template",
|
||||
}
|
||||
}
|
||||
/// Languages whose lengths are CSS pixels that can be shown in rem (not Tailwind: its lengths
|
||||
@@ -295,6 +300,9 @@ pub fn code_for(doc: &Document, id: NodeId, lang: CodeLang) -> String {
|
||||
match lang {
|
||||
CodeLang::Css => css(doc, id),
|
||||
CodeLang::Html => html(doc, id),
|
||||
CodeLang::Raw => crate::code_connect::link(doc, id, lang)
|
||||
.and_then(|l| crate::code_connect::connected_code(doc, id, lang, l))
|
||||
.unwrap_or_else(|| html(doc, id)),
|
||||
CodeLang::Tailwind => crate::tailwind::code(doc, id, None),
|
||||
CodeLang::React
|
||||
| CodeLang::Leptos
|
||||
|
||||
@@ -76,8 +76,11 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
let cmd = "inspect.componentCode";
|
||||
let id = targets(s, p).first().copied().ok_or_else(|| bad(cmd, "select a component or instance"))?;
|
||||
let lang = match string(p, "language") {
|
||||
// One list of code languages, shared with codeConnect (see `code_connect::language`).
|
||||
Some(l) => crate::code_connect::language(&l).ok_or_else(|| bad(cmd, "language: react|leptos|vue|swiftui|compose|arkui|flutter"))?,
|
||||
// One list of code languages, shared with codeConnect (see `code_connect::language`);
|
||||
// a raw template has no component definition.
|
||||
Some(l) => crate::code_connect::language(&l)
|
||||
.filter(|l| *l != CodeLang::Raw)
|
||||
.ok_or_else(|| bad(cmd, "language: react|leptos|vue|swiftui|compose|arkui|flutter"))?,
|
||||
None => CodeLang::React,
|
||||
};
|
||||
let doc = s.doc()?;
|
||||
|
||||
@@ -259,7 +259,9 @@ mod brush_tests;
|
||||
#[cfg(test)]
|
||||
mod canvas_fixes_tests;
|
||||
#[cfg(test)]
|
||||
mod code_connect_tests;
|
||||
mod code_connect_raw_tests;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod code_connect_tests;
|
||||
#[cfg(test)]
|
||||
mod collab_ids_tests;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//! The Inspect tab's Connect to code section, driven headless: a raw template link has no import
|
||||
//! line, so it shows no Import path field and its name takes the whole row (#2424).
|
||||
|
||||
use egui::accesskit::Node;
|
||||
use figcraft_engine::Session;
|
||||
use figcraft_engine::codegen::CodeLang;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::component_swap_default_tests::tree;
|
||||
use crate::layers_drag_tests::Ui;
|
||||
|
||||
/// The Connect to code fields shown for a component connected in `lang`: (has an Import path
|
||||
/// field, the Component name field's width).
|
||||
fn fields(lang: CodeLang) -> (bool, f64) {
|
||||
let mut s = Session::new();
|
||||
let f = s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 120, "height": 40, "name": "Card"})).unwrap();
|
||||
let c = s.execute("component.create", &json!({"ids": [f["id"]]})).unwrap();
|
||||
s.execute("codeConnect.set", &json!({"id": c["id"], "language": lang.id(), "name": "Card", "template": "<Card />"})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [c["id"]]})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.app.ui.right_tab = crate::RightTab::Inspect;
|
||||
let index = CodeLang::ALL.iter().position(|l| *l == lang).unwrap();
|
||||
u.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("inspect_lang"), index));
|
||||
u.ctx.enable_accesskit();
|
||||
let nodes = tree(&mut u);
|
||||
let named = |name: &str| nodes.iter().find(|n: &&Node| n.label() == Some(name) && n.bounds().is_some()).cloned();
|
||||
let name = named("Component name").expect("the Component name field");
|
||||
let b = name.bounds().unwrap();
|
||||
(named("Import path").is_some(), b.x1 - b.x0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_raw_link_has_no_import_path_and_a_wider_name() {
|
||||
let (react_import, react_name) = fields(CodeLang::React);
|
||||
let (raw_import, raw_name) = fields(CodeLang::Raw);
|
||||
assert!(react_import, "React has an import path");
|
||||
assert!(!raw_import, "a raw template has none");
|
||||
assert!(raw_name > react_name, "the name takes the row: {raw_name} > {react_name}");
|
||||
}
|
||||
@@ -49,6 +49,8 @@ mod board_picker_tests;
|
||||
#[cfg(test)]
|
||||
mod board_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod code_connect_panel_tests;
|
||||
#[cfg(test)]
|
||||
mod theme_startup_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -471,14 +471,19 @@ pub fn connect_section(app: &mut FigApp, ui: &mut Ui, doc: &Document, id: NodeId
|
||||
let from = widgets::elide(ui, &from, r.max.x - PAD - from_x);
|
||||
ui.painter().text(pos2(from_x, r.center().y), Align2::LEFT_CENTER, from, regular(11.0), t.text_secondary);
|
||||
let mut edit: Option<(&str, String)> = None;
|
||||
widgets::sublabels(ui, tr("Import path"), Some(tr("Name")));
|
||||
// A raw template has no import line: its name takes the whole row.
|
||||
let raw = lang == CodeLang::Raw;
|
||||
widgets::sublabels(ui, if raw { tr("Name") } else { tr("Import path") }, (!raw).then(|| tr("Name")));
|
||||
let col = widgets::col_width(ui.available_width());
|
||||
row(ui, 32.0, |ui| {
|
||||
ui.spacing_mut().item_spacing.x = 8.0;
|
||||
if let Some(v) = widgets::text_field(ui, Id::unique(("code_connect_import", owner, lang.id())), &link.import_path, col, tr("Import path")) {
|
||||
if !raw
|
||||
&& let Some(v) = widgets::text_field(ui, Id::unique(("code_connect_import", owner, lang.id())), &link.import_path, col, tr("Import path"))
|
||||
{
|
||||
edit = Some(("importPath", v));
|
||||
}
|
||||
if let Some(v) = widgets::text_field(ui, Id::unique(("code_connect_name", owner, lang.id())), &link.name, col, tr("Component name")) {
|
||||
let width = if raw { ui.available_width() - 2.0 * PAD } else { col };
|
||||
if let Some(v) = widgets::text_field(ui, Id::unique(("code_connect_name", owner, lang.id())), &link.name, width, tr("Component name")) {
|
||||
edit = Some(("name", v));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@ repository, third-party integrations. Remaining: 1–2 h.
|
||||
|
||||
| Feature | Status | Notes |
|
||||
|---|---|---|
|
||||
| 2026-11-29 | patch | M10, #2424: code connect takes a raw template (`raw`, Raw template in the Inspect panel) for template languages used without an import, such as Blade, Django, ERB and Twig: no import line (the import path is refused, and the Inspect panel shows only the name), each value goes into the template as plain text with nothing escaped or quoted, and a new link's template is `<Name prop="{prop}" … />`. `inspect.code {language: raw}` gives a connected component's template and HTML + CSS for any other layer; `inspect.componentCode` doesn't take it. It travels in `figcraft.connect.json` like the other languages. Tests: `code_connect_raw_tests`. Percentages and hours unchanged |
|
||||
| 2026-11-27 | patch | SwiftUI, Compose and Flutter code export dropped image fills, so a layer with a white fill, a photo and a 50% black overlay lost the photo (#2271). Each image fill is now written in its paint-order place, as the asset `file.exportAssets` hands over (named by the start of the image's content hash): SwiftUI `Image("<name>")` in a `.background(...)` (a rectangle or ellipse lays it over the paints below and clips it to the shape; a frame clips it), Compose `Modifier.paint(painterResource(R.drawable.image_<name>))` after a `clip` to the layer's shape (Android resource names can't start with a digit, hence `image_`), Flutter a `DecorationImage(image: AssetImage("<name>.<ext>"))` in that fill's `BoxDecoration`. Fill and crop cover the box, fit fits inside it, tile repeats (SwiftUI `resizingMode: .tile`, a Compose `ImageShader` brush, Flutter `ImageRepeat.repeat`); the paint's opacity carries over. Not carried over: crop rectangles, rotation, tile scale and image adjustments (`file.exportAssets` lists them per layer). A pattern fill's cells are layers no native paint repeats, so it is left out with a `// pattern fill left out` line. Tests: `dev::codegen::tests::native_code_keeps_an_image_fill_between_the_fills_around_it`, `dev::codegen::tests::native_image_fills_follow_their_scale_mode_and_opacity`, `dev::codegen::tests::native_code_says_a_pattern_fill_is_left_out`. Percentages and hours unchanged |
|
||||
| 2026-11-24 | patch | Vector code export drew a path's stroke as a box border around its bounds (#2270). CSS, HTML, React, Vue, Leptos and Tailwind no longer invent that border or a rectangular fill; the markup targets embed node-local SVG data URIs, so nested vectors need no external export and URL fragments cannot break them. A node-sized wrapper keeps layout, rotation and opacity, while the inner image uses the SVG's painted bounds with visible overflow. The SVG owns shadows and layer blur, so wrapper CSS does not apply them twice; standalone CSS and ordinary shapes keep theirs. SwiftUI and ArkUI no longer put a rectangle stroke around their vector image either. Ordinary box and ellipse strokes are unchanged. Tests: `dev::codegen::tests::vector_code_uses_its_svg_asset_not_a_box_border`, `dev::codegen::tests::vector_assets_are_self_contained_and_leptos_literals_escape`, `dev::codegen::tests::vector_asset_keeps_stroke_overflow_inside_a_node_sized_wrapper`, `dev::codegen::tests::vector_markup_does_not_duplicate_svg_effects`; real CLI checks nested assets, rotation/opacity, 24→28 stroke bounds and single-application effects |
|
||||
| 2026-11-12 | patch | SwiftUI, Compose and Flutter code export kept one colour per layer (the bottom visible solid, or a gradient's first stop) and dropped every other fill (#2271). Now each writes every visible solid and gradient fill of a frame, group, rectangle or ellipse, in paint order, and a gradient as a gradient. SwiftUI chains `.background(...)` with the top fill first, since each one goes behind the ones before it (a rectangle or ellipse fills with the bottom paint and lays a copy of the shape over it for each paint above). Compose chains `Modifier.background(...)` with the bottom fill first, since each one draws over the ones before it (a linear gradient snaps to eight directions, radial and angular ones sit at the box's centre). Flutter keeps the top fill in the `Container` and wraps each fill under it in a `DecoratedBox`, the bottom fill outermost and the drop shadow on the outermost box. A layer with one solid fill gives the same code as before; a lone gradient is now a gradient, not its first stop's colour. Still not written: image and pattern fills in the native targets, ArkUI (one background and one gradient per component, so a stack needs extra nodes) and text with several fills. The incumbent's iOS and Android output wasn't measured: the order follows how each platform paints. Percentages and hours unchanged |
|
||||
@@ -29,7 +30,7 @@ repository, third-party integrations. Remaining: 1–2 h.
|
||||
| Ready for dev list, statuses, "Changed" after edits | done | the list filters Ready for dev, Changed, Completed or any, and badges changed ones (`inspect.readyForDev {status: changed}`, `changed` per item); only sections and frames at the top of a page or section take a status (others are refused) |
|
||||
| Focus view (one frame, previous / next) | done | |
|
||||
| Compare changes (before/after side by side or overlaid, property diffs) | done | against the snapshot taken when a frame was first changed after it was marked ready, or any saved version (`dev.compare {version}`; the view's Compare with menu); a frame that isn't ready for dev compares with versions |
|
||||
| Code connect (map components to repository code) | done | per language (React, Leptos, Vue, SwiftUI, Compose, ArkUI, Flutter): import path, name and a template with `{property}` and `{property ? "a" : "b"}` placeholders; instances (also inside generated layer trees) show the snippet with their values; edited in the Inspect panel with a live preview; `figcraft.connect.json` export/import; generated layer trees bring the import lines of the connected components they call (also in definitions, slots and swapped-in instances) once each at the top, per language. `figcraft-cli connect publish` publishes a repository's mappings to a design file (`--dry-run` to check them first) |
|
||||
| Code connect (map components to repository code) | done | per language (React, Leptos, Vue, SwiftUI, Compose, ArkUI, Flutter, and Raw template for Blade, Django, ERB, Twig and other languages used without an import: no import line, values unescaped, only for the component or instance itself, while a generated tree around it stays plain HTML, #2424): import path, name and a template with `{property}` and `{property ? "a" : "b"}` placeholders; instances (also inside generated layer trees) show the snippet with their values; edited in the Inspect panel with a live preview; `figcraft.connect.json` export/import; generated layer trees bring the import lines of the connected components they call (also in definitions, slots and swapped-in instances) once each at the top, per language. `figcraft-cli connect publish` publishes a repository's mappings to a design file (`--dry-run` to check them first) |
|
||||
| Plugins in Dev Mode (Jira, GitHub, etc.) | partial | FigCraft's own WASM plugins that only read run from the Inspect tab, with their panels (callbacks can only read); no third-party integrations |
|
||||
| Measurements (redlines on hover, Alt in the design) | done | distances between the selection and the hovered layer, its parent or a guide, auto layout padding and gaps (Shift+Alt); measurements kept on the canvas (`devMode.addMeasurement` between two layers, along a side or to the layer around it; stored on the layer, saved, synced, undoable) drawn in Dev Mode as labelled redlines that follow the layers, listed, placed and removed in the Inspect tab; a measurement whose other layer was deleted isn't drawn until an undo brings it back |
|
||||
| VS Code extension | out of scope | FigCraft's MCP server and control channel already serve design data, code and connected snippets to agents and editors |
|
||||
|
||||
+8
-2
@@ -2002,7 +2002,7 @@ permissions: without it nothing is downloaded); `plugin.directory.publish {path
|
||||
corner smoothing and arcs are `// not mapped: …` comments. Components and instances are written as the frames they are;
|
||||
`inspect.componentCode` and code connect do not take `uno` yet.
|
||||
- **Code connect:** link a component (a variant links its set) to the code component it is built
|
||||
as, per language (`react`, `leptos`, `vue`, `swiftui`, `compose`, `arkui`, `flutter`): `codeConnect.set {id?, language?, importPath?,
|
||||
as, per language (`react`, `leptos`, `vue`, `swiftui`, `compose`, `arkui`, `flutter`, `raw`): `codeConnect.set {id?, language?, importPath?,
|
||||
name?, template?}` (undoable; fields left out keep their value; the defaults are the generated
|
||||
name and a call passing every property) → `{component, language, code, unknown}`. Templates are
|
||||
text, never executed: `{property}` (its name or parameter name) is the instance's value escaped
|
||||
@@ -2024,7 +2024,13 @@ permissions: without it nothing is downloaded); `plugin.directory.publish {path
|
||||
template, import, code}` with the snippet as `usage`. Example: template `<Button
|
||||
variant="primary" icon="{Has icon ? "cart" : "none"}">{label}</Button>` with import path
|
||||
`@acme/ui` gives `import { Button } from "@acme/ui";` then `<Button variant="primary" icon="none">{"Buy
|
||||
now"}</Button>`. `codeConnect.remove {id?, language?}` (no language: all). `codeConnect.export
|
||||
now"}</Button>`. `raw` is for template languages used without an import, such as Blade,
|
||||
Django, ERB or Twig: no import line (`importPath` is refused), and each value goes into the
|
||||
template as plain text, with nothing escaped or quoted. `<livewire:card title="{Title}" />` gives
|
||||
`<livewire:card title="Buy now" />`. A new raw link's template is `<Name prop="{prop}" … />`. In
|
||||
`inspect.code {language: raw}`, a layer that isn't connected in raw comes back as HTML + CSS, and
|
||||
`inspect.componentCode` doesn't take `raw` (a template has no component definition).
|
||||
`codeConnect.remove {id?, language?}` (no language: all). `codeConnect.export
|
||||
{path?}` → `{text, links}` (or writes the file): `{version: 1, links: [{component, language,
|
||||
importPath, name, template, source?, values?, notes?}]}`, sorted, meant to live in the code
|
||||
repository as `figcraft.connect.json` (writing a file that's there keeps its other top-level keys
|
||||
|
||||
Reference in new issue
Block a user