rich-text.js 162 KB

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