filerobot-image-editor
Version:
Vanilla Javascript bridged version of filerobot image editor (FIE).
1 lines • 3.63 kB
JavaScript
import _typeof from"@babel/runtime/helpers/typeof";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _defineProperty from"@babel/runtime/helpers/defineProperty";import _classPrivateFieldGet from"@babel/runtime/helpers/classPrivateFieldGet";import _classPrivateFieldSet from"@babel/runtime/helpers/classPrivateFieldSet";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}import{createElement}from"react";import{createRoot}from"react-dom/client";import AssemblyPoint,{TOOLS,TABS}from"react-filerobot-image-editor";import deepMerge from"react-filerobot-image-editor/lib/utils/deepMerge";var _root=new WeakMap,_getCurrentImgDataFnRef=new WeakMap,_updateStateFnRef=new WeakMap,FilerobotImageEditor=function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(_classCallCheck(this,a),_classPrivateFieldInitSpec(this,_root,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_getCurrentImgDataFnRef,{writable:!0,value:void 0}),_classPrivateFieldInitSpec(this,_updateStateFnRef,{writable:!0,value:void 0}),this.container=b,this.config=c,!b||!(b instanceof HTMLElement))throw new Error("`container` (argument 0) is required to initialize the image editor plugin.");_classPrivateFieldSet(this,_root,createRoot(this.container)),_classPrivateFieldSet(this,_getCurrentImgDataFnRef,{}),_classPrivateFieldSet(this,_updateStateFnRef,{}),this.getCurrentImgData=this.getCurrentImgData.bind(this),this.render=this.render.bind(this),this.terminate=this.terminate.bind(this),this.updateState=this.updateState.bind(this)}return _createClass(a,[{key:"render",value:function render(a){"object"===_typeof(a)&&(this.config=this.config=deepMerge(this.config||{},a)),this.config=_objectSpread(_objectSpread({},this.config),{},{getCurrentImgDataFnRef:_classPrivateFieldGet(this,_getCurrentImgDataFnRef),updateStateFnRef:_classPrivateFieldGet(this,_updateStateFnRef)}),_classPrivateFieldGet(this,_root)._internalRoot||_classPrivateFieldSet(this,_root,createRoot(this.container)),_classPrivateFieldGet(this,_root).render(createElement(AssemblyPoint,this.config))}},{key:"terminate",value:function terminate(){_classPrivateFieldGet(this,_root).unmount()}},{key:"getCurrentImgData",value:function getCurrentImgData(a,b,c){var d,e;return(null===(d=_classPrivateFieldGet(this,_getCurrentImgDataFnRef))||void 0===d||null===(e=d.current)||void 0===e?void 0:e.call(d,a,b,c))||{}}},{key:"updateState",value:function updateState(a){var b,c;null===(b=_classPrivateFieldGet(this,_updateStateFnRef))||void 0===b||null===(c=b.current)||void 0===c||c.call(b,a)}}]),a}();_defineProperty(FilerobotImageEditor,"TABS",TABS),_defineProperty(FilerobotImageEditor,"TOOLS",TOOLS),FilerobotImageEditor.TABS=TABS,FilerobotImageEditor.TOOLS=TOOLS;export default FilerobotImageEditor;