editorjs-inspector
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -6,5 +6,5 @@ import type { InlineTool, InlineToolConstructorOptions } from '@editorjs/editorjs'; | ||
static get title(): string; | ||
static domTree({ anchor, node, }: { | ||
anchor: Node; | ||
static domTree({ node, selectedNodes, }: { | ||
node: Node; | ||
selectedNodes: Node[]; | ||
}): HTMLLIElement; | ||
@@ -11,0 +11,0 @@ constructor({ api }: InlineToolConstructorOptions); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EditorJSInspector=t():e.EditorJSInspector=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);class o extends Error{constructor(...e){super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="EditorJSInspectorError"}}var r,i,s,a,c=o,l=function(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n},d=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class u{constructor({api:e}){r.set(this,void 0),i.set(this,void 0),s.set(this,void 0),a.set(this,void 0),l(this,r,e),l(this,i,document.createElement("button")),d(this,i).classList.add(d(this,r).styles.inlineToolButton),d(this,i).type="button",d(this,i).innerHTML='\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n </svg>\n ',l(this,s,document.createElement("div")),d(this,s).classList.add("editorjs-inspector-dialog"),d(this,s).style.position="absolute",d(this,s).style.backgroundColor="#ffffff",d(this,s).style.border="1px solid #eaeaea",d(this,s).style.borderRadius="4px",d(this,s).style.boxShadow="0 3px 15px -3px rgba(13,20,33,.13)",d(this,s).style.left="0",d(this,s).style.margin="1rem",d(this,s).style.paddingRight="1rem",l(this,a,!1)}static get isInline(){return!0}static get title(){return"Inspector"}static domTree({anchor:e,node:t}){var n;const o=document.createElement("li"),r=document.createElement("span");r.style.cursor="pointer",e.isEqualNode(t)&&(r.style.backgroundColor="#cae6fe"),r.textContent=t instanceof Element?`<${[t.nodeName.toLowerCase(),...Array.from(t.attributes).map(e=>`${e.name}="${e.value}"`)].join(" ")}>`:null!==(n=t.textContent)&&void 0!==n?n:"",r.addEventListener("pointerdown",e=>{const n=window.getSelection();if(!n)throw new c;const o=new Range;(t instanceof Element?o.selectNode:o.selectNodeContents)(t),n.removeAllRanges(),n.addRange(o),e.preventDefault()}),o.append(r);const i=document.createElement("ul");return i.append(...Array.from(t.childNodes).map(t=>u.domTree({anchor:e,node:t}))),o.append(i),o}get shortcut(){return"CMD+SHIFT+I"}checkState(){var e,t;if(d(this,i).classList.toggle(d(this,r).styles.inlineToolButtonActive,d(this,a)),!d(this,a))return this.clear(),!1;const n=null===(e=d(this,i).closest(".codex-editor"))||void 0===e?void 0:e.querySelector("div.ce-inline-toolbar"),o=window.getSelection();if(!n||!o)throw new c;if(!(null===(t=o.anchorNode)||void 0===t?void 0:t.parentElement))return!1;let l=o.anchorNode instanceof HTMLElement?o.anchorNode:o.anchorNode.parentElement;for(;l&&"true"!==l.contentEditable;)l=l.parentElement;if(!l)return!1;d(this,s).innerHTML="",d(this,s).style.display="block",d(this,s).style.top=n.offsetTop+n.offsetHeight+"px";const p=document.createElement("ul");return p.append(u.domTree({anchor:o.anchorNode,node:l})),d(this,s).append(p),!0}clear(){d(this,s).style.display="none"}render(){return setTimeout(()=>{var e;const t=null===(e=d(this,i).closest(".codex-editor"))||void 0===e?void 0:e.querySelector(".ce-inline-toolbar");if(!(null==t?void 0:t.parentNode))throw new c;t.parentNode.insertBefore(d(this,s),t)}),d(this,i)}surround(){l(this,a,!d(this,a))}}r=new WeakMap,i=new WeakMap,s=new WeakMap,a=new WeakMap;var p=u;t.default=p}]).default})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EditorJSInspector=t():e.EditorJSInspector=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);class o extends Error{constructor(...e){super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="EditorJSInspectorError"}}var r,i,s,a,l=o,d=function(e,t,n){if(!t.has(e))throw new TypeError("attempted to set private field on non-instance");return t.set(e,n),n},c=function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};class u{constructor({api:e}){r.set(this,void 0),i.set(this,void 0),s.set(this,void 0),a.set(this,void 0),d(this,r,e),d(this,i,document.createElement("button")),c(this,i).classList.add(c(this,r).styles.inlineToolButton),c(this,i).type="button",c(this,i).innerHTML='\n <svg class="icon" height="24" viewBox="0 0 24 24" width="24">\n <path d="M0 0h24v24H0z" fill="none"/>\n <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n </svg>\n ',d(this,s,document.createElement("div")),c(this,s).classList.add("editorjs-inspector-dialog"),c(this,s).style.position="absolute",c(this,s).style.backgroundColor="#ffffff",c(this,s).style.border="1px solid #eaeaea",c(this,s).style.borderRadius="4px",c(this,s).style.boxShadow="0 3px 15px -3px rgba(13,20,33,.13)",c(this,s).style.left="0",c(this,s).style.margin="1rem",c(this,s).style.paddingRight="1rem",d(this,a,!1)}static get isInline(){return!0}static get title(){return"Inspector"}static domTree({node:e,selectedNodes:t}){var n;const o=document.createElement("li"),r=document.createElement("span");r.style.cursor="pointer",t.some(t=>t.isEqualNode(e))&&(r.style.backgroundColor="#cae6fe"),r.textContent=e instanceof Element?`<${[e.nodeName.toLowerCase(),...Array.from(e.attributes).map(e=>`${e.name}="${e.value}"`)].join(" ")}>`:null!==(n=e.textContent)&&void 0!==n?n:"",r.addEventListener("pointerdown",t=>{const n=window.getSelection();if(!n)throw new l;const o=new Range;o.selectNode(e),n.removeAllRanges(),n.addRange(o),t.preventDefault()}),o.append(r);const i=document.createElement("ul");return i.append(...Array.from(e.childNodes).map(e=>u.domTree({node:e,selectedNodes:t}))),o.append(i),o}get shortcut(){return"CMD+SHIFT+I"}checkState(){var e,t;if(c(this,i).classList.toggle(c(this,r).styles.inlineToolButtonActive,c(this,a)),!c(this,a))return this.clear(),!1;const n=null===(e=c(this,i).closest(".codex-editor"))||void 0===e?void 0:e.querySelector("div.ce-inline-toolbar"),o=window.getSelection();if(!n||!o)throw new l;if(!(null===(t=o.anchorNode)||void 0===t?void 0:t.parentElement))return!1;let d=o.anchorNode instanceof HTMLElement?o.anchorNode:o.anchorNode.parentElement;for(;d&&"true"!==d.contentEditable;)d=d.parentElement;if(!d)return!1;c(this,s).innerHTML="",c(this,s).style.display="block",c(this,s).style.top=n.offsetTop+n.offsetHeight+"px";const p=o.getRangeAt(0),f=[p.startContainer instanceof Element?p.startContainer.childNodes[p.startOffset]:p.startContainer],h=document.createElement("ul");return h.append(u.domTree({node:d,selectedNodes:f})),c(this,s).append(h),!0}clear(){c(this,s).style.display="none"}render(){return setTimeout(()=>{var e;const t=null===(e=c(this,i).closest(".codex-editor"))||void 0===e?void 0:e.querySelector(".ce-inline-toolbar");if(!(null==t?void 0:t.parentNode))throw new l;t.parentNode.insertBefore(c(this,s),t)}),c(this,i)}surround(){d(this,a,!c(this,a))}}r=new WeakMap,i=new WeakMap,s=new WeakMap,a=new WeakMap;var p=u;t.default=p}]).default})); |
{ | ||
"name": "editorjs-inspector", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "DOM inspector feature for Editor.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -18,7 +18,7 @@ import type { | ||
static domTree({ | ||
anchor, | ||
node, | ||
selectedNodes, | ||
}: { | ||
anchor: Node; | ||
node: Node; | ||
selectedNodes: Node[]; | ||
}): HTMLLIElement { | ||
@@ -30,3 +30,3 @@ const listItem = document.createElement('li'); | ||
if (anchor.isEqualNode(node)) { | ||
if (selectedNodes.some((selectedNode) => selectedNode.isEqualNode(node))) { | ||
span.style.backgroundColor = '#cae6fe'; | ||
@@ -54,5 +54,3 @@ } | ||
(node instanceof Element ? range.selectNode : range.selectNodeContents)( | ||
node | ||
); | ||
range.selectNode(node); | ||
@@ -71,3 +69,3 @@ selection.removeAllRanges(); | ||
...Array.from(node.childNodes).map((childNode) => | ||
EditorJSInspector.domTree({ anchor, node: childNode }) | ||
EditorJSInspector.domTree({ node: childNode, selectedNodes }) | ||
) | ||
@@ -165,7 +163,13 @@ ); | ||
const range = selection.getRangeAt(0); | ||
const selectedNodes = [ | ||
range.startContainer instanceof Element | ||
? range.startContainer.childNodes[range.startOffset] | ||
: range.startContainer, | ||
]; | ||
const list = document.createElement('ul'); | ||
list.append( | ||
EditorJSInspector.domTree({ anchor: selection.anchorNode, node: root }) | ||
); | ||
list.append(EditorJSInspector.domTree({ node: root, selectedNodes })); | ||
@@ -172,0 +176,0 @@ this.#dialog.append(list); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
717405
227