@fiduswriter/editor 0.1.70 → 0.1.72

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 (37) hide show
  1. package/css/colors.css +1 -0
  2. package/css/editor.css +23 -5
  3. package/css/footnotes.css +14 -0
  4. package/css/margin_boxes.css +1 -6
  5. package/css/tracking.css +10 -0
  6. package/dist/comments/interactions.js +3 -1
  7. package/dist/comments/interactions.js.map +1 -1
  8. package/dist/marginboxes/index.d.ts +3 -1
  9. package/dist/marginboxes/index.d.ts.map +1 -1
  10. package/dist/marginboxes/index.js +62 -21
  11. package/dist/marginboxes/index.js.map +1 -1
  12. package/dist/marginboxes/templates.d.ts.map +1 -1
  13. package/dist/marginboxes/templates.js +42 -18
  14. package/dist/marginboxes/templates.js.map +1 -1
  15. package/dist/state_plugins/track/find_selected_changes.js +1 -1
  16. package/dist/state_plugins/track/find_selected_changes.js.map +1 -1
  17. package/dist/state_plugins/track/plugin.js +2 -2
  18. package/dist/state_plugins/track/plugin.js.map +1 -1
  19. package/dist/static_app.d.ts +5 -0
  20. package/dist/static_app.d.ts.map +1 -1
  21. package/dist/static_app.js +5 -0
  22. package/dist/static_app.js.map +1 -1
  23. package/dist/static_editor.d.ts +5 -0
  24. package/dist/static_editor.d.ts.map +1 -1
  25. package/dist/static_editor.js.map +1 -1
  26. package/dist/types.d.ts +5 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/comments/interactions.ts +3 -3
  31. package/src/marginboxes/index.ts +76 -24
  32. package/src/marginboxes/templates.ts +44 -10
  33. package/src/state_plugins/track/find_selected_changes.ts +1 -1
  34. package/src/state_plugins/track/plugin.ts +2 -2
  35. package/src/static_app.ts +10 -0
  36. package/src/static_editor.ts +5 -0
  37. package/src/types.ts +5 -0
@@ -108,6 +108,26 @@ interface MarginBoxOptionComment {
108
108
  resolved?: boolean
109
109
  }
110
110
 
111
+ /** A template for an answer to a comment */
112
+ const COMMENT_SHOW_MORE_THRESHOLD = 120
113
+ const COMMENT_TRUNCATE_LENGTH = 110
114
+
115
+ function commentContentTemplate({
116
+ serialized,
117
+ isGlobal
118
+ }: {
119
+ serialized: {html: string; text: string}
120
+ isGlobal: boolean
121
+ }): string {
122
+ if (isGlobal || serialized.text.length <= COMMENT_SHOW_MORE_THRESHOLD) {
123
+ return `<p class="comment-p">${serialized.html}</p>`
124
+ }
125
+ const truncatedText = `${escapeText(
126
+ serialized.text.slice(0, COMMENT_TRUNCATE_LENGTH - 1)
127
+ )}…`
128
+ return `<div class="comment-truncated"><p class="comment-p">${truncatedText}</p></div><div class="comment-full" style="display:none"><p class="comment-p">${serialized.html}</p></div>`
129
+ }
130
+
111
131
  /** A template for an answer to a comment */
