]> _ Git - fluidbook-toolbox.git/commitdiff
wait #7634 @5:00
authorsoufiane <soufiane@cubedesigners.com>
Wed, 9 Jul 2025 15:13:31 +0000 (17:13 +0200)
committersoufiane <soufiane@cubedesigners.com>
Wed, 9 Jul 2025 15:13:31 +0000 (17:13 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/MarkdownOperation.php
resources/markdowneditor/js/markdowneditor.js
resources/markdowneditor/style/style.sass
resources/views/fluidbook_publication/markdown_editor.blade.php

index 3e4e1c03533abdeb0399b70bc17653986a493941..0a3057556a11fe53c7e0ac0b9dc1b6e1275bf55a 100644 (file)
@@ -12,9 +12,10 @@ trait MarkdownOperation
     protected function setupMarkdownRoutes($segment, $routeName, $controller)
     {
         Route::match(['get'], $segment . '/{id}/edit/markdown', $controller . '@markdown')->name('fluidbook_markdowneditor');
+        Route::match(['post'], $segment . '/{id}/markdown', $controller . '@getFilesById');
     }
 
-    public function markdown($id, Request $request)
+    public function markdown($id)
     {
         if (!FluidbookPublication::hasPermission($id)) {
             abort(401);
@@ -24,4 +25,13 @@ trait MarkdownOperation
 
         return view('fluidbook_publication.markdown_editor', ['version' => 'stable', 'id' => $id, 'fluidbook' => FluidbookPublication::find($id), 'access' => "", 'token' => $token]);
     }
+
+    public static function getFilesById(Request $request,$id) {
+        $p = $request->page;
+        $path = public_path("/markdown_files/$id/p$p.md");
+
+        if(!file_exists($path)) return false;
+
+        return file_get_contents(public_path("/markdown_files/$id/p$p.md"));
+    }
 }
index d89096a98d6cec44a1e9bdafae1651e8e6388bd7..0a41ecb8dd669ff0c2374147f6f4db6fac11004c 100644 (file)
@@ -1,19 +1,44 @@
+import Editor from '@toast-ui/editor';
+window.$ = window.jQuery = require('jquery');
+
+$.ajaxSetup({
+    headers: {
+        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
+    }
+});
+
+
 function MarkdownEditor() {
+    this.mobileFirst = FLUIDBOOK_DATA.settings.mobileNavigationType === 'mobilefirst';
+    this.single = ['mobilefirst', 'portrait'].indexOf(FLUIDBOOK_DATA.settings.mobileNavigationType) >= 0 || FLUIDBOOK_DATA.settings.pages <= 1;
+    this.pagesSource = 'pages';
+    this.rasterizePages = this.splitPages(FLUIDBOOK_DATA.settings.rasterizePages);
+    this.vectorPages = this.splitPages(FLUIDBOOK_DATA.settings.vectorPages);
+    this.noCache = '?t=' + (new Date(FLUIDBOOK_DATA.composition_updated_at)).getTime();
+    this.currentPage = Math.max(0,parseInt(window.location.hash.substring(1))) || 0;
+    this.editor = null;
     this.init()
 }
 
 MarkdownEditor.prototype = {
     init: function() {
-        this.pagesSource = 'pages';
-        this.rasterizePages = this.splitPages(FLUIDBOOK_DATA.settings.rasterizePages);
-        this.vectorPages = this.splitPages(FLUIDBOOK_DATA.settings.vectorPages);
-        this.noCache = '?t=' + (new Date(FLUIDBOOK_DATA.composition_updated_at)).getTime();
+        this.markdown();
         this.loadPage(2)
     },
 
-    loadPage: function(p,side) {
-        const container = document.querySelector("#markdown-preview")
+    loadPage: function() {
+        this.loadPageHtml(this.currentPage, 'left');
+        if (!this.single) {
+            this.loadPageHtml(this.currentPage + 1, 'right');
+        }
+
+        this.setContentMarkdown()
+    },
+
+    loadPageHtml: function(p,side) {
+        const container = document.querySelector("#markdown-page-"+side)
         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);
@@ -33,7 +58,9 @@ MarkdownEditor.prototype = {
             }
         //}
         c += '</div>';
-        container.innerHTML = c;
+        if (p > 0 || p <= FLUIDBOOK_DATA.settings.pages) {
+            container.innerHTML = c;
+        }
     },
 
     splitPages: function (str) {
@@ -51,6 +78,37 @@ MarkdownEditor.prototype = {
         }
         return res;
     },
+
+    setContentMarkdown: function() {
+        if(this.currentPage === 0) this.currentPage = 1
+        const $this = this
+        $.ajax({
+            url: '/fluidbook-publication/' + FLUIDBOOK_DATA.id +'/markdown',
+            type: 'post',
+            data: {page:this.currentPage},
+            success: function (response) {
+                $this.editor.setMarkdown(response)
+                $this.editor.moveCursorToStart(true)
+            }
+        });
+    },
+
+    markdown: function() {
+        this.editor = new Editor({
+            el: document.querySelector('#editor'),
+            initialEditType: 'markdown',
+            previewStyle: 'vertical'
+        });
+
+        this.editor.getMarkdown();
+    }
+
+    /*isSpecialPage: function (page) {
+        if (page === undefined) {
+            page = this.linkeditor.currentPage;
+        }
+        return page.toString().indexOf('link_') === 0 || (THEME[page] !== undefined && THEME[page] !== null);
+    },*/
 }
 
 
index 8c27bf51224a9d1ebc8dd7911fd7702156e79aac..dcdc8ce816b4c8d5c6cfc3e37bbe69a9c8881e0a 100644 (file)
@@ -24,3 +24,11 @@ body
             top: 50%
             left: 50%
             transform: translate(-50%,-50%)
+
+    &-wrapper
+        display: flex
+        align-items: center
+
+    &-page
+        width: 50%
+        position: relative
index 84ab323b47666d66c1d9a911c6bad690dce42c01..490c863d54b243bdec17826fb753a80273747859 100644 (file)
 @section('content')
     <div class="markdown-editor">
         <div id="markdown-preview" class="markdown-container">
-            <div id="left"></div>
-            <div id="right"></div>
+            <div class="markdown-wrapper">
+                <div draggable="false" class="markdown-page" id="markdown-page-left"></div>
+                <div draggable="false" class="markdown-page" id="markdown-page-right"></div>
+            </div>
         </div>
         <div id="editor" class="markdown-editor-container"></div>
     </div>
         src="/packages/markdowneditor/js/markdowneditor.js?v={{filemtime(public_path('packages/markdowneditor/js/markdowneditor.js'))}}"></script>
     <script src="https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js"></script>
     <script>
-        const editor = new toastui.Editor({
-            el: document.querySelector('#editor'),
-            initialEditType: 'markdown',
-            initialValue: '{{ $content }}',
-            previewStyle: 'vertical'
-        });
 
-        editor.getMarkdown();
     </script>
 @endpush