|
1 | | -// ignore_for_file: deprecated_member_use |
2 | | - |
3 | 1 | part of '../html.dart'; |
4 | 2 |
|
5 | 3 | const kColumns = 3; |
6 | 4 | const kSpacing = 3.0; |
7 | 5 |
|
8 | 6 | class Galleria { |
9 | | - final BuildMetadata galleryMeta; |
| 7 | + final BuildTree galleryTree; |
10 | 8 | final TinhteWidgetFactory wf; |
11 | 9 |
|
| 10 | + final _items = <WidgetPlaceholder>[]; |
12 | 11 | final _lb = LbTrigger(); |
13 | 12 |
|
14 | | - Galleria(this.wf, this.galleryMeta); |
| 13 | + Galleria(this.wf, this.galleryTree); |
15 | 14 |
|
16 | 15 | BuildOp? _galleriaOp; |
17 | 16 | BuildOp get op { |
18 | | - return _galleriaOp ??= BuildOp( |
| 17 | + return _galleriaOp ??= BuildOp.v1( |
19 | 18 | onChild: onChild, |
20 | | - onWidgets: onWidgets, |
| 19 | + onRenderBlock: onRenderBlock, |
21 | 20 | ); |
22 | 21 | } |
23 | 22 |
|
24 | | - void onChild(BuildMetadata childMeta) { |
25 | | - final e = childMeta.element; |
26 | | - if (e.parent != galleryMeta.element) return; |
| 23 | + void onChild(BuildTree _, BuildTree subTree) { |
| 24 | + final e = subTree.element; |
| 25 | + if (e.parent != galleryTree.element) return; |
27 | 26 | if (e.localName != 'li') return; |
28 | | - |
29 | | - childMeta.register(_GalleriaItem(wf, this, childMeta).op); |
| 27 | + subTree.register(_GalleriaItem(wf, this, subTree).op); |
30 | 28 | } |
31 | 29 |
|
32 | | - Iterable<Widget> onWidgets( |
33 | | - BuildMetadata _, Iterable<WidgetPlaceholder> widgets) => |
34 | | - [ |
35 | | - WidgetPlaceholder<Galleria>(this, |
36 | | - child: _GalleriaGrid(widgets.toList(growable: false))) |
37 | | - ]; |
| 30 | + Widget onRenderBlock(BuildTree _, WidgetPlaceholder placeholder) => |
| 31 | + _items.isNotEmpty ? _GalleriaGrid(_items) : placeholder; |
38 | 32 | } |
39 | 33 |
|
40 | 34 | class _GalleriaItem { |
41 | | - final BuildMetadata itemMeta; |
| 35 | + final BuildTree itemTree; |
42 | 36 | final Galleria galleria; |
43 | 37 | final WidgetFactory wf; |
44 | 38 |
|
45 | 39 | Widget? _description; |
46 | 40 | BuildOp? _descriptionOp; |
47 | 41 | String? _source; |
48 | | - WidgetPlaceholder? _trigger; |
| 42 | + Widget? _trigger; |
49 | 43 | BuildOp? _triggerOp; |
50 | 44 |
|
51 | | - _GalleriaItem(this.wf, this.galleria, this.itemMeta); |
| 45 | + _GalleriaItem(this.wf, this.galleria, this.itemTree); |
52 | 46 |
|
53 | 47 | BuildOp? _itemOp; |
54 | 48 | BuildOp get op { |
55 | | - return _itemOp ??= BuildOp( |
| 49 | + return _itemOp ??= BuildOp.v1( |
56 | 50 | onChild: onChild, |
57 | | - onWidgets: onWidgets, |
| 51 | + onRenderBlock: onRenderBlock, |
58 | 52 | ); |
59 | 53 | } |
60 | 54 |
|
61 | | - void onChild(BuildMetadata childMeta) { |
62 | | - final e = childMeta.element; |
63 | | - if (e.parent != itemMeta.element) return; |
| 55 | + void onChild(BuildTree _, BuildTree subSubTree) { |
| 56 | + final e = subSubTree.element; |
| 57 | + if (e.parent != itemTree.element) return; |
64 | 58 |
|
65 | 59 | switch (e.className) { |
66 | 60 | case 'LbTrigger': |
67 | 61 | _source ??= wf.urlFull(e.attributes['href'] ?? ''); |
68 | | - final triggerOp = _triggerOp ??= BuildOp( |
69 | | - onWidgets: (meta, widgets) { |
70 | | - // bypass built-in A tag handling with 0 priority |
71 | | - // and NOT returning anything in `onWidgets` |
72 | | - _trigger = wf.buildColumnPlaceholder(meta, widgets); |
73 | | - return []; |
74 | | - }, |
75 | | - priority: 0, |
| 62 | + final triggerOp = _triggerOp ??= BuildOp.v1( |
| 63 | + alwaysRenderBlock: true, |
| 64 | + onRenderedBlock: (_, block) => _trigger = block, |
76 | 65 | ); |
77 | | - childMeta.register(triggerOp); |
| 66 | + subSubTree.register(triggerOp); |
78 | 67 | break; |
79 | 68 | case 'Tinhte_Gallery_Description': |
80 | | - final descriptionOp = _descriptionOp ??= BuildOp( |
81 | | - onWidgets: (meta, widgets) { |
82 | | - meta.tsb.enqueue((p, dynamic _) => p.copyWith( |
83 | | - style: p |
84 | | - .getDependency<ThemeData>() |
85 | | - .textTheme |
86 | | - .bodySmall |
87 | | - ?.copyWith(color: kCaptionColor))); |
88 | | - _description = wf.buildColumnPlaceholder(meta, widgets); |
89 | | - return []; |
| 69 | + final descriptionOp = _descriptionOp ??= BuildOp.v1( |
| 70 | + alwaysRenderBlock: true, |
| 71 | + onParsed: (descriptionTree) { |
| 72 | + return descriptionTree |
| 73 | + ..apply<BuildContext?>( |
| 74 | + (style, context) => style.copyWith( |
| 75 | + textStyle: Theme.of(context!) |
| 76 | + .textTheme |
| 77 | + .bodySmall |
| 78 | + ?.copyWith(color: kCaptionColor), |
| 79 | + ), |
| 80 | + null, |
| 81 | + ); |
90 | 82 | }, |
| 83 | + onRenderedBlock: (_, block) => _description = block, |
91 | 84 | ); |
92 | | - childMeta.register(descriptionOp); |
| 85 | + subSubTree.register(descriptionOp); |
93 | 86 | break; |
94 | 87 | } |
95 | 88 | } |
96 | 89 |
|
97 | | - Iterable<Widget> onWidgets( |
98 | | - BuildMetadata _, Iterable<WidgetPlaceholder> widgets) { |
| 90 | + Widget onRenderBlock(BuildTree _, WidgetPlaceholder placeholder) { |
99 | 91 | final scopedSource = _source; |
100 | 92 | final scopedTrigger = _trigger; |
101 | | - if (scopedSource == null || scopedTrigger == null) return widgets; |
| 93 | + if (scopedSource == null || scopedTrigger == null) return placeholder; |
102 | 94 |
|
103 | 95 | final index = galleria._lb.addSource( |
104 | 96 | LbTriggerSource.image(scopedSource), |
105 | 97 | caption: _description, |
106 | 98 | ); |
107 | | - scopedTrigger.wrapWith((context, child) => |
108 | | - galleria._lb.buildGestureDetector(context, child, index)); |
109 | 99 |
|
110 | | - return [scopedTrigger]; |
| 100 | + galleria._items.add( |
| 101 | + WidgetPlaceholder.lazy( |
| 102 | + scopedTrigger, |
| 103 | + debugLabel: '${itemTree.element.localName}--galleriaItem', |
| 104 | + ).wrapWith( |
| 105 | + (context, child) => |
| 106 | + galleria._lb.buildGestureDetector(context, child, index), |
| 107 | + ), |
| 108 | + ); |
| 109 | + |
| 110 | + return widget0; |
111 | 111 | } |
112 | 112 | } |
113 | 113 |
|
|
0 commit comments