dochub-sdk 0.1.369 → 0.1.371

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.
@@ -16,6 +16,7 @@
16
16
  "localstorage",
17
17
  "metamodel",
18
18
  "Nata",
19
+ "permitters",
19
20
  "Piontik",
20
21
  "PROPFIND",
21
22
  "uids",
@@ -4,8 +4,43 @@ import { DocHubComponentProto } from './Components';
4
4
  import { DocHub, EditorEvents } from '../..';
5
5
  import type { DocHubEditorContext } from '../..';
6
6
 
7
+ type DocHubRoutePermitter = (to, from) => Promise<boolean>;
8
+
9
+ class DocHubEditorExitPermitter {
10
+ private permitters: DocHubRoutePermitter[] = [];
11
+
12
+ constructor(...params) {
13
+ DocHub.router.registerMiddleware({
14
+ beforeEach: async(to, from, next): Promise<void> => {
15
+ debugger;
16
+ }
17
+ });
18
+ }
19
+
20
+ addPermitter(permitter: DocHubRoutePermitter) {
21
+ this.permitters.push(permitter);
22
+ }
23
+
24
+ removePermitter(permitter: DocHubRoutePermitter) {
25
+ this.permitters = this.permitters.filter((item) => item !== permitter);
26
+ }
27
+
28
+ async onBeforeEach(to, from, next) {
29
+ for(const permitter of this.permitters) {
30
+ const result = await permitter(to, from);
31
+ if (!result) {
32
+ // eslint-disable-next-line no-console
33
+ console.warn(`Editor prohibited transition to [${to.fullPath}].`);
34
+ next(false);
35
+ }
36
+ }
37
+ next();
38
+ }
39
+ }
40
+
7
41
  @Component
8
42
  export class DocHubEditorProto extends DocHubComponentProto {
43
+ static permitter: DocHubEditorExitPermitter;
9
44
  /**
10
45
  * Контекст редактирования
11
46
  */
@@ -16,15 +51,18 @@ export class DocHubEditorProto extends DocHubComponentProto {
16
51
 
17
52
  constructor(...params) {
18
53
  super(...params);
54
+ DocHubEditorProto.permitter ||= new DocHubEditorExitPermitter();
19
55
  this.$on(EditorEvents.save, this.onSave);
20
56
  this.$on(EditorEvents.saveAs, this.onSaveAs);
21
57
  this.$on(EditorEvents.goto, this.onGoTo);
58
+ DocHubEditorProto.permitter.addPermitter(this.beforeExit);
22
59
  }
23
60
 
24
61
  destroyed(): void {
25
62
  this.$off(EditorEvents.save, this.onSave);
26
63
  this.$off(EditorEvents.saveAs, this.onSaveAs);
27
64
  this.$off(EditorEvents.goto, this.onGoTo);
65
+ DocHubEditorProto.permitter.removePermitter(this.beforeExit);
28
66
  }
29
67
 
30
68
  /**
@@ -46,4 +84,14 @@ export class DocHubEditorProto extends DocHubComponentProto {
46
84
  async onSaveAs(uri: string): Promise<void> {
47
85
  console.warn('Save as function is not implemented', uri);
48
86
  }
87
+ /**
88
+ * Обрабатываем любой переход требуя автозапись
89
+ * @param to - роут куда происходит переход
90
+ * @param from - роут откуда происходит переход
91
+ * @returns - true если переход разрешен, иначе - false
92
+ */
93
+ async beforeExit(to, from): Promise<boolean> {
94
+ await this.onSave();
95
+ return true;
96
+ }
49
97
  }
@@ -171,15 +171,9 @@ export interface IDocHubJSONata {
171
171
  * @param debug - Объект реализующий отладчик
172
172
  */
173
173
  registerDebugger(debug: IDocHubDataLakeDebugger);
174
-
175
174
  /**
176
175
  * Создает объект запроса
177
176
  */
178
- expression(query: JSONataExpression): Promise<IDocHubJSONataQuery>;
179
-
180
- /**
181
- * Метод временный на период миграции к полной асинхронности
182
- */
183
- expressionLocal(query: JSONataExpression): IDocHubJSONataQuery;
177
+ expression(query: JSONataExpression): IDocHubJSONataQuery;
184
178
  }
185
179
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dochub-sdk",
3
- "version": "0.1.369",
3
+ "version": "0.1.371",
4
4
  "description": "The DocHub System Development Kit.",
5
5
  "private": false,
6
6
  "main": "index.ts",