Nenhuma Descrição

rich-text.js 134KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840
  1. this["wp"] = this["wp"] || {}; this["wp"]["richText"] =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = "yyEc");
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ "1ZqX":
  90. /***/ (function(module, exports) {
  91. (function() { module.exports = window["wp"]["data"]; }());
  92. /***/ }),
  93. /***/ "GRId":
  94. /***/ (function(module, exports) {
  95. (function() { module.exports = window["wp"]["element"]; }());
  96. /***/ }),
  97. /***/ "K9lf":
  98. /***/ (function(module, exports) {
  99. (function() { module.exports = window["wp"]["compose"]; }());
  100. /***/ }),
  101. /***/ "RxS6":
  102. /***/ (function(module, exports) {
  103. (function() { module.exports = window["wp"]["keycodes"]; }());
  104. /***/ }),
  105. /***/ "Vx3V":
  106. /***/ (function(module, exports) {
  107. (function() { module.exports = window["wp"]["escapeHtml"]; }());
  108. /***/ }),
  109. /***/ "YLtl":
  110. /***/ (function(module, exports) {
  111. (function() { module.exports = window["lodash"]; }());
  112. /***/ }),
  113. /***/ "pPDe":
  114. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  115. "use strict";
  116. var LEAF_KEY, hasWeakMap;
  117. /**
  118. * Arbitrary value used as key for referencing cache object in WeakMap tree.
  119. *
  120. * @type {Object}
  121. */
  122. LEAF_KEY = {};
  123. /**
  124. * Whether environment supports WeakMap.
  125. *
  126. * @type {boolean}
  127. */
  128. hasWeakMap = typeof WeakMap !== 'undefined';
  129. /**
  130. * Returns the first argument as the sole entry in an array.
  131. *
  132. * @param {*} value Value to return.
  133. *
  134. * @return {Array} Value returned as entry in array.
  135. */
  136. function arrayOf( value ) {
  137. return [ value ];
  138. }
  139. /**
  140. * Returns true if the value passed is object-like, or false otherwise. A value
  141. * is object-like if it can support property assignment, e.g. object or array.
  142. *
  143. * @param {*} value Value to test.
  144. *
  145. * @return {boolean} Whether value is object-like.
  146. */
  147. function isObjectLike( value ) {
  148. return !! value && 'object' === typeof value;
  149. }
  150. /**
  151. * Creates and returns a new cache object.
  152. *
  153. * @return {Object} Cache object.
  154. */
  155. function createCache() {
  156. var cache = {
  157. clear: function() {
  158. cache.head = null;
  159. },
  160. };
  161. return cache;
  162. }
  163. /**
  164. * Returns true if entries within the two arrays are strictly equal by
  165. * reference from a starting index.
  166. *
  167. * @param {Array} a First array.
  168. * @param {Array} b Second array.
  169. * @param {number} fromIndex Index from which to start comparison.
  170. *
  171. * @return {boolean} Whether arrays are shallowly equal.
  172. */
  173. function isShallowEqual( a, b, fromIndex ) {
  174. var i;
  175. if ( a.length !== b.length ) {
  176. return false;
  177. }
  178. for ( i = fromIndex; i < a.length; i++ ) {
  179. if ( a[ i ] !== b[ i ] ) {
  180. return false;
  181. }
  182. }
  183. return true;
  184. }
  185. /**
  186. * Returns a memoized selector function. The getDependants function argument is
  187. * called before the memoized selector and is expected to return an immutable
  188. * reference or array of references on which the selector depends for computing
  189. * its own return value. The memoize cache is preserved only as long as those
  190. * dependant references remain the same. If getDependants returns a different
  191. * reference(s), the cache is cleared and the selector value regenerated.
  192. *
  193. * @param {Function} selector Selector function.
  194. * @param {Function} getDependants Dependant getter returning an immutable
  195. * reference or array of reference used in
  196. * cache bust consideration.
  197. *
  198. * @return {Function} Memoized selector.
  199. */
  200. /* harmony default export */ __webpack_exports__["a"] = (function( selector, getDependants ) {
  201. var rootCache, getCache;
  202. // Use object source as dependant if getter not provided
  203. if ( ! getDependants ) {
  204. getDependants = arrayOf;
  205. }
  206. /**
  207. * Returns the root cache. If WeakMap is supported, this is assigned to the
  208. * root WeakMap cache set, otherwise it is a shared instance of the default
  209. * cache object.
  210. *
  211. * @return {(WeakMap|Object)} Root cache object.
  212. */
  213. function getRootCache() {
  214. return rootCache;
  215. }
  216. /**
  217. * Returns the cache for a given dependants array. When possible, a WeakMap
  218. * will be used to create a unique cache for each set of dependants. This
  219. * is feasible due to the nature of WeakMap in allowing garbage collection
  220. * to occur on entries where the key object is no longer referenced. Since
  221. * WeakMap requires the key to be an object, this is only possible when the
  222. * dependant is object-like. The root cache is created as a hierarchy where
  223. * each top-level key is the first entry in a dependants set, the value a
  224. * WeakMap where each key is the next dependant, and so on. This continues
  225. * so long as the dependants are object-like. If no dependants are object-
  226. * like, then the cache is shared across all invocations.
  227. *
  228. * @see isObjectLike
  229. *
  230. * @param {Array} dependants Selector dependants.
  231. *
  232. * @return {Object} Cache object.
  233. */
  234. function getWeakMapCache( dependants ) {
  235. var caches = rootCache,
  236. isUniqueByDependants = true,
  237. i, dependant, map, cache;
  238. for ( i = 0; i < dependants.length; i++ ) {
  239. dependant = dependants[ i ];
  240. // Can only compose WeakMap from object-like key.
  241. if ( ! isObjectLike( dependant ) ) {
  242. isUniqueByDependants = false;
  243. break;
  244. }
  245. // Does current segment of cache already have a WeakMap?
  246. if ( caches.has( dependant ) ) {
  247. // Traverse into nested WeakMap.
  248. caches = caches.get( dependant );
  249. } else {
  250. // Create, set, and traverse into a new one.
  251. map = new WeakMap();
  252. caches.set( dependant, map );
  253. caches = map;
  254. }
  255. }
  256. // We use an arbitrary (but consistent) object as key for the last item
  257. // in the WeakMap to serve as our running cache.
  258. if ( ! caches.has( LEAF_KEY ) ) {
  259. cache = createCache();
  260. cache.isUniqueByDependants = isUniqueByDependants;
  261. caches.set( LEAF_KEY, cache );
  262. }
  263. return caches.get( LEAF_KEY );
  264. }
  265. // Assign cache handler by availability of WeakMap
  266. getCache = hasWeakMap ? getWeakMapCache : getRootCache;
  267. /**
  268. * Resets root memoization cache.
  269. */
  270. function clear() {
  271. rootCache = hasWeakMap ? new WeakMap() : createCache();
  272. }
  273. // eslint-disable-next-line jsdoc/check-param-names
  274. /**
  275. * The augmented selector call, considering first whether dependants have
  276. * changed before passing it to underlying memoize function.
  277. *
  278. * @param {Object} source Source object for derivation.
  279. * @param {...*} extraArgs Additional arguments to pass to selector.
  280. *
  281. * @return {*} Selector result.
  282. */
  283. function callSelector( /* source, ...extraArgs */ ) {
  284. var len = arguments.length,
  285. cache, node, i, args, dependants;
  286. // Create copy of arguments (avoid leaking deoptimization).
  287. args = new Array( len );
  288. for ( i = 0; i < len; i++ ) {
  289. args[ i ] = arguments[ i ];
  290. }
  291. dependants = getDependants.apply( null, args );
  292. cache = getCache( dependants );
  293. // If not guaranteed uniqueness by dependants (primitive type or lack
  294. // of WeakMap support), shallow compare against last dependants and, if
  295. // references have changed, destroy cache to recalculate result.
  296. if ( ! cache.isUniqueByDependants ) {
  297. if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) {
  298. cache.clear();
  299. }
  300. cache.lastDependants = dependants;
  301. }
  302. node = cache.head;
  303. while ( node ) {
  304. // Check whether node arguments match arguments
  305. if ( ! isShallowEqual( node.args, args, 1 ) ) {
  306. node = node.next;
  307. continue;
  308. }
  309. // At this point we can assume we've found a match
  310. // Surface matched node to head if not already
  311. if ( node !== cache.head ) {
  312. // Adjust siblings to point to each other.
  313. node.prev.next = node.next;
  314. if ( node.next ) {
  315. node.next.prev = node.prev;
  316. }
  317. node.next = cache.head;
  318. node.prev = null;
  319. cache.head.prev = node;
  320. cache.head = node;
  321. }
  322. // Return immediately
  323. return node.val;
  324. }
  325. // No cached value found. Continue to insertion phase:
  326. node = {
  327. // Generate the result from original function
  328. val: selector.apply( null, args ),
  329. };
  330. // Avoid including the source object in the cache.
  331. args[ 0 ] = null;
  332. node.args = args;
  333. // Don't need to check whether node is already head, since it would
  334. // have been returned above already if it was
  335. // Shift existing head down list
  336. if ( cache.head ) {
  337. cache.head.prev = node;
  338. node.next = cache.head;
  339. }
  340. cache.head = node;
  341. return node.val;
  342. }
  343. callSelector.getDependants = getDependants;
  344. callSelector.clear = clear;
  345. clear();
  346. return callSelector;
  347. });
  348. /***/ }),
  349. /***/ "yyEc":
  350. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  351. "use strict";
  352. // ESM COMPAT FLAG
  353. __webpack_require__.r(__webpack_exports__);
  354. // EXPORTS
  355. __webpack_require__.d(__webpack_exports__, "store", function() { return /* reexport */ store; });
  356. __webpack_require__.d(__webpack_exports__, "applyFormat", function() { return /* reexport */ applyFormat; });
  357. __webpack_require__.d(__webpack_exports__, "concat", function() { return /* reexport */ concat; });
  358. __webpack_require__.d(__webpack_exports__, "create", function() { return /* reexport */ create; });
  359. __webpack_require__.d(__webpack_exports__, "getActiveFormat", function() { return /* reexport */ getActiveFormat; });
  360. __webpack_require__.d(__webpack_exports__, "getActiveObject", function() { return /* reexport */ getActiveObject; });
  361. __webpack_require__.d(__webpack_exports__, "getTextContent", function() { return /* reexport */ getTextContent; });
  362. __webpack_require__.d(__webpack_exports__, "__unstableIsListRootSelected", function() { return /* reexport */ isListRootSelected; });
  363. __webpack_require__.d(__webpack_exports__, "__unstableIsActiveListType", function() { return /* reexport */ isActiveListType; });
  364. __webpack_require__.d(__webpack_exports__, "isCollapsed", function() { return /* reexport */ isCollapsed; });
  365. __webpack_require__.d(__webpack_exports__, "isEmpty", function() { return /* reexport */ isEmpty; });
  366. __webpack_require__.d(__webpack_exports__, "__unstableIsEmptyLine", function() { return /* reexport */ isEmptyLine; });
  367. __webpack_require__.d(__webpack_exports__, "join", function() { return /* reexport */ join; });
  368. __webpack_require__.d(__webpack_exports__, "registerFormatType", function() { return /* reexport */ registerFormatType; });
  369. __webpack_require__.d(__webpack_exports__, "removeFormat", function() { return /* reexport */ removeFormat; });
  370. __webpack_require__.d(__webpack_exports__, "remove", function() { return /* reexport */ remove_remove; });
  371. __webpack_require__.d(__webpack_exports__, "replace", function() { return /* reexport */ replace_replace; });
  372. __webpack_require__.d(__webpack_exports__, "insert", function() { return /* reexport */ insert; });
  373. __webpack_require__.d(__webpack_exports__, "__unstableInsertLineSeparator", function() { return /* reexport */ insertLineSeparator; });
  374. __webpack_require__.d(__webpack_exports__, "__unstableRemoveLineSeparator", function() { return /* reexport */ removeLineSeparator; });
  375. __webpack_require__.d(__webpack_exports__, "insertObject", function() { return /* reexport */ insertObject; });
  376. __webpack_require__.d(__webpack_exports__, "slice", function() { return /* reexport */ slice; });
  377. __webpack_require__.d(__webpack_exports__, "split", function() { return /* reexport */ split; });
  378. __webpack_require__.d(__webpack_exports__, "__unstableToDom", function() { return /* reexport */ toDom; });
  379. __webpack_require__.d(__webpack_exports__, "toHTMLString", function() { return /* reexport */ toHTMLString; });
  380. __webpack_require__.d(__webpack_exports__, "toggleFormat", function() { return /* reexport */ toggleFormat; });
  381. __webpack_require__.d(__webpack_exports__, "__UNSTABLE_LINE_SEPARATOR", function() { return /* reexport */ LINE_SEPARATOR; });
  382. __webpack_require__.d(__webpack_exports__, "unregisterFormatType", function() { return /* reexport */ unregisterFormatType; });
  383. __webpack_require__.d(__webpack_exports__, "__unstableCanIndentListItems", function() { return /* reexport */ canIndentListItems; });
  384. __webpack_require__.d(__webpack_exports__, "__unstableCanOutdentListItems", function() { return /* reexport */ canOutdentListItems; });
  385. __webpack_require__.d(__webpack_exports__, "__unstableIndentListItems", function() { return /* reexport */ indentListItems; });
  386. __webpack_require__.d(__webpack_exports__, "__unstableOutdentListItems", function() { return /* reexport */ outdentListItems; });
  387. __webpack_require__.d(__webpack_exports__, "__unstableChangeListType", function() { return /* reexport */ changeListType; });
  388. __webpack_require__.d(__webpack_exports__, "__unstableCreateElement", function() { return /* reexport */ createElement; });
  389. __webpack_require__.d(__webpack_exports__, "useAnchorRef", function() { return /* reexport */ useAnchorRef; });
  390. __webpack_require__.d(__webpack_exports__, "__experimentalRichText", function() { return /* reexport */ __experimentalRichText; });
  391. __webpack_require__.d(__webpack_exports__, "__unstableUseRichText", function() { return /* reexport */ useRichText; });
  392. __webpack_require__.d(__webpack_exports__, "__unstableFormatEdit", function() { return /* reexport */ FormatEdit; });
  393. // NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
  394. var selectors_namespaceObject = {};
  395. __webpack_require__.r(selectors_namespaceObject);
  396. __webpack_require__.d(selectors_namespaceObject, "getFormatTypes", function() { return getFormatTypes; });
  397. __webpack_require__.d(selectors_namespaceObject, "getFormatType", function() { return getFormatType; });
  398. __webpack_require__.d(selectors_namespaceObject, "getFormatTypeForBareElement", function() { return getFormatTypeForBareElement; });
  399. __webpack_require__.d(selectors_namespaceObject, "getFormatTypeForClassName", function() { return getFormatTypeForClassName; });
  400. // NAMESPACE OBJECT: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
  401. var actions_namespaceObject = {};
  402. __webpack_require__.r(actions_namespaceObject);
  403. __webpack_require__.d(actions_namespaceObject, "addFormatTypes", function() { return addFormatTypes; });
  404. __webpack_require__.d(actions_namespaceObject, "removeFormatTypes", function() { return removeFormatTypes; });
  405. // EXTERNAL MODULE: external ["wp","data"]
  406. var external_wp_data_ = __webpack_require__("1ZqX");
  407. // EXTERNAL MODULE: external "lodash"
  408. var external_lodash_ = __webpack_require__("YLtl");
  409. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/reducer.js
  410. /**
  411. * External dependencies
  412. */
  413. /**
  414. * WordPress dependencies
  415. */
  416. /**
  417. * Reducer managing the format types
  418. *
  419. * @param {Object} state Current state.
  420. * @param {Object} action Dispatched action.
  421. *
  422. * @return {Object} Updated state.
  423. */
  424. function reducer_formatTypes(state = {}, action) {
  425. switch (action.type) {
  426. case 'ADD_FORMAT_TYPES':
  427. return { ...state,
  428. ...Object(external_lodash_["keyBy"])(action.formatTypes, 'name')
  429. };
  430. case 'REMOVE_FORMAT_TYPES':
  431. return Object(external_lodash_["omit"])(state, action.names);
  432. }
  433. return state;
  434. }
  435. /* harmony default export */ var reducer = (Object(external_wp_data_["combineReducers"])({
  436. formatTypes: reducer_formatTypes
  437. }));
  438. // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js
  439. var rememo = __webpack_require__("pPDe");
  440. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js
  441. /**
  442. * External dependencies
  443. */
  444. /**
  445. * Returns all the available format types.
  446. *
  447. * @param {Object} state Data state.
  448. *
  449. * @return {Array} Format types.
  450. */
  451. const getFormatTypes = Object(rememo["a" /* default */])(state => Object.values(state.formatTypes), state => [state.formatTypes]);
  452. /**
  453. * Returns a format type by name.
  454. *
  455. * @param {Object} state Data state.
  456. * @param {string} name Format type name.
  457. *
  458. * @return {Object?} Format type.
  459. */
  460. function getFormatType(state, name) {
  461. return state.formatTypes[name];
  462. }
  463. /**
  464. * Gets the format type, if any, that can handle a bare element (without a
  465. * data-format-type attribute), given the tag name of this element.
  466. *
  467. * @param {Object} state Data state.
  468. * @param {string} bareElementTagName The tag name of the element to find a
  469. * format type for.
  470. * @return {?Object} Format type.
  471. */
  472. function getFormatTypeForBareElement(state, bareElementTagName) {
  473. return Object(external_lodash_["find"])(getFormatTypes(state), ({
  474. className,
  475. tagName
  476. }) => {
  477. return className === null && bareElementTagName === tagName;
  478. });
  479. }
  480. /**
  481. * Gets the format type, if any, that can handle an element, given its classes.
  482. *
  483. * @param {Object} state Data state.
  484. * @param {string} elementClassName The classes of the element to find a format
  485. * type for.
  486. * @return {?Object} Format type.
  487. */
  488. function getFormatTypeForClassName(state, elementClassName) {
  489. return Object(external_lodash_["find"])(getFormatTypes(state), ({
  490. className
  491. }) => {
  492. if (className === null) {
  493. return false;
  494. }
  495. return ` ${elementClassName} `.indexOf(` ${className} `) >= 0;
  496. });
  497. }
  498. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/actions.js
  499. /**
  500. * External dependencies
  501. */
  502. /**
  503. * Returns an action object used in signalling that format types have been
  504. * added.
  505. *
  506. * @param {Array|Object} formatTypes Format types received.
  507. *
  508. * @return {Object} Action object.
  509. */
  510. function addFormatTypes(formatTypes) {
  511. return {
  512. type: 'ADD_FORMAT_TYPES',
  513. formatTypes: Object(external_lodash_["castArray"])(formatTypes)
  514. };
  515. }
  516. /**
  517. * Returns an action object used to remove a registered format type.
  518. *
  519. * @param {string|Array} names Format name.
  520. *
  521. * @return {Object} Action object.
  522. */
  523. function removeFormatTypes(names) {
  524. return {
  525. type: 'REMOVE_FORMAT_TYPES',
  526. names: Object(external_lodash_["castArray"])(names)
  527. };
  528. }
  529. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/index.js
  530. /**
  531. * WordPress dependencies
  532. */
  533. /**
  534. * Internal dependencies
  535. */
  536. const STORE_NAME = 'core/rich-text';
  537. /**
  538. * Store definition for the rich-text namespace.
  539. *
  540. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  541. *
  542. * @type {Object}
  543. */
  544. const store = Object(external_wp_data_["createReduxStore"])(STORE_NAME, {
  545. reducer: reducer,
  546. selectors: selectors_namespaceObject,
  547. actions: actions_namespaceObject
  548. });
  549. Object(external_wp_data_["register"])(store);
  550. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js
  551. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  552. /**
  553. * Optimised equality check for format objects.
  554. *
  555. * @param {?RichTextFormat} format1 Format to compare.
  556. * @param {?RichTextFormat} format2 Format to compare.
  557. *
  558. * @return {boolean} True if formats are equal, false if not.
  559. */
  560. function isFormatEqual(format1, format2) {
  561. // Both not defined.
  562. if (format1 === format2) {
  563. return true;
  564. } // Either not defined.
  565. if (!format1 || !format2) {
  566. return false;
  567. }
  568. if (format1.type !== format2.type) {
  569. return false;
  570. }
  571. const attributes1 = format1.attributes;
  572. const attributes2 = format2.attributes; // Both not defined.
  573. if (attributes1 === attributes2) {
  574. return true;
  575. } // Either not defined.
  576. if (!attributes1 || !attributes2) {
  577. return false;
  578. }
  579. const keys1 = Object.keys(attributes1);
  580. const keys2 = Object.keys(attributes2);
  581. if (keys1.length !== keys2.length) {
  582. return false;
  583. }
  584. const length = keys1.length; // Optimise for speed.
  585. for (let i = 0; i < length; i++) {
  586. const name = keys1[i];
  587. if (attributes1[name] !== attributes2[name]) {
  588. return false;
  589. }
  590. }
  591. return true;
  592. }
  593. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js
  594. /**
  595. * Internal dependencies
  596. */
  597. /** @typedef {import('./create').RichTextValue} RichTextValue */
  598. /**
  599. * Normalises formats: ensures subsequent adjacent equal formats have the same
  600. * reference.
  601. *
  602. * @param {RichTextValue} value Value to normalise formats of.
  603. *
  604. * @return {RichTextValue} New value with normalised formats.
  605. */
  606. function normaliseFormats(value) {
  607. const newFormats = value.formats.slice();
  608. newFormats.forEach((formatsAtIndex, index) => {
  609. const formatsAtPreviousIndex = newFormats[index - 1];
  610. if (formatsAtPreviousIndex) {
  611. const newFormatsAtIndex = formatsAtIndex.slice();
  612. newFormatsAtIndex.forEach((format, formatIndex) => {
  613. const previousFormat = formatsAtPreviousIndex[formatIndex];
  614. if (isFormatEqual(format, previousFormat)) {
  615. newFormatsAtIndex[formatIndex] = previousFormat;
  616. }
  617. });
  618. newFormats[index] = newFormatsAtIndex;
  619. }
  620. });
  621. return { ...value,
  622. formats: newFormats
  623. };
  624. }
  625. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/apply-format.js
  626. /**
  627. * External dependencies
  628. */
  629. /**
  630. * Internal dependencies
  631. */
  632. /** @typedef {import('./create').RichTextValue} RichTextValue */
  633. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  634. function replace(array, index, value) {
  635. array = array.slice();
  636. array[index] = value;
  637. return array;
  638. }
  639. /**
  640. * Apply a format object to a Rich Text value from the given `startIndex` to the
  641. * given `endIndex`. Indices are retrieved from the selection if none are
  642. * provided.
  643. *
  644. * @param {RichTextValue} value Value to modify.
  645. * @param {RichTextFormat} format Format to apply.
  646. * @param {number} [startIndex] Start index.
  647. * @param {number} [endIndex] End index.
  648. *
  649. * @return {RichTextValue} A new value with the format applied.
  650. */
  651. function applyFormat(value, format, startIndex = value.start, endIndex = value.end) {
  652. const {
  653. formats,
  654. activeFormats
  655. } = value;
  656. const newFormats = formats.slice(); // The selection is collapsed.
  657. if (startIndex === endIndex) {
  658. const startFormat = Object(external_lodash_["find"])(newFormats[startIndex], {
  659. type: format.type
  660. }); // If the caret is at a format of the same type, expand start and end to
  661. // the edges of the format. This is useful to apply new attributes.
  662. if (startFormat) {
  663. const index = newFormats[startIndex].indexOf(startFormat);
  664. while (newFormats[startIndex] && newFormats[startIndex][index] === startFormat) {
  665. newFormats[startIndex] = replace(newFormats[startIndex], index, format);
  666. startIndex--;
  667. }
  668. endIndex++;
  669. while (newFormats[endIndex] && newFormats[endIndex][index] === startFormat) {
  670. newFormats[endIndex] = replace(newFormats[endIndex], index, format);
  671. endIndex++;
  672. }
  673. }
  674. } else {
  675. // Determine the highest position the new format can be inserted at.
  676. let position = +Infinity;
  677. for (let index = startIndex; index < endIndex; index++) {
  678. if (newFormats[index]) {
  679. newFormats[index] = newFormats[index].filter(({
  680. type
  681. }) => type !== format.type);
  682. const length = newFormats[index].length;
  683. if (length < position) {
  684. position = length;
  685. }
  686. } else {
  687. newFormats[index] = [];
  688. position = 0;
  689. }
  690. }
  691. for (let index = startIndex; index < endIndex; index++) {
  692. newFormats[index].splice(position, 0, format);
  693. }
  694. }
  695. return normaliseFormats({ ...value,
  696. formats: newFormats,
  697. // Always revise active formats. This serves as a placeholder for new
  698. // inputs with the format so new input appears with the format applied,
  699. // and ensures a format of the same type uses the latest values.
  700. activeFormats: [...Object(external_lodash_["reject"])(activeFormats, {
  701. type: format.type
  702. }), format]
  703. });
  704. }
  705. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create-element.js
  706. /**
  707. * Parse the given HTML into a body element.
  708. *
  709. * Note: The current implementation will return a shared reference, reset on
  710. * each call to `createElement`. Therefore, you should not hold a reference to
  711. * the value to operate upon asynchronously, as it may have unexpected results.
  712. *
  713. * @param {HTMLDocument} document The HTML document to use to parse.
  714. * @param {string} html The HTML to parse.
  715. *
  716. * @return {HTMLBodyElement} Body element with parsed HTML.
  717. */
  718. function createElement({
  719. implementation
  720. }, html) {
  721. // Because `createHTMLDocument` is an expensive operation, and with this
  722. // function being internal to `rich-text` (full control in avoiding a risk
  723. // of asynchronous operations on the shared reference), a single document
  724. // is reused and reset for each call to the function.
  725. if (!createElement.body) {
  726. createElement.body = implementation.createHTMLDocument('').body;
  727. }
  728. createElement.body.innerHTML = html;
  729. return createElement.body;
  730. }
  731. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/special-characters.js
  732. /**
  733. * Line separator character, used for multiline text.
  734. */
  735. const LINE_SEPARATOR = '\u2028';
  736. /**
  737. * Object replacement character, used as a placeholder for objects.
  738. */
  739. const OBJECT_REPLACEMENT_CHARACTER = '\ufffc';
  740. /**
  741. * Zero width non-breaking space, used as padding in the editable DOM tree when
  742. * it is empty otherwise.
  743. */
  744. const ZWNBSP = '\ufeff';
  745. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create.js
  746. /**
  747. * WordPress dependencies
  748. */
  749. /**
  750. * Internal dependencies
  751. */
  752. /**
  753. * @typedef {Object} RichTextFormat
  754. *
  755. * @property {string} type Format type.
  756. */
  757. /**
  758. * @typedef {Array<RichTextFormat>} RichTextFormatList
  759. */
  760. /**
  761. * @typedef {Object} RichTextValue
  762. *
  763. * @property {string} text Text.
  764. * @property {Array<RichTextFormatList>} formats Formats.
  765. * @property {Array<RichTextFormat>} replacements Replacements.
  766. * @property {number|undefined} start Selection start.
  767. * @property {number|undefined} end Selection end.
  768. */
  769. function createEmptyValue() {
  770. return {
  771. formats: [],
  772. replacements: [],
  773. text: ''
  774. };
  775. }
  776. function simpleFindKey(object, value) {
  777. for (const key in object) {
  778. if (object[key] === value) {
  779. return key;
  780. }
  781. }
  782. }
  783. function toFormat({
  784. type,
  785. attributes
  786. }) {
  787. let formatType;
  788. if (attributes && attributes.class) {
  789. formatType = Object(external_wp_data_["select"])('core/rich-text').getFormatTypeForClassName(attributes.class);
  790. if (formatType) {
  791. // Preserve any additional classes.
  792. attributes.class = ` ${attributes.class} `.replace(` ${formatType.className} `, ' ').trim();
  793. if (!attributes.class) {
  794. delete attributes.class;
  795. }
  796. }
  797. }
  798. if (!formatType) {
  799. formatType = Object(external_wp_data_["select"])('core/rich-text').getFormatTypeForBareElement(type);
  800. }
  801. if (!formatType) {
  802. return attributes ? {
  803. type,
  804. attributes
  805. } : {
  806. type
  807. };
  808. }
  809. if (formatType.__experimentalCreatePrepareEditableTree && !formatType.__experimentalCreateOnChangeEditableValue) {
  810. return null;
  811. }
  812. if (!attributes) {
  813. return {
  814. type: formatType.name
  815. };
  816. }
  817. const registeredAttributes = {};
  818. const unregisteredAttributes = {};
  819. for (const name in attributes) {
  820. const key = simpleFindKey(formatType.attributes, name);
  821. if (key) {
  822. registeredAttributes[key] = attributes[name];
  823. } else {
  824. unregisteredAttributes[name] = attributes[name];
  825. }
  826. }
  827. return {
  828. type: formatType.name,
  829. attributes: registeredAttributes,
  830. unregisteredAttributes
  831. };
  832. }
  833. /**
  834. * Create a RichText value from an `Element` tree (DOM), an HTML string or a
  835. * plain text string, with optionally a `Range` object to set the selection. If
  836. * called without any input, an empty value will be created. If
  837. * `multilineTag` is provided, any content of direct children whose type matches
  838. * `multilineTag` will be separated by two newlines. The optional functions can
  839. * be used to filter out content.
  840. *
  841. * A value will have the following shape, which you are strongly encouraged not
  842. * to modify without the use of helper functions:
  843. *
  844. * ```js
  845. * {
  846. * text: string,
  847. * formats: Array,
  848. * replacements: Array,
  849. * ?start: number,
  850. * ?end: number,
  851. * }
  852. * ```
  853. *
  854. * As you can see, text and formatting are separated. `text` holds the text,
  855. * including any replacement characters for objects and lines. `formats`,
  856. * `objects` and `lines` are all sparse arrays of the same length as `text`. It
  857. * holds information about the formatting at the relevant text indices. Finally
  858. * `start` and `end` state which text indices are selected. They are only
  859. * provided if a `Range` was given.
  860. *
  861. * @param {Object} [$1] Optional named arguments.
  862. * @param {Element} [$1.element] Element to create value from.
  863. * @param {string} [$1.text] Text to create value from.
  864. * @param {string} [$1.html] HTML to create value from.
  865. * @param {Range} [$1.range] Range to create value from.
  866. * @param {string} [$1.multilineTag] Multiline tag if the structure is
  867. * multiline.
  868. * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if
  869. * nesting is possible.
  870. * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white
  871. * space characters.
  872. * @param {boolean} [$1.__unstableIsEditableTree]
  873. *
  874. * @return {RichTextValue} A rich text value.
  875. */
  876. function create({
  877. element,
  878. text,
  879. html,
  880. range,
  881. multilineTag,
  882. multilineWrapperTags,
  883. __unstableIsEditableTree: isEditableTree,
  884. preserveWhiteSpace
  885. } = {}) {
  886. if (typeof text === 'string' && text.length > 0) {
  887. return {
  888. formats: Array(text.length),
  889. replacements: Array(text.length),
  890. text
  891. };
  892. }
  893. if (typeof html === 'string' && html.length > 0) {
  894. // It does not matter which document this is, we're just using it to
  895. // parse.
  896. element = createElement(document, html);
  897. }
  898. if (typeof element !== 'object') {
  899. return createEmptyValue();
  900. }
  901. if (!multilineTag) {
  902. return createFromElement({
  903. element,
  904. range,
  905. isEditableTree,
  906. preserveWhiteSpace
  907. });
  908. }
  909. return createFromMultilineElement({
  910. element,
  911. range,
  912. multilineTag,
  913. multilineWrapperTags,
  914. isEditableTree,
  915. preserveWhiteSpace
  916. });
  917. }
  918. /**
  919. * Helper to accumulate the value's selection start and end from the current
  920. * node and range.
  921. *
  922. * @param {Object} accumulator Object to accumulate into.
  923. * @param {Node} node Node to create value with.
  924. * @param {Range} range Range to create value with.
  925. * @param {Object} value Value that is being accumulated.
  926. */
  927. function accumulateSelection(accumulator, node, range, value) {
  928. if (!range) {
  929. return;
  930. }
  931. const {
  932. parentNode
  933. } = node;
  934. const {
  935. startContainer,
  936. startOffset,
  937. endContainer,
  938. endOffset
  939. } = range;
  940. const currentLength = accumulator.text.length; // Selection can be extracted from value.
  941. if (value.start !== undefined) {
  942. accumulator.start = currentLength + value.start; // Range indicates that the current node has selection.
  943. } else if (node === startContainer && node.nodeType === node.TEXT_NODE) {
  944. accumulator.start = currentLength + startOffset; // Range indicates that the current node is selected.
  945. } else if (parentNode === startContainer && node === startContainer.childNodes[startOffset]) {
  946. accumulator.start = currentLength; // Range indicates that the selection is after the current node.
  947. } else if (parentNode === startContainer && node === startContainer.childNodes[startOffset - 1]) {
  948. accumulator.start = currentLength + value.text.length; // Fallback if no child inside handled the selection.
  949. } else if (node === startContainer) {
  950. accumulator.start = currentLength;
  951. } // Selection can be extracted from value.
  952. if (value.end !== undefined) {
  953. accumulator.end = currentLength + value.end; // Range indicates that the current node has selection.
  954. } else if (node === endContainer && node.nodeType === node.TEXT_NODE) {
  955. accumulator.end = currentLength + endOffset; // Range indicates that the current node is selected.
  956. } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset - 1]) {
  957. accumulator.end = currentLength + value.text.length; // Range indicates that the selection is before the current node.
  958. } else if (parentNode === endContainer && node === endContainer.childNodes[endOffset]) {
  959. accumulator.end = currentLength; // Fallback if no child inside handled the selection.
  960. } else if (node === endContainer) {
  961. accumulator.end = currentLength + endOffset;
  962. }
  963. }
  964. /**
  965. * Adjusts the start and end offsets from a range based on a text filter.
  966. *
  967. * @param {Node} node Node of which the text should be filtered.
  968. * @param {Range} range The range to filter.
  969. * @param {Function} filter Function to use to filter the text.
  970. *
  971. * @return {Object|void} Object containing range properties.
  972. */
  973. function filterRange(node, range, filter) {
  974. if (!range) {
  975. return;
  976. }
  977. const {
  978. startContainer,
  979. endContainer
  980. } = range;
  981. let {
  982. startOffset,
  983. endOffset
  984. } = range;
  985. if (node === startContainer) {
  986. startOffset = filter(node.nodeValue.slice(0, startOffset)).length;
  987. }
  988. if (node === endContainer) {
  989. endOffset = filter(node.nodeValue.slice(0, endOffset)).length;
  990. }
  991. return {
  992. startContainer,
  993. startOffset,
  994. endContainer,
  995. endOffset
  996. };
  997. }
  998. /**
  999. * Collapse any whitespace used for HTML formatting to one space character,
  1000. * because it will also be displayed as such by the browser.
  1001. *
  1002. * @param {string} string
  1003. */
  1004. function collapseWhiteSpace(string) {
  1005. return string.replace(/[\n\r\t]+/g, ' ');
  1006. }
  1007. const ZWNBSPRegExp = new RegExp(ZWNBSP, 'g');
  1008. /**
  1009. * Removes padding (zero width non breaking spaces) added by `toTree`.
  1010. *
  1011. * @param {string} string
  1012. */
  1013. function removePadding(string) {
  1014. return string.replace(ZWNBSPRegExp, '');
  1015. }
  1016. /**
  1017. * Creates a Rich Text value from a DOM element and range.
  1018. *
  1019. * @param {Object} $1 Named argements.
  1020. * @param {Element} [$1.element] Element to create value from.
  1021. * @param {Range} [$1.range] Range to create value from.
  1022. * @param {string} [$1.multilineTag] Multiline tag if the structure is
  1023. * multiline.
  1024. * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if
  1025. * nesting is possible.
  1026. * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white
  1027. * space characters.
  1028. * @param {Array} [$1.currentWrapperTags]
  1029. * @param {boolean} [$1.isEditableTree]
  1030. *
  1031. * @return {RichTextValue} A rich text value.
  1032. */
  1033. function createFromElement({
  1034. element,
  1035. range,
  1036. multilineTag,
  1037. multilineWrapperTags,
  1038. currentWrapperTags = [],
  1039. isEditableTree,
  1040. preserveWhiteSpace
  1041. }) {
  1042. const accumulator = createEmptyValue();
  1043. if (!element) {
  1044. return accumulator;
  1045. }
  1046. if (!element.hasChildNodes()) {
  1047. accumulateSelection(accumulator, element, range, createEmptyValue());
  1048. return accumulator;
  1049. }
  1050. const length = element.childNodes.length; // Optimise for speed.
  1051. for (let index = 0; index < length; index++) {
  1052. const node = element.childNodes[index];
  1053. const type = node.nodeName.toLowerCase();
  1054. if (node.nodeType === node.TEXT_NODE) {
  1055. let filter = removePadding;
  1056. if (!preserveWhiteSpace) {
  1057. filter = string => removePadding(collapseWhiteSpace(string));
  1058. }
  1059. const text = filter(node.nodeValue);
  1060. range = filterRange(node, range, filter);
  1061. accumulateSelection(accumulator, node, range, {
  1062. text
  1063. }); // Create a sparse array of the same length as `text`, in which
  1064. // formats can be added.
  1065. accumulator.formats.length += text.length;
  1066. accumulator.replacements.length += text.length;
  1067. accumulator.text += text;
  1068. continue;
  1069. }
  1070. if (node.nodeType !== node.ELEMENT_NODE) {
  1071. continue;
  1072. }
  1073. if (isEditableTree && ( // Ignore any placeholders.
  1074. node.getAttribute('data-rich-text-placeholder') || // Ignore any line breaks that are not inserted by us.
  1075. type === 'br' && !node.getAttribute('data-rich-text-line-break'))) {
  1076. accumulateSelection(accumulator, node, range, createEmptyValue());
  1077. continue;
  1078. }
  1079. if (type === 'script') {
  1080. const value = {
  1081. formats: [,],
  1082. replacements: [{
  1083. type,
  1084. attributes: {
  1085. 'data-rich-text-script': node.getAttribute('data-rich-text-script') || encodeURIComponent(node.innerHTML)
  1086. }
  1087. }],
  1088. text: OBJECT_REPLACEMENT_CHARACTER
  1089. };
  1090. accumulateSelection(accumulator, node, range, value);
  1091. mergePair(accumulator, value);
  1092. continue;
  1093. }
  1094. if (type === 'br') {
  1095. accumulateSelection(accumulator, node, range, createEmptyValue());
  1096. mergePair(accumulator, create({
  1097. text: '\n'
  1098. }));
  1099. continue;
  1100. }
  1101. const lastFormats = accumulator.formats[accumulator.formats.length - 1];
  1102. const lastFormat = lastFormats && lastFormats[lastFormats.length - 1];
  1103. const newFormat = toFormat({
  1104. type,
  1105. attributes: getAttributes({
  1106. element: node
  1107. })
  1108. });
  1109. const format = isFormatEqual(newFormat, lastFormat) ? lastFormat : newFormat;
  1110. if (multilineWrapperTags && multilineWrapperTags.indexOf(type) !== -1) {
  1111. const value = createFromMultilineElement({
  1112. element: node,
  1113. range,
  1114. multilineTag,
  1115. multilineWrapperTags,
  1116. currentWrapperTags: [...currentWrapperTags, format],
  1117. isEditableTree,
  1118. preserveWhiteSpace
  1119. });
  1120. accumulateSelection(accumulator, node, range, value);
  1121. mergePair(accumulator, value);
  1122. continue;
  1123. }
  1124. const value = createFromElement({
  1125. element: node,
  1126. range,
  1127. multilineTag,
  1128. multilineWrapperTags,
  1129. isEditableTree,
  1130. preserveWhiteSpace
  1131. });
  1132. accumulateSelection(accumulator, node, range, value);
  1133. if (!format) {
  1134. mergePair(accumulator, value);
  1135. } else if (value.text.length === 0) {
  1136. if (format.attributes) {
  1137. mergePair(accumulator, {
  1138. formats: [,],
  1139. replacements: [format],
  1140. text: OBJECT_REPLACEMENT_CHARACTER
  1141. });
  1142. }
  1143. } else {
  1144. // Indices should share a reference to the same formats array.
  1145. // Only create a new reference if `formats` changes.
  1146. function mergeFormats(formats) {
  1147. if (mergeFormats.formats === formats) {
  1148. return mergeFormats.newFormats;
  1149. }
  1150. const newFormats = formats ? [format, ...formats] : [format];
  1151. mergeFormats.formats = formats;
  1152. mergeFormats.newFormats = newFormats;
  1153. return newFormats;
  1154. } // Since the formats parameter can be `undefined`, preset
  1155. // `mergeFormats` with a new reference.
  1156. mergeFormats.newFormats = [format];
  1157. mergePair(accumulator, { ...value,
  1158. formats: Array.from(value.formats, mergeFormats)
  1159. });
  1160. }
  1161. }
  1162. return accumulator;
  1163. }
  1164. /**
  1165. * Creates a rich text value from a DOM element and range that should be
  1166. * multiline.
  1167. *
  1168. * @param {Object} $1 Named argements.
  1169. * @param {Element} [$1.element] Element to create value from.
  1170. * @param {Range} [$1.range] Range to create value from.
  1171. * @param {string} [$1.multilineTag] Multiline tag if the structure is
  1172. * multiline.
  1173. * @param {Array} [$1.multilineWrapperTags] Tags where lines can be found if
  1174. * nesting is possible.
  1175. * @param {boolean} [$1.currentWrapperTags] Whether to prepend a line
  1176. * separator.
  1177. * @param {boolean} [$1.preserveWhiteSpace] Whether or not to collapse white
  1178. * space characters.
  1179. * @param {boolean} [$1.isEditableTree]
  1180. *
  1181. * @return {RichTextValue} A rich text value.
  1182. */
  1183. function createFromMultilineElement({
  1184. element,
  1185. range,
  1186. multilineTag,
  1187. multilineWrapperTags,
  1188. currentWrapperTags = [],
  1189. isEditableTree,
  1190. preserveWhiteSpace
  1191. }) {
  1192. const accumulator = createEmptyValue();
  1193. if (!element || !element.hasChildNodes()) {
  1194. return accumulator;
  1195. }
  1196. const length = element.children.length; // Optimise for speed.
  1197. for (let index = 0; index < length; index++) {
  1198. const node = element.children[index];
  1199. if (node.nodeName.toLowerCase() !== multilineTag) {
  1200. continue;
  1201. }
  1202. const value = createFromElement({
  1203. element: node,
  1204. range,
  1205. multilineTag,
  1206. multilineWrapperTags,
  1207. currentWrapperTags,
  1208. isEditableTree,
  1209. preserveWhiteSpace
  1210. }); // Multiline value text should be separated by a line separator.
  1211. if (index !== 0 || currentWrapperTags.length > 0) {
  1212. mergePair(accumulator, {
  1213. formats: [,],
  1214. replacements: currentWrapperTags.length > 0 ? [currentWrapperTags] : [,],
  1215. text: LINE_SEPARATOR
  1216. });
  1217. }
  1218. accumulateSelection(accumulator, node, range, value);
  1219. mergePair(accumulator, value);
  1220. }
  1221. return accumulator;
  1222. }
  1223. /**
  1224. * Gets the attributes of an element in object shape.
  1225. *
  1226. * @param {Object} $1 Named argements.
  1227. * @param {Element} $1.element Element to get attributes from.
  1228. *
  1229. * @return {Object|void} Attribute object or `undefined` if the element has no
  1230. * attributes.
  1231. */
  1232. function getAttributes({
  1233. element
  1234. }) {
  1235. if (!element.hasAttributes()) {
  1236. return;
  1237. }
  1238. const length = element.attributes.length;
  1239. let accumulator; // Optimise for speed.
  1240. for (let i = 0; i < length; i++) {
  1241. const {
  1242. name,
  1243. value
  1244. } = element.attributes[i];
  1245. if (name.indexOf('data-rich-text-') === 0) {
  1246. continue;
  1247. }
  1248. const safeName = /^on/i.test(name) ? 'data-disable-rich-text-' + name : name;
  1249. accumulator = accumulator || {};
  1250. accumulator[safeName] = value;
  1251. }
  1252. return accumulator;
  1253. }
  1254. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/concat.js
  1255. /**
  1256. * Internal dependencies
  1257. */
  1258. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1259. /**
  1260. * Concats a pair of rich text values. Not that this mutates `a` and does NOT
  1261. * normalise formats!
  1262. *
  1263. * @param {Object} a Value to mutate.
  1264. * @param {Object} b Value to add read from.
  1265. *
  1266. * @return {Object} `a`, mutated.
  1267. */
  1268. function mergePair(a, b) {
  1269. a.formats = a.formats.concat(b.formats);
  1270. a.replacements = a.replacements.concat(b.replacements);
  1271. a.text += b.text;
  1272. return a;
  1273. }
  1274. /**
  1275. * Combine all Rich Text values into one. This is similar to
  1276. * `String.prototype.concat`.
  1277. *
  1278. * @param {...RichTextValue} values Objects to combine.
  1279. *
  1280. * @return {RichTextValue} A new value combining all given records.
  1281. */
  1282. function concat(...values) {
  1283. return normaliseFormats(values.reduce(mergePair, create()));
  1284. }
  1285. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js
  1286. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1287. /** @typedef {import('./create').RichTextFormatList} RichTextFormatList */
  1288. /**
  1289. * Gets the all format objects at the start of the selection.
  1290. *
  1291. * @param {RichTextValue} value Value to inspect.
  1292. * @param {Array} EMPTY_ACTIVE_FORMATS Array to return if there are no
  1293. * active formats.
  1294. *
  1295. * @return {RichTextFormatList} Active format objects.
  1296. */
  1297. function getActiveFormats({
  1298. formats,
  1299. start,
  1300. end,
  1301. activeFormats
  1302. }, EMPTY_ACTIVE_FORMATS = []) {
  1303. if (start === undefined) {
  1304. return EMPTY_ACTIVE_FORMATS;
  1305. }
  1306. if (start === end) {
  1307. // For a collapsed caret, it is possible to override the active formats.
  1308. if (activeFormats) {
  1309. return activeFormats;
  1310. }
  1311. const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS;
  1312. const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS; // By default, select the lowest amount of formats possible (which means
  1313. // the caret is positioned outside the format boundary). The user can
  1314. // then use arrow keys to define `activeFormats`.
  1315. if (formatsBefore.length < formatsAfter.length) {
  1316. return formatsBefore;
  1317. }
  1318. return formatsAfter;
  1319. }
  1320. return formats[start] || EMPTY_ACTIVE_FORMATS;
  1321. }
  1322. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-format.js
  1323. /**
  1324. * External dependencies
  1325. */
  1326. /**
  1327. * Internal dependencies
  1328. */
  1329. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1330. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  1331. /**
  1332. * Gets the format object by type at the start of the selection. This can be
  1333. * used to get e.g. the URL of a link format at the current selection, but also
  1334. * to check if a format is active at the selection. Returns undefined if there
  1335. * is no format at the selection.
  1336. *
  1337. * @param {RichTextValue} value Value to inspect.
  1338. * @param {string} formatType Format type to look for.
  1339. *
  1340. * @return {RichTextFormat|undefined} Active format object of the specified
  1341. * type, or undefined.
  1342. */
  1343. function getActiveFormat(value, formatType) {
  1344. return Object(external_lodash_["find"])(getActiveFormats(value), {
  1345. type: formatType
  1346. });
  1347. }
  1348. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-object.js
  1349. /**
  1350. * Internal dependencies
  1351. */
  1352. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1353. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  1354. /**
  1355. * Gets the active object, if there is any.
  1356. *
  1357. * @param {RichTextValue} value Value to inspect.
  1358. *
  1359. * @return {RichTextFormat|void} Active object, or undefined.
  1360. */
  1361. function getActiveObject({
  1362. start,
  1363. end,
  1364. replacements,
  1365. text
  1366. }) {
  1367. if (start + 1 !== end || text[start] !== OBJECT_REPLACEMENT_CHARACTER) {
  1368. return;
  1369. }
  1370. return replacements[start];
  1371. }
  1372. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-text-content.js
  1373. /**
  1374. * Internal dependencies
  1375. */
  1376. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1377. /**
  1378. * Get the textual content of a Rich Text value. This is similar to
  1379. * `Element.textContent`.
  1380. *
  1381. * @param {RichTextValue} value Value to use.
  1382. *
  1383. * @return {string} The text content.
  1384. */
  1385. function getTextContent({
  1386. text
  1387. }) {
  1388. return text.replace(new RegExp(OBJECT_REPLACEMENT_CHARACTER, 'g'), '').replace(new RegExp(LINE_SEPARATOR, 'g'), '\n');
  1389. }
  1390. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-line-index.js
  1391. /**
  1392. * Internal dependencies
  1393. */
  1394. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1395. /**
  1396. * Gets the currently selected line index, or the first line index if the
  1397. * selection spans over multiple items.
  1398. *
  1399. * @param {RichTextValue} value Value to get the line index from.
  1400. * @param {boolean} startIndex Optional index that should be contained by
  1401. * the line. Defaults to the selection start
  1402. * of the value.
  1403. *
  1404. * @return {number|void} The line index. Undefined if not found.
  1405. */
  1406. function getLineIndex({
  1407. start,
  1408. text
  1409. }, startIndex = start) {
  1410. let index = startIndex;
  1411. while (index--) {
  1412. if (text[index] === LINE_SEPARATOR) {
  1413. return index;
  1414. }
  1415. }
  1416. }
  1417. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-list-root-selected.js
  1418. /**
  1419. * Internal dependencies
  1420. */
  1421. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1422. /**
  1423. * Whether or not the root list is selected.
  1424. *
  1425. * @param {RichTextValue} value The value to check.
  1426. *
  1427. * @return {boolean} True if the root list or nothing is selected, false if an
  1428. * inner list is selected.
  1429. */
  1430. function isListRootSelected(value) {
  1431. const {
  1432. replacements,
  1433. start
  1434. } = value;
  1435. const lineIndex = getLineIndex(value, start);
  1436. const replacement = replacements[lineIndex];
  1437. return !replacement || replacement.length < 1;
  1438. }
  1439. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-active-list-type.js
  1440. /**
  1441. * Internal dependencies
  1442. */
  1443. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1444. /**
  1445. * Whether or not the selected list has the given tag name.
  1446. *
  1447. * @param {RichTextValue} value The value to check.
  1448. * @param {string} type The tag name the list should have.
  1449. * @param {string} rootType The current root tag name, to compare with in
  1450. * case nothing is selected.
  1451. *
  1452. * @return {boolean} True if the current list type matches `type`, false if not.
  1453. */
  1454. function isActiveListType(value, type, rootType) {
  1455. const {
  1456. replacements,
  1457. start
  1458. } = value;
  1459. const lineIndex = getLineIndex(value, start);
  1460. const replacement = replacements[lineIndex];
  1461. if (!replacement || replacement.length === 0) {
  1462. return type === rootType;
  1463. }
  1464. const lastFormat = replacement[replacement.length - 1];
  1465. return lastFormat.type === type;
  1466. }
  1467. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js
  1468. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1469. /**
  1470. * Check if the selection of a Rich Text value is collapsed or not. Collapsed
  1471. * means that no characters are selected, but there is a caret present. If there
  1472. * is no selection, `undefined` will be returned. This is similar to
  1473. * `window.getSelection().isCollapsed()`.
  1474. *
  1475. * @param {RichTextValue} value The rich text value to check.
  1476. *
  1477. * @return {boolean|undefined} True if the selection is collapsed, false if not,
  1478. * undefined if there is no selection.
  1479. */
  1480. function isCollapsed({
  1481. start,
  1482. end
  1483. }) {
  1484. if (start === undefined || end === undefined) {
  1485. return;
  1486. }
  1487. return start === end;
  1488. }
  1489. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-empty.js
  1490. /**
  1491. * Internal dependencies
  1492. */
  1493. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1494. /**
  1495. * Check if a Rich Text value is Empty, meaning it contains no text or any
  1496. * objects (such as images).
  1497. *
  1498. * @param {RichTextValue} value Value to use.
  1499. *
  1500. * @return {boolean} True if the value is empty, false if not.
  1501. */
  1502. function isEmpty({
  1503. text
  1504. }) {
  1505. return text.length === 0;
  1506. }
  1507. /**
  1508. * Check if the current collapsed selection is on an empty line in case of a
  1509. * multiline value.
  1510. *
  1511. * @param {RichTextValue} value Value te check.
  1512. *
  1513. * @return {boolean} True if the line is empty, false if not.
  1514. */
  1515. function isEmptyLine({
  1516. text,
  1517. start,
  1518. end
  1519. }) {
  1520. if (start !== end) {
  1521. return false;
  1522. }
  1523. if (text.length === 0) {
  1524. return true;
  1525. }
  1526. if (start === 0 && text.slice(0, 1) === LINE_SEPARATOR) {
  1527. return true;
  1528. }
  1529. if (start === text.length && text.slice(-1) === LINE_SEPARATOR) {
  1530. return true;
  1531. }
  1532. return text.slice(start - 1, end + 1) === `${LINE_SEPARATOR}${LINE_SEPARATOR}`;
  1533. }
  1534. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/join.js
  1535. /**
  1536. * Internal dependencies
  1537. */
  1538. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1539. /**
  1540. * Combine an array of Rich Text values into one, optionally separated by
  1541. * `separator`, which can be a Rich Text value, HTML string, or plain text
  1542. * string. This is similar to `Array.prototype.join`.
  1543. *
  1544. * @param {Array<RichTextValue>} values An array of values to join.
  1545. * @param {string|RichTextValue} [separator] Separator string or value.
  1546. *
  1547. * @return {RichTextValue} A new combined value.
  1548. */
  1549. function join(values, separator = '') {
  1550. if (typeof separator === 'string') {
  1551. separator = create({
  1552. text: separator
  1553. });
  1554. }
  1555. return normaliseFormats(values.reduce((accumlator, {
  1556. formats,
  1557. replacements,
  1558. text
  1559. }) => ({
  1560. formats: accumlator.formats.concat(separator.formats, formats),
  1561. replacements: accumlator.replacements.concat(separator.replacements, replacements),
  1562. text: accumlator.text + separator.text + text
  1563. })));
  1564. }
  1565. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/register-format-type.js
  1566. /**
  1567. * WordPress dependencies
  1568. */
  1569. /**
  1570. * Internal dependencies
  1571. */
  1572. /**
  1573. * @typedef {Object} WPFormat
  1574. *
  1575. * @property {string} name A string identifying the format. Must be
  1576. * unique across all registered formats.
  1577. * @property {string} tagName The HTML tag this format will wrap the
  1578. * selection with.
  1579. * @property {string} [className] A class to match the format.
  1580. * @property {string} title Name of the format.
  1581. * @property {Function} edit Should return a component for the user to
  1582. * interact with the new registered format.
  1583. */
  1584. /**
  1585. * Registers a new format provided a unique name and an object defining its
  1586. * behavior.
  1587. *
  1588. * @param {string} name Format name.
  1589. * @param {WPFormat} settings Format settings.
  1590. *
  1591. * @return {WPFormat|undefined} The format, if it has been successfully
  1592. * registered; otherwise `undefined`.
  1593. */
  1594. function registerFormatType(name, settings) {
  1595. settings = {
  1596. name,
  1597. ...settings
  1598. };
  1599. if (typeof settings.name !== 'string') {
  1600. window.console.error('Format names must be strings.');
  1601. return;
  1602. }
  1603. if (!/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/.test(settings.name)) {
  1604. window.console.error('Format names must contain a namespace prefix, include only lowercase alphanumeric characters or dashes, and start with a letter. Example: my-plugin/my-custom-format');
  1605. return;
  1606. }
  1607. if (Object(external_wp_data_["select"])(store).getFormatType(settings.name)) {
  1608. window.console.error('Format "' + settings.name + '" is already registered.');
  1609. return;
  1610. }
  1611. if (typeof settings.tagName !== 'string' || settings.tagName === '') {
  1612. window.console.error('Format tag names must be a string.');
  1613. return;
  1614. }
  1615. if ((typeof settings.className !== 'string' || settings.className === '') && settings.className !== null) {
  1616. window.console.error('Format class names must be a string, or null to handle bare elements.');
  1617. return;
  1618. }
  1619. if (!/^[_a-zA-Z]+[a-zA-Z0-9-]*$/.test(settings.className)) {
  1620. window.console.error('A class name must begin with a letter, followed by any number of hyphens, letters, or numbers.');
  1621. return;
  1622. }
  1623. if (settings.className === null) {
  1624. const formatTypeForBareElement = Object(external_wp_data_["select"])(store).getFormatTypeForBareElement(settings.tagName);
  1625. if (formatTypeForBareElement) {
  1626. window.console.error(`Format "${formatTypeForBareElement.name}" is already registered to handle bare tag name "${settings.tagName}".`);
  1627. return;
  1628. }
  1629. } else {
  1630. const formatTypeForClassName = Object(external_wp_data_["select"])(store).getFormatTypeForClassName(settings.className);
  1631. if (formatTypeForClassName) {
  1632. window.console.error(`Format "${formatTypeForClassName.name}" is already registered to handle class name "${settings.className}".`);
  1633. return;
  1634. }
  1635. }
  1636. if (!('title' in settings) || settings.title === '') {
  1637. window.console.error('The format "' + settings.name + '" must have a title.');
  1638. return;
  1639. }
  1640. if ('keywords' in settings && settings.keywords.length > 3) {
  1641. window.console.error('The format "' + settings.name + '" can have a maximum of 3 keywords.');
  1642. return;
  1643. }
  1644. if (typeof settings.title !== 'string') {
  1645. window.console.error('Format titles must be strings.');
  1646. return;
  1647. }
  1648. Object(external_wp_data_["dispatch"])(store).addFormatTypes(settings);
  1649. return settings;
  1650. }
  1651. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-format.js
  1652. /**
  1653. * External dependencies
  1654. */
  1655. /**
  1656. * Internal dependencies
  1657. */
  1658. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1659. /**
  1660. * Remove any format object from a Rich Text value by type from the given
  1661. * `startIndex` to the given `endIndex`. Indices are retrieved from the
  1662. * selection if none are provided.
  1663. *
  1664. * @param {RichTextValue} value Value to modify.
  1665. * @param {string} formatType Format type to remove.
  1666. * @param {number} [startIndex] Start index.
  1667. * @param {number} [endIndex] End index.
  1668. *
  1669. * @return {RichTextValue} A new value with the format applied.
  1670. */
  1671. function removeFormat(value, formatType, startIndex = value.start, endIndex = value.end) {
  1672. const {
  1673. formats,
  1674. activeFormats
  1675. } = value;
  1676. const newFormats = formats.slice(); // If the selection is collapsed, expand start and end to the edges of the
  1677. // format.
  1678. if (startIndex === endIndex) {
  1679. const format = Object(external_lodash_["find"])(newFormats[startIndex], {
  1680. type: formatType
  1681. });
  1682. if (format) {
  1683. while (Object(external_lodash_["find"])(newFormats[startIndex], format)) {
  1684. filterFormats(newFormats, startIndex, formatType);
  1685. startIndex--;
  1686. }
  1687. endIndex++;
  1688. while (Object(external_lodash_["find"])(newFormats[endIndex], format)) {
  1689. filterFormats(newFormats, endIndex, formatType);
  1690. endIndex++;
  1691. }
  1692. }
  1693. } else {
  1694. for (let i = startIndex; i < endIndex; i++) {
  1695. if (newFormats[i]) {
  1696. filterFormats(newFormats, i, formatType);
  1697. }
  1698. }
  1699. }
  1700. return normaliseFormats({ ...value,
  1701. formats: newFormats,
  1702. activeFormats: Object(external_lodash_["reject"])(activeFormats, {
  1703. type: formatType
  1704. })
  1705. });
  1706. }
  1707. function filterFormats(formats, index, formatType) {
  1708. const newFormats = formats[index].filter(({
  1709. type
  1710. }) => type !== formatType);
  1711. if (newFormats.length) {
  1712. formats[index] = newFormats;
  1713. } else {
  1714. delete formats[index];
  1715. }
  1716. }
  1717. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert.js
  1718. /**
  1719. * Internal dependencies
  1720. */
  1721. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1722. /**
  1723. * Insert a Rich Text value, an HTML string, or a plain text string, into a
  1724. * Rich Text value at the given `startIndex`. Any content between `startIndex`
  1725. * and `endIndex` will be removed. Indices are retrieved from the selection if
  1726. * none are provided.
  1727. *
  1728. * @param {RichTextValue} value Value to modify.
  1729. * @param {RichTextValue|string} valueToInsert Value to insert.
  1730. * @param {number} [startIndex] Start index.
  1731. * @param {number} [endIndex] End index.
  1732. *
  1733. * @return {RichTextValue} A new value with the value inserted.
  1734. */
  1735. function insert(value, valueToInsert, startIndex = value.start, endIndex = value.end) {
  1736. const {
  1737. formats,
  1738. replacements,
  1739. text
  1740. } = value;
  1741. if (typeof valueToInsert === 'string') {
  1742. valueToInsert = create({
  1743. text: valueToInsert
  1744. });
  1745. }
  1746. const index = startIndex + valueToInsert.text.length;
  1747. return normaliseFormats({
  1748. formats: formats.slice(0, startIndex).concat(valueToInsert.formats, formats.slice(endIndex)),
  1749. replacements: replacements.slice(0, startIndex).concat(valueToInsert.replacements, replacements.slice(endIndex)),
  1750. text: text.slice(0, startIndex) + valueToInsert.text + text.slice(endIndex),
  1751. start: index,
  1752. end: index
  1753. });
  1754. }
  1755. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove.js
  1756. /**
  1757. * Internal dependencies
  1758. */
  1759. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1760. /**
  1761. * Remove content from a Rich Text value between the given `startIndex` and
  1762. * `endIndex`. Indices are retrieved from the selection if none are provided.
  1763. *
  1764. * @param {RichTextValue} value Value to modify.
  1765. * @param {number} [startIndex] Start index.
  1766. * @param {number} [endIndex] End index.
  1767. *
  1768. * @return {RichTextValue} A new value with the content removed.
  1769. */
  1770. function remove_remove(value, startIndex, endIndex) {
  1771. return insert(value, create(), startIndex, endIndex);
  1772. }
  1773. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/replace.js
  1774. /**
  1775. * Internal dependencies
  1776. */
  1777. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1778. /**
  1779. * Search a Rich Text value and replace the match(es) with `replacement`. This
  1780. * is similar to `String.prototype.replace`.
  1781. *
  1782. * @param {RichTextValue} value The value to modify.
  1783. * @param {RegExp|string} pattern A RegExp object or literal. Can also be
  1784. * a string. It is treated as a verbatim
  1785. * string and is not interpreted as a
  1786. * regular expression. Only the first
  1787. * occurrence will be replaced.
  1788. * @param {Function|string} replacement The match or matches are replaced with
  1789. * the specified or the value returned by
  1790. * the specified function.
  1791. *
  1792. * @return {RichTextValue} A new value with replacements applied.
  1793. */
  1794. function replace_replace({
  1795. formats,
  1796. replacements,
  1797. text,
  1798. start,
  1799. end
  1800. }, pattern, replacement) {
  1801. text = text.replace(pattern, (match, ...rest) => {
  1802. const offset = rest[rest.length - 2];
  1803. let newText = replacement;
  1804. let newFormats;
  1805. let newReplacements;
  1806. if (typeof newText === 'function') {
  1807. newText = replacement(match, ...rest);
  1808. }
  1809. if (typeof newText === 'object') {
  1810. newFormats = newText.formats;
  1811. newReplacements = newText.replacements;
  1812. newText = newText.text;
  1813. } else {
  1814. newFormats = Array(newText.length);
  1815. newReplacements = Array(newText.length);
  1816. if (formats[offset]) {
  1817. newFormats = newFormats.fill(formats[offset]);
  1818. }
  1819. }
  1820. formats = formats.slice(0, offset).concat(newFormats, formats.slice(offset + match.length));
  1821. replacements = replacements.slice(0, offset).concat(newReplacements, replacements.slice(offset + match.length));
  1822. if (start) {
  1823. start = end = offset + newText.length;
  1824. }
  1825. return newText;
  1826. });
  1827. return normaliseFormats({
  1828. formats,
  1829. replacements,
  1830. text,
  1831. start,
  1832. end
  1833. });
  1834. }
  1835. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-line-separator.js
  1836. /**
  1837. * Internal dependencies
  1838. */
  1839. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1840. /**
  1841. * Insert a line break character into a Rich Text value at the given
  1842. * `startIndex`. Any content between `startIndex` and `endIndex` will be
  1843. * removed. Indices are retrieved from the selection if none are provided.
  1844. *
  1845. * @param {RichTextValue} value Value to modify.
  1846. * @param {number} [startIndex] Start index.
  1847. * @param {number} [endIndex] End index.
  1848. *
  1849. * @return {RichTextValue} A new value with the value inserted.
  1850. */
  1851. function insertLineSeparator(value, startIndex = value.start, endIndex = value.end) {
  1852. const beforeText = value.text.slice(0, startIndex);
  1853. const previousLineSeparatorIndex = beforeText.lastIndexOf(LINE_SEPARATOR);
  1854. const previousLineSeparatorFormats = value.replacements[previousLineSeparatorIndex];
  1855. let replacements = [,];
  1856. if (previousLineSeparatorFormats) {
  1857. replacements = [previousLineSeparatorFormats];
  1858. }
  1859. const valueToInsert = {
  1860. formats: [,],
  1861. replacements,
  1862. text: LINE_SEPARATOR
  1863. };
  1864. return insert(value, valueToInsert, startIndex, endIndex);
  1865. }
  1866. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-line-separator.js
  1867. /**
  1868. * Internal dependencies
  1869. */
  1870. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1871. /**
  1872. * Removes a line separator character, if existing, from a Rich Text value at
  1873. * the current indices. If no line separator exists on the indices it will
  1874. * return undefined.
  1875. *
  1876. * @param {RichTextValue} value Value to modify.
  1877. * @param {boolean} backward Indicates if are removing from the start
  1878. * index or the end index.
  1879. *
  1880. * @return {RichTextValue|undefined} A new value with the line separator
  1881. * removed. Or undefined if no line separator
  1882. * is found on the position.
  1883. */
  1884. function removeLineSeparator(value, backward = true) {
  1885. const {
  1886. replacements,
  1887. text,
  1888. start,
  1889. end
  1890. } = value;
  1891. const collapsed = isCollapsed(value);
  1892. let index = start - 1;
  1893. let removeStart = collapsed ? start - 1 : start;
  1894. let removeEnd = end;
  1895. if (!backward) {
  1896. index = end;
  1897. removeStart = start;
  1898. removeEnd = collapsed ? end + 1 : end;
  1899. }
  1900. if (text[index] !== LINE_SEPARATOR) {
  1901. return;
  1902. }
  1903. let newValue; // If the line separator that is about te be removed
  1904. // contains wrappers, remove the wrappers first.
  1905. if (collapsed && replacements[index] && replacements[index].length) {
  1906. const newReplacements = replacements.slice();
  1907. newReplacements[index] = replacements[index].slice(0, -1);
  1908. newValue = { ...value,
  1909. replacements: newReplacements
  1910. };
  1911. } else {
  1912. newValue = remove_remove(value, removeStart, removeEnd);
  1913. }
  1914. return newValue;
  1915. }
  1916. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-object.js
  1917. /**
  1918. * Internal dependencies
  1919. */
  1920. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1921. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  1922. /**
  1923. * Insert a format as an object into a Rich Text value at the given
  1924. * `startIndex`. Any content between `startIndex` and `endIndex` will be
  1925. * removed. Indices are retrieved from the selection if none are provided.
  1926. *
  1927. * @param {RichTextValue} value Value to modify.
  1928. * @param {RichTextFormat} formatToInsert Format to insert as object.
  1929. * @param {number} [startIndex] Start index.
  1930. * @param {number} [endIndex] End index.
  1931. *
  1932. * @return {RichTextValue} A new value with the object inserted.
  1933. */
  1934. function insertObject(value, formatToInsert, startIndex, endIndex) {
  1935. const valueToInsert = {
  1936. formats: [,],
  1937. replacements: [formatToInsert],
  1938. text: OBJECT_REPLACEMENT_CHARACTER
  1939. };
  1940. return insert(value, valueToInsert, startIndex, endIndex);
  1941. }
  1942. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/slice.js
  1943. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1944. /**
  1945. * Slice a Rich Text value from `startIndex` to `endIndex`. Indices are
  1946. * retrieved from the selection if none are provided. This is similar to
  1947. * `String.prototype.slice`.
  1948. *
  1949. * @param {RichTextValue} value Value to modify.
  1950. * @param {number} [startIndex] Start index.
  1951. * @param {number} [endIndex] End index.
  1952. *
  1953. * @return {RichTextValue} A new extracted value.
  1954. */
  1955. function slice(value, startIndex = value.start, endIndex = value.end) {
  1956. const {
  1957. formats,
  1958. replacements,
  1959. text
  1960. } = value;
  1961. if (startIndex === undefined || endIndex === undefined) {
  1962. return { ...value
  1963. };
  1964. }
  1965. return {
  1966. formats: formats.slice(startIndex, endIndex),
  1967. replacements: replacements.slice(startIndex, endIndex),
  1968. text: text.slice(startIndex, endIndex)
  1969. };
  1970. }
  1971. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/split.js
  1972. /**
  1973. * Internal dependencies
  1974. */
  1975. /** @typedef {import('./create').RichTextValue} RichTextValue */
  1976. /**
  1977. * Split a Rich Text value in two at the given `startIndex` and `endIndex`, or
  1978. * split at the given separator. This is similar to `String.prototype.split`.
  1979. * Indices are retrieved from the selection if none are provided.
  1980. *
  1981. * @param {RichTextValue} value
  1982. * @param {number|string} [string] Start index, or string at which to split.
  1983. *
  1984. * @return {Array<RichTextValue>|undefined} An array of new values.
  1985. */
  1986. function split({
  1987. formats,
  1988. replacements,
  1989. text,
  1990. start,
  1991. end
  1992. }, string) {
  1993. if (typeof string !== 'string') {
  1994. return splitAtSelection(...arguments);
  1995. }
  1996. let nextStart = 0;
  1997. return text.split(string).map(substring => {
  1998. const startIndex = nextStart;
  1999. const value = {
  2000. formats: formats.slice(startIndex, startIndex + substring.length),
  2001. replacements: replacements.slice(startIndex, startIndex + substring.length),
  2002. text: substring
  2003. };
  2004. nextStart += string.length + substring.length;
  2005. if (start !== undefined && end !== undefined) {
  2006. if (start >= startIndex && start < nextStart) {
  2007. value.start = start - startIndex;
  2008. } else if (start < startIndex && end > startIndex) {
  2009. value.start = 0;
  2010. }
  2011. if (end >= startIndex && end < nextStart) {
  2012. value.end = end - startIndex;
  2013. } else if (start < nextStart && end > nextStart) {
  2014. value.end = substring.length;
  2015. }
  2016. }
  2017. return value;
  2018. });
  2019. }
  2020. function splitAtSelection({
  2021. formats,
  2022. replacements,
  2023. text,
  2024. start,
  2025. end
  2026. }, startIndex = start, endIndex = end) {
  2027. if (start === undefined || end === undefined) {
  2028. return;
  2029. }
  2030. const before = {
  2031. formats: formats.slice(0, startIndex),
  2032. replacements: replacements.slice(0, startIndex),
  2033. text: text.slice(0, startIndex)
  2034. };
  2035. const after = {
  2036. formats: formats.slice(endIndex),
  2037. replacements: replacements.slice(endIndex),
  2038. text: text.slice(endIndex),
  2039. start: 0,
  2040. end: 0
  2041. };
  2042. return [// Ensure newlines are trimmed.
  2043. replace_replace(before, /\u2028+$/, ''), replace_replace(after, /^\u2028+/, '')];
  2044. }
  2045. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-format-type.js
  2046. /**
  2047. * WordPress dependencies
  2048. */
  2049. /**
  2050. * Internal dependencies
  2051. */
  2052. /** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */
  2053. /**
  2054. * Returns a registered format type.
  2055. *
  2056. * @param {string} name Format name.
  2057. *
  2058. * @return {RichTextFormatType|undefined} Format type.
  2059. */
  2060. function get_format_type_getFormatType(name) {
  2061. return Object(external_wp_data_["select"])(store).getFormatType(name);
  2062. }
  2063. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-tree.js
  2064. /**
  2065. * Internal dependencies
  2066. */
  2067. function restoreOnAttributes(attributes, isEditableTree) {
  2068. if (isEditableTree) {
  2069. return attributes;
  2070. }
  2071. const newAttributes = {};
  2072. for (const key in attributes) {
  2073. let newKey = key;
  2074. if (key.startsWith('data-disable-rich-text-')) {
  2075. newKey = key.slice('data-disable-rich-text-'.length);
  2076. }
  2077. newAttributes[newKey] = attributes[key];
  2078. }
  2079. return newAttributes;
  2080. }
  2081. /**
  2082. * Converts a format object to information that can be used to create an element
  2083. * from (type, attributes and object).
  2084. *
  2085. * @param {Object} $1 Named parameters.
  2086. * @param {string} $1.type The format type.
  2087. * @param {Object} $1.attributes The format attributes.
  2088. * @param {Object} $1.unregisteredAttributes The unregistered format
  2089. * attributes.
  2090. * @param {boolean} $1.object Whether or not it is an object
  2091. * format.
  2092. * @param {boolean} $1.boundaryClass Whether or not to apply a boundary
  2093. * class.
  2094. * @param {boolean} $1.isEditableTree
  2095. *
  2096. * @return {Object} Information to be used for
  2097. * element creation.
  2098. */
  2099. function fromFormat({
  2100. type,
  2101. attributes,
  2102. unregisteredAttributes,
  2103. object,
  2104. boundaryClass,
  2105. isEditableTree
  2106. }) {
  2107. const formatType = get_format_type_getFormatType(type);
  2108. let elementAttributes = {};
  2109. if (boundaryClass) {
  2110. elementAttributes['data-rich-text-format-boundary'] = 'true';
  2111. }
  2112. if (!formatType) {
  2113. if (attributes) {
  2114. elementAttributes = { ...attributes,
  2115. ...elementAttributes
  2116. };
  2117. }
  2118. return {
  2119. type,
  2120. attributes: restoreOnAttributes(elementAttributes, isEditableTree),
  2121. object
  2122. };
  2123. }
  2124. elementAttributes = { ...unregisteredAttributes,
  2125. ...elementAttributes
  2126. };
  2127. for (const name in attributes) {
  2128. const key = formatType.attributes ? formatType.attributes[name] : false;
  2129. if (key) {
  2130. elementAttributes[key] = attributes[name];
  2131. } else {
  2132. elementAttributes[name] = attributes[name];
  2133. }
  2134. }
  2135. if (formatType.className) {
  2136. if (elementAttributes.class) {
  2137. elementAttributes.class = `${formatType.className} ${elementAttributes.class}`;
  2138. } else {
  2139. elementAttributes.class = formatType.className;
  2140. }
  2141. }
  2142. return {
  2143. type: formatType.tagName,
  2144. object: formatType.object,
  2145. attributes: restoreOnAttributes(elementAttributes, isEditableTree)
  2146. };
  2147. }
  2148. /**
  2149. * Checks if both arrays of formats up until a certain index are equal.
  2150. *
  2151. * @param {Array} a Array of formats to compare.
  2152. * @param {Array} b Array of formats to compare.
  2153. * @param {number} index Index to check until.
  2154. */
  2155. function isEqualUntil(a, b, index) {
  2156. do {
  2157. if (a[index] !== b[index]) {
  2158. return false;
  2159. }
  2160. } while (index--);
  2161. return true;
  2162. }
  2163. function toTree({
  2164. value,
  2165. multilineTag,
  2166. preserveWhiteSpace,
  2167. createEmpty,
  2168. append,
  2169. getLastChild,
  2170. getParent,
  2171. isText,
  2172. getText,
  2173. remove,
  2174. appendText,
  2175. onStartIndex,
  2176. onEndIndex,
  2177. isEditableTree,
  2178. placeholder
  2179. }) {
  2180. const {
  2181. formats,
  2182. replacements,
  2183. text,
  2184. start,
  2185. end
  2186. } = value;
  2187. const formatsLength = formats.length + 1;
  2188. const tree = createEmpty();
  2189. const multilineFormat = {
  2190. type: multilineTag
  2191. };
  2192. const activeFormats = getActiveFormats(value);
  2193. const deepestActiveFormat = activeFormats[activeFormats.length - 1];
  2194. let lastSeparatorFormats;
  2195. let lastCharacterFormats;
  2196. let lastCharacter; // If we're building a multiline tree, start off with a multiline element.
  2197. if (multilineTag) {
  2198. append(append(tree, {
  2199. type: multilineTag
  2200. }), '');
  2201. lastCharacterFormats = lastSeparatorFormats = [multilineFormat];
  2202. } else {
  2203. append(tree, '');
  2204. }
  2205. for (let i = 0; i < formatsLength; i++) {
  2206. const character = text.charAt(i);
  2207. const shouldInsertPadding = isEditableTree && ( // Pad the line if the line is empty.
  2208. !lastCharacter || lastCharacter === LINE_SEPARATOR || // Pad the line if the previous character is a line break, otherwise
  2209. // the line break won't be visible.
  2210. lastCharacter === '\n');
  2211. let characterFormats = formats[i]; // Set multiline tags in queue for building the tree.
  2212. if (multilineTag) {
  2213. if (character === LINE_SEPARATOR) {
  2214. characterFormats = lastSeparatorFormats = (replacements[i] || []).reduce((accumulator, format) => {
  2215. accumulator.push(format, multilineFormat);
  2216. return accumulator;
  2217. }, [multilineFormat]);
  2218. } else {
  2219. characterFormats = [...lastSeparatorFormats, ...(characterFormats || [])];
  2220. }
  2221. }
  2222. let pointer = getLastChild(tree);
  2223. if (shouldInsertPadding && character === LINE_SEPARATOR) {
  2224. let node = pointer;
  2225. while (!isText(node)) {
  2226. node = getLastChild(node);
  2227. }
  2228. append(getParent(node), ZWNBSP);
  2229. } // Set selection for the start of line.
  2230. if (lastCharacter === LINE_SEPARATOR) {
  2231. let node = pointer;
  2232. while (!isText(node)) {
  2233. node = getLastChild(node);
  2234. }
  2235. if (onStartIndex && start === i) {
  2236. onStartIndex(tree, node);
  2237. }
  2238. if (onEndIndex && end === i) {
  2239. onEndIndex(tree, node);
  2240. }
  2241. }
  2242. if (characterFormats) {
  2243. characterFormats.forEach((format, formatIndex) => {
  2244. if (pointer && lastCharacterFormats && // Reuse the last element if all formats remain the same.
  2245. isEqualUntil(characterFormats, lastCharacterFormats, formatIndex) && ( // Do not reuse the last element if the character is a
  2246. // line separator.
  2247. character !== LINE_SEPARATOR || characterFormats.length - 1 !== formatIndex)) {
  2248. pointer = getLastChild(pointer);
  2249. return;
  2250. }
  2251. const {
  2252. type,
  2253. attributes,
  2254. unregisteredAttributes
  2255. } = format;
  2256. const boundaryClass = isEditableTree && character !== LINE_SEPARATOR && format === deepestActiveFormat;
  2257. const parent = getParent(pointer);
  2258. const newNode = append(parent, fromFormat({
  2259. type,
  2260. attributes,
  2261. unregisteredAttributes,
  2262. boundaryClass,
  2263. isEditableTree
  2264. }));
  2265. if (isText(pointer) && getText(pointer).length === 0) {
  2266. remove(pointer);
  2267. }
  2268. pointer = append(newNode, '');
  2269. });
  2270. } // No need for further processing if the character is a line separator.
  2271. if (character === LINE_SEPARATOR) {
  2272. lastCharacterFormats = characterFormats;
  2273. lastCharacter = character;
  2274. continue;
  2275. } // If there is selection at 0, handle it before characters are inserted.
  2276. if (i === 0) {
  2277. if (onStartIndex && start === 0) {
  2278. onStartIndex(tree, pointer);
  2279. }
  2280. if (onEndIndex && end === 0) {
  2281. onEndIndex(tree, pointer);
  2282. }
  2283. }
  2284. if (character === OBJECT_REPLACEMENT_CHARACTER) {
  2285. if (!isEditableTree && replacements[i].type === 'script') {
  2286. pointer = append(getParent(pointer), fromFormat({
  2287. type: 'script',
  2288. isEditableTree
  2289. }));
  2290. append(pointer, {
  2291. html: decodeURIComponent(replacements[i].attributes['data-rich-text-script'])
  2292. });
  2293. } else {
  2294. pointer = append(getParent(pointer), fromFormat({ ...replacements[i],
  2295. object: true,
  2296. isEditableTree
  2297. }));
  2298. } // Ensure pointer is text node.
  2299. pointer = append(getParent(pointer), '');
  2300. } else if (!preserveWhiteSpace && character === '\n') {
  2301. pointer = append(getParent(pointer), {
  2302. type: 'br',
  2303. attributes: isEditableTree ? {
  2304. 'data-rich-text-line-break': 'true'
  2305. } : undefined,
  2306. object: true
  2307. }); // Ensure pointer is text node.
  2308. pointer = append(getParent(pointer), '');
  2309. } else if (!isText(pointer)) {
  2310. pointer = append(getParent(pointer), character);
  2311. } else {
  2312. appendText(pointer, character);
  2313. }
  2314. if (onStartIndex && start === i + 1) {
  2315. onStartIndex(tree, pointer);
  2316. }
  2317. if (onEndIndex && end === i + 1) {
  2318. onEndIndex(tree, pointer);
  2319. }
  2320. if (shouldInsertPadding && i === text.length) {
  2321. append(getParent(pointer), ZWNBSP);
  2322. if (placeholder && text.length === 0) {
  2323. append(getParent(pointer), {
  2324. type: 'span',
  2325. attributes: {
  2326. 'data-rich-text-placeholder': placeholder,
  2327. // Necessary to prevent the placeholder from catching
  2328. // selection. The placeholder is also not editable after
  2329. // all.
  2330. contenteditable: 'false',
  2331. style: 'pointer-events:none;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;'
  2332. }
  2333. });
  2334. }
  2335. }
  2336. lastCharacterFormats = characterFormats;
  2337. lastCharacter = character;
  2338. }
  2339. return tree;
  2340. }
  2341. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-dom.js
  2342. /**
  2343. * Internal dependencies
  2344. */
  2345. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2346. /**
  2347. * Creates a path as an array of indices from the given root node to the given
  2348. * node.
  2349. *
  2350. * @param {Node} node Node to find the path of.
  2351. * @param {HTMLElement} rootNode Root node to find the path from.
  2352. * @param {Array} path Initial path to build on.
  2353. *
  2354. * @return {Array} The path from the root node to the node.
  2355. */
  2356. function createPathToNode(node, rootNode, path) {
  2357. const parentNode = node.parentNode;
  2358. let i = 0;
  2359. while (node = node.previousSibling) {
  2360. i++;
  2361. }
  2362. path = [i, ...path];
  2363. if (parentNode !== rootNode) {
  2364. path = createPathToNode(parentNode, rootNode, path);
  2365. }
  2366. return path;
  2367. }
  2368. /**
  2369. * Gets a node given a path (array of indices) from the given node.
  2370. *
  2371. * @param {HTMLElement} node Root node to find the wanted node in.
  2372. * @param {Array} path Path (indices) to the wanted node.
  2373. *
  2374. * @return {Object} Object with the found node and the remaining offset (if any).
  2375. */
  2376. function getNodeByPath(node, path) {
  2377. path = [...path];
  2378. while (node && path.length > 1) {
  2379. node = node.childNodes[path.shift()];
  2380. }
  2381. return {
  2382. node,
  2383. offset: path[0]
  2384. };
  2385. }
  2386. function to_dom_append(element, child) {
  2387. if (typeof child === 'string') {
  2388. child = element.ownerDocument.createTextNode(child);
  2389. }
  2390. const {
  2391. type,
  2392. attributes
  2393. } = child;
  2394. if (type) {
  2395. child = element.ownerDocument.createElement(type);
  2396. for (const key in attributes) {
  2397. child.setAttribute(key, attributes[key]);
  2398. }
  2399. }
  2400. return element.appendChild(child);
  2401. }
  2402. function to_dom_appendText(node, text) {
  2403. node.appendData(text);
  2404. }
  2405. function to_dom_getLastChild({
  2406. lastChild
  2407. }) {
  2408. return lastChild;
  2409. }
  2410. function to_dom_getParent({
  2411. parentNode
  2412. }) {
  2413. return parentNode;
  2414. }
  2415. function to_dom_isText(node) {
  2416. return node.nodeType === node.TEXT_NODE;
  2417. }
  2418. function to_dom_getText({
  2419. nodeValue
  2420. }) {
  2421. return nodeValue;
  2422. }
  2423. function to_dom_remove(node) {
  2424. return node.parentNode.removeChild(node);
  2425. }
  2426. function toDom({
  2427. value,
  2428. multilineTag,
  2429. prepareEditableTree,
  2430. isEditableTree = true,
  2431. placeholder,
  2432. doc = document
  2433. }) {
  2434. let startPath = [];
  2435. let endPath = [];
  2436. if (prepareEditableTree) {
  2437. value = { ...value,
  2438. formats: prepareEditableTree(value)
  2439. };
  2440. }
  2441. /**
  2442. * Returns a new instance of a DOM tree upon which RichText operations can be
  2443. * applied.
  2444. *
  2445. * Note: The current implementation will return a shared reference, reset on
  2446. * each call to `createEmpty`. Therefore, you should not hold a reference to
  2447. * the value to operate upon asynchronously, as it may have unexpected results.
  2448. *
  2449. * @return {Object} RichText tree.
  2450. */
  2451. const createEmpty = () => createElement(doc, '');
  2452. const tree = toTree({
  2453. value,
  2454. multilineTag,
  2455. createEmpty,
  2456. append: to_dom_append,
  2457. getLastChild: to_dom_getLastChild,
  2458. getParent: to_dom_getParent,
  2459. isText: to_dom_isText,
  2460. getText: to_dom_getText,
  2461. remove: to_dom_remove,
  2462. appendText: to_dom_appendText,
  2463. onStartIndex(body, pointer) {
  2464. startPath = createPathToNode(pointer, body, [pointer.nodeValue.length]);
  2465. },
  2466. onEndIndex(body, pointer) {
  2467. endPath = createPathToNode(pointer, body, [pointer.nodeValue.length]);
  2468. },
  2469. isEditableTree,
  2470. placeholder
  2471. });
  2472. return {
  2473. body: tree,
  2474. selection: {
  2475. startPath,
  2476. endPath
  2477. }
  2478. };
  2479. }
  2480. /**
  2481. * Create an `Element` tree from a Rich Text value and applies the difference to
  2482. * the `Element` tree contained by `current`. If a `multilineTag` is provided,
  2483. * text separated by two new lines will be wrapped in an `Element` of that type.
  2484. *
  2485. * @param {Object} $1 Named arguments.
  2486. * @param {RichTextValue} $1.value Value to apply.
  2487. * @param {HTMLElement} $1.current The live root node to apply the element tree to.
  2488. * @param {string} [$1.multilineTag] Multiline tag.
  2489. * @param {Function} [$1.prepareEditableTree] Function to filter editorable formats.
  2490. * @param {boolean} [$1.__unstableDomOnly] Only apply elements, no selection.
  2491. * @param {string} [$1.placeholder] Placeholder text.
  2492. */
  2493. function apply({
  2494. value,
  2495. current,
  2496. multilineTag,
  2497. prepareEditableTree,
  2498. __unstableDomOnly,
  2499. placeholder
  2500. }) {
  2501. // Construct a new element tree in memory.
  2502. const {
  2503. body,
  2504. selection
  2505. } = toDom({
  2506. value,
  2507. multilineTag,
  2508. prepareEditableTree,
  2509. placeholder,
  2510. doc: current.ownerDocument
  2511. });
  2512. applyValue(body, current);
  2513. if (value.start !== undefined && !__unstableDomOnly) {
  2514. applySelection(selection, current);
  2515. }
  2516. }
  2517. function applyValue(future, current) {
  2518. let i = 0;
  2519. let futureChild;
  2520. while (futureChild = future.firstChild) {
  2521. const currentChild = current.childNodes[i];
  2522. if (!currentChild) {
  2523. current.appendChild(futureChild);
  2524. } else if (!currentChild.isEqualNode(futureChild)) {
  2525. if (currentChild.nodeName !== futureChild.nodeName || currentChild.nodeType === currentChild.TEXT_NODE && currentChild.data !== futureChild.data) {
  2526. current.replaceChild(futureChild, currentChild);
  2527. } else {
  2528. const currentAttributes = currentChild.attributes;
  2529. const futureAttributes = futureChild.attributes;
  2530. if (currentAttributes) {
  2531. let ii = currentAttributes.length; // Reverse loop because `removeAttribute` on `currentChild`
  2532. // changes `currentAttributes`.
  2533. while (ii--) {
  2534. const {
  2535. name
  2536. } = currentAttributes[ii];
  2537. if (!futureChild.getAttribute(name)) {
  2538. currentChild.removeAttribute(name);
  2539. }
  2540. }
  2541. }
  2542. if (futureAttributes) {
  2543. for (let ii = 0; ii < futureAttributes.length; ii++) {
  2544. const {
  2545. name,
  2546. value
  2547. } = futureAttributes[ii];
  2548. if (currentChild.getAttribute(name) !== value) {
  2549. currentChild.setAttribute(name, value);
  2550. }
  2551. }
  2552. }
  2553. applyValue(futureChild, currentChild);
  2554. future.removeChild(futureChild);
  2555. }
  2556. } else {
  2557. future.removeChild(futureChild);
  2558. }
  2559. i++;
  2560. }
  2561. while (current.childNodes[i]) {
  2562. current.removeChild(current.childNodes[i]);
  2563. }
  2564. }
  2565. /**
  2566. * Returns true if two ranges are equal, or false otherwise. Ranges are
  2567. * considered equal if their start and end occur in the same container and
  2568. * offset.
  2569. *
  2570. * @param {Range} a First range object to test.
  2571. * @param {Range} b First range object to test.
  2572. *
  2573. * @return {boolean} Whether the two ranges are equal.
  2574. */
  2575. function isRangeEqual(a, b) {
  2576. return a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset;
  2577. }
  2578. function applySelection({
  2579. startPath,
  2580. endPath
  2581. }, current) {
  2582. const {
  2583. node: startContainer,
  2584. offset: startOffset
  2585. } = getNodeByPath(current, startPath);
  2586. const {
  2587. node: endContainer,
  2588. offset: endOffset
  2589. } = getNodeByPath(current, endPath);
  2590. const {
  2591. ownerDocument
  2592. } = current;
  2593. const {
  2594. defaultView
  2595. } = ownerDocument;
  2596. const selection = defaultView.getSelection();
  2597. const range = ownerDocument.createRange();
  2598. range.setStart(startContainer, startOffset);
  2599. range.setEnd(endContainer, endOffset);
  2600. const {
  2601. activeElement
  2602. } = ownerDocument;
  2603. if (selection.rangeCount > 0) {
  2604. // If the to be added range and the live range are the same, there's no
  2605. // need to remove the live range and add the equivalent range.
  2606. if (isRangeEqual(range, selection.getRangeAt(0))) {
  2607. return;
  2608. }
  2609. selection.removeAllRanges();
  2610. }
  2611. selection.addRange(range); // This function is not intended to cause a shift in focus. Since the above
  2612. // selection manipulations may shift focus, ensure that focus is restored to
  2613. // its previous state.
  2614. if (activeElement !== ownerDocument.activeElement) {
  2615. // The `instanceof` checks protect against edge cases where the focused
  2616. // element is not of the interface HTMLElement (does not have a `focus`
  2617. // or `blur` property).
  2618. //
  2619. // See: https://github.com/Microsoft/TypeScript/issues/5901#issuecomment-431649653
  2620. if (activeElement instanceof defaultView.HTMLElement) {
  2621. activeElement.focus();
  2622. }
  2623. }
  2624. }
  2625. // EXTERNAL MODULE: external ["wp","escapeHtml"]
  2626. var external_wp_escapeHtml_ = __webpack_require__("Vx3V");
  2627. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-html-string.js
  2628. /**
  2629. * WordPress dependencies
  2630. */
  2631. /**
  2632. * Internal dependencies
  2633. */
  2634. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2635. /**
  2636. * Create an HTML string from a Rich Text value. If a `multilineTag` is
  2637. * provided, text separated by a line separator will be wrapped in it.
  2638. *
  2639. * @param {Object} $1 Named argements.
  2640. * @param {RichTextValue} $1.value Rich text value.
  2641. * @param {string} [$1.multilineTag] Multiline tag.
  2642. * @param {boolean} [$1.preserveWhiteSpace] Whether or not to use newline
  2643. * characters for line breaks.
  2644. *
  2645. * @return {string} HTML string.
  2646. */
  2647. function toHTMLString({
  2648. value,
  2649. multilineTag,
  2650. preserveWhiteSpace
  2651. }) {
  2652. const tree = toTree({
  2653. value,
  2654. multilineTag,
  2655. preserveWhiteSpace,
  2656. createEmpty: to_html_string_createEmpty,
  2657. append: to_html_string_append,
  2658. getLastChild: to_html_string_getLastChild,
  2659. getParent: to_html_string_getParent,
  2660. isText: to_html_string_isText,
  2661. getText: to_html_string_getText,
  2662. remove: to_html_string_remove,
  2663. appendText: to_html_string_appendText
  2664. });
  2665. return createChildrenHTML(tree.children);
  2666. }
  2667. function to_html_string_createEmpty() {
  2668. return {};
  2669. }
  2670. function to_html_string_getLastChild({
  2671. children
  2672. }) {
  2673. return children && children[children.length - 1];
  2674. }
  2675. function to_html_string_append(parent, object) {
  2676. if (typeof object === 'string') {
  2677. object = {
  2678. text: object
  2679. };
  2680. }
  2681. object.parent = parent;
  2682. parent.children = parent.children || [];
  2683. parent.children.push(object);
  2684. return object;
  2685. }
  2686. function to_html_string_appendText(object, text) {
  2687. object.text += text;
  2688. }
  2689. function to_html_string_getParent({
  2690. parent
  2691. }) {
  2692. return parent;
  2693. }
  2694. function to_html_string_isText({
  2695. text
  2696. }) {
  2697. return typeof text === 'string';
  2698. }
  2699. function to_html_string_getText({
  2700. text
  2701. }) {
  2702. return text;
  2703. }
  2704. function to_html_string_remove(object) {
  2705. const index = object.parent.children.indexOf(object);
  2706. if (index !== -1) {
  2707. object.parent.children.splice(index, 1);
  2708. }
  2709. return object;
  2710. }
  2711. function createElementHTML({
  2712. type,
  2713. attributes,
  2714. object,
  2715. children
  2716. }) {
  2717. let attributeString = '';
  2718. for (const key in attributes) {
  2719. if (!Object(external_wp_escapeHtml_["isValidAttributeName"])(key)) {
  2720. continue;
  2721. }
  2722. attributeString += ` ${key}="${Object(external_wp_escapeHtml_["escapeAttribute"])(attributes[key])}"`;
  2723. }
  2724. if (object) {
  2725. return `<${type}${attributeString}>`;
  2726. }
  2727. return `<${type}${attributeString}>${createChildrenHTML(children)}</${type}>`;
  2728. }
  2729. function createChildrenHTML(children = []) {
  2730. return children.map(child => {
  2731. if (child.html !== undefined) {
  2732. return child.html;
  2733. }
  2734. return child.text === undefined ? createElementHTML(child) : Object(external_wp_escapeHtml_["escapeEditableHTML"])(child.text);
  2735. }).join('');
  2736. }
  2737. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/toggle-format.js
  2738. /**
  2739. * Internal dependencies
  2740. */
  2741. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2742. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  2743. /**
  2744. * Toggles a format object to a Rich Text value at the current selection.
  2745. *
  2746. * @param {RichTextValue} value Value to modify.
  2747. * @param {RichTextFormat} format Format to apply or remove.
  2748. *
  2749. * @return {RichTextValue} A new value with the format applied or removed.
  2750. */
  2751. function toggleFormat(value, format) {
  2752. if (getActiveFormat(value, format.type)) {
  2753. return removeFormat(value, format.type);
  2754. }
  2755. return applyFormat(value, format);
  2756. }
  2757. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js
  2758. /**
  2759. * WordPress dependencies
  2760. */
  2761. /**
  2762. * Internal dependencies
  2763. */
  2764. /** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */
  2765. /**
  2766. * Unregisters a format.
  2767. *
  2768. * @param {string} name Format name.
  2769. *
  2770. * @return {RichTextFormatType|undefined} The previous format value, if it has
  2771. * been successfully unregistered;
  2772. * otherwise `undefined`.
  2773. */
  2774. function unregisterFormatType(name) {
  2775. const oldFormat = Object(external_wp_data_["select"])(store).getFormatType(name);
  2776. if (!oldFormat) {
  2777. window.console.error(`Format ${name} is not registered.`);
  2778. return;
  2779. }
  2780. Object(external_wp_data_["dispatch"])(store).removeFormatTypes(name);
  2781. return oldFormat;
  2782. }
  2783. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/can-indent-list-items.js
  2784. /**
  2785. * Internal dependencies
  2786. */
  2787. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2788. /**
  2789. * Checks if the selected list item can be indented.
  2790. *
  2791. * @param {RichTextValue} value Value to check.
  2792. *
  2793. * @return {boolean} Whether or not the selected list item can be indented.
  2794. */
  2795. function canIndentListItems(value) {
  2796. const lineIndex = getLineIndex(value); // There is only one line, so the line cannot be indented.
  2797. if (lineIndex === undefined) {
  2798. return false;
  2799. }
  2800. const {
  2801. replacements
  2802. } = value;
  2803. const previousLineIndex = getLineIndex(value, lineIndex);
  2804. const formatsAtLineIndex = replacements[lineIndex] || [];
  2805. const formatsAtPreviousLineIndex = replacements[previousLineIndex] || []; // If the indentation of the current line is greater than previous line,
  2806. // then the line cannot be furter indented.
  2807. return formatsAtLineIndex.length <= formatsAtPreviousLineIndex.length;
  2808. }
  2809. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/can-outdent-list-items.js
  2810. /**
  2811. * Internal dependencies
  2812. */
  2813. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2814. /**
  2815. * Checks if the selected list item can be outdented.
  2816. *
  2817. * @param {RichTextValue} value Value to check.
  2818. *
  2819. * @return {boolean} Whether or not the selected list item can be outdented.
  2820. */
  2821. function canOutdentListItems(value) {
  2822. const {
  2823. replacements,
  2824. start
  2825. } = value;
  2826. const startingLineIndex = getLineIndex(value, start);
  2827. return replacements[startingLineIndex] !== undefined;
  2828. }
  2829. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/indent-list-items.js
  2830. /**
  2831. * Internal dependencies
  2832. */
  2833. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2834. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  2835. /**
  2836. * Gets the line index of the first previous list item with higher indentation.
  2837. *
  2838. * @param {RichTextValue} value Value to search.
  2839. * @param {number} lineIndex Line index of the list item to compare
  2840. * with.
  2841. *
  2842. * @return {number|void} The line index.
  2843. */
  2844. function getTargetLevelLineIndex({
  2845. text,
  2846. replacements
  2847. }, lineIndex) {
  2848. const startFormats = replacements[lineIndex] || [];
  2849. let index = lineIndex;
  2850. while (index-- >= 0) {
  2851. if (text[index] !== LINE_SEPARATOR) {
  2852. continue;
  2853. }
  2854. const formatsAtIndex = replacements[index] || []; // Return the first line index that is one level higher. If the level is
  2855. // lower or equal, there is no result.
  2856. if (formatsAtIndex.length === startFormats.length + 1) {
  2857. return index;
  2858. } else if (formatsAtIndex.length <= startFormats.length) {
  2859. return;
  2860. }
  2861. }
  2862. }
  2863. /**
  2864. * Indents any selected list items if possible.
  2865. *
  2866. * @param {RichTextValue} value Value to change.
  2867. * @param {RichTextFormat} rootFormat Root format.
  2868. *
  2869. * @return {RichTextValue} The changed value.
  2870. */
  2871. function indentListItems(value, rootFormat) {
  2872. if (!canIndentListItems(value)) {
  2873. return value;
  2874. }
  2875. const lineIndex = getLineIndex(value);
  2876. const previousLineIndex = getLineIndex(value, lineIndex);
  2877. const {
  2878. text,
  2879. replacements,
  2880. end
  2881. } = value;
  2882. const newFormats = replacements.slice();
  2883. const targetLevelLineIndex = getTargetLevelLineIndex(value, lineIndex);
  2884. for (let index = lineIndex; index < end; index++) {
  2885. if (text[index] !== LINE_SEPARATOR) {
  2886. continue;
  2887. } // Get the previous list, and if there's a child list, take over the
  2888. // formats. If not, duplicate the last level and create a new level.
  2889. if (targetLevelLineIndex) {
  2890. const targetFormats = replacements[targetLevelLineIndex] || [];
  2891. newFormats[index] = targetFormats.concat((newFormats[index] || []).slice(targetFormats.length - 1));
  2892. } else {
  2893. const targetFormats = replacements[previousLineIndex] || [];
  2894. const lastformat = targetFormats[targetFormats.length - 1] || rootFormat;
  2895. newFormats[index] = targetFormats.concat([lastformat], (newFormats[index] || []).slice(targetFormats.length));
  2896. }
  2897. }
  2898. return { ...value,
  2899. replacements: newFormats
  2900. };
  2901. }
  2902. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-parent-line-index.js
  2903. /**
  2904. * Internal dependencies
  2905. */
  2906. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2907. /**
  2908. * Gets the index of the first parent list. To get the parent list formats, we
  2909. * go through every list item until we find one with exactly one format type
  2910. * less.
  2911. *
  2912. * @param {RichTextValue} value Value to search.
  2913. * @param {number} lineIndex Line index of a child list item.
  2914. *
  2915. * @return {number|void} The parent list line index.
  2916. */
  2917. function getParentLineIndex({
  2918. text,
  2919. replacements
  2920. }, lineIndex) {
  2921. const startFormats = replacements[lineIndex] || [];
  2922. let index = lineIndex;
  2923. while (index-- >= 0) {
  2924. if (text[index] !== LINE_SEPARATOR) {
  2925. continue;
  2926. }
  2927. const formatsAtIndex = replacements[index] || [];
  2928. if (formatsAtIndex.length === startFormats.length - 1) {
  2929. return index;
  2930. }
  2931. }
  2932. }
  2933. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-last-child-index.js
  2934. /**
  2935. * Internal dependencies
  2936. */
  2937. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2938. /**
  2939. * Gets the line index of the last child in the list.
  2940. *
  2941. * @param {RichTextValue} value Value to search.
  2942. * @param {number} lineIndex Line index of a list item in the list.
  2943. *
  2944. * @return {number} The index of the last child.
  2945. */
  2946. function getLastChildIndex({
  2947. text,
  2948. replacements
  2949. }, lineIndex) {
  2950. const lineFormats = replacements[lineIndex] || []; // Use the given line index in case there are no next children.
  2951. let childIndex = lineIndex; // `lineIndex` could be `undefined` if it's the first line.
  2952. for (let index = lineIndex || 0; index < text.length; index++) {
  2953. // We're only interested in line indices.
  2954. if (text[index] !== LINE_SEPARATOR) {
  2955. continue;
  2956. }
  2957. const formatsAtIndex = replacements[index] || []; // If the amout of formats is equal or more, store it, then return the
  2958. // last one if the amount of formats is less.
  2959. if (formatsAtIndex.length >= lineFormats.length) {
  2960. childIndex = index;
  2961. } else {
  2962. return childIndex;
  2963. }
  2964. } // If the end of the text is reached, return the last child index.
  2965. return childIndex;
  2966. }
  2967. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/outdent-list-items.js
  2968. /**
  2969. * Internal dependencies
  2970. */
  2971. /** @typedef {import('./create').RichTextValue} RichTextValue */
  2972. /**
  2973. * Outdents any selected list items if possible.
  2974. *
  2975. * @param {RichTextValue} value Value to change.
  2976. *
  2977. * @return {RichTextValue} The changed value.
  2978. */
  2979. function outdentListItems(value) {
  2980. if (!canOutdentListItems(value)) {
  2981. return value;
  2982. }
  2983. const {
  2984. text,
  2985. replacements,
  2986. start,
  2987. end
  2988. } = value;
  2989. const startingLineIndex = getLineIndex(value, start);
  2990. const newFormats = replacements.slice(0);
  2991. const parentFormats = replacements[getParentLineIndex(value, startingLineIndex)] || [];
  2992. const endingLineIndex = getLineIndex(value, end);
  2993. const lastChildIndex = getLastChildIndex(value, endingLineIndex); // Outdent all list items from the starting line index until the last child
  2994. // index of the ending list. All children of the ending list need to be
  2995. // outdented, otherwise they'll be orphaned.
  2996. for (let index = startingLineIndex; index <= lastChildIndex; index++) {
  2997. // Skip indices that are not line separators.
  2998. if (text[index] !== LINE_SEPARATOR) {
  2999. continue;
  3000. } // In the case of level 0, the formats at the index are undefined.
  3001. const currentFormats = newFormats[index] || []; // Omit the indentation level where the selection starts.
  3002. newFormats[index] = parentFormats.concat(currentFormats.slice(parentFormats.length + 1));
  3003. if (newFormats[index].length === 0) {
  3004. delete newFormats[index];
  3005. }
  3006. }
  3007. return { ...value,
  3008. replacements: newFormats
  3009. };
  3010. }
  3011. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/change-list-type.js
  3012. /**
  3013. * Internal dependencies
  3014. */
  3015. /** @typedef {import('./create').RichTextValue} RichTextValue */
  3016. /** @typedef {import('./create').RichTextFormat} RichTextFormat */
  3017. /**
  3018. * Changes the list type of the selected indented list, if any. Looks at the
  3019. * currently selected list item and takes the parent list, then changes the list
  3020. * type of this list. When multiple lines are selected, the parent lists are
  3021. * takes and changed.
  3022. *
  3023. * @param {RichTextValue} value Value to change.
  3024. * @param {RichTextFormat} newFormat The new list format object. Choose between
  3025. * `{ type: 'ol' }` and `{ type: 'ul' }`.
  3026. *
  3027. * @return {RichTextValue} The changed value.
  3028. */
  3029. function changeListType(value, newFormat) {
  3030. const {
  3031. text,
  3032. replacements,
  3033. start,
  3034. end
  3035. } = value;
  3036. const startingLineIndex = getLineIndex(value, start);
  3037. const startLineFormats = replacements[startingLineIndex] || [];
  3038. const endLineFormats = replacements[getLineIndex(value, end)] || [];
  3039. const startIndex = getParentLineIndex(value, startingLineIndex);
  3040. const newReplacements = replacements.slice();
  3041. const startCount = startLineFormats.length - 1;
  3042. const endCount = endLineFormats.length - 1;
  3043. let changed;
  3044. for (let index = startIndex + 1 || 0; index < text.length; index++) {
  3045. if (text[index] !== LINE_SEPARATOR) {
  3046. continue;
  3047. }
  3048. if ((newReplacements[index] || []).length <= startCount) {
  3049. break;
  3050. }
  3051. if (!newReplacements[index]) {
  3052. continue;
  3053. }
  3054. changed = true;
  3055. newReplacements[index] = newReplacements[index].map((format, i) => {
  3056. return i < startCount || i > endCount ? format : newFormat;
  3057. });
  3058. }
  3059. if (!changed) {
  3060. return value;
  3061. }
  3062. return { ...value,
  3063. replacements: newReplacements
  3064. };
  3065. }
  3066. // EXTERNAL MODULE: external ["wp","element"]
  3067. var external_wp_element_ = __webpack_require__("GRId");
  3068. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js
  3069. /**
  3070. * WordPress dependencies
  3071. */
  3072. /**
  3073. * Internal dependencies
  3074. */
  3075. /** @typedef {import('@wordpress/element').RefObject} RefObject */
  3076. /** @typedef {import('../register-format-type').RichTextFormatType} RichTextFormatType */
  3077. /** @typedef {import('../create').RichTextValue} RichTextValue */
  3078. /**
  3079. * This hook, to be used in a format type's Edit component, returns the active
  3080. * element that is formatted, or the selection range if no format is active.
  3081. * The returned value is meant to be used for positioning UI, e.g. by passing it
  3082. * to the `Popover` component.
  3083. *
  3084. * @param {Object} $1 Named parameters.
  3085. * @param {RefObject<HTMLElement>} $1.ref React ref of the element
  3086. * containing the editable content.
  3087. * @param {RichTextValue} $1.value Value to check for selection.
  3088. * @param {RichTextFormatType} $1.settings The format type's settings.
  3089. *
  3090. * @return {Element|Range} The active element or selection range.
  3091. */
  3092. function useAnchorRef({
  3093. ref,
  3094. value,
  3095. settings = {}
  3096. }) {
  3097. const {
  3098. tagName,
  3099. className,
  3100. name
  3101. } = settings;
  3102. const activeFormat = name ? getActiveFormat(value, name) : undefined;
  3103. return Object(external_wp_element_["useMemo"])(() => {
  3104. if (!ref.current) return;
  3105. const {
  3106. ownerDocument: {
  3107. defaultView
  3108. }
  3109. } = ref.current;
  3110. const selection = defaultView.getSelection();
  3111. if (!selection.rangeCount) {
  3112. return;
  3113. }
  3114. const range = selection.getRangeAt(0);
  3115. if (!activeFormat) {
  3116. return range;
  3117. }
  3118. let element = range.startContainer; // If the caret is right before the element, select the next element.
  3119. element = element.nextElementSibling || element;
  3120. while (element.nodeType !== element.ELEMENT_NODE) {
  3121. element = element.parentNode;
  3122. }
  3123. return element.closest(tagName + (className ? '.' + className : ''));
  3124. }, [activeFormat, value.start, value.end, tagName, className]);
  3125. }
  3126. // EXTERNAL MODULE: external ["wp","compose"]
  3127. var external_wp_compose_ = __webpack_require__("K9lf");
  3128. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js
  3129. /**
  3130. * WordPress dependencies
  3131. */
  3132. /**
  3133. * In HTML, leading and trailing spaces are not visible, and multiple spaces
  3134. * elsewhere are visually reduced to one space. This rule prevents spaces from
  3135. * collapsing so all space is visible in the editor and can be removed. It also
  3136. * prevents some browsers from inserting non-breaking spaces at the end of a
  3137. * line to prevent the space from visually disappearing. Sometimes these non
  3138. * breaking spaces can linger in the editor causing unwanted non breaking spaces
  3139. * in between words. If also prevent Firefox from inserting a trailing `br` node
  3140. * to visualise any trailing space, causing the element to be saved.
  3141. *
  3142. * > Authors are encouraged to set the 'white-space' property on editing hosts
  3143. * > and on markup that was originally created through these editing mechanisms
  3144. * > to the value 'pre-wrap'. Default HTML whitespace handling is not well
  3145. * > suited to WYSIWYG editing, and line wrapping will not work correctly in
  3146. * > some corner cases if 'white-space' is left at its default value.
  3147. *
  3148. * https://html.spec.whatwg.org/multipage/interaction.html#best-practices-for-in-page-editors
  3149. *
  3150. * @type {string}
  3151. */
  3152. const whiteSpace = 'pre-wrap';
  3153. /**
  3154. * A minimum width of 1px will prevent the rich text container from collapsing
  3155. * to 0 width and hiding the caret. This is useful for inline containers.
  3156. */
  3157. const minWidth = '1px';
  3158. function useDefaultStyle() {
  3159. return Object(external_wp_element_["useCallback"])(element => {
  3160. if (!element) return;
  3161. element.style.whiteSpace = whiteSpace;
  3162. element.style.minWidth = minWidth;
  3163. }, []);
  3164. }
  3165. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js
  3166. /**
  3167. * WordPress dependencies
  3168. */
  3169. /*
  3170. * Calculates and renders the format boundary style when the active formats
  3171. * change.
  3172. */
  3173. function useBoundaryStyle({
  3174. record
  3175. }) {
  3176. const ref = Object(external_wp_element_["useRef"])();
  3177. const {
  3178. activeFormats = []
  3179. } = record.current;
  3180. Object(external_wp_element_["useEffect"])(() => {
  3181. // There's no need to recalculate the boundary styles if no formats are
  3182. // active, because no boundary styles will be visible.
  3183. if (!activeFormats || !activeFormats.length) {
  3184. return;
  3185. }
  3186. const boundarySelector = '*[data-rich-text-format-boundary]';
  3187. const element = ref.current.querySelector(boundarySelector);
  3188. if (!element) {
  3189. return;
  3190. }
  3191. const {
  3192. ownerDocument
  3193. } = element;
  3194. const {
  3195. defaultView
  3196. } = ownerDocument;
  3197. const computedStyle = defaultView.getComputedStyle(element);
  3198. const newColor = computedStyle.color.replace(')', ', 0.2)').replace('rgb', 'rgba');
  3199. const selector = `.rich-text:focus ${boundarySelector}`;
  3200. const rule = `background-color: ${newColor}`;
  3201. const style = `${selector} {${rule}}`;
  3202. const globalStyleId = 'rich-text-boundary-style';
  3203. let globalStyle = ownerDocument.getElementById(globalStyleId);
  3204. if (!globalStyle) {
  3205. globalStyle = ownerDocument.createElement('style');
  3206. globalStyle.id = globalStyleId;
  3207. ownerDocument.head.appendChild(globalStyle);
  3208. }
  3209. if (globalStyle.innerHTML !== style) {
  3210. globalStyle.innerHTML = style;
  3211. }
  3212. }, [activeFormats]);
  3213. return ref;
  3214. }
  3215. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-inline-warning.js
  3216. /**
  3217. * WordPress dependencies
  3218. */
  3219. const message = 'RichText cannot be used with an inline container. Please use a different display property.';
  3220. function useInlineWarning() {
  3221. const ref = Object(external_wp_element_["useRef"])();
  3222. Object(external_wp_element_["useEffect"])(() => {
  3223. if (false) {}
  3224. }, []);
  3225. return ref;
  3226. }
  3227. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-copy-handler.js
  3228. /**
  3229. * WordPress dependencies
  3230. */
  3231. /**
  3232. * Internal dependencies
  3233. */
  3234. function useCopyHandler(props) {
  3235. const propsRef = Object(external_wp_element_["useRef"])(props);
  3236. propsRef.current = props;
  3237. return Object(external_wp_compose_["useRefEffect"])(element => {
  3238. function onCopy(event) {
  3239. const {
  3240. record,
  3241. multilineTag,
  3242. preserveWhiteSpace
  3243. } = propsRef.current;
  3244. if (isCollapsed(record.current) || !element.contains(element.ownerDocument.activeElement)) {
  3245. return;
  3246. }
  3247. const selectedRecord = slice(record.current);
  3248. const plainText = getTextContent(selectedRecord);
  3249. const html = toHTMLString({
  3250. value: selectedRecord,
  3251. multilineTag,
  3252. preserveWhiteSpace
  3253. });
  3254. event.clipboardData.setData('text/plain', plainText);
  3255. event.clipboardData.setData('text/html', html);
  3256. event.clipboardData.setData('rich-text', 'true');
  3257. event.preventDefault();
  3258. }
  3259. element.addEventListener('copy', onCopy);
  3260. return () => {
  3261. element.removeEventListener('copy', onCopy);
  3262. };
  3263. }, []);
  3264. }
  3265. // EXTERNAL MODULE: external ["wp","keycodes"]
  3266. var external_wp_keycodes_ = __webpack_require__("RxS6");
  3267. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-format-boundaries.js
  3268. /**
  3269. * WordPress dependencies
  3270. */
  3271. /**
  3272. * Internal dependencies
  3273. */
  3274. const EMPTY_ACTIVE_FORMATS = [];
  3275. function useFormatBoundaries(props) {
  3276. const [, forceRender] = Object(external_wp_element_["useReducer"])(() => ({}));
  3277. const propsRef = Object(external_wp_element_["useRef"])(props);
  3278. propsRef.current = props;
  3279. return Object(external_wp_compose_["useRefEffect"])(element => {
  3280. function onKeyDown(event) {
  3281. const {
  3282. keyCode,
  3283. shiftKey,
  3284. altKey,
  3285. metaKey,
  3286. ctrlKey
  3287. } = event;
  3288. if ( // Only override left and right keys without modifiers pressed.
  3289. shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_wp_keycodes_["LEFT"] && keyCode !== external_wp_keycodes_["RIGHT"]) {
  3290. return;
  3291. }
  3292. const {
  3293. record,
  3294. applyRecord
  3295. } = propsRef.current;
  3296. const {
  3297. text,
  3298. formats,
  3299. start,
  3300. end,
  3301. activeFormats: currentActiveFormats = []
  3302. } = record.current;
  3303. const collapsed = isCollapsed(record.current);
  3304. const {
  3305. ownerDocument
  3306. } = element;
  3307. const {
  3308. defaultView
  3309. } = ownerDocument; // To do: ideally, we should look at visual position instead.
  3310. const {
  3311. direction
  3312. } = defaultView.getComputedStyle(element);
  3313. const reverseKey = direction === 'rtl' ? external_wp_keycodes_["RIGHT"] : external_wp_keycodes_["LEFT"];
  3314. const isReverse = event.keyCode === reverseKey; // If the selection is collapsed and at the very start, do nothing if
  3315. // navigating backward.
  3316. // If the selection is collapsed and at the very end, do nothing if
  3317. // navigating forward.
  3318. if (collapsed && currentActiveFormats.length === 0) {
  3319. if (start === 0 && isReverse) {
  3320. return;
  3321. }
  3322. if (end === text.length && !isReverse) {
  3323. return;
  3324. }
  3325. } // If the selection is not collapsed, let the browser handle collapsing
  3326. // the selection for now. Later we could expand this logic to set
  3327. // boundary positions if needed.
  3328. if (!collapsed) {
  3329. return;
  3330. }
  3331. const formatsBefore = formats[start - 1] || EMPTY_ACTIVE_FORMATS;
  3332. const formatsAfter = formats[start] || EMPTY_ACTIVE_FORMATS;
  3333. let newActiveFormatsLength = currentActiveFormats.length;
  3334. let source = formatsAfter;
  3335. if (formatsBefore.length > formatsAfter.length) {
  3336. source = formatsBefore;
  3337. } // If the amount of formats before the caret and after the caret is
  3338. // different, the caret is at a format boundary.
  3339. if (formatsBefore.length < formatsAfter.length) {
  3340. if (!isReverse && currentActiveFormats.length < formatsAfter.length) {
  3341. newActiveFormatsLength++;
  3342. }
  3343. if (isReverse && currentActiveFormats.length > formatsBefore.length) {
  3344. newActiveFormatsLength--;
  3345. }
  3346. } else if (formatsBefore.length > formatsAfter.length) {
  3347. if (!isReverse && currentActiveFormats.length > formatsAfter.length) {
  3348. newActiveFormatsLength--;
  3349. }
  3350. if (isReverse && currentActiveFormats.length < formatsBefore.length) {
  3351. newActiveFormatsLength++;
  3352. }
  3353. }
  3354. if (newActiveFormatsLength === currentActiveFormats.length) {
  3355. record.current._newActiveFormats = isReverse ? formatsBefore : formatsAfter;
  3356. return;
  3357. }
  3358. event.preventDefault();
  3359. const newActiveFormats = source.slice(0, newActiveFormatsLength);
  3360. const newValue = { ...record.current,
  3361. activeFormats: newActiveFormats
  3362. };
  3363. record.current = newValue;
  3364. applyRecord(newValue);
  3365. forceRender();
  3366. }
  3367. element.addEventListener('keydown', onKeyDown);
  3368. return () => {
  3369. element.removeEventListener('keydown', onKeyDown);
  3370. };
  3371. }, []);
  3372. }
  3373. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-select-object.js
  3374. /**
  3375. * WordPress dependencies
  3376. */
  3377. function useSelectObject() {
  3378. return Object(external_wp_compose_["useRefEffect"])(element => {
  3379. function onClick(event) {
  3380. const {
  3381. target
  3382. } = event; // If the child element has no text content, it must be an object.
  3383. if (target === element || target.textContent) {
  3384. return;
  3385. }
  3386. const {
  3387. ownerDocument
  3388. } = target;
  3389. const {
  3390. defaultView
  3391. } = ownerDocument;
  3392. const range = ownerDocument.createRange();
  3393. const selection = defaultView.getSelection();
  3394. range.selectNode(target);
  3395. selection.removeAllRanges();
  3396. selection.addRange(range);
  3397. }
  3398. element.addEventListener('click', onClick);
  3399. return () => {
  3400. element.removeEventListener('click', onClick);
  3401. };
  3402. }, []);
  3403. }
  3404. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-indent-list-item-on-space.js
  3405. /**
  3406. * WordPress dependencies
  3407. */
  3408. /**
  3409. * Internal dependencies
  3410. */
  3411. function useIndentListItemOnSpace(props) {
  3412. const propsRef = Object(external_wp_element_["useRef"])(props);
  3413. propsRef.current = props;
  3414. return Object(external_wp_compose_["useRefEffect"])(element => {
  3415. function onKeyDown(event) {
  3416. const {
  3417. keyCode,
  3418. shiftKey,
  3419. altKey,
  3420. metaKey,
  3421. ctrlKey
  3422. } = event;
  3423. const {
  3424. multilineTag,
  3425. createRecord,
  3426. handleChange
  3427. } = propsRef.current;
  3428. if ( // Only override when no modifiers are pressed.
  3429. shiftKey || altKey || metaKey || ctrlKey || keyCode !== external_wp_keycodes_["SPACE"] || multilineTag !== 'li') {
  3430. return;
  3431. }
  3432. const currentValue = createRecord();
  3433. if (!isCollapsed(currentValue)) {
  3434. return;
  3435. }
  3436. const {
  3437. text,
  3438. start
  3439. } = currentValue;
  3440. const characterBefore = text[start - 1]; // The caret must be at the start of a line.
  3441. if (characterBefore && characterBefore !== LINE_SEPARATOR) {
  3442. return;
  3443. }
  3444. handleChange(indentListItems(currentValue, {
  3445. type: element.tagName.toLowerCase()
  3446. }));
  3447. event.preventDefault();
  3448. }
  3449. element.addEventListener('keydown', onKeyDown);
  3450. return () => {
  3451. element.removeEventListener('keydown', onKeyDown);
  3452. };
  3453. }, []);
  3454. }
  3455. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/update-formats.js
  3456. /**
  3457. * Internal dependencies
  3458. */
  3459. /** @typedef {import('./create').RichTextValue} RichTextValue */
  3460. /**
  3461. * Efficiently updates all the formats from `start` (including) until `end`
  3462. * (excluding) with the active formats. Mutates `value`.
  3463. *
  3464. * @param {Object} $1 Named paramentes.
  3465. * @param {RichTextValue} $1.value Value te update.
  3466. * @param {number} $1.start Index to update from.
  3467. * @param {number} $1.end Index to update until.
  3468. * @param {Array} $1.formats Replacement formats.
  3469. *
  3470. * @return {RichTextValue} Mutated value.
  3471. */
  3472. function updateFormats({
  3473. value,
  3474. start,
  3475. end,
  3476. formats
  3477. }) {
  3478. const formatsBefore = value.formats[start - 1] || [];
  3479. const formatsAfter = value.formats[end] || []; // First, fix the references. If any format right before or after are
  3480. // equal, the replacement format should use the same reference.
  3481. value.activeFormats = formats.map((format, index) => {
  3482. if (formatsBefore[index]) {
  3483. if (isFormatEqual(format, formatsBefore[index])) {
  3484. return formatsBefore[index];
  3485. }
  3486. } else if (formatsAfter[index]) {
  3487. if (isFormatEqual(format, formatsAfter[index])) {
  3488. return formatsAfter[index];
  3489. }
  3490. }
  3491. return format;
  3492. });
  3493. while (--end >= start) {
  3494. if (value.activeFormats.length > 0) {
  3495. value.formats[end] = value.activeFormats;
  3496. } else {
  3497. delete value.formats[end];
  3498. }
  3499. }
  3500. return value;
  3501. }
  3502. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-input-and-selection.js
  3503. /**
  3504. * WordPress dependencies
  3505. */
  3506. /**
  3507. * Internal dependencies
  3508. */
  3509. /**
  3510. * All inserting input types that would insert HTML into the DOM.
  3511. *
  3512. * @see https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes
  3513. *
  3514. * @type {Set}
  3515. */
  3516. const INSERTION_INPUT_TYPES_TO_IGNORE = new Set(['insertParagraph', 'insertOrderedList', 'insertUnorderedList', 'insertHorizontalRule', 'insertLink']);
  3517. const use_input_and_selection_EMPTY_ACTIVE_FORMATS = [];
  3518. /**
  3519. * If the selection is set on the placeholder element, collapse the selection to
  3520. * the start (before the placeholder).
  3521. *
  3522. * @param {Window} defaultView
  3523. */
  3524. function fixPlaceholderSelection(defaultView) {
  3525. const selection = defaultView.getSelection();
  3526. const {
  3527. anchorNode,
  3528. anchorOffset
  3529. } = selection;
  3530. if (anchorNode.nodeType !== anchorNode.ELEMENT_NODE) {
  3531. return;
  3532. }
  3533. const targetNode = anchorNode.childNodes[anchorOffset];
  3534. if (!targetNode || targetNode.nodeType !== targetNode.ELEMENT_NODE || !targetNode.getAttribute('data-rich-text-placeholder')) {
  3535. return;
  3536. }
  3537. selection.collapseToStart();
  3538. }
  3539. function useInputAndSelection(props) {
  3540. const propsRef = Object(external_wp_element_["useRef"])(props);
  3541. propsRef.current = props;
  3542. return Object(external_wp_compose_["useRefEffect"])(element => {
  3543. const {
  3544. ownerDocument
  3545. } = element;
  3546. const {
  3547. defaultView
  3548. } = ownerDocument;
  3549. let isComposing = false;
  3550. let rafId;
  3551. function onInput(event) {
  3552. // Do not trigger a change if characters are being composed.
  3553. // Browsers will usually emit a final `input` event when the
  3554. // characters are composed.
  3555. // As of December 2019, Safari doesn't support
  3556. // nativeEvent.isComposing.
  3557. if (isComposing) {
  3558. return;
  3559. }
  3560. let inputType;
  3561. if (event) {
  3562. inputType = event.inputType;
  3563. }
  3564. const {
  3565. record,
  3566. applyRecord,
  3567. createRecord,
  3568. handleChange
  3569. } = propsRef.current; // The browser formatted something or tried to insert HTML.
  3570. // Overwrite it. It will be handled later by the format library if
  3571. // needed.
  3572. if (inputType && (inputType.indexOf('format') === 0 || INSERTION_INPUT_TYPES_TO_IGNORE.has(inputType))) {
  3573. applyRecord(record.current);
  3574. return;
  3575. }
  3576. const currentValue = createRecord();
  3577. const {
  3578. start,
  3579. activeFormats: oldActiveFormats = []
  3580. } = record.current; // Update the formats between the last and new caret position.
  3581. const change = updateFormats({
  3582. value: currentValue,
  3583. start,
  3584. end: currentValue.start,
  3585. formats: oldActiveFormats
  3586. });
  3587. handleChange(change);
  3588. }
  3589. /**
  3590. * Syncs the selection to local state. A callback for the `selectionchange`
  3591. * native events, `keyup`, `mouseup` and `touchend` synthetic events, and
  3592. * animation frames after the `focus` event.
  3593. *
  3594. * @param {Event|DOMHighResTimeStamp} event
  3595. */
  3596. function handleSelectionChange(event) {
  3597. if (ownerDocument.activeElement !== element) {
  3598. return;
  3599. }
  3600. const {
  3601. record,
  3602. applyRecord,
  3603. createRecord,
  3604. isSelected,
  3605. onSelectionChange
  3606. } = propsRef.current;
  3607. if (event.type !== 'selectionchange' && !isSelected) {
  3608. return;
  3609. } // Check if the implementor disabled editing. `contentEditable`
  3610. // does disable input, but not text selection, so we must ignore
  3611. // selection changes.
  3612. if (element.contentEditable !== 'true') {
  3613. return;
  3614. } // In case of a keyboard event, ignore selection changes during
  3615. // composition.
  3616. if (isComposing) {
  3617. return;
  3618. }
  3619. const {
  3620. start,
  3621. end,
  3622. text
  3623. } = createRecord();
  3624. const oldRecord = record.current; // Fallback mechanism for IE11, which doesn't support the input event.
  3625. // Any input results in a selection change.
  3626. if (text !== oldRecord.text) {
  3627. onInput();
  3628. return;
  3629. }
  3630. if (start === oldRecord.start && end === oldRecord.end) {
  3631. // Sometimes the browser may set the selection on the placeholder
  3632. // element, in which case the caret is not visible. We need to set
  3633. // the caret before the placeholder if that's the case.
  3634. if (oldRecord.text.length === 0 && start === 0) {
  3635. fixPlaceholderSelection(defaultView);
  3636. }
  3637. return;
  3638. }
  3639. const newValue = { ...oldRecord,
  3640. start,
  3641. end,
  3642. // _newActiveFormats may be set on arrow key navigation to control
  3643. // the right boundary position. If undefined, getActiveFormats will
  3644. // give the active formats according to the browser.
  3645. activeFormats: oldRecord._newActiveFormats,
  3646. _newActiveFormats: undefined
  3647. };
  3648. const newActiveFormats = getActiveFormats(newValue, use_input_and_selection_EMPTY_ACTIVE_FORMATS); // Update the value with the new active formats.
  3649. newValue.activeFormats = newActiveFormats; // It is important that the internal value is updated first,
  3650. // otherwise the value will be wrong on render!
  3651. record.current = newValue;
  3652. applyRecord(newValue, {
  3653. domOnly: true
  3654. });
  3655. onSelectionChange(start, end);
  3656. }
  3657. function onCompositionStart() {
  3658. isComposing = true; // Do not update the selection when characters are being composed as
  3659. // this rerenders the component and might distroy internal browser
  3660. // editing state.
  3661. ownerDocument.removeEventListener('selectionchange', handleSelectionChange);
  3662. }
  3663. function onCompositionEnd() {
  3664. isComposing = false; // Ensure the value is up-to-date for browsers that don't emit a final
  3665. // input event after composition.
  3666. onInput({
  3667. inputType: 'insertText'
  3668. }); // Tracking selection changes can be resumed.
  3669. ownerDocument.addEventListener('selectionchange', handleSelectionChange);
  3670. }
  3671. function onFocus() {
  3672. const {
  3673. record,
  3674. isSelected,
  3675. onSelectionChange
  3676. } = propsRef.current;
  3677. if (!isSelected) {
  3678. // We know for certain that on focus, the old selection is invalid.
  3679. // It will be recalculated on the next mouseup, keyup, or touchend
  3680. // event.
  3681. const index = undefined;
  3682. record.current = { ...record.current,
  3683. start: index,
  3684. end: index,
  3685. activeFormats: use_input_and_selection_EMPTY_ACTIVE_FORMATS
  3686. };
  3687. onSelectionChange(index, index);
  3688. } else {
  3689. onSelectionChange(record.current.start, record.current.end);
  3690. } // Update selection as soon as possible, which is at the next animation
  3691. // frame. The event listener for selection changes may be added too late
  3692. // at this point, but this focus event is still too early to calculate
  3693. // the selection.
  3694. rafId = defaultView.requestAnimationFrame(handleSelectionChange);
  3695. ownerDocument.addEventListener('selectionchange', handleSelectionChange);
  3696. }
  3697. function onBlur() {
  3698. ownerDocument.removeEventListener('selectionchange', handleSelectionChange);
  3699. }
  3700. element.addEventListener('input', onInput);
  3701. element.addEventListener('compositionstart', onCompositionStart);
  3702. element.addEventListener('compositionend', onCompositionEnd);
  3703. element.addEventListener('focus', onFocus);
  3704. element.addEventListener('blur', onBlur); // Selection updates must be done at these events as they
  3705. // happen before the `selectionchange` event. In some cases,
  3706. // the `selectionchange` event may not even fire, for
  3707. // example when the window receives focus again on click.
  3708. element.addEventListener('keyup', handleSelectionChange);
  3709. element.addEventListener('mouseup', handleSelectionChange);
  3710. element.addEventListener('touchend', handleSelectionChange);
  3711. return () => {
  3712. element.removeEventListener('input', onInput);
  3713. element.removeEventListener('compositionstart', onCompositionStart);
  3714. element.removeEventListener('compositionend', onCompositionEnd);
  3715. element.removeEventListener('focus', onFocus);
  3716. element.removeEventListener('blur', onBlur);
  3717. element.removeEventListener('keyup', handleSelectionChange);
  3718. element.removeEventListener('mouseup', handleSelectionChange);
  3719. element.removeEventListener('touchend', handleSelectionChange);
  3720. ownerDocument.removeEventListener('selectionchange', handleSelectionChange);
  3721. defaultView.cancelAnimationFrame(rafId);
  3722. };
  3723. }, []);
  3724. }
  3725. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-delete.js
  3726. /**
  3727. * WordPress dependencies
  3728. */
  3729. /**
  3730. * Internal dependencies
  3731. */
  3732. function useDelete(props) {
  3733. const propsRef = Object(external_wp_element_["useRef"])(props);
  3734. propsRef.current = props;
  3735. return Object(external_wp_compose_["useRefEffect"])(element => {
  3736. function onKeyDown(event) {
  3737. const {
  3738. keyCode
  3739. } = event;
  3740. const {
  3741. createRecord,
  3742. handleChange,
  3743. multilineTag
  3744. } = propsRef.current;
  3745. if (event.defaultPrevented) {
  3746. return;
  3747. }
  3748. if (keyCode !== external_wp_keycodes_["DELETE"] && keyCode !== external_wp_keycodes_["BACKSPACE"]) {
  3749. return;
  3750. }
  3751. const currentValue = createRecord();
  3752. const {
  3753. start,
  3754. end,
  3755. text
  3756. } = currentValue;
  3757. const isReverse = keyCode === external_wp_keycodes_["BACKSPACE"]; // Always handle full content deletion ourselves.
  3758. if (start === 0 && end !== 0 && end === text.length) {
  3759. handleChange(remove_remove(currentValue));
  3760. event.preventDefault();
  3761. return;
  3762. }
  3763. if (multilineTag) {
  3764. let newValue; // Check to see if we should remove the first item if empty.
  3765. if (isReverse && currentValue.start === 0 && currentValue.end === 0 && isEmptyLine(currentValue)) {
  3766. newValue = removeLineSeparator(currentValue, !isReverse);
  3767. } else {
  3768. newValue = removeLineSeparator(currentValue, isReverse);
  3769. }
  3770. if (newValue) {
  3771. handleChange(newValue);
  3772. event.preventDefault();
  3773. }
  3774. }
  3775. }
  3776. element.addEventListener('keydown', onKeyDown);
  3777. return () => {
  3778. element.removeEventListener('keydown', onKeyDown);
  3779. };
  3780. }, []);
  3781. }
  3782. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js
  3783. /**
  3784. * WordPress dependencies
  3785. */
  3786. /**
  3787. * Internal dependencies
  3788. */
  3789. function useRichText({
  3790. value = '',
  3791. selectionStart,
  3792. selectionEnd,
  3793. placeholder,
  3794. preserveWhiteSpace,
  3795. onSelectionChange,
  3796. onChange,
  3797. __unstableMultilineTag: multilineTag,
  3798. __unstableDisableFormats: disableFormats,
  3799. __unstableIsSelected: isSelected,
  3800. __unstableDependencies,
  3801. __unstableAfterParse,
  3802. __unstableBeforeSerialize,
  3803. __unstableAddInvisibleFormats
  3804. }) {
  3805. const [, forceRender] = Object(external_wp_element_["useReducer"])(() => ({}));
  3806. const ref = Object(external_wp_element_["useRef"])();
  3807. function createRecord() {
  3808. const {
  3809. ownerDocument: {
  3810. defaultView
  3811. }
  3812. } = ref.current;
  3813. const selection = defaultView.getSelection();
  3814. const range = selection.rangeCount > 0 ? selection.getRangeAt(0) : null;
  3815. return create({
  3816. element: ref.current,
  3817. range,
  3818. multilineTag,
  3819. multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined,
  3820. __unstableIsEditableTree: true,
  3821. preserveWhiteSpace
  3822. });
  3823. }
  3824. function applyRecord(newRecord, {
  3825. domOnly
  3826. } = {}) {
  3827. apply({
  3828. value: newRecord,
  3829. current: ref.current,
  3830. multilineTag,
  3831. multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined,
  3832. prepareEditableTree: __unstableAddInvisibleFormats,
  3833. __unstableDomOnly: domOnly,
  3834. placeholder
  3835. });
  3836. } // Internal values are updated synchronously, unlike props and state.
  3837. const _value = Object(external_wp_element_["useRef"])(value);
  3838. const record = Object(external_wp_element_["useRef"])();
  3839. function setRecordFromProps() {
  3840. _value.current = value;
  3841. record.current = create({
  3842. html: value,
  3843. multilineTag,
  3844. multilineWrapperTags: multilineTag === 'li' ? ['ul', 'ol'] : undefined,
  3845. preserveWhiteSpace
  3846. });
  3847. if (disableFormats) {
  3848. record.current.formats = Array(value.length);
  3849. record.current.replacements = Array(value.length);
  3850. }
  3851. record.current.formats = __unstableAfterParse(record.current);
  3852. record.current.start = selectionStart;
  3853. record.current.end = selectionEnd;
  3854. }
  3855. const hadSelectionUpdate = Object(external_wp_element_["useRef"])(false);
  3856. if (!record.current) {
  3857. setRecordFromProps();
  3858. } else if (selectionStart !== record.current.start || selectionEnd !== record.current.end) {
  3859. hadSelectionUpdate.current = isSelected;
  3860. record.current = { ...record.current,
  3861. start: selectionStart,
  3862. end: selectionEnd
  3863. };
  3864. }
  3865. /**
  3866. * Sync the value to global state. The node tree and selection will also be
  3867. * updated if differences are found.
  3868. *
  3869. * @param {Object} newRecord The record to sync and apply.
  3870. */
  3871. function handleChange(newRecord) {
  3872. applyRecord(newRecord);
  3873. if (disableFormats) {
  3874. _value.current = newRecord.text;
  3875. } else {
  3876. _value.current = toHTMLString({
  3877. value: { ...newRecord,
  3878. formats: __unstableBeforeSerialize(newRecord)
  3879. },
  3880. multilineTag,
  3881. preserveWhiteSpace
  3882. });
  3883. }
  3884. record.current = newRecord;
  3885. const {
  3886. start,
  3887. end,
  3888. formats,
  3889. text
  3890. } = newRecord; // Selection must be updated first, so it is recorded in history when
  3891. // the content change happens.
  3892. onSelectionChange(start, end);
  3893. onChange(_value.current, {
  3894. __unstableFormats: formats,
  3895. __unstableText: text
  3896. });
  3897. forceRender();
  3898. }
  3899. function applyFromProps() {
  3900. setRecordFromProps();
  3901. applyRecord(record.current);
  3902. }
  3903. const didMount = Object(external_wp_element_["useRef"])(false); // Value updates must happen synchonously to avoid overwriting newer values.
  3904. Object(external_wp_element_["useLayoutEffect"])(() => {
  3905. if (didMount.current && value !== _value.current) {
  3906. applyFromProps();
  3907. }
  3908. }, [value]); // Value updates must happen synchonously to avoid overwriting newer values.
  3909. Object(external_wp_element_["useLayoutEffect"])(() => {
  3910. if (!hadSelectionUpdate.current) {
  3911. return;
  3912. }
  3913. applyFromProps();
  3914. hadSelectionUpdate.current = false;
  3915. }, [hadSelectionUpdate.current]);
  3916. function focus() {
  3917. ref.current.focus();
  3918. applyRecord(record.current);
  3919. }
  3920. const mergedRefs = Object(external_wp_compose_["useMergeRefs"])([ref, useDefaultStyle(), useBoundaryStyle({
  3921. record
  3922. }), useInlineWarning(), useCopyHandler({
  3923. record,
  3924. multilineTag,
  3925. preserveWhiteSpace
  3926. }), useSelectObject(), useFormatBoundaries({
  3927. record,
  3928. applyRecord
  3929. }), useDelete({
  3930. createRecord,
  3931. handleChange,
  3932. multilineTag
  3933. }), useIndentListItemOnSpace({
  3934. multilineTag,
  3935. createRecord,
  3936. handleChange
  3937. }), useInputAndSelection({
  3938. record,
  3939. applyRecord,
  3940. createRecord,
  3941. handleChange,
  3942. isSelected,
  3943. onSelectionChange
  3944. }), Object(external_wp_compose_["useRefEffect"])(() => {
  3945. applyFromProps();
  3946. didMount.current = true;
  3947. }, [placeholder, ...__unstableDependencies])]);
  3948. return {
  3949. value: record.current,
  3950. onChange: handleChange,
  3951. onFocus: focus,
  3952. ref: mergedRefs
  3953. };
  3954. }
  3955. function __experimentalRichText() {}
  3956. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/format-edit.js
  3957. /**
  3958. * Internal dependencies
  3959. */
  3960. function FormatEdit({
  3961. formatTypes,
  3962. onChange,
  3963. onFocus,
  3964. value,
  3965. forwardedRef
  3966. }) {
  3967. return formatTypes.map(settings => {
  3968. const {
  3969. name,
  3970. edit: Edit
  3971. } = settings;
  3972. if (!Edit) {
  3973. return null;
  3974. }
  3975. const activeFormat = getActiveFormat(value, name);
  3976. const isActive = activeFormat !== undefined;
  3977. const activeObject = getActiveObject(value);
  3978. const isObjectActive = activeObject !== undefined && activeObject.type === name;
  3979. return Object(external_wp_element_["createElement"])(Edit, {
  3980. key: name,
  3981. isActive: isActive,
  3982. activeAttributes: isActive ? activeFormat.attributes || {} : {},
  3983. isObjectActive: isObjectActive,
  3984. activeObjectAttributes: isObjectActive ? activeObject.attributes || {} : {},
  3985. value: value,
  3986. onChange: onChange,
  3987. onFocus: onFocus,
  3988. contentRef: forwardedRef
  3989. });
  3990. });
  3991. }
  3992. // CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js
  3993. /***/ })
  3994. /******/ });