From 83833ba585eb638df6f54825ac5cc93550fe7d61 Mon Sep 17 00:00:00 2001 From: Rahman Ramsi Date: Sat, 18 Jun 2022 11:32:13 +0800 Subject: [PATCH] add drag-drop --- package-lock.json | 13 +++ package.json | 1 + resources/dist/js/editor.js | 16 ++++ resources/js/editor.js | 169 ++++++++++++++++++------------------ 4 files changed, 114 insertions(+), 85 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4366bb..5ab0727 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@editorjs/raw": "^2.3.1", "@tailwindcss/typography": "^0.5.2", "autoprefixer": "^10.4.7", + "editorjs-drag-drop": "^1.1.2", "editorjs-style": "^3.0.3", "editorjs-undo": "^1.0.1", "laravel-mix": "^6.0.49", @@ -4196,6 +4197,12 @@ "integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==", "dev": true }, + "node_modules/editorjs-drag-drop": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/editorjs-drag-drop/-/editorjs-drag-drop-1.1.2.tgz", + "integrity": "sha512-vgr0QgYScfIp1kurfh8FmceIAnS+ce3Vdtt5Z2SYTf3j0/eL3B5o5FrwOLJBv9GLumqXETZXbYcCo8Q75c7twQ==", + "dev": true + }, "node_modules/editorjs-style": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/editorjs-style/-/editorjs-style-3.0.3.tgz", @@ -12569,6 +12576,12 @@ "integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==", "dev": true }, + "editorjs-drag-drop": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/editorjs-drag-drop/-/editorjs-drag-drop-1.1.2.tgz", + "integrity": "sha512-vgr0QgYScfIp1kurfh8FmceIAnS+ce3Vdtt5Z2SYTf3j0/eL3B5o5FrwOLJBv9GLumqXETZXbYcCo8Q75c7twQ==", + "dev": true + }, "editorjs-style": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/editorjs-style/-/editorjs-style-3.0.3.tgz", diff --git a/package.json b/package.json index cf1fcc2..7ece9ee 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@editorjs/raw": "^2.3.1", "@tailwindcss/typography": "^0.5.2", "autoprefixer": "^10.4.7", + "editorjs-drag-drop": "^1.1.2", "editorjs-style": "^3.0.3", "editorjs-undo": "^1.0.1", "laravel-mix": "^6.0.49", diff --git a/resources/dist/js/editor.js b/resources/dist/js/editor.js index 8bba2d5..e026ddc 100644 --- a/resources/dist/js/editor.js +++ b/resources/dist/js/editor.js @@ -208,6 +208,9 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _editorjs_delimiter__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_editorjs_delimiter__WEBPACK_IMPORTED_MODULE_10__); /* harmony import */ var editorjs_style__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! editorjs-style */ "./node_modules/editorjs-style/dist/index.js"); /* harmony import */ var editorjs_style__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(editorjs_style__WEBPACK_IMPORTED_MODULE_11__); +/* harmony import */ var editorjs_drag_drop__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! editorjs-drag-drop */ "./node_modules/editorjs-drag-drop/dist/bundle.js"); +/* harmony import */ var editorjs_drag_drop__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(editorjs_drag_drop__WEBPACK_IMPORTED_MODULE_12__); + @@ -297,6 +300,9 @@ document.addEventListener("alpine:init", function () { _this.instance.save().then(function (outputData) { _this.state = outputData; }); + }, + onReady: function onReady() { + new (editorjs_drag_drop__WEBPACK_IMPORTED_MODULE_12___default())(_this.instance); } }); } @@ -306,6 +312,16 @@ document.addEventListener("alpine:init", function () { /***/ }), +/***/ "./node_modules/editorjs-drag-drop/dist/bundle.js": +/*!********************************************************!*\ + !*** ./node_modules/editorjs-drag-drop/dist/bundle.js ***! + \********************************************************/ +/***/ ((module) => { + +!function(e,t){ true?module.exports=t():0}(self,(function(){return(()=>{var e={424:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var n=r(81),o=r.n(n),i=r(645),a=r.n(i)()(o());a.push([e.id,'.ce-block--drop-target .ce-block__content:before {\n content: "";\n position: absolute;\n top: 50%;\n left: -20px;\n margin-top: -1px;\n height: 8px;\n width: 8px;\n border: solid #a0a0a0;\n border-width: 1px 1px 0 0;\n -webkit-transform-origin: right;\n transform-origin: right;\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n}\n\n.ce-block--drop-target .ce-block__content:after {\n background: none;\n}',""]);const s=a},645:e=>{"use strict";e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var r="",n=void 0!==t[5];return t[4]&&(r+="@supports (".concat(t[4],") {")),t[2]&&(r+="@media ".concat(t[2]," {")),n&&(r+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),r+=e(t),n&&(r+="}"),t[2]&&(r+="}"),t[4]&&(r+="}"),r})).join("")},t.i=function(e,r,n,o,i){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(n)for(var s=0;s0?" ".concat(u[5]):""," {").concat(u[1],"}")),u[5]=i),r&&(u[2]?(u[1]="@media ".concat(u[2]," {").concat(u[1],"}"),u[2]=r):u[2]=r),o&&(u[4]?(u[1]="@supports (".concat(u[4],") {").concat(u[1],"}"),u[4]=o):u[4]="".concat(o)),t.push(u))}},t}},81:e=>{"use strict";e.exports=function(e){return e[1]}},406:(e,t,r)=>{var n=r(424);"string"==typeof n&&(n=[[e.id,n,""]]);r(723)(n,{hmr:!0,transform:void 0,insertInto:void 0}),n.locals&&(e.exports=n.locals)},723:(e,t,r)=>{var n,o,i={},a=(n=function(){return window&&document&&document.all&&!window.atob},function(){return void 0===o&&(o=n.apply(this,arguments)),o}),s=function(e){return document.querySelector(e)},c=function(e){var t={};return function(e){if("function"==typeof e)return e();if(void 0===t[e]){var r=s.call(this,e);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}}(),l=null,u=0,f=[],d=r(947);function p(e,t){for(var r=0;r=0&&f.splice(t,1)}function y(e){var t=document.createElement("style");return void 0===e.attrs.type&&(e.attrs.type="text/css"),g(t,e.attrs),v(e,t),t}function g(e,t){Object.keys(t).forEach((function(r){e.setAttribute(r,t[r])}))}function m(e,t){var r,n,o,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var a=u++;r=l||(l=y(t)),n=x.bind(null,r,a,!1),o=x.bind(null,r,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(r=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",g(t,e.attrs),v(e,t),t}(t),n=O.bind(null,r,t),o=function(){b(r),r.href&&URL.revokeObjectURL(r.href)}):(r=y(t),n=B.bind(null,r),o=function(){b(r)});return n(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;n(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var r=h(e,t);return p(r,t),function(e){for(var n=[],o=0;o{e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var r=t.protocol+"//"+t.host,n=r+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,(function(e,t){var o,i=t.trim().replace(/^"(.*)"$/,(function(e,t){return t})).replace(/^'(.*)'$/,(function(e,t){return t}));return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?r+i:n+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")}))}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={id:n,exports:{}};return e[n](i,i.exports,r),i.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";function e(e,t){for(var r=0;rt}),r(406);var t=function(){function t(e,r){var n=e.configuration,o=e.blocks,i=e.toolbar,a=e.save;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),this.toolbar=i,this.borderStyle=r||"1px dashed #aaa",this.api=o,this.holder="string"==typeof n.holder?document.getElementById(n.holder):n.holder,this.readOnly=n.readOnly,this.startBlock=null,this.endBlock=null,this.save=a,this.setDragListener(),this.setDropListener()}var r,n,o;return r=t,o=[{key:"isReadOnlySupported",get:function(){return!0}}],(n=[{key:"setElementCursor",value:function(e){if(e){var t=document.createRange(),r=window.getSelection();t.setStart(e.childNodes[0],0),t.collapse(!0),r.removeAllRanges(),r.addRange(t),e.focus()}}},{key:"setDragListener",value:function(){var e=this;if(!this.readOnly){var t=this.holder.querySelector(".ce-toolbar__settings-btn");t.setAttribute("draggable","true"),t.addEventListener("dragstart",(function(){e.startBlock=e.api.getCurrentBlockIndex()})),t.addEventListener("drag",(function(){if(e.toolbar.close(),!e.isTheOnlyBlock()){var t=e.holder.querySelectorAll(".ce-block"),r=e.holder.querySelector(".ce-block--drop-target");e.setElementCursor(r),e.setBorderBlocks(t,r)}}))}}},{key:"setBorderBlocks",value:function(e,t){var r=this;Object.values(e).forEach((function(n){var o=n.querySelector(".ce-block__content");n!==t?(o.style.removeProperty("border-top"),o.style.removeProperty("border-bottom")):Object.keys(e).find((function(r){return e[r]===t}))>r.startBlock?o.style.borderBottom=r.borderStyle||borderStyle:o.style.borderTop=r.borderStyle}))}},{key:"setDropListener",value:function(){var e=this;document.addEventListener("drop",(function(t){var r=t.target;if(e.holder.contains(r)){var n=e.getDropTarget(r);if(n){var o=n.querySelector(".ce-block__content");o.style.removeProperty("border-top"),o.style.removeProperty("border-bottom"),e.endBlock=e.getTargetPosition(n),e.moveBlocks()}}}))}},{key:"getDropTarget",value:function(e){return e.classList.contains("ce-block")?e:e.closest(".ce-block")}},{key:"getTargetPosition",value:function(e){return Array.from(e.parentNode.children).indexOf(e)}},{key:"isTheOnlyBlock",value:function(){return 1===this.api.getBlocksCount()}},{key:"moveBlocks",value:function(){this.isTheOnlyBlock()||this.api.move(this.endBlock,this.startBlock)}}])&&e(r.prototype,n),o&&e(r,o),Object.defineProperty(r,"prototype",{writable:!1}),t}()})(),n.default})()})); + +/***/ }), + /***/ "./node_modules/editorjs-style/dist/index.js": /*!***************************************************!*\ !*** ./node_modules/editorjs-style/dist/index.js ***! diff --git a/resources/js/editor.js b/resources/js/editor.js index 07fa6f1..9e0c8ab 100644 --- a/resources/js/editor.js +++ b/resources/js/editor.js @@ -10,95 +10,94 @@ import Table from "@editorjs/table"; import RawTool from "@editorjs/raw"; import Delimiter from "@editorjs/delimiter"; import { StyleInlineTool } from "editorjs-style"; +import DragDrop from "editorjs-drag-drop"; document.addEventListener("alpine:init", () => { - Alpine.data( - "editorjs", - ({ state, statePath, placeholder, readOnly, tools }) => ({ - instance: null, - state: state, - tools: tools, - init() { - let enabledTools = {}; + Alpine.data( + "editorjs", + ({ state, statePath, placeholder, readOnly, tools }) => ({ + instance: null, + state: state, + tools: tools, + init() { + let enabledTools = {}; - if (this.tools.includes("header")) enabledTools.header = Header; - if (this.tools.includes("image")) { - enabledTools.image = { - class: ImageTool, - config: { - uploader: { - uploadByFile: (file) => { - return new Promise((resolve) => { - this.$wire.upload( - `componentFileAttachments.${statePath}`, - file, - (uploadedFilename) => { - this.$wire - .getComponentFileAttachmentUrl( - statePath - ) - .then((url) => { - if (!url) { - return resolve({ - success: 0, - }); - } - return resolve({ - success: 1, - file: { - url: url, - }, - }); - }); - } - ); - }); - }, + if (this.tools.includes("header")) enabledTools.header = Header; + if (this.tools.includes("image")) { + enabledTools.image = { + class: ImageTool, + config: { + uploader: { + uploadByFile: (file) => { + return new Promise((resolve) => { + this.$wire.upload( + `componentFileAttachments.${statePath}`, + file, + (uploadedFilename) => { + this.$wire + .getComponentFileAttachmentUrl(statePath) + .then((url) => { + if (!url) { + return resolve({ + success: 0, + }); + } + return resolve({ + success: 1, + file: { + url: url, + }, + }); + }); + } + ); + }); + }, - uploadByUrl: (url) => { - return this.$wire - .loadImageFromUrl(url) - .then((result) => { - return { - success: 1, - file: { - url: result, - }, - }; - }); - }, - }, - }, + uploadByUrl: (url) => { + return this.$wire.loadImageFromUrl(url).then((result) => { + return { + success: 1, + file: { + url: result, + }, }; - } - if (this.tools.includes("delimiter")) - enabledTools.delimiter = Delimiter; - if (this.tools.includes("list")) enabledTools.list = List; - if (this.tools.includes("underline")) - enabledTools.underline = Underline; - if (this.tools.includes("quote")) enabledTools.quote = Quote; - if (this.tools.includes("table")) enabledTools.table = Table; - if (this.tools.includes("raw")) enabledTools.raw = RawTool; - if (this.tools.includes("code")) enabledTools.code = Code; - if (this.tools.includes("inline-code")) - enabledTools.inlineCode = InlineCode; - if (this.tools.includes("style")) - enabledTools.style = StyleInlineTool; - this.instance = new EditorJS({ - holder: this.$el, - minHeight: 30, - data: this.state, - placeholder: placeholder, - readOnly: readOnly, - tools: enabledTools, - - onChange: () => { - this.instance.save().then((outputData) => { - this.state = outputData; - }); - }, - }); + }); + }, + }, }, - }) - ); + }; + } + if (this.tools.includes("delimiter")) + enabledTools.delimiter = Delimiter; + if (this.tools.includes("list")) enabledTools.list = List; + if (this.tools.includes("underline")) + enabledTools.underline = Underline; + if (this.tools.includes("quote")) enabledTools.quote = Quote; + if (this.tools.includes("table")) enabledTools.table = Table; + if (this.tools.includes("raw")) enabledTools.raw = RawTool; + if (this.tools.includes("code")) enabledTools.code = Code; + if (this.tools.includes("inline-code")) + enabledTools.inlineCode = InlineCode; + if (this.tools.includes("style")) enabledTools.style = StyleInlineTool; + this.instance = new EditorJS({ + holder: this.$el, + minHeight: 30, + data: this.state, + placeholder: placeholder, + readOnly: readOnly, + tools: enabledTools, + + onChange: () => { + this.instance.save().then((outputData) => { + this.state = outputData; + }); + }, + onReady: () => { + new DragDrop(this.instance); + }, + }); + }, + }) + ); });