From d87f33ba4aa709218c018f52be3f80c28b7e90e3 Mon Sep 17 00:00:00 2001 From: Ihor Marhitych Date: Sat, 25 Mar 2023 17:38:28 +0100 Subject: [PATCH] AnchorIdentifier onRemove: reset header anchor id to default --- .../js/wagtail-draftail-anchor.js | 113 +++++++++++++++++- .../js/wagtail_draftail_anchor.js | 42 ++++--- 2 files changed, 137 insertions(+), 18 deletions(-) diff --git a/wagtail_draftail_anchors/static/wagtaildraftailanchors/js/wagtail-draftail-anchor.js b/wagtail_draftail_anchors/static/wagtaildraftailanchors/js/wagtail-draftail-anchor.js index 2df8062..8be1813 100644 --- a/wagtail_draftail_anchors/static/wagtaildraftailanchors/js/wagtail-draftail-anchor.js +++ b/wagtail_draftail_anchors/static/wagtaildraftailanchors/js/wagtail-draftail-anchor.js @@ -1 +1,112 @@ -!function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e,n){var o;o=function(){var t=JSON.parse('{"$":"dollar","%":"percent","&":"and","<":"less",">":"greater","|":"or","¢":"cent","£":"pound","¤":"currency","¥":"yen","©":"(c)","ª":"a","®":"(r)","º":"o","À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","Æ":"AE","Ç":"C","È":"E","É":"E","Ê":"E","Ë":"E","Ì":"I","Í":"I","Î":"I","Ï":"I","Ð":"D","Ñ":"N","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","Ù":"U","Ú":"U","Û":"U","Ü":"U","Ý":"Y","Þ":"TH","ß":"ss","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","æ":"ae","ç":"c","è":"e","é":"e","ê":"e","ë":"e","ì":"i","í":"i","î":"i","ï":"i","ð":"d","ñ":"n","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","ù":"u","ú":"u","û":"u","ü":"u","ý":"y","þ":"th","ÿ":"y","Ā":"A","ā":"a","Ă":"A","ă":"a","Ą":"A","ą":"a","Ć":"C","ć":"c","Č":"C","č":"c","Ď":"D","ď":"d","Đ":"DJ","đ":"dj","Ē":"E","ē":"e","Ė":"E","ė":"e","Ę":"e","ę":"e","Ě":"E","ě":"e","Ğ":"G","ğ":"g","Ģ":"G","ģ":"g","Ĩ":"I","ĩ":"i","Ī":"i","ī":"i","Į":"I","į":"i","İ":"I","ı":"i","Ķ":"k","ķ":"k","Ļ":"L","ļ":"l","Ľ":"L","ľ":"l","Ł":"L","ł":"l","Ń":"N","ń":"n","Ņ":"N","ņ":"n","Ň":"N","ň":"n","Ő":"O","ő":"o","Œ":"OE","œ":"oe","Ŕ":"R","ŕ":"r","Ř":"R","ř":"r","Ś":"S","ś":"s","Ş":"S","ş":"s","Š":"S","š":"s","Ţ":"T","ţ":"t","Ť":"T","ť":"t","Ũ":"U","ũ":"u","Ū":"u","ū":"u","Ů":"U","ů":"u","Ű":"U","ű":"u","Ų":"U","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","ź":"z","Ż":"Z","ż":"z","Ž":"Z","ž":"z","ƒ":"f","Ơ":"O","ơ":"o","Ư":"U","ư":"u","Lj":"LJ","lj":"lj","Nj":"NJ","nj":"nj","Ș":"S","ș":"s","Ț":"T","ț":"t","˚":"o","Ά":"A","Έ":"E","Ή":"H","Ί":"I","Ό":"O","Ύ":"Y","Ώ":"W","ΐ":"i","Α":"A","Β":"B","Γ":"G","Δ":"D","Ε":"E","Ζ":"Z","Η":"H","Θ":"8","Ι":"I","Κ":"K","Λ":"L","Μ":"M","Ν":"N","Ξ":"3","Ο":"O","Π":"P","Ρ":"R","Σ":"S","Τ":"T","Υ":"Y","Φ":"F","Χ":"X","Ψ":"PS","Ω":"W","Ϊ":"I","Ϋ":"Y","ά":"a","έ":"e","ή":"h","ί":"i","ΰ":"y","α":"a","β":"b","γ":"g","δ":"d","ε":"e","ζ":"z","η":"h","θ":"8","ι":"i","κ":"k","λ":"l","μ":"m","ν":"n","ξ":"3","ο":"o","π":"p","ρ":"r","ς":"s","σ":"s","τ":"t","υ":"y","φ":"f","χ":"x","ψ":"ps","ω":"w","ϊ":"i","ϋ":"y","ό":"o","ύ":"y","ώ":"w","Ё":"Yo","Ђ":"DJ","Є":"Ye","І":"I","Ї":"Yi","Ј":"J","Љ":"LJ","Њ":"NJ","Ћ":"C","Џ":"DZ","А":"A","Б":"B","В":"V","Г":"G","Д":"D","Е":"E","Ж":"Zh","З":"Z","И":"I","Й":"J","К":"K","Л":"L","М":"M","Н":"N","О":"O","П":"P","Р":"R","С":"S","Т":"T","У":"U","Ф":"F","Х":"H","Ц":"C","Ч":"Ch","Ш":"Sh","Щ":"Sh","Ъ":"U","Ы":"Y","Ь":"","Э":"E","Ю":"Yu","Я":"Ya","а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ж":"zh","з":"z","и":"i","й":"j","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"ch","ш":"sh","щ":"sh","ъ":"u","ы":"y","ь":"","э":"e","ю":"yu","я":"ya","ё":"yo","ђ":"dj","є":"ye","і":"i","ї":"yi","ј":"j","љ":"lj","њ":"nj","ћ":"c","ѝ":"u","џ":"dz","Ґ":"G","ґ":"g","Ғ":"GH","ғ":"gh","Қ":"KH","қ":"kh","Ң":"NG","ң":"ng","Ү":"UE","ү":"ue","Ұ":"U","ұ":"u","Һ":"H","һ":"h","Ә":"AE","ә":"ae","Ө":"OE","ө":"oe","฿":"baht","ა":"a","ბ":"b","გ":"g","დ":"d","ე":"e","ვ":"v","ზ":"z","თ":"t","ი":"i","კ":"k","ლ":"l","მ":"m","ნ":"n","ო":"o","პ":"p","ჟ":"zh","რ":"r","ს":"s","ტ":"t","უ":"u","ფ":"f","ქ":"k","ღ":"gh","ყ":"q","შ":"sh","ჩ":"ch","ც":"ts","ძ":"dz","წ":"ts","ჭ":"ch","ხ":"kh","ჯ":"j","ჰ":"h","Ẁ":"W","ẁ":"w","Ẃ":"W","ẃ":"w","Ẅ":"W","ẅ":"w","ẞ":"SS","Ạ":"A","ạ":"a","Ả":"A","ả":"a","Ấ":"A","ấ":"a","Ầ":"A","ầ":"a","Ẩ":"A","ẩ":"a","Ẫ":"A","ẫ":"a","Ậ":"A","ậ":"a","Ắ":"A","ắ":"a","Ằ":"A","ằ":"a","Ẳ":"A","ẳ":"a","Ẵ":"A","ẵ":"a","Ặ":"A","ặ":"a","Ẹ":"E","ẹ":"e","Ẻ":"E","ẻ":"e","Ẽ":"E","ẽ":"e","Ế":"E","ế":"e","Ề":"E","ề":"e","Ể":"E","ể":"e","Ễ":"E","ễ":"e","Ệ":"E","ệ":"e","Ỉ":"I","ỉ":"i","Ị":"I","ị":"i","Ọ":"O","ọ":"o","Ỏ":"O","ỏ":"o","Ố":"O","ố":"o","Ồ":"O","ồ":"o","Ổ":"O","ổ":"o","Ỗ":"O","ỗ":"o","Ộ":"O","ộ":"o","Ớ":"O","ớ":"o","Ờ":"O","ờ":"o","Ở":"O","ở":"o","Ỡ":"O","ỡ":"o","Ợ":"O","ợ":"o","Ụ":"U","ụ":"u","Ủ":"U","ủ":"u","Ứ":"U","ứ":"u","Ừ":"U","ừ":"u","Ử":"U","ử":"u","Ữ":"U","ữ":"u","Ự":"U","ự":"u","Ỳ":"Y","ỳ":"y","Ỵ":"Y","ỵ":"y","Ỷ":"Y","ỷ":"y","Ỹ":"Y","ỹ":"y","‘":"\'","’":"\'","“":"\\"","”":"\\"","†":"+","•":"*","…":"...","₠":"ecu","₢":"cruzeiro","₣":"french franc","₤":"lira","₥":"mill","₦":"naira","₧":"peseta","₨":"rupee","₩":"won","₪":"new shequel","₫":"dong","€":"euro","₭":"kip","₮":"tugrik","₯":"drachma","₰":"penny","₱":"peso","₲":"guarani","₳":"austral","₴":"hryvnia","₵":"cedi","₸":"kazakhstani tenge","₹":"indian rupee","₽":"russian ruble","₿":"bitcoin","℠":"sm","™":"tm","∂":"d","∆":"delta","∑":"sum","∞":"infinity","♥":"love","元":"yuan","円":"yen","﷼":"rial"}'),e=JSON.parse('{"vi":{"Đ":"D","đ":"d"}}');function n(n,o){if("string"!=typeof n)throw new Error("slugify: string argument expected");var r=e[(o="string"==typeof o?{replacement:o}:o||{}).locale]||{},i=o.replacement||"-",a=n.split("").reduce((function(e,n){return e+(r[n]||t[n]||n)}),"").replace(o.remove||/[^\w\s$*_+~.()'"!\-:@]+/g,"").trim().replace(new RegExp("[\\s"+i+"]+","g"),i);return o.lower&&(a=a.toLowerCase()),o.strict&&(a=a.replace(new RegExp("[^a-zA-Z0-9"+i+"]","g"),"")),a}return n.extend=function(e){for(var n in e)t[n]=e[n]},n},t.exports=o(),t.exports.default=o()},function(t,e,n){"use strict";n.r(e);var o=n(0),r=n.n(o);function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],o=!0,r=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(o=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);o=!0);}catch(t){r=!0,i=t}finally{try{o||null==u.return||u.return()}finally{if(r)throw i}}return n}(t,e)||a(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[e++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,r,i=!0,u=!1;return{s:function(){o=t[Symbol.iterator]()},n:function(){var t=o.next();return i=t.done,t},e:function(t){u=!0,r=t},f:function(){try{i||null==o.return||o.return()}finally{if(u)throw r}}}}(u.entries());try{for(s.s();!(o=s.n()).done;){var f=i(o.value,2),p=f[0],d=f[1];if(d.getType().includes("header")){var y=O.createEmpty(p);if(d.getData().get("anchor"))continue;var h=new Map;h.set("id",r()(d.getText().toLowerCase())),n=S.mergeBlockData(n,y,h)}}}catch(t){s.e(t)}finally{s.f()}return l=C.push(t,n,t.getLastChangeType()),l=C.acceptSelection(l,c)}},I.push(_)}]); \ No newline at end of file +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __webpack_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __webpack_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __webpack_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./node_modules/slugify/slugify.js": +/*!*****************************************!*\ + !*** ./node_modules/slugify/slugify.js ***! + \*****************************************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +eval("\n;(function (name, root, factory) {\n if (true) {\n module.exports = factory()\n module.exports['default'] = factory()\n }\n /* istanbul ignore next */\n else {}\n}('slugify', this, function () {\n var charMap = JSON.parse('{\"$\":\"dollar\",\"%\":\"percent\",\"&\":\"and\",\"<\":\"less\",\">\":\"greater\",\"|\":\"or\",\"¢\":\"cent\",\"£\":\"pound\",\"¤\":\"currency\",\"¥\":\"yen\",\"©\":\"(c)\",\"ª\":\"a\",\"®\":\"(r)\",\"º\":\"o\",\"À\":\"A\",\"Á\":\"A\",\"Â\":\"A\",\"Ã\":\"A\",\"Ä\":\"A\",\"Å\":\"A\",\"Æ\":\"AE\",\"Ç\":\"C\",\"È\":\"E\",\"É\":\"E\",\"Ê\":\"E\",\"Ë\":\"E\",\"Ì\":\"I\",\"Í\":\"I\",\"Î\":\"I\",\"Ï\":\"I\",\"Ð\":\"D\",\"Ñ\":\"N\",\"Ò\":\"O\",\"Ó\":\"O\",\"Ô\":\"O\",\"Õ\":\"O\",\"Ö\":\"O\",\"Ø\":\"O\",\"Ù\":\"U\",\"Ú\":\"U\",\"Û\":\"U\",\"Ü\":\"U\",\"Ý\":\"Y\",\"Þ\":\"TH\",\"ß\":\"ss\",\"à\":\"a\",\"á\":\"a\",\"â\":\"a\",\"ã\":\"a\",\"ä\":\"a\",\"å\":\"a\",\"æ\":\"ae\",\"ç\":\"c\",\"è\":\"e\",\"é\":\"e\",\"ê\":\"e\",\"ë\":\"e\",\"ì\":\"i\",\"í\":\"i\",\"î\":\"i\",\"ï\":\"i\",\"ð\":\"d\",\"ñ\":\"n\",\"ò\":\"o\",\"ó\":\"o\",\"ô\":\"o\",\"õ\":\"o\",\"ö\":\"o\",\"ø\":\"o\",\"ù\":\"u\",\"ú\":\"u\",\"û\":\"u\",\"ü\":\"u\",\"ý\":\"y\",\"þ\":\"th\",\"ÿ\":\"y\",\"Ā\":\"A\",\"ā\":\"a\",\"Ă\":\"A\",\"ă\":\"a\",\"Ą\":\"A\",\"ą\":\"a\",\"Ć\":\"C\",\"ć\":\"c\",\"Č\":\"C\",\"č\":\"c\",\"Ď\":\"D\",\"ď\":\"d\",\"Đ\":\"DJ\",\"đ\":\"dj\",\"Ē\":\"E\",\"ē\":\"e\",\"Ė\":\"E\",\"ė\":\"e\",\"Ę\":\"e\",\"ę\":\"e\",\"Ě\":\"E\",\"ě\":\"e\",\"Ğ\":\"G\",\"ğ\":\"g\",\"Ģ\":\"G\",\"ģ\":\"g\",\"Ĩ\":\"I\",\"ĩ\":\"i\",\"Ī\":\"i\",\"ī\":\"i\",\"Į\":\"I\",\"į\":\"i\",\"İ\":\"I\",\"ı\":\"i\",\"Ķ\":\"k\",\"ķ\":\"k\",\"Ļ\":\"L\",\"ļ\":\"l\",\"Ľ\":\"L\",\"ľ\":\"l\",\"Ł\":\"L\",\"ł\":\"l\",\"Ń\":\"N\",\"ń\":\"n\",\"Ņ\":\"N\",\"ņ\":\"n\",\"Ň\":\"N\",\"ň\":\"n\",\"Ő\":\"O\",\"ő\":\"o\",\"Œ\":\"OE\",\"œ\":\"oe\",\"Ŕ\":\"R\",\"ŕ\":\"r\",\"Ř\":\"R\",\"ř\":\"r\",\"Ś\":\"S\",\"ś\":\"s\",\"Ş\":\"S\",\"ş\":\"s\",\"Š\":\"S\",\"š\":\"s\",\"Ţ\":\"T\",\"ţ\":\"t\",\"Ť\":\"T\",\"ť\":\"t\",\"Ũ\":\"U\",\"ũ\":\"u\",\"Ū\":\"u\",\"ū\":\"u\",\"Ů\":\"U\",\"ů\":\"u\",\"Ű\":\"U\",\"ű\":\"u\",\"Ų\":\"U\",\"ų\":\"u\",\"Ŵ\":\"W\",\"ŵ\":\"w\",\"Ŷ\":\"Y\",\"ŷ\":\"y\",\"Ÿ\":\"Y\",\"Ź\":\"Z\",\"ź\":\"z\",\"Ż\":\"Z\",\"ż\":\"z\",\"Ž\":\"Z\",\"ž\":\"z\",\"ƒ\":\"f\",\"Ơ\":\"O\",\"ơ\":\"o\",\"Ư\":\"U\",\"ư\":\"u\",\"Lj\":\"LJ\",\"lj\":\"lj\",\"Nj\":\"NJ\",\"nj\":\"nj\",\"Ș\":\"S\",\"ș\":\"s\",\"Ț\":\"T\",\"ț\":\"t\",\"˚\":\"o\",\"Ά\":\"A\",\"Έ\":\"E\",\"Ή\":\"H\",\"Ί\":\"I\",\"Ό\":\"O\",\"Ύ\":\"Y\",\"Ώ\":\"W\",\"ΐ\":\"i\",\"Α\":\"A\",\"Β\":\"B\",\"Γ\":\"G\",\"Δ\":\"D\",\"Ε\":\"E\",\"Ζ\":\"Z\",\"Η\":\"H\",\"Θ\":\"8\",\"Ι\":\"I\",\"Κ\":\"K\",\"Λ\":\"L\",\"Μ\":\"M\",\"Ν\":\"N\",\"Ξ\":\"3\",\"Ο\":\"O\",\"Π\":\"P\",\"Ρ\":\"R\",\"Σ\":\"S\",\"Τ\":\"T\",\"Υ\":\"Y\",\"Φ\":\"F\",\"Χ\":\"X\",\"Ψ\":\"PS\",\"Ω\":\"W\",\"Ϊ\":\"I\",\"Ϋ\":\"Y\",\"ά\":\"a\",\"έ\":\"e\",\"ή\":\"h\",\"ί\":\"i\",\"ΰ\":\"y\",\"α\":\"a\",\"β\":\"b\",\"γ\":\"g\",\"δ\":\"d\",\"ε\":\"e\",\"ζ\":\"z\",\"η\":\"h\",\"θ\":\"8\",\"ι\":\"i\",\"κ\":\"k\",\"λ\":\"l\",\"μ\":\"m\",\"ν\":\"n\",\"ξ\":\"3\",\"ο\":\"o\",\"π\":\"p\",\"ρ\":\"r\",\"ς\":\"s\",\"σ\":\"s\",\"τ\":\"t\",\"υ\":\"y\",\"φ\":\"f\",\"χ\":\"x\",\"ψ\":\"ps\",\"ω\":\"w\",\"ϊ\":\"i\",\"ϋ\":\"y\",\"ό\":\"o\",\"ύ\":\"y\",\"ώ\":\"w\",\"Ё\":\"Yo\",\"Ђ\":\"DJ\",\"Є\":\"Ye\",\"І\":\"I\",\"Ї\":\"Yi\",\"Ј\":\"J\",\"Љ\":\"LJ\",\"Њ\":\"NJ\",\"Ћ\":\"C\",\"Џ\":\"DZ\",\"А\":\"A\",\"Б\":\"B\",\"В\":\"V\",\"Г\":\"G\",\"Д\":\"D\",\"Е\":\"E\",\"Ж\":\"Zh\",\"З\":\"Z\",\"И\":\"I\",\"Й\":\"J\",\"К\":\"K\",\"Л\":\"L\",\"М\":\"M\",\"Н\":\"N\",\"О\":\"O\",\"П\":\"P\",\"Р\":\"R\",\"С\":\"S\",\"Т\":\"T\",\"У\":\"U\",\"Ф\":\"F\",\"Х\":\"H\",\"Ц\":\"C\",\"Ч\":\"Ch\",\"Ш\":\"Sh\",\"Щ\":\"Sh\",\"Ъ\":\"U\",\"Ы\":\"Y\",\"Ь\":\"\",\"Э\":\"E\",\"Ю\":\"Yu\",\"Я\":\"Ya\",\"а\":\"a\",\"б\":\"b\",\"в\":\"v\",\"г\":\"g\",\"д\":\"d\",\"е\":\"e\",\"ж\":\"zh\",\"з\":\"z\",\"и\":\"i\",\"й\":\"j\",\"к\":\"k\",\"л\":\"l\",\"м\":\"m\",\"н\":\"n\",\"о\":\"o\",\"п\":\"p\",\"р\":\"r\",\"с\":\"s\",\"т\":\"t\",\"у\":\"u\",\"ф\":\"f\",\"х\":\"h\",\"ц\":\"c\",\"ч\":\"ch\",\"ш\":\"sh\",\"щ\":\"sh\",\"ъ\":\"u\",\"ы\":\"y\",\"ь\":\"\",\"э\":\"e\",\"ю\":\"yu\",\"я\":\"ya\",\"ё\":\"yo\",\"ђ\":\"dj\",\"є\":\"ye\",\"і\":\"i\",\"ї\":\"yi\",\"ј\":\"j\",\"љ\":\"lj\",\"њ\":\"nj\",\"ћ\":\"c\",\"ѝ\":\"u\",\"џ\":\"dz\",\"Ґ\":\"G\",\"ґ\":\"g\",\"Ғ\":\"GH\",\"ғ\":\"gh\",\"Қ\":\"KH\",\"қ\":\"kh\",\"Ң\":\"NG\",\"ң\":\"ng\",\"Ү\":\"UE\",\"ү\":\"ue\",\"Ұ\":\"U\",\"ұ\":\"u\",\"Һ\":\"H\",\"һ\":\"h\",\"Ә\":\"AE\",\"ә\":\"ae\",\"Ө\":\"OE\",\"ө\":\"oe\",\"฿\":\"baht\",\"ა\":\"a\",\"ბ\":\"b\",\"გ\":\"g\",\"დ\":\"d\",\"ე\":\"e\",\"ვ\":\"v\",\"ზ\":\"z\",\"თ\":\"t\",\"ი\":\"i\",\"კ\":\"k\",\"ლ\":\"l\",\"მ\":\"m\",\"ნ\":\"n\",\"ო\":\"o\",\"პ\":\"p\",\"ჟ\":\"zh\",\"რ\":\"r\",\"ს\":\"s\",\"ტ\":\"t\",\"უ\":\"u\",\"ფ\":\"f\",\"ქ\":\"k\",\"ღ\":\"gh\",\"ყ\":\"q\",\"შ\":\"sh\",\"ჩ\":\"ch\",\"ც\":\"ts\",\"ძ\":\"dz\",\"წ\":\"ts\",\"ჭ\":\"ch\",\"ხ\":\"kh\",\"ჯ\":\"j\",\"ჰ\":\"h\",\"Ẁ\":\"W\",\"ẁ\":\"w\",\"Ẃ\":\"W\",\"ẃ\":\"w\",\"Ẅ\":\"W\",\"ẅ\":\"w\",\"ẞ\":\"SS\",\"Ạ\":\"A\",\"ạ\":\"a\",\"Ả\":\"A\",\"ả\":\"a\",\"Ấ\":\"A\",\"ấ\":\"a\",\"Ầ\":\"A\",\"ầ\":\"a\",\"Ẩ\":\"A\",\"ẩ\":\"a\",\"Ẫ\":\"A\",\"ẫ\":\"a\",\"Ậ\":\"A\",\"ậ\":\"a\",\"Ắ\":\"A\",\"ắ\":\"a\",\"Ằ\":\"A\",\"ằ\":\"a\",\"Ẳ\":\"A\",\"ẳ\":\"a\",\"Ẵ\":\"A\",\"ẵ\":\"a\",\"Ặ\":\"A\",\"ặ\":\"a\",\"Ẹ\":\"E\",\"ẹ\":\"e\",\"Ẻ\":\"E\",\"ẻ\":\"e\",\"Ẽ\":\"E\",\"ẽ\":\"e\",\"Ế\":\"E\",\"ế\":\"e\",\"Ề\":\"E\",\"ề\":\"e\",\"Ể\":\"E\",\"ể\":\"e\",\"Ễ\":\"E\",\"ễ\":\"e\",\"Ệ\":\"E\",\"ệ\":\"e\",\"Ỉ\":\"I\",\"ỉ\":\"i\",\"Ị\":\"I\",\"ị\":\"i\",\"Ọ\":\"O\",\"ọ\":\"o\",\"Ỏ\":\"O\",\"ỏ\":\"o\",\"Ố\":\"O\",\"ố\":\"o\",\"Ồ\":\"O\",\"ồ\":\"o\",\"Ổ\":\"O\",\"ổ\":\"o\",\"Ỗ\":\"O\",\"ỗ\":\"o\",\"Ộ\":\"O\",\"ộ\":\"o\",\"Ớ\":\"O\",\"ớ\":\"o\",\"Ờ\":\"O\",\"ờ\":\"o\",\"Ở\":\"O\",\"ở\":\"o\",\"Ỡ\":\"O\",\"ỡ\":\"o\",\"Ợ\":\"O\",\"ợ\":\"o\",\"Ụ\":\"U\",\"ụ\":\"u\",\"Ủ\":\"U\",\"ủ\":\"u\",\"Ứ\":\"U\",\"ứ\":\"u\",\"Ừ\":\"U\",\"ừ\":\"u\",\"Ử\":\"U\",\"ử\":\"u\",\"Ữ\":\"U\",\"ữ\":\"u\",\"Ự\":\"U\",\"ự\":\"u\",\"Ỳ\":\"Y\",\"ỳ\":\"y\",\"Ỵ\":\"Y\",\"ỵ\":\"y\",\"Ỷ\":\"Y\",\"ỷ\":\"y\",\"Ỹ\":\"Y\",\"ỹ\":\"y\",\"‘\":\"\\'\",\"’\":\"\\'\",\"“\":\"\\\\\\\"\",\"”\":\"\\\\\\\"\",\"†\":\"+\",\"•\":\"*\",\"…\":\"...\",\"₠\":\"ecu\",\"₢\":\"cruzeiro\",\"₣\":\"french franc\",\"₤\":\"lira\",\"₥\":\"mill\",\"₦\":\"naira\",\"₧\":\"peseta\",\"₨\":\"rupee\",\"₩\":\"won\",\"₪\":\"new shequel\",\"₫\":\"dong\",\"€\":\"euro\",\"₭\":\"kip\",\"₮\":\"tugrik\",\"₯\":\"drachma\",\"₰\":\"penny\",\"₱\":\"peso\",\"₲\":\"guarani\",\"₳\":\"austral\",\"₴\":\"hryvnia\",\"₵\":\"cedi\",\"₸\":\"kazakhstani tenge\",\"₹\":\"indian rupee\",\"₽\":\"russian ruble\",\"₿\":\"bitcoin\",\"℠\":\"sm\",\"™\":\"tm\",\"∂\":\"d\",\"∆\":\"delta\",\"∑\":\"sum\",\"∞\":\"infinity\",\"♥\":\"love\",\"元\":\"yuan\",\"円\":\"yen\",\"﷼\":\"rial\"}')\n var locales = JSON.parse('{\"vi\":{\"Đ\":\"D\",\"đ\":\"d\"}}')\n\n function replace (string, options) {\n if (typeof string !== 'string') {\n throw new Error('slugify: string argument expected')\n }\n\n options = (typeof options === 'string')\n ? {replacement: options}\n : options || {}\n\n var locale = locales[options.locale] || {}\n\n var replacement = options.replacement || '-'\n\n var slug = string.split('')\n // replace characters based on charMap\n .reduce(function (result, ch) {\n return result + (locale[ch] || charMap[ch] || ch)\n }, '')\n // remove not allowed characters\n .replace(options.remove || /[^\\w\\s$*_+~.()'\"!\\-:@]+/g, '')\n // trim leading/trailing spaces\n .trim()\n // convert spaces to replacement character\n // also remove duplicates of the replacement character\n .replace(new RegExp('[\\\\s' + replacement + ']+', 'g'), replacement)\n\n if (options.lower) {\n slug = slug.toLowerCase()\n }\n\n if (options.strict) {\n // remove anything besides letters, numbers, and the replacement char\n slug = slug\n .replace(new RegExp('[^a-zA-Z0-9' + replacement + ']', 'g'), '')\n }\n\n return slug\n }\n\n replace.extend = function (customMap) {\n for (var key in customMap) {\n charMap[key] = customMap[key]\n }\n }\n\n return replace\n}))\n\n\n//# sourceURL=webpack:///./node_modules/slugify/slugify.js?"); + +/***/ }), + +/***/ "./static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js": +/*!*************************************************************************!*\ + !*** ./static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js ***! + \*************************************************************************/ +/*! no exports provided */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var slugify__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! slugify */ \"./node_modules/slugify/slugify.js\");\n/* harmony import */ var slugify__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(slugify__WEBPACK_IMPORTED_MODULE_0__);\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _iterableToArrayLimit(arr, i) { if (typeof Symbol === \"undefined\" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nfunction _createForOfIteratorHelper(o) { if (typeof Symbol === \"undefined\" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(n); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nvar React = window.React;\nvar RichUtils = window.DraftJS.RichUtils;\nvar Modifier = window.DraftJS.Modifier;\nvar SelectionState = window.DraftJS.SelectionState;\nvar TooltipEntity = window.draftail.TooltipEntity;\nvar Icon = window.wagtail.components.Icon;\nvar EditorState = window.DraftJS.EditorState;\nvar Portal = window.wagtail.components.Portal;\nvar Tooltip = window.draftail.Tooltip;\n // Implement the new APIs.\n\nvar DECORATORS = [];\nvar CONTROLS = [];\nvar DRAFT_PLUGINS = [];\n\nvar registerDecorator = function registerDecorator(decorator) {\n DECORATORS.push(decorator);\n return DECORATORS;\n};\n\nvar registerControl = function registerControl(control) {\n CONTROLS.push(control);\n return CONTROLS;\n};\n\nvar registerDraftPlugin = function registerDraftPlugin(plugin) {\n DRAFT_PLUGINS.push(plugin);\n return DRAFT_PLUGINS;\n}; // Override the existing initEditor to hook the new APIs into it.\n// This works in Wagtail 2.0 but will definitely break in a future release.\n\n\nvar initEditor = window.draftail.initEditor;\n\nvar initEditorOverride = function initEditorOverride(selector, options, currentScript) {\n var overrides = {\n decorators: DECORATORS.concat(options.decorators || []),\n controls: CONTROLS.concat(options.controls || []),\n plugins: DRAFT_PLUGINS.concat(options.plugins || [])\n };\n var newOptions = Object.assign({}, options, overrides);\n return initEditor(selector, newOptions, currentScript);\n};\n\nwindow.draftail.registerControl = registerControl;\nwindow.draftail.registerDecorator = registerDecorator;\nwindow.draftail.initEditor = initEditorOverride;\n\nvar AnchorIdentifierSource = /*#__PURE__*/function (_React$Component) {\n _inherits(AnchorIdentifierSource, _React$Component);\n\n var _super = _createSuper(AnchorIdentifierSource);\n\n function AnchorIdentifierSource() {\n _classCallCheck(this, AnchorIdentifierSource);\n\n return _super.apply(this, arguments);\n }\n\n _createClass(AnchorIdentifierSource, [{\n key: \"componentDidMount\",\n value: function componentDidMount() {\n var _this$props = this.props,\n editorState = _this$props.editorState,\n entityType = _this$props.entityType,\n onComplete = _this$props.onComplete,\n entity = _this$props.entity;\n var content = editorState.getCurrentContent();\n var anchor_id = \"\";\n\n if (entity) {\n anchor_id = entity.data.anchor;\n }\n\n var anchor = window.prompt(\"Anchor identifier:\", anchor_id); // Uses the Draft.js API to create a new entity with the right data.\n\n if (anchor) {\n var contentWithEntity = content.createEntity(entityType.type, \"MUTABLE\", {\n anchor: slugify__WEBPACK_IMPORTED_MODULE_0___default()(anchor.toLowerCase())\n });\n var entityKey = contentWithEntity.getLastCreatedEntityKey();\n var selection = editorState.getSelection();\n var nextState = RichUtils.toggleLink(editorState, selection, entityKey);\n onComplete(nextState);\n } else {\n onComplete(editorState);\n }\n }\n }, {\n key: \"render\",\n value: function render() {\n return null;\n }\n }]);\n\n return AnchorIdentifierSource;\n}(React.Component);\n\nvar getAnchorIdentifierAttributes = function getAnchorIdentifierAttributes(data) {\n var url = data.anchor || null;\n var icon = /*#__PURE__*/React.createElement(Icon, {\n name: \"anchor\"\n });\n var label = \"#\".concat(url);\n return {\n url: url,\n icon: icon,\n label: label\n };\n};\n\nvar AnchorIdentifier = function AnchorIdentifier(props) {\n var entityKey = props.entityKey,\n contentState = props.contentState;\n var data = contentState.getEntity(entityKey).getData();\n return /*#__PURE__*/React.createElement(TooltipEntity, _extends({}, props, getAnchorIdentifierAttributes(data)));\n};\n\nwindow.draftail.registerPlugin({\n type: \"ANCHOR-IDENTIFIER\",\n source: AnchorIdentifierSource,\n decorator: AnchorIdentifier\n});\n\nvar HeaderAnchorDecorator = /*#__PURE__*/function (_React$Component2) {\n _inherits(HeaderAnchorDecorator, _React$Component2);\n\n var _super2 = _createSuper(HeaderAnchorDecorator);\n\n function HeaderAnchorDecorator(props) {\n var _this;\n\n _classCallCheck(this, HeaderAnchorDecorator);\n\n _this = _super2.call(this, props);\n _this.state = {\n showTooltipAt: null\n };\n _this.onEdit = _this.onEdit.bind(_assertThisInitialized(_this));\n _this.onRemove = _this.onRemove.bind(_assertThisInitialized(_this));\n _this.openTooltip = _this.openTooltip.bind(_assertThisInitialized(_this));\n _this.closeTooltip = _this.closeTooltip.bind(_assertThisInitialized(_this));\n return _this;\n }\n\n _createClass(HeaderAnchorDecorator, [{\n key: \"openTooltip\",\n value: function openTooltip(e) {\n var trigger = e.target.closest(\"[data-draftail-trigger]\"); // Click is within the tooltip.\n\n if (!trigger) {\n return;\n }\n\n var container = trigger.closest(\"[data-draftail-editor-wrapper]\");\n var containerRect = container.getBoundingClientRect();\n var rect = trigger.getBoundingClientRect();\n this.setState({\n showTooltipAt: {\n container: container,\n top: rect.top - containerRect.top - (document.documentElement.scrollTop || document.body.scrollTop),\n left: rect.left - containerRect.left - (document.documentElement.scrollLeft || document.body.scrollLeft),\n width: rect.width,\n height: rect.height\n }\n });\n }\n }, {\n key: \"closeTooltip\",\n value: function closeTooltip() {\n this.setState({\n showTooltipAt: null\n });\n }\n }, {\n key: \"getBlock\",\n value: function getBlock(editorState) {\n var block_key = editorState.getSelection().getFocusKey();\n return this.props.contentState.getBlockForKey(block_key);\n }\n }, {\n key: \"getData\",\n value: function getData(editorState) {\n var block = this.getBlock(editorState);\n return block.getData();\n }\n }, {\n key: \"setAnchor\",\n value: function setAnchor(anchor) {\n var editorState = this.props.getEditorState();\n var newEditorState = editorState;\n var newData = new Map();\n newData.set(\"anchor\", anchor);\n var content = editorState.getCurrentContent();\n var selection = editorState.getSelection();\n content = Modifier.mergeBlockData(content, selection, newData);\n newEditorState = EditorState.push(editorState, content, editorState.getLastChangeType());\n newEditorState = EditorState.acceptSelection(newEditorState, selection);\n this.props.setEditorState(newEditorState);\n }\n }, {\n key: \"onRemove\",\n value: function onRemove(e) {\n e.preventDefault();\n e.stopPropagation();\n var editorState = this.props.getEditorState();\n var block = this.getBlock(editorState);\n var anchor = slugify__WEBPACK_IMPORTED_MODULE_0___default()(block.getText().toLowerCase());\n this.setAnchor(null);\n }\n }, {\n key: \"onEdit\",\n value: function onEdit(e) {\n e.preventDefault();\n e.stopPropagation();\n var editorState = this.props.getEditorState();\n var block = this.getBlock(editorState);\n var data = this.getData(editorState);\n var anchor = window.prompt('Anchor Link:', data.get(\"anchor\") || data.get(\"id\") || slugify__WEBPACK_IMPORTED_MODULE_0___default()(block.getText().toLowerCase()));\n this.setAnchor(anchor);\n }\n }, {\n key: \"render\",\n value: function render() {\n var children = this.props.children;\n var showTooltipAt = this.state.showTooltipAt;\n var editorState = this.props.getEditorState();\n var data = this.getData(editorState);\n var block = this.getBlock(editorState); // try to get custom anchor first, then id and only then build it from the text\n\n var anchor = data.get(\"anchor\") || data.get(\"id\") || slugify__WEBPACK_IMPORTED_MODULE_0___default()(block.getText().toLowerCase());\n var url = \"#\".concat(anchor); // Contrary to what JSX A11Y says, this should be a button but it shouldn't be focusable.\n\n /* eslint-disable springload/jsx-a11y/interactive-supports-focus */\n\n return /*#__PURE__*/React.createElement(\"a\", {\n href: \"\",\n role: \"button\" // Use onMouseUp to preserve focus in the text even after clicking.\n ,\n onMouseUp: this.openTooltip,\n className: \"TooltipEntity\",\n \"data-draftail-trigger\": true\n }, children, showTooltipAt && /*#__PURE__*/React.createElement(Portal, {\n node: showTooltipAt.container,\n onClose: this.closeTooltip,\n closeOnClick: true,\n closeOnType: true,\n closeOnResize: true\n }, /*#__PURE__*/React.createElement(Tooltip, {\n target: showTooltipAt,\n direction: \"top\"\n }, /*#__PURE__*/React.createElement(\"span\", {\n className: \"Tooltip__link\"\n }, url), /*#__PURE__*/React.createElement(\"button\", {\n className: \"button Tooltip__button\",\n onClick: this.onEdit\n }, \"Edit\"), /*#__PURE__*/React.createElement(\"button\", {\n className: \"button button-secondary no Tooltip__button\",\n onClick: this.onRemove\n }, \"Reset\"))));\n }\n }]);\n\n return HeaderAnchorDecorator;\n}(React.Component);\n\nfunction headingStrategy(contentBlock, callback, contentState) {\n if (contentBlock.getType().includes(\"header\")) {\n callback(0, contentBlock.getLength());\n }\n}\n\nregisterDraftPlugin({\n decorators: [{\n strategy: headingStrategy,\n component: HeaderAnchorDecorator\n }],\n onChange: function onChange(editorState, PluginFunctions) {\n // if content has been modified, update all heading blocks's data with\n // a slugified version of their contents as 'anchor', for use\n // in generating anchor links consistently with their displayed form\n var content = editorState.getCurrentContent();\n\n if (content == PluginFunctions.getEditorState().getCurrentContent()) {\n return editorState;\n }\n\n var blocks = content.getBlockMap();\n var selection = editorState.getSelection();\n var newEditorState = editorState;\n\n var _iterator = _createForOfIteratorHelper(blocks.entries()),\n _step;\n\n try {\n for (_iterator.s(); !(_step = _iterator.n()).done;) {\n var _step$value = _slicedToArray(_step.value, 2),\n key = _step$value[0],\n block = _step$value[1];\n\n if (block.getType().includes(\"header\")) {\n var blockSelection = SelectionState.createEmpty(key);\n var data = block.getData(); // do not change if there is a custom anchor\n\n if (data.get(\"anchor\")) {\n continue;\n }\n\n var newData = new Map();\n newData.set(\"id\", slugify__WEBPACK_IMPORTED_MODULE_0___default()(block.getText().toLowerCase()));\n content = Modifier.mergeBlockData(content, blockSelection, newData);\n }\n }\n } catch (err) {\n _iterator.e(err);\n } finally {\n _iterator.f();\n }\n\n newEditorState = EditorState.push(editorState, content, editorState.getLastChangeType());\n newEditorState = EditorState.acceptSelection(newEditorState, selection);\n return newEditorState;\n }\n});\n\n//# sourceURL=webpack:///./static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js?"); + +/***/ }) + +/******/ }); \ No newline at end of file diff --git a/wagtail_draftail_anchors/static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js b/wagtail_draftail_anchors/static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js index 92feae1..3306f1a 100644 --- a/wagtail_draftail_anchors/static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js +++ b/wagtail_draftail_anchors/static_src/wagtaildraftailanchors/js/wagtail_draftail_anchor.js @@ -167,23 +167,8 @@ class HeaderAnchorDecorator extends React.Component { return block.getData(); } - onRemove(e) { - e.preventDefault(); - e.stopPropagation(); - this.setState({ showTooltipAt: null }); - } - - onEdit(e) { - e.preventDefault(); - e.stopPropagation(); - + setAnchor(anchor) { const editorState = this.props.getEditorState(); - const data = this.getData(editorState); - const block = this.getBlock(editorState); - const anchor = window.prompt('Anchor Link:', data.get("anchor") || data.get("id") || slugify(block.getText().toLowerCase())); - - this.setState({ showTooltipAt: null }); - let newEditorState = editorState; let newData = new Map(); @@ -202,6 +187,29 @@ class HeaderAnchorDecorator extends React.Component { this.props.setEditorState(newEditorState); } + onRemove(e) { + e.preventDefault(); + e.stopPropagation(); + + const editorState = this.props.getEditorState(); + const block = this.getBlock(editorState); + + const anchor = slugify(block.getText().toLowerCase()); + this.setAnchor(null); + } + + onEdit(e) { + e.preventDefault(); + e.stopPropagation(); + + const editorState = this.props.getEditorState(); + const block = this.getBlock(editorState); + + const data = this.getData(editorState); + const anchor = window.prompt('Anchor Link:', data.get("anchor") || data.get("id") || slugify(block.getText().toLowerCase())); + this.setAnchor(anchor); + } + render() { const children = this.props.children; @@ -249,7 +257,7 @@ class HeaderAnchorDecorator extends React.Component { className="button button-secondary no Tooltip__button" onClick={this.onRemove} > - Cancel + Reset