code wiki / _hdl_build / nx_editor_loop.nx

nx_editor_loop.nx source

↩ module page · 36 lines · 2131 B

1// nx_editor_loop.nx -- the NO-JS edit LOOP: the Nishi ecosystem MANAGING a layout with zero JavaScript. The editor 2// surface is rendered (ec_render) with a NATIVE HTML <form> of op buttons; submitting POSTs an op; the server APPLIES 3// the engine op (el_apply -> nx_editor_canvas) and RE-RENDERS. Every edit is a server round-trip -- no client JS, 4// and more governed than drag-drop (each op passes through our code). The daemon route (/editor/apply) is the 5// deployment wiring; this is the sovereign engine of it. REUSE: nx_editor_canvas. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_editor_canvas.nx" 8 9// null-terminated string equality. 10func el_streq(a: *u8, b: *u8) -> i64 { 11 var i: i64 = 0 12 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 13 if b[i] != (0 as u8) { return 0 } 14 return 1 15} 16// apply a posted op to the canvas via the engine. Returns 1 if applied, 0 if the op is unknown (rejected, no-op). 17func el_apply(c: *i64, n: i64, op: *u8) -> i64 { 18 if el_streq(op, "align-left" as *u8) == 1 { ec_align(c, n, 0); return 1 } 19 if el_streq(op, "align-right" as *u8) == 1 { ec_align(c, n, 1); return 1 } 20 if el_streq(op, "align-top" as *u8) == 1 { ec_align(c, n, 2); return 1 } 21 if el_streq(op, "snap" as *u8) == 1 { ec_snap_all(c, n, 8); return 1 } 22 if el_streq(op, "distribute" as *u8) == 1 { ec_distribute_h(c, n); return 1 } 23 return 0 24} 25// render the canvas + a NATIVE HTML ops form (no JS). Submitting an op is a server round-trip. 26func el_emit_form(c: *i64, n: i64, fd: i64) -> i64 { 27 ec_render(c, n, fd) 28 ec_w(fd, "<form method=\"post\" action=\"/editor/apply\">\n" as *u8) 29 ec_w(fd, "<button name=\"op\" value=\"align-left\">Align left</button>\n" as *u8) 30 ec_w(fd, "<button name=\"op\" value=\"align-right\">Align right</button>\n" as *u8) 31 ec_w(fd, "<button name=\"op\" value=\"align-top\">Align top</button>\n" as *u8) 32 ec_w(fd, "<button name=\"op\" value=\"snap\">Snap to grid</button>\n" as *u8) 33 ec_w(fd, "<button name=\"op\" value=\"distribute\">Distribute</button>\n" as *u8) 34 ec_w(fd, "</form>\n" as *u8) 35 return 0 36}