mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
refactor: rename zx.zx to zx.x
This commit is contained in:
parent
e3d6d1b175
commit
f22b89a423
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,6 +14,7 @@ node_modules
|
||||
# pkg/transformjs
|
||||
tmp
|
||||
test/data/assets/
|
||||
test/data/**/*.zxcache
|
||||
/package.json
|
||||
/bun.lock
|
||||
/src/cli/init/template/bun.lock
|
||||
|
||||
@ -501,7 +501,7 @@ pub fn transpileReturn(self: *Ast, node: ts.Node, ctx: *TranspileContext) !void
|
||||
const allocator_value = try getAllocatorAttribute(self, child);
|
||||
|
||||
// Synthesized _zx init - no source mapping (it's boilerplate)
|
||||
try ctx.write("var _zx = @import(\"zx\").");
|
||||
try ctx.write("var _zx = @import(\"zx\").x.");
|
||||
if (allocator_value) |alloc| {
|
||||
try ctx.write("allocInit(");
|
||||
try ctx.write(alloc);
|
||||
@ -580,7 +580,7 @@ pub fn transpileBlock(self: *Ast, node: ts.Node, ctx: *TranspileContext) !void {
|
||||
|
||||
ctx.indent_level += 1;
|
||||
try ctx.writeIndent();
|
||||
try ctx.write("var _zx = @import(\"zx\").");
|
||||
try ctx.write("var _zx = @import(\"zx\").x.");
|
||||
if (allocator_value) |alloc| {
|
||||
try ctx.write("allocInit(");
|
||||
try ctx.write(alloc);
|
||||
|
||||
17
src/root.zig
17
src/root.zig
@ -8,13 +8,13 @@ const module_options = @import("zx_module_options");
|
||||
const element = @import("element.zig");
|
||||
const plfm = @import("platform.zig");
|
||||
const prp = @import("props.zig");
|
||||
const z = @import("zx.zig");
|
||||
|
||||
const routing = @import("runtime/core/routing.zig");
|
||||
const app_module = @import("runtime/server/Server.zig");
|
||||
const opts = @import("options.zig");
|
||||
const ctxs = @import("contexts.zig");
|
||||
const reactivity = @import("runtime/client/reactivity.zig");
|
||||
const app_mod = @import("App.zig");
|
||||
|
||||
// -- Core Language --//
|
||||
pub const Ast = if (!module_options.exclude_core_lang) @import("zx_core_lang").Ast else @compileError("core_lang is excluded. Set exclude-core-lang=false to enable.");
|
||||
@ -26,13 +26,9 @@ pub const sourcemap = if (!module_options.exclude_core_lang) @import("zx_core_la
|
||||
pub const ElementTag = element.Tag;
|
||||
pub const Component = @import("Component.zig").Component;
|
||||
pub const Element = @import("Component.zig").Element;
|
||||
const ZxOptions = z.ZxOptions;
|
||||
pub const ZxContext = z.ZxContext;
|
||||
|
||||
pub const zx = z.x;
|
||||
pub const lazy = z.lazy;
|
||||
pub const init = z.init;
|
||||
pub const allocInit = z.allocInit;
|
||||
// Internal - Used by the .zx -> .zig transpiler
|
||||
pub const x = @import("x.zig");
|
||||
|
||||
pub const routes = @import("zx_meta").routes;
|
||||
pub const components = @import("zx_meta").components.components;
|
||||
@ -43,14 +39,12 @@ pub const info = @import("zx_info");
|
||||
pub const Allocator = std.mem.Allocator;
|
||||
pub const log = std.log;
|
||||
|
||||
// TODO: Legacy, should be removed
|
||||
pub const Server = app_module.Server;
|
||||
pub const Edge = @import("runtime/server/wasm/entrypoint.zig");
|
||||
pub const Client = @import("runtime/client/Client.zig");
|
||||
|
||||
const app_mod = @import("App.zig");
|
||||
pub const App = app_mod.App;
|
||||
pub const AppConfig = app_mod.Config;
|
||||
pub const allocator = app_mod.allocator;
|
||||
|
||||
// --- Namespaces --- //
|
||||
pub const client = @import("runtime/client.zig");
|
||||
@ -92,8 +86,6 @@ pub const StateHandle = @import("runtime/core/Event.zig").StateHandle;
|
||||
|
||||
pub const BuiltinAttribute = @import("attributes.zig").builtin;
|
||||
pub const Platform = plfm.Platform;
|
||||
pub const Os = plfm.Os;
|
||||
pub const Role = plfm.Role;
|
||||
|
||||
// --- Routing --- //
|
||||
pub const Router = @import("runtime/core/Router.zig");
|
||||
@ -112,6 +104,7 @@ pub const Socket = routing.Socket;
|
||||
pub const fetch = Fetch.fetch;
|
||||
|
||||
// --- Values --- //
|
||||
pub const allocator = app_mod.allocator;
|
||||
pub const platform: Platform = plfm.platform;
|
||||
pub const std_options: std.Options = opts.std_options;
|
||||
|
||||
|
||||
@ -1,33 +1,18 @@
|
||||
//! MDN Web API compliant Headers abstraction.
|
||||
//! This module is backend-agnostic. The actual implementation is provided via vtable.
|
||||
//! https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
||||
|
||||
const std = @import("std");
|
||||
const common = @import("common.zig");
|
||||
|
||||
pub const Headers = @This();
|
||||
|
||||
// Re-export types from std.http
|
||||
pub const Header = common.Header;
|
||||
/// @deprecated Use `Header` instead.
|
||||
pub const Entry = Header;
|
||||
|
||||
/// HTTP header iterator for parsing raw header bytes.
|
||||
/// Re-exported from std.http.HeaderIterator for convenience.
|
||||
///
|
||||
/// This is useful when you have raw HTTP protocol bytes and need to parse headers.
|
||||
/// For iterating over headers from a backend, use the `entries()` method which
|
||||
/// returns the vtable-based `Iterator`.
|
||||
///
|
||||
/// [Zig std.http Reference](https://ziglang.org/documentation/master/std/#std.http.HeaderIterator)
|
||||
pub const HeaderIterator = std.http.HeaderIterator;
|
||||
|
||||
// --- Headers Data --- //
|
||||
|
||||
/// Backend-specific context pointer (null for WASM/client-side)
|
||||
backend_ctx: ?*anyopaque = null,
|
||||
|
||||
/// VTable for backend-specific operations
|
||||
vtable: ?*const VTable = null,
|
||||
|
||||
/// Whether this Headers instance is read-only (from request)
|
||||
@ -69,6 +54,7 @@ pub fn has(self: *const Headers, name: []const u8) bool {
|
||||
}
|
||||
|
||||
/// Appends a new value onto an existing header (response only, no-op for request).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/Headers/append
|
||||
pub fn append(self: *Headers, name: []const u8, value: []const u8) void {
|
||||
if (self.read_only) return;
|
||||
@ -80,6 +66,7 @@ pub fn append(self: *Headers, name: []const u8, value: []const u8) void {
|
||||
}
|
||||
|
||||
/// Sets a header value (response only, no-op for request).
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/Headers/set
|
||||
pub fn set(self: *Headers, name: []const u8, value: []const u8) void {
|
||||
if (self.read_only) return;
|
||||
@ -91,6 +78,7 @@ pub fn set(self: *Headers, name: []const u8, value: []const u8) void {
|
||||
}
|
||||
|
||||
/// Deletes a header. Note: Most backends don't support header deletion.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete
|
||||
pub fn delete(self: *Headers, name: []const u8) void {
|
||||
_ = self;
|
||||
@ -109,6 +97,7 @@ pub fn entries(self: *const Headers) ?Iterator {
|
||||
}
|
||||
|
||||
/// Executes a provided function once for each header.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach
|
||||
pub fn forEach(self: *const Headers, callback: *const fn (value: []const u8, key: []const u8) void) void {
|
||||
if (self.entries()) |*iter| {
|
||||
@ -119,18 +108,6 @@ pub fn forEach(self: *const Headers, callback: *const fn (value: []const u8, key
|
||||
}
|
||||
}
|
||||
|
||||
// --- Iterator (vtable-based, for backend abstraction) --- //
|
||||
|
||||
/// Backend-agnostic iterator for iterating over headers.
|
||||
///
|
||||
/// Example:
|
||||
/// ```zig
|
||||
/// if (headers.entries()) |*iter| {
|
||||
/// while (iter.next()) |header| {
|
||||
/// std.debug.print("{s}: {s}\n", .{ header.name, header.value });
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub const Iterator = struct {
|
||||
backend_ctx: ?*anyopaque = null,
|
||||
nextFn: ?*const fn (ctx: *anyopaque) ?Header = null,
|
||||
|
||||
@ -26,7 +26,7 @@ pub const ComponentClientOptions = struct {
|
||||
id: []const u8,
|
||||
};
|
||||
|
||||
const ZxOptions = struct {
|
||||
const Options = struct {
|
||||
children: ?[]const Component = null,
|
||||
attributes: ?[]const Element.Attribute = null,
|
||||
allocator: ?std.mem.Allocator = null,
|
||||
@ -41,25 +41,17 @@ const ZxOptions = struct {
|
||||
name: ?[]const u8 = null,
|
||||
};
|
||||
|
||||
/// Initialize a ZxContext without an allocator
|
||||
/// Initialize a Context without an allocator
|
||||
/// The allocator must be provided via @allocator attribute on the parent element
|
||||
pub fn init() ZxContext {
|
||||
pub fn init() Context {
|
||||
return .{ .allocator = std.heap.page_allocator };
|
||||
}
|
||||
|
||||
/// Initialize a ZxContext with an allocator (for backward compatibility with direct API usage)
|
||||
pub fn allocInit(allocator: std.mem.Allocator) ZxContext {
|
||||
/// Initialize a Context with an allocator (for backward compatibility with direct API usage)
|
||||
pub fn allocInit(allocator: std.mem.Allocator) Context {
|
||||
return .{ .allocator = allocator };
|
||||
}
|
||||
|
||||
pub fn x(tag: ElementTag, options: ZxOptions) Component {
|
||||
return .{ .element = .{
|
||||
.tag = tag,
|
||||
.children = options.children,
|
||||
.attributes = options.attributes,
|
||||
} };
|
||||
}
|
||||
|
||||
/// Create a lazy component from a function
|
||||
/// The function will be invoked during rendering, allowing for dynamic slot handling
|
||||
/// Supports functions with 0 params (), 1 param (allocator), or 2 params (allocator, props)
|
||||
@ -68,14 +60,14 @@ pub fn lazy(allocator: Allocator, comptime func: anytype, props: anytype) Compon
|
||||
}
|
||||
|
||||
/// Context for creating components with allocator support
|
||||
pub const ZxContext = struct {
|
||||
const Context = struct {
|
||||
allocator: ?std.mem.Allocator = null,
|
||||
|
||||
pub fn getAlloc(self: *ZxContext) std.mem.Allocator {
|
||||
pub fn getAlloc(self: *Context) std.mem.Allocator {
|
||||
return self.allocator orelse @panic("Allocator not set. Please provide @allocator attribute to the parent element.");
|
||||
}
|
||||
|
||||
fn escapeHtml(self: *ZxContext, text: []const u8) []const u8 {
|
||||
fn escapeHtml(self: *Context, text: []const u8) []const u8 {
|
||||
// On browser, DOM APIs (textContent) handle escaping automatically
|
||||
// We only need to escape when generating HTML strings on the server
|
||||
// TODO: we would want to move the escaping logic at the time of rendering the element, and simply not use escapeHtml for client side rendering
|
||||
@ -90,7 +82,7 @@ pub const ZxContext = struct {
|
||||
return allocator.dupe(u8, aw.written()) catch @panic("OOM");
|
||||
}
|
||||
|
||||
pub fn ele(self: *ZxContext, tag: ElementTag, options: ZxOptions) Component {
|
||||
pub fn ele(self: *Context, tag: ElementTag, options: Options) Component {
|
||||
// Set allocator from @allocator option if provided
|
||||
if (options.allocator) |allocator| {
|
||||
self.allocator = allocator;
|
||||
@ -123,12 +115,12 @@ pub const ZxContext = struct {
|
||||
} };
|
||||
}
|
||||
|
||||
pub fn txt(self: *ZxContext, text: []const u8) Component {
|
||||
pub fn txt(self: *Context, text: []const u8) Component {
|
||||
const escaped = self.escapeHtml(text);
|
||||
return .{ .text = escaped };
|
||||
}
|
||||
|
||||
pub fn expr(self: *ZxContext, val: anytype) Component {
|
||||
pub fn expr(self: *Context, val: anytype) Component {
|
||||
const T = @TypeOf(val);
|
||||
|
||||
if (T == Component) return val;
|
||||
@ -209,13 +201,13 @@ pub const ZxContext = struct {
|
||||
return Cmp;
|
||||
}
|
||||
|
||||
pub fn fmt(self: *ZxContext, comptime format: []const u8, args: anytype) Component {
|
||||
pub fn fmt(self: *Context, comptime format: []const u8, args: anytype) Component {
|
||||
const allocator = self.getAlloc();
|
||||
const text = std.fmt.allocPrint(allocator, format, args) catch @panic("OOM");
|
||||
return .{ .text = text };
|
||||
}
|
||||
|
||||
pub fn printf(self: *ZxContext, comptime format: []const u8, args: anytype) []const u8 {
|
||||
pub fn printf(self: *Context, comptime format: []const u8, args: anytype) []const u8 {
|
||||
const allocator = self.getAlloc();
|
||||
const text = std.fmt.allocPrint(allocator, format, args) catch @panic("OOM");
|
||||
return text;
|
||||
@ -223,7 +215,7 @@ pub const ZxContext = struct {
|
||||
|
||||
/// Create an attribute with type-aware value handling
|
||||
/// Returns null for values that should omit the attribute (false booleans, null optionals)
|
||||
pub fn attr(self: *ZxContext, comptime name: []const u8, val: anytype) ?Element.Attribute {
|
||||
pub fn attr(self: *Context, comptime name: []const u8, val: anytype) ?Element.Attribute {
|
||||
const T = @TypeOf(val);
|
||||
|
||||
if (comptime isStatePointer(T)) {
|
||||
@ -314,13 +306,13 @@ pub const ZxContext = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn attrf(self: *ZxContext, comptime name: []const u8, comptime format: []const u8, args: anytype) ?Element.Attribute {
|
||||
pub fn attrf(self: *Context, comptime name: []const u8, comptime format: []const u8, args: anytype) ?Element.Attribute {
|
||||
const allocator = self.getAlloc();
|
||||
const text = std.fmt.allocPrint(allocator, format, args) catch @panic("OOM");
|
||||
return self.attr(name, text);
|
||||
}
|
||||
|
||||
pub fn attrv(self: *ZxContext, val: anytype) []const u8 {
|
||||
pub fn attrv(self: *Context, val: anytype) []const u8 {
|
||||
const attrkv = self.attr("f", val);
|
||||
if (attrkv) |a| {
|
||||
return a.value orelse "";
|
||||
@ -328,14 +320,14 @@ pub const ZxContext = struct {
|
||||
return "";
|
||||
}
|
||||
|
||||
pub fn propf(self: *ZxContext, comptime format: []const u8, args: anytype) []const u8 {
|
||||
pub fn propf(self: *Context, comptime format: []const u8, args: anytype) []const u8 {
|
||||
const allocator = self.getAlloc();
|
||||
return std.fmt.allocPrint(allocator, format, args) catch @panic("OOM");
|
||||
}
|
||||
pub const propv = attrv;
|
||||
|
||||
/// Filter and collect non-null attributes into a slice
|
||||
pub fn attrs(self: *ZxContext, inputs: anytype) []const Element.Attribute {
|
||||
pub fn attrs(self: *Context, inputs: anytype) []const Element.Attribute {
|
||||
const allocator = self.getAlloc();
|
||||
const InputType = @TypeOf(inputs);
|
||||
const input_info = @typeInfo(InputType);
|
||||
@ -376,7 +368,7 @@ pub const ZxContext = struct {
|
||||
|
||||
/// Spread a struct's fields as attributes
|
||||
/// Takes a struct and returns a slice of attributes for each field
|
||||
pub fn attrSpr(self: *ZxContext, props: anytype) []const ?Element.Attribute {
|
||||
pub fn attrSpr(self: *Context, props: anytype) []const ?Element.Attribute {
|
||||
const allocator = self.getAlloc();
|
||||
const T = @TypeOf(props);
|
||||
const type_info = @typeInfo(T);
|
||||
@ -400,7 +392,7 @@ pub const ZxContext = struct {
|
||||
|
||||
/// Merge two structs for component props spreading
|
||||
/// Later fields override earlier ones
|
||||
pub fn propsM(_: *ZxContext, base: anytype, overrides: anytype) prp.MergedPropsType(@TypeOf(base), @TypeOf(overrides)) {
|
||||
pub fn propsM(_: *Context, base: anytype, overrides: anytype) prp.MergedPropsType(@TypeOf(base), @TypeOf(overrides)) {
|
||||
const BaseType = @TypeOf(base);
|
||||
const OverrideType = @TypeOf(overrides);
|
||||
const ResultType = prp.MergedPropsType(BaseType, OverrideType);
|
||||
@ -433,7 +425,7 @@ pub const ZxContext = struct {
|
||||
/// - ?Element.Attribute (single attribute from attr())
|
||||
/// - []const ?Element.Attribute (slice from attrSpr())
|
||||
/// Later attributes with the same name override earlier ones (like JSX)
|
||||
pub fn attrsM(self: *ZxContext, inputs: anytype) []const Element.Attribute {
|
||||
pub fn attrsM(self: *Context, inputs: anytype) []const Element.Attribute {
|
||||
const allocator = self.getAlloc();
|
||||
const InputType = @TypeOf(inputs);
|
||||
const input_info = @typeInfo(InputType);
|
||||
@ -519,7 +511,7 @@ pub const ZxContext = struct {
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn cmp(self: *ZxContext, comptime func: anytype, options: ZxOptions, props: anytype) Component {
|
||||
pub fn cmp(self: *Context, comptime func: anytype, options: Options, props: anytype) Component {
|
||||
const allocator = self.getAlloc();
|
||||
|
||||
const FuncInfo = @typeInfo(@TypeOf(func));
|
||||
@ -600,7 +592,7 @@ pub const ZxContext = struct {
|
||||
}
|
||||
|
||||
/// Allocates a Component and returns a pointer to it (used for @fallback)
|
||||
pub fn ptr(self: *ZxContext, component: Component) *const Component {
|
||||
pub fn ptr(self: *Context, component: Component) *const Component {
|
||||
const allocator = self.getAlloc();
|
||||
const allocated = allocator.create(Component) catch @panic("OOM");
|
||||
allocated.* = component;
|
||||
@ -609,7 +601,7 @@ pub const ZxContext = struct {
|
||||
|
||||
/// Creates a React client-side rendered component.
|
||||
/// Uses JSON serialization for props to match React's expected format.
|
||||
pub fn client(self: *ZxContext, options: ClientComponentOptions, props: anytype) Component {
|
||||
pub fn client(self: *Context, options: ClientComponentOptions, props: anytype) Component {
|
||||
const allocator = self.getAlloc();
|
||||
const Props = @TypeOf(props);
|
||||
|
||||
@ -30,7 +30,7 @@ test "in Component" {
|
||||
defer arena.deinit();
|
||||
const arena_allocator = arena.allocator();
|
||||
|
||||
var ctx = zx.allocInit(arena_allocator);
|
||||
var ctx = zx.x.allocInit(arena_allocator);
|
||||
|
||||
const style: S = .{
|
||||
.color = .hex(0x0000ff),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const a = allocator;
|
||||
var _zx = @import("zx").allocInit(a);
|
||||
var _zx = @import("zx").x.allocInit(a);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
@ -22,7 +22,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
fn ArgToBuiltin(arena: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(arena);
|
||||
var _zx = @import("zx").x.allocInit(arena);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
@ -34,7 +34,7 @@ fn ArgToBuiltin(arena: zx.Allocator) zx.Component {
|
||||
const Props = struct { c: zx.Allocator };
|
||||
fn StructToBuiltin(a: zx.Allocator) zx.Component {
|
||||
const props = Props{ .c = a };
|
||||
var _zx = @import("zx").allocInit(props.c);
|
||||
var _zx = @import("zx").x.allocInit(props.c);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const hello_child = _zx_ele_blk_0: {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
break :_zx_ele_blk_0 _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -11,7 +11,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
},
|
||||
);
|
||||
};
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
@ -42,7 +42,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
// Note: Not providing allocator here will use the default allocator (std.heap.page_allocator) and will have performance penalty
|
||||
// Only use this when you need to create a component that doesn't need to allocate memory, like a complete static element.
|
||||
const hello_child_outside = _zx_ele_blk_1: {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
break :_zx_ele_blk_1 _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -55,7 +55,7 @@ const hello_child_outside = _zx_ele_blk_1: {
|
||||
|
||||
const Props = struct { children: zx.Component };
|
||||
pub fn ChildComponent(allocator: zx.Allocator, props: Props) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_active = true;
|
||||
const id = "main-content";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.fragment,
|
||||
.{
|
||||
|
||||
58
test/data/attribute/multiline.zig
Normal file
58
test/data/attribute/multiline.zig
Normal file
@ -0,0 +1,58 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const class_name = "container";
|
||||
const is_active = true;
|
||||
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.section,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("class", class_name),
|
||||
_zx.attr("id", "main"),
|
||||
_zx.attr("data-active", is_active),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.p,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("Multiline attributes"),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.input,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("type", "text"),
|
||||
_zx.attr("class", "input"),
|
||||
_zx.attr("placeholder", "Enter text"),
|
||||
}),
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.button,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("class", "btn"),
|
||||
_zx.attr("id", "submit"),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.txt("Submit"),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
45
test/data/attribute/multiline_normalize.zig
Normal file
45
test/data/attribute/multiline_normalize.zig
Normal file
@ -0,0 +1,45 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const class_name = "container";
|
||||
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.section,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("class", class_name),
|
||||
_zx.attr("id", "main"),
|
||||
_zx.attr("data-active", "true"),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.p,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("Messy indentation"),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.input,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("type", "text"),
|
||||
_zx.attr("class", "input"),
|
||||
_zx.attr("placeholder", "Enter text"),
|
||||
}),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
45
test/data/attribute/multiline_normalize_out.zig
Normal file
45
test/data/attribute/multiline_normalize_out.zig
Normal file
@ -0,0 +1,45 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const class_name = "container";
|
||||
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.section,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("class", class_name),
|
||||
_zx.attr("id", "main"),
|
||||
_zx.attr("data-active", "true"),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.ele(
|
||||
.p,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("Messy indentation"),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.input,
|
||||
.{
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("type", "text"),
|
||||
_zx.attr("class", "input"),
|
||||
_zx.attr("placeholder", "Enter text"),
|
||||
}),
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const value: i32 = 42;
|
||||
const class = "b-1 bold";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.form,
|
||||
.{
|
||||
|
||||
@ -9,7 +9,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
.value = "test@example.com",
|
||||
};
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.form,
|
||||
.{
|
||||
@ -35,7 +35,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const InputProps = struct { value: []const u8, name: []const u8, extra: []const u8 = "" };
|
||||
fn Input(ctx: *zx.ComponentCtx(InputProps)) zx.Component {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -9,7 +9,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const optional_null: ?[]const u8 = null;
|
||||
const enum_val = InputType.text;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.form,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -17,7 +17,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const ButtonProps = struct { title: []const u8 };
|
||||
pub fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -22,7 +22,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const ButtonProps = struct { title: []const u8 };
|
||||
pub fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -48,7 +48,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const WrapperProps = struct { children: zx.Component };
|
||||
fn Wrapper(allocator: zx.Allocator, props: WrapperProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -65,7 +65,7 @@ fn Wrapper(allocator: zx.Allocator, props: WrapperProps) zx.Component {
|
||||
|
||||
const ContainerProps = struct { children: zx.Component };
|
||||
fn Container(allocator: zx.Allocator, props: ContainerProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -40,7 +40,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
/// Component using ComponentContext (void props, children only)
|
||||
pub fn Wrapper(ctx: *zx.ComponentContext) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -57,7 +57,7 @@ pub fn Wrapper(ctx: *zx.ComponentContext) zx.Component {
|
||||
|
||||
/// Another component using ComponentContext
|
||||
fn Card(ctx: *zx.ComponentContext) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.article,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -37,7 +37,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
/// Component using ComponentCtx with props (no children)
|
||||
const ButtonProps = struct { title: []const u8 };
|
||||
pub fn Button(ctx: *zx.ComponentCtx(ButtonProps)) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
@ -55,7 +55,7 @@ pub fn Button(ctx: *zx.ComponentCtx(ButtonProps)) zx.Component {
|
||||
/// Component with multiple props
|
||||
const AlertProps = struct { message: []const u8, level: []const u8 };
|
||||
fn Alert(ctx: *zx.ComponentCtx(AlertProps)) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -74,7 +74,7 @@ fn Alert(ctx: *zx.ComponentCtx(AlertProps)) zx.Component {
|
||||
/// Component with props AND children
|
||||
const PanelProps = struct { title: []const u8 };
|
||||
fn Panel(ctx: *zx.ComponentCtx(PanelProps)) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const max_count = 10;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -26,7 +26,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
pub fn CounterComponent(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/// Test: CSR Zig component with props passed from server to client
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -28,7 +28,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const CounterProps = struct { initial: i32 = 0, label: []const u8 = "Count" };
|
||||
pub fn Counter(ctx: *zx.ComponentCtx(CounterProps)) zx.Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/// Test: Components with error union return type (!Component)
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -25,7 +25,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const FallibleProps = struct { success: bool };
|
||||
pub fn Fallible(allocator: zx.Allocator, props: FallibleProps) !zx.Component {
|
||||
if (!props.success) return error.TestError;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -40,7 +40,7 @@ pub fn Fallible(allocator: zx.Allocator, props: FallibleProps) !zx.Component {
|
||||
/// Error union with ComponentCtx signature
|
||||
pub fn FallibleCtx(ctx: *zx.ComponentCtx(FallibleProps)) !zx.Component {
|
||||
if (!ctx.props.success) return error.TestError;
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: z.Allocator) z.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -37,7 +37,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const ButtonProps = struct { title: []const u8 };
|
||||
fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
@ -51,7 +51,7 @@ fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
|
||||
const AsyncScoreProps = struct { index: u64, label: []const u8 };
|
||||
fn AsyncScore(allocator: zx.Allocator, props: AsyncScoreProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.span,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -18,7 +18,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const components = struct {
|
||||
const ButtonProps = struct { title: []const u8 };
|
||||
pub fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -23,7 +23,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
const CardProps = struct { title: []const u8, children: zx.Component };
|
||||
fn Card(allocator: zx.Allocator, props: CardProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -61,7 +61,7 @@ fn Card(allocator: zx.Allocator, props: CardProps) zx.Component {
|
||||
|
||||
const ButtonProps = struct { label: []const u8 };
|
||||
fn Button(allocator: zx.Allocator, props: ButtonProps) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/// Test: Components with error union of optional return type (!?Component)
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -25,7 +25,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const MaybeProps = struct { show: bool };
|
||||
pub fn MaybeContent(ctx: *zx.ComponentCtx(MaybeProps)) !?zx.Component {
|
||||
if (!ctx.props.show) return null;
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const max_count = 10;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.cmp(
|
||||
Button,
|
||||
.{ .name = "Button" },
|
||||
@ -8,7 +8,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
pub fn Button(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.button,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_names = [_][]const u8{ "John", "Jane", "Jim", "Jill" };
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -26,7 +26,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
pub fn StructCapture(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -54,7 +54,7 @@ pub fn StructCapture(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
pub fn StructExtraCapture(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -85,7 +85,7 @@ pub fn StructExtraCapture(allocator: zx.Allocator) zx.Component {
|
||||
|
||||
pub fn StructComplexParam(allocator: zx.Allocator) zx.Component {
|
||||
const data = .{ .users = users };
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -139,7 +139,7 @@ fn getUsers() [users.len]User {
|
||||
}
|
||||
|
||||
pub fn StructCaptureToComponent(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
@ -170,7 +170,7 @@ const users = [_]User{
|
||||
};
|
||||
|
||||
fn UserComponent(allocator: zx.Allocator, props: User) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.p,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const chars = "ABC";
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
.{ .name = "Team A", .members = &[_][]const u8{ "John", "Jane" } },
|
||||
.{ .name = "Team B", .members = &[_][]const u8{ "Jim", "Jill" } },
|
||||
};
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -4,7 +4,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
.{ .name = "Jane", .is_active = false },
|
||||
.{ .name = "Jim", .is_active = true },
|
||||
};
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -4,7 +4,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
.{ .name = "Jane", .role = .member },
|
||||
.{ .name = "Jim", .role = .guest },
|
||||
};
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const groups = [_][]const u8{ "A", "B" };
|
||||
var j: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = false;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = false;
|
||||
const user_name = if (is_logged_in) "zx" else null;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -6,7 +6,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_trial = false;
|
||||
const is_guest = false;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user = "John Doe";
|
||||
const user_empty = "";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const show_users = true;
|
||||
const user_names = [_][]const u8{ "John", "Jane", "Jim", "Jill" };
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const show_list = true;
|
||||
const items = [_][]const u8{ "Apple", "Banana", "Cherry" };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = true;
|
||||
const is_premium = false;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = true;
|
||||
const is_premium = true;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = true;
|
||||
const is_premium = true;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = false;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const is_logged_in = true;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const show_user_type = true;
|
||||
const user_type: UserType = .admin;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const show_list = true;
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const items = [_][]const u8{ "Apple", "Banana", "Cherry" };
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_type: UserType = .admin;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_type: UserType = .admin;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const admin_user: User = .{ .admin = .{ .level = 5 } };
|
||||
const member_user: User = .{ .member = .{ .points = 150 } };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const chars = "abcdefg";
|
||||
const char = chars[0];
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_type: UserType = .admin;
|
||||
const admin_users = [_][]const u8{ "John", "Jane" };
|
||||
const member_users = [_][]const u8{ "Jim", "Jill" };
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_type: UserType = .admin;
|
||||
const is_active = true;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const u: User = .{ .member = .{ .points = 150 } };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user_type: UserType = .admin;
|
||||
const status: Status = .inactive;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const mode: Mode = .repeat;
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var iter = getIterator();
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var iter = getIterator();
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var iter = getIterator();
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
const items = [_][]const u8{ "a", "b" };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var i: usize = 0;
|
||||
var j: usize = 0;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.fragment,
|
||||
.{
|
||||
@ -16,7 +16,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
fn FragmentComponent(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.fragment,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
@ -13,7 +13,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
}
|
||||
|
||||
pub fn Comments(_: zx.ComponentContext) zx.Component {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -30,7 +30,7 @@ pub fn Comments(_: zx.ComponentContext) zx.Component {
|
||||
}
|
||||
|
||||
pub fn EmptyComments(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -49,7 +49,7 @@ pub fn EmptyComments(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn CommentsWithSpecialChars(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -69,7 +69,7 @@ pub fn CommentsWithSpecialChars(_: zx.ComponentContext) zx.Element {
|
||||
|
||||
pub fn CommentsWithExpressions(_: zx.ComponentContext) zx.Element {
|
||||
const value = "test";
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -91,7 +91,7 @@ pub fn CommentsWithExpressions(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn NestedComments(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -124,7 +124,7 @@ pub fn NestedComments(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn CommentsWithAttributes(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -143,7 +143,7 @@ pub fn CommentsWithAttributes(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn MixedCommentsAndContent(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.ul,
|
||||
.{
|
||||
@ -178,7 +178,7 @@ pub fn MixedCommentsAndContent(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn CommentsWithZigCode(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -197,7 +197,7 @@ pub fn CommentsWithZigCode(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn CommentsOnlyComponent(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
@ -207,7 +207,7 @@ pub fn CommentsOnlyComponent(_: zx.ComponentContext) zx.Element {
|
||||
}
|
||||
|
||||
pub fn CommentsBetweenSiblings(_: zx.ComponentContext) zx.Element {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const greeting = zx.Component{ .text = "Hello!" };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -15,7 +15,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
// persons[0] = person;
|
||||
// persons[1] = person;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const items = [_][]const u8{ "apple", "banana", "cherry" };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const count = 5;
|
||||
const item = "apple";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const maybe_name: ?[]const u8 = "Alice";
|
||||
const no_name: ?[]const u8 = null;
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const user = User{ .name = "Alice", .age = 25 };
|
||||
const product = Product{ .title = "Book", .price = 29.99 };
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -2,7 +2,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const count = 42;
|
||||
const name = "John";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.section,
|
||||
.{
|
||||
@ -44,7 +44,7 @@ fn Component(ctx: *zx.ComponentCtx(struct {
|
||||
text: []const u8,
|
||||
name: []const u8,
|
||||
})) zx.Component {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -3,7 +3,7 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const html_content = "<script>alert('XSS')</script>";
|
||||
const unsafe_html = "<span>Test</span>";
|
||||
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.main,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Collection(allocator: zx.Allocator, props: anytype) zx.Component {
|
||||
const cards = props.cards;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pub fn Collection(allocator: zx.Allocator, props: anytype) zx.Component {
|
||||
const cards = props.cards;
|
||||
var _zx = @import("zx").allocInit(allocator);
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn FmtWhitespace(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn FmtWhitespace(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").init();
|
||||
var _zx = @import("zx").x.init();
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
pub fn _zx_md(ctx: *@import("zx").ComponentCtx(struct { children: @import("zx").Component })) @import("zx").Component {
|
||||
var _zx = @import("zx").allocInit(ctx.allocator);
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.h1,
|
||||
.{
|
||||
|
||||
83
test/data/mdzx/page.zig
Normal file
83
test/data/mdzx/page.zig
Normal file
@ -0,0 +1,83 @@
|
||||
const zx = @import("zx");
|
||||
const std = @import("std");
|
||||
const Lightning = @import("site/pages/components/icons.zig").Lightning;
|
||||
pub const meta = .{
|
||||
.title = "The Ultimate MDZX Test Suite",
|
||||
.version = "0.1.0",
|
||||
.tags = .{ "test", "markdown", "zig" },
|
||||
.draft = false,
|
||||
};
|
||||
pub const options: zx.PageOptions = .{};
|
||||
|
||||
pub fn _zx_md(ctx: *@import("zx").ComponentCtx(struct { children: @import("zx").Component })) @import("zx").Component {
|
||||
var _zx = @import("zx").x.allocInit(ctx.allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = ctx.allocator,
|
||||
.children = &.{
|
||||
_zx.cmp(
|
||||
Lightning,
|
||||
.{ .name = "Lightning" },
|
||||
.{ .class = "w-6 h-6 text-yellow-500" },
|
||||
),
|
||||
_zx.ele(
|
||||
.h1,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("1. Headers & Formatting"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h1,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H1 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h2,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H2 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h3,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H3 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h4,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H4 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h5,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H5 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
_zx.ele(
|
||||
.h6,
|
||||
.{
|
||||
.children = &.{
|
||||
_zx.txt("H6 Header"),
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
21
test/data/style/basic.zig
Normal file
21
test/data/style/basic.zig
Normal file
@ -0,0 +1,21 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const style: zx.Style = .{
|
||||
.display = .flex,
|
||||
.background_color = .hex(0xff0000),
|
||||
};
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("style", style),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.txt(" Hello"),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
23
test/data/style/component.zig
Normal file
23
test/data/style/component.zig
Normal file
@ -0,0 +1,23 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
const style: zx.Style = .{
|
||||
.display = .flex,
|
||||
.flex_direction = .column,
|
||||
.padding_top = .px(10),
|
||||
.width = .px(100),
|
||||
};
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("style", style),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.txt(" Hello"),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
17
test/data/style/inline.zig
Normal file
17
test/data/style/inline.zig
Normal file
@ -0,0 +1,17 @@
|
||||
pub fn Page(allocator: zx.Allocator) zx.Component {
|
||||
var _zx = @import("zx").x.allocInit(allocator);
|
||||
return _zx.ele(
|
||||
.div,
|
||||
.{
|
||||
.allocator = allocator,
|
||||
.attributes = _zx.attrs(.{
|
||||
_zx.attr("style", .{ .display = .flex, .padding_top = .px(10), .width = .px(100) }),
|
||||
}),
|
||||
.children = &.{
|
||||
_zx.txt(" Hello"),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const zx = @import("zx");
|
||||
Loading…
x
Reference in New Issue
Block a user