@manuscripts/article-editor 3.2.13-LEAN-2165.0 → 3.2.13

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.
Files changed (118) hide show
  1. package/dist/cjs/EditorApp.js +22 -11
  2. package/dist/cjs/EditorApp.js.map +1 -1
  3. package/dist/cjs/api/Api.js +168 -0
  4. package/dist/cjs/api/Api.js.map +1 -0
  5. package/dist/cjs/{postgres-data/PsSource.js → api/ApiSource.js} +17 -36
  6. package/dist/cjs/api/ApiSource.js.map +1 -0
  7. package/dist/cjs/api/StepsExchanger.js +99 -0
  8. package/dist/cjs/api/StepsExchanger.js.map +1 -0
  9. package/dist/cjs/api/buildData.js +66 -0
  10. package/dist/cjs/api/buildData.js.map +1 -0
  11. package/dist/cjs/{postgres-data → api}/buildUtilities.js +6 -12
  12. package/dist/cjs/api/buildUtilities.js.map +1 -0
  13. package/dist/cjs/api/savingUtilities.js.map +1 -0
  14. package/dist/{es/lib/api/index.js → cjs/api/types.js} +4 -3
  15. package/dist/cjs/api/types.js.map +1 -0
  16. package/dist/cjs/components/inspector/SnapshotsDropdown.js +54 -58
  17. package/dist/cjs/components/inspector/SnapshotsDropdown.js.map +1 -1
  18. package/dist/cjs/components/projects/ManuscriptPageContainer.js +0 -1
  19. package/dist/cjs/components/projects/ManuscriptPageContainer.js.map +1 -1
  20. package/dist/cjs/hooks/use-connect-editor.js +1 -1
  21. package/dist/cjs/hooks/use-connect-editor.js.map +1 -1
  22. package/dist/cjs/hooks/use-create-editor.js +19 -14
  23. package/dist/cjs/hooks/use-create-editor.js.map +1 -1
  24. package/dist/cjs/{quarterback/getDocWithoutTrackContent.js → lib/doc.js} +7 -8
  25. package/dist/cjs/lib/doc.js.map +1 -0
  26. package/dist/cjs/store/DataSourceStrategy.js +3 -11
  27. package/dist/cjs/store/DataSourceStrategy.js.map +1 -1
  28. package/dist/cjs/store/Store.js.map +1 -1
  29. package/dist/es/EditorApp.js +23 -12
  30. package/dist/es/EditorApp.js.map +1 -1
  31. package/dist/es/api/Api.js +160 -0
  32. package/dist/es/api/Api.js.map +1 -0
  33. package/dist/es/{postgres-data/PsSource.js → api/ApiSource.js} +15 -32
  34. package/dist/es/api/ApiSource.js.map +1 -0
  35. package/dist/es/api/StepsExchanger.js +94 -0
  36. package/dist/es/api/StepsExchanger.js.map +1 -0
  37. package/dist/es/api/buildData.js +62 -0
  38. package/dist/es/api/buildData.js.map +1 -0
  39. package/dist/es/{postgres-data → api}/buildUtilities.js +6 -12
  40. package/dist/es/api/buildUtilities.js.map +1 -0
  41. package/dist/es/api/savingUtilities.js.map +1 -0
  42. package/dist/{types/lib/api/index.d.ts → es/api/types.js} +3 -2
  43. package/dist/es/api/types.js.map +1 -0
  44. package/dist/es/components/inspector/SnapshotsDropdown.js +32 -59
  45. package/dist/es/components/inspector/SnapshotsDropdown.js.map +1 -1
  46. package/dist/es/components/projects/ManuscriptPageContainer.js +0 -1
  47. package/dist/es/components/projects/ManuscriptPageContainer.js.map +1 -1
  48. package/dist/es/hooks/use-connect-editor.js +1 -1
  49. package/dist/es/hooks/use-connect-editor.js.map +1 -1
  50. package/dist/es/hooks/use-create-editor.js +19 -14
  51. package/dist/es/hooks/use-create-editor.js.map +1 -1
  52. package/dist/es/{quarterback/getDocWithoutTrackContent.js → lib/doc.js} +6 -6
  53. package/dist/es/lib/doc.js.map +1 -0
  54. package/dist/es/store/DataSourceStrategy.js +3 -11
  55. package/dist/es/store/DataSourceStrategy.js.map +1 -1
  56. package/dist/es/store/Store.js.map +1 -1
  57. package/dist/types/{postgres-data → api}/Api.d.ts +17 -6
  58. package/dist/types/{postgres-data/PsSource.d.ts → api/ApiSource.d.ts} +4 -5
  59. package/dist/types/{quarterback/QuarterbackStepsExchanger.d.ts → api/StepsExchanger.d.ts} +19 -21
  60. package/dist/types/api/buildData.d.ts +2 -0
  61. package/dist/types/{postgres-data → api}/buildUtilities.d.ts +1 -1
  62. package/dist/types/{quarterback/api/loadDoc.d.ts → api/types.d.ts} +23 -6
  63. package/dist/types/lib/doc.d.ts +17 -0
  64. package/dist/types/store/DataSourceStrategy.d.ts +2 -5
  65. package/dist/types/store/Store.d.ts +5 -13
  66. package/package.json +2 -3
  67. package/dist/cjs/lib/api/collaboration.js +0 -25
  68. package/dist/cjs/lib/api/collaboration.js.map +0 -1
  69. package/dist/cjs/lib/api/index.js +0 -29
  70. package/dist/cjs/lib/api/index.js.map +0 -1
  71. package/dist/cjs/postgres-data/Api.js +0 -83
  72. package/dist/cjs/postgres-data/Api.js.map +0 -1
  73. package/dist/cjs/postgres-data/PsSource.js.map +0 -1
  74. package/dist/cjs/postgres-data/buildData.js +0 -85
  75. package/dist/cjs/postgres-data/buildData.js.map +0 -1
  76. package/dist/cjs/postgres-data/buildUtilities.js.map +0 -1
  77. package/dist/cjs/postgres-data/savingUtilities.js.map +0 -1
  78. package/dist/cjs/quarterback/QuarterbackStepsExchanger.js +0 -145
  79. package/dist/cjs/quarterback/QuarterbackStepsExchanger.js.map +0 -1
  80. package/dist/cjs/quarterback/api/document.js +0 -43
  81. package/dist/cjs/quarterback/api/document.js.map +0 -1
  82. package/dist/cjs/quarterback/api/loadDoc.js +0 -108
  83. package/dist/cjs/quarterback/api/loadDoc.js.map +0 -1
  84. package/dist/cjs/quarterback/api/methods.js +0 -147
  85. package/dist/cjs/quarterback/api/methods.js.map +0 -1
  86. package/dist/cjs/quarterback/getDocWithoutTrackContent.js.map +0 -1
  87. package/dist/cjs/quarterback/types.js +0 -3
  88. package/dist/cjs/quarterback/types.js.map +0 -1
  89. package/dist/es/lib/api/collaboration.js +0 -18
  90. package/dist/es/lib/api/collaboration.js.map +0 -1
  91. package/dist/es/lib/api/index.js.map +0 -1
  92. package/dist/es/postgres-data/Api.js +0 -77
  93. package/dist/es/postgres-data/Api.js.map +0 -1
  94. package/dist/es/postgres-data/PsSource.js.map +0 -1
  95. package/dist/es/postgres-data/buildData.js +0 -81
  96. package/dist/es/postgres-data/buildData.js.map +0 -1
  97. package/dist/es/postgres-data/buildUtilities.js.map +0 -1
  98. package/dist/es/postgres-data/savingUtilities.js.map +0 -1
  99. package/dist/es/quarterback/QuarterbackStepsExchanger.js +0 -118
  100. package/dist/es/quarterback/QuarterbackStepsExchanger.js.map +0 -1
  101. package/dist/es/quarterback/api/document.js +0 -32
  102. package/dist/es/quarterback/api/document.js.map +0 -1
  103. package/dist/es/quarterback/api/loadDoc.js +0 -81
  104. package/dist/es/quarterback/api/loadDoc.js.map +0 -1
  105. package/dist/es/quarterback/api/methods.js +0 -137
  106. package/dist/es/quarterback/api/methods.js.map +0 -1
  107. package/dist/es/quarterback/getDocWithoutTrackContent.js.map +0 -1
  108. package/dist/es/quarterback/types.js +0 -2
  109. package/dist/es/quarterback/types.js.map +0 -1
  110. package/dist/types/lib/api/collaboration.d.ts +0 -17
  111. package/dist/types/postgres-data/buildData.d.ts +0 -3
  112. package/dist/types/quarterback/api/document.d.ts +0 -20
  113. package/dist/types/quarterback/api/methods.d.ts +0 -38
  114. package/dist/types/quarterback/getDocWithoutTrackContent.d.ts +0 -3
  115. package/dist/types/quarterback/types.d.ts +0 -74
  116. /package/dist/cjs/{postgres-data → api}/savingUtilities.js +0 -0
  117. /package/dist/es/{postgres-data → api}/savingUtilities.js +0 -0
  118. /package/dist/types/{postgres-data → api}/savingUtilities.d.ts +0 -0
