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

BlockEditor driven by shared ObservableStore #1000

Merged

Conversation

gordonbrander
Copy link
Collaborator

@gordonbrander gordonbrander commented Nov 21, 2023

Fixes #987.

Depends on subconsciousnetwork/ObservableStore#43

This PR implements basic loading and saving of real data from database, including blocks and related notes. I've kept the scope to just saving and loading, and there is more work to be done wrt transcludes and loading states.

Approach

  • New changes to ObservableStore allow creating custom Update types for models. Make update a protocol (fixup) ObservableStore#43
  • Also introduces an updates publisher on stores
  • Custom update type lets us include a change description along with state changes, supplying extra information that the ViewController might need to perform these changes.
  • Root UIViewController subscribes to updates publisher and performs updates to controller based on state transactions.
  • ObservableStore instance is stored as a @StateObject on the enclosing SwiftUIView and passed down as an @ObservedObject to the UIViewControllerRepresentable.

The result is that we can share the same store between SwiftUI and UIKit land, as well as the same environment and side effects management.

Screenshots

Fork of ObservableStore that allows creating custom Update types for
models. This lets us publish a change description along with state
changes. The controller can use the change description to perform
appropriate updates.
...and update ObservableStore branch
...no longer use this class.
...also remove spacer from cells, since it was messing up constraint
resolution in the collection view.
It's handled in its own store now.
...and replace delegate approach with send functions and enums. This
lets us simply map between enums.
Not needed when we can use Self.
)
}

// TODO: re-implement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these TODOs are out of scope for this PR since they're related to bulk selection.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, out of scope. The selection mode wasn't working properly. Removed commented-out code, and added issues to TODOs.

Comment on lines 14 to 15
// TODO: serialize to nice Subtext whitespace
blocks.compactMap(\.text).joined(separator: "\n\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this out of scope?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bfollington yes, it will require a modification to the Subtext parser to enable rendering a "pretty printed" string that places spaces between some lines and not others (e.g. list items can have blank lines between but probably shouldn't for readability purposes". This is purely an aesthetic enhancement.

I'll file a bug to follow up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +37 to +48
textStorage.delegate = self
// !!!: Hack to trigger initial rendering of attributes
// UITextView has a bug where a text view that has been created
// with an empty string does not correctly render attributes until
// given a non-empty string. This results in a jump triggered by
// a change in intrinsic content size when the attributes are
// first applied.
//
// After being rendered with a non-empty string, it works properly.
// 2023-11-22 Gordon
self.text = " "
self.text = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Collaborator

@bfollington bfollington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, this is a massive improvement to the existing code. Excited to try the editor out.

@gordonbrander gordonbrander marked this pull request as ready for review December 1, 2023 18:24
@gordonbrander gordonbrander merged commit 61fe5cd into main Dec 1, 2023
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load and persist block editor from actual data
2 participants