Skip to content
Merged

wip #91

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions patches/tiptap-pagination-plus+3.0.5.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js b/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
index 52bd368..60f19f5 100644
index 52bd368..0b4d0d7 100644
--- a/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
+++ b/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
@@ -59,7 +59,11 @@ export const PaginationPlus = Extension.create({
Expand All @@ -26,7 +26,7 @@ index 52bd368..60f19f5 100644
.rm-with-pagination .rm-br-decoration {
display: table;
width: 100%;
@@ -202,36 +202,28 @@ export const PaginationPlus = Extension.create({
@@ -202,36 +202,35 @@ export const PaginationPlus = Extension.create({
};
},
apply: (tr, oldDeco, oldState, newState) => {
Expand All @@ -37,7 +37,14 @@ index 52bd368..60f19f5 100644
+ return oldDeco;
+ }
+
+ const opts = editor.storage.PaginationPlus
+ const opts = editor.storage.PaginationPlus;
+ const forceUpdate = tr.getMeta('pageFormatUpdate') || tr.getMeta('forcePaginationUpdate');
+ const isInitialized = oldDeco && oldDeco.decorations && typeof oldDeco.decorations.find === 'function' && oldDeco.decorations.find().length > 0;
+
+ if (!tr.docChanged && !forceUpdate && isInitialized) {
+ return oldDeco;
+ }
+
+ const pageCount = calculatePageCount(currentView, opts);
+ const currentPageCount = getExistingPageCount(currentView);
+
Expand Down Expand Up @@ -77,7 +84,7 @@ index 52bd368..60f19f5 100644
return getNewDecoration();
}
return oldDeco;
@@ -246,7 +238,8 @@ export const PaginationPlus = Extension.create({
@@ -246,7 +245,8 @@ export const PaginationPlus = Extension.create({
view: (editorView) => {
return {
update: (view) => {
Expand All @@ -87,7 +94,7 @@ index 52bd368..60f19f5 100644
const currentPageCount = getExistingPageCount(view);
const triggerUpdate = (_footerHeight) => {
requestAnimationFrame(() => {
@@ -258,8 +251,8 @@ export const PaginationPlus = Extension.create({
@@ -258,8 +258,8 @@ export const PaginationPlus = Extension.create({
triggerUpdate();
return;
}
Expand All @@ -98,16 +105,34 @@ index 52bd368..60f19f5 100644
const footerHeightForCurrentPages = new Map();
for (let i = 0; i <= pageCount; i++) {
if (footerHeight.has(i)) {
@@ -289,7 +282,7 @@ export const PaginationPlus = Extension.create({
@@ -289,8 +289,24 @@ export const PaginationPlus = Extension.create({
for (const page of pagesSetToCheck) {
const headerHeight = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
const footerHeight = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
- const { _pageHeaderHeight, _pageHeight } = getHeight(this.options, headerHeight, footerHeight);
- const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
+ const { _pageHeaderHeight, _pageHeight } = getHeight(opts, headerHeight, footerHeight);
const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
+ let contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
+
+ // --- ORPHAN PREVENTION OVERRIDE ---
+ // Find any text node below this page that forces a break
+ // To know which forced break belongs to this page, we look at the DOM
+ // The paragraphs are visually ordered.
+ // It's easiest to let the orphan-prevention-extension assign a specific data attribute for the page.
+ // If the node has data-forced-page="1", we use its value.
+ const domForcedNode = view.dom.querySelector(`[data-forced-page="${page}"]`);
+ if (domForcedNode) {
+ const forceOffset = parseFloat(domForcedNode.getAttribute('data-force-page-break-offset'));
+ if (!isNaN(forceOffset) && forceOffset > 0) {
+ contentHeight = forceOffset;
+ }
+ }
+ // --- END ORPHAN PREVENTION OVERRIDE ---
+
if (page === 1) {
pageContentHeightVariable[`rm-page-content-first`] = `${contentHeight}px`;
@@ -347,65 +340,74 @@ export const PaginationPlus = Extension.create({
}
@@ -347,65 +363,74 @@ export const PaginationPlus = Extension.create({
addCommands() {
return {
updatePageBreakBackground: (color) => () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/screenplay/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ export const useScriptioEditor = (
sceneBookmarkExtension,
sceneNumberRightExtension,
sceneIdDedupExtension,
commentMarkExtension,
/*commentMarkExtension,*/
],

onSelectionUpdate({ editor, transaction }) {
Expand Down