@@ -0,0 +1,160 @@
1
+ /*!
2
+ * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://mpapp-public.gitlab.io/manuscripts-frontend/LICENSE. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
3
+ *
4
+ * Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
5
+ *
6
+ * The Original Code is manuscripts-frontend.
7
+ *
8
+ * The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
9
+ *
10
+ * All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
11
+ */
12
+ import { ObjectTypes, } from '@manuscripts/json-schema';
13
+ import axios from 'axios';
14
+ import { createContext, useContext } from 'react';
15
+ import { getConfig } from '../config';
16
+ export class Api {
17
+ constructor(authToken) {
18
+ this.get = async (url) => {
19
+ try {
20
+ const result = await this.instance.get(url, {
21
+ headers: {
22
+ 'Content-Type': 'application/json;charset=UTF-8',
23
+ },
24
+ });
25
+ return result.data;
26
+ }
27
+ catch (e) {
28
+ console.log(e);
29
+ return undefined;
30
+ }
31
+ };
32
+ this.post = async (path, data) => {
33
+ return this.instance
34
+ .post(path, data)
35
+ .then((result) => result.data)
36
+ .catch((e) => {
37
+ const status = e.response?.status;
38
+ if (!status || status >= 500) {
39
+ console.log(e);
40
+ }
41
+ throw e;
42
+ });
43
+ };
44
+ this.delete = (url) => this.instance.delete(url);
45
+ this.options = (url) => this.instance.options(url);
46
+ this.put = (path, data) => this.instance.put(path, data);
47
+ this.getTransformVersion = () => this.get('/doc/version').then((d) => d?.transformVersion || '');
48
+ this.getUser = () => this.get('user');
49
+ this.getSectionCategories = () => this.get('/config?id=section-categories');
50
+ this.getCSLLocale = (lang) => lang !== 'en-US' ? this.get(`/csl/locales?id=${lang}`) : undefined;
51
+ this.getTemplate = (id) => id ? this.get(`/templates?id=${id}`) : undefined;
52
+ this.getBundle = (template) => template?.bundle
53
+ ? this.get(`/bundles?id=${template.bundle}`)
54
+ : undefined;
55
+ this.getCSLStyle = (bundle) => bundle?.csl?._id
56
+ ? this.get(`/csl/styles?id=${bundle.csl._id}`)
57
+ : undefined;
58
+ this.getUserProfiles = (containerID) => this.get(`/project/${containerID}/userProfiles`);
59
+ this.getProject = async (projectID) => {
60
+ const models = await this.get(`project/${projectID}`);
61
+ if (!models) {
62
+ throw new Error('Models are wrong.');
63
+ }
64
+ for (const model of models) {
65
+ if (model.objectType === ObjectTypes.Project) {
66
+ return model;
67
+ }
68
+ }
69
+ };
70
+ this.saveProject = (projectId, models) => {
71
+ return this.put(`project/${projectId}`, { data: models });
72
+ };
73
+ this.createProject = (projectId, title) => this.post(`project/${projectId}`, { title });
74
+ this.getSnapshot = (snapshotID) => this.get(`snapshot/${snapshotID}`);
75
+ this.createSnapshot = (projectID, manuscriptID) => this.post(`snapshot/${projectID}/manuscript/${manuscriptID}`, {
76
+ docID: manuscriptID,
77
+ name: new Date().toLocaleString('sv'),
78
+ });
79
+ this.getDocument = (projectID, manuscriptID) => this.get(`doc/${projectID}/manuscript/${manuscriptID}`);
80
+ this.sendSteps = (projectID, manuscriptID, data) => this.post(`doc/${projectID}/manuscript/${manuscriptID}/steps`, {
81
+ ...data,
82
+ steps: data.steps.map((s) => s.toJSON()),
83
+ }).catch((e) => {
84
+ const error = e.response?.status === 409 ? 'conflict' : e.message;
85
+ return {
86
+ error: error,
87
+ };
88
+ });
89
+ this.getStepsSince = (projectID, manuscriptID, version) => this.get(`doc/${projectID}/manuscript/${manuscriptID}/version/${version}`);
90
+ this.listenToSteps = (projectID, manuscriptID, listener) => {
91
+ const config = getConfig();
92
+ const base = config.api.url.replace('http', 'ws');
93
+ const url = `${base}/doc/${projectID}/manuscript/${manuscriptID}/listen`;
94
+ let ws;
95
+ const onOpen = () => {
96
+ console.log('Established WebSocket connection');
97
+ };
98
+ const onMessage = (event) => {
99
+ const data = JSON.parse(event.data);
100
+ if (typeof data.version !== 'undefined' &&
101
+ data.steps &&
102
+ Array.isArray(data.steps) &&
103
+ data.clientIDs) {
104
+ listener(data.version, data.steps, data.clientIDs);
105
+ }
106
+ };
107
+ const onClose = (event) => {
108
+ console.warn('WebSocket connection closed, reconnecting:', event.code, event.reason);
109
+ rejoin();
110
+ };
111
+ const onError = (event) => {
112
+ console.error('WebSocket error, reconnecting:', event);
113
+ rejoin();
114
+ };
115
+ const close = () => {
116
+ if (!ws) {
117
+ return;
118
+ }
119
+ ws.removeEventListener('open', onOpen);
120
+ ws.removeEventListener('message', onMessage);
121
+ ws.removeEventListener('close', onClose);
122
+ ws.removeEventListener('error', onError);
123
+ ws.close();
124
+ };
125
+ const rejoin = () => {
126
+ close();
127
+ setTimeout(join, 1500);
128
+ };
129
+ const join = () => {
130
+ try {
131
+ ws = new WebSocket(url);
132
+ ws.addEventListener('open', onOpen);
133
+ ws.addEventListener('message', onMessage);
134
+ ws.addEventListener('close', onClose);
135
+ ws.addEventListener('error', onError);
136
+ }
137
+ catch (e) {
138
+ console.log(e);
139
+ rejoin();
140
+ }
141
+ };
142
+ window.addEventListener('beforeunload', close);
143
+ join();
144
+ };
145
+ const config = getConfig();
146
+ this.instance = axios.create({
147
+ baseURL: config.api.url,
148
+ headers: { ...config.api.headers, Authorization: 'Bearer ' + authToken },
149
+ });
150
+ }
151
+ }
152
+ export const ApiContext = createContext(undefined);
153
+ export const useApi = () => {
154
+ const api = useContext(ApiContext);
155
+ if (!api) {
156
+ throw new Error('Api not initialized');
157
+ }
158
+ return api;
159
+ };
160
+ //# sourceMappingURL=Api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Api.js","sourceRoot":"","sources":["../../../src/api/Api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAIL,WAAW,GAIZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAoC,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAWrC,MAAM,OAAO,GAAG;IAGd,YAAY,SAAiB;QAQ7B,QAAG,GAAG,KAAK,EAAK,GAAW,EAAE,EAAE;YAC7B,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAI,GAAG,EAAE;oBAC7C,OAAO,EAAE;wBACP,cAAc,EAAE,gCAAgC;qBACj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AC,CAAA;YACD,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;YAC9C,IAAI,EAAE,CAAA;QACR,CAAC,CAAA;QArMC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG;YACvB,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,SAAS,GAAG,SAAS,EAAE;SACzE,CAAC,CAAA;IACJ,CAAC;CAiMF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAkB,SAAS,CAAC,CAAA;AAEnE,MAAM,CAAC,MAAM,MAAM,GAAG,GAAQ,EAAE;IAC9B,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAClC,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;KACvC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
@@ -9,39 +9,20 @@
9
9
  *
