From 9e69baeb7eae278b1f5a6423cd047d64e76b4fef Mon Sep 17 00:00:00 2001 From: soufiane Date: Thu, 7 Aug 2025 12:43:03 +0200 Subject: [PATCH] wait #7682 @9:00 --- .../MarkdownOperation.php | 3 +- app/Models/FluidbookDocument.php | 3 + app/Models/FluidbookPublication.php | 7 +- resources/linkeditor/js/linkeditor.zoom.js | 1 - resources/markdowneditor/js/markdowneditor.js | 39 +++--- .../markdowneditor/js/markdowneditor.zoom.js | 122 ++++++++++++++++++ resources/markdowneditor/style/style.sass | 10 +- .../markdown_editor.blade.php | 2 +- 8 files changed, 165 insertions(+), 22 deletions(-) create mode 100644 resources/markdowneditor/js/markdowneditor.zoom.js diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php index 3c2ff7627..228bd0b46 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php @@ -31,6 +31,7 @@ trait MarkdownOperation $token = Str::random(10); $contents = $this->getLatestMarkdown($id); + $fluidbook=FluidbookPublication::find($id); return view('fluidbook_publication.markdown_editor', ['contents' => $contents, 'version' => 'stable', 'id' => $id, 'fluidbook' => $fluidbook, 'access' => "", 'token' => $token]); @@ -51,7 +52,7 @@ trait MarkdownOperation } } - return $fluidbook->getAccessibleContents()['pages']; + return $fluidbook->getAccessibleContents(); } protected function saveMarkdown($fluidbook_id, $message = '', $md = '[]') diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index ee894ef29..6d35e1dd8 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -238,14 +238,17 @@ class FluidbookDocument extends ToolboxModel } } + $region = $forceRegion ?? $this->getRegion(); $base = 'fluidbookpublication/docs/' . $this->id . '/' . $path; $res = Files::mkdir($region == Region::EUROPE ? protected_path($base) : us_protected_path($base)); + if ($fname) { $res .= $fname; } + return $res; } diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index 75ee74c96..a9637bd55 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -477,8 +477,13 @@ class FluidbookPublication extends ToolboxStatusModel if (!file_exists($file)) { if ($revision === 'latest') { $json = ['pages' => []]; + foreach ($this->getComposition() as $page => $d) { - $json['pages'][$page] = file_get_contents($this->getAccessibleFile($page)); + try { + $json['pages'][$page] = file_get_contents($this->getAccessibleFile($page)); + }catch (\Exception $e) { + dump($page, $e->getMessage()); + } } file_put_contents($file, gzencode(json_encode($json))); diff --git a/resources/linkeditor/js/linkeditor.zoom.js b/resources/linkeditor/js/linkeditor.zoom.js index 82735bbcf..8a6f017bb 100644 --- a/resources/linkeditor/js/linkeditor.zoom.js +++ b/resources/linkeditor/js/linkeditor.zoom.js @@ -84,7 +84,6 @@ LinkeditorZoom.prototype = { this.linkeditor.rulers.updateRulers(); const $this = this $this.linkeditor.previewLinks.setPreview(true) - }, normalizeZoom: function (z) { diff --git a/resources/markdowneditor/js/markdowneditor.js b/resources/markdowneditor/js/markdowneditor.js index 75eb92239..a29d9494f 100644 --- a/resources/markdowneditor/js/markdowneditor.js +++ b/resources/markdowneditor/js/markdowneditor.js @@ -3,6 +3,7 @@ import MarkdowneditorToolbar from "./markdowneditor.toolbar"; import MarkdowneditorUndo from "./markdowneditor.undo"; import MarkdowneditorSave from "./markdowneditor.save"; import MarkdowneditorVersions from "./markdowneditor.versions"; +import MarkdowneditorZoom from "./markdowneditor.zoom"; import tippy from "tippy.js"; import 'tippy.js/dist/tippy.css'; @@ -18,6 +19,8 @@ window.key.filter = function (event) { return keyfilter(event); }; +require('jquery.scrollto'); + function keyfilter(event, disable = false) { if (disable) { return false @@ -56,6 +59,8 @@ MarkdownEditor.prototype = { this.undo = new MarkdowneditorUndo(this); this.save = new MarkdowneditorSave(this); this.versions = new MarkdowneditorVersions(this); + this.zoom = new MarkdowneditorZoom(this); + this.open = false this.savedScroll = null; @@ -144,24 +149,19 @@ MarkdownEditor.prototype = { const container = document.querySelector("#markdown-preview .markdown-wrapper") var imageFormat = FLUIDBOOK_DATA.settings.imageFormat ?? 'jpg'; - var c = '
'; - //if (this.linkeditor.utils.isSpecialPage(p)) { - //let data = this.linkeditor.utils.getSpecialPageAssetData(p); - //c += ''; - //} else { - if (this.pagesSource === 'pages') { - if (this.rasterizePages.indexOf(p) >= 0) { - c += ''; - } else if (this.vectorPages.indexOf(p) >= 0) { - c += ''; - } else { - c += ''; - c += ''; - } - } else if (this.pagesSource === 'thumbnails') { - c += ''; + var c = '
'; + if (this.pagesSource === 'pages') { + if (this.rasterizePages.indexOf(p) >= 0) { + c += ''; + } else if (this.vectorPages.indexOf(p) >= 0) { + c += ''; + } else { + c += ''; + c += ''; } - //} + } else if (this.pagesSource === 'thumbnails') { + c += ''; + } c += '
'; if (p > 0 || p <= FLUIDBOOK_DATA.settings.pages) { container.innerHTML = c; @@ -332,6 +332,11 @@ MarkdownEditor.prototype = { timeout: timeout, }).show(); }, + + setMouseCoordinates: function (e) { + this.mx = e.pageX; + this.my = e.pageY; + }, } diff --git a/resources/markdowneditor/js/markdowneditor.zoom.js b/resources/markdowneditor/js/markdowneditor.zoom.js new file mode 100644 index 000000000..6eed8b0c1 --- /dev/null +++ b/resources/markdowneditor/js/markdowneditor.zoom.js @@ -0,0 +1,122 @@ +function MarkdowneditorZoom(markdowneditor) { + this.markdowneditor = markdowneditor; + this.init(); +} + +MarkdowneditorZoom.prototype = { + init: function () { + var $this = this; + + this.zoom = 1; + this.zoomdragging = false; + this.mx = 0; + this.my = 0; + this.canvasRect = $("#markdown-preview").get(0).getBoundingClientRect() + this.initialWidth = $("#markdown-wrapper")[0].getBoundingClientRect().width + this.initialHeight = $("#markdown-wrapper")[0].getBoundingClientRect().height + this.container = $("#markdown-wrapper") + this.content = $('#markdown-zoom'); + this.ctrl = false + + $(window).on('mousemove mousedown mouseup', function (e) { + $this.setMouseCoordinates(e); + }) + + $(document).on('keydown', function(e){ + $this.ctrl = e.ctrlKey + }) + + $(document).on('keyup', function(e){ + $this.ctrl = false + }) + + $("#markdown-preview").on('mousewheel', function (e) { + e.stopPropagation(); + if($this.ctrl) { + + var step = $this.zoom >= 1 ? 0.25 : 0.1; + $this.setMouseCoordinates(e); + let cursorPositionOnFluidbookBeforeZoom = $this.getFluidbookPositionOfCursor(); + + const centerX = ($this.container.scrollLeft() + $this.container.width() / 2) / $this.zoom; + const centerY = ($this.container.scrollTop() + $this.container.height() / 2) / $this.zoom; + + let delta = e.originalEvent.deltaY; + if (delta === 0) { + return true; + } + + e.stopPropagation(); + e.stopImmediatePropagation(); + e.preventDefault(); + + if ($this.setZoom($this.zoom + step * (delta > 0 ? -1 : 1), e)) { + $this.moveZoomAfterWheelZoom(centerX, centerY); + } + + return false; + } + }); + + $(document).on("click", "#markdown-preview", function(e) { + const centerX = ($this.container.scrollLeft() + $this.container.width() / 2) / $this.zoom; + const centerY = ($this.container.scrollTop() + $this.container.height() / 2) / $this.zoom; + e.stopPropagation(); + e.stopImmediatePropagation(); + e.preventDefault(); + if($this.zoomdragging) { + $this.zoomdragging = false + $this.setZoom(1) + console.log() + $("#markdowneditor-zoom").css("cursor","zoom-in") + return false; + } + $this.zoomdragging = true + $this.setZoom(3) + $("#markdowneditor-zoom").css("cursor","zoom-out") + console.log(centerY,centerX) + $this.moveZoomAfterWheelZoom(centerX,centerY); + }) + }, + + setZoom: function(z) { + const $this = this + z = this.normalizeZoom(z); + this.zoom = z; + + $("#markdowneditor-zoom").css({ + //transform: 'scale(' + $this.zoom + ')', + width: $this.initialWidth * $this.zoom, + height: $this.initialHeight * $this.zoom, + margin: "0 auto" + }) + + return true; + }, + + moveZoomAfterWheelZoom: function (centerX,centerY) { + this.container.scrollLeft(centerX * this.zoom - this.container.width() / 2); + this.container.scrollTop(centerY * this.zoom - this.container.height() / 2); + }, + + getFluidbookPositionOfCursor: function () { + let rect = $("#markdowneditor-zoom").get(0).getBoundingClientRect(); + let lx = (this.mx - rect.x) / rect.width; + let ly = (this.my - rect.y) / rect.height; + + return {x: rect.x, y: rect.y, width: rect.width, height: rect.height}; + }, + + setMouseCoordinates: function (e) { + this.mx = e.pageX; + this.my = e.pageY; + }, + + normalizeZoom: function (z) { + if (this.markdowneditor.mobileFirst) { + return 1; + } + return Math.max(1, Math.min(8, z)); + } +}; +export default MarkdowneditorZoom; diff --git a/resources/markdowneditor/style/style.sass b/resources/markdowneditor/style/style.sass index 34e41b439..ca463a464 100644 --- a/resources/markdowneditor/style/style.sass +++ b/resources/markdowneditor/style/style.sass @@ -209,14 +209,22 @@ body transform: translate(-50%,-50%) &-wrapper - display: flex + //display: flex align-items: center user-select: none position: relative height: 100% overflow: auto margin-right: 7px + justify-content: center + #markdowneditor-zoom + width: 100% + height: 100% + will-change: transform + cursor: zoom-in + //transition: all .3s + //position: absolute &-page width: 100% diff --git a/resources/views/fluidbook_publication/markdown_editor.blade.php b/resources/views/fluidbook_publication/markdown_editor.blade.php index 5aa35553a..5aaa4cbb9 100644 --- a/resources/views/fluidbook_publication/markdown_editor.blade.php +++ b/resources/views/fluidbook_publication/markdown_editor.blade.php @@ -118,7 +118,7 @@
-
+
-- 2.39.5