WordPress/wp-includes/js/dist/annotations.min.js

2 lines
6.8 KiB
JavaScript

/*! This file is auto-generated */
!function(){"use strict";var e={d:function(t,n){for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{store:function(){return j}});var n={};e.r(n),e.d(n,{__experimentalGetAllAnnotationsForBlock:function(){return b},__experimentalGetAnnotations:function(){return O},__experimentalGetAnnotationsForBlock:function(){return T},__experimentalGetAnnotationsForRichText:function(){return N}});var r={};e.r(r),e.d(r,{__experimentalAddAnnotation:function(){return U},__experimentalRemoveAnnotation:function(){return F},__experimentalRemoveAnnotationsBySource:function(){return V},__experimentalUpdateAnnotationRange:function(){return G}});var o=window.wp.richText,a=window.wp.i18n;const i="core/annotations",u="core/annotation",l="annotation-text-";const c={name:u,title:(0,a.__)("Annotation"),tagName:"mark",className:"annotation-text",attributes:{className:"class",id:"id"},edit(){return null},__experimentalGetPropsForEditableTreePreparation(e,{richTextIdentifier:t,blockClientId:n}){return{annotations:e(i).__experimentalGetAnnotationsForRichText(n,t)}},__experimentalCreatePrepareEditableTree({annotations:e}){return(t,n)=>{if(0===e.length)return t;let r={formats:t,text:n};return r=function(e,t=[]){return t.forEach((t=>{let{start:n,end:r}=t;n>e.text.length&&(n=e.text.length),r>e.text.length&&(r=e.text.length);const a=l+t.source,i=l+t.id;e=(0,o.applyFormat)(e,{type:u,attributes:{className:a,id:i}},n,r)})),e}(r,e),r.formats}},__experimentalGetPropsForEditableTreeChangeHandler(e){return{removeAnnotation:e(i).__experimentalRemoveAnnotation,updateAnnotationRange:e(i).__experimentalUpdateAnnotationRange}},__experimentalCreateOnChangeEditableValue(e){return t=>{const n=function(e){const t={};return e.forEach(((e,n)=>{(e=(e=e||[]).filter((e=>e.type===u))).forEach((e=>{let{id:r}=e.attributes;r=r.replace(l,""),t.hasOwnProperty(r)||(t[r]={start:n}),t[r].end=n+1}))})),t}(t),{removeAnnotation:r,updateAnnotationRange:o,annotations:a}=e;!function(e,t,{removeAnnotation:n,updateAnnotationRange:r}){e.forEach((e=>{const o=t[e.id];if(!o)return void n(e.id);const{start:a,end:i}=e;a===o.start&&i===o.end||r(e.id,o.start,o.end)}))}(a,n,{removeAnnotation:r,updateAnnotationRange:o})}}},{name:s,...d}=c;(0,o.registerFormatType)(s,d);var p=window.wp.hooks,f=window.wp.data;function m(e,t){const n=e.filter(t);return e.length===n.length?e:n}(0,p.addFilter)("editor.BlockListBlock","core/annotations",(e=>(0,f.withSelect)(((e,{clientId:t,className:n})=>({className:e(i).__experimentalGetAnnotationsForBlock(t).map((e=>"is-annotated-by-"+e.source)).concat(n).filter(Boolean).join(" ")})))(e)));const g=(e,t)=>Object.entries(e).reduce(((e,[n,r])=>({...e,[n]:t(r)})),{});var v=function(e={},t){var n;switch(t.type){case"ANNOTATION_ADD":const r=t.blockClientId,o={id:t.id,blockClientId:r,richTextIdentifier:t.richTextIdentifier,source:t.source,selector:t.selector,range:t.range};if("range"===o.selector&&!function(e){return"number"==typeof e.start&&"number"==typeof e.end&&e.start<=e.end}(o.range))return e;const a=null!==(n=e?.[r])&&void 0!==n?n:[];return{...e,[r]:[...a,o]};case"ANNOTATION_REMOVE":return g(e,(e=>m(e,(e=>e.id!==t.annotationId))));case"ANNOTATION_UPDATE_RANGE":return g(e,(e=>{let n=!1;const r=e.map((e=>e.id===t.annotationId?(n=!0,{...e,range:{start:t.start,end:t.end}}):e));return n?r:e}));case"ANNOTATION_REMOVE_SOURCE":return g(e,(e=>m(e,(e=>e.source!==t.source))))}return e},h={};function _(e){return[e]}function A(e,t,n){var r;if(e.length!==t.length)return!1;for(r=n;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function y(e,t){var n,r=t||_;function o(){n=new WeakMap}function a(){var t,o,a,i,u,l=arguments.length;for(i=new Array(l),a=0;a<l;a++)i[a]=arguments[a];for(t=function(e){var t,r,o,a,i,u=n,l=!0;for(t=0;t<e.length;t++){if(!(i=r=e[t])||"object"!=typeof i){l=!1;break}u.has(r)?u=u.get(r):(o=new WeakMap,u.set(r,o),u=o)}return u.has(h)||((a=function(){var e={clear:function(){e.head=null}};return e}()).isUniqueByDependants=l,u.set(h,a)),u.get(h)}(u=r.apply(null,i)),t.isUniqueByDependants||(t.lastDependants&&!A(u,t.lastDependants,0)&&t.clear(),t.lastDependants=u),o=t.head;o;){if(A(o.args,i,1))return o!==t.head&&(o.prev.next=o.next,o.next&&(o.next.prev=o.prev),o.next=t.head,o.prev=null,t.head.prev=o,t.head=o),o.val;o=o.next}return o={val:e.apply(null,i)},i[0]=null,o.args=i,t.head&&(t.head.prev=o,o.next=t.head),t.head=o,o.val}return a.getDependants=r,a.clear=o,o(),a}const x=[],T=y(((e,t)=>{var n;return(null!==(n=e?.[t])&&void 0!==n?n:[]).filter((e=>"block"===e.selector))}),((e,t)=>{var n;return[null!==(n=e?.[t])&&void 0!==n?n:x]}));function b(e,t){var n;return null!==(n=e?.[t])&&void 0!==n?n:x}const N=y(((e,t,n)=>{var r;return(null!==(r=e?.[t])&&void 0!==r?r:[]).filter((e=>"range"===e.selector&&n===e.richTextIdentifier)).map((e=>{const{range:t,...n}=e;return{...t,...n}}))}),((e,t)=>{var n;return[null!==(n=e?.[t])&&void 0!==n?n:x]}));function O(e){return Object.values(e).flat()}var w,I=new Uint8Array(16);function R(){if(!w&&!(w="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return w(I)}var E=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var k=function(e){return"string"==typeof e&&E.test(e)},C=[],D=0;D<256;++D)C.push((D+256).toString(16).substr(1));var S=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(C[e[t+0]]+C[e[t+1]]+C[e[t+2]]+C[e[t+3]]+"-"+C[e[t+4]]+C[e[t+5]]+"-"+C[e[t+6]]+C[e[t+7]]+"-"+C[e[t+8]]+C[e[t+9]]+"-"+C[e[t+10]]+C[e[t+11]]+C[e[t+12]]+C[e[t+13]]+C[e[t+14]]+C[e[t+15]]).toLowerCase();if(!k(n))throw TypeError("Stringified UUID is invalid");return n};var P=function(e,t,n){var r=(e=e||{}).random||(e.rng||R)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return S(r)};function U({blockClientId:e,richTextIdentifier:t=null,range:n=null,selector:r="range",source:o="default",id:a=P()}){const i={type:"ANNOTATION_ADD",id:a,blockClientId:e,richTextIdentifier:t,source:o,selector:r};return"range"===r&&(i.range=n),i}function F(e){return{type:"ANNOTATION_REMOVE",annotationId:e}}function G(e,t,n){return{type:"ANNOTATION_UPDATE_RANGE",annotationId:e,start:t,end:n}}function V(e){return{type:"ANNOTATION_REMOVE_SOURCE",source:e}}const j=(0,f.createReduxStore)(i,{reducer:v,selectors:n,actions:r});(0,f.register)(j),(window.wp=window.wp||{}).annotations=t}();