-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
663 lines (635 loc) · 42.1 KB
/
Copy pathindex.html
File metadata and controls
663 lines (635 loc) · 42.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>dmax notebook asserts — index.html</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="stylesheet" href="tools/vendor/uplot.css" />
<style>
html,
body {
height: 100%;
margin: 0;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
overflow-anchor: none;
}
header {
padding: 8px 12px;
background: #0f172a;
color: #e2e8f0;
display: flex;
align-items: center;
gap: 12px;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
header a {
color: #bfdbfe;
}
#summary {
margin-left: auto;
font-weight: 600;
color: #bfdbfe;
text-decoration: none;
}
main {
padding-bottom: 24px;
}
#asserts-panel,
#ported-examples {
padding: 12px;
border-top: 1px solid #e2e8f0;
}
#asserts-panel {
position: relative;
}
#out {
padding: 12px 0 0;
white-space: pre-wrap;
word-break: break-word;
margin: 0;
overflow-anchor: none;
}
.note {
color: #475569;
font-style: italic;
padding: 8px 12px;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #f8fafc;
}
.page {
margin: 4px 0 10px;
padding: 6px 8px;
border: 1px solid #dbeafe;
border-radius: 6px;
background: #f8fbff;
color: #334155;
font-size: 12px;
line-height: 1.45;
}
.page code {
white-space: normal;
word-break: break-word;
}
.chk.pass {
color: #16a34a;
}
.chk.fail {
color: #dc2626;
}
#dbg-wrap {
position: relative;
margin-top: 8px;
}
#dbg-toggle {
position: absolute;
top: 8px;
right: 8px;
border: 1px solid #cbd5e1;
border-radius: 999px;
background: #0f172a;
color: #e2e8f0;
padding: 6px 10px;
font: inherit;
cursor: pointer;
z-index: 2;
}
#dbg-panel {
display: none;
margin-top: 8px;
}
#dbg-wrap:hover #dbg-panel,
#dbg-wrap[data-open="1"] #dbg-panel {
display: block;
}
.wc-demo {
display: grid;
gap: 10px;
align-items: start;
}
mx-uplot {
display: block;
min-height: 220px;
border: 1px solid #dbeafe;
border-radius: 6px;
background: #fff;
padding: 8px;
overflow: auto;
}
.active { border-color: #28a745 !important; background: #eaffea; }
.inactive { opacity: .7; filter: grayscale(.2); }
</style>
</head>
<body>
<header>
<a href="https://dadhi.github.io/dmax/">dmax</a>
<a href="examples/m-ex-cel.html">m-ex-cel</a>
<a id="summary" href="#asserts-panel">Tests 0: Passed 0, Failed 0</a>
</header>
<main>
<div id='foo' hidden>good</div>
<section id="ported-examples">
<h3 style="margin:0 0 8px 0">Live runtime examples</h3>
<div data-m-si='{
"user":{"name":"Alice","age":25,"ui":{"themeColor":"#007bff","isActive":true,"fontSize":16}},
"count":10,"doubled":20,"posts":["First post","Second post","Third post"],
"threads":[{"title":"Thread A","replies":["A1","A2"]},{"title":"Thread B","replies":["B1"]},{"title":"Thread C","replies":[]}],
"message":"Hello World","postObjs":[{"title":"Post A"},{"title":"Post B"}],"idx":0,
"draftPost":{"title":"I am in love with someone.","body":"This notebook now mirrors DummyJSON post payloads for deterministic action examples.","userId":5},
"parent":{"child":1},"demo-parent":{"child":1},
"onceTest":0,"alwaysTest":0,"guardVal":3,"otherFlag":false,
"modOnce":0,"modDeb":0,"modThr":0,"modAnd":0,"gate":false,
"busy":false,"err":null,"code":null,"postResult":null,"createdPost":null,
"post-loading":false,"post-error":null,"post-code":null,"post-result-custom":null,
"val-source":{"bar":7},
"uplot":{"title":"Revenue vs Cost","points":true,"labels":["Revenue","Cost"],"data":[[1,2,3,4,5],[12,18,16,22,24],[8,11,13,15,18]],"series":[{"label":"Revenue","stroke":"#2563eb"},{"label":"Cost","stroke":"#dc2626"}],"w":420,"h":220},
"uplot2":null,
"uplot-last":null,
"sse-message":"","sse-count":0,"sse-meta":null
}'></div>
<h4>0. uPlot host props and events</h4>
<template data-m-wc="mx-uplot" data-m-wc-props="cfg"><div data-m-ex@.cfg="window.mxUplotRender(el, detail.detail)"></div></template>
<div class="page">Edit the title or width and the chart should update immediately. Click Step data / Add point / Toggle points to change the first chart. Click Duplicate chart to create a second live instance. Click any point to inspect the emitted payload below.</div>
<p>This uses the in-page WC style: <code>data-m-wc</code> defines the host and normal <code>data-m-ex</code> drives host props/events. The same host could also be registered from JS with <code>dmWc(...)</code>; see <code>m-ex-cel</code> for the separate-file style.</p>
<div class="wc-demo">
<div>
<label>Title <input id="uplot-title-input" value="Revenue vs Cost" data-m-ex:.value@uplot="dm.uplot.title" data-m-ex:uplot@#uplot-title-input.input="window.setUplotTitle(dm.uplot, val)"></label>
<label>Width <input id="uplot-width-input" type="range" min="280" max="640" step="20" data-m-ex:.value@uplot="String(dm.uplot.w)" data-m-ex:uplot@#uplot-width-input.input="window.setUplotWidth(dm.uplot, +val)"></label>
<button id="uplot-step" data-m-ex:uplot@#uplot-step.click="window.stepUplot(dm.uplot)">Step data</button>
<button id="uplot-push" data-m-ex:uplot@#uplot-push.click="window.pushUplot(dm.uplot)">Add point</button>
<button id="uplot-pts" data-m-ex:uplot@#uplot-pts.click="window.toggleUplot(dm.uplot)">Toggle points</button>
<button id="uplot-dup" data-m-ex:uplot2@#uplot-dup.click="window.cloneUplot(dm.uplot)">Duplicate chart</button>
</div>
<p data-m-ex:.@uplot@uplot2="'title: ' + dm.uplot.title + ' · width: ' + dm.uplot.w + ' · points: ' + (dm.uplot.points ? 'on' : 'off') + ' · second chart: ' + (dm.uplot2 ? 'on' : 'off')"></p>
<mx-uplot id="uplotdemo" data-m-ex:.cfg@uplot data-m-ex:uplot-last^merge@.point^ev="{ from: 'uplot-1', ...val }"></mx-uplot>
<mx-uplot id="uplotDemo2" style="display:none" data-m-ex:.style.display@uplot2="dm.uplot2 ? '' : 'none'" data-m-ex:.cfg@uplot2 data-m-ex:uplot-last^merge@.point^ev="{ from: 'uplot-2', ...val }"></mx-uplot>
<pre style="background:#f8fafc;padding:8px;border-radius:6px;margin:0" data-m-ex:.@uplot-last^jsos.2="dm.uplotLast ? val : 'click a point'" aria-label="uPlot point payload"></pre>
</div>
<h4>1. Deep Nested Signal Sync</h4>
<div class="page"><code><input type="text" data-m-ex@.^rw@user.name></code> · <code><input type="text" data-m-ex:user.name@.input></code> · <code><input type="number" data-m-ex@.^rw^num@user.age></code> · <code><input type="number" data-m-ex:user.age@.input^num></code> Type in the inputs and look for the greeting and age text to update while you type.</div>
<label>User Name: <input id="exUserNameInput" type="text" data-m-ex@.^rw@user.name data-m-ex:user.name@.input></label>
<p>Hello, <strong data-m-ex:.@user.name></strong>!</p>
<label>Age: <input id="exUserAgeInput" type="number" data-m-ex@.^rw^num@user.age data-m-ex:user.age@.input^num></label>
<p>Age: <span data-m-ex:.@user.age></span> years old</p>
<h4>1.a data-m-ex Direction Examples</h4>
<div class="page"><code><span data-m-ex:.@user.name></code> · <code><input type="text" data-m-ex:user.name@.input></code> · <code><input type="text" data-m-ex@.^rw@user.name></code> Compare one-way signal->element, one-way element->signal, and two-way sync side by side.</div>
<label>Signal -> Element: <input id="sigToProp" data-m-ex:.@user.name></label>
<label>Element -> Signal (writes on key input): <input id="elToSig" value="Alice" data-m-ex:user.name@.input></label>
<label>Two-way: <input id="twoWay" data-m-ex@.^rw@user.name data-m-ex:user.name@.input></label>
<div>Signal preview: <span data-m-ex:.@user.name></span></div>
<h4>2. Style & Boolean Deep Sync</h4>
<div class="page"><code><input type="color" data-m-ex@.^rw@user.ui.theme-color></code> · <code><input type="color" data-m-ex:user.ui.theme-color@.input></code> · <code><div data-m-ex:.style.color@user.ui.theme-color></code> · <code><input type="range" data-m-ex@.^rw^num@user.ui.font-size></code> · <code><input type="range" data-m-ex:user.ui.font-size@.input^num></code> · <code><p data-m-ex:.style.font-size@user.ui.font-size="val + 'px'"></code> · <code><input type="checkbox" data-m-ex@.^rw@user.ui.is-active></code> Change the color, drag the font slider, and toggle the checkbox; style changes should apply immediately.</div>
<label>Theme Color: <input id="themeColorInput" type="color" data-m-ex@.^rw@user.ui.theme-color data-m-ex:user.ui.theme-color@.input></label>
<div id="themeColorPreview" style="padding:8px;border:1px solid #ccc;margin:6px 0" data-m-ex:.style.color@user.ui.theme-color>Color sync</div>
<label>Font Size: <span data-m-ex:.@user.ui.font-size></span>px</label>
<input id="themeFontSlider" type="range" min="12" max="32" data-m-ex@.^rw^num@user.ui.font-size data-m-ex:user.ui.font-size@.input^num>
<p id="themeFontPreview" data-m-ex:.style.font-size@user.ui.font-size="val + 'px'">Resizable text</p>
<label><input id="themeActiveToggle" type="checkbox" data-m-ex@.^rw@user.ui.is-active> Active</label>
<p>Status: <strong data-m-ex:.@user.ui.is-active="dm.user.ui.isActive ? '🟢 ONLINE' : '🔴 OFFLINE'"></strong></p>
<h4>3. Multiple Triggers & Targets</h4>
<div class="page"><code><button data-m-ex:count^inc@.></code> · <code><button data-m-ex:count^dec@.></code> · <code><button data-m-ex:count@.="0"></code><br><code><strong data-m-ex:.@count></code> · <code><span data-m-ex:.:doubled@count="dm.count * 2"></code> · <code><button data-m-ex:.@.="`${el.id || ''} ${detail && detail.type ? detail.type : 'click'}`"></code><br><code><button data-m-ex^once:once-test^inc@.></code> · <code><button data-m-ex^once:always-test^inc@.^always></code> · <code><button data-m-ex:guard-val^inc@.></code> Click the buttons and look for count, doubled value, trigger probe, once-only behavior, and guard labels to change.</div>
<button id="countPlusBtn" data-m-ex:count^inc@.>+1</button>
<button id="countMinusBtn" data-m-ex:count^dec@.>-1</button>
<button id="countResetBtn" data-m-ex:count@.="0">Reset</button>
<p>Count: <strong id="countDisplay" data-m-ex:.@count></strong></p>
<p>Doubled: <span id="doubledDisplay" data-m-ex:.:doubled@count="dm.count * 2"></span></p>
<button id="probeBtn" data-m-ex:.@.="`${el.id || ''} ${detail && detail.type ? detail.type : 'click'}`">Probe</button>
<span id="probeOut" data-m-ex:.@count="trig ? trig.root : ''"></span>
<div>
<button id="gOnceBtn" data-m-ex^once:once-test^inc@.>Once +1</button>
<span data-m-ex:.@once-test></span>
<button id="gAlwaysBtn" data-m-ex^once:always-test^inc@.^always>Once+Always +1</button>
<span data-m-ex:.@always-test></span>
</div>
<div>
<button id="incGuard" data-m-ex:guard-val^inc@.>Inc Guard</button>
<span data-m-ex:.@guard-val></span>
<span data-m-ex:.@guard-val^gt.5="dm.guardVal > 5 ? 'GT5' : ''"></span>
<span data-m-ex:.@guard-val^eq.3="dm.guardVal == 3 ? 'EQ3' : ''"></span>
<span data-m-ex^!and.other-flag:.@guard-val="dm.guardVal ? 'allowed' : ''"></span>
</div>
<div>
<span data-m-ex:.@_interval.1000="(detail && detail.ms) ? ('interval ' + detail.ms) : ''"></span>
<span id="timeoutOut" data-m-ex:.@_timeout.1500="(detail && detail.ms) ? ('timeout ' + detail.ms) : ''"></span>
</div>
<h4>4. Side Effects & Multiple Triggers</h4>
<div class="page"><code>data-m-ex:.@count@#btn1@#btn2="console.log('Triggered!', dm.count) || '✓ Check console'"</code> · <code>data-m-ex:.@count@#btn1@#btn2="({ btn1: 'Button 1', btn2: 'Button 2' }[(trig && trig.root) || ''] || 'count') + ' -> ' + dm.count"</code> Click either button and look for both console side effects and visible trigger-source text.</div>
<button id="btn1">Button 1</button><button id="btn2">Button 2</button>
<p><span id="example4ConsoleOut" data-m-ex:.@count@#btn1@#btn2="console.log('Triggered!', dm.count) || '✓ Check console'"></span></p>
<p><strong id="example4VisibleOut" data-m-ex:.@count@#btn1@#btn2="({ btn1: 'Button 1', btn2: 'Button 2' }[(trig && trig.root) || ''] || 'count') + ' -> ' + dm.count"></strong></p>
<h4>5. Cross-Element Property Sync</h4>
<div class="page"><code><input data-m-ex@.^rw@message></code> · <code><input data-m-ex:message@.input></code> · <code><p data-m-ex:.@#src.input></code> · <code><input readonly data-m-ex:.value@#src.input></code> Type in the source input and look for both the text preview and readonly mirror to track it while you type.</div>
<input id="src" placeholder="Type here..." data-m-ex@.^rw@message data-m-ex:message@.input>
<p id="srcPreview" data-m-ex:.@#src.input></p>
<input id="mirror" readonly data-m-ex:.value@#src.input>
<h4>6. Window Events & Intervals</h4>
<div class="page"><code>data-m-ex:.@_window.resize="window.innerWidth + 'px'"</code> · <code>data-m-ex:.@_interval.1000="new Date().toLocaleTimeString()"</code> · <code>data-m-ex:.@_timeout.1500="(detail && detail.ms) ? ('timeout ' + detail.ms) : ''"</code> · <code>data-m-ex:.@_viewed^once="'✓ Viewed (ratio: ' + (detail && detail.ratio != null ? detail.ratio.toFixed(2) : '?') + ')'"</code> · <code>data-m-ex:.@_init="'✓ Initialized (detail.type: ' + (detail && detail.type) + ')'"</code> Resize the window, wait for the timer labels, and scroll the viewed line into view to see each special trigger fire.</div>
<p>Window width: <span id="windowWidthOut" data-m-ex:.@_window.resize="window.innerWidth + 'px'"></span></p>
<p>Current time: <span id="timeOut" data-m-ex:.@_interval.1000="new Date().toLocaleTimeString()"></span></p>
<p>Scroll into view: <span id="viewedOut" data-m-ex:.@_viewed^once="'✓ Viewed (ratio: ' + (detail && detail.ratio != null ? detail.ratio.toFixed(2) : '?') + ')'"></span></p>
<p>On init: <span id="initOut" data-m-ex:.@_init="'✓ Initialized (detail.type: ' + (detail && detail.type) + ')'"></span></p>
<h4>6.a URL, history, WC defaults, and <code>^sel-all</code></h4>
<div class="page"><code>data-m-ex:_history.push-state@.</code> · <code>data-m-ex:.@_window.hashchange^.location.hash</code> · <code>data-m-ex:.@wc-step</code> · <code>data-m-ex:wc-picked@.step-picked^ev</code> · <code>data-m-ex:.@_init^sel-all..sel-all-demo-item</code> Push/replace the hash, watch the current hash react, then compare default WC prop/event behavior and selector-query reads.</div>
<p>
<button id="pushHash" data-m-ex:_history.push-state@.="[null, '', '#demo-push']">Push #demo-push</button>
<button id="replaceHash" data-m-ex:_history.replace-state@.="[null, '', '#demo-replace']">Replace #demo-replace</button>
</p>
<p>Current hash: <span id="hashOut" data-m-ex:.@_init@_window.hashchange^.location.hash="val || '#'"></span></p>
<mx-step id="wcStep" data-m-ex:.@wc-step="'' + val" data-m-ex:wc-picked@.step-picked^ev="val.step"></mx-step>
<p>WC default <code>value</code> prop: <span data-m-ex:.@wc-step></span></p>
<p>WC custom event detail: <span data-m-ex:.@wc-picked></span></p>
<ul><li class="sel-all-demo-item">alpha</li><li class="sel-all-demo-item">beta</li><li class="sel-all-demo-item">gamma</li></ul>
<p>QSA count: <span id="qsaCount" data-m-ex:.@_init^sel-all..sel-all-demo-item="val.length"></span></p>
<h4>7. Default Props & Events</h4>
<div class="page"><code><input data-m-ex:.@#inp1.input></code> · <code><button data-m-ex:.@#btn3="'Clicked!'"></code> Type in the input and click the button; the labels below should mirror the default prop/event behavior.</div>
<input id="inp1" placeholder="Mirrors on input">
<p><span id="inp1Preview" data-m-ex:.@#inp1.input></span></p>
<button id="btn3">Click me</button>
<p><span id="btn3Preview" data-m-ex:.@#btn3="'Clicked!'"></span></p>
<h4>7.a `^` / `^si` trigger picks</h4>
<div class="page"><code><input data-m-ex:val-prop-picked@.input^.data-foo-bar^num></code> · <code><strong data-m-ex:.@val-source^si.bar></code> · <code><strong data-m-ex:.@val-source^si.bar="val + 1"></code> Type in the input and click the increment button; compare the picked property value with the picked signal child value.</div>
<div style="margin:8px 0;padding:8px;border:1px solid #e2e8f0;border-radius:6px">
<label>Non-default event prop:
<input id="valpickinput" data-foo-bar="33" placeholder="Typing keeps val=data-foo-bar" data-m-ex:val-prop-picked@.input^.data-foo-bar^num>
</label>
<div>Typed text: <span id="valPickTyped" data-m-ex:.@#valpickinput.input></span></div>
<div>Picked <code>data-foo-bar</code>: <strong id="valPropPicked" data-m-ex:.@val-prop-picked></strong></div>
</div>
<div style="margin:8px 0;padding:8px;border:1px solid #e2e8f0;border-radius:6px">
<button id="valSignalStep" data-m-ex:val-source@.="({ bar: ((dm.valSource && dm.valSource.bar) || 0) + 1 })">Increment <code>valSource.bar</code></button>
<div>Signal child via <code>^si.bar</code>: <strong id="valSignalPicked" data-m-ex:.@val-source^si.bar></strong></div>
<div>Expression on picked child: <strong id="valSignalPlusOne" data-m-ex:.@val-source^si.bar="val + 1"></strong></div>
</div>
<h4>8. Classes & Display</h4>
<div class="page"><code><input type="checkbox" data-m-ex@.^rw@user.ui.is-active></code> · <code><div data-m-cl+active+!inactive@user.ui.is-active></code> · <code><p data-m-sh:.@user.ui.is-active></code> · <code><p data-m-sh:.@!user.ui.is-active></code> Toggle the checkbox and look for classes plus positive/negative visibility changes.</div>
<label><input id="classToggle" type="checkbox" data-m-ex@.^rw@user.ui.is-active> Toggle Active</label>
<div id="classBox" data-m-cl+active+!inactive@user.ui.is-active style="padding:8px;border:1px solid #ccc;margin:6px 0">Status Box</div>
<p id="displayBox" data-m-sh:.@user.ui.is-active>Visible only when active</p>
<p id="displayNeg" data-m-sh:.@!user.ui.is-active>Visible only when NOT active</p>
<h4>9. List Rendering (data-m-it)</h4>
<div class="page"><code>data-m-it+#tpl-post@posts</code> · <code>data-m-cl+zebra-even+!zebra-odd@posts="$ix % 2 === 0"</code> · <code>data-m-it@posts</code> · <code>data-m-it+#tpl-thread@threads</code><br><code>data-m-ex:posts@.</code> · <code>data-m-ex:posts@.</code> · <code>data-m-ex:posts@.</code> · <code>data-m-ex:posts@.</code> · <code>data-m-ex:threads@.</code> Use the list buttons and look for append/update/remove behavior plus stable zebra striping and nested thread refresh.</div>
<template id="tpl-post">
<li data-index="$ix" data-m-cl+zebra-even+!zebra-odd@posts="$ix % 2 === 0">
<span class="num" data-m-ex:.@posts="$ix + 1"></span>
<span class="item" data-m-ex:.@posts^si.$ix^jsos.2="typeof dm.posts[$ix] === 'object' ? val : dm.posts[$ix]" style="margin-left:8px"></span>
</li>
</template>
<ul id="dumpPostsPrimary" data-m-it+#tpl-post@posts></ul>
<ul id="inline-posts" data-m-it@posts><template><li data-index="$ix" data-m-cl+zebra-even+!zebra-odd@posts="$ix % 2 === 0"><span data-m-ex:.@posts="$ix + 1"></span> <span data-m-ex:.@posts="dm.posts[$ix]"></span></li></template></ul>
<template id="tpl-thread">
<li class="thread">
<strong data-m-ex:.@threads="$it.title"></strong>
<ul class="thread-replies" data-m-it@$it.replies>
<template><li data-m-ex:.="$it"></li></template>
</ul>
</li>
</template>
<ul id="thread-posts" data-m-it+#tpl-thread@threads></ul>
<ul id="inline-threads" data-m-it@threads>
<template>
<li class="thread">
<strong data-m-ex:.@threads="$it.title"></strong>
<ul class="thread-replies" data-m-it@$it.replies>
<template><li data-m-ex:.="$it"></li></template>
</ul>
</li>
</template>
</ul>
<div>
<button id="addPost" data-m-ex:posts@.="(dm.posts || []).concat(['New post ' + ((dm.posts && dm.posts.length) || 0)])">Add Post</button>
<button id="updateSecondPost" data-m-ex:posts@.="(dm.posts || []).map((post, idx) => idx === 1 ? 'Updated second post' : post)">Update Second</button>
<button id="removeFirst" data-m-ex:posts@.="(dm.posts || []).slice(1)">Remove First</button>
<button id="removePost" data-m-ex:posts@.="(dm.posts || []).slice(0, Math.max(0, (dm.posts || []).length - 1))">Remove Last</button>
<button id="refreshThreads" data-m-ex:threads@.="(dm.threads || []).concat([{ title: 'Thread D', replies: ['D1'] }])">Refresh Threads</button>
</div>
<h4>10. Modifiers demo</h4>
<div class="page"><code>data-m-ex:mod-once^inc@.^once</code> · <code>data-m-ex:mod-deb^inc@.^debounce.120</code> · <code>data-m-ex:mod-thr^inc@.^throttle.120</code> · <code>data-m-ex:mod-and^inc@.^and.gate</code> Click repeatedly and compare once-only, debounced, throttled, and gated behavior.</div>
<button id="onceBtn" data-m-ex:mod-once^inc@.^once>Once</button>
<span data-m-ex:.@mod-once></span>
<button id="debBtn" data-m-ex:mod-deb^inc@.^debounce.120>Debounce</button>
<span data-m-ex:.@mod-deb></span>
<button id="thrBtn" data-m-ex:mod-thr^inc@.^throttle.120>Throttle</button>
<span data-m-ex:.@mod-thr></span>
<label><input id="gate" type="checkbox" data-m-ex@.^rw@gate> Gate</label>
<button id="andBtn" data-m-ex:mod-and^inc@.^and.gate>AND</button>
<span data-m-ex:.@mod-and></span>
<h4>10.a Content vs Shape</h4>
<div class="page"><code>data-m-ex:demo-parent@.="{ ...(dm.demoParent || {}), child: ((dm.demoParent && dm.demoParent.child) || 0) + 1 }"</code><br><code>data-m-ex:demo-parent@.="{ ...(dm.demoParent || {}), addedAt: 'shape' }"</code> · <code>data-m-ex:demo-parent@.="(({ addedAt, ...o }) => o)(dm.demoParent || {})"</code> Compare content-only updates with shape changes; the shape subscriber should stay quiet until keys are added or removed.</div>
<div style="margin:8px 0;padding:8px;border:1px solid #e2e8f0;border-radius:6px">
<div>Parent signal preview:</div>
<pre id="demoState" style="background:#fafafa;padding:8px;border-radius:4px" data-m-ex:.@demo-parent^jsos.2></pre>
<div style="margin-top:6px">
<button id="demoChangeChild" data-m-ex:demo-parent@.="{ ...(dm.demoParent || {}), child: ((dm.demoParent && dm.demoParent.child) || 0) + 1 }">Change child (content)</button>
<button id="demoAddKey" data-m-ex:demo-parent@.="{ ...(dm.demoParent || {}), addedAt: 'shape' }">Add key (shape)</button>
<button id="demoRemoveKey" data-m-ex:demo-parent@.="(({ addedAt, ...o }) => o)(dm.demoParent || {})">Remove key (shape)</button>
</div>
<div style="margin-top:8px">
<div>Content subscriber: <span id="demoContent" data-m-ex:.@demo-parent="(dm.demoParent&&dm.demoParent.child)??''"></span></div>
<div>Shape subscriber: <span id="demoShape" data-m-ex:.@demo-parent^shape_only="detail ? window.formatShapeChange(detail) : ''"></span></div>
</div>
</div>
<h4>10.b Constant Index Signals</h4>
<div class="page"><code><strong data-m-ex:.@post-objs[0].title></code> · <code><strong data-m-ex:.@post-objs[1].title></code> · <code><button data-m-ex:post-objs[0].title@.="'NewP0Title'"></code> · <code><button data-m-ex:post-objs[1].title@.="'NewP1Title'"></code> Click each setter and check that only the targeted indexed value changes.</div>
<div style="margin:8px 0;padding:8px;border:1px solid #e2e8f0;border-radius:6px">
<div>Post 0: <strong id="post0Title" data-m-ex:.@post-objs[0].title></strong></div>
<div>Post 1: <strong id="post1Title" data-m-ex:.@post-objs[1].title></strong></div>
<div style="margin-top:6px">
<button id="setPost0Title" data-m-ex:post-objs[0].title@.="'NewP0Title'">Set post 0 title</button>
<button id="setPost1Title" data-m-ex:post-objs[1].title@.="'NewP1Title'">Set post 1 title</button>
</div>
</div>
<h4>State Tree (Live Debug)</h4>
<div id="dbg-wrap">
<button id="dbg-toggle" type="button" aria-expanded="false">Debug signals</button>
<div id="dbg-panel">
<pre data-m-dbg style="background:#f8fafc;padding:8px;border:1px solid #e2e8f0;border-radius:6px"></pre>
</div>
</div>
<h4>11. Actions demo + OOB HTML morph</h4>
<div class="page"><code>data-m-get^stat.req:post-result@.="'https://dummyjson.com/posts/1'"</code> Run the request and look for grouped status fields plus the JSON payload below.</div>
<button id="loadPost" data-m-get^stat.req:post-result@.="'https://dummyjson.com/posts/1'">Load DummyJSON post #1 (GET)</button>
<div>Busy: <span data-m-ex:.@req.busy></span> | Error: <span data-m-ex:.@req.err></span> | Code: <span data-m-ex:.@req.code></span></div>
<pre style="background:#f6f8fa;padding:8px;border-radius:6px;margin-top:8px" data-m-ex:.@post-result^jsos.2></pre>
<div style="margin-top:8px;border:1px solid #dbeafe;padding:8px;border-radius:6px">
<div class="page"><code>data-m-get^stat.post-state:post-result-custom@.="'https://dummyjson.com/posts/1'"</code> Same request, but read grouped custom status fields instead of the default ones.</div>
<button id="loadPostCustomBusy" data-m-get^stat.post-state:post-result-custom@.="'https://dummyjson.com/posts/1'">Load DummyJSON post #1 (custom grouped status)</button>
<strong style="margin-left:8px" data-m-sh:.@post-state.busy>Loading…</strong>
<div>Error: <span data-m-ex:.@post-state.err></span> | Code: <span data-m-ex:.@post-state.code></span></div>
<pre style="background:#eff6ff;padding:8px;border-radius:6px;margin-top:8px" data-m-ex:.@post-result-custom^jsos.2></pre>
</div>
<div>
<div class="page"><code>data-m-ex:draftPost@.="({ title: dmEl('new-title').value, body: dmEl('new-body').value, userId: +dmEl('new-user-id').value||0 })"</code><br><code>data-m-post^json^stat.req:created-post@.+draftPost^spread="'https://dummyjson.com/posts/add'"</code> Edit the fields and submit; the created-post JSON should echo the sent body with response data.</div>
<input id="new-title" placeholder="DummyJSON title" value="I am in love with someone." />
<input id="new-body" placeholder="DummyJSON body" value="This notebook now mirrors DummyJSON post payloads for deterministic action examples." />
<input id="new-user-id" type="number" min="1" placeholder="User ID" value="5" />
<button id="create-post" data-m-ex:draftPost@.="({ title: dmEl('new-title').value, body: dmEl('new-body').value, userId: +dmEl('new-user-id').value||0 })" data-m-post^json^stat.req:created-post@.+draftPost^spread="'https://dummyjson.com/posts/add'">Create DummyJSON post (POST ^json)</button>
<pre style="background:#fff8f0;padding:8px;border-radius:6px;margin-top:8px" data-m-ex:.@created-post^jsos.2></pre>
</div>
<div style="margin-top:8px;border:1px dashed #eab308;padding:8px">
<div class="page"><code>data-m-ex:.dataset.payload@created-post^jsos.2</code> writes JSON text into a data-* attribute without spelling out a manual stringify expression.</div>
<div id="jsosTarget" data-m-ex:.dataset.payload@created-post^jsos.2></div>
<pre style="background:#fffbeb;padding:8px;border-radius:6px;margin-top:8px" data-m-ex:.@created-post^jsos.2></pre>
</div>
<div style="margin-top:8px;border:1px dashed #cbd5e1;padding:8px">
<div class="page"><code>data-m-get^html^stat.req@.="'/mock/oob'"</code> Run it and watch the target block morph without a full replace.</div>
<button id="oobLoad" data-m-get^html^stat.req@.="'/mock/oob'">Load OOB HTML + morph</button>
<div id="oobTarget"><strong>Initial target content</strong></div>
</div>
<div style="margin-top:8px;border:1px dashed #94a3b8;padding:8px">
<div class="page"><code>data-m-get^sse^stat.sse-meta:sse-events@.="'/mock/dmax-sse'"</code> Replays one short mocked SSE response through dmax's real SSE path, then closes. It updates signals and morphs the target once so the behavior is easy to inspect.</div>
<button id="sseLoad" data-m-get^sse^stat.sse-meta:sse-events@.="'/mock/dmax-sse'">Replay one mocked SSE response</button>
<div>Message: <span data-m-ex:.@sse-message></span> | Count: <span data-m-ex:.@sse-count></span></div>
<div>SSE status: <span data-m-ex:.@sse-meta="!val ? 'idle' : val.open ? 'open' : val.close ? 'closed' : val.busy ? 'loading' : val.complete ? 'complete' : 'ready'"></span></div>
<div id="sseTarget"><strong>Initial SSE target</strong></div>
<pre style="background:#f8fafc;padding:8px;border-radius:6px;margin-top:8px" data-m-ex:.@sse-meta^jsos.2></pre>
</div>
</section>
<section id="asserts-panel">
<h3 style="margin:0 0 8px 0">Asserts</h3>
<div class="note">Output is mirrored from console.log/error. The sticky top summary updates live.</div>
<pre id="out"></pre>
</section>
</main>
<script>
if ('scrollRestoration' in history) history.scrollRestoration = 'manual'
const toTop = () => {
const hash = location.hash
if (hash && !document.getElementById(hash.slice(1))) history.replaceState(null, '', location.pathname + location.search)
else if (location.hash) return
scrollTo(0, 0)
document.documentElement.scrollTop = 0
document.body.scrollTop = 0
}
toTop()
addEventListener('load', toTop, { once: true })
addEventListener('pageshow', toTop, { once: true })
</script>
<script>
// Mirror console to <pre>, count tests
(function () {
const out = document.getElementById('out');
const summary = document.getElementById('summary');
let pass = 0, fail = 0, total = 0;
const orig = { log: console.log, error: console.error, warn: console.warn };
function toText(v) {
try {
if (typeof v === 'string') return v;
if (v && typeof v === 'object') return JSON.stringify(v);
return '' + v;
} catch (_) { return '' + v; }
}
function append(args) {
const isPass = args && args.length && (args[0] === '✓' || args[0] === '\u2713');
const isFail = args && args.length && (args[0] === '✗');
const line = args.map(toText).join(' ');
const div = document.createElement('div');
if (isPass || isFail) {
const chk = document.createElement('span');
chk.textContent = args[0];
chk.className = 'chk ' + (isPass ? 'pass' : 'fail');
div.appendChild(chk);
const rest = args.slice(1).map(toText).join(' ');
div.appendChild(document.createTextNode(' ' + rest));
} else div.textContent = line;
out.appendChild(div);
if (isPass) { pass++; total++; }
else if (isFail) { fail++; total++; }
summary.textContent = `Tests ${total}: Passed ${pass}, Failed ${fail}`;
}
console.log = (...args) => { try { append(args); } finally { orig.log.apply(console, args); } };
console.error = (...args) => { try { append(args); } finally { orig.error.apply(console, args); } };
console.warn = (...args) => { try { append(args); } finally { orig.warn.apply(console, args); } };
})();
</script>
<script>
window.formatShapeChange = function (change) {
if (!change) return '';
const parts = [];
if (change.added && change.added.length) parts.push('added: ' + change.added.join(','));
if (change.removed && change.removed.length) parts.push('removed: ' + change.removed.join(','));
if (change.addedRange) parts.push('addedRange: ' + change.addedRange.join(','));
if (change.removedRange) parts.push('removedRange: ' + change.removedRange.join(','));
return parts.join(' | ');
};
</script>
<script src="tools/vendor/uplot.js"></script>
<script>
customElements.get('mx-step') || customElements.define('mx-step', class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
this._value = 0
this.shadowRoot.innerHTML = '<button type="button">Step +1</button><output style="margin-left:8px"></output>'
}
get value() { return this._value }
set value(v) { this._value = +v || 0; this.shadowRoot.querySelector('output').textContent = '' + this._value }
connectedCallback() {
this.shadowRoot.querySelector('button').onclick = () => this.dispatchEvent(new CustomEvent('step-picked', { detail: { step: this._value + 1 } }))
this.value = this._value
}
})
</script>
<script>window.dmNoAutoScan = true</script>
<script src="dmax.js"></script>
<script>
(function () {
window.dmEl = (id) => document.getElementById(id)
const chartClone = (cfg, data = cfg && cfg.data) => cfg ? ({ ...cfg, data, labels: cfg.labels ? cfg.labels.slice() : cfg.labels, series: cfg.series ? cfg.series.map(s => s ? { ...s } : s) : cfg.series }) : cfg
const chartCloneDeepData = (cfg) => chartClone(cfg, cfg && cfg.data ? cfg.data.map(arr => arr.slice()) : cfg && cfg.data)
window.cloneUplot = (cfg) => cfg ? JSON.parse(JSON.stringify(cfg)) : cfg
window.setUplotTitle = (cfg, title) => cfg ? { ...chartCloneDeepData(cfg), title: String(title == null ? '' : title) } : cfg
window.setUplotWidth = (cfg, w) => cfg ? { ...chartCloneDeepData(cfg), w: +w || cfg.w || 420 } : cfg
window.stepUplot = (cfg) => cfg ? chartClone(cfg, cfg.data.map((arr, i) => i ? arr.map((n, j) => n + ((j & 1) ? -1 : 1) * (i + 1)) : arr.slice())) : cfg
window.pushUplot = (cfg) => {
if (!cfg || !cfg.data || !cfg.data.length) return cfg
const xs = cfg.data[0], nextX = (xs[xs.length - 1] || 0) + 1
return chartClone(cfg, cfg.data.map((arr, i) => arr.concat(i ? (arr[arr.length - 1] || 0) + (i === 1 ? 2 : 1) : nextX)))
}
window.toggleUplot = (cfg) => cfg ? { ...chartCloneDeepData(cfg), points: !cfg.points } : cfg
window.mxUplotRender = (box, cfg) => {
const host = box && box.parentNode, P = window.uPlot
if (!box || !host) return
if (!cfg || !cfg.data || !cfg.data.length || !P) {
if (box._plot) box._plot.destroy(), box._plot = null
box.textContent = P ? 'chart needs cfg' : 'uPlot unavailable'
return
}
if (box._plot) box._plot.destroy()
box.textContent = ''
const colors = ['#2563eb', '#dc2626', '#16a34a', '#a21caf']
const series = [{}, ...cfg.data.slice(1).map((_, i) => ({ label: cfg.labels && cfg.labels[i] || 'S' + (i + 1), stroke: colors[i] || '#334155', width: 2, ...(cfg.series && cfg.series[i] || {}), points: { show: !!cfg.points } }))]
const plot = box._plot = new P({ width: cfg.w || 420, height: cfg.h || 220, title: cfg.title || '', series, cursor: { drag: { x: false, y: false } } }, cfg.data, box)
plot.over.onclick = () => {
const i = plot.cursor.idx
if (i == null) return
host.dispatchEvent(new CustomEvent('point', { detail: { i, x: cfg.data[0][i], ys: cfg.data.slice(1).map(arr => arr[i]) } }))
}
}
const DUMMYJSON_POST = Object.freeze({
id: 1,
title: 'His mother had always taught him',
body: "His mother had always taught him not to ever think of himself as better than others. " +
"He'd tried to live by this motto. He never looked down on those who were less fortunate " +
'or who had less money than him. But the stupidity of the group of people he was talking ' +
'to made him change his mind.',
tags: Object.freeze(['history', 'american', 'crime']),
reactions: Object.freeze({ likes: 192, dislikes: 25 }),
views: 305,
userId: 121
});
const DUMMYJSON_CREATED_POST = Object.freeze({
id: 252,
title: 'I am in love with someone.',
body: 'This notebook now mirrors DummyJSON post payloads for deterministic action examples.',
userId: 5
});
function makeJsonResponse(payload, status) {
const code = status === null || status === undefined ? 200 : status;
const body = JSON.stringify(payload);
return {
ok: code >= 200 && code < 300,
status: code,
headers: { get: (n) => String(n || '').toLowerCase() === 'content-type' ? 'application/json' : null },
json: async () => payload,
text: async () => body,
clone() { return makeJsonResponse(payload, code); }
};
}
function getFetchPath(url) {
try { return new URL(String(url || ''), 'https://dummyjson.com').pathname; }
catch (_) { return String(url || ''); }
}
function isDummyJsonUrl(url) {
try {
const parsed = new URL(String(url || ''));
return parsed.hostname === 'dummyjson.com' && (parsed.protocol === 'https:' || parsed.protocol === 'http:');
} catch (_) {
return false;
}
}
function installDemoFetchMock() {
if (window.__dmaxDemoFetchInstalled && typeof window.fetch === 'function') return;
const baseFetch = typeof window.fetch === 'function' ? window.fetch.bind(window) : null;
window.fetch = function (url, init) {
const u = String(url || '');
const path = getFetchPath(url);
if (path === '/posts/1' && isDummyJsonUrl(url)) {
return Promise.resolve(makeJsonResponse(DUMMYJSON_POST, 200));
}
if (path === '/posts/add' && isDummyJsonUrl(url)) {
let submitted = null;
try { submitted = init && init.body ? JSON.parse(init.body) : null; } catch (_) { }
const payload = { ...DUMMYJSON_CREATED_POST, ...(submitted && typeof submitted === 'object' ? submitted : {}) };
if (payload.userId != null && payload.userId !== '') payload.userId = +payload.userId;
return Promise.resolve(makeJsonResponse(payload, 201));
}
if (u === '/mock/oob') {
const html = `<div id="oobTarget"><strong>OOB morphed content</strong> <span>(via dmAct + morph)</span></div>`;
return Promise.resolve({
ok: true,
headers: { get: (n) => String(n || '').toLowerCase() === 'content-type' ? 'text/html' : null },
text: async () => html
});
}
if (u === '/mock/dmax-sse') {
const bodyText = [
'event: dm-signals',
'data: dmSignals {"sseMessage":"hello from dmax","sseCount":1}',
'',
'event: dm-element',
'data: <div id="sseTarget"><strong>SSE morphed target</strong> <span>✓</span></div>',
''
].join('\n');
let streamBody = null;
if (typeof ReadableStream !== 'undefined' && typeof TextEncoder !== 'undefined') {
const encoded = new TextEncoder().encode(bodyText);
const half = Math.floor(encoded.length / 2);
streamBody = new ReadableStream({
start(ctrl) {
ctrl.enqueue(encoded.slice(0, half));
ctrl.enqueue(encoded.slice(half));
ctrl.close();
}
});
}
return Promise.resolve({
ok: true,
headers: { get: (n) => String(n || '').toLowerCase() === 'content-type' ? 'text/event-stream' : null },
body: streamBody,
text: async () => bodyText
});
}
if (baseFetch) return baseFetch(url, init);
return Promise.reject(new Error('fetch not available'));
};
window.__dmaxDemoFetchInstalled = true;
}
function initExamples() {
const roots = [document.getElementById('ported-examples'), document.getElementById('__fg_reactivity_tests')].filter(Boolean);
if (!roots.length) return;
for (const root of roots) dmScan(root);
installDemoFetchMock();
}
initExamples();
const dbgWrap = document.getElementById('dbg-wrap'), dbgToggle = document.getElementById('dbg-toggle');
if (dbgWrap && dbgToggle) dbgToggle.addEventListener('click', () => {
const open = dbgWrap.getAttribute('data-open') === '1';
dbgWrap.setAttribute('data-open', open ? '0' : '1');
dbgToggle.setAttribute('aria-expanded', open ? 'false' : 'true');
});
window.addEventListener('dmax:tests:done', installDemoFetchMock);
})();
</script>
<div id="__fg_reactivity_tests" style="display:none">
<span id="contentSub" data-m-ex:.@parent="(window.__contentCount = (window.__contentCount || 0) + 1, window.__contentCount)"></span>
<span id="shapeSub" data-m-ex:.@parent^shape_only="(window.__shapeCount = (window.__shapeCount || 0) + 1, window.__shapeCount)"></span>
<button id="chgChild" data-m-ex:parent@.click="{ ...(dm.parent || {}), child: ((dm.parent && dm.parent.child) || 0) + 1 }">Change child</button>
<button id="addKey" data-m-ex:parent@.click="{ ...(dm.parent || {}), added: true }">Add key</button>
<button id="removeKey" data-m-ex:parent@.click="(({ added, ...o }) => o)(dm.parent || {})">Remove key</button>
</div>
<script src="asserts.js"></script>
</body>
</html>