KeshavSoft Declarative UI 100% Headless Compiler Pure Functions

Turn Plain JSON Data into Declarative UI Blueprints

json-renderers-build json-renderers-build is a headless specification compiler in the KeshavSoft declarative UI ecosystem. It accepts a component type, data, and columns, then returns a JSON description of the requested UI. It does not create live DOM elements.

💡 Crucial concept: This repository does not touch the browser screen directly. It creates the clean architectural blueprint. Then downstream tools (@keshavsoft/json-to-tag and json-renderers) turn that blueprint into real clickable HTML elements and mount them to your page.

⚡ Quick Architectural Snapshot

  • ✓
    Zero DOM mutations: Runs anywhere: Node.js server, Web Worker, or Browser.
  • ✓
    6 Built-in Blueprints: Table, Vertical Form, Search Input, Select, Options Only, DataList.
  • ✓
    Pure & Deterministic: Same inputs always yield the identical specification AST.
  • ✓
    Automated Input Guards: Validates configurations and column shapes with informative errors.
Step-by-Step Architecture

How It Works in Simple Words

Think of building a house: you need an architect's blueprint before a builder pours concrete. In the KeshavSoft ecosystem, json-renderers-build is the architect.

1
Input Stage

Raw Data & Config

You provide plain JavaScript arrays or objects containing your business records and simple column definitions.

data: [ { name: "Alpha", city: "Hyd" } ]
columns: [ { columnName: "name" } ]
2
THIS REPOSITORY

json-renderers-build

Validates your inputs, selects the component blueprint, and compiles everything into a pure JSON specification AST (specAsJsonToDom).

⚡ 100% Headless: Does not touch the browser window, DOM nodes, or CSS directly.

3
Downstream Runtime

DOM & Mounting

@keshavsoft/json-to-tag takes the specification tree and creates real browser HTML elements (<table>, <form>), and json-renderers mounts them into your container.

target.replaceChildren(domElement);

📊 End-to-End Visual Dataflow

📋 1. Raw JSON Data Objects, strings, arrays
➔
⚙️ 2. json-renderers-build Compiles Spec Tree (AST)
➔
🌐 3. json-to-tag & Mounting Real live HTMLElement on page

🎯 Why not build the DOM directly here?

If a library mixes business data, layout logic, and browser DOM manipulation all in one place, you cannot run it on a Node.js server, inside a Web Worker, or in automated unit tests without loading heavy fake DOMs like jsdom.

By keeping json-renderers-build 100% headless, it runs anywhere JavaScript runs, executes in microseconds, and is completely free of DOM side-effects.

🛡️ Built-in Input Safety (Guard System)

Every request passes through an internal guard (guardFunc). It guarantees:

  • type is one of the supported components.
  • data is always an array.
  • For tables, each item in columns has a valid columnName and aligns with data row keys.
  • For forms, input field types are strictly checked against allowed HTML form field types.
Package Manifest Audit

What Dependencies Are Used & Why?

Every dependency in this repository has one clear, modular job. Here is the exact list from package.json explained in simple words.

Dependency Name Version Role in Simple Words Why Are We Using It?
json-renderers-build-table Component ^1.17.3 Table specification builder Generates full table specifications (<table>, <thead>, <tbody>, cells, widths) with Bootstrap styling so we don't have to handwrite repetitive table loops.
json-renderers-build-form Component ^1.1.0 Form specification builder Compiles a list of column definitions into complete vertical Bootstrap form layouts (labels, inputs, selects, textareas, checkboxes, submit buttons) with full accessibility attributes.
json-renderers-build-input-row Component ^1.1.0 Search & input row builder Provides 3 ready-made search input flavours (inputOnly, inputWithLabel, inputWithLabelButton) for standardized search and filter rows.
json-transformer-funcs Data Helper ^1.24.6 Array & collection transformer Provides the functional fromCollection() utility to map raw arrays of strings or objects into <option> blueprint nodes for select dropdowns and datalists without mutation.
json-to-spec Compiler ^32.1.3 Core AST compiler engine The foundational AST compilation engine in the KeshavSoft ecosystem. Merges declarative skeleton templates (skeleton.json) with dynamic data variables.
vite Dev Tool ^5.4.2 Bundler & Development server Bundles modular ES code from src/ into minified distribution files (docs/dist/v22/min.js) and provides local dev servers for live testing.
Component Builder src/v22/table/

