jacquard_api/pub_leaflet/blocks/
unordered_list.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13
14#[allow(unused_imports)]
15use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
16use jacquard_derive::{IntoStatic, lexicon, open_union};
17use jacquard_lexicon::lexicon::LexiconDoc;
18use jacquard_lexicon::schema::LexiconSchema;
19
20#[allow(unused_imports)]
21use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
22use serde::{Serialize, Deserialize};
23use crate::pub_leaflet::blocks::header::Header;
24use crate::pub_leaflet::blocks::image::Image;
25use crate::pub_leaflet::blocks::ordered_list::OrderedList;
26use crate::pub_leaflet::blocks::text::Text;
27use crate::pub_leaflet::blocks::unordered_list;
28
29#[lexicon]
30#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
31#[serde(rename_all = "camelCase")]
32pub struct ListItem<'a> {
33 #[serde(skip_serializing_if = "Option::is_none")]
35 #[serde(borrow)]
36 pub children: Option<Vec<unordered_list::ListItem<'a>>>,
37 #[serde(borrow)]
38 pub content: ListItemContent<'a>,
39 #[serde(skip_serializing_if = "Option::is_none")]
41 #[serde(borrow)]
42 pub ordered_list_children: Option<OrderedList<'a>>,
43}
44
45
46#[open_union]
47#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
48#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
49pub enum ListItemContent<'a> {
50 #[serde(rename = "pub.leaflet.blocks.text")]
51 Text(Box<Text<'a>>),
52 #[serde(rename = "pub.leaflet.blocks.header")]
53 Header(Box<Header<'a>>),
54 #[serde(rename = "pub.leaflet.blocks.image")]
55 Image(Box<Image<'a>>),
56}
57
58
59#[lexicon]
60#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
61#[serde(rename_all = "camelCase")]
62pub struct UnorderedList<'a> {
63 #[serde(borrow)]
64 pub children: Vec<unordered_list::ListItem<'a>>,
65}
66
67impl<'a> LexiconSchema for ListItem<'a> {
68 fn nsid() -> &'static str {
69 "pub.leaflet.blocks.unorderedList"
70 }
71 fn def_name() -> &'static str {
72 "listItem"
73 }
74 fn lexicon_doc() -> LexiconDoc<'static> {
75 lexicon_doc_pub_leaflet_blocks_unorderedList()
76 }
77 fn validate(&self) -> Result<(), ConstraintError> {
78 Ok(())
79 }
80}
81
82impl<'a> LexiconSchema for UnorderedList<'a> {
83 fn nsid() -> &'static str {
84 "pub.leaflet.blocks.unorderedList"
85 }
86 fn def_name() -> &'static str {
87 "main"
88 }
89 fn lexicon_doc() -> LexiconDoc<'static> {
90 lexicon_doc_pub_leaflet_blocks_unorderedList()
91 }
92 fn validate(&self) -> Result<(), ConstraintError> {
93 Ok(())
94 }
95}
96
97pub mod list_item_state {
98
99 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
100 #[allow(unused)]
101 use ::core::marker::PhantomData;
102 mod sealed {
103 pub trait Sealed {}
104 }
105 pub trait State: sealed::Sealed {
107 type Content;
108 }
109 pub struct Empty(());
111 impl sealed::Sealed for Empty {}
112 impl State for Empty {
113 type Content = Unset;
114 }
115 pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
117 impl<S: State> sealed::Sealed for SetContent<S> {}
118 impl<S: State> State for SetContent<S> {
119 type Content = Set<members::content>;
120 }
121 #[allow(non_camel_case_types)]
123 pub mod members {
124 pub struct content(());
126 }
127}
128
129pub struct ListItemBuilder<'a, S: list_item_state::State> {
131 _state: PhantomData<fn() -> S>,
132 _fields: (
133 Option<Vec<unordered_list::ListItem<'a>>>,
134 Option<ListItemContent<'a>>,
135 Option<OrderedList<'a>>,
136 ),
137 _lifetime: PhantomData<&'a ()>,
138}
139
140impl<'a> ListItem<'a> {
141 pub fn new() -> ListItemBuilder<'a, list_item_state::Empty> {
143 ListItemBuilder::new()
144 }
145}
146
147impl<'a> ListItemBuilder<'a, list_item_state::Empty> {
148 pub fn new() -> Self {
150 ListItemBuilder {
151 _state: PhantomData,
152 _fields: (None, None, None),
153 _lifetime: PhantomData,
154 }
155 }
156}
157
158impl<'a, S: list_item_state::State> ListItemBuilder<'a, S> {
159 pub fn children(
161 mut self,
162 value: impl Into<Option<Vec<unordered_list::ListItem<'a>>>>,
163 ) -> Self {
164 self._fields.0 = value.into();
165 self
166 }
167 pub fn maybe_children(
169 mut self,
170 value: Option<Vec<unordered_list::ListItem<'a>>>,
171 ) -> Self {
172 self._fields.0 = value;
173 self
174 }
175}
176
177impl<'a, S> ListItemBuilder<'a, S>
178where
179 S: list_item_state::State,
180 S::Content: list_item_state::IsUnset,
181{
182 pub fn content(
184 mut self,
185 value: impl Into<ListItemContent<'a>>,
186 ) -> ListItemBuilder<'a, list_item_state::SetContent<S>> {
187 self._fields.1 = Option::Some(value.into());
188 ListItemBuilder {
189 _state: PhantomData,
190 _fields: self._fields,
191 _lifetime: PhantomData,
192 }
193 }
194}
195
196impl<'a, S: list_item_state::State> ListItemBuilder<'a, S> {
197 pub fn ordered_list_children(
199 mut self,
200 value: impl Into<Option<OrderedList<'a>>>,
201 ) -> Self {
202 self._fields.2 = value.into();
203 self
204 }
205 pub fn maybe_ordered_list_children(
207 mut self,
208 value: Option<OrderedList<'a>>,
209 ) -> Self {
210 self._fields.2 = value;
211 self
212 }
213}
214
215impl<'a, S> ListItemBuilder<'a, S>
216where
217 S: list_item_state::State,
218 S::Content: list_item_state::IsSet,
219{
220 pub fn build(self) -> ListItem<'a> {
222 ListItem {
223 children: self._fields.0,
224 content: self._fields.1.unwrap(),
225 ordered_list_children: self._fields.2,
226 extra_data: Default::default(),
227 }
228 }
229 pub fn build_with_data(
231 self,
232 extra_data: BTreeMap<
233 jacquard_common::deps::smol_str::SmolStr,
234 jacquard_common::types::value::Data<'a>,
235 >,
236 ) -> ListItem<'a> {
237 ListItem {
238 children: self._fields.0,
239 content: self._fields.1.unwrap(),
240 ordered_list_children: self._fields.2,
241 extra_data: Some(extra_data),
242 }
243 }
244}
245
246fn lexicon_doc_pub_leaflet_blocks_unorderedList() -> LexiconDoc<'static> {
247 #[allow(unused_imports)]
248 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
249 use jacquard_lexicon::lexicon::*;
250 use alloc::collections::BTreeMap;
251 LexiconDoc {
252 lexicon: Lexicon::Lexicon1,
253 id: CowStr::new_static("pub.leaflet.blocks.unorderedList"),
254 defs: {
255 let mut map = BTreeMap::new();
256 map.insert(
257 SmolStr::new_static("listItem"),
258 LexUserType::Object(LexObject {
259 required: Some(vec![SmolStr::new_static("content")]),
260 properties: {
261 #[allow(unused_mut)]
262 let mut map = BTreeMap::new();
263 map.insert(
264 SmolStr::new_static("children"),
265 LexObjectProperty::Array(LexArray {
266 description: Some(
267 CowStr::new_static(
268 "Nested unordered list items. Mutually exclusive with orderedListChildren; if both are present, children takes precedence.",
269 ),
270 ),
271 items: LexArrayItem::Ref(LexRef {
272 r#ref: CowStr::new_static("#listItem"),
273 ..Default::default()
274 }),
275 ..Default::default()
276 }),
277 );
278 map.insert(
279 SmolStr::new_static("content"),
280 LexObjectProperty::Union(LexRefUnion {
281 refs: vec![
282 CowStr::new_static("pub.leaflet.blocks.text"),
283 CowStr::new_static("pub.leaflet.blocks.header"),
284 CowStr::new_static("pub.leaflet.blocks.image")
285 ],
286 ..Default::default()
287 }),
288 );
289 map.insert(
290 SmolStr::new_static("orderedListChildren"),
291 LexObjectProperty::Ref(LexRef {
292 r#ref: CowStr::new_static("pub.leaflet.blocks.orderedList"),
293 ..Default::default()
294 }),
295 );
296 map
297 },
298 ..Default::default()
299 }),
300 );
301 map.insert(
302 SmolStr::new_static("main"),
303 LexUserType::Object(LexObject {
304 required: Some(vec![SmolStr::new_static("children")]),
305 properties: {
306 #[allow(unused_mut)]
307 let mut map = BTreeMap::new();
308 map.insert(
309 SmolStr::new_static("children"),
310 LexObjectProperty::Array(LexArray {
311 items: LexArrayItem::Ref(LexRef {
312 r#ref: CowStr::new_static("#listItem"),
313 ..Default::default()
314 }),
315 ..Default::default()
316 }),
317 );
318 map
319 },
320 ..Default::default()
321 }),
322 );
323 map
324 },
325 ..Default::default()
326 }
327}
328
329pub mod unordered_list_state {
330
331 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
332 #[allow(unused)]
333 use ::core::marker::PhantomData;
334 mod sealed {
335 pub trait Sealed {}
336 }
337 pub trait State: sealed::Sealed {
339 type Children;
340 }
341 pub struct Empty(());
343 impl sealed::Sealed for Empty {}
344 impl State for Empty {
345 type Children = Unset;
346 }
347 pub struct SetChildren<S: State = Empty>(PhantomData<fn() -> S>);
349 impl<S: State> sealed::Sealed for SetChildren<S> {}
350 impl<S: State> State for SetChildren<S> {
351 type Children = Set<members::children>;
352 }
353 #[allow(non_camel_case_types)]
355 pub mod members {
356 pub struct children(());
358 }
359}
360
361pub struct UnorderedListBuilder<'a, S: unordered_list_state::State> {
363 _state: PhantomData<fn() -> S>,
364 _fields: (Option<Vec<unordered_list::ListItem<'a>>>,),
365 _lifetime: PhantomData<&'a ()>,
366}
367
368impl<'a> UnorderedList<'a> {
369 pub fn new() -> UnorderedListBuilder<'a, unordered_list_state::Empty> {
371 UnorderedListBuilder::new()
372 }
373}
374
375impl<'a> UnorderedListBuilder<'a, unordered_list_state::Empty> {
376 pub fn new() -> Self {
378 UnorderedListBuilder {
379 _state: PhantomData,
380 _fields: (None,),
381 _lifetime: PhantomData,
382 }
383 }
384}
385
386impl<'a, S> UnorderedListBuilder<'a, S>
387where
388 S: unordered_list_state::State,
389 S::Children: unordered_list_state::IsUnset,
390{
391 pub fn children(
393 mut self,
394 value: impl Into<Vec<unordered_list::ListItem<'a>>>,
395 ) -> UnorderedListBuilder<'a, unordered_list_state::SetChildren<S>> {
396 self._fields.0 = Option::Some(value.into());
397 UnorderedListBuilder {
398 _state: PhantomData,
399 _fields: self._fields,
400 _lifetime: PhantomData,
401 }
402 }
403}
404
405impl<'a, S> UnorderedListBuilder<'a, S>
406where
407 S: unordered_list_state::State,
408 S::Children: unordered_list_state::IsSet,
409{
410 pub fn build(self) -> UnorderedList<'a> {
412 UnorderedList {
413 children: self._fields.0.unwrap(),
414 extra_data: Default::default(),
415 }
416 }
417 pub fn build_with_data(
419 self,
420 extra_data: BTreeMap<
421 jacquard_common::deps::smol_str::SmolStr,
422 jacquard_common::types::value::Data<'a>,
423 >,
424 ) -> UnorderedList<'a> {
425 UnorderedList {
426 children: self._fields.0.unwrap(),
427 extra_data: Some(extra_data),
428 }
429 }
430}