@themarioga/grid-editor 9.0.0-beta.2 → 9.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +76 -8
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.css +187 -0
- package/dist/grideditor.d.ts +75 -0
- package/dist/grideditor.esm.js +38 -11
- package/dist/grideditor.js +38 -11
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/locales/grideditor.es.esm.js +22 -0
- package/dist/locales/grideditor.es.js +22 -0
- package/dist/locales/grideditor.es.min.js +2 -2
- package/dist/locales/grideditor.es.min.js.map +2 -2
- package/dist/plugins/grideditor.history.esm.js +360 -0
- package/dist/plugins/grideditor.history.js +365 -0
- package/dist/plugins/grideditor.history.min.js +1 -0
- package/dist/plugins/grideditor.history.min.js.map +7 -0
- package/dist/plugins/grideditor.offcanvas.esm.js +551 -0
- package/dist/plugins/grideditor.offcanvas.js +556 -0
- package/dist/plugins/grideditor.offcanvas.min.js +1 -0
- package/dist/plugins/grideditor.offcanvas.min.js.map +7 -0
- package/dist/plugins/grideditor.popup.esm.js +90 -37
- package/dist/plugins/grideditor.popup.js +90 -37
- package/dist/plugins/grideditor.popup.min.js +1 -1
- package/dist/plugins/grideditor.popup.min.js.map +4 -4
- package/docs/events.md +7 -3
- package/docs/locale-keys.md +32 -1
- package/docs/plugins.md +19 -5
- package/example/clipboard.html +22 -0
- package/example/containers.html +22 -4
- package/example/history.html +94 -0
- package/example/index.html +9 -1
- package/package.json +1 -1
- package/src/js/grideditor.js +37 -9
- package/src/js/locales/grideditor.es.js +22 -0
- package/src/js/plugins/grideditor.history.js +367 -0
- package/src/js/plugins/grideditor.offcanvas.js +420 -0
- package/src/js/plugins/grideditor.popup.js +8 -70
- package/src/js/triggers/triggers.js +121 -0
- package/src/less/grideditor.less +60 -0
- package/types/grideditor.d.ts +75 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var m=window.GridEditor;if(!m||typeof m.get!="function")throw new Error("grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, its locales and grideditor.jquery.js");function j(t,r){return t?t.querySelector(r):null}function F(t,r){return t?Array.prototype.filter.call(t.children,function(i){return!r||i.matches(r)}):[]}function A(t,r){return!!t&&t.nodeType===1&&t.matches(r)}function I(t,r,i){return W(r).forEach(function(o){i===void 0?t.classList.toggle(o):t.classList.toggle(o,!!i)}),t}function C(t,r){return!!t&&t.nodeType===1&&t.classList.contains(r)}function W(t){return String(t||"").split(/\s+/).filter(Boolean)}Object.assign(m.locales.en,{"history.undo":"Undo","history.redo":"Redo"});var L=50,S=500,Z=".ge-tools-drawer, .ge-drop-marker",$=".ge-drag-chosen, .ge-drag-placeholder, .ge-drag-helper, .ge-resizing",g=[],x=null;function z(t){x=g.filter(function(r){return r.contains(t.target)})[0]||null}document.addEventListener("pointerdown",z,!0);document.addEventListener("focusin",z,!0);function J(t){var r=(t.key||"").toLowerCase();return/^[a-z]$/.test(r)||(r={KeyZ:"z",KeyY:"y"}[t.code]||""),r==="z"||r==="y"?r:null}function Q(){var t=document.activeElement;return!!t&&(A(t,"input, textarea, select")||t.isContentEditable)}function M(t){return F(t).filter(function(r){return!A(r,Z)})}m.features.history=function(t){var r=P(t.settings.history||{}),i=[],o=-1,s={canUndo:!1,canRedo:!1},a=null,h=null,b=!1,U=!1,c=!1,l=!1,f=!1;function P(e){var n={shortcuts:e.shortcuts===void 0?!0:e.shortcuts,buttons:e.buttons===void 0?!0:e.buttons,max:e.max===void 0?L:e.max,delay:e.delay===void 0?S:e.delay};return["shortcuts","buttons"].forEach(function(u){typeof n[u]!="boolean"&&(t.warn("history."+u+" is true or false: true is used"),n[u]=!0)}),(!Number.isInteger(n.max)||n.max<1)&&(t.warn("history.max must be a whole number of steps, 1 or more: "+L+" is used"),n.max=L),(!Number.isInteger(n.delay)||n.delay<0)&&(t.warn("history.delay must be a whole number of milliseconds, 0 or more: "+S+" is used"),n.delay=S),n}function w(){h.observe(t.canvas,{subtree:!0,childList:!0,attributes:!0,characterData:!0}),b=!0}function E(){h&&h.disconnect(),b=!1}function v(){var e=b;e&&E();var n=t.snapshotHtml();return e&&w(),n}function O(){return C(t.canvas,"ge-editing")}function k(){return C(t.canvas,"ge-dropping")||!!j(t.canvas,$)}function R(){window.clearTimeout(a),a=window.setTimeout(N,r.delay)}function B(){return a!==null&&v()!==i[o]}function N(){if(window.clearTimeout(a),a=null,!(!c||f||l)){if(k()){R();return}var e=v();e!==i[o]&&(i.splice(o+1),i.push(e),i.length>r.max+1&&i.shift(),o=i.length-1,y())}}function y(){var e={canUndo:o>0,canRedo:o<i.length-1},n=e.canUndo!==s.canUndo||e.canRedo!==s.canRedo;s=e,Y(),n&&t.emit("history-change",{canvas:t.canvas,canUndo:e.canUndo,canRedo:e.canRedo})}function Y(){t.toolbarItems("history").forEach(function(e){var n=e.getAttribute("data-ge-item")==="0"?!s.canUndo:!s.canRedo;I(e,"disabled",n),n?e.setAttribute("aria-disabled","true"):e.removeAttribute("aria-disabled")})}function D(e){if(!e||e===t.canvas||!t.canvas.contains(e))return null;for(var n=[],u=e;u!==t.canvas;u=u.parentElement)n.unshift(M(u.parentElement).indexOf(u));return n}function H(e){if(!e)return null;for(var n=t.canvas,u=0;u<e.length&&n;u++)n=M(n)[e[u]];return n||null}function d(e,n){if(!c||f||l||!O()||k())return!1;N();var u=o+e;if(u<0||u>=i.length)return!1;var G=D(t.getSelected()),_=D(t.getActiveTarget());E(),o=u,t.setHtml(i[o]),i[o]=t.snapshotHtml();var p=H(G);return p&&t.setSelected(p),p=H(_),p&&t.setActiveTarget(p),w(),y(),t.emit(e<0?"after-undo":"after-redo",{canvas:t.canvas,html:i[o],source:n}),!0}function K(e){if(!(x!==t||e.altKey||!(e.ctrlKey||e.metaKey))){var n=J(e);!n||n==="y"&&e.shiftKey||!O()||Q()||t.panelOpen()||d(n==="y"||e.shiftKey?1:-1,"shortcut")&&e.preventDefault()}}function T(e){var n=g.indexOf(t);e&&n===-1?(g.push(t),document.addEventListener("keydown",K)):!e&&n!==-1&&(g.splice(n,1),document.removeEventListener("keydown",K))}function q(){f||(i=[v()],o=0,h=new MutationObserver(R),w(),c=!0,y())}return{toolbar:function(){return r.buttons?[{labelKey:"history.undo",iconClass:"bi bi-arrow-counterclockwise",className:"ge-history-undo",align:"end",disabled:function(){return!s.canUndo},action:function(){d(-1,"tool")}},{labelKey:"history.redo",iconClass:"bi bi-arrow-clockwise",className:"ge-history-redo",align:"end",disabled:function(){return!s.canRedo},action:function(){d(1,"tool")}}]:[]},onInit:function(){r.shortcuts&&T(!0),!U&&(U=!0,Promise.resolve().then(q))},onDeinit:function(){T(!1)},onSourceOpen:function(){l=!0},onSourceClose:function(){l=!1},onDestroy:function(){f=!0,window.clearTimeout(a),a=null,E(),T(!1),x===t&&(x=null),i=[]},cleanMarkup:function(){},methods:{undo:function(){return d(-1,"api")},redo:function(){return d(1,"api")},canUndo:function(){return c&&!f&&(o>0||B())},canRedo:function(){return c&&!f&&o<i.length-1&&!B()},clearHistory:function(){return!c||f?!1:(window.clearTimeout(a),a=null,i=[l?i[o]:v()],o=0,y(),!0)}}}};})();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/js/register.js", "../../src/js/dom.js", "../../src/js/plugins/grideditor.history.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * What a plugin's or a locale's classic script imports in place of the\n * editor: the GridEditor the page already loaded.\n *\n * The build points `import { GridEditor } from '../grideditor.js'` here for\n * the classic scripts, so each registers on the editor the page has rather\n * than bringing its own. Loaded before the editor there is nothing to\n * register on, and saying so is better than a TypeError three calls later.\n */\nvar GridEditor = window.GridEditor;\n\nif (!GridEditor || typeof GridEditor.get !== 'function') {\n throw new Error('grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, ' +\n 'its locales and grideditor.jquery.js');\n}\n\nexport { GridEditor };\nexport default GridEditor;\n", "/**\n * The DOM, the way grid-editor uses it.\n *\n * Small helpers over the browser's own API, for the core and the shipped\n * plugins. Not a public API: a plugin of a host's own is free to write its\n * DOM code however it likes, and this file makes no promise to it.\n *\n * Stateless on purpose. The build puts a copy of this file in each plugin's\n * classic script, so anything kept here would be kept once per copy; a\n * module that needs to remember something about a node keeps its own\n * WeakMap.\n */\n\n/** Every element under `root` matching `selector`, as an array. */\nexport function all(root, selector) {\n return root ? Array.prototype.slice.call(root.querySelectorAll(selector)) : [];\n}\n\n/** The first element under `root` matching `selector`, or null. */\nexport function one(root, selector) {\n return root ? root.querySelector(selector) : null;\n}\n\n/** `root` itself when it matches, then every element under it that does. */\nexport function selfAndAll(root, selector) {\n if (!root) { return []; }\n\n var found = all(root, selector);\n if (root.nodeType === 1 && root.matches(selector)) { found.unshift(root); }\n return found;\n}\n\n/** The element children of `node`, those matching `selector` if one is given. */\nexport function children(node, selector) {\n if (!node) { return []; }\n\n return Array.prototype.filter.call(node.children, function(each) {\n return !selector || each.matches(selector);\n });\n}\n\n/** The first element child matching `selector`, or null. */\nexport function child(node, selector) {\n return children(node, selector)[0] || null;\n}\n\n/** The nearest ancestor-or-self matching `selector` below `stopAt`, or null. */\nexport function closest(node, selector, stopAt) {\n var found = node && node.nodeType === 1 ? node.closest(selector) : null;\n\n if (found && stopAt && found !== stopAt && !stopAt.contains(found)) { return null; }\n return found;\n}\n\n/** Whether `node` is an element matching `selector`. */\nexport function is(node, selector) {\n return !!node && node.nodeType === 1 && node.matches(selector);\n}\n\n/** Whether `node` is in the document. */\nexport function attached(node) {\n return !!node && document.documentElement.contains(node);\n}\n\n/** The element siblings after `node` that match `selector`. */\nexport function nextAll(node, selector) {\n var found = [];\n\n for (var next = node.nextElementSibling; next; next = next.nextElementSibling) {\n if (!selector || next.matches(selector)) { found.push(next); }\n }\n return found;\n}\n\n/** The ancestors of `node` up to, and not including, `stop`, nearest first. */\nexport function parentsUntil(node, stop) {\n var found = [];\n\n for (var parent = node.parentElement; parent && parent !== stop; parent = parent.parentElement) {\n found.push(parent);\n }\n return found;\n}\n\n/**\n * The nodes the html parses into, detached. Parsed the way innerHTML parses,\n * so a <script> in it never runs, here or once it is in the page.\n */\nexport function parse(html) {\n var template = document.createElement('template');\n template.innerHTML = html;\n return Array.prototype.slice.call(template.content.childNodes);\n}\n\n/** The one element the html is, detached. */\nexport function create(html) {\n var nodes = parse(html.trim());\n\n for (var i = 0; i < nodes.length; i++) {\n if (nodes[i].nodeType === 1) { return nodes[i]; }\n }\n return null;\n}\n\n/** An element of `tag`, with `attributes` and `text`. */\nexport function element(tag, attributes, text) {\n var node = document.createElement(tag);\n\n Object.keys(attributes || {}).forEach(function(name) {\n var value = attributes[name];\n if (value !== null && value !== undefined && value !== false) { node.setAttribute(name, value); }\n });\n if (text !== undefined && text !== null) { node.textContent = text; }\n\n return node;\n}\n\n/** Replace what `node` holds with `html`. A <script> in it does not run. */\nexport function setHtml(node, html) {\n node.innerHTML = html === undefined || html === null ? '' : String(html);\n return node;\n}\n\n/** Add one or several space separated classes. */\nexport function addClass(node, names) {\n split(names).forEach(function(name) { node.classList.add(name); });\n return node;\n}\n\nexport function removeClass(node, names) {\n split(names).forEach(function(name) { node.classList.remove(name); });\n return node;\n}\n\n/** Each class on, or off, or flipped when `on` is not given. */\nexport function toggleClass(node, names, state) {\n split(names).forEach(function(name) {\n if (state === undefined) {\n node.classList.toggle(name);\n } else {\n node.classList.toggle(name, !!state);\n }\n });\n return node;\n}\n\nexport function hasClass(node, name) {\n return !!node && node.nodeType === 1 && node.classList.contains(name);\n}\n\nfunction split(names) {\n return String(names || '').split(/\\s+/).filter(Boolean);\n}\n\n/** Take the class attribute off when there is nothing left in it. */\nexport function dropEmptyClass(node) {\n if (!node.getAttribute('class')) { node.removeAttribute('class'); }\n return node;\n}\n\n/** Take the style attribute off when there is nothing left in it. */\nexport function dropEmptyStyle(node) {\n if (!node.getAttribute('style')) { node.removeAttribute('style'); }\n return node;\n}\n\n/** Set attributes; a null or undefined value takes the attribute off. */\nexport function attr(node, attributes) {\n Object.keys(attributes).forEach(function(name) {\n var value = attributes[name];\n\n if (value === null || value === undefined) {\n node.removeAttribute(name);\n } else {\n node.setAttribute(name, value);\n }\n });\n return node;\n}\n\n/**\n * Inline styles, by css property name. A number is pixels for the properties\n * that take a length, as jQuery had it; an empty string takes one off.\n */\nexport function css(node, styles) {\n Object.keys(styles).forEach(function(property) {\n var value = styles[property];\n\n if (typeof value === 'number' && !UNITLESS[property]) { value = value + 'px'; }\n node.style.setProperty(property, value === null || value === undefined ? '' : String(value));\n });\n return node;\n}\n\nvar UNITLESS = { opacity: true, 'z-index': true, 'flex-grow': true, 'flex-shrink': true, order: true };\n\n/** What an element of this tag shows as when nothing hides it. */\nvar defaultDisplays = {};\n\nfunction defaultDisplay(node) {\n var tag = node.nodeName;\n\n if (!defaultDisplays[tag]) {\n var probe = document.body.appendChild(document.createElement(tag));\n defaultDisplays[tag] = getComputedStyle(probe).display;\n probe.remove();\n if (defaultDisplays[tag] === 'none') { defaultDisplays[tag] = 'block'; }\n }\n return defaultDisplays[tag];\n}\n\n/** Show a node: its inline display:none off, and a display of its own if a stylesheet hides it. */\nexport function show(node) {\n node.style.removeProperty('display');\n if (getComputedStyle(node).display === 'none') { node.style.display = defaultDisplay(node); }\n return node;\n}\n\nexport function hide(node) {\n node.style.display = 'none';\n return node;\n}\n\n/** Show or hide; flip when `on` is not given. */\nexport function toggle(node, state) {\n if (state === undefined) { state = !visible(node); }\n return state ? show(node) : hide(node);\n}\n\n/** Whether a node takes up room: what jQuery's :visible meant. */\nexport function visible(node) {\n return !!(node.offsetWidth || node.offsetHeight || node.getClientRects().length);\n}\n\n/** The border box's width, fractions included. */\nexport function outerWidth(node) {\n return node.getBoundingClientRect().width;\n}\n\nexport function outerHeight(node) {\n return node.getBoundingClientRect().height;\n}\n\n/** The content box's height, which is what jQuery's height() gave. */\nexport function contentHeight(node) {\n var style = getComputedStyle(node);\n return node.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);\n}\n\n/** Where a node is on the page, not in the window. */\nexport function offset(node) {\n var box = node.getBoundingClientRect();\n return { top: box.top + window.pageYOffset, left: box.left + window.pageXOffset };\n}\n\n/** Its index among its parent's element children, those matching `selector` if given. */\nexport function indexIn(node, selector) {\n return children(node.parentElement, selector).indexOf(node);\n}\n\n/** Put `node` right after `reference`. */\nexport function insertAfter(node, reference) {\n reference.parentNode.insertBefore(node, reference.nextSibling);\n return node;\n}\n\n/** Replace `node` with what it holds. */\nexport function unwrap(node) {\n var parent = node.parentNode;\n\n while (node.firstChild) { parent.insertBefore(node.firstChild, node); }\n node.remove();\n}\n\n/** Put `node` inside `wrapper`, where `node` was. */\nexport function wrap(node, wrapper) {\n node.parentNode.insertBefore(wrapper, node);\n wrapper.appendChild(node);\n return wrapper;\n}\n\n/**\n * Listen on `root` for `types` (space separated) on descendants that match\n * `selector`, with `this` the matched element, as jQuery's delegated\n * handlers had it. Hands back the listener, for removeEventListener; a\n * signal in `options` removes it too.\n */\nexport function delegate(root, types, selector, handler, options) {\n var listener = function(event) {\n var match = closest(event.target, selector, root);\n if (match && root.contains(match)) { return handler.call(match, event); }\n return undefined;\n };\n\n split(types).forEach(function(type) { root.addEventListener(type, listener, options); });\n return listener;\n}\n\n/** Listen for several space separated event types with one handler. */\nexport function on(target, types, handler, options) {\n split(types).forEach(function(type) { target.addEventListener(type, handler, options); });\n return handler;\n}\n\nexport function off(target, types, handler, options) {\n split(types).forEach(function(type) { target.removeEventListener(type, handler, options); });\n}\n\n/** A mouse event of `type` sent to `node`, the way a pointer would. */\nexport function fire(node, type) {\n node.dispatchEvent(new MouseEvent(type, { bubbles: type !== 'mouseenter' && type !== 'mouseleave' }));\n}\n\n/* ------------------------------------------------------------------\n * Taking a node away, visibly.\n *\n * The durations are jQuery's: 400 ms unless the caller says otherwise. `done` runs once the node is out of sight, which is\n * when the caller removes it; a node that is already out of sight is done at\n * once, on the next task, as jQuery had it.\n * ------------------------------------------------------------------ */\n\nvar DEFAULT_DURATION = 400;\n\nfunction animateAway(node, frames, duration, done) {\n duration = duration === undefined ? DEFAULT_DURATION : duration;\n\n var finish = function() {\n hide(node);\n if (done) { done(); }\n };\n\n if (!visible(node) || !node.animate || duration <= 0) {\n window.setTimeout(finish, 0);\n return;\n }\n\n var animation = node.animate(frames(getComputedStyle(node)), {\n duration: duration,\n easing: 'ease-in-out',\n });\n var called = false;\n var once = function() {\n if (called) { return; }\n called = true;\n finish();\n };\n\n animation.onfinish = once;\n animation.oncancel = once;\n}\n\n/** Fold a node up to nothing, then hide it. */\nexport function slideUp(node, duration, done) {\n if (typeof duration === 'function') {\n done = duration;\n duration = undefined;\n }\n\n node.style.overflow = 'hidden';\n animateAway(node, function(style) {\n return [\n {\n height: style.height,\n paddingTop: style.paddingTop,\n paddingBottom: style.paddingBottom,\n marginTop: style.marginTop,\n marginBottom: style.marginBottom,\n },\n { height: '0px', paddingTop: '0px', paddingBottom: '0px', marginTop: '0px', marginBottom: '0px' },\n ];\n }, duration, function() {\n node.style.removeProperty('overflow');\n if (done) { done(); }\n });\n}\n\n/** Fade a node out, then hide it. */\nexport function fadeOut(node, duration, done) {\n animateAway(node, function(style) {\n return [{ opacity: style.opacity }, { opacity: 0 }];\n }, duration, done);\n}\n\n/** Fade and fold a node, in height and, with `width`, sideways too, then hide it. */\nexport function shrinkAway(node, duration, done, width) {\n node.style.overflow = 'hidden';\n animateAway(node, function(style) {\n var from = { opacity: style.opacity, height: style.height };\n var to = { opacity: 0, height: '0px' };\n\n if (width) {\n from.width = style.width;\n to.width = '0px';\n }\n return [from, to];\n }, duration, function() {\n node.style.removeProperty('overflow');\n if (done) { done(); }\n });\n}\n", "/**\n * Undo and redo for grid-editor.\n *\n * A feature plugin: load this file after the editor and what is edited is\n * kept, step by step, in memory, so Ctrl+Z goes back to how it was and\n * Ctrl+Y (or Ctrl+Shift+Z) comes forward again. Two buttons on the right of\n * the toolbar do the same. What it can ask the editor for is the handle its\n * factory is called with, described in docs/plugins.md.\n *\n * <script src=\"dist/grideditor.min.js\"></script>\n * <script src=\"dist/plugins/grideditor.history.min.js\"></script>\n *\n * A step is the canvas's markup as ge.snapshotHtml() gives it, kept `delay`\n * ms after the last change: a drag or a burst of typing is one step. Going\n * to one puts its markup back with ge.setHtml(), and the node that was\n * selected, and the target, are chosen again by where they were.\n *\n * Typing in a text is the text editor's own to undo while it has the focus:\n * the keys are left alone then, and what was typed becomes a step when it\n * is done.\n *\n * new GridEditor('#myGrid', { history: { max: 100, buttons: false } });\n */\nimport { GridEditor } from '../grideditor.js';\nimport * as dom from '../dom.js';\n\nObject.assign(GridEditor.locales.en, {\n 'history.undo': 'Undo',\n 'history.redo': 'Redo',\n});\n\nvar DEFAULT_MAX = 50;\nvar DEFAULT_DELAY = 500;\n\n/** What the editor puts in a node that is not the node's own: a position counts without it. */\nvar FURNITURE = '.ge-tools-drawer, .ge-drop-marker';\n\n/** What a drag or a resize leaves on the canvas while it lasts. */\nvar BUSY = '.ge-drag-chosen, .ge-drag-placeholder, .ge-drag-helper, .ge-resizing';\n\n/** The editors listening for the keys, and the one used last, which a key press goes to. */\nvar listeningEditors = [];\nvar lastEditor = null;\n\nfunction track(e) {\n lastEditor = listeningEditors.filter(function(ge) { return ge.contains(e.target); })[0] || null;\n}\n\n// Captured: a control that stops the event still counts as using its editor\ndocument.addEventListener('pointerdown', track, true);\ndocument.addEventListener('focusin', track, true);\n\n/** 'z', 'y' or null, from the letter typed or, on a layout without Latin letters, the key's place. */\nfunction shortcutKey(e) {\n var key = (e.key || '').toLowerCase();\n if (!/^[a-z]$/.test(key)) { key = { KeyZ: 'z', KeyY: 'y' }[e.code] || ''; }\n\n return key === 'z' || key === 'y' ? key : null;\n}\n\nfunction typing() {\n var focus = document.activeElement;\n return !!focus && (dom.is(focus, 'input, textarea, select') || focus.isContentEditable);\n}\n\n/** The children of `parent` that are its own content, without the editor's furniture. */\nfunction contentOf(parent) {\n return dom.children(parent).filter(function(child) { return !dom.is(child, FURNITURE); });\n}\n\nGridEditor.features.history = function(ge) {\n\n var options = optionsFrom(ge.settings.history || {});\n\n var stack = []; // The markup of each step, oldest first\n var index = -1; // The step the canvas is at\n var shown = { canUndo: false, canRedo: false }; // What the last history-change said\n var timer = null;\n var observer = null;\n var observing = false;\n var initiated = false; // Whether the first init has been looked at\n var started = false; // Whether there is a first step to go back to\n var sourceOpen = false;\n var destroyed = false;\n\n function optionsFrom(given) {\n var result = {\n shortcuts: given.shortcuts === undefined ? true : given.shortcuts,\n buttons: given.buttons === undefined ? true : given.buttons,\n max: given.max === undefined ? DEFAULT_MAX : given.max,\n delay: given.delay === undefined ? DEFAULT_DELAY : given.delay,\n };\n\n ['shortcuts', 'buttons'].forEach(function(name) {\n if (typeof result[name] !== 'boolean') {\n ge.warn('history.' + name + ' is true or false: true is used');\n result[name] = true;\n }\n });\n if (!Number.isInteger(result.max) || result.max < 1) {\n ge.warn('history.max must be a whole number of steps, 1 or more: ' + DEFAULT_MAX + ' is used');\n result.max = DEFAULT_MAX;\n }\n if (!Number.isInteger(result.delay) || result.delay < 0) {\n ge.warn('history.delay must be a whole number of milliseconds, 0 or more: ' + DEFAULT_DELAY + ' is used');\n result.delay = DEFAULT_DELAY;\n }\n\n return result;\n }\n\n function observe() {\n observer.observe(ge.canvas, { subtree: true, childList: true, attributes: true, characterData: true });\n observing = true;\n }\n\n function stopObserving() {\n if (observer) { observer.disconnect(); }\n observing = false;\n }\n\n /** The canvas's markup now. Reading may change the canvas, when a plugin cannot be read on a copy, and that is no change of the user's. */\n function read() {\n var watching = observing;\n if (watching) { stopObserving(); }\n var html = ge.snapshotHtml();\n if (watching) { observe(); }\n\n return html;\n }\n\n function editing() {\n return dom.hasClass(ge.canvas, 'ge-editing');\n }\n\n /** A drag or a resize is going on: the canvas is not at a step but between two. */\n function busy() {\n return dom.hasClass(ge.canvas, 'ge-dropping') || !!dom.one(ge.canvas, BUSY);\n }\n\n function schedule() {\n window.clearTimeout(timer);\n timer = window.setTimeout(commit, options.delay);\n }\n\n /** Whether something changed since the last step that is not a step yet. */\n function pending() {\n return timer !== null && read() !== stack[index];\n }\n\n /** What is on the canvas, if it is not the step it is at, becomes the next one. */\n function commit() {\n window.clearTimeout(timer);\n timer = null;\n\n if (!started || destroyed || sourceOpen) { return; }\n if (busy()) { schedule(); return; }\n\n var html = read();\n if (html === stack[index]) { return; }\n\n stack.splice(index + 1);\n stack.push(html);\n if (stack.length > options.max + 1) { stack.shift(); }\n index = stack.length - 1;\n\n notify();\n }\n\n /** The buttons, and a history-change when what can be done is not what was last said. */\n function notify() {\n var now = { canUndo: index > 0, canRedo: index < stack.length - 1 };\n var changed = now.canUndo !== shown.canUndo || now.canRedo !== shown.canRedo;\n\n shown = now;\n paint();\n\n if (changed) {\n ge.emit('history-change', { canvas: ge.canvas, canUndo: now.canUndo, canRedo: now.canRedo });\n }\n }\n\n function paint() {\n ge.toolbarItems('history').forEach(function(button) {\n var off = button.getAttribute('data-ge-item') === '0' ? !shown.canUndo : !shown.canRedo;\n\n dom.toggleClass(button, 'disabled', off);\n if (off) {\n button.setAttribute('aria-disabled', 'true');\n } else {\n button.removeAttribute('aria-disabled');\n }\n });\n }\n\n /**\n * Where a node is: its index among its parent's content, all the way up\n * from the canvas. The canvas is made again from markup, so a node is\n * not the same one afterwards, but the place it was in is.\n */\n function pathOf(node) {\n if (!node || node === ge.canvas || !ge.canvas.contains(node)) { return null; }\n\n var path = [];\n for (var at = node; at !== ge.canvas; at = at.parentElement) {\n path.unshift(contentOf(at.parentElement).indexOf(at));\n }\n\n return path;\n }\n\n function resolve(path) {\n if (!path) { return null; }\n\n var node = ge.canvas;\n for (var i = 0; i < path.length && node; i++) { node = contentOf(node)[path[i]]; }\n\n return node || null;\n }\n\n function go(step, source) {\n if (!started || destroyed || sourceOpen || !editing() || busy()) { return false; }\n\n // A change not yet a step is a step of its own, and the one undone\n commit();\n\n var to = index + step;\n if (to < 0 || to >= stack.length) { return false; }\n\n var selected = pathOf(ge.getSelected());\n var target = pathOf(ge.getActiveTarget());\n\n stopObserving();\n index = to;\n ge.setHtml(stack[index]);\n // The step as the canvas reads it back, so that is what is compared with\n stack[index] = ge.snapshotHtml();\n\n var node = resolve(selected);\n if (node) { ge.setSelected(node); }\n node = resolve(target);\n if (node) { ge.setActiveTarget(node); }\n\n observe();\n notify();\n ge.emit(step < 0 ? 'after-undo' : 'after-redo', { canvas: ge.canvas, html: stack[index], source: source });\n\n return true;\n }\n\n function onKeydown(e) {\n if (lastEditor !== ge || e.altKey || !(e.ctrlKey || e.metaKey)) { return; }\n\n var key = shortcutKey(e);\n if (!key || (key === 'y' && e.shiftKey)) { return; }\n if (!editing() || typing() || ge.panelOpen()) { return; }\n\n // Left alone, it is the browser's\n if (go(key === 'y' || e.shiftKey ? 1 : -1, 'shortcut')) { e.preventDefault(); }\n }\n\n function listenForShortcuts(on) {\n var at = listeningEditors.indexOf(ge);\n\n if (on && at === -1) {\n listeningEditors.push(ge);\n document.addEventListener('keydown', onKeydown);\n } else if (!on && at !== -1) {\n listeningEditors.splice(at, 1);\n document.removeEventListener('keydown', onKeydown);\n }\n }\n\n /** After the first init has finished: the canvas is ready to be read. */\n function start() {\n if (destroyed) { return; }\n\n stack = [read()];\n index = 0;\n observer = new MutationObserver(schedule);\n observe();\n started = true;\n notify();\n }\n\n return {\n toolbar: function() {\n if (!options.buttons) { return []; }\n\n return [\n {\n labelKey: 'history.undo',\n iconClass: 'bi bi-arrow-counterclockwise',\n className: 'ge-history-undo',\n align: 'end',\n disabled: function() { return !shown.canUndo; },\n action: function() { go(-1, 'tool'); },\n },\n {\n labelKey: 'history.redo',\n iconClass: 'bi bi-arrow-clockwise',\n className: 'ge-history-redo',\n align: 'end',\n disabled: function() { return !shown.canRedo; },\n action: function() { go(1, 'tool'); },\n },\n ];\n },\n\n onInit: function() {\n if (options.shortcuts) { listenForShortcuts(true); }\n\n if (initiated) { return; }\n initiated = true;\n Promise.resolve().then(start);\n },\n\n // A canvas out of editing leaves the keys to the page: it is read again when it is back\n onDeinit: function() { listenForShortcuts(false); },\n\n onSourceOpen: function() { sourceOpen = true; },\n onSourceClose: function() { sourceOpen = false; },\n\n onDestroy: function() {\n destroyed = true;\n window.clearTimeout(timer);\n timer = null;\n stopObserving();\n listenForShortcuts(false);\n if (lastEditor === ge) { lastEditor = null; }\n stack = [];\n },\n\n // Nothing of its own on the canvas\n cleanMarkup: function() {},\n\n methods: {\n undo: function() { return go(-1, 'api'); },\n\n redo: function() { return go(1, 'api'); },\n\n // A change waiting for its step counts: it is what an undo would undo\n canUndo: function() {\n return started && !destroyed && (index > 0 || pending());\n },\n\n // ... and it ends what could be redone\n canRedo: function() {\n return started && !destroyed && index < stack.length - 1 && !pending();\n },\n\n // What is there is the first step, with nothing before it or after it\n clearHistory: function() {\n if (!started || destroyed) { return false; }\n\n window.clearTimeout(timer);\n timer = null;\n // The textarea's markup is not the canvas's while the source is open\n stack = [sourceOpen ? stack[index] : read()];\n index = 0;\n notify();\n\n return true;\n },\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "MASA,IAAIA,EAAa,OAAO,WAExB,GAAI,CAACA,GAAc,OAAOA,EAAW,KAAQ,WACzC,MAAM,IAAI,MAAM,wHAC0B,ECMvC,SAASC,EAAIC,EAAMC,EAAU,CAChC,OAAOD,EAAOA,EAAK,cAAcC,CAAQ,EAAI,IACjD,CAYO,SAASC,EAASC,EAAMC,EAAU,CACrC,OAAKD,EAEE,MAAM,UAAU,OAAO,KAAKA,EAAK,SAAU,SAASE,EAAM,CAC7D,MAAO,CAACD,GAAYC,EAAK,QAAQD,CAAQ,CAC7C,CAAC,EAJmB,CAAC,CAKzB,CAgBO,SAASE,EAAGC,EAAMC,EAAU,CAC/B,MAAO,CAAC,CAACD,GAAQA,EAAK,WAAa,GAAKA,EAAK,QAAQC,CAAQ,CACjE,CA8EO,SAASC,EAAYC,EAA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B,CAAC,CAoBpC,EAEA,OAAQ,UAAW,CACXxC,EAAQ,WAAa+C,EAAmB,EAAI,EAE5C,CAAAvC,IACJA,EAAY,GACZ,QAAQ,QAAQ,EAAE,KAAKyC,CAAK,EAChC,EAGA,SAAU,UAAW,CAAEF,EAAmB,EAAK,CAAG,EAElD,aAAc,UAAW,CAAErC,EAAa,EAAM,EAC9C,cAAe,UAAW,CAAEA,EAAa,EAAO,EAEhD,UAAW,UAAW,CAClBC,EAAY,GACZ,OAAO,aAAaN,CAAK,EACzBA,EAAQ,KACRW,EAAc,EACd+B,EAAmB,EAAK,EACpB5D,IAAeG,IAAMH,EAAa,MACtCe,EAAQ,CAAC,CACb,EAGA,YAAa,UAAW,CAAC,EAEzB,QAAS,CACL,KAAM,UAAW,CAAE,OAAOsC,EAAG,GAAI,KAAK,CAAG,EAEzC,KAAM,UAAW,CAAE,OAAOA,EAAG,EAAG,KAAK,CAAG,EAGxC,QAAS,UAAW,CAChB,OAAO/B,GAAW,CAACE,IAAcR,EAAQ,GAAKuB,EAAQ,EAC1D,EAGA,QAAS,UAAW,CAChB,OAAOjB,GAAW,CAACE,GAAaR,EAAQD,EAAM,OAAS,GAAK,CAACwB,EAAQ,CACzE,EAGA,aAAc,UAAW,CACrB,MAAI,CAACjB,GAAWE,EAAoB,IAEpC,OAAO,aAAaN,CAAK,EACzBA,EAAQ,KAERH,EAAQ,CAACQ,EAAaR,EAAMC,CAAK,EAAIc,EAAK,CAAC,EAC3Cd,EAAQ,EACRwB,EAAO,EAEA,GACX,CACJ,CACJ,CACJ",
|
|
6
|
+
"names": ["GridEditor", "one", "root", "selector", "children", "node", "selector", "each", "is", "node", "selector", "toggleClass", "node", "names", "state", "split", "name", "hasClass", "GridEditor", "DEFAULT_MAX", "DEFAULT_DELAY", "FURNITURE", "BUSY", "listeningEditors", "lastEditor", "track", "e", "ge", "shortcutKey", "key", "typing", "focus", "is", "contentOf", "parent", "children", "child", "options", "optionsFrom", "stack", "index", "shown", "timer", "observer", "observing", "initiated", "started", "sourceOpen", "destroyed", "given", "result", "name", "observe", "stopObserving", "read", "watching", "html", "editing", "hasClass", "busy", "one", "schedule", "commit", "pending", "notify", "now", "changed", "paint", "button", "off", "toggleClass", "pathOf", "node", "path", "at", "resolve", "i", "go", "step", "source", "to", "selected", "target", "onKeydown", "listenForShortcuts", "on", "start"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
// src/js/plugins/grideditor.offcanvas.js
|
|
2
|
+
import { GridEditor } from "../grideditor.esm.js";
|
|
3
|
+
|
|
4
|
+
// src/js/dom.js
|
|
5
|
+
function all(root, selector) {
|
|
6
|
+
return root ? Array.prototype.slice.call(root.querySelectorAll(selector)) : [];
|
|
7
|
+
}
|
|
8
|
+
function children(node, selector) {
|
|
9
|
+
if (!node) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return Array.prototype.filter.call(node.children, function(each) {
|
|
13
|
+
return !selector || each.matches(selector);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function child(node, selector) {
|
|
17
|
+
return children(node, selector)[0] || null;
|
|
18
|
+
}
|
|
19
|
+
function closest(node, selector, stopAt) {
|
|
20
|
+
var found = node && node.nodeType === 1 ? node.closest(selector) : null;
|
|
21
|
+
if (found && stopAt && found !== stopAt && !stopAt.contains(found)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return found;
|
|
25
|
+
}
|
|
26
|
+
function parse(html) {
|
|
27
|
+
var template = document.createElement("template");
|
|
28
|
+
template.innerHTML = html;
|
|
29
|
+
return Array.prototype.slice.call(template.content.childNodes);
|
|
30
|
+
}
|
|
31
|
+
function create(html) {
|
|
32
|
+
var nodes = parse(html.trim());
|
|
33
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
34
|
+
if (nodes[i].nodeType === 1) {
|
|
35
|
+
return nodes[i];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function element(tag, attributes, text) {
|
|
41
|
+
var node = document.createElement(tag);
|
|
42
|
+
Object.keys(attributes || {}).forEach(function(name) {
|
|
43
|
+
var value = attributes[name];
|
|
44
|
+
if (value !== null && value !== void 0 && value !== false) {
|
|
45
|
+
node.setAttribute(name, value);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (text !== void 0 && text !== null) {
|
|
49
|
+
node.textContent = text;
|
|
50
|
+
}
|
|
51
|
+
return node;
|
|
52
|
+
}
|
|
53
|
+
function addClass(node, names) {
|
|
54
|
+
split(names).forEach(function(name) {
|
|
55
|
+
node.classList.add(name);
|
|
56
|
+
});
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
function removeClass(node, names) {
|
|
60
|
+
split(names).forEach(function(name) {
|
|
61
|
+
node.classList.remove(name);
|
|
62
|
+
});
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
65
|
+
function toggleClass(node, names, state) {
|
|
66
|
+
split(names).forEach(function(name) {
|
|
67
|
+
if (state === void 0) {
|
|
68
|
+
node.classList.toggle(name);
|
|
69
|
+
} else {
|
|
70
|
+
node.classList.toggle(name, !!state);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
function hasClass(node, name) {
|
|
76
|
+
return !!node && node.nodeType === 1 && node.classList.contains(name);
|
|
77
|
+
}
|
|
78
|
+
function split(names) {
|
|
79
|
+
return String(names || "").split(/\s+/).filter(Boolean);
|
|
80
|
+
}
|
|
81
|
+
function dropEmptyClass(node) {
|
|
82
|
+
if (!node.getAttribute("class")) {
|
|
83
|
+
node.removeAttribute("class");
|
|
84
|
+
}
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
function delegate(root, types, selector, handler, options) {
|
|
88
|
+
var listener = function(event) {
|
|
89
|
+
var match = closest(event.target, selector, root);
|
|
90
|
+
if (match && root.contains(match)) {
|
|
91
|
+
return handler.call(match, event);
|
|
92
|
+
}
|
|
93
|
+
return void 0;
|
|
94
|
+
};
|
|
95
|
+
split(types).forEach(function(type) {
|
|
96
|
+
root.addEventListener(type, listener, options);
|
|
97
|
+
});
|
|
98
|
+
return listener;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/js/triggers/triggers.js
|
|
102
|
+
function triggersFor(ge, kind, idAttribute, targetAttribute, toggle) {
|
|
103
|
+
var triggerClass = "ge-" + kind + "-trigger";
|
|
104
|
+
var orphanClass = "ge-" + kind + "-orphan";
|
|
105
|
+
var listening = null;
|
|
106
|
+
function idOf(container) {
|
|
107
|
+
return container.getAttribute(idAttribute);
|
|
108
|
+
}
|
|
109
|
+
function exists(id, root) {
|
|
110
|
+
return all(root || ge.canvas, "[" + idAttribute + "]").some(function(container) {
|
|
111
|
+
return idOf(container) === id;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function wire() {
|
|
115
|
+
all(ge.canvas, "[" + targetAttribute + "]").forEach(function(trigger) {
|
|
116
|
+
addClass(trigger, triggerClass);
|
|
117
|
+
var wanted = trigger.getAttribute(targetAttribute);
|
|
118
|
+
trigger.removeAttribute("data-bs-toggle");
|
|
119
|
+
trigger.removeAttribute("data-bs-target");
|
|
120
|
+
if (exists(wanted)) {
|
|
121
|
+
removeClass(trigger, orphanClass);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
var column = trigger.closest(".column");
|
|
125
|
+
var nearby = column ? all(column, "[" + idAttribute + "]") : [];
|
|
126
|
+
if (nearby.length === 1) {
|
|
127
|
+
trigger.setAttribute(targetAttribute, idOf(nearby[0]));
|
|
128
|
+
removeClass(trigger, orphanClass);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
addClass(trigger, orphanClass);
|
|
132
|
+
ge.operate(function() {
|
|
133
|
+
ge.emit(kind + "-orphan", ge.payloadFor(kind, trigger, {
|
|
134
|
+
parent: trigger.parentElement,
|
|
135
|
+
source: "api",
|
|
136
|
+
missing: wanted
|
|
137
|
+
}));
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function write(root) {
|
|
142
|
+
root = root || ge.canvas;
|
|
143
|
+
all(root, "[" + targetAttribute + "]").forEach(function(trigger) {
|
|
144
|
+
var wanted = trigger.getAttribute(targetAttribute);
|
|
145
|
+
removeClass(trigger, orphanClass);
|
|
146
|
+
dropEmptyClass(trigger);
|
|
147
|
+
if (!exists(wanted, root)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
trigger.setAttribute("data-bs-toggle", toggle);
|
|
151
|
+
trigger.setAttribute("data-bs-target", "#" + wanted);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
write,
|
|
156
|
+
// Triggers are markup the host owns, anywhere in the canvas, so they
|
|
157
|
+
// are looked at whenever the canvas is initialized rather than only
|
|
158
|
+
// when a container is touched
|
|
159
|
+
onInit: function() {
|
|
160
|
+
wire();
|
|
161
|
+
if (listening) {
|
|
162
|
+
listening.abort();
|
|
163
|
+
}
|
|
164
|
+
listening = new AbortController();
|
|
165
|
+
delegate(ge.canvas, "click", "." + triggerClass + ", [" + targetAttribute + "]", function(e) {
|
|
166
|
+
if (hasClass(ge.canvas, "ge-editing")) {
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
}
|
|
169
|
+
}, { signal: listening.signal });
|
|
170
|
+
},
|
|
171
|
+
onDeinit: function() {
|
|
172
|
+
if (listening) {
|
|
173
|
+
listening.abort();
|
|
174
|
+
}
|
|
175
|
+
listening = null;
|
|
176
|
+
write();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/js/plugins/grideditor.offcanvas.js
|
|
182
|
+
Object.assign(GridEditor.locales.en, {
|
|
183
|
+
"container.add_offcanvas": "Offcanvas",
|
|
184
|
+
"container.offcanvas_title": "Title",
|
|
185
|
+
"container.offcanvas_trigger": "Open",
|
|
186
|
+
"tool.toggle_offcanvas": "Fold this offcanvas away while editing",
|
|
187
|
+
"container.offcanvas_section": "Offcanvas",
|
|
188
|
+
"container.offcanvas_placement": "Placement",
|
|
189
|
+
"container.offcanvas_start": "Start",
|
|
190
|
+
"container.offcanvas_end": "End",
|
|
191
|
+
"container.offcanvas_top": "Top",
|
|
192
|
+
"container.offcanvas_bottom": "Bottom",
|
|
193
|
+
"container.offcanvas_backdrop": "Backdrop",
|
|
194
|
+
"container.offcanvas_backdrop_yes": "Yes",
|
|
195
|
+
"container.offcanvas_backdrop_no": "No",
|
|
196
|
+
"container.offcanvas_backdrop_static": "Static",
|
|
197
|
+
"container.offcanvas_scroll": "Allow body scroll",
|
|
198
|
+
"container.offcanvas_keyboard": "Close with Esc",
|
|
199
|
+
"container.offcanvas_responsive": "Responsive",
|
|
200
|
+
"container.offcanvas_responsive_never": "Always offcanvas",
|
|
201
|
+
"container.offcanvas_responsive_from": "Inline from {breakpoint}",
|
|
202
|
+
"container.offcanvas_dark": "Dark theme"
|
|
203
|
+
});
|
|
204
|
+
var DEFAULTS = {
|
|
205
|
+
placement: "start",
|
|
206
|
+
backdrop: true,
|
|
207
|
+
scroll: false,
|
|
208
|
+
keyboard: true,
|
|
209
|
+
responsive: null,
|
|
210
|
+
dark: false
|
|
211
|
+
};
|
|
212
|
+
var KEYS = ["placement", "backdrop", "scroll", "keyboard", "responsive", "dark"];
|
|
213
|
+
var PLACEMENTS = ["start", "end", "top", "bottom"];
|
|
214
|
+
var BACKDROPS = [true, false, "static"];
|
|
215
|
+
var LABELS = {
|
|
216
|
+
placement: { labelKey: "container.offcanvas_placement" },
|
|
217
|
+
backdrop: { labelKey: "container.offcanvas_backdrop" },
|
|
218
|
+
responsive: { labelKey: "container.offcanvas_responsive" },
|
|
219
|
+
scroll: { labelKey: "container.offcanvas_scroll" },
|
|
220
|
+
keyboard: { labelKey: "container.offcanvas_keyboard" },
|
|
221
|
+
dark: { labelKey: "container.offcanvas_dark" }
|
|
222
|
+
};
|
|
223
|
+
var PLACEMENT_CHOICES = [
|
|
224
|
+
{ value: "start", labelKey: "container.offcanvas_start" },
|
|
225
|
+
{ value: "end", labelKey: "container.offcanvas_end" },
|
|
226
|
+
{ value: "top", labelKey: "container.offcanvas_top" },
|
|
227
|
+
{ value: "bottom", labelKey: "container.offcanvas_bottom" }
|
|
228
|
+
];
|
|
229
|
+
var BACKDROP_CHOICES = [
|
|
230
|
+
{ value: "true", labelKey: "container.offcanvas_backdrop_yes" },
|
|
231
|
+
{ value: "false", labelKey: "container.offcanvas_backdrop_no" },
|
|
232
|
+
{ value: "static", labelKey: "container.offcanvas_backdrop_static" }
|
|
233
|
+
];
|
|
234
|
+
var fieldCounter = 0;
|
|
235
|
+
GridEditor.containers.offcanvas = function(ge) {
|
|
236
|
+
var RESPONSIVE = ge.breakpoints.filter(function(key) {
|
|
237
|
+
return key !== "xs";
|
|
238
|
+
});
|
|
239
|
+
var sections = [];
|
|
240
|
+
var triggers = triggersFor(ge, "offcanvas", "data-ge-offcanvas-id", "data-ge-offcanvas-target", "offcanvas");
|
|
241
|
+
var CHECKS = {
|
|
242
|
+
placement: function(value) {
|
|
243
|
+
return PLACEMENTS.indexOf(value) !== -1;
|
|
244
|
+
},
|
|
245
|
+
backdrop: function(value) {
|
|
246
|
+
return BACKDROPS.indexOf(value) !== -1;
|
|
247
|
+
},
|
|
248
|
+
responsive: function(value) {
|
|
249
|
+
return value === null || RESPONSIVE.indexOf(value) !== -1;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
function isValid(key, value) {
|
|
253
|
+
return CHECKS[key] ? CHECKS[key](value) : typeof value === "boolean";
|
|
254
|
+
}
|
|
255
|
+
function takes(key) {
|
|
256
|
+
if (key === "placement") {
|
|
257
|
+
return JSON.stringify(PLACEMENTS);
|
|
258
|
+
}
|
|
259
|
+
if (key === "backdrop") {
|
|
260
|
+
return JSON.stringify(BACKDROPS);
|
|
261
|
+
}
|
|
262
|
+
if (key === "responsive") {
|
|
263
|
+
return JSON.stringify([null].concat(RESPONSIVE));
|
|
264
|
+
}
|
|
265
|
+
return "[true,false]";
|
|
266
|
+
}
|
|
267
|
+
function chosen(options, key) {
|
|
268
|
+
var setting = ge.settings.offcanvas || {};
|
|
269
|
+
var value = options[key] !== void 0 ? options[key] : setting[key];
|
|
270
|
+
if (value === void 0) {
|
|
271
|
+
return DEFAULTS[key];
|
|
272
|
+
}
|
|
273
|
+
if (isValid(key, value)) {
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
ge.warn("offcanvas: " + JSON.stringify(value) + " is not a " + key + ", which takes " + takes(key) + ": " + JSON.stringify(DEFAULTS[key]) + " is used");
|
|
277
|
+
return DEFAULTS[key];
|
|
278
|
+
}
|
|
279
|
+
function isPanelClass(name) {
|
|
280
|
+
return name === "offcanvas" || /^offcanvas-/.test(name) && RESPONSIVE.indexOf(name.slice(10)) !== -1;
|
|
281
|
+
}
|
|
282
|
+
function isPanel(node) {
|
|
283
|
+
return Array.prototype.some.call(node.classList, isPanelClass);
|
|
284
|
+
}
|
|
285
|
+
function panelOf(container) {
|
|
286
|
+
var id = container.getAttribute("data-ge-offcanvas-id");
|
|
287
|
+
var own = children(container);
|
|
288
|
+
return own.filter(function(node) {
|
|
289
|
+
return id && node.id === id;
|
|
290
|
+
})[0] || own.filter(isPanel)[0] || null;
|
|
291
|
+
}
|
|
292
|
+
function triggerOf(container) {
|
|
293
|
+
return child(container, "[data-ge-offcanvas-target]");
|
|
294
|
+
}
|
|
295
|
+
function dropTriggerMarks(root) {
|
|
296
|
+
all(root, ".ge-offcanvas-trigger").forEach(function(trigger) {
|
|
297
|
+
removeClass(trigger, "ge-offcanvas-trigger");
|
|
298
|
+
dropEmptyClass(trigger);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function hideClass(responsive) {
|
|
302
|
+
return "d-" + responsive + "-none";
|
|
303
|
+
}
|
|
304
|
+
function read(container) {
|
|
305
|
+
var panel = panelOf(container);
|
|
306
|
+
var backdrop = panel.getAttribute("data-bs-backdrop");
|
|
307
|
+
var responsive = null;
|
|
308
|
+
Array.prototype.forEach.call(panel.classList, function(name) {
|
|
309
|
+
if (name !== "offcanvas" && isPanelClass(name)) {
|
|
310
|
+
responsive = name.slice(10);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return {
|
|
314
|
+
placement: PLACEMENTS.filter(function(place) {
|
|
315
|
+
return hasClass(panel, "offcanvas-" + place);
|
|
316
|
+
})[0] || "start",
|
|
317
|
+
backdrop: backdrop === "false" ? false : backdrop === "static" ? "static" : true,
|
|
318
|
+
scroll: panel.getAttribute("data-bs-scroll") === "true",
|
|
319
|
+
keyboard: panel.getAttribute("data-bs-keyboard") !== "false",
|
|
320
|
+
responsive,
|
|
321
|
+
dark: panel.getAttribute("data-bs-theme") === "dark"
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function setAttribute(panel, name, value) {
|
|
325
|
+
if (value === null) {
|
|
326
|
+
panel.removeAttribute(name);
|
|
327
|
+
} else {
|
|
328
|
+
panel.setAttribute(name, value);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function write(container, key, value) {
|
|
332
|
+
var panel = panelOf(container);
|
|
333
|
+
if (key === "placement") {
|
|
334
|
+
PLACEMENTS.forEach(function(place) {
|
|
335
|
+
removeClass(panel, "offcanvas-" + place);
|
|
336
|
+
});
|
|
337
|
+
addClass(panel, "offcanvas-" + value);
|
|
338
|
+
}
|
|
339
|
+
if (key === "backdrop") {
|
|
340
|
+
setAttribute(panel, "data-bs-backdrop", value === true ? null : String(value));
|
|
341
|
+
}
|
|
342
|
+
if (key === "scroll") {
|
|
343
|
+
setAttribute(panel, "data-bs-scroll", value ? "true" : null);
|
|
344
|
+
}
|
|
345
|
+
if (key === "keyboard") {
|
|
346
|
+
setAttribute(panel, "data-bs-keyboard", value ? null : "false");
|
|
347
|
+
}
|
|
348
|
+
if (key === "responsive") {
|
|
349
|
+
var before = read(container).responsive;
|
|
350
|
+
var trigger = triggerOf(container);
|
|
351
|
+
var rest = Array.prototype.filter.call(panel.classList, function(name) {
|
|
352
|
+
return !isPanelClass(name);
|
|
353
|
+
});
|
|
354
|
+
panel.className = [value === null ? "offcanvas" : "offcanvas-" + value].concat(rest).join(" ");
|
|
355
|
+
if (trigger) {
|
|
356
|
+
if (before !== null) {
|
|
357
|
+
removeClass(trigger, hideClass(before));
|
|
358
|
+
}
|
|
359
|
+
if (value !== null) {
|
|
360
|
+
addClass(trigger, hideClass(value));
|
|
361
|
+
}
|
|
362
|
+
dropEmptyClass(trigger);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (key === "dark") {
|
|
366
|
+
if (value) {
|
|
367
|
+
panel.setAttribute("data-bs-theme", "dark");
|
|
368
|
+
} else if (panel.getAttribute("data-bs-theme") === "dark") {
|
|
369
|
+
panel.removeAttribute("data-bs-theme");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function nextId() {
|
|
374
|
+
return "ge-offcanvas-option-" + ++fieldCounter;
|
|
375
|
+
}
|
|
376
|
+
function field(labelKey, control, id) {
|
|
377
|
+
var box = element("div", { "class": "ge-offcanvas-option mb-2" });
|
|
378
|
+
box.appendChild(element("label", { "class": "form-label", "for": id }, ge.t(labelKey)));
|
|
379
|
+
box.appendChild(control);
|
|
380
|
+
return box;
|
|
381
|
+
}
|
|
382
|
+
function checkbox(labelKey, onChange) {
|
|
383
|
+
var id = nextId();
|
|
384
|
+
var box = element("div", { "class": "form-check" });
|
|
385
|
+
var input = box.appendChild(element("input", { "class": "form-check-input", type: "checkbox", id }));
|
|
386
|
+
box.appendChild(element("label", { "class": "form-check-label", "for": id }, ge.t(labelKey)));
|
|
387
|
+
input.addEventListener("change", function() {
|
|
388
|
+
onChange(input.checked);
|
|
389
|
+
});
|
|
390
|
+
return { box, input };
|
|
391
|
+
}
|
|
392
|
+
function select(choices, onChange) {
|
|
393
|
+
var id = nextId();
|
|
394
|
+
var control = element("select", { "class": "form-select form-select-sm", id });
|
|
395
|
+
choices.forEach(function(choice) {
|
|
396
|
+
control.appendChild(element("option", { value: choice.value }, choice.label));
|
|
397
|
+
});
|
|
398
|
+
control.addEventListener("change", function() {
|
|
399
|
+
onChange(control.value);
|
|
400
|
+
});
|
|
401
|
+
return { id, control };
|
|
402
|
+
}
|
|
403
|
+
function createSection(container) {
|
|
404
|
+
var body = element("div", { "class": "ge-offcanvas-options" });
|
|
405
|
+
function change(key, value) {
|
|
406
|
+
write(container, key, value);
|
|
407
|
+
render();
|
|
408
|
+
}
|
|
409
|
+
var translated = function(choice) {
|
|
410
|
+
return { value: choice.value, label: ge.t(choice.labelKey) };
|
|
411
|
+
};
|
|
412
|
+
var selects = {
|
|
413
|
+
placement: select(PLACEMENT_CHOICES.map(translated), function(value) {
|
|
414
|
+
change("placement", value);
|
|
415
|
+
}),
|
|
416
|
+
backdrop: select(BACKDROP_CHOICES.map(translated), function(value) {
|
|
417
|
+
change("backdrop", value === "static" ? "static" : value === "true");
|
|
418
|
+
}),
|
|
419
|
+
responsive: select([{ value: "", label: ge.t("container.offcanvas_responsive_never") }].concat(
|
|
420
|
+
RESPONSIVE.map(function(key) {
|
|
421
|
+
return { value: key, label: ge.t("container.offcanvas_responsive_from", { breakpoint: key }) };
|
|
422
|
+
})
|
|
423
|
+
), function(value) {
|
|
424
|
+
change("responsive", value === "" ? null : value);
|
|
425
|
+
})
|
|
426
|
+
};
|
|
427
|
+
Object.keys(selects).forEach(function(key) {
|
|
428
|
+
var box = field(LABELS[key].labelKey, selects[key].control, selects[key].id);
|
|
429
|
+
box.setAttribute("data-ge-offcanvas-option", key);
|
|
430
|
+
body.appendChild(box);
|
|
431
|
+
});
|
|
432
|
+
var inputs = {};
|
|
433
|
+
["scroll", "keyboard", "dark"].forEach(function(key) {
|
|
434
|
+
var each = checkbox(LABELS[key].labelKey, function(on) {
|
|
435
|
+
change(key, on);
|
|
436
|
+
});
|
|
437
|
+
inputs[key] = each.input;
|
|
438
|
+
each.box.setAttribute("data-ge-offcanvas-option", key);
|
|
439
|
+
body.appendChild(each.box);
|
|
440
|
+
});
|
|
441
|
+
function render() {
|
|
442
|
+
var values = read(container);
|
|
443
|
+
selects.placement.control.value = values.placement;
|
|
444
|
+
selects.backdrop.control.value = String(values.backdrop);
|
|
445
|
+
selects.responsive.control.value = values.responsive === null ? "" : values.responsive;
|
|
446
|
+
Object.keys(inputs).forEach(function(key) {
|
|
447
|
+
inputs[key].checked = values[key];
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
render();
|
|
451
|
+
sections.push({ node: container, element: body, render });
|
|
452
|
+
return body;
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
labelKey: "container.add_offcanvas",
|
|
456
|
+
paneKind: "offcanvas",
|
|
457
|
+
// The ids a copy of an offcanvas has to rename together
|
|
458
|
+
references: ["data-ge-offcanvas-id", "data-ge-offcanvas-target"],
|
|
459
|
+
onInit: triggers.onInit,
|
|
460
|
+
onDeinit: function() {
|
|
461
|
+
sections = [];
|
|
462
|
+
triggers.onDeinit();
|
|
463
|
+
dropTriggerMarks(ge.canvas);
|
|
464
|
+
},
|
|
465
|
+
// What onDeinit and unmark do, on a copy of the canvas
|
|
466
|
+
cleanMarkup: function(root) {
|
|
467
|
+
var definition = this;
|
|
468
|
+
triggers.write(root);
|
|
469
|
+
dropTriggerMarks(root);
|
|
470
|
+
all(root, '[data-ge-container="offcanvas"]').forEach(function(container) {
|
|
471
|
+
definition.unmark(container);
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
create: function(options) {
|
|
475
|
+
options = options || {};
|
|
476
|
+
var id = ge.containerId("offcanvas");
|
|
477
|
+
var container = element("div", { "data-ge-container": "offcanvas", "data-ge-offcanvas-id": id });
|
|
478
|
+
if (options.trigger !== false) {
|
|
479
|
+
container.appendChild(element("button", {
|
|
480
|
+
type: "button",
|
|
481
|
+
"class": "btn btn-primary ge-offcanvas-trigger",
|
|
482
|
+
"data-ge-offcanvas-target": id
|
|
483
|
+
}, options.trigger_label || ge.t("container.offcanvas_trigger")));
|
|
484
|
+
}
|
|
485
|
+
var panel = container.appendChild(element("div", {
|
|
486
|
+
"class": "offcanvas",
|
|
487
|
+
tabindex: "-1",
|
|
488
|
+
id,
|
|
489
|
+
"aria-labelledby": id + "-label"
|
|
490
|
+
}));
|
|
491
|
+
var header = panel.appendChild(element("div", { "class": "offcanvas-header" }));
|
|
492
|
+
header.appendChild(element("h5", { "class": "offcanvas-title", id: id + "-label" })).appendChild(element(
|
|
493
|
+
"span",
|
|
494
|
+
{ "class": "ge-pane-label" },
|
|
495
|
+
options.title || ge.t("container.offcanvas_title")
|
|
496
|
+
));
|
|
497
|
+
header.appendChild(create('<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>'));
|
|
498
|
+
panel.appendChild(element("div", { "class": "offcanvas-body" })).appendChild(ge.defaultRegion());
|
|
499
|
+
KEYS.forEach(function(key) {
|
|
500
|
+
write(container, key, chosen(options, key));
|
|
501
|
+
});
|
|
502
|
+
return container;
|
|
503
|
+
},
|
|
504
|
+
mark: function(container) {
|
|
505
|
+
var header = child(panelOf(container), ".offcanvas-header");
|
|
506
|
+
all(header, "[data-bs-dismiss]").forEach(function(dismiss) {
|
|
507
|
+
ge.suspendToggles(dismiss);
|
|
508
|
+
});
|
|
509
|
+
all(header, ".offcanvas-title").forEach(function(title) {
|
|
510
|
+
ge.makeLabelEditable(ge.labelIn(title));
|
|
511
|
+
});
|
|
512
|
+
},
|
|
513
|
+
unmark: function(container) {
|
|
514
|
+
var header = child(panelOf(container), ".offcanvas-header");
|
|
515
|
+
if (header) {
|
|
516
|
+
ge.resumeToggles(header);
|
|
517
|
+
ge.unwrapLabels(header);
|
|
518
|
+
}
|
|
519
|
+
removeClass(container, "ge-offcanvas-collapsed");
|
|
520
|
+
},
|
|
521
|
+
/** A page of unfolded panels stays workable if they can be folded away. */
|
|
522
|
+
tools: function(drawer, container) {
|
|
523
|
+
ge.createTool(
|
|
524
|
+
drawer,
|
|
525
|
+
ge.t("tool.toggle_offcanvas"),
|
|
526
|
+
"ge-toggle-offcanvas",
|
|
527
|
+
"bi bi-chevron-bar-contract",
|
|
528
|
+
function() {
|
|
529
|
+
toggleClass(container, "ge-offcanvas-collapsed");
|
|
530
|
+
}
|
|
531
|
+
);
|
|
532
|
+
},
|
|
533
|
+
panelSection: function(node, kind) {
|
|
534
|
+
if (kind === "offcanvas" && panelOf(node)) {
|
|
535
|
+
return { labelKey: "container.offcanvas_section", body: createSection(node) };
|
|
536
|
+
}
|
|
537
|
+
return null;
|
|
538
|
+
},
|
|
539
|
+
// After a view change or a change of classes: the sections follow
|
|
540
|
+
onRefresh: function(scope) {
|
|
541
|
+
sections = sections.filter(function(entry) {
|
|
542
|
+
return entry.element.isConnected;
|
|
543
|
+
});
|
|
544
|
+
sections.forEach(function(entry) {
|
|
545
|
+
if (entry.node === scope || scope.contains(entry.node)) {
|
|
546
|
+
entry.render();
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
};
|