mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-24 10:27:00 -06:00
Batch r2-2: explicit imports, a method reference, the .fig test helper named main_component
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::cmd::CommandSpec;
|
||||
use crate::params::*;
|
||||
use crate::params::{get, id, id_of, num_or, string};
|
||||
use crate::{Result, Session, bad, spec};
|
||||
|
||||
const CMD: &str = "data.fill";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::Session;
|
||||
use crate::components::tests::{ex, idv};
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::{NodeId, NodeKind};
|
||||
use serde_json::json;
|
||||
|
||||
/// A 1080×1350 "Post" with "Title" and "Price" texts and a "Badge" rectangle. Returns the frame.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::{Document, NodeId, NodeKind, Variable, VariableId, VariableType};
|
||||
|
||||
use crate::codegen::{CodeLang, Ctx, Markup, css_var_name, css_var_of, num};
|
||||
use crate::component_codegen::component_type_name;
|
||||
@@ -454,7 +454,7 @@ pub fn code(doc: &Document, id: NodeId, mobile: Option<NodeId>) -> String {
|
||||
// ponytail: layers only on mobile are listed, not merged in; their place in the tree is ambiguous.
|
||||
let only_mobile: Vec<String> = small
|
||||
.iter()
|
||||
.flat_map(|m| m.keys())
|
||||
.flat_map(BTreeMap::keys)
|
||||
.filter(|p| !rules.iter().any(|(d, _, _)| d == *p))
|
||||
.map(|p| p.trim_start_matches('/').split('/').map(|seg| seg.rsplit_once('#').map_or(seg, |(n, _)| n)).collect::<Vec<_>>().join(" › "))
|
||||
.take(20)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use crate::Session;
|
||||
use crate::components::tests::{ex, idv};
|
||||
use crate::tailwind::{classes, merge};
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::NodeId;
|
||||
use serde_json::json;
|
||||
|
||||
fn code(s: &mut Session, id: NodeId, extra: serde_json::Value) -> String {
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
//! with a no-break space. Every style run scales by the same factor, so mixed sizes keep their
|
||||
//! proportions.
|
||||
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::{NodeKind, TextAutoResize, TextData};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::cmd::CommandSpec;
|
||||
use crate::params::*;
|
||||
use crate::params::{boolean, num, req_targets};
|
||||
use crate::{Result, Session, bad, spec};
|
||||
|
||||
const CMD: &str = "text.fit";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use crate::Session;
|
||||
use crate::components::tests::{ex, idv};
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::{NodeId, NodeKind};
|
||||
use serde_json::json;
|
||||
|
||||
/// A fixed-width (auto-height) headline of `width` px at 64px. Returns its id.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use figcraft_doc::*;
|
||||
use figcraft_doc::{Document, Variable, VariableId, VariableType, VariableValue};
|
||||
|
||||
use crate::codegen::num;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
use figcraft_doc::{Document, NodeKind};
|
||||
|
||||
use super::kiwi::{Kv, Schema};
|
||||
use super::*;
|
||||
use super::{MAX_FIG_NODES, export, import, layer_budget, map};
|
||||
|
||||
type Fields = Vec<(&'static str, Kv<'static>)>;
|
||||
|
||||
@@ -36,7 +36,7 @@ fn instance(id: u64, page: u64, main: u64) -> Kv<'static> {
|
||||
}
|
||||
|
||||
/// A main `id` of `layers` rectangles under `parent`.
|
||||
fn main(id: u64, parent: u64, name: &str, layers: u64) -> Vec<Kv<'static>> {
|
||||
fn main_component(id: u64, parent: u64, name: &str, layers: u64) -> Vec<Kv<'static>> {
|
||||
let mut out = vec![node(id, Some(parent), "SYMBOL", name, vec![("size", xy(10.0, 10.0))])];
|
||||
out.extend((1..=layers).map(|i| node(id * 10_000 + i, Some(id), "RECTANGLE", "R", vec![("size", xy(1.0, 1.0))])));
|
||||
out
|
||||
@@ -50,7 +50,7 @@ fn library_message(count: u64, main_layers: u64) -> Kv<'static> {
|
||||
node(2, Some(1), "CANVAS", "Screens", vec![]),
|
||||
node(3, Some(1), "CANVAS", "Internal", vec![("internalOnly", Kv::Bool(true))]),
|
||||
];
|
||||
nodes.extend(main(20, 3, "Library main", main_layers));
|
||||
nodes.extend(main_component(20, 3, "Library main", main_layers));
|
||||
nodes.extend((0..count).map(|i| instance(1_000 + i, 2, 20)));
|
||||
o(vec![("nodeChanges", Kv::Array(nodes))])
|
||||
}
|
||||
@@ -96,7 +96,7 @@ fn instances_of_a_main_the_cap_kept_out_say_so() {
|
||||
// file has it.
|
||||
let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])];
|
||||
nodes.extend((0..20).map(|i| instance(100 + i, 2, 900)));
|
||||
nodes.extend(main(900, 2, "Local main", 10));
|
||||
nodes.extend(main_component(900, 2, "Local main", 10));
|
||||
let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 60);
|
||||
assert!(warnings.iter().any(|w| w.starts_with("instances whose component was past the layer limit were imported as frames")), "{warnings:?}");
|
||||
assert!(!warnings.iter().any(|w| w.contains("aren't in the file")), "{warnings:?}");
|
||||
@@ -115,8 +115,8 @@ fn swap_defaults_the_cap_kept_out_say_so() {
|
||||
]);
|
||||
let mut nodes = vec![node(1, None, "DOCUMENT", "Document", vec![]), node(2, Some(1), "CANVAS", "Page", vec![])];
|
||||
nodes.push(node(50, Some(2), "SYMBOL", "Card", vec![("size", xy(10.0, 10.0)), ("componentPropDefs", Kv::Array(vec![swap]))]));
|
||||
nodes.extend(main(60, 2, "Filler", 40));
|
||||
nodes.extend(main(900, 2, "Icon main", 10));
|
||||
nodes.extend(main_component(60, 2, "Filler", 40));
|
||||
nodes.extend(main_component(900, 2, "Icon main", 10));
|
||||
let (doc, warnings) = import_at(&o(vec![("nodeChanges", Kv::Array(nodes))]), 30);
|
||||
assert!(doc.nodes().any(|n| n.name == "Card"));
|
||||
assert!(!doc.nodes().any(|n| n.name == "Icon main"));
|
||||
|
||||
Reference in New Issue
Block a user