WordPress/wp-includes/js/dist/format-library.min.js

12 lines
19 KiB
JavaScript

this.wp=this.wp||{},this.wp.formatLibrary=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=367)}({0:function(t,e){!function(){t.exports=this.wp.element}()},1:function(t,e){!function(){t.exports=this.wp.i18n}()},10:function(t,e,n){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}n.d(e,"a",function(){return r})},11:function(t,e,n){"use strict";n.d(e,"a",function(){return i});var r=n(32),o=n(3);function i(t,e){return!e||"object"!==Object(r.a)(e)&&"function"!=typeof e?Object(o.a)(t):e}},12:function(t,e,n){"use strict";function r(t){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}n.d(e,"a",function(){return r})},13:function(t,e,n){"use strict";function r(t,e){return(r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}n.d(e,"a",function(){return o})},15:function(t,e,n){"use strict";function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}n.d(e,"a",function(){return r})},16:function(t,e,n){var r;
/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/*!
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var t=[],e=0;e<arguments.length;e++){var r=arguments[e];if(r){var i=typeof r;if("string"===i||"number"===i)t.push(r);else if(Array.isArray(r)&&r.length){var a=o.apply(null,r);a&&t.push(a)}else if("object"===i)for(var c in r)n.call(r,c)&&r[c]&&t.push(c)}}return t.join(" ")}t.exports?(o.default=o,t.exports=o):void 0===(r=function(){return o}.apply(e,[]))||(t.exports=r)}()},18:function(t,e){!function(){t.exports=this.wp.keycodes}()},19:function(t,e,n){"use strict";function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}n.d(e,"a",function(){return r})},2:function(t,e){!function(){t.exports=this.lodash}()},20:function(t,e){!function(){t.exports=this.wp.richText}()},21:function(t,e,n){"use strict";function r(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}n.d(e,"a",function(){return r})},24:function(t,e){!function(){t.exports=this.wp.dom}()},25:function(t,e){!function(){t.exports=this.wp.url}()},3:function(t,e,n){"use strict";function r(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}n.d(e,"a",function(){return r})},32:function(t,e,n){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t){return(o="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}n.d(e,"a",function(){return o})},367:function(t,e,n){"use strict";n.r(e);var r=n(21),o=n(20),i=n(0),a=n(1),c=n(8),u={name:"core/bold",title:Object(a.__)("Bold"),tagName:"strong",className:null,edit:function(t){var e=t.isActive,n=t.value,r=t.onChange,u=function(){return r(Object(o.toggleFormat)(n,{type:"core/bold"}))};return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"primary",character:"b",onUse:u}),Object(i.createElement)(c.RichTextToolbarButton,{name:"bold",icon:"editor-bold",title:Object(a.__)("Bold"),onClick:u,isActive:e,shortcutType:"primary",shortcutCharacter:"b"}),Object(i.createElement)(c.UnstableRichTextInputEvent,{inputType:"formatBold",onInput:u}))}},l={name:"core/code",title:Object(a.__)("Code"),tagName:"code",className:null,edit:function(t){var e=t.value,n=t.onChange,r=t.isActive,u=function(){return n(Object(o.toggleFormat)(e,{type:"core/code"}))};return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"access",character:"x",onUse:u}),Object(i.createElement)(c.RichTextToolbarButton,{icon:"editor-code",title:Object(a.__)("Code"),onClick:u,isActive:r,shortcutType:"access",shortcutCharacter:"x"}))}},s=n(7),b=n(10),p=n(9),f=n(11),d=n(12),m=n(13),h=n(3),O=n(4),j=n(18),v=["image"],y=function(t){return t.stopPropagation()},g={name:"core/image",title:Object(a.__)("Image"),keywords:[Object(a.__)("photo"),Object(a.__)("media")],object:!0,tagName:"img",className:null,attributes:{className:"class",style:"style",url:"src",alt:"alt"},edit:function(t){function e(){var t;return Object(b.a)(this,e),(t=Object(f.a)(this,Object(d.a)(e).apply(this,arguments))).onChange=t.onChange.bind(Object(h.a)(Object(h.a)(t))),t.onKeyDown=t.onKeyDown.bind(Object(h.a)(Object(h.a)(t))),t.openModal=t.openModal.bind(Object(h.a)(Object(h.a)(t))),t.closeModal=t.closeModal.bind(Object(h.a)(Object(h.a)(t))),t.state={modal:!1},t}return Object(m.a)(e,t),Object(p.a)(e,[{key:"onChange",value:function(t){this.setState({width:t})}},{key:"onKeyDown",value:function(t){[j.LEFT,j.DOWN,j.RIGHT,j.UP,j.BACKSPACE,j.ENTER].indexOf(t.keyCode)>-1&&t.stopPropagation()}},{key:"openModal",value:function(){this.setState({modal:!0})}},{key:"closeModal",value:function(){this.setState({modal:!1})}},{key:"render",value:function(){var t=this,e=this.props,n=e.value,r=e.onChange,u=e.isObjectActive,l=e.activeObjectAttributes,b=l.style,p=n.start+b;return Object(i.createElement)(c.MediaUploadCheck,null,Object(i.createElement)(c.RichTextToolbarButton,{icon:Object(i.createElement)(O.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(i.createElement)(O.Path,{d:"M4 16h10c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2H4c-1.1 0-2 .9-2 2v9c0 1.1.9 2 2 2zM4 5h10v9H4V5zm14 9v2h4v-2h-4zM2 20h20v-2H2v2zm6.4-8.8L7 9.4 5 12h8l-2.6-3.4-2 2.6z"})),title:Object(a.__)("Inline Image"),onClick:this.openModal,isActive:u}),this.state.modal&&Object(i.createElement)(c.MediaUpload,{allowedTypes:v,onSelect:function(e){var i=e.id,a=e.url,c=e.alt,u=e.width;t.closeModal(),r(Object(o.insertObject)(n,{type:"core/image",attributes:{className:"wp-image-".concat(i),style:"width: ".concat(Math.min(u,150),"px;"),url:a,alt:c}}))},onClose:this.closeModal,render:function(t){return(0,t.open)(),null}}),u&&Object(i.createElement)(O.__unstablePositionedAtSelection,{key:p},Object(i.createElement)(O.Popover,{position:"bottom center",focusOnMount:!1},Object(i.createElement)("form",{className:"editor-format-toolbar__image-container-content block-editor-format-toolbar__image-container-content",onKeyPress:y,onKeyDown:this.onKeyDown,onSubmit:function(e){var o=n.replacements.slice();o[n.start]={type:"core/image",attributes:Object(s.a)({},l,{style:"width: ".concat(t.state.width,"px;")})},r(Object(s.a)({},n,{replacements:o})),e.preventDefault()}},Object(i.createElement)(O.TextControl,{className:"editor-format-toolbar__image-container-value block-editor-format-toolbar__image-container-value",type:"number",label:Object(a.__)("Width"),value:this.state.width,min:1,onChange:this.onChange}),Object(i.createElement)(O.IconButton,{icon:"editor-break",label:Object(a.__)("Apply"),type:"submit"})))))}}],[{key:"getDerivedStateFromProps",value:function(t,e){var n=t.activeObjectAttributes.style;return n===e.previousStyle?null:n?{width:n.replace(/\D/g,""),previousStyle:n}:{width:void 0,previousStyle:n}}}]),e}(i.Component)},k={name:"core/italic",title:Object(a.__)("Italic"),tagName:"em",className:null,edit:function(t){var e=t.isActive,n=t.value,r=t.onChange,u=function(){return r(Object(o.toggleFormat)(n,{type:"core/italic"}))};return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"primary",character:"i",onUse:u}),Object(i.createElement)(c.RichTextToolbarButton,{name:"italic",icon:"editor-italic",title:Object(a.__)("Italic"),onClick:u,isActive:e,shortcutType:"primary",shortcutCharacter:"i"}),Object(i.createElement)(c.UnstableRichTextInputEvent,{inputType:"formatItalic",onInput:u}))}},_=n(25),w=n(19),E=n(16),C=n.n(E),S=n(24),T=n(2);function x(t){if(!t)return!1;var e=t.trim();if(!e)return!1;if(/^\S+:/.test(e)){var n=Object(_.getProtocol)(e);if(!Object(_.isValidProtocol)(n))return!1;if(Object(T.startsWith)(n,"http")&&!/^https?:\/\/[^\/\s]/i.test(e))return!1;var r=Object(_.getAuthority)(e);if(!Object(_.isValidAuthority)(r))return!1;var o=Object(_.getPath)(e);if(o&&!Object(_.isValidPath)(o))return!1;var i=Object(_.getQueryString)(e);if(i&&!Object(_.isValidQueryString)(i))return!1;var a=Object(_.getFragment)(e);if(a&&!Object(_.isValidFragment)(a))return!1}return!(Object(T.startsWith)(e,"#")&&!Object(_.isValidFragment)(e))}function L(t){var e=t.url,n=t.opensInNewWindow,r=t.text,o={type:"core/link",attributes:{url:e}};if(n){var i=Object(a.sprintf)(Object(a.__)("%s (opens in a new tab)"),r);o.attributes.target="_blank",o.attributes.rel="noreferrer noopener",o.attributes["aria-label"]=i}return o}var R=function(t){return t.stopPropagation()};function A(t,e){return t.addingLink||e.editLink}var P=function(t){var e=t.value,n=t.onChangeInputValue,r=t.onKeyDown,o=t.submitLink,u=t.autocompleteRef;return Object(i.createElement)("form",{className:"editor-format-toolbar__link-container-content block-editor-format-toolbar__link-container-content",onKeyPress:R,onKeyDown:r,onSubmit:o},Object(i.createElement)(c.URLInput,{value:e,onChange:n,autocompleteRef:u}),Object(i.createElement)(O.IconButton,{icon:"editor-break",label:Object(a.__)("Apply"),type:"submit"}))},N=function(t){var e=t.url,n=Object(_.prependHTTP)(e),r=C()("editor-format-toolbar__link-container-value block-editor-format-toolbar__link-container-value",{"has-invalid-link":!x(n)});return e?Object(i.createElement)(O.ExternalLink,{className:r,href:e},Object(_.filterURLForDisplay)(Object(_.safeDecodeURI)(e))):Object(i.createElement)("span",{className:r})},I=function(t){var e=t.isActive,n=t.addingLink,o=t.value,a=Object(r.a)(t,["isActive","addingLink","value"]),u=Object(i.useMemo)(function(){var t=window.getSelection(),e=t.rangeCount>0?t.getRangeAt(0):null;if(e){if(n)return Object(S.getRectangleFromRange)(e);var r=e.startContainer;for(r=r.nextElementSibling||r;r.nodeType!==window.Node.ELEMENT_NODE;)r=r.parentNode;var o=r.closest("a");return o?o.getBoundingClientRect():void 0}},[e,n,o.start,o.end]);return u?Object(i.createElement)(c.URLPopover,Object(w.a)({anchorRect:u},a)):null},F=function(t){var e=t.url,n=t.editLink;return Object(i.createElement)("div",{className:"editor-format-toolbar__link-container-content block-editor-format-toolbar__link-container-content",onKeyPress:R},Object(i.createElement)(N,{url:e}),Object(i.createElement)(O.IconButton,{icon:"edit",label:Object(a.__)("Edit"),onClick:n}))},M=function(t){function e(){var t;return Object(b.a)(this,e),(t=Object(f.a)(this,Object(d.a)(e).apply(this,arguments))).editLink=t.editLink.bind(Object(h.a)(Object(h.a)(t))),t.submitLink=t.submitLink.bind(Object(h.a)(Object(h.a)(t))),t.onKeyDown=t.onKeyDown.bind(Object(h.a)(Object(h.a)(t))),t.onChangeInputValue=t.onChangeInputValue.bind(Object(h.a)(Object(h.a)(t))),t.setLinkTarget=t.setLinkTarget.bind(Object(h.a)(Object(h.a)(t))),t.onClickOutside=t.onClickOutside.bind(Object(h.a)(Object(h.a)(t))),t.resetState=t.resetState.bind(Object(h.a)(Object(h.a)(t))),t.autocompleteRef=Object(i.createRef)(),t.state={opensInNewWindow:!1,inputValue:""},t}return Object(m.a)(e,t),Object(p.a)(e,[{key:"onKeyDown",value:function(t){[j.LEFT,j.DOWN,j.RIGHT,j.UP,j.BACKSPACE,j.ENTER].indexOf(t.keyCode)>-1&&t.stopPropagation()}},{key:"onChangeInputValue",value:function(t){this.setState({inputValue:t})}},{key:"setLinkTarget",value:function(t){var e=this.props,n=e.activeAttributes.url,r=void 0===n?"":n,i=e.value,a=e.onChange;if(this.setState({opensInNewWindow:t}),!A(this.props,this.state)){var c=Object(o.getTextContent)(Object(o.slice)(i));a(Object(o.applyFormat)(i,L({url:r,opensInNewWindow:t,text:c})))}}},{key:"editLink",value:function(t){this.setState({editLink:!0}),t.preventDefault()}},{key:"submitLink",value:function(t){var e=this.props,n=e.isActive,r=e.value,i=e.onChange,c=e.speak,u=this.state,l=u.inputValue,s=u.opensInNewWindow,b=Object(_.prependHTTP)(l),p=L({url:b,opensInNewWindow:s,text:Object(o.getTextContent)(Object(o.slice)(r))});if(t.preventDefault(),Object(o.isCollapsed)(r)&&!n){var f=Object(o.applyFormat)(Object(o.create)({text:b}),p,0,b.length);i(Object(o.insert)(r,f))}else i(Object(o.applyFormat)(r,p));this.resetState(),x(b)?c(n?Object(a.__)("Link edited."):Object(a.__)("Link inserted."),"assertive"):c(Object(a.__)("Warning: the link has been inserted but may have errors. Please test it."),"assertive")}},{key:"onClickOutside",value:function(t){var e=this.autocompleteRef.current;e&&e.contains(t.target)||this.resetState()}},{key:"resetState",value:function(){this.props.stopAddingLink(),this.setState({editLink:!1})}},{key:"render",value:function(){var t=this,e=this.props,n=e.isActive,r=e.activeAttributes.url,o=e.addingLink,c=e.value;if(!n&&!o)return null;var u=this.state,l=u.inputValue,s=u.opensInNewWindow,b=A(this.props,this.state);return Object(i.createElement)(I,{value:c,isActive:n,addingLink:o,onClickOutside:this.onClickOutside,onClose:this.resetState,focusOnMount:!!b&&"firstElement",renderSettings:function(){return Object(i.createElement)(O.ToggleControl,{label:Object(a.__)("Open in New Tab"),checked:s,onChange:t.setLinkTarget})}},b?Object(i.createElement)(P,{value:l,onChangeInputValue:this.onChangeInputValue,onKeyDown:this.onKeyDown,submitLink:this.submitLink,autocompleteRef:this.autocompleteRef}):Object(i.createElement)(F,{url:r,editLink:this.editLink}))}}],[{key:"getDerivedStateFromProps",value:function(t,e){var n=t.activeAttributes,r=n.url,o="_blank"===n.target;if(!A(t,e)){if(r!==e.inputValue)return{inputValue:r};if(o!==e.opensInNewWindow)return{opensInNewWindow:o}}return null}}]),e}(i.Component),D=Object(O.withSpokenMessages)(M),U={name:"core/link",title:Object(a.__)("Link"),tagName:"a",className:null,attributes:{url:"href",target:"target"},edit:Object(O.withSpokenMessages)(function(t){function e(){var t;return Object(b.a)(this,e),(t=Object(f.a)(this,Object(d.a)(e).apply(this,arguments))).addLink=t.addLink.bind(Object(h.a)(Object(h.a)(t))),t.stopAddingLink=t.stopAddingLink.bind(Object(h.a)(Object(h.a)(t))),t.onRemoveFormat=t.onRemoveFormat.bind(Object(h.a)(Object(h.a)(t))),t.state={addingLink:!1},t}return Object(m.a)(e,t),Object(p.a)(e,[{key:"addLink",value:function(){var t=this.props,e=t.value,n=t.onChange,r=Object(o.getTextContent)(Object(o.slice)(e));r&&Object(_.isURL)(r)?n(Object(o.applyFormat)(e,{type:"core/link",attributes:{url:r}})):this.setState({addingLink:!0})}},{key:"stopAddingLink",value:function(){this.setState({addingLink:!1})}},{key:"onRemoveFormat",value:function(){var t=this.props,e=t.value,n=t.onChange,r=t.speak;n(Object(o.removeFormat)(e,"core/link")),r(Object(a.__)("Link removed."),"assertive")}},{key:"render",value:function(){var t=this.props,e=t.isActive,n=t.activeAttributes,r=t.value,o=t.onChange;return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"access",character:"a",onUse:this.addLink}),Object(i.createElement)(c.RichTextShortcut,{type:"access",character:"s",onUse:this.onRemoveFormat}),Object(i.createElement)(c.RichTextShortcut,{type:"primary",character:"k",onUse:this.addLink}),Object(i.createElement)(c.RichTextShortcut,{type:"primaryShift",character:"k",onUse:this.onRemoveFormat}),e&&Object(i.createElement)(c.RichTextToolbarButton,{name:"link",icon:"editor-unlink",title:Object(a.__)("Unlink"),onClick:this.onRemoveFormat,isActive:e,shortcutType:"primaryShift",shortcutCharacter:"k"}),!e&&Object(i.createElement)(c.RichTextToolbarButton,{name:"link",icon:"admin-links",title:Object(a.__)("Link"),onClick:this.addLink,isActive:e,shortcutType:"primary",shortcutCharacter:"k"}),Object(i.createElement)(D,{addingLink:this.state.addingLink,stopAddingLink:this.stopAddingLink,isActive:e,activeAttributes:n,value:r,onChange:o}))}}]),e}(i.Component))},V={name:"core/strikethrough",title:Object(a.__)("Strikethrough"),tagName:"s",className:null,edit:function(t){var e=t.isActive,n=t.value,r=t.onChange,u=function(){return r(Object(o.toggleFormat)(n,{type:"core/strikethrough"}))};return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"access",character:"d",onUse:u}),Object(i.createElement)(c.RichTextToolbarButton,{icon:"editor-strikethrough",title:Object(a.__)("Strikethrough"),onClick:u,isActive:e,shortcutType:"access",shortcutCharacter:"d"}))}};[u,l,g,k,U,V,{name:"core/underline",title:Object(a.__)("Underline"),tagName:"span",className:null,attributes:{style:"style"},edit:function(t){var e=t.value,n=t.onChange,r=function(){n(Object(o.toggleFormat)(e,{type:"core/underline",attributes:{style:"text-decoration: underline;"}}))};return Object(i.createElement)(i.Fragment,null,Object(i.createElement)(c.RichTextShortcut,{type:"primary",character:"u",onUse:r}),Object(i.createElement)(c.UnstableRichTextInputEvent,{inputType:"formatUnderline",onInput:r}))}}].forEach(function(t){var e=t.name,n=Object(r.a)(t,["name"]);return Object(o.registerFormatType)(e,n)})},4:function(t,e){!function(){t.exports=this.wp.components}()},7:function(t,e,n){"use strict";n.d(e,"a",function(){return o});var r=n(15);function o(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),o.forEach(function(e){Object(r.a)(t,e,n[e])})}return t}},8:function(t,e){!function(){t.exports=this.wp.blockEditor}()},9:function(t,e,n){"use strict";function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function o(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}n.d(e,"a",function(){return o})}});