1. json-renderers-build-table

What it does: Creates table specifications with columns, headers, rows, and buttons.

Why we use it: Instead of writing 100+ lines of loop code to build table headers, body rows, cell alignments, and Bootstrap table classes, we call its simple() function which returns a tested, standard table specification.

Component Builder src/v22/form/

2. json-renderers-build-form

What it does: Compiles schema definitions into vertical HTML forms.

Why we use it: Generates accessible form fields with proper labels, IDs, validation, input types (text, email, select, textarea), and submit buttons in one declarative call.

Component Builder src/v22/searchInput/

3. json-renderers-build-input-row

What it does: Generates flexible search boxes and input control rows.

Why we use it: Easily switch between standalone search boxes, labeled inputs, or inputs with attached search buttons without writing custom markup.

Data Helper src/v22/select/

4. json-transformer-funcs

What it does: Transforms collections and arrays into target formats.

Why we use it: When building select dropdowns, it takes an array of strings or objects and uses fromCollection() to map each item into an <option> specification cleanly without manual array mutation.

Compiler Core Engine

5. json-to-spec

What it does: Merges component templates with data to produce AST specs.

Why we use it: It provides the underlying template compiler engine that replaces template variables like ${columnName} and ${rowValue} inside component skeletons into completed JSON specification ASTs.

Dev Dependency vite.config.js

6. vite

What it does: Fast local build tool and development server.

Why we use it: Compiles and minifies the ES module files into single standalone script files in docs/dist/ (e.g., min.js) so developers can load the library via CDN or script tag without installing npm packages.

Interactive Demonstration

Live Component Playground

Select any component below to see the JavaScript input, compile the headless specification AST live in your browser, and view the mounted HTML element rendered via @keshavsoft/json-to-tag.

Table Specification Generates a full Bootstrap table specification tree with alternating rows and headers.
📂 Open Sample File

            
💡 What happens on click: 1. Calls render(config) from the compiled bundle.
2. Outputs the JSON specification tree AST.
3. Calls window.ks.jsonToTag.buildSpecElement(spec) to create the live DOM node and displays it in the preview box.
Click "Compile & Render" above to see the live output.
JSON-to-DOM Specification AST
// Spec will appear here...
Repository Samples

Sample Folder Overview

The samples/ directory contains working implementations testing different component types and real-world integration patterns.

Table Spec samples/table/

📊 Table Component Sample

Demonstrates generating a table with custom column widths, batch item records, and compiling via type: "tableFromSpec".

Vertical Form samples/form/

📝 Vertical Form with Submit

Shows a column-driven Bootstrap form with name, email, role select, notes textarea, updates checkbox, and captures live form submit events.

Search Control samples/searchInput/

🔍 Search Input & Button

Tests search inputs with customizable labels, placeholders, input IDs, and attached search action buttons.

Dropdown samples/select/

🔽 Standalone Select Dropdown

Creates a full <select> element AST populated with <option> tags from an array of strings.

Fragment samples/selectOptionsOnly/

⚡ Options Only Fragment

Useful when you already have an existing <select> in HTML and only need to generate the dynamic <option> children to append to it.

Interactive samples/v4/

🪟 Modal Dialog on Row Click

Advanced demonstration where clicking an action button on a table row dynamically compiles and renders a child batches table inside a Bootstrap modal.

Developer Cheatsheet

Quick Start & Installation

Ready to use json-renderers-build in your project? Follow these quick steps.

1. Install via NPM

Install into your Node.js or bundler project:

npm install json-renderers-build

Use in ES module code:

import render from "json-renderers-build";

const spec = render({
  type: "table",
  columns: [{ columnName: "Name" }],
  data: [{ Name: "Acme Corp" }]
});

2. Load in Browser via CDN

Use directly in any HTML file without build tools:

<script type="module">
  import render from "https://cdn.jsdelivr.net/gh/keshavsoft/json-renderers-build@main/docs/dist/v22/min.js";
  import "https://keshavsoft.github.io/json-to-tag/dist/v9/min.js";

  const spec = render({
    type: "select",
    data: ["Retail", "Wholesale", "Export"]
  });

  const element = window.ks.jsonToTag.buildSpecElement(spec);
  document.getElementById("container").replaceChildren(element);
</script>