mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
fix: Remove forced newline from toggle in list (#11976)
* Use helper * Address review feedback: add comment for offset, rename plugin variable
This commit is contained in:
1 parent
3ace24c966
commit
ffe4e5c7e4
2 files changed
+26
-46
No files matched your search
@@ -2595,27 +2595,34 @@ del {
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-block {
|
||||
li > .${EditorStyleHelper.toggleBlock} {
|
||||
position: relative;
|
||||
/* Nudge the toggle to visually align with the first line of list-item text.
|
||||
Keep this in em so it scales with the current font size. */
|
||||
top: 0.4em;
|
||||
}
|
||||
|
||||
.${EditorStyleHelper.toggleBlock} {
|
||||
display: flex;
|
||||
|
||||
&:focus-within {
|
||||
transition-delay: 0.1s;
|
||||
}
|
||||
|
||||
&.folded {
|
||||
&.${EditorStyleHelper.toggleBlockFolded} {
|
||||
&:dir(rtl) {
|
||||
--rotate-by: 90deg;
|
||||
}
|
||||
&:dir(ltr) {
|
||||
--rotate-by: -90deg;
|
||||
}
|
||||
> .toggle-block-content > :is(:not(.toggle-block-head)) {
|
||||
> .${EditorStyleHelper.toggleBlockContent} > :is(:not(.${EditorStyleHelper.toggleBlockHead})) {
|
||||
display: none;
|
||||
}
|
||||
> .toggle-block-content > :is(a.heading-name) {
|
||||
> .${EditorStyleHelper.toggleBlockContent} > :is(a.heading-name) {
|
||||
display: unset;
|
||||
}
|
||||
> .toggle-block-button {
|
||||
> .${EditorStyleHelper.toggleBlockButton} {
|
||||
svg {
|
||||
transform: rotate(var(--rotate-by));
|
||||
pointer-events: none;
|
||||
@@ -2624,7 +2631,7 @@ del {
|
||||
}
|
||||
}
|
||||
|
||||
> .toggle-block-button {
|
||||
> .${EditorStyleHelper.toggleBlockButton} {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -2634,22 +2641,22 @@ del {
|
||||
--line-height: var(--line-height-p);
|
||||
--font-size: var(--font-size-p);
|
||||
|
||||
&:has(+ .toggle-block-content > .toggle-block-head > h1) {
|
||||
&:has(+ .${EditorStyleHelper.toggleBlockContent} > .${EditorStyleHelper.toggleBlockHead} > h1) {
|
||||
--line-height: calc(var(--line-height-h) + 0.2);
|
||||
--font-size: var(--font-size-h1);
|
||||
}
|
||||
|
||||
&:has(+ .toggle-block-content > .toggle-block-head > h2) {
|
||||
&:has(+ .${EditorStyleHelper.toggleBlockContent} > .${EditorStyleHelper.toggleBlockHead} > h2) {
|
||||
--line-height: calc(var(--line-height-h) + 0.2);
|
||||
--font-size: var(--font-size-h2);
|
||||
}
|
||||
|
||||
&:has(+ .toggle-block-content > .toggle-block-head > h3) {
|
||||
&:has(+ .${EditorStyleHelper.toggleBlockContent} > .${EditorStyleHelper.toggleBlockHead} > h3) {
|
||||
--line-height: calc(var(--line-height-h) + 0.2);
|
||||
--font-size: var(--font-size-h3);
|
||||
}
|
||||
|
||||
&:has(+ .toggle-block-content > .toggle-block-head > h4) {
|
||||
&:has(+ .${EditorStyleHelper.toggleBlockContent} > .${EditorStyleHelper.toggleBlockHead} > h4) {
|
||||
--line-height: calc(var(--line-height-h) + 0.2);
|
||||
--font-size: var(--font-size-h4);
|
||||
}
|
||||
@@ -2677,14 +2684,14 @@ del {
|
||||
}
|
||||
}
|
||||
|
||||
> .toggle-block-content {
|
||||
> :is(:not(.toggle-block-head)) {
|
||||
> .${EditorStyleHelper.toggleBlockContent} {
|
||||
> :is(:not(.${EditorStyleHelper.toggleBlockHead})) {
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
> :is(:first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
> .toggle-block-head {
|
||||
> .${EditorStyleHelper.toggleBlockHead} {
|
||||
> * {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ export default class ToggleBlock extends Node {
|
||||
get plugins() {
|
||||
const userId = this.editor.props.userId;
|
||||
|
||||
// Assign IDs, fix positions, auto-fold empty
|
||||
const fixToggleBlocksPlugin = new Plugin({
|
||||
// Assign IDs and auto-fold empty
|
||||
const plugin = new Plugin({
|
||||
appendTransaction: (transactions, _oldState, newState) => {
|
||||
if (!transactions.some((tr) => tr.docChanged)) {
|
||||
return null;
|
||||
@@ -112,7 +112,7 @@ export default class ToggleBlock extends Node {
|
||||
|
||||
let tr: Transaction | null = null;
|
||||
|
||||
// 1. Assign IDs to blocks that need them and set fold state for creator
|
||||
// Assign IDs to blocks that need them and set fold state for creator
|
||||
const blocksNeedingIds = toggleBlocks.filter((b) => !b.node.attrs.id);
|
||||
if (blocksNeedingIds.length > 0) {
|
||||
tr = newState.tr;
|
||||
@@ -124,35 +124,8 @@ export default class ToggleBlock extends Node {
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Fix invalid positions (toggle at start of list item)
|
||||
// Use the updated doc if we made changes, process in reverse order
|
||||
const doc = tr?.doc ?? newState.doc;
|
||||
const currentBlocks = tr
|
||||
? findBlockNodes(doc, true).filter(
|
||||
(b) => b.node.type.name === this.name
|
||||
)
|
||||
: toggleBlocks;
|
||||
|
||||
const invalidBlocks = currentBlocks.filter((block) => {
|
||||
const $pos = doc.resolve(block.pos);
|
||||
return (
|
||||
$pos.parent.type === newState.schema.nodes.list_item &&
|
||||
$pos.parentOffset === 0
|
||||
);
|
||||
});
|
||||
|
||||
if (invalidBlocks.length > 0) {
|
||||
tr = tr ?? newState.tr;
|
||||
for (let i = invalidBlocks.length - 1; i >= 0; i--) {
|
||||
tr.insert(
|
||||
invalidBlocks[i].pos,
|
||||
newState.schema.nodes.paragraph.create({})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Auto-fold toggle blocks with empty bodies
|
||||
// Only if no structural changes were made (positions would be invalid)
|
||||
// Auto-fold toggle blocks with empty bodies, only if no structural
|
||||
// changes were made (positions would be invalid)
|
||||
if (!tr) {
|
||||
const pluginState = toggleFoldPluginKey.getState(newState);
|
||||
if (pluginState) {
|
||||
@@ -358,7 +331,7 @@ export default class ToggleBlock extends Node {
|
||||
});
|
||||
|
||||
return [
|
||||
fixToggleBlocksPlugin,
|
||||
plugin,
|
||||
foldPlugin,
|
||||
eventPlugin,
|
||||
new PlaceholderPlugin([
|
||||
|
||||
Reference in new issue
Block a user