-
-
Notifications
You must be signed in to change notification settings - Fork 61
$mol_book in dom #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
$mol_book in dom #761
Changes from all commits
aa738ea
9fac501
7c6cfdc
cc25d52
58d3853
805cc30
16c9207
c7389a8
0e2ad9a
153a912
21145b9
a42c8cf
08334d1
00fee31
e759205
d71b88a
43d4d8b
5be352f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
/* padding: 0 1px; | ||
scroll-padding: 0 1px; | ||
gap: 1px; */ | ||
--mol_book2_grip_top: 1.5rem; | ||
} | ||
|
||
[mol_book2] > * { | ||
|
@@ -26,11 +27,22 @@ | |
box-shadow: inset 0 0 0 1px var(--mol_theme_field); | ||
} | ||
|
||
[mol_book2] > *:not(:first-of-type):before, | ||
[mol_book2] > *:not(:last-of-type)::after { | ||
/* Prepend dots to not first page in the book, exclude placeholder */ | ||
[mol_book2] > *:not(:first-child):not([mol_book2]):not([mol_book2_gap])::before, | ||
/* Append dots to not last page in the book, exclude page before placeholder */ | ||
[mol_book2] > *:not(:last-child):not([mol_book2]):not([mol_book2_gap]):not(:has(+ [mol_book2_placeholder]))::after, | ||
|
||
/* Can't add dots to the book due to display: contents */ | ||
/* Prepend dots to all pages in the not first child book, exclude placeholder and second level child book */ | ||
[mol_book2] > *:not(:first-child)[mol_book2] > *:not([mol_book2]):not([mol_book2_gap])::before, | ||
|
||
/* Append dots to all pages in the not last child book not before placeholder */ | ||
[mol_book2] > *:not(:last-child)[mol_book2]:not(:has(+ [mol_book2_placeholder])) > :not([mol_book2]):not([mol_book2_gap])::after | ||
Comment on lines
+31
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Может всё же какой-то атрибут к страницам добавлять, через призрака? А то это какая-то адская логика в стилях. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Что б просетить атрибут, надо через js получить положение паги в общей иерархии паг. Этот факт заблокирует весь первый буклет, вместо того что бы отрисовать паги с загрузкой в каждой к примеру. Если буклет не блокировать, пропускать промис, то скорее всего будет меняться состав паг во время рендера, дребезг. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Какое отношение рендеринг призраков имеет к рендерингу бука? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не важно как добавляется атрибут, важно что для его значения надо знать где страница находится в иерархии. Ты ж имеешь в виду атрибут типа last, first и т.д.? Без него не решить куда точки поставить, а куда нет. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не важно, где определено свойство, важно, где оно вызывается. |
||
{ | ||
display: block; | ||
content: ''; | ||
position: absolute; | ||
top: 1.5rem; | ||
top: var(--mol_book2_grip_top); | ||
width: 3px; | ||
height: 1rem; | ||
background: linear-gradient( | ||
|
@@ -49,14 +61,16 @@ | |
opacity: .5; | ||
z-index: var(--mol_layer_speck); | ||
} | ||
[mol_book2] > *:not(:first-of-type):before { | ||
|
||
[mol_book2] > *:not(:first-child):not([mol_book2])::before { | ||
left: -1px; | ||
} | ||
[mol_book2] > *:not(:last-of-type)::after { | ||
|
||
[mol_book2] > *:not(:last-child):not([mol_book2])::after { | ||
right: -1px; | ||
} | ||
|
||
:where([mol_book2]) > * { | ||
:where([mol_book2]) > *:not([mol_book]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А где-то ещё используется первый бук? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ошибка, тут надо book2 |
||
background-color: var(--mol_theme_card); | ||
/* box-shadow: 0 0 0 1px var(--mol_theme_back); */ | ||
} | ||
|
@@ -65,7 +79,11 @@ | |
display: contents; | ||
} | ||
|
||
[mol_book2] > *:first-child { | ||
[mol_book2] [mol_book2] > [mol_book2_placeholder] { | ||
display: none; | ||
} | ||
Comment on lines
+82
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем его тогда вообще рендерить? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Проверял эвенты Идея была в том, что буклет ничего не знает про иерархию, просто предоставляет placeholder, хотелось бы его рендерить, справа от всех, но при этом не ломая структуру дом, что б владение и эвенты адекватными оставались, типа как портал. Но у меня не получилось так сделать на css, поэтому можно выпилить наверное. |
||
|
||
[mol_book2] > *:not([mol_book2]):first-child { | ||
scroll-snap-align: start; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
$mol_book2 $mol_scroll | ||
menu_title \ | ||
sub /$mol_view | ||
^ pages <= pages_deep /$mol_view | ||
^ pages /$mol_view | ||
^ placeholders /$mol_view | ||
<= Placeholder $mol_view | ||
Placeholder null | ||
minimal_width 0 | ||
Gap* $mol_view title \ | ||
auto / | ||
^ | ||
<= scroll_task_top null |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,8 @@ namespace $.$$ { | |
*/ | ||
export class $mol_book2 extends $.$mol_book2 { | ||
|
||
@ $mol_mem | ||
override pages_deep() { | ||
let result = [] as $mol_view[] | ||
for (const subpage of this.pages()) { | ||
if (subpage instanceof $mol_book2) result = [ ...result, ...subpage.pages_deep() ] | ||
else result.push(subpage) | ||
} | ||
|
||
return result | ||
} | ||
|
||
title() { | ||
return this.pages_deep().map( page => { | ||
return this.pages().map( page => { | ||
try { | ||
return page?.title() | ||
} catch( error ) { | ||
|
@@ -28,52 +17,99 @@ namespace $.$$ { | |
} | ||
|
||
menu_title() { | ||
return this.pages_deep()[0]?.title() || this.title() | ||
return this.pages()[0]?.title() || this.title() | ||
} | ||
|
||
@ $mol_mem | ||
sub() { | ||
override sub() { | ||
const placeholders = this.placeholders() | ||
const next = [ ... this.pages_deep(), ...placeholders ] | ||
|
||
const next = super.sub() | ||
const prev = $mol_mem_cached( ()=> this.sub() ) ?? [] | ||
const top = this.top_book ?? this | ||
|
||
for( let i = 1 ; i++ ; ) { | ||
let scroll_target | ||
for( let i = 1; i <= next.length; i++ ) { | ||
|
||
const p = prev[ prev.length - i ] | ||
const n = next[ next.length - i ] | ||
|
||
if( !n ) break | ||
|
||
if( p === n ) continue | ||
if( placeholders.includes(n) ) continue | ||
|
||
new this.$.$mol_after_tick( ()=> { | ||
const b = this.dom_node() as HTMLElement | ||
const p = n.dom_node() as HTMLElement | ||
b.scroll({ | ||
left: p.offsetLeft + p.offsetWidth - b.offsetWidth, | ||
behavior: 'smooth', | ||
}) | ||
// new this.$.$mol_after_timeout( 1000, ()=> n.bring() ) | ||
} ) | ||
|
||
break | ||
const prev_page = prev[ prev.length - i ] | ||
const next_page = next[ next.length - i ] | ||
if (next_page instanceof $mol_book2) { | ||
next_page.top_book = top | ||
} | ||
|
||
if( prev_page === next_page ) continue | ||
if( placeholders.includes(next_page) ) continue | ||
|
||
if (! scroll_target) scroll_target = next_page | ||
} | ||
|
||
return next as readonly $mol_view[] | ||
// need to set top_book to all sub books, can't break for | ||
if (scroll_target) top.scroll_target(scroll_target) | ||
|
||
return next | ||
} | ||
|
||
|
||
protected top_book = null as null | $mol_book2 | ||
|
||
@ $mol_mem | ||
scroll_target(page?: $mol_view | null) { | ||
return page ?? null | ||
} | ||
|
||
override scroll_task_top() { | ||
// avoid mem creation for non-top book | ||
if (this.top_book) return null | ||
this.scroll_task() | ||
} | ||
Comment on lines
+59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему бы не сделать рекурсивную логику? Верхний бук спрашивает у нижнего куда в нём скроллить и в конечном счёте получает глубоко вложенную страницу. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. непонятное что-то У меня логика была такая:
Отсюда, как раз наоборот, дочерние буклеты должны топовому передавать страницы, к которым они хотят, что б топовый подскролил. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Речь про получение страницы в топовом буке для подскролла.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. так все мое объяснение выше про нее There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ты там ниже ищешь страницу, к которой скроллить, не девая вложенным компонентам самим решать. |
||
|
||
@ $mol_mem | ||
scroll_task() { | ||
let page = this.scroll_target() | ||
|
||
// for display: contents view_rect always 0 | ||
// find last page | ||
while (page instanceof $mol_book2) { | ||
try { | ||
page = page.pages()?.at(-1) ?? null | ||
} catch (e) { | ||
return null | ||
} | ||
} | ||
|
||
if (! page ) return null | ||
|
||
const page_rect = page.view_rect() | ||
if (! page_rect) return null | ||
|
||
const top_rect = this.view_rect() | ||
if (! top_rect) return null | ||
|
||
const scroll_left = this.scroll_left() | ||
|
||
const page_right = page_rect.right + scroll_left | ||
|
||
const left = page_right - top_rect.right | ||
|
||
return new this.$.$mol_after_tick(() => { | ||
this.dom_node().scroll({ left, behavior: 'smooth' }) | ||
this.scroll_target(null) | ||
}) | ||
} | ||
|
||
bring() { | ||
|
||
const pages = this.pages_deep() | ||
const pages = this.pages() | ||
|
||
if( pages.length ) pages[ pages.length - 1 ].bring() | ||
else super.bring() | ||
|
||
} | ||
|
||
override placeholders() { | ||
if (this.Placeholder()) return [ this.Placeholder() ] | ||
return super.placeholders() | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,7 +268,7 @@ namespace $ { | |
} | ||
|
||
auto() { | ||
return null as any | ||
return [] as any | ||
} | ||
|
||
@ $mol_mem | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем переменная для этого?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так гвоздями все прибито, если чуть меньше сделать хедеры, точки эти едут, т.к. они абсолютом делаются.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А хедер ты меньше через переменные делаешь тоже?