diff --git a/build/edjsHTML.browser.js b/build/edjsHTML.browser.js index 1bccd1a..fede1f8 100644 --- a/build/edjsHTML.browser.js +++ b/build/edjsHTML.browser.js @@ -1 +1 @@ -var edjsHTML=function(){"use strict";var e=["left","right","center","justify"],t={delimiter:function(){return"
"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

'+r.text+"

":"

"+r.text+"

"},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items&&(r=n(e.items,t)),e.content?"
  • "+e.content+"
  • "+r:void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var a=[],u=0;u"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

    '+r.text+"

    ":"

    "+r.text+"

    "},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items.length&&(r=n(e.items,t)),e.content?"
  • "+e.content+" "+r+"
  • ":void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var a=[],u=0;u"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

    '+r.text+"

    ":"

    "+r.text+"

    "},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items&&(r=n(e.items,t)),e.content?"
  • "+e.content+"
  • "+r:void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var u=[],a=0;a"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

    '+r.text+"

    ":"

    "+r.text+"

    "},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items.length&&(r=n(e.items,t)),e.content?"
  • "+e.content+" "+r+"
  • ":void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var u=[],a=0;a"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

    '+r.text+"

    ":"

    "+r.text+"

    "},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items&&(r=n(e.items,t)),e.content?"
  • "+e.content+"
  • "+r:void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var a=[],u=0;u"},header:function(e){var t=e.data;return""+t.text+""},paragraph:function(t){var r=t.data,n=r.alignment||r.align;return void 0!==n&&e.includes(n)?'

    '+r.text+"

    ":"

    "+r.text+"

    "},list:function(e){var t=e.data,r="unordered"===t.style?"ul":"ol",n=function(e,t){var r=e.map((function(e){if(!e.content&&!e.items)return"
  • "+e+"
  • ";var r="";return e.items.length&&(r=n(e.items,t)),e.content?"
  • "+e.content+" "+r+"
  • ":void 0}));return"<"+t+">"+r.join("")+""};return n(t.items,r)},image:function(e){var t=e.data,r=t.caption?t.caption:"Image";return''+r+''},quote:function(e){var t=e.data;return"
    "+t.text+"
    - "+t.caption},code:function(e){return"
    "+e.data.code+"
    "},embed:function(e){var t=e.data;switch(t.service){case"vimeo":return'';case"youtube":return'';default:throw new Error("Only Youtube and Vime Embeds are supported right now.")}}};function r(e){return new Error(' The Parser function of type "'+e+'" is not defined. \n\n Define your custom parser functions as: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks ')}var n=function(e){void 0===e&&(e={});var i=Object.assign({},t,e);return{parse:function(e){return e.blocks.map((function(e){return i[e.type]?i[e.type](e):r(e.type)}))},parseBlock:function(e){return i[e.type]?i[e.type](e):r(e.type)},parseStrict:function(e){var t=e.blocks,o=n(i).validate({blocks:t});if(o.length)throw new Error("Parser Functions missing for blocks: "+o.toString());for(var a=[],u=0;u | Array; style?: string; code?: string; - service?: "vimeo" | "youtube"; + service?: 'vimeo' | 'youtube'; source?: string; embed?: string; width?: number; height?: number; - alignment?: "left" | "right" | "center" | "justify"; - align?: "left" | "right" | "center" | "justify"; + alignment?: 'left' | 'right' | 'center' | 'justify'; + align?: 'left' | 'right' | 'center' | 'justify'; }; }; declare const transforms: transforms; diff --git a/src/transforms.ts b/src/transforms.ts index b186b4e..3bb3b6f 100644 --- a/src/transforms.ts +++ b/src/transforms.ts @@ -15,7 +15,7 @@ type ListItem = { items: Array; }; -const alignType = ["left", "right", "center", "justify"] +const alignType = ['left', 'right', 'center', 'justify']; export type block = { type: string; @@ -33,13 +33,13 @@ export type block = { items?: Array | Array; style?: string; code?: string; - service?: "vimeo" | "youtube"; + service?: 'vimeo' | 'youtube'; source?: string; embed?: string; width?: number; height?: number; - alignment?: "left" | "right" | "center" | "justify"; - align?: "left" | "right" | "center" | "justify"; + alignment?: 'left' | 'right' | 'center' | 'justify'; + align?: 'left' | 'right' | 'center' | 'justify'; }; }; @@ -55,33 +55,36 @@ const transforms: transforms = { paragraph: ({ data }) => { const paragraphAlign = data.alignment || data.align; - if (typeof paragraphAlign !== 'undefined' && alignType.includes(paragraphAlign)) { + if ( + typeof paragraphAlign !== 'undefined' && + alignType.includes(paragraphAlign) + ) { return `

    ${data.text}

    `; } else { - return `

    ${data.text}

    ` + return `

    ${data.text}

    `; } }, list: ({ data }) => { - const listStyle = data.style === "unordered" ? "ul" : "ol"; + const listStyle = data.style === 'unordered' ? 'ul' : 'ol'; const recursor = (items: any, listStyle: string) => { const list = items.map((item: any) => { if (!item.content && !item.items) return `
  • ${item}
  • `; - let list = ""; - if (item.items) list = recursor(item.items, listStyle); + let list = ''; + if (item.items.length) list = recursor(item.items, listStyle); if (item.content) return `
  • ${item.content} ${list}
  • `; }); - return `<${listStyle}>${list.join("")}`; + return `<${listStyle}>${list.join('')}`; }; return recursor(data.items, listStyle); }, image: ({ data }) => { - let caption = data.caption ? data.caption : "Image"; + let caption = data.caption ? data.caption : 'Image'; return `${caption}`; @@ -97,13 +100,13 @@ const transforms: transforms = { embed: ({ data }) => { switch (data.service) { - case "vimeo": + case 'vimeo': return ``; - case "youtube": + case 'youtube': return ``; default: throw new Error( - "Only Youtube and Vime Embeds are supported right now." + 'Only Youtube and Vime Embeds are supported right now.' ); } },