next-box 1.1.28 → 1.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter, EventHandler } from './event-emitter';
2
- import { AppState, ExtensionEvents } from './interfaces';
2
+ import { AppState, ExtensionEvents, ModalFilesSelect } from './interfaces';
3
3
  export declare class NextBox extends EventEmitter {
4
4
  state?: AppState;
5
5
  debug: boolean;
@@ -48,7 +48,9 @@ export declare class NextBox extends EventEmitter {
48
48
  * Submit a file change request
49
49
  */
50
50
  fileReplace(body: any): Promise<Response | null>;
51
+ openModalFilesSelect(state: ModalFilesSelect): void;
51
52
  private get metaPath();
53
+ private makeSearchParams;
52
54
  private relativePath;
53
55
  private subscribeEvent;
54
56
  }
package/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.PolymaticaApi=e():t.PolymaticaApi=e()}(globalThis,(()=>(()=>{"use strict";var t={752:function(t,e,n){var o,i=this&&this.__extends||(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},o(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),r=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var o,i=0,r=e.length;i<r;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0}),e.NextBox=void 0;var a=n(139),s=n(382),l=n(679),p=Object.values(l.ExtensionEvents),u=function(t){function e(){var e=t.call(this)||this;return e.debug=!1,e}return i(e,t),e.prototype.on=function(e,n){var o;return(null===(o=this.state)||void 0===o?void 0:o.debug)&&console.log("on",e,n),t.prototype.on.call(this,e,n)},e.prototype.off=function(e,n){var o;return(null===(o=this.state)||void 0===o?void 0:o.debug)&&console.log("off",e,n),t.prototype.off.call(this,e,n)},e.prototype.emit=function(e){for(var n,o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];return(null===(n=this.state)||void 0===n?void 0:n.debug)&&console.log("emit",e,o),t.prototype.emit.apply(this,r([e],o,!1))},Object.defineProperty(e.prototype,"fileUrl",{get:function(){return this.state?this.relativePath("/file",this.state.file_info.path,this.state.file_info.file):""},enumerable:!1,configurable:!0}),e.prototype.init=function(){this.subscribeEvent(),(0,s.sendEvent)(l.AppEvents.Init)},e.prototype.readMeta=function(){return this.state?fetch(this.metaPath,{method:"GET"}).then((function(t){return t.json()})).catch((function(){return{}})):new Promise((function(){return{}}))},e.prototype.saveMeta=function(t){return this.state?fetch(this.metaPath,{method:"POST",body:JSON.stringify(t)}):new Promise((function(){return{}}))},e.prototype.changeContent=function(t){(0,s.sendEvent)(l.AppEvents.ChangeContent,t)},e.prototype.close=function(t){(0,s.sendEvent)(l.AppEvents.Close,t)},e.prototype.download=function(){return this.fileDownload()},e.prototype.fileDownload=function(){return this.state?fetch(this.relativePath("/file",this.state.file_info.path,this.state.file_info.file),{method:"GET"}):new Promise((function(t){return{text:function(){return""}}}))},e.prototype.replace=function(t){return this.fileReplace(t)},e.prototype.fileReplace=function(t){return this.state?fetch(this.relativePath("/file/replace",this.state.file_info.path,this.state.file_info.file),{method:"PUT",body:t}):new Promise((function(t){t(null)}))},Object.defineProperty(e.prototype,"metaPath",{get:function(){if(!this.state)throw"state not found";return this.relativePath(this.state.file_info.path,".",(0,s.translite)((0,s.getLang)(this.state.extenstion.name)))},enumerable:!1,configurable:!0}),e.prototype.relativePath=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return decodeURI(r([null===(t=this.state)||void 0===t?void 0:t.api_path],e,!0).join(""))},e.prototype.subscribeEvent=function(){var e=this;window.addEventListener("message",(function(n){var o=n.data.event,i=n.data.payload;if(p.includes(o)){switch(e.debug&&console.log("frame.message",o,n.data),o){case l.ExtensionEvents.Ready:e.debug=i.debug,e.state=i;break;case l.ExtensionEvents.ChangeView:e.state&&(e.state.view=i)}t.prototype.emit.call(e,o,i)}}))},e}(a.EventEmitter);e.NextBox=u},139:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.EventEmitter=void 0;var n=function(){function t(){this._handlers=new Map}return t.prototype.on=function(t,e){var n;this._handlers.has(t)||this._handlers.set(t,new Set),null===(n=this._handlers.get(t))||void 0===n||n.add(e)},t.prototype.off=function(t,e){var n;null===(n=this._handlers.get(t))||void 0===n||n.delete(e)},t.prototype.emit=function(t){for(var e,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];null===(e=this._handlers.get(t))||void 0===e||e.forEach((function(t){t&&t.apply(void 0,n)}))},t}();e.EventEmitter=n},382:function(t,e,n){var o=this&&this.__assign||function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},o.apply(this,arguments)};Object.defineProperty(e,"__esModule",{value:!0}),e.translite=e.devState=e.sendEvent=e.getLang=void 0;var i=n(679),r=n(251);e.getLang=function(t,e){if(void 0===e&&(e="ru"),t[e])return t[e];var n=Object.keys(t).pop();return n&&t[n]?t[n]:""},e.sendEvent=function(t,e){parent!==window&&parent.postMessage({event:t,payload:e},window.location.origin)},e.devState=function(t){return o(o({debug:!0,view:i.ViewState.edit,api_path:""},t),{extenstion:o({id:0,name:{ru:""},type:i.ExtentionsType.File},t.extenstion),file_info:o({path:"",file:"",name:"",ext:""},t.file_info)})},e.translite=function(t){return(t=(t=(t=(t=(t=t.toLocaleLowerCase()).trim()).replace(/ -/gi,"-")).replace(/- /gi,"-")).replace(/\s{2,}/gi," ")).split("").map((function(t){return/[a-z]/i.test(t)?t:r[t]||""})).join("")}},607:function(t,e,n){var o=this&&this.__createBinding||(Object.create?function(t,e,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,o,i)}:function(t,e,n,o){void 0===o&&(o=n),t[o]=e[n]}),i=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||o(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),i(n(679),e),i(n(178),e),i(n(139),e),i(n(382),e),i(n(752),e)},178:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.initFileApi=e.init=void 0;var o=n(752),i=n(679);e.init=function(t){var e=new o.NextBox;return e.on(i.ExtensionEvents.Ready,t),e.init(),setTimeout((function(){window.parent===self&&t()})),e},e.initFileApi=function(){return new Promise((function(t){var e=new o.NextBox;e.on(i.ExtensionEvents.Ready,(function(){t(e)}))}))}},679:(t,e)=>{var n,o,i,r;Object.defineProperty(e,"__esModule",{value:!0}),e.ViewState=e.ExtensionEvents=e.AppEvents=e.ExtentionsType=void 0,(r=e.ExtentionsType||(e.ExtentionsType={})).App="app",r.File="file",(i=e.AppEvents||(e.AppEvents={})).Init="init",i.ChangeContent="change-content",i.Close="close",(o=e.ExtensionEvents||(e.ExtensionEvents={})).Ready="ready",o.ChangeView="change-view",o.SaveAndClose="save-and-close",(n=e.ViewState||(e.ViewState={})).view="view",n.edit="edit"},251:t=>{t.exports=JSON.parse('{"а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ё":"e","ж":"zh","з":"z","и":"i","й":"i","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"cz","ш":"sh","щ":"scz","ы":"y","ь":"","э":"e","ю":"u","я":"ja"," ":"-"}')}},e={};return function n(o){var i=e[o];if(void 0!==i)return i.exports;var r=e[o]={exports:{}};return t[o].call(r.exports,r,r.exports,n),r.exports}(607)})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PolymaticaApi=t():e.PolymaticaApi=t()}(globalThis,(()=>(()=>{"use strict";var e={752:function(e,t,n){var o,i=this&&this.__extends||(o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},o(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),r=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var o,i=0,r=t.length;i<r;i++)!o&&i in t||(o||(o=Array.prototype.slice.call(t,0,i)),o[i]=t[i]);return e.concat(o||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.NextBox=void 0;var a=n(139),s=n(382),l=n(679),p=Object.values(l.ExtensionEvents),c=function(e){function t(){var t=e.call(this)||this;return t.debug=!1,t}return i(t,e),t.prototype.on=function(t,n){var o;return(null===(o=this.state)||void 0===o?void 0:o.debug)&&console.log("on",t,n),e.prototype.on.call(this,t,n)},t.prototype.off=function(t,n){var o;return(null===(o=this.state)||void 0===o?void 0:o.debug)&&console.log("off",t,n),e.prototype.off.call(this,t,n)},t.prototype.emit=function(t){for(var n,o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];return(null===(n=this.state)||void 0===n?void 0:n.debug)&&console.log("emit",t,o),e.prototype.emit.apply(this,r([t],o,!1))},Object.defineProperty(t.prototype,"fileUrl",{get:function(){return this.state?this.relativePath("/file",this.state.file_info.path,this.state.file_info.file):""},enumerable:!1,configurable:!0}),t.prototype.init=function(){this.subscribeEvent(),(0,s.sendEvent)(l.AppEvents.Init)},t.prototype.readMeta=function(){return this.state?fetch(this.metaPath,{method:"GET"}).then((function(e){return e.json()})).catch((function(){return{}})):new Promise((function(){return{}}))},t.prototype.saveMeta=function(e){return this.state?fetch(this.metaPath,{method:"POST",body:JSON.stringify(e)}):new Promise((function(){return{}}))},t.prototype.changeContent=function(e){(0,s.sendEvent)(l.AppEvents.ChangeContent,e)},t.prototype.close=function(e){(0,s.sendEvent)(l.AppEvents.Close,e)},t.prototype.download=function(){return this.fileDownload()},t.prototype.fileDownload=function(){return this.state?fetch(this.relativePath("/file",this.state.file_info.path,this.state.file_info.file)+this.makeSearchParams({t:Date.now()}),{method:"GET"}):new Promise((function(e){return{text:function(){return""}}}))},t.prototype.replace=function(e){return this.fileReplace(e)},t.prototype.fileReplace=function(e){return this.state?fetch(this.relativePath("/file/replace",this.state.file_info.path,this.state.file_info.file),{method:"PUT",body:e}):new Promise((function(e){e(null)}))},t.prototype.openModalFilesSelect=function(e){(0,s.sendEvent)(l.AppEvents.OpenModalFilesSelect,e)},Object.defineProperty(t.prototype,"metaPath",{get:function(){if(!this.state)throw"state not found";return this.relativePath(this.state.file_info.path,".",(0,s.translite)((0,s.getLang)(this.state.extenstion.name)))},enumerable:!1,configurable:!0}),t.prototype.makeSearchParams=function(e){return"?"+new URLSearchParams(e)},t.prototype.relativePath=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return decodeURI(r([null===(e=this.state)||void 0===e?void 0:e.api_path],t,!0).join(""))},t.prototype.subscribeEvent=function(){var t=this;window.addEventListener("message",(function(n){var o=n.data.event,i=n.data.payload;if(p.includes(o)){switch(t.debug&&console.log("frame.message",o,n.data),o){case l.ExtensionEvents.Ready:t.debug=i.debug,t.state=i;break;case l.ExtensionEvents.ChangeView:t.state&&(t.state.view=i)}e.prototype.emit.call(t,o,i)}}))},t}(a.EventEmitter);t.NextBox=c},139:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventEmitter=void 0;var n=function(){function e(){this._handlers=new Map}return e.prototype.on=function(e,t){var n;this._handlers.has(e)||this._handlers.set(e,new Set),null===(n=this._handlers.get(e))||void 0===n||n.add(t)},e.prototype.off=function(e,t){var n;null===(n=this._handlers.get(e))||void 0===n||n.delete(t)},e.prototype.emit=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];null===(t=this._handlers.get(e))||void 0===t||t.forEach((function(e){e&&e.apply(void 0,n)}))},e}();t.EventEmitter=n},382:function(e,t,n){var o=this&&this.__assign||function(){return o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.translite=t.devState=t.sendEvent=t.getLang=void 0;var i=n(679),r=n(251);t.getLang=function(e,t){if(void 0===t&&(t="ru"),e[t])return e[t];var n=Object.keys(e).pop();return n&&e[n]?e[n]:""},t.sendEvent=function(e,t){parent!==window&&parent.postMessage({event:e,payload:t},window.location.origin)},t.devState=function(e){return o(o({debug:!0,view:i.ViewState.edit,api_path:""},e),{extenstion:o({id:0,name:{ru:""},type:i.ExtentionsType.File},e.extenstion),file_info:o({path:"",file:"",name:"",ext:""},e.file_info)})},t.translite=function(e){return(e=(e=(e=(e=(e=e.toLocaleLowerCase()).trim()).replace(/ -/gi,"-")).replace(/- /gi,"-")).replace(/\s{2,}/gi," ")).split("").map((function(e){return/[a-z]/i.test(e)?e:r[e]||""})).join("")}},607:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(679),t),i(n(178),t),i(n(139),t),i(n(382),t),i(n(752),t)},178:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.initFileApi=t.init=void 0;var o=n(752),i=n(679);t.init=function(e){var t=new o.NextBox;return t.on(i.ExtensionEvents.Ready,e),t.init(),setTimeout((function(){window.parent===self&&e()})),t},t.initFileApi=function(){return new Promise((function(e){var t=new o.NextBox;t.on(i.ExtensionEvents.Ready,(function(){e(t)}))}))}},679:(e,t)=>{var n,o,i,r;Object.defineProperty(t,"__esModule",{value:!0}),t.ViewState=t.ExtensionEvents=t.AppEvents=t.ExtentionsType=void 0,(r=t.ExtentionsType||(t.ExtentionsType={})).App="app",r.File="file",(i=t.AppEvents||(t.AppEvents={})).Init="init",i.ChangeContent="change-content",i.Close="close",i.OpenModalFilesSelect="open-modal-files-select",(o=t.ExtensionEvents||(t.ExtensionEvents={})).Ready="ready",o.ChangeView="change-view",o.SaveAndClose="save-and-close",o.FilesSelected="files-selected",(n=t.ViewState||(t.ViewState={})).view="view",n.edit="edit"},251:e=>{e.exports=JSON.parse('{"а":"a","б":"b","в":"v","г":"g","д":"d","е":"e","ё":"e","ж":"zh","з":"z","и":"i","й":"i","к":"k","л":"l","м":"m","н":"n","о":"o","п":"p","р":"r","с":"s","т":"t","у":"u","ф":"f","х":"h","ц":"c","ч":"cz","ш":"sh","щ":"scz","ы":"y","ь":"","э":"e","ю":"u","я":"ja"," ":"-"}')}},t={};return function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o].call(r.exports,r,r.exports,n),r.exports}(607)})()));
package/interfaces.d.ts CHANGED
@@ -11,23 +11,33 @@ export type MetaData = {
11
11
  export declare enum AppEvents {
12
12
  Init = "init",
13
13
  ChangeContent = "change-content",
14
- Close = "close"
14
+ Close = "close",
15
+ OpenModalFilesSelect = "open-modal-files-select"
15
16
  }
16
17
  export declare enum ExtensionEvents {
17
18
  Ready = "ready",
18
19
  ChangeView = "change-view",
19
- SaveAndClose = "save-and-close"
20
+ SaveAndClose = "save-and-close",
21
+ FilesSelected = "files-selected"
20
22
  }
21
23
  export interface TransportEvent {
22
24
  uid?: string;
23
25
  event: AppEvents | ExtensionEvents;
24
26
  payload?: TransportEventPayload;
25
27
  }
28
+ export type TransportEventPayload = AppState | ViewState | SelectedFiles | ModalFilesSelect | any;
29
+ export interface ModalFilesSelect {
30
+ multi?: boolean;
31
+ title?: string;
32
+ }
33
+ export interface SelectedFiles {
34
+ connection: number;
35
+ paths: string[];
36
+ }
26
37
  export declare enum ViewState {
27
38
  view = "view",
28
39
  edit = "edit"
29
40
  }
30
- export type TransportEventPayload = AppState | ViewState | any;
31
41
  export interface AppState {
32
42
  extenstion: {
33
43
  id: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-box",
3
- "version": "1.1.28",
3
+ "version": "1.1.30",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",