Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Block Editor: use SwiftUI for transcludes and related (#994)
Browse files Browse the repository at this point in the history
Fixes #983

Replaces UIKit transcludes with SwiftUI transcludes using UIHostingView
from #981.

The transclude callbacks are not yet hooked up to anything. Saving this
for a future PR where we integrate the block editor with real data and
services.

Progress toward #214.
  • Loading branch information
gordonbrander authored Nov 14, 2023
1 parent 4202840 commit e02b211
Show file tree
Hide file tree
Showing 19 changed files with 387 additions and 858 deletions.
20 changes: 9 additions & 11 deletions xcode/Subconscious/Shared/Components/BacklinksView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ struct BacklinksView: View {
Spacer()
}
if backlinks.count > 0 {
ForEach(backlinks) { entry in
TranscludeView(
entry: entry,
onRequestDetail: {
onRequestDetail(EntryLink(entry))
},
onLink: { link in
onLink(entry.toResolvedAddress(), link)
}
)
}
TranscludeListView(
entries: backlinks,
onViewTransclude: { entry in
onRequestDetail(EntryLink(entry))
},
onTranscludeLink: { context, subSlashlink in
onLink(context, subSlashlink)
}
)
} else {
TitleGroupView(
title: Text("No related notes yet")
Expand Down
166 changes: 89 additions & 77 deletions xcode/Subconscious/Shared/Components/Common/SubtextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ struct SubtextView: View {
return nil
}

return RenderableBlock(block: block, entries: self.entries(for: block))
return RenderableBlock(
block: block,
entries: self.entries(for: block)
)
}
}

Expand All @@ -65,21 +68,24 @@ struct SubtextView: View {
var body: some View {
VStack(alignment: .leading, spacing: AppTheme.tightPadding) {
ForEach(blocks, id: \.self) { renderable in
if renderable.entries.isEmpty ||
!shouldReplaceBlockWithTransclude(block: renderable.block) {
Text(Self.renderer.render(renderable.block.description))
}

ForEach(renderable.entries, id: \.self) { entry in
TranscludeView(
entry: entry,
onRequestDetail: {
onViewTransclude(entry.address)
},
onLink: { link in
onTranscludeLink(entry.toResolvedAddress(), link)
}
)
VStack(spacing: AppTheme.tightPadding) {
if !shouldReplaceBlockWithTransclude(
block: renderable.block
) {
Text(
Self.renderer.render(renderable.block.description)
)
.fixedSize(horizontal: false, vertical: true)
}
if (!renderable.entries.isEmpty) {
TranscludeListView(
entries: renderable.entries,
onViewTransclude: { entry in
onViewTransclude(entry.address)
},
onTranscludeLink: onTranscludeLink
)
}
}
}
}
Expand All @@ -90,68 +96,74 @@ struct SubtextView: View {
struct SubtextView_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
SubtextView(
subtext: Subtext(
markup: """
# The Prophet, Kahlil Gibran
People of [[Orphalese]], the wind bids me leave you.
Less _hasty_ am I than the *wind*, yet I must go.
http://example.com
We [[wanderers]], ever seeking the lonelier way, begin no day where we have ended another day; and no sunrise finds us where sunset left us.
/wanderer-your-footsteps-are-the-road
Even while the `earth` sleeps we travel.
> We are the seeds of the tenacious plant, and it is in our ripeness and our fullness of heart that we are given to the wind and are scattered.
Brief were my days among you, and briefer still the words I have spoken.
But should my /voice fade in your ears, and my love vanish in your /memory, then I will come again,
And with a richer heart and lips more yielding to the spirit will I speak.
Yea, I shall return with the tide,
"""
),
transcludePreviews: [
Slashlink("/wanderer-your-footsteps-are-the-road")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/wanderer-your-footsteps-are-the-road"
)!,
excerpt: Subtext(markup: "hello mother"),
isTruncated: false,
modified: Date.now
ScrollView {
SubtextView(
subtext: Subtext(
markup: """
# The Prophet, Kahlil Gibran
People of [[Orphalese]], the wind bids me leave you.
Less _hasty_ am I than the *wind*, yet I must go.
http://example.com
/voice /voice
We [[wanderers]], ever seeking the lonelier way, begin no day where we have ended another day; and no sunrise finds us where sunset left us.
/wanderer-your-footsteps-are-the-road
Even while the `earth` sleeps we travel.
> We are the seeds of the tenacious plant, and it is in our ripeness and our fullness of heart that we are given to the wind and are scattered.
Brief were my days among you, and briefer still the words I have spoken.
But should my /voice fade in your ears, and my love vanish in your /memory, then I will come again,
And with a richer heart and lips more yielding to the spirit will I speak.
Yea, I shall return with the tide,
"""
),
Slashlink("/voice")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/voice"
)!,
excerpt: Subtext(markup: "hello father"),
isTruncated: false,
modified: Date.now
),
Slashlink("/memory")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/memory"
)!,
excerpt: Subtext(markup: "hello world"),
isTruncated: false,
modified: Date.now
)
],
onViewTransclude: {
_ in
},
onTranscludeLink: { address, link in }
)
transcludePreviews: [
Slashlink("/wanderer-your-footsteps-are-the-road")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/wanderer-your-footsteps-are-the-road"
)!,
excerpt: Subtext(markup: "hello"),
isTruncated: false,
modified: Date.now
),
Slashlink("/voice")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/voice"
)!,
excerpt: Subtext(markup: "hello"),
isTruncated: false,
modified: Date.now
),
Slashlink("/memory")!: EntryStub(
did: Did.dummyData(),
address: Slashlink(
"/memory"
)!,
excerpt: Subtext(markup: "hello world"),
isTruncated: false,
modified: Date.now
)
],
onViewTransclude: {
_ in
},
onTranscludeLink: { address, link in }
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// TranscludeListView.swift
// Subconscious
//
// Created by Gordon Brander on 11/11/23.
//

