json-renderers 1.13.7 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +293 -272
- package/docs/aboutSelect.html +964 -0
- package/docs/aboutTable.html +12 -0
- package/docs/dist/min.js +1510 -702
- package/docs/dist/v13/min.js +796 -702
- package/docs/dist/v14/min.js +1063 -0
- package/docs/dist/v15/min.js +1510 -0
- package/docs/index.html +934 -679
- package/docs/select.html +161 -0
- package/docs/table/cdn.html +634 -0
- package/docs/table/index.html +607 -0
- package/docs/table/windowKs.html +332 -0
- package/docs/table/windowKsV1.html +647 -0
- package/docs/table.html +195 -0
- package/package.json +2 -2
- package/src/index.js +2 -2
- package/src/v13/buildSpec/index.js +7 -6
- package/src/v13/index.js +42 -19
- package/src/v14/buildSpec/index.js +39 -0
- package/src/v14/common/deriveColumnsFromData.js +20 -0
- package/src/v14/index.js +81 -0
- package/src/v14/meta.js +6 -0
- package/src/v14/registerGlobal.js +14 -0
- package/src/v15/buildSpec/index.js +39 -0
- package/src/v15/common/deriveColumnsFromData.js +20 -0
- package/src/v15/guard.js +35 -0
- package/src/v15/index.js +70 -0
- package/src/v15/meta.js +6 -0
- package/src/v15/registerGlobal.js +14 -0
- package/src/v16/buildSpec/index.js +40 -0
- package/src/v16/common/deriveColumnsFromData.js +20 -0
- package/src/v16/guard.js +38 -0
- package/src/v16/index.js +110 -0
- package/src/v16/meta.js +6 -0
- package/src/v16/registerGlobal.js +27 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>window.ks.jsonRenderers.renderToDom | json-renderers</title>
|
|
8
|
+
<meta name="description"
|
|
9
|
+
content="Simple guide explaining how window.ks.jsonRenderers.renderToDom works to build and render HTML tables from JSON data." />
|
|
10
|
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
11
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
12
|
+
<link
|
|
13
|
+
href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Inter:wght@300;400;500;600;700;800&display=swap"
|
|
14
|
+
rel="stylesheet" />
|
|
15
|
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
16
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
17
|
+
<style>
|
|
18
|
+
body {
|
|
19
|
+
font-family: 'Inter', sans-serif;
|
|
20
|
+
background-color: #f8fafc;
|
|
21
|
+
color: #1e293b;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pre,
|
|
25
|
+
code {
|
|
26
|
+
font-family: 'Fira Code', monospace;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* Style rendered table in demo container */
|
|
30
|
+
#dom-render-container table {
|
|
31
|
+
width: 100%;
|
|
32
|
+
margin-bottom: 0;
|
|
33
|
+
color: #1e293b;
|
|
34
|
+
border-collapse: separate;
|
|
35
|
+
border-spacing: 0;
|
|
36
|
+
border-radius: 0.75rem;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
border: 1px solid #e2e8f0;
|
|
39
|
+
background-color: #ffffff;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#dom-render-container th {
|
|
43
|
+
background: #f1f5f9;
|
|
44
|
+
color: #0f172a;
|
|
45
|
+
font-weight: 600;
|
|
46
|
+
padding: 0.75rem 1rem;
|
|
47
|
+
border-bottom: 2px solid #e2e8f0;
|
|
48
|
+
text-transform: capitalize;
|
|
49
|
+
font-size: 0.875rem;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#dom-render-container td {
|
|
53
|
+
padding: 0.65rem 1rem;
|
|
54
|
+
border-bottom: 1px solid #f1f5f9;
|
|
55
|
+
background: #ffffff;
|
|
56
|
+
font-size: 0.875rem;
|
|
57
|
+
color: #334155;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#dom-render-container tr:hover td {
|
|
61
|
+
background: #f8fafc;
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
</head>
|
|
65
|
+
|
|
66
|
+
<body class="min-h-screen flex flex-col antialiased">
|
|
67
|
+
|
|
68
|
+
<!-- Navigation Bar -->
|
|
69
|
+
<header class="border-b border-slate-200 bg-white/95 backdrop-blur sticky top-0 z-50">
|
|
70
|
+
<div class="max-w-5xl mx-auto px-4 sm:px-6 py-3.5 flex items-center justify-between gap-4">
|
|
71
|
+
<div class="flex items-center gap-3">
|
|
72
|
+
<a href="../index.html"
|
|
73
|
+
class="w-9 h-9 rounded-xl bg-gradient-to-br from-indigo-500 to-teal-600 flex items-center justify-center font-bold text-white shadow-sm text-base">
|
|
74
|
+
📊
|
|
75
|
+
</a>
|
|
76
|
+
<div>
|
|
77
|
+
<a href="../index.html"
|
|
78
|
+
class="text-sm font-bold text-slate-900 hover:text-indigo-600 transition">json-renderers</a>
|
|
79
|
+
<span class="text-xs text-slate-500 block">window.ks Guide</span>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<nav class="flex items-center gap-2 text-xs sm:text-sm">
|
|
84
|
+
<a href="../index.html"
|
|
85
|
+
class="px-3 py-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-700 transition">Home</a>
|
|
86
|
+
<a href="windowKs.html"
|
|
87
|
+
class="px-3 py-1.5 rounded-lg bg-indigo-600 text-white font-semibold transition">window.ks</a>
|
|
88
|
+
|
|
89
|
+
</nav>
|
|
90
|
+
</div>
|
|
91
|
+
</header>
|
|
92
|
+
|
|
93
|
+
<!-- Main Content -->
|
|
94
|
+
<main class="flex-1 max-w-5xl w-full mx-auto p-4 sm:p-6 lg:p-8 space-y-8">
|
|
95
|
+
|
|
96
|
+
<!-- Document Header -->
|
|
97
|
+
<section class="bg-white rounded-2xl p-6 sm:p-8 border border-slate-200 shadow-sm space-y-3">
|
|
98
|
+
<div
|
|
99
|
+
class="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-indigo-50 border border-indigo-200 text-xs font-mono text-indigo-700 font-medium">
|
|
100
|
+
Global Window Object Guide
|
|
101
|
+
</div>
|
|
102
|
+
<h1 class="text-2xl sm:text-3xl font-extrabold text-slate-900 tracking-tight">
|
|
103
|
+
Using <code class="text-indigo-600">window.ks.jsonRenderers.renderToDom</code>
|
|
104
|
+
</h1>
|
|
105
|
+
<p class="text-slate-600 text-sm sm:text-base leading-relaxed">
|
|
106
|
+
When you import the bundle, it attaches the <code
|
|
107
|
+
class="text-indigo-700 bg-indigo-50 px-1.5 py-0.5 rounded font-mono">ks</code> global object to <code
|
|
108
|
+
class="text-indigo-700 bg-indigo-50 px-1.5 py-0.5 rounded font-mono">window</code>. Inside this object, the
|
|
109
|
+
function <code
|
|
110
|
+
class="text-indigo-700 bg-indigo-50 px-1.5 py-0.5 rounded font-mono">window.ks.jsonRenderers.renderToDom</code>
|
|
111
|
+
is available to build and mount HTML tables into the DOM.
|
|
112
|
+
</p>
|
|
113
|
+
</section>
|
|
114
|
+
|
|
115
|
+
<!-- Global Object Explanation -->
|
|
116
|
+
<section class="bg-white rounded-2xl p-6 sm:p-8 border border-slate-200 shadow-sm space-y-4">
|
|
117
|
+
<h2 class="text-lg font-bold text-slate-900">How the Global Object is Structured</h2>
|
|
118
|
+
<p class="text-sm text-slate-600 leading-relaxed">
|
|
119
|
+
The bundle creates a nested namespace on the browser window:
|
|
120
|
+
</p>
|
|
121
|
+
|
|
122
|
+
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3 pt-1">
|
|
123
|
+
<div class="p-4 rounded-xl bg-slate-50 border border-slate-200 space-y-1">
|
|
124
|
+
<div class="font-mono font-bold text-indigo-600 text-sm">1. window.ks</div>
|
|
125
|
+
<p class="text-xs text-slate-600">The root global object attached directly to the browser <code
|
|
126
|
+
class="font-mono text-[11px]">window</code>.</p>
|
|
127
|
+
</div>
|
|
128
|
+
<div class="p-4 rounded-xl bg-slate-50 border border-slate-200 space-y-1">
|
|
129
|
+
<div class="font-mono font-bold text-indigo-600 text-sm">2. jsonRenderers</div>
|
|
130
|
+
<p class="text-xs text-slate-600">The module namespace object inside <code
|
|
131
|
+
class="font-mono text-[11px]">window.ks</code> containing render tools.</p>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="p-4 rounded-xl bg-slate-50 border border-slate-200 space-y-1">
|
|
134
|
+
<div class="font-mono font-bold text-indigo-600 text-sm">3. renderToDom()</div>
|
|
135
|
+
<p class="text-xs text-slate-600">The execution function that compiles your JSON and builds the table in the
|
|
136
|
+
target HTML element.</p>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div
|
|
141
|
+
class="p-3.5 rounded-xl bg-indigo-50/70 border border-indigo-100 font-mono text-xs text-indigo-900 flex items-center gap-2">
|
|
142
|
+
<span class="font-bold text-indigo-700">Hierarchy:</span>
|
|
143
|
+
<code>window → ks → jsonRenderers → renderToDom({ ... })</code>
|
|
144
|
+
</div>
|
|
145
|
+
</section>
|
|
146
|
+
|
|
147
|
+
<!-- Code Walkthrough -->
|
|
148
|
+
<section class="bg-white rounded-2xl p-6 sm:p-8 border border-slate-200 shadow-sm space-y-5">
|
|
149
|
+
<div class="flex items-center justify-between">
|
|
150
|
+
<div>
|
|
151
|
+
<h2 class="text-lg font-bold text-slate-900">Code to Build the Table</h2>
|
|
152
|
+
<p class="text-xs sm:text-sm text-slate-500">Import the bundle, load JSON data, and run <code
|
|
153
|
+
class="font-mono text-indigo-700">window.ks.jsonRenderers.renderToDom</code>.</p>
|
|
154
|
+
</div>
|
|
155
|
+
<button onclick="copyCode('code-block')"
|
|
156
|
+
class="text-xs px-3 py-1.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-700 font-mono transition flex items-center gap-1">
|
|
157
|
+
<span>📋</span> Copy
|
|
158
|
+
</button>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<pre
|
|
162
|
+
class="bg-slate-950 rounded-xl p-4 sm:p-5 text-xs text-slate-200 font-mono overflow-x-auto border border-slate-800 leading-relaxed"><code id="code-block">import "https://cdn.jsdelivr.net/gh/keshavsoft/json-renderers@main/docs/dist/v14/min.js";
|
|
163
|
+
|
|
164
|
+
import data from "./batches.json" with { type: "json" };
|
|
165
|
+
|
|
166
|
+
const start = () => {
|
|
167
|
+
try {
|
|
168
|
+
window.ks.jsonRenderers.renderToDom({
|
|
169
|
+
type: "table",
|
|
170
|
+
data: data.slice(0, 50),
|
|
171
|
+
targetHtmlId: "dom-render-container",
|
|
172
|
+
columns: ["itemName", "baseUnit"],
|
|
173
|
+
showLog: true
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.log("error : ", err);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
start();</code></pre>
|
|
182
|
+
|
|
183
|
+
<!-- Target HTML Element -->
|
|
184
|
+
<div class="pt-2 space-y-2">
|
|
185
|
+
<h3 class="text-xs font-bold text-slate-800 uppercase tracking-wider font-mono">HTML Target Container</h3>
|
|
186
|
+
<p class="text-xs text-slate-600">Ensure your HTML contains a container whose <code
|
|
187
|
+
class="text-indigo-700 font-mono">id</code> matches <code
|
|
188
|
+
class="text-indigo-700 font-mono">targetHtmlId</code>:</p>
|
|
189
|
+
<pre
|
|
190
|
+
class="bg-slate-900 rounded-xl p-3 text-xs text-indigo-200 font-mono overflow-x-auto border border-slate-800"><code><div id="dom-render-container"></div></code></pre>
|
|
191
|
+
</div>
|
|
192
|
+
</section>
|
|
193
|
+
|
|
194
|
+
<!-- Parameters Table -->
|
|
195
|
+
<section class="bg-white rounded-2xl p-6 sm:p-8 border border-slate-200 shadow-sm space-y-4">
|
|
196
|
+
<h2 class="text-lg font-bold text-slate-900">Options Passed to renderToDom</h2>
|
|
197
|
+
<div class="overflow-x-auto">
|
|
198
|
+
<table class="w-full text-left text-xs border border-slate-200 rounded-xl overflow-hidden">
|
|
199
|
+
<thead class="bg-slate-50 text-slate-700 font-mono uppercase border-b border-slate-200">
|
|
200
|
+
<tr>
|
|
201
|
+
<th class="px-4 py-3 font-semibold">Parameter</th>
|
|
202
|
+
<th class="px-4 py-3 font-semibold">Type</th>
|
|
203
|
+
<th class="px-4 py-3 font-semibold">Description</th>
|
|
204
|
+
</tr>
|
|
205
|
+
</thead>
|
|
206
|
+
<tbody class="divide-y divide-slate-100 text-slate-600">
|
|
207
|
+
<tr>
|
|
208
|
+
<td class="px-4 py-3 font-mono font-bold text-indigo-700">type</td>
|
|
209
|
+
<td class="px-4 py-3 font-mono text-slate-500">string</td>
|
|
210
|
+
<td class="px-4 py-3">Set to <code class="font-mono text-slate-800">"table"</code> to build and render an
|
|
211
|
+
HTML table.</td>
|
|
212
|
+
</tr>
|
|
213
|
+
<tr>
|
|
214
|
+
<td class="px-4 py-3 font-mono font-bold text-indigo-700">data</td>
|
|
215
|
+
<td class="px-4 py-3 font-mono text-slate-500">Array<Object></td>
|
|
216
|
+
<td class="px-4 py-3">The array of objects containing the row records (e.g. <code
|
|
217
|
+
class="font-mono text-slate-800">data.slice(0, 50)</code>).</td>
|
|
218
|
+
</tr>
|
|
219
|
+
<tr>
|
|
220
|
+
<td class="px-4 py-3 font-mono font-bold text-indigo-700">targetHtmlId</td>
|
|
221
|
+
<td class="px-4 py-3 font-mono text-slate-500">string</td>
|
|
222
|
+
<td class="px-4 py-3">The DOM element ID where the table will be rendered (<code
|
|
223
|
+
class="font-mono text-slate-800">"dom-render-container"</code>).</td>
|
|
224
|
+
</tr>
|
|
225
|
+
<tr>
|
|
226
|
+
<td class="px-4 py-3 font-mono font-bold text-indigo-700">columns</td>
|
|
227
|
+
<td class="px-4 py-3 font-mono text-slate-500">Array<string></td>
|
|
228
|
+
<td class="px-4 py-3">Array of object keys to display as table headers and columns (e.g. <code
|
|
229
|
+
class="font-mono text-slate-800">["itemName", "baseUnit"]</code>).</td>
|
|
230
|
+
</tr>
|
|
231
|
+
<tr>
|
|
232
|
+
<td class="px-4 py-3 font-mono font-bold text-indigo-700">showLog</td>
|
|
233
|
+
<td class="px-4 py-3 font-mono text-slate-500">boolean</td>
|
|
234
|
+
<td class="px-4 py-3">Optional. Set to <code class="font-mono text-slate-800">true</code> to print build
|
|
235
|
+
logs in the browser console.</td>
|
|
236
|
+
</tr>
|
|
237
|
+
</tbody>
|
|
238
|
+
</table>
|
|
239
|
+
</div>
|
|
240
|
+
</section>
|
|
241
|
+
|
|
242
|
+
<!-- Live Render Demonstration -->
|
|
243
|
+
<section class="bg-white rounded-2xl p-6 sm:p-8 border border-slate-200 shadow-sm space-y-4">
|
|
244
|
+
<div class="flex items-center justify-between pb-3 border-b border-slate-100">
|
|
245
|
+
<div>
|
|
246
|
+
<h2 class="text-lg font-bold text-slate-900">Live Table Output</h2>
|
|
247
|
+
<p class="text-xs text-slate-500">Rendered automatically by calling <code
|
|
248
|
+
class="font-mono text-indigo-700">window.ks.jsonRenderers.renderToDom</code></p>
|
|
249
|
+
</div>
|
|
250
|
+
<span
|
|
251
|
+
class="px-2.5 py-1 text-xs font-mono rounded-full bg-emerald-100 text-emerald-800 font-semibold flex items-center gap-1.5">
|
|
252
|
+
<span class="w-2 h-2 rounded-full bg-emerald-500 animate-pulse"></span> Mounted to #dom-render-container
|
|
253
|
+
</span>
|
|
254
|
+
</div>
|
|
255
|
+
|
|
256
|
+
<!-- Container where table will be mounted -->
|
|
257
|
+
<div id="dom-render-container" class="overflow-x-auto min-h-[140px]">
|
|
258
|
+
<div class="text-center py-6 text-slate-400 text-sm">Loading table via window.ks...</div>
|
|
259
|
+
</div>
|
|
260
|
+
</section>
|
|
261
|
+
|
|
262
|
+
</main>
|
|
263
|
+
|
|
264
|
+
<!-- Footer -->
|
|
265
|
+
<footer class="border-t border-slate-200 bg-white py-6 mt-8">
|
|
266
|
+
<div
|
|
267
|
+
class="max-w-5xl mx-auto px-4 sm:px-6 flex flex-col sm:flex-row items-center justify-between gap-3 text-xs text-slate-500">
|
|
268
|
+
<div>
|
|
269
|
+
<span class="text-slate-800 font-semibold">json-renderers</span> • <code
|
|
270
|
+
class="text-indigo-600">window.ks.jsonRenderers.renderToDom</code>
|
|
271
|
+
</div>
|
|
272
|
+
<div class="flex items-center gap-4">
|
|
273
|
+
<a href="index.html" class="hover:underline">HTML Process</a>
|
|
274
|
+
<a href="cdn.html" class="hover:underline">Using CDN</a>
|
|
275
|
+
<a href="../../samples/table/byKs/index.html" target="_blank"
|
|
276
|
+
class="text-indigo-600 font-medium hover:underline">Sample (byKs)</a>
|
|
277
|
+
</div>
|
|
278
|
+
</div>
|
|
279
|
+
</footer>
|
|
280
|
+
|
|
281
|
+
<!-- Script executing window.ks.jsonRenderers.renderToDom -->
|
|
282
|
+
<script type="module">
|
|
283
|
+
// 1. Load the bundle to attach window.ks globally
|
|
284
|
+
try {
|
|
285
|
+
await import("../dist/v14/min.js");
|
|
286
|
+
} catch {
|
|
287
|
+
await import("https://cdn.jsdelivr.net/gh/keshavsoft/json-renderers@main/docs/dist/v14/min.js");
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 2. Sample data matching the columns ["itemName", "baseUnit"]
|
|
291
|
+
const data = [
|
|
292
|
+
{ itemName: "0.09/30mm Steel Wire", baseUnit: "kgs", category: "Raw Materials" },
|
|
293
|
+
{ itemName: "0.11-25 Copper Alloy", baseUnit: "kgs", category: "Metals" },
|
|
294
|
+
{ itemName: "0.11-30 Aluminum Rod", baseUnit: "kgs", category: "Metals" },
|
|
295
|
+
{ itemName: "0.11/32mm Brass Tube", baseUnit: "kgs", category: "Pipes" },
|
|
296
|
+
{ itemName: "Industrial Gear G-14", baseUnit: "pcs", category: "Machinery" },
|
|
297
|
+
{ itemName: "High-Tensile Fastener", baseUnit: "pcs", category: "Hardware" },
|
|
298
|
+
{ itemName: "Hydraulic Seal Ring", baseUnit: "pcs", category: "Seals" },
|
|
299
|
+
{ itemName: "Precision Bearing 6205", baseUnit: "pcs", category: "Bearings" }
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
// 3. Run the function to build the table
|
|
303
|
+
const start = () => {
|
|
304
|
+
try {
|
|
305
|
+
if (window.ks && window.ks.jsonRenderers && window.ks.jsonRenderers.renderToDom) {
|
|
306
|
+
window.ks.jsonRenderers.renderToDom({
|
|
307
|
+
type: "table",
|
|
308
|
+
data: data.slice(0, 50),
|
|
309
|
+
targetHtmlId: "dom-render-container",
|
|
310
|
+
columns: ["itemName", "baseUnit"],
|
|
311
|
+
showLog: true
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
console.log("error : ", err);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
start();
|
|
320
|
+
|
|
321
|
+
// Clipboard copy helper
|
|
322
|
+
window.copyCode = (id) => {
|
|
323
|
+
const code = document.getElementById(id);
|
|
324
|
+
if (!code) return;
|
|
325
|
+
navigator.clipboard.writeText(code.textContent).then(() => {
|
|
326
|
+
alert("Code copied to clipboard!");
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
</script>
|
|
330
|
+
</body>
|
|
331
|
+
|
|
332
|
+
</html>
|