]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7682 @9:00
authorsoufiane <soufiane@cubedesigners.com>
Thu, 7 Aug 2025 10:43:03 +0000 (12:43 +0200)
committersoufiane <soufiane@cubedesigners.com>
Thu, 7 Aug 2025 10:43:03 +0000 (12:43 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php
app/Models/FluidbookDocument.php
app/Models/FluidbookPublication.php
resources/linkeditor/js/linkeditor.zoom.js
resources/markdowneditor/js/markdowneditor.js
resources/markdowneditor/js/markdowneditor.zoom.js [new file with mode: 0644]
resources/markdowneditor/style/style.sass
resources/views/fluidbook_publication/markdown_editor.blade.php

index 3c2ff76272e698847f13094a4a434b25d676adb5..228bd0b468cbedfe816738fcbb33d5bd577fd1e8 100644 (file)
@@ -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 = '[]')
index ee894ef298de33f61f2b4bb7502383fc2d510b61..6d35e1dd82680f128c1d83d8ff4e0e9cca574d40 100644 (file)
@@ -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;
     }
 
index 75ee74c96650c1152484b808d5adcb7dd84ceda6..a9637bd55a30acf206a545de56c4d8e02de56299 100644 (file)
@@ -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)));
index 82735bbcfa74df91d7f2aa2359e6faba6ea2b866..8a6f017bbbb5055bd2bccead2027aa5ef75bcf2d 100644 (file)
@@ -84,7 +84,6 @@ LinkeditorZoom.prototype = {
         this.linkeditor.rulers.updateRulers();
         const $this = this
         $this.linkeditor.previewLinks.setPreview(true)
-
     },
 
     normalizeZoom: function (z) {
index 75eb92239438b86891bbc83940d0a11e2d875d70..a29d9494f28048b5bef26db8f5b70405c948b4ba 100644 (file)
@@ -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 = '<div class="contents">';
-        //if (this.linkeditor.utils.isSpecialPage(p)) {
-            //let data = this.linkeditor.utils.getSpecialPageAssetData(p);
-            //c += '<img draggable="false" width="' + data.dim[0] + '" height="' + data.dim[1] + '" class="images" src="' + data.url + '" />';
-        //} else {
-            if (this.pagesSource === 'pages') {
-                if (this.rasterizePages.indexOf(p) >= 0) {
-                    c += '<img draggable="false" src="raster_' + p + '.' + imageFormat + this.noCache + '" />';
-                } else if (this.vectorPages.indexOf(p) >= 0) {
-                    c += '<img draggable="false" src="vector_' + p + '.svg' + this.noCache + '" />';
-                } else {
-                    c += '<img draggable="false" class="images" src="images_' + p + '.' + imageFormat + this.noCache + '" />';
-                    c += '<img draggable="false" class="texts" src="texts_' + p + '.svg' + this.noCache + '" />';
-                }
-            } else if (this.pagesSource === 'thumbnails') {
-                c += '<img draggable="false" src="thumbspdf_' + p + '.' + imageFormat + this.noCache + '" />';
+        var c = '<div id="markdowneditor-zoom" class="contents">';
+        if (this.pagesSource === 'pages') {
+            if (this.rasterizePages.indexOf(p) >= 0) {
+                c += '<img draggable="false" src="raster_' + p + '.' + imageFormat + this.noCache + '" />';
+            } else if (this.vectorPages.indexOf(p) >= 0) {
+                c += '<img draggable="false" src="vector_' + p + '.svg' + this.noCache + '" />';
+            } else {
+                c += '<img draggable="false" class="images" src="images_' + p + '.' + imageFormat + this.noCache + '" />';
+                c += '<img draggable="false" class="texts" src="texts_' + p + '.svg' + this.noCache + '" />';
             }
-        //}
+        } else if (this.pagesSource === 'thumbnails') {
+            c += '<img draggable="false" src="thumbspdf_' + p + '.' + imageFormat + this.noCache + '" />';
+        }
         c += '</div>';
         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 (file)
index 0000000..6eed8b0
--- /dev/null
@@ -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;
index 34e41b439199faf260c1eb35136b37df99336425..ca463a4644a0f05ed7e3454fc30fb911f7885b2c 100644 (file)
@@ -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%
index 5aa35553a357b4c1725f862365a5f12c0397c080..5aaa4cbb9dc3cf8e5c5694e198349c9bb731276d 100644 (file)
                 </nav>
             </div>
             <div id="markdown-preview" class="markdown-container">
-                <div class="markdown-wrapper">
+                <div id="markdown-wrapper" class="markdown-wrapper">
                 </div>
                 <div class="handle preview-handle"></div>
             </div>