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

12 lines
18 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=313)}({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(29),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)}()},17:function(t,e){!function(){t.exports=this.wp.keycodes}()},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})},22:function(t,e){!function(){t.exports=this.wp.url}()},29: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})},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})},313:function(t,e,n){"use strict";n.r(e);var r=n(21),o=n(20),i=n(0),a=n(1),c=n(6),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;return Object(i.createElement)(c.RichTextShortcut,{type:"access",character:"x",onUse:function(){return n(Object(o.toggleFormat)(e,{type:"core/code"}))}})}},s=n(8),b=n(10),p=n(9),f=n(11),m=n(12),d=n(13),h=n(3),O=n(4),j=n(17),y=["image"],v=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(m.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(d.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.isActive,l=e.activeAttributes,b=l.style,p=n.start+b;return Object(i.createElement)(c.MediaUploadCheck,null,Object(i.createElement)(c.RichTextInserterItem,{name:"core/image",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}),this.state.modal&&Object(i.createElement)(c.MediaUpload,{allowedTypes:y,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.PositionedAtSelection,{key:p},Object(i.createElement)(O.Popover,{position:"bottom center",focusOnMount:!1},Object(i.createElement)("form",{className:"editor-format-toolbar__image-container-content",onKeyPress:v,onKeyDown:this.onKeyDown,onSubmit:function(e){var o=n.formats.slice(0);o[n.start]=[{type:"core/image",object:!0,attributes:Object(s.a)({},l,{style:"width: ".concat(t.state.width,"px;")})}],r(Object(s.a)({},n,{formats:o})),e.preventDefault()}},Object(i.createElement)(O.TextControl,{className:"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.activeAttributes.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}))}},w=n(22),_=n(16),S=n.n(_),E=n(2);function C(t){if(!t)return!1;var e=t.trim();if(!e)return!1;if(/^\S+:/.test(e)){var n=Object(w.getProtocol)(e);if(!Object(w.isValidProtocol)(n))return!1;if(Object(E.startsWith)(n,"http")&&!/^https?:\/\/[^\/\s]/i.test(e))return!1;var r=Object(w.getAuthority)(e);if(!Object(w.isValidAuthority)(r))return!1;var o=Object(w.getPath)(e);if(o&&!Object(w.isValidPath)(o))return!1;var i=Object(w.getQueryString)(e);if(i&&!Object(w.isValidQueryString)(i))return!1;var a=Object(w.getFragment)(e);if(a&&!Object(w.isValidFragment)(a))return!1}return!(Object(E.startsWith)(e,"#")&&!Object(w.isValidFragment)(e))}function T(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 x=function(t){return t.stopPropagation()};function L(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",onKeyPress:x,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"}))},R=function(t){var e=t.url,n=Object(w.prependHTTP)(e),r=S()("editor-format-toolbar__link-container-value",{"has-invalid-link":!C(n)});return e?Object(i.createElement)(O.ExternalLink,{className:r,href:e},Object(w.filterURLForDisplay)(Object(w.safeDecodeURI)(e))):Object(i.createElement)("span",{className:r})},A=function(t){var e=t.url,n=t.editLink;return Object(i.createElement)("div",{className:"editor-format-toolbar__link-container-content",onKeyPress:x},Object(i.createElement)(R,{url:e}),Object(i.createElement)(O.IconButton,{icon:"edit",label:Object(a.__)("Edit"),onClick:n}))},I=function(t){function e(){var t;return Object(b.a)(this,e),(t=Object(f.a)(this,Object(m.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(d.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}),!L(this.props,this.state)){var c=Object(o.getTextContent)(Object(o.slice)(i));a(Object(o.applyFormat)(i,T({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(w.prependHTTP)(l),p=T({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(),C(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,u=e.value;if(!n&&!o)return null;var l=this.state,s=l.inputValue,b=l.opensInNewWindow,p=L(this.props,this.state);return Object(i.createElement)(O.PositionedAtSelection,{key:"".concat(u.start).concat(u.end)},Object(i.createElement)(c.URLPopover,{onClickOutside:this.onClickOutside,onClose:this.resetState,focusOnMount:!!p&&"firstElement",renderSettings:function(){return Object(i.createElement)(O.ToggleControl,{label:Object(a.__)("Open in New Tab"),checked:b,onChange:t.setLinkTarget})}},p?Object(i.createElement)(P,{value:s,onChangeInputValue:this.onChangeInputValue,onKeyDown:this.onKeyDown,submitLink:this.submitLink,autocompleteRef:this.autocompleteRef}):Object(i.createElement)(A,{url:r,editLink:this.editLink})))}}],[{key:"getDerivedStateFromProps",value:function(t,e){var n=t.activeAttributes,r=n.url,o="_blank"===n.target;if(!L(t,e)){if(r!==e.inputValue)return{inputValue:r};if(o!==e.opensInNewWindow)return{opensInNewWindow:o}}return null}}]),e}(i.Component),N=Object(O.withSpokenMessages)(I),F={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(m.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(d.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(w.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)(N,{addingLink:this.state.addingLink,stopAddingLink:this.stopAddingLink,isActive:e,activeAttributes:n,value:r,onChange:o}))}}]),e}(i.Component))},U={name:"core/strikethrough",title:Object(a.__)("Strikethrough"),tagName:"del",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,{name:"strikethrough",icon:"editor-strikethrough",title:Object(a.__)("Strikethrough"),onClick:u,isActive:e,shortcutType:"access",shortcutCharacter:"d"}))}};[u,l,g,k,F,U,{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}()},6:function(t,e){!function(){t.exports=this.wp.editor}()},8: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}},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})}});