next-box 1.3.74 → 2.0.1

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/README.md CHANGED
@@ -1,6 +1,3 @@
1
- ![build: success](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:nextbox/npm-next-box/main/badges/build.svg)
2
- ![license: MIT](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:nextbox/npm-next-box/main/badges/license.svg)
3
-
4
1
  A library for developing extensions, components and working with data in the NextBox platform.
5
2
 
6
3
  ```javascript
@@ -87,3 +84,14 @@ npm install next-box
87
84
  https://cdn.jsdelivr.net/npm/next-box@latest/index.min.js
88
85
  "></script>
89
86
  ```
87
+
88
+ ```javascript
89
+ import NextBox from 'next-box';
90
+ import { StorageApi } from 'next-box/api/file-storage';
91
+ const nb = new NextBox();
92
+
93
+ nb.init((state) => {
94
+ const api = new StorageApi(state);
95
+ ...
96
+ });
97
+ ```
@@ -0,0 +1,2 @@
1
+ export * from './static-api';
2
+ export * from './storage-api';
@@ -1,8 +1,6 @@
1
- import { AppState, StaticFile } from "./interfaces";
2
- import { Api } from "./api";
1
+ import { Api } from '../classes/api';
2
+ import { StaticFile } from '../types/base';
3
3
  export declare class StaticApi extends Api {
4
- private staticDir;
5
- constructor(state: AppState);
6
4
  upload(file: Blob, name: string, path?: string): Promise<StaticFile>;
7
5
  get(path: string): Promise<Response>;
8
6
  delete(path: string): Promise<Response>;
@@ -1,18 +1,6 @@
1
- import { AppState, StorageElement } from './interfaces';
2
- import { Api } from './api';
3
- export declare class FileApi extends Api {
4
- state: AppState;
5
- /**
6
- * Returns the full path to download the file
7
- */
8
- get dowloadPath(): string;
9
- /**
10
- * Returns the path to the current file
11
- */
12
- get currentFilePath(): string;
13
- constructor(state: AppState);
14
- makeDownloadPath(path: string): string;
15
- relativePath(path?: string, defaultPath?: string): string;
1
+ import { Api } from '../classes/api';
2
+ import { StorageElement } from '../types/storage-element';
3
+ export declare class StorageApi extends Api {
16
4
  /**
17
5
  * Get file model
18
6
  */
@@ -59,8 +47,7 @@ export declare class FileApi extends Api {
59
47
  * Saving metadata extension
60
48
  */
61
49
  saveMeta(body: any, path?: string): Promise<any>;
50
+ relativePath(path?: string, defaultPath?: string): string;
62
51
  makeApiPath(...arg: string[]): string;
63
- private get metaPath();
64
- private get metaFileName();
65
- private responseJSON;
52
+ private get metaName();
66
53
  }
@@ -1,9 +1,10 @@
1
- import { AppState } from "./interfaces";
1
+ import { AppState } from '../types/state';
2
2
  export declare class Api {
3
- protected state: AppState;
4
- protected constructor(state: AppState);
3
+ state: AppState;
4
+ constructor(state: AppState);
5
5
  makeSearchParams(params: {
6
6
  [key: string]: any;
7
7
  }): string;
8
8
  makeHeaders(header?: Record<string, string>): Record<string, string>;
9
+ responseJSON(response: Response): Promise<any>;
9
10
  }
@@ -1,6 +1,8 @@
1
1
  export type EventHandler = (...args: any) => void;
2
2
  export declare class EventEmitter {
3
3
  _handlers: Map<string, Set<EventHandler>>;
4
+ _globalHandlers: Set<EventHandler>;
5
+ listen(handler: EventHandler): void;
4
6
  on(event: string, handler: EventHandler): void;
5
7
  off(event: string, handler: EventHandler): void;
6
8
  emit(event: string, ...args: any): void;
@@ -0,0 +1,2 @@
1
+ export * from './api';
2
+ export * from './event-emitter';
@@ -0,0 +1,2 @@
1
+ import { AppState } from '../types';
2
+ export declare const DefaultState: () => AppState;
@@ -0,0 +1 @@
1
+ export declare function dirname(path: string): string;
@@ -0,0 +1,2 @@
1
+ import { FileInfo } from '../types/base';
2
+ export declare function fileInfo(path: string): FileInfo;
@@ -0,0 +1,2 @@
1
+ import { Lang } from '../types/base';
2
+ export declare function getLang(lang: Lang, locale?: string): string;
@@ -0,0 +1,7 @@
1
+ export * from './dirname';
2
+ export * from './file-info';
3
+ export * from './get-lang';
4
+ export * from './parent-url';
5
+ export * from './path-join';
6
+ export * from './send-request';
7
+ export * from './translite';
@@ -0,0 +1 @@
1
+ export declare function parentURL(): URL;
@@ -0,0 +1 @@
1
+ export declare function pathJoin(...args: string[]): string;
@@ -0,0 +1 @@
1
+ export declare function sendRequest(input: string, init?: RequestInit): Promise<Response>;
@@ -0,0 +1 @@
1
+ export declare function translite(value: string): string;
package/app/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { EventEmitter, EventHandler } from './classes/event-emitter';
2
+ import { AppState } from './types/state';
3
+ import { TransportEvent, TransportPayloadModalFilesSelect, TransportPayloadNavigate } from './types/transport';
4
+ export declare class NextBox extends EventEmitter {
5
+ state?: AppState;
6
+ init(handler?: (state: AppState) => void): void;
7
+ /**
8
+ * Submit a content change message
9
+ * In the case when content is written before exiting the application or when writing large files
10
+ */
11
+ changeContent(state: boolean): void;
12
+ navigate(path: TransportPayloadNavigate['path'], queryParams?: TransportPayloadNavigate['queryParams']): void;
13
+ /**
14
+ * Send an event to close the editor
15
+ */
16
+ close(): void;
17
+ openModalFilesSelect(state: TransportPayloadModalFilesSelect): void;
18
+ on(event: TransportEvent, handler: EventHandler): void;
19
+ off(event: TransportEvent, handler: EventHandler): void;
20
+ emit(event: string, ...args: any): void;
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './interface';
2
+ export * from './transport';
@@ -0,0 +1,5 @@
1
+ import { TransportEvent, TransportPayload } from '../types/transport';
2
+ export interface TransportEngineInterface {
3
+ send(event: TransportEvent, payload?: TransportPayload): void;
4
+ subscribe(handler: (event: TransportEvent, ppayload: TransportPayload) => void): void;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { TransportEvent, TransportPayload } from '../types/transport';
2
+ import { TransportEngineInterface } from './interface';
3
+ export declare class TransportPostMessage implements TransportEngineInterface {
4
+ send(event: TransportEvent, payload?: any): void;
5
+ subscribe(handler: (event: TransportEvent, payload: TransportPayload) => void): void;
6
+ }
@@ -0,0 +1,18 @@
1
+ import { TransportEvent, TransportPayload } from '../types/transport';
2
+ import { EventEmitter } from '../classes/event-emitter';
3
+ declare global {
4
+ interface Window {
5
+ _nb_transport: NBTransport;
6
+ }
7
+ }
8
+ type EngineType = 'websocket' | 'postmessage' | '';
9
+ declare class NBTransport extends EventEmitter {
10
+ private engine;
11
+ engineType: EngineType;
12
+ debug: boolean;
13
+ constructor();
14
+ send(event: TransportEvent, payload?: TransportPayload): void;
15
+ subscribe(): void;
16
+ }
17
+ export declare const Transport: NBTransport;
18
+ export {};
@@ -0,0 +1,15 @@
1
+ import { TransportEvent } from '../types/transport';
2
+ import { TransportEngineInterface } from './interface';
3
+ declare const SOCKET: unique symbol;
4
+ declare global {
5
+ interface Window {
6
+ [SOCKET]: WebSocket;
7
+ }
8
+ }
9
+ export declare class TransportWebsocket implements TransportEngineInterface {
10
+ constructor();
11
+ init(): void;
12
+ send(event: TransportEvent, payload?: any): void;
13
+ subscribe(handler: (event: TransportEvent, ppayload: any) => void): void;
14
+ }
15
+ export {};
@@ -0,0 +1,18 @@
1
+ export type Lang = {
2
+ [key: string]: string;
3
+ };
4
+ export interface FileInfo {
5
+ base: string;
6
+ dir: string;
7
+ ext: string;
8
+ name: string;
9
+ root: string;
10
+ }
11
+ export declare enum ExtensionType {
12
+ App = "app",
13
+ File = "file",
14
+ WorkDir = "work_dir"
15
+ }
16
+ export interface StaticFile {
17
+ file_path: string;
18
+ }
@@ -0,0 +1,4 @@
1
+ export * from './base';
2
+ export * from './state';
3
+ export * from './storage-element';
4
+ export * from './transport';
@@ -0,0 +1,31 @@
1
+ import { ExtensionType, FileInfo, Lang } from './base';
2
+ export declare enum ViewState {
3
+ view = "view",
4
+ edit = "edit"
5
+ }
6
+ export interface AppState {
7
+ extenstion: {
8
+ id: number;
9
+ name: Lang;
10
+ type: ExtensionType;
11
+ };
12
+ api: {
13
+ host: string;
14
+ prefix: string;
15
+ headers: {
16
+ [key: string]: any;
17
+ };
18
+ query: {
19
+ [key: string]: any;
20
+ };
21
+ };
22
+ debug: boolean;
23
+ view: ViewState;
24
+ brouserURL: string;
25
+ storage: {
26
+ root: 'me' | 'fca';
27
+ rootID: number;
28
+ path: string;
29
+ info: FileInfo;
30
+ };
31
+ }
@@ -0,0 +1,30 @@
1
+ export interface StorageElement {
2
+ name: string;
3
+ size: number;
4
+ shared: boolean;
5
+ full_path: string;
6
+ path: string;
7
+ type: StorageElementType;
8
+ file_name_ext: string;
9
+ content_type: StorageElementContentType;
10
+ update_date: string;
11
+ with_preview: boolean;
12
+ is_favorite: boolean;
13
+ }
14
+ export declare enum StorageElementType {
15
+ Dir = "dir",
16
+ File = "file",
17
+ WorkDir = "work_dir"
18
+ }
19
+ export declare enum StorageElementContentType {
20
+ Any = "any",
21
+ Dir = "dir",
22
+ Code = "code",
23
+ Image = "image",
24
+ Audio = "audio",
25
+ Video = "video",
26
+ Text = "text",
27
+ Doc = "doc",
28
+ Xls = "xls",
29
+ Ppt = "ppt"
30
+ }
@@ -0,0 +1,39 @@
1
+ import { AppState } from './state';
2
+ export interface TransportData {
3
+ event: TransportEvent;
4
+ payload?: TransportPayload;
5
+ }
6
+ export declare enum TransportEvent {
7
+ ExtInit = "ext-init",
8
+ ExtChangeContent = "ext-change-content",
9
+ ExtOpenModalFilesSelect = "ext-open-modal-files-select",
10
+ ExtShowConfirm = "ext-show-confirm",
11
+ ExtNavigateTo = "ext-navigate-to",
12
+ ExtRequestError = "ext-request-error",
13
+ ExtClose = "ext-close",
14
+ AppReady = "app-ready",
15
+ AppChangeState = "app-change-state",
16
+ AppSaveAndClose = "app-save-and-close",
17
+ AppFilesSelected = "app-files-selected",
18
+ AppConfirmAccept = "app-confirm-accept",
19
+ AppConfirmReject = "app-confirm-reject"
20
+ }
21
+ export type TransportPayload = AppState | TransportPayloadSelectedFiles | TransportPayloadModalFilesSelect | TransportPayloadConfirm | TransportPayloadNavigate | any;
22
+ export interface TransportPayloadNavigate {
23
+ path: string;
24
+ queryParams?: {
25
+ [key: string]: string | boolean | number | null;
26
+ };
27
+ }
28
+ export interface TransportPayloadConfirm {
29
+ header: string;
30
+ message: string;
31
+ }
32
+ export interface TransportPayloadModalFilesSelect {
33
+ multy?: boolean;
34
+ title?: string;
35
+ }
36
+ export interface TransportPayloadSelectedFiles {
37
+ connection: number;
38
+ paths: string[];
39
+ }
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * from './interfaces';
2
- export * from './init';
3
- export * from './event-emitter';
4
- export * from './helpers';
5
1
  export * from './app';
2
+ export * from './app/types';
3
+ export * from './app/transport';
4
+ export * from './app/helpers';
5
+ export * from './app/classes';
6
+ export * from './app/api';
package/index.js CHANGED
@@ -1 +1 @@
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={203:function(e,t){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;var o=function(){function e(e){this.state=e}return e.prototype.makeSearchParams=function(e){if(this.state.file){e=n(n({},this.state.file.query),e);var t=this.state.file.share,o=t.share_token,r=t.password;o&&(e.share_token=o),r&&(e.SharePass=r)}return"?"+new URLSearchParams(e)},e.prototype.makeHeaders=function(e){var t=n({},e);if(this.state.file){var o=this.state.file.share,r=o.share_token,i=o.password;r&&(t.Authorization="Sharing ".concat(r)),i&&(t.SharePass=i)}return t},e}();t.Api=o},752:function(e,t,n){var o,r=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)}),i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);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(437),p=n(382),c=n(679),l=n(910),u=Object.values(c.ExtensionEvents),h=function(e){function t(){var t=e.call(this)||this;return t.debug=!1,t}return r(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=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return(null===(n=this.state)||void 0===n?void 0:n.debug)&&console.log("emit",t,o),e.prototype.emit.apply(this,i([t],o,!1))},t.prototype.init=function(){this.subscribeEvent(),(0,p.sendEvent)(c.AppEvents.Init)},t.prototype.changeContent=function(e){(0,p.sendEvent)(c.AppEvents.ChangeContent,e)},t.prototype.navigate=function(e,t){(0,p.sendEvent)(c.AppEvents.NavigateTo,{path:e,queryParams:t})},t.prototype.close=function(){(0,p.sendEvent)(c.AppEvents.Close)},t.prototype.openModalFilesSelect=function(e){(0,p.sendEvent)(c.AppEvents.OpenModalFilesSelect,e)},t.prototype.subscribeEvent=function(){var t=this;window.addEventListener("message",(function(n){var o=n.data.event,r=n.data.payload;if(u.includes(o)){switch(t.debug&&console.log("frame.message",o,n.data),o){case c.ExtensionEvents.Ready:t.debug=r.debug,t.state=r,t.fileApi=new s.FileApi(r),t.staticApi=new l.StaticApi(r);break;case c.ExtensionEvents.ChangeState:t.state&&(t.state=r)}e.prototype.emit.call(t,o,r)}}))},t}(a.EventEmitter);t.NextBox=h},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},437:function(e,t,n){var o,r=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)}),i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.FileApi=void 0;var a=n(382),s=function(e){function t(t){return e.call(this,t)||this}return r(t,e),Object.defineProperty(t.prototype,"dowloadPath",{get:function(){return this.makeDownloadPath(this.currentFilePath)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"currentFilePath",{get:function(){return(0,a.pathJoin)(this.state.file_info.dir,this.state.file_info.base)},enumerable:!1,configurable:!0}),t.prototype.makeDownloadPath=function(e){return this.makeApiPath("/files")+this.makeSearchParams({path:e})},t.prototype.relativePath=function(e,t){var n;return!e&&t?t||"":(0,a.pathJoin)((null===(n=this.state.file)||void 0===n?void 0:n.info.dir)||"",e||"")},t.prototype.info=function(e){return(0,a.sendRequest)(this.makeApiPath("/element")+this.makeSearchParams({path:e}),{headers:this.makeHeaders(),method:"GET",cache:"no-cache"}).then(this.responseJSON)},t.prototype.create=function(e,t,n){var o;return(0,a.sendRequest)(this.makeApiPath("/element"),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:JSON.stringify({name:e,path:this.relativePath(t),type:n,divide_id:(null===(o=this.state.file)||void 0===o?void 0:o.query.divide_id)||null})}).then(this.responseJSON)},t.prototype.delete=function(e,t){return(0,a.sendRequest)(this.makeApiPath("/element")+this.makeSearchParams({path:e,hard:t}),{method:"DELETE",headers:this.makeHeaders()})},t.prototype.download=function(e){return(0,a.sendRequest)(this.makeApiPath("/files")+this.makeSearchParams({path:this.relativePath(e,this.currentFilePath),t:Date.now()}),{headers:this.makeHeaders(),method:"GET",cache:"no-cache"})},t.prototype.replace=function(e,t){return(0,a.sendRequest)(this.makeApiPath("/files")+this.makeSearchParams({path:this.relativePath(t,this.currentFilePath)}),{cache:"no-cache",method:"PUT",body:e,headers:this.makeHeaders()}).then(this.responseJSON)},t.prototype.upload=function(e,t){var n=new FormData;return n.set("path",this.relativePath(e)),n.set("file",t),(0,a.sendRequest)(this.makeApiPath("/files"),{method:"POST",body:n,headers:this.makeHeaders()}).then(this.responseJSON)},t.prototype.uploadNet=function(e,t,n){return void 0===n&&(n=!1),(0,a.sendRequest)(this.makeApiPath("/files/net"),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:JSON.stringify({url:t,overwrite:n,path:this.relativePath(e)})}).then(this.responseJSON)},t.prototype.createMeta=function(e,t){return this.create(e||this.metaFileName,t||"","file")},t.prototype.readMeta=function(e){return this.download(e||this.metaPath)},t.prototype.saveMeta=function(e,t){return this.replace(e,t||this.metaPath)},t.prototype.makeApiPath=function(){for(var e,t,n,o,r,s=[],p=0;p<arguments.length;p++)s[p]=arguments[p];var c="storage";return(null===(e=this.state.file)||void 0===e?void 0:e.rootId)&&(c="disk/".concat(null===(t=this.state.file)||void 0===t?void 0:t.rootId)),(null===(n=this.state)||void 0===n?void 0:n.api_prefix)?decodeURI(a.pathJoin.apply(void 0,i([null===(o=this.state)||void 0===o?void 0:o.api_prefix,c],s,!1))):decodeURI(a.pathJoin.apply(void 0,i([null===(r=this.state)||void 0===r?void 0:r.api_path],s,!1)))},Object.defineProperty(t.prototype,"metaPath",{get:function(){if(!this.state.file)throw'"state.file" not found';return this.metaFileName},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metaFileName",{get:function(){return"."+(0,a.translite)((0,a.getLang)(this.state.extenstion.name))},enumerable:!1,configurable:!0}),t.prototype.responseJSON=function(e){return 200===e.status?e.json():Promise.resolve({error:"Parse error"})},t}(n(203).Api);t.FileApi=s},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 r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.parentURL=t.dirname=t.fileInfo=t.pathJoin=t.translite=t.devState=t.sendEvent=t.getLang=t.sendRequest=void 0;var r=n(679),i=n(251);function a(e,t){if(parent!==window){var n=new URL(window.location!=window.parent.location?document.referrer:document.location.href);parent.postMessage({event:e,payload:t},n.origin)}}function s(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=[],o=0,r=e.length;o<r;o++)n=n.concat(e[o].split("/"));var i=[];for(o=0,r=n.length;o<r;o++){var a=n[o];a&&"."!==a&&(".."===a?i.pop():i.push(a))}return""===n[0]&&i.unshift(""),i.join("/")||(i.length?"/":".")}function p(){return new URL(window.location!=window.parent.location?document.referrer:document.location.href)}t.sendRequest=function(e,t){var n=p().origin,o=new URL(e,n);return fetch(o,t).then((function(e){return parent!==window&&([401].includes(e.status)&&(parent.location.href="/auth"),(400===e.status||e.status>401)&&a(r.AppEvents.RequestError,e)),e}))},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=a,t.devState=function(e){return o(o({debug:!0,view:r.ViewState.edit,api_prefix:"",api_path:""},e),{extenstion:o({id:0,name:{ru:""},type:r.ExtensionType.File},e.extenstion),host:"",file_info:o({base:"",dir:"",ext:"",name:"",root:""},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-z0-9]/i.test(e)?e:i[e]||""})).join("")},t.pathJoin=s,t.fileInfo=function(e){var t={root:"",dir:"",base:"",ext:"",name:""};if(0===(e=s("/",e)).length)return t;var n,o=e.charCodeAt(0),r=47===o;r?(t.root="/",n=1):n=0;for(var i=-1,a=0,p=-1,c=!0,l=e.length-1,u=0;l>=n;--l)if(47!==(o=e.charCodeAt(l)))-1===p&&(c=!1,p=l+1),46===o?-1===i?i=l:1!==u&&(u=1):-1!==i&&(u=-1);else if(!c){a=l+1;break}return-1===i||-1===p||0===u||1===u&&i===p-1&&i===a+1?-1!==p&&(t.base=t.name=0===a&&r?e.slice(1,p):e.slice(a,p)):(0===a&&r?(t.name=e.slice(1,i),t.base=e.slice(1,p)):(t.name=e.slice(a,i),t.base=e.slice(a,p)),t.ext=e.slice(i,p)),a>0?t.dir=e.slice(0,a-1):r&&(t.dir="/"),t},t.dirname=function(e){if(0===(e=s("/",e)).length)return".";for(var t=e.charCodeAt(0),n=47===t,o=-1,r=!0,i=e.length-1;i>=1;--i)if(47===(t=e.charCodeAt(i))){if(!r){o=i;break}}else r=!1;return-1===o?n?"/":".":n&&1===o?"//":e.slice(0,o)},t.parentURL=p},607:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var r=Object.getOwnPropertyDescriptor(t,n);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,r)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=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}),r(n(679),t),r(n(178),t),r(n(139),t),r(n(382),t),r(n(752),t)},178:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.init=void 0;var o=n(752),r=n(679);t.init=function(e){var t=new o.NextBox;return t.on(r.ExtensionEvents.Ready,e),t.init(),setTimeout((function(){window.parent===self&&e()})),t}},679:(e,t)=>{var n,o,r,i,a,s,p;Object.defineProperty(t,"__esModule",{value:!0}),t.ShareType=t.SharePermissionType=t.StorageElementContentType=t.ExtensionType=t.StorageElementType=t.ViewState=t.ExtensionEvents=t.AppEvents=void 0,(p=t.AppEvents||(t.AppEvents={})).Init="init",p.ChangeContent="change-content",p.Close="close",p.OpenModalFilesSelect="open-modal-files-select",p.ShowConfirm="show-confirm",p.NavigateTo="navigate-to",p.RequestError="request-error",(s=t.ExtensionEvents||(t.ExtensionEvents={})).Ready="ready",s.ChangeState="change-state",s.SaveAndClose="save-and-close",s.FilesSelected="files-selected",s.ConfirmAccept="confirm-accept",s.ConfirmReject="confirm-reject",(a=t.ViewState||(t.ViewState={})).view="view",a.edit="edit",(i=t.StorageElementType||(t.StorageElementType={})).Dir="dir",i.File="file",i.WorkDir="work_dir",(r=t.ExtensionType||(t.ExtensionType={})).App="app",r.File="file",r.WorkDir="work_dir",(o=t.StorageElementContentType||(t.StorageElementContentType={})).Any="any",o.Dir="dir",o.Code="code",o.Image="image",o.Audio="audio",o.Video="video",o.Text="text",o.Doc="doc",o.Xls="xls",o.Ppt="ppt",(n=t.SharePermissionType||(t.SharePermissionType={})).Read="r",n.ReadAndWrite="rw",(t.ShareType||(t.ShareType={})).FileStorage="file_storage"},910:function(e,t,n){var o,r=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)});Object.defineProperty(t,"__esModule",{value:!0}),t.StaticApi=void 0;var i=n(382),a=function(e){function t(t){var n=e.call(this,t)||this;return n.staticDir="static/files",n}return r(t,e),t.prototype.upload=function(e,t,n){void 0===n&&(n="");var o=new FormData;return o.set("file",e),(0,i.sendRequest)((0,i.pathJoin)(this.state.api_prefix,this.staticDir,n,t),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:o}).then((function(e){return e.json()}))},t.prototype.get=function(e){return(0,i.sendRequest)((0,i.pathJoin)(this.state.api_prefix,this.staticDir,e),{method:"GET"})},t.prototype.delete=function(e){return(0,i.sendRequest)((0,i.pathJoin)(this.state.api_prefix,this.staticDir,e),{method:"DELETE"}).catch((function(e){return e}))},t}(n(203).Api);t.StaticApi=a},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 r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.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={181:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(481),t),o(n(861),t)},481:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.StaticApi=void 0;var i=n(892),a=n(307),s=n(392),p="static/files",c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.upload=function(e,t,n){void 0===n&&(n="");var r=new FormData;return r.set("file",e),(0,s.sendRequest)((0,a.pathJoin)(this.state.api.prefix,p,n,t),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:r}).then((function(e){return e.json()}))},t.prototype.get=function(e){return(0,s.sendRequest)((0,a.pathJoin)(this.state.api.prefix,p,e),{method:"GET"})},t.prototype.delete=function(e){return(0,s.sendRequest)((0,a.pathJoin)(this.state.api.prefix,p,e),{method:"DELETE"}).catch((function(e){return e}))},t}(i.Api);t.StaticApi=c},861:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.StorageApi=void 0;var a=n(307),s=n(892),p=n(566),c=n(392),u=n(299),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.info=function(e){return(0,c.sendRequest)(this.makeApiPath("/element")+this.makeSearchParams({path:e}),{headers:this.makeHeaders(),method:"GET",cache:"no-cache"}).then(this.responseJSON)},t.prototype.create=function(e,t,n){return(0,c.sendRequest)(this.makeApiPath("/element"),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:JSON.stringify({name:e,path:this.relativePath(t),type:n,divide_id:this.state.api.query.divide_id||null})}).then(this.responseJSON)},t.prototype.delete=function(e,t){return(0,c.sendRequest)(this.makeApiPath("/element")+this.makeSearchParams({path:e,hard:t}),{method:"DELETE",headers:this.makeHeaders()})},t.prototype.download=function(e){return(0,c.sendRequest)(this.makeApiPath("/files")+this.makeSearchParams({path:this.relativePath(e,this.state.storage.path),t:Date.now()}),{headers:this.makeHeaders(),method:"GET",cache:"no-cache"})},t.prototype.replace=function(e,t){return(0,c.sendRequest)(this.makeApiPath("/files")+this.makeSearchParams({path:this.relativePath(t,this.state.storage.path)}),{cache:"no-cache",method:"PUT",body:e,headers:this.makeHeaders()}).then(this.responseJSON)},t.prototype.upload=function(e,t){var n=new FormData;return n.set("path",this.relativePath(e)),n.set("file",t),(0,c.sendRequest)(this.makeApiPath("/files"),{method:"POST",body:n,headers:this.makeHeaders()}).then(this.responseJSON)},t.prototype.uploadNet=function(e,t,n){return void 0===n&&(n=!1),(0,c.sendRequest)(this.makeApiPath("/files/net"),{method:"POST",headers:this.makeHeaders({"Content-Type":"application/json"}),body:JSON.stringify({url:t,overwrite:n,path:this.relativePath(e)})}).then(this.responseJSON)},t.prototype.createMeta=function(e,t){return this.create(e||this.metaName,t||"","file")},t.prototype.readMeta=function(e){return this.download(e||this.metaName)},t.prototype.saveMeta=function(e,t){return this.replace(e,t||this.metaName)},t.prototype.relativePath=function(e,t){return!e&&t?t||"":(0,a.pathJoin)(this.state.storage.info.dir||"",e||"")},t.prototype.makeApiPath=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n="storage";return"fca"===this.state.storage.root&&(n="disk/".concat(this.state.storage.rootID)),decodeURI(a.pathJoin.apply(void 0,i([this.state.api.prefix,n],e,!1)))},Object.defineProperty(t.prototype,"metaName",{get:function(){return"."+(0,u.translite)((0,p.getLang)(this.state.extenstion.name))},enumerable:!1,configurable:!0}),t}(s.Api);t.StorageApi=l},892:function(e,t){var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.Api=void 0;var r=function(){function e(e){this.state=e}return e.prototype.makeSearchParams=function(e){return e=n(n({},this.state.api.query),e),"?"+new URLSearchParams(e)},e.prototype.makeHeaders=function(e){return n(n({},e),this.state.api.headers)},e.prototype.responseJSON=function(e){return 200===e.status?e.json():Promise.resolve({error:"Parse error"})},e}();t.Api=r},970:function(e,t){var n=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.EventEmitter=void 0;var r=function(){function e(){this._handlers=new Map,this._globalHandlers=new Set}return e.prototype.listen=function(e){this._globalHandlers.add(e)},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,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];null===(t=this._handlers.get(e))||void 0===t||t.forEach((function(e){e&&e.apply(void 0,r)})),this._globalHandlers.forEach((function(t){t.apply(void 0,n([e],r,!1))}))},e}();t.EventEmitter=r},534:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(892),t),o(n(970),t)},755:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DefaultState=void 0;var r=n(796);t.DefaultState=function(){return{extenstion:{id:0,name:{},type:r.ExtensionType.File},api:{host:"",prefix:"",headers:{},query:{}},debug:!0,view:r.ViewState.view,brouserURL:"",storage:{root:"me",rootID:0,path:"",info:{base:"",dir:"",ext:"",name:"",root:""}}}}},223:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.dirname=void 0;var r=n(307);t.dirname=function(e){if(0===(e=(0,r.pathJoin)("/",e)).length)return".";for(var t=e.charCodeAt(0),n=47===t,o=-1,i=!0,a=e.length-1;a>=1;--a)if(47===(t=e.charCodeAt(a))){if(!i){o=a;break}}else i=!1;return-1===o?n?"/":".":n&&1===o?"//":e.slice(0,o)}},572:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.fileInfo=void 0;var r=n(307);t.fileInfo=function(e){var t={root:"",dir:"",base:"",ext:"",name:""};if(0===(e=(0,r.pathJoin)("/",e)).length)return t;var n,o=e.charCodeAt(0),i=47===o;i?(t.root="/",n=1):n=0;for(var a=-1,s=0,p=-1,c=!0,u=e.length-1,l=0;u>=n;--u)if(47!==(o=e.charCodeAt(u)))-1===p&&(c=!1,p=u+1),46===o?-1===a?a=u:1!==l&&(l=1):-1!==a&&(l=-1);else if(!c){s=u+1;break}return-1===a||-1===p||0===l||1===l&&a===p-1&&a===s+1?-1!==p&&(t.base=t.name=0===s&&i?e.slice(1,p):e.slice(s,p)):(0===s&&i?(t.name=e.slice(1,a),t.base=e.slice(1,p)):(t.name=e.slice(s,a),t.base=e.slice(s,p)),t.ext=e.slice(a,p)),s>0?t.dir=e.slice(0,s-1):i&&(t.dir="/"),t}},566:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getLang=void 0,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]:""}},462:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(223),t),o(n(572),t),o(n(566),t),o(n(719),t),o(n(307),t),o(n(392),t),o(n(299),t)},719:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parentURL=void 0,t.parentURL=function(){return new URL(window.location!=window.parent.location?document.referrer:document.location.href)}},307:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.pathJoin=void 0,t.pathJoin=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n=[],r=0,o=e.length;r<o;r++)n=n.concat(e[r].split("/"));var i=[];for(r=0,o=n.length;r<o;r++){var a=n[r];a&&"."!==a&&(".."===a?i.pop():i.push(a))}return""===n[0]&&i.unshift(""),i.join("/")||(i.length?"/":".")}},392:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.sendRequest=void 0;var r=n(831),o=n(512),i=n(719);t.sendRequest=function(e,t){var n=(0,i.parentURL)().origin,a=new URL(e,n);return fetch(a,t).then((function(e){return parent!==window&&([401].includes(e.status)&&(parent.location.href="/auth"),(400===e.status||e.status>401)&&r.Transport.send(o.TransportEvent.ExtRequestError,e)),e}))}},299:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.translite=void 0;var n={а:"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.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-z0-9]/i.test(e)?e:n[e]||""})).join("")}},495:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.NextBox=void 0;var a=n(970),s=n(755),p=n(831),c=n(512),u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.init=function(e){var t=this,n=function(e){return t.state=e};if(!p.Transport.engineType){var r=(0,s.DefaultState)();n(r),e&&e(r)}p.Transport.on(c.TransportEvent.AppReady,(function(t){n(t),e&&e(t)})),p.Transport.on(c.TransportEvent.AppChangeState,n),p.Transport.send(c.TransportEvent.ExtInit)},t.prototype.changeContent=function(e){p.Transport.send(c.TransportEvent.ExtChangeContent,e)},t.prototype.navigate=function(e,t){p.Transport.send(c.TransportEvent.ExtNavigateTo,{path:e,queryParams:t})},t.prototype.close=function(){p.Transport.send(c.TransportEvent.ExtClose)},t.prototype.openModalFilesSelect=function(e){p.Transport.send(c.TransportEvent.ExtOpenModalFilesSelect,e)},t.prototype.on=function(t,n){var r;return(null===(r=this.state)||void 0===r?void 0:r.debug)&&console.log("on",t,n),e.prototype.on.call(this,t,n)},t.prototype.off=function(t,n){var r;return(null===(r=this.state)||void 0===r?void 0:r.debug)&&console.log("off",t,n),e.prototype.off.call(this,t,n)},t.prototype.emit=function(t){for(var n,r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];return(null===(n=this.state)||void 0===n?void 0:n.debug)&&console.log("emit",t,r),e.prototype.emit.apply(this,i([t],r,!1))},t}(a.EventEmitter);t.NextBox=u},176:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(595),t),o(n(831),t)},595:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0})},521:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TransportPostMessage=void 0;var n=function(){function e(){}return e.prototype.send=function(e,t){if(parent!==window){var n=new URL(window.location!=window.parent.location?document.referrer:document.location.href);parent.postMessage({event:e,payload:t},n.origin)}},e.prototype.subscribe=function(e){window.addEventListener("message",(function(t){var n=t.data.event,r=t.data.payload;e(n,r)}))},e}();t.TransportPostMessage=n},831:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=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])},r(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}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.Transport=void 0;var i=n(970),a=n(521),s=function(e){function t(){var t=e.call(this)||this;t.engineType="",t.debug=!1;var n=new URLSearchParams(window.location.search);return t.engineType=n.get("engine")||"",t.engine=new a.TransportPostMessage,t}return o(t,e),t.prototype.send=function(e,t){this.engine.send(e,t)},t.prototype.subscribe=function(){var e=this;this.engine.subscribe((function(t,n){t&&(e.debug&&console.log("frame.message",t,n),e.emit(t,n))}))},t}(i.EventEmitter);window._nb_transport instanceof s||(window._nb_transport=new s),t.Transport=window._nb_transport},85:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.ExtensionType=void 0,(n=t.ExtensionType||(t.ExtensionType={})).App="app",n.File="file",n.WorkDir="work_dir"},796:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(85),t),o(n(492),t),o(n(517),t),o(n(512),t)},492:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.ViewState=void 0,(n=t.ViewState||(t.ViewState={})).view="view",n.edit="edit"},517:(e,t)=>{var n,r;Object.defineProperty(t,"__esModule",{value:!0}),t.StorageElementContentType=t.StorageElementType=void 0,(r=t.StorageElementType||(t.StorageElementType={})).Dir="dir",r.File="file",r.WorkDir="work_dir",(n=t.StorageElementContentType||(t.StorageElementContentType={})).Any="any",n.Dir="dir",n.Code="code",n.Image="image",n.Audio="audio",n.Video="video",n.Text="text",n.Doc="doc",n.Xls="xls",n.Ppt="ppt"},512:(e,t)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.TransportEvent=void 0,(n=t.TransportEvent||(t.TransportEvent={})).ExtInit="ext-init",n.ExtChangeContent="ext-change-content",n.ExtOpenModalFilesSelect="ext-open-modal-files-select",n.ExtShowConfirm="ext-show-confirm",n.ExtNavigateTo="ext-navigate-to",n.ExtRequestError="ext-request-error",n.ExtClose="ext-close",n.AppReady="app-ready",n.AppChangeState="app-change-state",n.AppSaveAndClose="app-save-and-close",n.AppFilesSelected="app-files-selected",n.AppConfirmAccept="app-confirm-accept",n.AppConfirmReject="app-confirm-reject"},607:function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var o=Object.getOwnPropertyDescriptor(t,n);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,o)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(495),t),o(n(796),t),o(n(176),t),o(n(462),t),o(n(534),t),o(n(181),t)}},t={};return function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(607)})()));
package/init.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { NextBox } from './app';
2
- import { EventHandler } from './event-emitter';
2
+ import { EventHandler } from './app/classes';
3
3
  export declare function init(readyHandler: EventHandler): NextBox;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-box",
3
- "version": "1.3.74",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/app.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { EventEmitter, EventHandler } from './event-emitter';
2
- import { FileApi } from './file-api';
3
- import { AppState, ExtensionEvents, ModalFilesSelect, NavigateState } from './interfaces';
4
- import { StaticApi } from "./static-api";
5
- export declare class NextBox extends EventEmitter {
6
- state?: AppState;
7
- fileApi?: FileApi;
8
- staticApi?: StaticApi;
9
- debug: boolean;
10
- constructor();
11
- on(event: ExtensionEvents, handler: EventHandler): void;
12
- off(event: ExtensionEvents, handler: EventHandler): void;
13
- emit(event: string, ...args: any): void;
14
- /**
15
- * Subscribe postMessage and send an initialization event
16
- */
17
- init(): void;
18
- /**
19
- * Submit a content change message
20
- * In the case when content is written before exiting the application or when writing large files
21
- */
22
- changeContent(state: boolean): void;
23
- navigate(path: NavigateState['path'], queryParams?: NavigateState['queryParams']): void;
24
- /**
25
- * Send an event to close the editor
26
- */
27
- close(): void;
28
- openModalFilesSelect(state: ModalFilesSelect): void;
29
- private subscribeEvent;
30
- }
@@ -1 +0,0 @@
1
- export {};
package/helpers.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { TransportEventPayload, AppEvents, AppState, Lang, FileInfo } from './interfaces';
2
- export declare function sendRequest(input: string, init?: RequestInit): Promise<Response>;
3
- export declare function getLang(lang: Lang, locale?: string): string;
4
- export declare function sendEvent(event: AppEvents, payload?: TransportEventPayload): void;
5
- export declare function devState(state: Partial<AppState>): AppState;
6
- export declare function translite(value: string): string;
7
- export declare function pathJoin(...args: string[]): string;
8
- export declare function fileInfo(path: string): FileInfo;
9
- export declare function dirname(path: string): string;
10
- export declare function parentURL(): URL;
package/helpers.test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/interfaces.d.ts DELETED
@@ -1,175 +0,0 @@
1
- export type Lang = {
2
- [key: string]: string;
3
- };
4
- export type MetaData = {
5
- [key: string]: any;
6
- };
7
- export declare enum AppEvents {
8
- Init = "init",
9
- ChangeContent = "change-content",
10
- Close = "close",
11
- OpenModalFilesSelect = "open-modal-files-select",
12
- ShowConfirm = "show-confirm",
13
- NavigateTo = "navigate-to",
14
- RequestError = "request-error"
15
- }
16
- export declare enum ExtensionEvents {
17
- Ready = "ready",
18
- ChangeState = "change-state",
19
- SaveAndClose = "save-and-close",
20
- FilesSelected = "files-selected",
21
- ConfirmAccept = "confirm-accept",
22
- ConfirmReject = "confirm-reject"
23
- }
24
- export interface TransportEvent {
25
- uid?: string;
26
- event: AppEvents | ExtensionEvents;
27
- payload?: TransportEventPayload;
28
- }
29
- export type TransportEventPayload = AppState | ViewState | SelectedFiles | ModalFilesSelect | ConfirmState | NavigateState | any;
30
- export interface NavigateState {
31
- path: string;
32
- queryParams?: {
33
- [key: string]: string | boolean | number | null;
34
- };
35
- }
36
- export interface ConfirmState {
37
- header: string;
38
- message: string;
39
- }
40
- export interface ModalFilesSelect {
41
- multy?: boolean;
42
- title?: string;
43
- }
44
- export interface SelectedFiles {
45
- connection: number;
46
- paths: string[];
47
- }
48
- export declare enum ViewState {
49
- view = "view",
50
- edit = "edit"
51
- }
52
- export declare enum StorageElementType {
53
- Dir = "dir",
54
- File = "file",
55
- WorkDir = "work_dir"
56
- }
57
- export declare enum ExtensionType {
58
- App = "app",
59
- File = "file",
60
- WorkDir = "work_dir"
61
- }
62
- export declare enum StorageElementContentType {
63
- Any = "any",
64
- Dir = "dir",
65
- Code = "code",
66
- Image = "image",
67
- Audio = "audio",
68
- Video = "video",
69
- Text = "text",
70
- Doc = "doc",
71
- Xls = "xls",
72
- Ppt = "ppt"
73
- }
74
- export declare enum SharePermissionType {
75
- Read = "r",
76
- ReadAndWrite = "rw"
77
- }
78
- export declare enum ShareType {
79
- FileStorage = "file_storage"
80
- }
81
- export interface ShareSetting {
82
- path: string;
83
- password: string;
84
- share_token: string;
85
- permission_type: SharePermissionType;
86
- share_type: ShareType;
87
- }
88
- export interface AppState {
89
- extenstion: {
90
- id: number;
91
- name: Lang;
92
- type: ExtensionType;
93
- };
94
- app?: {
95
- path: string;
96
- };
97
- api_prefix: string;
98
- /**
99
- * @deprecated since version 1.4.0
100
- */
101
- api_path: string;
102
- /**
103
- * @deprecated since version 1.4.0
104
- */
105
- file_info: FileInfo;
106
- host: string;
107
- file?: {
108
- info: FileInfo;
109
- share: ShareSetting;
110
- query: {
111
- [key: string]: any;
112
- };
113
- rootId: number;
114
- };
115
- debug: boolean;
116
- view: ViewState;
117
- }
118
- export interface StorageElement {
119
- name: string;
120
- size: number;
121
- shared: boolean;
122
- full_path: string;
123
- path: string;
124
- type: StorageElementType;
125
- file_name_ext: string;
126
- content_type: StorageElementContentType;
127
- update_date: string;
128
- with_preview: boolean;
129
- is_favorite: boolean;
130
- }
131
- export interface FileInfo {
132
- base: string;
133
- dir: string;
134
- ext: string;
135
- name: string;
136
- root: string;
137
- }
138
- export interface StaticFile {
139
- file_path: string;
140
- }
141
- export interface AppConfig {
142
- version: string;
143
- uniq_key: string;
144
- icon: string;
145
- name: {
146
- [key: string]: string;
147
- };
148
- description: {
149
- [key: string]: string;
150
- };
151
- type: 'file' | 'work_dir' | 'app';
152
- file?: {
153
- mode: 'read' | 'write' | 'read_and_write';
154
- ext: string[];
155
- index: string;
156
- };
157
- app?: {
158
- menu: {
159
- index: string;
160
- icon: string;
161
- label: {
162
- [key: string]: string;
163
- };
164
- };
165
- };
166
- work_dir?: {
167
- index: string;
168
- };
169
- change_log?: {
170
- version: string;
171
- comment: {
172
- [key: string]: string;
173
- };
174
- }[];
175
- }