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

Block Editor: use SwiftUI for transcludes and related #994

Merged
merged 9 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
bfollington marked this conversation as resolved.
Show resolved Hide resolved
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)
bfollington marked this conversation as resolved.
Show resolved Hide resolved
}
if (!renderable.entries.isEmpty) {
bfollington marked this conversation as resolved.
Show resolved Hide resolved
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)
bfollington marked this conversation as resolved.
Show resolved Hide resolved
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
Loading