@wastech-mdlint/viewer 0.0.0-stage → 0.4.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 (189) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -2
  3. package/assets/favicon.ico +0 -0
  4. package/assets/viewer.css +4184 -0
  5. package/dist/asset-routes.d.ts +4 -0
  6. package/dist/asset-routes.js +107 -0
  7. package/dist/blame.d.ts +8 -0
  8. package/dist/blame.js +54 -0
  9. package/dist/branch-changes.d.ts +8 -0
  10. package/dist/branch-changes.js +49 -0
  11. package/dist/candidate-lint-worker.d.ts +1 -0
  12. package/dist/candidate-lint-worker.js +67 -0
  13. package/dist/candidate-lint.d.ts +39 -0
  14. package/dist/candidate-lint.js +115 -0
  15. package/dist/change-banner.d.ts +38 -0
  16. package/dist/change-banner.js +108 -0
  17. package/dist/change-diff.d.ts +23 -0
  18. package/dist/change-diff.js +140 -0
  19. package/dist/change-marks.d.ts +32 -0
  20. package/dist/change-marks.js +363 -0
  21. package/dist/changes-article.d.ts +15 -0
  22. package/dist/changes-article.js +244 -0
  23. package/dist/changes-routes.d.ts +12 -0
  24. package/dist/changes-routes.js +271 -0
  25. package/dist/changes.d.ts +113 -0
  26. package/dist/changes.js +324 -0
  27. package/dist/cli-args.d.ts +21 -0
  28. package/dist/cli-args.js +93 -0
  29. package/dist/client/banner-height.d.ts +1 -0
  30. package/dist/client/banner-height.js +33 -0
  31. package/dist/client/change-marks.d.ts +1 -0
  32. package/dist/client/change-marks.js +56 -0
  33. package/dist/client/changes.d.ts +1 -0
  34. package/dist/client/changes.js +183 -0
  35. package/dist/client/chart-option.d.ts +3 -0
  36. package/dist/client/chart-option.js +76 -0
  37. package/dist/client/charts.d.ts +1 -0
  38. package/dist/client/charts.js +54 -0
  39. package/dist/client/clipboard.d.ts +1 -0
  40. package/dist/client/clipboard.js +43 -0
  41. package/dist/client/code-copy.d.ts +1 -0
  42. package/dist/client/code-copy.js +29 -0
  43. package/dist/client/column-resize.d.ts +1 -0
  44. package/dist/client/column-resize.js +120 -0
  45. package/dist/client/config-dom.d.ts +13 -0
  46. package/dist/client/config-dom.js +47 -0
  47. package/dist/client/config-draft.d.ts +73 -0
  48. package/dist/client/config-draft.js +218 -0
  49. package/dist/client/config-editor.d.ts +3 -0
  50. package/dist/client/config-editor.js +677 -0
  51. package/dist/client/config-fields.d.ts +35 -0
  52. package/dist/client/config-fields.js +339 -0
  53. package/dist/client/config-json.d.ts +18 -0
  54. package/dist/client/config-json.js +96 -0
  55. package/dist/client/config-preview.d.ts +9 -0
  56. package/dist/client/config-preview.js +91 -0
  57. package/dist/client/config-rules.d.ts +14 -0
  58. package/dist/client/config-rules.js +202 -0
  59. package/dist/client/config-types.d.ts +91 -0
  60. package/dist/client/config-types.js +4 -0
  61. package/dist/client/copy-path.d.ts +1 -0
  62. package/dist/client/copy-path.js +32 -0
  63. package/dist/client/dashboard-requests.d.ts +11 -0
  64. package/dist/client/dashboard-requests.js +28 -0
  65. package/dist/client/dashboard.d.ts +1 -0
  66. package/dist/client/dashboard.js +119 -0
  67. package/dist/client/diagnostics.d.ts +1 -0
  68. package/dist/client/diagnostics.js +164 -0
  69. package/dist/client/diagrams.d.ts +1 -0
  70. package/dist/client/diagrams.js +81 -0
  71. package/dist/client/diff-expand.d.ts +1 -0
  72. package/dist/client/diff-expand.js +42 -0
  73. package/dist/client/display-settings-model.d.ts +74 -0
  74. package/dist/client/display-settings-model.js +229 -0
  75. package/dist/client/display-settings.d.ts +1 -0
  76. package/dist/client/display-settings.js +411 -0
  77. package/dist/client/echarts.d.ts +30 -0
  78. package/dist/client/echarts.js +14 -0
  79. package/dist/client/graph-layout.d.ts +88 -0
  80. package/dist/client/graph-layout.js +198 -0
  81. package/dist/client/graph.d.ts +2 -0
  82. package/dist/client/graph.js +566 -0
  83. package/dist/client/history.d.ts +21 -0
  84. package/dist/client/history.js +86 -0
  85. package/dist/client/live-reload-model.d.ts +28 -0
  86. package/dist/client/live-reload-model.js +52 -0
  87. package/dist/client/live-reload.d.ts +9 -0
  88. package/dist/client/live-reload.js +138 -0
  89. package/dist/client/menu.d.ts +14 -0
  90. package/dist/client/menu.js +176 -0
  91. package/dist/client/navigation-feedback.d.ts +1 -0
  92. package/dist/client/navigation-feedback.js +141 -0
  93. package/dist/client/open-config.d.ts +1 -0
  94. package/dist/client/open-config.js +48 -0
  95. package/dist/client/outline-spy.d.ts +1 -0
  96. package/dist/client/outline-spy.js +60 -0
  97. package/dist/client/prompts.d.ts +7 -0
  98. package/dist/client/prompts.js +65 -0
  99. package/dist/client/review.d.ts +1 -0
  100. package/dist/client/review.js +379 -0
  101. package/dist/client/search.d.ts +1 -0
  102. package/dist/client/search.js +199 -0
  103. package/dist/client/segmented.d.ts +13 -0
  104. package/dist/client/segmented.js +70 -0
  105. package/dist/client/source-lines.d.ts +16 -0
  106. package/dist/client/source-lines.js +47 -0
  107. package/dist/client/theme-toggle.d.ts +10 -0
  108. package/dist/client/theme-toggle.js +100 -0
  109. package/dist/client/theme.d.ts +0 -0
  110. package/dist/client/theme.js +50 -0
  111. package/dist/client/tree-marks.d.ts +31 -0
  112. package/dist/client/tree-marks.js +102 -0
  113. package/dist/client/tree-state.d.ts +0 -0
  114. package/dist/client/tree-state.js +179 -0
  115. package/dist/client/viewer.d.ts +1 -0
  116. package/dist/client/viewer.js +53 -0
  117. package/dist/config-editor.d.ts +166 -0
  118. package/dist/config-editor.js +378 -0
  119. package/dist/config-routes.d.ts +18 -0
  120. package/dist/config-routes.js +213 -0
  121. package/dist/context-view.d.ts +41 -0
  122. package/dist/context-view.js +295 -0
  123. package/dist/corpus-routes.d.ts +31 -0
  124. package/dist/corpus-routes.js +258 -0
  125. package/dist/corpus.d.ts +134 -0
  126. package/dist/corpus.js +653 -0
  127. package/dist/dashboard-article.d.ts +14 -0
  128. package/dist/dashboard-article.js +290 -0
  129. package/dist/dashboard.d.ts +94 -0
  130. package/dist/dashboard.js +468 -0
  131. package/dist/diagnostics.d.ts +23 -0
  132. package/dist/diagnostics.js +44 -0
  133. package/dist/document-routes.d.ts +39 -0
  134. package/dist/document-routes.js +396 -0
  135. package/dist/event-hub.d.ts +39 -0
  136. package/dist/event-hub.js +120 -0
  137. package/dist/findings-panel.d.ts +4 -0
  138. package/dist/findings-panel.js +74 -0
  139. package/dist/folder-page.d.ts +8 -0
  140. package/dist/folder-page.js +74 -0
  141. package/dist/graph-view.d.ts +66 -0
  142. package/dist/graph-view.js +236 -0
  143. package/dist/highlight.d.ts +24 -0
  144. package/dist/highlight.js +100 -0
  145. package/dist/http-send.d.ts +9 -0
  146. package/dist/http-send.js +53 -0
  147. package/dist/index.d.ts +2 -0
  148. package/dist/index.js +72 -0
  149. package/dist/open-file.d.ts +36 -0
  150. package/dist/open-file.js +87 -0
  151. package/dist/page-tree.d.ts +3 -0
  152. package/dist/page-tree.js +105 -0
  153. package/dist/page.d.ts +73 -0
  154. package/dist/page.js +478 -0
  155. package/dist/prompts.d.ts +25 -0
  156. package/dist/prompts.js +82 -0
  157. package/dist/render-cache.d.ts +23 -0
  158. package/dist/render-cache.js +38 -0
  159. package/dist/render-document.d.ts +60 -0
  160. package/dist/render-document.js +440 -0
  161. package/dist/request-path.d.ts +17 -0
  162. package/dist/request-path.js +51 -0
  163. package/dist/review-context.d.ts +24 -0
  164. package/dist/review-context.js +109 -0
  165. package/dist/review-queries.d.ts +26 -0
  166. package/dist/review-queries.js +69 -0
  167. package/dist/review-state.d.ts +106 -0
  168. package/dist/review-state.js +251 -0
  169. package/dist/review-store.d.ts +145 -0
  170. package/dist/review-store.js +530 -0
  171. package/dist/router.d.ts +28 -0
  172. package/dist/router.js +294 -0
  173. package/dist/search.d.ts +22 -0
  174. package/dist/search.js +164 -0
  175. package/dist/security.d.ts +95 -0
  176. package/dist/security.js +196 -0
  177. package/dist/server.d.ts +21 -0
  178. package/dist/server.js +224 -0
  179. package/dist/speculation-rules.d.ts +4 -0
  180. package/dist/speculation-rules.js +49 -0
  181. package/dist/state-dir.d.ts +6 -0
  182. package/dist/state-dir.js +31 -0
  183. package/dist/tree-marks.d.ts +49 -0
  184. package/dist/tree-marks.js +108 -0
  185. package/dist/viewer-context.d.ts +37 -0
  186. package/dist/viewer-context.js +74 -0
  187. package/dist/watch.d.ts +41 -0
  188. package/dist/watch.js +135 -0
  189. package/package.json +57 -4