10
10
  * All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
11
11
  */
12
- import { loadDoc } from '../quarterback/api/loadDoc';
13
- import Api from './Api';
12
+ import { getVersion as getTransformVersion } from '@manuscripts/transform';
14
13
  import { buildData } from './buildData';
15
14
  import { buildUtilities } from './buildUtilities';
16
- export default class PsSource {
17
- constructor(files) {
15
+ export class ApiSource {
16
+ constructor(api) {
18
17
  this.updateState = (state) => {
19
18
  console.error(new Error('Store not yet mounted').stack);
20
19
  };
21
20
  this.build = async (state, next, setState) => {
22
- if (state.userID && state.authToken) {
23
- this.api.setToken(state.authToken);
24
- }
25
21
  const projectID = state.projectID;
26
22
  const manuscriptID = state.manuscriptID;
27
- if (state.projectID && state.manuscriptID && state.authToken) {
28
- const res = await loadDoc(state.manuscriptID, state.projectID, state.authToken, state.doc);
29
- if (res?.doc && res.version >= 0) {
30
- this.data = {
31
- ...this.data,
32
- doc: res.doc,
33
- initialDocVersion: res.version,
34
- snapshots: res.snapshots,
35
- snapshotsMap: new Map(),
36
- };
37
- }
38
- }
39
- if (manuscriptID && projectID && this.data.doc) {
40
- const data = await buildData(projectID, manuscriptID, this.data.doc, this.api);
41
- this.data = {
42
- ...this.data,
43
- ...data,
44
- };
23
+ if (manuscriptID && projectID) {
24
+ await this.checkTransformVersion();
25
+ this.data = await buildData(projectID, manuscriptID, this.api);
45
26
  this.utilities = buildUtilities(projectID, manuscriptID, () => this.data, setState, this.api);
46
27
  }
47
28
  next({ ...state, ...this.data, ...this.utilities });
@@ -52,12 +33,14 @@ export default class PsSource {
52
33
  this.updateStore = (setState) => {
53
34
  this.updateState = setState;
54
35
  };
55
- this.api = new Api();
56
- this.files = files;
57
- // import api
58
- // get user and all the data
59
- // build and provide methods such as saveModel, saveManuscript etc. (see ModelManager in couch-data)
60
- // conform with the store
36
+ this.checkTransformVersion = async () => {
37
+ const fe = getTransformVersion();
38
+ const api = await this.api.getTransformVersion();
39
+ if (fe !== api) {
40
+ console.warn(`manuscripts-transform version mismatch. FE: ${fe}, api: ${api}`);
41
+ }
42
+ };
43
+ this.api = api;
61
44
  }
62
45
  }
63
- //# sourceMappingURL=PsSource.js.map
46
+ //# sourceMappingURL=ApiSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiSource.js","sourceRoot":"","sources":["../../../src/api/ApiSource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAK1E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,MAAM,OAAO,SAAS;IAKpB,YAAY,GAAQ;QAIpB,gBAAW,GAAgB,CAA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U,GAAG,EAAE,CACjE,CAAA;aACF;QACH,CAAC,CAAA;QArCC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;CAqCF"}
@@ -0,0 +1,94 @@
1
+ /*!
2
+ * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://mpapp-public.gitlab.io/manuscripts-frontend/LICENSE. The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover use of software over a computer network and provide for limited attribution for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
3
+ *
4
+ * Software distributed under the License is distributed on an “AS IS” basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.
5
+ *
6
+ * The Original Code is manuscripts-frontend.
7
+ *
8
+ * The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
9
+ *
10
+ * All portions of the code written by Atypon Systems LLC are Copyright (c) 2022 Atypon Systems LLC. All Rights Reserved.
11
+ */
12
+ import { CollabProvider } from '@manuscripts/body-editor';
13
+ import { schema } from '@manuscripts/transform';
14
+ import { Step } from 'prosemirror-transform';
15
+ import { saveWithDebounce } from './savingUtilities';
16
+ const MAX_ATTEMPTS = 20;
17
+ const THROTTLING_INTERVAL = 1200;
18
+ export class ObservableBoolean {
19
+ constructor() {
20
+ this.value = false;
21
+ this.subs = [];
22
+ }
23
+ setValue(value) {
24
+ this.value = value;
25
+ this.subs.forEach((s) => s(value));
26
+ }
27
+ onChange(sub) {
28
+ this.subs.push(sub);
29
+ }
30
+ }
31
+ export class StepsExchanger extends CollabProvider {
32
+ constructor(projectID, manuscriptID, currentVersion, api) {
33
+ super();
34
+ this.attempt = 0;
35
+ this.projectID = projectID;
36
+ this.manuscriptID = manuscriptID;
37
+ this.currentVersion = currentVersion;
38
+ this.isThrottling = new ObservableBoolean();
39
+ this.debounce = saveWithDebounce();
40
+ this.api = api;
41
+ this.start();
42
+ }
43
+ async sendSteps(version, steps, clientID, flush = false) {
44
+ this.flushImmediately = this.debounce(async () => {
45
+ const response = await this.api.sendSteps(this.projectID, this.manuscriptID, {
46
+ steps: steps,
47
+ version,
48
+ clientID,
49
+ });
50
+ if (response.error === 'conflict' && this.attempt < MAX_ATTEMPTS) {
51
+ console.warn('Retrying');
52
+ this.newStepsListener();
53
+ this.attempt++;
54
+ }
55
+ else if (response.error) {
56
+ console.error('Failed to send steps', response.error);
57
+ }
58
+ else {
59
+ this.attempt = 0;
60
+ }
61
+ }, THROTTLING_INTERVAL, flush, () => this.isThrottling.setValue(false));
62
+ if (!flush) {
63
+ this.isThrottling.setValue(true);
64
+ }
65
+ return Promise.resolve();
66
+ }
67
+ async receiveSteps(version, steps, clientIDs) {
68
+ this.currentVersion = version;
69
+ if (steps.length) {
70
+ //TODO send steps to listener
71
+ this.newStepsListener();
72
+ }
73
+ }
74
+ start() {
75
+ this.api.listenToSteps(this.projectID, this.manuscriptID, (version, steps, clientIDs) => this.receiveSteps(version, steps, clientIDs));
76
+ }
77
+ flush() {
78
+ this.flushImmediately && this.flushImmediately();
79
+ }
80
+ onNewSteps(listener) {
81
+ this.newStepsListener = listener;
82
+ }
83
+ async stepsSince(version) {
84
+ const response = await this.api.getStepsSince(this.projectID, this.manuscriptID, version);
85
+ if (response) {
86
+ return {
87
+ steps: response.steps.map((s) => Step.fromJSON(schema, s)),
88
+ clientIDs: response.clientIDs,
89
+ version: response.version,
90
+ };
91
+ }
92
+ }
93
+ }
94
+ //# sourceMappingURL=StepsExchanger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StepsExchanger.js","sourceRoot":"","sources":["../../../src/api/StepsExchanger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AA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AC,gBAAgB,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAClD,CAAC;IAED,UAAU,CAAC,QAA4C;QACrD,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAA;IAClC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3C,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,EACjB,OAAO,CACR,CAAA;QACD,IAAI,QAAQ,EAAE;YACZ,OAAO;gBACL,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBAC1D,SAAS,EAAE,QAAQ,CAAC,SAAS;gBAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO;aAC1B,CAAA;SACF;IACH,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import { schema } from '@manuscripts/transform';
2
+ import { getUserRole } from '../lib/roles';
3
+ const getDocumentData = async (projectID, manuscriptID, api) => {
4
+ const response = await api.getDocument(projectID, manuscriptID);
5
+ if (!response) {
6
+ throw new Error('Document not found');
7
+ }
8
+ return {
9
+ doc: schema.nodeFromJSON(response.doc),
10
+ initialDocVersion: response.version,
11
+ snapshots: response.snapshots,
12
+ };
13
+ };
14
+ const getManuscriptData = async (templateID, api) => {
15
+ const data = {};
16
+ const [sectionCategories, cslLocale, template] = await Promise.all([
17
+ api.getSectionCategories(),
18
+ // TODO:: config this!
19
+ api.getCSLLocale('en-US'),
20
+ api.getTemplate(templateID),
21
+ ]);
22
+ const bundle = await api.getBundle(template);
23
+ data.sectionCategories = sectionCategories || [];
24
+ data.cslStyle = await api.getCSLStyle(bundle);
25
+ data.cslLocale = cslLocale;
26
+ return data;
27
+ };
28
+ const getUserData = async (projectID, user, api) => {
29
+ const profilesById = new Map();
30
+ profilesById.set(user._id, user);
31
+ const profiles = await api.getUserProfiles(projectID);
32
+ if (profiles) {
33
+ for (const profile of profiles) {
34
+ if (profile) {
35
+ profilesById.set(profile._id, profile);
36
+ }
37
+ }
38
+ }
39
+ return {
40
+ collaboratorsById: profilesById,
41
+ };
42
+ };
43
+ export const buildData = async (projectID, manuscriptID, api) => {
44
+ const user = await api.getUser();
45
+ if (!user) {
46
+ return {};
47
+ }
48
+ const doc = await getDocumentData(projectID, manuscriptID, api);
49
+ const state = await getManuscriptData(doc.doc.attrs.prototype, api);
50
+ const project = await api.getProject(projectID);
51
+ const role = project ? getUserRole(project, user.userID) : null;
52
+ const users = await getUserData(projectID, user, api);
53
+ return {
54
+ user,
55
+ userRole: role,
56
+ ...users,
57
+ ...state,
58
+ ...doc,
59
+ project,
60
+ };
61
+ };
62
+ //# sourceMappingURL=buildData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildData.js","sourceRoot":"","sources":["../../../src/api/buildData.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI1C,MAAM,eAAe,GAAG,KAAK,EAC3B,SAAiB,EACjB,YAAoB,EACpB,GAAQ,EACR,EAAE;IACF,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;IAC/D,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;KACtC;IACD,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtC,iBAAiB,EAAE,QAAQ,CAAC,OAAO;QACnC,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC9B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,KAAK,EAAE,UAAkB,EAAE,GAAQ,EAAE,EAAE;IAC/D,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,OAAO,EAAE,CAAA;IAChC,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,CAAA;KACV;IAED,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,CAAC,CAAA;IAC/D,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IACnE,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;IAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC/D,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;IAErD,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,IAAI;QACd,GAAG,KAAK;QACR,GAAG,KAAK;QACR,GAAG,GAAG;QACN,OAAO;KACR,CAAA;AACH,CAAC,CAAA"}
@@ -9,21 +9,18 @@
9
9
  *
10
10
  * All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
11
11
  */
12
- import { ObjectTypes } from '@manuscripts/json-schema';
13
12
  import { getUserRole } from '../lib/roles';
14
13
  export const buildUtilities = (projectID, manuscriptID, getState, updateState, api) => {
15
14
  const createSnapshot = async () => {
16
15
  const state = getState();
17
16
  const snapshots = state.snapshots;
18
- const snapshotsMap = state.snapshotsMap;
19
- if (!snapshots || !snapshotsMap) {
20
- throw new Error('Unable to create snapshot due to incomplete data');
17
+ if (!snapshots) {
18
+ throw new Error('Missing snapshots');
21
19
  }
22
- const data = await api.createSnapshot(projectID, manuscriptID);
23
- const { snapshot, ...label } = data.snapshot;
20
+ const response = await api.createSnapshot(projectID, manuscriptID);
21
+ const { snapshot, ...label } = response.snapshot;
24
22
  updateState({
25
23
  snapshots: [...snapshots, label],
26
- snapshotsMap: snapshotsMap.set(label.id, data.snapshot),
27
24
  });
28
25
  };
29
26
  const refreshProject = async () => {
@@ -32,11 +29,7 @@ export const buildUtilities = (projectID, manuscriptID, getState, updateState, a
32
29
  if (!userID) {
33
30
  return;
34
31
  }
35
- const models = await api.getManuscript(projectID, manuscriptID);
36
- if (!models) {
37
- return;
38
- }
39
- const project = models.filter((m) => m.objectType === ObjectTypes.Project)[0];
32
+ const project = await api.getProject(projectID);
40
33
  if (!project) {
41
34
  return;
42
35
  }
@@ -48,6 +41,7 @@ export const buildUtilities = (projectID, manuscriptID, getState, updateState, a
48
41
  return {
49
42
  createSnapshot,
50
43
  refreshProject,
44
+ getSnapshot: api.getSnapshot,
51
45
  };
52
46
  };
53
47
  //# sourceMappingURL=buildUtilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildUtilities.js","sourceRoot":"","sources":["../../../src/api/buildUtilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI1C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,SAAiB,EACjB,YAAoB,EACpB,QAA8B,EAC9B,WAA4C,EAC5C,GAAQ,EACQ,EAAE;IAClB,MAAM,cAAc,GAAG,KAAK,IAAI,EAAE;QAChC,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAA;QACxB,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;SACrC;QACD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;QAClE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAA;QAChD,WAAW,CAAC;YACV,SAAS,EAAE,CAAC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,EAAE,CAAA;QACV,CAAC,EAAE,QAAQ,CAAC,CAAA;QAEZ,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,CAAA;YACR,YAAY,CAAC,OAAO,CAAC,CAAA;QACvB,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,MAAM,EAAU,CAAA;IAEhC,OAAO,CAAC,EAAa,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE;QACxC,SAAS,CAAC,OAAO,GAAG,EAAE,CAAA;QACtB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACpB,SAAS,CAAC,OAAO,EAAE,CAAA;YACnB,SAAS,CAAC,OAAO,GAAG,GAAG,EAAE;gBACvB,OAAO,IAAI,CAAA;YACb,CAAC,CAAA;YACD,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;gBACvC,SAAS,CAAC,OAAO,EAAE,CAAA;gBACnB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBACpC,OAAO,CAAC,OAAO,GAAG,CAAC,CAAA;YACrB,CAAC,EAAE,QAAQ,CAAC,CAAA;SACb;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * The Original Developer is the Initial Developer. The Initial Developer of the Original Code is Atypon Systems LLC.
9
9
  *
10
- * All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
10
+ * All portions of the code written by Atypon Systems LLC are Copyright (c) 2022 Atypon Systems LLC. All Rights Reserved.
11
11
  */
12
- export * from './collaboration';
12
+ export {};
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -10,84 +10,59 @@
10
10
  * All portions of the code written by Atypon Systems LLC are Copyright (c) 2019 Atypon Systems LLC. All Rights Reserved.
11
11
  */
12
12
  import { Avatar, SecondaryButton, useDropdown } from '@manuscripts/style-guide';
13
- import { trackChangesPluginKey, TrackChangesStatus, trackCommands, } from '@manuscripts/track-changes-plugin';
13
+ import { TrackChangesStatus, trackCommands, } from '@manuscripts/track-changes-plugin';
14
+ import { schema } from '@manuscripts/transform';
14
15
  import { EditorState } from 'prosemirror-state';
15
- import React from 'react';
16
+ import React, { useMemo, useState } from 'react';
16
17
  import styled from 'styled-components';
17
18
  import useExecCmd from '../../hooks/use-exec-cmd';
18
- import { get } from '../../quarterback/api/methods';
19
19
  import { useStore } from '../../store';
20
20
  import { FormattedDateTime } from '../FormattedDateTime';
21
21
  import { Dropdown, DropdownButtonContainer, DropdownContainer, DropdownToggle, } from '../nav/Dropdown';
22
22
  export const SnapshotsDropdown = () => {
23
23
  const { wrapperRef, toggleOpen, isOpen } = useDropdown();
24
- const [{ view, doc, originalPmDoc, authToken, snapshotsMap, snapshots, inspectedSnapshotId, }, dispatch,] = useStore((store) => ({
24
+ const [{ view, getSnapshot, snapshots }] = useStore((store) => ({
25
25
  view: store.view,
26
- doc: store.doc,
27
- originalPmDoc: store.originalPmDoc,
28
- authToken: store.authToken,
29
- snapshotsMap: store.snapshotsMap,
26
+ getSnapshot: store.getSnapshot,
30
27
  snapshots: store.snapshots,
31
- inspectedSnapshotId: store.inspectedSnapshotId,
32
28
  }));
33
29
  const execCmd = useExecCmd();
30
+ const [selectedSnapshot, setSelectedSnapshot] = useState();
31
+ const [doc, setDoc] = useState();
32
+ const sortedSnapshots = useMemo(() => snapshots.sort((a, b) => a.createdAt.localeCompare(b.createdAt)), [snapshots]);
34
33
  if (!view) {
35
34
  return null;
36
35
  }
37
- const sortedSnapshots = snapshots.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
38
- const isBeingInspected = (snap) => inspectedSnapshotId === snap.id;
39
36
  const hydrateDocFromJSON = (doc) => {
40
37
  const state = EditorState.create({
41
- doc: view.state.schema.nodeFromJSON(doc),
38
+ doc: doc,
42
39
  plugins: view.state.plugins,
43
40
  });
44
- view && view.updateState(state);
45
- const trackState = view
46
- ? trackChangesPluginKey.getState(view.state)
47
- : undefined;
48
- dispatch({ trackState });
41
+ view.updateState(state);
49
42
  };
50
- const inspectSnapshot = async (id) => {
51
- const inspected = snapshotsMap.get(id);
52
- if (inspected) {
53
- dispatch({ inspectedSnapshotId: id });
54
- return { data: inspected };
55
- }
56
- const resp = await get(`snapshot/${id}`, authToken);
57
- if ('data' in resp) {
58
- dispatch({
59
- snapshotsMap: snapshotsMap.set(id, resp.data),
60
- inspectedSnapshotId: resp.data.id,
61
- });
62
- return resp;
63
- }
64
- };
65
- async function handleInspectSnapshot(snap) {
66
- if (!inspectedSnapshotId) {
67
- dispatch({
68
- originalPmDoc: doc.toJSON(),
69
- });
70
- }
71
- else if (isBeingInspected(snap)) {
43
+ const handleSelect = async (id) => {
44
+ if (id === selectedSnapshot?.id) {
72
45
  handleResumeEditing();
73
46
  return;
74
47
  }
75
- const resp = await inspectSnapshot(snap.id);
76
- if (resp) {
77
- hydrateDocFromJSON(resp.data.snapshot);
48
+ const snapshot = await getSnapshot(id);
49
+ if (snapshot) {
50
+ setDoc(view.state.doc);
51
+ setSelectedSnapshot(snapshot);
52
+ hydrateDocFromJSON(schema.nodeFromJSON(snapshot.snapshot));
78
53
  execCmd(trackCommands.setTrackingStatus(TrackChangesStatus.viewSnapshots));
79
54
  }
80
- }
81
- function handleResumeEditing() {
82
- dispatch({
83
- inspectedSnapshotId: null,
84
- });
85
- if (originalPmDoc) {
86
- hydrateDocFromJSON(originalPmDoc);
55
+ };
56
+ const handleResumeEditing = () => {
57
+ if (!doc) {
58
+ console.warn('No original doc found');
59
+ return;
87
60
  }
61
+ setDoc(undefined);
62
+ setSelectedSnapshot(undefined);
63
+ hydrateDocFromJSON(doc);
88
64
  execCmd(trackCommands.setTrackingStatus(TrackChangesStatus.enabled));
89
- }
90
- const inspectedSnapshot = snapshotsMap.get(inspectedSnapshotId);
65
+ };
91
66
  return (React.createElement(SnapshotContainer, null,
92
67
  React.createElement(DropdownContainer, { id: 'snapshots-dropdown', ref: wrapperRef },
93
68
  React.createElement(DropdownButtonContainer, { onClick: toggleOpen, isOpen: isOpen, className: 'dropdown-toggle' },
@@ -96,14 +71,13 @@ export const SnapshotsDropdown = () => {
96
71
  React.createElement(Avatar, { size: 20 })),
97
72
  React.createElement(InnerContainer, null,
98
73
  React.createElement(Text, null,
99
- inspectedSnapshot ? inspectedSnapshot.name : 'Current',
74
+ selectedSnapshot ? selectedSnapshot.name : 'Current',
100
75
  React.createElement(DropdownToggle, { className: isOpen ? 'open' : '' })),
101
- inspectedSnapshot && (React.createElement(DateTime, null,
102
- React.createElement(FormattedDateTime, { date: Math.floor(new Date(inspectedSnapshot.createdAt).getTime() / 1000) }),
103
- ' '))))),
76
+ selectedSnapshot && (React.createElement(DateTime, null,
77
+ React.createElement(FormattedDateTime, { date: new Date(selectedSnapshot.createdAt).getTime() / 1000 })))))),
104
78
  isOpen && (React.createElement(SnapshotsList, { top: 25, direction: 'left', minWidth: 100 },
105
79
  React.createElement(Element, { onClick: (e) => {
106
- if (inspectedSnapshot) {
80
+ if (selectedSnapshot) {
107
81
  handleResumeEditing();
108
82
  }
109
83
  toggleOpen();
@@ -115,7 +89,7 @@ export const SnapshotsDropdown = () => {
115
89
  React.createElement(Text, null, 'Current')))),
116
90
  sortedSnapshots.map((snapshot) => {
117
91
  return (React.createElement(Element, { onClick: (e) => {
118
- handleInspectSnapshot(snapshot);
92
+ handleSelect(snapshot.id);
119
93
  toggleOpen();
120
94
  }, key: snapshot.id },
121
95
  React.createElement(Container, null,
@@ -124,8 +98,7 @@ export const SnapshotsDropdown = () => {
124
98
  React.createElement(InnerContainer, null,
125
99
  React.createElement(Text, null, snapshot.name),
126
100
  React.createElement(DateTime, null,
127
- React.createElement(FormattedDateTime, { date: Math.floor(new Date(snapshot.createdAt).getTime() / 1000) }),
128
- ' ')))));
101
+ React.createElement(FormattedDateTime, { date: new Date(snapshot.createdAt).getTime() / 1000 }))))));
129
102
  }))))));
130
103
  };
131
104
  const Container = styled.div `