next-box 1.2.1 → 1.3.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 +5 -9
- package/app.d.ts +2 -23
- package/file-api.d.ts +46 -0
- package/index.js +1 -1
- package/interfaces.d.ts +29 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,11 +7,6 @@ A library for developing extensions, components and working with data in the Nex
|
|
|
7
7
|
import { init, ExtensionEvents } from 'next-box';
|
|
8
8
|
|
|
9
9
|
const nb = init(() => {
|
|
10
|
-
/**
|
|
11
|
-
* Get file url
|
|
12
|
-
*/
|
|
13
|
-
console.log(nb.fileUrl);
|
|
14
|
-
|
|
15
10
|
/**
|
|
16
11
|
* Get app state
|
|
17
12
|
*/
|
|
@@ -20,7 +15,8 @@ const nb = init(() => {
|
|
|
20
15
|
/**
|
|
21
16
|
* Download file
|
|
22
17
|
*/
|
|
23
|
-
nb.
|
|
18
|
+
nb.fileApi
|
|
19
|
+
.download()
|
|
24
20
|
.then((response) => response.text())
|
|
25
21
|
.then((data) => {
|
|
26
22
|
document.body.innerHTML = data;
|
|
@@ -29,7 +25,7 @@ const nb = init(() => {
|
|
|
29
25
|
/**
|
|
30
26
|
* Replace file content
|
|
31
27
|
*/
|
|
32
|
-
nb.replace('new content');
|
|
28
|
+
nb.fileApi.replace('new content');
|
|
33
29
|
|
|
34
30
|
/**
|
|
35
31
|
* Display change event
|
|
@@ -67,12 +63,12 @@ const nb = init(() => {
|
|
|
67
63
|
/**
|
|
68
64
|
* Saving metadata extension
|
|
69
65
|
*/
|
|
70
|
-
nb.saveMeta({ my_key: 'value' });
|
|
66
|
+
nb.fileApi.saveMeta({ my_key: 'value' });
|
|
71
67
|
|
|
72
68
|
/**
|
|
73
69
|
* Reading metadata extension
|
|
74
70
|
*/
|
|
75
|
-
nb.readMeta().then((data) => {
|
|
71
|
+
nb.fileApi.readMeta().then((data) => {
|
|
76
72
|
console.log(data.my_key);
|
|
77
73
|
});
|
|
78
74
|
});
|
package/app.d.ts
CHANGED
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { EventEmitter, EventHandler } from './event-emitter';
|
|
2
|
+
import { FileApi } from './file-api';
|
|
2
3
|
import { AppState, ExtensionEvents, ModalFilesSelect } from './interfaces';
|
|
3
4
|
export declare class NextBox extends EventEmitter {
|
|
4
5
|
state?: AppState;
|
|
6
|
+
fileApi?: FileApi;
|
|
5
7
|
debug: boolean;
|
|
6
8
|
constructor();
|
|
7
9
|
on(event: ExtensionEvents, handler: EventHandler): void;
|
|
8
10
|
off(event: ExtensionEvents, handler: EventHandler): void;
|
|
9
11
|
emit(event: string, ...args: any): void;
|
|
10
|
-
/**
|
|
11
|
-
* Returns the full path to download the file
|
|
12
|
-
*/
|
|
13
|
-
get fileUrl(): string;
|
|
14
12
|
/**
|
|
15
13
|
* Subscribe postMessage and send an initialization event
|
|
16
14
|
*/
|
|
17
15
|
init(): void;
|
|
18
|
-
/**
|
|
19
|
-
* Reading metadata extension
|
|
20
|
-
*/
|
|
21
|
-
readMeta(): Promise<any>;
|
|
22
|
-
/**
|
|
23
|
-
* Saving metadata extension
|
|
24
|
-
*/
|
|
25
|
-
saveMeta(body: any): Promise<any>;
|
|
26
16
|
/**
|
|
27
17
|
* Submit a content change message
|
|
28
18
|
* In the case when content is written before exiting the application or when writing large files
|
|
@@ -32,17 +22,6 @@ export declare class NextBox extends EventEmitter {
|
|
|
32
22
|
* Send an event to close the editor
|
|
33
23
|
*/
|
|
34
24
|
close(state: boolean): void;
|
|
35
|
-
/**
|
|
36
|
-
* Submit a file download request
|
|
37
|
-
*/
|
|
38
|
-
fileDownload(): Promise<Response | Pick<Response, 'text'>>;
|
|
39
|
-
/**
|
|
40
|
-
* Submit a file change request
|
|
41
|
-
*/
|
|
42
|
-
fileReplace(body: any): Promise<Response | null>;
|
|
43
25
|
openModalFilesSelect(state: ModalFilesSelect): void;
|
|
44
|
-
private get metaPath();
|
|
45
|
-
private makeSearchParams;
|
|
46
|
-
private relativePath;
|
|
47
26
|
private subscribeEvent;
|
|
48
27
|
}
|
package/file-api.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AppState, StorageElement } from './interfaces';
|
|
2
|
+
export declare class FileApi {
|
|
3
|
+
private state;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the full path to download the file
|
|
6
|
+
*/
|
|
7
|
+
get filePath(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the path to the current file
|
|
10
|
+
*/
|
|
11
|
+
get currentFilePath(): string;
|
|
12
|
+
constructor(state: AppState);
|
|
13
|
+
/**
|
|
14
|
+
* Get file model
|
|
15
|
+
*/
|
|
16
|
+
info(path: string): Promise<StorageElement>;
|
|
17
|
+
/**
|
|
18
|
+
* Create empty file
|
|
19
|
+
*/
|
|
20
|
+
create(name: string, path: string, type: 'dir' | 'file'): Promise<{
|
|
21
|
+
row: StorageElement;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Delete file
|
|
25
|
+
*/
|
|
26
|
+
delete(path: string, hard?: boolean): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Submit a file download request
|
|
29
|
+
*/
|
|
30
|
+
download(path?: string): Promise<Response | Pick<Response, 'text'>>;
|
|
31
|
+
/**
|
|
32
|
+
* Submit a file change request
|
|
33
|
+
*/
|
|
34
|
+
replace(body: any, path?: string): Promise<Response | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Reading metadata extension
|
|
37
|
+
*/
|
|
38
|
+
readMeta(path?: string): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* Saving metadata extension
|
|
41
|
+
*/
|
|
42
|
+
saveMeta(body: any, path?: string): Promise<any>;
|
|
43
|
+
private get metaPath();
|
|
44
|
+
private makeSearchParams;
|
|
45
|
+
private relativePath;
|
|
46
|
+
}
|
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={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(
|
|
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(437),l=n(382),p=n(679),c=Object.values(p.ExtensionEvents),u=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))},t.prototype.init=function(){this.subscribeEvent(),(0,l.sendEvent)(p.AppEvents.Init)},t.prototype.changeContent=function(e){(0,l.sendEvent)(p.AppEvents.ChangeContent,e)},t.prototype.close=function(e){(0,l.sendEvent)(p.AppEvents.Close,e)},t.prototype.openModalFilesSelect=function(e){(0,l.sendEvent)(p.AppEvents.OpenModalFilesSelect,e)},t.prototype.subscribeEvent=function(){var t=this;window.addEventListener("message",(function(n){var o=n.data.event,i=n.data.payload;if(c.includes(o)){switch(t.debug&&console.log("frame.message",o,n.data),o){case p.ExtensionEvents.Ready:t.debug=i.debug,t.state=i,t.fileApi=new s.FileApi(i);break;case p.ExtensionEvents.ChangeView:t.state&&(t.state.view=i)}e.prototype.emit.call(t,o,i)}}))},t}(a.EventEmitter);t.NextBox=u},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=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.FileApi=void 0;var i=n(382),r=function(){function e(e){this.state=e}return Object.defineProperty(e.prototype,"filePath",{get:function(){return this.relativePath("/file",this.state.file_info.path,this.state.file_info.file)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentFilePath",{get:function(){return[this.state.file_info.path,this.state.file_info.file].join("")},enumerable:!1,configurable:!0}),e.prototype.info=function(e){return fetch(this.relativePath("/element",e),{method:"GET",cache:"no-cache"}).then((function(e){return e.json()}))},e.prototype.create=function(e,t,n){return fetch(this.relativePath("/element",t),{method:"POST",body:JSON.stringify({name:e,path:t,type:n})}).then((function(e){return e.json()}))},e.prototype.delete=function(e,t){return fetch(this.relativePath("/element")+this.makeSearchParams({path:e,hard:t}),{method:"DELETE"})},e.prototype.download=function(e){return fetch(this.relativePath("/file",e||this.currentFilePath)+this.makeSearchParams({t:Date.now()}),{method:"GET",cache:"no-cache"})},e.prototype.replace=function(e,t){return fetch(this.relativePath("/file/replace",t||this.currentFilePath),{cache:"no-cache",method:"PUT",body:e})},e.prototype.readMeta=function(e){return fetch(this.relativePath(e||this.metaPath),{method:"GET"})},e.prototype.saveMeta=function(e,t){return fetch(this.relativePath(t||this.metaPath),{method:"POST",body:e})},Object.defineProperty(e.prototype,"metaPath",{get:function(){return[this.state.file_info.path,".",(0,i.translite)((0,i.getLang)(this.state.extenstion.name))].join("")},enumerable:!1,configurable:!0}),e.prototype.makeSearchParams=function(e){return"?"+new URLSearchParams(e)},e.prototype.relativePath=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return decodeURI(o([null===(e=this.state)||void 0===e?void 0:e.api_path],t,!0).join(""))},e}();t.FileApi=r},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.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}},679:(e,t)=>{var n,o,i,r,a,s;Object.defineProperty(t,"__esModule",{value:!0}),t.StorageElementContentType=t.StorageElementType=t.ViewState=t.ExtensionEvents=t.AppEvents=t.ExtentionsType=void 0,(s=t.ExtentionsType||(t.ExtentionsType={})).App="app",s.File="file",(a=t.AppEvents||(t.AppEvents={})).Init="init",a.ChangeContent="change-content",a.Close="close",a.OpenModalFilesSelect="open-modal-files-select",(r=t.ExtensionEvents||(t.ExtensionEvents={})).Ready="ready",r.ChangeView="change-view",r.SaveAndClose="save-and-close",r.FilesSelected="files-selected",(i=t.ViewState||(t.ViewState={})).view="view",i.edit="edit",(o=t.StorageElementType||(t.StorageElementType={})).Dir="dir",o.File="file",o.AppDir="app_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"},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
|
@@ -27,7 +27,7 @@ export interface TransportEvent {
|
|
|
27
27
|
}
|
|
28
28
|
export type TransportEventPayload = AppState | ViewState | SelectedFiles | ModalFilesSelect | any;
|
|
29
29
|
export interface ModalFilesSelect {
|
|
30
|
-
|
|
30
|
+
multy?: boolean;
|
|
31
31
|
title?: string;
|
|
32
32
|
}
|
|
33
33
|
export interface SelectedFiles {
|
|
@@ -38,6 +38,23 @@ export declare enum ViewState {
|
|
|
38
38
|
view = "view",
|
|
39
39
|
edit = "edit"
|
|
40
40
|
}
|
|
41
|
+
export declare enum StorageElementType {
|
|
42
|
+
Dir = "dir",
|
|
43
|
+
File = "file",
|
|
44
|
+
AppDir = "app_dir"
|
|
45
|
+
}
|
|
46
|
+
export declare enum StorageElementContentType {
|
|
47
|
+
Any = "any",
|
|
48
|
+
Dir = "dir",
|
|
49
|
+
Code = "code",
|
|
50
|
+
Image = "image",
|
|
51
|
+
Audio = "audio",
|
|
52
|
+
Video = "video",
|
|
53
|
+
Text = "text",
|
|
54
|
+
Doc = "doc",
|
|
55
|
+
Xls = "xls",
|
|
56
|
+
Ppt = "ppt"
|
|
57
|
+
}
|
|
41
58
|
export interface AppState {
|
|
42
59
|
extenstion: {
|
|
43
60
|
id: number;
|
|
@@ -54,3 +71,14 @@ export interface AppState {
|
|
|
54
71
|
debug: boolean;
|
|
55
72
|
view: ViewState;
|
|
56
73
|
}
|
|
74
|
+
export interface StorageElement {
|
|
75
|
+
name: string;
|
|
76
|
+
size: number;
|
|
77
|
+
shared: boolean;
|
|
78
|
+
full_path: string;
|
|
79
|
+
type: StorageElementType;
|
|
80
|
+
file_name_ext: string;
|
|
81
|
+
content_type: StorageElementContentType;
|
|
82
|
+
update_date: string;
|
|
83
|
+
with_preview: boolean;
|
|
84
|
+
}
|