diff --git a/apple/Sources/Logseq/LGBottomTabStrip.swift b/apple/Sources/Logseq/LGBottomTabStrip.swift index f08c0ce8..cfc2ee9d 100644 --- a/apple/Sources/Logseq/LGBottomTabStrip.swift +++ b/apple/Sources/Logseq/LGBottomTabStrip.swift @@ -4,6 +4,11 @@ import SwiftUI import UIKit #endif +extension EnvironmentValues { + @Entry var lgPlacesTabsOnSide = false + @Entry var lgRendersSideTabs = false +} + @MainActor struct LGBottomTabStrip: View { let context: LUIAppleExtensionViewContext @@ -12,6 +17,8 @@ struct LGBottomTabStrip: View { @Environment(\.layoutDirection) private var layoutDirection @Environment(\.accessibilityReduceMotion) private var reduceMotion @Environment(\.accessibilityReduceTransparency) private var reduceTransparency + @Environment(\.lgPlacesTabsOnSide) private var placesTabsOnSide + @Environment(\.lgRendersSideTabs) private var rendersSideTabs @GestureState private var dragPosition: CGFloat? @State private var pendingSelection: Int? @State private var size: CGSize = .zero @@ -37,7 +44,9 @@ struct LGBottomTabStrip: View { @ViewBuilder var body: some View { let _ = context.revision #if os(iOS) - if #available(iOS 26.0, *), let items = nativeItems { + if rendersSideTabs, let items = nativeItems { + sideStrip(items) + } else if !placesTabsOnSide, #available(iOS 26.0, *), let items = nativeItems { let horizontalMargin: CGFloat = 21 LGNativeBottomTabBar( items: items, selectedIndex: selectedIndex, @@ -50,7 +59,7 @@ struct LGBottomTabStrip: View { .background(LGSidebarPanExclusion()) // Align the floating items within UITabBar with the trailing actions. .offset(y: 11) - } else { + } else if !placesTabsOnSide { fallbackStrip } #else @@ -93,6 +102,47 @@ struct LGBottomTabStrip: View { } #if os(iOS) + private func sideStrip(_ items: [LGNativeBottomTabBar.Item]) -> some View { + let primary = colors["foreground"] ?? .primary + let accent = colors["link"] ?? .accentColor + return VStack(spacing: 2) { + ForEach(items.indices, id: \.self) { index in + let item = items[index] + let selected = index == selectedIndex + Button { + guard context.isUserInteractionEnabled else { return } + try? context.emit(name: "select", values: ["index": .int(index)]) + } label: { + if let icon = item.icon(selected ? item.selectedImage : item.image, + foreground: UIColor(primary), accent: UIColor(accent)) { + Image(uiImage: icon) + .renderingMode(item.unread == true ? .original : .template) + .font(.system(size: 23)) + .foregroundStyle(selected ? accent : primary) + .frame(width: 44, height: 44) + .background { + if selected { indicator(dragging: false) } + } + .contentShape(Rectangle()) + } + } + .buttonStyle(.plain) + .accessibilityLabel(item.title) + .accessibilityIdentifier("tab.bottom.\(item.name)") + .accessibilityAddTraits(selected ? .isSelected : []) + .simultaneousGesture(TapGesture(count: 2).onEnded { + guard item.name == "home", context.isUserInteractionEnabled else { return } + try? context.emit(name: "home-double-tap") + }) + } + } + .padding(.horizontal, 2) + .padding(.vertical, 4) + .modifier(LGLiquidGlassSurface(shape: .capsule)) + .accessibilityElement(children: .contain) + .accessibilityIdentifier("group.side.tabs") + } + private var nativeItems: [LGNativeBottomTabBar.Item]? { guard case let .string(json) = context.property("items") else { return nil } return try? JSONDecoder().decode([LGNativeBottomTabBar.Item].self, from: Data(json.utf8)) @@ -175,7 +225,7 @@ private struct LGNativeBottomTabBar: UIViewRepresentable { item.accessibilityIdentifier = "tab.bottom.\(name)" } - @MainActor private func icon(_ iconName: String, foreground: UIColor, accent: UIColor) -> UIImage? { + @MainActor func icon(_ iconName: String, foreground: UIColor, accent: UIColor) -> UIImage? { switch LGIconPolicy.icons[iconName] { case let .systemName(symbol): if name == "notifications", diff --git a/apple/Sources/Logseq/LGDuoJournalBook.swift b/apple/Sources/Logseq/LGDuoJournalBook.swift new file mode 100644 index 00000000..24a7d140 --- /dev/null +++ b/apple/Sources/Logseq/LGDuoJournalBook.swift @@ -0,0 +1,186 @@ +#if os(iOS) +import LUIAppleBackend +import SwiftUI +import UIKit + +@available(iOS 18.0, *) +@MainActor +private struct LGDuoJournalPages: View { + let context: LUIAppleExtensionViewContext + let pages: [Int] + let width: CGFloat + let height: CGFloat + @State private var position: Int? + @Environment(\.layoutDirection) private var layoutDirection + @Environment(\.accessibilityReduceMotion) private var reduceMotion + + private var first: Int { context.property("first-index")?.intValue ?? 0 } + private var selected: Int { context.property("selected-index")?.intValue ?? 0 } + private var canTurn: Bool { context.property("can-turn") != .bool(false) } + + var body: some View { + let pageTurnAngle = reduceMotion ? 0.0 : 4.0 + ScrollView(.horizontal) { + LazyHStack(spacing: 0) { + ForEach(Array(pages.enumerated().reversed()), id: \.element) { offset, node in + context.nodeView(of: node) + .frame(width: width, height: height) + .overlay { spineShade } + .scrollTransition(.interactive, axis: .horizontal) { spread, phase in + spread.rotation3DEffect( + .degrees(-phase.value * pageTurnAngle), + axis: (x: 0, y: 1, z: 0), + anchor: phase.value < 0 ? .trailing : .leading, + perspective: 0.30 + ) + } + .environment(\.layoutDirection, layoutDirection) + .accessibilityHidden(first + offset != selected) + .id(first + offset) + } + } + .scrollTargetLayout() + .background(LGJournalPagingPan(enabled: canTurn)) + } + .defaultScrollAnchor(.trailing) + .scrollTargetBehavior(.viewAligned(limitBehavior: .alwaysByOne)) + .scrollIndicators(.hidden) + .clipped() + .scrollPosition(id: $position) + .onChange(of: selected, initial: true) { _, index in + if position != index { position = index } + } + .onScrollPhaseChange { _, phase in + if phase == .idle { select(position) } + } + .onChange(of: canTurn) { _, enabled in + if !enabled { position = selected } + } + .accessibilityScrollAction { edge in + switch edge { + case .leading: select(selected + 1) + case .trailing: select(selected - 1) + default: break + } + } + // Page positions are chronological. The notes themselves still use the app language. + .environment(\.layoutDirection, .leftToRight) + .accessibilityIdentifier("journal.duo.book") + } + + private var spineShade: some View { + LinearGradient( + stops: [ + .init(color: .clear, location: 0), + .init(color: .primary.opacity(0.07), location: 0.50), + .init(color: .clear, location: 1), + ], + startPoint: .leading, + endPoint: .trailing + ) + .frame(width: 14) + .allowsHitTesting(false) + .accessibilityHidden(true) + } + + private func select(_ index: Int?) { + guard canTurn, let index, + index != selected, (first..<(first + pages.count)).contains(index) else { return } + try? context.emit(name: "select", values: ["index": .int(index)]) + } +} + +// Suspend the horizontal gesture while leaving both notes free to scroll vertically. +private struct LGJournalPagingPan: UIViewRepresentable { + let enabled: Bool + + func makeUIView(context: Context) -> Marker { + let view = Marker() + view.isUserInteractionEnabled = false + return view + } + + func updateUIView(_ view: Marker, context: Context) { + view.enabled = enabled + view.updatePan() + } + + static func dismantleUIView(_ view: Marker, coordinator: ()) { + view.pan?.isEnabled = true + } + + final class Marker: UIView { + var enabled = true + weak var pan: UIPanGestureRecognizer? + + override func didMoveToSuperview() { + super.didMoveToSuperview() + updatePan() + } + + func updatePan() { + var ancestor = superview + while let view = ancestor { + if let scroll = view as? UIScrollView { + pan = scroll.panGestureRecognizer + pan?.isEnabled = enabled + return + } + ancestor = view.superview + } + } + } +} + +@MainActor +struct LGDuoJournalBook: View { + static let identifier = "duo-journal-book" + let context: LUIAppleExtensionViewContext + + static func register(in registry: LUIAppleExtensionRegistry) throws { + try registry.register(LUIAppleExtension( + identifier: identifier, + fingerprint: "lui-extension-v1|16:duo-journal-book|profiles:ios/swiftui|standard-children:1|children:|properties:8:can-turn:bool:required:none,11:first-index:int:required:none,14:selected-index:int:required:none|events:6:resize[5:width:int:required],6:select[5:index:int:required]", + acceptsStandardChildren: true, + properties: [ + .init(name: "can-turn", kind: .bool, isRequired: true), + .init(name: "first-index", kind: .int, isRequired: true), + .init(name: "selected-index", kind: .int, isRequired: true), + ], + events: [ + .init(name: "resize", fields: [.init(name: "width", kind: .int, isRequired: true)]), + .init(name: "select", fields: [.init(name: "index", kind: .int, isRequired: true)]), + ] + ) { AnyView(LGDuoJournalBook(context: $0)) }) + } + + var body: some View { + let _ = context.revision + let children = context.childIDs + if #available(iOS 18.0, *), LGSidebarOverlay.isDuo, children.count == 2 { + GeometryReader { geometry in + let _ = context.measureStamp(of: children[1]) + let spreads = context.childIDs(of: children[1]) + if geometry.size.width >= 600, !spreads.isEmpty { + LGDuoJournalPages(context: context, pages: spreads, + width: geometry.size.width, height: geometry.size.height) + } else { + context.content(for: children[0]) + } + } + .onGeometryChange(for: Bool.self) { $0.size.width >= 600 } action: { wide in + try? context.emit(name: "resize", values: ["width": .int(wide ? 600 : 0)]) + } + } else if let classic = children.first { + context.content(for: classic) + } + } +} + +private extension LUIExtensionValue { + var intValue: Int? { + if case let .int(value) = self { return value } + return nil + } +} +#endif diff --git a/apple/Sources/Logseq/LGNavigationExtension.swift b/apple/Sources/Logseq/LGNavigationExtension.swift index 70596e5f..385aa472 100644 --- a/apple/Sources/Logseq/LGNavigationExtension.swift +++ b/apple/Sources/Logseq/LGNavigationExtension.swift @@ -757,6 +757,9 @@ private struct LGNavigationContent: View { @Environment(\.luiSemanticColors) private var semanticColors @Environment(\.locale) private var locale @Environment(\.accessibilityReduceMotion) private var reduceMotion + #if os(iOS) + @Environment(\.horizontalSizeClass) private var horizontalSizeClass + #endif private var search: LGNativeSearchState? { toolbarStartIndex == nil ? nil : inheritedSearch } private func nativeSearchHost(_ search: LGNativeSearchState?) -> LGNativeSearchHost { @@ -768,6 +771,17 @@ private struct LGNavigationContent: View { } private var searchVisible: Bool { search?.isVisible == true } private var verticalToolbar: Bool { verticalToolbarEdge != nil } + private var usesUnfoldedDuoHeading: Bool { + #if os(iOS) + return verticalToolbar && LGSidebarOverlay.isDuo && horizontalSizeClass == .regular + #else + return false + #endif + } + + private var showsVerticalRootHeading: Bool { + verticalToolbar && toolbarStartIndex != nil && !pdfWorkspaceOpen + } private var searchRoutes: [Int] { guard searchVisible, let search else { return [] } return pageRoutes(in: search.context, depth: search.depth) @@ -799,6 +813,16 @@ private struct LGNavigationContent: View { verticalToolbar && !selectionActive && hasCollapsedComposer && captureActionIDs.count == 4 } + private var sideTabsID: Int? { + guard usesSideCaptureActions, let index = bottomChromeIndex, let chrome = childID(at: index) else { return nil } + func tabStrip(in node: Int) -> Int? { + if context.extensionIdentifier(of: node) == "bottom-tab-strip" { return node } + let _ = context.measureStamp(of: node) + return context.childIDs(of: node).lazy.compactMap(tabStrip(in:)).first + } + return tabStrip(in: chrome) + } + private var rootTitleContent: Int? { guard let toolbarStartIndex, let titleSlot = childID(at: toolbarStartIndex + 1) else { return nil } @@ -1119,14 +1143,15 @@ private struct LGNavigationContent: View { @ViewBuilder private var rootNavigationSurface: some View { let base = AnyView(transformedRootContent.safeAreaInset(edge: .top, spacing: 0) { - if verticalToolbar, toolbarStartIndex != nil { - // A principal item would create a second, horizontal bar on Duo. - let hideTitle = searchVisible || pdfWorkspaceOpen + if showsVerticalRootHeading { + // Keep the heading inside the active pane so the graph menu remains tappable. rootHeaderTitle - .frame(maxWidth: .infinity, minHeight: 44) - .opacity(hideTitle ? 0 : 1) - .allowsHitTesting(!hideTitle) - .accessibilityHidden(hideTitle) + .frame(maxWidth: .infinity, minHeight: 44, + alignment: usesUnfoldedDuoHeading ? .leading : .center) + .padding(.horizontal, 16) + .opacity(searchVisible ? 0 : 1) + .allowsHitTesting(!searchVisible) + .accessibilityHidden(searchVisible) } }) withAppTint(searchSurface(base, active: path.isEmpty)) @@ -1141,7 +1166,7 @@ private struct LGNavigationContent: View { .background { if toolbarStartIndex != nil { LGCaptureRailHost( - content: AnyView(captureRail + content: AnyView(sideControls .environment(\.luiSemanticColors, semanticColors) .environment(\.locale, locale) .environment(\.colorScheme, colorScheme)), @@ -1154,6 +1179,17 @@ private struct LGNavigationContent: View { #endif } + private var sideControls: some View { + VStack(spacing: 9) { + captureRail + if let tabs = sideTabsID { + context.nodeView(of: tabs) + .environment(\.lgRendersSideTabs, true) + } + } + .fixedSize() + } + private var captureRail: some View { VStack(spacing: 14) { ForEach(captureActionIDs, id: \.self) { actionID in @@ -1423,6 +1459,7 @@ private struct LGNavigationContent: View { private var floatingBottomChrome: some View { sizedBottomChrome .environment(\.lgUsesSideCaptureActions, usesSideCaptureActions) + .environment(\.lgPlacesTabsOnSide, sideTabsID != nil) .fixedSize(horizontal: false, vertical: true) } diff --git a/apple/Sources/Logseq/LGPDFWorkspace.swift b/apple/Sources/Logseq/LGPDFWorkspace.swift index 3b2e44bd..5a61931f 100644 --- a/apple/Sources/Logseq/LGPDFWorkspace.swift +++ b/apple/Sources/Logseq/LGPDFWorkspace.swift @@ -46,6 +46,7 @@ private struct LGPDFSplitContent: View { @State private var fraction = 0.5 @State private var isResizing = false @Environment(\.accessibilityReduceMotion) private var reduceMotion + @Environment(\.layoutDirection) private var layoutDirection var body: some View { GeometryReader { geometry in @@ -64,6 +65,7 @@ private struct LGPDFSplitContent: View { send(value) }) .frame(width: fullScreen ? geometry.size.width : width) + .environment(\.layoutDirection, layoutDirection) .accessibilityIdentifier("pdf.reader") LGPDFResizeHandle(onDelta: { delta in let current = min(max(minimum, available * fraction), available - minimum) @@ -94,6 +96,7 @@ private struct LGPDFSplitContent: View { .accessibilityHidden(fullScreen) .environment(\.lgPDFWorkspaceOpen, open) .environment(\.lgPDFMainHidden, fullScreen) + .environment(\.layoutDirection, layoutDirection) .environment(\.lgOpenPDF, { uuid, title, url in send(["action": "open", "uuid": uuid, "title": title, "path": url.path]) }) @@ -104,6 +107,9 @@ private struct LGPDFSplitContent: View { .accessibilityIdentifier(open ? "pdf.main" : "application.main") } .frame(width: geometry.size.width, height: geometry.size.height, alignment: .leading) + // The reader owns the physical left pane and the divider grows it + // to the right. Each pane still lays out its contents in the app's language. + .environment(\.layoutDirection, .leftToRight) .transaction { if isResizing { $0.disablesAnimations = true } } } } diff --git a/apple/Sources/Logseq/LGRichBlockExtension.swift b/apple/Sources/Logseq/LGRichBlockExtension.swift index b87d846b..eef26393 100644 --- a/apple/Sources/Logseq/LGRichBlockExtension.swift +++ b/apple/Sources/Logseq/LGRichBlockExtension.swift @@ -28,6 +28,7 @@ enum LGExtensionRegistry { ) try OutlinerRowExtension.register(in: registry, playback: LGYouTubePlaybackState()) #if os(iOS) + try LGDuoJournalBook.register(in: registry) try OutlinerSelectionToolbar.register(in: registry) try LGReactionPickerExtension.register(in: registry) #endif diff --git a/apple/Sources/Logseq/LGSidebarOverlay.swift b/apple/Sources/Logseq/LGSidebarOverlay.swift index be35d15b..9595fa19 100644 --- a/apple/Sources/Logseq/LGSidebarOverlay.swift +++ b/apple/Sources/Logseq/LGSidebarOverlay.swift @@ -41,7 +41,7 @@ struct LGSidebarOverlay: View { UIDevice.current.userInterfaceIdiom == .pad || Self.isDuo } - private static let isDuo: Bool = { + static let isDuo: Bool = { // Both displays on the Duo keep the existing renderer. The outer display // shares a compact size class with other phones. #if targetEnvironment(simulator) diff --git a/apple/Tests/UI/duo-toolbar-layout.swift b/apple/Tests/UI/duo-toolbar-layout.swift index 31201bdf..335e942b 100644 --- a/apple/Tests/UI/duo-toolbar-layout.swift +++ b/apple/Tests/UI/duo-toolbar-layout.swift @@ -234,12 +234,14 @@ import LogseqModel try saveScreenshot("duo-rail-misaligned.png") throw failure("Capture rail must align with the native overflow: more=\(more), actions=\(actionFrames), safeArea=\(host.view.safeAreaInsets)") } - guard let last = actionFrames.last, - window.bounds.maxY - last.maxY <= max(44, window.safeAreaInsets.bottom + 10) else { - throw failure("Capture rail must stay near the bottom edge, without a duplicate safe-area inset: \(actionFrames)") + guard let rail = views(window).first(where: { $0.accessibilityIdentifier == "navigation.capture-rail" }) else { + throw failure("Missing the shared side controls") } - guard let rail = views(window).first(where: { $0.accessibilityIdentifier == "navigation.capture-rail" }), - actionFrames.allSatisfy({ frame in + let railFrame = rail.convert(rail.bounds, to: window) + guard window.bounds.maxY - railFrame.maxY <= max(44, window.safeAreaInsets.bottom + 10) else { + throw failure("Side controls must stay near the bottom edge, without a duplicate safe-area inset: \(railFrame)") + } + guard actionFrames.allSatisfy({ frame in window.hitTest(CGPoint(x: frame.midX, y: frame.midY), with: nil)?.isDescendant(of: rail) == true }) else { throw failure("The visible side actions must receive touches at their rendered positions") diff --git a/apple/Tests/UI/pdf-workspace.swift b/apple/Tests/UI/pdf-workspace.swift index a153c11d..bc37c281 100644 --- a/apple/Tests/UI/pdf-workspace.swift +++ b/apple/Tests/UI/pdf-workspace.swift @@ -60,7 +60,8 @@ import UIKit try runtime.applyHostUpdate(kind: "graph-loading", payload: "false") let scene = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first! let window = UIWindow(windowScene: scene) - let host = UIHostingController(rootView: LGRendererRoot(renderer: runtime.renderer)) + let host = UIHostingController(rootView: LGRendererRoot(renderer: runtime.renderer) + .environment(\.layoutDirection, .rightToLeft)) window.rootViewController = host window.makeKeyAndVisible() defer { window.isHidden = true; window.rootViewController = nil; runtime.stop() } @@ -132,7 +133,9 @@ import UIKit try await wait("Resizing back must preserve the original split") { abs(pdf.bounds.width - beforeResize) < 1 } guard pdf.document === documentBeforeResize else { throw failure("Resizing must retain the PDF document") } let frame = pdf.convert(pdf.bounds, to: window) - guard frame.width > 100, frame.maxX < window.bounds.width - 100 else { + guard let originalMain, + frame.width > 100, + originalMain.convert(originalMain.bounds, to: window).minX >= frame.maxX else { throw failure("The PDF must occupy the left column and leave main on the right: \(frame)") } guard host.presentedViewController == nil else { throw failure("PDF opening must not present Quick Look or a modal") } diff --git a/shared/src/logseq/native_bridge.ml b/shared/src/logseq/native_bridge.ml index d1691fbd..9a2fc1d8 100644 --- a/shared/src/logseq/native_bridge.ml +++ b/shared/src/logseq/native_bridge.ml @@ -701,7 +701,8 @@ let extension_event node identifier name text value = let open Lui_protocol in let values = match identifier, name with - | "bottom-tab-strip", "select" -> ["index", IntValue value] + | ("bottom-tab-strip" | "duo-journal-book"), "select" -> ["index", IntValue value] + | "duo-journal-book", "resize" -> ["width", IntValue value] | "native-pdf-workspace", "event" -> ["payload", StringValue text] | "outliner-block-row", "set-priority" -> ["priority", StringValue text] | ("outliner-block-row" | "outliner-block-content"), "set-status" -> ["uuid", StringValue text; "count", IntValue value] diff --git a/shared/src/logseq/view.ml b/shared/src/logseq/view.ml index 434c24c5..66fa85cf 100644 --- a/shared/src/logseq/view.ml +++ b/shared/src/logseq/view.ml @@ -476,6 +476,13 @@ let extension_registry () = [property "inset" IntScalar true None; property "selected-index" IntScalar true None; property "items" StringScalar true None; property "cell-width" IntScalar true None] [event "select" [event_field "index" IntScalar true]; event "home-double-tap" []]); + Lui_extension.register_component registry (let open Lui_protocol in + let open Lui_extension in + component "duo-journal-book" [profile IOS SwiftUIHost] true [] + [property "can-turn" BoolScalar true None; property "first-index" IntScalar true None; + property "selected-index" IntScalar true None] + [event "resize" [event_field "width" IntScalar true]; + event "select" [event_field "index" IntScalar true]]); Lui_extension.register_component registry (Lui_extension.component "native-flashcards-toolbar" [Lui_protocol.profile Lui_protocol.IOS Lui_protocol.SwiftUIHost] diff --git a/shared/src/logseq/view_screens.ml b/shared/src/logseq/view_screens.ml index f79c0cde..7d2f2175 100644 --- a/shared/src/logseq/view_screens.ml +++ b/shared/src/logseq/view_screens.ml @@ -520,6 +520,116 @@ let root_outliner_view ?scroll_to_top (context : Lui_ui.ui_context) model_source ])))); ]) +let duo_journal_book model_source send classic : t = + custom (fun context parent -> + let node = Lui_ui.extension context "duo-journal-book" in + let scheduler = context.Lui_ui.ui_scheduler in + let wide = Signal.state scheduler false in + let selected = Signal.state scheduler 0 in + let active = Signal.value wide in + let position = Signal.value selected in + let home_request = Signal.cutoff Int.equal (Signal.map (fun current -> + current.Model.home_scroll_request) model_source) in + let observed_home_request = ref (Signal.sample home_request) in + ignore (Signal.own context.ui_scope (Signal.observe home_request (fun request -> + if request <> !observed_home_request then begin + observed_home_request := request; + Signal.set selected 0 + end))); + let day_plus = Dev_query.Date_time_util.journal_day_plus in + let rows = Signal.cutoff ( == ) (Signal.map (fun current -> + current.Model.journal_outliner_rows) model_source) in + let rows = Signal.cutoff ( == ) + (Signal.map2 (fun active rows -> if active then rows else []) active rows) in + let grouped = Signal.map (fun rows -> + let days = Hashtbl.create 8 in + List.iter (fun (row : Model.outline_row) -> + Option.iter (fun day -> + let previous = Option.value ~default:[] (Hashtbl.find_opt days day) in + Hashtbl.replace days day (row :: previous)) row.journal_day) rows; + Hashtbl.fold (fun day _ anchor -> max day anchor) days + (Cache_model.journal_day_for_ms (Session_types.now_ms ())), days) rows in + let has_more = Signal.cutoff Bool.equal (Signal.map (fun current -> + current.Model.has_older_journals) model_source) in + let can_turn = Signal.map (fun current -> + View_base.journal_home_visible_ current + && current.outliner_editing = None + && current.outliner_selected_block_ids = [] + && not current.composer_expanded + && current.discussion_composition = None) model_source in + let window = Signal.map2 (fun (active, index) ((anchor, days), has_more) -> + if not active then [] else + let oldest = Hashtbl.fold (fun day _ oldest -> min day oldest) days anchor in + List.filter (fun candidate -> + candidate >= 0 + && (candidate = index || has_more + || Option.fold ~none:false ~some:(fun day -> day >= oldest) + (day_plus anchor (-2 * candidate)))) [index - 1; index; index + 1]) + (Signal.map2 (fun active index -> active, index) active position) + (Signal.map2 (fun grouped has_more -> grouped, has_more) grouped has_more) in + let first = Signal.map (function index :: _ -> index | [] -> 0) window in + let state name wrap source = + Lui_ui.extension_property_signal context node name (Signal.map wrap source) in + attach context parent node; + state "can-turn" View_base.bool_wire_value can_turn; + state "first-index" View_base.int_wire_value first; + state "selected-index" View_base.int_wire_value position; + Lui_ui.on_event context node (function + | ExtensionEvent (_, _, "resize", fields) -> + (match String_map.find_opt "width" fields with + | Some (IntValue width) -> + let enable = width >= 600 in + Signal.set wide enable; + if enable && View_base.older_journals_visible_ (Signal.sample model_source) then + ignore (send Model.LoadOlderJournals) + | _ -> ()) + | ExtensionEvent (_, _, "select", fields) -> + (match String_map.find_opt "index" fields with + | Some (IntValue index) when Signal.sample can_turn && List.mem index (Signal.sample window) -> + Signal.set selected index; + let anchor, days = Signal.sample grouped in + let oldest = Hashtbl.fold (fun day _ oldest -> min day oldest) days anchor in + if Signal.sample has_more && Option.fold ~none:false ~some:(fun day -> day <= oldest) + (day_plus anchor (-2 * (index + 1))) then + ignore (send Model.LoadOlderJournals) + | _ -> ()) + | _ -> ()); + let visible = Signal.map View_base.journal_home_visible_ model_source in + let page index side = + let day = Signal.map2 (fun (anchor, _) index -> + Option.value ~default:anchor (day_plus anchor (-2 * index - side))) grouped index in + reactive (fun day -> + let recorded_rows = + Signal.cutoff (fun a b -> a == b || a = b) + (Signal.map (fun (_, days) -> Option.value ~default:[] (Hashtbl.find_opt days day) + |> List.rev) grouped) in + let projection = Signal.map2 (fun (current : Model.logseq_model) rows -> + View_base.journal_navigation_model + {current with journal_outliner_rows = rows; has_older_journals = false}) + model_source recorded_rows in + let empty = Signal.map (fun rows -> rows = []) recorded_rows in + box ~grow:1.0 ~accessibility_identifier:("journal.duo.day." ^ string_of_int day) [ + if_ ~test:empty + (column ~padding:16 [ + View_outliner.page_heading_text ~tracks_scroll_title:false + ~accessibility_identifier:"journal.duo.empty-title" + (Signal.map (fun current -> View_base.journal_display_title current (Some day) + (Journal.day_title day)) model_source); + spacer ~grow:1.0 []; + ]); + if_ ~test:(Signal.map not empty) (root_outliner_view context projection visible send) + ]) day in + ignore (mount context ~parent:node (box ~grow:1.0 [classic])); + ignore (mount context ~parent:node (box ~grow:1.0 [ + keyed ~source:window ~key:Fun.id ~cmp:Int.compare ~mount:(fun index -> + row ~grow:1.0 ~gap:0 ~cross:`stretch [ + page index 1; + box ~width:1 ~background:"border" []; + page index 0; + ]) + ])); + node) + let retained_journal_pane (context : Lui_ui.ui_context) model_source send : t = let scroll_to_top = @@ -543,6 +653,13 @@ let retained_journal_pane (context : Lui_ui.ui_context) model_source send model_source) send in + let content = + if uses_ios_native_header context then + keyed + ~source:(Signal.map (fun current -> [current.Model.selected_graph_id]) model_source) + ~key:Fun.id ~cmp:compare + ~mount:(fun _ -> duo_journal_book model_source send content) + else content in box ~grow:1.0 ~accessibility_identifier:"pane.journals" [content] let journal_tree_panes (context : Lui_ui.ui_context) model_source send : t