react-trix
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -8,4 +8,4 @@ parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"J4Nk":[function(require,module,exports) { | ||
},{"./cjs/react.production.min.js":"awqi"}],"kdL1":[function(require,module,exports) { | ||
"use strict";var t=this&&this.__extends||function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),e=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("react")),n=function(e){function n(t){var r=e.call(this,t)||this;return r.container=null,r.editor=null,r.d=null,r.id=r.generateId(),r.state={showMergeTags:!1,tags:[]},r}return t(n,e),n.prototype.generateId=function(){var t=Date.now(),e=0;return t<=e?t=++e:e=t,"T"+t.toString()},n.prototype.componentDidMount=function(){var t=this,e=this.props;this.container=document.getElementById("editor-"+this.id),this.container?(this.container.addEventListener("trix-initialize",function(){t.editor=t.container.editor,t.editor||console.error("cannot find trix editor"),e.onEditorReady&&"function"==typeof e.onEditorReady&&e.onEditorReady(t.editor)},!1),this.container.addEventListener("trix-change",this.handleChange.bind(this),!1),e.uploadURL&&this.container.addEventListener("trix-attachment-add",this.handleUpload.bind(this))):console.error("editor not found")},n.prototype.componentWillUnmount=function(){this.container.removeEventListener("trix-initialize",this.handleChange),this.container.removeEventListener("trix-change",this.handleChange),this.props.uploadURL&&this.container.removeEventListener("trix-attachment-add",this.handleUpload)},n.prototype.handleChange=function(t){var e=this.props,r=this.state,n=t.target.innerText;e.onChange&&e.onChange(t.target.innerHTML,n);var o=this.editor.getSelectedRange();if(n&&o[0]==o[1]&&e.mergeTags){var i=o[0]-1;if(i>=0&&i<n.length)for(var a=n[i],s=0;s<e.mergeTags.length;s++)if(a==e.mergeTags[s].trigger){r.showMergeTags=!0,r.tags=e.mergeTags[s].tags,this.setState(r);break}}},n.prototype.handleUpload=function(t){var e=t.attachment;if(e.file)return this.uploadAttachment(e)},n.prototype.uploadAttachment=function(t){var e,r,n;if(e=t.file,r=new FormData,this.props.uploadData)for(var o in this.props.uploadData)r.append(o,this.props.uploadData[o]);return r.append("file",e),(n=new XMLHttpRequest).open("POST",this.props.uploadURL,!0),n.upload.onprogress=function(e){var r=e.loaded/e.total*100;return t.setUploadProgress(r)},n.onload=function(){var e,r;if(n.status>=200&&n.status<300)return r=e=n.responseText,t.setAttributes({url:r,href:e})},n.send(r)},n.prototype.handleTagSelected=function(t,e){e.preventDefault();var r=this.state;r.showMergeTags=!1,this.setState(r),this.editor.expandSelectionInDirection("backward"),this.editor.insertString(t.tag)},n.prototype.renderTagSelector=function(t){var e=this;if(!t)return null;var n=document.getElementById("trix-editor-top-level").getBoundingClientRect(),o=this.editor.getClientRectAtPosition(this.editor.getSelectedRange()[0]),i={position:"absolute",top:o.top+25-n.top,left:o.left+25-n.left,width:"250px",boxSizing:"border-box",padding:0,margin:".2em 0 0",backgroundColor:"hsla(0,0%,100%,.9)",borderRadius:".3em",background:"linear-gradient(to bottom right, white, hsla(0,0%,100%,.8))",border:"1px solid rgba(0,0,0,.3)",boxShadow:".05em .2em .6em rgba(0,0,0,.2)",textShadow:"none"},a={display:"block",padding:".2em .5em",cursor:"pointer"};return r.createElement("div",{style:i,className:"react-trix-suggestions"},t.map(function(t){return r.createElement("a",{key:t.name,style:a,href:"#",onClick:e.handleTagSelected.bind(e,t)},t.name)}))},n.prototype.render=function(){var t=this,e=this.state,n=this.props,o={id:"editor-"+this.id,input:"input-"+this.id};n.autoFocus&&(o.autoFocus=n.autoFocus.toString()),n.placeholder&&(o.placeholder=n.placeholder);var i=null;return e.showMergeTags&&(i=this.renderTagSelector(e.tags)),r.createElement("div",{id:"trix-editor-top-level",ref:function(e){return t.d=e},style:{position:"relative"}},r.createElement("trix-editor",o),r.createElement("input",{type:"hidden",id:"input-"+this.id,value:this.props.value}),i)},n}(r.Component);exports.TrixEditor=n; | ||
"use strict";var t=this&&this.__extends||function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),e=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(exports,"__esModule",{value:!0});var r=e(require("react")),n=function(e){function n(t){var r=e.call(this,t)||this;return r.container=null,r.editor=null,r.d=null,r.id=r.generateId(),r.state={showMergeTags:!1,tags:[]},r}return t(n,e),n.prototype.generateId=function(){var t=Date.now(),e=0;return t<=e?t=++e:e=t,"T"+t.toString()},n.prototype.componentDidMount=function(){var t=this,e=this.props;this.container=document.getElementById("editor-"+this.id),this.container?(this.container.addEventListener("trix-initialize",function(){t.editor=t.container.editor,t.editor||console.error("cannot find trix editor"),e.onEditorReady&&"function"==typeof e.onEditorReady&&e.onEditorReady(t.editor)},!1),this.container.addEventListener("trix-change",this.handleChange.bind(this),!1),e.uploadURL&&this.container.addEventListener("trix-attachment-add",this.handleUpload.bind(this))):console.error("editor not found")},n.prototype.componentWillUnmount=function(){this.container.removeEventListener("trix-initialize",this.handleChange),this.container.removeEventListener("trix-change",this.handleChange),this.props.uploadURL&&this.container.removeEventListener("trix-attachment-add",this.handleUpload)},n.prototype.handleChange=function(t){var e=this.props,r=this.state,n=t.target.innerText;e.onChange&&e.onChange(t.target.innerHTML,n);var o=this.editor.getSelectedRange();if(n&&o[0]==o[1]&&e.mergeTags){var i=o[0]-1;if(i>=0&&i<n.length)for(var a=n[i],s=0;s<e.mergeTags.length;s++)if(a==e.mergeTags[s].trigger){r.showMergeTags=!0,r.tags=e.mergeTags[s].tags,this.setState(r);break}}},n.prototype.handleUpload=function(t){var e=t.attachment;if(e.file)return this.uploadAttachment(e)},n.prototype.uploadAttachment=function(t){var e,r,n;if(e=t.file,r=new FormData,this.props.uploadData)for(var o in this.props.uploadData)r.append(o,this.props.uploadData[o]);return r.append("file",e),(n=new XMLHttpRequest).open("POST",this.props.uploadURL,!0),n.upload.onprogress=function(e){var r=e.loaded/e.total*100;return t.setUploadProgress(r)},n.onload=function(){var e,r;if(n.status>=200&&n.status<300)return r=e=n.responseText,t.setAttributes({url:r,href:e})},n.send(r)},n.prototype.handleTagSelected=function(t,e){e.preventDefault();var r=this.state;r.showMergeTags=!1,this.setState(r),this.editor.expandSelectionInDirection("backward"),this.editor.insertString(t.tag)},n.prototype.renderTagSelector=function(t){var e=this;if(!t)return null;var n=document.getElementById("trix-editor-top-level").getBoundingClientRect(),o=this.editor.getClientRectAtPosition(this.editor.getSelectedRange()[0]),i={position:"absolute",top:o.top+25-n.top,left:o.left+25-n.left,width:"250px",boxSizing:"border-box",padding:0,margin:".2em 0 0",backgroundColor:"hsla(0,0%,100%,.9)",borderRadius:".3em",background:"linear-gradient(to bottom right, white, hsla(0,0%,100%,.8))",border:"1px solid rgba(0,0,0,.3)",boxShadow:".05em .2em .6em rgba(0,0,0,.2)",textShadow:"none"},a={display:"block",padding:".2em .5em",cursor:"pointer"};return r.createElement("div",{style:i,className:"react-trix-suggestions"},t.map(function(t){return r.createElement("a",{key:t.name,style:a,href:"#",onClick:e.handleTagSelected.bind(e,t)},t.name)}))},n.prototype.render=function(){var t=this,e=this.state,n=this.props,o={id:"editor-"+this.id,input:"input-"+this.id};n.autoFocus&&(o.autoFocus=n.autoFocus.toString()),n.placeholder&&(o.placeholder=n.placeholder),n.toolbar&&(o.toolbar=n.toolbar);var i=null;return e.showMergeTags&&(i=this.renderTagSelector(e.tags)),r.createElement("div",{id:"trix-editor-top-level",ref:function(e){return t.d=e},style:{position:"relative"}},r.createElement("trix-editor",o),r.createElement("input",{type:"hidden",id:"input-"+this.id,value:this.props.value}),i)},n}(r.Component);exports.TrixEditor=n; | ||
},{"react":"n8MK"}]},{},["kdL1"], null) | ||
//# sourceMappingURL=/react-trix.js.map |
@@ -13,2 +13,3 @@ import * as React from "react"; | ||
placeholder?: string; | ||
toolbar?: string; | ||
value?: string; | ||
@@ -15,0 +16,0 @@ uploadURL?: string; |
@@ -186,2 +186,5 @@ "use strict"; | ||
} | ||
if (props.toolbar) { | ||
attributes["toolbar"] = props.toolbar; | ||
} | ||
var mergetags = null; | ||
@@ -188,0 +191,0 @@ if (state.showMergeTags) { |
{ | ||
"name": "react-trix", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "React wrapper around Basecamp's Trix editor.", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
63825
312