@shaxpir/duiduidui-models 1.0.1 → 1.1.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 (224) 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/index.d.ts +0 -6
  47. package/dist/util/index.js +0 -6
  48. package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
  49. package/lib/models/BayesianScore.ts +32 -0
  50. package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
  51. package/lib/models/{content/Content.ts → Content.ts} +15 -18
  52. package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
  53. package/lib/models/{content/Device.ts → Device.ts} +26 -22
  54. package/lib/models/Hanzi.ts +16 -0
  55. package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
  56. package/lib/models/{content/Media.ts → Media.ts} +3 -4
  57. package/lib/models/Metric.ts +233 -0
  58. package/lib/models/{content/Model.ts → Model.ts} +4 -6
  59. package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
  60. package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
  61. package/lib/models/Phrase.ts +53 -0
  62. package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
  63. package/lib/models/Progress.ts +66 -0
  64. package/lib/models/Review.ts +18 -0
  65. package/lib/models/Session.ts +140 -0
  66. package/lib/models/Term.ts +139 -0
  67. package/lib/models/User.ts +97 -0
  68. package/lib/models/Workspace.ts +129 -0
  69. package/lib/models/index.ts +22 -2
  70. package/lib/repo/ShareSync.ts +9 -13
  71. package/lib/repo/index.ts +1 -0
  72. package/lib/util/index.ts +0 -6
  73. package/package.json +4 -15
  74. package/dist/models/OutboundMessage.d.ts +0 -18
  75. package/dist/models/OutboundMessage.js +0 -25
  76. package/dist/models/content/Activity.d.ts +0 -10
  77. package/dist/models/content/Billing.d.ts +0 -144
  78. package/dist/models/content/Billing.js +0 -418
  79. package/dist/models/content/Book.d.ts +0 -77
  80. package/dist/models/content/Book.js +0 -407
  81. package/dist/models/content/Category.d.ts +0 -16
  82. package/dist/models/content/Category.js +0 -20
  83. package/dist/models/content/Checkpointable.d.ts +0 -21
  84. package/dist/models/content/Checkpointable.js +0 -156
  85. package/dist/models/content/Comment.d.ts +0 -19
  86. package/dist/models/content/Comment.js +0 -53
  87. package/dist/models/content/ConceptArt.d.ts +0 -31
  88. package/dist/models/content/ConceptArt.js +0 -84
  89. package/dist/models/content/Context.d.ts +0 -28
  90. package/dist/models/content/Context.js +0 -162
  91. package/dist/models/content/DevEnv.d.ts +0 -5
  92. package/dist/models/content/DevEnv.js +0 -9
  93. package/dist/models/content/Dictionary.d.ts +0 -31
  94. package/dist/models/content/Dictionary.js +0 -5
  95. package/dist/models/content/DictionaryEntry.d.ts +0 -20
  96. package/dist/models/content/DictionaryEntry.js +0 -2
  97. package/dist/models/content/ElasticModel.d.ts +0 -149
  98. package/dist/models/content/ElasticModel.js +0 -179
  99. package/dist/models/content/Environment.d.ts +0 -61
  100. package/dist/models/content/Environment.js +0 -124
  101. package/dist/models/content/ExportOptions.d.ts +0 -64
  102. package/dist/models/content/ExportOptions.js +0 -213
  103. package/dist/models/content/Folder.d.ts +0 -16
  104. package/dist/models/content/Folder.js +0 -33
  105. package/dist/models/content/Fragment.d.ts +0 -54
  106. package/dist/models/content/Fragment.js +0 -181
  107. package/dist/models/content/Hanzi.d.ts +0 -21
  108. package/dist/models/content/HighlightRule.d.ts +0 -9
  109. package/dist/models/content/HighlightRule.js +0 -2
  110. package/dist/models/content/Migration.d.ts +0 -68
  111. package/dist/models/content/Migration.js +0 -155
  112. package/dist/models/content/Phrase.d.ts +0 -8
  113. package/dist/models/content/Placeholder.d.ts +0 -8
  114. package/dist/models/content/Placeholder.js +0 -36
  115. package/dist/models/content/RichText.d.ts +0 -58
  116. package/dist/models/content/RichText.js +0 -79
  117. package/dist/models/content/Session.js +0 -173
  118. package/dist/models/content/Speech.d.ts +0 -67
  119. package/dist/models/content/Speech.js +0 -97
  120. package/dist/models/content/Stub.d.ts +0 -24
  121. package/dist/models/content/Stub.js +0 -179
  122. package/dist/models/content/Time.d.ts +0 -56
  123. package/dist/models/content/Time.js +0 -295
  124. package/dist/models/content/User.d.ts +0 -36
  125. package/dist/models/content/User.js +0 -95
  126. package/dist/models/content/Workspace.d.ts +0 -71
  127. package/dist/models/content/Workspace.js +0 -237
  128. package/dist/models/content/index.d.ts +0 -17
  129. package/dist/models/content/index.js +0 -34
  130. package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
  131. package/dist/models/legacy/LegacyBodyFormat.js +0 -2
  132. package/dist/models/legacy/LegacyComment.d.ts +0 -12
  133. package/dist/models/legacy/LegacyComment.js +0 -2
  134. package/dist/models/legacy/LegacyContent.d.ts +0 -53
  135. package/dist/models/legacy/LegacyContent.js +0 -55
  136. package/dist/models/legacy/LegacyConversion.d.ts +0 -55
  137. package/dist/models/legacy/LegacyConversion.js +0 -401
  138. package/dist/models/legacy/LegacyFragment.d.ts +0 -21
  139. package/dist/models/legacy/LegacyFragment.js +0 -2
  140. package/dist/models/legacy/LegacyLocator.d.ts +0 -8
  141. package/dist/models/legacy/LegacyLocator.js +0 -31
  142. package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
  143. package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
  144. package/dist/models/legacy/LegacyPicture.d.ts +0 -14
  145. package/dist/models/legacy/LegacyPicture.js +0 -2
  146. package/dist/models/legacy/LegacyProfile.d.ts +0 -9
  147. package/dist/models/legacy/LegacyProfile.js +0 -2
  148. package/dist/models/legacy/LegacySession.d.ts +0 -41
  149. package/dist/models/legacy/LegacySession.js +0 -35
  150. package/dist/models/legacy/LegacyStory.d.ts +0 -23
  151. package/dist/models/legacy/LegacyStory.js +0 -2
  152. package/dist/models/legacy/LegacyStub.d.ts +0 -15
  153. package/dist/models/legacy/LegacyStub.js +0 -2
  154. package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
  155. package/dist/models/legacy/LegacyTransaction.js +0 -49
  156. package/dist/models/legacy/LegacyUser.d.ts +0 -28
  157. package/dist/models/legacy/LegacyUser.js +0 -32
  158. package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
  159. package/dist/models/legacy/LegacyWorkspace.js +0 -6
  160. package/dist/models/legacy/index.d.ts +0 -15
  161. package/dist/models/legacy/index.js +0 -32
  162. package/dist/models/markup/BodyFormat.d.ts +0 -14
  163. package/dist/models/markup/BodyFormat.js +0 -190
  164. package/dist/models/markup/DeltaOps.d.ts +0 -5
  165. package/dist/models/markup/DeltaOps.js +0 -74
  166. package/dist/models/markup/HtmlMarkup.d.ts +0 -4
  167. package/dist/models/markup/HtmlMarkup.js +0 -21
  168. package/dist/models/markup/index.d.ts +0 -4
  169. package/dist/models/markup/index.js +0 -21
  170. package/dist/util/Async.d.ts +0 -8
  171. package/dist/util/Async.js +0 -18
  172. package/dist/util/Base62.d.ts +0 -6
  173. package/dist/util/Base62.js +0 -47
  174. package/dist/util/BinarySearch.d.ts +0 -7
  175. package/dist/util/BinarySearch.js +0 -46
  176. package/dist/util/CachingHasher.d.ts +0 -8
  177. package/dist/util/CachingHasher.js +0 -41
  178. package/dist/util/Color.d.ts +0 -32
  179. package/dist/util/Color.js +0 -204
  180. package/dist/util/Dispatch.d.ts +0 -15
  181. package/dist/util/Dispatch.js +0 -79
  182. package/dist/util/EditDistance.d.ts +0 -13
  183. package/dist/util/EditDistance.js +0 -184
  184. package/dist/util/NumberFormat.d.ts +0 -14
  185. package/dist/util/NumberFormat.js +0 -224
  186. package/dist/util/Struct.d.ts +0 -4
  187. package/dist/util/Struct.js +0 -15
  188. package/dist/util/Template.d.ts +0 -16
  189. package/dist/util/Template.js +0 -128
  190. package/dist/util/Text.d.ts +0 -45
  191. package/dist/util/Text.js +0 -243
  192. package/dist/util/Tuples.d.ts +0 -9
  193. package/dist/util/Tuples.js +0 -135
  194. package/dist/util/Validate.d.ts +0 -4
  195. package/dist/util/Validate.js +0 -11
  196. package/dist/util/Vocabulary.d.ts +0 -3
  197. package/dist/util/Vocabulary.js +0 -35
  198. package/lib/models/content/Billing.ts +0 -558
  199. package/lib/models/content/DevEnv.ts +0 -5
  200. package/lib/models/content/DictionaryEntry.ts +0 -22
  201. package/lib/models/content/Hanzi.ts +0 -25
  202. package/lib/models/content/Phrase.ts +0 -10
  203. package/lib/models/content/Time.ts +0 -328
  204. package/lib/models/content/User.ts +0 -130
  205. package/lib/models/content/index.ts +0 -19
  206. package/lib/models/markup/DeltaOps.ts +0 -71
  207. package/lib/models/markup/index.ts +0 -6
  208. package/lib/util/Base62.ts +0 -47
  209. package/lib/util/CachingHasher.ts +0 -38
  210. package/lib/util/Dispatch.ts +0 -92
  211. package/lib/util/NumberFormat.ts +0 -194
  212. package/lib/util/Struct.ts +0 -14
  213. package/lib/util/Tuples.ts +0 -131
  214. /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
  215. /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
  216. /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
  217. /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
  218. /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
  219. /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
  220. /package/dist/models/{content/Activity.js → Review.js} +0 -0
  221. /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
  222. /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
  223. /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
  224. /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpeechPersona = exports.SpeechAge = exports.SpeechGender = exports.SpeechDialect = exports.SpeechLanguage = exports.SpeechEngine = exports.SpeechProvider = exports.SpeechDataType = void 0;
