next-box 1.1.11 → 1.1.12
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 +16 -13
- package/index.js +1 -1
- package/init.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,18 +6,21 @@ A library for developing extensions, components and working with data in the Nex
|
|
|
6
6
|
```javascript
|
|
7
7
|
import { init, ExtensionEvents } from 'next-box';
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
app.on(ExtensionEvents.Ready, () => {
|
|
9
|
+
const nb = init(() => {
|
|
12
10
|
/**
|
|
13
11
|
* Get file url
|
|
14
12
|
*/
|
|
15
|
-
console.log(
|
|
13
|
+
console.log(nb.fileUrl);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get app state
|
|
17
|
+
*/
|
|
18
|
+
console.log(nb.state);
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Download file
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
nb.download()
|
|
21
24
|
.then((response) => response.text())
|
|
22
25
|
.then((data) => {
|
|
23
26
|
document.body.innerHTML = data;
|
|
@@ -26,26 +29,26 @@ app.on(ExtensionEvents.Ready, () => {
|
|
|
26
29
|
/**
|
|
27
30
|
* Replace file content
|
|
28
31
|
*/
|
|
29
|
-
|
|
32
|
+
nb.replace('new content');
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
35
|
* Display change event
|
|
33
36
|
*/
|
|
34
|
-
|
|
37
|
+
nb.on(ExtensionEvents.ChangeView, (state) => {
|
|
35
38
|
console.log(state);
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* Display change event
|
|
40
43
|
*/
|
|
41
|
-
|
|
44
|
+
nb.on(ExtensionEvents.ChangeView, (state) => {
|
|
42
45
|
console.log(state);
|
|
43
46
|
});
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
49
|
* Request to save changes and close the editor
|
|
47
50
|
*/
|
|
48
|
-
|
|
51
|
+
nb.on(ExtensionEvents.SaveAndClose, (state) => {
|
|
49
52
|
console.log(state);
|
|
50
53
|
app.close();
|
|
51
54
|
});
|
|
@@ -54,22 +57,22 @@ app.on(ExtensionEvents.Ready, () => {
|
|
|
54
57
|
* Submit a content change message
|
|
55
58
|
* In the case when content is written before exiting the application or when writing large files
|
|
56
59
|
*/
|
|
57
|
-
|
|
60
|
+
nb.changeContent(true);
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
63
|
* Send an event to close the editor
|
|
61
64
|
*/
|
|
62
|
-
|
|
65
|
+
nb.close();
|
|
63
66
|
|
|
64
67
|
/**
|
|
65
68
|
* Saving metadata extension
|
|
66
69
|
*/
|
|
67
|
-
|
|
70
|
+
nb.saveMeta({ my_key: 'value' });
|
|
68
71
|
|
|
69
72
|
/**
|
|
70
73
|
* Reading metadata extension
|
|
71
74
|
*/
|
|
72
|
-
|
|
75
|
+
nb.readMeta().then((data) => {
|
|
73
76
|
console.log(data.my_key);
|
|
74
77
|
});
|
|
75
78
|
});
|
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),p=n(679),c=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){return
|
|
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),p=n(679),c=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){return t.prototype.on.call(this,e,n)},e.prototype.off=function(e,n){return t.prototype.off.call(this,e,n)},Object.defineProperty(e.prototype,"fileUrl",{get:function(){return this.state?this.relativePath(this.state.file_info.path,this.state.file_info.file):""},enumerable:!1,configurable:!0}),e.prototype.init=function(){this.subscribeEvent(),(0,s.sendEvent)(p.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)(p.AppEvents.ChangeContent,t)},e.prototype.close=function(t){(0,s.sendEvent)(p.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.name),{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.name),{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 r([null===(t=this.state)||void 0===t?void 0:t.api_path],e,!0).join("")},e.prototype.subscribeEvent=function(){var e=this;console.log("subscribe"),window.addEventListener("message",(function(n){var o=n.data.event,i=n.data.payload;switch(e.debug&&console.log("frame.message",n.data),o){case p.ExtensionEvents.Ready:e.debug=i.debug,t.prototype.emit.call(e,p.ExtensionEvents.Ready);break;case p.ExtensionEvents.ChangeView:e.state&&(e.state.view=i)}}))},e}(a.EventEmitter);e.NextBox=c},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.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);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){var e={а:"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",",":"","?":""," ":"-","~":"","!":"","@":"","#":"",$:"","%":"","^":"","&":"","*":"","(":"",")":"","=":"","+":"",":":"",";":"","<":"",">":"","'":"",'"':"","\\":"","/":"","№":"","[":"","]":"","{":"","}":"",ґ:"",ї:"",є:"",Ґ:"g",Ї:"i","—":"",".":"",Є:"e"};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:e[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(),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"}},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)})()));
|
package/init.d.ts
CHANGED