Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* dev: freeze scroll on show forms #23977 * clean up * refactor * clean up v2 * feedback * clean up
- Loading branch information
Showing
16 changed files
with
142 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
core-web/libs/block-editor/src/lib/extensions/freeze-scroll/freeze-scroll.extension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { PluginKey, Plugin, Transaction, EditorState } from 'prosemirror-state'; | ||
|
||
import { Extension } from '@tiptap/core'; | ||
|
||
export const FREEZE_SCROLL_KEY = new PluginKey('freeze-scroll'); | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
FreezeScroll: { | ||
freezeScroll: (value: boolean) => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
interface PluginState { | ||
freezeScroll: boolean; | ||
} | ||
|
||
export const FreezeScroll = Extension.create({ | ||
addCommands() { | ||
return { | ||
freezeScroll: | ||
(value) => | ||
({ chain }) => { | ||
return chain() | ||
.command(({ tr }) => { | ||
tr.setMeta(FREEZE_SCROLL_KEY, { freezeScroll: value }); | ||
|
||
return true; | ||
}) | ||
.run(); | ||
} | ||
}; | ||
}, | ||
|
||
addProseMirrorPlugins() { | ||
return [FreezeScrollPlugin]; | ||
} | ||
}); | ||
|
||
export const FreezeScrollPlugin = new Plugin({ | ||
key: FREEZE_SCROLL_KEY, | ||
state: { | ||
init(): PluginState { | ||
return { | ||
freezeScroll: false | ||
}; | ||
}, | ||
apply(transaction: Transaction, value: PluginState, oldState: EditorState): PluginState { | ||
const { freezeScroll } = transaction.getMeta(FREEZE_SCROLL_KEY) || {}; | ||
const state = FREEZE_SCROLL_KEY?.getState(oldState); | ||
|
||
if (typeof freezeScroll === 'boolean') { | ||
return { freezeScroll }; | ||
} | ||
|
||
// keep the old state in case we do not receive a new one. | ||
return state || value; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.