import SwiftUI

struct TranscludeListView: View {
var entries: [EntryStub]
var onViewTransclude: (EntryStub) -> Void
var onTranscludeLink: (ResolvedAddress, SubSlashlinkLink) -> Void

var body: some View {
VStack {
ForEach(entries, id: \.self) { entry in
TranscludeView(
entry: entry,
onRequestDetail: {
onViewTransclude(entry)
},
onLink: { link in
onTranscludeLink(entry.toResolvedAddress(), link)
}
)
}
}
}
}

struct TranscludeListView_Previews: PreviewProvider {
static var previews: some View {
TranscludeListView(
entries: [
EntryStub(
did: Did.dummyData(),
address: Slashlink("did:subconscious:local/loomings")!,
excerpt: Subtext(
markup: """
Call me Ishmael.
Some years ago- never mind how long precisely
"""
),
isTruncated: false,
modified: Date.now
),
],
onViewTransclude: { _ in },
onTranscludeLink: { _, _ in }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ extension BlockEditor {
for: indexPath
) as! TextBlockCell
cell.delegate = self
cell.render(state)
cell.update(parentController: self, state: state)
return cell
}

Expand Down Expand Up @@ -287,7 +287,7 @@ extension BlockEditor {
for: indexPath
) as! QuoteBlockCell
cell.delegate = self
cell.render(state)
cell.update(parentController: self, state: state)
return cell
}

Expand All @@ -301,7 +301,7 @@ extension BlockEditor {
for: indexPath
) as! ListBlockCell
cell.delegate = self
cell.render(state)
cell.update(parentController: self, state: state)
return cell
}

Expand All @@ -314,7 +314,7 @@ extension BlockEditor {
for: indexPath
) as! RelatedCell
let state = store.state.appendix
cell.render(state)
cell.update(parentController: self, state: state)
return cell
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit e02b211

Please sign in to comment.