112
132
  const answerCommentTemplate = ({
113
133
  answer,
@@ -115,7 +135,8 @@ const answerCommentTemplate = ({
115
135
  commentId,
116
136
  activeCommentAnswerId,
117
137
  active,
118
- user
138
+ user,
139
+ isGlobal
119
140
  }: {
120
141
  answer: CommentAnswer
121
142
  author: ContactPerson | undefined
@@ -123,8 +144,10 @@ const answerCommentTemplate = ({
123
144
  activeCommentAnswerId: number | string | undefined
124
145
  active: boolean
125
146
  user: EditorUser
126
- }) =>
127
- `<div class="comment-item comment-answer collapse ${active ? "show" : ""}" id="comment-answer-${answer.id}">
147
+ isGlobal: boolean
148
+ }) => {
149
+ const serialized = serializeComment(answer.answer)
150
+ return `<div class="comment-item comment-answer collapse ${active ? "show" : ""}" id="comment-answer-${answer.id}">
128
151
  <div class="comment-user">
129
152
  ${author ? avatarTemplate({user: author}) : '<span class="fw-string-avatar"></span>'}
130
153
  <h5 class="comment-user-name">${escapeText(author?.name || answer.username)}</h5>
@@ -138,11 +161,13 @@ const answerCommentTemplate = ({
138
161
  </div>
139
162
  </div>`
140
163
  : `<div class="comment-text-wrapper">
141
- <div class="comment-p">${serializeComment(answer.answer).html}</div>
164
+ ${commentContentTemplate({serialized, isGlobal})}
142
165
  </div>
143
166
  <div class="comment-collapsible-buttons">
144
167
  ${
145
- serializeComment(answer.answer).text.length > 68
168
+ !isGlobal &&
169
+ serialized.text.length >
170
+ COMMENT_SHOW_MORE_THRESHOLD
146
171
  ? `<a type="button" class="comment-expand-compress show-more-less">${gettext("show more")}</a>`
147
172
  : ""
148
173
  }
@@ -154,6 +179,7 @@ const answerCommentTemplate = ({
154
179
  }`
155
180
  }
156
181
  </div>`
182
+ }
157
183
 
158
184
  interface SingleCommentTemplateProps {
159
185
  comment: Comment
@@ -168,8 +194,9 @@ const singleCommentTemplate = ({
168
194
  author,
169
195
  active,
170
196
  editComment
171
- }: SingleCommentTemplateProps) =>
172
- `<div class="comment-item">
197
+ }: SingleCommentTemplateProps) => {
198
+ const serialized = serializeComment(comment.comment)
199
+ return `<div class="comment-item">
173
200
  <div class="comment-user">
174
201
  ${author ? avatarTemplate({user: author}) : '<span class="fw-string-avatar"></span>'}
175
202
  <h5 class="comment-user-name">${escapeText(author?.name || comment.username)}</h5>
@@ -179,13 +206,18 @@ const singleCommentTemplate = ({
179
206
  ${
180
207
  active && editComment
181
208
  ? '<div id="comment-editor"></div>'
182
- : `<p class="comment-p">${serializeComment(comment.comment).html}</p>`
209
+ : `${commentContentTemplate({
210
+ serialized,
211
+ isGlobal: !!comment.isGlobal
212
+ })}`
183
213
  }
184
214
  </div>
185
215
  <div class="comment-collapsible-buttons">
186
216
  ${
187
217
  !editComment &&
188
- serializeComment(comment.comment).text.length > 68
218
+ !comment.isGlobal &&
219
+ serialized.text.length >
220
+ COMMENT_SHOW_MORE_THRESHOLD
189
221
  ? `<a type="button" class="comment-expand-compress show-more-less">${gettext("show more")}</a>`
190
222
  : ""
191
223
  }
@@ -196,6 +228,7 @@ const singleCommentTemplate = ({
196
228
  }
197
229
  </div>
198
230
  </div>`
231
+ }
199
232
 
200
233
  /** A template for the editor of a first comment before it has been saved (not an answer to a comment). */
201
234
  const firstCommentTemplate = ({
@@ -330,7 +363,8 @@ ${
330
363
  commentId: comment.id,
331
364
  active,
332
365
  activeCommentAnswerId,
333
- user
366
+ user,
367
+ isGlobal: !!comment.isGlobal
334
368
  })
335
369
  )
336
370
  .join("")
@@ -98,7 +98,7 @@ export function findSelectedChanges(state: EditorState): SelectedChanges {
98
98
  }
99
99
  }
100
100
  }
101
- return false
101
+ return true
102
102
  })
103
103
  }
104
104
  if (insertionMark && insertionPos !== false) {
@@ -84,7 +84,7 @@ export function trackPlugin(options: {editor: Editor}) {
84
84
  decos: DecorationSet.empty
85
85
  }
86
86
  },
87
- apply(tr, _prev, _oldState, state) {
87
+ apply(tr, _prev, oldState, state) {
88
88
  const meta = tr.getMeta(key)
89
89
  if (meta) {
90
90
  // There has been an update, return values from meta instead
@@ -92,7 +92,7 @@ export function trackPlugin(options: {editor: Editor}) {
92
92
  return meta
93
93
  }
94
94
 
95
- const oldPluginState = key.getState(state) as {decos: DecorationSet} | undefined
95
+ const oldPluginState = key.getState(oldState) as {decos: DecorationSet} | undefined
96
96
  if (!oldPluginState) {
97
97
  return {decos: DecorationSet.empty}
98
98
  }
package/src/static_app.ts CHANGED
@@ -77,6 +77,11 @@ export interface StaticAppConfig {
77
77
  json: Record<string, unknown>
78
78
  status: number
79
79
  }>
80
+ /**
81
+ * Optional user preferences that control inline editing helpers.
82
+ * Recognized keys include `inline_references` and `inline_math`.
83
+ */
84
+ userPreferences?: Record<string, boolean>
80
85
  }
81
86
 
82
87
  interface StoredImage {
@@ -340,6 +345,11 @@ export async function createStaticApp(
340
345
  LANGUAGE: config.locale
341
346
  },
342
347
  csl: config.csl,
348
+ config: {
349
+ user: {
350
+ preferences: config.userPreferences ?? {}
351
+ }
352
+ },
343
353
  apiConnectors: {
344
354
  document: documentApi,
345
355
  documentImport: documentImportApi,
@@ -36,6 +36,11 @@ export interface StaticEditorConfig
36
36
  }>
37
37
  /** Optional extra editor plugins. */
38
38
  plugins?: Array<[string, Record<string, unknown>]>
39
+ /**
40
+ * Optional user preferences that control inline editing helpers.
41
+ * Recognized keys include `inline_references` and `inline_math`.
42
+ */
43
+ userPreferences?: Record<string, boolean>
39
44
  }
40
45
 
41
46
  async function loadLocaleCatalog(
package/src/types.ts CHANGED
@@ -122,6 +122,11 @@ export interface EditorApp {
122
122
  csl: CSL
123
123
  bibDB?: EditorBibDB
124
124
  imageDB: EditorImageDB
125
+ config?: {
126
+ user?: {
127
+ preferences?: Record<string, boolean>
128
+ }
129
+ }
125
130
  apiConnectors: {
126
131
  document: EditorDocumentApi
127
132
  documentImport: EditorDocumentImportApi