@editorjs/header 2.8.8 → 2.8.9
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/dist/header.mjs +39 -29
- package/dist/header.umd.js +2 -2
- package/dist/index.d.ts +6 -5
- package/package.json +2 -2
package/dist/header.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ce-header{padding:.6em 0 3px;margin:0;line-height:1.25em;outline:none}.ce-header p,.ce-header div{padding:0!important;margin:0!important}")),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})();
|
|
2
|
-
const a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19 17V10.2135C19 10.1287 18.9011 10.0824 18.836 10.1367L16 12.5"/></svg>',
|
|
2
|
+
const a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19 17V10.2135C19 10.1287 18.9011 10.0824 18.836 10.1367L16 12.5"/></svg>', h = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10 19 9.5 19 12C19 13.9771 16.0684 13.9997 16.0012 16.8981C15.9999 16.9533 16.0448 17 16.1 17L19.3 17"/></svg>', d = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10.5 16.8323 10 17.6 10C18.3677 10 19.5 10.311 19.5 11.5C19.5 12.5315 18.7474 12.9022 18.548 12.9823C18.5378 12.9864 18.5395 13.0047 18.5503 13.0063C18.8115 13.0456 20 13.3065 20 14.8C20 16 19.5 17 17.8 17C17.8 17 16 17 16 16.3"/></svg>', c = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M18 10L15.2834 14.8511C15.246 14.9178 15.294 15 15.3704 15C16.8489 15 18.7561 15 20.2 15M19 17C19 15.7187 19 14.8813 19 13.6"/></svg>', u = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 15.9C16 15.9 16.3768 17 17.8 17C19.5 17 20 15.6199 20 14.7C20 12.7323 17.6745 12.0486 16.1635 12.9894C16.094 13.0327 16 12.9846 16 12.9027V10.1C16 10.0448 16.0448 10 16.1 10H19.8"/></svg>', g = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19.5 10C16.5 10.5 16 13.3285 16 15M16 15V15C16 16.1046 16.8954 17 18 17H18.3246C19.3251 17 20.3191 16.3492 20.2522 15.3509C20.0612 12.4958 16 12.6611 16 15Z"/></svg>', v = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M9 7L9 12M9 17V12M9 12L15 12M15 7V12M15 17L15 12"/></svg>';
|
|
3
3
|
/**
|
|
4
4
|
* Header block for the Editor.js.
|
|
5
5
|
*
|
|
@@ -8,9 +8,9 @@ const a = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="
|
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @version 2.0.0
|
|
10
10
|
*/
|
|
11
|
-
class
|
|
11
|
+
class p {
|
|
12
12
|
constructor({ data: e, config: t, api: s, readOnly: r }) {
|
|
13
|
-
this.api = s, this.readOnly = r, this.
|
|
13
|
+
this.api = s, this.readOnly = r, this._config = t ?? null, this._data = this.normalizeData(e), this._element = this.getTag();
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Styles
|
|
@@ -171,8 +171,9 @@ class v {
|
|
|
171
171
|
* @returns {HTMLElement}
|
|
172
172
|
*/
|
|
173
173
|
getTag() {
|
|
174
|
+
var t;
|
|
174
175
|
const e = document.createElement(this.currentLevel.tag);
|
|
175
|
-
return e.innerHTML = this._data.text || "", e.classList.add(this._CSS.wrapper), e.contentEditable = this.readOnly ? "false" : "true", e.dataset.placeholder = this.api.i18n.t(this.
|
|
176
|
+
return e.innerHTML = this._data.text || "", e.classList.add(this._CSS.wrapper), e.contentEditable = this.readOnly ? "false" : "true", e.dataset.placeholder = this.api.i18n.t(((t = this._config) == null ? void 0 : t.placeholder) || ""), e;
|
|
176
177
|
}
|
|
177
178
|
/**
|
|
178
179
|
* Get current level
|
|
@@ -189,10 +190,14 @@ class v {
|
|
|
189
190
|
* @returns {level}
|
|
190
191
|
*/
|
|
191
192
|
get defaultLevel() {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
var e;
|
|
194
|
+
if ((e = this._config) != null && e.defaultLevel) {
|
|
195
|
+
const t = this.levels.find((s) => {
|
|
196
|
+
var r;
|
|
197
|
+
return s.number === ((r = this._config) == null ? void 0 : r.defaultLevel);
|
|
198
|
+
});
|
|
199
|
+
if (t)
|
|
200
|
+
return t;
|
|
196
201
|
console.warn("(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels");
|
|
197
202
|
}
|
|
198
203
|
return this.levels[1];
|
|
@@ -209,6 +214,7 @@ class v {
|
|
|
209
214
|
* @returns {level[]}
|
|
210
215
|
*/
|
|
211
216
|
get levels() {
|
|
217
|
+
var t;
|
|
212
218
|
const e = [
|
|
213
219
|
{
|
|
214
220
|
number: 1,
|
|
@@ -218,31 +224,34 @@ class v {
|
|
|
218
224
|
{
|
|
219
225
|
number: 2,
|
|
220
226
|
tag: "H2",
|
|
221
|
-
svg:
|
|
227
|
+
svg: h
|
|
222
228
|
},
|
|
223
229
|
{
|
|
224
230
|
number: 3,
|
|
225
231
|
tag: "H3",
|
|
226
|
-
svg:
|
|
232
|
+
svg: d
|
|
227
233
|
},
|
|
228
234
|
{
|
|
229
235
|
number: 4,
|
|
230
236
|
tag: "H4",
|
|
231
|
-
svg:
|
|
237
|
+
svg: c
|
|
232
238
|
},
|
|
233
239
|
{
|
|
234
240
|
number: 5,
|
|
235
241
|
tag: "H5",
|
|
236
|
-
svg:
|
|
242
|
+
svg: u
|
|
237
243
|
},
|
|
238
244
|
{
|
|
239
245
|
number: 6,
|
|
240
246
|
tag: "H6",
|
|
241
|
-
svg:
|
|
247
|
+
svg: g
|
|
242
248
|
}
|
|
243
249
|
];
|
|
244
|
-
return this.
|
|
245
|
-
(
|
|
250
|
+
return (t = this._config) != null && t.levels ? e.filter(
|
|
251
|
+
(s) => {
|
|
252
|
+
var r;
|
|
253
|
+
return (r = this._config) == null ? void 0 : r.levels.includes(s.number);
|
|
254
|
+
}
|
|
246
255
|
) : e;
|
|
247
256
|
}
|
|
248
257
|
/**
|
|
@@ -251,33 +260,34 @@ class v {
|
|
|
251
260
|
* @param {PasteEvent} event - event with pasted content
|
|
252
261
|
*/
|
|
253
262
|
onPaste(e) {
|
|
263
|
+
var s, r;
|
|
254
264
|
const t = e.detail;
|
|
255
265
|
if ("data" in t) {
|
|
256
|
-
const
|
|
257
|
-
let
|
|
258
|
-
switch (
|
|
266
|
+
const i = t.data;
|
|
267
|
+
let n = this.defaultLevel.number;
|
|
268
|
+
switch (i.tagName) {
|
|
259
269
|
case "H1":
|
|
260
|
-
|
|
270
|
+
n = 1;
|
|
261
271
|
break;
|
|
262
272
|
case "H2":
|
|
263
|
-
|
|
273
|
+
n = 2;
|
|
264
274
|
break;
|
|
265
275
|
case "H3":
|
|
266
|
-
|
|
276
|
+
n = 3;
|
|
267
277
|
break;
|
|
268
278
|
case "H4":
|
|
269
|
-
|
|
279
|
+
n = 4;
|
|
270
280
|
break;
|
|
271
281
|
case "H5":
|
|
272
|
-
|
|
282
|
+
n = 5;
|
|
273
283
|
break;
|
|
274
284
|
case "H6":
|
|
275
|
-
|
|
285
|
+
n = 6;
|
|
276
286
|
break;
|
|
277
287
|
}
|
|
278
|
-
this.
|
|
279
|
-
level:
|
|
280
|
-
text:
|
|
288
|
+
(s = this._config) != null && s.levels && (n = (r = this._config) == null ? void 0 : r.levels.reduce((o, l) => Math.abs(l - n) < Math.abs(o - n) ? l : o)), this.data = {
|
|
289
|
+
level: n,
|
|
290
|
+
text: i.innerHTML
|
|
281
291
|
};
|
|
282
292
|
}
|
|
283
293
|
}
|
|
@@ -301,11 +311,11 @@ class v {
|
|
|
301
311
|
*/
|
|
302
312
|
static get toolbox() {
|
|
303
313
|
return {
|
|
304
|
-
icon:
|
|
314
|
+
icon: v,
|
|
305
315
|
title: "Heading"
|
|
306
316
|
};
|
|
307
317
|
}
|
|
308
318
|
}
|
|
309
319
|
export {
|
|
310
|
-
|
|
320
|
+
p as default
|
|
311
321
|
};
|
package/dist/header.umd.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".ce-header{padding:.6em 0 3px;margin:0;line-height:1.25em;outline:none}.ce-header p,.ce-header div{padding:0!important;margin:0!important}")),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})();
|
|
2
|
-
(function(
|
|
2
|
+
(function(o,s){typeof exports=="object"&&typeof module<"u"?module.exports=s():typeof define=="function"&&define.amd?define(s):(o=typeof globalThis<"u"?globalThis:o||self,o.Header=s())})(this,function(){"use strict";const o="",s='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19 17V10.2135C19 10.1287 18.9011 10.0824 18.836 10.1367L16 12.5"/></svg>',d='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10 19 9.5 19 12C19 13.9771 16.0684 13.9997 16.0012 16.8981C15.9999 16.9533 16.0448 17 16.1 17L19.3 17"/></svg>',u='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 11C16 10.5 16.8323 10 17.6 10C18.3677 10 19.5 10.311 19.5 11.5C19.5 12.5315 18.7474 12.9022 18.548 12.9823C18.5378 12.9864 18.5395 13.0047 18.5503 13.0063C18.8115 13.0456 20 13.3065 20 14.8C20 16 19.5 17 17.8 17C17.8 17 16 17 16 16.3"/></svg>',c='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M18 10L15.2834 14.8511C15.246 14.9178 15.294 15 15.3704 15C16.8489 15 18.7561 15 20.2 15M19 17C19 15.7187 19 14.8813 19 13.6"/></svg>',g='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 15.9C16 15.9 16.3768 17 17.8 17C19.5 17 20 15.6199 20 14.7C20 12.7323 17.6745 12.0486 16.1635 12.9894C16.094 13.0327 16 12.9846 16 12.9027V10.1C16 10.0448 16.0448 10 16.1 10H19.8"/></svg>',v='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M6 7L6 12M6 17L6 12M6 12L12 12M12 7V12M12 17L12 12"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M19.5 10C16.5 10.5 16 13.3285 16 15M16 15V15C16 16.1046 16.8954 17 18 17H18.3246C19.3251 17 20.3191 16.3492 20.2522 15.3509C20.0612 12.4958 16 12.6611 16 15Z"/></svg>',w='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M9 7L9 12M9 17V12M9 12L15 12M15 7V12M15 17L15 12"/></svg>';/**
|
|
3
3
|
* Header block for the Editor.js.
|
|
4
4
|
*
|
|
5
5
|
* @author CodeX (team@ifmo.su)
|
|
6
6
|
* @copyright CodeX 2018
|
|
7
7
|
* @license MIT
|
|
8
8
|
* @version 2.0.0
|
|
9
|
-
*/class
|
|
9
|
+
*/class p{constructor({data:e,config:t,api:i,readOnly:r}){this.api=i,this.readOnly=r,this._config=t??null,this._data=this.normalizeData(e),this._element=this.getTag()}get _CSS(){return{block:this.api.styles.block,wrapper:"ce-header"}}isHeaderData(e){return e.text!==void 0}normalizeData(e){const t={text:"",level:this.defaultLevel.number};return this.isHeaderData(e)&&(t.text=e.text||"",e.level!==void 0&&!isNaN(parseInt(e.level.toString()))&&(t.level=parseInt(e.level.toString()))),t}render(){return this._element}renderSettings(){return this.levels.map(e=>({icon:e.svg,label:this.api.i18n.t(`Heading ${e.number}`),onActivate:()=>this.setLevel(e.number),closeOnActivate:!0,isActive:this.currentLevel.number===e.number,render:()=>document.createElement("div")}))}setLevel(e){this.data={level:e,text:this.data.text}}merge(e){this._element.insertAdjacentHTML("beforeend",e.text)}validate(e){return e.text.trim()!==""}save(e){return{text:e.innerHTML,level:this.currentLevel.number}}static get conversionConfig(){return{export:"text",import:"text"}}static get sanitize(){return{level:!1,text:{}}}static get isReadOnlySupported(){return!0}get data(){return this._data.text=this._element.innerHTML,this._data.level=this.currentLevel.number,this._data}set data(e){if(this._data=this.normalizeData(e),e.level!==void 0&&this._element.parentNode){const t=this.getTag();t.innerHTML=this._element.innerHTML,this._element.parentNode.replaceChild(t,this._element),this._element=t}e.text!==void 0&&(this._element.innerHTML=this._data.text||"")}getTag(){var t;const e=document.createElement(this.currentLevel.tag);return e.innerHTML=this._data.text||"",e.classList.add(this._CSS.wrapper),e.contentEditable=this.readOnly?"false":"true",e.dataset.placeholder=this.api.i18n.t(((t=this._config)==null?void 0:t.placeholder)||""),e}get currentLevel(){let e=this.levels.find(t=>t.number===this._data.level);return e||(e=this.defaultLevel),e}get defaultLevel(){var e;if((e=this._config)!=null&&e.defaultLevel){const t=this.levels.find(i=>{var r;return i.number===((r=this._config)==null?void 0:r.defaultLevel)});if(t)return t;console.warn("(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels")}return this.levels[1]}get levels(){var t;const e=[{number:1,tag:"H1",svg:s},{number:2,tag:"H2",svg:d},{number:3,tag:"H3",svg:u},{number:4,tag:"H4",svg:c},{number:5,tag:"H5",svg:g},{number:6,tag:"H6",svg:v}];return(t=this._config)!=null&&t.levels?e.filter(i=>{var r;return(r=this._config)==null?void 0:r.levels.includes(i.number)}):e}onPaste(e){var i,r;const t=e.detail;if("data"in t){const l=t.data;let n=this.defaultLevel.number;switch(l.tagName){case"H1":n=1;break;case"H2":n=2;break;case"H3":n=3;break;case"H4":n=4;break;case"H5":n=5;break;case"H6":n=6;break}(i=this._config)!=null&&i.levels&&(n=(r=this._config)==null?void 0:r.levels.reduce((a,h)=>Math.abs(h-n)<Math.abs(a-n)?h:a)),this.data={level:n,text:l.innerHTML}}}static get pasteConfig(){return{tags:["H1","H2","H3","H4","H5","H6"]}}static get toolbox(){return{icon:w,title:"Heading"}}}return p});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { API,
|
|
1
|
+
import { API, BlockTool, PasteEvent } from '@editorjs/editorjs';
|
|
2
|
+
import { MenuConfig } from '@editorjs/editorjs/types/tools';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @description Tool's input and output data format
|
|
@@ -38,7 +39,7 @@ interface ConstructorArgs {
|
|
|
38
39
|
/** Previously saved data */
|
|
39
40
|
data: HeaderData | {};
|
|
40
41
|
/** User config for the tool */
|
|
41
|
-
config
|
|
42
|
+
config?: HeaderConfig;
|
|
42
43
|
/** Editor.js API */
|
|
43
44
|
api: API;
|
|
44
45
|
/** Read-only mode flag */
|
|
@@ -52,7 +53,7 @@ interface ConstructorArgs {
|
|
|
52
53
|
* @license MIT
|
|
53
54
|
* @version 2.0.0
|
|
54
55
|
*/
|
|
55
|
-
export default class Header {
|
|
56
|
+
export default class Header implements BlockTool {
|
|
56
57
|
/**
|
|
57
58
|
* Render plugin`s main Element and fill it with saved data
|
|
58
59
|
*
|
|
@@ -76,7 +77,7 @@ export default class Header {
|
|
|
76
77
|
* Tool's settings passed from Editor
|
|
77
78
|
* @private
|
|
78
79
|
*/
|
|
79
|
-
private
|
|
80
|
+
private _config;
|
|
80
81
|
/**
|
|
81
82
|
* Block's data
|
|
82
83
|
* @private
|
|
@@ -121,7 +122,7 @@ export default class Header {
|
|
|
121
122
|
*
|
|
122
123
|
* @returns {Array}
|
|
123
124
|
*/
|
|
124
|
-
renderSettings():
|
|
125
|
+
renderSettings(): MenuConfig;
|
|
125
126
|
/**
|
|
126
127
|
* Callback for Block's settings buttons
|
|
127
128
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editorjs/header",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.9",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"codex editor",
|
|
6
6
|
"header",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@codexteam/icons": "^0.0.5",
|
|
43
|
-
"@editorjs/editorjs": "^2.
|
|
43
|
+
"@editorjs/editorjs": "^2.30.7"
|
|
44
44
|
}
|
|
45
45
|
}
|