4
- var SpeechDataType;
5
- (function (SpeechDataType) {
6
- SpeechDataType["AUDIO_MP3"] = "audio_mp3";
7
- SpeechDataType["AUDIO_OGG"] = "audio_ogg";
8
- SpeechDataType["META_WORD_MARKS"] = "meta_word_marks";
9
- })(SpeechDataType || (exports.SpeechDataType = SpeechDataType = {}));
10
- var SpeechProvider;
11
- (function (SpeechProvider) {
12
- SpeechProvider["AWS"] = "aws";
13
- SpeechProvider["ELEVEN_LABS"] = "eleven_labs";
14
- })(SpeechProvider || (exports.SpeechProvider = SpeechProvider = {}));
15
- var SpeechEngine;
16
- (function (SpeechEngine) {
17
- SpeechEngine["STANDARD"] = "standard";
18
- SpeechEngine["NEURAL"] = "neural";
19
- })(SpeechEngine || (exports.SpeechEngine = SpeechEngine = {}));
20
- ;
21
- var SpeechLanguage;
22
- (function (SpeechLanguage) {
23
- SpeechLanguage["ENGLISH"] = "English";
24
- })(SpeechLanguage || (exports.SpeechLanguage = SpeechLanguage = {}));
25
- ;
26
- var SpeechDialect;
27
- (function (SpeechDialect) {
28
- SpeechDialect["US"] = "US";
29
- SpeechDialect["AU"] = "AU";
30
- SpeechDialect["GB"] = "GB";
31
- SpeechDialect["IN"] = "IN";
32
- })(SpeechDialect || (exports.SpeechDialect = SpeechDialect = {}));
33
- var SpeechGender;
34
- (function (SpeechGender) {
35
- SpeechGender["MALE"] = "Male";
36
- SpeechGender["FEMALE"] = "Female";
37
- })(SpeechGender || (exports.SpeechGender = SpeechGender = {}));
38
- var SpeechAge;
39
- (function (SpeechAge) {
40
- SpeechAge["ADULT"] = "Adult";
41
- SpeechAge["CHILD"] = "Child";
42
- SpeechAge["ELDERLY"] = "Elderly";
43
- })(SpeechAge || (exports.SpeechAge = SpeechAge = {}));
44
- class SpeechPersona {
45
- constructor(code, name, provider, engine, language, dialect, gender, age) {
46
- this.code = code;
47
- this.name = name;
48
- this.provider = provider;
49
- this.engine = engine;
50
- this.language = language;
51
- this.dialect = dialect;
52
- this.gender = gender;
53
- this.age = age;
54
- }
55
- static byName(name) {
56
- name = name.toLowerCase();
57
- for (let i = 0; i < SpeechPersona.ALL.length; i++) {
58
- const persona = SpeechPersona.ALL[i];
59
- if (persona.name.toLowerCase() == name) {
60
- return persona;
61
- }
62
- }
63
- return null;
64
- }
65
- getLangaugeCode() {
66
- if (this.language === SpeechLanguage.ENGLISH) {
67
- if (this.dialect === SpeechDialect.US) {
68
- return "en-US";
69
- }
70
- else if (this.dialect === SpeechDialect.GB) {
71
- return "en-GB";
72
- }
73
- }
74
- return null;
75
- }
76
- }
77
- exports.SpeechPersona = SpeechPersona;
78
- SpeechPersona.AMY = new SpeechPersona("00", "Amy", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.FEMALE, SpeechAge.ADULT);
79
- SpeechPersona.BRIAN = new SpeechPersona("01", "Brian", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.MALE, SpeechAge.ADULT);
80
- SpeechPersona.EMMA = new SpeechPersona("02", "Emma", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.GB, SpeechGender.FEMALE, SpeechAge.ADULT);
81
- SpeechPersona.IVY = new SpeechPersona("03", "Ivy", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.CHILD);
82
- SpeechPersona.JOANNA = new SpeechPersona("04", "Joanna", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
83
- SpeechPersona.JOEY = new SpeechPersona("05", "Joey", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
84
- SpeechPersona.JUSTIN = new SpeechPersona("06", "Justin", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.CHILD);
85
- SpeechPersona.KENDRA = new SpeechPersona("07", "Kendra", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
86
- SpeechPersona.KEVIN = new SpeechPersona("08", "Kevin", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.CHILD);
87
- SpeechPersona.KIMBERY = new SpeechPersona("09", "Kimberly", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
88
- SpeechPersona.MATTHEW = new SpeechPersona("0a", "Matthew", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
89
- SpeechPersona.SALLI = new SpeechPersona("0b", "Salli", SpeechProvider.AWS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
90
- SpeechPersona.DAVID = new SpeechPersona("5FlhwUeTKmBbKy4nphG3", "David", SpeechProvider.ELEVEN_LABS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.MALE, SpeechAge.ADULT);
91
- SpeechPersona.RACHEL = new SpeechPersona("nTeH5Tfb8NMpR0YHgOSI", "Rachel", SpeechProvider.ELEVEN_LABS, SpeechEngine.NEURAL, SpeechLanguage.ENGLISH, SpeechDialect.US, SpeechGender.FEMALE, SpeechAge.ADULT);
92
- SpeechPersona.DEFAULT = SpeechPersona.JOANNA;
93
- SpeechPersona.ALL = [
94
- SpeechPersona.AMY, SpeechPersona.BRIAN, SpeechPersona.EMMA, SpeechPersona.IVY, SpeechPersona.JOANNA, SpeechPersona.JOEY,
95
- SpeechPersona.JUSTIN, SpeechPersona.KENDRA, SpeechPersona.KEVIN, SpeechPersona.KIMBERY, SpeechPersona.MATTHEW, SpeechPersona.SALLI,
96
- SpeechPersona.DAVID, SpeechPersona.RACHEL
97
- ];
@@ -1,24 +0,0 @@
1
- import { ArrayView } from "./ArrayView";
2
- import { ContentId, ContentRef } from "./Content";
3
- import { ContentKind } from "./ContentKind";
4
- export interface Stub {
5
- kind: ContentKind;
6
- label: string;
7
- parent?: ContentId;
8
- children?: Stub[];
9
- }
10
- export interface FolderStub extends Stub {
11
- id: ContentId;
12
- }
13
- export interface ContentStub extends Stub {
14
- category?: string;
15
- ref: ContentRef;
16
- }
17
- export declare class Stubs {
18
- static idFromStub(stub: Stub): ContentId;
19
- static refFromStub(stub: Stub): ContentRef;
20
- static unflatten(stubs: Stub[]): Stub[];
21
- static isFolderStub(stub: Stub): boolean;
22
- static isContentStub(stub: Stub): boolean;
23
- static insertStubAtActivePoint(stub: Stub, stubArrayView: ArrayView<Stub>, category: string, activeId: ContentId, defaultAtBeginning: boolean): number;
24
- }
@@ -1,179 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Stubs = void 0;
7
- const pluralize_1 = __importDefault(require("pluralize"));
8
- const Struct_1 = require("../../util/Struct");
9
- const Content_1 = require("./Content");
10
- const ContentKind_1 = require("./ContentKind");
11
- class Stubs {
12
- static idFromStub(stub) {
13
- let id = null;
14
- if (typeof (stub) === "string") {
15
- // The array entry is a bare string... either a locator or an ID.
16
- id = Content_1.Content.parseContentRef(stub).id;
17
- }
18
- else if (stub.hasOwnProperty("id")) {
19
- id = stub.id;
20
- }
21
- else if (stub.hasOwnProperty("ref")) {
22
- id = Content_1.Content.parseContentRef(stub.ref).id;
23
- }
24
- return id;
25
- }
26
- static refFromStub(stub) {
27
- let ref = null;
28
- if (typeof (stub) === "string") {
29
- ref = stub;
30
- }
31
- else if (stub.hasOwnProperty("ref")) {
32
- ref = stub.ref;
33
- }
34
- else if (stub.hasOwnProperty("id")) {
35
- ref = stub.id;
36
- }
37
- return ref;
38
- }
39
- static unflatten(stubs) {
40
- const nodesById = new Map();
41
- const unflattened = [];
42
- for (let i = 0, len = stubs.length; i < len; i++) {
43
- const stub = Struct_1.Struct.clone(stubs[i]);
44
- const id = Stubs.idFromStub(stub);
45
- nodesById.set(id, stub);
46
- if (stub.parent && nodesById.has(stub.parent)) {
47
- const parentNode = nodesById.get(stub.parent);
48
- if (!parentNode.hasOwnProperty("children")) {
49
- parentNode.children = [];
50
- }
51
- parentNode.children.push(stub);
52
- }
53
- else {
54
- unflattened.push(stub);
55
- }
56
- }
57
- return unflattened;
58
- }
59
- static isFolderStub(stub) {
60
- return stub && stub.hasOwnProperty('kind') && stub.kind == ContentKind_1.ContentKind.FOLDER;
61
- }
62
- static isContentStub(stub) {
63
- return stub && stub.hasOwnProperty('ref');
64
- }
65
- // Given an array of fragment stubs (like you'd find in 'book.payload.manuscript',
66
- // 'book.payload.notebook', or 'book.payload.ideas'), this function adds the
67
- // designated stub to the array at the correct index. This is based in part on
68
- // whether a fragment is already 'active' (selected by the user in the workspace
69
- // tree) and whether the default insertion point is at the beginning or end of
70
- // the array. When the correct insertion point has been found the function
71
- // automatically injects the correct tree-parent ID into the stub.
72
- static insertStubAtActivePoint(stub, stubArrayView, category, activeId, defaultAtBeginning) {
73
- // Build a parentage map of all the stubs in the array.
74
- const parentage = new Map();
75
- const indexesById = new Map();
76
- // Try to find a folder whose label matches the pluralization of the category for this stub.
77
- // For example, if the stub has a category of "character", then a matching folder would be
78
- // named "CHARACTERS" or "Characters". If we find such a folder, then the new stub will be
79
- // added within the matching folder's hierarchy.
80
- let categoryFolderStubIdx = -1;
81
- if (category !== null) {
82
- const singularCategory = pluralize_1.default.singular(category.toLowerCase());
83
- for (let i = 0, len = stubArrayView.length; i < len; i++) {
84
- const currentStub = stubArrayView.get(i);
85
- const stubId = Stubs.idFromStub(currentStub);
86
- indexesById.set(stubId, i);
87
- if (currentStub.parent) {
88
- parentage.set(stubId, currentStub.parent);
89
- }
90
- if (Stubs.isFolderStub(currentStub)) {
91
- const folderLabel = currentStub.label.toLowerCase();
92
- const singularLabel = pluralize_1.default.singular(folderLabel);
93
- if (singularLabel === singularCategory) {
94
- categoryFolderStubIdx = i;
95
- }
96
- }
97
- }
98
- }
99
- // Find the active ID (i.e., whatever is currently selected in the menu) in the stub array
100
- let activeIdx = stubArrayView.firstIndexWhere(stub => Stubs.idFromStub(stub) === activeId);
101
- // If there isn't an active ID (because nothing is currently selected in the menu), or if
102
- // the active ID doesn't seem to be within this particular stub array (manuscript vs notebook),
103
- // then treat any category folder we might have found ("Characters" or "Themes", etc) as the
104
- // as an active ID.
105
- if (activeIdx === -1) {
106
- activeIdx = categoryFolderStubIdx;
107
- }
108
- else if (categoryFolderStubIdx !== -1) {
109
- // If the active stub and the category folder stub both exist, then we need to figure out
110
- // which of them takes priority. Matching a category folder is more important, so generally,
111
- // we will just use the category folder. But if the active index is WITHIN the category
112
- // folder, then we'll use the active ID instead.
113
- let activeIdIsWithinCategoryFolder = false;
114
- let currentStub = stubArrayView.get(activeIdx);
115
- while (currentStub) {
116
- const currentStubId = Stubs.idFromStub(currentStub);
117
- if (parentage.has(currentStubId)) {
118
- const parentId = parentage.get(currentStubId);
119
- if (indexesById.has(parentId)) {
120
- const parentStubIndex = indexesById.get(parentId);
121
- if (parentStubIndex === categoryFolderStubIdx) {
122
- activeIdIsWithinCategoryFolder = true;
123
- break;
124
- }
125
- currentStub = stubArrayView.get(parentStubIndex);
126
- }
127
- else {
128
- // NOTE: It should be impossible to get here, because we've already built a map of all the
129
- // stubs in the array, and we've already checked that the parentage map contains the parent ID.
130
- throw new Error(`Parent ID ${parentId} not found in stub array`);
131
- }
132
- }
133
- else {
134
- currentStub = undefined;
135
- }
136
- }
137
- if (!activeIdIsWithinCategoryFolder) {
138
- activeIdx = categoryFolderStubIdx;
139
- }
140
- }
141
- // Insert the new stub into the array at the index of the active stub (which
142
- // may have been adjusted above to point to the category folder index).
143
- let idx;
144
- if (activeIdx === -1) {
145
- // Couldn't find the active ID in the array of stubs. Add the stub at either
146
- // the beginning or end of the array, depending on the designated default.
147
- if (defaultAtBeginning) {
148
- stubArrayView.unshift(stub);
149
- idx = 0;
150
- }
151
- else {
152
- idx = stubArrayView.length;
153
- stubArrayView.push(stub);
154
- }
155
- }
156
- else {
157
- // Find the stub at the active index. If it's a folder, then use it as the parent of the new stub. Otherwise,
158
- // if the stub at the active index has a parent, then the new stub should assume the same parent as its sibling.
159
- const activeStub = stubArrayView.get(activeIdx);
160
- if (Stubs.isFolderStub(activeStub)) {
161
- const folderStub = activeStub;
162
- stub.parent = folderStub.id;
163
- }
164
- else if (activeStub.parent) {
165
- stub.parent = activeStub.parent;
166
- }
167
- // Insert the new stub immediately after the active stub.
168
- idx = activeIdx + 1;
169
- if (idx >= stubArrayView.length) {
170
- stubArrayView.push(stub);
171
- }
172
- else {
173
- stubArrayView.insert(idx, stub);
174
- }
175
- }
176
- return idx;
177
- }
178
- }
179
- exports.Stubs = Stubs;
@@ -1,56 +0,0 @@
1
- import dayjs from 'dayjs';
2
- declare enum CompactDateTimeBrand {
3
- }
4
- declare enum CompactDateBrand {
5
- }
6
- export type CompactDateTime = string & CompactDateTimeBrand;
7
- export type CompactDate = string & CompactDateBrand;
8
- export interface SingleTime {
9
- utc_time: CompactDateTime;
10
- }
11
- export interface MultiTime {
12
- utc_time: CompactDateTime;
13
- local_time: CompactDateTime;
14
- }
15
- export declare class MultiClock {
16
- static utcNow(): MultiTime;
17
- static now(): MultiTime;
18
- }
19
- export declare class Time {
20
- static readonly DATETIME_FORMAT_LEGACY: string;
21
- static readonly DATE_FORMAT: string;
22
- static readonly DATETIME_FORMAT_COMPACT: string;
23
- static readonly DATE_NO_YEAR: string;
24
- static readonly DATE_BEAUTIFIED: string;
25
- static readonly DATE_FULLY_BEAUTIFIED: string;
26
- static readonly YEAR_ONLY: string;
27
- static asCompactDateTime(text: string): CompactDateTime;
28
- static asCompactDate(text: string): CompactDate | null;
29
- static isDateBefore(a: CompactDate, b: CompactDate): boolean;
30
- static isDateAfter(a: CompactDate, b: CompactDate): boolean;
31
- static compareDate(a: CompactDate, b: CompactDate): number;
32
- static isDateTimeBefore(a: CompactDateTime, b: CompactDateTime): boolean;
33
- static isDateTimeAfter(a: CompactDateTime, b: CompactDateTime): boolean;
34
- static compareDateTime(a: CompactDateTime, b: CompactDateTime): number;
35
- static sortByUtcTime(array: MultiTime[]): MultiTime[];
36
- static dateFrom(timestamp: CompactDateTime): CompactDate;
37
- static datesBetween(minDate: CompactDate, maxDate: CompactDate): CompactDate[];
38
- static plus(timestamp: CompactDateTime, amount: number, units: dayjs.ManipulateType): CompactDateTime;
39
- static todayLocal(): CompactDate;
40
- static todayUtc(): CompactDate;
41
- static startOfMonth(date: CompactDate): CompactDate;
42
- static local(utc?: CompactDateTime): CompactDateTime;
43
- static utcFromEpochSeconds(seconds: number): CompactDateTime;
44
- static utc(local?: CompactDateTime): CompactDateTime;
45
- static format(timestamp: CompactDateTime, pattern: string, isLocal: boolean): CompactDateTime;
46
- static formatFromDate(date: Date, pattern: string): string;
47
- static beautify(timestamp: CompactDateTime, isLocal?: boolean, amount?: number, units?: string): string;
48
- static absDiffMinutes(a: CompactDateTime, b: CompactDateTime): number;
49
- static elapsed(timestamp: CompactDateTime, isLocal: boolean): string;
50
- static timeUntil(utcTime: CompactDateTime, units: dayjs.UnitType): number;
51
- static timeSince(utcTime: CompactDateTime, units: dayjs.UnitType): number;
52
- static currentYear(): string;
53
- static humanizedDatePacific(epochSeconds: number): string;
54
- static humanizedTimePacific(epochSeconds: number): string;
55
- }
56
- export {};
@@ -1,295 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Time = exports.MultiClock = void 0;
7
- const dayjs_1 = __importDefault(require("dayjs"));
8
- const utc_1 = __importDefault(require("dayjs/plugin/utc"));
9
- const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
10
- const dayOfYear_1 = __importDefault(require("dayjs/plugin/dayOfYear"));
11
- dayjs_1.default.extend(utc_1.default);
12
- dayjs_1.default.extend(timezone_1.default);
13
- dayjs_1.default.extend(dayOfYear_1.default);
14
- var CompactDateTimeBrand;
15
- (function (CompactDateTimeBrand) {
16
- })(CompactDateTimeBrand || (CompactDateTimeBrand = {}));
17
- var CompactDateBrand;
18
- (function (CompactDateBrand) {
19
- })(CompactDateBrand || (CompactDateBrand = {}));
20
- class MultiClock {
21
- static utcNow() {
22
- const localtime = Time.local();
23
- const utcTime = Time.utc(localtime);
24
- return {
25
- local_time: utcTime,
26
- utc_time: utcTime
27
- };
28
- }
29
- static now() {
30
- const localtime = Time.local();
31
- return {
32
- local_time: localtime,
33
- utc_time: Time.utc(localtime)
34
- };
35
- }
36
- }
37
- exports.MultiClock = MultiClock;
38
- class Time {
39
- static asCompactDateTime(text) {
40
- // A compact datetime is always 17 digits long and starts with '20'
41
- if (text.startsWith("20") && /^\d{17}$/.test(text)) {
42
- return text;
43
- }
44
- return null;
45
- }
46
- static asCompactDate(text) {
47
- // A compact date is always 8 digits long and starts with '20'
48
- if (text.startsWith("20") && /^\d{8}$/.test(text)) {
49
- return text;
50
- }
51
- return null;
52
- }
53
- static isDateBefore(a, b) {
54
- return Time.compareDate(a, b) < 0;
55
- }
56
- static isDateAfter(a, b) {
57
- return Time.compareDate(a, b) > 0;
58
- }
59
- static compareDate(a, b) {
60
- if (a == null && b == null) {
61
- return 0;
62
- }
63
- else if (a == null) {
64
- return -1;
65
- }
66
- else if (b == null) {
67
- return 1;
68
- }
69
- return a.localeCompare(b);
70
- }
71
- static isDateTimeBefore(a, b) {
72
- return Time.compareDateTime(a, b) < 0;
73
- }
74
- static isDateTimeAfter(a, b) {
75
- return Time.compareDateTime(a, b) > 0;
76
- }
77
- static compareDateTime(a, b) {
78
- if (a == null && b == null) {
79
- return 0;
80
- }
81
- else if (a == null) {
82
- return -1;
83
- }
84
- else if (b == null) {
85
- return 1;
86
- }
87
- return a.localeCompare(b);
88
- }
89
- static sortByUtcTime(array) {
90
- return array.sort((a, b) => Time.compareDateTime(a.utc_time, b.utc_time));
91
- }
92
- static dateFrom(timestamp) {
93
- const timestampText = timestamp;
94
- if (timestampText.length >= 8 && /^\d{8}.*/.test(timestampText)) {
95
- return timestampText.substring(0, 8);
96
- }
97
- if (typeof (timestamp) === "string") {
98
- throw new Error("can\x27t parse date from malformed timestamp: " + timestamp);
99
- }
100
- else {
101
- throw new Error("can\x27t parse date from malformed timestamp: " + JSON.stringify(timestamp));
102
- }
103
- }
104
- static datesBetween(minDate, maxDate) {
105
- const dates = new Array();
106
- let d = minDate;
107
- while (d.localeCompare(minDate) >= 0 && d.localeCompare(maxDate) <= 0) {
108
- dates.push(d);
109
- d = (0, dayjs_1.default)(d, Time.DATE_FORMAT).add(1, 'days').format(Time.DATE_FORMAT);
110
- }
111
- return dates;
112
- }
113
- static plus(timestamp, amount, units) {
114
- const time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
115
- return time.add(amount, units).format(Time.DATETIME_FORMAT_COMPACT);
116
- }
117
- static todayLocal() {
118
- return Time.dateFrom(Time.local());
119
- }
120
- static todayUtc() {
121
- return Time.dateFrom(Time.utc());
122
- }
123
- static startOfMonth(date) {
124
- let text = date;
125
- if (text.startsWith("20") && /^\d{8}$/.test(text)) {
126
- text = text.substring(0, 6) + "01;";
127
- }
128
- return text;
129
- }
130
- static local(utc) {
131
- let result;
132
- if (typeof (utc) === "undefined") {
133
- result = (0, dayjs_1.default)().format(Time.DATETIME_FORMAT_COMPACT);
134
- }
135
- else {
136
- const timestamp = dayjs_1.default.utc(utc, Time.DATETIME_FORMAT_COMPACT)
137
- .local();
138
- result = timestamp.format(Time.DATETIME_FORMAT_COMPACT);
139
- }
140
- return result;
141
- }
142
- // TODO: Should this actually be called localFromEpochSeconds? Passing zero
143
- // returns timestamp that is local-timezone hours offset from UTC epoch time.
144
- static utcFromEpochSeconds(seconds) {
145
- return dayjs_1.default.unix(seconds).utc().format(Time.DATETIME_FORMAT_COMPACT);
146
- }
147
- static utc(local) {
148
- let result;
149
- if (typeof (local) === "undefined") {
150
- result = dayjs_1.default.utc().format(Time.DATETIME_FORMAT_COMPACT);
151
- }
152
- else {
153
- const timestamp = (0, dayjs_1.default)(local, Time.DATETIME_FORMAT_COMPACT)
154
- .utc();
155
- result = timestamp.format(Time.DATETIME_FORMAT_COMPACT);
156
- }
157
- return result;
158
- }
159
- static format(timestamp, pattern, isLocal) {
160
- let time = null;
161
- if (isLocal) {
162
- time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
163
- }
164
- else {
165
- time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
166
- .local();
167
- }
168
- return time.format(pattern);
169
- }
170
- static formatFromDate(date, pattern) {
171
- const time = (0, dayjs_1.default)(date);
172
- return time.format(pattern);
173
- }
174
- static beautify(timestamp, isLocal = false, amount, units) {
175
- const now = (0, dayjs_1.default)();
176
- let time = null;
177
- if (isLocal) {
178
- time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
179
- }
180
- else {
181
- time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
182
- .local();
183
- }
184
- // If the 'num' and 'units' params exist, then use them to manipulate the timestamp
185
- if (typeof (amount) === "number" && typeof (units) === "string") {
186
- time = time.add(amount, units);
187
- }
188
- let datePart = "", timePart = "";
189
- const timeDayOfYear = time.dayOfYear();
190
- const nowDayOfYear = now.dayOfYear();
191
- const timeYear = time.year();
192
- const nowYear = now.year();
193
- if (nowDayOfYear === timeDayOfYear && nowYear === timeYear) {
194
- datePart = "Today";
195
- }
196
- else if (nowDayOfYear - timeDayOfYear === 1 && nowYear === timeYear) {
197
- datePart = "Yesterday";
198
- }
199
- else if (nowDayOfYear === 1 && timeDayOfYear === 365 && timeYear % 4 !== 0 && nowYear - timeYear === 1) {
200
- datePart = "Yesterday";
201
- }
202
- else if (nowDayOfYear === 1 && timeDayOfYear === 366 && timeYear % 4 === 0 && nowYear - timeYear === 1) {
203
- datePart = "Yesterday";
204
- }
205
- else if (timeDayOfYear - nowDayOfYear === 1 && timeYear === nowYear) {
206
- datePart = "Tomorrow";
207
- }
208
- else if (timeDayOfYear === 1 && nowDayOfYear === 365 && nowYear % 4 !== 0 && timeYear - nowYear === 1) {
209
- datePart = "Tomorrow";
210
- }
211
- else if (timeDayOfYear === 1 && nowDayOfYear === 366 && nowYear % 4 === 0 && timeYear - nowYear === 1) {
212
- datePart = "Tomorrow";
213
- }
214
- else if (Math.abs(now.diff(time, "days")) <= 30) {
215
- datePart = time.format(Time.DATE_FULLY_BEAUTIFIED);
216
- }
217
- else {
218
- datePart = time.format(Time.DATE_BEAUTIFIED);
219
- }
220
- if (Math.abs(now.diff(time, "days")) <= 7) {
221
- timePart = time.format("h:mm a");
222
- timePart = timePart.replace(" am", "a");
223
- timePart = timePart.replace(" pm", "p");
224
- }
225
- if (timePart.length === 0) {
226
- return datePart;
227
- }
228
- else {
229
- return datePart + ", " + timePart;
230
- }
231
- }
232
- static absDiffMinutes(a, b) {
233
- const aMoment = (0, dayjs_1.default)(a, Time.DATETIME_FORMAT_COMPACT);
234
- const bMoment = (0, dayjs_1.default)(b, Time.DATETIME_FORMAT_COMPACT);
235
- return Math.abs(aMoment.diff(bMoment, 'minutes', true));
236
- }
237
- static elapsed(timestamp, isLocal) {
238
- let time = null;
239
- if (isLocal) {
240
- time = (0, dayjs_1.default)(timestamp, Time.DATETIME_FORMAT_COMPACT);
241
- }
242
- else {
243
- time = dayjs_1.default.utc(timestamp, Time.DATETIME_FORMAT_COMPACT)
244
- .local();
245
- }
246
- const difference = (0, dayjs_1.default)().diff(time, 'seconds');
247
- if (difference < 60) {
248
- return difference === 1 ? "1 second ago" : difference + " seconds ago";
249
- }
250
- else if (difference < 3 * 60) {
251
- const minutes = Math.floor(difference / 60);
252
- const seconds = Math.floor(difference % 60);
253
- const minText = minutes === 1 ? "1 minute" : minutes + " minutes";
254
- const secText = seconds === 1 ? "1 second" : seconds + " seconds";
255
- return minText + ", " + secText + " ago";
256
- }
257
- else if (difference < 60 * 60) {
258
- const minutes = Math.round(difference / 60);
259
- return "about " + minutes + " minutes ago";
260
- }
261
- else if (difference < 24 * 60 * 60) {
262
- const hours = Math.round(difference / (60 * 60));
263
- return "about " + hours + " hours ago";
264
- }
265
- else {
266
- return Time.beautify(timestamp, isLocal);
267
- }
268
- }
269
- static timeUntil(utcTime, units) {
270
- return -Time.timeSince(utcTime, units);
271
- }
272
- static timeSince(utcTime, units) {
273
- const then = dayjs_1.default.utc(utcTime, Time.DATETIME_FORMAT_COMPACT);
274
- const now = (0, dayjs_1.default)().utc();
275
- return now.diff(then, units, true);
276
- }
277
- static currentYear() {
278
- return (0, dayjs_1.default)().format(Time.YEAR_ONLY);
279
- }
280
- static humanizedDatePacific(epochSeconds) {
281
- return dayjs_1.default.unix(epochSeconds).tz("America/Los_Angeles").format("MMMM D, YYYY");
282
- }
283
- // TODO: Should this actually expect seconds instead of milliseconds?
284
- static humanizedTimePacific(epochSeconds) {
285
- return (0, dayjs_1.default)(epochSeconds).tz("America/Los_Angeles").format("h:mm:ss a") + " (Pacific)";
286
- }
287
- }
288
- exports.Time = Time;
289
- Time.DATETIME_FORMAT_LEGACY = "YYYY-MM-DDTHH:mm:ss.SSSZ";
290
- Time.DATE_FORMAT = "YYYYMMDD";
291
- Time.DATETIME_FORMAT_COMPACT = "YYYYMMDDHHmmssSSS";
292
- Time.DATE_NO_YEAR = "MMMM D";
293
- Time.DATE_BEAUTIFIED = "MMMM D, YYYY";
294
- Time.DATE_FULLY_BEAUTIFIED = "dddd, MMMM D, YYYY";
295
- Time.YEAR_ONLY = "YYYY";