ftml_viewer_components/components/
paragraphs.rs

1use flams_ontology::{
2    narration::paragraphs::ParagraphKind,
3    uris::{DocumentElementURI, Name},
4};
5use flams_web_utils::inject_css;
6use leptos::{context::Provider, prelude::*};
7
8use crate::{components::counters::SectionCounters, ts::FragmentContinuation, FragmentKind};
9
10pub(super) fn paragraph<V: IntoView + 'static>(
11    kind: ParagraphKind,
12    uri: DocumentElementURI,
13    styles: Box<[Name]>,
14    children: impl FnOnce() -> V + Send + 'static,
15) -> impl IntoView {
16    inject_css("ftml-sections", include_str!("sections.css"));
17    let mut counters: SectionCounters = expect_context();
18    let style = counters.get_para(kind, &styles);
19    let prefix = match kind {
20        ParagraphKind::Assertion => Some("ftml-assertion"),
21        ParagraphKind::Definition => Some("ftml-definition"),
22        ParagraphKind::Example => Some("ftml-example"),
23        ParagraphKind::Paragraph => Some("ftml-paragraph"),
24        _ => None,
25    };
26    let cls = prefix.map(|p| {
27        let mut s = String::new();
28        s.push_str(p);
29        for style in styles {
30            s.push(' ');
31            s.push_str(p);
32            s.push('-');
33            s.push_str(style.first_name().as_ref());
34        }
35        s
36    });
37
38    view! {
39      <Provider value=counters>
40      <div class=cls style=style>{FragmentContinuation::wrap(&(uri,kind.into()) ,children())}</div>
41      </Provider>
42    }
43}
44
45pub(super) fn slide<V: IntoView + 'static>(
46    uri: DocumentElementURI,
47    children: impl FnOnce() -> V + Send + 'static,
48) -> impl IntoView {
49    inject_css("ftml-slide", include_str!("slides.css"));
50    let counters = SectionCounters::slide_inc();
51    view!(<Provider value=counters>
52      <div class="ftml-slide">{FragmentContinuation::wrap(&(uri,FragmentKind::Slide) ,children())}</div>
53  </Provider>)
54}
55
56pub(super) fn slide_number() -> impl IntoView {
57    let v = SectionCounters::get_slide();
58    move || v.get()
59}
60/*
61pub(super) fn skip_slides(uri:&DocumentURI,id:&str) -> Option<u32> {
62  let ctw = expect_context::<RwSignal::<Option<Vec<TOCElem>>>>();
63  ctw.with(|v| v.as_ref().and_then(|v| {
64    leptos::logging::log!("TOC: {v:?}");
65    v.iter_elems().find_map(|e|
66      if let TOCElem::Inputref{uri:u,id:i,children,..} = e {
67        if u == uri && i == id {
68          Some(children.iter_elems().filter(|e| matches!(e ,TOCElem::Slide{..})).count() as u32)
69        } else { None }
70      } else { None }
71    )
72}))
73}
74 */