ripple 0.2.207 → 0.2.210
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/CHANGELOG.md +43 -0
- package/README.md +2 -1
- package/package.json +2 -6
- package/shims/rollup-estree-types.d.ts +1 -1
- package/src/compiler/index.d.ts +1 -0
- package/src/compiler/index.js +7 -1
- package/src/compiler/phases/1-parse/index.js +15 -6
- package/src/compiler/phases/2-analyze/css-analyze.js +100 -104
- package/src/compiler/phases/2-analyze/index.js +215 -2
- package/src/compiler/phases/3-transform/client/index.js +388 -50
- package/src/compiler/phases/3-transform/segments.js +123 -39
- package/src/compiler/phases/3-transform/server/index.js +266 -13
- package/src/compiler/types/index.d.ts +16 -3
- package/src/compiler/utils.js +1 -15
- package/src/constants.js +0 -2
- package/src/helpers.d.ts +4 -0
- package/src/html-tree-validation.js +211 -0
- package/src/jsx-runtime.d.ts +260 -259
- package/src/jsx-runtime.js +12 -12
- package/src/runtime/array.js +17 -17
- package/src/runtime/create-subscriber.js +1 -1
- package/src/runtime/index-client.js +1 -5
- package/src/runtime/index-server.js +15 -0
- package/src/runtime/internal/client/bindings.js +26 -20
- package/src/runtime/internal/client/compat.js +3 -3
- package/src/runtime/internal/client/composite.js +6 -1
- package/src/runtime/internal/client/head.js +50 -4
- package/src/runtime/internal/client/html.js +73 -12
- package/src/runtime/internal/client/hydration.js +12 -0
- package/src/runtime/internal/client/index.js +1 -1
- package/src/runtime/internal/client/portal.js +54 -29
- package/src/runtime/internal/client/rpc.js +3 -1
- package/src/runtime/internal/client/switch.js +5 -0
- package/src/runtime/internal/client/template.js +117 -11
- package/src/runtime/internal/client/try.js +1 -0
- package/src/runtime/internal/server/index.js +113 -1
- package/src/runtime/internal/server/rpc.js +4 -4
- package/src/runtime/map.js +2 -2
- package/src/runtime/object.js +6 -6
- package/src/runtime/proxy.js +12 -11
- package/src/runtime/reactive-value.js +9 -1
- package/src/runtime/set.js +12 -7
- package/src/runtime/url-search-params.js +0 -1
- package/src/server/index.js +4 -0
- package/src/utils/hashing.js +15 -0
- package/src/utils/normalize_css_property_name.js +1 -1
- package/tests/client/array/array.mutations.test.ripple +8 -8
- package/tests/client/basic/basic.errors.test.ripple +28 -0
- package/tests/client/basic/basic.events.test.ripple +6 -3
- package/tests/client/basic/basic.utilities.test.ripple +1 -1
- package/tests/client/compiler/compiler.regex.test.ripple +10 -8
- package/tests/client/composite/composite.generics.test.ripple +5 -2
- package/tests/client/dynamic-elements.test.ripple +30 -1
- package/tests/client/function-overload-import.ripple +6 -7
- package/tests/client/html.test.ripple +0 -1
- package/tests/client/input-value.test.ripple +539 -469
- package/tests/client/object.test.ripple +2 -2
- package/tests/client/portal.test.ripple +3 -3
- package/tests/client/return.test.ripple +2500 -0
- package/tests/client/try.test.ripple +69 -0
- package/tests/client/typescript-generics.test.ripple +1 -1
- package/tests/client/url/url.derived.test.ripple +1 -1
- package/tests/client/url/url.parsing.test.ripple +3 -3
- package/tests/client/url/url.partial-removal.test.ripple +7 -7
- package/tests/client/url/url.reactivity.test.ripple +15 -15
- package/tests/client/url/url.serialization.test.ripple +2 -2
- package/tests/hydration/basic.test.js +23 -0
- package/tests/hydration/build-components.js +10 -4
- package/tests/hydration/compiled/client/basic.js +165 -3
- package/tests/hydration/compiled/client/for.js +1140 -23
- package/tests/hydration/compiled/client/head.js +234 -0
- package/tests/hydration/compiled/client/html.js +135 -0
- package/tests/hydration/compiled/client/portal.js +172 -0
- package/tests/hydration/compiled/client/reactivity.js +3 -1
- package/tests/hydration/compiled/client/return.js +1976 -0
- package/tests/hydration/compiled/client/switch.js +162 -0
- package/tests/hydration/compiled/server/basic.js +249 -0
- package/tests/hydration/compiled/server/events.js +1 -1
- package/tests/hydration/compiled/server/for.js +891 -1
- package/tests/hydration/compiled/server/head.js +291 -0
- package/tests/hydration/compiled/server/html.js +133 -0
- package/tests/hydration/compiled/server/if.js +1 -1
- package/tests/hydration/compiled/server/portal.js +250 -0
- package/tests/hydration/compiled/server/reactivity.js +1 -1
- package/tests/hydration/compiled/server/return.js +1969 -0
- package/tests/hydration/compiled/server/switch.js +130 -0
- package/tests/hydration/components/basic.ripple +55 -0
- package/tests/hydration/components/for.ripple +403 -0
- package/tests/hydration/components/head.ripple +111 -0
- package/tests/hydration/components/html.ripple +38 -0
- package/tests/hydration/components/portal.ripple +49 -0
- package/tests/hydration/components/return.ripple +564 -0
- package/tests/hydration/components/switch.ripple +51 -0
- package/tests/hydration/for.test.js +363 -0
- package/tests/hydration/head.test.js +105 -0
- package/tests/hydration/html.test.js +46 -0
- package/tests/hydration/portal.test.js +71 -0
- package/tests/hydration/return.test.js +544 -0
- package/tests/hydration/switch.test.js +42 -0
- package/tests/server/basic.attributes.test.ripple +1 -1
- package/tests/server/compiler.test.ripple +22 -0
- package/tests/server/composite.test.ripple +5 -2
- package/tests/server/html-nesting-validation.test.ripple +237 -0
- package/tests/server/return.test.ripple +1379 -0
- package/tests/setup-hydration.js +6 -1
- package/tests/utils/escaping.test.js +3 -1
- package/tests/utils/normalize_css_property_name.test.js +0 -1
- package/tests/utils/patterns.test.js +6 -2
- package/tests/utils/sanitize_template_string.test.js +3 -2
- package/types/server.d.ts +16 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _$_ from 'ripple/internal/server';
|
|
2
2
|
|
|
3
|
-
import { track } from 'ripple/
|
|
3
|
+
import { track } from 'ripple/server';
|
|
4
4
|
|
|
5
5
|
export function StaticForLoop(__output) {
|
|
6
6
|
_$_.push_component();
|
|
@@ -351,4 +351,894 @@ export function ForLoopComplexObjects(__output) {
|
|
|
351
351
|
|
|
352
352
|
__output.push('</div>');
|
|
353
353
|
_$_.pop_component();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export function KeyedForLoopReorder(__output) {
|
|
357
|
+
_$_.push_component();
|
|
358
|
+
|
|
359
|
+
let items = track([
|
|
360
|
+
{ id: 1, name: 'First' },
|
|
361
|
+
{ id: 2, name: 'Second' },
|
|
362
|
+
{ id: 3, name: 'Third' }
|
|
363
|
+
]);
|
|
364
|
+
|
|
365
|
+
__output.push('<button');
|
|
366
|
+
__output.push(' class="reorder"');
|
|
367
|
+
__output.push('>');
|
|
368
|
+
|
|
369
|
+
{
|
|
370
|
+
__output.push('Reorder');
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
__output.push('</button>');
|
|
374
|
+
__output.push('<ul');
|
|
375
|
+
__output.push('>');
|
|
376
|
+
|
|
377
|
+
{
|
|
378
|
+
__output.push('<!--[-->');
|
|
379
|
+
|
|
380
|
+
for (const item of _$_.get(items)) {
|
|
381
|
+
__output.push('<li');
|
|
382
|
+
__output.push(_$_.attr('class', `item-${item.id}`));
|
|
383
|
+
__output.push('>');
|
|
384
|
+
|
|
385
|
+
{
|
|
386
|
+
__output.push(_$_.escape(item.name));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
__output.push('</li>');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
__output.push('<!--]-->');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
__output.push('</ul>');
|
|
396
|
+
_$_.pop_component();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function KeyedForLoopUpdate(__output) {
|
|
400
|
+
_$_.push_component();
|
|
401
|
+
|
|
402
|
+
let items = track([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }]);
|
|
403
|
+
|
|
404
|
+
__output.push('<button');
|
|
405
|
+
__output.push(' class="update"');
|
|
406
|
+
__output.push('>');
|
|
407
|
+
|
|
408
|
+
{
|
|
409
|
+
__output.push('Update');
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
__output.push('</button>');
|
|
413
|
+
__output.push('<ul');
|
|
414
|
+
__output.push('>');
|
|
415
|
+
|
|
416
|
+
{
|
|
417
|
+
__output.push('<!--[-->');
|
|
418
|
+
|
|
419
|
+
for (const item of _$_.get(items)) {
|
|
420
|
+
__output.push('<li');
|
|
421
|
+
__output.push(_$_.attr('class', `item-${item.id}`));
|
|
422
|
+
__output.push('>');
|
|
423
|
+
|
|
424
|
+
{
|
|
425
|
+
__output.push(_$_.escape(item.name));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
__output.push('</li>');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
__output.push('<!--]-->');
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
__output.push('</ul>');
|
|
435
|
+
_$_.pop_component();
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export function ForLoopMixedOperations(__output) {
|
|
439
|
+
_$_.push_component();
|
|
440
|
+
|
|
441
|
+
let items = track(['A', 'B', 'C', 'D']);
|
|
442
|
+
|
|
443
|
+
__output.push('<button');
|
|
444
|
+
__output.push(' class="shuffle"');
|
|
445
|
+
__output.push('>');
|
|
446
|
+
|
|
447
|
+
{
|
|
448
|
+
__output.push('Shuffle');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
__output.push('</button>');
|
|
452
|
+
__output.push('<ul');
|
|
453
|
+
__output.push('>');
|
|
454
|
+
|
|
455
|
+
{
|
|
456
|
+
__output.push('<!--[-->');
|
|
457
|
+
|
|
458
|
+
for (const item of _$_.get(items)) {
|
|
459
|
+
__output.push('<li');
|
|
460
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
461
|
+
__output.push('>');
|
|
462
|
+
|
|
463
|
+
{
|
|
464
|
+
__output.push(_$_.escape(item));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
__output.push('</li>');
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
__output.push('<!--]-->');
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
__output.push('</ul>');
|
|
474
|
+
_$_.pop_component();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export function ForLoopInsideIf(__output) {
|
|
478
|
+
_$_.push_component();
|
|
479
|
+
|
|
480
|
+
let showList = track(true);
|
|
481
|
+
let items = track(['X', 'Y', 'Z']);
|
|
482
|
+
|
|
483
|
+
__output.push('<button');
|
|
484
|
+
__output.push(' class="toggle"');
|
|
485
|
+
__output.push('>');
|
|
486
|
+
|
|
487
|
+
{
|
|
488
|
+
__output.push('Toggle List');
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
__output.push('</button>');
|
|
492
|
+
__output.push('<button');
|
|
493
|
+
__output.push(' class="add"');
|
|
494
|
+
__output.push('>');
|
|
495
|
+
|
|
496
|
+
{
|
|
497
|
+
__output.push('Add Item');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
__output.push('</button>');
|
|
501
|
+
__output.push('<!--[-->');
|
|
502
|
+
|
|
503
|
+
if (_$_.get(showList)) {
|
|
504
|
+
__output.push('<ul');
|
|
505
|
+
__output.push(' class="list"');
|
|
506
|
+
__output.push('>');
|
|
507
|
+
|
|
508
|
+
{
|
|
509
|
+
__output.push('<!--[-->');
|
|
510
|
+
|
|
511
|
+
for (const item of _$_.get(items)) {
|
|
512
|
+
__output.push('<li');
|
|
513
|
+
__output.push('>');
|
|
514
|
+
|
|
515
|
+
{
|
|
516
|
+
__output.push(_$_.escape(item));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
__output.push('</li>');
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
__output.push('<!--]-->');
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
__output.push('</ul>');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
__output.push('<!--]-->');
|
|
529
|
+
_$_.pop_component();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function ForLoopEmptyToPopulated(__output) {
|
|
533
|
+
_$_.push_component();
|
|
534
|
+
|
|
535
|
+
let items = track([]);
|
|
536
|
+
|
|
537
|
+
__output.push('<button');
|
|
538
|
+
__output.push(' class="populate"');
|
|
539
|
+
__output.push('>');
|
|
540
|
+
|
|
541
|
+
{
|
|
542
|
+
__output.push('Populate');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
__output.push('</button>');
|
|
546
|
+
__output.push('<ul');
|
|
547
|
+
__output.push(' class="list"');
|
|
548
|
+
__output.push('>');
|
|
549
|
+
|
|
550
|
+
{
|
|
551
|
+
__output.push('<!--[-->');
|
|
552
|
+
|
|
553
|
+
for (const item of _$_.get(items)) {
|
|
554
|
+
__output.push('<li');
|
|
555
|
+
__output.push('>');
|
|
556
|
+
|
|
557
|
+
{
|
|
558
|
+
__output.push(_$_.escape(item));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
__output.push('</li>');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
__output.push('<!--]-->');
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
__output.push('</ul>');
|
|
568
|
+
_$_.pop_component();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export function ForLoopPopulatedToEmpty(__output) {
|
|
572
|
+
_$_.push_component();
|
|
573
|
+
|
|
574
|
+
let items = track(['One', 'Two', 'Three']);
|
|
575
|
+
|
|
576
|
+
__output.push('<button');
|
|
577
|
+
__output.push(' class="clear"');
|
|
578
|
+
__output.push('>');
|
|
579
|
+
|
|
580
|
+
{
|
|
581
|
+
__output.push('Clear');
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
__output.push('</button>');
|
|
585
|
+
__output.push('<ul');
|
|
586
|
+
__output.push(' class="list"');
|
|
587
|
+
__output.push('>');
|
|
588
|
+
|
|
589
|
+
{
|
|
590
|
+
__output.push('<!--[-->');
|
|
591
|
+
|
|
592
|
+
for (const item of _$_.get(items)) {
|
|
593
|
+
__output.push('<li');
|
|
594
|
+
__output.push('>');
|
|
595
|
+
|
|
596
|
+
{
|
|
597
|
+
__output.push(_$_.escape(item));
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
__output.push('</li>');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
__output.push('<!--]-->');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
__output.push('</ul>');
|
|
607
|
+
_$_.pop_component();
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export function NestedForLoopReactive(__output) {
|
|
611
|
+
_$_.push_component();
|
|
612
|
+
|
|
613
|
+
let grid = track([[1, 2], [3, 4]]);
|
|
614
|
+
|
|
615
|
+
__output.push('<button');
|
|
616
|
+
__output.push(' class="add-row"');
|
|
617
|
+
__output.push('>');
|
|
618
|
+
|
|
619
|
+
{
|
|
620
|
+
__output.push('Add Row');
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
__output.push('</button>');
|
|
624
|
+
__output.push('<button');
|
|
625
|
+
__output.push(' class="update-cell"');
|
|
626
|
+
__output.push('>');
|
|
627
|
+
|
|
628
|
+
{
|
|
629
|
+
__output.push('Update Cell');
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
__output.push('</button>');
|
|
633
|
+
__output.push('<div');
|
|
634
|
+
__output.push(' class="grid"');
|
|
635
|
+
__output.push('>');
|
|
636
|
+
|
|
637
|
+
{
|
|
638
|
+
__output.push('<!--[-->');
|
|
639
|
+
|
|
640
|
+
var rowIndex = 0;
|
|
641
|
+
|
|
642
|
+
for (const row of _$_.get(grid)) {
|
|
643
|
+
__output.push('<div');
|
|
644
|
+
__output.push(_$_.attr('class', `row-${rowIndex}`));
|
|
645
|
+
__output.push('>');
|
|
646
|
+
|
|
647
|
+
{
|
|
648
|
+
__output.push('<!--[-->');
|
|
649
|
+
|
|
650
|
+
var colIndex = 0;
|
|
651
|
+
|
|
652
|
+
for (const cell of row) {
|
|
653
|
+
__output.push('<span');
|
|
654
|
+
__output.push(_$_.attr('class', `cell-${rowIndex}-${colIndex}`));
|
|
655
|
+
__output.push('>');
|
|
656
|
+
|
|
657
|
+
{
|
|
658
|
+
__output.push(_$_.escape(cell));
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
__output.push('</span>');
|
|
662
|
+
colIndex++;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
__output.push('<!--]-->');
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
__output.push('</div>');
|
|
669
|
+
rowIndex++;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
__output.push('<!--]-->');
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
__output.push('</div>');
|
|
676
|
+
_$_.pop_component();
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
export function ForLoopDeeplyNested(__output) {
|
|
680
|
+
_$_.push_component();
|
|
681
|
+
|
|
682
|
+
const departments = [
|
|
683
|
+
{
|
|
684
|
+
id: 'd1',
|
|
685
|
+
name: 'Engineering',
|
|
686
|
+
|
|
687
|
+
teams: [
|
|
688
|
+
{ id: 't1', name: 'Frontend', members: ['Alice', 'Bob'] },
|
|
689
|
+
{ id: 't2', name: 'Backend', members: ['Charlie'] }
|
|
690
|
+
]
|
|
691
|
+
},
|
|
692
|
+
|
|
693
|
+
{
|
|
694
|
+
id: 'd2',
|
|
695
|
+
name: 'Design',
|
|
696
|
+
teams: [{ id: 't3', name: 'UX', members: ['Diana', 'Eve', 'Frank'] }]
|
|
697
|
+
}
|
|
698
|
+
];
|
|
699
|
+
|
|
700
|
+
__output.push('<div');
|
|
701
|
+
__output.push(' class="org"');
|
|
702
|
+
__output.push('>');
|
|
703
|
+
|
|
704
|
+
{
|
|
705
|
+
__output.push('<!--[-->');
|
|
706
|
+
|
|
707
|
+
for (const dept of departments) {
|
|
708
|
+
__output.push('<div');
|
|
709
|
+
__output.push(_$_.attr('class', `dept-${dept.id}`));
|
|
710
|
+
__output.push('>');
|
|
711
|
+
|
|
712
|
+
{
|
|
713
|
+
__output.push('<h2');
|
|
714
|
+
__output.push(' class="dept-name"');
|
|
715
|
+
__output.push('>');
|
|
716
|
+
|
|
717
|
+
{
|
|
718
|
+
__output.push(_$_.escape(dept.name));
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
__output.push('</h2>');
|
|
722
|
+
__output.push('<!--[-->');
|
|
723
|
+
|
|
724
|
+
for (const team of dept.teams) {
|
|
725
|
+
__output.push('<div');
|
|
726
|
+
__output.push(_$_.attr('class', `team-${team.id}`));
|
|
727
|
+
__output.push('>');
|
|
728
|
+
|
|
729
|
+
{
|
|
730
|
+
__output.push('<h3');
|
|
731
|
+
__output.push(' class="team-name"');
|
|
732
|
+
__output.push('>');
|
|
733
|
+
|
|
734
|
+
{
|
|
735
|
+
__output.push(_$_.escape(team.name));
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
__output.push('</h3>');
|
|
739
|
+
__output.push('<ul');
|
|
740
|
+
__output.push('>');
|
|
741
|
+
|
|
742
|
+
{
|
|
743
|
+
__output.push('<!--[-->');
|
|
744
|
+
|
|
745
|
+
for (const member of team.members) {
|
|
746
|
+
__output.push('<li');
|
|
747
|
+
__output.push(' class="member"');
|
|
748
|
+
__output.push('>');
|
|
749
|
+
|
|
750
|
+
{
|
|
751
|
+
__output.push(_$_.escape(member));
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
__output.push('</li>');
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
__output.push('<!--]-->');
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
__output.push('</ul>');
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
__output.push('</div>');
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
__output.push('<!--]-->');
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
__output.push('</div>');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
__output.push('<!--]-->');
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
__output.push('</div>');
|
|
776
|
+
_$_.pop_component();
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export function ForLoopIndexUpdate(__output) {
|
|
780
|
+
_$_.push_component();
|
|
781
|
+
|
|
782
|
+
let items = track(['First', 'Second', 'Third']);
|
|
783
|
+
|
|
784
|
+
__output.push('<button');
|
|
785
|
+
__output.push(' class="prepend"');
|
|
786
|
+
__output.push('>');
|
|
787
|
+
|
|
788
|
+
{
|
|
789
|
+
__output.push('Prepend');
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
__output.push('</button>');
|
|
793
|
+
__output.push('<ul');
|
|
794
|
+
__output.push('>');
|
|
795
|
+
|
|
796
|
+
{
|
|
797
|
+
__output.push('<!--[-->');
|
|
798
|
+
|
|
799
|
+
var i = 0;
|
|
800
|
+
|
|
801
|
+
for (const item of _$_.get(items)) {
|
|
802
|
+
__output.push('<li');
|
|
803
|
+
__output.push(_$_.attr('class', `item-${i}`));
|
|
804
|
+
__output.push('>');
|
|
805
|
+
|
|
806
|
+
{
|
|
807
|
+
__output.push(_$_.escape(`[${i}] ${item}`));
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
__output.push('</li>');
|
|
811
|
+
i++;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
__output.push('<!--]-->');
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
__output.push('</ul>');
|
|
818
|
+
_$_.pop_component();
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export function KeyedForLoopWithIndex(__output) {
|
|
822
|
+
_$_.push_component();
|
|
823
|
+
|
|
824
|
+
let items = track([
|
|
825
|
+
{ id: 'a', value: 'Alpha' },
|
|
826
|
+
{ id: 'b', value: 'Beta' },
|
|
827
|
+
{ id: 'c', value: 'Gamma' }
|
|
828
|
+
]);
|
|
829
|
+
|
|
830
|
+
__output.push('<button');
|
|
831
|
+
__output.push(' class="reorder"');
|
|
832
|
+
__output.push('>');
|
|
833
|
+
|
|
834
|
+
{
|
|
835
|
+
__output.push('Rotate');
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
__output.push('</button>');
|
|
839
|
+
__output.push('<ul');
|
|
840
|
+
__output.push('>');
|
|
841
|
+
|
|
842
|
+
{
|
|
843
|
+
__output.push('<!--[-->');
|
|
844
|
+
|
|
845
|
+
var i = 0;
|
|
846
|
+
|
|
847
|
+
for (const item of _$_.get(items)) {
|
|
848
|
+
__output.push('<li');
|
|
849
|
+
__output.push(_$_.attr('data-index', i, false));
|
|
850
|
+
__output.push(_$_.attr('class', `item-${item.id}`));
|
|
851
|
+
__output.push('>');
|
|
852
|
+
|
|
853
|
+
{
|
|
854
|
+
__output.push(_$_.escape(`[${i}] ${item.id}: ${item.value}`));
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
__output.push('</li>');
|
|
858
|
+
i++;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
__output.push('<!--]-->');
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
__output.push('</ul>');
|
|
865
|
+
_$_.pop_component();
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export function ForLoopWithSiblings(__output) {
|
|
869
|
+
_$_.push_component();
|
|
870
|
+
|
|
871
|
+
let items = track(['A', 'B']);
|
|
872
|
+
|
|
873
|
+
__output.push('<div');
|
|
874
|
+
__output.push(' class="wrapper"');
|
|
875
|
+
__output.push('>');
|
|
876
|
+
|
|
877
|
+
{
|
|
878
|
+
__output.push('<header');
|
|
879
|
+
__output.push(' class="before"');
|
|
880
|
+
__output.push('>');
|
|
881
|
+
|
|
882
|
+
{
|
|
883
|
+
__output.push('Before');
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
__output.push('</header>');
|
|
887
|
+
__output.push('<!--[-->');
|
|
888
|
+
|
|
889
|
+
for (const item of _$_.get(items)) {
|
|
890
|
+
__output.push('<div');
|
|
891
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
892
|
+
__output.push('>');
|
|
893
|
+
|
|
894
|
+
{
|
|
895
|
+
__output.push(_$_.escape(item));
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
__output.push('</div>');
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
__output.push('<!--]-->');
|
|
902
|
+
__output.push('<footer');
|
|
903
|
+
__output.push(' class="after"');
|
|
904
|
+
__output.push('>');
|
|
905
|
+
|
|
906
|
+
{
|
|
907
|
+
__output.push('After');
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
__output.push('</footer>');
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
__output.push('</div>');
|
|
914
|
+
__output.push('<button');
|
|
915
|
+
__output.push(' class="add"');
|
|
916
|
+
__output.push('>');
|
|
917
|
+
|
|
918
|
+
{
|
|
919
|
+
__output.push('Add');
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
__output.push('</button>');
|
|
923
|
+
_$_.pop_component();
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
export function ForLoopItemState(__output) {
|
|
927
|
+
_$_.push_component();
|
|
928
|
+
|
|
929
|
+
const initialItems = [
|
|
930
|
+
{ id: 1, text: 'Todo 1' },
|
|
931
|
+
{ id: 2, text: 'Todo 2' },
|
|
932
|
+
{ id: 3, text: 'Todo 3' }
|
|
933
|
+
];
|
|
934
|
+
|
|
935
|
+
__output.push('<div');
|
|
936
|
+
__output.push('>');
|
|
937
|
+
|
|
938
|
+
{
|
|
939
|
+
__output.push('<!--[-->');
|
|
940
|
+
|
|
941
|
+
for (const item of initialItems) {
|
|
942
|
+
{
|
|
943
|
+
const comp = TodoItem;
|
|
944
|
+
const args = [__output, { id: item.id, text: item.text }];
|
|
945
|
+
|
|
946
|
+
comp(...args);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
__output.push('<!--]-->');
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
__output.push('</div>');
|
|
954
|
+
_$_.pop_component();
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function TodoItem(__output, props) {
|
|
958
|
+
_$_.push_component();
|
|
959
|
+
|
|
960
|
+
let done = track(false);
|
|
961
|
+
|
|
962
|
+
__output.push('<div');
|
|
963
|
+
__output.push(_$_.attr('class', `todo-${props.id}`));
|
|
964
|
+
__output.push('>');
|
|
965
|
+
|
|
966
|
+
{
|
|
967
|
+
__output.push('<input');
|
|
968
|
+
__output.push(' type="checkbox"');
|
|
969
|
+
__output.push(_$_.attr('checked', _$_.get(done), true));
|
|
970
|
+
__output.push(' class="checkbox"');
|
|
971
|
+
__output.push(' />');
|
|
972
|
+
__output.push('<span');
|
|
973
|
+
__output.push(_$_.attr('class', _$_.get(done) ? 'completed' : 'pending'));
|
|
974
|
+
__output.push('>');
|
|
975
|
+
|
|
976
|
+
{
|
|
977
|
+
__output.push(_$_.escape(props.text));
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
__output.push('</span>');
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
__output.push('</div>');
|
|
984
|
+
_$_.pop_component();
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
export function ForLoopSingleItem(__output) {
|
|
988
|
+
_$_.push_component();
|
|
989
|
+
|
|
990
|
+
const items = ['Only'];
|
|
991
|
+
|
|
992
|
+
__output.push('<ul');
|
|
993
|
+
__output.push('>');
|
|
994
|
+
|
|
995
|
+
{
|
|
996
|
+
__output.push('<!--[-->');
|
|
997
|
+
|
|
998
|
+
for (const item of items) {
|
|
999
|
+
__output.push('<li');
|
|
1000
|
+
__output.push(' class="single"');
|
|
1001
|
+
__output.push('>');
|
|
1002
|
+
|
|
1003
|
+
{
|
|
1004
|
+
__output.push(_$_.escape(item));
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
__output.push('</li>');
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
__output.push('<!--]-->');
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
__output.push('</ul>');
|
|
1014
|
+
_$_.pop_component();
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
export function ForLoopAddAtBeginning(__output) {
|
|
1018
|
+
_$_.push_component();
|
|
1019
|
+
|
|
1020
|
+
let items = track(['B', 'C']);
|
|
1021
|
+
|
|
1022
|
+
__output.push('<button');
|
|
1023
|
+
__output.push(' class="prepend"');
|
|
1024
|
+
__output.push('>');
|
|
1025
|
+
|
|
1026
|
+
{
|
|
1027
|
+
__output.push('Prepend A');
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
__output.push('</button>');
|
|
1031
|
+
__output.push('<ul');
|
|
1032
|
+
__output.push('>');
|
|
1033
|
+
|
|
1034
|
+
{
|
|
1035
|
+
__output.push('<!--[-->');
|
|
1036
|
+
|
|
1037
|
+
for (const item of _$_.get(items)) {
|
|
1038
|
+
__output.push('<li');
|
|
1039
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
1040
|
+
__output.push('>');
|
|
1041
|
+
|
|
1042
|
+
{
|
|
1043
|
+
__output.push(_$_.escape(item));
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
__output.push('</li>');
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
__output.push('<!--]-->');
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
__output.push('</ul>');
|
|
1053
|
+
_$_.pop_component();
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
export function ForLoopAddInMiddle(__output) {
|
|
1057
|
+
_$_.push_component();
|
|
1058
|
+
|
|
1059
|
+
let items = track(['A', 'C']);
|
|
1060
|
+
|
|
1061
|
+
__output.push('<button');
|
|
1062
|
+
__output.push(' class="insert"');
|
|
1063
|
+
__output.push('>');
|
|
1064
|
+
|
|
1065
|
+
{
|
|
1066
|
+
__output.push('Insert B');
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
__output.push('</button>');
|
|
1070
|
+
__output.push('<ul');
|
|
1071
|
+
__output.push('>');
|
|
1072
|
+
|
|
1073
|
+
{
|
|
1074
|
+
__output.push('<!--[-->');
|
|
1075
|
+
|
|
1076
|
+
for (const item of _$_.get(items)) {
|
|
1077
|
+
__output.push('<li');
|
|
1078
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
1079
|
+
__output.push('>');
|
|
1080
|
+
|
|
1081
|
+
{
|
|
1082
|
+
__output.push(_$_.escape(item));
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
__output.push('</li>');
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
__output.push('<!--]-->');
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
__output.push('</ul>');
|
|
1092
|
+
_$_.pop_component();
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
export function ForLoopRemoveFromMiddle(__output) {
|
|
1096
|
+
_$_.push_component();
|
|
1097
|
+
|
|
1098
|
+
let items = track(['A', 'B', 'C']);
|
|
1099
|
+
|
|
1100
|
+
__output.push('<button');
|
|
1101
|
+
__output.push(' class="remove-middle"');
|
|
1102
|
+
__output.push('>');
|
|
1103
|
+
|
|
1104
|
+
{
|
|
1105
|
+
__output.push('Remove B');
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
__output.push('</button>');
|
|
1109
|
+
__output.push('<ul');
|
|
1110
|
+
__output.push('>');
|
|
1111
|
+
|
|
1112
|
+
{
|
|
1113
|
+
__output.push('<!--[-->');
|
|
1114
|
+
|
|
1115
|
+
for (const item of _$_.get(items)) {
|
|
1116
|
+
__output.push('<li');
|
|
1117
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
1118
|
+
__output.push('>');
|
|
1119
|
+
|
|
1120
|
+
{
|
|
1121
|
+
__output.push(_$_.escape(item));
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
__output.push('</li>');
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
__output.push('<!--]-->');
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
__output.push('</ul>');
|
|
1131
|
+
_$_.pop_component();
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
export function ForLoopLargeList(__output) {
|
|
1135
|
+
_$_.push_component();
|
|
1136
|
+
|
|
1137
|
+
const items = Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`);
|
|
1138
|
+
|
|
1139
|
+
__output.push('<ul');
|
|
1140
|
+
__output.push(' class="large-list"');
|
|
1141
|
+
__output.push('>');
|
|
1142
|
+
|
|
1143
|
+
{
|
|
1144
|
+
__output.push('<!--[-->');
|
|
1145
|
+
|
|
1146
|
+
var i = 0;
|
|
1147
|
+
|
|
1148
|
+
for (const item of items) {
|
|
1149
|
+
__output.push('<li');
|
|
1150
|
+
__output.push(_$_.attr('class', `item-${i}`));
|
|
1151
|
+
__output.push('>');
|
|
1152
|
+
|
|
1153
|
+
{
|
|
1154
|
+
__output.push(_$_.escape(item));
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
__output.push('</li>');
|
|
1158
|
+
i++;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
__output.push('<!--]-->');
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
__output.push('</ul>');
|
|
1165
|
+
_$_.pop_component();
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
export function ForLoopSwap(__output) {
|
|
1169
|
+
_$_.push_component();
|
|
1170
|
+
|
|
1171
|
+
let items = track(['A', 'B', 'C', 'D']);
|
|
1172
|
+
|
|
1173
|
+
__output.push('<button');
|
|
1174
|
+
__output.push(' class="swap"');
|
|
1175
|
+
__output.push('>');
|
|
1176
|
+
|
|
1177
|
+
{
|
|
1178
|
+
__output.push('Swap First and Last');
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
__output.push('</button>');
|
|
1182
|
+
__output.push('<ul');
|
|
1183
|
+
__output.push('>');
|
|
1184
|
+
|
|
1185
|
+
{
|
|
1186
|
+
__output.push('<!--[-->');
|
|
1187
|
+
|
|
1188
|
+
for (const item of _$_.get(items)) {
|
|
1189
|
+
__output.push('<li');
|
|
1190
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
1191
|
+
__output.push('>');
|
|
1192
|
+
|
|
1193
|
+
{
|
|
1194
|
+
__output.push(_$_.escape(item));
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
__output.push('</li>');
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
__output.push('<!--]-->');
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
__output.push('</ul>');
|
|
1204
|
+
_$_.pop_component();
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export function ForLoopReverse(__output) {
|
|
1208
|
+
_$_.push_component();
|
|
1209
|
+
|
|
1210
|
+
let items = track(['A', 'B', 'C', 'D']);
|
|
1211
|
+
|
|
1212
|
+
__output.push('<button');
|
|
1213
|
+
__output.push(' class="reverse"');
|
|
1214
|
+
__output.push('>');
|
|
1215
|
+
|
|
1216
|
+
{
|
|
1217
|
+
__output.push('Reverse');
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
__output.push('</button>');
|
|
1221
|
+
__output.push('<ul');
|
|
1222
|
+
__output.push('>');
|
|
1223
|
+
|
|
1224
|
+
{
|
|
1225
|
+
__output.push('<!--[-->');
|
|
1226
|
+
|
|
1227
|
+
for (const item of _$_.get(items)) {
|
|
1228
|
+
__output.push('<li');
|
|
1229
|
+
__output.push(_$_.attr('class', `item-${item}`));
|
|
1230
|
+
__output.push('>');
|
|
1231
|
+
|
|
1232
|
+
{
|
|
1233
|
+
__output.push(_$_.escape(item));
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
__output.push('</li>');
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
__output.push('<!--]-->');
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
__output.push('</ul>');
|
|
1243
|
+
_$_.pop_component();
|
|
354
1244
|
}
|