mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 15:26:17 +00:00
fix(ffi): keep merged children in place and rename PageView to PageData
Merging a first child into its parent now gives its children the merged block's slot instead of appending them after the parent's other children. PageView clashed with Flutter's PageView widget in Dart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
305428eaea
commit
8c11d049fb
5 files changed
+104
-85
No files matched your search
@@ -55,7 +55,7 @@ impl BlockDto {
|
||||
|
||||
/// Everything the page view needs in one call.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PageView {
|
||||
pub struct PageData {
|
||||
pub page: PageDto,
|
||||
pub blocks: Vec<BlockDto>,
|
||||
pub aliases: Vec<String>,
|
||||
|
||||
@@ -42,7 +42,7 @@ impl SynapseGraph {
|
||||
|
||||
// ------------------------------------------------------------- pages
|
||||
|
||||
pub fn page(&self, id: String) -> Result<Option<PageView>> {
|
||||
pub fn page(&self, id: String) -> Result<Option<PageData>> {
|
||||
let g = self.lock();
|
||||
match g.get_page(parse_id(&id)?)? {
|
||||
Some(p) => Ok(Some(page_view(&g, &p)?)),
|
||||
@@ -51,7 +51,7 @@ impl SynapseGraph {
|
||||
}
|
||||
|
||||
/// Page by title or alias, without creating it.
|
||||
pub fn page_by_title(&self, title: String) -> Result<Option<PageView>> {
|
||||
pub fn page_by_title(&self, title: String) -> Result<Option<PageData>> {
|
||||
let g = self.lock();
|
||||
match g.page_by_title(&title)? {
|
||||
Some(p) => Ok(Some(page_view(&g, &p)?)),
|
||||
@@ -61,7 +61,7 @@ impl SynapseGraph {
|
||||
|
||||
/// Page by title or alias, created if missing (following a `[[link]]`). Date titles open
|
||||
/// the journal of that day.
|
||||
pub fn open_page(&self, title: String) -> Result<PageView> {
|
||||
pub fn open_page(&self, title: String) -> Result<PageData> {
|
||||
let g = self.lock();
|
||||
let page = match g.page_by_title(&title)? {
|
||||
Some(p) => p,
|
||||
@@ -115,7 +115,7 @@ impl SynapseGraph {
|
||||
// ---------------------------------------------------------- journals
|
||||
|
||||
/// The journal of `date` (created if missing).
|
||||
pub fn journal(&self, date: String) -> Result<PageView> {
|
||||
pub fn journal(&self, date: String) -> Result<PageData> {
|
||||
let g = self.lock();
|
||||
let p = g.journal(parse_date(&date)?)?;
|
||||
page_view(&g, &p)
|
||||
@@ -123,7 +123,7 @@ impl SynapseGraph {
|
||||
|
||||
/// Journals feed, newest first. With `before = None` it starts at today (creating today's
|
||||
/// journal); otherwise at the newest journal strictly before `before`.
|
||||
pub fn journals(&self, before: Option<String>, limit: u32) -> Result<Vec<PageView>> {
|
||||
pub fn journals(&self, before: Option<String>, limit: u32) -> Result<Vec<PageData>> {
|
||||
let g = self.lock();
|
||||
let mut out = Vec::new();
|
||||
let mut cursor = match before {
|
||||
@@ -293,7 +293,7 @@ fn asset_dto(a: synapse_core::Asset) -> AssetDto {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageView> {
|
||||
pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageData> {
|
||||
let (prev, next) = match p.journal_date {
|
||||
Some(d) => {
|
||||
let n = g.journal_neighbors(d)?;
|
||||
@@ -301,7 +301,7 @@ pub(crate) fn page_view(g: &Graph, p: &Page) -> Result<PageView> {
|
||||
}
|
||||
None => (None, None),
|
||||
};
|
||||
Ok(PageView {
|
||||
Ok(PageData {
|
||||
page: PageDto::from(p),
|
||||
blocks: outline(g, p.id)?,
|
||||
aliases: g.aliases_of(p.id)?,
|
||||
|
||||
@@ -83,7 +83,8 @@ impl SynapseGraph {
|
||||
}
|
||||
|
||||
/// Backspace at the start of `id`: its text is appended to `into` (the previous visible
|
||||
/// block), its children are moved under `into`, and the block is deleted.
|
||||
/// block) and the block is deleted. Its children keep their visual place: they take the
|
||||
/// block's slot when `into` is its parent, otherwise they become last children of `into`.
|
||||
pub fn merge_block(&self, id: String, into: String) -> Result<Vec<BlockDto>> {
|
||||
let g = self.lock();
|
||||
let b = get(&g, parse_id(&id)?)?;
|
||||
@@ -100,11 +101,16 @@ impl SynapseGraph {
|
||||
.filter(|(_, c)| c.parent_id == Some(b.id))
|
||||
.map(|(_, c)| c.id)
|
||||
.collect();
|
||||
if !children.is_empty() && target.collapsed {
|
||||
if !children.is_empty() && target.collapsed && b.parent_id != Some(target.id) {
|
||||
g.set_collapsed(target.id, false)?;
|
||||
}
|
||||
let at = if b.parent_id == Some(target.id) {
|
||||
Placement::Before(b.id)
|
||||
} else {
|
||||
Placement::LastChildOf(Some(target.id))
|
||||
};
|
||||
for c in children {
|
||||
g.move_block(c, target.page_id, Placement::LastChildOf(Some(target.id)))?;
|
||||
g.move_block(c, target.page_id, at)?;
|
||||
}
|
||||
g.delete_block(b.id)?;
|
||||
outline(&g, target.page_id)
|
||||
|
||||
@@ -2148,6 +2148,18 @@ impl SseDecode for Vec<crate::api::dto::PageBrief> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Vec<crate::api::dto::PageData> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut len_ = <i32>::sse_decode(deserializer);
|
||||
let mut ans_ = Vec::with_capacity(len_ as usize);
|
||||
for idx_ in 0..len_ {
|
||||
ans_.push(<crate::api::dto::PageData>::sse_decode(deserializer));
|
||||
}
|
||||
return ans_;
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Vec<crate::api::dto::PageDto> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -2160,18 +2172,6 @@ impl SseDecode for Vec<crate::api::dto::PageDto> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Vec<crate::api::dto::PageView> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut len_ = <i32>::sse_decode(deserializer);
|
||||
let mut ans_ = Vec::with_capacity(len_ as usize);
|
||||
for idx_ in 0..len_ {
|
||||
ans_.push(<crate::api::dto::PageView>::sse_decode(deserializer));
|
||||
}
|
||||
return ans_;
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Vec<u8> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -2242,11 +2242,11 @@ impl SseDecode for Option<crate::api::dto::BlockRefDto> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Option<crate::api::dto::PageView> {
|
||||
impl SseDecode for Option<crate::api::dto::PageData> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
if (<bool>::sse_decode(deserializer)) {
|
||||
return Some(<crate::api::dto::PageView>::sse_decode(deserializer));
|
||||
return Some(<crate::api::dto::PageData>::sse_decode(deserializer));
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
@@ -2267,6 +2267,24 @@ impl SseDecode for crate::api::dto::PageBrief {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::dto::PageData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut var_page = <crate::api::dto::PageDto>::sse_decode(deserializer);
|
||||
let mut var_blocks = <Vec<crate::api::dto::BlockDto>>::sse_decode(deserializer);
|
||||
let mut var_aliases = <Vec<String>>::sse_decode(deserializer);
|
||||
let mut var_prevJournal = <Option<String>>::sse_decode(deserializer);
|
||||
let mut var_nextJournal = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::api::dto::PageData {
|
||||
page: var_page,
|
||||
blocks: var_blocks,
|
||||
aliases: var_aliases,
|
||||
prev_journal: var_prevJournal,
|
||||
next_journal: var_nextJournal,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::dto::PageDto {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -2287,24 +2305,6 @@ impl SseDecode for crate::api::dto::PageDto {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::dto::PageView {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut var_page = <crate::api::dto::PageDto>::sse_decode(deserializer);
|
||||
let mut var_blocks = <Vec<crate::api::dto::BlockDto>>::sse_decode(deserializer);
|
||||
let mut var_aliases = <Vec<String>>::sse_decode(deserializer);
|
||||
let mut var_prevJournal = <Option<String>>::sse_decode(deserializer);
|
||||
let mut var_nextJournal = <Option<String>>::sse_decode(deserializer);
|
||||
return crate::api::dto::PageView {
|
||||
page: var_page,
|
||||
blocks: var_blocks,
|
||||
aliases: var_aliases,
|
||||
prev_journal: var_prevJournal,
|
||||
next_journal: var_nextJournal,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::dto::Place {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@@ -2736,6 +2736,25 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::dto::PageBrief> for crate::ap
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::dto::PageData {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.page.into_into_dart().into_dart(),
|
||||
self.blocks.into_into_dart().into_dart(),
|
||||
self.aliases.into_into_dart().into_dart(),
|
||||
self.prev_journal.into_into_dart().into_dart(),
|
||||
self.next_journal.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::api::dto::PageData {}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::api::dto::PageData> for crate::api::dto::PageData {
|
||||
fn into_into_dart(self) -> crate::api::dto::PageData {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::dto::PageDto {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@@ -2756,25 +2775,6 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::dto::PageDto> for crate::api:
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::dto::PageView {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.page.into_into_dart().into_dart(),
|
||||
self.blocks.into_into_dart().into_dart(),
|
||||
self.aliases.into_into_dart().into_dart(),
|
||||
self.prev_journal.into_into_dart().into_dart(),
|
||||
self.next_journal.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::api::dto::PageView {}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::api::dto::PageView> for crate::api::dto::PageView {
|
||||
fn into_into_dart(self) -> crate::api::dto::PageView {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::dto::Place {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@@ -3064,6 +3064,16 @@ impl SseEncode for Vec<crate::api::dto::PageBrief> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Vec<crate::api::dto::PageData> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<i32>::sse_encode(self.len() as _, serializer);
|
||||
for item in self {
|
||||
<crate::api::dto::PageData>::sse_encode(item, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Vec<crate::api::dto::PageDto> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@@ -3074,16 +3084,6 @@ impl SseEncode for Vec<crate::api::dto::PageDto> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Vec<crate::api::dto::PageView> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<i32>::sse_encode(self.len() as _, serializer);
|
||||
for item in self {
|
||||
<crate::api::dto::PageView>::sse_encode(item, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Vec<u8> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@@ -3144,12 +3144,12 @@ impl SseEncode for Option<crate::api::dto::BlockRefDto> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Option<crate::api::dto::PageView> {
|
||||
impl SseEncode for Option<crate::api::dto::PageData> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<bool>::sse_encode(self.is_some(), serializer);
|
||||
if let Some(value) = self {
|
||||
<crate::api::dto::PageView>::sse_encode(value, serializer);
|
||||
<crate::api::dto::PageData>::sse_encode(value, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3163,6 +3163,17 @@ impl SseEncode for crate::api::dto::PageBrief {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::dto::PageData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::api::dto::PageDto>::sse_encode(self.page, serializer);
|
||||
<Vec<crate::api::dto::BlockDto>>::sse_encode(self.blocks, serializer);
|
||||
<Vec<String>>::sse_encode(self.aliases, serializer);
|
||||
<Option<String>>::sse_encode(self.prev_journal, serializer);
|
||||
<Option<String>>::sse_encode(self.next_journal, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::dto::PageDto {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@@ -3175,17 +3186,6 @@ impl SseEncode for crate::api::dto::PageDto {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::dto::PageView {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::api::dto::PageDto>::sse_encode(self.page, serializer);
|
||||
<Vec<crate::api::dto::BlockDto>>::sse_encode(self.blocks, serializer);
|
||||
<Vec<String>>::sse_encode(self.aliases, serializer);
|
||||
<Option<String>>::sse_encode(self.prev_journal, serializer);
|
||||
<Option<String>>::sse_encode(self.next_journal, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::dto::Place {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
|
||||
Reference in new issue
Block a user