Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
lock_to_source.hpp
Go to the documentation of this file.
1#pragma once
2
32
34
35#include <optional>
36#include <string>
37#include <vector>
38
39namespace pulp::view {
40
49 std::string anchor_id;
50 std::string property_path;
54 std::string value;
55};
56
75
77struct LockResult {
82 std::string source;
85 std::string style_property;
87 std::string message;
90 int line = 0;
91
93 bool mutated() const {
95 }
96
99 bool ok() const {
100 return status == LockStatus::rewritten ||
103 }
104};
105
119std::optional<std::string>
120lock_property_to_style_name(const std::string& property_path);
121
134LockResult lock_tweak_into_source(const std::string& source,
135 const LockToSourceTweak& tweak);
136
143std::vector<LockResult>
144lock_tweaks_into_source(const std::string& source,
145 const std::vector<LockToSourceTweak>& tweaks);
146
147// ── Structural reparent lock-to-source ───────────────────────────────────────
148//
149// A reflow-aware drag can "drop element A inside container B" — a STRUCTURAL
150// tree edit, not a style tweak. In the generated web-compat artifact every
151// element block ends with `<parentVar>.appendChild(<var>);` wiring it to its
152// parent. Reparenting therefore means rewriting the dragged element's
153// `appendChild` receiver from its old parent's var to the NEW parent's var.
154//
155// This is the structural sibling of lock_tweak_into_source(): it is a pure
156// text-in/text-out rewrite over the same anchor-comment block model. It does
157// NOT (yet) move the element block's TEXT to sit physically inside the new
158// parent's block — the appendChild receiver rewrite is what changes the live
159// DOM parent, and re-running the element block in source order still produces
160// the reparented tree because createElement + appendChild are order-independent
161// once the receiver is correct. Reordering the physical block position to match
162// remains a separate formatting pass.
163
173 std::string child_anchor_id;
175 std::string insert_after_anchor_id; // preceding sibling, or "" = first child
176};
177
192LockResult reparent_in_source(const std::string& source,
193 const ReparentToSourceEdit& edit);
194
200bool is_generated_source(const std::string& source);
201
202} // namespace pulp::view
Import design files from external tools (Figma, Stitch, v0, Pencil) into Pulp's web-compat JS format.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ inserted
Definition design_update.hpp:10
LockResult lock_tweak_into_source(const std::string &source, const LockToSourceTweak &tweak)
Locate the element anchored by tweak.anchor_id in a generated web-compat JS/TSX source string and rew...
LockStatus
Outcome status for a single lock attempt.
Definition lock_to_source.hpp:58
@ already_current
The element block was found and the property already held exactly value — the source text is unchange...
Definition lock_to_source.hpp:66
@ anchor_not_found
No // @pulp-anchor <id> comment matched anchor_id.
Definition lock_to_source.hpp:70
@ rewritten
The property line existed and its value was rewritten.
Definition lock_to_source.hpp:60
@ inserted
No line for the property existed; a new el.style.
Definition lock_to_source.hpp:63
std::optional< std::string > lock_property_to_style_name(const std::string &property_path)
Map a dotted tweak property_path (paint.backgroundColor, style.width, layout.padding,...
@ already_current
The element and prop were found and the prop already held exactly value — source unchanged (idempoten...
Definition jsx_lock.hpp:85
@ anchor_not_found
No element carried data-pulp-anchor="<anchor_id>".
Definition jsx_lock.hpp:88
std::vector< LockResult > lock_tweaks_into_source(const std::string &source, const std::vector< LockToSourceTweak > &tweaks)
Lock several tweaks into the same source in one pass.
@ unsupported_property
Definition design_ir.hpp:702
bool is_generated_source(const std::string &source)
Heuristic guard for the generated-file boundary.
LockResult reparent_in_source(const std::string &source, const ReparentToSourceEdit &edit)
Rewrite the dragged element's appendChild receiver so the generated source wires it under the new par...
Result of locking one tweak into a generated source string.
Definition lock_to_source.hpp:77
std::string style_property
The CSS-style property name the path resolved to (camelCase, e.g.
Definition lock_to_source.hpp:85
std::string message
Human-readable summary, suitable for CLI / inspector display.
Definition lock_to_source.hpp:87
int line
1-based line number of the rewritten / inserted assignment, or 0 when nothing was located.
Definition lock_to_source.hpp:90
bool mutated() const
True when the lock changed the source text.
Definition lock_to_source.hpp:93
std::string source
The (possibly rewritten) source text.
Definition lock_to_source.hpp:82
LockStatus status
Definition lock_to_source.hpp:78
bool ok() const
True when the anchor was located, regardless of whether a rewrite was needed (already_current counts ...
Definition lock_to_source.hpp:99
A single tweak to promote into source.
Definition lock_to_source.hpp:48
std::string anchor_id
Definition lock_to_source.hpp:49
std::string property_path
Definition lock_to_source.hpp:50
std::string value
The tweaked value, already stringified the way it should appear in the generated source's JS string l...
Definition lock_to_source.hpp:54
A single structural reparent to promote into source: move the element anchored by child_anchor_id to ...
Definition lock_to_source.hpp:172
std::string insert_after_anchor_id
Definition lock_to_source.hpp:175
std::string child_anchor_id
Definition lock_to_source.hpp:173
std::string new_parent_anchor_id
Definition lock_to_source.hpp:174