@@ -0,0 +1,218 @@
1
+ // Unsaved work, kept across a reload — live reload refreshes the page whenever a document is added
2
+ // or removed, and losing a half-made config change to that would be a trap. It is restored only
3
+ // onto the same version of the file it was made to, which `base`, the file's hash, identifies.
4
+ const DRAFT_KEY = "wastech-mdlint-viewer:config-draft";
5
+ // A draft made to a version of the file that is no longer on disk — a pull, a checkout or an
6
+ // editor's format-on-save changed it meanwhile. It cannot be restored as it stands, and dropping it
7
+ // would lose the reader's work without a word, so it is kept apart from the current draft, offered
8
+ // back until the reader applies or discards it, and never overwritten by the change they make next.
9
+ const SET_ASIDE_KEY = "wastech-mdlint-viewer:config-draft-set-aside";
10
+ /**
11
+ * A stored value as a draft, or `undefined` when it is not one. Storage is written by this page
12
+ * alone, under keys only it uses, but also by older versions of the viewer and by hand; a value that
13
+ * does not have a draft's shape would break the editor rather than restore anything.
14
+ */
15
+ export function parseDraft(value) {
16
+ if (typeof value !== "object" || value === null) {
17
+ return undefined;
18
+ }
19
+ const draft = value;
20
+ if (typeof draft.base !== "string" ||
21
+ typeof draft.text !== "string" ||
22
+ !Array.isArray(draft.edits) ||
23
+ !draft.edits.every(isEdit) ||
24
+ (draft.mode !== "form" && draft.mode !== "text") ||
25
+ (draft.full !== undefined && typeof draft.full !== "string") ||
26
+ (draft.saving !== undefined && !isSaving(draft.saving))) {
27
+ return undefined;
28
+ }
29
+ return {
30
+ base: draft.base,
31
+ text: draft.text,
32
+ edits: draft.edits,
33
+ mode: draft.mode,
34
+ // A draft without it was written before it was kept. Taking its text for the reader's own errs
35
+ // towards keeping that text, where the other answer would drop it for the file's new one.
36
+ textEdited: typeof draft.textEdited === "boolean" ? draft.textEdited : true,
37
+ full: draft.full,
38
+ saving: draft.saving,
39
+ };
40
+ }
41
+ function isEdit(value) {
42
+ return (typeof value === "object" &&
43
+ value !== null &&
44
+ ["set", "remove", "insert"].includes(value.op) &&
45
+ Array.isArray(value.path));
46
+ }
47
+ function isSaving(value) {
48
+ return (typeof value === "object" &&
49
+ value !== null &&
50
+ typeof value.text === "string" &&
51
+ typeof value.edited === "boolean" &&
52
+ (value.edits === undefined ||
53
+ (Array.isArray(value.edits) &&
54
+ value.edits.every(isEdit))));
55
+ }
56
+ /**
57
+ * The changed file's whole text, for copying or downloading: the text itself when no form edit is
58
+ * left to apply to it, the server's last answer when there is, or `undefined` when there is none.
59
+ */
60
+ export function draftText(draft) {
61
+ return draft.edits.length === 0 ? draft.text : draft.full;
62
+ }
63
+ /**
64
+ * What is left of a draft once its save has written `saved`: nothing, when the reader changed
65
+ * nothing while the save was on its way, or the change they made meanwhile, now based on the saved
66
+ * file.
67
+ *
68
+ * A change made in the form stays one: the saved text, with the edits made after the save began.
69
+ * It has to, because a draft whose text is taken for the reader's own replaces the file when it is
70
+ * later set aside and applied — and the text it held was the one from before the save, so applying
71
+ * it would put back what another program changed since. A text the reader wrote, or a draft whose
72
+ * edits cannot be split at the save, keeps its text and edits as they are: applied to the text they
73
+ * were made to, they give the saved text plus the later change.
74
+ */
75
+ export function afterSave(draft, saved) {
76
+ if (draft.saving?.edited !== true ||
77
+ (draft.edits.length === 0 && draft.text === saved.text)) {
78
+ return undefined;
79
+ }
80
+ // Split only where the saved edits still lead the draft's, each as it was saved: one changed in
81
+ // place since — the editor folds a field typed into twice into one edit — would otherwise be
82
+ // dropped as already saved while holding the reader's later value.
83
+ const savedEdits = draft.saving.edits;
84
+ if (!draft.textEdited &&
85
+ savedEdits !== undefined &&
86
+ savedEdits.length <= draft.edits.length &&
87
+ savedEdits.every((savedEdit, index) => JSON.stringify(savedEdit) === JSON.stringify(draft.edits[index]))) {
88
+ return {
89
+ base: saved.hash,
90
+ text: saved.text,
91
+ edits: draft.edits.slice(savedEdits.length),
92
+ mode: draft.mode,
93
+ textEdited: false,
94
+ // The whole changed file is the same text either way: the saved edits are now in `text`.
95
+ full: draft.full,
96
+ };
97
+ }
98
+ return {
99
+ base: saved.hash,
100
+ text: draft.text,
101
+ edits: draft.edits,
102
+ mode: draft.mode,
103
+ textEdited: draft.text !== saved.text,
104
+ full: draft.full,
105
+ };
106
+ }
107
+ /**
108
+ * What to do with the stored drafts once the page has read the config file:
109
+ *
110
+ * - `restore`: the draft to put back into the editor, made to this version of the file.
111
+ * - `setAside`: a draft made to another version, to offer back to the reader.
112
+ *
113
+ * A draft whose save wrote the file the page now reads is not stale: the reload that save started
114
+ * reached the page before the save's answer did, and the draft becomes whatever the reader changed
115
+ * after saving. Any other draft for another version is set aside, replacing an older one set aside
116
+ * before — that one the reader was already shown, and went on to make a new change instead.
117
+ */
118
+ export function planDrafts(stored, setAside, file) {
119
+ let restore;
120
+ let aside = setAside;
121
+ if (stored !== undefined) {
122
+ if (stored.base === file.hash) {
123
+ // A save still marked was never written: the file is still the version the draft was made to.
124
+ restore = { ...stored, saving: undefined };
125
+ }
126
+ else if (stored.saving?.text === file.text) {
127
+ restore = afterSave(stored, file);
128
+ }
129
+ else {
130
+ aside = stored;
131
+ }
132
+ }
133
+ // The file can come back to the version a set-aside draft was made to — a checkout undone — and
134
+ // the draft then applies as it stands.
135
+ if (restore === undefined && aside?.base === file.hash) {
136
+ restore = aside;
137
+ aside = undefined;
138
+ }
139
+ return { restore, setAside: aside };
140
+ }
141
+ /**
142
+ * A set-aside draft, made to apply to the current file: a change made in the form replays its edits
143
+ * onto the current text, as they name values by their place in the config, not by line; a text the
144
+ * reader wrote replaces the current one, and the preview then shows what that does.
145
+ */
146
+ export function rebaseDraft(draft, file) {
147
+ if (!draft.textEdited) {
148
+ return {
149
+ base: file.hash,
150
+ text: file.text,
151
+ edits: draft.edits,
152
+ mode: draft.mode,
153
+ textEdited: false,
154
+ };
155
+ }
156
+ // Folded into one text where the server already did it; otherwise the edits ride along on the
157
+ // reader's text, and the first preview folds them as it does for any restored draft.
158
+ const text = draftText(draft);
159
+ return text === undefined
160
+ ? {
161
+ base: file.hash,
162
+ text: draft.text,
163
+ edits: draft.edits,
164
+ mode: draft.mode,
165
+ textEdited: draft.text !== file.text,
166
+ full: draft.full,
167
+ }
168
+ : {
169
+ base: file.hash,
170
+ text,
171
+ edits: [],
172
+ mode: draft.mode,
173
+ textEdited: text !== file.text,
174
+ };
175
+ }
176
+ /**
177
+ * Keeps the draft, or forgets it when there is nothing unsaved; `false` when storage refused, for a
178
+ * caller about to reload the page and count on finding it there.
179
+ */
180
+ export function storeDraft(draft) {
181
+ return store(DRAFT_KEY, draft);
182
+ }
183
+ export function clearDraft() {
184
+ store(DRAFT_KEY, undefined);
185
+ }
186
+ export function readDraft() {
187
+ return read(DRAFT_KEY);
188
+ }
189
+ export function storeSetAside(draft) {
190
+ store(SET_ASIDE_KEY, draft);
191
+ }
192
+ export function readSetAside() {
193
+ return read(SET_ASIDE_KEY);
194
+ }
195
+ // Storage can be unavailable (private windows, blocked site data) or full. A reload then loses the
196
+ // draft, as it would without this; nothing else depends on it.
197
+ function store(key, draft) {
198
+ try {
199
+ if (draft === undefined) {
200
+ sessionStorage.removeItem(key);
201
+ }
202
+ else {
203
+ sessionStorage.setItem(key, JSON.stringify(draft));
204
+ }
205
+ return true;
206
+ }
207
+ catch {
208
+ return false;
209
+ }
210
+ }
211
+ function read(key) {
212
+ try {
213
+ return parseDraft(JSON.parse(sessionStorage.getItem(key) ?? "null"));
214
+ }
215
+ catch {
216
+ return undefined;
217
+ }
218
+ }
@@ -0,0 +1,3 @@
1
+ /** The id of the data the editor is built from, as the server names it. */
2
+ export declare const CONFIG_DATA_ID = "viewer.config-data";
3
+ export declare function initConfigEditor(): void;