@shaxpir/duiduidui-models 1.0.1 → 1.2.0

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 (226) hide show
  1. package/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
  2. package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
  3. package/dist/models/BayesianScore.d.ts +9 -0
  4. package/dist/models/BayesianScore.js +27 -0
  5. package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
  6. package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
  7. package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
  8. package/dist/models/{content/Content.js → Content.js} +2 -6
  9. package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
  10. package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
  11. package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
  12. package/dist/models/{content/Device.js → Device.js} +14 -18
  13. package/dist/models/Hanzi.d.ts +15 -0
  14. package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
  15. package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
  16. package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
  17. package/dist/models/{content/Media.js → Media.js} +4 -5
  18. package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
  19. package/dist/models/{content/Metric.js → Metric.js} +18 -20
  20. package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
  21. package/dist/models/{content/Model.js → Model.js} +5 -6
  22. package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
  23. package/dist/models/{markup/Operation.js → Operation.js} +30 -25
  24. package/dist/models/Phrase.d.ts +39 -0
  25. package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
  26. package/dist/models/{content/Profile.js → Profile.js} +7 -9
  27. package/dist/models/Progress.d.ts +26 -0
  28. package/dist/models/Progress.js +39 -0
  29. package/dist/models/Review.d.ts +14 -0
  30. package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
  31. package/dist/models/Session.js +103 -0
  32. package/dist/models/Term.d.ts +36 -0
  33. package/dist/models/Term.js +82 -0
  34. package/dist/models/User.d.ts +32 -0
  35. package/dist/models/User.js +65 -0
  36. package/dist/models/Workspace.d.ts +37 -0
  37. package/dist/models/Workspace.js +94 -0
  38. package/dist/models/index.d.ts +22 -2
  39. package/dist/models/index.js +22 -2
  40. package/dist/repo/PermissiveJson1.d.ts +16 -16
  41. package/dist/repo/PermissiveJson1.js +17 -7
  42. package/dist/repo/ShareSync.d.ts +6 -6
  43. package/dist/repo/ShareSync.js +26 -19
  44. package/dist/repo/index.d.ts +1 -0
  45. package/dist/repo/index.js +1 -0
  46. package/dist/util/Encryption.d.ts +1 -1
  47. package/dist/util/index.d.ts +0 -6
  48. package/dist/util/index.js +0 -6
  49. package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
  50. package/lib/models/BayesianScore.ts +32 -0
  51. package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
  52. package/lib/models/{content/Content.ts → Content.ts} +15 -18
  53. package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
  54. package/lib/models/{content/Device.ts → Device.ts} +26 -22
  55. package/lib/models/Hanzi.ts +16 -0
  56. package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
  57. package/lib/models/{content/Media.ts → Media.ts} +3 -4
  58. package/lib/models/Metric.ts +233 -0
  59. package/lib/models/{content/Model.ts → Model.ts} +4 -6
  60. package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
  61. package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
  62. package/lib/models/Phrase.ts +53 -0
  63. package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
  64. package/lib/models/Progress.ts +66 -0
  65. package/lib/models/Review.ts +18 -0
  66. package/lib/models/Session.ts +140 -0
  67. package/lib/models/Term.ts +139 -0
  68. package/lib/models/User.ts +97 -0
  69. package/lib/models/Workspace.ts +129 -0
  70. package/lib/models/index.ts +22 -2
  71. package/lib/repo/ShareSync.ts +9 -13
  72. package/lib/repo/index.ts +1 -0
  73. package/lib/util/Encryption.ts +1 -1
  74. package/lib/util/index.ts +0 -6
  75. package/package.json +4 -15
  76. package/dist/models/OutboundMessage.d.ts +0 -18
  77. package/dist/models/OutboundMessage.js +0 -25
  78. package/dist/models/content/Activity.d.ts +0 -10
  79. package/dist/models/content/Billing.d.ts +0 -144
  80. package/dist/models/content/Billing.js +0 -418
  81. package/dist/models/content/Book.d.ts +0 -77
  82. package/dist/models/content/Book.js +0 -407
  83. package/dist/models/content/Category.d.ts +0 -16
  84. package/dist/models/content/Category.js +0 -20
  85. package/dist/models/content/Checkpointable.d.ts +0 -21
  86. package/dist/models/content/Checkpointable.js +0 -156
  87. package/dist/models/content/Comment.d.ts +0 -19
  88. package/dist/models/content/Comment.js +0 -53
  89. package/dist/models/content/ConceptArt.d.ts +0 -31
  90. package/dist/models/content/ConceptArt.js +0 -84
  91. package/dist/models/content/Context.d.ts +0 -28
  92. package/dist/models/content/Context.js +0 -162
  93. package/dist/models/content/DevEnv.d.ts +0 -5
  94. package/dist/models/content/DevEnv.js +0 -9
  95. package/dist/models/content/Dictionary.d.ts +0 -31
  96. package/dist/models/content/Dictionary.js +0 -5
  97. package/dist/models/content/DictionaryEntry.d.ts +0 -20
  98. package/dist/models/content/DictionaryEntry.js +0 -2
  99. package/dist/models/content/ElasticModel.d.ts +0 -149
  100. package/dist/models/content/ElasticModel.js +0 -179
  101. package/dist/models/content/Environment.d.ts +0 -61
  102. package/dist/models/content/Environment.js +0 -124
  103. package/dist/models/content/ExportOptions.d.ts +0 -64
  104. package/dist/models/content/ExportOptions.js +0 -213
  105. package/dist/models/content/Folder.d.ts +0 -16
  106. package/dist/models/content/Folder.js +0 -33
  107. package/dist/models/content/Fragment.d.ts +0 -54
  108. package/dist/models/content/Fragment.js +0 -181
  109. package/dist/models/content/Hanzi.d.ts +0 -21
  110. package/dist/models/content/HighlightRule.d.ts +0 -9
  111. package/dist/models/content/HighlightRule.js +0 -2
  112. package/dist/models/content/Migration.d.ts +0 -68
  113. package/dist/models/content/Migration.js +0 -155
  114. package/dist/models/content/Phrase.d.ts +0 -8
  115. package/dist/models/content/Placeholder.d.ts +0 -8
  116. package/dist/models/content/Placeholder.js +0 -36
  117. package/dist/models/content/RichText.d.ts +0 -58
  118. package/dist/models/content/RichText.js +0 -79
  119. package/dist/models/content/Session.js +0 -173
  120. package/dist/models/content/Speech.d.ts +0 -67
  121. package/dist/models/content/Speech.js +0 -97
  122. package/dist/models/content/Stub.d.ts +0 -24
  123. package/dist/models/content/Stub.js +0 -179
  124. package/dist/models/content/Time.d.ts +0 -56
  125. package/dist/models/content/Time.js +0 -295
  126. package/dist/models/content/User.d.ts +0 -36
  127. package/dist/models/content/User.js +0 -95
  128. package/dist/models/content/Workspace.d.ts +0 -71
  129. package/dist/models/content/Workspace.js +0 -237
  130. package/dist/models/content/index.d.ts +0 -17
  131. package/dist/models/content/index.js +0 -34
  132. package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
  133. package/dist/models/legacy/LegacyBodyFormat.js +0 -2
  134. package/dist/models/legacy/LegacyComment.d.ts +0 -12
  135. package/dist/models/legacy/LegacyComment.js +0 -2
  136. package/dist/models/legacy/LegacyContent.d.ts +0 -53
  137. package/dist/models/legacy/LegacyContent.js +0 -55
  138. package/dist/models/legacy/LegacyConversion.d.ts +0 -55
  139. package/dist/models/legacy/LegacyConversion.js +0 -401
  140. package/dist/models/legacy/LegacyFragment.d.ts +0 -21
  141. package/dist/models/legacy/LegacyFragment.js +0 -2
  142. package/dist/models/legacy/LegacyLocator.d.ts +0 -8
  143. package/dist/models/legacy/LegacyLocator.js +0 -31
  144. package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
  145. package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
  146. package/dist/models/legacy/LegacyPicture.d.ts +0 -14
  147. package/dist/models/legacy/LegacyPicture.js +0 -2
  148. package/dist/models/legacy/LegacyProfile.d.ts +0 -9
  149. package/dist/models/legacy/LegacyProfile.js +0 -2
  150. package/dist/models/legacy/LegacySession.d.ts +0 -41
  151. package/dist/models/legacy/LegacySession.js +0 -35
  152. package/dist/models/legacy/LegacyStory.d.ts +0 -23
  153. package/dist/models/legacy/LegacyStory.js +0 -2
  154. package/dist/models/legacy/LegacyStub.d.ts +0 -15
  155. package/dist/models/legacy/LegacyStub.js +0 -2
  156. package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
  157. package/dist/models/legacy/LegacyTransaction.js +0 -49
  158. package/dist/models/legacy/LegacyUser.d.ts +0 -28
  159. package/dist/models/legacy/LegacyUser.js +0 -32
  160. package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
  161. package/dist/models/legacy/LegacyWorkspace.js +0 -6
  162. package/dist/models/legacy/index.d.ts +0 -15
  163. package/dist/models/legacy/index.js +0 -32
  164. package/dist/models/markup/BodyFormat.d.ts +0 -14
  165. package/dist/models/markup/BodyFormat.js +0 -190
  166. package/dist/models/markup/DeltaOps.d.ts +0 -5
  167. package/dist/models/markup/DeltaOps.js +0 -74
  168. package/dist/models/markup/HtmlMarkup.d.ts +0 -4
  169. package/dist/models/markup/HtmlMarkup.js +0 -21
  170. package/dist/models/markup/index.d.ts +0 -4
  171. package/dist/models/markup/index.js +0 -21
  172. package/dist/util/Async.d.ts +0 -8
  173. package/dist/util/Async.js +0 -18
  174. package/dist/util/Base62.d.ts +0 -6
  175. package/dist/util/Base62.js +0 -47
  176. package/dist/util/BinarySearch.d.ts +0 -7
  177. package/dist/util/BinarySearch.js +0 -46
  178. package/dist/util/CachingHasher.d.ts +0 -8
  179. package/dist/util/CachingHasher.js +0 -41
  180. package/dist/util/Color.d.ts +0 -32
  181. package/dist/util/Color.js +0 -204
  182. package/dist/util/Dispatch.d.ts +0 -15
  183. package/dist/util/Dispatch.js +0 -79
  184. package/dist/util/EditDistance.d.ts +0 -13
  185. package/dist/util/EditDistance.js +0 -184
  186. package/dist/util/NumberFormat.d.ts +0 -14
  187. package/dist/util/NumberFormat.js +0 -224
  188. package/dist/util/Struct.d.ts +0 -4
  189. package/dist/util/Struct.js +0 -15
  190. package/dist/util/Template.d.ts +0 -16
  191. package/dist/util/Template.js +0 -128
  192. package/dist/util/Text.d.ts +0 -45
  193. package/dist/util/Text.js +0 -243
  194. package/dist/util/Tuples.d.ts +0 -9
  195. package/dist/util/Tuples.js +0 -135
  196. package/dist/util/Validate.d.ts +0 -4
  197. package/dist/util/Validate.js +0 -11
  198. package/dist/util/Vocabulary.d.ts +0 -3
  199. package/dist/util/Vocabulary.js +0 -35
  200. package/lib/models/content/Billing.ts +0 -558
  201. package/lib/models/content/DevEnv.ts +0 -5
  202. package/lib/models/content/DictionaryEntry.ts +0 -22
  203. package/lib/models/content/Hanzi.ts +0 -25
  204. package/lib/models/content/Phrase.ts +0 -10
  205. package/lib/models/content/Time.ts +0 -328
  206. package/lib/models/content/User.ts +0 -130
  207. package/lib/models/content/index.ts +0 -19
  208. package/lib/models/markup/DeltaOps.ts +0 -71
  209. package/lib/models/markup/index.ts +0 -6
  210. package/lib/util/Base62.ts +0 -47
  211. package/lib/util/CachingHasher.ts +0 -38
  212. package/lib/util/Dispatch.ts +0 -92
  213. package/lib/util/NumberFormat.ts +0 -194
  214. package/lib/util/Struct.ts +0 -14
  215. package/lib/util/Tuples.ts +0 -131
  216. /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
  217. /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
  218. /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
  219. /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
  220. /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
  221. /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
  222. /package/dist/models/{content/Activity.js → Review.js} +0 -0
  223. /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
  224. /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
  225. /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
  226. /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
@@ -1,77 +0,0 @@
1
- /// <reference path="../../../decs.d.ts" />
2
- import { Doc } from '@shaxpir/sharedb/lib/client';
3
- import { ShareSync } from "../../repo/ShareSync";
4
- import { ArrayView } from './ArrayView';
5
- import { ContentBody, ContentId, ContentMeta, ContentRef } from './Content';
6
- import { Context } from './Context';
7
- import { ExportOptions } from "./ExportOptions";
8
- import { Fragment } from "./Fragment";
9
- import { ContentStub, Stub } from "./Stub";
10
- export declare enum BookType {
11
- FICTION = "fiction",
12
- NONFICTION = "non-fiction",
13
- EMPTY = "empty"
14
- }
15
- export declare enum BookStubArrayKey {
16
- MANUSCRIPT = "manuscript",
17
- NOTEBOOK = "notebook",
18
- TRASH = "trash"
19
- }
20
- export interface BookPayload {
21
- name: string;
22
- subtitle: string;
23
- synopsis_ref: ContentRef;
24
- cover_media_ref: ContentId;
25
- author: string;
26
- contributors: ContentId[];
27
- copyright: string;
28
- publisher: string;
29
- isbn: string;
30
- manuscript: Stub[];
31
- notebook: Stub[];
32
- export_options: ExportOptions;
33
- trash: Stub[];
34
- total_word_count: number;
35
- }
36
- export interface BookBody extends ContentBody {
37
- meta: ContentMeta;
38
- payload: BookPayload;
39
- }
40
- export declare class Book extends Context {
41
- private _manuscriptView;
42
- private _notebookView;
43
- constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
44
- get payload(): BookPayload;
45
- static create(userId: ContentId, template: BookType): Book;
46
- get coverMediaRef(): ContentId;
47
- setCoverMediaRef(value: ContentId): void;
48
- get synopsisRef(): ContentRef;
49
- setSynopsisId(value: ContentRef): void;
50
- get name(): string;
51
- setName(value: string): void;
52
- get subtitle(): string;
53
- setSubtitle(value: string): void;
54
- get author(): string;
55
- setAuthor(value: string): void;
56
- get copyright(): string;
57
- setCopyright(value: string): void;
58
- get publisher(): string;
59
- setPublisher(value: string): void;
60
- get isbn(): string;
61
- setIsbn(value: string): void;
62
- get totalWordCount(): number;
63
- get manuscript(): ArrayView<Stub>;
64
- get notebook(): ArrayView<Stub>;
65
- get exportOptions(): ExportOptions;
66
- replaceExportOptions(newOptions: ExportOptions): void;
67
- getStubArrayKeys(): BookStubArrayKey[];
68
- getStubArrayView(key: BookStubArrayKey): ArrayView<Stub>;
69
- addFragmentToManuscript(fragment: Fragment, activeId: ContentId): void;
70
- addFragmentToNotebook(fragment: Fragment, activeId?: ContentId): void;
71
- updateWordCount(): Promise<void>;
72
- getAllCategories(context: BookStubArrayKey): string[];
73
- getPlaceholder(): string;
74
- asStub(): ContentStub;
75
- static harvestUniqueCategories(bookPayload: BookPayload, context: BookStubArrayKey): string[];
76
- mergeIncomingContext(incomingBook: BookBody): boolean;
77
- }
@@ -1,407 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Book = exports.BookStubArrayKey = exports.BookType = void 0;
4
- const ShareSync_1 = require("../../repo/ShareSync");
5
- const Struct_1 = require("../../util/Struct");
6
- const Operation_1 = require("../markup/Operation");
7
- const ArrayView_1 = require("./ArrayView");
8
- const Category_1 = require("./Category");
9
- const ContentKind_1 = require("./ContentKind");
10
- const Context_1 = require("./Context");
11
- const ExportOptions_1 = require("./ExportOptions");
12
- const Folder_1 = require("./Folder");
13
- const Fragment_1 = require("./Fragment");
14
- const Placeholder_1 = require("./Placeholder");
15
- const Stub_1 = require("./Stub");
16
- const Time_1 = require("./Time");
17
- const Workspace_1 = require("./Workspace");
18
- var BookType;
19
- (function (BookType) {
20
- BookType["FICTION"] = "fiction";
21
- BookType["NONFICTION"] = "non-fiction";
22
- BookType["EMPTY"] = "empty";
23
- })(BookType || (exports.BookType = BookType = {}));
24
- var BookStubArrayKey;
25
- (function (BookStubArrayKey) {
26
- BookStubArrayKey["MANUSCRIPT"] = "manuscript";
27
- BookStubArrayKey["NOTEBOOK"] = "notebook";
28
- BookStubArrayKey["TRASH"] = "trash";
29
- })(BookStubArrayKey || (exports.BookStubArrayKey = BookStubArrayKey = {}));
30
- class Book extends Context_1.Context {
31
- constructor(doc, shouldAcquire, shareSync) {
32
- super(doc, shouldAcquire, shareSync);
33
- this._manuscriptView = new ArrayView_1.ArrayView(this, ['payload', 'manuscript']);
34
- this._notebookView = new ArrayView_1.ArrayView(this, ['payload', 'notebook']);
35
- }
36
- get payload() {
37
- this.checkDisposed("Book.payload");
38
- return this.doc.data.payload;
39
- }
40
- static create(userId, template) {
41
- const shareSync = ShareSync_1.ShareSyncFactory.get();
42
- const bookId = shareSync.makeContentId();
43
- // Create a synopsis and a chapter
44
- const synopsis = Fragment_1.Fragment.create(userId, bookId, Category_1.Category.SYNOPSIS);
45
- const chapter = Fragment_1.Fragment.create(userId, bookId, Category_1.Category.CHAPTER);
46
- // Add three folders to the notebook
47
- const notebookStubs = [];
48
- if (template === BookType.FICTION) {
49
- notebookStubs.push(Folder_1.Folder.create("CHARACTERS"));
50
- notebookStubs.push(Folder_1.Folder.create("PLACES"));
51
- notebookStubs.push(Folder_1.Folder.create("THEMES"));
52
- }
53
- else if (template === BookType.NONFICTION) {
54
- notebookStubs.push(Folder_1.Folder.create("TOPICS"));
55
- notebookStubs.push(Folder_1.Folder.create("RESOURCES"));
56
- notebookStubs.push(Folder_1.Folder.create("QUESTIONS"));
57
- }
58
- const manuscriptStubs = [
59
- {
60
- kind: ContentKind_1.ContentKind.FRAGMENT,
61
- category: Category_1.Category.CHAPTER,
62
- ref: chapter.id,
63
- label: ""
64
- }
65
- ];
66
- const now = Time_1.MultiClock.now();
67
- return shareSync.createContent({
68
- meta: {
69
- ref: bookId,
70
- is_head: true,
71
- kind: ContentKind_1.ContentKind.BOOK,
72
- id: bookId,
73
- owner: userId,
74
- created_at: now,
75
- updated_at: now
76
- },
77
- payload: {
78
- name: "",
79
- subtitle: "",
80
- author: "",
81
- contributors: new Array(),
82
- copyright: "© " + Time_1.Time.currentYear(),
83
- publisher: "",
84
- isbn: "",
85
- synopsis_ref: synopsis.id,
86
- cover_media_ref: null,
87
- manuscript: manuscriptStubs,
88
- notebook: notebookStubs,
89
- trash: [],
90
- export_options: ExportOptions_1.ExportOptionsModel.makeDefaultOptions(),
91
- total_word_count: 0
92
- }
93
- });
94
- }
95
- get coverMediaRef() {
96
- this.checkDisposed("Book.coverMediaRef");
97
- return this.payload.cover_media_ref;
98
- }
99
- setCoverMediaRef(value) {
100
- this.checkDisposed("Book.setCoverMediaRef");
101
- if (this.coverMediaRef != value) {
102
- const batch = new Operation_1.BatchOperation(this);
103
- batch.setPathValue(['payload', 'cover_media_ref'], value);
104
- batch.commit();
105
- }
106
- }
107
- get synopsisRef() {
108
- this.checkDisposed("Book.synopsisRef");
109
- return this.payload.synopsis_ref;
110
- }
111
- setSynopsisId(value) {
112
- this.checkDisposed("Book.setSynopsisId");
113
- if (this.synopsisRef != value) {
114
- const batch = new Operation_1.BatchOperation(this);
115
- batch.setPathValue(['payload', 'synopsis_ref'], value);
116
- batch.commit();
117
- }
118
- }
119
- get name() {
120
- this.checkDisposed("Book.name");
121
- return this.payload.name;
122
- }
123
- setName(value) {
124
- this.checkDisposed("Book.setName");
125
- if (this.name != value) {
126
- const book = this;
127
- const batch = new Operation_1.BatchOperation(this);
128
- batch.editPathText(['payload', 'name'], value);
129
- batch.commit();
130
- // Update the name of this book in the workspace stub arrays.
131
- const workspaceId = Workspace_1.Workspace.makeWorkspaceId(book.meta.owner);
132
- ShareSync_1.ShareSyncFactory.get().acquire(ContentKind_1.ContentKind.WORKSPACE, workspaceId).then((workspace) => {
133
- workspace.editStubFieldText(book.id, 'label', book.name);
134
- workspace.release();
135
- });
136
- }
137
- }
138
- get subtitle() {
139
- this.checkDisposed("Book.subtitle");
140
- return this.payload.subtitle;
141
- }
142
- setSubtitle(value) {
143
- this.checkDisposed("Book.setSubtitle");
144
- if (this.subtitle != value) {
145
- const batch = new Operation_1.BatchOperation(this);
146
- batch.editPathText(['payload', 'subtitle'], value);
147
- batch.commit();
148
- }
149
- }
150
- get author() {
151
- this.checkDisposed("Book.author");
152
- return this.payload.author;
153
- }
154
- setAuthor(value) {
155
- this.checkDisposed("Book.setAuthor");
156
- if (this.author != value) {
157
- const batch = new Operation_1.BatchOperation(this);
158
- batch.editPathText(['payload', 'author'], value);
159
- batch.commit();
160
- }
161
- }
162
- get copyright() {
163
- this.checkDisposed("Book.copyright");
164
- return this.payload.copyright;
165
- }
166
- setCopyright(value) {
167
- this.checkDisposed("Book.setCopyright");
168
- if (this.copyright != value) {
169
- const batch = new Operation_1.BatchOperation(this);
170
- batch.editPathText(['payload', 'copyright'], value);
171
- batch.commit();
172
- }
173
- }
174
- get publisher() {
175
- this.checkDisposed("Book.publisher");
176
- return this.payload.publisher;
177
- }
178
- setPublisher(value) {
179
- this.checkDisposed("Book.setPublisher");
180
- if (this.publisher != value) {
181
- const batch = new Operation_1.BatchOperation(this);
182
- batch.editPathText(['payload', 'publisher'], value);
183
- batch.commit();
184
- }
185
- }
186
- get isbn() {
187
- this.checkDisposed("Book.isbn");
188
- return this.payload.isbn;
189
- }
190
- setIsbn(value) {
191
- this.checkDisposed("Book.setIsbn");
192
- if (this.isbn != value) {
193
- const batch = new Operation_1.BatchOperation(this);
194
- batch.editPathText(['payload', 'isbn'], value);
195
- batch.commit();
196
- }
197
- }
198
- get totalWordCount() {
199
- this.checkDisposed("Book.totalWordCount");
200
- return this.payload.total_word_count;
201
- }
202
- get manuscript() {
203
- this.checkDisposed("Book.manuscript");
204
- return this._manuscriptView;
205
- }
206
- get notebook() {
207
- this.checkDisposed("Book.notebook");
208
- return this._notebookView;
209
- }
210
- get exportOptions() {
211
- this.checkDisposed("Book.exportOptions");
212
- return this.payload.export_options || null;
213
- }
214
- replaceExportOptions(newOptions) {
215
- this.checkDisposed("Book.replaceExportOptions");
216
- // This method does a parallel-walk of the old export-options and the new
217
- // export-options, and performs a minimal set of batch operations to bring
218
- // this book's own embedded export-options inline with the new options.
219
- const oldOptions = (this.exportOptions || {});
220
- if (!Struct_1.Struct.equals(oldOptions, newOptions)) {
221
- const batch = new Operation_1.BatchOperation(this);
222
- if (oldOptions.selected_format != newOptions.selected_format) {
223
- batch.setPathValue(['payload', 'export_options', 'selected_format'], newOptions.selected_format);
224
- }
225
- const oldFormatNames = Object.keys(oldOptions.formats).sort();
226
- const newFormatNames = Object.keys(newOptions.formats).sort();
227
- const commonFormatNames = [];
228
- for (let i = 0; i < oldFormatNames.length; i++) {
229
- const oldFormatName = oldFormatNames[i];
230
- if (newFormatNames.includes(oldFormatName)) {
231
- commonFormatNames.push(oldFormatName);
232
- }
233
- else {
234
- batch.removeValueAtPath(['payload', 'export_options', 'formats', oldFormatName]);
235
- }
236
- }
237
- for (let i = 0; i < newFormatNames.length; i++) {
238
- const newFormatName = newFormatNames[i];
239
- if (!oldFormatNames.includes(newFormatName)) {
240
- const newFormatValue = newOptions.formats[newFormatName];
241
- batch.setPathValue(['payload', 'export_options', 'formats', newFormatName], newFormatValue);
242
- }
243
- }
244
- for (let i = 0; i < commonFormatNames.length; i++) {
245
- const formatName = commonFormatNames[i];
246
- const oldFormatOptions = oldOptions.formats[formatName];
247
- const newFormatOptions = newOptions.formats[formatName];
248
- if (oldFormatOptions.include_toc != newFormatOptions.include_toc) {
249
- batch.setPathValue(['payload', 'export_options', 'formats', formatName, 'include_toc'], newFormatOptions.include_toc);
250
- }
251
- if (oldFormatOptions.include_synopsis != newFormatOptions.include_synopsis) {
252
- batch.setPathValue(['payload', 'export_options', 'formats', formatName, 'include_synopsis'], newFormatOptions.include_synopsis);
253
- }
254
- const stubKeys = ['manuscript', 'notebook'];
255
- for (let j = 0; j < stubKeys.length; j++) {
256
- const stubKey = stubKeys[j];
257
- const oldStubKeyOptions = oldFormatOptions[stubKey];
258
- const newStubKeyOptions = newFormatOptions[stubKey];
259
- if (oldStubKeyOptions.include != newStubKeyOptions.include) {
260
- batch.setPathValue(['payload', 'export_options', 'formats', formatName, stubKey, 'include'], newStubKeyOptions.include);
261
- }
262
- const oldCategoryNames = Object.keys(oldStubKeyOptions.categories).sort();
263
- const newCategoryNames = Object.keys(newStubKeyOptions.categories).sort();
264
- const commonCategoryNames = [];
265
- for (let k = 0; k < oldCategoryNames.length; k++) {
266
- const oldCategoryName = oldCategoryNames[k];
267
- if (newCategoryNames.includes(oldCategoryName)) {
268
- commonCategoryNames.push(oldCategoryName);
269
- }
270
- else {
271
- batch.removeValueAtPath(['payload', 'export_options', 'formats', formatName, stubKey, 'categories', oldCategoryName]);
272
- }
273
- }
274
- for (let k = 0; k < newCategoryNames.length; k++) {
275
- const newCategoryName = newCategoryNames[k];
276
- if (!oldCategoryNames.includes(newCategoryName)) {
277
- const newCategoryOptions = newStubKeyOptions.categories[newCategoryName];
278
- batch.setPathValue(['payload', 'export_options', 'formats', formatName, stubKey, 'categories', newCategoryName], newCategoryOptions);
279
- }
280
- }
281
- for (let k = 0; k < commonCategoryNames.length; k++) {
282
- const categoryName = commonCategoryNames[k];
283
- const oldCategoryOptions = oldStubKeyOptions.categories[categoryName];
284
- const newCategoryOptions = newStubKeyOptions.categories[categoryName];
285
- const categoryOptionKeys = ['toc', 'name', 'number', 'prefix', 'brk'];
286
- for (let m = 0; m < categoryOptionKeys.length; m++) {
287
- const categoryOptionKey = categoryOptionKeys[m];
288
- const oldCategoryOptionValue = oldCategoryOptions[categoryOptionKey];
289
- const newCategoryOptionValue = newCategoryOptions[categoryOptionKey];
290
- if (oldCategoryOptionValue != newCategoryOptionValue) {
291
- batch.setPathValue(['payload', 'export_options', formatName, stubKey, 'categories', categoryName, categoryOptionKey], newCategoryOptionValue);
292
- }
293
- }
294
- }
295
- }
296
- }
297
- batch.commit();
298
- }
299
- }
300
- getStubArrayKeys() {
301
- return [
302
- BookStubArrayKey.MANUSCRIPT,
303
- BookStubArrayKey.NOTEBOOK,
304
- BookStubArrayKey.TRASH
305
- ];
306
- }
307
- getStubArrayView(key) {
308
- this.checkDisposed("Book.getStubArrayView");
309
- if (key === BookStubArrayKey.MANUSCRIPT) {
310
- return this._manuscriptView;
311
- }
312
- else if (key === BookStubArrayKey.NOTEBOOK) {
313
- return this._notebookView;
314
- }
315
- else if (key === BookStubArrayKey.TRASH) {
316
- return this._trashView;
317
- }
318
- return null;
319
- }
320
- addFragmentToManuscript(fragment, activeId) {
321
- this.checkDisposed("Book.addFragmentToManuscript");
322
- const stub = fragment.asStub();
323
- if (fragment.category === Category_1.Category.FRONT_MATTER) {
324
- // Always add front-matter to the front.
325
- this.manuscript.unshift(stub);
326
- }
327
- else if (fragment.category === Category_1.Category.BACK_MATTER) {
328
- // Always add back-matter to the back.
329
- this.manuscript.push(stub);
330
- }
331
- else {
332
- // All other content should be added to the most natural point, based on whatever content is currently active
333
- Stub_1.Stubs.insertStubAtActivePoint(stub, this._manuscriptView, fragment.category, activeId, false);
334
- }
335
- if (fragment.wordCount > 0) {
336
- this.updateWordCount();
337
- }
338
- }
339
- addFragmentToNotebook(fragment, activeId) {
340
- this.checkDisposed("Book.addFragmentToNotebook");
341
- const stub = fragment.asStub();
342
- Stub_1.Stubs.insertStubAtActivePoint(stub, this._notebookView, fragment.category, activeId, true);
343
- }
344
- async updateWordCount() {
345
- this.checkDisposed("Book.updateWordCount");
346
- const prevTotalWordCount = this.totalWordCount;
347
- const shareSync = ShareSync_1.ShareSyncFactory.get();
348
- let totalWordCount = 0;
349
- for (let i = 0, len = this.manuscript.length; i < len; i++) {
350
- const stub = this.manuscript.get(i);
351
- if (Stub_1.Stubs.isContentStub(stub)) {
352
- // TODO: should we skip front-matter and back-matter fragments?
353
- const ref = stub.ref;
354
- const chapter = await shareSync.acquire(ContentKind_1.ContentKind.FRAGMENT, ref);
355
- totalWordCount += chapter.wordCount;
356
- chapter.release();
357
- }
358
- }
359
- if (totalWordCount != prevTotalWordCount) {
360
- const batch = new Operation_1.BatchOperation(this);
361
- batch.setPathValue(['payload', 'total_word_count'], totalWordCount);
362
- batch.commit();
363
- }
364
- }
365
- getAllCategories(context) {
366
- this.checkDisposed("Book.getAllCategories");
367
- return Book.harvestUniqueCategories(this.payload, context);
368
- }
369
- getPlaceholder() {
370
- this.checkDisposed("Book.getPlaceholder");
371
- return Placeholder_1.Placeholder.forContent(this);
372
- }
373
- asStub() {
374
- this.checkDisposed("Book.asStub");
375
- return {
376
- kind: ContentKind_1.ContentKind.BOOK,
377
- ref: this.id,
378
- label: this.name
379
- };
380
- }
381
- static harvestUniqueCategories(bookPayload, context) {
382
- const stubs = context === BookStubArrayKey.MANUSCRIPT ?
383
- bookPayload.manuscript :
384
- bookPayload.notebook;
385
- const unique = [];
386
- const categories = {};
387
- for (let i = 0, len = stubs.length; i < len; i++) {
388
- const stub = stubs[i];
389
- let category = null;
390
- if (Stub_1.Stubs.isFolderStub(stub)) {
391
- category = ContentKind_1.ContentKind.FOLDER;
392
- }
393
- else if (Stub_1.Stubs.isContentStub(stub)) {
394
- category = stub.category;
395
- }
396
- if (!categories.hasOwnProperty(category)) {
397
- categories[category] = true;
398
- unique.push(category);
399
- }
400
- }
401
- return unique;
402
- }
403
- mergeIncomingContext(incomingBook) {
404
- return super.mergeIncomingContext(incomingBook);
405
- }
406
- }
407
- exports.Book = Book;
@@ -1,16 +0,0 @@
1
- export declare enum Category {
2
- FRONT_MATTER = "front-matter",
3
- BACK_MATTER = "back-matter",
4
- FOLDER = "folder",
5
- PART = "part",
6
- CHAPTER = "chapter",
7
- SCENE = "scene",
8
- SYNOPSIS = "synopsis",
9
- ARTICLE = "article",
10
- SHORT_STORY = "short-story",
11
- IDEA = "idea",
12
- NOTE = "note",
13
- CHARACTER = "character",
14
- PLACE = "place",
15
- THEME = "theme"
16
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Category = void 0;
4
- var Category;
5
- (function (Category) {
6
- Category["FRONT_MATTER"] = "front-matter";
7
- Category["BACK_MATTER"] = "back-matter";
8
- Category["FOLDER"] = "folder";
9
- Category["PART"] = "part";
10
- Category["CHAPTER"] = "chapter";
11
- Category["SCENE"] = "scene";
12
- Category["SYNOPSIS"] = "synopsis";
13
- Category["ARTICLE"] = "article";
14
- Category["SHORT_STORY"] = "short-story";
15
- Category["IDEA"] = "idea";
16
- Category["NOTE"] = "note";
17
- Category["CHARACTER"] = "character";
18
- Category["PLACE"] = "place";
19
- Category["THEME"] = "theme";
20
- })(Category || (exports.Category = Category = {}));
@@ -1,21 +0,0 @@
1
- /// <reference path="../../../decs.d.ts" />
2
- import { Doc } from '@shaxpir/sharedb/lib/client';
3
- import { ShareSync } from '../../repo/ShareSync';
4
- import { ArrayView } from './ArrayView';
5
- import { Content, ContentBody } from "./Content";
6
- import { CompactDateTime, MultiTime } from './Time';
7
- export declare abstract class Checkpointable extends Content {
8
- private _checkpointsView;
9
- constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
10
- get checkpoints(): ArrayView<CompactDateTime>;
11
- hasCheckpoint(timestamp: CompactDateTime): boolean;
12
- addCheckpoint(timestamp: CompactDateTime): boolean;
13
- makeCheckpointBody(): ContentBody;
14
- cloneCheckpoints(): CompactDateTime[];
15
- recordCheckpoint(checkpointBody: ContentBody): void;
16
- acquireLastCheckpoint(): Promise<Content>;
17
- acquireLatestCheckpointAt(timestamp: CompactDateTime): Promise<Content>;
18
- loadLatestCheckpointAt(timestamp: CompactDateTime): Promise<Content>;
19
- beforeRestoreTo(checkpoint: Checkpointable, now: MultiTime): Promise<void>;
20
- restoreTo(checkpoint: Checkpointable, now: MultiTime): Promise<void>;
21
- }